1 /*
2  * GStreamer
3  * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
4  * Copyright (C) 2020 Rafał Dzięgiel <rafostar.github@gmail.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library 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  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef __GTK_GST_BASE_WIDGET_H__
23 #define __GTK_GST_BASE_WIDGET_H__
24 
25 #include <gtk/gtk.h>
26 #include <gst/gst.h>
27 #include <gst/video/video.h>
28 
29 #if !defined(BUILD_FOR_GTK4)
30 #include <gdk/gdk.h>
31 #endif
32 
33 #define GTK_GST_BASE_WIDGET(w)         ((GtkGstBaseWidget *)(w))
34 #define GTK_GST_BASE_WIDGET_CLASS(k)   ((GtkGstBaseWidgetClass *)(k))
35 #define GTK_GST_BASE_WIDGET_LOCK(w)    g_mutex_lock(&((GtkGstBaseWidget*)(w))->lock)
36 #define GTK_GST_BASE_WIDGET_UNLOCK(w)  g_mutex_unlock(&((GtkGstBaseWidget*)(w))->lock)
37 
38 G_BEGIN_DECLS
39 
40 typedef struct _GtkGstBaseWidget GtkGstBaseWidget;
41 typedef struct _GtkGstBaseWidgetClass GtkGstBaseWidgetClass;
42 
43 struct _GtkGstBaseWidget
44 {
45   union {
46     GtkDrawingArea drawing_area;
47     GtkGLArea gl_area;
48   } parent;
49 
50   /* properties */
51   gboolean force_aspect_ratio;
52   gint par_n, par_d;
53   gboolean ignore_alpha;
54 
55   gint display_width;
56   gint display_height;
57 
58   gboolean negotiated;
59   GstBuffer *pending_buffer;
60   GstBuffer *buffer;
61   GstVideoInfo v_info;
62 
63   /* resize */
64   gboolean pending_resize;
65   GstVideoInfo pending_v_info;
66   guint display_ratio_num;
67   guint display_ratio_den;
68 
69   /*< private >*/
70   GMutex lock;
71   GWeakRef element;
72 
73   /* event controllers */
74   GtkEventController *key_controller;
75   GtkEventController *motion_controller;
76   GtkGesture *click_gesture;
77 
78   /* Pending draw idles callback */
79   guint draw_id;
80 };
81 
82 struct _GtkGstBaseWidgetClass
83 {
84   union {
85     GtkDrawingAreaClass drawing_area_class;
86     GtkGLAreaClass gl_area_class;
87   } parent_class;
88 };
89 
90 /* For implementer */
91 void            gtk_gst_base_widget_class_init           (GtkGstBaseWidgetClass * klass);
92 void            gtk_gst_base_widget_init                 (GtkGstBaseWidget * widget);
93 
94 void            gtk_gst_base_widget_finalize             (GObject * object);
95 
96 /* API */
97 gboolean        gtk_gst_base_widget_set_format           (GtkGstBaseWidget * widget, GstVideoInfo * v_info);
98 void            gtk_gst_base_widget_set_buffer           (GtkGstBaseWidget * widget, GstBuffer * buffer);
99 void            gtk_gst_base_widget_set_element          (GtkGstBaseWidget * widget, GstElement * element);
100 
101 G_END_DECLS
102 
103 #endif /* __GTK_GST_BASE_WIDGET_H__ */
104