vdpau: add gstvdpaudevice for abstracting vdpau initalization

This commit is contained in:
Carl-Anton Ingmarsson 2009-04-01 21:19:18 +02:00 committed by Jan Schmidt
parent a22a18d1e7
commit f74f44c24f
7 changed files with 392 additions and 213 deletions

View file

@ -1,9 +1,10 @@
plugin_LTLIBRARIES = libgstvdpau.la
libgstvdpau_la_SOURCES = \
gst-vdpau-device.c \
gstvdpaudecoder.c \
gstvdpaumpegdecoder.c \
mpegutil.c
mpegutil.c \
libgstvdpau_la_CFLAGS = $(GST_CFLAGS) $(X11_CFLAGS) -Ivdpau
libgstvdpau_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS) \
@ -12,8 +13,9 @@ libgstvdpau_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstvdpau_la_LIBTOOLFLAGS = --tag=disable-static
noinst_HEADERS = \
gst-vdpau-device.h \
gstvdpaudecoder.h \
gstvdpaumpegdecoder.h \
mpegutil.h
mpegutil.h

View file

@ -0,0 +1,267 @@
/*
* 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
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <vdpau/vdpau_x11.h>
#include <gst/gst.h>
#include "gst-vdpau-device.h"
GST_DEBUG_CATEGORY_STATIC (gst_vdpau_device_debug);
#define GST_CAT_DEFAULT gst_vdpau_device_debug
enum
{
PROP_0,
PROP_DISPLAY
};
G_DEFINE_TYPE (GstVdpauDevice, gst_vdpau_device, G_TYPE_OBJECT);
static void
gst_vdpau_device_init (GstVdpauDevice * device)
{
device->display_name = NULL;
device->display = NULL;
device->device = VDP_INVALID_HANDLE;
}
static void
gst_vdpau_device_finalize (GObject * object)
{
GstVdpauDevice *device = (GstVdpauDevice *) object;
device->vdp_device_destroy (device->device);
g_free (device->display_name);
G_OBJECT_CLASS (gst_vdpau_device_parent_class)->finalize (object);
}
static void
gst_vdpau_device_constructed (GObject * object)
{
GstVdpauDevice *device = (GstVdpauDevice *) object;
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},
{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},
{0, NULL}
};
/* FIXME: We probably want to use the same VdpDevice for every VDPAU element */
device->display = XOpenDisplay (device->display_name);
if (!device->display) {
GST_ERROR_OBJECT (device, "Could not open X display with name: %s",
device->display_name);
return;
}
screen = DefaultScreen (device->display);
status =
vdp_device_create_x11 (device->display, screen, &device->device,
&device->vdp_get_proc_address);
if (status != VDP_STATUS_OK) {
GST_ERROR_OBJECT (device, "Could not create VDPAU device");
XCloseDisplay (device->display);
device->display = NULL;
return;
}
status = device->vdp_get_proc_address (device->device,
VDP_FUNC_ID_GET_ERROR_STRING, (void **) &device->vdp_get_error_string);
if (status != VDP_STATUS_OK) {
GST_ERROR_OBJECT (device,
"Could not get vdp_get_error_string function pointer from VDPAU");
goto error;
}
for (i = 0; vdp_function[i].func != NULL; i++) {
status = device->vdp_get_proc_address (device->device,
vdp_function[i].id, vdp_function[i].func);
if (status != VDP_STATUS_OK) {
GST_ERROR_OBJECT (device, "Could not get function pointer from VDPAU,"
" error returned was: %s", device->vdp_get_error_string (status));
goto error;
}
}
return;
error:
XCloseDisplay (device->display);
device->display = NULL;
if (device->device != VDP_INVALID_HANDLE) {
device->vdp_device_destroy (device->device);
device->device = VDP_INVALID_HANDLE;
}
}
static void
gst_vdpau_device_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstVdpauDevice *device;
g_return_if_fail (GST_IS_VDPAU_DEVICE (object));
device = (GstVdpauDevice *) object;
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
gst_vdpau_device_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec)
{
GstVdpauDevice *device;
g_return_if_fail (GST_IS_VDPAU_DEVICE (object));
device = (GstVdpauDevice *) object;
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
gst_vdpau_device_class_init (GstVdpauDeviceClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = gst_vdpau_device_constructed;
object_class->finalize = gst_vdpau_device_finalize;
object_class->get_property = gst_vdpau_device_get_property;
object_class->set_property = gst_vdpau_device_set_property;
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));
GST_DEBUG_CATEGORY_INIT (gst_vdpau_device_debug, "vdpaudevice",
0, "vdpaudevice");
}
GstVdpauDevice *
gst_vdpau_device_new (const gchar * display_name)
{
GstVdpauDevice *device;
device = g_object_new (GST_TYPE_VDPAU_DEVICE, "display", display_name);
return device;
}
static void
device_destroyed_cb (gpointer data, GObject * object)
{
GHashTable *devices_hash = data;
GHashTableIter iter;
gpointer device;
g_hash_table_iter_init (&iter, devices_hash);
while (g_hash_table_iter_next (&iter, NULL, &device)) {
if (device == object) {
g_hash_table_iter_remove (&iter);
break;
}
}
}
static gpointer
create_devices_hash (gpointer data)
{
return g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
}
GstVdpauDevice *
gst_vdpau_get_device (const gchar * display_name)
{
static GOnce my_once = G_ONCE_INIT;
GHashTable *devices_hash;
GstVdpauDevice *device;
g_once (&my_once, create_devices_hash, NULL);
devices_hash = my_once.retval;
if (display_name)
device = g_hash_table_lookup (devices_hash, display_name);
else
device = g_hash_table_lookup (devices_hash, "");
if (!device) {
g_debug ("asdasd");
device = gst_vdpau_device_new (display_name);
g_object_weak_ref (G_OBJECT (device), device_destroyed_cb, devices_hash);
} else
g_object_ref (device);
g_debug ("HMM");
return device;
}

