@@ -20,21 +20,14 @@ namespace avtranscoder
20
20
AvInputVideo::AvInputVideo ( AvInputStream& inputStream )
21
21
: IInputEssence()
22
22
, _inputStream ( &inputStream )
23
- , _codec ( NULL )
24
- , _codecContext ( NULL )
23
+ , _codec( eCodecTypeDecoder, inputStream.getVideoCodec().getCodecId() )
25
24
, _frame ( NULL )
26
25
, _selectedStream( -1 )
27
26
{
28
27
}
29
28
30
29
AvInputVideo::~AvInputVideo ()
31
30
{
32
- if ( _codecContext != NULL )
33
- {
34
- // avcodec_close( _codecContext );
35
- av_free ( _codecContext );
36
- _codecContext = NULL ;
37
- }
38
31
if ( _frame != NULL )
39
32
{
40
33
#if LIBAVCODEC_VERSION_MAJOR > 54
@@ -52,33 +45,22 @@ AvInputVideo::~AvInputVideo()
52
45
53
46
void AvInputVideo::setup ()
54
47
{
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 ();
68
50
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;
71
53
72
- int ret = avcodec_open2 ( _codecContext, _codec , NULL );
54
+ int ret = avcodec_open2 ( avCodecContext, avCodec , NULL );
73
55
74
- if ( ret < 0 || _codecContext == NULL || _codec == NULL )
56
+ if ( ret < 0 || avCodecContext == NULL || avCodec == NULL )
75
57
{
76
58
std::string msg = " unable open video codec: " ;
77
- msg += _codec ->long_name ;
59
+ msg += avCodec ->long_name ;
78
60
msg += " (" ;
79
- msg += _codec ->name ;
61
+ msg += avCodec ->name ;
80
62
msg += " )" ;
81
- avcodec_close ( _codecContext );
63
+ avcodec_close ( avCodecContext );
82
64
throw std::runtime_error ( msg );
83
65
}
84
66
@@ -110,7 +92,7 @@ bool AvInputVideo::readNextFrame( Frame& frameBuffer )
110
92
packet.data = data.getPtr ();
111
93
packet.size = data.getSize ();
112
94
113
- int ret = avcodec_decode_video2 ( _codecContext , _frame, &got_frame, &packet );
95
+ int ret = avcodec_decode_video2 ( _codec. getAVCodecContext () , _frame, &got_frame, &packet );
114
96
115
97
if ( ret < 0 )
116
98
{
@@ -142,12 +124,12 @@ bool AvInputVideo::readNextFrame( Frame& frameBuffer, const size_t subStreamInde
142
124
143
125
void AvInputVideo::flushDecoder ()
144
126
{
145
- avcodec_flush_buffers ( _codecContext );
127
+ avcodec_flush_buffers ( _codec. getAVCodecContext () );
146
128
}
147
129
148
130
void AvInputVideo::setProfile ( const Profile::ProfileDesc& desc )
149
131
{
150
- Context codecContext ( _codecContext );
132
+ Context codecContext ( _codec. getAVCodecContext () );
151
133
152
134
for ( Profile::ProfileDesc::const_iterator it = desc.begin (); it != desc.end (); ++it )
153
135
{
0 commit comments