Fix GstVaapiDisplay initialization.
[platform/upstream/gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapidisplay_x11.c
1 /*
2  *  gstvaapidisplay_x11.c - VA/X11 display abstraction
3  *
4  *  gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program 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
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "vaapi_utils.h"
23 #include "gstvaapidisplay_x11.h"
24
25 #define DEBUG 1
26 #include "vaapi_debug.h"
27
28 G_DEFINE_TYPE(GstVaapiDisplayX11,
29               gst_vaapi_display_x11,
30               GST_VAAPI_TYPE_DISPLAY);
31
32 #define GST_VAAPI_DISPLAY_X11_GET_PRIVATE(obj)                  \
33     (G_TYPE_INSTANCE_GET_PRIVATE((obj),                         \
34                                  GST_VAAPI_TYPE_DISPLAY_X11,    \
35                                  GstVaapiDisplayX11Private))
36
37 struct _GstVaapiDisplayX11Private {
38     Display *display;
39 };
40
41 enum {
42     PROP_0,
43
44     PROP_X11_DISPLAY
45 };
46
47 static void
48 gst_vaapi_display_x11_finalize(GObject *object)
49 {
50     G_OBJECT_CLASS(gst_vaapi_display_x11_parent_class)->finalize(object);
51 }
52
53 static void
54 gst_vaapi_display_x11_set_property(GObject      *object,
55                                    guint         prop_id,
56                                    const GValue *value,
57                                    GParamSpec   *pspec)
58 {
59     GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
60
61     switch (prop_id) {
62     case PROP_X11_DISPLAY:
63         display->priv->display = g_value_get_pointer(value);
64         break;
65     default:
66         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
67         break;
68     }
69 }
70
71 static void
72 gst_vaapi_display_x11_get_property(GObject    *object,
73                                    guint       prop_id,
74                                    GValue     *value,
75                                    GParamSpec *pspec)
76 {
77     GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
78
79     switch (prop_id) {
80     case PROP_X11_DISPLAY:
81         g_value_set_pointer(value, gst_vaapi_display_x11_get_display(display));
82         break;
83     default:
84         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
85         break;
86     }
87 }
88
89 static void
90 gst_vaapi_display_x11_class_init(GstVaapiDisplayX11Class *klass)
91 {
92     GObjectClass * const object_class = G_OBJECT_CLASS(klass);
93
94     g_type_class_add_private(klass, sizeof(GstVaapiDisplayX11Private));
95
96     object_class->finalize     = gst_vaapi_display_x11_finalize;
97     object_class->set_property = gst_vaapi_display_x11_set_property;
98     object_class->get_property = gst_vaapi_display_x11_get_property;
99
100     g_object_class_install_property
101         (object_class,
102          PROP_X11_DISPLAY,
103          g_param_spec_pointer("x11-display",
104                               "X11 display",
105                               "X11 display",
106                               G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
107 }
108
109 static void
110 gst_vaapi_display_x11_init(GstVaapiDisplayX11 *display)
111 {
112     GstVaapiDisplayX11Private *priv = GST_VAAPI_DISPLAY_X11_GET_PRIVATE(display);
113
114     display->priv = priv;
115     priv->display = NULL;
116 }
117
118 Display *
119 gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
120 {
121     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL);
122
123     return display->priv->display;
124 }
125
126 GstVaapiDisplay *
127 gst_vaapi_display_x11_new(Display *x11_display)
128 {
129     g_return_val_if_fail(x11_display, NULL);
130
131     return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
132                         "x11-display", x11_display,
133                         "display", vaGetDisplay(x11_display),
134                         NULL);
135 }