VLC 4.0.0-dev
Loading...
Searching...
No Matches
vlc_opengl_interop.h
Go to the documentation of this file.
1/*****************************************************************************
2 * vlc_opengl_interop.h: VLC picture_t to GL texture API
3 *****************************************************************************
4 * Copyright (C) 2019-2022 Videolabs
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
20
21#ifndef VLC_GL_INTEROP_H
22#define VLC_GL_INTEROP_H 1
23
24#include <vlc_es.h>
25#include <vlc_picture.h>
26
27typedef struct vlc_gl_t vlc_gl_t;
30
31struct vlc_gl_interop_ops {
32 /**
33 * Callback to allocate data for bound textures
34 *
35 * This function pointer can be NULL. Software converters should call
36 * glTexImage2D() to allocate textures data (it will be deallocated by the
37 * caller when calling glDeleteTextures()). Won't be called if
38 * handle_texs_gen is true.
39 *
40 * \param interop the OpenGL interop
41 * \param textures array of textures to bind (one per plane)
42 * \param tex_width array of tex width (one per plane)
43 * \param tex_height array of tex height (one per plane)
44 * \return VLC_SUCCESS or a VLC error
45 */
46 int (*allocate_textures)(const struct vlc_gl_interop *interop,
47 uint32_t textures[], const int32_t tex_width[],
48 const int32_t tex_height[]);
49
50 /**
51 * Callback to deallocate data for bound texture
52 *
53 * This function pointer can be NULL. it will be called before calling glDeleteTextures
54 *
55 * \param interop the OpenGL interop
56 * \param textures array of textures to bind (one per plane)
57 */
58 void (*deallocate_textures)(const struct vlc_gl_interop *interop, uint32_t textures[]);
60 /**
61 * Callback to update a picture
62 *
63 * This function pointer cannot be NULL. The implementation should upload
64 * every planes of the picture.
65 *
66 * \param interop the OpenGL interop
67 * \param textures array of textures to bind (one per plane)
68 * \param tex_width array of tex width (one per plane)
69 * \param tex_height array of tex height (one per plane)
70 * \param pic picture to update
71 * \param plane_offset offsets of each picture planes to read data from
72 * (one per plane, can be NULL)
73 * \return VLC_SUCCESS or a VLC error
74 */
75 int (*update_textures)(const struct vlc_gl_interop *interop,
76 uint32_t textures[], const int32_t tex_width[],
77 const int32_t tex_height[], picture_t *pic,
78 const size_t plane_offsets[]);
79
80 /**
81 * Callback to retrieve the transform matrix to apply to texture coordinates
82 *
83 * This function pointer can be NULL. If it is set, it may return NULL.
84 *
85 * Otherwise, it must return a 2x3 matrix, as an array of 6 floats in
86 * column-major order.
87 *
88 * This transform matrix maps 2D homogeneous texture coordinates of the
89 * form (s, t, 1) with s and t in the inclusive range [0, 1] to the
90 * texture coordinate that should be used to sample that location from the
91 * texture.
92 *
93 * The returned pointer is owned by the converter module, and must not be
94 * freed before the module is closed.
95 *
96 * \param interop the OpenGL interop
97 * \return a 2x3 transformation matrix (possibly NULL)
98 */
99 const float *
100 (*get_transform_matrix)(const struct vlc_gl_interop *interop);
101
102 /**
103 * Called before the interop is destroyed
104 *
105 * This function pointer can be NULL.
106 *
107 * \param interop the OpenGL interop
108 */
109 void (*close)(struct vlc_gl_interop *interop);
111
112struct vlc_gl_interop {
114 module_t *module;
115
116 vlc_gl_t *gl;
117 uint32_t tex_target;
119 /* Input format
120 *
121 * This is the format of the pictures received from the core.
122 *
123 * It can be modified from the module open function to request changes from
124 * the core.
125 */
128 /* Output format
129 *
130 * This is the format of the pictures exposed by the interop to the sampler.
131 *
132 * It may differ from the input format:
133 * - the orientation may be vertically flipped
134 * - the chroma contains the "software" chroma if the input chroma is opaque
135 * - the chroma may also be changed internally to a fallback (see
136 * opengl_interop_generic_init())
137 */
140 /* Pointer to decoder video context, set by the caller (can be NULL) */
141 struct vlc_video_context *vctx;
143 /* Set to true if textures are generated from pf_update() */
144 bool handle_texs_gen;
146 /* Initialized by the interop */
147 struct vlc_gl_tex_cfg {
148 /*
149 * Texture scale factor, cannot be 0.
150 * In 4:2:0, 1/1 for the Y texture and 1/2 for the UV texture(s)
151 */
155 int32_t internal;
156 uint32_t format;
157 uint32_t type;
159 unsigned tex_count;
161 void *priv;
162 const struct vlc_gl_interop_ops *ops;
164 /* This avoids each module to link against GetTexFormatSize() directly. */
165 int
166 (*get_tex_format_size)(struct vlc_gl_interop *interop, uint32_t target,
167 uint32_t format, int32_t internal, uint32_t type);
168};
169
170/* Activation function for the OpenGL interop implementations. */
171typedef int (*vlc_gl_interop_probe)(struct vlc_gl_interop *interop);
173static inline int
174vlc_gl_interop_GetTexFormatSize(struct vlc_gl_interop *interop, uint32_t target,
175 uint32_t format, int32_t internal,
176 uint32_t type)
177{
178 return interop->get_tex_format_size(interop, target, format, internal,
179 type);
180}
181
182#endif
#define PICTURE_PLANE_MAX
Maximum number of plane for a picture.
Definition vlc_picture.h:69
Internal module descriptor.
Definition modules.h:76
Video picture.
Definition vlc_picture.h:130
video format description
Definition vlc_es.h:356
Definition vlc_opengl_interop.h:148
vlc_rational_t h
Definition vlc_opengl_interop.h:154
uint32_t format
Definition vlc_opengl_interop.h:157
vlc_rational_t w
Definition vlc_opengl_interop.h:153
uint32_t type
Definition vlc_opengl_interop.h:158
int32_t internal
Definition vlc_opengl_interop.h:156
Definition vlc_opengl_interop.h:32
int(* update_textures)(const struct vlc_gl_interop *interop, uint32_t textures[], const int32_t tex_width[], const int32_t tex_height[], picture_t *pic, const size_t plane_offsets[])
Callback to update a picture.
Definition vlc_opengl_interop.h:76
void(* deallocate_textures)(const struct vlc_gl_interop *interop, uint32_t textures[])
Callback to deallocate data for bound texture.
Definition vlc_opengl_interop.h:59
int(* allocate_textures)(const struct vlc_gl_interop *interop, uint32_t textures[], const int32_t tex_width[], const int32_t tex_height[])
Callback to allocate data for bound textures.
Definition vlc_opengl_interop.h:47
void(* close)(struct vlc_gl_interop *interop)
Called before the interop is destroyed.
Definition vlc_opengl_interop.h:110
Definition vlc_opengl_interop.h:113
void * priv
Definition vlc_opengl_interop.h:162
struct vlc_gl_interop::vlc_gl_tex_cfg texs[(5)]
bool handle_texs_gen
Definition vlc_opengl_interop.h:145
video_format_t fmt_out
Definition vlc_opengl_interop.h:139
int(* get_tex_format_size)(struct vlc_gl_interop *interop, uint32_t target, uint32_t format, int32_t internal, uint32_t type)
Definition vlc_opengl_interop.h:167
video_format_t fmt_in
Definition vlc_opengl_interop.h:127
vlc_object_t obj
Definition vlc_opengl_interop.h:114
const struct vlc_gl_interop_ops * ops
Definition vlc_opengl_interop.h:163
struct vlc_video_context * vctx
Definition vlc_opengl_interop.h:142
module_t *vlc_gl_t * gl
Definition vlc_opengl_interop.h:117
unsigned tex_count
Definition vlc_opengl_interop.h:160
uint32_t tex_target
Definition vlc_opengl_interop.h:118
Definition vlc_opengl.h:100
VLC object common members.
Definition vlc_objects.h:53
Definition fourcc_gen.c:34
Definition decoder_device.c:98
This file is a collection of common definitions and types.
This file defines the elementary streams format types.
int(* vlc_gl_interop_probe)(struct vlc_gl_interop *interop)
Definition vlc_opengl_interop.h:172
static int vlc_gl_interop_GetTexFormatSize(struct vlc_gl_interop *interop, uint32_t target, uint32_t format, int32_t internal, uint32_t type)
Definition vlc_opengl_interop.h:175
This file defines picture structures and functions in vlc.