Skip to content

Add Options #7

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jun 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down
16 changes: 13 additions & 3 deletions app/avInfo/avInfo.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#include <iostream>
#include <iomanip>

#include <AvTranscoder/Description.hpp>

int main( int argc, char** argv )
{
// std::cout << "avinfo" << std::endl;
std::vector<std::string> inputExtension = getInputExtensions();
std::vector<std::string> outputExtension = getOutputExtensions();
std::vector<std::string> inputExtension = avtranscoder::getInputExtensions();
std::vector<std::string> outputExtension = avtranscoder::getOutputExtensions();

std::cout << "----- inputExtension -----" << std::endl;
std::cout << "nb inputExtension: " << inputExtension.size() << std::endl;
for( std::vector<std::string>::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<std::string>::iterator it = outputExtension.begin(); it != outputExtension.end(); ++it )
std::cout << *it << std::endl;

return 0;
}
86 changes: 86 additions & 0 deletions app/optionChecker/optionChecker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <AvTranscoder/OptionLoader.hpp>
#include <AvTranscoder/Option.hpp>

#include <string>
#include <iostream>
#include <utility> //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;
}
60 changes: 56 additions & 4 deletions src/AvTranscoder/Description.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ extern "C" {

#include <vector>
#include <cstring>
#include <algorithm> //sort, unique

namespace avtranscoder
{

std::vector<size_t> getVersion()
{
Expand All @@ -33,26 +37,74 @@ std::vector<std::string> getInputExtensions()
{
if( iFormat->extensions != NULL )
{
char* ext = const_cast<char*>( iFormat->extensions );

// parse extensions
std::string exts = std::string( iFormat->extensions );
char* ext = strtok( const_cast<char*>( 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<char*>( 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<std::string>::iterator last = std::unique( extensions.begin(), extensions.end() );
extensions.erase( last, extensions.end() );

return extensions;
}

std::vector<std::string> getOutputExtensions()
{
av_register_all();
std::vector<std::string> 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<char*>( 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<char*>( 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<std::string>::iterator last = std::unique( extensions.begin(), extensions.end() );
extensions.erase( last, extensions.end() );

return extensions;
}


}

#endif

5 changes: 2 additions & 3 deletions src/AvTranscoder/InputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ namespace avtranscoder
class InputStream
{
public:
InputStream( )
{}
InputStream() {}

virtual ~InputStream(){};
virtual ~InputStream() {};

virtual size_t getStreamIndex() const = 0;

Expand Down
3 changes: 0 additions & 3 deletions src/AvTranscoder/InputStreamAudio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class AvExport InputStreamAudio
AVFrame* m_frame;

int m_selectedStream;

private:

};

}
Expand Down
92 changes: 92 additions & 0 deletions src/AvTranscoder/Option.cpp
Original file line number Diff line number Diff line change
@@ -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<int, int> Option::getDefaultValueRatio() const
{
return std::pair<int, int>( m_avOption.default_val.q.num, m_avOption.default_val.q.den );
}

void Option::appendChild( const Option& child )
{
m_options.push_back( child );
}

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add new line at the end of the file ...

Loading