[vlc-commits] sout avcodec: simplify OpenEncoder retry
Rafaël Carré
git at videolan.org
Mon Apr 29 14:13:38 CEST 2013
vlc | branch: master | Rafaël Carré <funman at videolan.org> | Mon Apr 29 14:11:51 2013 +0200| [c5978915e71e4a662bb0db2b9207024e228556ed] | committer: Rafaël Carré
sout avcodec: simplify OpenEncoder retry
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c5978915e71e4a662bb0db2b9207024e228556ed
---
modules/codec/avcodec/encoder.c | 103 ++++++++++++++++++---------------------
1 file changed, 48 insertions(+), 55 deletions(-)
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 3b1c478..5c06385 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -740,73 +740,66 @@ int OpenEncoder( vlc_object_t *p_this )
vlc_avcodec_unlock();
if( ret )
{
- if( p_enc->fmt_in.i_cat == AUDIO_ES &&
- (p_context->channels > 2 || i_codec_id == AV_CODEC_ID_MP2
- || i_codec_id == AV_CODEC_ID_MP3) )
+ if( p_enc->fmt_in.i_cat != AUDIO_ES ||
+ (p_context->channels <= 2 && i_codec_id != AV_CODEC_ID_MP2
+ && i_codec_id != AV_CODEC_ID_MP3) )
{
- if( p_context->channels > 2 )
- {
- p_context->channels = 2;
- p_enc->fmt_in.audio.i_channels = 2; // FIXME
- msg_Warn( p_enc, "stereo mode selected (codec limitation)" );
- }
+ msg_Err( p_enc, "cannot open encoder" );
+ dialog_Fatal( p_enc, _("Streaming / Transcoding failed"),
+ "%s", _("VLC could not open the encoder.") );
+ free( p_sys );
+ return VLC_EGENERIC;
+ }
- if( i_codec_id == AV_CODEC_ID_MP2 || i_codec_id == AV_CODEC_ID_MP3 )
- {
- int i_frequency, i;
+ if( p_context->channels > 2 )
+ {
+ p_context->channels = 2;
+ p_enc->fmt_in.audio.i_channels = 2; // FIXME
+ msg_Warn( p_enc, "stereo mode selected (codec limitation)" );
+ }
- for ( i_frequency = 0; i_frequency < 6; i_frequency++ )
- {
- if ( p_enc->fmt_out.audio.i_rate
- == mpa_freq_tab[i_frequency] )
- break;
- }
- if ( i_frequency == 6 )
- {
- msg_Err( p_enc, "MPEG audio doesn't support frequency=%d",
- p_enc->fmt_out.audio.i_rate );
- free( p_sys );
- return VLC_EGENERIC;
- }
+ if( i_codec_id == AV_CODEC_ID_MP2 || i_codec_id == AV_CODEC_ID_MP3 )
+ {
+ int i_frequency, i;
+ es_format_t *fmt = &p_enc->fmt_out;
- for ( i = 1; i < 14; i++ )
- {
- if ( p_enc->fmt_out.i_bitrate / 1000
- <= mpa_bitrate_tab[i_frequency / 3][i] )
- break;
- }
- if ( p_enc->fmt_out.i_bitrate / 1000
- != mpa_bitrate_tab[i_frequency / 3][i] )
- {
- msg_Warn( p_enc,
- "MPEG audio doesn't support bitrate=%d, using %d",
- p_enc->fmt_out.i_bitrate,
- mpa_bitrate_tab[i_frequency / 3][i] * 1000 );
- p_enc->fmt_out.i_bitrate =
- mpa_bitrate_tab[i_frequency / 3][i] * 1000;
- p_context->bit_rate = p_enc->fmt_out.i_bitrate;
- }
- }
+ for ( i_frequency = 0; i_frequency < 6; i_frequency++ )
+ if ( fmt->audio.i_rate == mpa_freq_tab[i_frequency] )
+ break;
- p_context->codec = NULL;
- vlc_avcodec_lock();
- ret = avcodec_open2( p_context, p_codec, NULL /* options */ );
- vlc_avcodec_unlock();
- if( ret )
+ if ( i_frequency == 6 )
{
- msg_Err( p_enc, "cannot open encoder" );
- dialog_Fatal( p_enc,
- _("Streaming / Transcoding failed"),
- "%s", _("VLC could not open the encoder.") );
+ msg_Err( p_enc, "MPEG audio doesn't support frequency=%d",
+ fmt->audio.i_rate );
free( p_sys );
return VLC_EGENERIC;
}
+
+ for ( i = 1; i < 14; i++ )
+ if (fmt->i_bitrate/1000 <= mpa_bitrate_tab[i_frequency / 3][i])
+ break;
+
+ if (fmt->i_bitrate / 1000 != mpa_bitrate_tab[i_frequency / 3][i])
+ {
+ msg_Warn( p_enc,
+ "MPEG audio doesn't support bitrate=%d, using %d",
+ fmt->i_bitrate,
+ mpa_bitrate_tab[i_frequency / 3][i] * 1000 );
+ fmt->i_bitrate = mpa_bitrate_tab[i_frequency / 3][i] * 1000;
+ p_context->bit_rate = fmt->i_bitrate;
+ }
}
- else
+
+ p_context->codec = NULL;
+ vlc_avcodec_lock();
+ ret = avcodec_open2( p_context, p_codec, NULL /* options */ );
+ vlc_avcodec_unlock();
+ if( ret )
{
msg_Err( p_enc, "cannot open encoder" );
- dialog_Fatal( p_enc, _("Streaming / Transcoding failed"),
- "%s", _("VLC could not open the encoder.") );
+ dialog_Fatal( p_enc,
+ _("Streaming / Transcoding failed"),
+ "%s", _("VLC could not open the encoder.") );
free( p_sys );
return VLC_EGENERIC;
}
More information about the vlc-commits
mailing list