Skip to content

Commit ae27b3c

Browse files
Merge pull request #100 from cchampet/dev_Progress_fix_java_binding
ProgressListener: clean
2 parents 4158cfe + 6f603c1 commit ae27b3c

File tree

17 files changed

+152
-69
lines changed

17 files changed

+152
-69
lines changed

app/cpp/avMeta/avMeta.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <AvTranscoder/File/InputFile.hpp>
22
#include <AvTranscoder/Metadatas/Print.hpp>
3+
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
34

45
#include <iostream>
56

@@ -11,7 +12,7 @@ int main( int argc, char** argv )
1112
return( -1 );
1213
}
1314

14-
avtranscoder::ProgressListener p;
15+
avtranscoder::NoDisplayProgress p;
1516

1617
avtranscoder::InputFile input( argv[1] );
1718
input.analyse( p, avtranscoder::InputFile::eAnalyseLevelFull );

app/cpp/avTranscoder/avTranscoder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <AvTranscoder/File/InputFile.hpp>
66
#include <AvTranscoder/File/OutputFile.hpp>
7+
#include <AvTranscoder/progress/ConsoleProgress.hpp>
78
#include <AvTranscoder/EssenceStream/InputAudio.hpp>
89
#include <AvTranscoder/EssenceStream/InputVideo.hpp>
910
#include <AvTranscoder/EssenceStream/OutputAudio.hpp>
@@ -17,7 +18,7 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )
1718
// av_log_set_level( AV_LOG_DEBUG );
1819

1920
Profile profile( true );
20-
ProgressListener p;
21+
ConsoleProgress p;
2122

2223
InputFile input( inputfilename );
2324
input.analyse( p );

app/cpp/avplay/AvReader.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <AvTranscoder/EssenceStream/InputVideo.hpp>
77
#include <AvTranscoder/EssenceTransform/VideoEssenceTransform.hpp>
88
#include <AvTranscoder/Metadatas/Print.hpp>
9+
#include <AvTranscoder/progress/ConsoleProgress.hpp>
910

1011
#include "Reader.hpp"
1112

@@ -18,7 +19,7 @@ class AvReader : public Reader
1819
, _sourceImage( NULL )
1920
, _imageToDisplay( NULL )
2021
{
21-
avtranscoder::ProgressListener p;
22+
avtranscoder::ConsoleProgress p;
2223

2324
_inputFile.analyse( p );
2425
_videoStream = _inputFile.getProperties().videoStreams.at(0).streamId;

app/cpp/genericProcessor/genericProcessor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
#include <AvTranscoder/progress/ConsoleProgress.hpp>
22
#include <AvTranscoder/Transcoder/Transcoder.hpp>
33

44
#include <iostream>
@@ -122,7 +122,7 @@ int main( int argc, char** argv )
122122
if( verbose )
123123
std::cout << "start Transcode" << std::endl;
124124

125-
avtranscoder::ProgressListener progress;
125+
avtranscoder::ConsoleProgress progress;
126126

127127
// video re-wrapping or transcoding if necessary
128128
transcoder.process( progress );

src/AvTranscoder/File/InputFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ InputFile::~InputFile()
6464
}
6565
}
6666

