tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

hwaccel_internal.h (5839B)


      1 /*
      2 * This file is part of FFmpeg.
      3 *
      4 * FFmpeg is free software; you can redistribute it and/or
      5 * modify it under the terms of the GNU Lesser General Public
      6 * License as published by the Free Software Foundation; either
      7 * version 2.1 of the License, or (at your option) any later version.
      8 *
      9 * FFmpeg is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12 * Lesser General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU Lesser General Public
     15 * License along with FFmpeg; if not, write to the Free Software
     16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     17 */
     18 
     19 /**
     20 * Header providing the internals of AVHWAccel.
     21 */
     22 
     23 #ifndef AVCODEC_HWACCEL_INTERNAL_H
     24 #define AVCODEC_HWACCEL_INTERNAL_H
     25 
     26 #include <stdint.h>
     27 
     28 #include "avcodec.h"
     29 #include "libavutil/refstruct.h"
     30 
     31 #define HWACCEL_CAP_ASYNC_SAFE      (1 << 0)
     32 #define HWACCEL_CAP_THREAD_SAFE     (1 << 1)
     33 
     34 typedef struct FFHWAccel {
     35    /**
     36     * The public AVHWAccel. See avcodec.h for it.
     37     */
     38    AVHWAccel p;
     39 
     40    /**
     41     * Allocate a custom buffer
     42     */
     43    int (*alloc_frame)(AVCodecContext *avctx, AVFrame *frame);
     44 
     45    /**
     46     * Called at the beginning of each frame or field picture.
     47     *
     48     * Meaningful frame information (codec specific) is guaranteed to
     49     * be parsed at this point. This function is mandatory.
     50     *
     51     * Note that buf can be NULL along with buf_size set to 0.
     52     * Otherwise, this means the whole frame is available at this point.
     53     *
     54     * @param avctx the codec context
     55     * @param buf the frame data buffer base
     56     * @param buf_size the size of the frame in bytes
     57     * @return zero if successful, a negative value otherwise
     58     */
     59    int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
     60 
     61    /**
     62     * Callback for parameter data (SPS/PPS/VPS etc).
     63     *
     64     * Useful for hardware decoders which keep persistent state about the
     65     * video parameters, and need to receive any changes to update that state.
     66     *
     67     * @param avctx the codec context
     68     * @param type the nal unit type
     69     * @param buf the nal unit data buffer
     70     * @param buf_size the size of the nal unit in bytes
     71     * @return zero if successful, a negative value otherwise
     72     */
     73    int (*decode_params)(AVCodecContext *avctx, int type, const uint8_t *buf, uint32_t buf_size);
     74 
     75    /**
     76     * Callback for each slice.
     77     *
     78     * Meaningful slice information (codec specific) is guaranteed to
     79     * be parsed at this point. This function is mandatory.
     80     *
     81     * @param avctx the codec context
     82     * @param buf the slice data buffer base
     83     * @param buf_size the size of the slice in bytes
     84     * @return zero if successful, a negative value otherwise
     85     */
     86    int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
     87 
     88    /**
     89     * Called at the end of each frame or field picture.
     90     *
     91     * The whole picture is parsed at this point and can now be sent
     92     * to the hardware accelerator. This function is mandatory.
     93     *
     94     * @param avctx the codec context
     95     * @return zero if successful, a negative value otherwise
     96     */
     97    int (*end_frame)(AVCodecContext *avctx);
     98 
     99    /**
    100     * Size of per-frame hardware accelerator private data.
    101     *
    102     * Private data is allocated with av_mallocz() before
    103     * AVCodecContext.get_buffer() and deallocated after
    104     * AVCodecContext.release_buffer().
    105     */
    106    int frame_priv_data_size;
    107 
    108    /**
    109     * Size of the private data to allocate in
    110     * AVCodecInternal.hwaccel_priv_data.
    111     */
    112    int priv_data_size;
    113 
    114    /**
    115     * Internal hwaccel capabilities.
    116     */
    117    int caps_internal;
    118 
    119    /**
    120     * Initialize the hwaccel private data.
    121     *
    122     * This will be called from ff_get_format(), after hwaccel and
    123     * hwaccel_context are set and the hwaccel private data in AVCodecInternal
    124     * is allocated.
    125     */
    126    int (*init)(AVCodecContext *avctx);
    127 
    128    /**
    129     * Uninitialize the hwaccel private data.
    130     *
    131     * This will be called from get_format() or ff_codec_close(), after hwaccel
    132     * and hwaccel_context are already uninitialized.
    133     */
    134    int (*uninit)(AVCodecContext *avctx);
    135 
    136    /**
    137     * Fill the given hw_frames context with current codec parameters. Called
    138     * from get_format. Refer to avcodec_get_hw_frames_parameters() for
    139     * details.
    140     *
    141     * This CAN be called before AVHWAccel.init is called, and you must assume
    142     * that avctx->hwaccel_priv_data is invalid.
    143     */
    144    int (*frame_params)(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx);
    145 
    146    /**
    147     * Copy necessary context variables from a previous thread context to the current one.
    148     * For thread-safe hwaccels only.
    149     */
    150    int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
    151 
    152    /**
    153     * Callback to free the hwaccel-specific frame data.
    154     *
    155     * @param hwctx a pointer to an AVHWDeviceContext.
    156     * @param data the per-frame hardware accelerator private data to be freed.
    157     */
    158    void (*free_frame_priv)(AVRefStructOpaque hwctx, void *data);
    159 
    160    /**
    161     * Callback to flush the hwaccel state.
    162     */
    163    void (*flush)(AVCodecContext *avctx);
    164 } FFHWAccel;
    165 
    166 static inline const FFHWAccel *ffhwaccel(const AVHWAccel *codec)
    167 {
    168    return (const FFHWAccel*)codec;
    169 }
    170 
    171 #define FF_HW_CALL(avctx, function, ...) \
    172        (ffhwaccel((avctx)->hwaccel)->function((avctx), __VA_ARGS__))
    173 
    174 #define FF_HW_SIMPLE_CALL(avctx, function) \
    175        (ffhwaccel((avctx)->hwaccel)->function(avctx))
    176 
    177 #define FF_HW_HAS_CB(avctx, function) \
    178        ((avctx)->hwaccel && ffhwaccel((avctx)->hwaccel)->function)
    179 
    180 #endif /* AVCODEC_HWACCEL_INTERNAL */