[FFmpeg-devel] [RFC] stream parsing

Benjamin Larsson banan
Mon Sep 27 10:10:04 CEST 2010


On 09/27/2010 02:35 AM, Michael Niedermayer wrote:
> On Mon, Sep 27, 2010 at 01:17:40AM +0200, Benjamin Larsson wrote:
>   
>>     
>>>> -static int has_codec_parameters(AVCodecContext *enc)
>>>> +static int has_codec_parameters(AVCodecContext *enc, AVCodec *codec)
>>>>  {
>>>>      int val;
>>>>      switch(enc->codec_type) {
>>>>      case AVMEDIA_TYPE_AUDIO:
>>>>          val = enc->sample_rate && enc->channels && enc->sample_fmt != SAMPLE_FMT_NONE;
>>>> +        /* Some containers report wrong information about channel configuration
>>>> +         * let the codecs handle it in those cases (dca for example)).
>>>> +         */
>>>> +        if (codec && codec->capabilities & CODEC_CAP_CHANNEL_CONF) {
>>>> +            enc->sample_rate    = 0;
>>>> +            enc->channel_layout = 0;
>>>> +            enc->frame_size     = 0;
>>>> +            enc->channels       = 0;
>>>> +            return 0;
>>>> +        }
>>>>         
>>> av_find_stream_info() will return once all streams has_codec_parameters()
>>> return non zero
>>> this explicitly returns 0 unconditional on any parameters being available or
>>> not thus has_codec_parameters() will never return non zero for an affected
>>> stream, leading to exit only by bug and time/pos limits
>>>       
>> codec is always NULL in the for(;;) block. Thus this code will only be
>> triggered once.
>>     
> i have to maintain this code, and this patch is a huge convoluted hack
> passing NULL instead of the correct AVCodec to make the code not end in a
> near infinite loop is just crazy
>
> Please tell me if this works:
> @@ -2000,6 +2000,8 @@
>      int val;
>      switch(enc->codec_type) {
>      case AVMEDIA_TYPE_AUDIO:
> +        if(!enc->channel_layout && (!enc->codec || (enc->codec->capabilities & CODEC_CAP_CHANNEL_CONF)))
> +            return 0;
>          val = enc->sample_rate && enc->channels && enc->sample_fmt != SAMPLE_FMT_NONE;
>          if(!enc->frame_size &&
>             (enc->codec_id == CODEC_ID_VORBIS ||
>
> if not, please tell me why it fails, ill fix it
>   

Well it works if the container does not populate the channel_layout
(riff based ones do that if the field is there). So in that case the
info from the container will be taken instead of overridden by the codec
info. Setting enc->channels to 0 will make sure that
has_codec_parameters() will return 0 until the codec has overridden the
channels variable.

MvH
Benjamin Larsson



More information about the ffmpeg-devel mailing list