Skip to content

Commit da88461

Browse files
Merge pull request #7 from cchampet/dev_audioProcessing
Add Options
2 parents 5f2a237 + d2bbcf8 commit da88461

File tree

11 files changed

+515
-15
lines changed

11 files changed

+515
-15
lines changed

app/SConscript

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ if platform.system() != 'Windows':
111111
],
112112
)
113113

114+
avprofiles = env.Program(
115+
'avoptions',
116+
Glob( 'optionChecker/*.cpp' ),
117+
LIBS = [
118+
sAvTranscoder,
119+
'avutil',
120+
'avformat',
121+
'avcodec'
122+
],
123+
CXXFLAGS = [
124+
'-std=c++0x'
125+
],
126+
)
127+
114128
env.Depends( avmeta, sAvTranscoder )
115129
env.Depends( audioRewrapper, sAvTranscoder )
116130

app/avInfo/avInfo.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
#include <iostream>
2-
#include <iomanip>
32

43
#include <AvTranscoder/Description.hpp>
54

65
int main( int argc, char** argv )
76
{
87
// std::cout << "avinfo" << std::endl;
9-
std::vector<std::string> inputExtension = getInputExtensions();
10-
std::vector<std::string> outputExtension = getOutputExtensions();
8+
std::vector<std::string> inputExtension = avtranscoder::getInputExtensions();
9+
std::vector<std::string> outputExtension = avtranscoder::getOutputExtensions();
10+
11+
std::cout << "----- inputExtension -----" << std::endl;
12+
std::cout << "nb inputExtension: " << inputExtension.size() << std::endl;
13+
for( std::vector<std::string>::iterator it = inputExtension.begin(); it != inputExtension.end(); ++it )
14+
std::cout << *it << std::endl;
15+
16+
std::cout << "----- outputExtension -----" << std::endl;
17+
std::cout << "nb outputExtension: " << outputExtension.size() << std::endl;
18+
for( std::vector<std::string>::iterator it = outputExtension.begin(); it != outputExtension.end(); ++it )
19+
std::cout << *it << std::endl;
20+
1121
return 0;
1222
}

app/optionChecker/optionChecker.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include <AvTranscoder/OptionLoader.hpp>
2+
#include <AvTranscoder/Option.hpp>
3+
4+
#include <string>
5+
#include <iostream>
6+
#include <utility> //pair
7+
8+
int optionChecker( const std::string& inputfilename )
9+
{
10+
avtranscoder::OptionLoader optionLoader;
11+
optionLoader.loadOptions( 0, 0 );
12+
13+
// display Options
14+
for( auto option : optionLoader.getOptions() )
15+
{
16+
std::cout << std::left;
17+
std::cout << "****************************" << std::endl;
18+
std::cout << "Name: " << option.getName() << std::endl;
19+
std::cout << "Unit : " << option.getUnit() << std::endl;
20+
std::cout << "Help: " << option.getHelp() << std::endl;
21+
std::cout << "Type: " << option.getType() << std::endl;
22+
23+
// get default value
24+
25+
if( option.getType() == avtranscoder::TypeInt )
26+
{
27+
std::cout << "DefaultValue: " << option.getDefaultValueInt() << std::endl;
28+
}
29+
else if( option.getType() == avtranscoder::TypeBool )
30+
{
31+
std::cout << "DefaultValue: " << option.getDefaultValueBool() << std::endl;
32+
}
33+
else if( option.getType() == avtranscoder::TypeDouble )
34+
{
35+
std::cout << "DefaultValue: " << option.getDefaultValueDouble() << std::endl;
36+
}
37+
else if( option.getType() == avtranscoder::TypeRatio )
38+
{
39+
std::cout << "DefaultValue: " << option.getDefaultValueRatio().first << ", " << option.getDefaultValueRatio().second << std::endl;
40+
}
41+
else if( option.getType() == avtranscoder::TypeString )
42+
{
43+
std::cout << "DefaultValue: " << option.getDefaultValueString() << std::endl;
44+
}
45+
else if( option.getType() == avtranscoder::TypeChoice )
46+
{
47+
std::cout << "Nb choices: " << option.getNbChilds() << std::endl;
48+
std::cout << "Default choice index: " << option.getDefaultChildIndex() << std::endl;
49+
for(size_t i = 0; i < option.getNbChilds(); ++i )
50+
std::cout << "Choice " << i << ": " <<
51+
option.getChild( i ).getName() << " // " <<
52+
option.getChild( i ).getHelp() << std::endl;
53+
}
54+
else if( option.getType() == avtranscoder::TypeGroup )
55+
{
56+
std::cout << "Nb choices: " << option.getNbChilds() << std::endl;
57+
for(size_t i = 0; i < option.getNbChilds(); ++i )
58+
std::cout << "Element " << i << ": " <<
59+
option.getChild( i ).getName() << " // " <<
60+
option.getChild( i ).getDefaultValueBool() << std::endl;
61+
}
62+
}
63+
}
64+
65+
int main( int argc, char** argv )
66+
{
67+
if( argc <= 1 )
68+
{
69+
std::cout << "audiorewrapper require a media filename" << std::endl;
70+
std::cout << "example: audioWrap file.ext" << std::endl;
71+
return( -1 );
72+
}
73+
74+
std::cout << "start ..." << std::endl;
75+
76+
try
77+
{
78+
optionChecker( argv[1] );
79+
}
80+
catch( std::exception &e )
81+
{
82+
std::cout << "[ERROR] " << e.what() << std::endl;
83+
}
84+
85+
std::cout << "end ..." << std::endl;
86+
}