67-
InputFile& InputFile::analyse( ProgressListener& progress, const EAnalyseLevel level )
67+
InputFile& InputFile::analyse( IProgress& progress, const EAnalyseLevel level )
6868
{
6969
assert( _formatContext != NULL );
7070

@@ -134,7 +134,7 @@ InputFile& InputFile::analyse( ProgressListener& progress, const EAnalyseLevel l
134134
return *this;
135135
}
136136

137-
Properties InputFile::analyseFile( const std::string& filename, ProgressListener& progress, const EAnalyseLevel level )
137+
Properties InputFile::analyseFile( const std::string& filename, IProgress& progress, const EAnalyseLevel level )
138138
{
139139
InputFile file( filename );
140140
file.analyse( progress, level );

src/AvTranscoder/File/InputFile.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <AvTranscoder/CodedStream/AvInputStream.hpp>
1111

1212
#include <AvTranscoder/Metadatas/MediaMetadatasStructures.hpp>
13-
#include <AvTranscoder/ProgressListener.hpp>
13+
#include <AvTranscoder/progress/IProgress.hpp>
1414

1515
#include <AvTranscoder/Profile.hpp>
1616

@@ -50,7 +50,7 @@ class AvExport InputFile
5050
* call this function before getProperties().
5151
* @param progress callback to get analysis progression
5252
**/
53-
InputFile& analyse( ProgressListener& progress, const EAnalyseLevel level = eAnalyseLevelFull );
53+
InputFile& analyse( IProgress& progress, const EAnalyseLevel level = eAnalyseLevelFull );
5454

5555
/**
5656
* @brief Return media properties on the current InputFile.
@@ -67,7 +67,7 @@ class AvExport InputFile
6767
* @param progress callback to get analysis progression
6868
* @return structure of media metadatas
6969
**/
70-
static Properties analyseFile( const std::string& filename, ProgressListener& progress, const EAnalyseLevel level = eAnalyseLevelFull );
70+
static Properties analyseFile( const std::string& filename, IProgress& progress, const EAnalyseLevel level = eAnalyseLevelFull );
7171

7272
/**
7373
* @brief Get stream type: video, audio, subtitle, etc.

src/AvTranscoder/Metadatas/VideoStreamProperties.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void getGopProperties(
3333
AVCodecContext* codecContext,
3434
AVCodec* codec,
3535
const int videoStreamIndex,
36-
ProgressListener& progress
36+
IProgress& progress
3737
)
3838
{
3939
AVPacket pkt;
@@ -108,7 +108,7 @@ std::string makeTimecodeMpegToString( uint32_t tc25bit )
108108
VideoProperties videoStreamInfo(
109109
AVFormatContext* formatContext,
110110
const size_t videoStreamIndex,
111-
ProgressListener& progress,
111+
IProgress& progress,
112112
const InputFile::EAnalyseLevel level
113113
)
114114
{

src/AvTranscoder/ProgressListener.hpp

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/AvTranscoder/ProgressListener.i

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/AvTranscoder/Transcoder/Transcoder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "Transcoder.hpp"
2+
23
#include <limits>
4+
#include <iostream>
35

46
namespace avtranscoder
57
{
@@ -238,7 +240,7 @@ bool Transcoder::processFrame()
238240
return true;
239241
}
240242

241-
void Transcoder::process( ProgressListener& progress )
243+
void Transcoder::process( IProgress& progress )
242244
{
243245
size_t frame = 0;
244246

src/AvTranscoder/Transcoder/Transcoder.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <AvTranscoder/EssenceStream/DummyAudio.hpp>
1212
#include <AvTranscoder/EssenceStream/DummyVideo.hpp>
1313

14-
#include <AvTranscoder/ProgressListener.hpp>
14+
#include <AvTranscoder/progress/IProgress.hpp>
1515

1616
#include <AvTranscoder/Profile.hpp>
1717

@@ -111,7 +111,7 @@ class Transcoder
111111
* @brief Process all the streams, and ended the process depending on the transcode politic.
112112
* @param progress
113113
*/
114-
void process( ProgressListener& progress );
114+
void process( IProgress& progress );
115115

116116
/**
117117
* @brief Set the transcodage politic.

src/AvTranscoder/avTranscoder.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#include <AvTranscoder/Transcoder/Transcoder.hpp>
5151
%}
5252

53-
%include "AvTranscoder/ProgressListener.i"
53+
%include "AvTranscoder/progress/progress.i"
5454

5555
namespace std {
5656
%template(IntPair) pair< size_t, size_t >;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "ConsoleProgress.hpp"
2+
3+
#include <iostream>
4+
#include <iomanip>
5+
6+
namespace avtranscoder
7+
{
8+
9+
ConsoleProgress::~ConsoleProgress()
10+
{
11+
}
12+
13+
EJobStatus ConsoleProgress::progress( const double processedDuration, const double programDuration )
14+
{
15+
std::string progress( 80, '-' );
16+
std::string done( 80.0 * processedDuration / programDuration, '#' );
17+
progress.replace( 0, done.size(), done );
18+
19+
std::cout << std::setprecision(2) << std::fixed << "\r[" << progress << "] " << processedDuration << "/" << programDuration << std::flush;
20+
21+
// if( processedFrames >= 100 )
22+
// return avtranscoder::eJobStatusCancel;
23+
24+
return eJobStatusContinue;
25+
}
26+
27+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef _AV_TRANSCODER_CONSOLE_PROGRESS_HPP_
2+
#define _AV_TRANSCODER_CONSOLE_PROGRESS_HPP_
3+
4+
#include "IProgress.hpp"
5+
6+
namespace avtranscoder
7+
{
8+
9+
/**
10+
* @brief Implementation of IProgress, to display a progress bar in console.
11+
*/
12+
class ConsoleProgress : public IProgress
13+
{
14+
public:
15+
~ConsoleProgress();
16+
17+
EJobStatus progress( const double processedDuration, const double programDuration );
18+
};
19+
20+
}
21+
22+
#endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ifndef _AV_TRANSCODER_IPROGRESS_LISTENER_HPP_
2+
#define _AV_TRANSCODER_IPROGRESS_LISTENER_HPP_
3+
4+
#include <AvTranscoder/common.hpp>
5+
6+
#include <iostream>
7+
8+
namespace avtranscoder
9+
{
10+
11+
/**
12+
* @brief Indicate the state of a process.
13+
*/
14+
enum EJobStatus
15+
{
16+
eJobStatusContinue = 0,
17+
eJobStatusCancel
18+
};
19+
20+
/**
21+
* @brief Base class of Progress.
22+
* Inherit this class to have your own way to manage a progress bar.
23+
* You can inherit this class in C++, but also in python / Java binding.
24+
*/
25+
class IProgress
26+
{
27+
public:
28+
virtual ~IProgress() {};
29+
30+
/**
31+
* @brief Manage the progress.
32+
* @param processedDuration: what is processed
33+
* @param programDuration: what you need to process (the totality)
34+
* @return eJobStatusContinue if we continue the progress or eJobStatusCancel to stop it.
35+
*/
36+
virtual EJobStatus progress( const double processedDuration, const double programDuration ) = 0;
37+
};
38+
39+
}
40+
41+
#endif
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef _AV_TRANSCODER_NO_DISPLAY_PROGRESS_HPP_
2+
#define _AV_TRANSCODER_NO_DISPLAY_PROGRESS_HPP_
3+
4+
#include "IProgress.hpp"
5+
6+
namespace avtranscoder
7+
{
8+
9+
/**
10+
* @brief Implementation of IProgress, to manage cases when we need an IProgress but don't care of a progress bar.
11+
*/
12+
class NoDisplayProgress : public IProgress
13+
{
14+
public:
15+
~NoDisplayProgress()
16+
{}
17+
18+
EJobStatus progress( const double processedDuration, const double programDuration )
19+
{
20+
return eJobStatusContinue;
21+
}
22+
};
23+
24+
}
25+
26+
#endif

src/AvTranscoder/progress/progress.i

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
%module(directors="1") AvTranscoder
2+
3+
4+
%{
5+
#include <AvTranscoder/progress/IProgress.hpp>
6+
#include <AvTranscoder/progress/ConsoleProgress.hpp>
7+
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
8+
%}
9+
10+
/* turn on director wrapping for IProgress */
11+
%feature("director") IProgress;
12+
13+
%include <AvTranscoder/progress/IProgress.hpp>
14+
%include <AvTranscoder/progress/ConsoleProgress.hpp>
15+
%include <AvTranscoder/progress/NoDisplayProgress.hpp>

0 commit comments

Comments
 (0)