From 917de8dbe28f51eb8da39d9e55631aa66df60375 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Fri, 6 Jun 2014 12:12:48 +0200 Subject: [PATCH 01/24] InputStream and InputStreamAudio: refactoring --- src/AvTranscoder/InputStream.hpp | 5 ++--- src/AvTranscoder/InputStreamAudio.hpp | 3 --- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/AvTranscoder/InputStream.hpp b/src/AvTranscoder/InputStream.hpp index ba220303..8393e750 100644 --- a/src/AvTranscoder/InputStream.hpp +++ b/src/AvTranscoder/InputStream.hpp @@ -11,10 +11,9 @@ namespace avtranscoder class InputStream { public: - InputStream( ) - {} + InputStream() {} - virtual ~InputStream(){}; + virtual ~InputStream() {}; virtual size_t getStreamIndex() const = 0; diff --git a/src/AvTranscoder/InputStreamAudio.hpp b/src/AvTranscoder/InputStreamAudio.hpp index eec97ba6..10aebb31 100644 --- a/src/AvTranscoder/InputStreamAudio.hpp +++ b/src/AvTranscoder/InputStreamAudio.hpp @@ -24,9 +24,6 @@ class AvExport InputStreamAudio AVFrame* m_frame; int m_selectedStream; - -private: - }; } From c20f6e568b0469f401137c18f2106897d92fcb4e Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Fri, 6 Jun 2014 12:18:45 +0200 Subject: [PATCH 02/24] Add Option: wrap the AVOption of libav / ffmpeg * Add an abstract class "Option", and basic subclasses : "OptionInt", "OptionDouble", "OptionString". * Add "optionChecker" app, which parses AVOptions of a CodecContext and create an array of Options. * Update SConscripts to add "src/AvTranscoder/Options" folder, and compile "optionChecker" app with c++11 flag. --- app/SConscript | 14 +++ app/optionChecker/optionChecker.cpp | 124 ++++++++++++++++++++++ src/AvTranscoder/Option.cpp | 35 ++++++ src/AvTranscoder/Option.hpp | 51 +++++++++ src/AvTranscoder/Options/OptionDouble.cpp | 21 ++++ src/AvTranscoder/Options/OptionDouble.hpp | 35 ++++++ src/AvTranscoder/Options/OptionInt.cpp | 21 ++++ src/AvTranscoder/Options/OptionInt.hpp | 34 ++++++ src/AvTranscoder/Options/OptionString.cpp | 21 ++++ src/AvTranscoder/Options/OptionString.hpp | 36 +++++++ src/SConscript | 4 +- 11 files changed, 394 insertions(+), 2 deletions(-) create mode 100644 app/optionChecker/optionChecker.cpp create mode 100644 src/AvTranscoder/Option.cpp create mode 100644 src/AvTranscoder/Option.hpp create mode 100644 src/AvTranscoder/Options/OptionDouble.cpp create mode 100644 src/AvTranscoder/Options/OptionDouble.hpp create mode 100644 src/AvTranscoder/Options/OptionInt.cpp create mode 100644 src/AvTranscoder/Options/OptionInt.hpp create mode 100644 src/AvTranscoder/Options/OptionString.cpp create mode 100644 src/AvTranscoder/Options/OptionString.hpp diff --git a/app/SConscript b/app/SConscript index 8a36c3a6..e723839a 100644 --- a/app/SConscript +++ b/app/SConscript @@ -103,6 +103,20 @@ avprofiles = env.Program( ], ) +avprofiles = env.Program( + 'avoptions', + Glob( 'optionChecker/*.cpp' ), + LIBS = [ + sAvTranscoder, + 'avutil', + 'avformat', + 'avcodec' + ], + CXXFLAGS = [ + '-std=c++0x' + ], + ) + env.Depends( avmeta, sAvTranscoder ) env.Depends( audioRewrapper, sAvTranscoder ) diff --git a/app/optionChecker/optionChecker.cpp b/app/optionChecker/optionChecker.cpp new file mode 100644 index 00000000..5688f1b4 --- /dev/null +++ b/app/optionChecker/optionChecker.cpp @@ -0,0 +1,124 @@ +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +int optionChecker( const std::string& inputfilename ) +{ + avtranscoder::InputFile inputFile( inputfilename ); + inputFile.analyse(); + + avtranscoder::AudioDesc audioDesc( inputFile.getStream( 0 ).getAudioDesc() ); + + std::vector options; + try + { + const AVOption* avOption = NULL; + + while( ( avOption = av_opt_next( audioDesc.getCodecContext(), avOption ) ) != NULL ) + { + std::cout << "The option is " << avOption->name; + std::cout << " of type : " << avOption->type << std::endl; + + avtranscoder::Option* opt = NULL; + + switch( avOption->type ) + { + case AV_OPT_TYPE_INT: + case AV_OPT_TYPE_INT64: + { + opt = new avtranscoder::OptionInt( *avOption ); + break; + } + case AV_OPT_TYPE_DOUBLE: + { + opt = new avtranscoder::OptionDouble( *avOption ); + break; + } + case AV_OPT_TYPE_STRING: + { + opt = new avtranscoder::OptionString( *avOption ); + break; + } + } + + if( opt ) + options.push_back( opt ); + } + } + catch( std::exception &e ) + { + for( auto it = options.begin(); it != options.end(); ++it) + { + delete *it; + } + options.clear(); + + throw e; + } + + for( auto option : options ) + { + std::cout << std::left; + std::cout << "****************************" << std::endl; + std::cout << std::setw(30) << option->getName(); + std::cout << ": " << option->getHelp() << std::endl; + std::cout << "Type: " << option->getType() << std::endl; + + // get default value + int valueInt; + double valueDouble; + std::string valueStr; + + switch( option->getType() ) + { + case AV_OPT_TYPE_INT: + case AV_OPT_TYPE_INT64: + { + std::cout << "DefaultValue: " << option->getDefaultValue( valueInt ) << std::endl; + break; + } + case AV_OPT_TYPE_DOUBLE: + { + std::cout << "DefaultValue: " << option->getDefaultValue( valueDouble ) << std::endl; + break; + } + case AV_OPT_TYPE_STRING: + { + std::cout << "DefaultValue: " << option->getDefaultValue( valueStr ) << std::endl; + break; + } + } + } + +} + +int main( int argc, char** argv ) +{ + if( argc <= 1 ) + { + std::cout << "audiorewrapper require a media filename" << std::endl; + std::cout << "example: audioWrap file.ext" << std::endl; + return( -1 ); + } + + std::cout << "start ..." << std::endl; + + try + { + optionChecker( argv[1] ); + } + catch( std::exception &e ) + { + std::cout << "[ERROR] " << e.what() << std::endl; + } + + std::cout << "end ..." << std::endl; +} \ No newline at end of file diff --git a/src/AvTranscoder/Option.cpp b/src/AvTranscoder/Option.cpp new file mode 100644 index 00000000..97d27414 --- /dev/null +++ b/src/AvTranscoder/Option.cpp @@ -0,0 +1,35 @@ +#include "Option.hpp" + +#include + +namespace avtranscoder +{ + +Option::Option( const AVOption& avOption ) + : m_name ( avOption.name ) + , m_help ( avOption.help ? avOption.help : "" ) + , m_flags( avOption.flags ) +{ +} + +int Option::getDefaultValue( int& value ) const +{ + throw std::runtime_error( "Wrong access to int getDefaultValue" ); +} + +int64_t Option::getDefaultValue( int64_t& value ) const +{ + throw std::runtime_error( "Wrong access to int64_t getDefaultValue" ); +} + +double Option::getDefaultValue( double& value ) const +{ + throw std::runtime_error( "Wrong access to double getDefaultValue" ); +} + +std::string& Option::getDefaultValue( std::string& value ) +{ + throw std::runtime_error( "Wrong access to char* getDefaultValue" ); +} + +} diff --git a/src/AvTranscoder/Option.hpp b/src/AvTranscoder/Option.hpp new file mode 100644 index 00000000..688e25d4 --- /dev/null +++ b/src/AvTranscoder/Option.hpp @@ -0,0 +1,51 @@ +#ifndef _AV_TRANSCODER_OPTION_HPP +#define _AV_TRANSCODER_OPTION_HPP + +extern "C" { +#ifndef __STDC_CONSTANT_MACROS + #define __STDC_CONSTANT_MACROS +#endif +#include +} + +#include +#include + +namespace avtranscoder +{ + +/** + * @breif Abstract class to manage AVOption. + * Subclasses implement specific AVOption: int, boolean... + */ +class Option +{ +public: + Option( const AVOption& avOption ); + virtual ~Option() {} + + virtual AVOptionType getType() const = 0; + + virtual int getDefaultValue( int& value ) const; + virtual int64_t getDefaultValue( int64_t& value ) const; + virtual double getDefaultValue( double& value ) const; + virtual std::string& getDefaultValue( std::string& value ); + + std::string& getName() { return m_name; } + std::string& getHelp() { return m_help; } + + bool isEncodingOpt(){ return m_flags & AV_OPT_FLAG_ENCODING_PARAM; } + bool isDecodingOpt(){ return m_flags & AV_OPT_FLAG_DECODING_PARAM; } + bool isAudioOpt(){ return m_flags & AV_OPT_FLAG_AUDIO_PARAM; } + bool isVideoOpt(){ return m_flags & AV_OPT_FLAG_VIDEO_PARAM; } + bool isSubtitleOpt(){ return m_flags & AV_OPT_FLAG_SUBTITLE_PARAM; } + +protected: + std::string m_name; + std::string m_help; + int m_flags; +}; + +} + +#endif diff --git a/src/AvTranscoder/Options/OptionDouble.cpp b/src/AvTranscoder/Options/OptionDouble.cpp new file mode 100644 index 00000000..b736c1a5 --- /dev/null +++ b/src/AvTranscoder/Options/OptionDouble.cpp @@ -0,0 +1,21 @@ +#include "OptionDouble.hpp" + + +namespace avtranscoder +{ + +OptionDouble::OptionDouble( const AVOption& avOption ) + : Option( avOption ) + , m_defaultValue( avOption.default_val.dbl ) + , m_minValue( avOption.min ) + , m_maxValue( avOption.max ) +{ + +} + +OptionDouble::~OptionDouble() +{ + +} + +} diff --git a/src/AvTranscoder/Options/OptionDouble.hpp b/src/AvTranscoder/Options/OptionDouble.hpp new file mode 100644 index 00000000..144fdc93 --- /dev/null +++ b/src/AvTranscoder/Options/OptionDouble.hpp @@ -0,0 +1,35 @@ +#ifndef _AV_TRANSCODER_OPTION_DOUBLE_HPP +#define _AV_TRANSCODER_OPTION_DOUBLE_HPP + +#include + +extern "C" { +#ifndef __STDC_CONSTANT_MACROS + #define __STDC_CONSTANT_MACROS +#endif +#include +} + +namespace avtranscoder +{ + +class OptionDouble : public Option +{ +public: + OptionDouble( const AVOption& avOption ); + + ~OptionDouble(); + + AVOptionType getType() const { return AV_OPT_TYPE_DOUBLE; } + double getDefaultValue( double &defaultValue ) const { return defaultValue = m_defaultValue; } + +private: + double m_defaultValue; + double m_minValue; + double m_maxValue; + +}; + +} + +#endif \ No newline at end of file diff --git a/src/AvTranscoder/Options/OptionInt.cpp b/src/AvTranscoder/Options/OptionInt.cpp new file mode 100644 index 00000000..498e7147 --- /dev/null +++ b/src/AvTranscoder/Options/OptionInt.cpp @@ -0,0 +1,21 @@ +#include "OptionInt.hpp" + + +namespace avtranscoder +{ + +OptionInt::OptionInt( const AVOption& avOption ) + : Option( avOption ) + , m_defaultValue( avOption.default_val.i64 ) + , m_minValue( avOption.min ) + , m_maxValue( avOption.max ) +{ + +} + +OptionInt::~OptionInt() +{ + +} + +} diff --git a/src/AvTranscoder/Options/OptionInt.hpp b/src/AvTranscoder/Options/OptionInt.hpp new file mode 100644 index 00000000..ac42000f --- /dev/null +++ b/src/AvTranscoder/Options/OptionInt.hpp @@ -0,0 +1,34 @@ +#ifndef _AV_TRANSCODER_OPTION_INT_HPP +#define _AV_TRANSCODER_OPTION_INT_HPP + +#include + +extern "C" { +#ifndef __STDC_CONSTANT_MACROS + #define __STDC_CONSTANT_MACROS +#endif +#include +} + +namespace avtranscoder +{ + +class OptionInt : public Option +{ +public: + OptionInt( const AVOption& avOption ); + + ~OptionInt(); + + AVOptionType getType() const { return AV_OPT_TYPE_INT; } + int getDefaultValue( int& defaultValue ) const { return defaultValue = m_defaultValue; } + +private: + int m_defaultValue; + double m_minValue; + double m_maxValue; +}; + +} + +#endif diff --git a/src/AvTranscoder/Options/OptionString.cpp b/src/AvTranscoder/Options/OptionString.cpp new file mode 100644 index 00000000..cbafeb22 --- /dev/null +++ b/src/AvTranscoder/Options/OptionString.cpp @@ -0,0 +1,21 @@ +#include "OptionString.hpp" + + +namespace avtranscoder +{ + +OptionString::OptionString( const AVOption& avOption ) + : Option( avOption ) + , m_defaultValue( avOption.default_val.str ? avOption.default_val.str : "" ) + , m_minValue( avOption.min ) + , m_maxValue( avOption.max ) +{ + +} + +OptionString::~OptionString() +{ + +} + +} diff --git a/src/AvTranscoder/Options/OptionString.hpp b/src/AvTranscoder/Options/OptionString.hpp new file mode 100644 index 00000000..b2b178b2 --- /dev/null +++ b/src/AvTranscoder/Options/OptionString.hpp @@ -0,0 +1,36 @@ +#ifndef _AV_TRANSCODER_OPTION_STRING_HPP +#define _AV_TRANSCODER_OPTION_STRING_HPP + +#include + +extern "C" { +#ifndef __STDC_CONSTANT_MACROS + #define __STDC_CONSTANT_MACROS +#endif +#include +} + +#include + +namespace avtranscoder +{ + +class OptionString : public Option +{ +public: + OptionString( const AVOption& avOption ); + + ~OptionString(); + + AVOptionType getType() const { return AV_OPT_TYPE_STRING; } + std::string& getDefaultValue( std::string& defaultValue ) { return defaultValue = m_defaultValue; } + +private: + std::string m_defaultValue; + double m_minValue; + double m_maxValue; +}; + +} + +#endif diff --git a/src/SConscript b/src/SConscript index db147a3c..87d03bf4 100644 --- a/src/SConscript +++ b/src/SConscript @@ -14,7 +14,7 @@ env.Append( sAvTranscoder = env.StaticLibrary( 'sAvTranscoder', - Glob( 'AvTranscoder/*.cpp' ) + Glob( 'AvTranscoder/DatasStructures/*.cpp' ) , + Glob( 'AvTranscoder/*.cpp' ) + Glob( 'AvTranscoder/DatasStructures/*.cpp' ) + Glob( 'AvTranscoder/Options/*.cpp' ), LIBS = [ 'libavutil', 'libavcodec', @@ -26,7 +26,7 @@ sAvTranscoder = env.StaticLibrary( SharedAvTranscoder = env.SharedLibrary( 'AvTranscoder', - Glob( 'AvTranscoder/*.cpp' ) + Glob( 'AvTranscoder/DatasStructures/*.cpp' ) , + Glob( 'AvTranscoder/*.cpp' ) + Glob( 'AvTranscoder/DatasStructures/*.cpp' ) + Glob( 'AvTranscoder/Options/*.cpp' ), LIBS = [ 'libavutil', 'libavcodec', From 806ee1ea58cffe37960311cc056f1c477c724fd9 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Fri, 6 Jun 2014 13:54:45 +0200 Subject: [PATCH 03/24] Option: add OptionBoolean * Corresponding to AV_OPT_TYPE_FLAGS in libav / ffmpeg. * Manage AV_OPT_TYPE_FLOAT and AV_OPT_TYPE_DOUBLE by the same way : create "OptionDouble". * Add const to the getDefaultValue function of "OptionString". --- app/optionChecker/optionChecker.cpp | 8 +++++ src/AvTranscoder/Option.cpp | 14 ++++----- src/AvTranscoder/Option.hpp | 4 +-- src/AvTranscoder/Options/OptionBoolean.cpp | 21 +++++++++++++ src/AvTranscoder/Options/OptionBoolean.hpp | 34 ++++++++++++++++++++++ src/AvTranscoder/Options/OptionString.hpp | 2 +- 6 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 src/AvTranscoder/Options/OptionBoolean.cpp create mode 100644 src/AvTranscoder/Options/OptionBoolean.hpp diff --git a/app/optionChecker/optionChecker.cpp b/app/optionChecker/optionChecker.cpp index 5688f1b4..345ac0cf 100644 --- a/app/optionChecker/optionChecker.cpp +++ b/app/optionChecker/optionChecker.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -37,6 +38,7 @@ int optionChecker( const std::string& inputfilename ) opt = new avtranscoder::OptionInt( *avOption ); break; } + case AV_OPT_TYPE_FLOAT: case AV_OPT_TYPE_DOUBLE: { opt = new avtranscoder::OptionDouble( *avOption ); @@ -47,6 +49,11 @@ int optionChecker( const std::string& inputfilename ) opt = new avtranscoder::OptionString( *avOption ); break; } + case AV_OPT_TYPE_FLAGS: + { + opt = new avtranscoder::OptionBoolean( *avOption ); + break; + } } if( opt ) @@ -85,6 +92,7 @@ int optionChecker( const std::string& inputfilename ) std::cout << "DefaultValue: " << option->getDefaultValue( valueInt ) << std::endl; break; } + case AV_OPT_TYPE_FLOAT: case AV_OPT_TYPE_DOUBLE: { std::cout << "DefaultValue: " << option->getDefaultValue( valueDouble ) << std::endl; diff --git a/src/AvTranscoder/Option.cpp b/src/AvTranscoder/Option.cpp index 97d27414..52d6b008 100644 --- a/src/AvTranscoder/Option.cpp +++ b/src/AvTranscoder/Option.cpp @@ -14,22 +14,22 @@ Option::Option( const AVOption& avOption ) int Option::getDefaultValue( int& value ) const { - throw std::runtime_error( "Wrong access to int getDefaultValue" ); + throw std::runtime_error( "Wrong access to getDefaultValue (int)." ); } -int64_t Option::getDefaultValue( int64_t& value ) const +double Option::getDefaultValue( double& value ) const { - throw std::runtime_error( "Wrong access to int64_t getDefaultValue" ); + throw std::runtime_error( "Wrong access to getDefaultValue (double)." ); } -double Option::getDefaultValue( double& value ) const +std::string& Option::getDefaultValue( std::string& value ) const { - throw std::runtime_error( "Wrong access to double getDefaultValue" ); + throw std::runtime_error( "Wrong access to getDefaultValue (char*)." ); } -std::string& Option::getDefaultValue( std::string& value ) +bool Option::getDefaultValue( bool& value ) const { - throw std::runtime_error( "Wrong access to char* getDefaultValue" ); + throw std::runtime_error( "Wrong access to getDefaultValue (bool)." ); } } diff --git a/src/AvTranscoder/Option.hpp b/src/AvTranscoder/Option.hpp index 688e25d4..88c77b01 100644 --- a/src/AvTranscoder/Option.hpp +++ b/src/AvTranscoder/Option.hpp @@ -27,9 +27,9 @@ class Option virtual AVOptionType getType() const = 0; virtual int getDefaultValue( int& value ) const; - virtual int64_t getDefaultValue( int64_t& value ) const; virtual double getDefaultValue( double& value ) const; - virtual std::string& getDefaultValue( std::string& value ); + virtual std::string& getDefaultValue( std::string& value ) const; + virtual bool getDefaultValue( bool& value ) const; std::string& getName() { return m_name; } std::string& getHelp() { return m_help; } diff --git a/src/AvTranscoder/Options/OptionBoolean.cpp b/src/AvTranscoder/Options/OptionBoolean.cpp new file mode 100644 index 00000000..3cb8ccc0 --- /dev/null +++ b/src/AvTranscoder/Options/OptionBoolean.cpp @@ -0,0 +1,21 @@ +#include "OptionBoolean.hpp" + + +namespace avtranscoder +{ + +OptionBoolean::OptionBoolean( const AVOption& avOption ) + : Option( avOption ) + , m_defaultValue( (bool)avOption.default_val.i64 ) + , m_minValue( avOption.min ) + , m_maxValue( avOption.max ) +{ + +} + +OptionBoolean::~OptionBoolean() +{ + +} + +} diff --git a/src/AvTranscoder/Options/OptionBoolean.hpp b/src/AvTranscoder/Options/OptionBoolean.hpp new file mode 100644 index 00000000..a907f249 --- /dev/null +++ b/src/AvTranscoder/Options/OptionBoolean.hpp @@ -0,0 +1,34 @@ +#ifndef _AV_TRANSCODER_OPTION_BOOLEAN_HPP +#define _AV_TRANSCODER_OPTION_BOOLEAN_HPP + +#include + +extern "C" { +#ifndef __STDC_CONSTANT_MACROS + #define __STDC_CONSTANT_MACROS +#endif +#include +} + +namespace avtranscoder +{ + +class OptionBoolean : public Option +{ +public: + OptionBoolean( const AVOption& avOption ); + + ~OptionBoolean(); + + AVOptionType getType() const { return AV_OPT_TYPE_FLAGS; } + bool getDefaultValue( bool& defaultValue ) const { return defaultValue = m_defaultValue; } + +private: + bool m_defaultValue; + double m_minValue; + double m_maxValue; +}; + +} + +#endif diff --git a/src/AvTranscoder/Options/OptionString.hpp b/src/AvTranscoder/Options/OptionString.hpp index b2b178b2..97f313e1 100644 --- a/src/AvTranscoder/Options/OptionString.hpp +++ b/src/AvTranscoder/Options/OptionString.hpp @@ -23,7 +23,7 @@ class OptionString : public Option ~OptionString(); AVOptionType getType() const { return AV_OPT_TYPE_STRING; } - std::string& getDefaultValue( std::string& defaultValue ) { return defaultValue = m_defaultValue; } + std::string& getDefaultValue( std::string& defaultValue ) const { return defaultValue = m_defaultValue; } private: std::string m_defaultValue; From df26c04655401f7a5e60831a61dcb5beaedb17dc Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Fri, 6 Jun 2014 14:24:36 +0200 Subject: [PATCH 04/24] Option: add OptionBoolean * Corresponding to AV_OPT_TYPE_RATIONAL in libav / ffmpeg. * Create a struct Value2D to get the defaultValue of this option by one call of getDefaultValue (which returns a Value2D). --- app/optionChecker/optionChecker.cpp | 19 +++++++++ src/AvTranscoder/Option.cpp | 5 +++ src/AvTranscoder/Option.hpp | 3 ++ src/AvTranscoder/Options/Option2D.cpp | 21 ++++++++++ src/AvTranscoder/Options/Option2D.hpp | 56 +++++++++++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 src/AvTranscoder/Options/Option2D.cpp create mode 100644 src/AvTranscoder/Options/Option2D.hpp diff --git a/app/optionChecker/optionChecker.cpp b/app/optionChecker/optionChecker.cpp index 345ac0cf..78042674 100644 --- a/app/optionChecker/optionChecker.cpp +++ b/app/optionChecker/optionChecker.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,11 @@ int optionChecker( const std::string& inputfilename ) opt = new avtranscoder::OptionBoolean( *avOption ); break; } + case AV_OPT_TYPE_RATIONAL: + { + opt = new avtranscoder::Option2D( *avOption ); + break; + } } if( opt ) @@ -83,6 +89,8 @@ int optionChecker( const std::string& inputfilename ) int valueInt; double valueDouble; std::string valueStr; + bool valueBool; + avtranscoder::Value2D value2D; switch( option->getType() ) { @@ -103,6 +111,17 @@ int optionChecker( const std::string& inputfilename ) std::cout << "DefaultValue: " << option->getDefaultValue( valueStr ) << std::endl; break; } + case AV_OPT_TYPE_FLAGS: + { + std::cout << "DefaultValue: " << option->getDefaultValue( valueBool ) << std::endl; + break; + } + case AV_OPT_TYPE_RATIONAL: + { + option->getDefaultValue( value2D ); + std::cout << "DefaultValue: " << value2D.num << ", " << value2D.dem << std::endl; + break; + } } } diff --git a/src/AvTranscoder/Option.cpp b/src/AvTranscoder/Option.cpp index 52d6b008..ff565299 100644 --- a/src/AvTranscoder/Option.cpp +++ b/src/AvTranscoder/Option.cpp @@ -32,4 +32,9 @@ bool Option::getDefaultValue( bool& value ) const throw std::runtime_error( "Wrong access to getDefaultValue (bool)." ); } +Value2D& Option::getDefaultValue( Value2D& value ) const +{ + throw std::runtime_error( "Wrong access to getDefaultValue (Value2D)." ); +} + } diff --git a/src/AvTranscoder/Option.hpp b/src/AvTranscoder/Option.hpp index 88c77b01..78d4e156 100644 --- a/src/AvTranscoder/Option.hpp +++ b/src/AvTranscoder/Option.hpp @@ -14,6 +14,8 @@ extern "C" { namespace avtranscoder { +class Value2D; + /** * @breif Abstract class to manage AVOption. * Subclasses implement specific AVOption: int, boolean... @@ -30,6 +32,7 @@ class Option virtual double getDefaultValue( double& value ) const; virtual std::string& getDefaultValue( std::string& value ) const; virtual bool getDefaultValue( bool& value ) const; + virtual Value2D& getDefaultValue( Value2D& value ) const; std::string& getName() { return m_name; } std::string& getHelp() { return m_help; } diff --git a/src/AvTranscoder/Options/Option2D.cpp b/src/AvTranscoder/Options/Option2D.cpp new file mode 100644 index 00000000..04c05078 --- /dev/null +++ b/src/AvTranscoder/Options/Option2D.cpp @@ -0,0 +1,21 @@ +#include "Option2D.hpp" + + +namespace avtranscoder +{ + +Option2D::Option2D( const AVOption& avOption ) + : Option( avOption ) + , m_defaultValue( avOption.default_val.q.num, avOption.default_val.q.den ) + , m_minValue( avOption.min ) + , m_maxValue( avOption.max ) +{ + +} + +Option2D::~Option2D() +{ + +} + +} diff --git a/src/AvTranscoder/Options/Option2D.hpp b/src/AvTranscoder/Options/Option2D.hpp new file mode 100644 index 00000000..7c549dc0 --- /dev/null +++ b/src/AvTranscoder/Options/Option2D.hpp @@ -0,0 +1,56 @@ +#ifndef _AV_TRANSCODER_OPTION_2D_HPP +#define _AV_TRANSCODER_OPTION_2D_HPP + +#include + +extern "C" { +#ifndef __STDC_CONSTANT_MACROS + #define __STDC_CONSTANT_MACROS +#endif +#include +} + +namespace avtranscoder +{ + +/** + * @brief Object return by getDefaultValue of Option2D. + */ +struct Value2D +{ + Value2D() + : num( 0 ) + , dem( 0 ) + {} + + Value2D( int numValue, int demValue ) + : num( numValue ) + , dem( demValue ) + {} + + int num; + int dem; +}; + +/** + * @brief Wrap of AVOption with a type of AV_OPT_TYPE_RATIONAL. + */ +class Option2D : public Option +{ +public: + Option2D( const AVOption& avOption ); + + ~Option2D(); + + AVOptionType getType() const { return AV_OPT_TYPE_RATIONAL; } + Value2D& getDefaultValue( Value2D& defaultValue ) const { return defaultValue = m_defaultValue; } + +private: + Value2D m_defaultValue; + double m_minValue; + double m_maxValue; +}; + +} + +#endif From f27a034261b01bbaf9dcc41ceca63b98dad108c2 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Fri, 6 Jun 2014 14:26:37 +0200 Subject: [PATCH 05/24] Option: add comments --- src/AvTranscoder/Option.hpp | 4 ++-- src/AvTranscoder/Options/OptionBoolean.hpp | 3 +++ src/AvTranscoder/Options/OptionDouble.hpp | 3 +++ src/AvTranscoder/Options/OptionInt.hpp | 3 +++ src/AvTranscoder/Options/OptionString.hpp | 3 +++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/AvTranscoder/Option.hpp b/src/AvTranscoder/Option.hpp index 78d4e156..368455a6 100644 --- a/src/AvTranscoder/Option.hpp +++ b/src/AvTranscoder/Option.hpp @@ -17,8 +17,8 @@ namespace avtranscoder class Value2D; /** - * @breif Abstract class to manage AVOption. - * Subclasses implement specific AVOption: int, boolean... + * @breif Abstract class to wrap AVOption. + * Subclasses implement specific AVOption: int, boolean... */ class Option { diff --git a/src/AvTranscoder/Options/OptionBoolean.hpp b/src/AvTranscoder/Options/OptionBoolean.hpp index a907f249..456f0534 100644 --- a/src/AvTranscoder/Options/OptionBoolean.hpp +++ b/src/AvTranscoder/Options/OptionBoolean.hpp @@ -13,6 +13,9 @@ extern "C" { namespace avtranscoder { +/** + * @brief Wrap of AVOption with a type of AV_OPT_TYPE_FLAGS. + */ class OptionBoolean : public Option { public: diff --git a/src/AvTranscoder/Options/OptionDouble.hpp b/src/AvTranscoder/Options/OptionDouble.hpp index 144fdc93..d50581a6 100644 --- a/src/AvTranscoder/Options/OptionDouble.hpp +++ b/src/AvTranscoder/Options/OptionDouble.hpp @@ -13,6 +13,9 @@ extern "C" { namespace avtranscoder { +/** + * @brief Wrap of AVOption with a type of AV_OPT_TYPE_DOUBLE. + */ class OptionDouble : public Option { public: diff --git a/src/AvTranscoder/Options/OptionInt.hpp b/src/AvTranscoder/Options/OptionInt.hpp index ac42000f..a7bf51ed 100644 --- a/src/AvTranscoder/Options/OptionInt.hpp +++ b/src/AvTranscoder/Options/OptionInt.hpp @@ -13,6 +13,9 @@ extern "C" { namespace avtranscoder { +/** + * @brief Wrap of AVOption with a type of AV_OPT_TYPE_INT. + */ class OptionInt : public Option { public: diff --git a/src/AvTranscoder/Options/OptionString.hpp b/src/AvTranscoder/Options/OptionString.hpp index 97f313e1..d611c9c2 100644 --- a/src/AvTranscoder/Options/OptionString.hpp +++ b/src/AvTranscoder/Options/OptionString.hpp @@ -15,6 +15,9 @@ extern "C" { namespace avtranscoder { +/** + * @brief Wrap of AVOption with a type of AV_OPT_TYPE_STRING. + */ class OptionString : public Option { public: From 42799deaaea3a7e85901cdf1bf555148232b661e Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Fri, 6 Jun 2014 15:02:34 +0200 Subject: [PATCH 06/24] Option: add OptionGroup * Corresponding to AV_OPT_TYPE_FLAGS with unit informed in libav / ffmpeg. * Update optionChecker to create OptionGroup, and continue to parse if meet unknowed AVOption type. * Update comments of OptionBoolean. --- app/optionChecker/optionChecker.cpp | 57 +++++++++++++++++----- src/AvTranscoder/Options/OptionBoolean.hpp | 2 +- src/AvTranscoder/Options/OptionGroup.cpp | 21 ++++++++ src/AvTranscoder/Options/OptionGroup.hpp | 37 ++++++++++++++ 4 files changed, 105 insertions(+), 12 deletions(-) create mode 100644 src/AvTranscoder/Options/OptionGroup.cpp create mode 100644 src/AvTranscoder/Options/OptionGroup.hpp diff --git a/app/optionChecker/optionChecker.cpp b/app/optionChecker/optionChecker.cpp index 78042674..ac6ff803 100644 --- a/app/optionChecker/optionChecker.cpp +++ b/app/optionChecker/optionChecker.cpp @@ -6,9 +6,11 @@ #include #include #include +#include #include #include +#include #include #include @@ -23,24 +25,46 @@ int optionChecker( const std::string& inputfilename ) try { const AVOption* avOption = NULL; - + while( ( avOption = av_opt_next( audioDesc.getCodecContext(), avOption ) ) != NULL ) { - std::cout << "The option is " << avOption->name; - std::cout << " of type : " << avOption->type << std::endl; - avtranscoder::Option* opt = NULL; + if( !avOption || ! avOption->name ) + { + continue; + } + + std::cout << "The option is " << avOption->name << " of type : " << avOption->type << std::endl; + + if( avOption->unit && avOption->type == AV_OPT_TYPE_FLAGS ) + { + opt = new avtranscoder::OptionGroup( *avOption ); + options.push_back( opt ); + continue; + } + if( avOption->unit && avOption->type == AV_OPT_TYPE_INT ) + { + // OptionChoice + //options.push_back( opt ); + continue; + } + switch( avOption->type ) { + case AV_OPT_TYPE_FLAGS: + { + opt = new avtranscoder::OptionBoolean( *avOption ); + break; + } case AV_OPT_TYPE_INT: case AV_OPT_TYPE_INT64: { opt = new avtranscoder::OptionInt( *avOption ); break; } - case AV_OPT_TYPE_FLOAT: case AV_OPT_TYPE_DOUBLE: + case AV_OPT_TYPE_FLOAT: { opt = new avtranscoder::OptionDouble( *avOption ); break; @@ -50,18 +74,26 @@ int optionChecker( const std::string& inputfilename ) opt = new avtranscoder::OptionString( *avOption ); break; } - case AV_OPT_TYPE_FLAGS: + case AV_OPT_TYPE_RATIONAL: { - opt = new avtranscoder::OptionBoolean( *avOption ); + opt = new avtranscoder::Option2D( *avOption ); break; } - case AV_OPT_TYPE_RATIONAL: + case AV_OPT_TYPE_BINARY: + { + //opt = new avtranscoder::OptionString( *avOption ); + break; + } + case AV_OPT_TYPE_CONST: { - opt = new avtranscoder::Option2D( *avOption ); break; } + default: + { + //throw std::runtime_error( "undefined type for " + std::string( avOption->name ) ); + std::cout << "----- Unknowed type for " << avOption->name << "-----" << std::endl; + } } - if( opt ) options.push_back( opt ); } @@ -113,7 +145,10 @@ int optionChecker( const std::string& inputfilename ) } case AV_OPT_TYPE_FLAGS: { - std::cout << "DefaultValue: " << option->getDefaultValue( valueBool ) << std::endl; + if( option->getName().substr(0, 2) == "g_" ) // OptionGroup + std::cout << "DefaultValue: " << option->getDefaultValue( valueInt ) << std::endl; + else // OptionBoolean + std::cout << "DefaultValue: " << option->getDefaultValue( valueBool ) << std::endl; break; } case AV_OPT_TYPE_RATIONAL: diff --git a/src/AvTranscoder/Options/OptionBoolean.hpp b/src/AvTranscoder/Options/OptionBoolean.hpp index 456f0534..38e66192 100644 --- a/src/AvTranscoder/Options/OptionBoolean.hpp +++ b/src/AvTranscoder/Options/OptionBoolean.hpp @@ -14,7 +14,7 @@ namespace avtranscoder { /** - * @brief Wrap of AVOption with a type of AV_OPT_TYPE_FLAGS. + * @brief Wrap of AVOption with a type of AV_OPT_TYPE_FLAGS and no unit informed.. */ class OptionBoolean : public Option { diff --git a/src/AvTranscoder/Options/OptionGroup.cpp b/src/AvTranscoder/Options/OptionGroup.cpp new file mode 100644 index 00000000..b0285723 --- /dev/null +++ b/src/AvTranscoder/Options/OptionGroup.cpp @@ -0,0 +1,21 @@ +#include "OptionGroup.hpp" + + +namespace avtranscoder +{ + +OptionGroup::OptionGroup( const AVOption& avOption ) + : Option( avOption ) + , m_defaultValue( avOption.default_val.i64 ) +{ + std::string name = "g_"; + name += avOption.unit; + m_name = name; +} + +OptionGroup::~OptionGroup() +{ + +} + +} diff --git a/src/AvTranscoder/Options/OptionGroup.hpp b/src/AvTranscoder/Options/OptionGroup.hpp new file mode 100644 index 00000000..77cec68f --- /dev/null +++ b/src/AvTranscoder/Options/OptionGroup.hpp @@ -0,0 +1,37 @@ +#ifndef _AV_TRANSCODER_OPTION_GROUP_HPP +#define _AV_TRANSCODER_OPTION_GROUP_HPP + +#include + +extern "C" { +#ifndef __STDC_CONSTANT_MACROS + #define __STDC_CONSTANT_MACROS +#endif +#include +} + +namespace avtranscoder +{ + +/** + * @brief Wrap of AVOption with a type of AV_OPT_TYPE_FLAGS and unit informed. + */ +class OptionGroup : public Option +{ +public: + OptionGroup( const AVOption& avOption ); + + ~OptionGroup(); + + AVOptionType getType() const { return AV_OPT_TYPE_FLAGS; } + int getDefaultValue( int& defaultValue ) const { return defaultValue = m_defaultValue; } + +private: + int m_defaultValue; + double m_minValue; + double m_maxValue; +}; + +} + +#endif From 4be2b691d927eba88c5807f2796882cf0530fd56 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Fri, 6 Jun 2014 16:50:26 +0200 Subject: [PATCH 07/24] Option: add OptionChoice * Corresponding to AV_OPT_TYPE_INT with unit informed in libav / ffmpeg. * Update optionChecker to create OptionChoice, add list of choices to them, and set their default choice. * Option: add unit attribut. * Subclasses Option: update getType function to return a string instead of an enum defined in libav / ffmpeg (AVOptionType). --- app/optionChecker/optionChecker.cpp | 115 ++++++++++++++------- src/AvTranscoder/Option.cpp | 1 + src/AvTranscoder/Option.hpp | 5 +- src/AvTranscoder/Options/Option2D.hpp | 2 +- src/AvTranscoder/Options/OptionBoolean.hpp | 2 +- src/AvTranscoder/Options/OptionChoice.cpp | 33 ++++++ src/AvTranscoder/Options/OptionChoice.hpp | 52 ++++++++++ src/AvTranscoder/Options/OptionDouble.hpp | 4 +- src/AvTranscoder/Options/OptionGroup.hpp | 2 +- src/AvTranscoder/Options/OptionInt.hpp | 2 +- src/AvTranscoder/Options/OptionString.hpp | 2 +- 11 files changed, 176 insertions(+), 44 deletions(-) create mode 100644 src/AvTranscoder/Options/OptionChoice.cpp create mode 100644 src/AvTranscoder/Options/OptionChoice.hpp diff --git a/app/optionChecker/optionChecker.cpp b/app/optionChecker/optionChecker.cpp index ac6ff803..d2806c10 100644 --- a/app/optionChecker/optionChecker.cpp +++ b/app/optionChecker/optionChecker.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -22,6 +23,7 @@ int optionChecker( const std::string& inputfilename ) avtranscoder::AudioDesc audioDesc( inputFile.getStream( 0 ).getAudioDesc() ); std::vector options; + std::vector optionsChoice; // need to access easely to the OptionChoice to add the list of value for each of them try { const AVOption* avOption = NULL; @@ -45,8 +47,9 @@ int optionChecker( const std::string& inputfilename ) } if( avOption->unit && avOption->type == AV_OPT_TYPE_INT ) { - // OptionChoice - //options.push_back( opt ); + opt = new avtranscoder::OptionChoice( *avOption ); + options.push_back( opt ); + optionsChoice.push_back( dynamic_cast( opt ) ); continue; } @@ -90,14 +93,53 @@ int optionChecker( const std::string& inputfilename ) } default: { - //throw std::runtime_error( "undefined type for " + std::string( avOption->name ) ); std::cout << "----- Unknowed type for " << avOption->name << "-----" << std::endl; + break; } } if( opt ) options.push_back( opt ); } + + // adding enum values and set default value for enums + avOption = NULL; + while( (avOption = av_opt_next( audioDesc.getCodecContext(), avOption) ) != NULL ) + { + if( !avOption || + !avOption->name || + ( avOption->unit && avOption->type == AV_OPT_TYPE_FLAGS ) || + ( avOption->unit && avOption->type == AV_OPT_TYPE_INT ) ) + { + continue; + } + + switch( avOption->type ) + { + case AV_OPT_TYPE_CONST: + { + for( size_t i = 0; i < optionsChoice.size(); i++ ) + { + if( avOption->unit == optionsChoice.at( i )->getUnit() ) + { + if( avOption->help ) + optionsChoice.at( i )->appendOption( avOption->name, avOption->help ); + else + optionsChoice.at( i )->appendOption( avOption->name ); + + double valueDouble; + if( avOption->default_val.dbl == optionsChoice.at( i )->getDefaultValue( valueDouble ) ) + optionsChoice.at( i )->setDefaultChoiceIndex( optionsChoice.at( i )->getNbChoices() - 1 ); + } + } + } + default: + { + break; + } + } + } } + catch( std::exception &e ) { for( auto it = options.begin(); it != options.end(); ++it) @@ -109,6 +151,7 @@ int optionChecker( const std::string& inputfilename ) throw e; } + // display Options for( auto option : options ) { std::cout << std::left; @@ -124,42 +167,42 @@ int optionChecker( const std::string& inputfilename ) bool valueBool; avtranscoder::Value2D value2D; - switch( option->getType() ) + if( option->getType() == "OptionInt" ) { - case AV_OPT_TYPE_INT: - case AV_OPT_TYPE_INT64: - { - std::cout << "DefaultValue: " << option->getDefaultValue( valueInt ) << std::endl; - break; - } - case AV_OPT_TYPE_FLOAT: - case AV_OPT_TYPE_DOUBLE: - { - std::cout << "DefaultValue: " << option->getDefaultValue( valueDouble ) << std::endl; - break; - } - case AV_OPT_TYPE_STRING: - { - std::cout << "DefaultValue: " << option->getDefaultValue( valueStr ) << std::endl; - break; - } - case AV_OPT_TYPE_FLAGS: - { - if( option->getName().substr(0, 2) == "g_" ) // OptionGroup - std::cout << "DefaultValue: " << option->getDefaultValue( valueInt ) << std::endl; - else // OptionBoolean - std::cout << "DefaultValue: " << option->getDefaultValue( valueBool ) << std::endl; - break; - } - case AV_OPT_TYPE_RATIONAL: - { - option->getDefaultValue( value2D ); - std::cout << "DefaultValue: " << value2D.num << ", " << value2D.dem << std::endl; - break; - } + std::cout << "DefaultValue: " << option->getDefaultValue( valueInt ) << std::endl; + } + else if( option->getType() == "OptionBoolean" ) + { + std::cout << "DefaultValue: " << option->getDefaultValue( valueBool ) << std::endl; + } + else if( option->getType() == "OptionDouble" ) + { + std::cout << "DefaultValue: " << option->getDefaultValue( valueDouble ) << std::endl; + } + else if( option->getType() == "Option2D" ) + { + option->getDefaultValue( value2D ); + std::cout << "DefaultValue: " << value2D.num << ", " << value2D.dem << std::endl; + } + else if( option->getType() == "OptionString" ) + { + std::cout << "DefaultValue: " << option->getDefaultValue( valueStr ) << std::endl; + } + else if( option->getType() == "OptionChoice" ) + { + std::cout << "DefaultValue: " << option->getDefaultValue( valueDouble ) << std::endl; + + avtranscoder::OptionChoice* choice = dynamic_cast( option ); + std::cout << "Nb choices: " << choice->getNbChoices() << std::endl; + std::cout << "Default choice index: " << choice->getDefaultChoiceIndex() << std::endl; + for(size_t i = 0; i < choice->getChoices().size(); ++i ) + std::cout << "Choice " << i << ": " << choice->getChoice( i ).first << " // " << choice->getChoice( i ).second << std::endl; + } + else if( option->getType() == "OptionChoice" ) + { + std::cout << "DefaultValue: " << option->getDefaultValue( valueInt ) << std::endl; } } - } int main( int argc, char** argv ) diff --git a/src/AvTranscoder/Option.cpp b/src/AvTranscoder/Option.cpp index ff565299..b6a3cfd4 100644 --- a/src/AvTranscoder/Option.cpp +++ b/src/AvTranscoder/Option.cpp @@ -8,6 +8,7 @@ namespace avtranscoder Option::Option( const AVOption& avOption ) : m_name ( avOption.name ) , m_help ( avOption.help ? avOption.help : "" ) + , m_unit ( avOption.unit ? avOption.unit : "" ) , m_flags( avOption.flags ) { } diff --git a/src/AvTranscoder/Option.hpp b/src/AvTranscoder/Option.hpp index 368455a6..005660fb 100644 --- a/src/AvTranscoder/Option.hpp +++ b/src/AvTranscoder/Option.hpp @@ -10,6 +10,7 @@ extern "C" { #include #include +#include namespace avtranscoder { @@ -26,7 +27,7 @@ class Option Option( const AVOption& avOption ); virtual ~Option() {} - virtual AVOptionType getType() const = 0; + virtual std::string getType() const = 0; virtual int getDefaultValue( int& value ) const; virtual double getDefaultValue( double& value ) const; @@ -36,6 +37,7 @@ class Option std::string& getName() { return m_name; } std::string& getHelp() { return m_help; } + std::string& getUnit() { return m_unit; } bool isEncodingOpt(){ return m_flags & AV_OPT_FLAG_ENCODING_PARAM; } bool isDecodingOpt(){ return m_flags & AV_OPT_FLAG_DECODING_PARAM; } @@ -46,6 +48,7 @@ class Option protected: std::string m_name; std::string m_help; + std::string m_unit; int m_flags; }; diff --git a/src/AvTranscoder/Options/Option2D.hpp b/src/AvTranscoder/Options/Option2D.hpp index 7c549dc0..60a68c35 100644 --- a/src/AvTranscoder/Options/Option2D.hpp +++ b/src/AvTranscoder/Options/Option2D.hpp @@ -42,7 +42,7 @@ class Option2D : public Option ~Option2D(); - AVOptionType getType() const { return AV_OPT_TYPE_RATIONAL; } + std::string getType() const { return "Option2D"; } Value2D& getDefaultValue( Value2D& defaultValue ) const { return defaultValue = m_defaultValue; } private: diff --git a/src/AvTranscoder/Options/OptionBoolean.hpp b/src/AvTranscoder/Options/OptionBoolean.hpp index 38e66192..6d09a63f 100644 --- a/src/AvTranscoder/Options/OptionBoolean.hpp +++ b/src/AvTranscoder/Options/OptionBoolean.hpp @@ -23,7 +23,7 @@ class OptionBoolean : public Option ~OptionBoolean(); - AVOptionType getType() const { return AV_OPT_TYPE_FLAGS; } + std::string getType() const { return "OptionBoolean"; } bool getDefaultValue( bool& defaultValue ) const { return defaultValue = m_defaultValue; } private: diff --git a/src/AvTranscoder/Options/OptionChoice.cpp b/src/AvTranscoder/Options/OptionChoice.cpp new file mode 100644 index 00000000..98c66b4a --- /dev/null +++ b/src/AvTranscoder/Options/OptionChoice.cpp @@ -0,0 +1,33 @@ +#include "OptionChoice.hpp" + + +namespace avtranscoder +{ + +OptionChoice::OptionChoice( const AVOption& avOption ) + : Option( avOption ) + , m_defaultValue( avOption.default_val.dbl ) + , m_minValue( avOption.min ) + , m_maxValue( avOption.max ) + , m_choices() + , m_defaultChoiceIndex( 0 ) +{ + +} + +OptionChoice::~OptionChoice() +{ + +} + +void OptionChoice::appendOption( const char* name, const char* help ) +{ + m_choices.push_back( std::pair( name, help ) ); +} + +void OptionChoice::appendOption( const char* name ) +{ + m_choices.push_back( std::pair( name, "" ) ); +} + +} diff --git a/src/AvTranscoder/Options/OptionChoice.hpp b/src/AvTranscoder/Options/OptionChoice.hpp new file mode 100644 index 00000000..434629e9 --- /dev/null +++ b/src/AvTranscoder/Options/OptionChoice.hpp @@ -0,0 +1,52 @@ +#ifndef _AV_TRANSCODER_OPTION_CHOICE_HPP +#define _AV_TRANSCODER_OPTION_CHOICE_HPP + +#include + +extern "C" { +#ifndef __STDC_CONSTANT_MACROS + #define __STDC_CONSTANT_MACROS +#endif +#include +} + +#include +#include //pair + +namespace avtranscoder +{ + +/** + * @brief Wrap of AVOption with a type of AV_OPT_TYPE_DOUBLE. + */ +class OptionChoice : public Option +{ +public: + OptionChoice( const AVOption& avOption ); + + ~OptionChoice(); + + std::string getType() const { return "OptionChoice"; } + double getDefaultValue( double& defaultValue ) const { return defaultValue = m_defaultValue; } + + std::vector< std::pair >& getChoices() { return m_choices; } + std::pair& getChoice( size_t index ) { return m_choices.at( index ); } + size_t getNbChoices() const { return m_choices.size(); } + int getDefaultChoiceIndex( ) const { return m_defaultChoiceIndex; } + + void setDefaultChoiceIndex( int defaultChoiceIndex ) { m_defaultChoiceIndex = defaultChoiceIndex; } + + void appendOption( const char* name, const char* help ); + void appendOption( const char* name ); + +private: + double m_defaultValue; + double m_minValue; + double m_maxValue; + std::vector< std::pair > m_choices; + int m_defaultChoiceIndex; +}; + +} + +#endif diff --git a/src/AvTranscoder/Options/OptionDouble.hpp b/src/AvTranscoder/Options/OptionDouble.hpp index d50581a6..726f32e9 100644 --- a/src/AvTranscoder/Options/OptionDouble.hpp +++ b/src/AvTranscoder/Options/OptionDouble.hpp @@ -23,8 +23,8 @@ class OptionDouble : public Option ~OptionDouble(); - AVOptionType getType() const { return AV_OPT_TYPE_DOUBLE; } - double getDefaultValue( double &defaultValue ) const { return defaultValue = m_defaultValue; } + std::string getType() const { return "OptionDouble"; } + double getDefaultValue( double& defaultValue ) const { return defaultValue = m_defaultValue; } private: double m_defaultValue; diff --git a/src/AvTranscoder/Options/OptionGroup.hpp b/src/AvTranscoder/Options/OptionGroup.hpp index 77cec68f..41de8fa2 100644 --- a/src/AvTranscoder/Options/OptionGroup.hpp +++ b/src/AvTranscoder/Options/OptionGroup.hpp @@ -23,7 +23,7 @@ class OptionGroup : public Option ~OptionGroup(); - AVOptionType getType() const { return AV_OPT_TYPE_FLAGS; } + std::string getType() const { return "OptionGroup"; } int getDefaultValue( int& defaultValue ) const { return defaultValue = m_defaultValue; } private: diff --git a/src/AvTranscoder/Options/OptionInt.hpp b/src/AvTranscoder/Options/OptionInt.hpp index a7bf51ed..0fecca0a 100644 --- a/src/AvTranscoder/Options/OptionInt.hpp +++ b/src/AvTranscoder/Options/OptionInt.hpp @@ -23,7 +23,7 @@ class OptionInt : public Option ~OptionInt(); - AVOptionType getType() const { return AV_OPT_TYPE_INT; } + std::string getType() const { return "OptionInt"; } int getDefaultValue( int& defaultValue ) const { return defaultValue = m_defaultValue; } private: diff --git a/src/AvTranscoder/Options/OptionString.hpp b/src/AvTranscoder/Options/OptionString.hpp index d611c9c2..ed09e3b6 100644 --- a/src/AvTranscoder/Options/OptionString.hpp +++ b/src/AvTranscoder/Options/OptionString.hpp @@ -25,7 +25,7 @@ class OptionString : public Option ~OptionString(); - AVOptionType getType() const { return AV_OPT_TYPE_STRING; } + std::string getType() const { return "OptionString"; } std::string& getDefaultValue( std::string& defaultValue ) const { return defaultValue = m_defaultValue; } private: From 71cf63199c823528d8ba989f335ff16dcd897bd0 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 10 Jun 2014 11:13:17 +0200 Subject: [PATCH 08/24] OptionGroup: add array of OptionBoolean * Update optionChecker to fill OptionGroup by OptionBoolean. --- app/optionChecker/optionChecker.cpp | 33 ++++++++++++++++++++---- src/AvTranscoder/Options/OptionGroup.cpp | 6 +++++ src/AvTranscoder/Options/OptionGroup.hpp | 9 +++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/app/optionChecker/optionChecker.cpp b/app/optionChecker/optionChecker.cpp index d2806c10..fe162002 100644 --- a/app/optionChecker/optionChecker.cpp +++ b/app/optionChecker/optionChecker.cpp @@ -24,25 +24,27 @@ int optionChecker( const std::string& inputfilename ) std::vector options; std::vector optionsChoice; // need to access easely to the OptionChoice to add the list of value for each of them + std::vector optionsGroup; // need to access easely to the OptionGroup to add the list of value for each of them try { const AVOption* avOption = NULL; while( ( avOption = av_opt_next( audioDesc.getCodecContext(), avOption ) ) != NULL ) - { - avtranscoder::Option* opt = NULL; - + { if( !avOption || ! avOption->name ) { continue; } + avtranscoder::Option* opt = NULL; + std::cout << "The option is " << avOption->name << " of type : " << avOption->type << std::endl; if( avOption->unit && avOption->type == AV_OPT_TYPE_FLAGS ) { opt = new avtranscoder::OptionGroup( *avOption ); options.push_back( opt ); + optionsGroup.push_back( dynamic_cast( opt ) ); continue; } if( avOption->unit && avOption->type == AV_OPT_TYPE_INT ) @@ -84,7 +86,7 @@ int optionChecker( const std::string& inputfilename ) } case AV_OPT_TYPE_BINARY: { - //opt = new avtranscoder::OptionString( *avOption ); + opt = new avtranscoder::OptionString( *avOption ); break; } case AV_OPT_TYPE_CONST: @@ -112,6 +114,8 @@ int optionChecker( const std::string& inputfilename ) { continue; } + + avtranscoder::OptionBoolean* optBoolean = NULL; switch( avOption->type ) { @@ -131,6 +135,18 @@ int optionChecker( const std::string& inputfilename ) optionsChoice.at( i )->setDefaultChoiceIndex( optionsChoice.at( i )->getNbChoices() - 1 ); } } + + for( size_t i = 0; i < optionsGroup.size(); i++ ) + { + std::string name = "g_"; + name += avOption->unit; + if( name == optionsGroup.at( i )->getName() ) + { + optBoolean = new avtranscoder::OptionBoolean( *avOption ); + optionsGroup.at( i )->appendElement( *optBoolean ); + break; + } + } } default: { @@ -198,9 +214,16 @@ int optionChecker( const std::string& inputfilename ) for(size_t i = 0; i < choice->getChoices().size(); ++i ) std::cout << "Choice " << i << ": " << choice->getChoice( i ).first << " // " << choice->getChoice( i ).second << std::endl; } - else if( option->getType() == "OptionChoice" ) + else if( option->getType() == "OptionGroup" ) { std::cout << "DefaultValue: " << option->getDefaultValue( valueInt ) << std::endl; + + avtranscoder::OptionGroup* group = dynamic_cast( option ); + std::cout << "Nb choices: " << group->getNbElements() << std::endl; + for(size_t i = 0; i < group->getNbElements(); ++i ) + std::cout << "Element " << i << ": " << + group->getElement( i ).getName() << " // " << + group->getElement( i ).getDefaultValue( valueBool ) << std::endl; } } } diff --git a/src/AvTranscoder/Options/OptionGroup.cpp b/src/AvTranscoder/Options/OptionGroup.cpp index b0285723..2d39543b 100644 --- a/src/AvTranscoder/Options/OptionGroup.cpp +++ b/src/AvTranscoder/Options/OptionGroup.cpp @@ -7,6 +7,7 @@ namespace avtranscoder OptionGroup::OptionGroup( const AVOption& avOption ) : Option( avOption ) , m_defaultValue( avOption.default_val.i64 ) + , m_elements() { std::string name = "g_"; name += avOption.unit; @@ -18,4 +19,9 @@ OptionGroup::~OptionGroup() } +void OptionGroup::appendElement( const OptionBoolean& element ) +{ + m_elements.push_back( element ); +} + } diff --git a/src/AvTranscoder/Options/OptionGroup.hpp b/src/AvTranscoder/Options/OptionGroup.hpp index 41de8fa2..fe9cf59c 100644 --- a/src/AvTranscoder/Options/OptionGroup.hpp +++ b/src/AvTranscoder/Options/OptionGroup.hpp @@ -2,6 +2,7 @@ #define _AV_TRANSCODER_OPTION_GROUP_HPP #include +#include extern "C" { #ifndef __STDC_CONSTANT_MACROS @@ -26,10 +27,18 @@ class OptionGroup : public Option std::string getType() const { return "OptionGroup"; } int getDefaultValue( int& defaultValue ) const { return defaultValue = m_defaultValue; } + std::vector< OptionBoolean >& getElements() { return m_elements; } + OptionBoolean& getElement( size_t index ) { return m_elements.at( index ); } + size_t getNbElements() const { return m_elements.size(); } + + void appendElement( const OptionBoolean& element ); + private: int m_defaultValue; double m_minValue; double m_maxValue; + + std::vector< OptionBoolean > m_elements; }; } From db23f056db5ca6bb1fb9ff27932d7d1f9e3b5d5b Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 10 Jun 2014 11:14:53 +0200 Subject: [PATCH 09/24] OptionChoice: refactoring * Rename appendOption by appendChoice. * Update @brief of the class. --- app/optionChecker/optionChecker.cpp | 6 +++--- src/AvTranscoder/Options/OptionChoice.cpp | 4 ++-- src/AvTranscoder/Options/OptionChoice.hpp | 7 ++++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/optionChecker/optionChecker.cpp b/app/optionChecker/optionChecker.cpp index fe162002..a4550470 100644 --- a/app/optionChecker/optionChecker.cpp +++ b/app/optionChecker/optionChecker.cpp @@ -126,9 +126,9 @@ int optionChecker( const std::string& inputfilename ) if( avOption->unit == optionsChoice.at( i )->getUnit() ) { if( avOption->help ) - optionsChoice.at( i )->appendOption( avOption->name, avOption->help ); + optionsChoice.at( i )->appendChoice( avOption->name, avOption->help ); else - optionsChoice.at( i )->appendOption( avOption->name ); + optionsChoice.at( i )->appendChoice( avOption->name ); double valueDouble; if( avOption->default_val.dbl == optionsChoice.at( i )->getDefaultValue( valueDouble ) ) @@ -211,7 +211,7 @@ int optionChecker( const std::string& inputfilename ) avtranscoder::OptionChoice* choice = dynamic_cast( option ); std::cout << "Nb choices: " << choice->getNbChoices() << std::endl; std::cout << "Default choice index: " << choice->getDefaultChoiceIndex() << std::endl; - for(size_t i = 0; i < choice->getChoices().size(); ++i ) + for(size_t i = 0; i < choice->getNbChoices(); ++i ) std::cout << "Choice " << i << ": " << choice->getChoice( i ).first << " // " << choice->getChoice( i ).second << std::endl; } else if( option->getType() == "OptionGroup" ) diff --git a/src/AvTranscoder/Options/OptionChoice.cpp b/src/AvTranscoder/Options/OptionChoice.cpp index 98c66b4a..c6a943c1 100644 --- a/src/AvTranscoder/Options/OptionChoice.cpp +++ b/src/AvTranscoder/Options/OptionChoice.cpp @@ -20,12 +20,12 @@ OptionChoice::~OptionChoice() } -void OptionChoice::appendOption( const char* name, const char* help ) +void OptionChoice::appendChoice( const char* name, const char* help ) { m_choices.push_back( std::pair( name, help ) ); } -void OptionChoice::appendOption( const char* name ) +void OptionChoice::appendChoice( const char* name ) { m_choices.push_back( std::pair( name, "" ) ); } diff --git a/src/AvTranscoder/Options/OptionChoice.hpp b/src/AvTranscoder/Options/OptionChoice.hpp index 434629e9..da28d42f 100644 --- a/src/AvTranscoder/Options/OptionChoice.hpp +++ b/src/AvTranscoder/Options/OptionChoice.hpp @@ -17,7 +17,7 @@ namespace avtranscoder { /** - * @brief Wrap of AVOption with a type of AV_OPT_TYPE_DOUBLE. + * @brief Wrap of AVOption with a type of AV_OPT_TYPE_INT and unit informed. */ class OptionChoice : public Option { @@ -36,13 +36,14 @@ class OptionChoice : public Option void setDefaultChoiceIndex( int defaultChoiceIndex ) { m_defaultChoiceIndex = defaultChoiceIndex; } - void appendOption( const char* name, const char* help ); - void appendOption( const char* name ); + void appendChoice( const char* name, const char* help ); + void appendChoice( const char* name ); private: double m_defaultValue; double m_minValue; double m_maxValue; + std::vector< std::pair > m_choices; int m_defaultChoiceIndex; }; From a4d8b3bba3cf9467ff3a3897b2affc2fa7b37cf2 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 10 Jun 2014 11:16:57 +0200 Subject: [PATCH 10/24] Option: update comment --- src/AvTranscoder/Option.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AvTranscoder/Option.hpp b/src/AvTranscoder/Option.hpp index 005660fb..47e9596a 100644 --- a/src/AvTranscoder/Option.hpp +++ b/src/AvTranscoder/Option.hpp @@ -18,7 +18,7 @@ namespace avtranscoder class Value2D; /** - * @breif Abstract class to wrap AVOption. + * @brief Abstract class to wrap AVOption. * Subclasses implement specific AVOption: int, boolean... */ class Option From 6d0bde8dd0d6789b5424f3b5daaa93c08b763327 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 10 Jun 2014 11:17:38 +0200 Subject: [PATCH 11/24] Option2D: refactoring * Suppress tabulation. --- src/AvTranscoder/Options/Option2D.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AvTranscoder/Options/Option2D.hpp b/src/AvTranscoder/Options/Option2D.hpp index 60a68c35..c3385830 100644 --- a/src/AvTranscoder/Options/Option2D.hpp +++ b/src/AvTranscoder/Options/Option2D.hpp @@ -1,5 +1,5 @@ #ifndef _AV_TRANSCODER_OPTION_2D_HPP -#define _AV_TRANSCODER_OPTION_2D_HPP +#define _AV_TRANSCODER_OPTION_2D_HPP #include From 6c91f89a64de1e83689a6ca166ff84b0d667b2a7 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 10 Jun 2014 11:28:48 +0200 Subject: [PATCH 12/24] Option2D: refactoring * Rename Option2D by OptionRatio. * Use std::pair instead of custom struct Value2D. --- app/optionChecker/optionChecker.cpp | 11 ++-- src/AvTranscoder/Option.cpp | 4 +- src/AvTranscoder/Option.hpp | 5 +- .../Options/{Option2D.cpp => OpionRatio.cpp} | 6 +- src/AvTranscoder/Options/OpionRatio.hpp | 37 ++++++++++++ src/AvTranscoder/Options/Option2D.hpp | 56 ------------------- 6 files changed, 50 insertions(+), 69 deletions(-) rename src/AvTranscoder/Options/{Option2D.cpp => OpionRatio.cpp} (66%) create mode 100644 src/AvTranscoder/Options/OpionRatio.hpp delete mode 100644 src/AvTranscoder/Options/Option2D.hpp diff --git a/app/optionChecker/optionChecker.cpp b/app/optionChecker/optionChecker.cpp index a4550470..e17ccafe 100644 --- a/app/optionChecker/optionChecker.cpp +++ b/app/optionChecker/optionChecker.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -14,6 +14,7 @@ #include #include #include +#include //pair int optionChecker( const std::string& inputfilename ) { @@ -81,7 +82,7 @@ int optionChecker( const std::string& inputfilename ) } case AV_OPT_TYPE_RATIONAL: { - opt = new avtranscoder::Option2D( *avOption ); + opt = new avtranscoder::OpionRatio( *avOption ); break; } case AV_OPT_TYPE_BINARY: @@ -181,7 +182,7 @@ int optionChecker( const std::string& inputfilename ) double valueDouble; std::string valueStr; bool valueBool; - avtranscoder::Value2D value2D; + std::pair value2D; if( option->getType() == "OptionInt" ) { @@ -195,10 +196,10 @@ int optionChecker( const std::string& inputfilename ) { std::cout << "DefaultValue: " << option->getDefaultValue( valueDouble ) << std::endl; } - else if( option->getType() == "Option2D" ) + else if( option->getType() == "OptionRatio" ) { option->getDefaultValue( value2D ); - std::cout << "DefaultValue: " << value2D.num << ", " << value2D.dem << std::endl; + std::cout << "DefaultValue: " << value2D.first << ", " << value2D.second << std::endl; } else if( option->getType() == "OptionString" ) { diff --git a/src/AvTranscoder/Option.cpp b/src/AvTranscoder/Option.cpp index b6a3cfd4..3645d1e9 100644 --- a/src/AvTranscoder/Option.cpp +++ b/src/AvTranscoder/Option.cpp @@ -33,9 +33,9 @@ bool Option::getDefaultValue( bool& value ) const throw std::runtime_error( "Wrong access to getDefaultValue (bool)." ); } -Value2D& Option::getDefaultValue( Value2D& value ) const +std::pair& Option::getDefaultValue( std::pair& value ) const { - throw std::runtime_error( "Wrong access to getDefaultValue (Value2D)." ); + throw std::runtime_error( "Wrong access to getDefaultValue (std::pair)." ); } } diff --git a/src/AvTranscoder/Option.hpp b/src/AvTranscoder/Option.hpp index 47e9596a..002432cc 100644 --- a/src/AvTranscoder/Option.hpp +++ b/src/AvTranscoder/Option.hpp @@ -11,12 +11,11 @@ extern "C" { #include #include #include +#include //pair namespace avtranscoder { -class Value2D; - /** * @brief Abstract class to wrap AVOption. * Subclasses implement specific AVOption: int, boolean... @@ -33,7 +32,7 @@ class Option virtual double getDefaultValue( double& value ) const; virtual std::string& getDefaultValue( std::string& value ) const; virtual bool getDefaultValue( bool& value ) const; - virtual Value2D& getDefaultValue( Value2D& value ) const; + virtual std::pair& getDefaultValue( std::pair& value ) const; std::string& getName() { return m_name; } std::string& getHelp() { return m_help; } diff --git a/src/AvTranscoder/Options/Option2D.cpp b/src/AvTranscoder/Options/OpionRatio.cpp similarity index 66% rename from src/AvTranscoder/Options/Option2D.cpp rename to src/AvTranscoder/Options/OpionRatio.cpp index 04c05078..b95061fa 100644 --- a/src/AvTranscoder/Options/Option2D.cpp +++ b/src/AvTranscoder/Options/OpionRatio.cpp @@ -1,10 +1,10 @@ -#include "Option2D.hpp" +#include "OpionRatio.hpp" namespace avtranscoder { -Option2D::Option2D( const AVOption& avOption ) +OpionRatio::OpionRatio( const AVOption& avOption ) : Option( avOption ) , m_defaultValue( avOption.default_val.q.num, avOption.default_val.q.den ) , m_minValue( avOption.min ) @@ -13,7 +13,7 @@ Option2D::Option2D( const AVOption& avOption ) } -Option2D::~Option2D() +OpionRatio::~OpionRatio() { } diff --git a/src/AvTranscoder/Options/OpionRatio.hpp b/src/AvTranscoder/Options/OpionRatio.hpp new file mode 100644 index 00000000..166997f8 --- /dev/null +++ b/src/AvTranscoder/Options/OpionRatio.hpp @@ -0,0 +1,37 @@ +#ifndef _AV_TRANSCODER_OPTION_2D_HPP +#define _AV_TRANSCODER_OPTION_2D_HPP + +#include + +extern "C" { +#ifndef __STDC_CONSTANT_MACROS + #define __STDC_CONSTANT_MACROS +#endif +#include +} + +namespace avtranscoder +{ + +/** + * @brief Wrap of AVOption with a type of AV_OPT_TYPE_RATIONAL. + */ +class OpionRatio : public Option +{ +public: + OpionRatio( const AVOption& avOption ); + + ~OpionRatio(); + + std::string getType() const { return "OptionRatio"; } + std::pair& getDefaultValue( std::pair& defaultValue ) const { return defaultValue = m_defaultValue; } + +private: + std::pair m_defaultValue; + double m_minValue; + double m_maxValue; +}; + +} + +#endif diff --git a/src/AvTranscoder/Options/Option2D.hpp b/src/AvTranscoder/Options/Option2D.hpp deleted file mode 100644 index c3385830..00000000 --- a/src/AvTranscoder/Options/Option2D.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _AV_TRANSCODER_OPTION_2D_HPP -#define _AV_TRANSCODER_OPTION_2D_HPP - -#include - -extern "C" { -#ifndef __STDC_CONSTANT_MACROS - #define __STDC_CONSTANT_MACROS -#endif -#include -} - -namespace avtranscoder -{ - -/** - * @brief Object return by getDefaultValue of Option2D. - */ -struct Value2D -{ - Value2D() - : num( 0 ) - , dem( 0 ) - {} - - Value2D( int numValue, int demValue ) - : num( numValue ) - , dem( demValue ) - {} - - int num; - int dem; -}; - -/** - * @brief Wrap of AVOption with a type of AV_OPT_TYPE_RATIONAL. - */ -class Option2D : public Option -{ -public: - Option2D( const AVOption& avOption ); - - ~Option2D(); - - std::string getType() const { return "Option2D"; } - Value2D& getDefaultValue( Value2D& defaultValue ) const { return defaultValue = m_defaultValue; } - -private: - Value2D m_defaultValue; - double m_minValue; - double m_maxValue; -}; - -} - -#endif From 0c766a8411af87cae3d9abf5127ee6269c08c6f3 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 10 Jun 2014 13:29:06 +0200 Subject: [PATCH 13/24] Add OptionLoader: manage a list of Option * Update optionsChecker to use the OptionLoader. The app calls the loader and displays the list of options. --- app/optionChecker/optionChecker.cpp | 156 +------------------------ src/AvTranscoder/OptionLoader.cpp | 171 ++++++++++++++++++++++++++++ src/AvTranscoder/OptionLoader.hpp | 30 +++++ 3 files changed, 205 insertions(+), 152 deletions(-) create mode 100644 src/AvTranscoder/OptionLoader.cpp create mode 100644 src/AvTranscoder/OptionLoader.hpp diff --git a/app/optionChecker/optionChecker.cpp b/app/optionChecker/optionChecker.cpp index e17ccafe..8e8db5a3 100644 --- a/app/optionChecker/optionChecker.cpp +++ b/app/optionChecker/optionChecker.cpp @@ -1,16 +1,10 @@ #include #include -#include -#include -#include -#include -#include #include #include -#include +#include -#include #include #include #include @@ -23,153 +17,11 @@ int optionChecker( const std::string& inputfilename ) avtranscoder::AudioDesc audioDesc( inputFile.getStream( 0 ).getAudioDesc() ); - std::vector options; - std::vector optionsChoice; // need to access easely to the OptionChoice to add the list of value for each of them - std::vector optionsGroup; // need to access easely to the OptionGroup to add the list of value for each of them - try - { - const AVOption* avOption = NULL; - - while( ( avOption = av_opt_next( audioDesc.getCodecContext(), avOption ) ) != NULL ) - { - if( !avOption || ! avOption->name ) - { - continue; - } - - avtranscoder::Option* opt = NULL; - - std::cout << "The option is " << avOption->name << " of type : " << avOption->type << std::endl; - - if( avOption->unit && avOption->type == AV_OPT_TYPE_FLAGS ) - { - opt = new avtranscoder::OptionGroup( *avOption ); - options.push_back( opt ); - optionsGroup.push_back( dynamic_cast( opt ) ); - continue; - } - if( avOption->unit && avOption->type == AV_OPT_TYPE_INT ) - { - opt = new avtranscoder::OptionChoice( *avOption ); - options.push_back( opt ); - optionsChoice.push_back( dynamic_cast( opt ) ); - continue; - } - - switch( avOption->type ) - { - case AV_OPT_TYPE_FLAGS: - { - opt = new avtranscoder::OptionBoolean( *avOption ); - break; - } - case AV_OPT_TYPE_INT: - case AV_OPT_TYPE_INT64: - { - opt = new avtranscoder::OptionInt( *avOption ); - break; - } - case AV_OPT_TYPE_DOUBLE: - case AV_OPT_TYPE_FLOAT: - { - opt = new avtranscoder::OptionDouble( *avOption ); - break; - } - case AV_OPT_TYPE_STRING: - { - opt = new avtranscoder::OptionString( *avOption ); - break; - } - case AV_OPT_TYPE_RATIONAL: - { - opt = new avtranscoder::OpionRatio( *avOption ); - break; - } - case AV_OPT_TYPE_BINARY: - { - opt = new avtranscoder::OptionString( *avOption ); - break; - } - case AV_OPT_TYPE_CONST: - { - break; - } - default: - { - std::cout << "----- Unknowed type for " << avOption->name << "-----" << std::endl; - break; - } - } - if( opt ) - options.push_back( opt ); - } - - // adding enum values and set default value for enums - avOption = NULL; - while( (avOption = av_opt_next( audioDesc.getCodecContext(), avOption) ) != NULL ) - { - if( !avOption || - !avOption->name || - ( avOption->unit && avOption->type == AV_OPT_TYPE_FLAGS ) || - ( avOption->unit && avOption->type == AV_OPT_TYPE_INT ) ) - { - continue; - } - - avtranscoder::OptionBoolean* optBoolean = NULL; - - switch( avOption->type ) - { - case AV_OPT_TYPE_CONST: - { - for( size_t i = 0; i < optionsChoice.size(); i++ ) - { - if( avOption->unit == optionsChoice.at( i )->getUnit() ) - { - if( avOption->help ) - optionsChoice.at( i )->appendChoice( avOption->name, avOption->help ); - else - optionsChoice.at( i )->appendChoice( avOption->name ); - - double valueDouble; - if( avOption->default_val.dbl == optionsChoice.at( i )->getDefaultValue( valueDouble ) ) - optionsChoice.at( i )->setDefaultChoiceIndex( optionsChoice.at( i )->getNbChoices() - 1 ); - } - } - - for( size_t i = 0; i < optionsGroup.size(); i++ ) - { - std::string name = "g_"; - name += avOption->unit; - if( name == optionsGroup.at( i )->getName() ) - { - optBoolean = new avtranscoder::OptionBoolean( *avOption ); - optionsGroup.at( i )->appendElement( *optBoolean ); - break; - } - } - } - default: - { - break; - } - } - } - } - - catch( std::exception &e ) - { - for( auto it = options.begin(); it != options.end(); ++it) - { - delete *it; - } - options.clear(); - - throw e; - } + avtranscoder::OptionLoader optionLoader; + optionLoader.loadOptions( audioDesc.getCodecContext() ); // display Options - for( auto option : options ) + for( auto option : optionLoader.getOptions() ) { std::cout << std::left; std::cout << "****************************" << std::endl; diff --git a/src/AvTranscoder/OptionLoader.cpp b/src/AvTranscoder/OptionLoader.cpp new file mode 100644 index 00000000..d178217a --- /dev/null +++ b/src/AvTranscoder/OptionLoader.cpp @@ -0,0 +1,171 @@ +#include "OptionLoader.hpp" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace avtranscoder +{ + +OptionLoader::OptionLoader() + : m_options() +{ + +} + +void OptionLoader::loadOptions( void* av_class ) +{ + // tmp vectors to access easely to the OptionChoice/OptionGroup to add choice / boolean to them + std::vector optionsChoice; + std::vector optionsGroup; + try + { + const AVOption* avOption = NULL; + + while( ( avOption = av_opt_next( av_class, avOption ) ) != NULL ) + { + if( !avOption || ! avOption->name ) + { + continue; + } + + avtranscoder::Option* opt = NULL; + + //std::cout << "The option is " << avOption->name << " of type : " << avOption->type << std::endl; + + if( avOption->unit && avOption->type == AV_OPT_TYPE_FLAGS ) + { + opt = new avtranscoder::OptionGroup( *avOption ); + m_options.push_back( opt ); + optionsGroup.push_back( dynamic_cast( opt ) ); + continue; + } + if( avOption->unit && avOption->type == AV_OPT_TYPE_INT ) + { + opt = new avtranscoder::OptionChoice( *avOption ); + m_options.push_back( opt ); + optionsChoice.push_back( dynamic_cast( opt ) ); + continue; + } + + switch( avOption->type ) + { + case AV_OPT_TYPE_FLAGS: + { + opt = new avtranscoder::OptionBoolean( *avOption ); + break; + } + case AV_OPT_TYPE_INT: + case AV_OPT_TYPE_INT64: + { + opt = new avtranscoder::OptionInt( *avOption ); + break; + } + case AV_OPT_TYPE_DOUBLE: + case AV_OPT_TYPE_FLOAT: + { + opt = new avtranscoder::OptionDouble( *avOption ); + break; + } + case AV_OPT_TYPE_STRING: + { + opt = new avtranscoder::OptionString( *avOption ); + break; + } + case AV_OPT_TYPE_RATIONAL: + { + opt = new avtranscoder::OpionRatio( *avOption ); + break; + } + case AV_OPT_TYPE_BINARY: + { + opt = new avtranscoder::OptionString( *avOption ); + break; + } + case AV_OPT_TYPE_CONST: + { + break; + } + default: + { + //std::cout << "----- Unknowed type for " << avOption->name << "-----" << std::endl; + break; + } + } + if( opt ) + m_options.push_back( opt ); + } + + // adding enum values and set default value for enums + avOption = NULL; + while( (avOption = av_opt_next( av_class, avOption) ) != NULL ) + { + if( !avOption || + !avOption->name || + ( avOption->unit && avOption->type == AV_OPT_TYPE_FLAGS ) || + ( avOption->unit && avOption->type == AV_OPT_TYPE_INT ) ) + { + continue; + } + + avtranscoder::OptionBoolean* optBoolean = NULL; + + switch( avOption->type ) + { + case AV_OPT_TYPE_CONST: + { + for( size_t i = 0; i < optionsChoice.size(); i++ ) + { + if( avOption->unit == optionsChoice.at( i )->getUnit() ) + { + if( avOption->help ) + optionsChoice.at( i )->appendChoice( avOption->name, avOption->help ); + else + optionsChoice.at( i )->appendChoice( avOption->name ); + + double valueDouble; + if( avOption->default_val.dbl == optionsChoice.at( i )->getDefaultValue( valueDouble ) ) + optionsChoice.at( i )->setDefaultChoiceIndex( optionsChoice.at( i )->getNbChoices() - 1 ); + } + } + + for( size_t i = 0; i < optionsGroup.size(); i++ ) + { + std::string name = "g_"; + name += avOption->unit; + if( name == optionsGroup.at( i )->getName() ) + { + optBoolean = new avtranscoder::OptionBoolean( *avOption ); + optionsGroup.at( i )->appendElement( *optBoolean ); + break; + } + } + } + default: + { + break; + } + } + } + } + + catch( std::exception &e ) + { + for( std::vector::iterator it = m_options.begin(); it != m_options.end(); ++it) + { + delete *it; + } + m_options.clear(); + + throw e; + } +} + +} diff --git a/src/AvTranscoder/OptionLoader.hpp b/src/AvTranscoder/OptionLoader.hpp new file mode 100644 index 00000000..187023d0 --- /dev/null +++ b/src/AvTranscoder/OptionLoader.hpp @@ -0,0 +1,30 @@ +#ifndef _AV_TRANSCODER_OPTION_LOADER_HPP +#define _AV_TRANSCODER_OPTION_LOADER_HPP + +#include + +#include + +namespace avtranscoder +{ + +/** + * @brief Manage a list of Option. + * The list is filled by loading options from a libav / ffmpeg object. + */ +class OptionLoader +{ +public: + OptionLoader(); + + std::vector& getOptions() { return m_options; } + + void loadOptions( void* av_class ); + +private: + std::vector m_options; +}; + +} + +#endif From 307a9d0a4c274eeece85cfb9c9d1fc1ac2d2b7e8 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 10 Jun 2014 13:44:43 +0200 Subject: [PATCH 14/24] OptionLoader: add flags to loadOptions * 2 new params: * req_flags * rej_flags * Can manage specific AVOptions depending on their flags. --- app/optionChecker/optionChecker.cpp | 9 ++++++++- src/AvTranscoder/OptionLoader.cpp | 9 +++++++-- src/AvTranscoder/OptionLoader.hpp | 5 ++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/optionChecker/optionChecker.cpp b/app/optionChecker/optionChecker.cpp index 8e8db5a3..33848b33 100644 --- a/app/optionChecker/optionChecker.cpp +++ b/app/optionChecker/optionChecker.cpp @@ -5,6 +5,13 @@ #include #include +extern "C" { +#ifndef __STDC_CONSTANT_MACROS + #define __STDC_CONSTANT_MACROS +#endif +#include +} + #include #include #include @@ -18,7 +25,7 @@ int optionChecker( const std::string& inputfilename ) avtranscoder::AudioDesc audioDesc( inputFile.getStream( 0 ).getAudioDesc() ); avtranscoder::OptionLoader optionLoader; - optionLoader.loadOptions( audioDesc.getCodecContext() ); + optionLoader.loadOptions( audioDesc.getCodecContext(), 0, 0 ); // display Options for( auto option : optionLoader.getOptions() ) diff --git a/src/AvTranscoder/OptionLoader.cpp b/src/AvTranscoder/OptionLoader.cpp index d178217a..489e291e 100644 --- a/src/AvTranscoder/OptionLoader.cpp +++ b/src/AvTranscoder/OptionLoader.cpp @@ -20,7 +20,7 @@ OptionLoader::OptionLoader() } -void OptionLoader::loadOptions( void* av_class ) +void OptionLoader::loadOptions( void* av_class, int req_flags, int rej_flags ) { // tmp vectors to access easely to the OptionChoice/OptionGroup to add choice / boolean to them std::vector optionsChoice; @@ -31,7 +31,10 @@ void OptionLoader::loadOptions( void* av_class ) while( ( avOption = av_opt_next( av_class, avOption ) ) != NULL ) { - if( !avOption || ! avOption->name ) + if( !avOption || + ! avOption->name || + ( avOption->flags & req_flags ) != req_flags || + ( avOption->flags & rej_flags ) ) { continue; } @@ -109,6 +112,8 @@ void OptionLoader::loadOptions( void* av_class ) { if( !avOption || !avOption->name || + ( avOption->flags & req_flags ) != req_flags || + ( avOption->flags & rej_flags ) || ( avOption->unit && avOption->type == AV_OPT_TYPE_FLAGS ) || ( avOption->unit && avOption->type == AV_OPT_TYPE_INT ) ) { diff --git a/src/AvTranscoder/OptionLoader.hpp b/src/AvTranscoder/OptionLoader.hpp index 187023d0..f93660bc 100644 --- a/src/AvTranscoder/OptionLoader.hpp +++ b/src/AvTranscoder/OptionLoader.hpp @@ -19,7 +19,10 @@ class OptionLoader std::vector& getOptions() { return m_options; } - void loadOptions( void* av_class ); + /** + * @param av_class: a libav / ffmpeg object which contains AVOption. + */ + void loadOptions( void* av_class, int req_flags, int rej_flags ); private: std::vector m_options; From d3a8c58dc51583d20300ee3f7a9f9072e1e48463 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 10 Jun 2014 18:16:55 +0200 Subject: [PATCH 15/24] Option: delete Option subclasses * Option class is not abstract anymore: it represents all possible type of Option (Int, Boolean, Choice...). * OptionType enum manages the different cases of option (Int, Boolean, Choice...). * Option class contains an array of Option: contains sub options in case of Choice or Group. * OptionLoader manages an array of Option (instead of pointers). * OptionChecker doesn't need to include libav / ffmpeg files (thankfully). * Update SConstruct: Options folder doesn't exist anymore. --- app/optionChecker/optionChecker.cpp | 71 +++----- src/AvTranscoder/Option.cpp | 85 +++++++-- src/AvTranscoder/Option.hpp | 92 ++++++---- src/AvTranscoder/OptionLoader.cpp | 197 +++++---------------- src/AvTranscoder/OptionLoader.hpp | 4 +- src/AvTranscoder/Options/OpionRatio.cpp | 21 --- src/AvTranscoder/Options/OpionRatio.hpp | 37 ---- src/AvTranscoder/Options/OptionBoolean.cpp | 21 --- src/AvTranscoder/Options/OptionBoolean.hpp | 37 ---- src/AvTranscoder/Options/OptionChoice.cpp | 33 ---- src/AvTranscoder/Options/OptionChoice.hpp | 53 ------ src/AvTranscoder/Options/OptionDouble.cpp | 21 --- src/AvTranscoder/Options/OptionDouble.hpp | 38 ---- src/AvTranscoder/Options/OptionGroup.cpp | 27 --- src/AvTranscoder/Options/OptionGroup.hpp | 46 ----- src/AvTranscoder/Options/OptionInt.cpp | 21 --- src/AvTranscoder/Options/OptionInt.hpp | 37 ---- src/AvTranscoder/Options/OptionString.cpp | 21 --- src/AvTranscoder/Options/OptionString.hpp | 39 ---- src/SConscript | 4 +- 20 files changed, 209 insertions(+), 696 deletions(-) delete mode 100644 src/AvTranscoder/Options/OpionRatio.cpp delete mode 100644 src/AvTranscoder/Options/OpionRatio.hpp delete mode 100644 src/AvTranscoder/Options/OptionBoolean.cpp delete mode 100644 src/AvTranscoder/Options/OptionBoolean.hpp delete mode 100644 src/AvTranscoder/Options/OptionChoice.cpp delete mode 100644 src/AvTranscoder/Options/OptionChoice.hpp delete mode 100644 src/AvTranscoder/Options/OptionDouble.cpp delete mode 100644 src/AvTranscoder/Options/OptionDouble.hpp delete mode 100644 src/AvTranscoder/Options/OptionGroup.cpp delete mode 100644 src/AvTranscoder/Options/OptionGroup.hpp delete mode 100644 src/AvTranscoder/Options/OptionInt.cpp delete mode 100644 src/AvTranscoder/Options/OptionInt.hpp delete mode 100644 src/AvTranscoder/Options/OptionString.cpp delete mode 100644 src/AvTranscoder/Options/OptionString.hpp diff --git a/app/optionChecker/optionChecker.cpp b/app/optionChecker/optionChecker.cpp index 33848b33..02907f17 100644 --- a/app/optionChecker/optionChecker.cpp +++ b/app/optionChecker/optionChecker.cpp @@ -1,17 +1,8 @@ #include #include -#include -#include #include -extern "C" { -#ifndef __STDC_CONSTANT_MACROS - #define __STDC_CONSTANT_MACROS -#endif -#include -} - #include #include #include @@ -32,58 +23,48 @@ int optionChecker( const std::string& inputfilename ) { std::cout << std::left; std::cout << "****************************" << std::endl; - std::cout << std::setw(30) << option->getName(); - std::cout << ": " << option->getHelp() << std::endl; - std::cout << "Type: " << option->getType() << std::endl; + std::cout << std::setw(30) << option.getName(); + std::cout << ": " << option.getHelp() << std::endl; + std::cout << "Type: " << option.getType() << std::endl; // get default value - int valueInt; - double valueDouble; - std::string valueStr; - bool valueBool; - std::pair value2D; - if( option->getType() == "OptionInt" ) + if( option.getType() == avtranscoder::TypeInt ) { - std::cout << "DefaultValue: " << option->getDefaultValue( valueInt ) << std::endl; + std::cout << "DefaultValue: " << option.getDefaultValueInt() << std::endl; } - else if( option->getType() == "OptionBoolean" ) + else if( option.getType() == avtranscoder::TypeBool ) { - std::cout << "DefaultValue: " << option->getDefaultValue( valueBool ) << std::endl; + std::cout << "DefaultValue: " << option.getDefaultValueBool() << std::endl; } - else if( option->getType() == "OptionDouble" ) + else if( option.getType() == avtranscoder::TypeDouble ) { - std::cout << "DefaultValue: " << option->getDefaultValue( valueDouble ) << std::endl; + std::cout << "DefaultValue: " << option.getDefaultValueDouble() << std::endl; } - else if( option->getType() == "OptionRatio" ) + else if( option.getType() == avtranscoder::TypeRatio ) { - option->getDefaultValue( value2D ); - std::cout << "DefaultValue: " << value2D.first << ", " << value2D.second << std::endl; + std::cout << "DefaultValue: " << option.getDefaultValueRatio().first << ", " << option.getDefaultValueRatio().second << std::endl; } - else if( option->getType() == "OptionString" ) + else if( option.getType() == avtranscoder::TypeString ) { - std::cout << "DefaultValue: " << option->getDefaultValue( valueStr ) << std::endl; + std::cout << "DefaultValue: " << option.getDefaultValueString() << std::endl; } - else if( option->getType() == "OptionChoice" ) + else if( option.getType() == avtranscoder::TypeChoice ) { - std::cout << "DefaultValue: " << option->getDefaultValue( valueDouble ) << std::endl; - - avtranscoder::OptionChoice* choice = dynamic_cast( option ); - std::cout << "Nb choices: " << choice->getNbChoices() << std::endl; - std::cout << "Default choice index: " << choice->getDefaultChoiceIndex() << std::endl; - for(size_t i = 0; i < choice->getNbChoices(); ++i ) - std::cout << "Choice " << i << ": " << choice->getChoice( i ).first << " // " << choice->getChoice( i ).second << std::endl; + std::cout << "Nb choices: " << option.getNbChilds() << std::endl; + std::cout << "Default choice index: " << option.getDefaultChildIndex() << std::endl; + for(size_t i = 0; i < option.getNbChilds(); ++i ) + std::cout << "Choice " << i << ": " << + option.getChild( i ).getName() << " // " << + option.getChild( i ).getHelp() << std::endl; } - else if( option->getType() == "OptionGroup" ) + else if( option.getType() == avtranscoder::TypeGroup ) { - std::cout << "DefaultValue: " << option->getDefaultValue( valueInt ) << std::endl; - - avtranscoder::OptionGroup* group = dynamic_cast( option ); - std::cout << "Nb choices: " << group->getNbElements() << std::endl; - for(size_t i = 0; i < group->getNbElements(); ++i ) + std::cout << "Nb choices: " << option.getNbChilds() << std::endl; + for(size_t i = 0; i < option.getNbChilds(); ++i ) std::cout << "Element " << i << ": " << - group->getElement( i ).getName() << " // " << - group->getElement( i ).getDefaultValue( valueBool ) << std::endl; + option.getChild( i ).getName() << " // " << + option.getChild( i ).getDefaultValueBool() << std::endl; } } } @@ -109,4 +90,4 @@ int main( int argc, char** argv ) } std::cout << "end ..." << std::endl; -} \ No newline at end of file +} diff --git a/src/AvTranscoder/Option.cpp b/src/AvTranscoder/Option.cpp index 3645d1e9..d73f0713 100644 --- a/src/AvTranscoder/Option.cpp +++ b/src/AvTranscoder/Option.cpp @@ -1,41 +1,92 @@ #include "Option.hpp" -#include - namespace avtranscoder { -Option::Option( const AVOption& avOption ) - : m_name ( avOption.name ) - , m_help ( avOption.help ? avOption.help : "" ) - , m_unit ( avOption.unit ? avOption.unit : "" ) - , m_flags( avOption.flags ) +Option::Option( const AVOption& avOption, OptionType type ) + : m_avOption( avOption ) + , m_type( type ) + , m_options() + , m_defaultChildIndex( 0 ) +{ + +} + +OptionType Option::getTypeFromAVOption( const char* unit, AVOptionType avType ) +{ + if( unit && avType == AV_OPT_TYPE_FLAGS ) + return TypeGroup; + else if( unit && avType == AV_OPT_TYPE_INT ) + return TypeChoice; + else if( unit && avType == AV_OPT_TYPE_CONST ) + return TypeChild; + + switch( avType ) + { + case AV_OPT_TYPE_FLAGS: + { + return TypeBool; + } + case AV_OPT_TYPE_INT: + case AV_OPT_TYPE_INT64: + { + return TypeInt; + } + case AV_OPT_TYPE_DOUBLE: + case AV_OPT_TYPE_FLOAT: + { + return TypeDouble; + } + case AV_OPT_TYPE_STRING: + case AV_OPT_TYPE_BINARY: + { + return TypeString; + } + case AV_OPT_TYPE_RATIONAL: + { + return TypeRatio; + } + default: + { + return TypeUnknown; + } + } + return TypeUnknown; +} + +OptionType Option::getType() const +{ + return m_type; +} + +bool Option::getDefaultValueBool() const { + return m_avOption.default_val.i64; } -int Option::getDefaultValue( int& value ) const +int Option::getDefaultValueInt() const { - throw std::runtime_error( "Wrong access to getDefaultValue (int)." ); + return m_avOption.default_val.i64; } -double Option::getDefaultValue( double& value ) const +double Option::getDefaultValueDouble() const { - throw std::runtime_error( "Wrong access to getDefaultValue (double)." ); + return m_avOption.default_val.dbl; } -std::string& Option::getDefaultValue( std::string& value ) const +std::string Option::getDefaultValueString() const { - throw std::runtime_error( "Wrong access to getDefaultValue (char*)." ); + return std::string( m_avOption.default_val.str ? m_avOption.default_val.str : "" ); } -bool Option::getDefaultValue( bool& value ) const +std::pair Option::getDefaultValueRatio() const { - throw std::runtime_error( "Wrong access to getDefaultValue (bool)." ); + return std::pair( m_avOption.default_val.q.num, m_avOption.default_val.q.den ); } -std::pair& Option::getDefaultValue( std::pair& value ) const +void Option::appendChild( const Option& child ) { - throw std::runtime_error( "Wrong access to getDefaultValue (std::pair)." ); + m_options.push_back( child ); } } diff --git a/src/AvTranscoder/Option.hpp b/src/AvTranscoder/Option.hpp index 002432cc..c6a6c81d 100644 --- a/src/AvTranscoder/Option.hpp +++ b/src/AvTranscoder/Option.hpp @@ -9,46 +9,78 @@ extern "C" { } #include -#include #include #include //pair namespace avtranscoder { +enum OptionType { + TypeBool, + TypeInt, + TypeDouble, + TypeString, + TypeRatio, + TypeChoice, + TypeGroup, + + TypeChild, // Option which brelongs to Choice or Group + TypeUnknown +}; + /** - * @brief Abstract class to wrap AVOption. - * Subclasses implement specific AVOption: int, boolean... + * @brief Wrapper of AVOption. + * Get its type to know what the option is about: Int, Double, Ratio, Choice... + * Parse its array of options to get the potential childs (Choice and Group). */ class Option -{ +{ +public: + static OptionType getTypeFromAVOption( const char* unit, AVOptionType avType ); + public: - Option( const AVOption& avOption ); - virtual ~Option() {} - - virtual std::string getType() const = 0; - - virtual int getDefaultValue( int& value ) const; - virtual double getDefaultValue( double& value ) const; - virtual std::string& getDefaultValue( std::string& value ) const; - virtual bool getDefaultValue( bool& value ) const; - virtual std::pair& getDefaultValue( std::pair& value ) const; - - std::string& getName() { return m_name; } - std::string& getHelp() { return m_help; } - std::string& getUnit() { return m_unit; } - - bool isEncodingOpt(){ return m_flags & AV_OPT_FLAG_ENCODING_PARAM; } - bool isDecodingOpt(){ return m_flags & AV_OPT_FLAG_DECODING_PARAM; } - bool isAudioOpt(){ return m_flags & AV_OPT_FLAG_AUDIO_PARAM; } - bool isVideoOpt(){ return m_flags & AV_OPT_FLAG_VIDEO_PARAM; } - bool isSubtitleOpt(){ return m_flags & AV_OPT_FLAG_SUBTITLE_PARAM; } - -protected: - std::string m_name; - std::string m_help; - std::string m_unit; - int m_flags; + Option( const AVOption& avOption, OptionType type ); + ~Option() {} + + OptionType getType() const; + const std::string getName() { return std::string( m_avOption.name ? m_avOption.name : "" ); } + const std::string getHelp() { return std::string( m_avOption.help ? m_avOption.help : "" ); } + const std::string getUnit() { return std::string( m_avOption.unit ? m_avOption.unit : "" ); } + + // flags + int getFlags() { return m_avOption.flags; } + bool isEncodingOpt(){ return m_avOption.flags & AV_OPT_FLAG_ENCODING_PARAM; } + bool isDecodingOpt(){ return m_avOption.flags & AV_OPT_FLAG_DECODING_PARAM; } + bool isAudioOpt(){ return m_avOption.flags & AV_OPT_FLAG_AUDIO_PARAM; } + bool isVideoOpt(){ return m_avOption.flags & AV_OPT_FLAG_VIDEO_PARAM; } + bool isSubtitleOpt(){ return m_avOption.flags & AV_OPT_FLAG_SUBTITLE_PARAM; } + + // default value + bool getDefaultValueBool() const; + int getDefaultValueInt() const; + double getDefaultValueDouble() const; + std::string getDefaultValueString() const; + std::pair getDefaultValueRatio() const; + + // array of childs + bool hasChild() { return ! m_options.empty(); } + std::vector