src/AvTranscoder/Description.hpp

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ extern "C" {
1111

1212
#include <vector>
1313
#include <cstring>
14+
#include <algorithm> //sort, unique
15+
16+
namespace avtranscoder
17+
{
1418

1519
std::vector<size_t> getVersion()
1620
{
@@ -33,26 +37,74 @@ std::vector<std::string> getInputExtensions()
3337
{
3438
if( iFormat->extensions != NULL )
3539
{
36-
char* ext = const_cast<char*>( iFormat->extensions );
37-
40+
// parse extensions
41+
std::string exts = std::string( iFormat->extensions );
42+
char* ext = strtok( const_cast<char*>( exts.c_str() ), "," );
43+
while( ext != NULL )
44+
{
45+
extensions.push_back( std::string( ext ) );
46+
ext = strtok( NULL, "," );
47+
}
48+
49+
// parse name (name's format defines (in general) extensions )
50+
// don't need to do it in recent LibAV/FFMpeg versions
51+
exts = std::string( iFormat->name );
52+
ext = strtok( const_cast<char*>( exts.c_str() ), "," );
3853
while( ext != NULL )
3954
{
4055
extensions.push_back( std::string( ext ) );
4156
ext = strtok( NULL, "," );
4257
}
4358
}
4459
}
60+
// sort
61+
std::sort( extensions.begin(), extensions.end() );
62+
// suppress duplicates
63+
std::vector<std::string>::iterator last = std::unique( extensions.begin(), extensions.end() );
64+
extensions.erase( last, extensions.end() );
65+
4566
return extensions;
4667
}
4768

4869
std::vector<std::string> getOutputExtensions()
4970
{
71+
av_register_all();
5072
std::vector<std::string> extensions;
73+
AVOutputFormat* oFormat = NULL;
5174

75+
while( ( oFormat = av_oformat_next( oFormat ) ) )
76+
{
77+
if( oFormat->extensions != NULL )
78+
{
79+
// parse extensions
80+
std::string exts = std::string( oFormat->extensions );
81+
char* ext = strtok( const_cast<char*>( exts.c_str() ), "," );
82+
while( ext != NULL )
83+
{
84+
extensions.push_back( std::string( ext ) );
85+
ext = strtok( NULL, "," );
86+
}
87+
88+
// parse name (name's format defines (in general) extensions )
89+
// don't need to do it in recent LibAV/FFMpeg versions
90+
exts = std::string( oFormat->name );
91+
ext = strtok( const_cast<char*>( exts.c_str() ), "," );
92+
while( ext != NULL )
93+
{
94+
extensions.push_back( std::string( ext ) );
95+
ext = strtok( NULL, "," );
96+
}
97+
}
98+
}
99+
// sort
100+
std::sort( extensions.begin(), extensions.end() );
101+
// suppress duplicates
102+
std::vector<std::string>::iterator last = std::unique( extensions.begin(), extensions.end() );
103+
extensions.erase( last, extensions.end() );
104+
52105
return extensions;
53106
}
54107

55-
108+
}
56109

57110
#endif
58-

src/AvTranscoder/InputStream.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ namespace avtranscoder
1111
class InputStream
1212
{
1313
public:
14-
InputStream( )
15-
{}
14+
InputStream() {}
1615

17-
virtual ~InputStream(){};
16+
virtual ~InputStream() {};
1817

1918
virtual size_t getStreamIndex() const = 0;
2019

src/AvTranscoder/InputStreamAudio.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ class AvExport InputStreamAudio
2424
AVFrame* m_frame;
2525

2626
int m_selectedStream;
27-
28-
private:
29-
3027
};
3128

3229
}