View file

@ -0,0 +1,80 @@
/*
* 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
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef _GST_VDPAU_DEVICE_H_
#define _GST_VDPAU_DEVICE_H_
#include <X11/Xlib.h>
#include <vdpau/vdpau.h>
#include <glib-object.h>
G_BEGIN_DECLS
#define GST_TYPE_VDPAU_DEVICE (gst_vdpau_device_get_type ())
#define GST_VDPAU_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VDPAU_DEVICE, GstVdpauDevice))
#define GST_VDPAU_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VDPAU_DEVICE, GstVdpauDeviceClass))
#define GST_IS_VDPAU_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VDPAU_DEVICE))
#define GST_IS_VDPAU_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VDPAU_DEVICE))
#define GST_VDPAU_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_VDPAU_DEVICE, GstVdpauDeviceClass))
typedef struct _GstVdpauDeviceClass GstVdpauDeviceClass;
typedef struct _GstVdpauDevice GstVdpauDevice;
struct _GstVdpauDeviceClass
{
GObjectClass parent_class;
};
struct _GstVdpauDevice
{
GObject object;
gchar *display_name;
Display *display;
VdpDevice device;
VdpDeviceDestroy *vdp_device_destroy;
VdpGetProcAddress *vdp_get_proc_address;
VdpGetErrorString *vdp_get_error_string;
VdpVideoSurfaceCreate *vdp_video_surface_create;
VdpVideoSurfaceDestroy *vdp_video_surface_destroy;
VdpVideoSurfaceQueryCapabilities *vdp_video_surface_query_capabilities;
VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities *vdp_video_surface_query_ycbcr_capabilities;
VdpVideoSurfaceGetParameters *vdp_video_surface_get_parameters;
VdpVideoSurfaceGetBitsYCbCr *vdp_video_surface_get_bits_ycbcr;
VdpDecoderCreate *vdp_decoder_create;
VdpDecoderDestroy *vdp_decoder_destroy;
VdpDecoderRender *vdp_decoder_render;
VdpDecoderQueryCapabilities *vdp_decoder_query_capabilities;
VdpDecoderGetParameters *vdp_decoder_get_parameters;
};
GType gst_vdpau_device_get_type (void) G_GNUC_CONST;
GstVdpauDevice *gst_vdpau_device_new (const gchar *display_name);
GstVdpauDevice *gst_vdpau_get_device (const gchar *display_name);
G_END_DECLS
#endif /* _GST_VDPAU_DEVICE_H_ */

