wayland: Add new gst-wayland library containing a new GstWaylandVideo interface
[platform/upstream/gstreamer.git] / gst-libs / gst / wayland / wayland.c
1 /*
2  * GStreamer Wayland Library
3  * Copyright (C) 2014 Collabora Ltd.
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 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <gst/wayland/wayland.h>
26 #include <gst/video/videooverlay.h>
27
28 G_DEFINE_INTERFACE (GstWaylandVideo, gst_wayland_video, GST_TYPE_VIDEO_OVERLAY);
29
30 static void
31 gst_wayland_video_default_init (GstWaylandVideoInterface * klass)
32 {
33   (void) klass;
34 }
35
36 /**
37  * gst_wayland_video_set_surface_size:
38  *
39  * This tells the video sink to change the size of its drawing
40  * surface. The caller must call gst_wayland_video_pause_rendering
41  * before calling this method and gst_wayland_video_resume_rendering
42  * later, on the next redraw request.
43  */
44 void
45 gst_wayland_video_set_surface_size (GstWaylandVideo * video, gint w, gint h)
46 {
47   GstWaylandVideoInterface *iface;
48
49   g_return_if_fail (video != NULL);
50   g_return_if_fail (GST_IS_WAYLAND_VIDEO (video));
51
52   iface = GST_WAYLAND_VIDEO_GET_INTERFACE (video);
53
54   if (iface->set_surface_size) {
55     iface->set_surface_size (video, w, h);
56   }
57 }
58
59 /**
60  * gst_wayland_video_pause_rendering:
61  *
62  * This tells the video sink to stop rendering on the surface,
63  * dropping frames in the meanwhile. This should be called
64  * before resizing a stack of subsurfaces, one of which is
65  * the surface of the video sink.
66  */
67 void
68 gst_wayland_video_pause_rendering (GstWaylandVideo * video)
69 {
70   GstWaylandVideoInterface *iface;
71
72   g_return_if_fail (video != NULL);
73   g_return_if_fail (GST_IS_WAYLAND_VIDEO (video));
74
75   iface = GST_WAYLAND_VIDEO_GET_INTERFACE (video);
76
77   if (iface->pause_rendering) {
78     iface->pause_rendering (video);
79   }
80 }
81
82 /**
83  * gst_wayland_video_resume_rendering:
84  *
85  * Resumes surface rendering that was previously paused
86  * with gst_wayland_video_pause_rendering. This function will
87  * block until there is a new wl_buffer commited on the surface
88  * inside the element, either with a new frame (if the element
89  * is PLAYING) or with an old frame (if the element is PAUSED).
90  */
91 void
92 gst_wayland_video_resume_rendering (GstWaylandVideo * video)
93 {
94   GstWaylandVideoInterface *iface;
95
96   g_return_if_fail (video != NULL);
97   g_return_if_fail (GST_IS_WAYLAND_VIDEO (video));
98
99   iface = GST_WAYLAND_VIDEO_GET_INTERFACE (video);
100
101   if (iface->resume_rendering) {
102     iface->resume_rendering (video);
103   }
104 }