diff --git a/app/SConscript b/app/SConscript index b423923f..3266c5e8 100644 --- a/app/SConscript +++ b/app/SConscript @@ -104,6 +104,20 @@ if platform.system() != 'Windows': ], ) +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/avInfo/avInfo.cpp b/app/avInfo/avInfo.cpp index e8829bba..909c84f3 100644 --- a/app/avInfo/avInfo.cpp +++ b/app/avInfo/avInfo.cpp @@ -1,12 +1,22 @@ #include -#include #include int main( int argc, char** argv ) { // std::cout << "avinfo" << std::endl; - std::vector inputExtension = getInputExtensions(); - std::vector outputExtension = getOutputExtensions(); + std::vector inputExtension = avtranscoder::getInputExtensions(); + std::vector outputExtension = avtranscoder::getOutputExtensions(); + + std::cout << "----- inputExtension -----" << std::endl; + std::cout << "nb inputExtension: " << inputExtension.size() << std::endl; + for( std::vector::iterator it = inputExtension.begin(); it != inputExtension.end(); ++it ) + std::cout << *it << std::endl; + + std::cout << "----- outputExtension -----" << std::endl; + std::cout << "nb outputExtension: " << outputExtension.size() << std::endl; + for( std::vector::iterator it = outputExtension.begin(); it != outputExtension.end(); ++it ) + std::cout << *it << std::endl; + return 0; } diff --git a/app/optionChecker/optionChecker.cpp b/app/optionChecker/optionChecker.cpp new file mode 100644 index 00000000..1aefbb78 --- /dev/null +++ b/app/optionChecker/optionChecker.cpp @@ -0,0 +1,86 @@ +#include +#include + +#include +#include +#include //pair + +int optionChecker( const std::string& inputfilename ) +{ + avtranscoder::OptionLoader optionLoader; + optionLoader.loadOptions( 0, 0 ); + + // display Options + for( auto option : optionLoader.getOptions() ) + { + std::cout << std::left; + std::cout << "****************************" << std::endl; + std::cout << "Name: " << option.getName() << std::endl; + std::cout << "Unit : " << option.getUnit() << std::endl; + std::cout << "Help: " << option.getHelp() << std::endl; + std::cout << "Type: " << option.getType() << std::endl; + + // get default value + + if( option.getType() == avtranscoder::TypeInt ) + { + std::cout << "DefaultValue: " << option.getDefaultValueInt() << std::endl; + } + else if( option.getType() == avtranscoder::TypeBool ) + { + std::cout << "DefaultValue: " << option.getDefaultValueBool() << std::endl; + } + else if( option.getType() == avtranscoder::TypeDouble ) + { + std::cout << "DefaultValue: " << option.getDefaultValueDouble() << std::endl; + } + else if( option.getType() == avtranscoder::TypeRatio ) + { + std::cout << "DefaultValue: " << option.getDefaultValueRatio().first << ", " << option.getDefaultValueRatio().second << std::endl; + } + else if( option.getType() == avtranscoder::TypeString ) + { + std::cout << "DefaultValue: " << option.getDefaultValueString() << std::endl; + } + else if( option.getType() == avtranscoder::TypeChoice ) + { + 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() == avtranscoder::TypeGroup ) + { + std::cout << "Nb choices: " << option.getNbChilds() << std::endl; + for(size_t i = 0; i < option.getNbChilds(); ++i ) + std::cout << "Element " << i << ": " << + option.getChild( i ).getName() << " // " << + option.getChild( i ).getDefaultValueBool() << std::endl; + } + } +} + +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; +} diff --git a/src/AvTranscoder/Description.hpp b/src/AvTranscoder/Description.hpp index 73d80b1b..4e964e2f 100644 --- a/src/AvTranscoder/Description.hpp +++ b/src/AvTranscoder/Description.hpp @@ -11,6 +11,10 @@ extern "C" { #include #include +#include //sort, unique + +namespace avtranscoder +{ std::vector getVersion() { @@ -33,8 +37,19 @@ std::vector getInputExtensions() { if( iFormat->extensions != NULL ) { - char* ext = const_cast( iFormat->extensions ); - + // parse extensions + std::string exts = std::string( iFormat->extensions ); + char* ext = strtok( const_cast( exts.c_str() ), "," ); + while( ext != NULL ) + { + extensions.push_back( std::string( ext ) ); + ext = strtok( NULL, "," ); + } + + // parse name (name's format defines (in general) extensions ) + // don't need to do it in recent LibAV/FFMpeg versions + exts = std::string( iFormat->name ); + ext = strtok( const_cast( exts.c_str() ), "," ); while( ext != NULL ) { extensions.push_back( std::string( ext ) ); @@ -42,17 +57,54 @@ std::vector getInputExtensions() } } } + // sort + std::sort( extensions.begin(), extensions.end() ); + // suppress duplicates + std::vector::iterator last = std::unique( extensions.begin(), extensions.end() ); + extensions.erase( last, extensions.end() ); + return extensions; } std::vector getOutputExtensions() { + av_register_all(); std::vector extensions; + AVOutputFormat* oFormat = NULL; + while( ( oFormat = av_oformat_next( oFormat ) ) ) + { + if( oFormat->extensions != NULL ) + { + // parse extensions + std::string exts = std::string( oFormat->extensions ); + char* ext = strtok( const_cast( exts.c_str() ), "," ); + while( ext != NULL ) + { + extensions.push_back( std::string( ext ) ); + ext = strtok( NULL, "," ); + } + + // parse name (name's format defines (in general) extensions ) + // don't need to do it in recent LibAV/FFMpeg versions + exts = std::string( oFormat->name ); + ext = strtok( const_cast( exts.c_str() ), "," ); + while( ext != NULL ) + { + extensions.push_back( std::string( ext ) ); + ext = strtok( NULL, "," ); + } + } + } + // sort + std::sort( extensions.begin(), extensions.end() ); + // suppress duplicates + std::vector::iterator last = std::unique( extensions.begin(), extensions.end() ); + extensions.erase( last, extensions.end() ); + return extensions; } - +} #endif - 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: - }; } diff --git a/src/AvTranscoder/Option.cpp b/src/AvTranscoder/Option.cpp new file mode 100644 index 00000000..d73f0713 --- /dev/null +++ b/src/AvTranscoder/Option.cpp @@ -0,0 +1,92 @@ +#include "Option.hpp" + +namespace avtranscoder +{ + +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::getDefaultValueInt() const +{ + return m_avOption.default_val.i64; +} + +double Option::getDefaultValueDouble() const +{ + return m_avOption.default_val.dbl; +} + +std::string Option::getDefaultValueString() const +{ + return std::string( m_avOption.default_val.str ? m_avOption.default_val.str : "" ); +} + +std::pair Option::getDefaultValueRatio() const +{ + return std::pair( m_avOption.default_val.q.num, m_avOption.default_val.q.den ); +} + +void Option::appendChild( const Option& child ) +{ + m_options.push_back( child ); +} + +} diff --git a/src/AvTranscoder/Option.hpp b/src/AvTranscoder/Option.hpp new file mode 100644 index 00000000..376099c2 --- /dev/null +++ b/src/AvTranscoder/Option.hpp @@ -0,0 +1,90 @@ +#ifndef _AV_TRANSCODER_OPTION_HPP +#define _AV_TRANSCODER_OPTION_HPP + +extern "C" { +#ifndef __STDC_CONSTANT_MACROS + #define __STDC_CONSTANT_MACROS +#endif +#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 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, OptionType type ); + ~Option() {} + + OptionType getType() const; + std::string getName() const { return std::string( m_avOption.name ? m_avOption.name : "" ); } + std::string getHelp() const { return std::string( m_avOption.help ? m_avOption.help : "" ); } + std::string getUnit() const { return std::string( m_avOption.unit ? m_avOption.unit : "" ); } + int getOffset() const { return m_avOption.offset; } + + // flags + int getFlags() const { return m_avOption.flags; } + bool isEncodingOpt() const { return m_avOption.flags & AV_OPT_FLAG_ENCODING_PARAM; } + bool isDecodingOpt() const { return m_avOption.flags & AV_OPT_FLAG_DECODING_PARAM; } + bool isAudioOpt() const { return m_avOption.flags & AV_OPT_FLAG_AUDIO_PARAM; } + bool isVideoOpt() const { return m_avOption.flags & AV_OPT_FLAG_VIDEO_PARAM; } + bool isSubtitleOpt() const { 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() const { return ! m_options.empty(); } + const std::vector