2009-04-03 15:51:16 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2009 Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-04-03 15:51:16 +00:00
|
|
|
*/
|
|
|
|
|
2012-03-06 17:11:35 +00:00
|
|
|
/* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
|
|
|
|
* with newer GLib versions (>= 2.31.0) */
|
|
|
|
#define GLIB_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
|
2009-04-13 20:19:20 +00:00
|
|
|
#include "gstvdpdevice.h"
|
2009-04-03 15:51:16 +00:00
|
|
|
|
2009-04-13 20:19:20 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_vdp_device_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_vdp_device_debug
|
2009-04-03 15:51:16 +00:00
|
|
|
|
2010-03-17 20:02:07 +00:00
|
|
|
#define DEBUG_INIT(bla) \
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_vdp_device_debug, "vdpdevice", 0, "VDPAU device object");
|
|
|
|
|
2009-04-03 15:51:16 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_DISPLAY
|
|
|
|
};
|
|
|
|
|
2010-03-17 20:02:07 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstVdpDevice, gst_vdp_device, G_TYPE_OBJECT,
|
|
|
|
DEBUG_INIT ());
|
2009-04-03 15:51:16 +00:00
|
|
|
|
2010-07-30 20:27:49 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vdp_device_open (GstVdpDevice * device, GError ** error)
|
2009-04-03 15:51:16 +00:00
|
|
|
{
|
|
|
|
gint screen;
|
|
|
|
VdpStatus status;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gint id;
|
|
|
|
void *func;
|
|
|
|
} VdpFunction;
|
|
|
|
|
|
|
|
VdpFunction vdp_function[] = {
|
|
|
|
{VDP_FUNC_ID_DEVICE_DESTROY, &device->vdp_device_destroy},
|
|
|
|
{VDP_FUNC_ID_VIDEO_SURFACE_CREATE,
|
|
|
|
&device->vdp_video_surface_create},
|
|
|
|
{VDP_FUNC_ID_VIDEO_SURFACE_DESTROY,
|
|
|
|
&device->vdp_video_surface_destroy},
|
|
|
|
{VDP_FUNC_ID_VIDEO_SURFACE_QUERY_CAPABILITIES,
|
|
|
|
&device->vdp_video_surface_query_capabilities},
|
|
|
|
{VDP_FUNC_ID_VIDEO_SURFACE_QUERY_GET_PUT_BITS_Y_CB_CR_CAPABILITIES,
|
|
|
|
&device->vdp_video_surface_query_ycbcr_capabilities},
|
|
|
|
{VDP_FUNC_ID_VIDEO_SURFACE_GET_BITS_Y_CB_CR,
|
|
|
|
&device->vdp_video_surface_get_bits_ycbcr},
|
2009-04-07 18:46:49 +00:00
|
|
|
{VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR,
|
|
|
|
&device->vdp_video_surface_put_bits_ycbcr},
|
2009-04-03 15:51:16 +00:00
|
|
|
{VDP_FUNC_ID_VIDEO_SURFACE_GET_PARAMETERS,
|
|
|
|
&device->vdp_video_surface_get_parameters},
|
|
|
|
{VDP_FUNC_ID_DECODER_CREATE, &device->vdp_decoder_create},
|
|
|
|
{VDP_FUNC_ID_DECODER_RENDER, &device->vdp_decoder_render},
|
|
|
|
{VDP_FUNC_ID_DECODER_DESTROY, &device->vdp_decoder_destroy},
|
|
|
|
{VDP_FUNC_ID_DECODER_QUERY_CAPABILITIES,
|
|
|
|
&device->vdp_decoder_query_capabilities},
|
|
|
|
{VDP_FUNC_ID_DECODER_GET_PARAMETERS,
|
|
|
|
&device->vdp_decoder_get_parameters},
|
2009-06-30 21:55:13 +00:00
|
|
|
{VDP_FUNC_ID_VIDEO_MIXER_CREATE, &device->vdp_video_mixer_create},
|
|
|
|
{VDP_FUNC_ID_VIDEO_MIXER_DESTROY, &device->vdp_video_mixer_destroy},
|
|
|
|
{VDP_FUNC_ID_VIDEO_MIXER_RENDER, &device->vdp_video_mixer_render},
|
2009-07-04 11:59:36 +00:00
|
|
|
{VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES,
|
|
|
|
&device->vdp_video_mixer_set_feature_enables},
|
2009-07-04 13:46:02 +00:00
|
|
|
{VDP_FUNC_ID_VIDEO_MIXER_SET_ATTRIBUTE_VALUES,
|
|
|
|
&device->vdp_video_mixer_set_attribute_values},
|
2009-06-30 21:55:13 +00:00
|
|
|
{VDP_FUNC_ID_OUTPUT_SURFACE_CREATE, &device->vdp_output_surface_create},
|
|
|
|
{VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY, &device->vdp_output_surface_destroy},
|
|
|
|
{VDP_FUNC_ID_OUTPUT_SURFACE_QUERY_CAPABILITIES,
|
|
|
|
&device->vdp_output_surface_query_capabilities},
|
2009-11-22 21:28:18 +00:00
|
|
|
{VDP_FUNC_ID_OUTPUT_SURFACE_GET_BITS_NATIVE,
|
|
|
|
&device->vdp_output_surface_get_bits_native},
|
2009-06-30 21:55:13 +00:00
|
|
|
{VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11,
|
|
|
|
&device->vdp_presentation_queue_target_create_x11},
|
2010-03-17 20:02:07 +00:00
|
|
|
{VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_DESTROY,
|
|
|
|
&device->vdp_presentation_queue_target_destroy},
|
2009-06-30 21:55:13 +00:00
|
|
|
{VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE,
|
|
|
|
&device->vdp_presentation_queue_create},
|
|
|
|
{VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY,
|
|
|
|
&device->vdp_presentation_queue_destroy},
|
|
|
|
{VDP_FUNC_ID_PRESENTATION_QUEUE_DISPLAY,
|
|
|
|
&device->vdp_presentation_queue_display},
|
|
|
|
{VDP_FUNC_ID_PRESENTATION_QUEUE_BLOCK_UNTIL_SURFACE_IDLE,
|
|
|
|
&device->vdp_presentation_queue_block_until_surface_idle},
|
|
|
|
{VDP_FUNC_ID_PRESENTATION_QUEUE_SET_BACKGROUND_COLOR,
|
2009-10-27 21:04:10 +00:00
|
|
|
&device->vdp_presentation_queue_set_background_color},
|
|
|
|
{VDP_FUNC_ID_PRESENTATION_QUEUE_QUERY_SURFACE_STATUS,
|
|
|
|
&device->vdp_presentation_queue_query_surface_status}
|
2009-04-03 15:51:16 +00:00
|
|
|
};
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (device, "Opening the device for display '%s'",
|
|
|
|
device->display_name);
|
|
|
|
|
2009-04-03 15:51:16 +00:00
|
|
|
device->display = XOpenDisplay (device->display_name);
|
2010-07-30 20:27:49 +00:00
|
|
|
if (!device->display)
|
|
|
|
goto create_display_error;
|
2009-04-03 15:51:16 +00:00
|
|
|
|
|
|
|
screen = DefaultScreen (device->display);
|
|
|
|
status =
|
|
|
|
vdp_device_create_x11 (device->display, screen, &device->device,
|
|
|
|
&device->vdp_get_proc_address);
|
2010-07-30 20:27:49 +00:00
|
|
|
if (status != VDP_STATUS_OK)
|
|
|
|
goto create_device_error;
|
2009-04-03 15:51:16 +00:00
|
|
|
|
|
|
|
status = device->vdp_get_proc_address (device->device,
|
|
|
|
VDP_FUNC_ID_GET_ERROR_STRING, (void **) &device->vdp_get_error_string);
|
2010-07-30 20:27:49 +00:00
|
|
|
if (status != VDP_STATUS_OK)
|
|
|
|
goto get_error_string_error;
|
2009-04-03 15:51:16 +00:00
|
|
|
|
2009-06-30 22:13:14 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (vdp_function); i++) {
|
2009-04-03 15:51:16 +00:00
|
|
|
status = device->vdp_get_proc_address (device->device,
|
|
|
|
vdp_function[i].id, vdp_function[i].func);
|
|
|
|
|
2010-07-30 20:27:49 +00:00
|
|
|
if (status != VDP_STATUS_OK)
|
|
|
|
goto function_error;
|
2009-04-03 15:51:16 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (device, "Succesfully opened the device");
|
|
|
|
|
2010-07-30 20:27:49 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
create_display_error:
|
|
|
|
g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_OPEN_READ,
|
|
|
|
"Could not open X display with name: %s", device->display_name);
|
|
|
|
return FALSE;
|
2009-04-03 15:51:16 +00:00
|
|
|
|
2010-07-30 20:27:49 +00:00
|
|
|
create_device_error:
|
|
|
|
g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_OPEN_READ,
|
|
|
|
"Could not create VDPAU device for display: %s", device->display_name);
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
get_error_string_error:
|
|
|
|
g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_OPEN_READ,
|
|
|
|
"Could not get vdp_get_error_string function pointer from VDPAU");
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
function_error:
|
|
|
|
g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_OPEN_READ,
|
|
|
|
"Could not get function pointer from VDPAU, error returned was: %s",
|
|
|
|
device->vdp_get_error_string (status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstVdpDevice *
|
|
|
|
gst_vdp_device_new (const gchar * display_name, GError ** error)
|
|
|
|
{
|
|
|
|
GstVdpDevice *device;
|
|
|
|
|
|
|
|
device = g_object_new (GST_TYPE_VDP_DEVICE, "display", display_name, NULL);
|
|
|
|
|
|
|
|
if (!gst_vdp_device_open (device, error)) {
|
|
|
|
g_object_unref (device);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vdp_device_init (GstVdpDevice * device)
|
|
|
|
{
|
|
|
|
device->display_name = NULL;
|
2009-04-03 15:51:16 +00:00
|
|
|
device->display = NULL;
|
2010-07-30 20:27:49 +00:00
|
|
|
device->device = VDP_INVALID_HANDLE;
|
2010-08-06 10:14:04 +00:00
|
|
|
device->vdp_decoder_destroy = NULL;
|
2010-07-30 20:27:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vdp_device_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstVdpDevice *device = (GstVdpDevice *) object;
|
2009-04-03 15:51:16 +00:00
|
|
|
|
2010-08-06 10:14:04 +00:00
|
|
|
if (device->device != VDP_INVALID_HANDLE && device->vdp_decoder_destroy) {
|
2009-04-03 15:51:16 +00:00
|
|
|
device->vdp_device_destroy (device->device);
|
|
|
|
device->device = VDP_INVALID_HANDLE;
|
|
|
|
}
|
2010-08-06 10:14:04 +00:00
|
|
|
|
2010-07-30 20:27:49 +00:00
|
|
|
if (device->display) {
|
|
|
|
XCloseDisplay (device->display);
|
|
|
|
device->display = NULL;
|
|
|
|
}
|
2010-08-06 10:14:04 +00:00
|
|
|
|
2010-07-30 20:27:49 +00:00
|
|
|
g_free (device->display_name);
|
|
|
|
device->display_name = NULL;
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_vdp_device_parent_class)->finalize (object);
|
2009-04-03 15:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-04-13 20:19:20 +00:00
|
|
|
gst_vdp_device_set_property (GObject * object, guint prop_id,
|
2009-04-03 15:51:16 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2009-04-13 20:19:20 +00:00
|
|
|
GstVdpDevice *device;
|
2009-04-03 15:51:16 +00:00
|
|
|
|
2009-06-07 21:46:38 +00:00
|
|
|
g_return_if_fail (GST_IS_VDP_DEVICE (object));
|
2009-04-03 15:51:16 +00:00
|
|
|
|
2009-04-13 20:19:20 +00:00
|
|
|
device = (GstVdpDevice *) object;
|
2009-04-03 15:51:16 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISPLAY:
|
|
|
|
device->display_name = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-04-13 20:19:20 +00:00
|
|
|
gst_vdp_device_get_property (GObject * object, guint prop_id, GValue * value,
|
2009-04-03 15:51:16 +00:00
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
2009-04-13 20:19:20 +00:00
|
|
|
GstVdpDevice *device;
|
2009-04-03 15:51:16 +00:00
|
|
|
|
2009-06-07 21:46:38 +00:00
|
|
|
g_return_if_fail (GST_IS_VDP_DEVICE (object));
|
2009-04-03 15:51:16 +00:00
|
|
|
|
2009-04-13 20:19:20 +00:00
|
|
|
device = (GstVdpDevice *) object;
|
2009-04-03 15:51:16 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISPLAY:
|
|
|
|
g_value_set_string (value, device->display_name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-04-13 20:19:20 +00:00
|
|
|
gst_vdp_device_class_init (GstVdpDeviceClass * klass)
|
2009-04-03 15:51:16 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2009-04-13 20:19:20 +00:00
|
|
|
object_class->finalize = gst_vdp_device_finalize;
|
|
|
|
object_class->get_property = gst_vdp_device_get_property;
|
|
|
|
object_class->set_property = gst_vdp_device_set_property;
|
2009-04-03 15:51:16 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_DISPLAY,
|
|
|
|
g_param_spec_string ("display",
|
|
|
|
"Display",
|
|
|
|
"X Display Name",
|
|
|
|
"", G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
}
|
|
|
|
|
2009-08-17 21:39:14 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GHashTable *hash_table;
|
2013-04-01 07:10:53 +00:00
|
|
|
GMutex mutex;
|
2009-08-17 21:39:14 +00:00
|
|
|
} GstVdpDeviceCache;
|
|
|
|
|
2009-04-03 15:51:16 +00:00
|
|
|
static void
|
|
|
|
device_destroyed_cb (gpointer data, GObject * object)
|
|
|
|
{
|
2009-08-17 21:39:14 +00:00
|
|
|
GstVdpDeviceCache *device_cache = data;
|
2009-04-03 15:51:16 +00:00
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer device;
|
|
|
|
|
2009-05-05 21:19:56 +00:00
|
|
|
GST_DEBUG ("Removing object from hash table");
|
|
|
|
|
2013-04-01 07:10:53 +00:00
|
|
|
g_mutex_lock (&device_cache->mutex);
|
2009-08-17 21:39:14 +00:00
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, device_cache->hash_table);
|
2009-04-03 15:51:16 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, NULL, &device)) {
|
|
|
|
if (device == object) {
|
|
|
|
g_hash_table_iter_remove (&iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-08-17 21:39:14 +00:00
|
|
|
|
2013-04-01 07:10:53 +00:00
|
|
|
g_mutex_unlock (&device_cache->mutex);
|
2009-04-03 15:51:16 +00:00
|
|
|
}
|
|
|
|
|
2009-04-13 20:19:20 +00:00
|
|
|
GstVdpDevice *
|
2010-07-30 20:27:49 +00:00
|
|
|
gst_vdp_get_device (const gchar * display_name, GError ** error)
|
2009-04-03 15:51:16 +00:00
|
|
|
{
|
2009-04-27 18:15:07 +00:00
|
|
|
static gsize once = 0;
|
2009-08-17 21:39:14 +00:00
|
|
|
static GstVdpDeviceCache device_cache;
|
2009-04-13 20:19:20 +00:00
|
|
|
GstVdpDevice *device;
|
2009-04-03 15:51:16 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG ("display_name '%s'", display_name);
|
|
|
|
|
2009-04-27 18:15:07 +00:00
|
|
|
if (g_once_init_enter (&once)) {
|
2009-08-17 21:39:14 +00:00
|
|
|
device_cache.hash_table =
|
2009-04-27 18:15:07 +00:00
|
|
|
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
2013-04-01 07:10:53 +00:00
|
|
|
g_mutex_init (&device_cache.mutex);
|
2009-08-17 21:39:14 +00:00
|
|
|
|
2009-04-27 18:15:07 +00:00
|
|
|
g_once_init_leave (&once, 1);
|
|
|
|
}
|
2009-04-03 15:51:16 +00:00
|
|
|
|
2013-04-01 07:10:53 +00:00
|
|
|
g_mutex_lock (&device_cache.mutex);
|
2009-08-17 21:39:14 +00:00
|
|
|
|
2009-04-03 15:51:16 +00:00
|
|
|
if (display_name)
|
2009-08-17 21:39:14 +00:00
|
|
|
device = g_hash_table_lookup (device_cache.hash_table, display_name);
|
2009-04-03 15:51:16 +00:00
|
|
|
else
|
2009-08-17 21:39:14 +00:00
|
|
|
device = g_hash_table_lookup (device_cache.hash_table, "");
|
2009-04-03 15:51:16 +00:00
|
|
|
|
|
|
|
if (!device) {
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG ("No cached device, creating a new one");
|
2010-07-30 20:27:49 +00:00
|
|
|
device = gst_vdp_device_new (display_name, error);
|
2009-08-17 21:39:14 +00:00
|
|
|
if (device) {
|
|
|
|
g_object_weak_ref (G_OBJECT (device), device_destroyed_cb, &device_cache);
|
|
|
|
if (display_name)
|
|
|
|
g_hash_table_insert (device_cache.hash_table, g_strdup (display_name),
|
|
|
|
device);
|
|
|
|
else
|
|
|
|
g_hash_table_insert (device_cache.hash_table, g_strdup (""), device);
|
2012-09-20 17:03:11 +00:00
|
|
|
} else
|
|
|
|
GST_ERROR ("Could not create GstVdpDevice !");
|
2009-04-03 15:51:16 +00:00
|
|
|
} else
|
|
|
|
g_object_ref (device);
|
|
|
|
|
2013-04-01 07:10:53 +00:00
|
|
|
g_mutex_unlock (&device_cache.mutex);
|
2009-08-17 21:39:14 +00:00
|
|
|
|
2009-04-03 15:51:16 +00:00
|
|
|
return device;
|
|
|
|
}
|