Skip to content

Commit f1824d7

Browse files
committed
Merge pull request #162 from cchampet/fix_utilFunctions
Fix util functions
2 parents c67abcb + b826dc2 commit f1824d7

File tree

1 file changed

+39
-68
lines changed

1 file changed

+39
-68
lines changed

src/AvTranscoder/util.cpp

Lines changed: 39 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern "C" {
77
}
88

99
#include <utility>
10+
#include <algorithm>
1011

1112
namespace avtranscoder
1213
{
@@ -144,25 +145,18 @@ NamesArray getVideoCodecsNames()
144145
AVCodec* c = NULL;
145146
while( ( c = av_codec_next( c ) ) != NULL )
146147
{
147-
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
148-
if( ! c->encode )
149-
continue;
150-
#else
151-
if( ! c->encode2 )
152-
continue;
153-
#endif
154-
switch( c->type )
148+
if( c->type == AVMEDIA_TYPE_VIDEO)
155149
{
156-
case AVMEDIA_TYPE_VIDEO:
157-
{
158-
if( ! c->name && ! c->long_name )
159-
continue;
150+
if( ! c->name && ! c->long_name )
151+
continue;
160152

161-
videoCodecsNames.push_back( std::make_pair( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) ) );
162-
break;
163-
}
164-
default:
165-
break;
153+
std::pair< std::string, std::string > codecNames( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) );
154+
155+
// skip duplicates
156+
if( std::find( videoCodecsNames.begin(), videoCodecsNames.end(), codecNames ) != videoCodecsNames.end() )
157+
continue;
158+
159+
videoCodecsNames.push_back( codecNames );
166160
}
167161
}
168162
return videoCodecsNames;
@@ -175,35 +169,26 @@ NamesArray getAudioCodecsNames()
175169
AVCodec* c = NULL;
176170
while( ( c = av_codec_next( c ) ) != NULL )
177171
{
178-
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
179-
if( ! c->encode )
180-
continue;
181-
#else
182-
if( ! c->encode2 )
183-
continue;
184-
#endif
185-
switch( c->type )
172+
if( c->type == AVMEDIA_TYPE_AUDIO )
186173
{
187-
case AVMEDIA_TYPE_AUDIO:
188-
{
189-
if( ! c->name && ! c->long_name )
190-
continue;
174+
if( ! c->name && ! c->long_name )
175+
continue;
191176

192-
audioCodecsNames.push_back( std::make_pair( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) ) );
193-
break;
194-
}
195-
default:
196-
break;
177+
std::pair< std::string, std::string > codecNames( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) );
178+
179+
// skip duplicates
180+
if( std::find( audioCodecsNames.begin(), audioCodecsNames.end(), codecNames ) != audioCodecsNames.end() )
181+
continue;
182+
183+
audioCodecsNames.push_back( codecNames );
197184
}
198185
}
199186
return audioCodecsNames;
200187
}
201188

202189
OptionArrayMap getOutputFormatOptions()
203190
{
204-
av_register_all();
205-
206-
std::map< std::string, std::vector<Option> > optionsPerFormat;
191+
OptionArrayMap optionsPerFormat;
207192

208193
AVOutputFormat* outputFormat = av_oformat_next( NULL );
209194

@@ -216,7 +201,7 @@ OptionArrayMap getOutputFormatOptions()
216201
{
217202
if( outputFormat->priv_class )
218203
{
219-
std::string outputFormatName( outputFormat->name );
204+
const std::string outputFormatName( outputFormat->name );
220205
OptionArray options;
221206
loadOptions( options, (void*)&outputFormat->priv_class, 0 );
222207
optionsPerFormat.insert( std::make_pair( outputFormatName, options ) );
@@ -229,29 +214,22 @@ OptionArrayMap getOutputFormatOptions()
229214

230215
OptionArrayMap getVideoCodecOptions()
231216
{
232-
std::map< std::string, std::vector<Option> > videoCodecOptions;
217+
OptionArrayMap videoCodecOptions;
233218

234219
AVCodec* codec = av_codec_next( NULL );
235220

236221
// iterate on codecs
237222
while( codec )
238223
{
239-
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
240-
if( codec->encode )
241-
#else
242-
if( codec->encode2 )
243-
#endif
224+
// add only video codec
225+
if( codec->type == AVMEDIA_TYPE_VIDEO )
244226
{
245-
// add only video codec
246-
if( codec->type == AVMEDIA_TYPE_VIDEO )
227+
if( codec->priv_class )
247228
{
248-
if( codec->priv_class )
249-
{
250-
std::string videoCodecName( codec->name );
251-
OptionArray options;
252-
loadOptions( options, (void*)&codec->priv_class, 0 );
253-
videoCodecOptions.insert( std::make_pair( videoCodecName, options ) );
254-
}
229+
std::string videoCodecName( codec->name );
230+
OptionArray options;
231+
loadOptions( options, (void*)&codec->priv_class, 0 );
232+
videoCodecOptions.insert( std::make_pair( videoCodecName, options ) );
255233
}
256234
}
257235
codec = av_codec_next( codec );
@@ -261,29 +239,22 @@ OptionArrayMap getVideoCodecOptions()
261239

262240
OptionArrayMap getAudioCodecOptions()
263241
{
264-
std::map< std::string, std::vector<Option> > audioCodecOptions;
242+
OptionArrayMap audioCodecOptions;
265243

266244
AVCodec* codec = av_codec_next( NULL );
267245

268246
// iterate on codecs
269247
while( codec )
270248
{
271-
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
272-
if( codec->encode )
273-
#else
274-
if( codec->encode2 )
275-
#endif
249+
// add only audio codec
250+
if( codec->type == AVMEDIA_TYPE_AUDIO )
276251
{
277-
// add only audio codec
278-
if( codec->type == AVMEDIA_TYPE_AUDIO )
252+
if( codec->priv_class )
279253
{
280-
if( codec->priv_class )
281-
{
282-
std::string audioCodecName( codec->name );
283-
OptionArray options;
284-
loadOptions( options, (void*)&codec->priv_class, 0 );
285-
audioCodecOptions.insert( std::make_pair( audioCodecName, options ) );
286-
}
254+
std::string audioCodecName( codec->name );
255+
OptionArray options;
256+
loadOptions( options, (void*)&codec->priv_class, 0 );
257+
audioCodecOptions.insert( std::make_pair( audioCodecName, options ) );
287258
}
288259
}
289260
codec = av_codec_next( codec );

0 commit comments

Comments
 (0)