Commit c5978915 authored by Rafaël Carré's avatar Rafaël Carré

sout avcodec: simplify OpenEncoder retry

parent c27af088
...@@ -740,73 +740,66 @@ int OpenEncoder( vlc_object_t *p_this ) ...@@ -740,73 +740,66 @@ int OpenEncoder( vlc_object_t *p_this )
vlc_avcodec_unlock(); vlc_avcodec_unlock();
if( ret ) if( ret )
{ {
if( p_enc->fmt_in.i_cat == AUDIO_ES && if( p_enc->fmt_in.i_cat != AUDIO_ES ||
(p_context->channels > 2 || i_codec_id == AV_CODEC_ID_MP2 (p_context->channels <= 2 && i_codec_id != AV_CODEC_ID_MP2
|| i_codec_id == AV_CODEC_ID_MP3) ) && i_codec_id != AV_CODEC_ID_MP3) )
{ {
if( p_context->channels > 2 ) msg_Err( p_enc, "cannot open encoder" );
{ dialog_Fatal( p_enc, _("Streaming / Transcoding failed"),
p_context->channels = 2; "%s", _("VLC could not open the encoder.") );
p_enc->fmt_in.audio.i_channels = 2; // FIXME free( p_sys );
msg_Warn( p_enc, "stereo mode selected (codec limitation)" ); return VLC_EGENERIC;
} }
if( i_codec_id == AV_CODEC_ID_MP2 || i_codec_id == AV_CODEC_ID_MP3 ) if( p_context->channels > 2 )
{ {
int i_frequency, i; 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( i_codec_id == AV_CODEC_ID_MP2 || i_codec_id == AV_CODEC_ID_MP3 )
{ {
if ( p_enc->fmt_out.audio.i_rate int i_frequency, i;
== mpa_freq_tab[i_frequency] ) es_format_t *fmt = &p_enc->fmt_out;
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;
}
for ( i = 1; i < 14; i++ ) for ( i_frequency = 0; i_frequency < 6; i_frequency++ )
{ if ( fmt->audio.i_rate == mpa_freq_tab[i_frequency] )
if ( p_enc->fmt_out.i_bitrate / 1000 break;
<= 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;
}
}
p_context->codec = NULL; if ( i_frequency == 6 )
vlc_avcodec_lock();
ret = avcodec_open2( p_context, p_codec, NULL /* options */ );
vlc_avcodec_unlock();
if( ret )
{ {
msg_Err( p_enc, "cannot open encoder" ); msg_Err( p_enc, "MPEG audio doesn't support frequency=%d",
dialog_Fatal( p_enc, fmt->audio.i_rate );
_("Streaming / Transcoding failed"),
"%s", _("VLC could not open the encoder.") );
free( p_sys ); free( p_sys );
return VLC_EGENERIC; 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" ); msg_Err( p_enc, "cannot open encoder" );
dialog_Fatal( p_enc, _("Streaming / Transcoding failed"), dialog_Fatal( p_enc,
"%s", _("VLC could not open the encoder.") ); _("Streaming / Transcoding failed"),
"%s", _("VLC could not open the encoder.") );
free( p_sys ); free( p_sys );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment