Skip to content
Luca Barbato edited this page Sep 25, 2013 · 2 revisions

More flexible and consistent HWAccel support.

/**
 * Enable hardware accelerated decoding depending on the codec
 * and pix_fmt.
 *
 * @param  avctx The codec context to enable
 * @param  options HWAccel specific options
 * @return 0 on success, AVERROR otherwise.
 */
int ff_hwaccel_open(AVCodecContext *avctx, AVDictionary **options);


/**
 * Deallocate the hardware accelerated context if hwaccel is in use
 *
 * @param avctx The codec context
 */
void ff_hwaccel_close(AVCodecContext *avctx);
typedef struct AVHWAccel {
    /**
     * Name of the hardware accelerated codec.
     * The name is globally unique among encoders and among decoders (but an
     * encoder and a decoder can share the same name).
     */
    const char *name;

    /**
     * Type of codec implemented by the hardware accelerator.
     *
     * See AVMEDIA_TYPE_xxx
     */
    enum AVMediaType type;

    /**
     * Codec implemented by the hardware accelerator.
     *
     * See AV_CODEC_ID_xxx
     */
    enum AVCodecID id;

    /**
     * Supported pixel format.
     *
     * Only hardware accelerated formats are supported here.
     */
    enum AVPixelFormat pix_fmt;

    /**
     * Hardware accelerated codec capabilities.
     * see FF_HWACCEL_CODEC_CAP_*
     */
    int capabilities;

    struct AVHWAccel *next;

    /**
     * Called at the beginning of each frame or field picture.
     *
     * Meaningful frame information (codec specific) is guaranteed to
     * be parsed at this point. This function is mandatory.
     *
     * Note that buf can be NULL along with buf_size set to 0.
     * Otherwise, this means the whole frame is available at this point.
     *
     * @param avctx the codec context
     * @param buf the frame data buffer base
     * @param buf_size the size of the frame in bytes
     * @return zero if successful, a negative value otherwise
     */
    int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);

    /**
     * Callback for each slice.
     *
     * Meaningful slice information (codec specific) is guaranteed to
     * be parsed at this point. This function is mandatory for FF_HWACCEL_SLICES
     * capable hwaccel.
     *
     * @param avctx the codec context
     * @param buf the slice data buffer base
     * @param buf_size the size of the slice in bytes
     * @return zero if successful, a negative value otherwise
     */
    int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);

    /**
     * Called at the end of each frame or field picture.
     *
     * The whole picture is parsed at this point and can now be sent
     * to the hardware accelerator. This function is mandatory.
     *
     * @param avctx the codec context
     * @return zero if successful, a negative value otherwise
     */
    int (*end_frame)(AVCodecContext *avctx);

    /**
     * Encoder function.
     */
    int (*encode)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
                  int *got_packet_ptr);
    /**
     * Called if the HWAccel capability is FF_HWACCEL_BITSTREAM
     */
    int (*decode)(AVCodecContext *avctx, AVFrame *frame, const AVPacket *avpkt,
                  int *got_frame_ptr);
    
    /**
     * Size of HW accelerator private data.
     *
     * Private data is allocated with av_mallocz() before
     * AVCodecContext.get_buffer() and deallocated after
     * AVCodecContext.release_buffer().
     */
    int priv_data_size;

    /**
     * Size of HW accelerator global private data.
     *
     * Private data is allocated with av_mallocz() before
     * AVHWAccel.init() and deallocated after
     * AVHWAccel.close().
     * @see avcodec_open2
     */
    int global_data_size;

    /**
     * Initialization function.
     *
     * @param avctx The codec context
     * @return zero on success, AVERROR otherwise
     */
    int (*init)(AVCodecContext *avctx);

    /**
     * Deallocation function
     *
     * @param avctx The codec context
     */
    void (*close)(AVCodecContext *avctx);
} AVHWAccel;

Plan

  • Have a normal init/close system, optional configuration goes through avoptions.
  • Support bitstream hwaccel (qsv, vda)
  • Support encoding

Milestones

  • Write down the basic infrastructure
  • Port vaapi to it
  • Port vdpau to it
  • Port vda and videotoolbox to it
  • Port qsv to it
Clone this wiki locally