2009-07-01 17:55:12 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 David Schleef <ds@schleef.org>
|
2011-03-30 07:15:13 +00:00
|
|
|
* Copyright (C) 2011 Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>.
|
|
|
|
* Copyright (C) 2011 Nokia Corporation. All rights reserved.
|
|
|
|
* Contact: Stefan Kost <stefan.kost@nokia.com>
|
2009-07-01 17:55:12 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstbasevideodecoder
|
|
|
|
* @short_description: Base class for video decoders
|
|
|
|
* @see_also: #GstBaseTransform
|
|
|
|
*
|
|
|
|
* This base class is for video decoders turning encoded data into raw video
|
|
|
|
* frames.
|
|
|
|
*
|
|
|
|
* GstBaseVideoDecoder and subclass should cooperate as follows.
|
|
|
|
* <orderedlist>
|
|
|
|
* <listitem>
|
|
|
|
* <itemizedlist><title>Configuration</title>
|
|
|
|
* <listitem><para>
|
|
|
|
* Initially, GstBaseVideoDecoder calls @start when the decoder element
|
|
|
|
* is activated, which allows subclass to perform any global setup.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* GstBaseVideoDecoder calls @set_format to inform subclass of caps
|
|
|
|
* describing input video data that it is about to receive, including
|
|
|
|
* possibly configuration data.
|
|
|
|
* While unlikely, it might be called more than once, if changing input
|
|
|
|
* parameters require reconfiguration.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* GstBaseVideoDecoder calls @stop at end of all processing.
|
|
|
|
* </para></listitem>
|
|
|
|
* </itemizedlist>
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* <itemizedlist>
|
|
|
|
* <title>Data processing</title>
|
|
|
|
* <listitem><para>
|
|
|
|
* Base class gathers input data, and optionally allows subclass
|
|
|
|
* to parse this into subsequently manageable chunks, typically
|
|
|
|
* corresponding to and referred to as 'frames'.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* Input frame is provided to subclass' @handle_frame.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* If codec processing results in decoded data, subclass should call
|
|
|
|
* @gst_base_video_decoder_finish_frame to have decoded data pushed
|
|
|
|
* downstream.
|
|
|
|
* </para></listitem>
|
|
|
|
* </itemizedlist>
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* <itemizedlist><title>Shutdown phase</title>
|
|
|
|
* <listitem><para>
|
|
|
|
* GstBaseVideoDecoder class calls @stop to inform the subclass that data
|
|
|
|
* parsing will be stopped.
|
|
|
|
* </para></listitem>
|
|
|
|
* </itemizedlist>
|
|
|
|
* </listitem>
|
|
|
|
* </orderedlist>
|
|
|
|
*
|
|
|
|
* Subclass is responsible for providing pad template caps for
|
|
|
|
* source and sink pads. The pads need to be named "sink" and "src". It also
|
|
|
|
* needs to set the fixed caps on srcpad, when the format is ensured. This
|
|
|
|
* is typically when base class calls subclass' @set_format function, though
|
|
|
|
* it might be delayed until calling @gst_base_video_decoder_finish_frame.
|
|
|
|
*
|
|
|
|
* Subclass is also responsible for providing (presentation) timestamps
|
|
|
|
* (likely based on corresponding input ones). If that is not applicable
|
|
|
|
* or possible, baseclass provides limited framerate based interpolation.
|
|
|
|
*
|
|
|
|
* Similarly, the baseclass provides some limited (legacy) seeking support
|
|
|
|
* (upon explicit subclass request), as full-fledged support
|
|
|
|
* should rather be left to upstream demuxer, parser or alike. This simple
|
|
|
|
* approach caters for seeking and duration reporting using estimated input
|
|
|
|
* bitrates.
|
|
|
|
*
|
2011-03-31 12:47:55 +00:00
|
|
|
* Baseclass provides some support for reverse playback, in particular
|
|
|
|
* in case incoming data is not packetized or upstream does not provide
|
|
|
|
* fragments on keyframe boundaries. However, subclass should then be prepared
|
|
|
|
* for the parsing and frame processing stage to occur separately (rather
|
|
|
|
* than otherwise the latter immediately following the former),
|
|
|
|
* and should ensure the parsing stage properly marks keyframes or rely on
|
|
|
|
* upstream to do so properly for incoming data.
|
|
|
|
*
|
2011-03-30 07:15:13 +00:00
|
|
|
* Things that subclass need to take care of:
|
|
|
|
* <itemizedlist>
|
|
|
|
* <listitem><para>Provide pad templates</para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* Set source pad caps when appropriate
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* Configure some baseclass behaviour parameters.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* Optionally parse input data, if it is not considered packetized.
|
|
|
|
* Parse sync is obtained either by providing baseclass with a
|
|
|
|
* mask and pattern or a custom @scan_for_sync. When sync is established,
|
|
|
|
* @parse_data should invoke @gst_base_video_decoder_add_to_frame and
|
|
|
|
* @gst_base_video_decoder_have_frame as appropriate.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* Accept data in @handle_frame and provide decoded results to
|
|
|
|
* @gst_base_video_decoder_finish_frame.
|
|
|
|
* </para></listitem>
|
|
|
|
* </itemizedlist>
|
|
|
|
*/
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstbasevideodecoder.h"
|
2011-07-09 09:40:17 +00:00
|
|
|
#include "gstbasevideoutils.h"
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2010-06-02 23:01:28 +00:00
|
|
|
GST_DEBUG_CATEGORY (basevideodecoder_debug);
|
|
|
|
#define GST_CAT_DEFAULT basevideodecoder_debug
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
static void gst_base_video_decoder_finalize (GObject * object);
|
|
|
|
|
2011-11-03 12:56:49 +00:00
|
|
|
static gboolean gst_base_video_decoder_setcaps (GstBaseVideoDecoder * vdec,
|
2009-07-01 17:55:12 +00:00
|
|
|
GstCaps * caps);
|
|
|
|
static gboolean gst_base_video_decoder_sink_event (GstPad * pad,
|
|
|
|
GstEvent * event);
|
|
|
|
static gboolean gst_base_video_decoder_src_event (GstPad * pad,
|
|
|
|
GstEvent * event);
|
|
|
|
static GstFlowReturn gst_base_video_decoder_chain (GstPad * pad,
|
|
|
|
GstBuffer * buf);
|
|
|
|
static gboolean gst_base_video_decoder_sink_query (GstPad * pad,
|
|
|
|
GstQuery * query);
|
|
|
|
static GstStateChangeReturn gst_base_video_decoder_change_state (GstElement *
|
|
|
|
element, GstStateChange transition);
|
|
|
|
static gboolean gst_base_video_decoder_src_query (GstPad * pad,
|
|
|
|
GstQuery * query);
|
|
|
|
static void gst_base_video_decoder_reset (GstBaseVideoDecoder *
|
2011-03-29 13:41:08 +00:00
|
|
|
base_video_decoder, gboolean full);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_video_decoder_have_frame_2 (GstBaseVideoDecoder * base_video_decoder);
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
static guint64
|
|
|
|
gst_base_video_decoder_get_timestamp (GstBaseVideoDecoder * base_video_decoder,
|
|
|
|
int picture_number);
|
|
|
|
static guint64
|
|
|
|
gst_base_video_decoder_get_field_timestamp (GstBaseVideoDecoder *
|
|
|
|
base_video_decoder, int field_offset);
|
2010-06-01 22:54:51 +00:00
|
|
|
static guint64 gst_base_video_decoder_get_field_duration (GstBaseVideoDecoder *
|
|
|
|
base_video_decoder, int n_fields);
|
2011-10-04 12:27:32 +00:00
|
|
|
static GstVideoFrameState *gst_base_video_decoder_new_frame (GstBaseVideoDecoder
|
|
|
|
* base_video_decoder);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-31 12:47:55 +00:00
|
|
|
static void gst_base_video_decoder_clear_queues (GstBaseVideoDecoder * dec);
|
|
|
|
|
2011-10-04 12:27:32 +00:00
|
|
|
#define gst_base_video_decoder_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstBaseVideoDecoder, gst_base_video_decoder,
|
|
|
|
GST_TYPE_BASE_VIDEO_CODEC);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_base_video_decoder_class_init (GstBaseVideoDecoderClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
gstelement_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->finalize = gst_base_video_decoder_finalize;
|
|
|
|
|
2011-04-03 20:32:20 +00:00
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_video_decoder_change_state);
|
2011-10-04 12:27:32 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (basevideodecoder_debug, "basevideodecoder", 0,
|
|
|
|
"Base Video Decoder");
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-10-04 12:27:32 +00:00
|
|
|
gst_base_video_decoder_init (GstBaseVideoDecoder * base_video_decoder)
|
2009-07-01 17:55:12 +00:00
|
|
|
{
|
|
|
|
GstPad *pad;
|
|
|
|
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "gst_base_video_decoder_init");
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
pad = GST_BASE_VIDEO_CODEC_SINK_PAD (base_video_decoder);
|
|
|
|
|
2011-04-03 20:32:20 +00:00
|
|
|
gst_pad_set_chain_function (pad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_video_decoder_chain));
|
|
|
|
gst_pad_set_event_function (pad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_video_decoder_sink_event));
|
|
|
|
gst_pad_set_query_function (pad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_video_decoder_sink_query));
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
pad = GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_decoder);
|
|
|
|
|
2011-04-03 20:32:20 +00:00
|
|
|
gst_pad_set_event_function (pad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_video_decoder_src_event));
|
|
|
|
gst_pad_set_query_function (pad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_video_decoder_src_query));
|
2010-06-01 22:54:51 +00:00
|
|
|
gst_pad_use_fixed_caps (pad);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
base_video_decoder->input_adapter = gst_adapter_new ();
|
|
|
|
base_video_decoder->output_adapter = gst_adapter_new ();
|
|
|
|
|
2011-03-29 13:41:08 +00:00
|
|
|
gst_base_video_decoder_reset (base_video_decoder, TRUE);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
base_video_decoder->sink_clipping = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-06-28 09:47:25 +00:00
|
|
|
static gboolean
|
|
|
|
gst_base_video_decoder_push_src_event (GstBaseVideoDecoder * decoder,
|
|
|
|
GstEvent * event)
|
|
|
|
{
|
|
|
|
/* Forward non-serialized events and EOS/FLUSH_STOP immediately.
|
|
|
|
* For EOS this is required because no buffer or serialized event
|
|
|
|
* will come after EOS and nothing could trigger another
|
|
|
|
* _finish_frame() call. *
|
|
|
|
* If the subclass handles sending of EOS manually it can return
|
|
|
|
* _DROPPED from ::finish() and all other subclasses should have
|
|
|
|
* decoded/flushed all remaining data before this
|
|
|
|
*
|
|
|
|
* For FLUSH_STOP this is required because it is expected
|
|
|
|
* to be forwarded immediately and no buffers are queued anyway.
|
|
|
|
*/
|
|
|
|
if (!GST_EVENT_IS_SERIALIZED (event)
|
|
|
|
|| GST_EVENT_TYPE (event) == GST_EVENT_EOS
|
|
|
|
|| GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_STOP)
|
|
|
|
return gst_pad_push_event (decoder->base_video_codec.srcpad, event);
|
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (decoder);
|
2011-06-28 09:47:25 +00:00
|
|
|
decoder->current_frame_events =
|
|
|
|
g_list_prepend (decoder->current_frame_events, event);
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (decoder);
|
2011-06-28 09:47:25 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
static gboolean
|
2011-11-03 12:56:49 +00:00
|
|
|
gst_base_video_decoder_setcaps (GstBaseVideoDecoder * base_video_decoder,
|
|
|
|
GstCaps * caps)
|
2009-07-01 17:55:12 +00:00
|
|
|
{
|
|
|
|
GstBaseVideoDecoderClass *base_video_decoder_class;
|
|
|
|
GstStructure *structure;
|
|
|
|
const GValue *codec_data;
|
2011-07-11 06:54:53 +00:00
|
|
|
GstVideoState state;
|
2010-06-01 22:54:51 +00:00
|
|
|
gboolean ret = TRUE;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
base_video_decoder_class =
|
|
|
|
GST_BASE_VIDEO_DECODER_GET_CLASS (base_video_decoder);
|
|
|
|
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "setcaps %" GST_PTR_FORMAT, caps);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
|
|
|
|
2011-07-11 06:54:53 +00:00
|
|
|
memset (&state, 0, sizeof (state));
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2011-07-11 06:54:53 +00:00
|
|
|
state.caps = gst_caps_ref (caps);
|
2011-06-27 07:41:40 +00:00
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
2011-11-03 12:56:49 +00:00
|
|
|
/* FIXME : Add have_{width_height|framerate|par} fields to
|
|
|
|
* GstVideoState so we can make better decisions
|
|
|
|
*/
|
2011-10-05 10:53:07 +00:00
|
|
|
|
2011-11-03 12:56:49 +00:00
|
|
|
gst_structure_get_int (structure, "width", &state.width);
|
|
|
|
gst_structure_get_int (structure, "height", &state.height);
|
|
|
|
|
|
|
|
if (!gst_structure_get_fraction (structure, "framerate", &state.fps_n,
|
|
|
|
&state.fps_d)) {
|
2011-07-11 06:54:53 +00:00
|
|
|
state.fps_n = 0;
|
|
|
|
state.fps_d = 1;
|
2011-04-01 20:12:30 +00:00
|
|
|
}
|
2011-11-03 12:56:49 +00:00
|
|
|
|
|
|
|
if (!gst_structure_get_fraction (structure, "pixel-aspect-ratio",
|
2011-07-11 06:54:53 +00:00
|
|
|
&state.par_n, &state.par_d)) {
|
|
|
|
state.par_n = 0;
|
|
|
|
state.par_d = 1;
|
2011-04-01 20:12:30 +00:00
|
|
|
}
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2011-07-11 06:54:53 +00:00
|
|
|
state.have_interlaced =
|
2011-11-03 12:56:49 +00:00
|
|
|
gst_structure_get_boolean (structure, "interlaced", &state.interlaced);
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
codec_data = gst_structure_get_value (structure, "codec_data");
|
|
|
|
if (codec_data && G_VALUE_TYPE (codec_data) == GST_TYPE_BUFFER) {
|
2011-11-03 12:56:49 +00:00
|
|
|
state.codec_data = GST_BUFFER (gst_value_get_buffer (codec_data));
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 08:41:54 +00:00
|
|
|
if (base_video_decoder_class->set_format) {
|
2011-11-03 12:56:49 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "Calling ::set_format()");
|
2011-07-11 06:54:53 +00:00
|
|
|
ret = base_video_decoder_class->set_format (base_video_decoder, &state);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
2011-11-03 12:56:49 +00:00
|
|
|
gst_buffer_replace (&GST_BASE_VIDEO_CODEC (base_video_decoder)->
|
|
|
|
state.codec_data, NULL);
|
2011-07-11 06:54:53 +00:00
|
|
|
gst_caps_replace (&GST_BASE_VIDEO_CODEC (base_video_decoder)->state.caps,
|
|
|
|
NULL);
|
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->state = state;
|
|
|
|
} else {
|
|
|
|
gst_buffer_replace (&state.codec_data, NULL);
|
|
|
|
gst_caps_replace (&state.caps, NULL);
|
2010-06-01 22:54:51 +00:00
|
|
|
}
|
2009-10-02 12:25:50 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
return ret;
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_base_video_decoder_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstBaseVideoDecoder *base_video_decoder;
|
|
|
|
|
|
|
|
base_video_decoder = GST_BASE_VIDEO_DECODER (object);
|
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_DEBUG_OBJECT (object, "finalize");
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
if (base_video_decoder->input_adapter) {
|
|
|
|
g_object_unref (base_video_decoder->input_adapter);
|
|
|
|
base_video_decoder->input_adapter = NULL;
|
|
|
|
}
|
|
|
|
if (base_video_decoder->output_adapter) {
|
|
|
|
g_object_unref (base_video_decoder->output_adapter);
|
|
|
|
base_video_decoder->output_adapter = NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-03 12:56:49 +00:00
|
|
|
if (base_video_decoder->pool) {
|
|
|
|
g_object_unref (base_video_decoder->pool);
|
|
|
|
base_video_decoder->pool = NULL;
|
|
|
|
}
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2011-03-29 13:41:08 +00:00
|
|
|
/* hard == FLUSH, otherwise discont */
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_video_decoder_flush (GstBaseVideoDecoder * dec, gboolean hard)
|
|
|
|
{
|
|
|
|
GstBaseVideoDecoderClass *klass;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
|
|
|
|
klass = GST_BASE_VIDEO_DECODER_GET_CLASS (dec);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (dec, "flush hard %d", hard);
|
|
|
|
|
2011-07-11 10:59:07 +00:00
|
|
|
/* Inform subclass */
|
|
|
|
/* FIXME ? only if hard, or tell it if hard ? */
|
|
|
|
if (klass->reset)
|
|
|
|
klass->reset (dec);
|
|
|
|
|
2011-03-29 13:41:08 +00:00
|
|
|
/* FIXME make some more distinction between hard and soft,
|
|
|
|
* but subclass may not be prepared for that */
|
|
|
|
/* FIXME perhaps also clear pending frames ?,
|
|
|
|
* but again, subclass may still come up with one of those */
|
|
|
|
if (!hard) {
|
|
|
|
/* TODO ? finish/drain some stuff */
|
|
|
|
} else {
|
|
|
|
gst_segment_init (&GST_BASE_VIDEO_CODEC (dec)->segment,
|
|
|
|
GST_FORMAT_UNDEFINED);
|
2011-03-31 12:47:55 +00:00
|
|
|
gst_base_video_decoder_clear_queues (dec);
|
2011-04-01 16:00:11 +00:00
|
|
|
dec->error_count = 0;
|
2011-06-28 09:47:25 +00:00
|
|
|
g_list_foreach (dec->current_frame_events, (GFunc) gst_event_unref, NULL);
|
|
|
|
g_list_free (dec->current_frame_events);
|
|
|
|
dec->current_frame_events = NULL;
|
2011-03-29 13:41:08 +00:00
|
|
|
}
|
|
|
|
/* and get (re)set for the sequel */
|
|
|
|
gst_base_video_decoder_reset (dec, FALSE);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
static gboolean
|
|
|
|
gst_base_video_decoder_sink_event (GstPad * pad, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstBaseVideoDecoder *base_video_decoder;
|
|
|
|
GstBaseVideoDecoderClass *base_video_decoder_class;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
base_video_decoder = GST_BASE_VIDEO_DECODER (gst_pad_get_parent (pad));
|
|
|
|
base_video_decoder_class =
|
|
|
|
GST_BASE_VIDEO_DECODER_GET_CLASS (base_video_decoder);
|
|
|
|
|
2011-03-28 11:32:17 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder,
|
|
|
|
"received event %d, %s", GST_EVENT_TYPE (event),
|
|
|
|
GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2011-10-04 12:27:32 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
2011-11-03 12:56:49 +00:00
|
|
|
ret = gst_base_video_decoder_setcaps (base_video_decoder, caps);
|
2011-10-04 12:27:32 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
break;
|
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
case GST_EVENT_EOS:
|
|
|
|
{
|
2011-06-28 09:47:25 +00:00
|
|
|
GstFlowReturn flow_ret;
|
2011-08-18 08:02:50 +00:00
|
|
|
|
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
2010-06-01 22:54:51 +00:00
|
|
|
if (!base_video_decoder->packetized) {
|
|
|
|
do {
|
|
|
|
flow_ret =
|
|
|
|
base_video_decoder_class->parse_data (base_video_decoder, TRUE);
|
|
|
|
} while (flow_ret == GST_FLOW_OK);
|
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
if (base_video_decoder_class->finish) {
|
2011-06-28 09:47:25 +00:00
|
|
|
flow_ret = base_video_decoder_class->finish (base_video_decoder);
|
|
|
|
} else {
|
|
|
|
flow_ret = GST_FLOW_OK;
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:47:25 +00:00
|
|
|
if (flow_ret == GST_FLOW_OK)
|
|
|
|
ret = gst_base_video_decoder_push_src_event (base_video_decoder, event);
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
2009-07-01 17:55:12 +00:00
|
|
|
break;
|
2011-08-18 08:02:50 +00:00
|
|
|
}
|
2011-10-04 12:27:32 +00:00
|
|
|
case GST_EVENT_SEGMENT:
|
2009-07-01 17:55:12 +00:00
|
|
|
{
|
2011-10-04 12:27:32 +00:00
|
|
|
GstSegment seg;
|
2010-10-10 00:36:07 +00:00
|
|
|
GstSegment *segment = &GST_BASE_VIDEO_CODEC (base_video_decoder)->segment;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
2011-10-04 12:27:32 +00:00
|
|
|
gst_event_copy_segment (event, &seg);
|
2011-03-28 11:32:17 +00:00
|
|
|
|
2011-10-04 12:27:32 +00:00
|
|
|
if (seg.format == GST_FORMAT_TIME) {
|
2011-03-28 11:32:17 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder,
|
2011-10-04 12:27:32 +00:00
|
|
|
"received TIME SEGMENT %" GST_SEGMENT_FORMAT, &seg);
|
2011-03-28 11:32:17 +00:00
|
|
|
} else {
|
|
|
|
GstFormat dformat = GST_FORMAT_TIME;
|
2011-10-04 12:27:32 +00:00
|
|
|
gint64 start;
|
2011-03-28 11:32:17 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base_video_decoder,
|
2011-10-04 12:27:32 +00:00
|
|
|
"received SEGMENT %" GST_SEGMENT_FORMAT, &seg);
|
2011-03-28 11:32:17 +00:00
|
|
|
/* handle newsegment as a result from our legacy simple seeking */
|
|
|
|
/* note that initial 0 should convert to 0 in any case */
|
|
|
|
if (base_video_decoder->do_byte_time &&
|
|
|
|
gst_pad_query_convert (GST_BASE_VIDEO_CODEC_SINK_PAD
|
2011-10-04 12:27:32 +00:00
|
|
|
(base_video_decoder), GST_FORMAT_BYTES, seg.start, dformat,
|
2011-03-28 11:32:17 +00:00
|
|
|
&start)) {
|
|
|
|
/* best attempt convert */
|
|
|
|
/* as these are only estimates, stop is kept open-ended to avoid
|
|
|
|
* premature cutting */
|
|
|
|
GST_DEBUG_OBJECT (base_video_decoder,
|
|
|
|
"converted to TIME start %" GST_TIME_FORMAT,
|
2011-10-04 12:27:32 +00:00
|
|
|
GST_TIME_ARGS (seg.start));
|
|
|
|
seg.start = start;
|
|
|
|
seg.stop = GST_CLOCK_TIME_NONE;
|
|
|
|
seg.time = start;
|
2011-03-28 11:32:17 +00:00
|
|
|
/* replace event */
|
|
|
|
gst_event_unref (event);
|
2011-10-04 12:27:32 +00:00
|
|
|
event = gst_event_new_segment (&seg);
|
2011-03-28 11:32:17 +00:00
|
|
|
} else {
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
2011-03-28 11:32:17 +00:00
|
|
|
goto newseg_wrong_format;
|
|
|
|
}
|
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-10-04 12:27:32 +00:00
|
|
|
gst_base_video_decoder_flush (base_video_decoder, FALSE);
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2011-10-04 12:27:32 +00:00
|
|
|
base_video_decoder->timestamp_offset = seg.start;
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2011-10-04 12:27:32 +00:00
|
|
|
*segment = seg;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-06-28 09:47:25 +00:00
|
|
|
ret = gst_base_video_decoder_push_src_event (base_video_decoder, event);
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
2009-07-01 17:55:12 +00:00
|
|
|
break;
|
2011-03-28 11:32:17 +00:00
|
|
|
}
|
2011-03-29 13:41:08 +00:00
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
{
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
2011-03-29 13:41:08 +00:00
|
|
|
/* well, this is kind of worse than a DISCONT */
|
|
|
|
gst_base_video_decoder_flush (base_video_decoder, TRUE);
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
2010-06-01 22:54:51 +00:00
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
default:
|
|
|
|
/* FIXME this changes the order of events */
|
2011-06-28 09:47:25 +00:00
|
|
|
ret = gst_base_video_decoder_push_src_event (base_video_decoder, event);
|
2009-07-01 17:55:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
gst_object_unref (base_video_decoder);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
newseg_wrong_format:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "received non TIME newsegment");
|
|
|
|
gst_event_unref (event);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-28 11:32:17 +00:00
|
|
|
/* perform upstream byte <-> time conversion (duration, seeking)
|
|
|
|
* if subclass allows and if enough data for moderately decent conversion */
|
|
|
|
static inline gboolean
|
|
|
|
gst_base_video_decoder_do_byte (GstBaseVideoDecoder * dec)
|
|
|
|
{
|
|
|
|
GstBaseVideoCodec *codec = GST_BASE_VIDEO_CODEC (dec);
|
|
|
|
|
|
|
|
return dec->do_byte_time && (codec->bytes > 0) && (codec->time > GST_SECOND);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_base_video_decoder_do_seek (GstBaseVideoDecoder * dec, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstBaseVideoCodec *codec = GST_BASE_VIDEO_CODEC (dec);
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType start_type, end_type;
|
|
|
|
GstFormat format;
|
|
|
|
gdouble rate;
|
|
|
|
gint64 start, start_time, end_time;
|
|
|
|
GstSegment seek_segment;
|
|
|
|
guint32 seqnum;
|
|
|
|
|
|
|
|
gst_event_parse_seek (event, &rate, &format, &flags, &start_type,
|
|
|
|
&start_time, &end_type, &end_time);
|
|
|
|
|
|
|
|
/* we'll handle plain open-ended flushing seeks with the simple approach */
|
|
|
|
if (rate != 1.0) {
|
|
|
|
GST_DEBUG_OBJECT (dec, "unsupported seek: rate");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start_type != GST_SEEK_TYPE_SET) {
|
|
|
|
GST_DEBUG_OBJECT (dec, "unsupported seek: start time");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end_type != GST_SEEK_TYPE_NONE ||
|
|
|
|
(end_type == GST_SEEK_TYPE_SET && end_time != GST_CLOCK_TIME_NONE)) {
|
|
|
|
GST_DEBUG_OBJECT (dec, "unsupported seek: end time");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(flags & GST_SEEK_FLAG_FLUSH)) {
|
|
|
|
GST_DEBUG_OBJECT (dec, "unsupported seek: not flushing");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (&seek_segment, &codec->segment, sizeof (seek_segment));
|
2011-10-04 12:27:32 +00:00
|
|
|
gst_segment_do_seek (&seek_segment, rate, format, flags, start_type,
|
2011-03-28 11:32:17 +00:00
|
|
|
start_time, end_type, end_time, NULL);
|
2011-10-04 12:27:32 +00:00
|
|
|
start_time = seek_segment.position;
|
2011-03-28 11:32:17 +00:00
|
|
|
|
|
|
|
if (!gst_pad_query_convert (codec->sinkpad, GST_FORMAT_TIME, start_time,
|
2011-10-04 12:27:32 +00:00
|
|
|
GST_FORMAT_BYTES, &start)) {
|
2011-03-28 11:32:17 +00:00
|
|
|
GST_DEBUG_OBJECT (dec, "conversion failed");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
seqnum = gst_event_get_seqnum (event);
|
|
|
|
event = gst_event_new_seek (1.0, GST_FORMAT_BYTES, flags,
|
|
|
|
GST_SEEK_TYPE_SET, start, GST_SEEK_TYPE_NONE, -1);
|
|
|
|
gst_event_set_seqnum (event, seqnum);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dec, "seeking to %" GST_TIME_FORMAT " at byte offset %"
|
|
|
|
G_GINT64_FORMAT, GST_TIME_ARGS (start_time), start);
|
|
|
|
|
|
|
|
return gst_pad_push_event (codec->sinkpad, event);
|
|
|
|
}
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
static gboolean
|
|
|
|
gst_base_video_decoder_src_event (GstPad * pad, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstBaseVideoDecoder *base_video_decoder;
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
base_video_decoder = GST_BASE_VIDEO_DECODER (gst_pad_get_parent (pad));
|
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder,
|
|
|
|
"received event %d, %s", GST_EVENT_TYPE (event),
|
|
|
|
GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
|
|
|
GstFormat format, tformat;
|
|
|
|
gdouble rate;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType cur_type, stop_type;
|
|
|
|
gint64 cur, stop;
|
2011-03-28 11:32:17 +00:00
|
|
|
gint64 tcur, tstop;
|
|
|
|
guint32 seqnum;
|
|
|
|
|
|
|
|
gst_event_parse_seek (event, &rate, &format, &flags, &cur_type, &cur,
|
|
|
|
&stop_type, &stop);
|
|
|
|
seqnum = gst_event_get_seqnum (event);
|
|
|
|
|
|
|
|
/* upstream gets a chance first */
|
|
|
|
if ((res =
|
|
|
|
gst_pad_push_event (GST_BASE_VIDEO_CODEC_SINK_PAD
|
|
|
|
(base_video_decoder), event)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* if upstream fails for a time seek, maybe we can help if allowed */
|
|
|
|
if (format == GST_FORMAT_TIME) {
|
|
|
|
if (gst_base_video_decoder_do_byte (base_video_decoder))
|
|
|
|
res = gst_base_video_decoder_do_seek (base_video_decoder, event);
|
|
|
|
break;
|
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-28 11:32:17 +00:00
|
|
|
/* ... though a non-time seek can be aided as well */
|
|
|
|
/* First bring the requested format to time */
|
2009-07-01 17:55:12 +00:00
|
|
|
tformat = GST_FORMAT_TIME;
|
2011-10-04 12:27:32 +00:00
|
|
|
if (!(res = gst_pad_query_convert (pad, format, cur, tformat, &tcur)))
|
2009-07-01 17:55:12 +00:00
|
|
|
goto convert_error;
|
2011-10-04 12:27:32 +00:00
|
|
|
if (!(res = gst_pad_query_convert (pad, format, stop, tformat, &tstop)))
|
2009-07-01 17:55:12 +00:00
|
|
|
goto convert_error;
|
|
|
|
|
2011-03-28 11:32:17 +00:00
|
|
|
/* then seek with time on the peer */
|
|
|
|
event = gst_event_new_seek (rate, GST_FORMAT_TIME,
|
2009-07-01 17:55:12 +00:00
|
|
|
flags, cur_type, tcur, stop_type, tstop);
|
2011-03-28 11:32:17 +00:00
|
|
|
gst_event_set_seqnum (event, seqnum);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
res =
|
|
|
|
gst_pad_push_event (GST_BASE_VIDEO_CODEC_SINK_PAD
|
2011-03-28 11:32:17 +00:00
|
|
|
(base_video_decoder), event);
|
2009-07-01 17:55:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_QOS:
|
|
|
|
{
|
2011-10-04 12:27:32 +00:00
|
|
|
GstQOSType type;
|
2009-07-01 17:55:12 +00:00
|
|
|
gdouble proportion;
|
|
|
|
GstClockTimeDiff diff;
|
|
|
|
GstClockTime timestamp;
|
2010-06-01 22:54:51 +00:00
|
|
|
GstClockTime duration;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-10-04 12:27:32 +00:00
|
|
|
gst_event_parse_qos (event, &type, &proportion, &diff, ×tamp);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (base_video_decoder);
|
2010-10-10 00:36:07 +00:00
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->proportion = proportion;
|
2010-06-01 22:54:51 +00:00
|
|
|
if (G_LIKELY (GST_CLOCK_TIME_IS_VALID (timestamp))) {
|
|
|
|
if (G_UNLIKELY (diff > 0)) {
|
2010-10-10 00:36:07 +00:00
|
|
|
if (GST_BASE_VIDEO_CODEC (base_video_decoder)->state.fps_n > 0)
|
2010-06-01 22:54:51 +00:00
|
|
|
duration =
|
|
|
|
gst_util_uint64_scale (GST_SECOND,
|
2010-10-10 00:36:07 +00:00
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->state.fps_d,
|
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->state.fps_n);
|
2010-06-01 22:54:51 +00:00
|
|
|
else
|
|
|
|
duration = 0;
|
2010-10-10 00:36:07 +00:00
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->earliest_time =
|
|
|
|
timestamp + 2 * diff + duration;
|
2010-06-01 22:54:51 +00:00
|
|
|
} else {
|
2010-10-10 00:36:07 +00:00
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->earliest_time =
|
|
|
|
timestamp + diff;
|
2010-06-01 22:54:51 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-10-10 00:36:07 +00:00
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->earliest_time =
|
|
|
|
GST_CLOCK_TIME_NONE;
|
2010-06-01 22:54:51 +00:00
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
GST_OBJECT_UNLOCK (base_video_decoder);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base_video_decoder,
|
|
|
|
"got QoS %" GST_TIME_FORMAT ", %" G_GINT64_FORMAT ", %g",
|
|
|
|
GST_TIME_ARGS (timestamp), diff, proportion);
|
|
|
|
|
|
|
|
res =
|
|
|
|
gst_pad_push_event (GST_BASE_VIDEO_CODEC_SINK_PAD
|
|
|
|
(base_video_decoder), event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res =
|
|
|
|
gst_pad_push_event (GST_BASE_VIDEO_CODEC_SINK_PAD
|
|
|
|
(base_video_decoder), event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
gst_object_unref (base_video_decoder);
|
|
|
|
return res;
|
|
|
|
|
|
|
|
convert_error:
|
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "could not convert format");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_base_video_decoder_src_query (GstPad * pad, GstQuery * query)
|
|
|
|
{
|
2011-03-28 07:14:57 +00:00
|
|
|
GstBaseVideoDecoder *dec;
|
2010-06-01 22:54:51 +00:00
|
|
|
gboolean res = TRUE;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-28 07:14:57 +00:00
|
|
|
dec = GST_BASE_VIDEO_DECODER (gst_pad_get_parent (pad));
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-28 11:32:17 +00:00
|
|
|
GST_LOG_OBJECT (dec, "handling query: %" GST_PTR_FORMAT, query);
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
2010-06-01 22:54:51 +00:00
|
|
|
case GST_QUERY_POSITION:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
2011-03-28 11:32:17 +00:00
|
|
|
gint64 time, value;
|
|
|
|
|
|
|
|
/* upstream gets a chance first */
|
|
|
|
if ((res =
|
|
|
|
gst_pad_peer_query (GST_BASE_VIDEO_CODEC_SINK_PAD (dec),
|
|
|
|
query))) {
|
|
|
|
GST_LOG_OBJECT (dec, "returning peer response");
|
|
|
|
break;
|
2010-06-01 22:54:51 +00:00
|
|
|
}
|
|
|
|
|
2011-03-28 11:32:17 +00:00
|
|
|
/* we start from the last seen time */
|
2011-03-28 07:14:57 +00:00
|
|
|
time = dec->last_timestamp;
|
2011-03-28 11:32:17 +00:00
|
|
|
/* correct for the segment values */
|
|
|
|
time = gst_segment_to_stream_time (&GST_BASE_VIDEO_CODEC (dec)->segment,
|
2010-10-10 00:36:07 +00:00
|
|
|
GST_FORMAT_TIME, time);
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2011-03-28 11:32:17 +00:00
|
|
|
GST_LOG_OBJECT (dec,
|
|
|
|
"query %p: our time: %" GST_TIME_FORMAT, query, GST_TIME_ARGS (time));
|
|
|
|
|
|
|
|
/* and convert to the final format */
|
|
|
|
gst_query_parse_position (query, &format, NULL);
|
|
|
|
if (!(res = gst_pad_query_convert (pad, GST_FORMAT_TIME, time,
|
2011-10-04 12:27:32 +00:00
|
|
|
format, &value)))
|
2011-03-28 11:32:17 +00:00
|
|
|
break;
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2011-03-28 11:32:17 +00:00
|
|
|
gst_query_set_position (query, format, value);
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2011-03-28 11:32:17 +00:00
|
|
|
GST_LOG_OBJECT (dec,
|
|
|
|
"query %p: we return %" G_GINT64_FORMAT " (format %u)", query, value,
|
|
|
|
format);
|
2010-06-01 22:54:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_DURATION:
|
|
|
|
{
|
2011-03-28 11:32:17 +00:00
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
/* upstream in any case */
|
|
|
|
if ((res = gst_pad_query_default (pad, query)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
gst_query_parse_duration (query, &format, NULL);
|
|
|
|
/* try answering TIME by converting from BYTE if subclass allows */
|
|
|
|
if (format == GST_FORMAT_TIME && gst_base_video_decoder_do_byte (dec)) {
|
|
|
|
gint64 value;
|
|
|
|
|
|
|
|
format = GST_FORMAT_BYTES;
|
|
|
|
if (gst_pad_query_peer_duration (GST_BASE_VIDEO_CODEC_SINK_PAD (dec),
|
2011-10-04 12:27:32 +00:00
|
|
|
format, &value)) {
|
2011-03-28 11:32:17 +00:00
|
|
|
GST_LOG_OBJECT (dec, "upstream size %" G_GINT64_FORMAT, value);
|
|
|
|
format = GST_FORMAT_TIME;
|
|
|
|
if (gst_pad_query_convert (GST_BASE_VIDEO_CODEC_SINK_PAD (dec),
|
2011-10-04 12:27:32 +00:00
|
|
|
GST_FORMAT_BYTES, value, format, &value)) {
|
2011-03-28 11:32:17 +00:00
|
|
|
gst_query_set_duration (query, GST_FORMAT_TIME, value);
|
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-01 22:54:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
case GST_QUERY_CONVERT:
|
|
|
|
{
|
|
|
|
GstFormat src_fmt, dest_fmt;
|
|
|
|
gint64 src_val, dest_val;
|
|
|
|
|
2011-03-28 07:14:57 +00:00
|
|
|
GST_DEBUG_OBJECT (dec, "convert query");
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
|
2011-03-28 09:15:49 +00:00
|
|
|
res = gst_base_video_rawvideo_convert (&GST_BASE_VIDEO_CODEC (dec)->state,
|
|
|
|
src_fmt, src_val, &dest_fmt, &dest_val);
|
2009-07-01 17:55:12 +00:00
|
|
|
if (!res)
|
|
|
|
goto error;
|
|
|
|
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = gst_pad_query_default (pad, query);
|
2011-03-28 11:32:17 +00:00
|
|
|
}
|
2011-03-28 07:14:57 +00:00
|
|
|
gst_object_unref (dec);
|
2009-07-01 17:55:12 +00:00
|
|
|
return res;
|
|
|
|
|
|
|
|
error:
|
2011-03-28 07:14:57 +00:00
|
|
|
GST_ERROR_OBJECT (dec, "query failed");
|
|
|
|
gst_object_unref (dec);
|
2009-07-01 17:55:12 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_base_video_decoder_sink_query (GstPad * pad, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstBaseVideoDecoder *base_video_decoder;
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
base_video_decoder = GST_BASE_VIDEO_DECODER (gst_pad_get_parent (pad));
|
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "handling query: %" GST_PTR_FORMAT,
|
|
|
|
query);
|
2011-03-27 20:27:09 +00:00
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_CONVERT:
|
|
|
|
{
|
2011-03-28 09:15:49 +00:00
|
|
|
GstBaseVideoCodec *codec = GST_BASE_VIDEO_CODEC (base_video_decoder);
|
2009-07-01 17:55:12 +00:00
|
|
|
GstFormat src_fmt, dest_fmt;
|
|
|
|
gint64 src_val, dest_val;
|
|
|
|
|
|
|
|
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
|
2011-03-28 09:15:49 +00:00
|
|
|
res = gst_base_video_encoded_video_convert (&codec->state, codec->bytes,
|
|
|
|
codec->time, src_fmt, src_val, &dest_fmt, &dest_val);
|
2009-07-01 17:55:12 +00:00
|
|
|
if (!res)
|
|
|
|
goto error;
|
|
|
|
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = gst_pad_query_default (pad, query);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
gst_object_unref (base_video_decoder);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
error:
|
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "query failed");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
typedef struct _Timestamp Timestamp;
|
|
|
|
struct _Timestamp
|
|
|
|
{
|
|
|
|
guint64 offset;
|
|
|
|
GstClockTime timestamp;
|
|
|
|
GstClockTime duration;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_base_video_decoder_add_timestamp (GstBaseVideoDecoder * base_video_decoder,
|
|
|
|
GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
Timestamp *ts;
|
|
|
|
|
|
|
|
ts = g_malloc (sizeof (Timestamp));
|
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder,
|
2011-03-27 20:27:09 +00:00
|
|
|
"adding timestamp %" GST_TIME_FORMAT " %" GST_TIME_FORMAT,
|
2010-06-02 19:16:56 +00:00
|
|
|
GST_TIME_ARGS (base_video_decoder->input_offset),
|
2010-06-01 22:54:51 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
|
|
|
|
|
|
|
|
ts->offset = base_video_decoder->input_offset;
|
|
|
|
ts->timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
ts->duration = GST_BUFFER_DURATION (buffer);
|
|
|
|
|
|
|
|
base_video_decoder->timestamps =
|
|
|
|
g_list_append (base_video_decoder->timestamps, ts);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_base_video_decoder_get_timestamp_at_offset (GstBaseVideoDecoder *
|
|
|
|
base_video_decoder, guint64 offset, GstClockTime * timestamp,
|
|
|
|
GstClockTime * duration)
|
|
|
|
{
|
|
|
|
Timestamp *ts;
|
|
|
|
GList *g;
|
|
|
|
|
|
|
|
*timestamp = GST_CLOCK_TIME_NONE;
|
|
|
|
*duration = GST_CLOCK_TIME_NONE;
|
|
|
|
|
|
|
|
g = base_video_decoder->timestamps;
|
|
|
|
while (g) {
|
|
|
|
ts = g->data;
|
|
|
|
if (ts->offset <= offset) {
|
|
|
|
*timestamp = ts->timestamp;
|
|
|
|
*duration = ts->duration;
|
|
|
|
g_free (ts);
|
|
|
|
g = g_list_next (g);
|
|
|
|
base_video_decoder->timestamps =
|
|
|
|
g_list_remove (base_video_decoder->timestamps, ts);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder,
|
2011-03-27 20:27:09 +00:00
|
|
|
"got timestamp %" GST_TIME_FORMAT " %" GST_TIME_FORMAT,
|
2010-06-02 19:16:56 +00:00
|
|
|
GST_TIME_ARGS (offset), GST_TIME_ARGS (*timestamp));
|
2010-06-01 22:54:51 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 12:47:55 +00:00
|
|
|
static void
|
|
|
|
gst_base_video_decoder_clear_queues (GstBaseVideoDecoder * dec)
|
|
|
|
{
|
|
|
|
g_list_foreach (dec->queued, (GFunc) gst_mini_object_unref, NULL);
|
|
|
|
g_list_free (dec->queued);
|
|
|
|
dec->queued = NULL;
|
|
|
|
g_list_foreach (dec->gather, (GFunc) gst_mini_object_unref, NULL);
|
|
|
|
g_list_free (dec->gather);
|
|
|
|
dec->gather = NULL;
|
2011-07-09 09:09:12 +00:00
|
|
|
g_list_foreach (dec->decode, (GFunc) gst_base_video_codec_free_frame, NULL);
|
2011-03-31 12:47:55 +00:00
|
|
|
g_list_free (dec->decode);
|
|
|
|
dec->decode = NULL;
|
|
|
|
g_list_foreach (dec->parse, (GFunc) gst_mini_object_unref, NULL);
|
|
|
|
g_list_free (dec->parse);
|
2011-07-11 07:35:25 +00:00
|
|
|
dec->parse = NULL;
|
2011-07-09 09:09:12 +00:00
|
|
|
g_list_foreach (dec->parse_gather, (GFunc) gst_base_video_codec_free_frame,
|
2011-03-31 12:47:55 +00:00
|
|
|
NULL);
|
|
|
|
g_list_free (dec->parse_gather);
|
2011-07-11 07:35:25 +00:00
|
|
|
dec->parse_gather = NULL;
|
2011-03-31 12:47:55 +00:00
|
|
|
}
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
static void
|
2011-03-29 13:41:08 +00:00
|
|
|
gst_base_video_decoder_reset (GstBaseVideoDecoder * base_video_decoder,
|
|
|
|
gboolean full)
|
2009-07-01 17:55:12 +00:00
|
|
|
{
|
2011-03-29 13:41:08 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "reset full %d", full);
|
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
|
|
|
|
2011-03-29 13:41:08 +00:00
|
|
|
if (full) {
|
|
|
|
gst_segment_init (&GST_BASE_VIDEO_CODEC (base_video_decoder)->segment,
|
|
|
|
GST_FORMAT_UNDEFINED);
|
2011-03-31 12:47:55 +00:00
|
|
|
gst_base_video_decoder_clear_queues (base_video_decoder);
|
2011-04-01 16:00:11 +00:00
|
|
|
base_video_decoder->error_count = 0;
|
2011-03-29 13:41:08 +00:00
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-30 08:28:08 +00:00
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->discont = TRUE;
|
2009-07-01 17:55:12 +00:00
|
|
|
base_video_decoder->have_sync = FALSE;
|
|
|
|
|
|
|
|
base_video_decoder->timestamp_offset = GST_CLOCK_TIME_NONE;
|
2011-03-29 13:41:08 +00:00
|
|
|
base_video_decoder->field_index = 0;
|
2009-07-01 17:55:12 +00:00
|
|
|
base_video_decoder->last_timestamp = GST_CLOCK_TIME_NONE;
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
base_video_decoder->input_offset = 0;
|
|
|
|
base_video_decoder->frame_offset = 0;
|
2011-03-29 13:41:08 +00:00
|
|
|
gst_adapter_clear (base_video_decoder->input_adapter);
|
|
|
|
gst_adapter_clear (base_video_decoder->output_adapter);
|
|
|
|
g_list_foreach (base_video_decoder->timestamps, (GFunc) g_free, NULL);
|
|
|
|
g_list_free (base_video_decoder->timestamps);
|
|
|
|
base_video_decoder->timestamps = NULL;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
if (base_video_decoder->current_frame) {
|
2011-07-09 09:09:12 +00:00
|
|
|
gst_base_video_codec_free_frame (base_video_decoder->current_frame);
|
2009-07-01 17:55:12 +00:00
|
|
|
base_video_decoder->current_frame = NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-29 13:41:08 +00:00
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->system_frame_number = 0;
|
|
|
|
base_video_decoder->base_picture_number = 0;
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
GST_OBJECT_LOCK (base_video_decoder);
|
2010-10-10 00:36:07 +00:00
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->earliest_time =
|
|
|
|
GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->proportion = 0.5;
|
2010-06-01 22:54:51 +00:00
|
|
|
GST_OBJECT_UNLOCK (base_video_decoder);
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2011-03-31 12:47:55 +00:00
|
|
|
gst_base_video_decoder_chain_forward (GstBaseVideoDecoder * base_video_decoder,
|
|
|
|
GstBuffer * buf)
|
2009-07-01 17:55:12 +00:00
|
|
|
{
|
|
|
|
GstBaseVideoDecoderClass *klass;
|
|
|
|
GstFlowReturn ret;
|
|
|
|
|
2011-03-27 20:27:09 +00:00
|
|
|
klass = GST_BASE_VIDEO_DECODER_GET_CLASS (base_video_decoder);
|
|
|
|
|
2011-03-30 07:17:22 +00:00
|
|
|
g_return_val_if_fail (base_video_decoder->packetized || klass->parse_data,
|
|
|
|
GST_FLOW_ERROR);
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
if (base_video_decoder->current_frame == NULL) {
|
|
|
|
base_video_decoder->current_frame =
|
|
|
|
gst_base_video_decoder_new_frame (base_video_decoder);
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
2010-06-01 22:54:51 +00:00
|
|
|
|
|
|
|
if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
|
|
|
|
gst_base_video_decoder_add_timestamp (base_video_decoder, buf);
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
2011-10-05 10:53:07 +00:00
|
|
|
base_video_decoder->input_offset += gst_buffer_get_size (buf);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
if (base_video_decoder->packetized) {
|
|
|
|
base_video_decoder->current_frame->sink_buffer = buf;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-31 12:47:55 +00:00
|
|
|
if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT))
|
|
|
|
base_video_decoder->current_frame->is_sync_point = TRUE;
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
ret = gst_base_video_decoder_have_frame_2 (base_video_decoder);
|
|
|
|
} else {
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
gst_adapter_push (base_video_decoder->input_adapter, buf);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
if (!base_video_decoder->have_sync) {
|
|
|
|
int n, m;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "no sync, scanning");
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
n = gst_adapter_available (base_video_decoder->input_adapter);
|
2010-09-19 02:21:47 +00:00
|
|
|
if (klass->capture_mask != 0) {
|
|
|
|
m = gst_adapter_masked_scan_uint32 (base_video_decoder->input_adapter,
|
|
|
|
klass->capture_mask, klass->capture_pattern, 0, n - 3);
|
|
|
|
} else if (klass->scan_for_sync) {
|
|
|
|
m = klass->scan_for_sync (base_video_decoder, FALSE, 0, n);
|
|
|
|
} else {
|
|
|
|
m = 0;
|
|
|
|
}
|
2010-06-01 22:54:51 +00:00
|
|
|
if (m == -1) {
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_ERROR_OBJECT (base_video_decoder, "scan returned no sync");
|
2010-09-19 02:21:47 +00:00
|
|
|
gst_adapter_flush (base_video_decoder->input_adapter, n - 3);
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
return GST_FLOW_OK;
|
2010-09-19 02:21:47 +00:00
|
|
|
} else {
|
|
|
|
if (m > 0) {
|
|
|
|
if (m >= n) {
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_ERROR_OBJECT (base_video_decoder,
|
|
|
|
"subclass scanned past end %d >= %d", m, n);
|
2010-09-19 02:21:47 +00:00
|
|
|
}
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2010-09-19 02:21:47 +00:00
|
|
|
gst_adapter_flush (base_video_decoder->input_adapter, m);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2010-09-19 02:21:47 +00:00
|
|
|
if (m < n) {
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder,
|
|
|
|
"found possible sync after %d bytes (of %d)", m, n);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2010-09-19 02:21:47 +00:00
|
|
|
/* this is only "maybe" sync */
|
|
|
|
base_video_decoder->have_sync = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
do {
|
2011-11-03 12:56:49 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "Calling ::parse_data()");
|
2010-06-01 22:54:51 +00:00
|
|
|
ret = klass->parse_data (base_video_decoder, FALSE);
|
|
|
|
} while (ret == GST_FLOW_OK);
|
|
|
|
|
|
|
|
if (ret == GST_BASE_VIDEO_DECODER_FLOW_NEED_DATA) {
|
2009-07-01 17:55:12 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 12:47:55 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_video_decoder_flush_decode (GstBaseVideoDecoder * dec)
|
|
|
|
{
|
|
|
|
GstFlowReturn res = GST_FLOW_OK;
|
|
|
|
GList *walk;
|
|
|
|
|
|
|
|
walk = dec->decode;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dec, "flushing buffers to decode");
|
|
|
|
|
|
|
|
/* clear buffer and decoder state */
|
|
|
|
gst_base_video_decoder_flush (dec, FALSE);
|
|
|
|
|
|
|
|
/* signal have_frame it should not capture frames */
|
|
|
|
dec->process = TRUE;
|
|
|
|
|
|
|
|
while (walk) {
|
|
|
|
GList *next;
|
2011-10-04 12:27:32 +00:00
|
|
|
GstVideoFrameState *frame = (GstVideoFrameState *) (walk->data);
|
2011-03-31 12:47:55 +00:00
|
|
|
GstBuffer *buf = frame->sink_buffer;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dec, "decoding frame %p, ts %" GST_TIME_FORMAT,
|
|
|
|
buf, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
|
|
|
|
|
|
|
|
next = g_list_next (walk);
|
|
|
|
if (dec->current_frame)
|
2011-07-09 09:09:12 +00:00
|
|
|
gst_base_video_codec_free_frame (dec->current_frame);
|
2011-03-31 12:47:55 +00:00
|
|
|
dec->current_frame = frame;
|
|
|
|
/* decode buffer, resulting data prepended to queue */
|
|
|
|
res = gst_base_video_decoder_have_frame_2 (dec);
|
|
|
|
|
|
|
|
walk = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
dec->process = FALSE;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_video_decoder_flush_parse (GstBaseVideoDecoder * dec)
|
|
|
|
{
|
|
|
|
GstFlowReturn res = GST_FLOW_OK;
|
|
|
|
GList *walk;
|
|
|
|
|
|
|
|
walk = dec->parse;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dec, "flushing buffers to parsing");
|
|
|
|
|
|
|
|
/* clear buffer and decoder state */
|
|
|
|
gst_base_video_decoder_flush (dec, FALSE);
|
|
|
|
|
|
|
|
while (walk) {
|
|
|
|
GList *next;
|
|
|
|
GstBuffer *buf = GST_BUFFER_CAST (walk->data);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dec, "parsing buffer %p, ts %" GST_TIME_FORMAT,
|
|
|
|
buf, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
|
|
|
|
|
|
|
|
next = g_list_next (walk);
|
|
|
|
/* parse buffer, resulting frames prepended to parse_gather queue */
|
|
|
|
gst_buffer_ref (buf);
|
|
|
|
res = gst_base_video_decoder_chain_forward (dec, buf);
|
|
|
|
|
|
|
|
/* if we generated output, we can discard the buffer, else we
|
|
|
|
* keep it in the queue */
|
|
|
|
if (dec->parse_gather) {
|
|
|
|
GST_DEBUG_OBJECT (dec, "parsed buffer to %p", dec->parse_gather->data);
|
|
|
|
dec->parse = g_list_delete_link (dec->parse, walk);
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (dec, "buffer did not decode, keeping");
|
|
|
|
}
|
|
|
|
walk = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now we can process frames */
|
|
|
|
GST_DEBUG_OBJECT (dec, "checking frames");
|
|
|
|
while (dec->parse_gather) {
|
2011-10-04 12:27:32 +00:00
|
|
|
GstVideoFrameState *frame;
|
2011-03-31 12:47:55 +00:00
|
|
|
|
2011-10-04 12:27:32 +00:00
|
|
|
frame = (GstVideoFrameState *) (dec->parse_gather->data);
|
2011-03-31 12:47:55 +00:00
|
|
|
/* remove from the gather list */
|
|
|
|
dec->parse_gather =
|
|
|
|
g_list_delete_link (dec->parse_gather, dec->parse_gather);
|
|
|
|
/* copy to decode queue */
|
|
|
|
dec->decode = g_list_prepend (dec->decode, frame);
|
|
|
|
|
|
|
|
/* if we copied a keyframe, flush and decode the decode queue */
|
|
|
|
if (frame->is_sync_point) {
|
|
|
|
GST_DEBUG_OBJECT (dec, "copied keyframe");
|
|
|
|
res = gst_base_video_decoder_flush_decode (dec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now send queued data downstream */
|
|
|
|
while (dec->queued) {
|
|
|
|
GstBuffer *buf = GST_BUFFER_CAST (dec->queued->data);
|
|
|
|
|
|
|
|
if (G_LIKELY (res == GST_FLOW_OK)) {
|
|
|
|
GST_DEBUG_OBJECT (dec, "pushing buffer %p of size %u, "
|
|
|
|
"time %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT, buf,
|
2011-10-05 10:53:07 +00:00
|
|
|
gst_buffer_get_size (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
|
2011-03-31 12:47:55 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
|
|
|
|
/* should be already, but let's be sure */
|
2011-10-04 12:27:32 +00:00
|
|
|
buf = gst_buffer_make_writable (buf);
|
2011-03-31 12:47:55 +00:00
|
|
|
/* avoid stray DISCONT from forward processing,
|
|
|
|
* which have no meaning in reverse pushing */
|
|
|
|
GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
res = gst_pad_push (GST_BASE_VIDEO_CODEC_SRC_PAD (dec), buf);
|
|
|
|
} else {
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
dec->queued = g_list_delete_link (dec->queued, dec->queued);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_video_decoder_chain_reverse (GstBaseVideoDecoder * dec,
|
|
|
|
GstBuffer * buf)
|
|
|
|
{
|
|
|
|
GstFlowReturn result = GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* if we have a discont, move buffers to the decode list */
|
|
|
|
if (!buf || GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT)) {
|
|
|
|
GST_DEBUG_OBJECT (dec, "received discont");
|
|
|
|
while (dec->gather) {
|
|
|
|
GstBuffer *gbuf;
|
|
|
|
|
|
|
|
gbuf = GST_BUFFER_CAST (dec->gather->data);
|
|
|
|
/* remove from the gather list */
|
|
|
|
dec->gather = g_list_delete_link (dec->gather, dec->gather);
|
|
|
|
/* copy to parse queue */
|
|
|
|
dec->parse = g_list_prepend (dec->parse, gbuf);
|
|
|
|
}
|
|
|
|
/* parse and decode stuff in the parse queue */
|
|
|
|
gst_base_video_decoder_flush_parse (dec);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_LIKELY (buf)) {
|
|
|
|
GST_DEBUG_OBJECT (dec, "gathering buffer %p of size %u, "
|
|
|
|
"time %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT, buf,
|
2011-10-05 10:53:07 +00:00
|
|
|
gst_buffer_get_size (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
|
2011-03-31 12:47:55 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
|
|
|
|
|
|
|
|
/* add buffer to gather queue */
|
|
|
|
dec->gather = g_list_prepend (dec->gather, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_video_decoder_chain (GstPad * pad, GstBuffer * buf)
|
|
|
|
{
|
|
|
|
GstBaseVideoDecoder *base_video_decoder;
|
2011-08-18 08:02:50 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2011-03-31 12:47:55 +00:00
|
|
|
|
|
|
|
base_video_decoder = GST_BASE_VIDEO_DECODER (GST_PAD_PARENT (pad));
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (base_video_decoder,
|
|
|
|
"chain %" GST_TIME_FORMAT " duration %" GST_TIME_FORMAT " size %d",
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
|
2011-10-05 10:53:07 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), gst_buffer_get_size (buf));
|
2011-03-31 12:47:55 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
|
|
|
|
2011-03-31 12:47:55 +00:00
|
|
|
/* NOTE:
|
|
|
|
* requiring the pad to be negotiated makes it impossible to use
|
|
|
|
* oggdemux or filesrc ! decoder */
|
|
|
|
|
|
|
|
if (GST_BASE_VIDEO_CODEC (base_video_decoder)->segment.format ==
|
|
|
|
GST_FORMAT_UNDEFINED) {
|
|
|
|
GstEvent *event;
|
|
|
|
GstFlowReturn ret;
|
2011-11-03 12:56:49 +00:00
|
|
|
GstSegment *segment = &GST_BASE_VIDEO_CODEC (base_video_decoder)->segment;
|
2011-03-31 12:47:55 +00:00
|
|
|
|
|
|
|
GST_WARNING_OBJECT (base_video_decoder,
|
|
|
|
"Received buffer without a new-segment. "
|
|
|
|
"Assuming timestamps start from 0.");
|
|
|
|
|
2011-11-03 12:56:49 +00:00
|
|
|
gst_segment_init (segment, GST_FORMAT_TIME);
|
2011-03-31 12:47:55 +00:00
|
|
|
|
2011-11-03 12:56:49 +00:00
|
|
|
event = gst_event_new_segment (segment);
|
2011-03-31 12:47:55 +00:00
|
|
|
|
2011-06-28 09:47:25 +00:00
|
|
|
ret = gst_base_video_decoder_push_src_event (base_video_decoder, event);
|
2011-03-31 12:47:55 +00:00
|
|
|
if (!ret) {
|
|
|
|
GST_ERROR_OBJECT (base_video_decoder, "new segment event ret=%d", ret);
|
2011-08-18 08:02:50 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
2011-03-31 12:47:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_UNLIKELY (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT))) {
|
|
|
|
gint64 ts, index;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "received DISCONT buffer");
|
|
|
|
|
|
|
|
/* track present position */
|
|
|
|
ts = base_video_decoder->timestamp_offset;
|
|
|
|
index = base_video_decoder->field_index;
|
|
|
|
|
2011-07-11 10:36:42 +00:00
|
|
|
gst_base_video_decoder_flush (base_video_decoder, FALSE);
|
|
|
|
|
2011-03-31 12:47:55 +00:00
|
|
|
/* buffer may claim DISCONT loudly, if it can't tell us where we are now,
|
|
|
|
* we'll stick to where we were ...
|
|
|
|
* Particularly useful/needed for upstream BYTE based */
|
|
|
|
if (GST_BASE_VIDEO_CODEC (base_video_decoder)->segment.rate > 0.0 &&
|
|
|
|
!GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
|
|
|
|
GST_DEBUG_OBJECT (base_video_decoder,
|
|
|
|
"... but restoring previous ts tracking");
|
|
|
|
base_video_decoder->timestamp_offset = ts;
|
|
|
|
base_video_decoder->field_index = index & ~1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_BASE_VIDEO_CODEC (base_video_decoder)->segment.rate > 0.0)
|
2011-08-18 08:02:50 +00:00
|
|
|
ret = gst_base_video_decoder_chain_forward (base_video_decoder, buf);
|
2011-03-31 12:47:55 +00:00
|
|
|
else
|
2011-08-18 08:02:50 +00:00
|
|
|
ret = gst_base_video_decoder_chain_reverse (base_video_decoder, buf);
|
|
|
|
|
|
|
|
done:
|
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
|
|
|
return ret;
|
2011-03-31 12:47:55 +00:00
|
|
|
}
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_base_video_decoder_change_state (GstElement * element,
|
|
|
|
GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstBaseVideoDecoder *base_video_decoder;
|
|
|
|
GstBaseVideoDecoderClass *base_video_decoder_class;
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
base_video_decoder = GST_BASE_VIDEO_DECODER (element);
|
|
|
|
base_video_decoder_class = GST_BASE_VIDEO_DECODER_GET_CLASS (element);
|
|
|
|
|
|
|
|
switch (transition) {
|
2011-03-29 08:41:54 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
if (base_video_decoder_class->start) {
|
|
|
|
base_video_decoder_class->start (base_video_decoder);
|
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2010-06-01 22:54:51 +00:00
|
|
|
if (base_video_decoder_class->stop) {
|
|
|
|
base_video_decoder_class->stop (base_video_decoder);
|
|
|
|
}
|
2011-08-18 08:02:50 +00:00
|
|
|
|
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
2011-03-29 13:41:08 +00:00
|
|
|
gst_base_video_decoder_reset (base_video_decoder, TRUE);
|
2011-06-28 09:47:25 +00:00
|
|
|
g_list_foreach (base_video_decoder->current_frame_events,
|
|
|
|
(GFunc) gst_event_unref, NULL);
|
|
|
|
g_list_free (base_video_decoder->current_frame_events);
|
|
|
|
base_video_decoder->current_frame_events = NULL;
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
2009-07-01 17:55:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-04 12:27:32 +00:00
|
|
|
static GstVideoFrameState *
|
2009-07-01 17:55:12 +00:00
|
|
|
gst_base_video_decoder_new_frame (GstBaseVideoDecoder * base_video_decoder)
|
|
|
|
{
|
2011-10-04 12:27:32 +00:00
|
|
|
GstVideoFrameState *frame;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
2011-07-09 09:09:12 +00:00
|
|
|
frame =
|
|
|
|
gst_base_video_codec_new_frame (GST_BASE_VIDEO_CODEC
|
|
|
|
(base_video_decoder));
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
frame->decode_frame_number = frame->system_frame_number -
|
|
|
|
base_video_decoder->reorder_depth;
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
frame->decode_timestamp = GST_CLOCK_TIME_NONE;
|
|
|
|
frame->presentation_timestamp = GST_CLOCK_TIME_NONE;
|
|
|
|
frame->presentation_duration = GST_CLOCK_TIME_NONE;
|
2009-07-01 17:55:12 +00:00
|
|
|
frame->n_fields = 2;
|
|
|
|
|
2011-06-28 09:47:25 +00:00
|
|
|
frame->events = base_video_decoder->current_frame_events;
|
|
|
|
base_video_decoder->current_frame_events = NULL;
|
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/**
|
|
|
|
* gst_base_video_decoder_finish_frame:
|
|
|
|
* @base_video_decoder: a #GstBaseVideoDecoder
|
2011-10-04 12:27:32 +00:00
|
|
|
* @frame: a decoded #GstVideoFrameState
|
2011-03-30 07:15:13 +00:00
|
|
|
*
|
|
|
|
* @frame should have a valid decoded data buffer, whose metadata fields
|
|
|
|
* are then appropriately set according to frame data and pushed downstream.
|
|
|
|
* If no output data is provided, @frame is considered skipped.
|
|
|
|
* In any case, the frame is considered finished and released.
|
|
|
|
*
|
|
|
|
* Returns: a #GstFlowReturn resulting from sending data downstream
|
|
|
|
*/
|
2009-07-01 17:55:12 +00:00
|
|
|
GstFlowReturn
|
|
|
|
gst_base_video_decoder_finish_frame (GstBaseVideoDecoder * base_video_decoder,
|
2011-10-04 12:27:32 +00:00
|
|
|
GstVideoFrameState * frame)
|
2009-07-01 17:55:12 +00:00
|
|
|
{
|
2010-10-10 00:36:07 +00:00
|
|
|
GstVideoState *state = &GST_BASE_VIDEO_CODEC (base_video_decoder)->state;
|
2009-07-01 17:55:12 +00:00
|
|
|
GstBuffer *src_buffer;
|
2011-03-28 06:59:20 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2011-07-11 09:52:33 +00:00
|
|
|
GList *l, *events = NULL;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "finish frame");
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
|
|
|
|
2011-07-11 09:28:40 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "n %d in %d out %d",
|
2010-10-10 00:36:07 +00:00
|
|
|
g_list_length (GST_BASE_VIDEO_CODEC (base_video_decoder)->frames),
|
|
|
|
gst_adapter_available (base_video_decoder->input_adapter),
|
|
|
|
gst_adapter_available (base_video_decoder->output_adapter));
|
2011-07-11 09:28:40 +00:00
|
|
|
#endif
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder,
|
2011-03-27 20:27:09 +00:00
|
|
|
"finish frame sync=%d pts=%" GST_TIME_FORMAT, frame->is_sync_point,
|
2010-06-02 19:16:56 +00:00
|
|
|
GST_TIME_ARGS (frame->presentation_timestamp));
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-06-28 09:47:25 +00:00
|
|
|
/* Push all pending events that arrived before this frame */
|
|
|
|
for (l = base_video_decoder->base_video_codec.frames; l; l = l->next) {
|
2011-10-04 12:27:32 +00:00
|
|
|
GstVideoFrameState *tmp = l->data;
|
2011-06-28 09:47:25 +00:00
|
|
|
|
|
|
|
if (tmp->events) {
|
2011-07-11 09:52:33 +00:00
|
|
|
GList *k;
|
2011-06-28 09:47:25 +00:00
|
|
|
|
2011-07-11 09:52:33 +00:00
|
|
|
for (k = g_list_last (tmp->events); k; k = k->prev)
|
|
|
|
events = g_list_prepend (events, k->data);
|
|
|
|
g_list_free (tmp->events);
|
2011-06-28 09:47:25 +00:00
|
|
|
tmp->events = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp == frame)
|
|
|
|
break;
|
|
|
|
}
|
2011-07-11 09:52:33 +00:00
|
|
|
|
|
|
|
for (l = g_list_last (events); l; l = l->next)
|
|
|
|
gst_pad_push_event (GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_decoder),
|
|
|
|
l->data);
|
|
|
|
g_list_free (events);
|
2011-06-28 09:47:25 +00:00
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (frame->presentation_timestamp)) {
|
|
|
|
if (frame->presentation_timestamp != base_video_decoder->timestamp_offset) {
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder,
|
|
|
|
"sync timestamp %" GST_TIME_FORMAT " diff %" GST_TIME_FORMAT,
|
2010-06-02 19:16:56 +00:00
|
|
|
GST_TIME_ARGS (frame->presentation_timestamp),
|
|
|
|
GST_TIME_ARGS (frame->presentation_timestamp -
|
2010-10-10 00:36:07 +00:00
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->segment.start));
|
2010-06-01 22:54:51 +00:00
|
|
|
base_video_decoder->timestamp_offset = frame->presentation_timestamp;
|
2010-09-19 02:14:36 +00:00
|
|
|
base_video_decoder->field_index &= 1;
|
2009-07-01 17:55:12 +00:00
|
|
|
} else {
|
2010-06-01 22:54:51 +00:00
|
|
|
/* This case is for one initial timestamp and no others, e.g.,
|
|
|
|
* filesrc ! decoder ! xvimagesink */
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_WARNING_OBJECT (base_video_decoder,
|
|
|
|
"sync timestamp didn't change, ignoring");
|
2010-06-01 22:54:51 +00:00
|
|
|
frame->presentation_timestamp = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (frame->is_sync_point) {
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_WARNING_OBJECT (base_video_decoder,
|
|
|
|
"sync point doesn't have timestamp");
|
2010-06-01 22:54:51 +00:00
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (base_video_decoder->timestamp_offset)) {
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_WARNING_OBJECT (base_video_decoder,
|
|
|
|
"No base timestamp. Assuming frames start at segment start");
|
2010-06-01 22:54:51 +00:00
|
|
|
base_video_decoder->timestamp_offset =
|
2010-10-10 00:36:07 +00:00
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->segment.start;
|
2010-09-19 02:14:36 +00:00
|
|
|
base_video_decoder->field_index &= 1;
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
frame->field_index = base_video_decoder->field_index;
|
|
|
|
base_video_decoder->field_index += frame->n_fields;
|
|
|
|
|
|
|
|
if (frame->presentation_timestamp == GST_CLOCK_TIME_NONE) {
|
|
|
|
frame->presentation_timestamp =
|
|
|
|
gst_base_video_decoder_get_field_timestamp (base_video_decoder,
|
|
|
|
frame->field_index);
|
|
|
|
frame->presentation_duration = GST_CLOCK_TIME_NONE;
|
|
|
|
frame->decode_timestamp =
|
|
|
|
gst_base_video_decoder_get_timestamp (base_video_decoder,
|
|
|
|
frame->decode_frame_number);
|
|
|
|
}
|
|
|
|
if (frame->presentation_duration == GST_CLOCK_TIME_NONE) {
|
|
|
|
frame->presentation_duration =
|
2010-06-01 22:54:51 +00:00
|
|
|
gst_base_video_decoder_get_field_duration (base_video_decoder,
|
|
|
|
frame->n_fields);
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (base_video_decoder->last_timestamp)) {
|
|
|
|
if (frame->presentation_timestamp < base_video_decoder->last_timestamp) {
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_WARNING_OBJECT (base_video_decoder,
|
|
|
|
"decreasing timestamp (%" GST_TIME_FORMAT " < %"
|
2010-06-02 19:16:56 +00:00
|
|
|
GST_TIME_FORMAT ")", GST_TIME_ARGS (frame->presentation_timestamp),
|
|
|
|
GST_TIME_ARGS (base_video_decoder->last_timestamp));
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
base_video_decoder->last_timestamp = frame->presentation_timestamp;
|
|
|
|
|
2011-03-28 06:59:20 +00:00
|
|
|
/* no buffer data means this frame is skipped/dropped */
|
|
|
|
if (!frame->src_buffer) {
|
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "skipping frame %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (frame->presentation_timestamp));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-10-04 12:27:32 +00:00
|
|
|
src_buffer = gst_buffer_make_writable (frame->src_buffer);
|
2011-03-27 00:55:31 +00:00
|
|
|
frame->src_buffer = NULL;
|
|
|
|
|
|
|
|
GST_BUFFER_FLAG_UNSET (src_buffer, GST_BUFFER_FLAG_DELTA_UNIT);
|
2010-10-10 00:36:07 +00:00
|
|
|
if (state->interlaced) {
|
|
|
|
int tff = state->top_field_first;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
if (frame->field_index & 1) {
|
|
|
|
tff ^= 1;
|
|
|
|
}
|
|
|
|
if (tff) {
|
2011-11-03 12:56:49 +00:00
|
|
|
GST_BUFFER_FLAG_SET (src_buffer, GST_VIDEO_BUFFER_FLAG_TFF);
|
2009-07-01 17:55:12 +00:00
|
|
|
} else {
|
2011-11-03 12:56:49 +00:00
|
|
|
GST_BUFFER_FLAG_UNSET (src_buffer, GST_VIDEO_BUFFER_FLAG_TFF);
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
2011-11-03 12:56:49 +00:00
|
|
|
GST_BUFFER_FLAG_UNSET (src_buffer, GST_VIDEO_BUFFER_FLAG_RFF);
|
|
|
|
GST_BUFFER_FLAG_UNSET (src_buffer, GST_VIDEO_BUFFER_FLAG_ONEFIELD);
|
2009-07-01 17:55:12 +00:00
|
|
|
if (frame->n_fields == 3) {
|
2011-11-03 12:56:49 +00:00
|
|
|
GST_BUFFER_FLAG_SET (src_buffer, GST_VIDEO_BUFFER_FLAG_RFF);
|
2009-07-01 17:55:12 +00:00
|
|
|
} else if (frame->n_fields == 1) {
|
2011-11-03 12:56:49 +00:00
|
|
|
GST_BUFFER_FLAG_SET (src_buffer, GST_VIDEO_BUFFER_FLAG_ONEFIELD);
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-30 08:28:08 +00:00
|
|
|
if (GST_BASE_VIDEO_CODEC (base_video_decoder)->discont) {
|
2011-03-27 00:55:31 +00:00
|
|
|
GST_BUFFER_FLAG_SET (src_buffer, GST_BUFFER_FLAG_DISCONT);
|
2011-03-30 08:28:08 +00:00
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->discont = FALSE;
|
2010-05-24 19:55:16 +00:00
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-27 00:55:31 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (src_buffer) = frame->presentation_timestamp;
|
|
|
|
GST_BUFFER_DURATION (src_buffer) = frame->presentation_duration;
|
|
|
|
GST_BUFFER_OFFSET (src_buffer) = GST_BUFFER_OFFSET_NONE;
|
|
|
|
GST_BUFFER_OFFSET_END (src_buffer) = GST_BUFFER_OFFSET_NONE;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-28 09:15:49 +00:00
|
|
|
/* update rate estimate */
|
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->bytes +=
|
2011-10-05 10:53:07 +00:00
|
|
|
gst_buffer_get_size (src_buffer);
|
2011-03-28 09:15:49 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (frame->presentation_duration)) {
|
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->time +=
|
|
|
|
frame->presentation_duration;
|
|
|
|
} else {
|
|
|
|
/* better none than nothing valid */
|
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->time = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "pushing frame ts %" GST_TIME_FORMAT
|
|
|
|
", duration %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (src_buffer)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (src_buffer)));
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
if (base_video_decoder->sink_clipping) {
|
2011-11-03 12:56:49 +00:00
|
|
|
guint64 start = GST_BUFFER_TIMESTAMP (src_buffer);
|
|
|
|
guint64 stop = GST_BUFFER_TIMESTAMP (src_buffer) +
|
2009-07-01 17:55:12 +00:00
|
|
|
GST_BUFFER_DURATION (src_buffer);
|
2010-10-10 00:36:07 +00:00
|
|
|
GstSegment *segment = &GST_BASE_VIDEO_CODEC (base_video_decoder)->segment;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2010-10-10 00:36:07 +00:00
|
|
|
if (gst_segment_clip (segment, GST_FORMAT_TIME, start, stop, &start, &stop)) {
|
2009-07-01 17:55:12 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (src_buffer) = start;
|
|
|
|
GST_BUFFER_DURATION (src_buffer) = stop - start;
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder,
|
2011-03-27 20:27:09 +00:00
|
|
|
"accepting buffer inside segment: %" GST_TIME_FORMAT
|
2010-06-01 22:54:51 +00:00
|
|
|
" %" GST_TIME_FORMAT
|
|
|
|
" seg %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT
|
|
|
|
" time %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (src_buffer)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (src_buffer) +
|
|
|
|
GST_BUFFER_DURATION (src_buffer)),
|
2010-10-10 00:36:07 +00:00
|
|
|
GST_TIME_ARGS (segment->start),
|
|
|
|
GST_TIME_ARGS (segment->stop), GST_TIME_ARGS (segment->time));
|
2009-07-01 17:55:12 +00:00
|
|
|
} else {
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder,
|
2011-03-27 20:27:09 +00:00
|
|
|
"dropping buffer outside segment: %" GST_TIME_FORMAT
|
2010-06-01 22:54:51 +00:00
|
|
|
" %" GST_TIME_FORMAT
|
|
|
|
" seg %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT
|
|
|
|
" time %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (src_buffer)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (src_buffer) +
|
|
|
|
GST_BUFFER_DURATION (src_buffer)),
|
2010-10-10 00:36:07 +00:00
|
|
|
GST_TIME_ARGS (segment->start),
|
|
|
|
GST_TIME_ARGS (segment->stop), GST_TIME_ARGS (segment->time));
|
2009-07-01 17:55:12 +00:00
|
|
|
gst_buffer_unref (src_buffer);
|
2011-08-18 08:02:50 +00:00
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
goto done;
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-01 16:00:11 +00:00
|
|
|
/* we got data, so note things are looking up again */
|
|
|
|
if (G_UNLIKELY (base_video_decoder->error_count))
|
|
|
|
base_video_decoder->error_count--;
|
|
|
|
|
2011-03-31 12:47:55 +00:00
|
|
|
if (GST_BASE_VIDEO_CODEC (base_video_decoder)->segment.rate < 0.0) {
|
|
|
|
GST_LOG_OBJECT (base_video_decoder, "queued buffer");
|
|
|
|
base_video_decoder->queued =
|
|
|
|
g_list_prepend (base_video_decoder->queued, src_buffer);
|
|
|
|
} else {
|
|
|
|
ret = gst_pad_push (GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_decoder),
|
|
|
|
src_buffer);
|
|
|
|
}
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2011-03-28 06:59:20 +00:00
|
|
|
done:
|
2010-10-10 00:36:07 +00:00
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->frames =
|
|
|
|
g_list_remove (GST_BASE_VIDEO_CODEC (base_video_decoder)->frames, frame);
|
2011-07-09 09:09:12 +00:00
|
|
|
gst_base_video_codec_free_frame (frame);
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
|
|
|
|
2011-03-28 06:59:20 +00:00
|
|
|
return ret;
|
2010-06-01 22:54:51 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/**
|
|
|
|
* gst_base_video_decoder_finish_frame:
|
|
|
|
* @base_video_decoder: a #GstBaseVideoDecoder
|
2011-10-04 12:27:32 +00:00
|
|
|
* @n_bytes: an encoded #GstVideoFrameState
|
2011-03-30 07:15:13 +00:00
|
|
|
*
|
|
|
|
* Removes next @n_bytes of input data and adds it to currently parsed frame.
|
|
|
|
*/
|
2009-07-01 17:55:12 +00:00
|
|
|
void
|
|
|
|
gst_base_video_decoder_add_to_frame (GstBaseVideoDecoder * base_video_decoder,
|
|
|
|
int n_bytes)
|
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "add %d bytes to frame", n_bytes);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
if (n_bytes == 0)
|
|
|
|
return;
|
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
2010-06-01 22:54:51 +00:00
|
|
|
if (gst_adapter_available (base_video_decoder->output_adapter) == 0) {
|
|
|
|
base_video_decoder->frame_offset = base_video_decoder->input_offset -
|
|
|
|
gst_adapter_available (base_video_decoder->input_adapter);
|
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
buf = gst_adapter_take_buffer (base_video_decoder->input_adapter, n_bytes);
|
|
|
|
|
|
|
|
gst_adapter_push (base_video_decoder->output_adapter, buf);
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static guint64
|
|
|
|
gst_base_video_decoder_get_timestamp (GstBaseVideoDecoder * base_video_decoder,
|
|
|
|
int picture_number)
|
|
|
|
{
|
2010-10-10 00:36:07 +00:00
|
|
|
GstVideoState *state = &GST_BASE_VIDEO_CODEC (base_video_decoder)->state;
|
|
|
|
|
2011-04-03 20:35:13 +00:00
|
|
|
if (state->fps_d == 0 || state->fps_n == 0) {
|
2009-07-01 17:55:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (picture_number < base_video_decoder->base_picture_number) {
|
|
|
|
return base_video_decoder->timestamp_offset -
|
|
|
|
(gint64) gst_util_uint64_scale (base_video_decoder->base_picture_number
|
2010-10-10 00:36:07 +00:00
|
|
|
- picture_number, state->fps_d * GST_SECOND, state->fps_n);
|
2009-07-01 17:55:12 +00:00
|
|
|
} else {
|
|
|
|
return base_video_decoder->timestamp_offset +
|
|
|
|
gst_util_uint64_scale (picture_number -
|
|
|
|
base_video_decoder->base_picture_number,
|
2010-10-10 00:36:07 +00:00
|
|
|
state->fps_d * GST_SECOND, state->fps_n);
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint64
|
|
|
|
gst_base_video_decoder_get_field_timestamp (GstBaseVideoDecoder *
|
|
|
|
base_video_decoder, int field_offset)
|
|
|
|
{
|
2010-10-10 00:36:07 +00:00
|
|
|
GstVideoState *state = &GST_BASE_VIDEO_CODEC (base_video_decoder)->state;
|
|
|
|
|
2011-04-03 20:35:13 +00:00
|
|
|
if (state->fps_d == 0 || state->fps_n == 0) {
|
2009-07-01 17:55:12 +00:00
|
|
|
return GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
if (field_offset < 0) {
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_WARNING_OBJECT (base_video_decoder, "field offset < 0");
|
2009-07-01 17:55:12 +00:00
|
|
|
return GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
return base_video_decoder->timestamp_offset +
|
2010-10-10 00:36:07 +00:00
|
|
|
gst_util_uint64_scale (field_offset, state->fps_d * GST_SECOND,
|
|
|
|
state->fps_n * 2);
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
static guint64
|
|
|
|
gst_base_video_decoder_get_field_duration (GstBaseVideoDecoder *
|
|
|
|
base_video_decoder, int n_fields)
|
|
|
|
{
|
2010-10-10 00:36:07 +00:00
|
|
|
GstVideoState *state = &GST_BASE_VIDEO_CODEC (base_video_decoder)->state;
|
|
|
|
|
2011-04-03 20:35:13 +00:00
|
|
|
if (state->fps_d == 0 || state->fps_n == 0) {
|
2010-06-01 22:54:51 +00:00
|
|
|
return GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
if (n_fields < 0) {
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_WARNING_OBJECT (base_video_decoder, "n_fields < 0");
|
2010-06-01 22:54:51 +00:00
|
|
|
return GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
2010-10-10 00:36:07 +00:00
|
|
|
return gst_util_uint64_scale (n_fields, state->fps_d * GST_SECOND,
|
|
|
|
state->fps_n * 2);
|
2010-06-01 22:54:51 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/**
|
|
|
|
* gst_base_video_decoder_have_frame:
|
|
|
|
* @base_video_decoder: a #GstBaseVideoDecoder
|
|
|
|
*
|
|
|
|
* Gathers all data collected for currently parsed frame, gathers corresponding
|
|
|
|
* metadata and passes it along for further processing, i.e. @handle_frame.
|
|
|
|
*
|
|
|
|
* Returns: a #GstFlowReturn
|
|
|
|
*/
|
2009-07-01 17:55:12 +00:00
|
|
|
GstFlowReturn
|
|
|
|
gst_base_video_decoder_have_frame (GstBaseVideoDecoder * base_video_decoder)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
int n_available;
|
2010-06-01 22:54:51 +00:00
|
|
|
GstClockTime timestamp;
|
|
|
|
GstClockTime duration;
|
2011-08-18 08:02:50 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "have_frame");
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
n_available = gst_adapter_available (base_video_decoder->output_adapter);
|
|
|
|
if (n_available) {
|
|
|
|
buffer = gst_adapter_take_buffer (base_video_decoder->output_adapter,
|
|
|
|
n_available);
|
|
|
|
} else {
|
|
|
|
buffer = gst_buffer_new_and_alloc (0);
|
|
|
|
}
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
base_video_decoder->current_frame->sink_buffer = buffer;
|
|
|
|
|
|
|
|
gst_base_video_decoder_get_timestamp_at_offset (base_video_decoder,
|
|
|
|
base_video_decoder->frame_offset, ×tamp, &duration);
|
|
|
|
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = timestamp;
|
|
|
|
GST_BUFFER_DURATION (buffer) = duration;
|
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "collected frame size %d, "
|
|
|
|
"ts %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT,
|
|
|
|
n_available, GST_TIME_ARGS (timestamp), GST_TIME_ARGS (duration));
|
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
ret = gst_base_video_decoder_have_frame_2 (base_video_decoder);
|
|
|
|
|
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
|
|
|
|
|
|
|
return ret;
|
2010-06-01 22:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_video_decoder_have_frame_2 (GstBaseVideoDecoder * base_video_decoder)
|
|
|
|
{
|
2011-10-04 12:27:32 +00:00
|
|
|
GstVideoFrameState *frame = base_video_decoder->current_frame;
|
2010-06-01 22:54:51 +00:00
|
|
|
GstBaseVideoDecoderClass *base_video_decoder_class;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
|
|
|
|
base_video_decoder_class =
|
|
|
|
GST_BASE_VIDEO_DECODER_GET_CLASS (base_video_decoder);
|
|
|
|
|
2011-03-30 07:17:22 +00:00
|
|
|
g_return_val_if_fail (base_video_decoder_class->handle_frame != NULL,
|
|
|
|
GST_FLOW_ERROR);
|
|
|
|
|
2011-03-31 12:47:55 +00:00
|
|
|
/* capture frames and queue for later processing */
|
|
|
|
if (GST_BASE_VIDEO_CODEC (base_video_decoder)->segment.rate < 0.0 &&
|
|
|
|
!base_video_decoder->process) {
|
|
|
|
base_video_decoder->parse_gather =
|
|
|
|
g_list_prepend (base_video_decoder->parse_gather, frame);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
frame->distance_from_sync = base_video_decoder->distance_from_sync;
|
|
|
|
base_video_decoder->distance_from_sync++;
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
frame->presentation_timestamp = GST_BUFFER_TIMESTAMP (frame->sink_buffer);
|
|
|
|
frame->presentation_duration = GST_BUFFER_DURATION (frame->sink_buffer);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "pts %" GST_TIME_FORMAT,
|
2009-07-01 17:55:12 +00:00
|
|
|
GST_TIME_ARGS (frame->presentation_timestamp));
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "dts %" GST_TIME_FORMAT,
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_TIME_ARGS (frame->decode_timestamp));
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "dist %d", frame->distance_from_sync);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2010-10-10 00:36:07 +00:00
|
|
|
GST_BASE_VIDEO_CODEC (base_video_decoder)->frames =
|
|
|
|
g_list_append (GST_BASE_VIDEO_CODEC (base_video_decoder)->frames, frame);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2010-10-10 00:36:07 +00:00
|
|
|
frame->deadline =
|
|
|
|
gst_segment_to_running_time (&GST_BASE_VIDEO_CODEC
|
|
|
|
(base_video_decoder)->segment, GST_FORMAT_TIME,
|
|
|
|
frame->presentation_timestamp);
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
/* do something with frame */
|
2011-11-03 12:56:49 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "Calling ::handle_frame()");
|
2010-09-19 00:28:48 +00:00
|
|
|
ret = base_video_decoder_class->handle_frame (base_video_decoder, frame);
|
2010-08-27 16:32:46 +00:00
|
|
|
if (ret != GST_FLOW_OK) {
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "flow error %s",
|
|
|
|
gst_flow_get_name (ret));
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 12:47:55 +00:00
|
|
|
exit:
|
2009-07-01 17:55:12 +00:00
|
|
|
/* create new frame */
|
|
|
|
base_video_decoder->current_frame =
|
|
|
|
gst_base_video_decoder_new_frame (base_video_decoder);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/**
|
|
|
|
* gst_base_video_decoder_get_state:
|
|
|
|
* @base_video_decoder: a #GstBaseVideoDecoder
|
|
|
|
*
|
|
|
|
* Returns: #GstVideoState describing format of video data.
|
|
|
|
*/
|
2009-07-01 17:55:12 +00:00
|
|
|
GstVideoState *
|
|
|
|
gst_base_video_decoder_get_state (GstBaseVideoDecoder * base_video_decoder)
|
|
|
|
{
|
2010-10-10 00:36:07 +00:00
|
|
|
return &GST_BASE_VIDEO_CODEC (base_video_decoder)->state;
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/**
|
|
|
|
* gst_base_video_decoder_lost_sync:
|
|
|
|
* @base_video_decoder: a #GstBaseVideoDecoder
|
|
|
|
*
|
|
|
|
* Advances out-of-sync input data by 1 byte and marks it accordingly.
|
|
|
|
*/
|
2009-07-01 17:55:12 +00:00
|
|
|
void
|
|
|
|
gst_base_video_decoder_lost_sync (GstBaseVideoDecoder * base_video_decoder)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_BASE_VIDEO_DECODER (base_video_decoder));
|
|
|
|
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "lost_sync");
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
if (gst_adapter_available (base_video_decoder->input_adapter) >= 1) {
|
|
|
|
gst_adapter_flush (base_video_decoder->input_adapter, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
base_video_decoder->have_sync = FALSE;
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/* FIXME not quite exciting; get rid of this ? */
|
|
|
|
/**
|
|
|
|
* gst_base_video_decoder_set_sync_point:
|
|
|
|
* @base_video_decoder: a #GstBaseVideoDecoder
|
|
|
|
*
|
|
|
|
* Marks current frame as a sync point, i.e. keyframe.
|
|
|
|
*/
|
2009-07-01 17:55:12 +00:00
|
|
|
void
|
|
|
|
gst_base_video_decoder_set_sync_point (GstBaseVideoDecoder * base_video_decoder)
|
|
|
|
{
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "set_sync_point");
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
2009-07-01 17:55:12 +00:00
|
|
|
base_video_decoder->current_frame->is_sync_point = TRUE;
|
|
|
|
base_video_decoder->distance_from_sync = 0;
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
2010-06-01 22:54:51 +00:00
|
|
|
}
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/**
|
|
|
|
* gst_base_video_decoder_get_oldest_frame:
|
|
|
|
* @base_video_decoder: a #GstBaseVideoDecoder
|
|
|
|
*
|
2011-10-04 12:27:32 +00:00
|
|
|
* Returns: oldest pending unfinished #GstVideoFrameState.
|
2011-03-30 07:15:13 +00:00
|
|
|
*/
|
2011-10-04 12:27:32 +00:00
|
|
|
GstVideoFrameState *
|
2010-06-01 22:54:51 +00:00
|
|
|
gst_base_video_decoder_get_oldest_frame (GstBaseVideoDecoder *
|
|
|
|
base_video_decoder)
|
|
|
|
{
|
|
|
|
GList *g;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
2010-10-10 00:36:07 +00:00
|
|
|
g = g_list_first (GST_BASE_VIDEO_CODEC (base_video_decoder)->frames);
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
if (g == NULL)
|
|
|
|
return NULL;
|
2011-10-04 12:27:32 +00:00
|
|
|
return (GstVideoFrameState *) (g->data);
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/**
|
|
|
|
* gst_base_video_decoder_get_frame:
|
|
|
|
* @base_video_decoder: a #GstBaseVideoDecoder
|
|
|
|
* @frame_number: system_frame_number of a frame
|
|
|
|
*
|
2011-10-04 12:27:32 +00:00
|
|
|
* Returns: pending unfinished #GstVideoFrameState identified by @frame_number.
|
2011-03-30 07:15:13 +00:00
|
|
|
*/
|
2011-10-04 12:27:32 +00:00
|
|
|
GstVideoFrameState *
|
2009-07-01 17:55:12 +00:00
|
|
|
gst_base_video_decoder_get_frame (GstBaseVideoDecoder * base_video_decoder,
|
|
|
|
int frame_number)
|
|
|
|
{
|
|
|
|
GList *g;
|
2011-10-04 12:27:32 +00:00
|
|
|
GstVideoFrameState *frame = NULL;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
2010-10-10 00:36:07 +00:00
|
|
|
for (g = g_list_first (GST_BASE_VIDEO_CODEC (base_video_decoder)->frames);
|
|
|
|
g; g = g_list_next (g)) {
|
2011-10-04 12:27:32 +00:00
|
|
|
GstVideoFrameState *tmp = g->data;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
if (frame->system_frame_number == frame_number) {
|
2011-07-11 09:28:40 +00:00
|
|
|
frame = tmp;
|
|
|
|
break;
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-07-11 09:28:40 +00:00
|
|
|
return frame;
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/**
|
|
|
|
* gst_base_video_decoder_set_src_caps:
|
|
|
|
* @base_video_decoder: a #GstBaseVideoDecoder
|
|
|
|
*
|
|
|
|
* Sets src pad caps according to currently configured #GstVideoState.
|
|
|
|
*
|
2011-11-03 12:56:49 +00:00
|
|
|
* The #GstVideoInfo and #GstBufferPool will be created and negotiated
|
|
|
|
* according to those values.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the format was properly negotiated, else %FALSE.
|
2011-03-30 07:15:13 +00:00
|
|
|
*/
|
2011-03-30 07:17:22 +00:00
|
|
|
gboolean
|
2009-07-01 17:55:12 +00:00
|
|
|
gst_base_video_decoder_set_src_caps (GstBaseVideoDecoder * base_video_decoder)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
2011-11-03 12:56:49 +00:00
|
|
|
GstBaseVideoCodec *codec = GST_BASE_VIDEO_CODEC (base_video_decoder);
|
|
|
|
GstVideoState *state = &codec->state;
|
|
|
|
GstVideoInfo *info = &codec->info;
|
|
|
|
GstQuery *query;
|
|
|
|
GstBufferPool *pool = NULL;
|
|
|
|
GstStructure *config;
|
|
|
|
guint size, min, max, prefix, alignment;
|
2011-03-30 07:17:22 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
/* minimum sense */
|
|
|
|
g_return_val_if_fail (state->format != GST_VIDEO_FORMAT_UNKNOWN, FALSE);
|
|
|
|
g_return_val_if_fail (state->width != 0, FALSE);
|
|
|
|
g_return_val_if_fail (state->height != 0, FALSE);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
|
|
|
|
2011-11-03 12:56:49 +00:00
|
|
|
gst_video_info_set_format (info, state->format, state->width, state->height);
|
|
|
|
|
2011-03-30 07:17:22 +00:00
|
|
|
/* sanitize */
|
2011-06-04 02:36:12 +00:00
|
|
|
if (state->fps_n == 0 || state->fps_d == 0) {
|
2011-03-30 07:17:22 +00:00
|
|
|
state->fps_n = 0;
|
|
|
|
state->fps_d = 1;
|
|
|
|
}
|
2011-06-04 02:36:12 +00:00
|
|
|
if (state->par_n == 0 || state->par_d == 0) {
|
|
|
|
state->par_n = 1;
|
2011-03-30 07:17:22 +00:00
|
|
|
state->par_d = 1;
|
|
|
|
}
|
|
|
|
|
2011-11-03 12:56:49 +00:00
|
|
|
info->par_n = state->par_n;
|
|
|
|
info->par_d = state->par_d;
|
|
|
|
info->fps_n = state->fps_n;
|
|
|
|
info->fps_d = state->fps_d;
|
|
|
|
|
|
|
|
if (state->have_interlaced) {
|
|
|
|
if (state->interlaced)
|
|
|
|
GST_VIDEO_INFO_FLAG_SET (info, GST_VIDEO_FLAG_INTERLACED);
|
|
|
|
if (state->top_field_first)
|
|
|
|
GST_VIDEO_INFO_FLAG_SET (info, GST_VIDEO_FLAG_TFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME : Handle chroma site */
|
|
|
|
/* FIXME : Handle colorimetry */
|
|
|
|
|
|
|
|
caps = gst_video_info_to_caps (info);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-27 20:27:09 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "setting caps %" GST_PTR_FORMAT, caps);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-03-30 07:17:22 +00:00
|
|
|
ret =
|
|
|
|
gst_pad_set_caps (GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_decoder),
|
|
|
|
caps);
|
2010-06-01 22:54:51 +00:00
|
|
|
gst_caps_unref (caps);
|
2011-03-30 07:17:22 +00:00
|
|
|
|
2011-11-03 12:56:49 +00:00
|
|
|
/* Negotiate pool */
|
|
|
|
query = gst_query_new_allocation (caps, TRUE);
|
|
|
|
|
|
|
|
if (gst_pad_peer_query (codec->srcpad, query)) {
|
|
|
|
GST_DEBUG_OBJECT (codec, "got downstream ALLOCATION hints");
|
|
|
|
/* we got configuration from our peer, parse them */
|
|
|
|
gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
|
|
|
|
&alignment, &pool);
|
|
|
|
size = MAX (size, info->size);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (codec, "didn't get downstream ALLOCATION hints");
|
|
|
|
size = info->size;
|
|
|
|
min = max = 0;
|
|
|
|
prefix = 0;
|
|
|
|
alignment = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool == NULL) {
|
|
|
|
/* we did not get a pool, make one ourselves then */
|
|
|
|
pool = gst_buffer_pool_new ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base_video_decoder->pool)
|
|
|
|
gst_object_unref (base_video_decoder->pool);
|
|
|
|
base_video_decoder->pool = pool;
|
|
|
|
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set (config, caps, size, min, max, prefix, alignment);
|
|
|
|
state->bytes_per_picture = size;
|
|
|
|
|
|
|
|
/* just set the option, if the pool can support it we will transparently use
|
|
|
|
* it through the video info API. We could also see if the pool support this
|
|
|
|
* option and only activate it then. */
|
|
|
|
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
|
|
|
|
|
|
|
/* check if downstream supports cropping */
|
|
|
|
base_video_decoder->use_cropping =
|
2011-11-03 15:57:17 +00:00
|
|
|
gst_query_has_allocation_meta (query, GST_VIDEO_CROP_META_API);
|
2011-11-03 12:56:49 +00:00
|
|
|
|
|
|
|
gst_buffer_pool_set_config (pool, config);
|
|
|
|
/* and activate */
|
|
|
|
gst_buffer_pool_set_active (pool, TRUE);
|
|
|
|
|
|
|
|
gst_query_unref (query);
|
2011-03-30 08:18:23 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
|
|
|
|
2011-03-30 07:17:22 +00:00
|
|
|
return ret;
|
2010-06-01 22:54:51 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/**
|
|
|
|
* gst_base_video_decoder_alloc_src_buffer:
|
|
|
|
* @base_video_decoder: a #GstBaseVideoDecoder
|
|
|
|
*
|
2011-11-03 12:56:49 +00:00
|
|
|
* Helper function that returns a buffer from the decoders' configured
|
|
|
|
* #GstBufferPool.
|
2011-03-30 07:15:13 +00:00
|
|
|
*
|
|
|
|
* Returns: allocated buffer
|
|
|
|
*/
|
2011-03-27 00:43:54 +00:00
|
|
|
GstBuffer *
|
|
|
|
gst_base_video_decoder_alloc_src_buffer (GstBaseVideoDecoder *
|
|
|
|
base_video_decoder)
|
|
|
|
{
|
2011-11-03 12:56:49 +00:00
|
|
|
GstBuffer *buffer = NULL;
|
2011-08-18 08:02:50 +00:00
|
|
|
|
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
|
|
|
|
2011-11-03 12:56:49 +00:00
|
|
|
gst_buffer_pool_acquire_buffer (base_video_decoder->pool, &buffer, NULL);
|
2011-03-27 00:43:54 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
2011-11-03 12:56:49 +00:00
|
|
|
|
2011-03-27 00:43:54 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/**
|
|
|
|
* gst_base_video_decoder_alloc_src_frame:
|
|
|
|
* @base_video_decoder: a #GstBaseVideoDecoder
|
2011-10-04 12:27:32 +00:00
|
|
|
* @frame: a #GstVideoFrameState
|
2011-03-30 07:15:13 +00:00
|
|
|
*
|
|
|
|
* Helper function that uses gst_pad_alloc_buffer_and_set_caps
|
|
|
|
* to allocate a buffer to hold a video frame for @base_video_decoder's
|
2011-03-30 08:18:23 +00:00
|
|
|
* current #GstVideoState. Subclass should already have configured video state
|
|
|
|
* and set src pad caps.
|
2011-03-30 07:15:13 +00:00
|
|
|
*
|
|
|
|
* Returns: result from pad alloc call
|
|
|
|
*/
|
2010-06-01 22:54:51 +00:00
|
|
|
GstFlowReturn
|
|
|
|
gst_base_video_decoder_alloc_src_frame (GstBaseVideoDecoder *
|
2011-10-04 12:27:32 +00:00
|
|
|
base_video_decoder, GstVideoFrameState * frame)
|
2010-06-01 22:54:51 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn flow_ret;
|
|
|
|
|
2011-11-03 12:56:49 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "alloc buffer");
|
2010-06-01 22:54:51 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_LOCK (base_video_decoder);
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
flow_ret =
|
2011-11-03 12:56:49 +00:00
|
|
|
gst_buffer_pool_acquire_buffer (base_video_decoder->pool,
|
|
|
|
&frame->src_buffer, NULL);
|
2010-06-01 22:54:51 +00:00
|
|
|
|
|
|
|
if (flow_ret != GST_FLOW_OK) {
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_WARNING_OBJECT (base_video_decoder, "failed to get buffer %s",
|
|
|
|
gst_flow_get_name (flow_ret));
|
2010-06-01 22:54:51 +00:00
|
|
|
}
|
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_BASE_VIDEO_CODEC_STREAM_UNLOCK (base_video_decoder);
|
|
|
|
|
2010-06-01 22:54:51 +00:00
|
|
|
return flow_ret;
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
2010-09-19 00:28:48 +00:00
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/**
|
|
|
|
* gst_base_video_decoder_get_max_decode_time:
|
|
|
|
* @base_video_decoder: a #GstBaseVideoDecoder
|
2011-10-04 12:27:32 +00:00
|
|
|
* @frame: a #GstVideoFrameState
|
2011-03-30 07:15:13 +00:00
|
|
|
*
|
|
|
|
* Determines maximum possible decoding time for @frame that will
|
|
|
|
* allow it to decode and arrive in time (as determined by QoS messages).
|
|
|
|
* In particular, a negative result means decoding in time is no longer possible
|
|
|
|
* and should therefore occur as soon/skippy as possible.
|
|
|
|
*
|
|
|
|
* Returns: max decoding time.
|
|
|
|
*/
|
2010-09-19 00:28:48 +00:00
|
|
|
GstClockTimeDiff
|
|
|
|
gst_base_video_decoder_get_max_decode_time (GstBaseVideoDecoder *
|
2011-10-04 12:27:32 +00:00
|
|
|
base_video_decoder, GstVideoFrameState * frame)
|
2010-09-19 00:28:48 +00:00
|
|
|
{
|
|
|
|
GstClockTimeDiff deadline;
|
2010-10-10 00:36:07 +00:00
|
|
|
GstClockTime earliest_time;
|
2010-09-19 00:28:48 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_OBJECT_LOCK (base_video_decoder);
|
2010-10-10 00:36:07 +00:00
|
|
|
earliest_time = GST_BASE_VIDEO_CODEC (base_video_decoder)->earliest_time;
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (earliest_time))
|
|
|
|
deadline = GST_CLOCK_DIFF (earliest_time, frame->deadline);
|
2010-09-19 00:28:48 +00:00
|
|
|
else
|
|
|
|
deadline = G_MAXINT64;
|
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_LOG_OBJECT (base_video_decoder, "earliest %" GST_TIME_FORMAT
|
|
|
|
", frame deadline %" GST_TIME_FORMAT ", deadline %" GST_TIME_FORMAT,
|
2011-04-28 10:02:27 +00:00
|
|
|
GST_TIME_ARGS (earliest_time), GST_TIME_ARGS (frame->deadline),
|
|
|
|
GST_TIME_ARGS (deadline));
|
2011-03-28 14:15:19 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
GST_OBJECT_UNLOCK (base_video_decoder);
|
|
|
|
|
2010-09-19 00:28:48 +00:00
|
|
|
return deadline;
|
|
|
|
}
|
2010-09-19 02:21:47 +00:00
|
|
|
|
2011-03-30 07:15:13 +00:00
|
|
|
/**
|
|
|
|
* gst_base_video_decoder_get_oldest_frame:
|
|
|
|
* @base_video_decoder_class: a #GstBaseVideoDecoderClass
|
|
|
|
*
|
|
|
|
* Sets the mask and pattern that will be scanned for to obtain parse sync.
|
|
|
|
* Note that a non-zero @mask implies that @scan_for_sync will be ignored.
|
|
|
|
*
|
|
|
|
*/
|
2010-09-19 02:21:47 +00:00
|
|
|
void
|
|
|
|
gst_base_video_decoder_class_set_capture_pattern (GstBaseVideoDecoderClass *
|
|
|
|
base_video_decoder_class, guint32 mask, guint32 pattern)
|
|
|
|
{
|
|
|
|
g_return_if_fail (((~mask) & pattern) == 0);
|
|
|
|
|
2011-03-28 14:15:19 +00:00
|
|
|
GST_DEBUG ("capture mask %08x, pattern %08x", mask, pattern);
|
|
|
|
|
2010-09-19 02:21:47 +00:00
|
|
|
base_video_decoder_class->capture_mask = mask;
|
|
|
|
base_video_decoder_class->capture_pattern = pattern;
|
|
|
|
}
|
2011-04-01 16:00:11 +00:00
|
|
|
|
|
|
|
GstFlowReturn
|
|
|
|
_gst_base_video_decoder_error (GstBaseVideoDecoder * dec, gint weight,
|
|
|
|
GQuark domain, gint code, gchar * txt, gchar * dbg, const gchar * file,
|
|
|
|
const gchar * function, gint line)
|
|
|
|
{
|
|
|
|
if (txt)
|
|
|
|
GST_WARNING_OBJECT (dec, "error: %s", txt);
|
|
|
|
if (dbg)
|
|
|
|
GST_WARNING_OBJECT (dec, "error: %s", dbg);
|
|
|
|
dec->error_count += weight;
|
|
|
|
GST_BASE_VIDEO_CODEC (dec)->discont = TRUE;
|
|
|
|
if (dec->max_errors < dec->error_count) {
|
|
|
|
gst_element_message_full (GST_ELEMENT (dec), GST_MESSAGE_ERROR,
|
|
|
|
domain, code, txt, dbg, file, function, line);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
} else {
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
}
|