Skip to content

ProgressListener: clean #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/cpp/avMeta/avMeta.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <AvTranscoder/File/InputFile.hpp>
#include <AvTranscoder/Metadatas/Print.hpp>
#include <AvTranscoder/progress/NoDisplayProgress.hpp>

#include <iostream>

Expand All @@ -11,7 +12,7 @@ int main( int argc, char** argv )
return( -1 );
}

avtranscoder::ProgressListener p;
avtranscoder::NoDisplayProgress p;

avtranscoder::InputFile input( argv[1] );
input.analyse( p, avtranscoder::InputFile::eAnalyseLevelFull );
Expand Down
3 changes: 2 additions & 1 deletion app/cpp/avTranscoder/avTranscoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

Profile profile( true );
ProgressListener p;
ConsoleProgress p;

InputFile input( inputfilename );
input.analyse( p );
Expand Down
3 changes: 2 additions & 1 deletion app/cpp/avplay/AvReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <AvTranscoder/EssenceStream/InputVideo.hpp>
#include <AvTranscoder/EssenceTransform/VideoEssenceTransform.hpp>
#include <AvTranscoder/Metadatas/Print.hpp>
#include <AvTranscoder/progress/ConsoleProgress.hpp>

#include "Reader.hpp"

Expand All @@ -18,7 +19,7 @@ class AvReader : public Reader
, _sourceImage( NULL )
, _imageToDisplay( NULL )
{
avtranscoder::ProgressListener p;
avtranscoder::ConsoleProgress p;

_inputFile.analyse( p );
_videoStream = _inputFile.getProperties().videoStreams.at(0).streamId;
Expand Down
4 changes: 2 additions & 2 deletions app/cpp/genericProcessor/genericProcessor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#include <AvTranscoder/progress/ConsoleProgress.hpp>
#include <AvTranscoder/Transcoder/Transcoder.hpp>

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

avtranscoder::ProgressListener progress;
avtranscoder::ConsoleProgress progress;

// video re-wrapping or transcoding if necessary
transcoder.process( progress );
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/File/InputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ InputFile::~InputFile()
}
}

