File tree Expand file tree Collapse file tree 3 files changed +40
-6
lines changed Expand file tree Collapse file tree 3 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -73,8 +73,7 @@ void optionChecker( const std::string& inputfilename )
73
73
displayOptions ( formatOptions );
74
74
75
75
// codec options
76
- AVCodecContext* avCodecContext = avcodec_alloc_context3 ( NULL );
77
- avtranscoder::CodecContext codecContext ( *avCodecContext, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM );
76
+ avtranscoder::CodecContext codecContext ( AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM );
78
77
std::vector<avtranscoder::Option> codecOptions = codecContext.getOptions ();
79
78
displayOptions ( codecOptions );
80
79
Original file line number Diff line number Diff line change 1
1
#include " CodecContext.hpp"
2
2
3
+ #include < stdexcept>
4
+
3
5
namespace avtranscoder
4
6
{
5
7
6
- CodecContext::CodecContext ( AVCodecContext& avCodecContext, int req_flags )
7
- : Context( &avCodecContext, req_flags )
8
- {}
8
+ CodecContext::CodecContext ( AVCodec& avCodec, int req_flags )
9
+ : Context( NULL , req_flags )
10
+ {
11
+ _avContext = avcodec_alloc_context3 ( &avCodec );
12
+ if ( ! _avContext )
13
+ {
14
+ throw std::runtime_error ( " unable to allocate the codecContext and set its fields to default values" );
15
+ }
16
+
17
+ // Set default codec parameters
18
+ if ( avcodec_get_context_defaults3 ( &getAVCodecContext (), &avCodec ) != 0 )
19
+ {
20
+ throw std::runtime_error ( " unable to find set codecContext to default values corresponding to the given codec" );
21
+ }
22
+
23
+ loadOptions ( _avContext, req_flags );
24
+ }
25
+
26
+ CodecContext::CodecContext ( int req_flags )
27
+ : Context( NULL , req_flags )
28
+ {
29
+ _avContext = avcodec_alloc_context3 ( NULL );
30
+ loadOptions ( _avContext, req_flags );
31
+ }
32
+
33
+ CodecContext::~CodecContext ()
34
+ {
35
+ if ( ! _avContext )
36
+ return ;
37
+
38
+ avcodec_close ( &getAVCodecContext () );
39
+ av_free ( &getAVCodecContext () );
40
+ _avContext = NULL ;
41
+ }
9
42
10
43
}
Original file line number Diff line number Diff line change @@ -16,7 +16,9 @@ namespace avtranscoder
16
16
class AvExport CodecContext : public Context
17
17
{
18
18
public:
19
- CodecContext ( AVCodecContext& avCodecContext, int req_flags = 0 );
19
+ CodecContext ( AVCodec& avCodec, int req_flags = 0 ); // /< Allocate an AVCodecContext with the given AVCodec
20
+ CodecContext ( int req_flags = 0 ); // /< Allocate an AVCodecContext with default values
21
+ ~CodecContext ();
20
22
21
23
#ifndef SWIG
22
24
AVCodecContext& getAVCodecContext () const { return *static_cast <AVCodecContext*>( _avContext ); }
You can’t perform that action at this time.
0 commit comments