On Mon, 30 Jan 2017 10:10:11 +0000
Mark Thompson <[email protected]> wrote:

> >> +     *
> >> +     * If set by libavcodec:
> >> +     *
> >> +     * - decoding: The hw_device_ctx field should be set by the user 
> >> before
> >> +     *             calling avcodec_open2().  If at some later point a 
> >> hardware
> >> +     *             pixel format is selected by get_format(), then a new
> >> +     *             AVHWFramesContext will be created by the decoder and 
> >> put
> >> +     *             in this field.
> >> +     *  
> >   
> >> +     *             It can be read only inside the get_buffer2() callback
> >> +     *             (which must return a buffer from the given context).  
> > 
> > Any reason for this specific restriction?
> > 
> > Shouldn't it be ok to access it any time - just that it might not be
> > set to something useful? (Could be NULL or wrong format.)  
> 
> If the decoder is single-threaded, yes.  If it isn't, then I think that 
> inside get_buffer2() is the only place where you can guarantee there isn't a 
> data race (which is undefined behaviour in C11).

Good point about threading. I'm not sure how that works with hwaccel.
Normally, each thread has a "shadow" AVCodecContext, and the generic
thread code copies fields between them at defined times. Maybe elenril
knows how this affects hwaccel.

> >> +     * A reference to the AVHWDeviceContext describing the device which 
> >> will
> >> +     * be used by a hardware encoder/decoder.  The reference is set by the
> >> +     * caller and afterwards owned (and freed) by libavcodec.
> >> +     *
> >> +     * This should only be used if either the codec device does not 
> >> require
> >> +     * hardware frames or any that are used are allocated internally by
> >> +     * libavcodec.  If the frames may be supplied by the user, then
> >> +     * hw_frames_ctx must be used instead.  
> > 
> > I'm not sure about the word "may". For some decoders, the user can
> > either set hw_device_ctx, or he can set a hw_frames_ctx (but they
> > can't both be set). Some decoders support hw_frames_ctx only. Shouldn't
> > it say "have to" instead of "may"? Maybe the wording is fine - I'm not a
> > native speaker.  
> 
> It's trying to say "if you ever want to supply the frames, you need to use 
> hw_frames_ctx" - that is, even if you only want to do it some of the time you 
> still need to make the frames context all the time.

Oh ok.

>   This should only be used if either the codec device does not require
>   hardware frames or any that are used are allocated internally by
>   libavcodec.  If the user ever intends to supply any of the frames used
>   for decoding then hw_frames_ctx must be used instead.

Sounds ok. Maybe the exclusiveness of both fields could be emphasized
in a more explicit way:

    The user must never set both hw_frames_ctx and hw_device_ctx. The
    API supports setting hw_frames_ctx for manual frame allocation, and
    hw_device_ctx for automatic management. Both modes are exclusive to
    each other.

> >> +     *
> >> +     * If the same device is to be used throughout the lifetime of a 
> >> decoder,
> >> +     * this field should be set before avcodec_open2() is called.  Some
> >> +     * decoders can only use one device and therefore require this 
> >> behaviour.
> >> +     *
> >> +     * For other decoders, the hw_device_ctx field can be set inside the
> >> +     * get_format() callback to indicate the device to use for decoding a
> >> +     * particular section of  the stream.  Any previous value in the field
> >> +     * must be unreferenced before being overwritten.  This also supports
> >> +     * changing between use of hw_device_ctx and hw_frames_ctx - when 
> >> doing
> >> +     * so, the other field must always be set to NULL.  
> 
> Should mention encoders here too:
> 
>   For encoders, this field must be set before avcodec_open2() is called.
>   (Encoders can only use a single device.)

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

Reply via email to