summaryrefslogtreecommitdiff
path: root/sys/vdpau/gstvdp/gstvdpdevice.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/vdpau/gstvdp/gstvdpdevice.c')
-rw-r--r--sys/vdpau/gstvdp/gstvdpdevice.c147
1 files changed, 71 insertions, 76 deletions
diff --git a/sys/vdpau/gstvdp/gstvdpdevice.c b/sys/vdpau/gstvdp/gstvdpdevice.c
index 8867e4e34..2e441b93c 100644
--- a/sys/vdpau/gstvdp/gstvdpdevice.c
+++ b/sys/vdpau/gstvdp/gstvdpdevice.c
@@ -37,39 +37,9 @@ enum
37G_DEFINE_TYPE_WITH_CODE (GstVdpDevice, gst_vdp_device, G_TYPE_OBJECT, 37G_DEFINE_TYPE_WITH_CODE (GstVdpDevice, gst_vdp_device, G_TYPE_OBJECT,
38 DEBUG_INIT ()); 38 DEBUG_INIT ());
39 39
40static void 40static gboolean
41gst_vdp_device_init (GstVdpDevice * device) 41gst_vdp_device_open (GstVdpDevice * device, GError ** error)
42{
43 device->display_name = NULL;
44 device->display = NULL;
45 device->device = VDP_INVALID_HANDLE;
46
47 device->constructed = FALSE;
48}
49
50static void
51gst_vdp_device_finalize (GObject * object)
52{ 42{
53 GstVdpDevice *device = (GstVdpDevice *) object;
54
55 if (device->device != VDP_INVALID_HANDLE) {
56 device->vdp_device_destroy (device->device);
57 device->device = VDP_INVALID_HANDLE;
58 }
59 if (device->display) {
60 XCloseDisplay (device->display);
61 device->display = NULL;
62 }
63 g_free (device->display_name);
64 device->display_name = NULL;
65
66 G_OBJECT_CLASS (gst_vdp_device_parent_class)->finalize (object);
67}
68
69static void
70gst_vdp_device_constructed (GObject * object)
71{
72 GstVdpDevice *device = (GstVdpDevice *) object;
73 gint screen; 43 gint screen;
74 VdpStatus status; 44 VdpStatus status;
75 gint i; 45 gint i;
@@ -135,55 +105,96 @@ gst_vdp_device_constructed (GObject * object)
135 }; 105 };
136 106
137 device->display = XOpenDisplay (device->display_name); 107 device->display = XOpenDisplay (device->display_name);
138 if (!device->display) { 108 if (!device->display)
139 GST_ERROR_OBJECT (device, "Could not open X display with name: %s", 109 goto create_display_error;
140 device->display_name);
141 return;
142 }
143 110
144 screen = DefaultScreen (device->display); 111 screen = DefaultScreen (device->display);
145 status = 112 status =
146 vdp_device_create_x11 (device->display, screen, &device->device, 113 vdp_device_create_x11 (device->display, screen, &device->device,
147 &device->vdp_get_proc_address); 114 &device->vdp_get_proc_address);
148 if (status != VDP_STATUS_OK) { 115 if (status != VDP_STATUS_OK)
149 GST_ERROR_OBJECT (device, "Could not create VDPAU device"); 116 goto create_device_error;
150 device->device = VDP_INVALID_HANDLE;
151 XCloseDisplay (device->display);
152 device->display = NULL;
153
154 return;
155 }
156 117
157 status = device->vdp_get_proc_address (device->device, 118 status = device->vdp_get_proc_address (device->device,
158 VDP_FUNC_ID_GET_ERROR_STRING, (void **) &device->vdp_get_error_string); 119 VDP_FUNC_ID_GET_ERROR_STRING, (void **) &device->vdp_get_error_string);
159 if (status != VDP_STATUS_OK) { 120 if (status != VDP_STATUS_OK)
160 GST_ERROR_OBJECT (device, 121 goto get_error_string_error;
161 "Could not get vdp_get_error_string function pointer from VDPAU");
162 goto error;
163 }
164 122
165 for (i = 0; i < G_N_ELEMENTS (vdp_function); i++) { 123 for (i = 0; i < G_N_ELEMENTS (vdp_function); i++) {
166 status = device->vdp_get_proc_address (device->device, 124 status = device->vdp_get_proc_address (device->device,
167 vdp_function[i].id, vdp_function[i].func); 125 vdp_function[i].id, vdp_function[i].func);
168 126
169 if (status != VDP_STATUS_OK) { 127 if (status != VDP_STATUS_OK)
170 GST_ERROR_OBJECT (device, "Could not get function pointer from VDPAU," 128 goto function_error;
171 " error returned was: %s", device->vdp_get_error_string (status));
172 goto error;
173 }
174 } 129 }
175 130
176 device->constructed = TRUE; 131 return TRUE;
177 return; 132
133create_display_error:
134 g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_OPEN_READ,
135 "Could not open X display with name: %s", device->display_name);
136 return FALSE;
178 137
179error: 138create_device_error:
180 XCloseDisplay (device->display); 139 XCloseDisplay (device->display);
140 g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_OPEN_READ,
141 "Could not create VDPAU device for display: %s", device->display_name);
142 return FALSE;
143
144get_error_string_error:
145 XCloseDisplay (device->display);
146 g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_OPEN_READ,
147 "Could not get vdp_get_error_string function pointer from VDPAU");
148 return FALSE;
149
150function_error:
151 XCloseDisplay (device->display);
152 g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_OPEN_READ,
153 "Could not get function pointer from VDPAU, error returned was: %s",
154 device->vdp_get_error_string (status));
155 return FALSE;
156}
157
158static GstVdpDevice *
159gst_vdp_device_new (const gchar * display_name, GError ** error)
160{
161 GstVdpDevice *device;
162
163 device = g_object_new (GST_TYPE_VDP_DEVICE, "display", display_name, NULL);
164
165 if (!gst_vdp_device_open (device, error)) {
166 g_object_unref (device);
167 return NULL;
168 }
169
170 return device;
171}
172
173static void
174gst_vdp_device_init (GstVdpDevice * device)
175{
176 device->display_name = NULL;
181 device->display = NULL; 177 device->display = NULL;
178 device->device = VDP_INVALID_HANDLE;
179}
180
181static void
182gst_vdp_device_finalize (GObject * object)
183{
184 GstVdpDevice *device = (GstVdpDevice *) object;
182 185
183 if (device->device != VDP_INVALID_HANDLE) { 186 if (device->device != VDP_INVALID_HANDLE) {
184 device->vdp_device_destroy (device->device); 187 device->vdp_device_destroy (device->device);
185 device->device = VDP_INVALID_HANDLE; 188 device->device = VDP_INVALID_HANDLE;
186 } 189 }
190 if (device->display) {
191 XCloseDisplay (device->display);
192 device->display = NULL;
193 }
194 g_free (device->display_name);
195 device->display_name = NULL;
196
197 G_OBJECT_CLASS (gst_vdp_device_parent_class)->finalize (object);
187} 198}
188 199
189static void 200static void
@@ -231,7 +242,6 @@ gst_vdp_device_class_init (GstVdpDeviceClass * klass)
231{ 242{
232 GObjectClass *object_class = G_OBJECT_CLASS (klass); 243 GObjectClass *object_class = G_OBJECT_CLASS (klass);
233 244
234 object_class->constructed = gst_vdp_device_constructed;
235 object_class->finalize = gst_vdp_device_finalize; 245 object_class->finalize = gst_vdp_device_finalize;
236 object_class->get_property = gst_vdp_device_get_property; 246 object_class->get_property = gst_vdp_device_get_property;
237 object_class->set_property = gst_vdp_device_set_property; 247 object_class->set_property = gst_vdp_device_set_property;
@@ -244,21 +254,6 @@ gst_vdp_device_class_init (GstVdpDeviceClass * klass)
244 "", G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); 254 "", G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
245} 255}
246 256
247static GstVdpDevice *
248gst_vdp_device_new (const gchar * display_name)
249{
250 GstVdpDevice *device;
251
252 device = g_object_new (GST_TYPE_VDP_DEVICE, "display", display_name, NULL);
253
254 if (!device->constructed) {
255 g_object_unref (device);
256 return NULL;
257 }
258
259 return device;
260}
261
262typedef struct 257typedef struct
263{ 258{
264 GHashTable *hash_table; 259 GHashTable *hash_table;
@@ -288,7 +283,7 @@ device_destroyed_cb (gpointer data, GObject * object)
288} 283}
289 284
290GstVdpDevice * 285GstVdpDevice *
291gst_vdp_get_device (const gchar * display_name) 286gst_vdp_get_device (const gchar * display_name, GError ** error)
292{ 287{
293 static gsize once = 0; 288 static gsize once = 0;
294 static GstVdpDeviceCache device_cache; 289 static GstVdpDeviceCache device_cache;
@@ -310,7 +305,7 @@ gst_vdp_get_device (const gchar * display_name)
310 device = g_hash_table_lookup (device_cache.hash_table, ""); 305 device = g_hash_table_lookup (device_cache.hash_table, "");
311 306
312 if (!device) { 307 if (!device) {
313 device = gst_vdp_device_new (display_name); 308 device = gst_vdp_device_new (display_name, error);
314 if (device) { 309 if (device) {
315 g_object_weak_ref (G_OBJECT (device), device_destroyed_cb, &device_cache); 310 g_object_weak_ref (G_OBJECT (device), device_destroyed_cb, &device_cache);
316 if (display_name) 311 if (display_name)