vdpau: add gst_vdp_init function where we register types

This commit is contained in:
Carl-Anton Ingmarsson 2010-03-17 21:02:07 +01:00
parent c4f60760ed
commit ae660783f5
9 changed files with 111 additions and 89 deletions

View file

@ -1,31 +1,44 @@
#ifdef HAVE_CONFIG_H /*
# include <config.h> * GStreamer
#endif * 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 <gst/gst.h> #include <gst/gst.h>
#include "gstvdpmpegdec.h" #include "gstvdpdevice.h"
#include "gstvdpvideopostprocess.h" #include "gstvdpvideobuffer.h"
#include "gstvdpsink.h" #include "gstvdpvideosrcpad.h"
#include "gstvdpoutputbuffer.h"
#include "gstvdpoutputsrcpad.h"
static gboolean #include "gstvdp.h"
vdpau_init (GstPlugin * vdpau_plugin)
GST_DEBUG_CATEGORY (gst_vdp_debug);
void
gst_vdp_init ()
{ {
/* Before giving these elements a rank again, make sure they pass at /* do this so debug categories get created */
* least the generic/states test when there's no device available */ gst_vdp_device_get_type ();
gst_element_register (vdpau_plugin, "vdpaumpegdec", gst_vdp_output_buffer_get_type ();
GST_RANK_NONE, GST_TYPE_VDP_MPEG_DEC); gst_vdp_video_buffer_get_type ();
gst_element_register (vdpau_plugin, "vdpauvideopostprocess", gst_vdp_video_src_pad_get_type ();
GST_RANK_NONE, GST_TYPE_VDP_VIDEO_POST_PROCESS); gst_vdp_output_src_pad_get_type ();
gst_element_register (vdpau_plugin, "vdpausink",
GST_RANK_NONE, GST_TYPE_VDP_SINK);
return TRUE; GST_DEBUG_CATEGORY_INIT (gst_vdp_debug, "vdp", 0, "GstVdp debug category");
} }
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"vdpau",
"Various elements utilizing VDPAU",
vdpau_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")

View file

