On Mon, 24 Mar 2014 20:25:09 +0100, wm4 <[email protected]> wrote:
> On Mon, 24 Mar 2014 10:03:16 +0100
> Anton Khirnov <[email protected]> wrote:
> 
> > 
> > On Mon, 24 Mar 2014 08:46:01 +0100, Rémi Denis-Courmont <[email protected]> 
> > wrote:
> > > On Mon, 24 Mar 2014 03:01:46 +0100, Luca Barbato <[email protected]>
> > > wrote:
> > > > From: Anton Khirnov <[email protected]>
> > > > 
> > > > This way each decoder does not have to do the same thing manually.
> > > > ---
> > > >  libavcodec/h263dec.c    |  1 -
> > > >  libavcodec/h264_slice.c |  2 --
> > > >  libavcodec/internal.h   |  9 ---------
> > > >  libavcodec/mpeg12dec.c  |  2 --
> > > >  libavcodec/utils.c      | 48
> > > >  +++++++++++++++++++++++++++++++++---------------
> > > >  libavcodec/vc1dec.c     |  1 -
> > > >  6 files changed, 33 insertions(+), 30 deletions(-)
> > > > 
> > > > diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> > > > index 2b3c00a..e52d915 100644
> > > > --- a/libavcodec/utils.c
> > > > +++ b/libavcodec/utils.c
> > > > @@ -836,9 +836,41 @@ enum AVPixelFormat
> > > avcodec_default_get_format(struct
> > > > AVCodecContext *s, const en
> > > >      return fmt[0];
> > > >  }
> > > >  
> > > > +static AVHWAccel *find_hwaccel(enum AVCodecID codec_id,
> > > > +                               enum AVPixelFormat pix_fmt)
> > > > +{
> > > > +    AVHWAccel *hwaccel = NULL;
> > > > +
> > > > +    while ((hwaccel = av_hwaccel_next(hwaccel)))
> > > > +        if (hwaccel->id == codec_id
> > > > +            && hwaccel->pix_fmt == pix_fmt)
> > > > +            return hwaccel;
> > > > +    return NULL;
> > > > +}
> > > > +
> > > > +
> > > >  int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
> > > >  {
> > > > -    return avctx->get_format(avctx, fmt);
> > > > +    const AVPixFmtDescriptor *desc;
> > > > +    enum AVPixelFormat ret = avctx->get_format(avctx, fmt);
> > > > +
> > > > +    desc = av_pix_fmt_desc_get(ret);
> > > > +    if (!desc)
> > > > +        return AV_PIX_FMT_NONE;
> > > > +
> > > > +    if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
> > > > +        avctx->hwaccel = find_hwaccel(avctx->codec_id, ret);
> > > > +        if (!avctx->hwaccel) {
> > > > +            av_log(avctx, AV_LOG_ERROR,
> > > > +                   "Could not find an AVHWAccel for the pixel format:
> > > %s",
> > > > +                   desc->name);
> > > > +            return AV_PIX_FMT_NONE;
> > > 
> > > Is this recoverable in any reasonably way?
> > > 
> > > I can see three ways this situation happens:
> > > 
> > > 1) libavcodec advertised a pxiel format in get_format() that it does not
> > > actually support. That would be a bug in libavcodec (this bug actually 
> > > does
> > > exist if you disable some hwaccel manually in ./configure).
> > > 
> > > 2) The application returned a pixel format that was not advertised. I
> > > think that is a non-recoverable application bug.
> > > 
> > 
> > Yes, those two are bugs that should be fixed in their respective places, and
> > in the following we can assume they do not happen.
> 
> I use separate AVCodecContexts for software and hardware decoding. If
> initializing hardware decoding somehow fails, I return AV_PIX_FMT_NONE
> from get_format to make the decoder return as soon as possible. Pretty
> violent, but works well.

I think the question was whether we can recover from failures in this function
itself.

When the caller get_format() fails, there is nothing libavcodec can reasonably
do.

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

Reply via email to