On Mon, 18 Nov 2013 19:45 +0200, Rémi Denis-Courmont <[email protected]> wrote:
> Le vendredi 8 novembre 2013, 23:42:11 Anton Khirnov a écrit :
> > ---
> >  avconv.c        |   79
> > +++++++++++++++++++++++++++++++++++++++++++++++++++++++ avconv.h        |  
> > 15 +++++++++++
> >  avconv_filter.c |    3 ++-
> >  avconv_opt.c    |   18 ++++++++++++-
> >  doc/avconv.texi |   20 ++++++++++++++
> >  5 files changed, 133 insertions(+), 2 deletions(-)
> > 
> > diff --git a/avconv.c b/avconv.c
> > index 8d8c802..33a9a73 100644
> > --- a/avconv.c
> > +++ b/avconv.c
> > @@ -1165,6 +1165,13 @@ static int decode_video(InputStream *ist, AVPacket
> > *pkt, int *got_output) return ret;
> >      }
> > 
> > +    if (ist->hwaccel_retrieve_data) {
> > +        err = ist->hwaccel_retrieve_data(ist->st->codec, decoded_frame);
> > +        if (err < 0)
> > +            goto fail;
> > +        ist->hwaccel_pix_fmt = decoded_frame->format;
> > +    }
> > +
> >      decoded_frame->pts = guess_correct_pts(&ist->pts_ctx,
> > decoded_frame->pkt_pts, decoded_frame->pkt_dts); pkt->size = 0;
> > @@ -1212,6 +1219,7 @@ static int decode_video(InputStream *ist, AVPacket
> > *pkt, int *got_output) break;
> >      }
> > 
> > +fail:
> >      av_frame_unref(ist->filter_frame);
> >      av_frame_unref(decoded_frame);
> >      return err < 0 ? err : ret;
> > @@ -1359,6 +1367,70 @@ static void print_sdp(void)
> >      av_freep(&avc);
> >  }
> > 
> > +typedef struct HWAccel {
> > +    const char *name;
> > +    int (*init)(AVCodecContext *s);
> > +    enum HWAccelID id;
> > +    enum AVPixelFormat pix_fmt;
> > +} HWAccel;
> > +
> > +static const HWAccel hwaccels[] = {
> > +    { 0 },
> > +};
> > +
> > +static const HWAccel *get_hwaccel(enum AVPixelFormat pix_fmt)
> > +{
> > +    int i;
> > +    for (i = 0; hwaccels[i].name; i++)
> > +        if (hwaccels[i].pix_fmt == pix_fmt)
> > +            return &hwaccels[i];
> > +    return NULL;
> > +}
> > +
> > +static enum AVPixelFormat get_format(AVCodecContext *s, const enum
> > AVPixelFormat *pix_fmts)
> > +{
> > +    InputStream *ist = s->opaque;
> > +    const enum AVPixelFormat *p;
> > +    int ret;
> > +
> > +    for (p = pix_fmts; *p != -1; p++) {
> > +        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(*p);
> > +        const HWAccel         *hwaccel = get_hwaccel(*p);
> 
> Should this not be after the following if() ?
> 

Yes, I suppose it should. Moved locally.

> > +
> > +        if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
> > +            break;
> > +        else if (!hwaccel ||
> > +                 (ist->active_hwaccel_id && ist->active_hwaccel_id !=
> > hwaccel->id) ||
> 
> I don't really follow why you need to keep track of and cross-check the 
> current hardware acceleration identifier.

To make sure a different hwaccel does not get selected on a reinit. It probably
cannot happen with any current decoder, but is conceivable in theory.

> 
> > +                 (ist->hwaccel_id != HWACCEL_AUTO &&
> > ist->hwaccel_id != hwaccel->id))
> > +            continue;
> > +
> > +        ret = hwaccel->init(s);
> > +        if (ret < 0) {
> > +            if (ist->hwaccel_id == hwaccel->id) {
> > +                av_log(NULL, AV_LOG_FATAL,
> > +                       "%s hwaccel requested for input stream #%d:%d, "
> > +                       "but cannot be initialized.\n", hwaccel->name,
> > +                       ist->file_index, ist->st->index);
> > +                exit_program(1);
> > +            }
> > +            continue;
> > +        }
> > +        ist->active_hwaccel_id = hwaccel->id;
> > +        break;
> > +    }
> > +
> > +    return *p;
> > +}
> > +
> > +static int get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
> > +{
> > +    InputStream *ist = s->opaque;
> > +
> > +    if (ist->hwaccel_get_buffer)
> 
> Does it really make sense for this to be NULL ever? This get_buffer() 
> callback 
> is only used with hwaccel afterall.

If you look at the code below, get_buffer is set unconditionally, so this code
is always called whether hwaccel is used or not. It could even switch from using
hwaccel to sw and back to hwaccel again.

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

Reply via email to