1 /*
2  * GStreamer
3  * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef __CA_OPENGL_LAYER_SINK_H__
22 #define __CA_OPENGL_LAYER_SINK_H__
23 
24 #include <gst/gst.h>
25 #include <gst/video/gstvideosink.h>
26 #include <gst/video/video.h>
27 
28 #include <gst/gl/gl.h>
29 #include <gst/gl/gstglfuncs.h>
30 #include <gst/gl/cocoa/gstglcaopengllayer.h>
31 
32 G_BEGIN_DECLS
33 
34 #define GST_TYPE_CA_OPENGL_LAYER_SINK \
35     (gst_ca_opengl_layer_sink_get_type())
36 #define GST_CA_OPENGL_LAYER_SINK(obj) \
37     (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CA_OPENGL_LAYER_SINK,GstCAOpenGLLayerSink))
38 #define GST_CA_OPENGL_LAYER_SINK_CLASS(klass) \
39     (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CA_OPENGL_LAYER_SINK,GstCAOpenGLLayerSinkClass))
40 #define GST_IS_CA_OPENGL_LAYER_SINK(obj) \
41     (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CA_OPENGL_LAYER_SINK))
42 #define GST_IS_CA_OPENGL_LAYER_SINK_CLASS(klass) \
43     (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CA_OPENGL_LAYER_SINK))
44 
45 typedef struct _GstCAOpenGLLayerSink GstCAOpenGLLayerSink;
46 typedef struct _GstCAOpenGLLayerSinkClass GstCAOpenGLLayerSinkClass;
47 
48 struct _GstCAOpenGLLayerSink
49 {
50     GstVideoSink video_sink;
51 
52     /* caps */
53     GstVideoInfo info;
54     GstCaps *gl_caps;
55 
56     /* gl state */
57     GstGLDisplay *display;
58     GstGLContext *other_context;
59     GstGLContext *context;
60 
61     guint      next_tex;
62     GstBuffer *next_buffer;
63     GstBuffer *next_sync;
64 
65     gpointer layer;
66 
67     gboolean keep_aspect_ratio;
68 
69     /* avoid replacing the stored_buffer while drawing */
70     GMutex drawing_lock;
71     GstBuffer *stored_buffer;
72     GstBuffer *stored_sync;
73     GLuint redisplay_texture;
74 
75     gboolean caps_change;
76     guint window_width;
77     guint window_height;
78 
79     /* gl state */
80     GstGLShader *redisplay_shader;
81     GLuint vao;
82     GLuint vertex_buffer;
83     GLuint vbo_indices;
84     GLint  attr_position;
85     GLint  attr_texture;
86 };
87 
88 struct _GstCAOpenGLLayerSinkClass
89 {
90     GstVideoSinkClass video_sink_class;
91 };
92 
93 GType gst_ca_opengl_layer_sink_get_type(void);
94 GType gst_ca_opengl_layer_sink_bin_get_type (void);
95 
96 G_END_DECLS
97 
98 #endif /* __CA_OPENGL_LAYER_SINK__ */
99