Skip to content

Commit a7b4158

Browse files
committed
AvInputVideo: use VideoCodec
* Symmetry with AvOutputVideo: * use a VideoCodec. * no need to allocate and free AV codec objects ; it is done by our ICodec class.
1 parent 4425760 commit a7b4158

File tree

2 files changed

+15
-35
lines changed

2 files changed

+15
-35
lines changed

src/AvTranscoder/essenceStream/AvInputVideo.cpp

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,14 @@ namespace avtranscoder
2020
AvInputVideo::AvInputVideo( AvInputStream& inputStream )
2121
: IInputEssence()
2222
, _inputStream ( &inputStream )
23-
, _codec ( NULL )
24-
, _codecContext ( NULL )
23+
, _codec( eCodecTypeDecoder, inputStream.getVideoCodec().getCodecId() )
2524
, _frame ( NULL )
2625
, _selectedStream( -1 )
2726
{
2827
}
2928

3029
AvInputVideo::~AvInputVideo()
3130
{
32-
if( _codecContext != NULL )
33-
{
34-
//avcodec_close( _codecContext );
35-
av_free( _codecContext );
36-
_codecContext = NULL;
37-
}
3831
if( _frame != NULL )
3932
{
4033
#if LIBAVCODEC_VERSION_MAJOR > 54
@@ -52,33 +45,22 @@ AvInputVideo::~AvInputVideo()
5245

5346
void AvInputVideo::setup()
5447
{
55-
av_register_all();
56-
57-
_codec = avcodec_find_decoder( _inputStream->getVideoCodec().getCodecId() );
58-
if( _codec == NULL )
59-
{
60-
throw std::runtime_error( "codec not supported" );
61-
}
62-
63-
_codecContext = avcodec_alloc_context3( _codec );
64-
if( _codecContext == NULL )
65-
{
66-
throw std::runtime_error( "unable to find context for codec" );
67-
}
48+
AVCodecContext* avCodecContext = _codec.getAVCodecContext();
49+
AVCodec* avCodec = _codec.getAVCodec();
6850

69-
// if( codec->capabilities & CODEC_CAP_TRUNCATED )
70-
// codecContext->flags |= CODEC_FLAG_TRUNCATED;
51+
// if( avCodec->capabilities & CODEC_CAP_TRUNCATED )
52+
// avCodecContext->flags |= CODEC_FLAG_TRUNCATED;
7153

72-
int ret = avcodec_open2( _codecContext, _codec, NULL );
54+
int ret = avcodec_open2( avCodecContext, avCodec, NULL );
7355

74-
if( ret < 0 || _codecContext == NULL || _codec == NULL )
56+
if( ret < 0 || avCodecContext == NULL || avCodec == NULL )
7557
{
7658
std::string msg = "unable open video codec: ";
77-
msg += _codec->long_name;
59+
msg += avCodec->long_name;
7860
msg += " (";
79-
msg += _codec->name;
61+
msg += avCodec->name;
8062
msg += ")";
81-
avcodec_close( _codecContext );
63+
avcodec_close( avCodecContext );
8264
throw std::runtime_error( msg );
8365
}
8466

@@ -110,7 +92,7 @@ bool AvInputVideo::readNextFrame( Frame& frameBuffer )
11092
packet.data = data.getPtr();
11193
packet.size = data.getSize();
11294

113-
int ret = avcodec_decode_video2( _codecContext, _frame, &got_frame, &packet );
95+
int ret = avcodec_decode_video2( _codec.getAVCodecContext(), _frame, &got_frame, &packet );
11496

11597
if( ret < 0 )
11698
{
@@ -142,12 +124,12 @@ bool AvInputVideo::readNextFrame( Frame& frameBuffer, const size_t subStreamInde
142124

143125
void AvInputVideo::flushDecoder()
144126
{
145-
avcodec_flush_buffers( _codecContext );
127+
avcodec_flush_buffers( _codec.getAVCodecContext() );
146128
}
147129

148130
void AvInputVideo::setProfile( const Profile::ProfileDesc& desc )
149131
{
150-
Context codecContext( _codecContext );
132+
Context codecContext( _codec.getAVCodecContext() );
151133

152134
for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
153135
{

src/AvTranscoder/essenceStream/AvInputVideo.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
#define _AV_TRANSCODER_ESSENCE_STREAM_AV_INPUT_VIDEO_HPP_
33

44
#include "IInputEssence.hpp"
5+
#include <AvTranscoder/codec/VideoCodec.hpp>
56
#include <AvTranscoder/Profile.hpp>
67

7-
struct AVCodec;
8-
struct AVCodecContext;
98
struct AVFrame;
109

1110
namespace avtranscoder
@@ -30,8 +29,7 @@ class AvExport AvInputVideo : public IInputEssence
3029

3130
private:
3231
AvInputStream* _inputStream;
33-
AVCodec* _codec;
34-
AVCodecContext* _codecContext;
32+
VideoCodec _codec;
3533
AVFrame* _frame;
3634

3735
int _selectedStream;

0 commit comments

Comments
 (0)