InputFile& InputFile::analyse( ProgressListener& progress, const EAnalyseLevel level )
InputFile& InputFile::analyse( IProgress& progress, const EAnalyseLevel level )
{
assert( _formatContext != NULL );

Expand Down Expand Up @@ -134,7 +134,7 @@ InputFile& InputFile::analyse( ProgressListener& progress, const EAnalyseLevel l
return *this;
}

Properties InputFile::analyseFile( const std::string& filename, ProgressListener& progress, const EAnalyseLevel level )
Properties InputFile::analyseFile( const std::string& filename, IProgress& progress, const EAnalyseLevel level )
{
InputFile file( filename );
file.analyse( progress, level );
Expand Down
6 changes: 3 additions & 3 deletions src/AvTranscoder/File/InputFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <AvTranscoder/CodedStream/AvInputStream.hpp>

#include <AvTranscoder/Metadatas/MediaMetadatasStructures.hpp>
#include <AvTranscoder/ProgressListener.hpp>
#include <AvTranscoder/progress/IProgress.hpp>

#include <AvTranscoder/Profile.hpp>

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

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

/**
* @brief Get stream type: video, audio, subtitle, etc.
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/Metadatas/VideoStreamProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void getGopProperties(
AVCodecContext* codecContext,
AVCodec* codec,
const int videoStreamIndex,
ProgressListener& progress
IProgress& progress
)
{
AVPacket pkt;
Expand Down Expand Up @@ -108,7 +108,7 @@ std::string makeTimecodeMpegToString( uint32_t tc25bit )
VideoProperties videoStreamInfo(
AVFormatContext* formatContext,
const size_t videoStreamIndex,
ProgressListener& progress,
IProgress& progress,
const InputFile::EAnalyseLevel level
)
{
Expand Down
42 changes: 0 additions & 42 deletions src/AvTranscoder/ProgressListener.hpp

This file was deleted.

11 changes: 0 additions & 11 deletions src/AvTranscoder/ProgressListener.i

This file was deleted.

4 changes: 3 additions & 1 deletion src/AvTranscoder/Transcoder/Transcoder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Transcoder.hpp"

#include <limits>
#include <iostream>

namespace avtranscoder
{
Expand Down Expand Up @@ -238,7 +240,7 @@ bool Transcoder::processFrame()
return true;
}

void Transcoder::process( ProgressListener& progress )
void Transcoder::process( IProgress& progress )
{
size_t frame = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/Transcoder/Transcoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <AvTranscoder/EssenceStream/DummyAudio.hpp>
#include <AvTranscoder/EssenceStream/DummyVideo.hpp>

#include <AvTranscoder/ProgressListener.hpp>
#include <AvTranscoder/progress/IProgress.hpp>

#include <AvTranscoder/Profile.hpp>

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

/**
* @brief Set the transcodage politic.
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/avTranscoder.i
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include <AvTranscoder/Transcoder/Transcoder.hpp>
%}

%include "AvTranscoder/ProgressListener.i"
%include "AvTranscoder/progress/progress.i"

namespace std {
%template(IntPair) pair< size_t, size_t >;
Expand Down
27 changes: 27 additions & 0 deletions src/AvTranscoder/progress/ConsoleProgress.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "ConsoleProgress.hpp"

#include <iostream>
#include <iomanip>

namespace avtranscoder
{

ConsoleProgress::~ConsoleProgress()
{
}

EJobStatus ConsoleProgress::progress( const double processedDuration, const double programDuration )
{
std::string progress( 80, '-' );
std::string done( 80.0 * processedDuration / programDuration, '#' );
progress.replace( 0, done.size(), done );

std::cout << std::setprecision(2) << std::fixed << "\r[" << progress << "] " << processedDuration << "/" << programDuration << std::flush;

// if( processedFrames >= 100 )
// return avtranscoder::eJobStatusCancel;

return eJobStatusContinue;
}

}
22 changes: 22 additions & 0 deletions src/AvTranscoder/progress/ConsoleProgress.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef _AV_TRANSCODER_CONSOLE_PROGRESS_HPP_
#define _AV_TRANSCODER_CONSOLE_PROGRESS_HPP_

#include "IProgress.hpp"

namespace avtranscoder
{

/**
* @brief Implementation of IProgress, to display a progress bar in console.
*/
class ConsoleProgress : public IProgress
{
public:
~ConsoleProgress();

EJobStatus progress( const double processedDuration, const double programDuration );
};

}

#endif
41 changes: 41 additions & 0 deletions src/AvTranscoder/progress/IProgress.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef _AV_TRANSCODER_IPROGRESS_LISTENER_HPP_
#define _AV_TRANSCODER_IPROGRESS_LISTENER_HPP_

#include <AvTranscoder/common.hpp>

#include <iostream>

namespace avtranscoder
{

/**
* @brief Indicate the state of a process.
*/
enum EJobStatus
{
eJobStatusContinue = 0,
eJobStatusCancel
};

/**
* @brief Base class of Progress.
* Inherit this class to have your own way to manage a progress bar.
* You can inherit this class in C++, but also in python / Java binding.
*/
class IProgress
{
public:
virtual ~IProgress() {};

/**
* @brief Manage the progress.
* @param processedDuration: what is processed
* @param programDuration: what you need to process (the totality)
* @return eJobStatusContinue if we continue the progress or eJobStatusCancel to stop it.
*/
virtual EJobStatus progress( const double processedDuration, const double programDuration ) = 0;
};

}

#endif
26 changes: 26 additions & 0 deletions src/AvTranscoder/progress/NoDisplayProgress.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef _AV_TRANSCODER_NO_DISPLAY_PROGRESS_HPP_
#define _AV_TRANSCODER_NO_DISPLAY_PROGRESS_HPP_

#include "IProgress.hpp"

namespace avtranscoder
{

/**
* @brief Implementation of IProgress, to manage cases when we need an IProgress but don't care of a progress bar.
*/
class NoDisplayProgress : public IProgress
{
public:
~NoDisplayProgress()
{}

EJobStatus progress( const double processedDuration, const double programDuration )
{
return eJobStatusContinue;
}
};

}

#endif
15 changes: 15 additions & 0 deletions src/AvTranscoder/progress/progress.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%module(directors="1") AvTranscoder


%{
#include <AvTranscoder/progress/IProgress.hpp>
#include <AvTranscoder/progress/ConsoleProgress.hpp>
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
%}

/* turn on director wrapping for IProgress */
%feature("director") IProgress;

%include <AvTranscoder/progress/IProgress.hpp>
%include <AvTranscoder/progress/ConsoleProgress.hpp>
%include <AvTranscoder/progress/NoDisplayProgress.hpp>