1 /*
2  * GStreamer
3  * Copyright (C) 2003 Julien Moutte <julien@moutte.net>
4  * Copyright (C) 2005,2006,2007 David A. Schleef <ds@schleef.org>
5  * Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef _GLIMAGESINK_H_
24 #define _GLIMAGESINK_H_
25 
26 #include <gst/gst.h>
27 #include <gst/video/gstvideosink.h>
28 #include <gst/video/video.h>
29 
30 #include <gst/gl/gl.h>
31 #include <gst/gl/gstglfuncs.h>
32 
33 G_BEGIN_DECLS
34 
35 GST_DEBUG_CATEGORY_EXTERN (gst_debug_glimage_sink);
36 
37 #define GST_TYPE_GLIMAGE_SINK \
38     (gst_glimage_sink_get_type())
39 #define GST_GLIMAGE_SINK(obj) \
40     (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GLIMAGE_SINK,GstGLImageSink))
41 #define GST_GLIMAGE_SINK_CLASS(klass) \
42     (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GLIMAGE_SINK,GstGLImageSinkClass))
43 #define GST_IS_GLIMAGE_SINK(obj) \
44     (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GLIMAGE_SINK))
45 #define GST_IS_GLIMAGE_SINK_CLASS(klass) \
46     (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GLIMAGE_SINK))
47 
48 typedef enum
49 {
50   GST_GL_ROTATE_METHOD_IDENTITY,
51   GST_GL_ROTATE_METHOD_90R,
52   GST_GL_ROTATE_METHOD_180,
53   GST_GL_ROTATE_METHOD_90L,
54   GST_GL_ROTATE_METHOD_FLIP_HORIZ,
55   GST_GL_ROTATE_METHOD_FLIP_VERT,
56   GST_GL_ROTATE_METHOD_FLIP_UL_LR,
57   GST_GL_ROTATE_METHOD_FLIP_UR_LL,
58   GST_GL_ROTATE_METHOD_AUTO,
59 }GstGLRotateMethod;
60 
61 typedef struct _GstGLImageSink GstGLImageSink;
62 typedef struct _GstGLImageSinkClass GstGLImageSinkClass;
63 
64 struct _GstGLImageSink
65 {
66     GstVideoSink video_sink;
67 
68     guintptr window_id;
69     guintptr new_window_id;
70     gulong mouse_sig_id;
71     gulong key_sig_id;
72 
73     /* GstVideoOverlay::set_render_rectangle() cache */
74     gint x;
75     gint y;
76     gint width;
77     gint height;
78 
79     /* Input info before 3d stereo output conversion, if any */
80     GstVideoInfo in_info;
81     GstCaps *in_caps;
82 
83     /* format/caps we actually hand off to the app */
84     GstVideoInfo out_info;
85     GstCaps *out_caps;
86     GstGLTextureTarget texture_target;
87 
88     GstGLDisplay *display;
89     GstGLContext *context;
90     GstGLContext *other_context;
91     gboolean handle_events;
92     gboolean ignore_alpha;
93 
94     GstGLViewConvert *convert_views;
95 
96     /* Original input RGBA buffer, ready for display,
97      * or possible reconversion through the views filter */
98     GstBuffer *input_buffer;
99     /* Secondary view buffer - when operating in frame-by-frame mode */
100     GstBuffer *input_buffer2;
101 
102     guint      next_tex;
103     GstBuffer *next_buffer;
104     GstBuffer *next_buffer2; /* frame-by-frame 2nd view */
105     GstBuffer *next_sync;
106     GstGLSyncMeta *next_sync_meta;
107 
108     volatile gint to_quit;
109     gboolean keep_aspect_ratio;
110     gint par_n, par_d;
111 
112     /* avoid replacing the stored_buffer while drawing */
113     GMutex drawing_lock;
114     GstBuffer *stored_buffer[2];
115     GstBuffer *stored_sync;
116     GstGLSyncMeta *stored_sync_meta;
117     GLuint redisplay_texture;
118 
119     /* protected with drawing_lock */
120     gboolean window_resized;
121     guint window_width;
122     guint window_height;
123 
124     GstVideoRectangle display_rect;
125 
126     GstGLShader *redisplay_shader;
127     GLuint vao;
128     GLuint vbo_indices;
129     GLuint vertex_buffer;
130     GLint  attr_position;
131     GLint  attr_texture;
132 
133     GstVideoMultiviewMode mview_output_mode;
134     GstVideoMultiviewFlags mview_output_flags;
135     gboolean output_mode_changed;
136     GstGLStereoDownmix mview_downmix_mode;
137 
138     GstGLOverlayCompositor *overlay_compositor;
139 
140     /* current video flip method */
141     GstGLRotateMethod current_rotate_method;
142     GstGLRotateMethod rotate_method;
143     const gfloat *transform_matrix;
144 };
145 
146 struct _GstGLImageSinkClass
147 {
148     GstVideoSinkClass video_sink_class;
149 };
150 
151 GType gst_glimage_sink_get_type(void);
152 GType gst_gl_image_sink_bin_get_type(void);
153 
154 G_END_DECLS
155 
156 #endif
157 
158