Skip to content

Commit 4f9988f

Browse files
author
Clement Champetier
committed
CodecContext has a link to an AVCodecContext
1 parent b88569e commit 4f9988f

File tree

4 files changed

+14
-26
lines changed

4 files changed

+14
-26
lines changed

app/optionChecker/optionChecker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ void optionChecker( const std::string& inputfilename )
7373
displayOptions( formatOptions );
7474

7575
// codec options
76-
avtranscoder::CodecContext codecContext( AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM );
76+
AVCodecContext* avCodecContext = avcodec_alloc_context3( NULL );
77+
avtranscoder::CodecContext codecContext( *avCodecContext, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM );
7778
std::vector<avtranscoder::Option> codecOptions = codecContext.getOptions();
7879
displayOptions( codecOptions );
7980

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

3-
extern "C" {
4-
#include <libavcodec/avcodec.h>
5-
#include <libavutil/mem.h>
6-
}
7-
83
namespace avtranscoder
94
{
105

11-
CodecContext::CodecContext( int req_flags )
12-
: _avCodecContext( NULL )
13-
{
14-
_avCodecContext = avcodec_alloc_context3( NULL );
15-
loadOptions( _avCodecContext, req_flags );
16-
}
17-
18-
CodecContext::~CodecContext()
19-
{
20-
avcodec_close( _avCodecContext );
21-
av_free( _avCodecContext );
22-
}
6+
CodecContext::CodecContext( AVCodecContext& avCodecContext, int req_flags )
7+
: Context( &avCodecContext, req_flags )
8+
{}
239

2410
}

src/AvTranscoder/option/CodecContext.hpp

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

44
#include "Context.hpp"
55

6-
struct AVCodecContext;
6+
extern "C" {
7+
#include <libavcodec/avcodec.h>
8+
}
79

810
namespace avtranscoder
911
{
1012

1113
/**
1214
* @brief Wrapper of an AVCodecContext.
13-
* @note The AVCodecContext is allocated and free by the class. It is not the case of the base class.
1415
*/
1516
class AvExport CodecContext : public Context
1617
{
1718
public:
18-
CodecContext( int req_flags = 0 );
19-
~CodecContext();
20-
21-
private:
22-
AVCodecContext* _avCodecContext;
19+
CodecContext( AVCodecContext& avCodecContext, int req_flags = 0 );
20+
21+
#ifndef SWIG
22+
AVCodecContext& getAVCodecContext() const { return *static_cast<AVCodecContext*>( _avContext ); }
23+
#endif
2324
};
2425

2526
}

src/AvTranscoder/option/Context.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AvExport Context
4848
protected:
4949
void loadOptions( void* av_class, int req_flags );
5050

51-
private:
51+
protected:
5252
OptionMap _options;
5353
void* _avContext; ///< Has link (no ownership)
5454
};

0 commit comments

Comments
 (0)