FFmpeg
opengl_enc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Lukasz Marek
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 //TODO: support for more formats
22 //TODO: support for more systems.
23 //TODO: implement X11, Windows, Mac OS native default window. SDL 1.2 doesn't allow to render to custom thread.
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stddef.h>
29 
30 #include "config.h"
31 
32 #if HAVE_WINDOWS_H
33 #include <windows.h>
34 #endif
35 #if HAVE_OPENGL_GL3_H
36 #include <OpenGL/gl3.h>
37 #elif HAVE_ES2_GL_H
38 #include <ES2/gl.h>
39 #else
40 #include <GL/gl.h>
41 #include <GL/glext.h>
42 #endif
43 #if HAVE_GLXGETPROCADDRESS
44 #include <GL/glx.h>
45 #endif
46 
47 #if CONFIG_SDL2
48 #include <SDL.h>
49 #endif
50 
51 #include "libavutil/common.h"
52 #include "libavutil/frame.h"
53 #include "libavutil/mem.h"
54 #include "libavutil/pixdesc.h"
55 #include "libavutil/log.h"
56 #include "libavutil/opt.h"
57 #include "libavutil/avassert.h"
58 #include "libavformat/avformat.h"
59 #include "libavformat/internal.h"
60 #include "libavformat/mux.h"
61 #include "libavdevice/avdevice.h"
62 #include "opengl_enc_shaders.h"
63 
64 #ifndef APIENTRY
65 #define APIENTRY
66 #endif
67 
68 /* FF_GL_RED_COMPONENT is used for planar pixel types.
69  * Only red component is sampled in shaders.
70  * On some platforms GL_RED is not available and GL_LUMINANCE have to be used,
71  * but since OpenGL 3.0 GL_LUMINANCE is deprecated.
72  * GL_RED produces RGBA = value, 0, 0, 1.
73  * GL_LUMINANCE produces RGBA = value, value, value, 1.
74  * Note: GL_INTENSITY may also be used which produce RGBA = value, value, value, value. */
75 #if defined(GL_RED)
76 #define FF_GL_RED_COMPONENT GL_RED
77 #elif defined(GL_LUMINANCE)
78 #define FF_GL_RED_COMPONENT GL_LUMINANCE
79 #else
80 #define FF_GL_RED_COMPONENT 0x1903; //GL_RED
81 #endif
82 
83 /* Constants not defined for iOS */
84 #define FF_GL_UNSIGNED_BYTE_3_3_2 0x8032
85 #define FF_GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
86 #define FF_GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
87 #define FF_GL_UNPACK_ROW_LENGTH 0x0CF2
88 
89 /* MinGW exposes only OpenGL 1.1 API */
90 #define FF_GL_ARRAY_BUFFER 0x8892
91 #define FF_GL_ELEMENT_ARRAY_BUFFER 0x8893
92 #define FF_GL_STATIC_DRAW 0x88E4
93 #define FF_GL_FRAGMENT_SHADER 0x8B30
94 #define FF_GL_VERTEX_SHADER 0x8B31
95 #define FF_GL_COMPILE_STATUS 0x8B81
96 #define FF_GL_LINK_STATUS 0x8B82
97 #define FF_GL_INFO_LOG_LENGTH 0x8B84
98 typedef void (APIENTRY *FF_PFNGLACTIVETEXTUREPROC) (GLenum texture);
99 typedef void (APIENTRY *FF_PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
100 typedef void (APIENTRY *FF_PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
101 typedef void (APIENTRY *FF_PFNGLBUFFERDATAPROC) (GLenum target, ptrdiff_t size, const GLvoid *data, GLenum usage);
102 typedef void (APIENTRY *FF_PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
103 typedef GLint (APIENTRY *FF_PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const char *name);
105 typedef void (APIENTRY *FF_PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, uintptr_t pointer);
106 typedef GLint (APIENTRY *FF_PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const char *name);
107 typedef void (APIENTRY *FF_PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0);
108 typedef void (APIENTRY *FF_PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
109 typedef void (APIENTRY *FF_PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
110 typedef GLuint (APIENTRY *FF_PFNGLCREATEPROGRAMPROC) (void);
111 typedef void (APIENTRY *FF_PFNGLDELETEPROGRAMPROC) (GLuint program);
112 typedef void (APIENTRY *FF_PFNGLUSEPROGRAMPROC) (GLuint program);
113 typedef void (APIENTRY *FF_PFNGLLINKPROGRAMPROC) (GLuint program);
114 typedef void (APIENTRY *FF_PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
115 typedef void (APIENTRY *FF_PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, char *infoLog);
116 typedef void (APIENTRY *FF_PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
117 typedef GLuint (APIENTRY *FF_PFNGLCREATESHADERPROC) (GLenum type);
118 typedef void (APIENTRY *FF_PFNGLDELETESHADERPROC) (GLuint shader);
119 typedef void (APIENTRY *FF_PFNGLCOMPILESHADERPROC) (GLuint shader);
120 typedef void (APIENTRY *FF_PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const char* *string, const GLint *length);
121 typedef void (APIENTRY *FF_PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
122 typedef void (APIENTRY *FF_PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, char *infoLog);
123 
124 typedef struct FFOpenGLFunctions {
125  FF_PFNGLACTIVETEXTUREPROC glActiveTexture; //Require GL ARB multitexture
126  FF_PFNGLGENBUFFERSPROC glGenBuffers; //Require GL_ARB_vertex_buffer_object
127  FF_PFNGLDELETEBUFFERSPROC glDeleteBuffers; //Require GL_ARB_vertex_buffer_object
128  FF_PFNGLBUFFERDATAPROC glBufferData; //Require GL_ARB_vertex_buffer_object
129  FF_PFNGLBINDBUFFERPROC glBindBuffer; //Require GL_ARB_vertex_buffer_object
130  FF_PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation; //Require GL_ARB_vertex_shader
133  FF_PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; //Require GL_ARB_shader_objects
134  FF_PFNGLUNIFORM1FPROC glUniform1f; //Require GL_ARB_shader_objects
135  FF_PFNGLUNIFORM1IPROC glUniform1i; //Require GL_ARB_shader_objects
136  FF_PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; //Require GL_ARB_shader_objects
137  FF_PFNGLCREATEPROGRAMPROC glCreateProgram; //Require GL_ARB_shader_objects
138  FF_PFNGLDELETEPROGRAMPROC glDeleteProgram; //Require GL_ARB_shader_objects
139  FF_PFNGLUSEPROGRAMPROC glUseProgram; //Require GL_ARB_shader_objects
140  FF_PFNGLLINKPROGRAMPROC glLinkProgram; //Require GL_ARB_shader_objects
141  FF_PFNGLGETPROGRAMIVPROC glGetProgramiv; //Require GL_ARB_shader_objects
142  FF_PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; //Require GL_ARB_shader_objects
143  FF_PFNGLATTACHSHADERPROC glAttachShader; //Require GL_ARB_shader_objects
144  FF_PFNGLCREATESHADERPROC glCreateShader; //Require GL_ARB_shader_objects
145  FF_PFNGLDELETESHADERPROC glDeleteShader; //Require GL_ARB_shader_objects
146  FF_PFNGLCOMPILESHADERPROC glCompileShader; //Require GL_ARB_shader_objects
147  FF_PFNGLSHADERSOURCEPROC glShaderSource; //Require GL_ARB_shader_objects
148  FF_PFNGLGETSHADERIVPROC glGetShaderiv; //Require GL_ARB_shader_objects
149  FF_PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; //Require GL_ARB_shader_objects
151 
152 #define OPENGL_ERROR_CHECK(ctx) \
153 {\
154  GLenum err_code; \
155  if ((err_code = glGetError()) != GL_NO_ERROR) { \
156  av_log(ctx, AV_LOG_ERROR, "OpenGL error occurred in '%s', line %d: %d\n", __func__, __LINE__, err_code); \
157  goto fail; \
158  } \
159 }\
160 
161 typedef struct OpenGLVertexInfo
162 {
163  float x, y, z; ///<Position
164  float s0, t0; ///<Texture coords
166 
167 /* defines 2 triangles to display */
168 static const GLushort g_index[6] =
169 {
170  0, 1, 2,
171  0, 3, 2,
172 };
173 
174 typedef struct OpenGLContext {
175  AVClass *class; ///< class for private options
176 
177 #if CONFIG_SDL2
178  SDL_Window *window;
179  SDL_GLContext glcontext;
180 #endif
182 
183  int inited; ///< Set to 1 when write_header was successfully called.
184  uint8_t background[4]; ///< Background color
185  int no_window; ///< 0 for create default window
186  char *window_title; ///< Title of the window
187 
188  /* OpenGL implementation limits */
189  GLint max_texture_size; ///< Maximum texture size
190  GLint max_viewport_width; ///< Maximum viewport size
191  GLint max_viewport_height; ///< Maximum viewport size
192  int non_pow_2_textures; ///< 1 when non power of 2 textures are supported
193  int unpack_subimage; ///< 1 when GL_EXT_unpack_subimage is available
194 
195  /* Current OpenGL configuration */
196  GLuint program; ///< Shader program
197  GLuint vertex_shader; ///< Vertex shader
198  GLuint fragment_shader; ///< Fragment shader for current pix_pmt
199  GLuint texture_name[4]; ///< Textures' IDs
200  GLuint index_buffer; ///< Index buffer
201  GLuint vertex_buffer; ///< Vertex buffer
203  GLint projection_matrix_location; ///< Uniforms' locations
209  GLint position_attrib; ///< Attibutes' locations
211 
212  GLfloat projection_matrix[16]; ///< Projection matrix
213  GLfloat model_view_matrix[16]; ///< Modev view matrix
214  GLfloat color_map[16]; ///< RGBA color map matrix
215  GLfloat chroma_div_w; ///< Chroma subsampling w ratio
216  GLfloat chroma_div_h; ///< Chroma subsampling h ratio
217 
218  /* Stream information */
219  GLenum format;
220  GLenum type;
221  int width; ///< Stream width
222  int height; ///< Stream height
223  enum AVPixelFormat pix_fmt; ///< Stream pixel format
224  int picture_width; ///< Rendered width
225  int picture_height; ///< Rendered height
228 
229  int warned;
230 } OpenGLContext;
231 
232 static const struct OpenGLFormatDesc {
234  const char * const * fragment_shader;
235  GLenum format;
236  GLenum type;
237 } opengl_format_desc[] = {
253  { AV_PIX_FMT_RGB24, &FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET, GL_RGB, GL_UNSIGNED_BYTE },
254  { AV_PIX_FMT_BGR24, &FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET, GL_RGB, GL_UNSIGNED_BYTE },
255  { AV_PIX_FMT_0RGB, &FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET, GL_RGBA, GL_UNSIGNED_BYTE },
256  { AV_PIX_FMT_RGB0, &FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET, GL_RGBA, GL_UNSIGNED_BYTE },
257  { AV_PIX_FMT_0BGR, &FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET, GL_RGBA, GL_UNSIGNED_BYTE },
258  { AV_PIX_FMT_BGR0, &FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET, GL_RGBA, GL_UNSIGNED_BYTE },
259  { AV_PIX_FMT_RGB565, &FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 },
260  { AV_PIX_FMT_BGR565, &FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 },
265  { AV_PIX_FMT_RGB48, &FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET, GL_RGB, GL_UNSIGNED_SHORT },
266  { AV_PIX_FMT_BGR48, &FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET, GL_RGB, GL_UNSIGNED_SHORT },
267  { AV_PIX_FMT_ARGB, &FF_OPENGL_FRAGMENT_SHADER_RGBA_PACKET, GL_RGBA, GL_UNSIGNED_BYTE },
268  { AV_PIX_FMT_RGBA, &FF_OPENGL_FRAGMENT_SHADER_RGBA_PACKET, GL_RGBA, GL_UNSIGNED_BYTE },
269  { AV_PIX_FMT_ABGR, &FF_OPENGL_FRAGMENT_SHADER_RGBA_PACKET, GL_RGBA, GL_UNSIGNED_BYTE },
270  { AV_PIX_FMT_BGRA, &FF_OPENGL_FRAGMENT_SHADER_RGBA_PACKET, GL_RGBA, GL_UNSIGNED_BYTE },
271  { AV_PIX_FMT_RGBA64, &FF_OPENGL_FRAGMENT_SHADER_RGBA_PACKET, GL_RGBA, GL_UNSIGNED_SHORT },
272  { AV_PIX_FMT_BGRA64, &FF_OPENGL_FRAGMENT_SHADER_RGBA_PACKET, GL_RGBA, GL_UNSIGNED_SHORT },
279  { AV_PIX_FMT_NONE, NULL }
280 };
281 
283 static int opengl_draw(AVFormatContext *h, void *intput, int repaint, int is_pkt);
284 static av_cold int opengl_init_context(OpenGLContext *opengl);
285 
287 {
288  glDeleteTextures(4, opengl->texture_name);
289  opengl->texture_name[0] = opengl->texture_name[1] =
290  opengl->texture_name[2] = opengl->texture_name[3] = 0;
291  if (opengl->glprocs.glUseProgram)
292  opengl->glprocs.glUseProgram(0);
293  if (opengl->glprocs.glDeleteProgram) {
294  opengl->glprocs.glDeleteProgram(opengl->program);
295  opengl->program = 0;
296  }
297  if (opengl->glprocs.glDeleteShader) {
298  opengl->glprocs.glDeleteShader(opengl->vertex_shader);
299  opengl->glprocs.glDeleteShader(opengl->fragment_shader);
300  opengl->vertex_shader = opengl->fragment_shader = 0;
301  }
302  if (opengl->glprocs.glBindBuffer) {
305  }
306  if (opengl->glprocs.glDeleteBuffers) {
307  opengl->glprocs.glDeleteBuffers(2, &opengl->index_buffer);
308  opengl->vertex_buffer = opengl->index_buffer = 0;
309  }
310 }
311 
313 {
314  int ret = 0;
315  OpenGLContext *opengl = h->priv_data;
316  opengl->window_width = width;
317  opengl->window_height = height;
318  if (opengl->inited) {
319  if (opengl->no_window &&
321  av_log(opengl, AV_LOG_ERROR, "Application failed to prepare window buffer.\n");
322  goto end;
323  }
324  if ((ret = opengl_prepare_vertex(h)) < 0)
325  goto end;
326  ret = opengl_draw(h, NULL, 1, 0);
327  }
328  end:
329  return ret;
330 }
331 
332 static int opengl_control_message(AVFormatContext *h, int type, void *data, size_t data_size)
333 {
334  OpenGLContext *opengl = h->priv_data;
335  switch(type) {
337  if (data) {
339  return opengl_resize(h, message->width, message->height);
340  }
341  return AVERROR(EINVAL);
343  return opengl_resize(h, opengl->window_width, opengl->window_height);
344  }
345  return AVERROR(ENOSYS);
346 }
347 
348 #if CONFIG_SDL2
349 static int opengl_sdl_process_events(AVFormatContext *h)
350 {
351  OpenGLContext *opengl = h->priv_data;
353  SDL_Event event;
354  SDL_PumpEvents();
355  while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) > 0) {
356  switch (event.type) {
357  case SDL_QUIT:
358  return AVERROR(EIO);
359  case SDL_KEYDOWN:
360  switch (event.key.keysym.sym) {
361  case SDLK_ESCAPE:
362  case SDLK_q:
363  return AVERROR(EIO);
364  }
365  return 0;
366  case SDL_WINDOWEVENT:
367  switch(event.window.event) {
368  case SDL_WINDOWEVENT_RESIZED:
369  case SDL_WINDOWEVENT_SIZE_CHANGED:
370  SDL_GL_GetDrawableSize(opengl->window, &message.width, &message.height);
372  default:
373  break;
374  }
375  }
376  }
377  return 0;
378 }
379 
380 static int av_cold opengl_sdl_create_window(AVFormatContext *h)
381 {
382  OpenGLContext *opengl = h->priv_data;
384  if (SDL_Init(SDL_INIT_VIDEO)) {
385  av_log(opengl, AV_LOG_ERROR, "Unable to initialize SDL: %s\n", SDL_GetError());
386  return AVERROR_EXTERNAL;
387  }
388  opengl->window = SDL_CreateWindow(opengl->window_title,
389  SDL_WINDOWPOS_UNDEFINED,
390  SDL_WINDOWPOS_UNDEFINED,
391  opengl->window_width, opengl->window_height,
392  SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
393  if (!opengl->window) {
394  av_log(opengl, AV_LOG_ERROR, "Unable to create default window: %s\n", SDL_GetError());
395  return AVERROR_EXTERNAL;
396  }
397  opengl->glcontext = SDL_GL_CreateContext(opengl->window);
398  if (!opengl->glcontext) {
399  av_log(opengl, AV_LOG_ERROR, "Unable to create OpenGL context on default window: %s\n", SDL_GetError());
400  return AVERROR_EXTERNAL;
401  }
402  SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
403  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
404  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
405  SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
406  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
407  av_log(opengl, AV_LOG_INFO, "SDL driver: '%s'.\n", SDL_GetCurrentVideoDriver());
408  SDL_GL_GetDrawableSize(opengl->window, &message.width, &message.height);
410 }
411 
412 static int av_cold opengl_sdl_load_procedures(OpenGLContext *opengl)
413 {
414  FFOpenGLFunctions *procs = &opengl->glprocs;
415 
416 #define LOAD_OPENGL_FUN(name, type) \
417  procs->name = (type)SDL_GL_GetProcAddress(#name); \
418  if (!procs->name) { \
419  av_log(opengl, AV_LOG_ERROR, "Cannot load OpenGL function: '%s'\n", #name); \
420  return AVERROR(ENOSYS); \
421  }
422 
428  LOAD_OPENGL_FUN(glGetAttribLocation, FF_PFNGLGETATTRIBLOCATIONPROC)
429  LOAD_OPENGL_FUN(glGetUniformLocation, FF_PFNGLGETUNIFORMLOCATIONPROC)
432  LOAD_OPENGL_FUN(glUniformMatrix4fv, FF_PFNGLUNIFORMMATRIX4FVPROC)
438  LOAD_OPENGL_FUN(glGetProgramInfoLog, FF_PFNGLGETPROGRAMINFOLOGPROC)
445  LOAD_OPENGL_FUN(glGetShaderInfoLog, FF_PFNGLGETSHADERINFOLOGPROC)
446  LOAD_OPENGL_FUN(glEnableVertexAttribArray, FF_PFNGLENABLEVERTEXATTRIBARRAYPROC)
447  LOAD_OPENGL_FUN(glVertexAttribPointer, FF_PFNGLVERTEXATTRIBPOINTERPROC)
448 
449  return 0;
450 
451 #undef LOAD_OPENGL_FUN
452 }
453 #endif /* CONFIG_SDL2 */
454 
455 #if defined(__APPLE__)
456 static int av_cold opengl_load_procedures(OpenGLContext *opengl)
457 {
458  FFOpenGLFunctions *procs = &opengl->glprocs;
459 
460 #if CONFIG_SDL2
461  if (!opengl->no_window)
462  return opengl_sdl_load_procedures(opengl);
463 #endif
464 
465  procs->glActiveTexture = glActiveTexture;
466  procs->glGenBuffers = glGenBuffers;
467  procs->glDeleteBuffers = glDeleteBuffers;
468  procs->glBufferData = glBufferData;
469  procs->glBindBuffer = glBindBuffer;
470  procs->glGetAttribLocation = glGetAttribLocation;
471  procs->glGetUniformLocation = glGetUniformLocation;
472  procs->glUniform1f = glUniform1f;
473  procs->glUniform1i = glUniform1i;
474  procs->glUniformMatrix4fv = glUniformMatrix4fv;
475  procs->glCreateProgram = glCreateProgram;
476  procs->glDeleteProgram = glDeleteProgram;
477  procs->glUseProgram = glUseProgram;
478  procs->glLinkProgram = glLinkProgram;
479  procs->glGetProgramiv = glGetProgramiv;
480  procs->glGetProgramInfoLog = glGetProgramInfoLog;
481  procs->glAttachShader = glAttachShader;
482  procs->glCreateShader = glCreateShader;
483  procs->glDeleteShader = glDeleteShader;
484  procs->glCompileShader = glCompileShader;
485  procs->glShaderSource = glShaderSource;
486  procs->glGetShaderiv = glGetShaderiv;
487  procs->glGetShaderInfoLog = glGetShaderInfoLog;
488  procs->glEnableVertexAttribArray = glEnableVertexAttribArray;
489  procs->glVertexAttribPointer = (FF_PFNGLVERTEXATTRIBPOINTERPROC) glVertexAttribPointer;
490  return 0;
491 }
492 #else
494 {
495  FFOpenGLFunctions *procs = &opengl->glprocs;
496 
497 #if HAVE_GLXGETPROCADDRESS
498 #define SelectedGetProcAddress glXGetProcAddress
499 #elif HAVE_WGLGETPROCADDRESS
500 #define SelectedGetProcAddress wglGetProcAddress
501 #endif
502 
503 #define LOAD_OPENGL_FUN(name, type) \
504  procs->name = (type)SelectedGetProcAddress(#name); \
505  if (!procs->name) { \
506  av_log(opengl, AV_LOG_ERROR, "Cannot load OpenGL function: '%s'\n", #name); \
507  return AVERROR(ENOSYS); \
508  }
509 
510 #if CONFIG_SDL2
511  if (!opengl->no_window)
512  return opengl_sdl_load_procedures(opengl);
513 #endif
514 
520  LOAD_OPENGL_FUN(glGetAttribLocation, FF_PFNGLGETATTRIBLOCATIONPROC)
521  LOAD_OPENGL_FUN(glGetUniformLocation, FF_PFNGLGETUNIFORMLOCATIONPROC)
524  LOAD_OPENGL_FUN(glUniformMatrix4fv, FF_PFNGLUNIFORMMATRIX4FVPROC)
530  LOAD_OPENGL_FUN(glGetProgramInfoLog, FF_PFNGLGETPROGRAMINFOLOGPROC)
537  LOAD_OPENGL_FUN(glGetShaderInfoLog, FF_PFNGLGETSHADERINFOLOGPROC)
538  LOAD_OPENGL_FUN(glEnableVertexAttribArray, FF_PFNGLENABLEVERTEXATTRIBARRAYPROC)
539  LOAD_OPENGL_FUN(glVertexAttribPointer, FF_PFNGLVERTEXATTRIBPOINTERPROC)
540 
541  return 0;
542 
543 #undef SelectedGetProcAddress
544 #undef LOAD_OPENGL_FUN
545 }
546 #endif
547 
548 static void opengl_make_identity(float matrix[16])
549 {
550  memset(matrix, 0, 16 * sizeof(float));
551  matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1.0f;
552 }
553 
554 static void opengl_make_ortho(float matrix[16], float left, float right,
555  float bottom, float top, float nearZ, float farZ)
556 {
557  float ral = right + left;
558  float rsl = right - left;
559  float tab = top + bottom;
560  float tsb = top - bottom;
561  float fan = farZ + nearZ;
562  float fsn = farZ - nearZ;
563 
564  memset(matrix, 0, 16 * sizeof(float));
565  matrix[0] = 2.0f / rsl;
566  matrix[5] = 2.0f / tsb;
567  matrix[10] = -2.0f / fsn;
568  matrix[12] = -ral / rsl;
569  matrix[13] = -tab / tsb;
570  matrix[14] = -fan / fsn;
571  matrix[15] = 1.0f;
572 }
573 
575 {
576  OpenGLContext *opengl = h->priv_data;
577  static const struct{
578  const char *extension;
579  int major;
580  int minor;
581  } required_extensions[] = {
582  { "GL_ARB_multitexture", 1, 3 },
583  { "GL_ARB_vertex_buffer_object", 1, 5 }, //GLX_ARB_vertex_buffer_object
584  { "GL_ARB_vertex_shader", 2, 0 },
585  { "GL_ARB_fragment_shader", 2, 0 },
586  { "GL_ARB_shader_objects", 2, 0 },
587  { NULL, 0, 0 }
588  };
589  int i, major, minor;
590  const char *extensions, *version;
591 
592  version = glGetString(GL_VERSION);
593  extensions = glGetString(GL_EXTENSIONS);
594  if (!version || !extensions) {
595  av_log(h, AV_LOG_ERROR, "No OpenGL context initialized for the current thread\n");
596  return AVERROR(ENOSYS);
597  }
598 
599  av_log(h, AV_LOG_DEBUG, "OpenGL version: %s\n", version);
600  if (sscanf(version, "%d.%d", &major, &minor) != 2)
601  return AVERROR(ENOSYS);
602 
603  for (i = 0; required_extensions[i].extension; i++) {
604  if (major < required_extensions[i].major &&
605  (major == required_extensions[i].major && minor < required_extensions[i].minor) &&
606  !strstr(extensions, required_extensions[i].extension)) {
607  av_log(h, AV_LOG_ERROR, "Required extension %s is not supported.\n",
608  required_extensions[i].extension);
609  av_log(h, AV_LOG_DEBUG, "Supported extensions are: %s\n", extensions);
610  return AVERROR(ENOSYS);
611  }
612  }
613  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &opengl->max_texture_size);
614  glGetIntegerv(GL_MAX_VIEWPORT_DIMS, &opengl->max_viewport_width);
615  opengl->non_pow_2_textures = major >= 2 || strstr(extensions, "GL_ARB_texture_non_power_of_two");
616 #if defined(GL_ES_VERSION_2_0)
617  opengl->unpack_subimage = !!strstr(extensions, "GL_EXT_unpack_subimage");
618 #else
619  opengl->unpack_subimage = 1;
620 #endif
621 
622  av_log(h, AV_LOG_DEBUG, "Non Power of 2 textures support: %s\n", opengl->non_pow_2_textures ? "Yes" : "No");
623  av_log(h, AV_LOG_DEBUG, "Unpack Subimage extension support: %s\n", opengl->unpack_subimage ? "Yes" : "No");
624  av_log(h, AV_LOG_DEBUG, "Max texture size: %dx%d\n", opengl->max_texture_size, opengl->max_texture_size);
625  av_log(h, AV_LOG_DEBUG, "Max viewport size: %dx%d\n",
626  opengl->max_viewport_width, opengl->max_viewport_height);
627 
628  OPENGL_ERROR_CHECK(opengl);
629  return 0;
630  fail:
631  return AVERROR_EXTERNAL;
632 }
633 
635 {
636  int i;
637  for (i = 0; i < FF_ARRAY_ELEMS(opengl_format_desc); i++) {
638  if (opengl_format_desc[i].fixel_format == format)
640  }
641  return NULL;
642 }
643 
644 static int opengl_type_size(GLenum type)
645 {
646  switch(type) {
647  case GL_UNSIGNED_SHORT:
649  case GL_UNSIGNED_SHORT_5_6_5:
650  return 2;
651  case GL_UNSIGNED_BYTE:
654  default:
655  break;
656  }
657  return 1;
658 }
659 
661 {
662  int i;
663  for (i = 0; i < FF_ARRAY_ELEMS(opengl_format_desc); i++) {
664  if (opengl_format_desc[i].fixel_format == opengl->pix_fmt) {
665  opengl->format = opengl_format_desc[i].format;
666  opengl->type = opengl_format_desc[i].type;
667  break;
668  }
669  }
670 }
671 
673 {
674  AVRational sar, dar; /* sample and display aspect ratios */
675  OpenGLContext *opengl = s->priv_data;
676  AVStream *st = s->streams[0];
677  AVCodecParameters *par = st->codecpar;
678 
679  /* compute overlay width and height from the codec context information */
680  sar = st->sample_aspect_ratio.num ? st->sample_aspect_ratio : (AVRational){ 1, 1 };
681  dar = av_mul_q(sar, (AVRational){ par->width, par->height });
682 
683  /* we suppose the screen has a 1/1 sample aspect ratio */
684  /* fit in the window */
685  if (av_cmp_q(dar, (AVRational){ opengl->window_width, opengl->window_height }) > 0) {
686  /* fit in width */
687  opengl->picture_width = opengl->window_width;
688  opengl->picture_height = av_rescale(opengl->picture_width, dar.den, dar.num);
689  } else {
690  /* fit in height */
691  opengl->picture_height = opengl->window_height;
692  opengl->picture_width = av_rescale(opengl->picture_height, dar.num, dar.den);
693  }
694 }
695 
696 static av_cold void opengl_get_texture_size(OpenGLContext *opengl, int in_width, int in_height,
697  int *out_width, int *out_height)
698 {
699  if (opengl->non_pow_2_textures) {
700  *out_width = in_width;
701  *out_height = in_height;
702  } else {
703  int max = FFMIN(FFMAX(in_width, in_height), opengl->max_texture_size);
704  unsigned power_of_2 = 1;
705  while (power_of_2 < max)
706  power_of_2 *= 2;
707  *out_height = power_of_2;
708  *out_width = power_of_2;
709  av_log(opengl, AV_LOG_DEBUG, "Texture size calculated from %dx%d into %dx%d\n",
710  in_width, in_height, *out_width, *out_height);
711  }
712 }
713 
715 {
716  const AVPixFmtDescriptor *desc;
717  int shift;
718  enum AVPixelFormat pix_fmt = opengl->pix_fmt;
719 
720  /* We need order of components, not exact position, some minor HACKs here */
726 
728  if (!(desc->flags & AV_PIX_FMT_FLAG_RGB))
729  return;
730 
731 #define FILL_COMPONENT(i) { \
732  shift = (desc->comp[i].depth - 1) >> 3; \
733  opengl->color_map[(i << 2) + (desc->comp[i].offset >> shift)] = 1.0; \
734  }
735 
736  memset(opengl->color_map, 0, sizeof(opengl->color_map));
737  FILL_COMPONENT(0);
738  FILL_COMPONENT(1);
739  FILL_COMPONENT(2);
740  if (desc->flags & AV_PIX_FMT_FLAG_ALPHA)
741  FILL_COMPONENT(3);
742 
743 #undef FILL_COMPONENT
744 }
745 
746 static av_cold GLuint opengl_load_shader(OpenGLContext *opengl, GLenum type, const char *source)
747 {
748  GLuint shader = opengl->glprocs.glCreateShader(type);
749  GLint result;
750  if (!shader) {
751  av_log(opengl, AV_LOG_ERROR, "glCreateShader() failed\n");
752  return 0;
753  }
754  opengl->glprocs.glShaderSource(shader, 1, &source, NULL);
755  opengl->glprocs.glCompileShader(shader);
756 
758  if (!result) {
759  char *log;
761  if (result) {
762  if ((log = av_malloc(result))) {
763  opengl->glprocs.glGetShaderInfoLog(shader, result, NULL, log);
764  av_log(opengl, AV_LOG_ERROR, "Compile error: %s\n", log);
765  av_free(log);
766  }
767  }
768  goto fail;
769  }
770  OPENGL_ERROR_CHECK(opengl);
771  return shader;
772  fail:
773  opengl->glprocs.glDeleteShader(shader);
774  return 0;
775 }
776 
778 {
779  GLint result;
780  const char *fragment_shader_code = opengl_get_fragment_shader_code(pix_fmt);
781 
782  if (!fragment_shader_code) {
783  av_log(opengl, AV_LOG_ERROR, "Provided pixel format '%s' is not supported\n",
785  return AVERROR(EINVAL);
786  }
787 
790  if (!opengl->vertex_shader) {
791  av_log(opengl, AV_LOG_ERROR, "Vertex shader loading failed.\n");
792  goto fail;
793  }
795  fragment_shader_code);
796  if (!opengl->fragment_shader) {
797  av_log(opengl, AV_LOG_ERROR, "Fragment shader loading failed.\n");
798  goto fail;
799  }
800 
801  opengl->program = opengl->glprocs.glCreateProgram();
802  if (!opengl->program)
803  goto fail;
804 
805  opengl->glprocs.glAttachShader(opengl->program, opengl->vertex_shader);
806  opengl->glprocs.glAttachShader(opengl->program, opengl->fragment_shader);
807  opengl->glprocs.glLinkProgram(opengl->program);
808 
810  if (!result) {
811  char *log;
813  if (result) {
814  log = av_malloc(result);
815  if (!log)
816  goto fail;
817  opengl->glprocs.glGetProgramInfoLog(opengl->program, result, NULL, log);
818  av_log(opengl, AV_LOG_ERROR, "Link error: %s\n", log);
819  av_free(log);
820  }
821  goto fail;
822  }
823 
824  opengl->position_attrib = opengl->glprocs.glGetAttribLocation(opengl->program, "a_position");
825  opengl->texture_coords_attrib = opengl->glprocs.glGetAttribLocation(opengl->program, "a_textureCoords");
826  opengl->projection_matrix_location = opengl->glprocs.glGetUniformLocation(opengl->program, "u_projectionMatrix");
827  opengl->model_view_matrix_location = opengl->glprocs.glGetUniformLocation(opengl->program, "u_modelViewMatrix");
828  opengl->color_map_location = opengl->glprocs.glGetUniformLocation(opengl->program, "u_colorMap");
829  opengl->texture_location[0] = opengl->glprocs.glGetUniformLocation(opengl->program, "u_texture0");
830  opengl->texture_location[1] = opengl->glprocs.glGetUniformLocation(opengl->program, "u_texture1");
831  opengl->texture_location[2] = opengl->glprocs.glGetUniformLocation(opengl->program, "u_texture2");
832  opengl->texture_location[3] = opengl->glprocs.glGetUniformLocation(opengl->program, "u_texture3");
833  opengl->chroma_div_w_location = opengl->glprocs.glGetUniformLocation(opengl->program, "u_chroma_div_w");
834  opengl->chroma_div_h_location = opengl->glprocs.glGetUniformLocation(opengl->program, "u_chroma_div_h");
835 
836  OPENGL_ERROR_CHECK(opengl);
837  return 0;
838  fail:
839  opengl->glprocs.glDeleteShader(opengl->vertex_shader);
840  opengl->glprocs.glDeleteShader(opengl->fragment_shader);
841  opengl->glprocs.glDeleteProgram(opengl->program);
842  opengl->fragment_shader = opengl->vertex_shader = opengl->program = 0;
843  return AVERROR_EXTERNAL;
844 }
845 
846 static av_cold int opengl_configure_texture(OpenGLContext *opengl, GLuint texture,
847  GLsizei width, GLsizei height)
848 {
849  if (texture) {
850  int new_width, new_height;
851  opengl_get_texture_size(opengl, width, height, &new_width, &new_height);
852  glBindTexture(GL_TEXTURE_2D, texture);
853  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
854  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
855  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
856  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
857  glTexImage2D(GL_TEXTURE_2D, 0, opengl->format, new_width, new_height, 0,
858  opengl->format, opengl->type, NULL);
860  }
861  return 0;
862  fail:
863  return AVERROR_EXTERNAL;
864 }
865 
867 {
868  OpenGLContext *opengl = s->priv_data;
869  int tex_w, tex_h;
870 
871  if (opengl->window_width > opengl->max_viewport_width || opengl->window_height > opengl->max_viewport_height) {
872  opengl->window_width = FFMIN(opengl->window_width, opengl->max_viewport_width);
873  opengl->window_height = FFMIN(opengl->window_height, opengl->max_viewport_height);
874  av_log(opengl, AV_LOG_WARNING, "Too big viewport requested, limited to %dx%d", opengl->window_width, opengl->window_height);
875  }
876  glViewport(0, 0, opengl->window_width, opengl->window_height);
878  - (float)opengl->window_width / 2.0f, (float)opengl->window_width / 2.0f,
879  - (float)opengl->window_height / 2.0f, (float)opengl->window_height / 2.0f,
880  1.0f, -1.0f);
882 
884 
885  opengl->vertex[0].z = opengl->vertex[1].z = opengl->vertex[2].z = opengl->vertex[3].z = 0.0f;
886  opengl->vertex[0].x = opengl->vertex[1].x = - (float)opengl->picture_width / 2.0f;
887  opengl->vertex[2].x = opengl->vertex[3].x = (float)opengl->picture_width / 2.0f;
888  opengl->vertex[1].y = opengl->vertex[2].y = - (float)opengl->picture_height / 2.0f;
889  opengl->vertex[0].y = opengl->vertex[3].y = (float)opengl->picture_height / 2.0f;
890 
891  opengl_get_texture_size(opengl, opengl->width, opengl->height, &tex_w, &tex_h);
892 
893  opengl->vertex[0].s0 = 0.0f;
894  opengl->vertex[0].t0 = 0.0f;
895  opengl->vertex[1].s0 = 0.0f;
896  opengl->vertex[1].t0 = (float)opengl->height / (float)tex_h;
897  opengl->vertex[2].s0 = (float)opengl->width / (float)tex_w;
898  opengl->vertex[2].t0 = (float)opengl->height / (float)tex_h;
899  opengl->vertex[3].s0 = (float)opengl->width / (float)tex_w;
900  opengl->vertex[3].t0 = 0.0f;
901 
903  opengl->glprocs.glBufferData(FF_GL_ARRAY_BUFFER, sizeof(opengl->vertex), opengl->vertex, FF_GL_STATIC_DRAW);
905  OPENGL_ERROR_CHECK(opengl);
906  return 0;
907  fail:
908  return AVERROR_EXTERNAL;
909 }
910 
911 static int opengl_prepare(OpenGLContext *opengl)
912 {
913  int i;
914  opengl->glprocs.glUseProgram(opengl->program);
915  opengl->glprocs.glUniformMatrix4fv(opengl->projection_matrix_location, 1, GL_FALSE, opengl->projection_matrix);
916  opengl->glprocs.glUniformMatrix4fv(opengl->model_view_matrix_location, 1, GL_FALSE, opengl->model_view_matrix);
917  for (i = 0; i < 4; i++)
918  if (opengl->texture_location[i] != -1) {
919  opengl->glprocs.glActiveTexture(GL_TEXTURE0 + i);
920  glBindTexture(GL_TEXTURE_2D, opengl->texture_name[i]);
921  opengl->glprocs.glUniform1i(opengl->texture_location[i], i);
922  }
923  if (opengl->color_map_location != -1)
924  opengl->glprocs.glUniformMatrix4fv(opengl->color_map_location, 1, GL_FALSE, opengl->color_map);
925  if (opengl->chroma_div_h_location != -1)
926  opengl->glprocs.glUniform1f(opengl->chroma_div_h_location, opengl->chroma_div_h);
927  if (opengl->chroma_div_w_location != -1)
928  opengl->glprocs.glUniform1f(opengl->chroma_div_w_location, opengl->chroma_div_w);
929 
930  OPENGL_ERROR_CHECK(opengl);
931  return 0;
932  fail:
933  return AVERROR_EXTERNAL;
934 }
935 
937 {
938  OpenGLContext *opengl = h->priv_data;
939  int ret;
940 
941  if (!opengl->no_window) {
942 #if CONFIG_SDL2
943  if ((ret = opengl_sdl_create_window(h)) < 0) {
944  av_log(opengl, AV_LOG_ERROR, "Cannot create default SDL window.\n");
945  return ret;
946  }
947 #else
948  av_log(opengl, AV_LOG_ERROR, "FFmpeg is compiled without SDL. Cannot create default window.\n");
949  return AVERROR(ENOSYS);
950 #endif
951  } else {
953  message.x = message.y = 0;
954  message.width = opengl->window_width;
955  message.height = opengl->window_height;
957  &message , sizeof(message))) < 0) {
958  av_log(opengl, AV_LOG_ERROR, "Application failed to create window buffer.\n");
959  return ret;
960  }
962  av_log(opengl, AV_LOG_ERROR, "Application failed to prepare window buffer.\n");
963  return ret;
964  }
965  }
966  return 0;
967 }
968 
970 {
971  int ret;
972  OpenGLContext *opengl = h->priv_data;
973  if (!opengl->no_window) {
974 #if CONFIG_SDL2
975  SDL_GL_DeleteContext(opengl->glcontext);
976  SDL_DestroyWindow(opengl->window);
977  SDL_Quit();
978 #endif
980  av_log(opengl, AV_LOG_ERROR, "Application failed to release window buffer.\n");
981  return ret;
982  }
983  return 0;
984 }
985 
987 {
988  OpenGLContext *opengl = h->priv_data;
989 
990  if (opengl->no_window &&
992  av_log(opengl, AV_LOG_ERROR, "Application failed to prepare window buffer.\n");
993 
994  opengl_deinit_context(opengl);
996 
997  return 0;
998 }
999 
1001 {
1002  int i, ret;
1003  const AVPixFmtDescriptor *desc;
1004 
1005  if ((ret = opengl_compile_shaders(opengl, opengl->pix_fmt)) < 0)
1006  goto fail;
1007 
1008  desc = av_pix_fmt_desc_get(opengl->pix_fmt);
1009  av_assert0(desc->nb_components > 0 && desc->nb_components <= 4);
1010  glGenTextures(desc->nb_components, opengl->texture_name);
1011 
1012  opengl->glprocs.glGenBuffers(2, &opengl->index_buffer);
1013  if (!opengl->index_buffer || !opengl->vertex_buffer) {
1014  av_log(opengl, AV_LOG_ERROR, "Buffer generation failed.\n");
1016  goto fail;
1017  }
1018 
1019  opengl_configure_texture(opengl, opengl->texture_name[0], opengl->width, opengl->height);
1020  if (desc->nb_components > 1) {
1021  int has_alpha = desc->flags & AV_PIX_FMT_FLAG_ALPHA;
1022  int num_planes = desc->nb_components - (has_alpha ? 1 : 0);
1023  if (opengl->non_pow_2_textures) {
1024  opengl->chroma_div_w = 1.0f;
1025  opengl->chroma_div_h = 1.0f;
1026  } else {
1027  opengl->chroma_div_w = 1 << desc->log2_chroma_w;
1028  opengl->chroma_div_h = 1 << desc->log2_chroma_h;
1029  }
1030  for (i = 1; i < num_planes; i++)
1031  if (opengl->non_pow_2_textures)
1032  opengl_configure_texture(opengl, opengl->texture_name[i],
1033  AV_CEIL_RSHIFT(opengl->width, desc->log2_chroma_w),
1034  AV_CEIL_RSHIFT(opengl->height, desc->log2_chroma_h));
1035  else
1036  opengl_configure_texture(opengl, opengl->texture_name[i], opengl->width, opengl->height);
1037  if (has_alpha)
1038  opengl_configure_texture(opengl, opengl->texture_name[3], opengl->width, opengl->height);
1039  }
1040 
1044 
1045  glEnable(GL_BLEND);
1046  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1047 
1048  glClearColor((float)opengl->background[0] / 255.0f, (float)opengl->background[1] / 255.0f,
1049  (float)opengl->background[2] / 255.0f, 1.0f);
1050 
1052  OPENGL_ERROR_CHECK(opengl);
1053 
1054  return 0;
1055  fail:
1056  return ret;
1057 }
1058 
1060 {
1061  OpenGLContext *opengl = h->priv_data;
1062  AVCodecParameters *par = h->streams[0]->codecpar;
1063  AVStream *st;
1064  int ret;
1065 
1066  if (!opengl->warned) {
1067  av_log(opengl, AV_LOG_WARNING,
1068  "The opengl output device is deprecated due to being fundamentally incompatible with libavformat API. "
1069  "For monitoring purposes in ffmpeg you can output to a file or use pipes and a video player.\n"
1070  "Example: ffmpeg -i INPUT -f nut -c:v rawvideo - | ffplay -\n"
1071  );
1072  opengl->warned = 1;
1073  }
1074 
1075  if (h->nb_streams != 1 ||
1076  par->codec_type != AVMEDIA_TYPE_VIDEO ||
1078  av_log(opengl, AV_LOG_ERROR, "Only a single raw or wrapped avframe video stream is supported.\n");
1079  return AVERROR(EINVAL);
1080  }
1081  st = h->streams[0];
1082  opengl->width = st->codecpar->width;
1083  opengl->height = st->codecpar->height;
1084  opengl->pix_fmt = st->codecpar->format;
1085  if (!opengl->window_width)
1086  opengl->window_width = opengl->width;
1087  if (!opengl->window_height)
1088  opengl->window_height = opengl->height;
1089 
1090  if (!opengl->window_title && !opengl->no_window)
1091  opengl->window_title = av_strdup(h->url);
1092 
1093  if ((ret = opengl_create_window(h)))
1094  goto fail;
1095 
1096  if ((ret = opengl_read_limits(h)) < 0)
1097  goto fail;
1098 
1099  if (opengl->width > opengl->max_texture_size || opengl->height > opengl->max_texture_size) {
1100  av_log(opengl, AV_LOG_ERROR, "Too big picture %dx%d, max supported size is %dx%d\n",
1101  opengl->width, opengl->height, opengl->max_texture_size, opengl->max_texture_size);
1102  ret = AVERROR(EINVAL);
1103  goto fail;
1104  }
1105 
1106  if ((ret = opengl_load_procedures(opengl)) < 0)
1107  goto fail;
1108 
1109  opengl_fill_color_map(opengl);
1110  opengl_get_texture_params(opengl);
1111 
1112  if ((ret = opengl_init_context(opengl)) < 0)
1113  goto fail;
1114 
1115  if ((ret = opengl_prepare_vertex(h)) < 0)
1116  goto fail;
1117 
1118  glClear(GL_COLOR_BUFFER_BIT);
1119 
1120 #if CONFIG_SDL2
1121  if (!opengl->no_window)
1122  SDL_GL_SwapWindow(opengl->window);
1123 #endif
1124  if (opengl->no_window &&
1126  av_log(opengl, AV_LOG_ERROR, "Application failed to display window buffer.\n");
1127  goto fail;
1128  }
1129 
1131  OPENGL_ERROR_CHECK(opengl);
1132 
1133  opengl->inited = 1;
1134  return 0;
1135 
1136  fail:
1138  return ret;
1139 }
1140 
1141 static uint8_t* opengl_get_plane_pointer(OpenGLContext *opengl, AVPacket *pkt, int comp_index,
1142  const AVPixFmtDescriptor *desc)
1143 {
1144  uint8_t *data = pkt->data;
1145  int wordsize = opengl_type_size(opengl->type);
1146  int width_chroma = AV_CEIL_RSHIFT(opengl->width, desc->log2_chroma_w);
1147  int height_chroma = AV_CEIL_RSHIFT(opengl->height, desc->log2_chroma_h);
1148  int plane = desc->comp[comp_index].plane;
1149 
1150  switch(plane) {
1151  case 0:
1152  break;
1153  case 1:
1154  data += opengl->width * opengl->height * wordsize;
1155  break;
1156  case 2:
1157  data += opengl->width * opengl->height * wordsize;
1158  data += width_chroma * height_chroma * wordsize;
1159  break;
1160  case 3:
1161  data += opengl->width * opengl->height * wordsize;
1162  data += 2 * width_chroma * height_chroma * wordsize;
1163  break;
1164  default:
1165  return NULL;
1166  }
1167  return data;
1168 }
1169 
1170 #define LOAD_TEXTURE_DATA(comp_index, sub) \
1171 { \
1172  int width = sub ? AV_CEIL_RSHIFT(opengl->width, desc->log2_chroma_w) : opengl->width; \
1173  int height = sub ? AV_CEIL_RSHIFT(opengl->height, desc->log2_chroma_h): opengl->height; \
1174  uint8_t *data; \
1175  int plane = desc->comp[comp_index].plane; \
1176  \
1177  glBindTexture(GL_TEXTURE_2D, opengl->texture_name[comp_index]); \
1178  if (!is_pkt) { \
1179  GLint length = ((AVFrame *)input)->linesize[plane]; \
1180  int bytes_per_pixel = opengl_type_size(opengl->type); \
1181  if (!(desc->flags & AV_PIX_FMT_FLAG_PLANAR)) \
1182  bytes_per_pixel *= desc->nb_components; \
1183  data = ((AVFrame *)input)->data[plane]; \
1184  if (!(length % bytes_per_pixel) && \
1185  (opengl->unpack_subimage || ((length / bytes_per_pixel) == width))) { \
1186  length /= bytes_per_pixel; \
1187  if (length != width) \
1188  glPixelStorei(FF_GL_UNPACK_ROW_LENGTH, length); \
1189  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, \
1190  opengl->format, opengl->type, data); \
1191  if (length != width) \
1192  glPixelStorei(FF_GL_UNPACK_ROW_LENGTH, 0); \
1193  } else { \
1194  int h; \
1195  for (h = 0; h < height; h++) { \
1196  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, h, width, 1, \
1197  opengl->format, opengl->type, data); \
1198  data += length; \
1199  } \
1200  } \
1201  } else { \
1202  data = opengl_get_plane_pointer(opengl, input, comp_index, desc); \
1203  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, \
1204  opengl->format, opengl->type, data); \
1205  } \
1206 }
1207 
1208 static int opengl_draw(AVFormatContext *h, void *input, int repaint, int is_pkt)
1209 {
1210  OpenGLContext *opengl = h->priv_data;
1211  enum AVPixelFormat pix_fmt = h->streams[0]->codecpar->format;
1213  int ret;
1214 
1215 #if CONFIG_SDL2
1216  /* At this point, opengl->glcontext implies opengl->glcontext */
1217  if (opengl->glcontext)
1218  SDL_GL_MakeCurrent(opengl->window, opengl->glcontext);
1219 
1220  if (!opengl->no_window && (ret = opengl_sdl_process_events(h)) < 0)
1221  goto fail;
1222 #endif
1223  if (opengl->no_window &&
1225  av_log(opengl, AV_LOG_ERROR, "Application failed to prepare window buffer.\n");
1226  goto fail;
1227  }
1228 
1229  glClear(GL_COLOR_BUFFER_BIT);
1230 
1231  if (!repaint) {
1232  if (is_pkt)
1233  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1234  LOAD_TEXTURE_DATA(0, 0)
1235  if (desc->flags & AV_PIX_FMT_FLAG_PLANAR) {
1236  LOAD_TEXTURE_DATA(1, 1)
1237  LOAD_TEXTURE_DATA(2, 1)
1238  if (desc->flags & AV_PIX_FMT_FLAG_ALPHA)
1239  LOAD_TEXTURE_DATA(3, 0)
1240  }
1241  }
1243  OPENGL_ERROR_CHECK(opengl);
1244 
1245  if ((ret = opengl_prepare(opengl)) < 0)
1246  goto fail;
1247 
1250  opengl->glprocs.glVertexAttribPointer(opengl->position_attrib, 3, GL_FLOAT, GL_FALSE, sizeof(OpenGLVertexInfo), 0);
1252  opengl->glprocs.glVertexAttribPointer(opengl->texture_coords_attrib, 2, GL_FLOAT, GL_FALSE, sizeof(OpenGLVertexInfo), 12);
1254 
1255  glDrawElements(GL_TRIANGLES, FF_ARRAY_ELEMS(g_index), GL_UNSIGNED_SHORT, 0);
1256 
1258  OPENGL_ERROR_CHECK(opengl);
1259 
1260 #if CONFIG_SDL2
1261  if (!opengl->no_window)
1262  SDL_GL_SwapWindow(opengl->window);
1263 #endif
1264  if (opengl->no_window &&
1266  av_log(opengl, AV_LOG_ERROR, "Application failed to display window buffer.\n");
1267  goto fail;
1268  }
1269 
1270  return 0;
1271  fail:
1272  return ret;
1273 }
1274 
1276 {
1277  AVCodecParameters *par = h->streams[0]->codecpar;
1278  if (par->codec_id == AV_CODEC_ID_WRAPPED_AVFRAME) {
1279  AVFrame *frame = (AVFrame *)pkt->data;
1280  return opengl_draw(h, frame, 0, 0);
1281  } else {
1282  return opengl_draw(h, pkt, 0, 1);
1283  }
1284 }
1285 
1286 static int opengl_write_frame(AVFormatContext *h, int stream_index,
1287  AVFrame **frame, unsigned flags)
1288 {
1290  return 0;
1291  return opengl_draw(h, *frame, 0, 0);
1292 }
1293 
1294 #define OFFSET(x) offsetof(OpenGLContext, x)
1295 #define ENC AV_OPT_FLAG_ENCODING_PARAM
1296 static const AVOption options[] = {
1297  { "background", "set background color", OFFSET(background), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, ENC },
1298  { "no_window", "disable default window", OFFSET(no_window), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, ENC },
1299  { "window_title", "set window title", OFFSET(window_title), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, ENC },
1300  { "window_size", "set window size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, ENC },
1301  { NULL }
1302 };
1303 
1304 static const AVClass opengl_class = {
1305  .class_name = "opengl outdev",
1306  .item_name = av_default_item_name,
1307  .option = options,
1308  .version = LIBAVUTIL_VERSION_INT,
1310 };
1311 
1313  .p.name = "opengl",
1314  .p.long_name = NULL_IF_CONFIG_SMALL("OpenGL output"),
1315  .p.audio_codec = AV_CODEC_ID_NONE,
1316  .p.video_codec = AV_CODEC_ID_WRAPPED_AVFRAME,
1318  .p.priv_class = &opengl_class,
1319  .priv_data_size = sizeof(OpenGLContext),
1322  .write_uncoded_frame = opengl_write_frame,
1324  .control_message = opengl_control_message,
1325 };
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:522
OpenGLContext::vertex_buffer
GLuint vertex_buffer
Vertex buffer.
Definition: opengl_enc.c:201
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:501
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
OpenGLContext::width
int width
Stream width.
Definition: opengl_enc.c:221
FF_OPENGL_FRAGMENT_SHADER_RGBA_PACKET
static const char *const FF_OPENGL_FRAGMENT_SHADER_RGBA_PACKET
Fragment shader for packet RGBA formats.
Definition: opengl_enc_shaders.h:44
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
FF_PFNGLSHADERSOURCEPROC
void(APIENTRY * FF_PFNGLSHADERSOURCEPROC)(GLuint shader, GLsizei count, const char **string, const GLint *length)
Definition: opengl_enc.c:120
program
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C program
Definition: undefined.txt:6
options
static const AVOption options[]
Definition: opengl_enc.c:1296
AVOutputFormat::name
const char * name
Definition: avformat.h:510
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
FF_PFNGLCREATESHADERPROC
GLuint(APIENTRY * FF_PFNGLCREATESHADERPROC)(GLenum type)
Definition: opengl_enc.c:117
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
ff_opengl_muxer
const FFOutputFormat ff_opengl_muxer
Definition: opengl_enc.c:1312
message
Definition: api-threadmessage-test.c:47
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
OpenGLContext::chroma_div_h_location
GLint chroma_div_h_location
Definition: opengl_enc.c:207
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2965
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:482
opengl_enc_shaders.h
matrix
Definition: vc1dsp.c:43
FFOpenGLFunctions::glGetProgramiv
FF_PFNGLGETPROGRAMIVPROC glGetProgramiv
Definition: opengl_enc.c:141
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:479
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:65
OpenGLContext::texture_location
GLint texture_location[4]
Definition: opengl_enc.c:208
opengl_init_context
static av_cold int opengl_init_context(OpenGLContext *opengl)
Definition: opengl_enc.c:1000
normalize.log
log
Definition: normalize.py:21
AV_DEV_TO_APP_PREPARE_WINDOW_BUFFER
@ AV_DEV_TO_APP_PREPARE_WINDOW_BUFFER
Prepare window buffer message.
Definition: avdevice.h:235
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
pixdesc.h
opengl_control_message
static int opengl_control_message(AVFormatContext *h, int type, void *data, size_t data_size)
Definition: opengl_enc.c:332
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:521
OpenGLFormatDesc::type
GLenum type
Definition: opengl_enc.c:236
opengl_get_fragment_shader_code
static const char * opengl_get_fragment_shader_code(enum AVPixelFormat format)
Definition: opengl_enc.c:634
AVPacket::data
uint8_t * data
Definition: packet.h:524
AVOption
AVOption.
Definition: opt.h:357
OpenGLContext::max_viewport_width
GLint max_viewport_width
Maximum viewport size.
Definition: opengl_enc.c:190
data
const char data[16]
Definition: mxf.c:148
avdevice_dev_to_app_control_message
int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type, void *data, size_t data_size)
Send control message from device to application.
Definition: avdevice.c:34
FF_OPENGL_VERTEX_SHADER
static const char *const FF_OPENGL_VERTEX_SHADER
Definition: opengl_enc_shaders.h:26
g_index
static const GLushort g_index[6]
Definition: opengl_enc.c:168
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:76
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
OpenGLContext::vertex_shader
GLuint vertex_shader
Vertex shader.
Definition: opengl_enc.c:197
OpenGLContext::no_window
int no_window
0 for create default window
Definition: opengl_enc.c:185
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
max
#define max(a, b)
Definition: cuda_runtime.h:33
FF_PFNGLDELETEBUFFERSPROC
void(APIENTRY * FF_PFNGLDELETEBUFFERSPROC)(GLsizei n, const GLuint *buffers)
Definition: opengl_enc.c:100
FF_PFNGLATTACHSHADERPROC
void(APIENTRY * FF_PFNGLATTACHSHADERPROC)(GLuint program, GLuint shader)
Definition: opengl_enc.c:116
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
OpenGLContext::color_map
GLfloat color_map[16]
RGBA color map matrix.
Definition: opengl_enc.c:214
opengl_load_shader
static av_cold GLuint opengl_load_shader(OpenGLContext *opengl, GLenum type, const char *source)
Definition: opengl_enc.c:746
AV_APP_TO_DEV_WINDOW_REPAINT
@ AV_APP_TO_DEV_WINDOW_REPAINT
Repaint request message.
Definition: avdevice.h:150
FF_OPENGL_FRAGMENT_SHADER_GRAY
static const char *const FF_OPENGL_FRAGMENT_SHADER_GRAY
Definition: opengl_enc_shaders.h:176
FF_PFNGLCOMPILESHADERPROC
void(APIENTRY * FF_PFNGLCOMPILESHADERPROC)(GLuint shader)
Definition: opengl_enc.c:119
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:65
FF_PFNGLGETSHADERIVPROC
void(APIENTRY * FF_PFNGLGETSHADERIVPROC)(GLuint shader, GLenum pname, GLint *params)
Definition: opengl_enc.c:121
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
OpenGLVertexInfo::z
float z
Position.
Definition: opengl_enc.c:163
FF_GL_UNSIGNED_SHORT_1_5_5_5_REV
#define FF_GL_UNSIGNED_SHORT_1_5_5_5_REV
Definition: opengl_enc.c:86
OpenGLContext::chroma_div_h
GLfloat chroma_div_h
Chroma subsampling h ratio.
Definition: opengl_enc.c:216
FF_GL_UNSIGNED_BYTE_2_3_3_REV
#define FF_GL_UNSIGNED_BYTE_2_3_3_REV
Definition: opengl_enc.c:85
window
static SDL_Window * window
Definition: ffplay.c:361
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:212
FF_PFNGLUNIFORM1IPROC
void(APIENTRY * FF_PFNGLUNIFORM1IPROC)(GLint location, GLint v0)
Definition: opengl_enc.c:108
v0
#define v0
Definition: regdef.h:26
fail
#define fail()
Definition: checkasm.h:182
FFOpenGLFunctions::glCreateProgram
FF_PFNGLCREATEPROGRAMPROC glCreateProgram
Definition: opengl_enc.c:137
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:523
opengl_compute_display_area
static void opengl_compute_display_area(AVFormatContext *s)
Definition: opengl_enc.c:672
tab
static const struct twinvq_data tab
Definition: twinvq_data.h:10345
OpenGLContext::texture_name
GLuint texture_name[4]
Textures' IDs.
Definition: opengl_enc.c:199
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
OpenGLFormatDesc::fixel_format
enum AVPixelFormat fixel_format
Definition: opengl_enc.c:233
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:462
opengl_write_frame
static int opengl_write_frame(AVFormatContext *h, int stream_index, AVFrame **frame, unsigned flags)
Definition: opengl_enc.c:1286
APIENTRY
#define APIENTRY
Definition: opengl_enc.c:65
opengl_configure_texture
static av_cold int opengl_configure_texture(OpenGLContext *opengl, GLuint texture, GLsizei width, GLsizei height)
Definition: opengl_enc.c:846
OFFSET
#define OFFSET(x)
Definition: opengl_enc.c:1294
AVRational::num
int num
Numerator.
Definition: rational.h:59
FFOpenGLFunctions::glUniformMatrix4fv
FF_PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv
Definition: opengl_enc.c:136
FF_PFNGLGETSHADERINFOLOGPROC
void(APIENTRY * FF_PFNGLGETSHADERINFOLOGPROC)(GLuint shader, GLsizei bufSize, GLsizei *length, char *infoLog)
Definition: opengl_enc.c:122
OpenGLContext::fragment_shader
GLuint fragment_shader
Fragment shader for current pix_pmt.
Definition: opengl_enc.c:198
FFOpenGLFunctions::glCreateShader
FF_PFNGLCREATESHADERPROC glCreateShader
Definition: opengl_enc.c:144
AV_PIX_FMT_BGR8
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:90
avassert.h
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
OpenGLContext::texture_coords_attrib
GLint texture_coords_attrib
Definition: opengl_enc.c:210
opengl_prepare
static int opengl_prepare(OpenGLContext *opengl)
Definition: opengl_enc.c:911
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
opengl_get_texture_size
static av_cold void opengl_get_texture_size(OpenGLContext *opengl, int in_width, int in_height, int *out_width, int *out_height)
Definition: opengl_enc.c:696
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:490
OpenGLContext::picture_height
int picture_height
Rendered height.
Definition: opengl_enc.c:225
opengl_make_ortho
static void opengl_make_ortho(float matrix[16], float left, float right, float bottom, float top, float nearZ, float farZ)
Definition: opengl_enc.c:554
AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER
@ AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER
Display window buffer message.
Definition: avdevice.h:246
OpenGLContext::position_attrib
GLint position_attrib
Attibutes' locations.
Definition: opengl_enc.c:209
float
float
Definition: af_crystalizer.c:121
OpenGLContext::format
GLenum format
Definition: opengl_enc.c:219
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
OpenGLContext::color_map_location
GLint color_map_location
Definition: opengl_enc.c:205
LOAD_OPENGL_FUN
#define LOAD_OPENGL_FUN(name, type)
OpenGLFormatDesc
Definition: opengl_enc.c:232
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:491
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:59
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:134
OpenGLContext::unpack_subimage
int unpack_subimage
1 when GL_EXT_unpack_subimage is available
Definition: opengl_enc.c:193
FFOpenGLFunctions::glUniform1i
FF_PFNGLUNIFORM1IPROC glUniform1i
Definition: opengl_enc.c:135
FF_PFNGLBINDBUFFERPROC
void(APIENTRY * FF_PFNGLBINDBUFFERPROC)(GLenum target, GLuint buffer)
Definition: opengl_enc.c:102
AV_DEV_TO_APP_CREATE_WINDOW_BUFFER
@ AV_DEV_TO_APP_CREATE_WINDOW_BUFFER
Create window buffer message.
Definition: avdevice.h:224
OpenGLContext::window_height
int window_height
Definition: opengl_enc.c:227
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
opengl_write_packet
static int opengl_write_packet(AVFormatContext *h, AVPacket *pkt)
Definition: opengl_enc.c:1275
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:489
opengl_make_identity
static void opengl_make_identity(float matrix[16])
Definition: opengl_enc.c:548
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:147
FF_OPENGL_FRAGMENT_SHADER_RGB_PLANAR
static const char *const FF_OPENGL_FRAGMENT_SHADER_RGB_PLANAR
Fragment shader for planar RGB formats.
Definition: opengl_enc_shaders.h:100
FF_PFNGLBUFFERDATAPROC
void(APIENTRY * FF_PFNGLBUFFERDATAPROC)(GLenum target, ptrdiff_t size, const GLvoid *data, GLenum usage)
Definition: opengl_enc.c:101
FF_GL_FRAGMENT_SHADER
#define FF_GL_FRAGMENT_SHADER
Definition: opengl_enc.c:93
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
AV_CODEC_ID_WRAPPED_AVFRAME
@ AV_CODEC_ID_WRAPPED_AVFRAME
Passthrough codec, AVFrames wrapped in AVPacket.
Definition: codec_id.h:601
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
opengl_format_desc
static const struct OpenGLFormatDesc opengl_format_desc[]
FF_PFNGLUNIFORM1FPROC
void(APIENTRY * FF_PFNGLUNIFORM1FPROC)(GLint location, GLfloat v0)
Definition: opengl_enc.c:107
window_title
static const char * window_title
Definition: ffplay.c:307
AVFormatContext
Format I/O context.
Definition: avformat.h:1255
OpenGLContext::max_viewport_height
GLint max_viewport_height
Maximum viewport size.
Definition: opengl_enc.c:191
internal.h
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:497
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:766
OpenGLContext::window_title
char * window_title
Title of the window.
Definition: opengl_enc.c:186
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:468
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
result
and forward the result(frame or status change) to the corresponding input. If nothing is possible
AV_PIX_FMT_BGR48
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:469
NULL
#define NULL
Definition: coverity.c:32
FF_PFNGLVERTEXATTRIBPOINTERPROC
void(APIENTRY * FF_PFNGLVERTEXATTRIBPOINTERPROC)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, uintptr_t pointer)
Definition: opengl_enc.c:105
FFOpenGLFunctions::glGetAttribLocation
FF_PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation
Definition: opengl_enc.c:130
FF_PFNGLENABLEVERTEXATTRIBARRAYPROC
void(APIENTRY * FF_PFNGLENABLEVERTEXATTRIBARRAYPROC)(GLuint index)
Definition: opengl_enc.c:104
ENC
#define ENC
Definition: opengl_enc.c:1295
opengl_read_limits
static av_cold int opengl_read_limits(AVFormatContext *h)
Definition: opengl_enc.c:574
write_trailer
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:101
OpenGLVertexInfo::x
float x
Definition: opengl_enc.c:163
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
OpenGLContext::warned
int warned
Definition: opengl_enc.c:229
FF_GL_VERTEX_SHADER
#define FF_GL_VERTEX_SHADER
Definition: opengl_enc.c:94
OpenGLContext::program
GLuint program
Shader program.
Definition: opengl_enc.c:196
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Definition: opt.h:260
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive ints
Definition: opt.h:255
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
FF_OPENGL_FRAGMENT_SHADER_YUV_PLANAR
static const char *const FF_OPENGL_FRAGMENT_SHADER_YUV_PLANAR
Fragment shader for planar YUV formats.
Definition: opengl_enc_shaders.h:121
AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT
@ AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT
Definition: log.h:40
FF_OPENGL_FRAGMENT_SHADER_RGBA_PLANAR
static const char *const FF_OPENGL_FRAGMENT_SHADER_RGBA_PLANAR
Fragment shader for planar RGBA formats.
Definition: opengl_enc_shaders.h:78
FFOutputFormat
Definition: mux.h:61
OpenGLContext::pix_fmt
enum AVPixelFormat pix_fmt
Stream pixel format.
Definition: opengl_enc.c:223
FFOpenGLFunctions::glGetShaderInfoLog
FF_PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog
Definition: opengl_enc.c:149
AV_PIX_FMT_RGB8
@ AV_PIX_FMT_RGB8
packed RGB 3:3:2, 8bpp, (msb)3R 3G 2B(lsb)
Definition: pixfmt.h:93
AV_PIX_FMT_BGR0
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:265
opengl_fill_color_map
static av_cold void opengl_fill_color_map(OpenGLContext *opengl)
Definition: opengl_enc.c:714
FF_PFNGLDELETESHADERPROC
void(APIENTRY * FF_PFNGLDELETESHADERPROC)(GLuint shader)
Definition: opengl_enc.c:118
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
AV_PIX_FMT_ABGR
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:101
FF_PFNGLGETPROGRAMIVPROC
void(APIENTRY * FF_PFNGLGETPROGRAMIVPROC)(GLuint program, GLenum pname, GLint *params)
Definition: opengl_enc.c:114
opengl_compile_shaders
static av_cold int opengl_compile_shaders(OpenGLContext *opengl, enum AVPixelFormat pix_fmt)
Definition: opengl_enc.c:777
index
int index
Definition: gxfenc.c:90
OPENGL_ERROR_CHECK
#define OPENGL_ERROR_CHECK(ctx)
Definition: opengl_enc.c:152
source
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a source
Definition: filter_design.txt:255
FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET
static const char *const FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET
Fragment shader for packet RGB formats.
Definition: opengl_enc_shaders.h:61
usage
const char * usage
Definition: floatimg_cmp.c:60
opengl_deinit_context
static av_cold void opengl_deinit_context(OpenGLContext *opengl)
Definition: opengl_enc.c:286
FFOpenGLFunctions::glUniform1f
FF_PFNGLUNIFORM1FPROC glUniform1f
Definition: opengl_enc.c:134
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
opengl_prepare_vertex
static av_cold int opengl_prepare_vertex(AVFormatContext *s)
Definition: opengl_enc.c:866
opengl_load_procedures
static int av_cold opengl_load_procedures(OpenGLContext *opengl)
Definition: opengl_enc.c:493
opengl_draw
static int opengl_draw(AVFormatContext *h, void *intput, int repaint, int is_pkt)
Definition: opengl_enc.c:1208
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
FF_GL_COMPILE_STATUS
#define FF_GL_COMPILE_STATUS
Definition: opengl_enc.c:95
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:136
shift
static int shift(int a, int b)
Definition: bonk.c:261
FFOpenGLFunctions::glCompileShader
FF_PFNGLCOMPILESHADERPROC glCompileShader
Definition: opengl_enc.c:146
OpenGLContext::glprocs
FFOpenGLFunctions glprocs
Definition: opengl_enc.c:181
FF_GL_STATIC_DRAW
#define FF_GL_STATIC_DRAW
Definition: opengl_enc.c:92
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:464
size
int size
Definition: twinvq_data.h:10344
FF_GL_ELEMENT_ARRAY_BUFFER
#define FF_GL_ELEMENT_ARRAY_BUFFER
Definition: opengl_enc.c:91
FF_PFNGLUSEPROGRAMPROC
void(APIENTRY * FF_PFNGLUSEPROGRAMPROC)(GLuint program)
Definition: opengl_enc.c:112
AV_PIX_FMT_BGR555
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:471
opengl_get_plane_pointer
static uint8_t * opengl_get_plane_pointer(OpenGLContext *opengl, AVPacket *pkt, int comp_index, const AVPixFmtDescriptor *desc)
Definition: opengl_enc.c:1141
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:468
OpenGLContext::chroma_div_w
GLfloat chroma_div_w
Chroma subsampling w ratio.
Definition: opengl_enc.c:215
OpenGLContext::projection_matrix_location
GLint projection_matrix_location
Uniforms' locations.
Definition: opengl_enc.c:203
FFOpenGLFunctions::glLinkProgram
FF_PFNGLLINKPROGRAMPROC glLinkProgram
Definition: opengl_enc.c:140
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:821
frame.h
avdevice.h
OpenGLContext::picture_width
int picture_width
Rendered width.
Definition: opengl_enc.c:224
height
#define height
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:174
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
OpenGLContext::index_buffer
GLuint index_buffer
Index buffer.
Definition: opengl_enc.c:200
AV_PIX_FMT_RGB0
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:263
version
version
Definition: libkvazaar.c:321
FFOpenGLFunctions::glDeleteProgram
FF_PFNGLDELETEPROGRAMPROC glDeleteProgram
Definition: opengl_enc.c:138
FF_GL_LINK_STATUS
#define FF_GL_LINK_STATUS
Definition: opengl_enc.c:96
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
OpenGLContext::height
int height
Stream height.
Definition: opengl_enc.c:222
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:99
OpenGLVertexInfo::s0
float s0
Definition: opengl_enc.c:164
FF_PFNGLGETPROGRAMINFOLOGPROC
void(APIENTRY * FF_PFNGLGETPROGRAMINFOLOGPROC)(GLuint program, GLsizei bufSize, GLsizei *length, char *infoLog)
Definition: opengl_enc.c:115
FFOpenGLFunctions::glDeleteShader
FF_PFNGLDELETESHADERPROC glDeleteShader
Definition: opengl_enc.c:145
opengl_release_window
static int opengl_release_window(AVFormatContext *h)
Definition: opengl_enc.c:969
AV_PIX_FMT_BGRA64
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:473
AVDeviceRect
Definition: avdevice.h:115
log.h
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
opengl_create_window
static int opengl_create_window(AVFormatContext *h)
Definition: opengl_enc.c:936
OpenGLContext::background
uint8_t background[4]
Background color.
Definition: opengl_enc.c:184
AVCodecParameters::height
int height
Definition: codec_par.h:135
opengl_class
static const AVClass opengl_class
Definition: opengl_enc.c:1304
opengl_get_texture_params
static av_cold void opengl_get_texture_params(OpenGLContext *opengl)
Definition: opengl_enc.c:660
LOAD_TEXTURE_DATA
#define LOAD_TEXTURE_DATA(comp_index, sub)
Definition: opengl_enc.c:1170
common.h
OpenGLVertexInfo::y
float y
Definition: opengl_enc.c:163
AV_PIX_FMT_RGB555
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:466
OpenGLContext::inited
int inited
Set to 1 when write_header was successfully called.
Definition: opengl_enc.c:183
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
FFOpenGLFunctions::glGenBuffers
FF_PFNGLGENBUFFERSPROC glGenBuffers
Definition: opengl_enc.c:126
FF_GL_ARRAY_BUFFER
#define FF_GL_ARRAY_BUFFER
Definition: opengl_enc.c:90
AV_PIX_FMT_BGR565
#define AV_PIX_FMT_BGR565
Definition: pixfmt.h:470
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
FFOpenGLFunctions::glAttachShader
FF_PFNGLATTACHSHADERPROC glAttachShader
Definition: opengl_enc.c:143
write_packet
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
Definition: ffmpeg_mux.c:209
OpenGLContext::model_view_matrix_location
GLint model_view_matrix_location
Definition: opengl_enc.c:204
AV_PIX_FMT_RGB565
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:465
FFOpenGLFunctions::glBindBuffer
FF_PFNGLBINDBUFFERPROC glBindBuffer
Definition: opengl_enc.c:129
stride
#define stride
Definition: h264pred_template.c:537
av_cmp_q
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
AV_APP_TO_DEV_WINDOW_SIZE
@ AV_APP_TO_DEV_WINDOW_SIZE
Window size change message.
Definition: avdevice.h:140
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:743
OpenGLContext
Definition: opengl_enc.c:174
FF_PFNGLACTIVETEXTUREPROC
void(APIENTRY * FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
Definition: opengl_enc.c:98
FFOpenGLFunctions::glGetUniformLocation
FF_PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation
Definition: opengl_enc.c:133
AV_PIX_FMT_0BGR
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:264
OpenGLFormatDesc::format
GLenum format
Definition: opengl_enc.c:235
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
FFOpenGLFunctions::glDeleteBuffers
FF_PFNGLDELETEBUFFERSPROC glDeleteBuffers
Definition: opengl_enc.c:127
OpenGLVertexInfo
Definition: opengl_enc.c:161
avformat.h
opengl_resize
static int opengl_resize(AVFormatContext *h, int width, int height)
Definition: opengl_enc.c:312
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
FFOpenGLFunctions::glActiveTexture
FF_PFNGLACTIVETEXTUREPROC glActiveTexture
Definition: opengl_enc.c:125
FFOpenGLFunctions::glGetProgramInfoLog
FF_PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog
Definition: opengl_enc.c:142
OpenGLVertexInfo::t0
float t0
Texture coords.
Definition: opengl_enc.c:164
FFOpenGLFunctions::glBufferData
FF_PFNGLBUFFERDATAPROC glBufferData
Definition: opengl_enc.c:128
FFOpenGLFunctions::glUseProgram
FF_PFNGLUSEPROGRAMPROC glUseProgram
Definition: opengl_enc.c:139
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:245
FF_GL_RED_COMPONENT
#define FF_GL_RED_COMPONENT
Definition: opengl_enc.c:80
OpenGLContext::model_view_matrix
GLfloat model_view_matrix[16]
Modev view matrix.
Definition: opengl_enc.c:213
AV_WRITE_UNCODED_FRAME_QUERY
@ AV_WRITE_UNCODED_FRAME_QUERY
Query whether the feature is possible on this stream.
Definition: mux.h:239
AV_PIX_FMT_FLAG_PLANAR
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:132
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
opengl_type_size
static int opengl_type_size(GLenum type)
Definition: opengl_enc.c:644
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
FF_GL_UNSIGNED_BYTE_3_3_2
#define FF_GL_UNSIGNED_BYTE_3_3_2
Definition: opengl_enc.c:84
FF_GL_INFO_LOG_LENGTH
#define FF_GL_INFO_LOG_LENGTH
Definition: opengl_enc.c:97
FF_PFNGLGETUNIFORMLOCATIONPROC
GLint(APIENTRY * FF_PFNGLGETUNIFORMLOCATIONPROC)(GLuint program, const char *name)
Definition: opengl_enc.c:106
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
opengl_write_trailer
static av_cold int opengl_write_trailer(AVFormatContext *h)
Definition: opengl_enc.c:986
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FF_PFNGLLINKPROGRAMPROC
void(APIENTRY * FF_PFNGLLINKPROGRAMPROC)(GLuint program)
Definition: opengl_enc.c:113
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
mem.h
FF_PFNGLUNIFORMMATRIX4FVPROC
void(APIENTRY * FF_PFNGLUNIFORMMATRIX4FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
Definition: opengl_enc.c:109
FF_PFNGLCREATEPROGRAMPROC
GLuint(APIENTRY * FF_PFNGLCREATEPROGRAMPROC)(void)
Definition: opengl_enc.c:110
opengl_write_header
static av_cold int opengl_write_header(AVFormatContext *h)
Definition: opengl_enc.c:1059
AVCodecParameters::format
int format
Definition: codec_par.h:92
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
message
static int FUNC() message(CodedBitstreamContext *ctx, RWContext *rw, SEIRawMessage *current)
Definition: cbs_sei_syntax_template.c:165
FFOpenGLFunctions::glGetShaderiv
FF_PFNGLGETSHADERIVPROC glGetShaderiv
Definition: opengl_enc.c:148
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
FF_OPENGL_FRAGMENT_SHADER_YUVA_PLANAR
static const char *const FF_OPENGL_FRAGMENT_SHADER_YUVA_PLANAR
Fragment shader for planar YUVA formats.
Definition: opengl_enc_shaders.h:150
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:501
OpenGLContext::chroma_div_w_location
GLint chroma_div_w_location
Definition: opengl_enc.c:206
FF_PFNGLGENBUFFERSPROC
void(APIENTRY * FF_PFNGLGENBUFFERSPROC)(GLsizei n, GLuint *buffers)
Definition: opengl_enc.c:99
OpenGLContext::projection_matrix
GLfloat projection_matrix[16]
Projection matrix.
Definition: opengl_enc.c:212
FILL_COMPONENT
#define FILL_COMPONENT(i)
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:80
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
FFOpenGLFunctions::glVertexAttribPointer
FF_PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer
Definition: opengl_enc.c:132
AV_PIX_FMT_0RGB
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:262
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:79
FFOpenGLFunctions::glEnableVertexAttribArray
FF_PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray
Definition: opengl_enc.c:131
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
OpenGLContext::vertex
OpenGLVertexInfo vertex[4]
VBO.
Definition: opengl_enc.c:202
OpenGLContext::max_texture_size
GLint max_texture_size
Maximum texture size.
Definition: opengl_enc.c:189
OpenGLContext::type
GLenum type
Definition: opengl_enc.c:220
AV_DEV_TO_APP_DESTROY_WINDOW_BUFFER
@ AV_DEV_TO_APP_DESTROY_WINDOW_BUFFER
Destroy window buffer message.
Definition: avdevice.h:257
h
h
Definition: vp9dsp_template.c:2038
FFOpenGLFunctions::glShaderSource
FF_PFNGLSHADERSOURCEPROC glShaderSource
Definition: opengl_enc.c:147
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:249
write_header
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:345
transpose
#define transpose(x)
FF_PFNGLGETATTRIBLOCATIONPROC
GLint(APIENTRY * FF_PFNGLGETATTRIBLOCATIONPROC)(GLuint program, const char *name)
Definition: opengl_enc.c:103
OpenGLFormatDesc::fragment_shader
const char *const * fragment_shader
Definition: opengl_enc.c:234
OpenGLContext::window_width
int window_width
Definition: opengl_enc.c:226
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:173
FFOpenGLFunctions
Definition: opengl_enc.c:124
FF_PFNGLDELETEPROGRAMPROC
void(APIENTRY * FF_PFNGLDELETEPROGRAMPROC)(GLuint program)
Definition: opengl_enc.c:111
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2885
OpenGLContext::non_pow_2_textures
int non_pow_2_textures
1 when non power of 2 textures are supported
Definition: opengl_enc.c:192
mux.h