On 19/01/12 17:34, Anton Khirnov wrote:
> 
> On Thu, 19 Jan 2012 09:56:04 -0500, Justin Ruggles <[email protected]> 
> wrote:
>> On 01/19/2012 02:40 AM, Anton Khirnov wrote:
>>
>>>
>>> On Wed, 18 Jan 2012 17:19:43 -0500, Justin Ruggles 
>>> <[email protected]> wrote:
>>>> Allows for choosing an alternate decoder when available.
>>>> ---
>>>>  avplay.c |   35 ++++++++++++++++++++++++++++++-----
>>>>  1 files changed, 30 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/avplay.c b/avplay.c
>>>> index 4d21234..ad27aef 100644
>>>> --- a/avplay.c
>>>> +++ b/avplay.c
>>>> @@ -259,6 +259,8 @@ static int exit_on_keydown;
>>>>  static int exit_on_mousedown;
>>>>  static int loop = 1;
>>>>  static int framedrop = 1;
>>>> +static const char *acodec_name;
>>>> +static const char *vcodec_name;
>>>>  
>>>>  static int rdftspeed = 20;
>>>>  #if CONFIG_AVFILTER
>>>> @@ -2167,10 +2169,11 @@ static int stream_component_open(VideoState *is, 
>>>> int stream_index)
>>>>  {
>>>>      AVFormatContext *ic = is->ic;
>>>>      AVCodecContext *avctx;
>>>> -    AVCodec *codec;
>>>> +    AVCodec *codec = NULL;
>>>>      SDL_AudioSpec wanted_spec, spec;
>>>>      AVDictionary *opts;
>>>>      AVDictionaryEntry *t = NULL;
>>>> +    enum AVMediaType codec_type;
>>>>  
>>>>      if (stream_index < 0 || stream_index >= ic->nb_streams)
>>>>          return -1;
>>>> @@ -2178,7 +2181,26 @@ static int stream_component_open(VideoState *is, 
>>>> int stream_index)
>>>>  
>>>>      opts = filter_codec_opts(codec_opts, avctx->codec_id, ic, 
>>>> ic->streams[stream_index]);
>>>>  
>>>> -    codec = avcodec_find_decoder(avctx->codec_id);
>>>> +    codec_type = avcodec_get_type(avctx->codec_id);
>>>> +    if (acodec_name && codec_type == AVMEDIA_TYPE_AUDIO ||
>>>> +        vcodec_name && codec_type == AVMEDIA_TYPE_VIDEO) {
>>>> +        const char *name;
>>>> +        if (codec_type == AVMEDIA_TYPE_AUDIO)
>>>> +            name = acodec_name;
>>>> +        else
>>>> +            name = vcodec_name;
>>>> +
>>>> +        codec = avcodec_find_decoder_by_name(name);
>>>> +        if (!codec) {
>>>> +            av_log(NULL, AV_LOG_FATAL, "Unknown decoder '%s'\n", name);
>>>> +        } else if (codec->type != codec_type) {
>>>> +            av_log(NULL, AV_LOG_FATAL, "Invalid decoder type '%s'\n", 
>>>> name);
>>>> +            codec = NULL;
>>>
>>> I would expect an exit_program() here.
>>
>> I thought falling back to the default decoder would be more
>> user-friendly, but if failing is preferred instead I can change it.
>>
> 
> The user took time specifying the decoder he wants, so he probably cares
> that exactly this decoder gets used. I consider aborting more
> user-friendly in this case.

I would even allow overriding the codec_id. We are assuming the user
knows what's doing.


lu
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to