2009-04-07 18:46:49 +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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/video/video.h>
|
|
|
|
|
2009-04-13 20:19:20 +00:00
|
|
|
#include "gstvdpvideobuffer.h"
|
2009-06-22 21:25:55 +00:00
|
|
|
#include "gstvdputils.h"
|
2009-04-13 20:19:20 +00:00
|
|
|
#include "gstvdpyuvvideo.h"
|
2009-04-07 18:46:49 +00:00
|
|
|
|
2009-04-13 20:19:20 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_vdp_yuv_video_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_vdp_yuv_video_debug
|
2009-04-07 18:46:49 +00:00
|
|
|
|
|
|
|
/* Filter signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2009-06-23 21:03:52 +00:00
|
|
|
PROP_0
|
2009-04-07 18:46:49 +00:00
|
|
|
};
|
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
static GstStaticPadTemplate sink_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE (GST_BASE_TRANSFORM_SINK_NAME,
|
2009-04-07 18:46:49 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2009-06-22 20:17:48 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420") ";"
|
2009-06-23 15:16:25 +00:00
|
|
|
GST_VIDEO_CAPS_YUV ("YV12") ";" GST_VIDEO_CAPS_YUV ("NV12") ";"
|
2009-06-23 15:26:22 +00:00
|
|
|
GST_VIDEO_CAPS_YUV ("UYVY") ";" GST_VIDEO_CAPS_YUV ("YUY2")));
|
2009-04-07 18:46:49 +00:00
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
static GstStaticPadTemplate src_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE (GST_BASE_TRANSFORM_SRC_NAME,
|
2009-04-07 18:46:49 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2009-04-26 21:25:33 +00:00
|
|
|
GST_STATIC_CAPS (GST_VDP_VIDEO_CAPS));
|
2009-04-07 18:46:49 +00:00
|
|
|
|
|
|
|
#define DEBUG_INIT(bla) \
|
2009-06-22 20:17:48 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_vdp_yuv_video_debug, "vdpauyuvvideo", 0, "YUV to VDPAU video surface");
|
2009-04-07 18:46:49 +00:00
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
GST_BOILERPLATE_FULL (GstVdpYUVVideo, gst_vdp_yuv_video, GstBaseTransform,
|
|
|
|
GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
|
2009-04-07 18:46:49 +00:00
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vdp_yuv_video_transform_size (GstBaseTransform * trans,
|
|
|
|
GstPadDirection direction, GstCaps * caps, guint size,
|
|
|
|
GstCaps * othercaps, guint * othersize)
|
|
|
|
{
|
|
|
|
*othersize = size;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_vdp_yuv_video_transform (GstBaseTransform * trans, GstBuffer * inbuf,
|
|
|
|
GstBuffer * outbuf)
|
|
|
|
{
|
|
|
|
GstVdpYUVVideo *yuv_video = GST_VDP_YUV_VIDEO (trans);
|
2009-04-13 20:19:20 +00:00
|
|
|
GstVdpDevice *device;
|
2009-04-07 18:46:49 +00:00
|
|
|
VdpVideoSurface surface;
|
|
|
|
|
2009-06-23 21:03:52 +00:00
|
|
|
device = GST_VDP_VIDEO_BUFFER (outbuf)->device;
|
2009-06-24 09:36:28 +00:00
|
|
|
if (!yuv_video->device)
|
|
|
|
yuv_video->device = g_object_ref (device);
|
|
|
|
|
2009-04-26 21:25:33 +00:00
|
|
|
surface = GST_VDP_VIDEO_BUFFER (outbuf)->surface;
|
2009-04-07 18:46:49 +00:00
|
|
|
|
|
|
|
switch (yuv_video->format) {
|
|
|
|
case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
|
|
|
|
{
|
|
|
|
VdpStatus status;
|
|
|
|
guint8 *data[3];
|
|
|
|
guint32 stride[3];
|
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
data[0] = GST_BUFFER_DATA (inbuf) +
|
2009-04-07 18:46:49 +00:00
|
|
|
gst_video_format_get_component_offset (GST_VIDEO_FORMAT_YV12,
|
|
|
|
0, yuv_video->width, yuv_video->height);
|
2009-06-22 20:17:48 +00:00
|
|
|
data[1] = GST_BUFFER_DATA (inbuf) +
|
2009-04-07 18:46:49 +00:00
|
|
|
gst_video_format_get_component_offset (GST_VIDEO_FORMAT_YV12,
|
|
|
|
2, yuv_video->width, yuv_video->height);
|
2009-06-22 20:17:48 +00:00
|
|
|
data[2] = GST_BUFFER_DATA (inbuf) +
|
2009-04-07 18:46:49 +00:00
|
|
|
gst_video_format_get_component_offset (GST_VIDEO_FORMAT_YV12,
|
|
|
|
1, yuv_video->width, yuv_video->height);
|
|
|
|
|
|
|
|
stride[0] = gst_video_format_get_row_stride (GST_VIDEO_FORMAT_YV12,
|
|
|
|
0, yuv_video->width);
|
|
|
|
stride[1] = gst_video_format_get_row_stride (GST_VIDEO_FORMAT_YV12,
|
|
|
|
2, yuv_video->width);
|
|
|
|
stride[2] = gst_video_format_get_row_stride (GST_VIDEO_FORMAT_YV12,
|
|
|
|
1, yuv_video->width);
|
|
|
|
|
|
|
|
status =
|
|
|
|
device->vdp_video_surface_put_bits_ycbcr (surface,
|
|
|
|
VDP_YCBCR_FORMAT_YV12, (void *) data, stride);
|
|
|
|
if (G_UNLIKELY (status != VDP_STATUS_OK)) {
|
|
|
|
GST_ELEMENT_ERROR (yuv_video, RESOURCE, READ,
|
|
|
|
("Couldn't push YV12 data to VDPAU"),
|
|
|
|
("Error returned from vdpau was: %s",
|
|
|
|
device->vdp_get_error_string (status)));
|
2009-06-22 20:17:48 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2009-04-07 18:46:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
|
|
|
|
{
|
|
|
|
VdpStatus status;
|
|
|
|
guint8 *data[3];
|
|
|
|
guint32 stride[3];
|
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
data[0] = GST_BUFFER_DATA (inbuf) +
|
2009-04-07 18:46:49 +00:00
|
|
|
gst_video_format_get_component_offset (GST_VIDEO_FORMAT_I420,
|
|
|
|
0, yuv_video->width, yuv_video->height);
|
2009-06-22 20:17:48 +00:00
|
|
|
data[1] = GST_BUFFER_DATA (inbuf) +
|
2009-04-07 18:46:49 +00:00
|
|
|
gst_video_format_get_component_offset (GST_VIDEO_FORMAT_I420,
|
|
|
|
2, yuv_video->width, yuv_video->height);
|
2009-06-22 20:17:48 +00:00
|
|
|
data[2] = GST_BUFFER_DATA (inbuf) +
|
2009-04-07 18:46:49 +00:00
|
|
|
gst_video_format_get_component_offset (GST_VIDEO_FORMAT_I420,
|
|
|
|
1, yuv_video->width, yuv_video->height);
|
|
|
|
|
|
|
|
stride[0] = gst_video_format_get_row_stride (GST_VIDEO_FORMAT_I420,
|
|
|
|
0, yuv_video->width);
|
|
|
|
stride[1] = gst_video_format_get_row_stride (GST_VIDEO_FORMAT_I420,
|
|
|
|
2, yuv_video->width);
|
|
|
|
stride[2] = gst_video_format_get_row_stride (GST_VIDEO_FORMAT_I420,
|
|
|
|
1, yuv_video->width);
|
|
|
|
|
|
|
|
status =
|
|
|
|
device->vdp_video_surface_put_bits_ycbcr (surface,
|
|
|
|
VDP_YCBCR_FORMAT_YV12, (void *) data, stride);
|
|
|
|
if (G_UNLIKELY (status != VDP_STATUS_OK)) {
|
|
|
|
GST_ELEMENT_ERROR (yuv_video, RESOURCE, READ,
|
|
|
|
("Couldn't push YV12 data to VDPAU"),
|
|
|
|
("Error returned from vdpau was: %s",
|
|
|
|
device->vdp_get_error_string (status)));
|
2009-06-22 20:17:48 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2009-04-07 18:46:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_MAKE_FOURCC ('N', 'V', '1', '2'):
|
|
|
|
{
|
|
|
|
VdpStatus status;
|
|
|
|
guint8 *data[2];
|
|
|
|
guint32 stride[2];
|
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
data[0] = GST_BUFFER_DATA (inbuf);
|
|
|
|
data[1] = GST_BUFFER_DATA (inbuf) + yuv_video->width * yuv_video->height;
|
2009-04-07 18:46:49 +00:00
|
|
|
|
|
|
|
stride[0] = yuv_video->width;
|
|
|
|
stride[1] = yuv_video->width;
|
|
|
|
|
|
|
|
status =
|
|
|
|
device->vdp_video_surface_put_bits_ycbcr (surface,
|
|
|
|
VDP_YCBCR_FORMAT_NV12, (void *) data, stride);
|
|
|
|
if (G_UNLIKELY (status != VDP_STATUS_OK)) {
|
|
|
|
GST_ELEMENT_ERROR (yuv_video, RESOURCE, READ,
|
|
|
|
("Couldn't get data from vdpau"),
|
|
|
|
("Error returned from vdpau was: %s",
|
|
|
|
device->vdp_get_error_string (status)));
|
2009-06-22 20:17:48 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2009-04-07 18:46:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-06-23 15:16:25 +00:00
|
|
|
case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
|
|
|
|
{
|
|
|
|
VdpStatus status;
|
|
|
|
guint8 *data[1];
|
|
|
|
guint32 stride[1];
|
|
|
|
|
|
|
|
data[0] = GST_BUFFER_DATA (inbuf);
|
|
|
|
|
|
|
|
stride[0] = gst_video_format_get_row_stride (GST_VIDEO_FORMAT_UYVY,
|
|
|
|
0, yuv_video->width);
|
|
|
|
|
|
|
|
status =
|
|
|
|
device->vdp_video_surface_put_bits_ycbcr (surface,
|
|
|
|
VDP_YCBCR_FORMAT_UYVY, (void *) data, stride);
|
|
|
|
if (G_UNLIKELY (status != VDP_STATUS_OK)) {
|
|
|
|
GST_ELEMENT_ERROR (yuv_video, RESOURCE, READ,
|
|
|
|
("Couldn't get data from vdpau"),
|
|
|
|
("Error returned from vdpau was: %s",
|
|
|
|
device->vdp_get_error_string (status)));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-06-23 15:26:22 +00:00
|
|
|
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
|
|
|
|
{
|
|
|
|
VdpStatus status;
|
|
|
|
guint8 *data[1];
|
|
|
|
guint32 stride[1];
|
|
|
|
|
|
|
|
data[0] = GST_BUFFER_DATA (inbuf);
|
|
|
|
|
|
|
|
stride[0] = gst_video_format_get_row_stride (GST_VIDEO_FORMAT_YUY2,
|
|
|
|
0, yuv_video->width);
|
|
|
|
|
|
|
|
status =
|
|
|
|
device->vdp_video_surface_put_bits_ycbcr (surface,
|
|
|
|
VDP_YCBCR_FORMAT_YUYV, (void *) data, stride);
|
|
|
|
if (G_UNLIKELY (status != VDP_STATUS_OK)) {
|
|
|
|
GST_ELEMENT_ERROR (yuv_video, RESOURCE, READ,
|
|
|
|
("Couldn't get data from vdpau"),
|
|
|
|
("Error returned from vdpau was: %s",
|
|
|
|
device->vdp_get_error_string (status)));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-04-07 18:46:49 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
gst_buffer_copy_metadata (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS);
|
2009-04-07 18:46:49 +00:00
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
return GST_FLOW_OK;
|
2009-04-07 18:46:49 +00:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vdp_yuv_video_set_caps (GstBaseTransform * trans, GstCaps * incaps,
|
|
|
|
GstCaps * outcaps)
|
2009-04-07 18:46:49 +00:00
|
|
|
{
|
2009-06-22 20:17:48 +00:00
|
|
|
GstVdpYUVVideo *yuv_video = GST_VDP_YUV_VIDEO (trans);
|
|
|
|
GstStructure *structure;
|
2009-04-07 18:46:49 +00:00
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
structure = gst_caps_get_structure (incaps, 0);
|
2009-04-07 18:46:49 +00:00
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
if (!gst_structure_get_int (structure, "width", &yuv_video->width))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_structure_get_int (structure, "height", &yuv_video->height))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_structure_get_fourcc (structure, "format", &yuv_video->format))
|
|
|
|
return FALSE;
|
2009-04-07 18:46:49 +00:00
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-04-07 18:46:49 +00:00
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_vdp_yuv_video_transform_caps (GstBaseTransform * trans,
|
|
|
|
GstPadDirection direction, GstCaps * caps)
|
|
|
|
{
|
2009-06-24 09:36:28 +00:00
|
|
|
GstVdpYUVVideo *yuv_video = GST_VDP_YUV_VIDEO (trans);
|
2009-06-23 14:57:45 +00:00
|
|
|
GstCaps *result;
|
2009-06-22 20:17:48 +00:00
|
|
|
|
|
|
|
if (direction == GST_PAD_SINK) {
|
2009-06-24 09:36:28 +00:00
|
|
|
result = gst_vdp_yuv_to_video_caps (caps, yuv_video->device);
|
2009-06-22 20:17:48 +00:00
|
|
|
} else if (direction == GST_PAD_SRC) {
|
2009-06-24 09:36:28 +00:00
|
|
|
result = gst_vdp_video_to_yuv_caps (caps, yuv_video->device);
|
2009-04-07 18:46:49 +00:00
|
|
|
}
|
|
|
|
|
2009-06-23 14:57:45 +00:00
|
|
|
GST_LOG ("transformed %" GST_PTR_FORMAT " to %" GST_PTR_FORMAT, caps, result);
|
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
return result;
|
2009-04-07 18:46:49 +00:00
|
|
|
}
|
|
|
|
|
2009-06-24 09:36:28 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vdp_yuv_video_start (GstBaseTransform * trans)
|
|
|
|
{
|
|
|
|
GstVdpYUVVideo *yuv_video = GST_VDP_YUV_VIDEO (trans);
|
|
|
|
|
|
|
|
yuv_video->device = NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vdp_yuv_video_stop (GstBaseTransform * trans)
|
|
|
|
{
|
|
|
|
GstVdpYUVVideo *yuv_video = GST_VDP_YUV_VIDEO (trans);
|
|
|
|
|
|
|
|
if (yuv_video->device)
|
|
|
|
g_object_unref (yuv_video->device);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-04-07 18:46:49 +00:00
|
|
|
/* GObject vmethod implementations */
|
|
|
|
|
|
|
|
static void
|
2009-04-13 20:19:20 +00:00
|
|
|
gst_vdp_yuv_video_base_init (gpointer klass)
|
2009-04-07 18:46:49 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_set_details_simple (element_class,
|
|
|
|
"VdpauYUVVideo",
|
|
|
|
"Coyuv_video/Decoder/Video",
|
|
|
|
"VDPAU video surface to YUV",
|
|
|
|
"Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>");
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&sink_template));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&src_template));
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:17:48 +00:00
|
|
|
static void
|
|
|
|
gst_vdp_yuv_video_class_init (GstVdpYUVVideoClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstBaseTransformClass *trans_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
trans_class = (GstBaseTransformClass *) klass;
|
|
|
|
|
2009-06-24 09:36:28 +00:00
|
|
|
trans_class->start = gst_vdp_yuv_video_start;
|
|
|
|
trans_class->stop = gst_vdp_yuv_video_stop;
|
2009-06-22 20:17:48 +00:00
|
|
|
trans_class->transform_caps = gst_vdp_yuv_video_transform_caps;
|
|
|
|
trans_class->transform_size = gst_vdp_yuv_video_transform_size;
|
|
|
|
trans_class->set_caps = gst_vdp_yuv_video_set_caps;
|
|
|
|
trans_class->transform = gst_vdp_yuv_video_transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vdp_yuv_video_init (GstVdpYUVVideo * yuv_video, GstVdpYUVVideoClass * klass)
|
|
|
|
{
|
|
|
|
}
|