View file

@ -1,6 +1,5 @@
/*
* GStreamer
* Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
* Copyright (C) 2009 Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>
*
* This library is free software; you can redistribute it and/or
@ -27,7 +26,6 @@
#include <gst/video/video.h>
#include "gstvdpaudecoder.h"
#include <vdpau/vdpau_x11.h>
GST_DEBUG_CATEGORY_STATIC (gst_vdpaudecoder_debug);
#define GST_CAT_DEFAULT gst_vdpaudecoder_debug
@ -68,10 +66,10 @@ GstFlowReturn
gst_vdpau_decoder_push_video_surface (GstVdpauDecoder * dec,
VdpVideoSurface surface)
{
VdpauFunctions *f;
GstVdpauDevice *device;
GstBuffer *buffer;
f = dec->functions;
device = dec->device;
switch (dec->format) {
case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
@ -110,13 +108,13 @@ gst_vdpau_decoder_push_video_surface (GstVdpauDecoder * dec,
1, dec->width);
status =
f->vdp_video_surface_get_bits_ycbcr (surface, VDP_YCBCR_FORMAT_YV12,
(void *) data, stride);
device->vdp_video_surface_get_bits_ycbcr (surface,
VDP_YCBCR_FORMAT_YV12, (void *) data, stride);
if (G_UNLIKELY (status != VDP_STATUS_OK)) {
GST_ELEMENT_ERROR (dec, RESOURCE, READ,
("Couldn't get data from vdpau"),
("Error returned from vdpau was: %s",
f->vdp_get_error_string (status)));
device->vdp_get_error_string (status)));
return GST_FLOW_ERROR;
}
break;
@ -144,13 +142,13 @@ gst_vdpau_decoder_push_video_surface (GstVdpauDecoder * dec,
stride[1] = dec->width;
status =
f->vdp_video_surface_get_bits_ycbcr (surface, VDP_YCBCR_FORMAT_NV12,
(void *) data, stride);
device->vdp_video_surface_get_bits_ycbcr (surface,
VDP_YCBCR_FORMAT_NV12, (void *) data, stride);
if (G_UNLIKELY (status != VDP_STATUS_OK)) {
GST_ELEMENT_ERROR (dec, RESOURCE, READ,
("Couldn't get data from vdpau"),
("Error returned from vdpau was: %s",
f->vdp_get_error_string (status)));
device->vdp_get_error_string (status)));
return GST_FLOW_ERROR;
}
break;
@ -217,13 +215,13 @@ static VdpauFormats formats[6] = {
VdpVideoSurface
gst_vdpau_decoder_create_video_surface (GstVdpauDecoder * dec)
{
VdpauFunctions *f;
GstVdpauDevice *device;
VdpChromaType chroma_type;
gint i;
VdpStatus status;
VdpVideoSurface surface;
f = dec->functions;
device = dec->device;
chroma_type = VDP_CHROMA_TYPE_422;
for (i = 0; i < 6; i++) {
@ -233,13 +231,14 @@ gst_vdpau_decoder_create_video_surface (GstVdpauDecoder * dec)
}
}
status = f->vdp_video_surface_create (dec->device, chroma_type, dec->width,
status =
device->vdp_video_surface_create (device->device, chroma_type, dec->width,
dec->height, &surface);
if (status != VDP_STATUS_OK) {
GST_ELEMENT_ERROR (dec, RESOURCE, READ,
("Couldn't create a VdpVideoSurface"),
("Error returned from vdpau was: %s",
f->vdp_get_error_string (status)));
device->vdp_get_error_string (status)));
return VDP_INVALID_HANDLE;
}
@ -249,11 +248,11 @@ gst_vdpau_decoder_create_video_surface (GstVdpauDecoder * dec)
static GstCaps *
gst_vdpaudecoder_get_vdpau_support (GstVdpauDecoder * dec)
{
VdpauFunctions *f;
GstVdpauDevice *device;
GstCaps *caps;
gint i;
f = dec->functions;
device = dec->device;
caps = gst_caps_new_empty ();
@ -263,14 +262,14 @@ gst_vdpaudecoder_get_vdpau_support (GstVdpauDecoder * dec)
guint32 max_w, max_h;
status =
f->vdp_video_surface_query_capabilities (dec->device, chroma_types[i],
&is_supported, &max_w, &max_h);
device->vdp_video_surface_query_capabilities (device->device,
chroma_types[i], &is_supported, &max_w, &max_h);
if (status != VDP_STATUS_OK && status != VDP_STATUS_INVALID_CHROMA_TYPE) {
GST_ELEMENT_ERROR (dec, RESOURCE, READ,
("Could not get query VDPAU video surface capabilites"),
("Error returned from vdpau was: %s",
f->vdp_get_error_string (status)));
device->vdp_get_error_string (status)));
return NULL;
}
@ -282,14 +281,14 @@ gst_vdpaudecoder_get_vdpau_support (GstVdpauDecoder * dec)
continue;
status =
f->vdp_video_surface_query_ycbcr_capabilities (dec->device,
device->vdp_video_surface_query_ycbcr_capabilities (device->device,
formats[j].chroma_type, formats[j].format, &is_supported);
if (status != VDP_STATUS_OK
&& status != VDP_STATUS_INVALID_Y_CB_CR_FORMAT) {
GST_ELEMENT_ERROR (dec, RESOURCE, READ,
("Could not query VDPAU YCbCr capabilites"),
("Error returned from vdpau was: %s",
f->vdp_get_error_string (status)));
device->vdp_get_error_string (status)));
return NULL;
}
@ -317,111 +316,25 @@ gst_vdpaudecoder_get_vdpau_support (GstVdpauDecoder * dec)
static gboolean
gst_vdpaudecoder_init_vdpau (GstVdpauDecoder * dec)
{
gint screen;
VdpStatus status;
gint i;
VdpauFunctions *f;
GstCaps *caps;
typedef struct
{
int id;
void *func;
} VdpFunction;
VdpFunction vdp_function[] = {
{VDP_FUNC_ID_DEVICE_DESTROY, &dec->functions->vdp_device_destroy},
{VDP_FUNC_ID_VIDEO_SURFACE_CREATE,
&dec->functions->vdp_video_surface_create},
{VDP_FUNC_ID_VIDEO_SURFACE_DESTROY,
&dec->functions->vdp_video_surface_destroy},
{VDP_FUNC_ID_VIDEO_SURFACE_QUERY_CAPABILITIES,
&dec->functions->vdp_video_surface_query_capabilities},
{VDP_FUNC_ID_VIDEO_SURFACE_QUERY_GET_PUT_BITS_Y_CB_CR_CAPABILITIES,
&dec->functions->vdp_video_surface_query_ycbcr_capabilities},
{VDP_FUNC_ID_VIDEO_SURFACE_GET_BITS_Y_CB_CR,
&dec->functions->vdp_video_surface_get_bits_ycbcr},
{VDP_FUNC_ID_VIDEO_SURFACE_GET_PARAMETERS,
&dec->functions->vdp_video_surface_get_parameters},
{VDP_FUNC_ID_DECODER_CREATE, &dec->functions->vdp_decoder_create},
{VDP_FUNC_ID_DECODER_RENDER, &dec->functions->vdp_decoder_render},
{VDP_FUNC_ID_DECODER_DESTROY, &dec->functions->vdp_decoder_destroy},
{VDP_FUNC_ID_DECODER_QUERY_CAPABILITIES,
&dec->functions->vdp_decoder_query_capabilities},
{VDP_FUNC_ID_DECODER_GET_PARAMETERS,
&dec->functions->vdp_decoder_get_parameters},
{0, NULL}
};
/* FIXME: We probably want to use the same VdpDevice for every VDPAU element */
dec->display = XOpenDisplay (dec->display_name);
if (!dec->display) {
GST_ELEMENT_ERROR (dec, RESOURCE, READ, ("Could not initialise VDPAU"),
("Could not open display"));
return FALSE;
}
f = dec->functions;
screen = DefaultScreen (dec->display);
status =
vdp_device_create_x11 (dec->display, screen, &dec->device,
&f->vdp_get_proc_address);
if (status != VDP_STATUS_OK) {
GST_ELEMENT_ERROR (dec, RESOURCE, READ, ("Could not initialise VDPAU"),
("Could not create VDPAU device"));
XCloseDisplay (dec->display);
dec->display = NULL;
return FALSE;
}
status = f->vdp_get_proc_address (dec->device,
VDP_FUNC_ID_GET_ERROR_STRING, (void **) &f->vdp_get_error_string);
if (status != VDP_STATUS_OK) {
GST_ELEMENT_ERROR (dec, RESOURCE, READ,
("Could'nt get function pointer from vdpau"),
("Couldn't get vdp_get_error_string function pointer"));
goto error;
}
for (i = 0; vdp_function[i].func != NULL; i++) {
status = f->vdp_get_proc_address (dec->device,
vdp_function[i].id, vdp_function[i].func);
if (status != VDP_STATUS_OK) {
GST_ELEMENT_ERROR (dec, RESOURCE, READ,
("Could not get function pointer from vdpau"),
("Error returned from vdpau was: %s",
f->vdp_get_error_string (status)));
goto error;
}
}
dec->device = gst_vdpau_get_device (dec->display_name);
caps = gst_vdpaudecoder_get_vdpau_support (dec);
if (!caps)
goto error;
return FALSE;
dec->src_caps = caps;
return TRUE;
error:
f->vdp_device_destroy (dec->device);
dec->device = VDP_INVALID_HANDLE;
return FALSE;
}
static GstStateChangeReturn
gst_vdpaudecoder_change_state (GstElement * element, GstStateChange transition)
{
GstVdpauDecoder *dec;
VdpauFunctions *f;
dec = GST_VDPAU_DECODER (element);
f = dec->functions;
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
@ -429,11 +342,8 @@ gst_vdpaudecoder_change_state (GstElement * element, GstStateChange transition)
return GST_STATE_CHANGE_FAILURE;
break;
case GST_STATE_CHANGE_READY_TO_NULL:
f->vdp_device_destroy (dec->device);
XCloseDisplay (dec->display);
dec->device = VDP_INVALID_HANDLE;
dec->display = NULL;
g_object_unref (dec->device);
dec->device = NULL;
break;
default:
break;
@ -561,8 +471,7 @@ static void
gst_vdpaudecoder_init (GstVdpauDecoder * dec, GstVdpauDecoderClass * klass)
{
dec->display_name = NULL;
dec->display = NULL;
dec->device = VDP_INVALID_HANDLE;
dec->device = NULL;
dec->silent = FALSE;
dec->src_caps = NULL;
@ -574,8 +483,6 @@ gst_vdpaudecoder_init (GstVdpauDecoder * dec, GstVdpauDecoderClass * klass)
dec->frame_nr = 0;
dec->functions = g_slice_new0 (VdpauFunctions);
dec->src = gst_pad_new_from_static_template (&src_template, "src");
gst_pad_set_getcaps_function (dec->src, gst_vdpaudecoder_src_getcaps);
gst_element_add_pad (GST_ELEMENT (dec), dec->src);

View file

@ -1,6 +1,5 @@
/*
* GStreamer
* Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
* Copyright (C) 2009 Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>
*
* This library is free software; you can redistribute it and/or
@ -23,10 +22,8 @@
#define __GST_VDPAU_DECODER_H__
#include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
#include <X11/Xlib.h>
#include <vdpau/vdpau.h>
#include "gst-vdpau-device.h"
G_BEGIN_DECLS
@ -45,10 +42,7 @@ struct _GstVdpauDecoder {
GstElement element;
gchar *display_name;
Display *display;
VdpDevice device;
VdpauFunctions *functions;
GstVdpauDevice *device;
GstPad *src;
GstPad *sink;
@ -65,30 +59,11 @@ struct _GstVdpauDecoder {
};
struct _GstVdpauDecoderClass {
GstBaseTransformClass parent_class;
GstElementClass parent_class;
gboolean (*set_caps) (GstVdpauDecoder *dec, GstCaps *caps);
};
struct _VdpauFunctions {
VdpDeviceDestroy *vdp_device_destroy;
VdpGetProcAddress *vdp_get_proc_address;
VdpGetErrorString *vdp_get_error_string;
VdpVideoSurfaceCreate *vdp_video_surface_create;
VdpVideoSurfaceDestroy *vdp_video_surface_destroy;
VdpVideoSurfaceQueryCapabilities *vdp_video_surface_query_capabilities;
VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities *vdp_video_surface_query_ycbcr_capabilities;
VdpVideoSurfaceGetParameters *vdp_video_surface_get_parameters;
VdpVideoSurfaceGetBitsYCbCr *vdp_video_surface_get_bits_ycbcr;
VdpDecoderCreate *vdp_decoder_create;
VdpDecoderDestroy *vdp_decoder_destroy;
VdpDecoderRender *vdp_decoder_render;
VdpDecoderQueryCapabilities *vdp_decoder_query_capabilities;
VdpDecoderGetParameters *vdp_decoder_get_parameters;
};
GType gst_vdpaudecoder_get_type (void);
gboolean gst_vdpau_decoder_push_video_surface (GstVdpauDecoder * dec,

View file

@ -1,29 +1,6 @@
/*
* GStreamer
* Copyright (C) 2009 Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Alternatively, the contents of this file may be used under the
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
* which case the following provisions apply instead of the ones
* mentioned above:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -108,7 +85,7 @@ gst_vdpau_mpeg_decoder_set_caps (GstVdpauDecoder * dec, GstCaps * caps)
GstBuffer *codec_data;
MPEGSeqHdr hdr = { 0, };
VdpDecoderProfile profile;
VdpauFunctions *f;
GstVdpauDevice *device;
VdpStatus status;
mpeg_dec = GST_VDPAU_MPEG_DECODER (dec);
@ -137,14 +114,14 @@ gst_vdpau_mpeg_decoder_set_caps (GstVdpauDecoder * dec, GstCaps * caps)
memcpy (&mpeg_dec->vdp_info.non_intra_quantizer_matrix,
&hdr.non_intra_quantizer_matrix, 64);
f = dec->functions;
status = f->vdp_decoder_create (dec->device, profile, dec->width,
device = dec->device;
status = device->vdp_decoder_create (device->device, profile, dec->width,
dec->height, 2, &mpeg_dec->decoder);
if (status != VDP_STATUS_OK) {
GST_ELEMENT_ERROR (mpeg_dec, RESOURCE, READ,
("Could not create vdpau decoder"),
("Error returned from vdpau was: %s",
f->vdp_get_error_string (status)));
device->vdp_get_error_string (status)));
return FALSE;
}
return TRUE;
@ -156,7 +133,7 @@ gst_vdpau_mpeg_decoder_decode (GstVdpauMpegDecoder * mpeg_dec)
GstVdpauDecoder *dec;
GstBuffer *buffer;
VdpVideoSurface surface;
VdpauFunctions *f;
GstVdpauDevice *device;
VdpBitstreamBuffer vbit[1];
VdpStatus status;
GstFlowReturn ret;
@ -166,20 +143,16 @@ gst_vdpau_mpeg_decoder_decode (GstVdpauMpegDecoder * mpeg_dec)
buffer = gst_adapter_take_buffer (mpeg_dec->adapter,
gst_adapter_available (mpeg_dec->adapter));
if (mpeg_dec->vdp_info.picture_coding_type == P_FRAME) {
mpeg_dec->p_buffer = buffer;
}
surface =
gst_vdpau_decoder_create_video_surface (GST_VDPAU_DECODER (mpeg_dec));
f = dec->functions;
device = dec->device;
vbit[0].struct_version = VDP_BITSTREAM_BUFFER_VERSION;
vbit[0].bitstream = GST_BUFFER_DATA (buffer);
vbit[0].bitstream_bytes = GST_BUFFER_SIZE (buffer);
status = f->vdp_decoder_render (mpeg_dec->decoder, surface,
status = device->vdp_decoder_render (mpeg_dec->decoder, surface,
(VdpPictureInfo *) & mpeg_dec->vdp_info, 1, vbit);
gst_buffer_unref (buffer);
mpeg_dec->vdp_info.slice_count = 0;
@ -188,12 +161,12 @@ gst_vdpau_mpeg_decoder_decode (GstVdpauMpegDecoder * mpeg_dec)
GST_ELEMENT_ERROR (mpeg_dec, RESOURCE, READ,
("Could not decode"),
("Error returned from vdpau was: %s",
f->vdp_get_error_string (status)));
device->vdp_get_error_string (status)));
if (mpeg_dec->vdp_info.forward_reference != VDP_INVALID_HANDLE)
f->vdp_video_surface_destroy (mpeg_dec->vdp_info.forward_reference);
device->vdp_video_surface_destroy (mpeg_dec->vdp_info.forward_reference);
f->vdp_video_surface_destroy (surface);
device->vdp_video_surface_destroy (surface);
return GST_FLOW_ERROR;
}
@ -203,7 +176,7 @@ gst_vdpau_mpeg_decoder_decode (GstVdpauMpegDecoder * mpeg_dec)
surface);
if (mpeg_dec->vdp_info.forward_reference != VDP_INVALID_HANDLE)
f->vdp_video_surface_destroy (mpeg_dec->vdp_info.forward_reference);
device->vdp_video_surface_destroy (mpeg_dec->vdp_info.forward_reference);
mpeg_dec->vdp_info.forward_reference = surface;
@ -254,8 +227,8 @@ gst_vdpau_mpeg_decoder_parse_picture (GstVdpauMpegDecoder * mpeg_dec,
if (pic_hdr.pic_type == I_FRAME &&
mpeg_dec->vdp_info.forward_reference != VDP_INVALID_HANDLE) {
dec->functions->vdp_video_surface_destroy (mpeg_dec->vdp_info.
forward_reference);
dec->device->vdp_video_surface_destroy (mpeg_dec->
vdp_info.forward_reference);
mpeg_dec->vdp_info.forward_reference = VDP_INVALID_HANDLE;
}

View file

@ -1,29 +1,6 @@
/*
* GStreamer
* Copyright (C) 2009 Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Alternatively, the contents of this file may be used under the
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
* which case the following provisions apply instead of the ones
* mentioned above:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -74,8 +51,6 @@ struct _GstVdpauMpegDecoder
GstAdapter *adapter;
gint slices;
GstBuffer *p_buffer;
VdpPictureInfoMPEG1Or2 p_vdp_info;
};
struct _GstVdpauMpegDecoderClass