@ -18,13 +18,14 @@
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#include <gst/gst.h>
#include "gstvdpdevice.h" #include "gstvdpdevice.h"
GST_DEBUG_CATEGORY_STATIC (gst_vdp_device_debug); GST_DEBUG_CATEGORY_STATIC (gst_vdp_device_debug);
#define GST_CAT_DEFAULT gst_vdp_device_debug #define GST_CAT_DEFAULT gst_vdp_device_debug
#define DEBUG_INIT(bla) \
GST_DEBUG_CATEGORY_INIT (gst_vdp_device_debug, "vdpdevice", 0, "VDPAU device object");
enum enum
{ {
PROP_0, PROP_0,
@ -33,7 +34,8 @@ enum
G_DEFINE_TYPE (GstVdpDevice, gst_vdp_device, G_TYPE_OBJECT); G_DEFINE_TYPE_WITH_CODE (GstVdpDevice, gst_vdp_device, G_TYPE_OBJECT,
DEBUG_INIT ());
static void static void
gst_vdp_device_init (GstVdpDevice * device) gst_vdp_device_init (GstVdpDevice * device)
@ -116,6 +118,8 @@ gst_vdp_device_constructed (GObject * object)
&device->vdp_output_surface_get_bits_native}, &device->vdp_output_surface_get_bits_native},
{VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11, {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11,
&device->vdp_presentation_queue_target_create_x11}, &device->vdp_presentation_queue_target_create_x11},
{VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_DESTROY,
&device->vdp_presentation_queue_target_destroy},
{VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE, {VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE,
&device->vdp_presentation_queue_create}, &device->vdp_presentation_queue_create},
{VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY, {VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY,
@ -290,8 +294,6 @@ gst_vdp_get_device (const gchar * display_name)
GstVdpDevice *device; GstVdpDevice *device;
if (g_once_init_enter (&once)) { if (g_once_init_enter (&once)) {
GST_DEBUG_CATEGORY_INIT (gst_vdp_device_debug, "vdpaudevice",
0, "vdpaudevice");
device_cache.hash_table = device_cache.hash_table =
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
device_cache.mutex = g_mutex_new (); device_cache.mutex = g_mutex_new ();

View file

@ -25,7 +25,7 @@
#include <vdpau/vdpau.h> #include <vdpau/vdpau.h>
#include <vdpau/vdpau_x11.h> #include <vdpau/vdpau_x11.h>
#include <glib-object.h> #include <gst/gst.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -84,6 +84,8 @@ struct _GstVdpDevice
VdpOutputSurfaceGetBitsNative *vdp_output_surface_get_bits_native; VdpOutputSurfaceGetBitsNative *vdp_output_surface_get_bits_native;
VdpPresentationQueueTargetCreateX11 *vdp_presentation_queue_target_create_x11; VdpPresentationQueueTargetCreateX11 *vdp_presentation_queue_target_create_x11;
VdpPresentationQueueTargetDestroy *vdp_presentation_queue_target_destroy;
VdpPresentationQueueCreate *vdp_presentation_queue_create; VdpPresentationQueueCreate *vdp_presentation_queue_create;
VdpPresentationQueueDestroy *vdp_presentation_queue_destroy; VdpPresentationQueueDestroy *vdp_presentation_queue_destroy;
VdpPresentationQueueDisplay *vdp_presentation_queue_display; VdpPresentationQueueDisplay *vdp_presentation_queue_display;
@ -92,7 +94,7 @@ struct _GstVdpDevice
VdpPresentationQueueQuerySurfaceStatus *vdp_presentation_queue_query_surface_status; VdpPresentationQueueQuerySurfaceStatus *vdp_presentation_queue_query_surface_status;
}; };
GType gst_vdp_device_get_type (void) G_GNUC_CONST; GType gst_vdp_device_get_type (void);
GstVdpDevice *gst_vdp_get_device (const gchar *display_name); GstVdpDevice *gst_vdp_get_device (const gchar *display_name);

View file

@ -39,32 +39,6 @@ gst_vdp_video_remove_pixel_aspect_ratio (GstStructure * structure)
} }
} }
GstCaps *
gst_vdp_yuv_to_output_caps (GstCaps * caps)
{
GstCaps *result;
gint i;
result = gst_caps_copy (caps);
for (i = 0; i < gst_caps_get_size (caps); i++) {
GstStructure *structure, *rgb_structure;
structure = gst_caps_get_structure (result, i);
rgb_structure = gst_structure_copy (structure);
gst_structure_set_name (structure, "video/x-vdpau-output");
gst_structure_remove_field (structure, "format");
gst_vdp_video_remove_pixel_aspect_ratio (structure);
gst_structure_set_name (rgb_structure, "video/x-raw-rgb");
gst_structure_remove_field (rgb_structure, "format");
gst_vdp_video_remove_pixel_aspect_ratio (rgb_structure);
gst_caps_append_structure (result, rgb_structure);
}
return result;
}
GstCaps * GstCaps *
gst_vdp_video_to_output_caps (GstCaps * caps) gst_vdp_video_to_output_caps (GstCaps * caps)
{ {

View file

@ -25,6 +25,5 @@
#include "gstvdpdevice.h" #include "gstvdpdevice.h"
GstCaps *gst_vdp_video_to_output_caps (GstCaps *caps); GstCaps *gst_vdp_video_to_output_caps (GstCaps *caps);
GstCaps *gst_vdp_yuv_to_output_caps (GstCaps *caps);
#endif /* _GST_VDP_UTILS_H_ */ #endif /* _GST_VDP_UTILS_H_ */

View file

@ -24,6 +24,12 @@
#include "gstvdpvideobuffer.h" #include "gstvdpvideobuffer.h"
GST_DEBUG_CATEGORY_STATIC (gst_vdp_video_buffer_debug);
#define GST_CAT_DEFAULT gst_vdp_video_buffer_debug
#define DEBUG_INIT(bla) \
GST_DEBUG_CATEGORY_INIT (gst_vdp_video_buffer_debug, "vdpvideobuffer", 0, "VDPAU video buffer");
GstVdpVideoBuffer * GstVdpVideoBuffer *
gst_vdp_video_buffer_new (GstVdpDevice * device, VdpChromaType chroma_type, gst_vdp_video_buffer_new (GstVdpDevice * device, VdpChromaType chroma_type,
gint width, gint height) gint width, gint height)
@ -293,41 +299,63 @@ gst_vdp_video_buffer_calculate_size (guint32 fourcc, gint width, gint height,
return TRUE; return TRUE;
} }
gboolean GstCaps *
gst_vdp_video_buffer_parse_yuv_caps (GstCaps * yuv_caps, gst_vdp_video_buffer_parse_yuv_caps (GstCaps * yuv_caps)
VdpChromaType * chroma_type, gint * width, gint * height)
{ {
GstStructure *structure;
guint32 fourcc; GstCaps *video_caps;
gint i; gint i;
g_return_val_if_fail (GST_IS_CAPS (yuv_caps), FALSE); g_return_val_if_fail (GST_IS_CAPS (yuv_caps), NULL);
g_return_val_if_fail (!gst_caps_is_empty (yuv_caps), FALSE);
g_return_val_if_fail (chroma_type, FALSE);
g_return_val_if_fail (width, FALSE);
g_return_val_if_fail (height, FALSE);
structure = gst_caps_get_structure (yuv_caps, 0); video_caps = gst_caps_copy (yuv_caps);
for (i = 0; i < gst_caps_get_size (video_caps); i++) {
GstStructure *structure;
guint32 fourcc;
VdpChromaType chroma_type;
structure = gst_caps_get_structure (video_caps, i);
if (!gst_structure_has_name (structure, "video/x-raw-yuv")) if (!gst_structure_has_name (structure, "video/x-raw-yuv"))
return FALSE; goto not_yuv_error;
if (!gst_structure_get_fourcc (structure, "format", &fourcc) || if (!gst_structure_get_fourcc (structure, "format", &fourcc))
!gst_structure_get_int (structure, "width", width) || goto no_format_error;
!gst_structure_get_int (structure, "height", height))
return FALSE;
*chroma_type = -1; chroma_type = -1;
for (i = 0; i < G_N_ELEMENTS (formats); i++) { for (i = 0; i < G_N_ELEMENTS (formats); i++) {
if (formats[i].fourcc == fourcc) { if (formats[i].fourcc == fourcc) {
*chroma_type = formats[i].chroma_type; chroma_type = formats[i].chroma_type;
break; break;
} }
} }
if (*chroma_type == -1) if (chroma_type == -1)
return FALSE; goto no_chroma_error;
/* now we transform the caps */
gst_structure_set_name (structure, "video/x-vdpau-video");
gst_structure_remove_field (structure, "format");
gst_structure_set (structure, "chroma-type", G_TYPE_INT, chroma_type, NULL);
}
return video_caps;
error:
gst_caps_unref (video_caps);
return NULL;
not_yuv_error:
GST_WARNING ("The caps weren't of type \"video/x-raw-yuv\"");
goto error;
no_format_error:
GST_WARNING ("The caps didn't have a \"fourcc\" field");
goto error;
no_chroma_error:
GST_WARNING ("The caps had an invalid \"fourcc\" field");
goto error;
return TRUE;
} }
gboolean gboolean

View file

@ -99,7 +99,7 @@ GstCaps *gst_vdp_video_buffer_get_caps (gboolean filter, VdpChromaType chroma_ty
GstCaps *gst_vdp_video_buffer_get_allowed_yuv_caps (GstVdpDevice * device); GstCaps *gst_vdp_video_buffer_get_allowed_yuv_caps (GstVdpDevice * device);
GstCaps *gst_vdp_video_buffer_get_allowed_video_caps (GstVdpDevice * device); GstCaps *gst_vdp_video_buffer_get_allowed_video_caps (GstVdpDevice * device);
gboolean gst_vdp_video_buffer_parse_yuv_caps (GstCaps *yuv_caps, VdpChromaType *chroma_type, gint *width, gint *height); GstCaps *gst_vdp_video_buffer_parse_yuv_caps (GstCaps *yuv_caps);
gboolean gst_vdp_video_buffer_calculate_size (guint32 fourcc, gint width, gint height, guint *size); gboolean gst_vdp_video_buffer_calculate_size (guint32 fourcc, gint width, gint height, guint *size);
gboolean gst_vdp_video_buffer_download (GstVdpVideoBuffer *inbuf, GstBuffer *outbuf, guint32 fourcc, gint width, gint height); gboolean gst_vdp_video_buffer_download (GstVdpVideoBuffer *inbuf, GstBuffer *outbuf, guint32 fourcc, gint width, gint height);

View file

@ -113,9 +113,13 @@ gst_vdp_video_src_pad_push (GstVdpVideoSrcPad * vdp_pad,
GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS); GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS);
gst_buffer_unref (GST_BUFFER_CAST (video_buf)); gst_buffer_unref (GST_BUFFER_CAST (video_buf));
} else } else
out_buf = GST_BUFFER (video_buf); out_buf = GST_BUFFER_CAST (video_buf);
gst_buffer_set_caps (out_buf, GST_PAD_CAPS (vdp_pad)); /* FIXME: can't use gst_buffer_set_caps since we may have additional
* references to the bufffer. We can't either use
* gst_buffer_make_metadata_writable since that creates a regular buffer and
* not a GstVdpVideoBuffer */
gst_caps_replace (&(GST_BUFFER_CAPS (out_buf)), GST_PAD_CAPS (vdp_pad));
return gst_pad_push (pad, out_buf); return gst_pad_push (pad, out_buf);
} }

View file

@ -49,7 +49,7 @@ GstCaps *gst_vdp_video_src_pad_get_template_caps ();
GstVdpVideoSrcPad * gst_vdp_video_src_pad_new (GstPadTemplate * templ, const gchar * name); GstVdpVideoSrcPad * gst_vdp_video_src_pad_new (GstPadTemplate * templ, const gchar * name);
GType gst_vdp_video_src_pad_get_type (void) G_GNUC_CONST; GType gst_vdp_video_src_pad_get_type (void);
G_END_DECLS G_END_DECLS