2010-06-09 13:43:43 +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
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-06-09 13:43:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-vdpaumpegdec
|
|
|
|
*
|
|
|
|
* FIXME:Describe vdpaumpegdec here.
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example launch line</title>
|
|
|
|
* |[
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 -v -m fakesrc ! vdpaumpegdec ! fakesink silent=TRUE
|
2010-06-09 13:43:43 +00:00
|
|
|
* ]|
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2010-09-01 21:47:21 +00:00
|
|
|
#include <config.h>
|
2010-06-09 13:43:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/base/gstbytereader.h>
|
|
|
|
#include <gst/base/gstbitreader.h>
|
2012-09-20 17:03:11 +00:00
|
|
|
#include <gst/codecparsers/gstmpegvideoparser.h>
|
|
|
|
#include <gst/codecparsers/gstmpegvideometa.h>
|
2010-06-09 13:43:43 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gstvdpmpegdec.h"
|
2012-09-20 17:03:11 +00:00
|
|
|
#include "gstvdpvideomemory.h"
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_vdp_mpeg_dec_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_vdp_mpeg_dec_debug
|
|
|
|
|
|
|
|
/* the capabilities of the inputs and outputs.
|
|
|
|
*
|
|
|
|
* describe the real formats here.
|
|
|
|
*/
|
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/mpeg, mpegversion = (int) [ 1, 2 ], "
|
|
|
|
"systemstream = (boolean) false")
|
|
|
|
);
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
#define DEBUG_INIT \
|
2010-06-09 13:43:43 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_vdp_mpeg_dec_debug, "vdpaumpegdec", 0, \
|
|
|
|
"VDPAU mpeg decoder");
|
2012-09-20 17:03:11 +00:00
|
|
|
#define gst_vdp_mpeg_dec_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstVdpMpegDec, gst_vdp_mpeg_dec, GST_TYPE_VDP_DECODER,
|
|
|
|
DEBUG_INIT);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
static void gst_vdp_mpeg_dec_init_info (VdpPictureInfoMPEG1Or2 * vdp_info);
|
|
|
|
|
|
|
|
#define SYNC_CODE_SIZE 3
|
|
|
|
|
|
|
|
static VdpDecoderProfile
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_vdp_mpeg_dec_get_profile (GstMpegVideoSequenceExt * hdr)
|
2010-06-09 13:43:43 +00:00
|
|
|
{
|
|
|
|
VdpDecoderProfile profile;
|
|
|
|
|
|
|
|
switch (hdr->profile) {
|
2012-09-20 17:03:11 +00:00
|
|
|
case GST_MPEG_VIDEO_PROFILE_SIMPLE:
|
2010-06-09 13:43:43 +00:00
|
|
|
profile = VDP_DECODER_PROFILE_MPEG2_SIMPLE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vdp_mpeg_dec_handle_picture_coding (GstVdpMpegDec * mpeg_dec,
|
2012-09-20 17:03:11 +00:00
|
|
|
GstMpegVideoPictureExt * pic_ext, GstVideoCodecFrame * frame)
|
2010-06-09 13:43:43 +00:00
|
|
|
{
|
|
|
|
VdpPictureInfoMPEG1Or2 *info;
|
2012-09-20 17:03:11 +00:00
|
|
|
#if 0
|
2010-06-09 13:43:43 +00:00
|
|
|
gint fields;
|
2012-09-20 17:03:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "Handling GstMpegVideoPictureExt");
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
info = &mpeg_dec->vdp_info;
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
/* FIXME : Set defaults when pic_ext isn't present */
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
memcpy (&mpeg_dec->vdp_info.f_code, &pic_ext->f_code, 4);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
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;
|
|
|
|
info->alternate_scan = pic_ext->alternate_scan;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
#if 0
|
2010-06-09 13:43:43 +00:00
|
|
|
fields = 2;
|
2012-09-20 17:03:11 +00:00
|
|
|
if (pic_ext->picture_structure == 3) {
|
2010-06-09 13:43:43 +00:00
|
|
|
if (mpeg_dec->stream_info.interlaced) {
|
2012-09-20 17:03:11 +00:00
|
|
|
if (pic_ext->progressive_frame == 0)
|
2010-06-09 13:43:43 +00:00
|
|
|
fields = 2;
|
2012-09-20 17:03:11 +00:00
|
|
|
if (pic_ext->progressive_frame == 0 && pic_ext->repeat_first_field == 0)
|
2010-06-09 13:43:43 +00:00
|
|
|
fields = 2;
|
2012-09-20 17:03:11 +00:00
|
|
|
if (pic_ext->progressive_frame == 1 && pic_ext->repeat_first_field == 1)
|
2010-06-09 13:43:43 +00:00
|
|
|
fields = 3;
|
|
|
|
} else {
|
2012-09-20 17:03:11 +00:00
|
|
|
if (pic_ext->repeat_first_field == 0)
|
2010-06-09 13:43:43 +00:00
|
|
|
fields = 2;
|
2012-09-20 17:03:11 +00:00
|
|
|
if (pic_ext->repeat_first_field == 1 && pic_ext->top_field_first == 0)
|
2010-06-09 13:43:43 +00:00
|
|
|
fields = 4;
|
2012-09-20 17:03:11 +00:00
|
|
|
if (pic_ext->repeat_first_field == 1 && pic_ext->top_field_first == 1)
|
2010-06-09 13:43:43 +00:00
|
|
|
fields = 6;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
fields = 1;
|
2012-09-20 17:03:11 +00:00
|
|
|
#endif
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
if (pic_ext->top_field_first)
|
|
|
|
GST_FIXME ("Set TFF on outgoing buffer");
|
|
|
|
#if 0
|
|
|
|
GST_VIDEO_FRAME_FLAG_SET (frame, GST_VIDEO_FRAME_FLAG_TFF);
|
|
|
|
#endif
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_vdp_mpeg_dec_handle_picture (GstVdpMpegDec * mpeg_dec,
|
|
|
|
GstMpegVideoPictureHdr * pic_hdr)
|
2010-06-09 13:43:43 +00:00
|
|
|
{
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "Handling GstMpegVideoPictureHdr");
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
mpeg_dec->vdp_info.picture_coding_type = pic_hdr->pic_type;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
if (mpeg_dec->stream_info.version == 1) {
|
|
|
|
mpeg_dec->vdp_info.full_pel_forward_vector =
|
2012-09-20 17:03:11 +00:00
|
|
|
pic_hdr->full_pel_forward_vector;
|
2010-06-09 13:43:43 +00:00
|
|
|
mpeg_dec->vdp_info.full_pel_backward_vector =
|
2012-09-20 17:03:11 +00:00
|
|
|
pic_hdr->full_pel_backward_vector;
|
|
|
|
memcpy (&mpeg_dec->vdp_info.f_code, &pic_hdr->f_code, 4);
|
2010-06-09 13:43:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
mpeg_dec->frame_nr = mpeg_dec->gop_frame + pic_hdr->tsn;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_vdp_mpeg_dec_set_format (GstVideoDecoder * decoder,
|
|
|
|
GstVideoCodecState * state)
|
2010-06-09 13:43:43 +00:00
|
|
|
{
|
2012-09-20 17:03:11 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec = (GstVdpMpegDec *) decoder;
|
|
|
|
|
|
|
|
/* FIXME : Check the hardware can handle the level/profile */
|
|
|
|
if (mpeg_dec->input_state)
|
|
|
|
gst_video_codec_state_unref (mpeg_dec->input_state);
|
|
|
|
mpeg_dec->input_state = gst_video_codec_state_ref (state);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static gboolean
|
|
|
|
gst_vdp_mpeg_dec_handle_gop (GstVdpMpegDec * mpeg_dec, const guint8 * data,
|
|
|
|
gsize size, guint offset)
|
|
|
|
{
|
|
|
|
GstMpegVideoGop gop;
|
2010-06-09 13:43:43 +00:00
|
|
|
GstClockTime time;
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
if (!gst_mpeg_video_parse_gop (&gop, data, size, offset))
|
2010-06-09 13:43:43 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
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->stream_info.fps_n,
|
|
|
|
mpeg_dec->stream_info.fps_d * GST_SECOND) + gop.frame;
|
|
|
|
|
|
|
|
if (mpeg_dec->state == GST_VDP_MPEG_DEC_STATE_NEED_GOP)
|
|
|
|
mpeg_dec->state = GST_VDP_MPEG_DEC_STATE_NEED_DATA;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2012-09-20 17:03:11 +00:00
|
|
|
#endif
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vdp_mpeg_dec_handle_quant_matrix (GstVdpMpegDec * mpeg_dec,
|
2012-09-20 17:03:11 +00:00
|
|
|
GstMpegVideoQuantMatrixExt * qm)
|
2010-06-09 13:43:43 +00:00
|
|
|
{
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "Handling GstMpegVideoQuantMatrixExt");
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
memcpy (&mpeg_dec->vdp_info.intra_quantizer_matrix,
|
2012-09-20 17:03:11 +00:00
|
|
|
&qm->intra_quantiser_matrix, 64);
|
2010-06-09 13:43:43 +00:00
|
|
|
memcpy (&mpeg_dec->vdp_info.non_intra_quantizer_matrix,
|
2012-09-20 17:03:11 +00:00
|
|
|
&qm->non_intra_quantiser_matrix, 64);
|
|
|
|
|
2010-06-09 13:43:43 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-22 22:28:49 +00:00
|
|
|
static GstFlowReturn
|
2010-06-09 13:43:43 +00:00
|
|
|
gst_vdp_mpeg_dec_handle_sequence (GstVdpMpegDec * mpeg_dec,
|
2012-09-20 17:03:11 +00:00
|
|
|
GstMpegVideoSequenceHdr * hdr, GstMpegVideoSequenceExt * ext)
|
2010-06-09 13:43:43 +00:00
|
|
|
{
|
2012-09-20 17:03:11 +00:00
|
|
|
GstFlowReturn ret;
|
|
|
|
GstVideoDecoder *video_decoder = GST_VIDEO_DECODER (mpeg_dec);
|
2010-06-09 13:43:43 +00:00
|
|
|
GstVdpMpegStreamInfo stream_info;
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "Handling GstMpegVideoSequenceHdr");
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
memcpy (&mpeg_dec->vdp_info.intra_quantizer_matrix,
|
2012-09-20 17:03:11 +00:00
|
|
|
&hdr->intra_quantizer_matrix, 64);
|
2010-06-09 13:43:43 +00:00
|
|
|
memcpy (&mpeg_dec->vdp_info.non_intra_quantizer_matrix,
|
2012-09-20 17:03:11 +00:00
|
|
|
&hdr->non_intra_quantizer_matrix, 64);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
stream_info.width = hdr->width;
|
|
|
|
stream_info.height = hdr->height;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
stream_info.fps_n = hdr->fps_n;
|
|
|
|
stream_info.fps_d = hdr->fps_d;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
stream_info.par_n = hdr->par_w;
|
|
|
|
stream_info.par_d = hdr->par_h;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
stream_info.interlaced = FALSE;
|
|
|
|
stream_info.version = 1;
|
|
|
|
stream_info.profile = VDP_DECODER_PROFILE_MPEG1;
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
if (ext) {
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "Handling GstMpegVideoSequenceExt");
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
/* FIXME : isn't this already processed by mpegvideoparse ? */
|
|
|
|
stream_info.fps_n *= (ext->fps_n_ext + 1);
|
|
|
|
stream_info.fps_d *= (ext->fps_d_ext + 1);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
stream_info.width += (ext->horiz_size_ext << 12);
|
|
|
|
stream_info.height += (ext->vert_size_ext << 12);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
stream_info.interlaced = !ext->progressive;
|
2010-06-09 13:43:43 +00:00
|
|
|
stream_info.version = 2;
|
2012-09-20 17:03:11 +00:00
|
|
|
stream_info.profile = gst_vdp_mpeg_dec_get_profile (ext);
|
2010-06-09 13:43:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "Setting output state to %dx%d",
|
|
|
|
stream_info.width, stream_info.height);
|
|
|
|
mpeg_dec->output_state =
|
|
|
|
gst_video_decoder_set_output_state (video_decoder, GST_VIDEO_FORMAT_YV12,
|
|
|
|
stream_info.width, stream_info.height, mpeg_dec->input_state);
|
|
|
|
if (stream_info.interlaced)
|
|
|
|
mpeg_dec->output_state->info.interlace_mode =
|
|
|
|
GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
|
|
|
|
gst_video_decoder_negotiate (video_decoder);
|
|
|
|
|
|
|
|
ret = gst_vdp_decoder_init_decoder (GST_VDP_DECODER (mpeg_dec),
|
|
|
|
stream_info.profile, 2, mpeg_dec->output_state);
|
2010-07-22 22:28:49 +00:00
|
|
|
mpeg_dec->state = GST_VDP_MPEG_DEC_STATE_NEED_DATA;
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
return ret;
|
2010-06-09 13:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_vdp_mpeg_dec_handle_frame (GstVideoDecoder * video_decoder,
|
|
|
|
GstVideoCodecFrame * frame)
|
2010-06-09 13:43:43 +00:00
|
|
|
{
|
2012-09-20 17:03:11 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (video_decoder);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
VdpPictureInfoMPEG1Or2 *info;
|
2012-09-20 17:03:11 +00:00
|
|
|
GstMpegVideoMeta *mpeg_meta;
|
|
|
|
GstVdpVideoMemory *vmem;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2011-03-27 17:47:43 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2010-06-09 13:43:43 +00:00
|
|
|
VdpBitstreamBuffer vbit[1];
|
2012-09-20 17:03:11 +00:00
|
|
|
GstMapInfo mapinfo;
|
2010-07-22 22:28:49 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
/* FIXME : Specify in sink query that we need the mpeg video meta */
|
2010-07-22 22:28:49 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
/* Parse all incoming data from the frame */
|
|
|
|
mpeg_meta = gst_buffer_get_mpeg_video_meta (frame->input_buffer);
|
|
|
|
if (!mpeg_meta)
|
|
|
|
goto no_meta;
|
|
|
|
|
|
|
|
/* GST_MPEG_VIDEO_PACKET_SEQUENCE */
|
|
|
|
if (mpeg_meta->sequencehdr) {
|
|
|
|
ret =
|
|
|
|
gst_vdp_mpeg_dec_handle_sequence (mpeg_dec, mpeg_meta->sequencehdr,
|
|
|
|
mpeg_meta->sequenceext);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto sequence_parse_fail;
|
2010-06-09 13:43:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
if (mpeg_dec->state == GST_VDP_MPEG_DEC_STATE_NEED_SEQUENCE)
|
|
|
|
goto need_sequence;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
/* GST_MPEG_VIDEO_PACKET_PICTURE */
|
|
|
|
if (mpeg_meta->pichdr)
|
|
|
|
gst_vdp_mpeg_dec_handle_picture (mpeg_dec, mpeg_meta->pichdr);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
/* GST_MPEG_VIDEO_PACKET_EXT_PICTURE_CODING */
|
|
|
|
if (mpeg_meta->picext)
|
|
|
|
gst_vdp_mpeg_dec_handle_picture_coding (mpeg_dec, mpeg_meta->picext, frame);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
/* GST_MPEG_VIDEO_PACKET_GOP */
|
|
|
|
/* if (mpeg_meta->gop) */
|
|
|
|
/* GST_FIXME_OBJECT (mpeg_dec, "Handle GOP !"); */
|
|
|
|
/* gst_vdp_mpeg_dec_handle_gop (mpeg_dec, mpeg_frame.gop); */
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
/* GST_MPEG_VIDEO_PACKET_EXT_QUANT_MATRIX */
|
|
|
|
if (mpeg_meta->quantext)
|
|
|
|
gst_vdp_mpeg_dec_handle_quant_matrix (mpeg_dec, mpeg_meta->quantext);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
info = &mpeg_dec->vdp_info;
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
info->slice_count = mpeg_meta->num_slices;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "picture coding type %d",
|
|
|
|
info->picture_coding_type);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
/* check if we can decode the frame */
|
|
|
|
if (info->picture_coding_type != GST_MPEG_VIDEO_PICTURE_TYPE_I
|
|
|
|
&& info->backward_reference == VDP_INVALID_HANDLE)
|
|
|
|
goto need_i_frame;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
if (info->picture_coding_type == GST_MPEG_VIDEO_PICTURE_TYPE_B
|
|
|
|
&& info->forward_reference == VDP_INVALID_HANDLE)
|
|
|
|
goto need_non_b_frame;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
if (info->picture_coding_type != GST_MPEG_VIDEO_PICTURE_TYPE_B) {
|
2010-06-09 13:43:43 +00:00
|
|
|
if (info->backward_reference != VDP_INVALID_HANDLE) {
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "Pushing B frame");
|
|
|
|
ret = gst_video_decoder_finish_frame (video_decoder, mpeg_dec->b_frame);
|
2010-06-09 13:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (info->forward_reference != VDP_INVALID_HANDLE) {
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "Releasing no-longer needed forward frame");
|
|
|
|
gst_video_codec_frame_unref (mpeg_dec->f_frame);
|
2010-06-09 13:43:43 +00:00
|
|
|
info->forward_reference = VDP_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->forward_reference = info->backward_reference;
|
|
|
|
mpeg_dec->f_frame = mpeg_dec->b_frame;
|
|
|
|
|
|
|
|
info->backward_reference = VDP_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto exit_after_b_frame;
|
2011-03-27 17:47:43 +00:00
|
|
|
|
2010-07-22 22:28:49 +00:00
|
|
|
/* decode */
|
2012-09-20 17:03:11 +00:00
|
|
|
if (!gst_buffer_map (frame->input_buffer, &mapinfo, GST_MAP_READ))
|
|
|
|
goto map_fail;
|
|
|
|
|
2010-07-22 22:28:49 +00:00
|
|
|
vbit[0].struct_version = VDP_BITSTREAM_BUFFER_VERSION;
|
2012-09-20 17:03:11 +00:00
|
|
|
vbit[0].bitstream = mapinfo.data + mpeg_meta->slice_offset;
|
|
|
|
vbit[0].bitstream_bytes = mapinfo.size - mpeg_meta->slice_offset;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2010-07-22 22:28:49 +00:00
|
|
|
ret = gst_vdp_decoder_render (GST_VDP_DECODER (mpeg_dec),
|
2012-09-20 17:03:11 +00:00
|
|
|
(VdpPictureInfo *) info, 1, vbit, frame);
|
|
|
|
|
|
|
|
gst_buffer_unmap (frame->input_buffer, &mapinfo);
|
|
|
|
|
2010-07-22 22:28:49 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
2012-09-20 17:03:11 +00:00
|
|
|
goto render_fail;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
vmem = (GstVdpVideoMemory *) gst_buffer_get_memory (frame->output_buffer, 0);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
if (info->picture_coding_type == GST_MPEG_VIDEO_PICTURE_TYPE_B) {
|
|
|
|
ret = gst_video_decoder_finish_frame (video_decoder, frame);
|
2010-06-09 13:43:43 +00:00
|
|
|
} else {
|
2012-09-20 17:03:11 +00:00
|
|
|
info->backward_reference = vmem->surface;
|
|
|
|
mpeg_dec->b_frame = gst_video_codec_frame_ref (frame);
|
2010-06-09 13:43:43 +00:00
|
|
|
}
|
|
|
|
|
2010-09-06 15:42:15 +00:00
|
|
|
return ret;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
/* EARLY EXIT */
|
|
|
|
need_sequence:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec, "Drop frame since we haven't found a "
|
|
|
|
"GST_MPEG_VIDEO_PACKET_SEQUENCE yet");
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_video_decoder_finish_frame (video_decoder, frame);
|
|
|
|
return GST_FLOW_OK;
|
2010-06-09 13:43:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
need_i_frame:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec,
|
|
|
|
"Drop frame since we haven't got an I_FRAME yet");
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_video_decoder_finish_frame (video_decoder, frame);
|
|
|
|
return GST_FLOW_OK;
|
2010-06-09 13:43:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
need_non_b_frame:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (mpeg_dec,
|
|
|
|
"Drop frame since we haven't got two non B_FRAME yet");
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_video_decoder_finish_frame (video_decoder, frame);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
/* ERRORS */
|
|
|
|
no_meta:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (video_decoder,
|
|
|
|
"Input buffer does not have MpegVideo GstMeta");
|
|
|
|
gst_video_decoder_drop_frame (video_decoder, frame);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
sequence_parse_fail:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (video_decoder, "Failed to handle sequence header");
|
|
|
|
gst_video_decoder_finish_frame (video_decoder, frame);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
exit_after_b_frame:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (video_decoder, "Leaving after pushing B frame");
|
|
|
|
gst_video_decoder_finish_frame (video_decoder, frame);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
map_fail:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (video_decoder, "Failed to map input buffer");
|
|
|
|
gst_video_decoder_drop_frame (video_decoder, frame);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
render_fail:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (video_decoder, "Error when rendering the frame");
|
|
|
|
gst_video_decoder_drop_frame (video_decoder, frame);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-06-09 13:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2013-08-15 13:46:58 +00:00
|
|
|
gst_vdp_mpeg_dec_flush (GstVideoDecoder * video_decoder)
|
2010-06-09 13:43:43 +00:00
|
|
|
{
|
2012-09-20 17:03:11 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (video_decoder);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
if (mpeg_dec->vdp_info.forward_reference != VDP_INVALID_HANDLE)
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_video_codec_frame_unref (mpeg_dec->f_frame);
|
2010-06-09 13:43:43 +00:00
|
|
|
if (mpeg_dec->vdp_info.backward_reference != VDP_INVALID_HANDLE)
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_video_codec_frame_unref (mpeg_dec->b_frame);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
gst_vdp_mpeg_dec_init_info (&mpeg_dec->vdp_info);
|
|
|
|
|
|
|
|
mpeg_dec->prev_packet = -1;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_vdp_mpeg_dec_start (GstVideoDecoder * video_decoder)
|
2010-06-09 13:43:43 +00:00
|
|
|
{
|
2012-09-20 17:03:11 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (video_decoder);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (video_decoder, "Starting");
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
gst_vdp_mpeg_dec_init_info (&mpeg_dec->vdp_info);
|
|
|
|
|
|
|
|
mpeg_dec->decoder = VDP_INVALID_HANDLE;
|
|
|
|
mpeg_dec->state = GST_VDP_MPEG_DEC_STATE_NEED_SEQUENCE;
|
|
|
|
|
|
|
|
memset (&mpeg_dec->stream_info, 0, sizeof (GstVdpMpegStreamInfo));
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
return GST_VIDEO_DECODER_CLASS (parent_class)->start (video_decoder);
|
2010-06-09 13:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_vdp_mpeg_dec_stop (GstVideoDecoder * video_decoder)
|
2010-06-09 13:43:43 +00:00
|
|
|
{
|
2012-09-20 17:03:11 +00:00
|
|
|
GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (video_decoder);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
|
|
|
if (mpeg_dec->vdp_info.forward_reference != VDP_INVALID_HANDLE)
|
|
|
|
mpeg_dec->vdp_info.forward_reference = VDP_INVALID_HANDLE;
|
|
|
|
if (mpeg_dec->vdp_info.backward_reference != VDP_INVALID_HANDLE)
|
|
|
|
mpeg_dec->vdp_info.backward_reference = VDP_INVALID_HANDLE;
|
|
|
|
|
|
|
|
mpeg_dec->state = GST_VDP_MPEG_DEC_STATE_NEED_SEQUENCE;
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
return GST_VIDEO_DECODER_CLASS (parent_class)->stop (video_decoder);
|
2010-06-09 13:43:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
/* initialize the vdpaumpegdecoder's class */
|
2010-06-09 13:43:43 +00:00
|
|
|
static void
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_vdp_mpeg_dec_class_init (GstVdpMpegDecClass * klass)
|
2010-06-09 13:43:43 +00:00
|
|
|
{
|
2012-09-20 17:03:11 +00:00
|
|
|
GstElementClass *element_class;
|
|
|
|
GstVideoDecoderClass *video_decoder_class;
|
|
|
|
|
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
video_decoder_class = GST_VIDEO_DECODER_CLASS (klass);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class,
|
2010-06-09 13:43:43 +00:00
|
|
|
"VDPAU Mpeg Decoder",
|
|
|
|
"Decoder",
|
|
|
|
"Decode mpeg stream with vdpau",
|
|
|
|
"Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>");
|
|
|
|
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (element_class, &sink_template);
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
video_decoder_class->start = gst_vdp_mpeg_dec_start;
|
|
|
|
video_decoder_class->stop = gst_vdp_mpeg_dec_stop;
|
2013-08-15 13:46:58 +00:00
|
|
|
video_decoder_class->flush = gst_vdp_mpeg_dec_flush;
|
2010-06-09 13:43:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
video_decoder_class->handle_frame = gst_vdp_mpeg_dec_handle_frame;
|
|
|
|
video_decoder_class->set_format = gst_vdp_mpeg_dec_set_format;
|
2010-06-09 13:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vdp_mpeg_dec_init_info (VdpPictureInfoMPEG1Or2 * vdp_info)
|
|
|
|
{
|
|
|
|
vdp_info->forward_reference = VDP_INVALID_HANDLE;
|
|
|
|
vdp_info->backward_reference = VDP_INVALID_HANDLE;
|
|
|
|
vdp_info->slice_count = 0;
|
|
|
|
vdp_info->picture_structure = 3;
|
|
|
|
vdp_info->picture_coding_type = 0;
|
|
|
|
vdp_info->intra_dc_precision = 0;
|
|
|
|
vdp_info->frame_pred_frame_dct = 1;
|
|
|
|
vdp_info->concealment_motion_vectors = 0;
|
|
|
|
vdp_info->intra_vlc_format = 0;
|
|
|
|
vdp_info->alternate_scan = 0;
|
|
|
|
vdp_info->q_scale_type = 0;
|
|
|
|
vdp_info->top_field_first = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_vdp_mpeg_dec_init (GstVdpMpegDec * mpeg_dec)
|
2010-06-09 13:43:43 +00:00
|
|
|
{
|
|
|
|
}
|