FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions | Variables
opengl_enc.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stddef.h>
#include "config.h"
#include <GL/gl.h>
#include <GL/glext.h>
#include "libavutil/common.h"
#include "libavutil/pixdesc.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavformat/avformat.h"
#include "libavformat/internal.h"
#include "libavdevice/avdevice.h"
#include "opengl_enc_shaders.h"

Go to the source code of this file.

Data Structures

struct  FFOpenGLFunctions
 
struct  OpenGLVertexInfo
 
struct  OpenGLContext
 
struct  OpenGLFormatDesc
 

Macros

#define APIENTRY
 
#define FF_GL_RED_COMPONENT   0x1903;
 
#define FF_GL_UNSIGNED_BYTE_3_3_2   0x8032
 
#define FF_GL_UNSIGNED_BYTE_2_3_3_REV   0x8362
 
#define FF_GL_UNSIGNED_SHORT_1_5_5_5_REV   0x8366
 
#define FF_GL_UNPACK_ROW_LENGTH   0x0CF2
 
#define FF_GL_ARRAY_BUFFER   0x8892
 
#define FF_GL_ELEMENT_ARRAY_BUFFER   0x8893
 
#define FF_GL_STATIC_DRAW   0x88E4
 
#define FF_GL_FRAGMENT_SHADER   0x8B30
 
#define FF_GL_VERTEX_SHADER   0x8B31
 
#define FF_GL_COMPILE_STATUS   0x8B81
 
#define FF_GL_LINK_STATUS   0x8B82
 
#define FF_GL_INFO_LOG_LENGTH   0x8B84
 
#define OPENGL_ERROR_CHECK(ctx)
 
#define LOAD_OPENGL_FUN(name, type)
 
#define FILL_COMPONENT(i)
 
#define LOAD_TEXTURE_DATA(comp_index, sub)
 
#define OFFSET(x)   offsetof(OpenGLContext, x)
 
#define ENC   AV_OPT_FLAG_ENCODING_PARAM
 

Typedefs

typedef GLuintbuffers
 
typedef ptrdiff_t size
 
typedef ptrdiff_t const GLvoid * data
 
typedef ptrdiff_t const GLvoid
GLenum 
usage
 
typedef GLuint buffer
 
typedef const char * name
 
typedef GLint GLenum type
 
typedef GLint GLenum GLboolean normalized
 
typedef GLint GLenum GLboolean
GLsizei 
stride
 
typedef GLint GLenum GLboolean
GLsizei uintptr_t 
pointer
 
typedef GLfloat v0
 
typedef GLsizei count
 
typedef GLsizei GLboolean transpose
 
typedef GLsizei GLboolean
const GLfloat * 
value
 
typedef GLenum pname
 
typedef GLenum GLintparams
 
typedef GLsizei bufSize
 
typedef GLsizei GLsizei * length
 
typedef GLsizei GLsizei char * infoLog
 
typedef GLuint shader
 
typedef GLsizei const char ** string
 

Functions

