VLC 4.0.0-dev
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
27struct vlc_gl_interop;
29
30struct vlc_gl_interop_ops {
31 /**
32 * Callback to allocate data for bound textures
33 *
34 * This function pointer can be NULL. Software converters should call
35 * glTexImage2D() to allocate textures data (it will be deallocated by the
36 * caller when calling glDeleteTextures()). Won't be called if
37 * handle_texs_gen is true.
38 *
39 * \param interop the OpenGL interop
40 * \param textures array of textures to bind (one per plane)
41 * \param tex_width array of tex width (one per plane)
42 * \param tex_height array of tex height (one per plane)
43 * \return VLC_SUCCESS or a VLC error
44 */
45 int (*allocate_textures)(const struct vlc_gl_interop *interop,
46 uint32_t textures[], const int32_t tex_width[],
47 const int32_t tex_height[]);
48
49 /**
50 * Callback to update a picture
51 *
52 * This function pointer cannot be NULL. The implementation should upload
53 * every planes of the picture.
54 *
55 * \param interop the OpenGL interop
56 * \param textures array of textures to bind (one per plane)
57 * \param tex_width array of tex width (one per plane)
58 * \param tex_height array of tex height (one per plane)
59 * \param pic picture to update
60 * \param plane_offset offsets of each picture planes to read data from
61 * (one per plane, can be NULL)
62 * \return VLC_SUCCESS or a VLC error
63 */
64 int (*update_textures)(const struct vlc_gl_interop *interop,
65 uint32_t textures[], const int32_t tex_width[],
66 const int32_t tex_height[], picture_t *pic,
67 const size_t plane_offsets[]);
68
69 /**
70 * Callback to retrieve the transform matrix to apply to texture coordinates
71 *
72 * This function pointer can be NULL. If it is set, it may return NULL.
73 *
74 * Otherwise, it must return a 2x3 matrix, as an array of 6 floats in
75 * column-major order.
76 *
77 * This transform matrix maps 2D homogeneous texture coordinates of the
78 * form (s, t, 1) with s and t in the inclusive range [0, 1] to the
79 * texture coordinate that should be used to sample that location from the
80 * texture.
81 *
82 * The returned pointer is owned by the converter module, and must not be
83 * freed before the module is closed.
84 *
85 * \param interop the OpenGL interop
86 * \return a 2x3 transformation matrix (possibly NULL)
87 */
88 const float *
89 (*get_transform_matrix)(const struct vlc_gl_interop *interop);
90
91 /**
92 * Called before the interop is destroyed
93 *
94 * This function pointer can be NULL.
95 *
96 * \param interop the OpenGL interop
97 */
98 void (*close)(struct vlc_gl_interop *interop);
99};
100
101struct vlc_gl_interop {
105 vlc_gl_t *gl;
106 uint32_t tex_target;
108 /* Input format
109 *
110 * This is the format of the pictures received from the core.
111 *
112 * It can be modified from the module open function to request changes from
113 * the core.
114 */
117 /* Output format
118 *
119 * This is the format of the pictures exposed by the interop to the sampler.
120 *
121 * It may differ from the input format:
122 * - the orientation may be vertically flipped
123 * - the chroma contains the "software" chroma if the input chroma is opaque
124 * - the chroma may also be changed internally to a fallback (see
125 * opengl_interop_generic_init())
126 */
129 /* Pointer to decoder video context, set by the caller (can be NULL) */
130 struct vlc_video_context *vctx;
132 /* Set to true if textures are generated from pf_update() */
133 bool handle_texs_gen;
135 /* Initialized by the interop */
136 struct vlc_gl_tex_cfg {
137 /*
138 * Texture scale factor, cannot be 0.
139 * In 4:2:0, 1/1 for the Y texture and 1/2 for the UV texture(s)
140 */
144 int32_t internal;
145 uint32_t format;
146 uint32_t type;
148 unsigned tex_count;
150 void *priv;
151 const struct vlc_gl_interop_ops *ops;
153 /* This avoids each module to link against GetTexFormatSize() directly. */
154 int
155 (*get_tex_format_size)(struct vlc_gl_interop *interop, uint32_t target,
156 uint32_t format, int32_t internal, uint32_t type);
157};
158
159static inline int
160vlc_gl_interop_GetTexFormatSize(struct vlc_gl_interop *interop, uint32_t target,
161 uint32_t format, int32_t internal,
162 uint32_t type)
163{
164 return interop->get_tex_format_size(interop, target, format, internal,
165 type);
166}
167
168#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:352
Definition: vlc_opengl_interop.h:137
vlc_rational_t h
Definition: vlc_opengl_interop.h:143
uint32_t format
Definition: vlc_opengl_interop.h:146
vlc_rational_t w
Definition: vlc_opengl_interop.h:142
uint32_t type
Definition: vlc_opengl_interop.h:147
int32_t internal
Definition: vlc_opengl_interop.h:145
Definition: vlc_opengl_interop.h:31
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:65
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:46
void(* close)(struct vlc_gl_interop *interop)
Called before the interop is destroyed.
Definition: vlc_opengl_interop.h:99
Definition: vlc_opengl_interop.h:102
void * priv
Definition: vlc_opengl_interop.h:151
struct vlc_gl_interop::vlc_gl_tex_cfg texs[(5)]
bool handle_texs_gen
Definition: vlc_opengl_interop.h:134
module_t * module
Definition: vlc_opengl_interop.h:104
video_format_t fmt_out
Definition: vlc_opengl_interop.h:128
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:156
video_format_t fmt_in
Definition: vlc_opengl_interop.h:116
vlc_object_t obj
Definition: vlc_opengl_interop.h:103
const struct vlc_gl_interop_ops * ops
Definition: vlc_opengl_interop.h:152
struct vlc_video_context * vctx
Definition: vlc_opengl_interop.h:131
unsigned tex_count
Definition: vlc_opengl_interop.h:149
vlc_gl_t * gl
Definition: vlc_opengl_interop.h:106
uint32_t tex_target
Definition: vlc_opengl_interop.h:107
Definition: vlc_opengl.h:98
VLC object common members.
Definition: vlc_objects.h:45
Definition: fourcc_gen.c:34
Definition: decoder_device.c:97
This file is a collection of common definitions and types.
This file defines the elementary streams format types.
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:161
This file defines picture structures and functions in vlc.