Skip to content

Commit 5ca4839

Browse files
author
Clement Champetier
committed
FormatContext has a link to an AVFormatContext
1 parent 4f9988f commit 5ca4839

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

app/optionChecker/optionChecker.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <AvTranscoder/util.hpp>
22
#include <AvTranscoder/option/Context.hpp>
3+
#include "AvTranscoder/option/FormatContext.hpp"
34
#include <AvTranscoder/option/CodecContext.hpp>
45
#include <AvTranscoder/option/Option.hpp>
56
#include <AvTranscoder/file/InputFile.hpp>
@@ -68,7 +69,8 @@ void optionChecker( const std::string& inputfilename )
6869
avtranscoder::InputFile file( inputfilename );
6970

7071
// format options
71-
avtranscoder::Context formatContext( &file.getAVFormatContext() );
72+
AVFormatContext* avFormatContext = avformat_alloc_context();
73+
avtranscoder::FormatContext formatContext( *avFormatContext );
7274
std::vector<avtranscoder::Option> formatOptions = formatContext.getOptions();
7375
displayOptions( formatOptions );
7476

src/AvTranscoder/option/Context.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace avtranscoder
1212
{
1313

1414
typedef std::vector<Option> OptionArray;
15-
typedef std::map<std::string, Option> OptionMap;
15+
typedef std::map<std::string, Option> OptionMap; ///< Key: option name / value: option
1616

1717
/**
1818
* @brief Wrapper of AVContext.
@@ -40,8 +40,8 @@ class AvExport Context
4040
loadOptions( avContext, req_flags );
4141
}
4242

43-
OptionArray getOptions();
44-
OptionMap& getOptionsMap() { return _options; }
43+
OptionArray getOptions(); ///< Get options as array
44+
OptionMap& getOptionsMap() { return _options; } ///< Get options as map
4545

4646
Option& getOption( const std::string& optionName ) { return _options.at(optionName); }
4747

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
#include "FormatContext.hpp"
22

3-
extern "C" {
4-
#include <libavformat/avformat.h>
5-
}
6-
73
namespace avtranscoder
84
{
95

10-
FormatContext::FormatContext( int req_flags )
11-
: _avFormatContext( NULL )
12-
{
13-
_avFormatContext = avformat_alloc_context();
14-
loadOptions( _avFormatContext, req_flags );
15-
}
16-
17-
FormatContext::~FormatContext()
18-
{
19-
avformat_free_context( _avFormatContext );
20-
}
6+
FormatContext::FormatContext( AVFormatContext& avFormatContext, int req_flags )
7+
: Context( &avFormatContext, req_flags )
8+
{}
219

2210
}

src/AvTranscoder/option/FormatContext.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33

44
#include "Context.hpp"
55

6-
struct AVFormatContext;
6+
extern "C" {
7+
#include <libavformat/avformat.h>
8+
}
79

810
namespace avtranscoder
911
{
1012

1113
/**
1214
* @brief Wrapper of an AVFormatContext.
13-
* @note The AVFormatContext is allocated and free by the class. It is not the case of the base class.
1415
*/
1516
class FormatContext : public Context
1617
{
1718
public:
18-
FormatContext( int req_flags = 0 );
19-
~FormatContext();
19+
FormatContext( AVFormatContext& avFormatContext, int req_flags = 0 );
2020

21-
private:
22-
AVFormatContext* _avFormatContext;
21+
#ifndef SWIG
22+
AVFormatContext& getAVFormatContext() const { return *static_cast<AVFormatContext*>( _avContext ); }
23+
#endif
2324
};
2425

2526
}

0 commit comments

Comments
 (0)