Skip to content

Commit c7df3a2

Browse files
committed
Merge pull request #125 from cchampet/dev_decodersAllocAVFrameInConstructor
Video/Audio decoders: allocate AVFrame in constructor
2 parents c856aeb + bad4039 commit c7df3a2

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/AvTranscoder/decoder/AudioDecoder.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ AudioDecoder::AudioDecoder( InputStream& inputStream )
2121
: _inputStream ( &inputStream )
2222
, _frame ( NULL )
2323
{
24+
#if LIBAVCODEC_VERSION_MAJOR > 54
25+
_frame = av_frame_alloc();
26+
#else
27+
_frame = avcodec_alloc_frame();
28+
#endif
29+
if( _frame == NULL )
30+
{
31+
throw std::runtime_error( "unable to setup frame buffer" );
32+
}
2433
}
2534

2635
AudioDecoder::~AudioDecoder()
@@ -44,16 +53,6 @@ AudioDecoder::~AudioDecoder()
4453
void AudioDecoder::setup()
4554
{
4655
_inputStream->getAudioCodec().open();
47-
48-
#if LIBAVCODEC_VERSION_MAJOR > 54
49-
_frame = av_frame_alloc();
50-
#else
51-
_frame = avcodec_alloc_frame();
52-
#endif
53-
if( _frame == NULL )
54-
{
55-
throw std::runtime_error( "unable to setup frame buffer" );
56-
}
5756
}
5857

5958
bool AudioDecoder::decodeNextFrame( Frame& frameBuffer )

src/AvTranscoder/decoder/VideoDecoder.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ VideoDecoder::VideoDecoder( InputStream& inputStream )
2020
: _inputStream ( &inputStream )
2121
, _frame ( NULL )
2222
{
23+
#if LIBAVCODEC_VERSION_MAJOR > 54
24+
_frame = av_frame_alloc();
25+
#else
26+
_frame = avcodec_alloc_frame();
27+
#endif
28+
if( _frame == NULL )
29+
{
30+
throw std::runtime_error( "unable to setup frame buffer" );
31+
}
2332
}
2433

2534
VideoDecoder::~VideoDecoder()
@@ -42,16 +51,6 @@ VideoDecoder::~VideoDecoder()
4251
void VideoDecoder::setup()
4352
{
4453
_inputStream->getVideoCodec().open();
45-
46-
#if LIBAVCODEC_VERSION_MAJOR > 54
47-
_frame = av_frame_alloc();
48-
#else
49-
_frame = avcodec_alloc_frame();
50-
#endif
51-
if( _frame == NULL )
52-
{
53-
throw std::runtime_error( "unable to setup frame buffer" );
54-
}
5554
}
5655

5756
bool VideoDecoder::decodeNextFrame( Frame& frameBuffer )

0 commit comments

Comments
 (0)