Add initial VA display abstraction.
[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_set_display(GstVaapiDisplayX11 *display,
49                                   Display            *x11_display);
50
51 static void
52 gst_vaapi_display_x11_finalize(GObject *object)
53 {
54     GstVaapiDisplayX11        *display = GST_VAAPI_DISPLAY_X11(object);
55     GstVaapiDisplayX11Private *priv    = display->priv;
56
57     G_OBJECT_CLASS(gst_vaapi_display_x11_parent_class)->finalize(object);
58 }
59
60 static void
61 gst_vaapi_display_x11_set_property(GObject      *object,
62                                    guint         prop_id,
63                                    const GValue *value,
64                                    GParamSpec   *pspec)
65 {
66     GstVaapiDisplayX11        *display = GST_VAAPI_DISPLAY_X11(object);
67     GstVaapiDisplayX11Private *priv    = display->priv;
68
69     switch (prop_id) {
70     case PROP_X11_DISPLAY:
71         gst_vaapi_display_x11_set_display(display, g_value_get_pointer(value));
72         break;
73     default:
74         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
75         break;
76     }
77 }
78
79 static void
80 gst_vaapi_display_x11_get_property(GObject    *object,
81                                    guint       prop_id,
82                                    GValue     *value,
83                                    GParamSpec *pspec)
84 {
85     GstVaapiDisplayX11        *display = GST_VAAPI_DISPLAY_X11(object);
86     GstVaapiDisplayX11Private *priv    = display->priv;
87
88     switch (prop_id) {
89     case PROP_X11_DISPLAY:
90         g_value_set_pointer(value, gst_vaapi_display_x11_get_display(display));
91         break;
92     default:
93         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
94         break;
95     }
96 }
97
98 static void
99 gst_vaapi_display_x11_class_init(GstVaapiDisplayX11Class *klass)
100 {
101     GObjectClass * const object_class = G_OBJECT_CLASS(klass);
102
103     g_type_class_add_private(klass, sizeof(GstVaapiDisplayX11Private));
104
105     object_class->finalize     = gst_vaapi_display_x11_finalize;
106     object_class->set_property = gst_vaapi_display_x11_set_property;
107     object_class->get_property = gst_vaapi_display_x11_get_property;
108
109     g_object_class_install_property
110         (object_class,
111          PROP_X11_DISPLAY,
112          g_param_spec_pointer("x11-display",
113                               "X11 display",
114                               "X11 display",
115                               G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
116 }
117
118 static void
119 gst_vaapi_display_x11_init(GstVaapiDisplayX11 *display)
120 {
121     GstVaapiDisplayX11Private *priv = GST_VAAPI_DISPLAY_X11_GET_PRIVATE(display);
122
123     display->priv = priv;
124     priv->display = NULL;
125 }
126
127 Display *
128 gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
129 {
130     GstVaapiDisplayX11Private *priv = display->priv;
131
132     return priv->display;
133 }
134
135 void
136 gst_vaapi_display_x11_set_display(GstVaapiDisplayX11 *display,
137                                   Display            *x11_display)
138 {
139     GstVaapiDisplayX11Private *priv = display->priv;
140
141     if (x11_display) {
142         VADisplay va_display = vaGetDisplay(x11_display);
143         if (va_display)
144             g_object_set(GST_VAAPI_DISPLAY(display),
145                          "display", va_display,
146                          NULL);
147     }
148
149     priv->display = x11_display;
150 }
151
152 GstVaapiDisplay *
153 gst_vaapi_display_x11_new(Display *x11_display)
154 {
155     return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
156                         "x11-display", x11_display,
157                         NULL);
158 }