2009-03-15 20:21: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>
|
2009-03-31 20:53:40 +00:00
|
|
|
#include <gst/video/video.h>
|
2009-03-15 20:21:49 +00:00
|
|
|
|
2009-04-13 20:19:20 +00:00
|
|
|
#include "gstvdpdecoder.h"
|
2009-03-15 20:21:49 +00:00
|
|
|
|
2009-04-13 20:19:20 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_vdp_decoder_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_vdp_decoder_debug
|
2009-03-15 20:21:49 +00:00
|
|
|
|
|
|
|
/* Filter signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2009-04-14 19:07:32 +00:00
|
|
|
PROP_DISPLAY
|
2009-03-15 20:21:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2009-04-14 21:47:40 +00:00
|
|
|
GST_STATIC_CAPS ("video/x-vdpau-video, " "chroma-type = (int) 0"));
|
2009-03-15 20:21:49 +00:00
|
|
|
|
|
|
|
#define DEBUG_INIT(bla) \
|
2009-04-13 20:19:20 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_vdp_decoder_debug, "vdpaudecoder", 0, "vdpaudecoder base class");
|
2009-03-15 20:21:49 +00:00
|
|
|
|
2009-04-13 20:19:20 +00:00
|
|
|
GST_BOILERPLATE_FULL (GstVdpDecoder, gst_vdp_decoder, GstElement,
|
2009-03-15 20:21:49 +00:00
|
|
|
GST_TYPE_ELEMENT, DEBUG_INIT);
|
|
|
|
|
2009-04-13 20:19:20 +00:00
|
|
|
static void gst_vdp_decoder_finalize (GObject * object);
|
|
|
|
static void gst_vdp_decoder_set_property (GObject * object, guint prop_id,
|
2009-03-15 20:21:49 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2009-04-13 20:19:20 +00:00
|
|
|
static void gst_vdp_decoder_get_property (GObject * object, guint prop_id,
|
2009-03-15 20:21:49 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
GstFlowReturn
|
2009-04-13 20:19:20 +00:00
|
|
|
gst_vdp_decoder_push_video_buffer (GstVdpDecoder * dec,
|
|
|
|
GstVdpVideoBuffer * buffer)
|
2009-03-23 19:47:00 +00:00
|
|
|
{
|
2009-04-27 16:34:53 +00:00
|
|
|
if (GST_BUFFER_TIMESTAMP (buffer) == GST_CLOCK_TIME_NONE) {
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) =
|
|
|
|
gst_util_uint64_scale_int (GST_SECOND * dec->frame_nr,
|
|
|
|
dec->framerate_denominator, dec->framerate_numerator);
|
2009-04-27 18:18:52 +00:00
|
|
|
dec->frame_nr++;
|
2009-04-27 16:34:53 +00:00
|
|
|
}
|
2009-04-04 18:53:35 +00:00
|
|
|
gst_buffer_set_caps (GST_BUFFER (buffer), GST_PAD_CAPS (dec->src));
|
2009-03-31 20:53:40 +00:00
|
|
|
|
2009-04-04 18:53:35 +00:00
|
|
|
return gst_pad_push (dec->src, GST_BUFFER (buffer));
|
2009-03-20 20:24:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-04-13 20:19:20 +00:00
|
|
|
gst_vdp_decoder_sink_set_caps (GstPad * pad, GstCaps * caps)
|
2009-03-20 20:24:40 +00:00
|
|
|
{
|
2009-04-26 21:25:33 +00:00
|
|
|
GstVdpDecoder *dec = GST_VDP_DECODER (GST_OBJECT_PARENT (pad));
|
|
|
|
GstVdpDecoderClass *dec_class = GST_VDP_DECODER_GET_CLASS (dec);
|
2009-03-20 20:24:40 +00:00
|
|
|
|
|
|
|
GstCaps *src_caps, *new_caps;
|
|
|
|
GstStructure *structure;
|
|
|
|
gint width, height;
|
|
|
|
gint framerate_numerator, framerate_denominator;
|
2009-03-31 20:53:40 +00:00
|
|
|
gint par_numerator, par_denominator;
|
2009-03-20 20:24:40 +00:00
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
gst_structure_get_int (structure, "width", &width);
|
|
|
|
gst_structure_get_int (structure, "height", &height);
|
|
|
|
gst_structure_get_fraction (structure, "framerate",
|
|
|
|
&framerate_numerator, &framerate_denominator);
|
2009-03-31 20:53:40 +00:00
|
|
|
gst_structure_get_fraction (structure, "pixel-aspect-ratio",
|
|
|
|
&par_numerator, &par_denominator);
|
2009-03-20 20:24:40 +00:00
|
|
|
|
|
|
|
src_caps = gst_pad_get_allowed_caps (dec->src);
|
2009-03-27 15:55:19 +00:00
|
|
|
if (G_UNLIKELY (!src_caps))
|
|
|
|
return FALSE;
|
2009-03-20 20:24:40 +00:00
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
new_caps = gst_caps_copy_nth (src_caps, 0);
|
|
|
|
gst_caps_unref (src_caps);
|
|
|
|
structure = gst_caps_get_structure (new_caps, 0);
|
2009-03-20 20:24:40 +00:00
|
|
|
gst_structure_set (structure,
|
2009-04-04 18:53:35 +00:00
|
|
|
"device", G_TYPE_OBJECT, dec->device,
|
|
|
|
"chroma-type", G_TYPE_INT, VDP_CHROMA_TYPE_420,
|
2009-03-20 20:24:40 +00:00
|
|
|
"width", G_TYPE_INT, width,
|
|
|
|
"height", G_TYPE_INT, height,
|
|
|
|
"framerate", GST_TYPE_FRACTION, framerate_numerator,
|
2009-03-31 20:53:40 +00:00
|
|
|
framerate_denominator,
|
|
|
|
"pixel-aspect-ratio", GST_TYPE_FRACTION, par_numerator,
|
|
|
|
par_denominator, NULL);
|
2009-03-20 20:24:40 +00:00
|
|
|
|
|
|
|
gst_pad_fixate_caps (dec->src, new_caps);
|
|
|
|
res = gst_pad_set_caps (dec->src, new_caps);
|
|
|
|
|
|
|
|
gst_caps_unref (new_caps);
|
|
|
|
|
2009-03-27 15:55:19 +00:00
|
|
|
if (G_UNLIKELY (!res))
|
2009-03-20 20:24:40 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2009-03-25 18:59:06 +00:00
|
|
|
dec->width = width;
|
|
|
|
dec->height = height;
|
2009-03-31 20:53:40 +00:00
|
|
|
dec->framerate_numerator = framerate_numerator;
|
|
|
|
dec->framerate_denominator = framerate_denominator;
|
2009-03-23 19:47:00 +00:00
|
|
|
|
2009-03-26 20:04:48 +00:00
|
|
|
if (dec_class->set_caps && !dec_class->set_caps (dec, caps))
|
|
|
|
return FALSE;
|
|
|
|
|
2009-03-20 20:24:40 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-03-15 20:21:49 +00:00
|
|
|
/* GObject vmethod implementations */
|
|
|
|
|
|
|
|
static void
|
2009-04-13 20:19:20 +00:00
|
|
|
gst_vdp_decoder_base_init (gpointer klass)
|
2009-03-15 20:21:49 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&src_template));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize the vdpaudecoder's class */
|
|
|
|
static void
|
2009-04-13 20:19:20 +00:00
|
|
|
gst_vdp_decoder_class_init (GstVdpDecoderClass * klass)
|
2009-03-15 20:21:49 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
2009-04-13 20:19:20 +00:00
|
|
|
gobject_class->finalize = gst_vdp_decoder_finalize;
|
|
|
|
gobject_class->set_property = gst_vdp_decoder_set_property;
|
|
|
|
gobject_class->get_property = gst_vdp_decoder_get_property;
|
2009-03-15 20:21:49 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_DISPLAY,
|
|
|
|
g_param_spec_string ("display", "Display", "X Display name",
|
|
|
|
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-04-13 20:19:20 +00:00
|
|
|
gst_vdp_decoder_init (GstVdpDecoder * dec, GstVdpDecoderClass * klass)
|
2009-03-15 20:21:49 +00:00
|
|
|
{
|
2009-03-29 13:28:06 +00:00
|
|
|
dec->display_name = NULL;
|
2009-04-01 19:19:18 +00:00
|
|
|
dec->device = NULL;
|
2009-03-15 20:21:49 +00:00
|
|
|
|
2009-03-25 18:59:06 +00:00
|
|
|
dec->height = 0;
|
|
|
|
dec->width = 0;
|
2009-03-31 20:53:40 +00:00
|
|
|
dec->framerate_numerator = 0;
|
|
|
|
dec->framerate_denominator = 0;
|
2009-03-25 18:59:06 +00:00
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
dec->frame_nr = 0;
|
|
|
|
|
2009-03-15 20:21:49 +00:00
|
|
|
dec->src = gst_pad_new_from_static_template (&src_template, "src");
|
|
|
|
gst_element_add_pad (GST_ELEMENT (dec), dec->src);
|
|
|
|
|
2009-03-15 20:23:35 +00:00
|
|
|
dec->sink = gst_pad_new_from_template (gst_element_class_get_pad_template
|
2009-03-15 20:21:49 +00:00
|
|
|
(GST_ELEMENT_CLASS (klass), "sink"), "sink");
|
2009-04-13 20:19:20 +00:00
|
|
|
gst_pad_set_setcaps_function (dec->sink, gst_vdp_decoder_sink_set_caps);
|
2009-03-15 20:21:49 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (dec), dec->sink);
|
2009-03-26 20:04:48 +00:00
|
|
|
gst_pad_set_active (dec->sink, TRUE);
|
2009-03-15 20:21:49 +00:00
|
|
|
}
|
|
|
|
|
2009-04-01 19:40:14 +00:00
|
|
|
static void
|
2009-04-13 20:19:20 +00:00
|
|
|
gst_vdp_decoder_finalize (GObject * object)
|
2009-04-01 19:40:14 +00:00
|
|
|
{
|
2009-04-13 20:19:20 +00:00
|
|
|
GstVdpDecoder *dec = (GstVdpDecoder *) object;
|
2009-04-01 19:40:14 +00:00
|
|
|
|
|
|
|
g_free (dec->display_name);
|
|
|
|
}
|
|
|
|
|
2009-03-15 20:21:49 +00:00
|
|
|
static void
|
2009-04-13 20:19:20 +00:00
|
|
|
gst_vdp_decoder_set_property (GObject * object, guint prop_id,
|
2009-03-15 20:21:49 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2009-04-26 21:25:33 +00:00
|
|
|
GstVdpDecoder *dec = GST_VDP_DECODER (object);
|
2009-03-15 20:21:49 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISPLAY:
|
2009-03-29 13:28:06 +00:00
|
|
|
g_free (dec->display_name);
|
|
|
|
dec->display_name = g_value_dup_string (value);
|
2009-03-15 20:21:49 +00:00
|
|
|
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_decoder_get_property (GObject * object, guint prop_id,
|
2009-03-15 20:21:49 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2009-04-26 21:25:33 +00:00
|
|
|
GstVdpDecoder *dec = GST_VDP_DECODER (object);
|
2009-03-15 20:21:49 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISPLAY:
|
2009-03-29 13:28:06 +00:00
|
|
|
g_value_set_string (value, dec->display_name);
|
2009-03-15 20:21:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|