diff options
-rw-r--r-- | sys/vdpau/Makefile.am | 6 | ||||
-rw-r--r-- | sys/vdpau/gstvdpmpegdec.c | 232 | ||||
-rw-r--r-- | sys/vdpau/gstvdpmpegdec.h | 12 | ||||
-rw-r--r-- | sys/vdpau/gstvdpvideobuffer.c | 34 | ||||
-rw-r--r-- | sys/vdpau/gstvdpvideobuffer.h | 4 | ||||
-rw-r--r-- | sys/vdpau/gstvdpvideosrcpad.c | 321 | ||||
-rw-r--r-- | sys/vdpau/gstvdpvideosrcpad.h | 73 |
7 files changed, 448 insertions, 234 deletions
diff --git a/sys/vdpau/Makefile.am b/sys/vdpau/Makefile.am index fbc841375..ad0b105e4 100644 --- a/sys/vdpau/Makefile.am +++ b/sys/vdpau/Makefile.am @@ -27,13 +27,15 @@ lib_LTLIBRARIES = libgstvdp-@GST_MAJORMINOR@.la libgstvdp_@GST_MAJORMINOR@_la_SOURCES = \ gstvdpdevice.c \ gstvdpvideobuffer.c \ - gstvdpoutputbuffer.c + gstvdpoutputbuffer.c \ + gstvdpvideosrcpad.c libgstvdp_@GST_MAJORMINOR@includedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/vdpau libgstvdp_@GST_MAJORMINOR@include_HEADERS = \ gstvdpdevice.h \ gstvdpvideobuffer.h \ - gstvdpoutputbuffer.h + gstvdpoutputbuffer.h \ + gstvdpvideosrcpad.h libgstvdp_@GST_MAJORMINOR@_la_CFLAGS = $(GST_CFLAGS) $(VDPAU_CFLAGS) $(X11_CFLAGS) libgstvdp_@GST_MAJORMINOR@_la_LIBADD = $(GST_LIBS) $(VDPAU_LIBS) $(X11_LIBS) -lgstvideo-$(GST_MAJORMINOR) diff --git a/sys/vdpau/gstvdpmpegdec.c b/sys/vdpau/gstvdpmpegdec.c index c6d1cd0ec..3e9f63c18 100644 --- a/sys/vdpau/gstvdpmpegdec.c +++ b/sys/vdpau/gstvdpmpegdec.c @@ -41,7 +41,7 @@ #include <string.h> #include "mpegutil.h" -#include "gstvdputils.h" +#include "gstvdpvideosrcpad.h" #include "gstvdpvideobuffer.h" #include "gstvdpmpegdec.h" @@ -172,12 +172,12 @@ gst_vdp_mpeg_dec_set_caps (GstPad * pad, GstCaps * caps) gst_pad_fixate_caps (mpeg_dec->src, src_caps); structure = gst_caps_get_structure (src_caps, 0); - mpeg_dec->yuv_output = gst_structure_has_name (structure, "video/x-raw-yuv"); GST_DEBUG_OBJECT (mpeg_dec, "Setting source caps to %" GST_PTR_FORMAT, src_caps); - res = gst_pad_set_caps (mpeg_dec->src, src_caps); + res = gst_vdp_video_src_pad_set_caps + (GST_VDP_VIDEO_SRC_PAD (mpeg_dec->src), src_caps); gst_caps_unref (src_caps); if (!res) goto done; @@ -258,37 +258,10 @@ error: GstFlowReturn gst_vdp_mpeg_dec_push_video_buffer (GstVdpMpegDec * mpeg_dec, - GstVdpVideoBuffer * buffer) + GstVdpVideoBuffer * buf) { - GstBuffer *buf; - GstFlowReturn ret; gint64 byterate; - if (mpeg_dec->yuv_output) { - GstCaps *caps; - guint size; - - caps = GST_PAD_CAPS (mpeg_dec->src); - if (!gst_vdp_video_buffer_calculate_size (caps, &size)) - goto size_error; - - ret = gst_pad_alloc_buffer (mpeg_dec->src, GST_BUFFER_OFFSET_NONE, size, - caps, &buf); - if (ret != GST_FLOW_OK) - goto error; - - if (!gst_caps_is_equal_fixed (caps, GST_BUFFER_CAPS (buf))) - goto wrong_caps; - - if (!gst_vdp_video_buffer_download (buffer, buf, caps)) - goto download_error; - - gst_buffer_copy_metadata (buf, (const GstBuffer *) buffer, - GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS); - gst_buffer_unref (GST_BUFFER (buffer)); - } else - buf = GST_BUFFER (buffer); - if (GST_BUFFER_TIMESTAMP (buf) == GST_CLOCK_TIME_NONE && GST_CLOCK_TIME_IS_VALID (mpeg_dec->next_timestamp)) { GST_BUFFER_TIMESTAMP (buf) = mpeg_dec->next_timestamp; @@ -325,87 +298,31 @@ gst_vdp_mpeg_dec_push_video_buffer (GstVdpMpegDec * mpeg_dec, mpeg_dec->byterate = (mpeg_dec->byterate + byterate) / 2; } - gst_buffer_set_caps (buf, GST_PAD_CAPS (mpeg_dec->src)); - GST_DEBUG_OBJECT (mpeg_dec, "Pushing buffer with timestamp: %" GST_TIME_FORMAT " frame_nr: %" G_GINT64_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), - GST_BUFFER_OFFSET (buffer)); - - return gst_pad_push (mpeg_dec->src, buf); - -size_error: - GST_ELEMENT_ERROR (mpeg_dec, STREAM, FAILED, - ("Couldn't calculate buffer size for caps"), (NULL)); - ret = GST_FLOW_ERROR; - goto error; - -wrong_caps: - GST_ELEMENT_ERROR (mpeg_dec, STREAM, FAILED, - ("Sink element returned buffer with wrong caps"), (NULL)); - ret = GST_FLOW_ERROR; - goto error; - -download_error: - GST_ELEMENT_ERROR (mpeg_dec, RESOURCE, READ, - ("Couldn't convert from GstVdpVideoBuffer to the requested format"), - (NULL)); - ret = GST_FLOW_ERROR; - goto error; + GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), GST_BUFFER_OFFSET (buf)); -error: - gst_buffer_unref (GST_BUFFER (buffer)); - return ret; + return gst_vdp_video_src_pad_push ((GstVdpVideoSrcPad *) mpeg_dec->src, buf); } static GstFlowReturn -gst_vdp_mpeg_dec_alloc_buffer (GstVdpMpegDec * mpeg_dec, GstBuffer ** outbuf) +gst_vdp_mpeg_dec_alloc_buffer (GstVdpMpegDec * mpeg_dec, + GstVdpVideoBuffer ** outbuf) { - GstCaps *caps; + GstVdpVideoSrcPad *vdp_pad; GstFlowReturn ret = GST_FLOW_OK; - caps = GST_PAD_CAPS (mpeg_dec->src); - - if (mpeg_dec->yuv_output) { - GstVdpDevice *device; - GstStructure *structure; - gint width, height; - - if (G_UNLIKELY (!mpeg_dec->device)) { - mpeg_dec->device = gst_vdp_get_device (mpeg_dec->display); - if (G_UNLIKELY (!mpeg_dec->device)) - goto device_error; - } - device = mpeg_dec->device; - - structure = gst_caps_get_structure (caps, 0); - if (!gst_structure_get_int (structure, "width", &width)) - goto invalid_caps; - if (!gst_structure_get_int (structure, "height", &height)) - goto invalid_caps; - - *outbuf = (GstBuffer *) gst_vdp_video_buffer_new (device, - VDP_CHROMA_TYPE_420, width, height); - if (!*outbuf) - goto video_buffer_error; - } else { - ret = gst_pad_alloc_buffer (mpeg_dec->src, 0, 0, caps, outbuf); - if (ret != GST_FLOW_OK) - goto done; - - if (!gst_caps_is_equal_fixed (caps, GST_BUFFER_CAPS (*outbuf))) - goto wrong_caps; - - if (G_UNLIKELY (!mpeg_dec->device)) - mpeg_dec->device = g_object_ref (GST_VDP_VIDEO_BUFFER (*outbuf)->device); - } + vdp_pad = (GstVdpVideoSrcPad *) mpeg_dec->src; + ret = gst_vdp_video_src_pad_alloc_buffer (vdp_pad, outbuf); + if (ret != GST_FLOW_OK) + return ret; if (mpeg_dec->decoder == VDP_INVALID_HANDLE) { GstVdpDevice *device; VdpStatus status; - device = mpeg_dec->device; + device = GST_VDP_VIDEO_BUFFER (*outbuf)->device; status = device->vdp_decoder_create (device->device, mpeg_dec->profile, mpeg_dec->width, mpeg_dec->height, 2, &mpeg_dec->decoder); @@ -414,42 +331,12 @@ gst_vdp_mpeg_dec_alloc_buffer (GstVdpMpegDec * mpeg_dec, GstBuffer ** outbuf) ("Could not create vdpau decoder"), ("Error returned from vdpau was: %s", device->vdp_get_error_string (status))); - goto decoder_error; + gst_buffer_unref (GST_BUFFER_CAST (*outbuf)); + return GST_FLOW_ERROR; } } -done: - return ret; - -device_error: - GST_ELEMENT_ERROR (mpeg_dec, RESOURCE, OPEN_READ, - ("Couldn't create GstVdpDevice"), (NULL)); - ret = GST_FLOW_ERROR; - goto done; - -video_buffer_error: - GST_ELEMENT_ERROR (mpeg_dec, RESOURCE, READ, - ("Couldn't create GstVdpVideoBuffer"), (NULL)); - ret = GST_FLOW_ERROR; - goto done; - -invalid_caps: - GST_ELEMENT_ERROR (mpeg_dec, STREAM, FAILED, ("Invalid caps"), (NULL)); - ret = GST_FLOW_ERROR; - goto done; - -wrong_caps: - GST_ELEMENT_ERROR (mpeg_dec, STREAM, FAILED, - ("Sink element returned buffer with wrong caps"), (NULL)); - ret = GST_FLOW_ERROR; - gst_buffer_unref (*outbuf); - goto done; - -decoder_error: - ret = GST_FLOW_ERROR; - gst_buffer_unref (*outbuf); - goto done; - + return GST_FLOW_OK; } static GstFlowReturn @@ -458,7 +345,7 @@ gst_vdp_mpeg_dec_decode (GstVdpMpegDec * mpeg_dec, { VdpPictureInfoMPEG1Or2 *info; GstBuffer *buffer; - GstBuffer *outbuf; + GstVdpVideoBuffer *outbuf; VdpVideoSurface surface; GstVdpDevice *device; VdpBitstreamBuffer vbit[1]; @@ -468,13 +355,12 @@ gst_vdp_mpeg_dec_decode (GstVdpMpegDec * mpeg_dec, if (info->picture_coding_type != B_FRAME) { if (info->backward_reference != VDP_INVALID_HANDLE) { - gst_buffer_ref (mpeg_dec->b_buffer); - gst_vdp_mpeg_dec_push_video_buffer (mpeg_dec, - GST_VDP_VIDEO_BUFFER (mpeg_dec->b_buffer)); + gst_buffer_ref (GST_BUFFER_CAST (mpeg_dec->b_buffer)); + gst_vdp_mpeg_dec_push_video_buffer (mpeg_dec, mpeg_dec->b_buffer); } if (info->forward_reference != VDP_INVALID_HANDLE) { - gst_buffer_unref (mpeg_dec->f_buffer); + gst_buffer_unref (GST_BUFFER_CAST (mpeg_dec->f_buffer)); info->forward_reference = VDP_INVALID_HANDLE; } @@ -526,17 +412,16 @@ gst_vdp_mpeg_dec_decode (GstVdpMpegDec * mpeg_dec, ("Error returned from vdpau was: %s", device->vdp_get_error_string (status))); - gst_buffer_unref (GST_BUFFER (outbuf)); + gst_buffer_unref (GST_BUFFER_CAST (outbuf)); return GST_FLOW_ERROR; } if (info->picture_coding_type == B_FRAME) { - gst_vdp_mpeg_dec_push_video_buffer (mpeg_dec, - GST_VDP_VIDEO_BUFFER (outbuf)); + gst_vdp_mpeg_dec_push_video_buffer (mpeg_dec, outbuf); } else { info->backward_reference = surface; - mpeg_dec->b_buffer = GST_BUFFER (outbuf); + mpeg_dec->b_buffer = outbuf; } return GST_FLOW_OK; @@ -692,9 +577,9 @@ static void gst_vdp_mpeg_dec_flush (GstVdpMpegDec * mpeg_dec) { if (mpeg_dec->vdp_info.forward_reference != VDP_INVALID_HANDLE) - gst_buffer_unref (mpeg_dec->f_buffer); + gst_buffer_unref (GST_BUFFER_CAST (mpeg_dec->f_buffer)); if (mpeg_dec->vdp_info.backward_reference != VDP_INVALID_HANDLE) - gst_buffer_unref (mpeg_dec->b_buffer); + gst_buffer_unref (GST_BUFFER_CAST (mpeg_dec->b_buffer)); gst_adapter_clear (mpeg_dec->adapter); @@ -707,7 +592,6 @@ gst_vdp_mpeg_dec_start (GstVdpMpegDec * mpeg_dec) { gst_vdp_mpeg_dec_init_info (&mpeg_dec->vdp_info); - mpeg_dec->device = NULL; mpeg_dec->decoder = VDP_INVALID_HANDLE; mpeg_dec->state = GST_VDP_MPEG_DEC_NEED_SEQUENCE; @@ -722,11 +606,13 @@ gst_vdp_mpeg_dec_start (GstVdpMpegDec * mpeg_dec) static void gst_vdp_mpeg_dec_stop (GstVdpMpegDec * mpeg_dec) { - if (mpeg_dec->device) { - if (mpeg_dec->decoder != VDP_INVALID_HANDLE) - mpeg_dec->device->vdp_decoder_destroy (mpeg_dec->decoder); + GstVdpDevice *device; - g_object_unref (mpeg_dec->device); + if ((device = + gst_vdp_video_src_pad_get_device (GST_VDP_VIDEO_SRC_PAD + (mpeg_dec->src)))) { + if (mpeg_dec->decoder != VDP_INVALID_HANDLE) + device->vdp_decoder_destroy (mpeg_dec->decoder); } if (mpeg_dec->vdp_info.forward_reference != VDP_INVALID_HANDLE) @@ -833,31 +719,6 @@ done: return ret; } -static GstCaps * -gst_vdp_mpeg_dec_src_getcaps (GstPad * pad) -{ - GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (gst_pad_get_parent (pad)); - GstElementClass *eclass = GST_ELEMENT_GET_CLASS (mpeg_dec); - GstCaps *caps, *templ_caps; - - templ_caps = - gst_pad_template_get_caps (gst_element_class_get_pad_template (eclass, - "src")); - - if (mpeg_dec->device) { - GstCaps *yuv_caps, *video_caps; - - video_caps = gst_vdp_video_buffer_get_allowed_video_caps (mpeg_dec->device); - yuv_caps = gst_vdp_video_buffer_get_allowed_yuv_caps (mpeg_dec->device); - gst_caps_append (video_caps, yuv_caps); - caps = gst_caps_intersect (video_caps, templ_caps); - gst_caps_unref (video_caps); - } else - caps = gst_caps_copy (templ_caps); - - return caps; -} - static gboolean gst_vdp_mpeg_dec_convert (GstVdpMpegDec * mpeg_dec, GstFormat src_format, gint64 src_value, @@ -1175,33 +1036,33 @@ gst_vdp_mpeg_dec_finalize (GObject * object) } static void -gst_vdp_mpeg_dec_get_property (GObject * object, guint property_id, +gst_vdp_mpeg_dec_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { GstVdpMpegDec *mpeg_dec = (GstVdpMpegDec *) object; - switch (property_id) { + switch (prop_id) { case PROP_DISPLAY: - g_value_set_string (value, mpeg_dec->display); + g_object_get_property (G_OBJECT (mpeg_dec->src), "display", value); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void -gst_vdp_mpeg_dec_set_property (GObject * object, guint property_id, +gst_vdp_mpeg_dec_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstVdpMpegDec *mpeg_dec = (GstVdpMpegDec *) object; - switch (property_id) { + switch (prop_id) { case PROP_DISPLAY: - mpeg_dec->display = g_value_dup_string (value); + g_object_set_property (G_OBJECT (mpeg_dec->src), "display", value); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } @@ -1211,7 +1072,6 @@ gst_vdp_mpeg_dec_base_init (gpointer gclass) { GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); - GstCaps *caps; GstPadTemplate *src_template; gst_element_class_set_details_simple (element_class, @@ -1224,9 +1084,7 @@ gst_vdp_mpeg_dec_base_init (gpointer gclass) gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&sink_template)); - caps = gst_vdp_video_buffer_get_caps (TRUE, VDP_CHROMA_TYPE_420); - src_template = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, - caps); + src_template = gst_vdp_video_src_pad_get_pad_template (); gst_element_class_add_pad_template (element_class, src_template); } @@ -1271,11 +1129,7 @@ gst_vdp_mpeg_dec_init_info (VdpPictureInfoMPEG1Or2 * vdp_info) static void gst_vdp_mpeg_dec_init (GstVdpMpegDec * mpeg_dec, GstVdpMpegDecClass * gclass) { - mpeg_dec->src = - gst_pad_new_from_template (gst_element_class_get_pad_template - (GST_ELEMENT_CLASS (gclass), "src"), "src"); - gst_pad_set_getcaps_function (mpeg_dec->src, - GST_DEBUG_FUNCPTR (gst_vdp_mpeg_dec_src_getcaps)); + mpeg_dec->src = GST_PAD (gst_vdp_video_src_pad_new ()); gst_pad_set_event_function (mpeg_dec->src, GST_DEBUG_FUNCPTR (gst_vdp_mpeg_dec_src_event)); gst_pad_set_query_function (mpeg_dec->src, @@ -1293,8 +1147,6 @@ gst_vdp_mpeg_dec_init (GstVdpMpegDec * mpeg_dec, GstVdpMpegDecClass * gclass) GST_DEBUG_FUNCPTR (gst_vdp_mpeg_dec_sink_event)); gst_element_add_pad (GST_ELEMENT (mpeg_dec), mpeg_dec->sink); - mpeg_dec->display = NULL; - mpeg_dec->adapter = gst_adapter_new (); mpeg_dec->mutex = g_mutex_new (); } diff --git a/sys/vdpau/gstvdpmpegdec.h b/sys/vdpau/gstvdpmpegdec.h index 6fb7f18fe..1e57f26ba 100644 --- a/sys/vdpau/gstvdpmpegdec.h +++ b/sys/vdpau/gstvdpmpegdec.h @@ -24,7 +24,7 @@ #include <gst/gst.h> #include <gst/base/gstadapter.h> -#include "gstvdpdevice.h" +#include "gstvdpvideobuffer.h" G_BEGIN_DECLS @@ -51,12 +51,6 @@ struct _GstVdpMpegDec GstPad *src; GstPad *sink; - /* properties */ - gchar *display; - - gboolean yuv_output; - - GstVdpDevice *device; VdpDecoderProfile profile; VdpDecoder decoder; @@ -79,8 +73,8 @@ struct _GstVdpMpegDec guint64 gop_frame; /* forward and backward reference */ - GstBuffer *f_buffer; - GstBuffer *b_buffer; + GstVdpVideoBuffer *f_buffer; + GstVdpVideoBuffer *b_buffer; /* calculated timestamp, size and duration */ GstClockTime next_timestamp; diff --git a/sys/vdpau/gstvdpvideobuffer.c b/sys/vdpau/gstvdpvideobuffer.c index ae4bd0bf2..6a6ea7075 100644 --- a/sys/vdpau/gstvdpvideobuffer.c +++ b/sys/vdpau/gstvdpvideobuffer.c @@ -257,22 +257,9 @@ error: } gboolean -gst_vdp_video_buffer_calculate_size (GstCaps * caps, guint * size) +gst_vdp_video_buffer_calculate_size (guint32 fourcc, gint width, gint height, + guint * size) { - GstStructure *structure; - gint width, height; - guint fourcc; - - structure = gst_caps_get_structure (caps, 0); - - if (!gst_structure_get_int (structure, "width", &width)) - return FALSE; - if (!gst_structure_get_int (structure, "height", &height)) - return FALSE; - - if (!gst_structure_get_fourcc (structure, "format", &fourcc)) - return FALSE; - switch (fourcc) { case GST_MAKE_FOURCC ('Y', 'V', '1', '2'): { @@ -345,11 +332,8 @@ gst_vdp_video_buffer_parse_yuv_caps (GstCaps * yuv_caps, gboolean gst_vdp_video_buffer_download (GstVdpVideoBuffer * video_buf, - GstBuffer * outbuf, GstCaps * outcaps) + GstBuffer * outbuf, guint32 fourcc, gint width, gint height) { - GstStructure *structure; - gint width, height; - guint fourcc; guint8 *data[3]; guint32 stride[3]; @@ -360,18 +344,6 @@ gst_vdp_video_buffer_download (GstVdpVideoBuffer * video_buf, g_return_val_if_fail (GST_IS_VDP_VIDEO_BUFFER (video_buf), FALSE); g_return_val_if_fail (GST_IS_BUFFER (outbuf), FALSE); - g_return_val_if_fail (GST_IS_CAPS (outcaps), FALSE); - - structure = gst_caps_get_structure (outcaps, 0); - - if (!gst_structure_get_int (structure, "width", &width)) - return FALSE; - if (!gst_structure_get_int (structure, "height", &height)) - return FALSE; - - structure = gst_caps_get_structure (outcaps, 0); - if (!gst_structure_get_fourcc (structure, "format", &fourcc)) - return FALSE; switch (fourcc) { case GST_MAKE_FOURCC ('Y', 'V', '1', '2'): diff --git a/sys/vdpau/gstvdpvideobuffer.h b/sys/vdpau/gstvdpvideobuffer.h index d528b6d32..d99237bdc 100644 --- a/sys/vdpau/gstvdpvideobuffer.h +++ b/sys/vdpau/gstvdpvideobuffer.h @@ -101,8 +101,8 @@ 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); -gboolean gst_vdp_video_buffer_calculate_size (GstCaps *caps, guint *size); -gboolean gst_vdp_video_buffer_download (GstVdpVideoBuffer *inbuf, GstBuffer *outbuf, GstCaps *outcaps); +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_upload (GstVdpVideoBuffer *video_buf, GstBuffer *src_buf, guint fourcc, gint width, gint height); #define GST_VDP_VIDEO_CAPS \ diff --git a/sys/vdpau/gstvdpvideosrcpad.c b/sys/vdpau/gstvdpvideosrcpad.c new file mode 100644 index 000000000..f26dd5a54 --- /dev/null +++ b/sys/vdpau/gstvdpvideosrcpad.c @@ -0,0 +1,321 @@ +/* + * 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 "gstvdpvideobuffer.h" + +#include "gstvdpvideosrcpad.h" + +enum +{ + PROP_0, + PROP_DISPLAY +}; + +G_DEFINE_TYPE (GstVdpVideoSrcPad, gst_vdp_video_src_pad, GST_TYPE_PAD); + +GstFlowReturn +gst_vdp_video_src_pad_push (GstVdpVideoSrcPad * vdp_pad, + GstVdpVideoBuffer * video_buf) +{ + GstPad *pad; + GstBuffer *out_buf; + + g_return_val_if_fail (GST_IS_VDP_VIDEO_SRC_PAD (vdp_pad), GST_FLOW_ERROR); + g_return_val_if_fail (GST_IS_VDP_VIDEO_BUFFER (video_buf), GST_FLOW_ERROR); + + pad = (GstPad *) vdp_pad; + + if (G_UNLIKELY (!GST_PAD_CAPS (pad))) + return GST_FLOW_NOT_NEGOTIATED; + + if (vdp_pad->yuv_output) { + guint size; + GstFlowReturn ret; + GstCaps *caps; + + if (!gst_vdp_video_buffer_calculate_size (vdp_pad->fourcc, vdp_pad->width, + vdp_pad->height, &size)) { + GST_ERROR_OBJECT (vdp_pad, "Couldn't calculate buffer size for caps"); + gst_buffer_unref (GST_BUFFER_CAST (video_buf)); + return GST_FLOW_ERROR; + } + + caps = GST_PAD_CAPS (pad); + ret = gst_pad_alloc_buffer (pad, + GST_BUFFER_OFFSET_NONE, size, caps, &out_buf); + if (ret != GST_FLOW_OK) { + gst_buffer_unref (GST_BUFFER_CAST (video_buf)); + return ret; + } + + if (!gst_caps_is_equal_fixed (caps, GST_BUFFER_CAPS (out_buf))) { + GST_ERROR_OBJECT (vdp_pad, "Couldn't calculate buffer size for caps"); + gst_buffer_unref (GST_BUFFER_CAST (video_buf)); + return GST_FLOW_ERROR; + } + + if (!gst_vdp_video_buffer_download (video_buf, out_buf, vdp_pad->fourcc, + vdp_pad->width, vdp_pad->height)) { + GST_ERROR_OBJECT (vdp_pad, + "Couldn't convert from GstVdpVideoBuffer to the requested format"); + gst_buffer_unref (GST_BUFFER_CAST (video_buf)); + gst_buffer_unref (GST_BUFFER_CAST (out_buf)); + } + + gst_buffer_copy_metadata (out_buf, (const GstBuffer *) video_buf, + GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS); + gst_buffer_unref (GST_BUFFER_CAST (video_buf)); + } else + out_buf = GST_BUFFER (video_buf); + + gst_buffer_set_caps (out_buf, GST_PAD_CAPS (vdp_pad)); + + return gst_pad_push (pad, out_buf); +} + +GstFlowReturn +gst_vdp_video_src_pad_alloc_buffer (GstVdpVideoSrcPad * vdp_pad, + GstVdpVideoBuffer ** video_buf) +{ + GstCaps *caps; + GstFlowReturn ret; + + g_return_val_if_fail (GST_IS_VDP_VIDEO_SRC_PAD (vdp_pad), GST_FLOW_ERROR); + + caps = GST_PAD_CAPS (vdp_pad); + if (!caps) + return GST_FLOW_NOT_NEGOTIATED; + + if (vdp_pad->yuv_output) { + GstVdpDevice *device; + + if (G_UNLIKELY (!vdp_pad->device)) { + vdp_pad->device = gst_vdp_get_device (vdp_pad->display); + if (G_UNLIKELY (!vdp_pad->device)) + goto device_error; + } + device = vdp_pad->device; + + *video_buf = gst_vdp_video_buffer_new (device, VDP_CHROMA_TYPE_420, + vdp_pad->width, vdp_pad->height); + if (!*video_buf) + goto video_buffer_error; + } else { + ret = gst_pad_alloc_buffer ((GstPad *) vdp_pad, 0, 0, caps, + (GstBuffer **) video_buf); + if (ret != GST_FLOW_OK) + return ret; + + if (!gst_caps_is_equal_fixed (caps, GST_BUFFER_CAPS (*video_buf))) + goto wrong_caps; + + if (G_UNLIKELY (!vdp_pad->device)) + vdp_pad->device = + g_object_ref (GST_VDP_VIDEO_BUFFER (*video_buf)->device); + } + + return GST_FLOW_OK; + +device_error: + GST_ERROR_OBJECT (vdp_pad, "Couldn't create GstVdpDevice"); + return GST_FLOW_ERROR; + +video_buffer_error: + GST_ERROR_OBJECT (vdp_pad, "Couldn't create GstVdpVideoBuffer"); + return GST_FLOW_ERROR; + +wrong_caps: + GST_ERROR_OBJECT (vdp_pad, "Sink element returned buffer with wrong caps"); + gst_buffer_unref (GST_BUFFER_CAST (*video_buf)); + return GST_FLOW_ERROR; +} + +gboolean +gst_vdp_video_src_pad_set_caps (GstVdpVideoSrcPad * vdp_pad, GstCaps * caps) +{ + const GstStructure *structure; + + g_return_val_if_fail (GST_IS_VDP_VIDEO_SRC_PAD (vdp_pad), FALSE); + + if (G_UNLIKELY (!caps)) + return gst_pad_set_caps (GST_PAD (vdp_pad), caps); + + if (G_UNLIKELY (!GST_IS_CAPS (caps) || !gst_caps_is_fixed (caps))) + return FALSE; + + structure = gst_caps_get_structure (caps, 0); + if (gst_structure_has_name (structure, "video/x-raw-yuv")) { + if (!gst_structure_get_int (structure, "width", &vdp_pad->width)) + return FALSE; + if (!gst_structure_get_int (structure, "height", &vdp_pad->height)) + return FALSE; + if (!gst_structure_get_fourcc (structure, "format", &vdp_pad->fourcc)) + return FALSE; + + vdp_pad->yuv_output = TRUE; + } else if (gst_structure_has_name (structure, "video/x-vdpau-video")) { + if (!gst_structure_get_int (structure, "width", &vdp_pad->width)) + return FALSE; + if (!gst_structure_get_int (structure, "height", &vdp_pad->height)) + return FALSE; + + vdp_pad->yuv_output = FALSE; + } else + return FALSE; + + return gst_pad_set_caps (GST_PAD (vdp_pad), caps); +} + +GstVdpDevice * +gst_vdp_video_src_pad_get_device (GstVdpVideoSrcPad * vdp_pad) +{ + g_return_val_if_fail (GST_IS_VDP_VIDEO_SRC_PAD (vdp_pad), FALSE); + + return vdp_pad->device; +} + +GstPadTemplate * +gst_vdp_video_src_pad_get_pad_template () +{ + GstCaps *caps; + GstPadTemplate *src_template; + + caps = gst_vdp_video_buffer_get_caps (TRUE, VDP_CHROMA_TYPE_420); + src_template = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, + caps); + + return src_template; +} + +static GstCaps * +gst_vdp_video_src_pad_getcaps (GstPad * pad) +{ + GstVdpVideoSrcPad *vdp_pad = (GstVdpVideoSrcPad *) pad; + GstCaps *templ_caps, *caps; + + templ_caps = gst_vdp_video_buffer_get_caps (TRUE, VDP_CHROMA_TYPE_420); + + if (vdp_pad->device) { + GstCaps *yuv_caps, *video_caps; + + video_caps = gst_vdp_video_buffer_get_allowed_video_caps (vdp_pad->device); + yuv_caps = gst_vdp_video_buffer_get_allowed_yuv_caps (vdp_pad->device); + gst_caps_append (video_caps, yuv_caps); + caps = gst_caps_intersect (video_caps, templ_caps); + + gst_caps_unref (templ_caps); + gst_caps_unref (video_caps); + } else + caps = templ_caps; + + return caps; +} + +static gboolean +gst_vdp_video_src_pad_activate_push (GstPad * pad, gboolean active) +{ + GstVdpVideoSrcPad *vdp_pad = GST_VDP_VIDEO_SRC_PAD (pad); + + if (!active) { + if (vdp_pad->device) + g_object_unref (vdp_pad->device); + vdp_pad->device = NULL; + } + + return TRUE; +} + +GstVdpVideoSrcPad * +gst_vdp_video_src_pad_new () +{ + return g_object_new (GST_TYPE_VDP_VIDEO_SRC_PAD, "direction", GST_PAD_SRC, + NULL); +} + +static void +gst_vdp_video_src_pad_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + GstVdpVideoSrcPad *vdp_pad = (GstVdpVideoSrcPad *) object; + + switch (prop_id) { + case PROP_DISPLAY: + g_value_set_string (value, vdp_pad->display); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_vdp_video_src_pad_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstVdpVideoSrcPad *vdp_pad = (GstVdpVideoSrcPad *) object; + + switch (prop_id) { + case PROP_DISPLAY: + vdp_pad->display = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_vdp_video_src_pad_finalize (GObject * object) +{ + GstVdpVideoSrcPad *vdp_pad = (GstVdpVideoSrcPad *) object; + + g_free (vdp_pad->display); + + G_OBJECT_CLASS (gst_vdp_video_src_pad_parent_class)->finalize (object); +} + +static void +gst_vdp_video_src_pad_init (GstVdpVideoSrcPad * vdp_pad) +{ + GstPad *pad = GST_PAD (vdp_pad); + + vdp_pad->device = NULL; + vdp_pad->display = NULL; + + gst_pad_set_getcaps_function (pad, + GST_DEBUG_FUNCPTR (gst_vdp_video_src_pad_getcaps)); + gst_pad_set_activatepush_function (pad, + GST_DEBUG_FUNCPTR (gst_vdp_video_src_pad_activate_push)); +} + +static void +gst_vdp_video_src_pad_class_init (GstVdpVideoSrcPadClass * klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = gst_vdp_video_src_pad_get_property; + object_class->set_property = gst_vdp_video_src_pad_set_property; + object_class->finalize = gst_vdp_video_src_pad_finalize; + + g_object_class_install_property (object_class, PROP_DISPLAY, + g_param_spec_string ("display", "Display", "X Display name", + NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + +} diff --git a/sys/vdpau/gstvdpvideosrcpad.h b/sys/vdpau/gstvdpvideosrcpad.h new file mode 100644 index 000000000..eaf2e4690 --- /dev/null +++ b/sys/vdpau/gstvdpvideosrcpad.h @@ -0,0 +1,73 @@ +/* + * 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_VDP_VIDEO_SRC_PAD_H_ +#define _GST_VDP_VIDEO_SRC_PAD_H_ + +#include <gst/gst.h> + +#include "gstvdpdevice.h" +#include "gstvdpvideobuffer.h" + +G_BEGIN_DECLS + +#define GST_TYPE_VDP_VIDEO_SRC_PAD (gst_vdp_video_src_pad_get_type ()) +#define GST_VDP_VIDEO_SRC_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VDP_VIDEO_SRC_PAD, GstVdpVideoSrcPad)) +#define GST_VDP_VIDEO_SRC_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VDP_VIDEO_SRC_PAD, GstVdpVideoSrcPadClass)) +#define GST_IS_VDP_VIDEO_SRC_PAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VDP_VIDEO_SRC_PAD)) +#define GST_IS_VDP_VIDEO_SRC_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VDP_VIDEO_SRC_PAD)) +#define GST_VDP_VIDEO_SRC_PAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_VDP_VIDEO_SRC_PAD, GstVdpVideoSrcPadClass)) + +typedef struct _GstVdpVideoSrcPad GstVdpVideoSrcPad; +typedef struct _GstVdpVideoSrcPadClass GstVdpVideoSrcPadClass; + +struct _GstVdpVideoSrcPad +{ + GstPad pad; + + GstVdpDevice *device; + + gboolean yuv_output; + gint width, height; + guint32 fourcc; + + /* properties */ + gchar *display; +}; + +struct _GstVdpVideoSrcPadClass +{ + GstPadClass pad_class; +}; + +GstFlowReturn gst_vdp_video_src_pad_push (GstVdpVideoSrcPad *vdp_pad, GstVdpVideoBuffer *video_buf); +GstFlowReturn gst_vdp_video_src_pad_alloc_buffer (GstVdpVideoSrcPad *vdp_pad, GstVdpVideoBuffer **video_buf); + +GstVdpDevice *gst_vdp_video_src_pad_get_device (GstVdpVideoSrcPad *vdp_pad); + +gboolean gst_vdp_video_src_pad_set_caps (GstVdpVideoSrcPad *vdp_pad, GstCaps *caps); +GstPadTemplate *gst_vdp_video_src_pad_get_pad_template (); + +GstVdpVideoSrcPad *gst_vdp_video_src_pad_new (); +GType gst_vdp_video_src_pad_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* _GST_VDP_VIDEO_SRC_PAD_H_ */ |