Skip to content

Commit 163210e

Browse files
author
Clement Champetier
committed
OptionLoader: add format and codec context attributes
* In loadOptions function, choose what ffmpeg / libav object on which we'll scan AVOption: avFormat or avCodec. * Update OptionChecker app: no need to get a codecContext from the audioDesc of a stream of an InputFile !
1 parent 6bc55f5 commit 163210e

File tree

3 files changed

+58
-15
lines changed

3 files changed

+58
-15
lines changed

app/optionChecker/optionChecker.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
#include <AvTranscoder/InputFile.hpp>
2-
#include <AvTranscoder/DatasStructures/AudioDesc.hpp>
3-
41
#include <AvTranscoder/OptionLoader.hpp>
2+
#include <AvTranscoder/Option.hpp>
53

64
#include <string>
75
#include <iostream>
86
#include <utility> //pair
97

108
int optionChecker( const std::string& inputfilename )
11-
{
12-
avtranscoder::InputFile inputFile( inputfilename );
13-
inputFile.analyse();
14-
15-
avtranscoder::AudioDesc audioDesc( inputFile.getStream( 0 ).getAudioDesc() );
16-
9+
{
1710
avtranscoder::OptionLoader optionLoader;
18-
optionLoader.loadOptions( audioDesc.getCodecContext(), 0, 0 );
11+
optionLoader.loadOptions( 0, 0 );
1912

2013
// display Options
2114
for( auto option : optionLoader.getOptions() )

src/AvTranscoder/OptionLoader.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,49 @@ namespace avtranscoder
1717

1818
OptionLoader::OptionLoader()
1919
: m_options()
20+
, m_avFormatContext( NULL )
21+
, m_avCodecContext( NULL )
2022
{
23+
m_avFormatContext = avformat_alloc_context();
2124

25+
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 8, 0 )
26+
m_avCodecContext = avcodec_alloc_context();
27+
// deprecated in the same version
28+
//m_avCodecContext = avcodec_alloc_context2( AVMEDIA_TYPE_UNKNOWN );
29+
#else
30+
AVCodec* avCodec = NULL;
31+
m_avCodecContext = avcodec_alloc_context3( avCodec );
32+
#endif
33+
}
34+
35+
OptionLoader::~OptionLoader()
36+
{
37+
avformat_free_context( m_avFormatContext );
38+
avcodec_close( m_avCodecContext );
2239
}
2340

24-
void OptionLoader::loadOptions( void* av_class, int req_flags, int rej_flags )
41+
void OptionLoader::loadOptions( int req_flags, int rej_flags )
2542
{
2643
std::map<std::string, int> optionUnitToIndex;
2744
std::vector<Option> childOptions;
2845

2946
const AVOption* avOption = NULL;
30-
47+
48+
// get ffmpeg / libav object on which we'll scan AVOption
49+
void* av_class = NULL;
50+
if( ( req_flags & AV_OPT_FLAG_VIDEO_PARAM ) == AV_OPT_FLAG_VIDEO_PARAM ||
51+
( req_flags & AV_OPT_FLAG_AUDIO_PARAM ) == AV_OPT_FLAG_AUDIO_PARAM ||
52+
( req_flags & AV_OPT_FLAG_METADATA ) == AV_OPT_FLAG_METADATA ||
53+
( req_flags & AV_OPT_FLAG_FILTERING_PARAM ) == AV_OPT_FLAG_FILTERING_PARAM ||
54+
( req_flags & AV_OPT_FLAG_SUBTITLE_PARAM ) == AV_OPT_FLAG_SUBTITLE_PARAM )
55+
{
56+
av_class = (void*)m_avCodecContext;
57+
}
58+
else
59+
{
60+
av_class = (void*)m_avFormatContext;
61+
}
62+
3163
// iterate on options
3264
while( ( avOption = av_opt_next( av_class, avOption ) ) != NULL )
3365
{
@@ -65,7 +97,7 @@ void OptionLoader::loadOptions( void* av_class, int req_flags, int rej_flags )
6597

6698
m_options.at( indexParentOption ).appendChild( *it );
6799

68-
// child to a Choice
100+
// child of a Choice
69101
if( m_options.at( indexParentOption ).getType() == TypeChoice )
70102
{
71103
if( it->getDefaultValueInt() == m_options.at( indexParentOption ).getDefaultValueInt() )

src/AvTranscoder/OptionLoader.hpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
#include <AvTranscoder/Option.hpp>
55

6+
extern "C" {
7+
#ifndef __STDC_CONSTANT_MACROS
8+
#define __STDC_CONSTANT_MACROS
9+
#endif
10+
#include <libavcodec/avcodec.h>
11+
#include <libavformat/avformat.h>
12+
}
13+
614
#include <vector>
715

816
namespace avtranscoder
@@ -16,16 +24,26 @@ class OptionLoader
1624
{
1725
public:
1826
OptionLoader();
27+
~OptionLoader();
1928

2029
std::vector<Option>& getOptions() { return m_options; }
2130

31+
const AVFormatContext* getFormatContext() const { return m_avFormatContext; }
32+
const AVCodecContext* getCodecContext() const { return m_avCodecContext; }
33+
2234
/**
23-
* @param av_class: a libav / ffmpeg object which contains AVOption.
35+
* @brief: load array of Option depending on the flags.
36+
* @param req_flags
37+
* @param rej_flags
2438
*/
25-
void loadOptions( void* av_class, int req_flags, int rej_flags );
39+
void loadOptions( int req_flags, int rej_flags );
2640

2741
private:
2842
std::vector<Option> m_options;
43+
44+
AVFormatContext* m_avFormatContext;
45+
AVCodecContext* m_avCodecContext;
46+
2947
};
3048

3149
}

0 commit comments

Comments
 (0)