Skip to content

Commit 53140cd

Browse files
change progress callback for java wrapping support
1 parent 84ef709 commit 53140cd

File tree

5 files changed

+66
-24
lines changed

5 files changed

+66
-24
lines changed

app/genericProcessor/genericProcessor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ int main( int argc, char** argv )
7373

7474
std::cout << "start Transcode" << std::endl;
7575

76+
avtranscoder::ProgressListener progress;
77+
7678
// video re-wrapping or transcoding if necessary
77-
transcoder.process( callBackProgress );
79+
transcoder.process( progress );
7880

7981
std::cout << std::endl << "end ..." << std::endl;
8082
}

src/AvTranscoder/ProgressListener.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef _AV_TRANSCODER_PROGRESS_LISTENER_HPP_
2+
#define _AV_TRANSCODER_PROGRESS_LISTENER_HPP_
3+
4+
namespace avtranscoder
5+
{
6+
7+
enum EJobStatus
8+
{
9+
eJobStatusContinue = 0,
10+
eJobStatusCancel
11+
};
12+
13+
class ProgressListener
14+
{
15+
public:
16+
ProgressListener()
17+
{}
18+
19+
virtual ~ProgressListener()
20+
{}
21+
22+
virtual EJobStatus progress( const double processedDuration, const double programDuration )
23+
{
24+
std::cout << "c++ progress " << processedDuration << "/" << programDuration << std::endl;
25+
return eJobStatusContinue;
26+
}
27+
};
28+
29+
}
30+
31+
#endif

src/AvTranscoder/Transcoder.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,38 @@
33

44
#include <AvTranscoder/InputStream.hpp>
55
#include <AvTranscoder/OutputFile.hpp>
6+
#include <AvTranscoder/ProgressListener.hpp>
7+
68

79
#include <string>
810
#include <vector>
911

1012
namespace avtranscoder
1113
{
1214

13-
enum EJobStatus
14-
{
15-
eJobStatusContinue = 0,
16-
eJobStatusCancel
17-
};
18-
1915
class Transcoder
2016
{
2117
public:
2218
typedef std::vector< std::pair< std::string, size_t > > StreamsDefinition;
2319

2420
Transcoder( const std::string& filename );
25-
Transcoder( OutputFile& outputFile );
21+
Transcoder( OutputFile* outputFile );
22+
23+
~Transcoder();
2624

2725
void add( const std::string& filename, const size_t streamIndex );
2826

2927
void add( const StreamsDefinition& streams );
3028

31-
void process( EJobStatus (*callback)(double, double) );
29+
void process( ProgressListener& progress );
3230

3331
private:
34-
OutputFile _outputFile;
32+
OutputFile* _outputFile;
3533
std::vector< InputStream > _inputStreams;
3634
};
3735

3836
}
3937

38+
#include "Transcoder.tcc"
39+
4040
#endif

src/AvTranscoder/Transcoder.cpp renamed to src/AvTranscoder/Transcoder.tcc

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
#include "Transcoder.hpp"
2-
31
#include <AvTranscoder/InputFile.hpp>
42

53
namespace avtranscoder
64
{
75

86
Transcoder::Transcoder( const std::string& filename )
9-
: _outputFile( filename )
7+
: _outputFile( NULL )
8+
{
9+
_outputFile = new OutputFile( filename );
10+
_outputFile->setup();
11+
}
12+
13+
Transcoder::Transcoder( OutputFile* outputFile )
14+
: _outputFile( NULL )
1015
{
11-
_outputFile.setup();
16+
_outputFile = outputFile;
17+
_outputFile->setup();
1218
}
1319

14-
Transcoder::Transcoder( OutputFile& outputFile )
15-
: _outputFile( outputFile )
20+
Transcoder::~Transcoder()
1621
{
17-
_outputFile.setup();
22+
delete _outputFile;
23+
_outputFile = NULL;
1824
}
1925

2026
void Transcoder::add( const std::string& filename, const size_t streamIndex )
@@ -26,13 +32,13 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex )
2632
case AVMEDIA_TYPE_VIDEO:
2733
{
2834
_inputStreams.push_back( avtranscoder::InputStream( filename, streamIndex ) );
29-
_outputFile.addVideoStream( _inputStreams.back().getVideoDesc() );
35+
_outputFile->addVideoStream( _inputStreams.back().getVideoDesc() );
3036
break;
3137
}
3238
case AVMEDIA_TYPE_AUDIO:
3339
{
3440
_inputStreams.push_back( avtranscoder::InputStream( filename, streamIndex ) );
35-
_outputFile.addAudioStream( _inputStreams.back().getAudioDesc() );
41+
_outputFile->addAudioStream( _inputStreams.back().getAudioDesc() );
3642
break;
3743
}
3844
case AVMEDIA_TYPE_DATA:
@@ -55,7 +61,7 @@ void Transcoder::add( const StreamsDefinition& streams )
5561
return;
5662
}
5763

58-
void Transcoder::process( EJobStatus (*callback)(double, double) )
64+
void Transcoder::process( ProgressListener& progress )
5965
{
6066
size_t frame = 0;
6167

@@ -69,7 +75,7 @@ void Transcoder::process( EJobStatus (*callback)(double, double) )
6975
dataStreams.push_back( dataStream );
7076
}
7177

72-
_outputFile.beginWrap();
78+
_outputFile->beginWrap();
7379

7480
bool continueProcess( true );
7581

@@ -87,7 +93,7 @@ void Transcoder::process( EJobStatus (*callback)(double, double) )
8793
if( ! continueProcess )
8894
break;
8995

90-
switch( callback( _inputStreams.at( 0 ).getPacketDuration() * ( frame + 1 ), _inputStreams.at( 0 ).getDuration() ) )
96+
switch( progress.progress( _inputStreams.at( 0 ).getPacketDuration() * ( frame + 1 ), _inputStreams.at( 0 ).getDuration() ) )
9197
{
9298
case eJobStatusContinue:
9399
{
@@ -105,13 +111,13 @@ void Transcoder::process( EJobStatus (*callback)(double, double) )
105111

106112
for( size_t streamIndex = 0; streamIndex < _inputStreams.size(); ++streamIndex )
107113
{
108-
_outputFile.wrap( dataStreams.at( streamIndex ), streamIndex );
114+
_outputFile->wrap( dataStreams.at( streamIndex ), streamIndex );
109115
}
110116

111117
++frame;
112118
}
113119

114-
_outputFile.endWrap();
120+
_outputFile->endWrap();
115121

116122
}
117123

src/AvTranscoder/avTranscoder.i

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <AvTranscoder/InputStreamAudio.hpp>
3131
#include <AvTranscoder/InputStreamVideo.hpp>
3232

33+
34+
#include <AvTranscoder/ProgressListener.hpp>
3335
#include <AvTranscoder/Transcoder.hpp>
3436

3537
%}
@@ -67,4 +69,5 @@ namespace std {
6769
%include <AvTranscoder/InputStreamAudio.hpp>
6870
%include <AvTranscoder/InputStreamVideo.hpp>
6971

72+
%include <AvTranscoder/ProgressListener.hpp>
7073
%include <AvTranscoder/Transcoder.hpp>

0 commit comments

Comments
 (0)