Skip to content

Commit 060bc45

Browse files
committed
Merge pull request #52 from cchampet/dev_specific_codec_options
ICodec can load specific codec options
2 parents a0ba631 + d40b820 commit 060bc45

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/AvTranscoder/codec/ICodec.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ void ICodec::open()
7676

7777
std::string ICodec::getCodecName() const
7878
{
79-
assert( _avCodec != NULL );
80-
return avcodec_descriptor_get( _avCodec->id )->name;
79+
assert( _avCodecContext != NULL );
80+
return avcodec_descriptor_get( _avCodecContext->codec_id )->name;
8181
}
8282

8383
AVCodecID ICodec::getCodecId() const
8484
{
85-
assert( _avCodec != NULL );
86-
return _avCodec->id;
85+
assert( _avCodecContext != NULL );
86+
return _avCodecContext->codec_id;
8787
}
8888

8989
int ICodec::getLatency() const
@@ -124,19 +124,13 @@ void ICodec::setCodec( const ECodecType type, const AVCodecID codecId )
124124
}
125125

126126
if( type == eCodecTypeEncoder )
127-
{
128127
_avCodec = avcodec_find_encoder( codecId );
129-
if( _avCodecContext )
130-
_avCodecContext->codec = _avCodec;
131-
}
132128
else if( type == eCodecTypeDecoder )
133-
{
134129
_avCodec = avcodec_find_decoder( codecId );
135-
if( _avCodecContext )
136-
_avCodecContext->codec = _avCodec;
137-
}
138-
}
139130

131+
if( _avCodecContext )
132+
_avCodecContext->codec = _avCodec;
133+
}
140134

141135
void ICodec::allocateContext()
142136
{
@@ -145,14 +139,23 @@ void ICodec::allocateContext()
145139
{
146140
throw std::runtime_error( "unable to allocate the codecContext and set its fields to default values" );
147141
}
142+
_avCodecContext->codec = _avCodec;
148143
}
149144

150145
void ICodec::loadCodecOptions()
151146
{
152147
if( _type == eCodecTypeEncoder )
148+
{
153149
loadOptions( _options, _avCodecContext, AV_OPT_FLAG_ENCODING_PARAM );
150+
// load specific options of the codec
151+
loadOptions( _options, _avCodecContext->priv_data, AV_OPT_FLAG_ENCODING_PARAM );
152+
}
154153
else if( _type == eCodecTypeDecoder )
154+
{
155155
loadOptions( _options, _avCodecContext, AV_OPT_FLAG_DECODING_PARAM );
156+
// load specific options of the codec
157+
loadOptions( _options, _avCodecContext->priv_data, AV_OPT_FLAG_DECODING_PARAM );
158+
}
156159
}
157160

158161
}

0 commit comments

Comments
 (0)