src/AvTranscoder/Option.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#include "Option.hpp"
2+
3+
namespace avtranscoder
4+
{
5+
6+
Option::Option( const AVOption& avOption, OptionType type )
7+
: m_avOption( avOption )
8+
, m_type( type )
9+
, m_options()
10+
, m_defaultChildIndex( 0 )
11+
{
12+
13+
}
14+
15+
OptionType Option::getTypeFromAVOption( const char* unit, AVOptionType avType )
16+
{
17+
if( unit && avType == AV_OPT_TYPE_FLAGS )
18+
return TypeGroup;
19+
else if( unit && avType == AV_OPT_TYPE_INT )
20+
return TypeChoice;
21+
else if( unit && avType == AV_OPT_TYPE_CONST )
22+
return TypeChild;
23+
24+
switch( avType )
25+
{
26+
case AV_OPT_TYPE_FLAGS:
27+
{
28+
return TypeBool;
29+
}
30+
case AV_OPT_TYPE_INT:
31+
case AV_OPT_TYPE_INT64:
32+
{
33+
return TypeInt;
34+
}
35+
case AV_OPT_TYPE_DOUBLE:
36+
case AV_OPT_TYPE_FLOAT:
37+
{
38+
return TypeDouble;
39+
}
40+
case AV_OPT_TYPE_STRING:
41+
case AV_OPT_TYPE_BINARY:
42+
{
43+
return TypeString;
44+
}
45+
case AV_OPT_TYPE_RATIONAL:
46+
{
47+
return TypeRatio;
48+
}
49+
default:
50+
{
51+
return TypeUnknown;
52+
}
53+
}
54+
return TypeUnknown;
55+
}
56+
57+
OptionType Option::getType() const
58+
{
59+
return m_type;
60+
}
61+
62+
bool Option::getDefaultValueBool() const
63+
{
64+
return m_avOption.default_val.i64;
65+
}
66+
67+
int Option::getDefaultValueInt() const
68+
{
69+
return m_avOption.default_val.i64;
70+
}
71+
72+
double Option::getDefaultValueDouble() const
73+
{
74+
return m_avOption.default_val.dbl;
75+
}
76+
77+
std::string Option::getDefaultValueString() const
78+
{
79+
return std::string( m_avOption.default_val.str ? m_avOption.default_val.str : "" );
80+
}
81+
82+
std::pair<int, int> Option::getDefaultValueRatio() const
83+
{
84+
return std::pair<int, int>( m_avOption.default_val.q.num, m_avOption.default_val.q.den );
85+
}
86+
87+
void Option::appendChild( const Option& child )
88+
{
89+
m_options.push_back( child );
90+
}
91+
92+
}

0 commit comments

Comments
 (0)