2009-03-25 19:38:27 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-04-14 19:04:59 +00:00
|
|
|
* SECTION:element-vdpaumpegdec
|
2009-03-25 19:38:27 +00:00
|
|
|
*
|
2009-04-14 19:04:59 +00:00
|
|
|
* FIXME:Describe vdpaumpegdec here.
|
2009-03-25 19:38:27 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example launch line</title>
|
|
|
|
* |[
|
2009-04-14 19:04:59 +00:00
|
|
|
* gst-launch -v -m fakesrc ! vdpaumpegdec ! fakesink silent=TRUE
|
2009-03-25 19:38:27 +00:00
|
|
|
* ]|
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2009-06-04 16:11:06 +00:00
|
|
|
#include <gst/base/gstbytereader.h>
|
|
|
|
#include <gst/base/gstbitreader.h>
|
2009-03-31 20:53:40 +00:00
|
|
|
#include <string.h>
|
2009-03-25 19:38:27 +00:00
|
|
|
|
2009-03-27 15:55:19 +00:00
|
|
|
#include "mpegutil.h"
|
2009-06-05 19:48:28 +00:00
|
|
|
#include "gstvdpmpegdec.h"
|
2009-03-25 19:38:27 +00:00
|
|
|
|
2009-06-05 19:46:08 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_vdp_mpeg_dec_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_vdp_mpeg_dec_debug
|
2009-03-25 19:38:27 +00:00
|
|
|
|
|
|
|
/* Filter signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2009-06-04 17:17:14 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_DISPLAY
|
2009-03-25 19:38:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* the capabilities of the inputs and outputs.
|
|
|
|
*
|
|
|
|
* describe the real formats here.
|
|
|
|
*/
|
2009-06-04 17:17:14 +00:00
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
2009-03-25 19:38:27 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2009-03-26 20:04:48 +00:00
|
|
|
GST_STATIC_CAPS ("video/mpeg, mpegversion = (int) [ 1, 2 ], "
|
2009-03-27 15:55:19 +00:00
|
|
|
"systemstream = (boolean) false, parsed = (boolean) true")
|
2009-03-25 19:38:27 +00:00
|
|
|
);
|
2009-06-04 17:17:14 +00:00
|
|
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2009-06-15 17:29:56 +00:00
|
|
|
GST_STATIC_CAPS (GST_VDP_VIDEO_CAPS));
|
2009-03-25 19:38:27 +00:00
|
|
|
|
2009-04-04 20:03:23 +00:00
|
|
|
#define DEBUG_INIT(bla) \
|
2009-06-05 19:46:08 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_vdp_mpeg_dec_debug, "vdpaumpegdec", 0, "VDPAU powered mpeg decoder");
|
2009-04-04 20:03:23 +00:00
|
|
|
|
2009-06-05 19:46:08 +00:00
|
|
|
GST_BOILERPLATE_FULL (GstVdpMpegDec, gst_vdp_mpeg_dec,
|
2009-06-04 17:17:14 +00:00
|
|
|
GstElement, GST_TYPE_ELEMENT, DEBUG_INIT);
|
2009-03-25 19:38:27 +00:00
|
|
|
|
2009-06-05 19:46:08 +00:00
|
|
|
static void gst_vdp_mpeg_dec_init_info (VdpPictureInfoMPEG1Or2 * vdp_info);
|
|
|
|
static void gst_vdp_mpeg_dec_finalize (GObject * object);
|
|
|
|
static void gst_vdp_mpeg_dec_set_property (GObject * object,
|
2009-03-25 19:38:27 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
2009-06-05 19:46:08 +00:00
|
|
|
static void gst_vdp_mpeg_dec_get_property (GObject * object,
|
2009-03-25 19:38:27 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
|
2009-06-04 16:11:06 +00:00
|
|
|
guint8 *
|
|
|
|
mpeg_util_find_start_code (guint32 * sync_word, guint8 * cur, guint8 * end)
|
|
|
|
{
|
|
|
|
guint32 code;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (cur == NULL))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
code = *sync_word;
|
|
|
|
|
|
|
|
while (cur < end) {
|
|
|
|
code <<= 8;
|
|
|
|
|
|
|
|
if (code == 0x00000100) {
|
|
|
|
/* Reset the sync word accumulator */
|
|
|
|
*sync_word = 0xffffffff;
|
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the next available byte to the collected sync word */
|
|
|
|
code |= *cur++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*sync_word = code;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
guint8 *cur;
|
|
|
|
guint8 *end;
|
|
|
|
} GstVdpMpegPacketizer;
|
|
|
|
|
|
|
|
static GstBuffer *
|
|
|
|
gst_vdp_mpeg_packetizer_get_next_packet (GstVdpMpegPacketizer * packetizer)
|
|
|
|
{
|
|
|
|
guint32 sync_word = 0xffffff;
|
|
|
|
guint8 *packet_start;
|
|
|
|
guint8 *packet_end;
|
|
|
|
|
|
|
|
if (!packetizer->cur)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
packet_start = packetizer->cur - 3;
|
|
|
|
packetizer->cur = packet_end = mpeg_util_find_start_code (&sync_word,
|
|
|
|
packetizer->cur, packetizer->end);
|
|
|
|
|
|
|
|
if (packet_end)
|
|
|
|
packet_end -= 3;
|
|
|
|
else
|
|
|
|
packet_end = packetizer->end;
|
|
|
|
|
|
|
|
return gst_buffer_create_sub (packetizer->buffer,
|
|
|
|
packet_start - GST_BUFFER_DATA (packetizer->buffer),
|
|
|
|
packet_end - packet_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vdp_mpeg_packetizer_init (GstVdpMpegPacketizer * packetizer,
|
|
|
|
GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
guint32 sync_word = 0xffffffff;
|
|
|
|
|
|
|
|
packetizer->buffer = buffer;
|
|
|
|
packetizer->end = GST_BUFFER_DATA (buffer) + GST_BUFFER_SIZE (buffer);
|
|
|
|
packetizer->cur = mpeg_util_find_start_code (&sync_word,
|
|
|
|
GST_BUFFER_DATA (buffer), packetizer->end);
|
|
|
|
}
|
|
|
|
|
2009-03-26 20:04:48 +00:00
|
|
|
static gboolean
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_set_caps (GstPad * pad, GstCaps * caps)
|
2009-03-26 20:04:48 +00:00
|
|
|
{
|
2009-06-06 22:55:55 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (gst_pad_get_parent (pad));
|
2009-03-26 20:04:48 +00:00
|
|
|
GstStructure *structure;
|
2009-06-04 17:17:14 +00:00
|
|
|
|
|
|
|
gint width, height;
|
|
|
|
gint fps_n, fps_d;
|
|
|
|
gint par_n, par_d;
|
2009-06-05 16:28:17 +00:00
|
|
|
gboolean interlaced = FALSE;
|
2009-06-04 17:17:14 +00:00
|
|
|
|
|
|
|
GstCaps *src_caps;
|
|
|
|
gboolean res;
|
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
const GValue *value;
|
2009-03-29 13:28:06 +00:00
|
|
|
VdpDecoderProfile profile;
|
2009-04-13 20:19:20 +00:00
|
|
|
GstVdpDevice *device;
|
2009-03-29 13:28:06 +00:00
|
|
|
VdpStatus status;
|
2009-03-26 20:04:48 +00:00
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2009-06-04 17:17:14 +00:00
|
|
|
|
|
|
|
/* create src_pad caps */
|
|
|
|
gst_structure_get_int (structure, "width", &width);
|
|
|
|
gst_structure_get_int (structure, "height", &height);
|
2009-06-04 19:17:40 +00:00
|
|
|
gst_structure_get_fraction (structure, "framerate", &fps_n, &fps_d);
|
2009-06-04 17:17:14 +00:00
|
|
|
gst_structure_get_fraction (structure, "pixel-aspect-ratio", &par_n, &par_d);
|
|
|
|
gst_structure_get_boolean (structure, "interlaced", &interlaced);
|
|
|
|
|
|
|
|
src_caps = gst_caps_new_simple ("video/x-vdpau-video",
|
|
|
|
"device", G_TYPE_OBJECT, mpeg_dec->device,
|
2009-06-15 17:29:56 +00:00
|
|
|
"chroma-type", G_TYPE_INT, VDP_CHROMA_TYPE_420,
|
2009-06-04 17:17:14 +00:00
|
|
|
"width", G_TYPE_INT, width,
|
|
|
|
"height", G_TYPE_INT, height,
|
|
|
|
"framerate", GST_TYPE_FRACTION, fps_n, fps_d,
|
|
|
|
"pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d,
|
|
|
|
"interlaced", G_TYPE_BOOLEAN, interlaced, NULL);
|
|
|
|
|
2009-06-19 20:20:26 +00:00
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "Setting source caps to %" GST_PTR_FORMAT,
|
|
|
|
src_caps);
|
|
|
|
|
2009-06-04 17:17:14 +00:00
|
|
|
res = gst_pad_set_caps (mpeg_dec->src, src_caps);
|
|
|
|
gst_caps_unref (src_caps);
|
|
|
|
if (!res)
|
2009-06-06 22:55:55 +00:00
|
|
|
goto done;
|
2009-06-04 17:17:14 +00:00
|
|
|
|
|
|
|
mpeg_dec->width = width;
|
|
|
|
mpeg_dec->height = height;
|
|
|
|
mpeg_dec->fps_n = fps_n;
|
|
|
|
mpeg_dec->fps_d = fps_d;
|
|
|
|
mpeg_dec->interlaced = interlaced;
|
|
|
|
|
|
|
|
/* parse caps to setup decoder */
|
2009-03-31 20:53:40 +00:00
|
|
|
gst_structure_get_int (structure, "mpegversion", &mpeg_dec->version);
|
|
|
|
if (mpeg_dec->version == 1)
|
2009-03-29 13:28:06 +00:00
|
|
|
profile = VDP_DECODER_PROFILE_MPEG1;
|
2009-03-27 15:55:19 +00:00
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
value = gst_structure_get_value (structure, "codec_data");
|
2009-06-04 16:11:06 +00:00
|
|
|
if (value) {
|
|
|
|
GstBuffer *codec_data, *buf;
|
|
|
|
GstVdpMpegPacketizer packetizer;
|
|
|
|
|
|
|
|
codec_data = gst_value_get_buffer (value);
|
|
|
|
gst_vdp_mpeg_packetizer_init (&packetizer, codec_data);
|
|
|
|
if ((buf = gst_vdp_mpeg_packetizer_get_next_packet (&packetizer))) {
|
|
|
|
MPEGSeqHdr hdr;
|
2009-06-05 09:17:16 +00:00
|
|
|
guint32 bitrate;
|
2009-06-04 16:11:06 +00:00
|
|
|
|
|
|
|
mpeg_util_parse_sequence_hdr (&hdr, buf);
|
|
|
|
|
|
|
|
memcpy (&mpeg_dec->vdp_info.intra_quantizer_matrix,
|
|
|
|
&hdr.intra_quantizer_matrix, 64);
|
|
|
|
memcpy (&mpeg_dec->vdp_info.non_intra_quantizer_matrix,
|
|
|
|
&hdr.non_intra_quantizer_matrix, 64);
|
|
|
|
|
2009-06-05 09:17:16 +00:00
|
|
|
bitrate = hdr.bitrate;
|
2009-06-04 16:11:06 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
|
|
|
|
if ((buf = gst_vdp_mpeg_packetizer_get_next_packet (&packetizer))) {
|
|
|
|
MPEGSeqExtHdr ext;
|
|
|
|
|
|
|
|
mpeg_util_parse_sequence_extension (&ext, buf);
|
|
|
|
if (mpeg_dec->version != 1) {
|
|
|
|
switch (ext.profile) {
|
|
|
|
case 5:
|
|
|
|
profile = VDP_DECODER_PROFILE_MPEG2_SIMPLE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-15 17:29:56 +00:00
|
|
|
bitrate += (ext.bitrate_ext << 18);
|
2009-06-04 16:11:06 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
2009-06-05 09:17:16 +00:00
|
|
|
|
2009-06-05 16:18:38 +00:00
|
|
|
mpeg_dec->duration =
|
|
|
|
gst_util_uint64_scale (1, GST_SECOND * mpeg_dec->fps_d,
|
|
|
|
mpeg_dec->fps_n);
|
|
|
|
|
2009-06-05 09:17:16 +00:00
|
|
|
mpeg_dec->byterate = bitrate * 50;
|
|
|
|
GST_DEBUG ("byterate: %" G_GINT64_FORMAT, mpeg_dec->byterate);
|
2009-03-27 15:55:19 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-13 19:11:54 +00:00
|
|
|
|
2009-06-04 17:17:14 +00:00
|
|
|
device = mpeg_dec->device;
|
2009-04-27 18:50:11 +00:00
|
|
|
|
|
|
|
if (mpeg_dec->decoder != VDP_INVALID_HANDLE) {
|
|
|
|
device->vdp_decoder_destroy (mpeg_dec->decoder);
|
|
|
|
mpeg_dec->decoder = VDP_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2009-06-04 17:17:14 +00:00
|
|
|
status = device->vdp_decoder_create (device->device, profile, mpeg_dec->width,
|
|
|
|
mpeg_dec->height, 2, &mpeg_dec->decoder);
|
2009-03-29 13:28:06 +00:00
|
|
|
if (status != VDP_STATUS_OK) {
|
|
|
|
GST_ELEMENT_ERROR (mpeg_dec, RESOURCE, READ,
|
|
|
|
("Could not create vdpau decoder"),
|
|
|
|
("Error returned from vdpau was: %s",
|
2009-04-01 19:19:18 +00:00
|
|
|
device->vdp_get_error_string (status)));
|
2009-06-06 22:55:55 +00:00
|
|
|
res = FALSE;
|
|
|
|
goto done;
|
2009-03-29 13:28:06 +00:00
|
|
|
}
|
2009-06-06 22:55:55 +00:00
|
|
|
res = TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
gst_object_unref (mpeg_dec);
|
|
|
|
|
|
|
|
return res;
|
2009-03-26 20:04:48 +00:00
|
|
|
}
|
|
|
|
|
2009-06-04 17:17:14 +00:00
|
|
|
GstFlowReturn
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_push_video_buffer (GstVdpMpegDec * mpeg_dec,
|
2009-06-04 17:17:14 +00:00
|
|
|
GstVdpVideoBuffer * buffer)
|
|
|
|
{
|
2009-06-05 19:16:48 +00:00
|
|
|
gint64 byterate;
|
|
|
|
|
2009-06-05 15:43:49 +00:00
|
|
|
if (GST_BUFFER_TIMESTAMP (buffer) == GST_CLOCK_TIME_NONE
|
|
|
|
&& GST_CLOCK_TIME_IS_VALID (mpeg_dec->next_timestamp)) {
|
2009-06-04 17:30:02 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = mpeg_dec->next_timestamp;
|
2009-06-05 15:43:49 +00:00
|
|
|
} else if (GST_BUFFER_TIMESTAMP (buffer) == GST_CLOCK_TIME_NONE) {
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = gst_util_uint64_scale (mpeg_dec->frame_nr,
|
|
|
|
GST_SECOND * mpeg_dec->fps_d, mpeg_dec->fps_n);
|
2009-06-04 17:17:14 +00:00
|
|
|
}
|
2009-06-04 17:30:02 +00:00
|
|
|
|
2009-06-05 15:43:49 +00:00
|
|
|
if (mpeg_dec->seeking) {
|
|
|
|
GstEvent *event;
|
|
|
|
|
|
|
|
event = gst_event_new_new_segment (FALSE,
|
|
|
|
mpeg_dec->segment.rate, GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buffer),
|
|
|
|
mpeg_dec->segment.stop, GST_BUFFER_TIMESTAMP (buffer));
|
|
|
|
|
|
|
|
gst_pad_push_event (mpeg_dec->src, event);
|
2009-06-05 19:18:47 +00:00
|
|
|
|
|
|
|
mpeg_dec->seeking = FALSE;
|
2009-06-05 15:43:49 +00:00
|
|
|
}
|
|
|
|
|
2009-06-04 17:30:02 +00:00
|
|
|
mpeg_dec->next_timestamp = GST_BUFFER_TIMESTAMP (buffer) +
|
2009-06-04 19:17:40 +00:00
|
|
|
GST_BUFFER_DURATION (buffer);
|
2009-06-04 17:30:02 +00:00
|
|
|
|
2009-06-06 19:27:52 +00:00
|
|
|
gst_segment_set_last_stop (&mpeg_dec->segment, GST_FORMAT_TIME,
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer));
|
|
|
|
|
2009-06-05 19:16:48 +00:00
|
|
|
mpeg_dec->accumulated_duration += GST_BUFFER_DURATION (buffer);
|
|
|
|
mpeg_dec->accumulated_size += GST_BUFFER_SIZE (buffer);
|
|
|
|
byterate = gst_util_uint64_scale (mpeg_dec->accumulated_size, GST_SECOND,
|
|
|
|
mpeg_dec->accumulated_duration);
|
|
|
|
GST_DEBUG ("byterate: %" G_GINT64_FORMAT, mpeg_dec->byterate);
|
|
|
|
|
|
|
|
mpeg_dec->byterate = (mpeg_dec->byterate + byterate) / 2;
|
|
|
|
|
2009-06-04 17:17:14 +00:00
|
|
|
gst_buffer_set_caps (GST_BUFFER (buffer), GST_PAD_CAPS (mpeg_dec->src));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec,
|
2009-06-05 17:08:24 +00:00
|
|
|
"Pushing buffer with timestamp: %" GST_TIME_FORMAT
|
|
|
|
" frame_nr: %" G_GINT64_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
|
|
|
|
GST_BUFFER_OFFSET (buffer));
|
2009-06-04 17:17:14 +00:00
|
|
|
|
|
|
|
return gst_pad_push (mpeg_dec->src, GST_BUFFER (buffer));
|
|
|
|
}
|
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
static GstFlowReturn
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_decode (GstVdpMpegDec * mpeg_dec,
|
2009-06-05 19:42:30 +00:00
|
|
|
GstClockTime timestamp, gint64 size)
|
2009-03-31 20:53:40 +00:00
|
|
|
{
|
2009-05-05 21:13:25 +00:00
|
|
|
VdpPictureInfoMPEG1Or2 *info;
|
2009-03-31 20:53:40 +00:00
|
|
|
GstBuffer *buffer;
|
2009-04-13 20:19:20 +00:00
|
|
|
GstVdpVideoBuffer *outbuf;
|
2009-03-31 20:53:40 +00:00
|
|
|
VdpVideoSurface surface;
|
2009-04-13 20:19:20 +00:00
|
|
|
GstVdpDevice *device;
|
2009-03-31 20:53:40 +00:00
|
|
|
VdpBitstreamBuffer vbit[1];
|
|
|
|
VdpStatus status;
|
|
|
|
|
2009-05-05 21:13:25 +00:00
|
|
|
info = &mpeg_dec->vdp_info;
|
2009-03-31 20:53:40 +00:00
|
|
|
|
|
|
|
buffer = gst_adapter_take_buffer (mpeg_dec->adapter,
|
|
|
|
gst_adapter_available (mpeg_dec->adapter));
|
|
|
|
|
2009-06-04 17:17:14 +00:00
|
|
|
outbuf = gst_vdp_video_buffer_new (mpeg_dec->device, VDP_CHROMA_TYPE_420,
|
|
|
|
mpeg_dec->width, mpeg_dec->height);
|
2009-05-05 16:37:50 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
|
2009-06-04 19:17:40 +00:00
|
|
|
GST_BUFFER_DURATION (outbuf) = mpeg_dec->duration;
|
2009-06-05 15:43:49 +00:00
|
|
|
GST_BUFFER_OFFSET (outbuf) = mpeg_dec->frame_nr;
|
2009-06-05 19:42:30 +00:00
|
|
|
GST_BUFFER_SIZE (outbuf) = size;
|
2009-06-05 19:16:48 +00:00
|
|
|
|
2009-06-05 20:28:02 +00:00
|
|
|
if (info->picture_coding_type == I_FRAME)
|
|
|
|
GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
else
|
|
|
|
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
|
2009-06-05 16:28:17 +00:00
|
|
|
if (info->top_field_first)
|
|
|
|
GST_BUFFER_FLAG_SET (outbuf, GST_VIDEO_BUFFER_TFF);
|
2009-06-05 20:28:02 +00:00
|
|
|
else
|
|
|
|
GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_TFF);
|
|
|
|
|
2009-05-05 21:19:56 +00:00
|
|
|
|
2009-06-05 21:11:18 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->forward_reference != VDP_INVALID_HANDLE) {
|
|
|
|
gst_buffer_unref (mpeg_dec->f_buffer);
|
|
|
|
info->forward_reference = VDP_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->forward_reference = info->backward_reference;
|
|
|
|
mpeg_dec->f_buffer = mpeg_dec->b_buffer;
|
|
|
|
|
|
|
|
info->backward_reference = VDP_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2009-05-05 21:13:25 +00:00
|
|
|
if (info->forward_reference != VDP_INVALID_HANDLE &&
|
|
|
|
info->picture_coding_type != I_FRAME)
|
2009-05-03 19:52:49 +00:00
|
|
|
gst_vdp_video_buffer_add_reference (outbuf,
|
|
|
|
GST_VDP_VIDEO_BUFFER (mpeg_dec->f_buffer));
|
2009-05-05 21:19:56 +00:00
|
|
|
|
2009-06-05 21:11:18 +00:00
|
|
|
if (info->backward_reference != VDP_INVALID_HANDLE
|
|
|
|
&& info->picture_coding_type == B_FRAME)
|
2009-05-03 19:52:49 +00:00
|
|
|
gst_vdp_video_buffer_add_reference (outbuf,
|
|
|
|
GST_VDP_VIDEO_BUFFER (mpeg_dec->b_buffer));
|
|
|
|
|
2009-04-04 18:53:35 +00:00
|
|
|
surface = outbuf->surface;
|
2009-03-31 20:53:40 +00:00
|
|
|
|
2009-06-04 17:17:14 +00:00
|
|
|
device = mpeg_dec->device;
|
2009-03-31 20:53:40 +00:00
|
|
|
|
|
|
|
vbit[0].struct_version = VDP_BITSTREAM_BUFFER_VERSION;
|
|
|
|
vbit[0].bitstream = GST_BUFFER_DATA (buffer);
|
|
|
|
vbit[0].bitstream_bytes = GST_BUFFER_SIZE (buffer);
|
|
|
|
|
2009-04-01 19:19:18 +00:00
|
|
|
status = device->vdp_decoder_render (mpeg_dec->decoder, surface,
|
2009-05-05 21:13:25 +00:00
|
|
|
(VdpPictureInfo *) info, 1, vbit);
|
2009-03-31 20:53:40 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2009-05-05 21:13:25 +00:00
|
|
|
info->slice_count = 0;
|
2009-03-31 20:53:40 +00:00
|
|
|
|
|
|
|
if (status != VDP_STATUS_OK) {
|
|
|
|
GST_ELEMENT_ERROR (mpeg_dec, RESOURCE, READ,
|
|
|
|
("Could not decode"),
|
|
|
|
("Error returned from vdpau was: %s",
|
2009-04-01 19:19:18 +00:00
|
|
|
device->vdp_get_error_string (status)));
|
2009-03-31 20:53:40 +00:00
|
|
|
|
2009-04-04 18:53:35 +00:00
|
|
|
gst_buffer_unref (GST_BUFFER (outbuf));
|
2009-03-31 20:53:40 +00:00
|
|
|
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-05-05 21:13:25 +00:00
|
|
|
if (info->picture_coding_type == B_FRAME) {
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_push_video_buffer (mpeg_dec,
|
2009-06-04 17:17:14 +00:00
|
|
|
GST_VDP_VIDEO_BUFFER (outbuf));
|
2009-05-03 19:52:49 +00:00
|
|
|
} else {
|
2009-05-05 21:13:25 +00:00
|
|
|
info->backward_reference = surface;
|
2009-05-03 19:52:49 +00:00
|
|
|
mpeg_dec->b_buffer = GST_BUFFER (outbuf);
|
2009-04-16 20:06:50 +00:00
|
|
|
}
|
|
|
|
|
2009-05-03 19:52:49 +00:00
|
|
|
return GST_FLOW_OK;
|
2009-03-31 20:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_parse_picture_coding (GstVdpMpegDec * mpeg_dec,
|
2009-06-04 16:11:06 +00:00
|
|
|
GstBuffer * buffer)
|
2009-03-31 20:53:40 +00:00
|
|
|
{
|
|
|
|
MPEGPictureExt pic_ext;
|
|
|
|
VdpPictureInfoMPEG1Or2 *info;
|
2009-06-04 19:17:40 +00:00
|
|
|
gint fields;
|
2009-03-31 20:53:40 +00:00
|
|
|
|
|
|
|
info = &mpeg_dec->vdp_info;
|
|
|
|
|
2009-06-04 16:11:06 +00:00
|
|
|
if (!mpeg_util_parse_picture_coding_extension (&pic_ext, buffer))
|
2009-03-31 20:53:40 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
memcpy (&mpeg_dec->vdp_info.f_code, &pic_ext.f_code, 4);
|
|
|
|
|
|
|
|
info->intra_dc_precision = pic_ext.intra_dc_precision;
|
|
|
|
info->picture_structure = pic_ext.picture_structure;
|
|
|
|
info->top_field_first = pic_ext.top_field_first;
|
|
|
|
info->frame_pred_frame_dct = pic_ext.frame_pred_frame_dct;
|
|
|
|
info->concealment_motion_vectors = pic_ext.concealment_motion_vectors;
|
|
|
|
info->q_scale_type = pic_ext.q_scale_type;
|
|
|
|
info->intra_vlc_format = pic_ext.intra_vlc_format;
|
2009-04-15 21:38:53 +00:00
|
|
|
info->alternate_scan = pic_ext.alternate_scan;
|
2009-03-31 20:53:40 +00:00
|
|
|
|
2009-06-05 15:43:49 +00:00
|
|
|
fields = 2;
|
2009-06-04 19:17:40 +00:00
|
|
|
if (pic_ext.picture_structure == 3) {
|
|
|
|
if (mpeg_dec->interlaced) {
|
|
|
|
if (pic_ext.progressive_frame == 0)
|
|
|
|
fields = 2;
|
|
|
|
if (pic_ext.progressive_frame == 0 && pic_ext.repeat_first_field == 0)
|
|
|
|
fields = 2;
|
|
|
|
if (pic_ext.progressive_frame == 1 && pic_ext.repeat_first_field == 1)
|
|
|
|
fields = 3;
|
|
|
|
} else {
|
|
|
|
if (pic_ext.repeat_first_field == 0)
|
|
|
|
fields = 2;
|
|
|
|
if (pic_ext.repeat_first_field == 1 && pic_ext.top_field_first == 0)
|
|
|
|
fields = 4;
|
|
|
|
if (pic_ext.repeat_first_field == 1 && pic_ext.top_field_first == 1)
|
|
|
|
fields = 6;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
fields = 1;
|
|
|
|
|
|
|
|
GST_DEBUG ("fields: %d", fields);
|
|
|
|
|
|
|
|
mpeg_dec->duration = gst_util_uint64_scale (fields,
|
|
|
|
GST_SECOND * mpeg_dec->fps_d, 2 * mpeg_dec->fps_n);
|
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-04-04 20:45:09 +00:00
|
|
|
static gboolean
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_parse_sequence (GstVdpMpegDec * mpeg_dec, GstBuffer * buffer)
|
2009-04-04 20:45:09 +00:00
|
|
|
{
|
|
|
|
MPEGSeqHdr hdr;
|
|
|
|
|
2009-06-04 16:11:06 +00:00
|
|
|
if (!mpeg_util_parse_sequence_hdr (&hdr, buffer))
|
2009-04-04 20:45:09 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
memcpy (&mpeg_dec->vdp_info.intra_quantizer_matrix,
|
|
|
|
&hdr.intra_quantizer_matrix, 64);
|
|
|
|
memcpy (&mpeg_dec->vdp_info.non_intra_quantizer_matrix,
|
|
|
|
&hdr.non_intra_quantizer_matrix, 64);
|
|
|
|
|
2009-06-08 12:35:29 +00:00
|
|
|
if (mpeg_dec->state == GST_VDP_MPEG_DEC_NEED_SEQUENCE)
|
|
|
|
mpeg_dec->state = GST_VDP_MPEG_DEC_NEED_DATA;
|
|
|
|
|
2009-04-04 20:45:09 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
static gboolean
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_parse_picture (GstVdpMpegDec * mpeg_dec, GstBuffer * buffer)
|
2009-03-31 20:53:40 +00:00
|
|
|
{
|
|
|
|
MPEGPictureHdr pic_hdr;
|
|
|
|
|
2009-06-04 16:11:06 +00:00
|
|
|
if (!mpeg_util_parse_picture_hdr (&pic_hdr, buffer))
|
2009-03-31 20:53:40 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2009-05-03 19:52:49 +00:00
|
|
|
if (pic_hdr.pic_type != I_FRAME
|
|
|
|
&& mpeg_dec->vdp_info.backward_reference == VDP_INVALID_HANDLE) {
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec,
|
|
|
|
"Drop frame since we haven't got an I_FRAME yet");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (pic_hdr.pic_type == B_FRAME
|
|
|
|
&& mpeg_dec->vdp_info.forward_reference == VDP_INVALID_HANDLE) {
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec,
|
|
|
|
"Drop frame since we haven't got two non B_FRAMES yet");
|
2009-04-27 19:30:59 +00:00
|
|
|
return FALSE;
|
2009-03-31 20:53:40 +00:00
|
|
|
}
|
|
|
|
|
2009-05-03 19:52:49 +00:00
|
|
|
mpeg_dec->vdp_info.picture_coding_type = pic_hdr.pic_type;
|
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
if (mpeg_dec->version == 1) {
|
|
|
|
mpeg_dec->vdp_info.full_pel_forward_vector =
|
|
|
|
pic_hdr.full_pel_forward_vector;
|
|
|
|
mpeg_dec->vdp_info.full_pel_backward_vector =
|
|
|
|
pic_hdr.full_pel_backward_vector;
|
|
|
|
memcpy (&mpeg_dec->vdp_info.f_code, &pic_hdr.f_code, 4);
|
2009-04-14 17:08:53 +00:00
|
|
|
}
|
2009-03-31 20:53:40 +00:00
|
|
|
|
2009-06-05 15:43:49 +00:00
|
|
|
mpeg_dec->frame_nr = mpeg_dec->gop_frame + pic_hdr.tsn;
|
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_parse_gop (GstVdpMpegDec * mpeg_dec, GstBuffer * buffer)
|
2009-03-31 20:53:40 +00:00
|
|
|
{
|
2009-06-04 16:11:06 +00:00
|
|
|
MPEGGop gop;
|
2009-06-05 15:43:49 +00:00
|
|
|
GstClockTime time;
|
2009-03-31 20:53:40 +00:00
|
|
|
|
2009-06-04 16:11:06 +00:00
|
|
|
if (!mpeg_util_parse_gop (&gop, buffer))
|
2009-03-31 20:53:40 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2009-06-05 15:43:49 +00:00
|
|
|
time = GST_SECOND * (gop.hour * 3600 + gop.minute * 60 + gop.second);
|
|
|
|
|
|
|
|
GST_DEBUG ("gop timestamp: %" GST_TIME_FORMAT, GST_TIME_ARGS (time));
|
|
|
|
|
|
|
|
mpeg_dec->gop_frame =
|
|
|
|
gst_util_uint64_scale (time, mpeg_dec->fps_n,
|
|
|
|
mpeg_dec->fps_d * GST_SECOND) + gop.frame;
|
|
|
|
|
2009-06-08 12:35:29 +00:00
|
|
|
if (mpeg_dec->state == GST_VDP_MPEG_DEC_NEED_GOP)
|
|
|
|
mpeg_dec->state = GST_VDP_MPEG_DEC_NEED_DATA;
|
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_parse_quant_matrix (GstVdpMpegDec * mpeg_dec,
|
2009-06-04 16:11:06 +00:00
|
|
|
GstBuffer * buffer)
|
2009-03-31 20:53:40 +00:00
|
|
|
{
|
|
|
|
MPEGQuantMatrix qm;
|
|
|
|
|
2009-06-04 16:11:06 +00:00
|
|
|
if (!mpeg_util_parse_quant_matrix (&qm, buffer))
|
2009-03-31 20:53:40 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
memcpy (&mpeg_dec->vdp_info.intra_quantizer_matrix,
|
|
|
|
&qm.intra_quantizer_matrix, 64);
|
|
|
|
memcpy (&mpeg_dec->vdp_info.non_intra_quantizer_matrix,
|
|
|
|
&qm.non_intra_quantizer_matrix, 64);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-04-26 20:05:11 +00:00
|
|
|
static void
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_flush (GstVdpMpegDec * mpeg_dec)
|
2009-04-26 20:05:11 +00:00
|
|
|
{
|
|
|
|
if (mpeg_dec->vdp_info.forward_reference != VDP_INVALID_HANDLE)
|
|
|
|
gst_buffer_unref (mpeg_dec->f_buffer);
|
2009-05-03 19:52:49 +00:00
|
|
|
if (mpeg_dec->vdp_info.backward_reference != VDP_INVALID_HANDLE)
|
|
|
|
gst_buffer_unref (mpeg_dec->b_buffer);
|
2009-04-26 20:05:11 +00:00
|
|
|
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_init_info (&mpeg_dec->vdp_info);
|
2009-04-27 13:12:26 +00:00
|
|
|
|
|
|
|
gst_adapter_clear (mpeg_dec->adapter);
|
2009-06-05 15:43:49 +00:00
|
|
|
|
|
|
|
mpeg_dec->next_timestamp = GST_CLOCK_TIME_NONE;
|
2009-06-05 09:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_reset (GstVdpMpegDec * mpeg_dec)
|
2009-06-05 09:51:41 +00:00
|
|
|
{
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_flush (mpeg_dec);
|
2009-06-05 09:17:16 +00:00
|
|
|
|
2009-06-05 09:51:41 +00:00
|
|
|
if (mpeg_dec->decoder != VDP_INVALID_HANDLE)
|
|
|
|
mpeg_dec->device->vdp_decoder_destroy (mpeg_dec->decoder);
|
|
|
|
mpeg_dec->decoder = VDP_INVALID_HANDLE;
|
|
|
|
if (mpeg_dec->device)
|
|
|
|
g_object_unref (mpeg_dec->device);
|
|
|
|
mpeg_dec->device = NULL;
|
|
|
|
|
2009-06-08 12:35:29 +00:00
|
|
|
mpeg_dec->state = GST_VDP_MPEG_DEC_NEED_SEQUENCE;
|
|
|
|
|
2009-06-05 15:43:49 +00:00
|
|
|
gst_segment_init (&mpeg_dec->segment, GST_FORMAT_TIME);
|
|
|
|
mpeg_dec->seeking = FALSE;
|
2009-06-05 19:16:48 +00:00
|
|
|
|
|
|
|
mpeg_dec->accumulated_size = 0;
|
|
|
|
mpeg_dec->accumulated_duration = 0;
|
2009-04-26 20:05:11 +00:00
|
|
|
}
|
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
static GstFlowReturn
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_chain (GstPad * pad, GstBuffer * buffer)
|
2009-03-31 20:53:40 +00:00
|
|
|
{
|
2009-06-06 22:55:55 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (gst_pad_get_parent (pad));
|
2009-06-04 16:11:06 +00:00
|
|
|
GstVdpMpegPacketizer packetizer;
|
|
|
|
GstBuffer *buf;
|
2009-04-15 21:49:07 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2009-03-31 20:53:40 +00:00
|
|
|
|
2009-04-26 20:05:11 +00:00
|
|
|
if (G_UNLIKELY (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT))) {
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "Received discont buffer");
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_flush (mpeg_dec);
|
2009-04-26 20:05:11 +00:00
|
|
|
}
|
|
|
|
|
2009-06-05 19:46:08 +00:00
|
|
|
|
2009-06-04 16:11:06 +00:00
|
|
|
gst_vdp_mpeg_packetizer_init (&packetizer, buffer);
|
|
|
|
while ((buf = gst_vdp_mpeg_packetizer_get_next_packet (&packetizer))) {
|
|
|
|
GstBitReader b_reader = GST_BIT_READER_INIT_FROM_BUFFER (buf);
|
|
|
|
guint32 sync_code;
|
|
|
|
guint8 start_code;
|
2009-03-31 20:53:40 +00:00
|
|
|
|
2009-06-04 16:11:06 +00:00
|
|
|
/* skip sync_code */
|
|
|
|
gst_bit_reader_get_bits_uint32 (&b_reader, &sync_code, 8 * 3);
|
2009-03-31 20:53:40 +00:00
|
|
|
|
2009-06-04 16:11:06 +00:00
|
|
|
/* start_code */
|
|
|
|
gst_bit_reader_get_bits_uint8 (&b_reader, &start_code, 8);
|
2009-03-31 20:53:40 +00:00
|
|
|
|
2009-06-04 16:11:06 +00:00
|
|
|
if (start_code >= MPEG_PACKET_SLICE_MIN
|
|
|
|
&& start_code <= MPEG_PACKET_SLICE_MAX) {
|
2009-03-31 20:53:40 +00:00
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "MPEG_PACKET_SLICE");
|
2009-06-04 16:11:06 +00:00
|
|
|
|
|
|
|
gst_buffer_ref (buf);
|
|
|
|
gst_adapter_push (mpeg_dec->adapter, buf);
|
2009-04-14 17:08:53 +00:00
|
|
|
mpeg_dec->vdp_info.slice_count++;
|
2009-03-31 20:53:40 +00:00
|
|
|
}
|
|
|
|
|
2009-06-04 16:11:06 +00:00
|
|
|
switch (start_code) {
|
2009-03-31 20:53:40 +00:00
|
|
|
case MPEG_PACKET_PICTURE:
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "MPEG_PACKET_PICTURE");
|
2009-04-15 21:49:07 +00:00
|
|
|
|
2009-06-06 22:55:55 +00:00
|
|
|
if (!gst_vdp_mpeg_dec_parse_picture (mpeg_dec, buf))
|
|
|
|
goto done;
|
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
break;
|
|
|
|
case MPEG_PACKET_SEQUENCE:
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "MPEG_PACKET_SEQUENCE");
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_parse_sequence (mpeg_dec, buf);
|
2009-03-31 20:53:40 +00:00
|
|
|
break;
|
|
|
|
case MPEG_PACKET_EXTENSION:
|
2009-06-04 16:11:06 +00:00
|
|
|
{
|
|
|
|
guint8 ext_code;
|
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "MPEG_PACKET_EXTENSION");
|
2009-06-04 16:11:06 +00:00
|
|
|
|
|
|
|
/* ext_code */
|
|
|
|
gst_bit_reader_get_bits_uint8 (&b_reader, &ext_code, 4);
|
|
|
|
switch (ext_code) {
|
2009-03-31 20:53:40 +00:00
|
|
|
case MPEG_PACKET_EXT_PICTURE_CODING:
|
2009-04-26 18:40:45 +00:00
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "MPEG_PACKET_EXT_PICTURE_CODING");
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_parse_picture_coding (mpeg_dec, buf);
|
2009-03-31 20:53:40 +00:00
|
|
|
break;
|
2009-04-15 21:31:33 +00:00
|
|
|
case MPEG_PACKET_EXT_QUANT_MATRIX:
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "MPEG_PACKET_EXT_QUANT_MATRIX");
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_parse_quant_matrix (mpeg_dec, buf);
|
2009-04-15 21:31:33 +00:00
|
|
|
break;
|
2009-03-31 20:53:40 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2009-06-04 16:11:06 +00:00
|
|
|
}
|
2009-03-31 20:53:40 +00:00
|
|
|
case MPEG_PACKET_GOP:
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "MPEG_PACKET_GOP");
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_parse_gop (mpeg_dec, buf);
|
2009-03-31 20:53:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-06-04 16:11:06 +00:00
|
|
|
|
|
|
|
gst_buffer_unref (buf);
|
2009-03-31 20:53:40 +00:00
|
|
|
}
|
|
|
|
|
2009-06-08 12:35:29 +00:00
|
|
|
if (mpeg_dec->state == GST_VDP_MPEG_DEC_NEED_SEQUENCE ||
|
|
|
|
mpeg_dec->state == GST_VDP_MPEG_DEC_NEED_GOP) {
|
|
|
|
gst_adapter_clear (mpeg_dec->adapter);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2009-04-27 16:34:53 +00:00
|
|
|
if (mpeg_dec->vdp_info.slice_count > 0)
|
2009-06-05 19:46:08 +00:00
|
|
|
ret = gst_vdp_mpeg_dec_decode (mpeg_dec, GST_BUFFER_TIMESTAMP (buffer),
|
2009-06-05 19:42:30 +00:00
|
|
|
GST_BUFFER_SIZE (buffer));
|
2009-04-27 16:34:53 +00:00
|
|
|
|
2009-06-06 22:55:55 +00:00
|
|
|
done:
|
|
|
|
gst_object_unref (mpeg_dec);
|
|
|
|
|
2009-04-15 21:49:07 +00:00
|
|
|
return ret;
|
2009-03-31 20:53:40 +00:00
|
|
|
}
|
|
|
|
|
2009-06-05 09:17:16 +00:00
|
|
|
static gboolean
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_convert (GstVdpMpegDec * mpeg_dec,
|
2009-06-05 09:17:16 +00:00
|
|
|
GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat dest_format, gint64 * dest_value)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (src_format == dest_format) {
|
|
|
|
*dest_value = src_value;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mpeg_dec->byterate == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_TIME) {
|
|
|
|
*dest_value = gst_util_uint64_scale (GST_SECOND, src_value,
|
|
|
|
mpeg_dec->byterate);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_BYTES) {
|
|
|
|
*dest_value =
|
|
|
|
gst_util_uint64_scale_int (src_value, mpeg_dec->byterate, GST_SECOND);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GstQueryType *
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_mpeg_dec_get_querytypes (GstPad * pad)
|
2009-06-05 09:17:16 +00:00
|
|
|
{
|
|
|
|
static const GstQueryType list[] = {
|
|
|
|
GST_QUERY_POSITION,
|
|
|
|
GST_QUERY_DURATION,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_src_query (GstPad * pad, GstQuery * query)
|
2009-06-05 09:17:16 +00:00
|
|
|
{
|
2009-06-06 22:55:55 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (gst_pad_get_parent (pad));
|
|
|
|
gboolean res;
|
2009-06-05 09:17:16 +00:00
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_POSITION:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
|
2009-06-06 22:55:55 +00:00
|
|
|
if ((res = gst_pad_query_default (pad, query)))
|
|
|
|
goto done;
|
2009-06-05 09:17:16 +00:00
|
|
|
|
|
|
|
gst_query_parse_position (query, &format, NULL);
|
|
|
|
if (format == GST_FORMAT_TIME &&
|
|
|
|
GST_CLOCK_TIME_IS_VALID (mpeg_dec->next_timestamp)) {
|
|
|
|
gst_query_set_position (query, GST_FORMAT_TIME,
|
|
|
|
mpeg_dec->next_timestamp);
|
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GST_QUERY_DURATION:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
|
2009-06-06 22:55:55 +00:00
|
|
|
if ((res = gst_pad_query_default (pad, query)))
|
|
|
|
goto done;
|
2009-06-05 09:17:16 +00:00
|
|
|
|
|
|
|
gst_query_parse_duration (query, &format, NULL);
|
|
|
|
if (format == GST_FORMAT_TIME) {
|
|
|
|
gint64 bytes;
|
|
|
|
|
|
|
|
format = GST_FORMAT_BYTES;
|
|
|
|
if (gst_pad_query_duration (pad, &format, &bytes)
|
|
|
|
&& format == GST_FORMAT_BYTES) {
|
|
|
|
gint64 duration;
|
|
|
|
|
2009-06-05 19:46:08 +00:00
|
|
|
if (gst_vdp_mpeg_dec_convert (mpeg_dec, GST_FORMAT_BYTES,
|
2009-06-05 09:17:16 +00:00
|
|
|
bytes, GST_FORMAT_TIME, &duration)) {
|
|
|
|
GST_DEBUG ("duration: %" GST_TIME_FORMAT, GST_TIME_ARGS (duration));
|
|
|
|
gst_query_set_duration (query, GST_FORMAT_TIME, duration);
|
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
res = gst_pad_query_default (pad, query);
|
|
|
|
}
|
|
|
|
|
2009-06-06 22:55:55 +00:00
|
|
|
done:
|
|
|
|
gst_object_unref (mpeg_dec);
|
|
|
|
|
2009-06-05 09:17:16 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-06-05 15:43:49 +00:00
|
|
|
static gboolean
|
2009-06-06 22:55:55 +00:00
|
|
|
normal_seek (GstVdpMpegDec * mpeg_dec, GstEvent * event)
|
2009-06-05 15:43:49 +00:00
|
|
|
{
|
|
|
|
gdouble rate;
|
2009-06-08 12:15:03 +00:00
|
|
|
GstFormat format;
|
2009-06-05 15:43:49 +00:00
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType cur_type, stop_type;
|
|
|
|
gint64 time_cur, bytes_cur;
|
|
|
|
gint64 time_stop, bytes_stop;
|
|
|
|
gboolean res;
|
2009-06-06 19:27:52 +00:00
|
|
|
gboolean update;
|
2009-06-05 15:43:49 +00:00
|
|
|
GstEvent *peer_event;
|
|
|
|
|
|
|
|
GST_DEBUG ("normal seek");
|
|
|
|
|
|
|
|
gst_event_parse_seek (event, &rate, &format, &flags,
|
2009-06-06 19:27:52 +00:00
|
|
|
&cur_type, &time_cur, &stop_type, &time_stop);
|
2009-06-05 15:43:49 +00:00
|
|
|
|
2009-06-06 19:27:52 +00:00
|
|
|
if (format != GST_FORMAT_TIME)
|
|
|
|
return FALSE;
|
2009-06-05 15:43:49 +00:00
|
|
|
|
2009-06-06 19:27:52 +00:00
|
|
|
gst_segment_set_seek (&mpeg_dec->segment, rate, GST_FORMAT_TIME, flags,
|
|
|
|
cur_type, time_cur, stop_type, time_stop, &update);
|
2009-06-05 15:43:49 +00:00
|
|
|
|
2009-06-06 19:27:52 +00:00
|
|
|
if (update) {
|
|
|
|
/* seek on bytes */
|
|
|
|
if (!gst_vdp_mpeg_dec_convert (mpeg_dec, GST_FORMAT_TIME, time_cur,
|
2009-06-08 12:15:03 +00:00
|
|
|
GST_FORMAT_BYTES, &bytes_cur))
|
2009-06-06 19:27:52 +00:00
|
|
|
goto convert_failed;
|
|
|
|
if (!gst_vdp_mpeg_dec_convert (mpeg_dec, GST_FORMAT_TIME, time_stop,
|
2009-06-08 12:15:03 +00:00
|
|
|
GST_FORMAT_BYTES, &bytes_stop))
|
2009-06-06 19:27:52 +00:00
|
|
|
goto convert_failed;
|
2009-06-05 15:43:49 +00:00
|
|
|
|
2009-06-06 19:27:52 +00:00
|
|
|
/* conversion succeeded, create the seek */
|
|
|
|
peer_event =
|
|
|
|
gst_event_new_seek (rate, GST_FORMAT_BYTES, flags,
|
|
|
|
cur_type, bytes_cur, stop_type, bytes_stop);
|
2009-06-05 15:43:49 +00:00
|
|
|
|
2009-06-06 23:12:50 +00:00
|
|
|
g_mutex_lock (mpeg_dec->mutex);
|
2009-06-05 15:43:49 +00:00
|
|
|
|
2009-06-06 19:27:52 +00:00
|
|
|
/* do the seek */
|
|
|
|
res = gst_pad_push_event (mpeg_dec->sink, peer_event);
|
2009-06-06 23:12:50 +00:00
|
|
|
|
2009-06-08 12:35:29 +00:00
|
|
|
if (res) {
|
|
|
|
mpeg_dec->state = GST_VDP_MPEG_DEC_NEED_GOP;
|
2009-06-06 23:12:50 +00:00
|
|
|
mpeg_dec->seeking = TRUE;
|
2009-06-08 12:35:29 +00:00
|
|
|
}
|
2009-06-06 23:12:50 +00:00
|
|
|
|
|
|
|
g_mutex_unlock (mpeg_dec->mutex);
|
|
|
|
|
2009-06-06 23:25:01 +00:00
|
|
|
} else {
|
|
|
|
GstEvent *event;
|
|
|
|
|
|
|
|
/* send segment with new rate */
|
|
|
|
event = gst_event_new_new_segment (TRUE,
|
|
|
|
mpeg_dec->segment.rate, GST_FORMAT_TIME, mpeg_dec->segment.start,
|
|
|
|
mpeg_dec->segment.stop, mpeg_dec->segment.time);
|
|
|
|
|
|
|
|
gst_pad_push_event (mpeg_dec->src, event);
|
|
|
|
res = TRUE;
|
|
|
|
}
|
2009-06-05 15:43:49 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
convert_failed:
|
|
|
|
{
|
|
|
|
/* probably unsupported seek format */
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec,
|
|
|
|
"failed to convert format %u into GST_FORMAT_TIME", format);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_src_event (GstPad * pad, GstEvent * event)
|
2009-06-05 15:43:49 +00:00
|
|
|
{
|
2009-06-06 22:55:55 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (gst_pad_get_parent (pad));
|
2009-06-05 15:43:49 +00:00
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
2009-06-06 22:55:55 +00:00
|
|
|
if ((res = gst_pad_event_default (pad, event)))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
res = normal_seek (mpeg_dec, event);
|
2009-06-05 15:43:49 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = gst_pad_event_default (pad, event);
|
|
|
|
}
|
|
|
|
|
2009-06-06 22:55:55 +00:00
|
|
|
done:
|
|
|
|
gst_object_unref (mpeg_dec);
|
|
|
|
|
2009-06-05 15:43:49 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-04-26 21:20:30 +00:00
|
|
|
static gboolean
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_sink_event (GstPad * pad, GstEvent * event)
|
2009-04-26 21:20:30 +00:00
|
|
|
{
|
2009-06-06 22:55:55 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (gst_pad_get_parent (pad));
|
2009-04-26 21:20:30 +00:00
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "flush stop");
|
|
|
|
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_flush (mpeg_dec);
|
2009-06-04 17:17:14 +00:00
|
|
|
res = gst_pad_push_event (mpeg_dec->src, event);
|
2009-04-26 21:20:30 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2009-06-05 15:43:49 +00:00
|
|
|
case GST_EVENT_NEWSEGMENT:
|
|
|
|
{
|
|
|
|
gboolean update;
|
|
|
|
gdouble rate;
|
|
|
|
GstFormat format;
|
|
|
|
gint64 start;
|
|
|
|
gint64 stop;
|
|
|
|
gint64 position;
|
|
|
|
|
|
|
|
gst_event_parse_new_segment (event, &update, &rate, &format,
|
|
|
|
&start, &stop, &position);
|
|
|
|
|
|
|
|
if (format != GST_FORMAT_TIME) {
|
2009-06-05 19:46:08 +00:00
|
|
|
if (!gst_vdp_mpeg_dec_convert (mpeg_dec, format, start,
|
2009-06-05 15:43:49 +00:00
|
|
|
GST_FORMAT_TIME, &start))
|
|
|
|
goto convert_error;
|
2009-06-05 19:46:08 +00:00
|
|
|
if (!gst_vdp_mpeg_dec_convert (mpeg_dec, format, stop,
|
2009-06-05 15:43:49 +00:00
|
|
|
GST_FORMAT_TIME, &stop))
|
|
|
|
goto convert_error;
|
2009-06-05 19:46:08 +00:00
|
|
|
if (!gst_vdp_mpeg_dec_convert (mpeg_dec, format, position,
|
2009-06-05 15:43:49 +00:00
|
|
|
GST_FORMAT_TIME, &position))
|
|
|
|
goto convert_error;
|
|
|
|
|
|
|
|
gst_event_unref (event);
|
|
|
|
event = gst_event_new_new_segment (update, rate, GST_FORMAT_TIME, start,
|
|
|
|
stop, position);
|
|
|
|
}
|
|
|
|
|
2009-06-06 23:12:50 +00:00
|
|
|
g_mutex_lock (mpeg_dec->mutex);
|
2009-06-05 15:53:16 +00:00
|
|
|
/* if we seek ourselves we don't push out a newsegment now since we
|
|
|
|
* use the calculated timestamp of the first frame for this */
|
|
|
|
if (mpeg_dec->seeking) {
|
|
|
|
gst_event_unref (event);
|
2009-06-06 22:55:55 +00:00
|
|
|
res = TRUE;
|
2009-06-06 23:12:50 +00:00
|
|
|
g_mutex_unlock (mpeg_dec->mutex);
|
2009-06-06 22:55:55 +00:00
|
|
|
goto done;
|
2009-06-05 15:53:16 +00:00
|
|
|
}
|
2009-06-06 23:12:50 +00:00
|
|
|
g_mutex_unlock (mpeg_dec->mutex);
|
2009-06-05 15:53:16 +00:00
|
|
|
|
2009-06-19 20:20:26 +00:00
|
|
|
GST_DEBUG_OBJECT (mpeg_dec,
|
|
|
|
"Pushing new segment update %d format %d start %"
|
|
|
|
GST_TIME_FORMAT " stop %" GST_TIME_FORMAT " position %"
|
|
|
|
GST_TIME_FORMAT, update, format, GST_TIME_ARGS (start),
|
|
|
|
GST_TIME_ARGS (stop), GST_TIME_ARGS (position));
|
2009-06-05 15:43:49 +00:00
|
|
|
convert_error:
|
2009-06-05 15:53:16 +00:00
|
|
|
res = gst_pad_push_event (mpeg_dec->src, event);
|
2009-06-05 15:43:49 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2009-04-26 21:20:30 +00:00
|
|
|
default:
|
|
|
|
res = gst_pad_event_default (pad, event);
|
|
|
|
}
|
|
|
|
|
2009-06-06 22:55:55 +00:00
|
|
|
done:
|
|
|
|
gst_object_unref (mpeg_dec);
|
|
|
|
|
2009-04-26 21:20:30 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-04-27 18:50:11 +00:00
|
|
|
static GstStateChangeReturn
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_change_state (GstElement * element, GstStateChange transition)
|
2009-04-27 18:50:11 +00:00
|
|
|
{
|
2009-06-05 19:46:08 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec;
|
2009-05-05 15:15:33 +00:00
|
|
|
GstStateChangeReturn ret;
|
2009-04-27 18:50:11 +00:00
|
|
|
|
2009-06-05 19:46:08 +00:00
|
|
|
mpeg_dec = GST_VDP_MPEG_DEC (element);
|
2009-04-27 18:50:11 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2009-06-04 17:17:14 +00:00
|
|
|
mpeg_dec->device = gst_vdp_get_device (mpeg_dec->display_name);
|
2009-04-27 18:50:11 +00:00
|
|
|
break;
|
2009-05-05 15:15:33 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
2009-04-27 18:50:11 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_reset (mpeg_dec);
|
2009-04-27 18:50:11 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-05-05 15:15:33 +00:00
|
|
|
return ret;
|
2009-04-27 18:50:11 +00:00
|
|
|
}
|
|
|
|
|
2009-03-25 19:38:27 +00:00
|
|
|
/* GObject vmethod implementations */
|
|
|
|
|
|
|
|
static void
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_base_init (gpointer gclass)
|
2009-03-25 19:38:27 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
|
|
|
|
|
|
|
|
gst_element_class_set_details_simple (element_class,
|
2009-04-14 19:04:59 +00:00
|
|
|
"VDPAU Mpeg Decoder",
|
2009-03-25 19:38:27 +00:00
|
|
|
"Decoder",
|
|
|
|
"decode mpeg stream with vdpau",
|
|
|
|
"Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>");
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2009-06-04 17:17:14 +00:00
|
|
|
gst_static_pad_template_get (&sink_template));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&src_template));
|
2009-03-25 19:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize the vdpaumpegdecoder's class */
|
|
|
|
static void
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_class_init (GstVdpMpegDecClass * klass)
|
2009-03-25 19:38:27 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
2009-06-05 19:46:08 +00:00
|
|
|
gobject_class->finalize = gst_vdp_mpeg_dec_finalize;
|
|
|
|
gobject_class->set_property = gst_vdp_mpeg_dec_set_property;
|
|
|
|
gobject_class->get_property = gst_vdp_mpeg_dec_get_property;
|
2009-03-25 19:38:27 +00:00
|
|
|
|
2009-06-05 09:24:34 +00:00
|
|
|
gstelement_class->change_state =
|
2009-06-05 19:46:08 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_vdp_mpeg_dec_change_state);
|
2009-06-04 17:17:14 +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));
|
2009-03-25 19:38:27 +00:00
|
|
|
}
|
|
|
|
|
2009-03-31 20:53:40 +00:00
|
|
|
static void
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_init_info (VdpPictureInfoMPEG1Or2 * vdp_info)
|
2009-03-31 20:53:40 +00:00
|
|
|
{
|
|
|
|
vdp_info->forward_reference = VDP_INVALID_HANDLE;
|
|
|
|
vdp_info->backward_reference = VDP_INVALID_HANDLE;
|
|
|
|
vdp_info->slice_count = 0;
|
2009-04-15 16:17:54 +00:00
|
|
|
vdp_info->picture_structure = 3;
|
2009-03-31 20:53:40 +00:00
|
|
|
vdp_info->picture_coding_type = 0;
|
|
|
|
vdp_info->intra_dc_precision = 0;
|
2009-04-15 16:17:54 +00:00
|
|
|
vdp_info->frame_pred_frame_dct = 1;
|
2009-03-31 20:53:40 +00:00
|
|
|
vdp_info->concealment_motion_vectors = 0;
|
2009-04-15 16:17:54 +00:00
|
|
|
vdp_info->intra_vlc_format = 0;
|
|
|
|
vdp_info->alternate_scan = 0;
|
|
|
|
vdp_info->q_scale_type = 0;
|
|
|
|
vdp_info->top_field_first = 1;
|
2009-03-31 20:53:40 +00:00
|
|
|
}
|
|
|
|
|
2009-03-25 19:38:27 +00:00
|
|
|
static void
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_init (GstVdpMpegDec * mpeg_dec, GstVdpMpegDecClass * gclass)
|
2009-03-25 19:38:27 +00:00
|
|
|
{
|
2009-06-04 17:17:14 +00:00
|
|
|
mpeg_dec->src = gst_pad_new_from_static_template (&src_template, "src");
|
2009-06-09 21:14:26 +00:00
|
|
|
gst_pad_use_fixed_caps (mpeg_dec->src);
|
2009-06-05 15:43:49 +00:00
|
|
|
gst_pad_set_event_function (mpeg_dec->src,
|
2009-06-05 19:46:08 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_vdp_mpeg_dec_src_event));
|
2009-06-05 09:24:34 +00:00
|
|
|
gst_pad_set_query_function (mpeg_dec->src,
|
2009-06-05 19:46:08 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_vdp_mpeg_dec_src_query));
|
2009-06-05 09:17:16 +00:00
|
|
|
gst_pad_set_query_type_function (mpeg_dec->src,
|
2009-06-05 19:46:08 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_mpeg_dec_get_querytypes));
|
2009-06-04 17:17:14 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (mpeg_dec), mpeg_dec->src);
|
2009-03-31 20:53:40 +00:00
|
|
|
|
2009-06-04 17:17:14 +00:00
|
|
|
mpeg_dec->sink = gst_pad_new_from_static_template (&sink_template, "sink");
|
2009-06-05 09:24:34 +00:00
|
|
|
gst_pad_set_setcaps_function (mpeg_dec->sink,
|
2009-06-05 19:46:08 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_vdp_mpeg_dec_set_caps));
|
2009-06-05 09:24:34 +00:00
|
|
|
gst_pad_set_chain_function (mpeg_dec->sink,
|
2009-06-05 19:46:08 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_vdp_mpeg_dec_chain));
|
2009-06-05 09:24:34 +00:00
|
|
|
gst_pad_set_event_function (mpeg_dec->sink,
|
2009-06-05 19:46:08 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_vdp_mpeg_dec_sink_event));
|
2009-06-04 17:17:14 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (mpeg_dec), mpeg_dec->sink);
|
|
|
|
|
|
|
|
mpeg_dec->display_name = NULL;
|
2009-06-05 09:51:41 +00:00
|
|
|
mpeg_dec->adapter = gst_adapter_new ();
|
2009-03-31 20:53:40 +00:00
|
|
|
|
2009-06-05 09:51:41 +00:00
|
|
|
mpeg_dec->device = NULL;
|
|
|
|
mpeg_dec->decoder = VDP_INVALID_HANDLE;
|
2009-06-05 16:18:38 +00:00
|
|
|
mpeg_dec->vdp_info.forward_reference = VDP_INVALID_HANDLE;
|
|
|
|
mpeg_dec->vdp_info.backward_reference = VDP_INVALID_HANDLE;
|
2009-06-05 15:43:49 +00:00
|
|
|
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_reset (mpeg_dec);
|
2009-06-06 23:12:50 +00:00
|
|
|
|
|
|
|
mpeg_dec->mutex = g_mutex_new ();
|
2009-03-25 19:38:27 +00:00
|
|
|
}
|
|
|
|
|
2009-04-01 19:40:14 +00:00
|
|
|
static void
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_finalize (GObject * object)
|
2009-04-01 19:40:14 +00:00
|
|
|
{
|
2009-06-05 19:46:08 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec = (GstVdpMpegDec *) object;
|
2009-04-01 19:40:14 +00:00
|
|
|
|
|
|
|
g_object_unref (mpeg_dec->adapter);
|
2009-06-06 23:12:50 +00:00
|
|
|
g_mutex_free (mpeg_dec->mutex);
|
2009-04-01 19:40:14 +00:00
|
|
|
}
|
|
|
|
|
2009-03-25 19:38:27 +00:00
|
|
|
static void
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_set_property (GObject * object, guint prop_id,
|
2009-03-25 19:38:27 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2009-06-05 19:46:08 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (object);
|
2009-06-04 17:17:14 +00:00
|
|
|
|
2009-03-25 19:38:27 +00:00
|
|
|
switch (prop_id) {
|
2009-06-04 17:17:14 +00:00
|
|
|
case PROP_DISPLAY:
|
|
|
|
g_free (mpeg_dec->display_name);
|
|
|
|
mpeg_dec->display_name = g_value_dup_string (value);
|
|
|
|
break;
|
2009-03-25 19:38:27 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-05 19:46:08 +00:00
|
|
|
gst_vdp_mpeg_dec_get_property (GObject * object, guint prop_id,
|
2009-03-25 19:38:27 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2009-06-05 19:46:08 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (object);
|
2009-06-04 17:17:14 +00:00
|
|
|
|
2009-03-25 19:38:27 +00:00
|
|
|
switch (prop_id) {
|
2009-06-04 17:17:14 +00:00
|
|
|
case PROP_DISPLAY:
|
|
|
|
g_value_set_string (value, mpeg_dec->display_name);
|
|
|
|
break;
|
2009-03-25 19:38:27 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|