Coverage Report

Created: 2026-03-31 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/codec/avcodec/va.h
Line
Count
Source
1
/*****************************************************************************
2
 * va.h: Video Acceleration API for avcodec
3
 *****************************************************************************
4
 * Copyright (C) 2009 Laurent Aimar
5
 *
6
 * Authors: Laurent Aimar <fenrir_AT_ videolan _DOT_ org>
7
 *
8
 * This program is free software; you can redistribute it and/or modify it
9
 * under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation; either version 2.1 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program; if not, write to the Free Software Foundation,
20
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21
 *****************************************************************************/
22
23
#ifndef VLC_AVCODEC_VA_H
24
#define VLC_AVCODEC_VA_H 1
25
26
#include "avcommon_compat.h"
27
#include <libavutil/pixdesc.h>
28
29
typedef struct vlc_va_t vlc_va_t;
30
typedef struct vlc_decoder_device vlc_decoder_device;
31
typedef struct vlc_video_context vlc_video_context;
32
33
struct vlc_va_cfg
34
{
35
    /**
36
     * AVContext to set the hwaccel_context on.
37
     *
38
     * The VA can assume fields codec_id, coded_width, coded_height,
39
     * active_thread_type, thread_count, framerate, profile, refs (H264) and
40
     * hw_pix_fmt are set correctly */
41
    AVCodecContext *avctx;
42
43
    /** avcodec hardare PIX_FMT */
44
    enum AVPixelFormat hwfmt;
45
46
    /**  Description of the hardware fornat */
47
    const AVPixFmtDescriptor *desc;
48
49
    /** VLC format of the content to decode */
50
    const es_format_t *fmt_in;
51
52
    /** Decoder device that will be used to create the video context */
53
    vlc_decoder_device *dec_device;
54
55
    /**
56
     * Resulting Video format
57
     *
58
     * Valid, can be changed by the module to change the size or chroma.
59
     */
60
    video_format_t *video_fmt_out;
61
62
    /**
63
    * Pointer to the previous video context
64
    *
65
    * Only valid if use_hwframes is true and when recreating the va module.
66
    * This context can be re-used (held, and set to vctx_out) if the internal
67
    * format/size matches the new cfg.
68
    */
69
    vlc_video_context *vctx_prev;
70
71
    /**
72
     * Pointer to the used video context
73
     *
74
     * The video context must be allocated from the dec_device, filled and set
75
     * to this pointer.
76
     */
77
    vlc_video_context *vctx_out;
78
79
    /**
80
     * Indicate if the module is using the new AVHWFramesContext API
81
     *
82
     * False, by default, set to true if the module is using this API
83
     */
84
    bool use_hwframes;
85
86
    /**
87
     * Request more pictures
88
     *
89
     * 0 by default, set if from the module
90
     */
91
    unsigned extra_pictures;
92
};
93
94
struct vlc_va_operations {
95
    int (*get)(vlc_va_t *, picture_t *pic, AVCodecContext *ctx, AVFrame *frame);
96
    void (*close)(vlc_va_t *, AVCodecContext* ctx);
97
};
98
99
struct vlc_va_t {
100
    struct vlc_object_t obj;
101
102
    void *sys;
103
    const struct vlc_va_operations *ops;
104
};
105
106
typedef int (*vlc_va_open)(vlc_va_t *, struct vlc_va_cfg *cfg);
107
108
#define set_va_callback(activate, priority) \
109
    { \
110
        vlc_va_open open__ = activate; \
111
        (void) open__; \
112
        set_callback(activate) \
113
    } \
114
    set_capability( "hw decoder", priority )
115
116
/**
117
 * Determines whether the hardware acceleration PixelFormat can be used to
118
 * decode pixels.
119
 * @param hwfmt the hardware acceleration pixel format
120
 * @return true if the hardware acceleration should be supported
121
 */
122
bool vlc_va_MightDecode(enum AVPixelFormat hwfmt);
123
124
/**
125
 * Creates an accelerated video decoding back-end for libavcodec.
126
 * @param obj parent VLC object
127
 * @param cfg pointer to a configuration struct
128
 * @return a new VLC object on success, NULL on error.
129
 */
130
vlc_va_t *vlc_va_New(vlc_object_t *obj, struct vlc_va_cfg *cfg);
131
132
/**
133
 * Get a hardware video surface for a libavcodec frame.
134
 * The surface will be used as output for the hardware decoder, and possibly
135
 * also as a reference frame to decode other surfaces.
136
 *
137
 * The type of the surface depends on the hardware pixel format:
138
 * AV_PIX_FMT_D3D11VA_VLD - ID3D11VideoDecoderOutputView*
139
 * AV_PIX_FMT_DXVA2_VLD   - IDirect3DSurface9*
140
 * AV_PIX_FMT_VDPAU       - VdpVideoSurface
141
 * AV_PIX_FMT_VAAPI       - VASurfaceID
142
 *
143
 * @param pic pointer to VLC picture containing the surface [IN/OUT]
144
 * @param ctx pointer to the current AVCodecContext [IN]
145
 * @param frame pointer to the AVFrame [IN]
146
 *
147
 * @note This function needs not be reentrant.
148
 *
149
 * @return VLC_SUCCESS on success, otherwise an error code.
150
 */
151
static inline int vlc_va_Get(vlc_va_t *va, picture_t *pic, AVCodecContext *ctx,
152
                             AVFrame *frame)
153
0
{
154
0
    return va->ops->get(va, pic, ctx, frame);
155
0
}
Unexecuted instantiation: video.c:vlc_va_Get
Unexecuted instantiation: va.c:vlc_va_Get
156
157
/**
158
 * Destroys a libavcodec hardware acceleration back-end.
159
 * All allocated surfaces shall have been released beforehand.
160
 *
161
 * @param avctx pointer to the current AVCodecContext if it needs to be cleaned, NULL otherwise [IN]
162
 */
163
void vlc_va_Delete(vlc_va_t *, AVCodecContext * avctx);
164
165
#endif