typedef void (APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
 
typedef GLint (APIENTRY *FF_PFNGLGETATTRIBLOCATIONPROC)(GLuint program
 
typedef GLuint (APIENTRY *FF_PFNGLCREATEPROGRAMPROC)(void)
 
static av_cold int opengl_prepare_vertex (AVFormatContext *s)
 
static int opengl_draw (AVFormatContext *h, void *intput, int repaint, int is_pkt)
 
static av_cold int opengl_init_context (OpenGLContext *opengl)
 
static av_cold void opengl_deinit_context (OpenGLContext *opengl)
 
static int opengl_resize (AVFormatContext *h, int width, int height)
 
static int opengl_control_message (AVFormatContext *h, int type, void *data, size_t data_size)
 
static int av_cold opengl_load_procedures (OpenGLContext *opengl)
 
static void opengl_make_identity (float matrix[16])
 
static void opengl_make_ortho (float matrix[16], float left, float right, float bottom, float top, float nearZ, float farZ)
 
static av_cold int opengl_read_limits (OpenGLContext *opengl)
 
static const char * opengl_get_fragment_shader_code (enum AVPixelFormat format)
 
static int opengl_type_size (GLenum type)
 
static av_cold void opengl_get_texture_params (OpenGLContext *opengl)
 
static void opengl_compute_display_area (AVFormatContext *s)
 
static av_cold void opengl_get_texture_size (OpenGLContext *opengl, int in_width, int in_height, int *out_width, int *out_height)
 
static av_cold void opengl_fill_color_map (OpenGLContext *opengl)
 
static av_cold GLuint opengl_load_shader (OpenGLContext *opengl, GLenum type, const char *source)
 
static av_cold int opengl_compile_shaders (OpenGLContext *opengl, enum AVPixelFormat pix_fmt)
 
static av_cold int opengl_configure_texture (OpenGLContext *opengl, GLuint texture, GLsizei width, GLsizei height)
 
static int opengl_prepare (OpenGLContext *opengl)
 
static int opengl_create_window (AVFormatContext *h)
 
static int opengl_release_window (AVFormatContext *h)
 
static av_cold int opengl_write_trailer (AVFormatContext *h)
 
static av_cold int opengl_write_header (AVFormatContext *h)
 
static uint8_topengl_get_plane_pointer (OpenGLContext *opengl, AVPacket *pkt, int comp_index, const AVPixFmtDescriptor *desc)
 
static int opengl_write_packet (AVFormatContext *h, AVPacket *pkt)
 
static int opengl_write_frame (AVFormatContext *h, int stream_index, AVFrame **frame, unsigned flags)
 

Variables

static const GLushort g_index [6]
 
static struct OpenGLFormatDesc opengl_format_desc []
 
static const AVOption options []
 
static const AVClass opengl_class
 
AVOutputFormat ff_opengl_muxer
 

Macro Definition Documentation

#define APIENTRY

Definition at line 65 of file opengl_enc.c.

#define FF_GL_RED_COMPONENT   0x1903;

Definition at line 80 of file opengl_enc.c.

#define FF_GL_UNSIGNED_BYTE_3_3_2   0x8032

Definition at line 84 of file opengl_enc.c.

Referenced by opengl_type_size().

#define FF_GL_UNSIGNED_BYTE_2_3_3_REV   0x8362

Definition at line 85 of file opengl_enc.c.

Referenced by opengl_type_size().

#define FF_GL_UNSIGNED_SHORT_1_5_5_5_REV   0x8366

Definition at line 86 of file opengl_enc.c.

Referenced by opengl_type_size().

#define FF_GL_UNPACK_ROW_LENGTH   0x0CF2

Definition at line 87 of file opengl_enc.c.

#define FF_GL_ARRAY_BUFFER   0x8892

Definition at line 90 of file opengl_enc.c.

Referenced by opengl_deinit_context(), opengl_draw(), and opengl_prepare_vertex().

#define FF_GL_ELEMENT_ARRAY_BUFFER   0x8893

Definition at line 91 of file opengl_enc.c.

Referenced by opengl_deinit_context(), opengl_draw(), and opengl_init_context().

#define FF_GL_STATIC_DRAW   0x88E4

Definition at line 92 of file opengl_enc.c.

Referenced by opengl_init_context(), and opengl_prepare_vertex().

#define FF_GL_FRAGMENT_SHADER   0x8B30

Definition at line 93 of file opengl_enc.c.

Referenced by opengl_compile_shaders().

#define FF_GL_VERTEX_SHADER   0x8B31

Definition at line 94 of file opengl_enc.c.

Referenced by opengl_compile_shaders().

#define FF_GL_COMPILE_STATUS   0x8B81

Definition at line 95 of file opengl_enc.c.

Referenced by opengl_load_shader().

#define FF_GL_LINK_STATUS   0x8B82

Definition at line 96 of file opengl_enc.c.

Referenced by opengl_compile_shaders().

#define FF_GL_INFO_LOG_LENGTH   0x8B84

Definition at line 97 of file opengl_enc.c.

Referenced by opengl_compile_shaders(), and opengl_load_shader().

#define OPENGL_ERROR_CHECK (   ctx)
Value:
{\
GLenum err_code; \
if ((err_code = glGetError()) != GL_NO_ERROR) { \
av_log(ctx, AV_LOG_ERROR, "OpenGL error occurred in '%s', line %d: %d\n", __FUNCTION__, __LINE__, err_code); \
goto fail; \
} \
}\

Definition at line 152 of file opengl_enc.c.

Referenced by opengl_compile_shaders(), opengl_configure_texture(), opengl_draw(), opengl_init_context(), opengl_load_shader(), opengl_prepare(), opengl_prepare_vertex(), opengl_read_limits(), and opengl_write_header().

#define LOAD_OPENGL_FUN (   name,
  type 
)
Value:
procs->name = (type)SelectedGetProcAddress(#name); \
if (!procs->name) { \
av_log(opengl, AV_LOG_ERROR, "Cannot load OpenGL function: '%s'\n", #name); \
return AVERROR(ENOSYS); \
}

Referenced by opengl_load_procedures().

#define FILL_COMPONENT (   i)
Value:
{ \
shift = desc->comp[i].depth_minus1 >> 3; \
opengl->color_map[(i << 2) + ((desc->comp[i].offset_plus1 - 1) >> shift)] = 1.0; \
}

Referenced by opengl_fill_color_map().

#define LOAD_TEXTURE_DATA (   comp_index,
  sub 
)

Definition at line 1162 of file opengl_enc.c.

Referenced by opengl_draw().

#define OFFSET (   x)    offsetof(OpenGLContext, x)

Definition at line 1276 of file opengl_enc.c.

#define ENC   AV_OPT_FLAG_ENCODING_PARAM

Definition at line 1277 of file opengl_enc.c.

Typedef Documentation

typedef const GLuint * buffers

Definition at line 99 of file opengl_enc.c.

typedef GLint size

Definition at line 101 of file opengl_enc.c.

typedef ptrdiff_t const GLvoid* data
Examples:
qsvdec.c.

Definition at line 101 of file opengl_enc.c.

typedef ptrdiff_t const GLvoid GLenum usage

Definition at line 101 of file opengl_enc.c.

typedef GLuint buffer
Examples:
avio_reading.c.

Definition at line 102 of file opengl_enc.c.

typedef const char * name

Definition at line 103 of file opengl_enc.c.

typedef GLint GLenum type
Examples:
transcoding.c.

Definition at line 105 of file opengl_enc.c.

typedef GLint GLenum GLboolean normalized

Definition at line 105 of file opengl_enc.c.

typedef GLint GLenum GLboolean GLsizei stride

Definition at line 105 of file opengl_enc.c.

typedef GLint GLenum GLboolean GLsizei uintptr_t pointer

Definition at line 105 of file opengl_enc.c.

typedef GLint v0

Definition at line 107 of file opengl_enc.c.

typedef GLsizei count

Definition at line 109 of file opengl_enc.c.

typedef GLsizei GLboolean transpose

Definition at line 109 of file opengl_enc.c.

typedef GLsizei GLboolean const GLfloat* value

Definition at line 109 of file opengl_enc.c.

typedef GLenum pname

Definition at line 114 of file opengl_enc.c.

typedef GLenum GLint * params

Definition at line 114 of file opengl_enc.c.

typedef GLsizei bufSize

Definition at line 115 of file opengl_enc.c.

typedef GLsizei GLsizei * length

Definition at line 115 of file opengl_enc.c.

typedef GLsizei GLsizei char * infoLog

Definition at line 115 of file opengl_enc.c.

typedef GLuint shader

Definition at line 116 of file opengl_enc.c.

typedef GLsizei const char* * string

Definition at line 120 of file opengl_enc.c.

Function Documentation

typedef void ( APIENTRY FF_PFNGLACTIVETEXTUREPROC)
typedef GLint ( APIENTRY FF_PFNGLGETATTRIBLOCATIONPROC)
typedef GLuint ( APIENTRY FF_PFNGLCREATEPROGRAMPROC)

Referenced by opengl_load_shader().

static av_cold int opengl_prepare_vertex ( AVFormatContext s)
static

Definition at line 870 of file opengl_enc.c.

Referenced by opengl_resize(), and opengl_write_header().

static int opengl_draw ( AVFormatContext h,
void intput,
int  repaint,
int  is_pkt 
)
static

Definition at line 1200 of file opengl_enc.c.

Referenced by opengl_resize(), opengl_write_frame(), and opengl_write_packet().

static av_cold int opengl_init_context ( OpenGLContext opengl)
static

Definition at line 1002 of file opengl_enc.c.

Referenced by opengl_write_header().

static av_cold void opengl_deinit_context ( OpenGLContext opengl)
static

Definition at line 282 of file opengl_enc.c.

Referenced by opengl_write_trailer().

static int opengl_resize ( AVFormatContext h,
int  width,
int  height 
)
static

Definition at line 308 of file opengl_enc.c.

Referenced by opengl_control_message().

static int opengl_control_message ( AVFormatContext h,
int  type,
void data,
size_t  data_size 
)
static

Definition at line 328 of file opengl_enc.c.

static int av_cold opengl_load_procedures ( OpenGLContext opengl)
static

Definition at line 503 of file opengl_enc.c.

Referenced by opengl_write_header().

static void opengl_make_identity ( float  matrix[16])
static

Definition at line 558 of file opengl_enc.c.

Referenced by opengl_prepare_vertex().

static void opengl_make_ortho ( float  matrix[16],
float  left,
float  right,
float  bottom,
float  top,
float  nearZ,
float  farZ 
)
static

Definition at line 564 of file opengl_enc.c.

Referenced by opengl_prepare_vertex().

static av_cold int opengl_read_limits ( OpenGLContext opengl)
static

Definition at line 584 of file opengl_enc.c.

Referenced by opengl_write_header().

static const char* opengl_get_fragment_shader_code ( enum AVPixelFormat  format)
static

Definition at line 638 of file opengl_enc.c.

Referenced by opengl_compile_shaders().

static int opengl_type_size ( GLenum  type)
static

Definition at line 648 of file opengl_enc.c.

Referenced by opengl_get_plane_pointer().

static av_cold void opengl_get_texture_params ( OpenGLContext opengl)
static

Definition at line 664 of file opengl_enc.c.

Referenced by opengl_write_header().

static void opengl_compute_display_area ( AVFormatContext s)
static

Definition at line 676 of file opengl_enc.c.

Referenced by opengl_prepare_vertex().

static av_cold void opengl_get_texture_size ( OpenGLContext opengl,
int  in_width,
int  in_height,
int *  out_width,
int *  out_height 
)
static

Definition at line 700 of file opengl_enc.c.

Referenced by opengl_configure_texture(), and opengl_prepare_vertex().

static av_cold void opengl_fill_color_map ( OpenGLContext opengl)
static

Definition at line 718 of file opengl_enc.c.

Referenced by opengl_write_header().

static av_cold GLuint opengl_load_shader ( OpenGLContext opengl,
GLenum  type,
const char *  source 
)
static

Definition at line 750 of file opengl_enc.c.

Referenced by opengl_compile_shaders().

static av_cold int opengl_compile_shaders ( OpenGLContext opengl,
enum AVPixelFormat  pix_fmt 
)
static

Definition at line 781 of file opengl_enc.c.

Referenced by opengl_init_context().

static av_cold int opengl_configure_texture ( OpenGLContext opengl,
GLuint  texture,
GLsizei  width,
GLsizei  height 
)
static

Definition at line 850 of file opengl_enc.c.

Referenced by opengl_init_context().

static int opengl_prepare ( OpenGLContext opengl)
static

Definition at line 915 of file opengl_enc.c.

Referenced by opengl_draw().

static int opengl_create_window ( AVFormatContext h)
static

Definition at line 940 of file opengl_enc.c.

Referenced by opengl_write_header().

static int opengl_release_window ( AVFormatContext h)
static

Definition at line 973 of file opengl_enc.c.

Referenced by opengl_write_trailer().

static av_cold int opengl_write_trailer ( AVFormatContext h)
static

Definition at line 988 of file opengl_enc.c.

Referenced by opengl_write_header().

static av_cold int opengl_write_header ( AVFormatContext h)
static

Definition at line 1061 of file opengl_enc.c.

static uint8_t* opengl_get_plane_pointer ( OpenGLContext opengl,
AVPacket pkt,
int  comp_index,
const AVPixFmtDescriptor desc 
)
static

Definition at line 1133 of file opengl_enc.c.

static int opengl_write_packet ( AVFormatContext h,
AVPacket pkt 
)
static

Definition at line 1263 of file opengl_enc.c.

static int opengl_write_frame ( AVFormatContext h,
int  stream_index,
AVFrame **  frame,
unsigned  flags 
)
static

Definition at line 1268 of file opengl_enc.c.

Variable Documentation

const GLushort g_index[6]
static
Initial value:
=
{
0, 1, 2,
0, 3, 2,
}

Definition at line 168 of file opengl_enc.c.

Referenced by opengl_draw(), and opengl_init_context().

struct OpenGLFormatDesc opengl_format_desc[]
static
const AVOption options[]
static
Initial value:
= {
{ "background", "set background color", OFFSET(background), AV_OPT_TYPE_COLOR, {.str = "black"}, CHAR_MIN, CHAR_MAX, ENC },
{ "no_window", "disable default window", OFFSET(no_window), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, ENC },
{ "window_title", "set window title", OFFSET(window_title), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, ENC },
{ "window_size", "set window size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, ENC },
{ NULL }
}

Definition at line 1278 of file opengl_enc.c.

const AVClass opengl_class
static
Initial value:
= {
.class_name = "opengl outdev",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 1286 of file opengl_enc.c.

AVOutputFormat ff_opengl_muxer
Initial value:
= {
.name = "opengl",
.long_name = NULL_IF_CONFIG_SMALL("OpenGL output"),
.priv_data_size = sizeof(OpenGLContext),
.audio_codec = AV_CODEC_ID_NONE,
.video_codec = AV_CODEC_ID_RAWVIDEO,
.write_uncoded_frame = opengl_write_frame,
.control_message = opengl_control_message,
.priv_class = &opengl_class,
}

Definition at line 1294 of file opengl_enc.c.