2008-11-13 12:59:34 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Nokia Corporation. All rights reserved.
|
|
|
|
* Contact: Stefan Kost <stefan.kost@nokia.com>
|
|
|
|
* Copyright (C) 2008 Sebastian Dröge <sebastian.droege@collabora.co.uk>.
|
2011-10-20 06:31:18 +00:00
|
|
|
* Copyright (C) 2011, Hewlett-Packard Development Company, L.P.
|
|
|
|
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
|
2008-11-13 12:59:34 +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
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-11-13 12:59:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gstbaseparse
|
|
|
|
* @short_description: Base class for stream parsers
|
|
|
|
* @see_also: #GstBaseTransform
|
|
|
|
*
|
2011-02-18 13:05:31 +00:00
|
|
|
* This base class is for parser elements that process data and splits it
|
2008-11-13 12:59:34 +00:00
|
|
|
* into separate audio/video/whatever frames.
|
|
|
|
*
|
|
|
|
* It provides for:
|
|
|
|
* <itemizedlist>
|
2011-04-09 21:57:46 +00:00
|
|
|
* <listitem><para>provides one sink pad and one source pad</para></listitem>
|
|
|
|
* <listitem><para>handles state changes</para></listitem>
|
|
|
|
* <listitem><para>can operate in pull mode or push mode</para></listitem>
|
|
|
|
* <listitem><para>handles seeking in both modes</para></listitem>
|
2012-12-14 14:22:27 +00:00
|
|
|
* <listitem><para>handles events (SEGMENT/EOS/FLUSH)</para></listitem>
|
2008-11-13 12:59:34 +00:00
|
|
|
* <listitem><para>
|
2011-04-09 21:57:46 +00:00
|
|
|
* handles queries (POSITION/DURATION/SEEKING/FORMAT/CONVERT)
|
2008-11-13 12:59:34 +00:00
|
|
|
* </para></listitem>
|
2011-04-09 21:57:46 +00:00
|
|
|
* <listitem><para>handles flushing</para></listitem>
|
2008-11-13 12:59:34 +00:00
|
|
|
* </itemizedlist>
|
|
|
|
*
|
2011-04-09 21:57:46 +00:00
|
|
|
* The purpose of this base class is to provide the basic functionality of
|
2008-11-13 12:59:34 +00:00
|
|
|
* a parser and share a lot of rather complex code.
|
|
|
|
*
|
|
|
|
* Description of the parsing mechanism:
|
|
|
|
* <orderedlist>
|
|
|
|
* <listitem>
|
|
|
|
* <itemizedlist><title>Set-up phase</title>
|
|
|
|
* <listitem><para>
|
|
|
|
* GstBaseParse calls @start to inform subclass that data processing is
|
|
|
|
* about to start now.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
2012-02-13 17:22:37 +00:00
|
|
|
* GstBaseParse class calls @set_sink_caps to inform the subclass about
|
|
|
|
* incoming sinkpad caps. Subclass could already set the srcpad caps
|
|
|
|
* accordingly, but this might be delayed until calling
|
|
|
|
* gst_base_parse_finish_frame() with a non-queued frame.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
2011-04-09 21:57:46 +00:00
|
|
|
* At least at this point subclass needs to tell the GstBaseParse class
|
2011-02-18 13:05:31 +00:00
|
|
|
* how big data chunks it wants to receive (min_frame_size). It can do
|
2011-04-09 21:57:46 +00:00
|
|
|
* this with gst_base_parse_set_min_frame_size().
|
2008-11-13 12:59:34 +00:00
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* GstBaseParse class sets up appropriate data passing mode (pull/push)
|
|
|
|
* and starts to process the data.
|
|
|
|
* </para></listitem>
|
|
|
|
* </itemizedlist>
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* <itemizedlist>
|
|
|
|
* <title>Parsing phase</title>
|
|
|
|
* <listitem><para>
|
2011-02-18 13:05:31 +00:00
|
|
|
* GstBaseParse gathers at least min_frame_size bytes of data either
|
2011-04-09 21:57:46 +00:00
|
|
|
* by pulling it from upstream or collecting buffers in an internal
|
2008-11-13 12:59:34 +00:00
|
|
|
* #GstAdapter.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
2011-01-06 10:16:56 +00:00
|
|
|
* A buffer of (at least) min_frame_size bytes is passed to subclass with
|
2012-02-13 17:22:37 +00:00
|
|
|
* @handle_frame. Subclass checks the contents and can optionally
|
|
|
|
* return GST_FLOW_OK along with an amount of data to be skipped to find
|
|
|
|
* a valid frame (which will result in a subsequent DISCONT).
|
|
|
|
* If, otherwise, the buffer does not hold a complete frame,
|
|
|
|
* @handle_frame can merely return and will be called again when additional
|
|
|
|
* data is available. In push mode this amounts to an
|
|
|
|
* additional input buffer (thus minimal additional latency), in pull mode
|
|
|
|
* this amounts to some arbitrary reasonable buffer size increase.
|
2013-01-14 20:02:42 +00:00
|
|
|
* Of course, gst_base_parse_set_min_frame_size() could also be used if a
|
|
|
|
* very specific known amount of additional data is required.
|
2012-02-13 17:22:37 +00:00
|
|
|
* If, however, the buffer holds a complete valid frame, it can pass
|
|
|
|
* the size of this frame to gst_base_parse_finish_frame().
|
|
|
|
* If acting as a converter, it can also merely indicate consumed input data
|
|
|
|
* while simultaneously providing custom output data.
|
|
|
|
* Note that baseclass performs some processing (such as tracking
|
|
|
|
* overall consumed data rate versus duration) for each finished frame,
|
|
|
|
* but other state is only updated upon each call to @handle_frame
|
|
|
|
* (such as tracking upstream input timestamp).
|
|
|
|
* </para><para>
|
|
|
|
* Subclass is also responsible for setting the buffer metadata
|
|
|
|
* (e.g. buffer timestamp and duration, or keyframe if applicable).
|
2010-09-27 10:16:43 +00:00
|
|
|
* (although the latter can also be done by GstBaseParse if it is
|
2011-01-10 16:07:38 +00:00
|
|
|
* appropriately configured, see below). Frame is provided with
|
|
|
|
* timestamp derived from upstream (as much as generally possible),
|
2011-04-09 21:57:46 +00:00
|
|
|
* duration obtained from configuration (see below), and offset
|
2011-01-10 16:07:38 +00:00
|
|
|
* if meaningful (in pull mode).
|
2012-02-13 17:22:37 +00:00
|
|
|
* </para><para>
|
|
|
|
* Note that @check_valid_frame might receive any small
|
|
|
|
* amount of input data when leftover data is being drained (e.g. at EOS).
|
2008-11-13 12:59:34 +00:00
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
2012-02-13 17:22:37 +00:00
|
|
|
* As part of finish frame processing,
|
|
|
|
* just prior to actually pushing the buffer in question,
|
2011-10-20 14:59:01 +00:00
|
|
|
* it is passed to @pre_push_frame which gives subclass yet one
|
2010-09-27 10:16:43 +00:00
|
|
|
* last chance to examine buffer metadata, or to send some custom (tag)
|
|
|
|
* events, or to perform custom (segment) filtering.
|
2008-11-13 12:59:34 +00:00
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
2011-04-09 21:57:46 +00:00
|
|
|
* During the parsing process GstBaseParseClass will handle both srcpad
|
|
|
|
* and sinkpad events. They will be passed to subclass if @event or
|
2008-11-13 12:59:34 +00:00
|
|
|
* @src_event callbacks have been provided.
|
|
|
|
* </para></listitem>
|
|
|
|
* </itemizedlist>
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* <itemizedlist><title>Shutdown phase</title>
|
|
|
|
* <listitem><para>
|
|
|
|
* GstBaseParse 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
|
2011-02-18 13:05:31 +00:00
|
|
|
* 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 (e.g.
|
2008-11-13 12:59:34 +00:00
|
|
|
* when base class calls subclass' @set_sink_caps function).
|
|
|
|
*
|
2011-04-09 21:57:46 +00:00
|
|
|
* This base class uses #GST_FORMAT_DEFAULT as a meaning of frames. So,
|
2008-11-13 12:59:34 +00:00
|
|
|
* subclass conversion routine needs to know that conversion from
|
2011-04-09 21:57:46 +00:00
|
|
|
* #GST_FORMAT_TIME to #GST_FORMAT_DEFAULT must return the
|
2008-11-13 12:59:34 +00:00
|
|
|
* frame number that can be found from the given byte position.
|
|
|
|
*
|
2011-04-09 21:57:46 +00:00
|
|
|
* GstBaseParse uses subclasses conversion methods also for seeking (or
|
|
|
|
* otherwise uses its own default one, see also below).
|
2008-11-13 12:59:34 +00:00
|
|
|
*
|
|
|
|
* Subclass @start and @stop functions will be called to inform the beginning
|
|
|
|
* and end of data processing.
|
|
|
|
*
|
|
|
|
* Things that subclass need to take care of:
|
|
|
|
* <itemizedlist>
|
|
|
|
* <listitem><para>Provide pad templates</para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* Fixate the source pad caps when appropriate
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* Inform base class how big data chunks should be retrieved. This is
|
2011-04-09 21:57:46 +00:00
|
|
|
* done with gst_base_parse_set_min_frame_size() function.
|
2008-11-13 12:59:34 +00:00
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
2012-02-13 17:22:37 +00:00
|
|
|
* Examine data chunks passed to subclass with @handle_frame and pass
|
|
|
|
* proper frame(s) to gst_base_parse_finish_frame(), and setting src pad
|
|
|
|
* caps and timestamps on frame.
|
2008-11-13 12:59:34 +00:00
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>Provide conversion functions</para></listitem>
|
|
|
|
* <listitem><para>
|
2011-04-09 21:57:46 +00:00
|
|
|
* Update the duration information with gst_base_parse_set_duration()
|
2008-11-13 12:59:34 +00:00
|
|
|
* </para></listitem>
|
2009-11-23 14:48:25 +00:00
|
|
|
* <listitem><para>
|
2011-04-09 21:57:46 +00:00
|
|
|
* Optionally passthrough using gst_base_parse_set_passthrough()
|
2010-09-27 10:16:43 +00:00
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
2011-04-09 21:57:46 +00:00
|
|
|
* Configure various baseparse parameters using
|
|
|
|
* gst_base_parse_set_average_bitrate(), gst_base_parse_set_syncable()
|
|
|
|
* and gst_base_parse_set_frame_rate().
|
2010-09-27 10:16:43 +00:00
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* In particular, if subclass is unable to determine a duration, but
|
|
|
|
* parsing (or specs) yields a frames per seconds rate, then this can be
|
|
|
|
* provided to GstBaseParse to enable it to cater for
|
2011-04-09 21:57:46 +00:00
|
|
|
* buffer time metadata (which will be taken from upstream as much as
|
|
|
|
* possible). Internally keeping track of frame durations and respective
|
|
|
|
* sizes that have been pushed provides GstBaseParse with an estimated
|
|
|
|
* bitrate. A default @convert (used if not overriden) will then use these
|
|
|
|
* rates to perform obvious conversions. These rates are also used to
|
|
|
|
* update (estimated) duration at regular frame intervals.
|
2009-11-23 14:48:25 +00:00
|
|
|
* </para></listitem>
|
2008-11-13 12:59:34 +00:00
|
|
|
* </itemizedlist>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
* - In push mode provide a queue of adapter-"queued" buffers for upstream
|
|
|
|
* buffer metadata
|
|
|
|
* - Queue buffers/events until caps are set
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-03-13 23:43:52 +00:00
|
|
|
#include <gst/base/gstadapter.h>
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
#include "gstbaseparse.h"
|
|
|
|
|
2011-12-30 15:03:02 +00:00
|
|
|
/* FIXME: get rid of old GstIndex code */
|
|
|
|
#include "gstindex.h"
|
|
|
|
#include "gstindex.c"
|
|
|
|
#include "gstmemindex.c"
|
|
|
|
|
2011-04-15 16:41:02 +00:00
|
|
|
#define GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC (1 << 0)
|
|
|
|
|
2010-03-26 18:56:49 +00:00
|
|
|
#define MIN_FRAMES_TO_POST_BITRATE 10
|
2010-11-17 13:30:09 +00:00
|
|
|
#define TARGET_DIFFERENCE (20 * GST_SECOND)
|
2012-06-13 12:02:48 +00:00
|
|
|
#define MAX_INDEX_ENTRIES 4096
|
2010-03-26 18:56:49 +00:00
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_base_parse_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_base_parse_debug
|
|
|
|
|
|
|
|
/* Supported formats */
|
2011-04-19 10:51:30 +00:00
|
|
|
static const GstFormat fmtlist[] = {
|
2008-11-13 12:59:34 +00:00
|
|
|
GST_FORMAT_DEFAULT,
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
GST_FORMAT_TIME,
|
2011-08-25 21:26:08 +00:00
|
|
|
GST_FORMAT_UNDEFINED
|
2008-11-13 12:59:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define GST_BASE_PARSE_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BASE_PARSE, GstBaseParsePrivate))
|
|
|
|
|
|
|
|
struct _GstBaseParsePrivate
|
|
|
|
{
|
2011-11-18 11:35:46 +00:00
|
|
|
GstPadMode pad_mode;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-03-13 23:43:52 +00:00
|
|
|
GstAdapter *adapter;
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
gint64 duration;
|
|
|
|
GstFormat duration_fmt;
|
2009-12-16 17:38:33 +00:00
|
|
|
gint64 estimated_duration;
|
2011-10-06 12:34:09 +00:00
|
|
|
gint64 estimated_drift;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
guint min_frame_size;
|
2013-08-07 16:24:40 +00:00
|
|
|
gboolean disable_passthrough;
|
2011-04-06 16:43:27 +00:00
|
|
|
gboolean passthrough;
|
2012-09-13 05:44:37 +00:00
|
|
|
gboolean pts_interpolate;
|
2013-02-26 18:58:49 +00:00
|
|
|
gboolean infer_ts;
|
2011-04-06 16:43:27 +00:00
|
|
|
gboolean syncable;
|
|
|
|
gboolean has_timing_info;
|
2009-11-23 14:48:25 +00:00
|
|
|
guint fps_num, fps_den;
|
2011-01-21 13:53:39 +00:00
|
|
|
gint update_interval;
|
2010-09-17 16:24:22 +00:00
|
|
|
guint bitrate;
|
2010-09-22 13:07:09 +00:00
|
|
|
guint lead_in, lead_out;
|
|
|
|
GstClockTime lead_in_ts, lead_out_ts;
|
2011-05-12 09:55:20 +00:00
|
|
|
GstClockTime min_latency, max_latency;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
gboolean discont;
|
|
|
|
gboolean flushing;
|
2009-10-28 13:06:13 +00:00
|
|
|
gboolean drain;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
gint64 offset;
|
2010-09-20 14:39:37 +00:00
|
|
|
gint64 sync_offset;
|
2012-09-03 06:32:50 +00:00
|
|
|
GstClockTime next_pts;
|
|
|
|
GstClockTime next_dts;
|
|
|
|
GstClockTime prev_pts;
|
|
|
|
GstClockTime prev_dts;
|
2009-11-23 14:48:25 +00:00
|
|
|
GstClockTime frame_duration;
|
2010-11-08 18:58:31 +00:00
|
|
|
gboolean seen_keyframe;
|
|
|
|
gboolean is_video;
|
2012-02-13 17:22:37 +00:00
|
|
|
gint flushed;
|
2009-11-23 14:48:25 +00:00
|
|
|
|
|
|
|
guint64 framecount;
|
|
|
|
guint64 bytecount;
|
2010-03-25 11:22:58 +00:00
|
|
|
guint64 data_bytecount;
|
2009-12-16 17:38:33 +00:00
|
|
|
guint64 acc_duration;
|
2012-09-03 06:32:50 +00:00
|
|
|
GstClockTime first_frame_pts;
|
|
|
|
GstClockTime first_frame_dts;
|
2010-11-17 13:30:09 +00:00
|
|
|
gint64 first_frame_offset;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-03-25 11:22:58 +00:00
|
|
|
gboolean post_min_bitrate;
|
|
|
|
gboolean post_avg_bitrate;
|
|
|
|
gboolean post_max_bitrate;
|
|
|
|
guint min_bitrate;
|
|
|
|
guint avg_bitrate;
|
|
|
|
guint max_bitrate;
|
2010-09-20 11:30:54 +00:00
|
|
|
guint posted_avg_bitrate;
|
2010-03-25 11:22:58 +00:00
|
|
|
|
2011-04-02 12:02:01 +00:00
|
|
|
/* frames/buffers that are queued and ready to go on OK */
|
2011-04-02 13:04:42 +00:00
|
|
|
GQueue queued_frames;
|
2011-04-02 12:02:01 +00:00
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
GstBuffer *cache;
|
2010-09-21 08:57:04 +00:00
|
|
|
|
|
|
|
/* index entry storage, either ours or provided */
|
|
|
|
GstIndex *index;
|
|
|
|
gint index_id;
|
|
|
|
gboolean own_index;
|
2011-12-04 13:35:38 +00:00
|
|
|
GMutex index_lock;
|
2011-04-19 12:05:53 +00:00
|
|
|
|
2010-09-21 08:57:04 +00:00
|
|
|
/* seek table entries only maintained if upstream is BYTE seekable */
|
|
|
|
gboolean upstream_seekable;
|
2010-10-29 12:08:58 +00:00
|
|
|
gboolean upstream_has_duration;
|
2010-11-16 16:04:35 +00:00
|
|
|
gint64 upstream_size;
|
2010-09-21 08:57:04 +00:00
|
|
|
/* minimum distance between two index entries */
|
|
|
|
GstClockTimeDiff idx_interval;
|
2012-06-13 12:02:48 +00:00
|
|
|
guint64 idx_byte_interval;
|
2010-09-21 08:57:04 +00:00
|
|
|
/* ts and offset of last entry added */
|
|
|
|
GstClockTime index_last_ts;
|
2011-01-11 14:22:51 +00:00
|
|
|
gint64 index_last_offset;
|
2010-11-17 13:30:09 +00:00
|
|
|
gboolean index_last_valid;
|
2010-09-22 10:13:12 +00:00
|
|
|
|
|
|
|
/* timestamps currently produced are accurate, e.g. started from 0 onwards */
|
|
|
|
gboolean exact_position;
|
|
|
|
/* seek events are temporarily kept to match them with newsegments */
|
|
|
|
GSList *pending_seeks;
|
2010-09-25 12:32:06 +00:00
|
|
|
|
2010-09-29 14:12:42 +00:00
|
|
|
/* reverse playback */
|
|
|
|
GSList *buffers_pending;
|
2012-02-14 18:33:46 +00:00
|
|
|
GSList *buffers_head;
|
2010-09-29 14:12:42 +00:00
|
|
|
GSList *buffers_queued;
|
2011-01-14 14:16:04 +00:00
|
|
|
GSList *buffers_send;
|
2012-09-03 06:32:50 +00:00
|
|
|
GstClockTime last_pts;
|
|
|
|
GstClockTime last_dts;
|
2010-09-29 14:12:42 +00:00
|
|
|
gint64 last_offset;
|
2011-03-13 23:38:12 +00:00
|
|
|
|
2012-03-05 13:41:12 +00:00
|
|
|
/* Pending serialized events */
|
|
|
|
GList *pending_events;
|
2011-03-13 23:38:12 +00:00
|
|
|
/* Newsegment event to be sent after SEEK */
|
2012-03-05 13:41:12 +00:00
|
|
|
gboolean pending_segment;
|
2011-03-13 23:38:12 +00:00
|
|
|
|
2012-02-15 16:11:54 +00:00
|
|
|
/* offset of last parsed frame/data */
|
2012-02-13 17:22:37 +00:00
|
|
|
gint64 prev_offset;
|
2012-02-15 16:11:54 +00:00
|
|
|
/* force a new frame, regardless of offset */
|
|
|
|
gboolean new_frame;
|
2012-02-13 17:22:37 +00:00
|
|
|
/* whether we are merely scanning for a frame */
|
|
|
|
gboolean scanning;
|
|
|
|
/* ... and resulting frame, if any */
|
|
|
|
GstBaseParseFrame *scanned_frame;
|
2011-10-20 06:31:18 +00:00
|
|
|
|
|
|
|
/* TRUE if we're still detecting the format, i.e.
|
|
|
|
* if ::detect() is still called for future buffers */
|
|
|
|
gboolean detecting;
|
|
|
|
GList *detect_buffers;
|
|
|
|
guint detect_buffers_size;
|
2012-07-11 08:26:13 +00:00
|
|
|
|
|
|
|
/* if TRUE, a STREAM_START event needs to be pushed */
|
|
|
|
gboolean push_stream_start;
|
2008-11-13 12:59:34 +00:00
|
|
|
};
|
|
|
|
|
2010-09-22 10:13:12 +00:00
|
|
|
typedef struct _GstBaseParseSeek
|
|
|
|
{
|
|
|
|
GstSegment segment;
|
|
|
|
gboolean accurate;
|
|
|
|
gint64 offset;
|
|
|
|
GstClockTime start_ts;
|
|
|
|
} GstBaseParseSeek;
|
|
|
|
|
2013-08-07 16:24:40 +00:00
|
|
|
#define DEFAULT_DISABLE_PASSTHROUGH FALSE
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_DISABLE_PASSTHROUGH,
|
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
2011-12-04 13:35:38 +00:00
|
|
|
#define GST_BASE_PARSE_INDEX_LOCK(parse) \
|
|
|
|
g_mutex_lock (&parse->priv->index_lock);
|
|
|
|
#define GST_BASE_PARSE_INDEX_UNLOCK(parse) \
|
|
|
|
g_mutex_unlock (&parse->priv->index_lock);
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
|
|
|
static void gst_base_parse_class_init (GstBaseParseClass * klass);
|
|
|
|
static void gst_base_parse_init (GstBaseParse * parse,
|
|
|
|
GstBaseParseClass * klass);
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_base_parse_get_type (void)
|
|
|
|
{
|
2011-03-12 15:34:33 +00:00
|
|
|
static volatile gsize base_parse_type = 0;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-03-12 15:34:33 +00:00
|
|
|
if (g_once_init_enter (&base_parse_type)) {
|
2008-11-13 12:59:34 +00:00
|
|
|
static const GTypeInfo base_parse_info = {
|
|
|
|
sizeof (GstBaseParseClass),
|
2010-03-25 17:09:17 +00:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
2008-11-13 12:59:34 +00:00
|
|
|
(GClassInitFunc) gst_base_parse_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstBaseParse),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_base_parse_init,
|
|
|
|
};
|
2011-03-12 15:34:33 +00:00
|
|
|
GType _type;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-03-12 15:34:33 +00:00
|
|
|
_type = g_type_register_static (GST_TYPE_ELEMENT,
|
|
|
|
"GstBaseParse", &base_parse_info, G_TYPE_FLAG_ABSTRACT);
|
|
|
|
g_once_init_leave (&base_parse_type, _type);
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
2011-03-12 15:34:33 +00:00
|
|
|
return (GType) base_parse_type;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gst_base_parse_finalize (GObject * object);
|
|
|
|
|
2010-09-21 07:59:56 +00:00
|
|
|
static GstStateChangeReturn gst_base_parse_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
|
|
|
static void gst_base_parse_reset (GstBaseParse * parse);
|
|
|
|
|
2011-12-30 15:03:02 +00:00
|
|
|
#if 0
|
2010-09-21 08:57:04 +00:00
|
|
|
static void gst_base_parse_set_index (GstElement * element, GstIndex * index);
|
|
|
|
static GstIndex *gst_base_parse_get_index (GstElement * element);
|
2011-12-30 15:03:02 +00:00
|
|
|
#endif
|
2010-09-21 08:57:04 +00:00
|
|
|
|
2011-11-18 12:46:46 +00:00
|
|
|
static gboolean gst_base_parse_sink_activate (GstPad * sinkpad,
|
|
|
|
GstObject * parent);
|
2011-11-21 12:29:05 +00:00
|
|
|
static gboolean gst_base_parse_sink_activate_mode (GstPad * pad,
|
|
|
|
GstObject * parent, GstPadMode mode, gboolean active);
|
2008-11-13 12:59:34 +00:00
|
|
|
static gboolean gst_base_parse_handle_seek (GstBaseParse * parse,
|
|
|
|
GstEvent * event);
|
2010-03-25 11:22:58 +00:00
|
|
|
static void gst_base_parse_handle_tag (GstBaseParse * parse, GstEvent * event);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2013-08-07 16:24:40 +00:00
|
|
|
static void gst_base_parse_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_base_parse_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2011-11-17 11:40:45 +00:00
|
|
|
static gboolean gst_base_parse_src_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
2011-11-16 16:22:56 +00:00
|
|
|
static gboolean gst_base_parse_src_query (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query);
|
2011-11-15 10:20:48 +00:00
|
|
|
|
2011-11-17 11:40:45 +00:00
|
|
|
static gboolean gst_base_parse_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
2011-11-16 16:22:56 +00:00
|
|
|
static gboolean gst_base_parse_sink_query (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-11-17 11:40:45 +00:00
|
|
|
static GstFlowReturn gst_base_parse_chain (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buffer);
|
2008-11-13 12:59:34 +00:00
|
|
|
static void gst_base_parse_loop (GstPad * pad);
|
|
|
|
|
2009-01-30 18:18:10 +00:00
|
|
|
static GstFlowReturn gst_base_parse_parse_frame (GstBaseParse * parse,
|
2011-01-10 14:34:48 +00:00
|
|
|
GstBaseParseFrame * frame);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2013-01-12 20:54:26 +00:00
|
|
|
static gboolean gst_base_parse_sink_event_default (GstBaseParse * parse,
|
2008-11-13 12:59:34 +00:00
|
|
|
GstEvent * event);
|
|
|
|
|
2013-01-12 20:54:26 +00:00
|
|
|
static gboolean gst_base_parse_src_event_default (GstBaseParse * parse,
|
2008-11-13 12:59:34 +00:00
|
|
|
GstEvent * event);
|
|
|
|
|
2013-01-13 14:45:31 +00:00
|
|
|
static gboolean gst_base_parse_sink_query_default (GstBaseParse * parse,
|
|
|
|
GstQuery * query);
|
|
|
|
static gboolean gst_base_parse_src_query_default (GstBaseParse * parse,
|
|
|
|
GstQuery * query);
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
static void gst_base_parse_drain (GstBaseParse * parse);
|
|
|
|
|
2010-03-26 18:56:49 +00:00
|
|
|
static void gst_base_parse_post_bitrates (GstBaseParse * parse,
|
|
|
|
gboolean post_min, gboolean post_avg, gboolean post_max);
|
|
|
|
|
2010-09-29 14:12:42 +00:00
|
|
|
static gint64 gst_base_parse_find_offset (GstBaseParse * parse,
|
|
|
|
GstClockTime time, gboolean before, GstClockTime * _ts);
|
2010-11-17 13:30:09 +00:00
|
|
|
static GstFlowReturn gst_base_parse_locate_time (GstBaseParse * parse,
|
|
|
|
GstClockTime * _time, gint64 * _offset);
|
2010-09-29 14:12:42 +00:00
|
|
|
|
2012-02-14 18:33:46 +00:00
|
|
|
static GstFlowReturn gst_base_parse_start_fragment (GstBaseParse * parse);
|
|
|
|
static GstFlowReturn gst_base_parse_finish_fragment (GstBaseParse * parse,
|
|
|
|
gboolean prev_head);
|
|
|
|
|
|
|
|
static inline GstFlowReturn gst_base_parse_check_sync (GstBaseParse * parse);
|
2010-09-29 14:12:42 +00:00
|
|
|
|
2011-03-31 13:48:47 +00:00
|
|
|
static gboolean gst_base_parse_is_seekable (GstBaseParse * parse);
|
|
|
|
|
2010-09-29 14:12:42 +00:00
|
|
|
static void
|
|
|
|
gst_base_parse_clear_queues (GstBaseParse * parse)
|
|
|
|
{
|
|
|
|
g_slist_foreach (parse->priv->buffers_queued, (GFunc) gst_buffer_unref, NULL);
|
|
|
|
g_slist_free (parse->priv->buffers_queued);
|
|
|
|
parse->priv->buffers_queued = NULL;
|
|
|
|
g_slist_foreach (parse->priv->buffers_pending, (GFunc) gst_buffer_unref,
|
|
|
|
NULL);
|
|
|
|
g_slist_free (parse->priv->buffers_pending);
|
|
|
|
parse->priv->buffers_pending = NULL;
|
2012-02-14 18:33:46 +00:00
|
|
|
g_slist_foreach (parse->priv->buffers_head, (GFunc) gst_buffer_unref, NULL);
|
|
|
|
g_slist_free (parse->priv->buffers_head);
|
|
|
|
parse->priv->buffers_head = NULL;
|
2011-01-14 14:16:04 +00:00
|
|
|
g_slist_foreach (parse->priv->buffers_send, (GFunc) gst_buffer_unref, NULL);
|
|
|
|
g_slist_free (parse->priv->buffers_send);
|
|
|
|
parse->priv->buffers_send = NULL;
|
2011-10-20 06:31:18 +00:00
|
|
|
|
|
|
|
g_list_foreach (parse->priv->detect_buffers, (GFunc) gst_buffer_unref, NULL);
|
|
|
|
g_list_free (parse->priv->detect_buffers);
|
|
|
|
parse->priv->detect_buffers = NULL;
|
|
|
|
parse->priv->detect_buffers_size = 0;
|
2011-11-14 01:26:31 +00:00
|
|
|
|
|
|
|
g_queue_foreach (&parse->priv->queued_frames,
|
|
|
|
(GFunc) gst_base_parse_frame_free, NULL);
|
|
|
|
g_queue_clear (&parse->priv->queued_frames);
|
2012-03-05 12:12:18 +00:00
|
|
|
|
|
|
|
gst_buffer_replace (&parse->priv->cache, NULL);
|
|
|
|
|
|
|
|
g_list_foreach (parse->priv->pending_events, (GFunc) gst_event_unref, NULL);
|
|
|
|
g_list_free (parse->priv->pending_events);
|
2012-03-05 13:25:57 +00:00
|
|
|
parse->priv->pending_events = NULL;
|
2012-03-05 13:41:12 +00:00
|
|
|
parse->priv->pending_segment = FALSE;
|
2010-09-29 14:12:42 +00:00
|
|
|
}
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
static void
|
|
|
|
gst_base_parse_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstBaseParse *parse = GST_BASE_PARSE (object);
|
|
|
|
|
2011-03-13 23:43:52 +00:00
|
|
|
g_object_unref (parse->priv->adapter);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
if (parse->priv->cache) {
|
|
|
|
gst_buffer_unref (parse->priv->cache);
|
|
|
|
parse->priv->cache = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_foreach (parse->priv->pending_events, (GFunc) gst_mini_object_unref,
|
|
|
|
NULL);
|
|
|
|
g_list_free (parse->priv->pending_events);
|
|
|
|
parse->priv->pending_events = NULL;
|
2012-03-05 13:41:12 +00:00
|
|
|
parse->priv->pending_segment = FALSE;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-21 08:57:04 +00:00
|
|
|
if (parse->priv->index) {
|
|
|
|
gst_object_unref (parse->priv->index);
|
|
|
|
parse->priv->index = NULL;
|
|
|
|
}
|
2011-12-04 13:35:38 +00:00
|
|
|
g_mutex_clear (&parse->priv->index_lock);
|
2011-04-19 12:05:53 +00:00
|
|
|
|
2010-09-29 14:12:42 +00:00
|
|
|
gst_base_parse_clear_queues (parse);
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_base_parse_class_init (GstBaseParseClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2010-09-21 07:59:56 +00:00
|
|
|
GstElementClass *gstelement_class;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
g_type_class_add_private (klass, sizeof (GstBaseParsePrivate));
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2013-08-07 16:24:40 +00:00
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_base_parse_finalize);
|
2013-08-07 16:24:40 +00:00
|
|
|
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_base_parse_set_property);
|
|
|
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_base_parse_get_property);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstBaseParse:disable-passthrough:
|
|
|
|
*
|
|
|
|
* If set to #TRUE, baseparse will unconditionally force parsing of the
|
|
|
|
* incoming data. This can be required in the rare cases where the incoming
|
|
|
|
* side-data (caps, pts, dts, ...) is not trusted by the user and wants to
|
|
|
|
* force validation and parsing of the incoming data.
|
|
|
|
* If set to #FALSE, decision of whether to parse the data or not is up to
|
|
|
|
* the implementation (standard behaviour).
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_DISABLE_PASSTHROUGH,
|
|
|
|
g_param_spec_boolean ("disable-passthrough", "Disable passthrough",
|
|
|
|
"Force processing (disables passthrough)",
|
|
|
|
DEFAULT_DISABLE_PASSTHROUGH,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-21 07:59:56 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_parse_change_state);
|
2011-12-30 15:03:02 +00:00
|
|
|
|
|
|
|
#if 0
|
2010-09-21 08:57:04 +00:00
|
|
|
gstelement_class->set_index = GST_DEBUG_FUNCPTR (gst_base_parse_set_index);
|
|
|
|
gstelement_class->get_index = GST_DEBUG_FUNCPTR (gst_base_parse_get_index);
|
2011-12-30 15:03:02 +00:00
|
|
|
#endif
|
2010-09-21 07:59:56 +00:00
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
/* Default handlers */
|
2013-01-12 20:54:26 +00:00
|
|
|
klass->sink_event = gst_base_parse_sink_event_default;
|
|
|
|
klass->src_event = gst_base_parse_src_event_default;
|
2013-01-13 14:45:31 +00:00
|
|
|
klass->sink_query = gst_base_parse_sink_query_default;
|
|
|
|
klass->src_query = gst_base_parse_src_query_default;
|
2010-09-16 16:56:46 +00:00
|
|
|
klass->convert = gst_base_parse_convert_default;
|
2010-03-25 17:09:17 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_base_parse_debug, "baseparse", 0,
|
|
|
|
"baseparse element");
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_base_parse_init (GstBaseParse * parse, GstBaseParseClass * bclass)
|
|
|
|
{
|
|
|
|
GstPadTemplate *pad_template;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "gst_base_parse_init");
|
|
|
|
|
|
|
|
parse->priv = GST_BASE_PARSE_GET_PRIVATE (parse);
|
|
|
|
|
|
|
|
pad_template =
|
|
|
|
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
|
|
|
|
g_return_if_fail (pad_template != NULL);
|
|
|
|
parse->sinkpad = gst_pad_new_from_template (pad_template, "sink");
|
|
|
|
gst_pad_set_event_function (parse->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_parse_sink_event));
|
2011-11-15 10:20:48 +00:00
|
|
|
gst_pad_set_query_function (parse->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_parse_sink_query));
|
2008-11-13 12:59:34 +00:00
|
|
|
gst_pad_set_chain_function (parse->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_parse_chain));
|
|
|
|
gst_pad_set_activate_function (parse->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_parse_sink_activate));
|
2011-11-21 12:29:05 +00:00
|
|
|
gst_pad_set_activatemode_function (parse->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_parse_sink_activate_mode));
|
2012-03-15 19:23:59 +00:00
|
|
|
GST_PAD_SET_PROXY_ALLOCATION (parse->sinkpad);
|
2008-11-13 12:59:34 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (parse), parse->sinkpad);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "sinkpad created");
|
|
|
|
|
|
|
|
pad_template =
|
|
|
|
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
|
|
|
|
g_return_if_fail (pad_template != NULL);
|
|
|
|
parse->srcpad = gst_pad_new_from_template (pad_template, "src");
|
|
|
|
gst_pad_set_event_function (parse->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_parse_src_event));
|
|
|
|
gst_pad_set_query_function (parse->srcpad,
|
2011-11-15 10:20:48 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_base_parse_src_query));
|
2009-10-28 11:00:08 +00:00
|
|
|
gst_pad_use_fixed_caps (parse->srcpad);
|
2008-11-13 12:59:34 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (parse), parse->srcpad);
|
|
|
|
GST_DEBUG_OBJECT (parse, "src created");
|
|
|
|
|
2011-04-02 13:04:42 +00:00
|
|
|
g_queue_init (&parse->priv->queued_frames);
|
|
|
|
|
2011-03-13 23:43:52 +00:00
|
|
|
parse->priv->adapter = gst_adapter_new ();
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-11-18 11:35:46 +00:00
|
|
|
parse->priv->pad_mode = GST_PAD_MODE_NONE;
|
2010-09-21 07:59:56 +00:00
|
|
|
|
2011-12-04 13:35:38 +00:00
|
|
|
g_mutex_init (&parse->priv->index_lock);
|
2011-04-19 12:05:53 +00:00
|
|
|
|
2010-09-21 07:59:56 +00:00
|
|
|
/* init state */
|
|
|
|
gst_base_parse_reset (parse);
|
|
|
|
GST_DEBUG_OBJECT (parse, "init ok");
|
2011-11-28 17:23:41 +00:00
|
|
|
|
|
|
|
GST_OBJECT_FLAG_SET (parse, GST_ELEMENT_FLAG_INDEXABLE);
|
2010-09-21 07:59:56 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 16:24:40 +00:00
|
|
|
static void
|
|
|
|
gst_base_parse_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstBaseParse *parse = GST_BASE_PARSE (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISABLE_PASSTHROUGH:
|
|
|
|
parse->priv->disable_passthrough = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_base_parse_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstBaseParse *parse = GST_BASE_PARSE (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISABLE_PASSTHROUGH:
|
|
|
|
g_value_set_boolean (value, parse->priv->disable_passthrough);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-15 14:02:20 +00:00
|
|
|
static GstBaseParseFrame *
|
|
|
|
gst_base_parse_frame_copy (GstBaseParseFrame * frame)
|
2011-01-10 14:34:48 +00:00
|
|
|
{
|
2011-04-15 14:02:20 +00:00
|
|
|
GstBaseParseFrame *copy;
|
|
|
|
|
|
|
|
copy = g_slice_dup (GstBaseParseFrame, frame);
|
|
|
|
copy->buffer = gst_buffer_ref (frame->buffer);
|
2011-04-15 16:41:02 +00:00
|
|
|
copy->_private_flags &= ~GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC;
|
|
|
|
|
2011-04-15 17:38:46 +00:00
|
|
|
GST_TRACE ("copied frame %p -> %p", frame, copy);
|
|
|
|
|
2011-04-15 14:02:20 +00:00
|
|
|
return copy;
|
2011-01-10 14:34:48 +00:00
|
|
|
}
|
|
|
|
|
2011-04-15 18:07:55 +00:00
|
|
|
void
|
2011-04-15 14:02:20 +00:00
|
|
|
gst_base_parse_frame_free (GstBaseParseFrame * frame)
|
2011-01-10 14:34:48 +00:00
|
|
|
{
|
2011-04-15 17:38:46 +00:00
|
|
|
GST_TRACE ("freeing frame %p", frame);
|
|
|
|
|
2011-01-10 14:34:48 +00:00
|
|
|
if (frame->buffer) {
|
|
|
|
gst_buffer_unref (frame->buffer);
|
|
|
|
frame->buffer = NULL;
|
|
|
|
}
|
2011-04-15 16:41:02 +00:00
|
|
|
|
2011-05-17 20:17:14 +00:00
|
|
|
if (!(frame->_private_flags & GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC)) {
|
2011-04-15 16:41:02 +00:00
|
|
|
g_slice_free (GstBaseParseFrame, frame);
|
2011-05-17 20:17:14 +00:00
|
|
|
} else {
|
|
|
|
memset (frame, 0, sizeof (*frame));
|
|
|
|
}
|
2011-01-10 14:34:48 +00:00
|
|
|
}
|
|
|
|
|
2012-01-28 14:35:51 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GstBaseParseFrame, gst_base_parse_frame,
|
|
|
|
(GBoxedCopyFunc) gst_base_parse_frame_copy,
|
|
|
|
(GBoxedFreeFunc) gst_base_parse_frame_free);
|
2011-04-02 12:02:01 +00:00
|
|
|
|
2011-01-10 14:34:48 +00:00
|
|
|
/**
|
|
|
|
* gst_base_parse_frame_init:
|
2011-03-31 14:50:22 +00:00
|
|
|
* @frame: #GstBaseParseFrame.
|
2011-01-10 14:34:48 +00:00
|
|
|
*
|
|
|
|
* Sets a #GstBaseParseFrame to initial state. Currently this means
|
2011-04-15 16:41:02 +00:00
|
|
|
* all public fields are zero-ed and a private flag is set to make
|
|
|
|
* sure gst_base_parse_frame_free() only frees the contents but not
|
|
|
|
* the actual frame. Use this function to initialise a #GstBaseParseFrame
|
|
|
|
* allocated on the stack.
|
2011-01-10 14:34:48 +00:00
|
|
|
*/
|
|
|
|
void
|
2011-04-15 17:00:21 +00:00
|
|
|
gst_base_parse_frame_init (GstBaseParseFrame * frame)
|
2011-04-02 12:02:01 +00:00
|
|
|
{
|
|
|
|
memset (frame, 0, sizeof (GstBaseParseFrame));
|
2011-04-15 16:41:02 +00:00
|
|
|
frame->_private_flags = GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC;
|
2011-04-15 17:38:46 +00:00
|
|
|
GST_TRACE ("inited frame %p", frame);
|
2011-01-10 14:34:48 +00:00
|
|
|
}
|
|
|
|
|
2011-04-15 16:41:02 +00:00
|
|
|
/**
|
|
|
|
* gst_base_parse_frame_new:
|
|
|
|
* @buffer: (transfer none): a #GstBuffer
|
|
|
|
* @flags: the flags
|
|
|
|
* @overhead: number of bytes in this frame which should be counted as
|
|
|
|
* metadata overhead, ie. not used to calculate the average bitrate.
|
|
|
|
* Set to -1 to mark the entire frame as metadata. If in doubt, set to 0.
|
|
|
|
*
|
|
|
|
* Allocates a new #GstBaseParseFrame. This function is mainly for bindings,
|
|
|
|
* elements written in C should usually allocate the frame on the stack and
|
|
|
|
* then use gst_base_parse_frame_init() to initialise it.
|
|
|
|
*
|
|
|
|
* Returns: a newly-allocated #GstBaseParseFrame. Free with
|
2012-02-15 16:12:09 +00:00
|
|
|
* gst_base_parse_frame_free() when no longer needed.
|
2011-04-15 16:41:02 +00:00
|
|
|
*/
|
|
|
|
GstBaseParseFrame *
|
|
|
|
gst_base_parse_frame_new (GstBuffer * buffer, GstBaseParseFrameFlags flags,
|
|
|
|
gint overhead)
|
2011-01-10 14:34:48 +00:00
|
|
|
{
|
2011-04-15 16:41:02 +00:00
|
|
|
GstBaseParseFrame *frame;
|
2011-01-10 14:34:48 +00:00
|
|
|
|
2011-04-15 16:41:02 +00:00
|
|
|
frame = g_slice_new0 (GstBaseParseFrame);
|
|
|
|
frame->buffer = gst_buffer_ref (buffer);
|
2011-04-02 12:02:01 +00:00
|
|
|
|
2011-04-15 17:38:46 +00:00
|
|
|
GST_TRACE ("created frame %p", frame);
|
2011-04-15 16:41:02 +00:00
|
|
|
return frame;
|
2011-04-02 12:02:01 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 14:34:48 +00:00
|
|
|
static inline void
|
|
|
|
gst_base_parse_frame_update (GstBaseParse * parse, GstBaseParseFrame * frame,
|
|
|
|
GstBuffer * buf)
|
|
|
|
{
|
|
|
|
gst_buffer_replace (&frame->buffer, buf);
|
2011-04-04 16:58:59 +00:00
|
|
|
|
|
|
|
parse->flags = 0;
|
|
|
|
|
|
|
|
/* set flags one by one for clarity */
|
|
|
|
if (G_UNLIKELY (parse->priv->drain))
|
|
|
|
parse->flags |= GST_BASE_PARSE_FLAG_DRAINING;
|
|
|
|
|
2011-01-10 14:34:48 +00:00
|
|
|
/* losing sync is pretty much a discont (and vice versa), no ? */
|
2011-04-04 16:58:59 +00:00
|
|
|
if (G_UNLIKELY (parse->priv->discont))
|
|
|
|
parse->flags |= GST_BASE_PARSE_FLAG_LOST_SYNC;
|
2011-01-10 14:34:48 +00:00
|
|
|
}
|
|
|
|
|
2010-09-21 07:59:56 +00:00
|
|
|
static void
|
|
|
|
gst_base_parse_reset (GstBaseParse * parse)
|
|
|
|
{
|
|
|
|
GST_OBJECT_LOCK (parse);
|
|
|
|
gst_segment_init (&parse->segment, GST_FORMAT_TIME);
|
2008-11-13 12:59:34 +00:00
|
|
|
parse->priv->duration = -1;
|
|
|
|
parse->priv->min_frame_size = 1;
|
2010-09-21 07:59:56 +00:00
|
|
|
parse->priv->discont = TRUE;
|
2008-11-13 12:59:34 +00:00
|
|
|
parse->priv->flushing = FALSE;
|
|
|
|
parse->priv->offset = 0;
|
2010-09-21 07:59:56 +00:00
|
|
|
parse->priv->sync_offset = 0;
|
2011-01-21 13:53:39 +00:00
|
|
|
parse->priv->update_interval = -1;
|
2010-09-21 07:59:56 +00:00
|
|
|
parse->priv->fps_num = parse->priv->fps_den = 0;
|
|
|
|
parse->priv->frame_duration = GST_CLOCK_TIME_NONE;
|
2010-09-22 13:07:09 +00:00
|
|
|
parse->priv->lead_in = parse->priv->lead_out = 0;
|
|
|
|
parse->priv->lead_in_ts = parse->priv->lead_out_ts = 0;
|
2010-09-21 07:59:56 +00:00
|
|
|
parse->priv->bitrate = 0;
|
|
|
|
parse->priv->framecount = 0;
|
|
|
|
parse->priv->bytecount = 0;
|
|
|
|
parse->priv->acc_duration = 0;
|
2012-09-03 06:32:50 +00:00
|
|
|
parse->priv->first_frame_pts = GST_CLOCK_TIME_NONE;
|
|
|
|
parse->priv->first_frame_dts = GST_CLOCK_TIME_NONE;
|
2010-11-17 13:30:09 +00:00
|
|
|
parse->priv->first_frame_offset = -1;
|
2010-09-21 07:59:56 +00:00
|
|
|
parse->priv->estimated_duration = -1;
|
2011-10-06 12:34:09 +00:00
|
|
|
parse->priv->estimated_drift = 0;
|
2013-02-09 11:32:02 +00:00
|
|
|
parse->priv->next_pts = GST_CLOCK_TIME_NONE;
|
2012-09-03 06:32:50 +00:00
|
|
|
parse->priv->next_dts = 0;
|
2011-04-06 16:43:27 +00:00
|
|
|
parse->priv->syncable = TRUE;
|
2013-08-07 16:24:40 +00:00
|
|
|
parse->priv->disable_passthrough = DEFAULT_DISABLE_PASSTHROUGH;
|
2011-04-06 16:43:27 +00:00
|
|
|
parse->priv->passthrough = FALSE;
|
2012-09-13 05:44:37 +00:00
|
|
|
parse->priv->pts_interpolate = TRUE;
|
2013-02-26 18:58:49 +00:00
|
|
|
parse->priv->infer_ts = TRUE;
|
2011-04-06 16:43:27 +00:00
|
|
|
parse->priv->has_timing_info = FALSE;
|
2010-09-21 07:59:56 +00:00
|
|
|
parse->priv->post_min_bitrate = TRUE;
|
|
|
|
parse->priv->post_avg_bitrate = TRUE;
|
|
|
|
parse->priv->post_max_bitrate = TRUE;
|
|
|
|
parse->priv->min_bitrate = G_MAXUINT;
|
|
|
|
parse->priv->max_bitrate = 0;
|
|
|
|
parse->priv->avg_bitrate = 0;
|
|
|
|
parse->priv->posted_avg_bitrate = 0;
|
|
|
|
|
2011-01-11 14:22:51 +00:00
|
|
|
parse->priv->index_last_ts = GST_CLOCK_TIME_NONE;
|
|
|
|
parse->priv->index_last_offset = -1;
|
2010-11-17 13:30:09 +00:00
|
|
|
parse->priv->index_last_valid = TRUE;
|
2010-09-21 08:57:04 +00:00
|
|
|
parse->priv->upstream_seekable = FALSE;
|
2010-11-16 16:04:35 +00:00
|
|
|
parse->priv->upstream_size = 0;
|
2010-10-29 12:08:58 +00:00
|
|
|
parse->priv->upstream_has_duration = FALSE;
|
2010-09-21 08:57:04 +00:00
|
|
|
parse->priv->idx_interval = 0;
|
2012-06-13 12:02:48 +00:00
|
|
|
parse->priv->idx_byte_interval = 0;
|
2010-09-22 10:13:12 +00:00
|
|
|
parse->priv->exact_position = TRUE;
|
2010-11-08 18:58:31 +00:00
|
|
|
parse->priv->seen_keyframe = FALSE;
|
2010-09-21 08:57:04 +00:00
|
|
|
|
2012-09-03 06:32:50 +00:00
|
|
|
parse->priv->last_dts = GST_CLOCK_TIME_NONE;
|
|
|
|
parse->priv->last_pts = GST_CLOCK_TIME_NONE;
|
2010-09-29 14:12:42 +00:00
|
|
|
parse->priv->last_offset = 0;
|
|
|
|
|
2010-09-21 07:59:56 +00:00
|
|
|
g_list_foreach (parse->priv->pending_events, (GFunc) gst_mini_object_unref,
|
|
|
|
NULL);
|
|
|
|
g_list_free (parse->priv->pending_events);
|
|
|
|
parse->priv->pending_events = NULL;
|
2012-03-05 13:41:12 +00:00
|
|
|
parse->priv->pending_segment = FALSE;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-21 07:59:56 +00:00
|
|
|
if (parse->priv->cache) {
|
|
|
|
gst_buffer_unref (parse->priv->cache);
|
|
|
|
parse->priv->cache = NULL;
|
|
|
|
}
|
2010-09-22 10:13:12 +00:00
|
|
|
|
|
|
|
g_slist_foreach (parse->priv->pending_seeks, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free (parse->priv->pending_seeks);
|
|
|
|
parse->priv->pending_seeks = NULL;
|
2011-05-17 20:17:14 +00:00
|
|
|
|
2012-01-12 19:53:11 +00:00
|
|
|
if (parse->priv->adapter)
|
|
|
|
gst_adapter_clear (parse->priv->adapter);
|
|
|
|
|
2012-02-15 16:11:54 +00:00
|
|
|
parse->priv->new_frame = TRUE;
|
2011-10-20 06:31:18 +00:00
|
|
|
|
|
|
|
g_list_foreach (parse->priv->detect_buffers, (GFunc) gst_buffer_unref, NULL);
|
|
|
|
g_list_free (parse->priv->detect_buffers);
|
|
|
|
parse->priv->detect_buffers = NULL;
|
|
|
|
parse->priv->detect_buffers_size = 0;
|
2010-09-21 07:59:56 +00:00
|
|
|
GST_OBJECT_UNLOCK (parse);
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-03-31 14:50:22 +00:00
|
|
|
/* gst_base_parse_parse_frame:
|
2008-11-13 12:59:34 +00:00
|
|
|
* @parse: #GstBaseParse.
|
|
|
|
* @buffer: #GstBuffer.
|
|
|
|
*
|
|
|
|
* Default callback for parse_frame.
|
|
|
|
*/
|
2009-01-30 18:18:10 +00:00
|
|
|
static GstFlowReturn
|
2011-01-10 14:34:48 +00:00
|
|
|
gst_base_parse_parse_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
2011-01-10 14:34:48 +00:00
|
|
|
GstBuffer *buffer = frame->buffer;
|
|
|
|
|
2012-09-03 06:32:50 +00:00
|
|
|
if (!GST_BUFFER_PTS_IS_VALID (buffer) &&
|
|
|
|
GST_CLOCK_TIME_IS_VALID (parse->priv->next_pts)) {
|
|
|
|
GST_BUFFER_PTS (buffer) = parse->priv->next_pts;
|
|
|
|
}
|
|
|
|
if (!GST_BUFFER_DTS_IS_VALID (buffer) &&
|
|
|
|
GST_CLOCK_TIME_IS_VALID (parse->priv->next_dts)) {
|
|
|
|
GST_BUFFER_DTS (buffer) = parse->priv->next_dts;
|
2009-11-23 14:48:25 +00:00
|
|
|
}
|
|
|
|
if (!GST_BUFFER_DURATION_IS_VALID (buffer) &&
|
|
|
|
GST_CLOCK_TIME_IS_VALID (parse->priv->frame_duration)) {
|
|
|
|
GST_BUFFER_DURATION (buffer) = parse->priv->frame_duration;
|
|
|
|
}
|
2009-01-30 18:18:10 +00:00
|
|
|
return GST_FLOW_OK;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 14:50:22 +00:00
|
|
|
/* gst_base_parse_convert:
|
2008-11-13 12:59:34 +00:00
|
|
|
* @parse: #GstBaseParse.
|
2010-09-16 16:56:46 +00:00
|
|
|
* @src_format: #GstFormat describing the source format.
|
|
|
|
* @src_value: Source value to be converted.
|
|
|
|
* @dest_format: #GstFormat defining the converted format.
|
|
|
|
* @dest_value: Pointer where the conversion result will be put.
|
2008-11-13 12:59:34 +00:00
|
|
|
*
|
2010-09-16 16:56:46 +00:00
|
|
|
* Converts using configured "convert" vmethod in #GstBaseParse class.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if conversion was successful.
|
2008-11-13 12:59:34 +00:00
|
|
|
*/
|
|
|
|
static gboolean
|
2010-09-16 16:56:46 +00:00
|
|
|
gst_base_parse_convert (GstBaseParse * parse,
|
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value, GstFormat dest_format, gint64 * dest_value)
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
2010-09-16 16:56:46 +00:00
|
|
|
GstBaseParseClass *klass = GST_BASE_PARSE_GET_CLASS (parse);
|
|
|
|
gboolean ret;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-16 16:56:46 +00:00
|
|
|
g_return_val_if_fail (dest_value != NULL, FALSE);
|
|
|
|
|
|
|
|
if (!klass->convert)
|
|
|
|
return FALSE;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-16 16:56:46 +00:00
|
|
|
ret = klass->convert (parse, src_format, src_value, dest_format, dest_value);
|
|
|
|
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
{
|
|
|
|
if (ret) {
|
|
|
|
if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_BYTES) {
|
|
|
|
GST_LOG_OBJECT (parse,
|
|
|
|
"TIME -> BYTES: %" GST_TIME_FORMAT " -> %" G_GINT64_FORMAT,
|
|
|
|
GST_TIME_ARGS (src_value), *dest_value);
|
|
|
|
} else if (dest_format == GST_FORMAT_TIME &&
|
|
|
|
src_format == GST_FORMAT_BYTES) {
|
|
|
|
GST_LOG_OBJECT (parse,
|
|
|
|
"BYTES -> TIME: %" G_GINT64_FORMAT " -> %" GST_TIME_FORMAT,
|
|
|
|
src_value, GST_TIME_ARGS (*dest_value));
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (parse,
|
|
|
|
"%s -> %s: %" G_GINT64_FORMAT " -> %" G_GINT64_FORMAT,
|
|
|
|
GST_STR_NULL (gst_format_get_name (src_format)),
|
|
|
|
GST_STR_NULL (gst_format_get_name (dest_format)),
|
|
|
|
src_value, *dest_value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (parse, "conversion failed");
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
2010-09-16 16:56:46 +00:00
|
|
|
#endif
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-16 16:56:46 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-03-31 14:50:22 +00:00
|
|
|
/* gst_base_parse_sink_event:
|
2008-11-13 12:59:34 +00:00
|
|
|
* @pad: #GstPad that received the event.
|
|
|
|
* @event: #GstEvent to be handled.
|
|
|
|
*
|
|
|
|
* Handler for sink pad events.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the event was handled.
|
|
|
|
*/
|
|
|
|
static gboolean
|
2011-11-17 11:40:45 +00:00
|
|
|
gst_base_parse_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
2012-09-05 02:38:26 +00:00
|
|
|
GstBaseParse *parse = GST_BASE_PARSE (parent);
|
|
|
|
GstBaseParseClass *bclass = GST_BASE_PARSE_GET_CLASS (parse);
|
2012-02-15 09:11:35 +00:00
|
|
|
gboolean ret;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2012-09-05 02:38:26 +00:00
|
|
|
ret = bclass->sink_event (parse, event);
|
2011-11-17 11:40:45 +00:00
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-12 20:54:26 +00:00
|
|
|
/* gst_base_parse_sink_event_default:
|
2008-11-13 12:59:34 +00:00
|
|
|
* @parse: #GstBaseParse.
|
|
|
|
* @event: #GstEvent to be handled.
|
|
|
|
*
|
|
|
|
* Element-level event handler function.
|
|
|
|
*
|
2011-01-14 19:30:11 +00:00
|
|
|
* The event will be unreffed only if it has been handled and this
|
|
|
|
* function returns %TRUE
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the event was handled and not need forwarding.
|
2008-11-13 12:59:34 +00:00
|
|
|
*/
|
|
|
|
static gboolean
|
2013-01-12 20:54:26 +00:00
|
|
|
gst_base_parse_sink_event_default (GstBaseParse * parse, GstEvent * event)
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
2012-09-05 02:38:26 +00:00
|
|
|
GstBaseParseClass *klass = GST_BASE_PARSE_GET_CLASS (parse);
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
gboolean forward_immediate = FALSE;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "handling event %d, %s", GST_EVENT_TYPE (event),
|
|
|
|
GST_EVENT_TYPE_NAME (event));
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2011-06-02 17:24:26 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
GST_DEBUG_OBJECT (parse, "caps: %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
if (klass->set_sink_caps)
|
2012-02-15 09:11:35 +00:00
|
|
|
ret = klass->set_sink_caps (parse, caps);
|
|
|
|
else
|
|
|
|
ret = TRUE;
|
2011-06-02 17:24:26 +00:00
|
|
|
|
2011-07-11 09:40:08 +00:00
|
|
|
/* will send our own caps downstream */
|
|
|
|
gst_event_unref (event);
|
2012-09-05 02:38:26 +00:00
|
|
|
event = NULL;
|
2011-06-02 17:24:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-05-13 16:07:24 +00:00
|
|
|
case GST_EVENT_SEGMENT:
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
2011-05-13 16:07:24 +00:00
|
|
|
const GstSegment *in_segment;
|
|
|
|
GstSegment out_segment;
|
2012-09-26 04:23:52 +00:00
|
|
|
gint64 offset = 0, next_dts;
|
2013-07-25 15:20:14 +00:00
|
|
|
guint32 seqnum = gst_event_get_seqnum (event);
|
2011-05-13 16:07:24 +00:00
|
|
|
|
2011-05-18 14:56:13 +00:00
|
|
|
gst_event_parse_segment (event, &in_segment);
|
2011-05-13 16:07:24 +00:00
|
|
|
gst_segment_init (&out_segment, GST_FORMAT_TIME);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-05-13 16:07:24 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "segment %" GST_SEGMENT_FORMAT, in_segment);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-05-13 16:07:24 +00:00
|
|
|
if (in_segment->format == GST_FORMAT_BYTES) {
|
2010-09-22 10:13:12 +00:00
|
|
|
GstBaseParseSeek *seek = NULL;
|
|
|
|
GSList *node;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
/* stop time is allowed to be open-ended, but not start & pos */
|
2011-05-13 16:07:24 +00:00
|
|
|
offset = in_segment->time;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-22 10:13:12 +00:00
|
|
|
GST_OBJECT_LOCK (parse);
|
|
|
|
for (node = parse->priv->pending_seeks; node; node = node->next) {
|
|
|
|
GstBaseParseSeek *tmp = node->data;
|
|
|
|
|
2011-05-13 16:07:24 +00:00
|
|
|
if (tmp->offset == offset) {
|
2010-09-22 10:13:12 +00:00
|
|
|
seek = tmp;
|
|
|
|
break;
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
2010-09-22 10:13:12 +00:00
|
|
|
parse->priv->pending_seeks =
|
|
|
|
g_slist_remove (parse->priv->pending_seeks, seek);
|
|
|
|
GST_OBJECT_UNLOCK (parse);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-22 10:13:12 +00:00
|
|
|
if (seek) {
|
|
|
|
GST_DEBUG_OBJECT (parse,
|
|
|
|
"Matched newsegment to%s seek: %" GST_SEGMENT_FORMAT,
|
|
|
|
seek->accurate ? " accurate" : "", &seek->segment);
|
2011-05-13 16:07:24 +00:00
|
|
|
|
|
|
|
out_segment.start = seek->segment.start;
|
|
|
|
out_segment.stop = seek->segment.stop;
|
|
|
|
out_segment.time = seek->segment.start;
|
|
|
|
|
2012-09-26 04:23:52 +00:00
|
|
|
next_dts = seek->start_ts;
|
2010-09-22 10:13:12 +00:00
|
|
|
parse->priv->exact_position = seek->accurate;
|
|
|
|
g_free (seek);
|
|
|
|
} else {
|
|
|
|
/* best attempt convert */
|
|
|
|
/* as these are only estimates, stop is kept open-ended to avoid
|
|
|
|
* premature cutting */
|
2011-05-13 16:07:24 +00:00
|
|
|
gst_base_parse_convert (parse, GST_FORMAT_BYTES, in_segment->start,
|
2012-09-26 04:23:52 +00:00
|
|
|
GST_FORMAT_TIME, (gint64 *) & next_dts);
|
2011-05-13 16:07:24 +00:00
|
|
|
|
2012-09-26 04:23:52 +00:00
|
|
|
out_segment.start = next_dts;
|
2011-05-13 16:07:24 +00:00
|
|
|
out_segment.stop = GST_CLOCK_TIME_NONE;
|
2012-09-26 04:23:52 +00:00
|
|
|
out_segment.time = next_dts;
|
2011-05-13 16:07:24 +00:00
|
|
|
|
|
|
|
parse->priv->exact_position = (in_segment->start == 0);
|
2010-09-22 10:13:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_event_unref (event);
|
2011-05-13 16:07:24 +00:00
|
|
|
|
|
|
|
event = gst_event_new_segment (&out_segment);
|
2013-07-25 15:20:14 +00:00
|
|
|
gst_event_set_seqnum (event, seqnum);
|
2011-05-13 16:07:24 +00:00
|
|
|
|
2011-08-10 09:01:58 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "Converted incoming segment to TIME. %"
|
2011-05-13 16:07:24 +00:00
|
|
|
GST_SEGMENT_FORMAT, in_segment);
|
|
|
|
|
|
|
|
} else if (in_segment->format != GST_FORMAT_TIME) {
|
2011-02-18 13:05:31 +00:00
|
|
|
/* Unknown incoming segment format. Output a default open-ended
|
2008-11-13 12:59:34 +00:00
|
|
|
* TIME segment */
|
|
|
|
gst_event_unref (event);
|
2011-05-13 16:07:24 +00:00
|
|
|
|
|
|
|
out_segment.start = 0;
|
2012-02-08 14:03:56 +00:00
|
|
|
out_segment.stop = GST_CLOCK_TIME_NONE;
|
|
|
|
out_segment.time = 0;
|
2011-05-13 16:07:24 +00:00
|
|
|
|
|
|
|
event = gst_event_new_segment (&out_segment);
|
2013-07-25 15:20:14 +00:00
|
|
|
gst_event_set_seqnum (event, seqnum);
|
2011-05-13 16:07:24 +00:00
|
|
|
|
2012-09-26 04:23:52 +00:00
|
|
|
next_dts = 0;
|
2010-09-21 08:57:04 +00:00
|
|
|
} else {
|
|
|
|
/* not considered BYTE seekable if it is talking to us in TIME,
|
|
|
|
* whatever else it might claim */
|
|
|
|
parse->priv->upstream_seekable = FALSE;
|
2012-09-26 04:23:52 +00:00
|
|
|
next_dts = in_segment->start;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 16:07:24 +00:00
|
|
|
memcpy (&parse->segment, &out_segment, sizeof (GstSegment));
|
|
|
|
|
|
|
|
/*
|
|
|
|
gst_segment_set_newsegment (&parse->segment, update, rate,
|
|
|
|
applied_rate, format, start, stop, start);
|
|
|
|
*/
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
/* save the segment for later, right before we push a new buffer so that
|
|
|
|
* the caps are fixed and the next linked element can receive
|
|
|
|
* the segment. */
|
2012-03-05 13:41:12 +00:00
|
|
|
parse->priv->pending_segment = TRUE;
|
2012-02-15 09:11:35 +00:00
|
|
|
ret = TRUE;
|
2009-04-27 20:39:15 +00:00
|
|
|
|
|
|
|
/* but finish the current segment */
|
|
|
|
GST_DEBUG_OBJECT (parse, "draining current segment");
|
2011-05-13 16:07:24 +00:00
|
|
|
if (in_segment->rate > 0.0)
|
2010-09-29 14:12:42 +00:00
|
|
|
gst_base_parse_drain (parse);
|
|
|
|
else
|
2012-02-14 18:33:46 +00:00
|
|
|
gst_base_parse_finish_fragment (parse, FALSE);
|
2011-03-13 23:43:52 +00:00
|
|
|
gst_adapter_clear (parse->priv->adapter);
|
2011-05-13 16:07:24 +00:00
|
|
|
|
2009-04-27 20:39:15 +00:00
|
|
|
parse->priv->offset = offset;
|
2010-09-20 14:39:37 +00:00
|
|
|
parse->priv->sync_offset = offset;
|
2012-09-26 04:23:52 +00:00
|
|
|
parse->priv->next_dts = next_dts;
|
2013-03-27 17:25:08 +00:00
|
|
|
parse->priv->next_pts = GST_CLOCK_TIME_NONE;
|
2012-09-03 06:32:50 +00:00
|
|
|
parse->priv->last_pts = GST_CLOCK_TIME_NONE;
|
|
|
|
parse->priv->last_dts = GST_CLOCK_TIME_NONE;
|
2013-02-26 18:58:49 +00:00
|
|
|
parse->priv->prev_pts = GST_CLOCK_TIME_NONE;
|
|
|
|
parse->priv->prev_dts = GST_CLOCK_TIME_NONE;
|
2010-09-20 14:39:37 +00:00
|
|
|
parse->priv->discont = TRUE;
|
2010-11-08 18:58:31 +00:00
|
|
|
parse->priv->seen_keyframe = FALSE;
|
2008-11-13 12:59:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GST_EVENT_FLUSH_START:
|
2012-09-11 01:38:57 +00:00
|
|
|
GST_OBJECT_LOCK (parse);
|
2008-11-13 12:59:34 +00:00
|
|
|
parse->priv->flushing = TRUE;
|
2012-09-11 01:38:57 +00:00
|
|
|
GST_OBJECT_UNLOCK (parse);
|
2008-11-13 12:59:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
2011-03-13 23:43:52 +00:00
|
|
|
gst_adapter_clear (parse->priv->adapter);
|
2010-09-29 14:12:42 +00:00
|
|
|
gst_base_parse_clear_queues (parse);
|
2008-11-13 12:59:34 +00:00
|
|
|
parse->priv->flushing = FALSE;
|
|
|
|
parse->priv->discont = TRUE;
|
2012-09-03 06:32:50 +00:00
|
|
|
parse->priv->last_pts = GST_CLOCK_TIME_NONE;
|
|
|
|
parse->priv->last_dts = GST_CLOCK_TIME_NONE;
|
2012-02-15 16:11:54 +00:00
|
|
|
parse->priv->new_frame = TRUE;
|
2012-09-05 02:38:26 +00:00
|
|
|
|
|
|
|
forward_immediate = TRUE;
|
2008-11-13 12:59:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_EVENT_EOS:
|
2010-09-29 14:12:42 +00:00
|
|
|
if (parse->segment.rate > 0.0)
|
|
|
|
gst_base_parse_drain (parse);
|
|
|
|
else
|
2012-02-14 18:33:46 +00:00
|
|
|
gst_base_parse_finish_fragment (parse, TRUE);
|
2010-09-20 11:57:55 +00:00
|
|
|
|
|
|
|
/* If we STILL have zero frames processed, fire an error */
|
|
|
|
if (parse->priv->framecount == 0) {
|
|
|
|
GST_ELEMENT_ERROR (parse, STREAM, WRONG_TYPE,
|
|
|
|
("No valid frames found before end of stream"), (NULL));
|
|
|
|
}
|
2012-03-05 13:41:12 +00:00
|
|
|
/* newsegment and other serialized events before eos */
|
|
|
|
if (G_UNLIKELY (parse->priv->pending_events)) {
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = parse->priv->pending_events; l != NULL; l = l->next) {
|
|
|
|
gst_pad_push_event (parse->srcpad, GST_EVENT (l->data));
|
|
|
|
}
|
|
|
|
g_list_free (parse->priv->pending_events);
|
|
|
|
parse->priv->pending_events = NULL;
|
|
|
|
parse->priv->pending_segment = FALSE;
|
2010-09-20 11:57:55 +00:00
|
|
|
}
|
2012-09-11 01:38:57 +00:00
|
|
|
if (parse->priv->framecount < MIN_FRAMES_TO_POST_BITRATE) {
|
|
|
|
/* We've not posted bitrate tags yet - do so now */
|
|
|
|
gst_base_parse_post_bitrates (parse, TRUE, TRUE, TRUE);
|
|
|
|
}
|
|
|
|
forward_immediate = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_EVENT_CUSTOM_DOWNSTREAM:{
|
|
|
|
/* FIXME: Code duplicated from libgstvideo because core can't depend on -base */
|
|
|
|
#ifndef GST_VIDEO_EVENT_STILL_STATE_NAME
|
|
|
|
#define GST_VIDEO_EVENT_STILL_STATE_NAME "GstEventStillFrame"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const GstStructure *s;
|
|
|
|
gboolean ev_still_state;
|
|
|
|
|
|
|
|
s = gst_event_get_structure (event);
|
|
|
|
if (s != NULL &&
|
|
|
|
gst_structure_has_name (s, GST_VIDEO_EVENT_STILL_STATE_NAME) &&
|
|
|
|
gst_structure_get_boolean (s, "still-state", &ev_still_state)) {
|
|
|
|
if (ev_still_state) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "draining current data for still-frame");
|
|
|
|
if (parse->segment.rate > 0.0)
|
|
|
|
gst_base_parse_drain (parse);
|
|
|
|
else
|
|
|
|
gst_base_parse_finish_fragment (parse, TRUE);
|
|
|
|
}
|
|
|
|
forward_immediate = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_GAP:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (parse, "draining current data due to gap event");
|
|
|
|
if (parse->segment.rate > 0.0)
|
|
|
|
gst_base_parse_drain (parse);
|
|
|
|
else
|
|
|
|
gst_base_parse_finish_fragment (parse, TRUE);
|
2012-09-05 02:38:26 +00:00
|
|
|
forward_immediate = TRUE;
|
2008-11-13 12:59:34 +00:00
|
|
|
break;
|
2012-09-11 01:38:57 +00:00
|
|
|
}
|
|
|
|
case GST_EVENT_TAG:
|
|
|
|
/* See if any bitrate tags were posted */
|
|
|
|
gst_base_parse_handle_tag (parse, event);
|
|
|
|
break;
|
2012-11-16 18:41:48 +00:00
|
|
|
|
|
|
|
case GST_EVENT_STREAM_START:
|
|
|
|
if (parse->priv->pad_mode != GST_PAD_MODE_PULL)
|
|
|
|
forward_immediate = TRUE;
|
|
|
|
break;
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-09-05 02:38:26 +00:00
|
|
|
|
|
|
|
/* 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 (event) {
|
|
|
|
if (!GST_EVENT_IS_SERIALIZED (event) || forward_immediate) {
|
|
|
|
ret = gst_pad_push_event (parse->srcpad, event);
|
|
|
|
} else {
|
|
|
|
// GST_VIDEO_DECODER_STREAM_LOCK (decoder);
|
|
|
|
parse->priv->pending_events =
|
|
|
|
g_list_prepend (parse->priv->pending_events, event);
|
|
|
|
// GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "event handled");
|
|
|
|
|
2012-02-15 09:11:35 +00:00
|
|
|
return ret;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
2011-11-15 10:20:48 +00:00
|
|
|
static gboolean
|
2013-01-13 14:45:31 +00:00
|
|
|
gst_base_parse_sink_query_default (GstBaseParse * parse, GstQuery * query)
|
2011-11-15 10:20:48 +00:00
|
|
|
{
|
2013-01-13 14:45:31 +00:00
|
|
|
GstPad *pad;
|
2011-11-15 10:20:48 +00:00
|
|
|
gboolean res;
|
|
|
|
|
2013-01-13 14:45:31 +00:00
|
|
|
pad = GST_BASE_PARSE_SINK_PAD (parse);
|
2011-11-15 10:20:48 +00:00
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
2013-01-13 14:45:31 +00:00
|
|
|
GstBaseParseClass *bclass;
|
|
|
|
|
|
|
|
bclass = GST_BASE_PARSE_GET_CLASS (parse);
|
|
|
|
|
2011-11-15 10:20:48 +00:00
|
|
|
if (bclass->get_sink_caps) {
|
|
|
|
GstCaps *caps, *filter;
|
|
|
|
|
|
|
|
gst_query_parse_caps (query, &filter);
|
|
|
|
caps = bclass->get_sink_caps (parse, filter);
|
|
|
|
GST_LOG_OBJECT (parse, "sink getcaps returning caps %" GST_PTR_FORMAT,
|
|
|
|
caps);
|
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
res = TRUE;
|
2011-11-24 10:23:07 +00:00
|
|
|
} else {
|
2011-11-26 16:34:12 +00:00
|
|
|
GstCaps *caps, *template_caps, *filter;
|
2011-11-24 10:23:07 +00:00
|
|
|
|
|
|
|
gst_query_parse_caps (query, &filter);
|
2011-11-26 16:34:12 +00:00
|
|
|
template_caps = gst_pad_get_pad_template_caps (pad);
|
|
|
|
if (filter != NULL) {
|
|
|
|
caps =
|
|
|
|
gst_caps_intersect_full (filter, template_caps,
|
|
|
|
GST_CAPS_INTERSECT_FIRST);
|
2012-01-27 11:50:24 +00:00
|
|
|
gst_caps_unref (template_caps);
|
2011-11-26 16:34:12 +00:00
|
|
|
} else {
|
2012-01-27 11:50:24 +00:00
|
|
|
caps = template_caps;
|
2011-11-26 16:34:12 +00:00
|
|
|
}
|
2011-11-24 10:23:07 +00:00
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
}
|
2011-11-15 10:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2013-01-13 14:45:31 +00:00
|
|
|
res = gst_pad_query_default (pad, GST_OBJECT_CAST (parse), query);
|
2011-11-15 10:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-01-13 14:45:31 +00:00
|
|
|
static gboolean
|
|
|
|
gst_base_parse_sink_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstBaseParseClass *bclass;
|
|
|
|
GstBaseParse *parse;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
parse = GST_BASE_PARSE (parent);
|
|
|
|
bclass = GST_BASE_PARSE_GET_CLASS (parse);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "%s query", GST_QUERY_TYPE_NAME (query));
|
|
|
|
|
|
|
|
if (bclass->sink_query)
|
|
|
|
ret = bclass->sink_query (parse, query);
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (parse, "%s query result: %d %" GST_PTR_FORMAT,
|
|
|
|
GST_QUERY_TYPE_NAME (query), ret, query);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_base_parse_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstBaseParseClass *bclass;
|
|
|
|
GstBaseParse *parse;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
parse = GST_BASE_PARSE (parent);
|
|
|
|
bclass = GST_BASE_PARSE_GET_CLASS (parse);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "%s query: %" GST_PTR_FORMAT,
|
|
|
|
GST_QUERY_TYPE_NAME (query), query);
|
|
|
|
|
|
|
|
if (bclass->src_query)
|
|
|
|
ret = bclass->src_query (parse, query);
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (parse, "%s query result: %d %" GST_PTR_FORMAT,
|
|
|
|
GST_QUERY_TYPE_NAME (query), ret, query);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-03-31 14:50:22 +00:00
|
|
|
/* gst_base_parse_src_event:
|
2008-11-13 12:59:34 +00:00
|
|
|
* @pad: #GstPad that received the event.
|
|
|
|
* @event: #GstEvent that was received.
|
|
|
|
*
|
|
|
|
* Handler for source pad events.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the event was handled.
|
|
|
|
*/
|
|
|
|
static gboolean
|
2011-11-17 11:40:45 +00:00
|
|
|
gst_base_parse_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
|
|
|
GstBaseParse *parse;
|
|
|
|
GstBaseParseClass *bclass;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
2011-11-17 11:40:45 +00:00
|
|
|
parse = GST_BASE_PARSE (parent);
|
2008-11-13 12:59:34 +00:00
|
|
|
bclass = GST_BASE_PARSE_GET_CLASS (parse);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "event %d, %s", GST_EVENT_TYPE (event),
|
|
|
|
GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
|
|
|
if (bclass->src_event)
|
2012-02-15 09:11:35 +00:00
|
|
|
ret = bclass->src_event (parse, event);
|
|
|
|
else
|
|
|
|
gst_event_unref (event);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:48:47 +00:00
|
|
|
static gboolean
|
|
|
|
gst_base_parse_is_seekable (GstBaseParse * parse)
|
|
|
|
{
|
|
|
|
/* FIXME: could do more here, e.g. check index or just send data from 0
|
|
|
|
* in pull mode and let decoder/sink clip */
|
2011-04-06 16:43:27 +00:00
|
|
|
return parse->priv->syncable;
|
2011-03-31 13:48:47 +00:00
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2013-01-12 20:54:26 +00:00
|
|
|
/* gst_base_parse_src_event_default:
|
2008-11-13 12:59:34 +00:00
|
|
|
* @parse: #GstBaseParse.
|
|
|
|
* @event: #GstEvent that was received.
|
|
|
|
*
|
|
|
|
* Default srcpad event handler.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the event was handled and can be dropped.
|
|
|
|
*/
|
|
|
|
static gboolean
|
2013-01-12 20:54:26 +00:00
|
|
|
gst_base_parse_src_event_default (GstBaseParse * parse, GstEvent * event)
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
2012-02-15 09:11:35 +00:00
|
|
|
gboolean res = FALSE;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
2012-02-15 09:11:35 +00:00
|
|
|
if (gst_base_parse_is_seekable (parse))
|
|
|
|
res = gst_base_parse_handle_seek (parse, event);
|
2008-11-13 12:59:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-02-15 09:11:35 +00:00
|
|
|
res = gst_pad_event_default (parse->srcpad, GST_OBJECT_CAST (parse),
|
|
|
|
event);
|
2008-11-13 12:59:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-02-15 09:11:35 +00:00
|
|
|
return res;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-23 14:48:25 +00:00
|
|
|
/**
|
2010-09-16 16:56:46 +00:00
|
|
|
* gst_base_parse_convert_default:
|
2009-11-23 14:48:25 +00:00
|
|
|
* @parse: #GstBaseParse.
|
|
|
|
* @src_format: #GstFormat describing the source format.
|
|
|
|
* @src_value: Source value to be converted.
|
|
|
|
* @dest_format: #GstFormat defining the converted format.
|
|
|
|
* @dest_value: Pointer where the conversion result will be put.
|
|
|
|
*
|
2010-09-16 16:56:46 +00:00
|
|
|
* Default implementation of "convert" vmethod in #GstBaseParse class.
|
2009-11-23 14:48:25 +00:00
|
|
|
*
|
|
|
|
* Returns: TRUE if conversion was successful.
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-09-16 16:56:46 +00:00
|
|
|
gst_base_parse_convert_default (GstBaseParse * parse,
|
2009-11-23 14:48:25 +00:00
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value, GstFormat dest_format, gint64 * dest_value)
|
|
|
|
{
|
|
|
|
gboolean ret = FALSE;
|
2009-12-16 17:38:33 +00:00
|
|
|
guint64 bytes, duration;
|
2009-11-23 14:48:25 +00:00
|
|
|
|
2009-12-16 17:38:33 +00:00
|
|
|
if (G_UNLIKELY (src_format == dest_format)) {
|
2009-11-23 14:48:25 +00:00
|
|
|
*dest_value = src_value;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-12-16 17:38:33 +00:00
|
|
|
if (G_UNLIKELY (src_value == -1)) {
|
|
|
|
*dest_value = -1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-17 15:19:37 +00:00
|
|
|
if (G_UNLIKELY (src_value == 0)) {
|
|
|
|
*dest_value = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-12-16 17:38:33 +00:00
|
|
|
/* need at least some frames */
|
|
|
|
if (!parse->priv->framecount)
|
2012-02-15 10:11:11 +00:00
|
|
|
goto no_framecount;
|
2009-12-16 17:38:33 +00:00
|
|
|
|
2010-09-22 11:55:20 +00:00
|
|
|
duration = parse->priv->acc_duration / GST_MSECOND;
|
|
|
|
bytes = parse->priv->bytecount;
|
2009-12-16 17:38:33 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (!duration || !bytes))
|
2012-02-15 10:11:11 +00:00
|
|
|
goto no_duration_bytes;
|
2009-11-23 14:48:25 +00:00
|
|
|
|
|
|
|
if (src_format == GST_FORMAT_BYTES) {
|
|
|
|
if (dest_format == GST_FORMAT_TIME) {
|
|
|
|
/* BYTES -> TIME conversion */
|
|
|
|
GST_DEBUG_OBJECT (parse, "converting bytes -> time");
|
2009-12-16 17:38:33 +00:00
|
|
|
*dest_value = gst_util_uint64_scale (src_value, duration, bytes);
|
2009-11-23 14:48:25 +00:00
|
|
|
*dest_value *= GST_MSECOND;
|
|
|
|
GST_DEBUG_OBJECT (parse, "conversion result: %" G_GINT64_FORMAT " ms",
|
|
|
|
*dest_value / GST_MSECOND);
|
|
|
|
ret = TRUE;
|
2012-02-15 10:11:11 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (parse, "converting bytes -> other not implemented");
|
2009-11-23 14:48:25 +00:00
|
|
|
}
|
|
|
|
} else if (src_format == GST_FORMAT_TIME) {
|
|
|
|
if (dest_format == GST_FORMAT_BYTES) {
|
2010-09-16 09:51:20 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "converting time -> bytes");
|
2009-12-16 17:38:33 +00:00
|
|
|
*dest_value = gst_util_uint64_scale (src_value / GST_MSECOND, bytes,
|
|
|
|
duration);
|
2009-11-23 14:48:25 +00:00
|
|
|
GST_DEBUG_OBJECT (parse,
|
|
|
|
"time %" G_GINT64_FORMAT " ms in bytes = %" G_GINT64_FORMAT,
|
|
|
|
src_value / GST_MSECOND, *dest_value);
|
|
|
|
ret = TRUE;
|
2012-02-15 10:11:11 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (parse, "converting time -> other not implemented");
|
2009-11-23 14:48:25 +00:00
|
|
|
}
|
|
|
|
} else if (src_format == GST_FORMAT_DEFAULT) {
|
2009-12-16 17:38:33 +00:00
|
|
|
/* DEFAULT == frame-based */
|
2009-11-23 14:48:25 +00:00
|
|
|
if (dest_format == GST_FORMAT_TIME) {
|
2012-02-15 10:11:11 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "converting default -> time");
|
2009-12-16 17:38:33 +00:00
|
|
|
if (parse->priv->fps_den) {
|
|
|
|
*dest_value = gst_util_uint64_scale (src_value,
|
|
|
|
GST_SECOND * parse->priv->fps_den, parse->priv->fps_num);
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
2012-02-15 10:11:11 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (parse, "converting default -> other not implemented");
|
2009-11-23 14:48:25 +00:00
|
|
|
}
|
2012-02-15 10:11:11 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (parse, "conversion not implemented");
|
2009-11-23 14:48:25 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2012-02-15 10:11:11 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_framecount:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (parse, "no framecount");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_duration_bytes:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (parse, "no duration %" G_GUINT64_FORMAT ", bytes %"
|
|
|
|
G_GUINT64_FORMAT, duration, bytes);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-11-23 14:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-04-08 18:07:02 +00:00
|
|
|
gst_base_parse_update_duration (GstBaseParse * baseparse)
|
2009-11-23 14:48:25 +00:00
|
|
|
{
|
|
|
|
GstPad *peer;
|
|
|
|
GstBaseParse *parse;
|
|
|
|
|
2011-04-08 18:07:02 +00:00
|
|
|
parse = GST_BASE_PARSE (baseparse);
|
2009-11-23 14:48:25 +00:00
|
|
|
|
|
|
|
peer = gst_pad_get_peer (parse->sinkpad);
|
|
|
|
if (peer) {
|
|
|
|
gboolean qres = FALSE;
|
2009-12-16 17:38:33 +00:00
|
|
|
gint64 ptot, dest_value;
|
2009-11-23 14:48:25 +00:00
|
|
|
|
2011-07-26 23:26:43 +00:00
|
|
|
qres = gst_pad_query_duration (peer, GST_FORMAT_BYTES, &ptot);
|
2009-11-23 14:48:25 +00:00
|
|
|
gst_object_unref (GST_OBJECT (peer));
|
|
|
|
if (qres) {
|
2011-07-26 23:26:43 +00:00
|
|
|
if (gst_base_parse_convert (parse, GST_FORMAT_BYTES, ptot,
|
2011-01-21 13:53:39 +00:00
|
|
|
GST_FORMAT_TIME, &dest_value)) {
|
2011-10-06 12:34:09 +00:00
|
|
|
|
|
|
|
/* inform if duration changed, but try to avoid spamming */
|
|
|
|
parse->priv->estimated_drift +=
|
|
|
|
dest_value - parse->priv->estimated_duration;
|
|
|
|
if (parse->priv->estimated_drift > GST_SECOND ||
|
|
|
|
parse->priv->estimated_drift < -GST_SECOND) {
|
|
|
|
gst_element_post_message (GST_ELEMENT (parse),
|
2012-09-02 01:04:14 +00:00
|
|
|
gst_message_new_duration_changed (GST_OBJECT (parse)));
|
2011-10-06 12:34:09 +00:00
|
|
|
parse->priv->estimated_drift = 0;
|
|
|
|
}
|
2009-12-16 17:38:33 +00:00
|
|
|
parse->priv->estimated_duration = dest_value;
|
2011-01-21 13:53:39 +00:00
|
|
|
GST_LOG_OBJECT (parse,
|
|
|
|
"updated estimated duration to %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (dest_value));
|
|
|
|
}
|
2009-11-23 14:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-03-26 18:56:49 +00:00
|
|
|
static void
|
|
|
|
gst_base_parse_post_bitrates (GstBaseParse * parse, gboolean post_min,
|
|
|
|
gboolean post_avg, gboolean post_max)
|
|
|
|
{
|
2011-05-06 22:40:58 +00:00
|
|
|
GstTagList *taglist = NULL;
|
|
|
|
|
|
|
|
if (post_min && parse->priv->post_min_bitrate) {
|
2011-10-30 10:26:11 +00:00
|
|
|
taglist = gst_tag_list_new_empty ();
|
2010-03-26 18:56:49 +00:00
|
|
|
|
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_MINIMUM_BITRATE, parse->priv->min_bitrate, NULL);
|
2011-05-06 22:40:58 +00:00
|
|
|
}
|
2010-03-26 18:56:49 +00:00
|
|
|
|
2010-09-20 11:30:54 +00:00
|
|
|
if (post_avg && parse->priv->post_avg_bitrate) {
|
2011-05-06 22:40:58 +00:00
|
|
|
if (taglist == NULL)
|
2011-10-30 10:26:11 +00:00
|
|
|
taglist = gst_tag_list_new_empty ();
|
2011-05-06 22:40:58 +00:00
|
|
|
|
2010-09-20 11:30:54 +00:00
|
|
|
parse->priv->posted_avg_bitrate = parse->priv->avg_bitrate;
|
2010-03-26 18:56:49 +00:00
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_BITRATE,
|
|
|
|
parse->priv->avg_bitrate, NULL);
|
2010-09-20 11:30:54 +00:00
|
|
|
}
|
2010-03-26 18:56:49 +00:00
|
|
|
|
2011-05-06 22:40:58 +00:00
|
|
|
if (post_max && parse->priv->post_max_bitrate) {
|
|
|
|
if (taglist == NULL)
|
2011-10-30 10:26:11 +00:00
|
|
|
taglist = gst_tag_list_new_empty ();
|
2011-05-06 22:40:58 +00:00
|
|
|
|
2010-03-26 18:56:49 +00:00
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_MAXIMUM_BITRATE, parse->priv->max_bitrate, NULL);
|
2011-05-06 22:40:58 +00:00
|
|
|
}
|
2010-03-26 18:56:49 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "Updated bitrates. Min: %u, Avg: %u, Max: %u",
|
|
|
|
parse->priv->min_bitrate, parse->priv->avg_bitrate,
|
|
|
|
parse->priv->max_bitrate);
|
|
|
|
|
2011-05-06 22:40:58 +00:00
|
|
|
if (taglist != NULL) {
|
2012-07-27 21:52:12 +00:00
|
|
|
gst_pad_push_event (parse->srcpad, gst_event_new_tag (taglist));
|
2011-05-06 22:40:58 +00:00
|
|
|
}
|
2010-03-26 18:56:49 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 14:50:22 +00:00
|
|
|
/* gst_base_parse_update_bitrates:
|
2010-03-25 11:22:58 +00:00
|
|
|
* @parse: #GstBaseParse.
|
|
|
|
* @buffer: Current frame as a #GstBuffer
|
|
|
|
*
|
|
|
|
* Keeps track of the minimum and maximum bitrates, and also maintains a
|
|
|
|
* running average bitrate of the stream so far.
|
|
|
|
*/
|
|
|
|
static void
|
2011-01-10 14:34:48 +00:00
|
|
|
gst_base_parse_update_bitrates (GstBaseParse * parse, GstBaseParseFrame * frame)
|
2010-03-25 11:22:58 +00:00
|
|
|
{
|
|
|
|
/* Only update the tag on a 10 kbps delta */
|
|
|
|
static const gint update_threshold = 10000;
|
|
|
|
|
|
|
|
guint64 data_len, frame_dur;
|
2011-01-10 14:34:48 +00:00
|
|
|
gint overhead, frame_bitrate, old_avg_bitrate;
|
2010-03-25 11:22:58 +00:00
|
|
|
gboolean update_min = FALSE, update_avg = FALSE, update_max = FALSE;
|
2011-01-10 14:34:48 +00:00
|
|
|
GstBuffer *buffer = frame->buffer;
|
2010-03-25 11:22:58 +00:00
|
|
|
|
2011-01-10 14:34:48 +00:00
|
|
|
overhead = frame->overhead;
|
|
|
|
if (overhead == -1)
|
|
|
|
return;
|
2010-03-25 11:22:58 +00:00
|
|
|
|
2011-04-11 08:53:39 +00:00
|
|
|
data_len = gst_buffer_get_size (buffer) - overhead;
|
2010-03-25 11:22:58 +00:00
|
|
|
parse->priv->data_bytecount += data_len;
|
|
|
|
|
2010-09-22 11:55:20 +00:00
|
|
|
/* duration should be valid by now,
|
|
|
|
* either set by subclass or maybe based on fps settings */
|
2010-11-25 16:14:23 +00:00
|
|
|
if (GST_BUFFER_DURATION_IS_VALID (buffer) && parse->priv->acc_duration != 0) {
|
2010-03-25 11:22:58 +00:00
|
|
|
/* Calculate duration of a frame from buffer properties */
|
|
|
|
frame_dur = GST_BUFFER_DURATION (buffer);
|
|
|
|
parse->priv->avg_bitrate = (8 * parse->priv->data_bytecount * GST_SECOND) /
|
|
|
|
parse->priv->acc_duration;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* No way to figure out frame duration (is this even possible?) */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-17 16:24:22 +00:00
|
|
|
/* override if subclass provided bitrate, e.g. metadata based */
|
|
|
|
if (parse->priv->bitrate) {
|
|
|
|
parse->priv->avg_bitrate = parse->priv->bitrate;
|
2010-10-11 15:36:19 +00:00
|
|
|
/* spread this (confirmed) info ASAP */
|
|
|
|
if (parse->priv->posted_avg_bitrate != parse->priv->avg_bitrate)
|
|
|
|
gst_base_parse_post_bitrates (parse, FALSE, TRUE, FALSE);
|
2010-09-17 16:24:22 +00:00
|
|
|
}
|
|
|
|
|
2011-01-11 14:23:29 +00:00
|
|
|
if (frame_dur)
|
|
|
|
frame_bitrate = (8 * data_len * GST_SECOND) / frame_dur;
|
|
|
|
else
|
|
|
|
return;
|
2010-03-25 11:22:58 +00:00
|
|
|
|
2010-09-20 11:30:54 +00:00
|
|
|
GST_LOG_OBJECT (parse, "frame bitrate %u, avg bitrate %u", frame_bitrate,
|
|
|
|
parse->priv->avg_bitrate);
|
|
|
|
|
2010-10-25 12:15:50 +00:00
|
|
|
if (parse->priv->framecount < MIN_FRAMES_TO_POST_BITRATE) {
|
|
|
|
goto exit;
|
|
|
|
} else if (parse->priv->framecount == MIN_FRAMES_TO_POST_BITRATE) {
|
|
|
|
/* always post all at threshold time */
|
|
|
|
update_min = update_max = update_avg = TRUE;
|
2011-02-08 18:09:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (G_LIKELY (parse->priv->framecount >= MIN_FRAMES_TO_POST_BITRATE)) {
|
2010-10-25 12:15:50 +00:00
|
|
|
if (frame_bitrate < parse->priv->min_bitrate) {
|
|
|
|
parse->priv->min_bitrate = frame_bitrate;
|
|
|
|
update_min = TRUE;
|
|
|
|
}
|
2010-03-25 11:22:58 +00:00
|
|
|
|
2010-10-25 12:15:50 +00:00
|
|
|
if (frame_bitrate > parse->priv->max_bitrate) {
|
|
|
|
parse->priv->max_bitrate = frame_bitrate;
|
|
|
|
update_max = TRUE;
|
|
|
|
}
|
2010-03-26 18:56:49 +00:00
|
|
|
|
2010-10-25 12:15:50 +00:00
|
|
|
old_avg_bitrate = parse->priv->posted_avg_bitrate;
|
|
|
|
if ((gint) (old_avg_bitrate - parse->priv->avg_bitrate) > update_threshold
|
|
|
|
|| (gint) (parse->priv->avg_bitrate - old_avg_bitrate) >
|
|
|
|
update_threshold)
|
|
|
|
update_avg = TRUE;
|
|
|
|
}
|
2010-09-20 11:30:54 +00:00
|
|
|
|
2010-10-25 12:15:50 +00:00
|
|
|
if ((update_min || update_avg || update_max))
|
2010-03-26 18:56:49 +00:00
|
|
|
gst_base_parse_post_bitrates (parse, update_min, update_avg, update_max);
|
2010-09-17 16:33:29 +00:00
|
|
|
|
2010-10-25 12:15:50 +00:00
|
|
|
exit:
|
|
|
|
return;
|
2010-03-25 11:22:58 +00:00
|
|
|
}
|
|
|
|
|
2010-09-21 08:57:04 +00:00
|
|
|
/**
|
|
|
|
* gst_base_parse_add_index_entry:
|
|
|
|
* @parse: #GstBaseParse.
|
|
|
|
* @offset: offset of entry
|
|
|
|
* @ts: timestamp associated with offset
|
|
|
|
* @key: whether entry refers to keyframe
|
|
|
|
* @force: add entry disregarding sanity checks
|
|
|
|
*
|
|
|
|
* Adds an entry to the index associating @offset to @ts. It is recommended
|
|
|
|
* to only add keyframe entries. @force allows to bypass checks, such as
|
|
|
|
* whether the stream is (upstream) seekable, another entry is already "close"
|
|
|
|
* to the new entry, etc.
|
|
|
|
*
|
|
|
|
* Returns: #gboolean indicating whether entry was added
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_base_parse_add_index_entry (GstBaseParse * parse, guint64 offset,
|
|
|
|
GstClockTime ts, gboolean key, gboolean force)
|
|
|
|
{
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
GstIndexAssociation associations[2];
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (parse, "Adding key=%d index entry %" GST_TIME_FORMAT
|
|
|
|
" @ offset 0x%08" G_GINT64_MODIFIER "x", key, GST_TIME_ARGS (ts), offset);
|
|
|
|
|
|
|
|
if (G_LIKELY (!force)) {
|
|
|
|
|
|
|
|
if (!parse->priv->upstream_seekable) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "upstream not seekable; discarding");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2010-11-17 13:30:09 +00:00
|
|
|
/* FIXME need better helper data structure that handles these issues
|
|
|
|
* related to ongoing collecting of index entries */
|
2012-06-13 12:02:48 +00:00
|
|
|
if (parse->priv->index_last_offset + parse->priv->idx_byte_interval >=
|
|
|
|
(gint64) offset) {
|
|
|
|
GST_LOG_OBJECT (parse,
|
|
|
|
"already have entries up to offset 0x%08" G_GINT64_MODIFIER "x",
|
|
|
|
parse->priv->index_last_offset + parse->priv->idx_byte_interval);
|
2010-09-21 08:57:04 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2011-01-11 14:22:51 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (parse->priv->index_last_ts) &&
|
|
|
|
GST_CLOCK_DIFF (parse->priv->index_last_ts, ts) <
|
2010-09-21 08:57:04 +00:00
|
|
|
parse->priv->idx_interval) {
|
2012-09-26 05:01:42 +00:00
|
|
|
GST_LOG_OBJECT (parse, "entry too close to last time %" GST_TIME_FORMAT,
|
2010-09-21 08:57:04 +00:00
|
|
|
GST_TIME_ARGS (parse->priv->index_last_ts));
|
|
|
|
goto exit;
|
|
|
|
}
|
2010-11-17 13:30:09 +00:00
|
|
|
|
|
|
|
/* if last is not really the last one */
|
|
|
|
if (!parse->priv->index_last_valid) {
|
|
|
|
GstClockTime prev_ts;
|
|
|
|
|
|
|
|
gst_base_parse_find_offset (parse, ts, TRUE, &prev_ts);
|
|
|
|
if (GST_CLOCK_DIFF (prev_ts, ts) < parse->priv->idx_interval) {
|
2012-09-26 05:01:42 +00:00
|
|
|
GST_LOG_OBJECT (parse,
|
2010-11-17 13:30:09 +00:00
|
|
|
"entry too close to existing entry %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (prev_ts));
|
|
|
|
parse->priv->index_last_offset = offset;
|
|
|
|
parse->priv->index_last_ts = ts;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
2010-09-21 08:57:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
associations[0].format = GST_FORMAT_TIME;
|
|
|
|
associations[0].value = ts;
|
|
|
|
associations[1].format = GST_FORMAT_BYTES;
|
|
|
|
associations[1].value = offset;
|
|
|
|
|
|
|
|
/* index might change on-the-fly, although that would be nutty app ... */
|
2011-12-04 13:35:38 +00:00
|
|
|
GST_BASE_PARSE_INDEX_LOCK (parse);
|
2010-09-21 08:57:04 +00:00
|
|
|
gst_index_add_associationv (parse->priv->index, parse->priv->index_id,
|
2011-12-30 15:31:17 +00:00
|
|
|
(key) ? GST_INDEX_ASSOCIATION_FLAG_KEY_UNIT :
|
|
|
|
GST_INDEX_ASSOCIATION_FLAG_DELTA_UNIT, 2,
|
|
|
|
(const GstIndexAssociation *) &associations);
|
2011-12-04 13:35:38 +00:00
|
|
|
GST_BASE_PARSE_INDEX_UNLOCK (parse);
|
2010-09-21 08:57:04 +00:00
|
|
|
|
2010-11-08 18:58:31 +00:00
|
|
|
if (key) {
|
|
|
|
parse->priv->index_last_offset = offset;
|
|
|
|
parse->priv->index_last_ts = ts;
|
|
|
|
}
|
2010-09-21 08:57:04 +00:00
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for seekable upstream, above and beyond a mere query */
|
|
|
|
static void
|
|
|
|
gst_base_parse_check_seekability (GstBaseParse * parse)
|
|
|
|
{
|
|
|
|
GstQuery *query;
|
|
|
|
gboolean seekable = FALSE;
|
|
|
|
gint64 start = -1, stop = -1;
|
|
|
|
guint idx_interval = 0;
|
2012-06-13 12:02:48 +00:00
|
|
|
guint64 idx_byte_interval = 0;
|
2010-09-21 08:57:04 +00:00
|
|
|
|
|
|
|
query = gst_query_new_seeking (GST_FORMAT_BYTES);
|
2011-05-17 09:20:05 +00:00
|
|
|
if (!gst_pad_peer_query (parse->sinkpad, query)) {
|
2010-09-21 08:57:04 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "seeking query failed");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_query_parse_seeking (query, NULL, &seekable, &start, &stop);
|
|
|
|
|
|
|
|
/* try harder to query upstream size if we didn't get it the first time */
|
|
|
|
if (seekable && stop == -1) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "doing duration query to fix up unset stop");
|
2011-11-15 16:50:34 +00:00
|
|
|
gst_pad_peer_query_duration (parse->sinkpad, GST_FORMAT_BYTES, &stop);
|
2010-09-21 08:57:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if upstream doesn't know the size, it's likely that it's not seekable in
|
|
|
|
* practice even if it technically may be seekable */
|
|
|
|
if (seekable && (start != 0 || stop <= start)) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "seekable but unknown start/stop -> disable");
|
|
|
|
seekable = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* let's not put every single frame into our index */
|
|
|
|
if (seekable) {
|
|
|
|
if (stop < 10 * 1024 * 1024)
|
|
|
|
idx_interval = 100;
|
|
|
|
else if (stop < 100 * 1024 * 1024)
|
|
|
|
idx_interval = 500;
|
|
|
|
else
|
|
|
|
idx_interval = 1000;
|
2012-06-13 12:02:48 +00:00
|
|
|
|
|
|
|
/* ensure that even for large files (e.g. very long audio files), the index
|
|
|
|
* stays reasonably-size, with some arbitrary limit to the total number of
|
|
|
|
* index entries */
|
|
|
|
idx_byte_interval = (stop - start) / MAX_INDEX_ENTRIES;
|
|
|
|
GST_DEBUG_OBJECT (parse,
|
|
|
|
"Limiting index entries to %d, indexing byte interval %"
|
|
|
|
G_GUINT64_FORMAT " bytes", MAX_INDEX_ENTRIES, idx_byte_interval);
|
2010-09-21 08:57:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
gst_query_unref (query);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "seekable: %d (%" G_GUINT64_FORMAT " - %"
|
|
|
|
G_GUINT64_FORMAT ")", seekable, start, stop);
|
|
|
|
parse->priv->upstream_seekable = seekable;
|
2010-11-16 16:04:35 +00:00
|
|
|
parse->priv->upstream_size = seekable ? stop : 0;
|
2010-09-21 08:57:04 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "idx_interval: %ums", idx_interval);
|
|
|
|
parse->priv->idx_interval = idx_interval * GST_MSECOND;
|
2012-06-13 12:02:48 +00:00
|
|
|
parse->priv->idx_byte_interval = idx_byte_interval;
|
2010-09-21 08:57:04 +00:00
|
|
|
}
|
|
|
|
|
2010-10-29 12:08:58 +00:00
|
|
|
/* some misc checks on upstream */
|
|
|
|
static void
|
|
|
|
gst_base_parse_check_upstream (GstBaseParse * parse)
|
|
|
|
{
|
|
|
|
gint64 stop;
|
|
|
|
|
2011-11-15 16:50:34 +00:00
|
|
|
if (gst_pad_peer_query_duration (parse->sinkpad, GST_FORMAT_TIME, &stop))
|
2010-10-29 12:08:58 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (stop) && stop) {
|
|
|
|
/* upstream has one, accept it also, and no further updates */
|
|
|
|
gst_base_parse_set_duration (parse, GST_FORMAT_TIME, stop, 0);
|
|
|
|
parse->priv->upstream_has_duration = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "upstream_has_duration: %d",
|
|
|
|
parse->priv->upstream_has_duration);
|
|
|
|
}
|
|
|
|
|
2010-11-08 18:58:31 +00:00
|
|
|
/* checks src caps to determine if dealing with audio or video */
|
|
|
|
/* TODO maybe forego automagic stuff and let subclass configure it ? */
|
|
|
|
static void
|
|
|
|
gst_base_parse_check_media (GstBaseParse * parse)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
GstStructure *s;
|
|
|
|
|
2011-05-06 17:04:54 +00:00
|
|
|
caps = gst_pad_get_current_caps (parse->srcpad);
|
2010-11-08 18:58:31 +00:00
|
|
|
if (G_LIKELY (caps) && (s = gst_caps_get_structure (caps, 0))) {
|
|
|
|
parse->priv->is_video =
|
|
|
|
g_str_has_prefix (gst_structure_get_name (s), "video");
|
|
|
|
} else {
|
|
|
|
/* historical default */
|
|
|
|
parse->priv->is_video = FALSE;
|
|
|
|
}
|
2011-05-06 17:04:54 +00:00
|
|
|
if (caps)
|
|
|
|
gst_caps_unref (caps);
|
2010-11-08 18:58:31 +00:00
|
|
|
|
2011-08-18 19:46:01 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "media is video: %d", parse->priv->is_video);
|
2010-11-08 18:58:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-15 17:38:46 +00:00
|
|
|
/* takes ownership of frame */
|
|
|
|
static void
|
|
|
|
gst_base_parse_queue_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
|
|
|
|
{
|
|
|
|
if (!(frame->_private_flags & GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC)) {
|
|
|
|
/* frame allocated on the heap, we can just take ownership */
|
|
|
|
g_queue_push_tail (&parse->priv->queued_frames, frame);
|
|
|
|
GST_TRACE ("queued frame %p", frame);
|
|
|
|
} else {
|
|
|
|
GstBaseParseFrame *copy;
|
|
|
|
|
|
|
|
/* probably allocated on the stack, must make a proper copy */
|
|
|
|
copy = gst_base_parse_frame_copy (frame);
|
|
|
|
g_queue_push_tail (&parse->priv->queued_frames, copy);
|
|
|
|
GST_TRACE ("queued frame %p (copy of %p)", copy, frame);
|
|
|
|
gst_base_parse_frame_free (frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-13 17:22:37 +00:00
|
|
|
/* makes sure that @buf is properly prepared and decorated for passing
|
|
|
|
* to baseclass, and an equally setup frame is returned setup with @buf.
|
|
|
|
* Takes ownership of @buf. */
|
|
|
|
static GstBaseParseFrame *
|
|
|
|
gst_base_parse_prepare_frame (GstBaseParse * parse, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstBaseParseFrame *frame = NULL;
|
|
|
|
|
|
|
|
buffer = gst_buffer_make_writable (buffer);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (parse,
|
|
|
|
"preparing frame at offset %" G_GUINT64_FORMAT
|
|
|
|
" (%#" G_GINT64_MODIFIER "x) of size %" G_GSIZE_FORMAT,
|
|
|
|
GST_BUFFER_OFFSET (buffer), GST_BUFFER_OFFSET (buffer),
|
|
|
|
gst_buffer_get_size (buffer));
|
|
|
|
|
|
|
|
if (parse->priv->discont) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "marking DISCONT");
|
|
|
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
parse->priv->discont = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_BUFFER_OFFSET (buffer) = parse->priv->offset;
|
|
|
|
|
2012-02-15 16:11:54 +00:00
|
|
|
frame = gst_base_parse_frame_new (buffer, 0, 0);
|
2012-02-13 17:22:37 +00:00
|
|
|
|
|
|
|
/* also ensure to update state flags */
|
|
|
|
gst_base_parse_frame_update (parse, frame, buffer);
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
|
2012-02-15 16:11:54 +00:00
|
|
|
if (parse->priv->prev_offset != parse->priv->offset || parse->priv->new_frame) {
|
|
|
|
GST_LOG_OBJECT (parse, "marking as new frame");
|
|
|
|
parse->priv->new_frame = FALSE;
|
|
|
|
frame->flags |= GST_BASE_PARSE_FRAME_FLAG_NEW_FRAME;
|
|
|
|
}
|
|
|
|
|
2012-02-13 17:22:37 +00:00
|
|
|
frame->offset = parse->priv->prev_offset = parse->priv->offset;
|
|
|
|
|
|
|
|
/* use default handler to provide initial (upstream) metadata */
|
|
|
|
gst_base_parse_parse_frame (parse, frame);
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2012-02-14 18:33:46 +00:00
|
|
|
/* Wraps buffer in a frame and dispatches to subclass.
|
|
|
|
* Also manages data skipping and offset handling (including adapter flushing).
|
|
|
|
* Takes ownership of @buffer */
|
2012-02-13 17:22:37 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_parse_handle_buffer (GstBaseParse * parse, GstBuffer * buffer,
|
|
|
|
gint * skip, gint * flushed)
|
|
|
|
{
|
|
|
|
GstBaseParseClass *klass = GST_BASE_PARSE_GET_CLASS (parse);
|
|
|
|
GstBaseParseFrame *frame;
|
|
|
|
GstFlowReturn ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (skip != NULL || flushed != NULL, GST_FLOW_ERROR);
|
|
|
|
|
2012-02-14 18:33:46 +00:00
|
|
|
GST_LOG_OBJECT (parse,
|
2012-12-11 15:46:01 +00:00
|
|
|
"handling buffer of size %" G_GSIZE_FORMAT " with dts %" GST_TIME_FORMAT
|
|
|
|
", pts %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT,
|
|
|
|
gst_buffer_get_size (buffer), GST_TIME_ARGS (GST_BUFFER_DTS (buffer)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
|
2012-02-14 18:33:46 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
|
|
|
|
|
2012-02-13 17:22:37 +00:00
|
|
|
/* track what is being flushed during this single round of frame processing */
|
|
|
|
parse->priv->flushed = 0;
|
|
|
|
*skip = 0;
|
|
|
|
|
|
|
|
/* make it easy for _finish_frame to pick up input data */
|
|
|
|
if (parse->priv->pad_mode == GST_PAD_MODE_PULL) {
|
|
|
|
gst_buffer_ref (buffer);
|
|
|
|
gst_adapter_push (parse->priv->adapter, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
frame = gst_base_parse_prepare_frame (parse, buffer);
|
|
|
|
ret = klass->handle_frame (parse, frame, skip);
|
|
|
|
|
|
|
|
*flushed = parse->priv->flushed;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (parse, "handle_frame skipped %d, flushed %d",
|
|
|
|
*skip, *flushed);
|
|
|
|
|
|
|
|
/* subclass can only do one of these, or semantics are too unclear */
|
|
|
|
g_assert (*skip == 0 || *flushed == 0);
|
|
|
|
|
2012-02-14 18:33:46 +00:00
|
|
|
/* track skipping */
|
|
|
|
if (*skip > 0) {
|
2012-09-03 06:32:50 +00:00
|
|
|
GstClockTime pts, dts;
|
2012-02-14 18:33:46 +00:00
|
|
|
GstBuffer *outbuf;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (parse, "finding sync, skipping %d bytes", *skip);
|
|
|
|
if (parse->segment.rate < 0.0 && !parse->priv->buffers_queued) {
|
|
|
|
/* reverse playback, and no frames found yet, so we are skipping
|
|
|
|
* the leading part of a fragment, which may form the tail of
|
|
|
|
* fragment coming later, hopefully subclass skips efficiently ... */
|
2012-09-03 06:32:50 +00:00
|
|
|
pts = gst_adapter_prev_pts (parse->priv->adapter, NULL);
|
|
|
|
dts = gst_adapter_prev_dts (parse->priv->adapter, NULL);
|
2012-02-14 18:33:46 +00:00
|
|
|
outbuf = gst_adapter_take_buffer (parse->priv->adapter, *skip);
|
|
|
|
outbuf = gst_buffer_make_writable (outbuf);
|
2012-09-03 06:32:50 +00:00
|
|
|
GST_BUFFER_PTS (outbuf) = pts;
|
|
|
|
GST_BUFFER_DTS (outbuf) = dts;
|
2012-02-14 18:33:46 +00:00
|
|
|
parse->priv->buffers_head =
|
|
|
|
g_slist_prepend (parse->priv->buffers_head, outbuf);
|
|
|
|
outbuf = NULL;
|
|
|
|
} else {
|
|
|
|
gst_adapter_flush (parse->priv->adapter, *skip);
|
|
|
|
}
|
|
|
|
if (!parse->priv->discont)
|
|
|
|
parse->priv->sync_offset = parse->priv->offset;
|
|
|
|
parse->priv->offset += *skip;
|
|
|
|
parse->priv->discont = TRUE;
|
|
|
|
/* check for indefinite skipping */
|
|
|
|
if (ret == GST_FLOW_OK)
|
|
|
|
ret = gst_base_parse_check_sync (parse);
|
|
|
|
}
|
|
|
|
|
2012-02-13 17:22:37 +00:00
|
|
|
parse->priv->offset += *flushed;
|
|
|
|
|
2012-02-14 18:33:46 +00:00
|
|
|
if (parse->priv->pad_mode == GST_PAD_MODE_PULL) {
|
|
|
|
gst_adapter_clear (parse->priv->adapter);
|
2012-02-13 17:22:37 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 16:11:54 +00:00
|
|
|
gst_base_parse_frame_free (frame);
|
|
|
|
|
2012-02-13 17:22:37 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-02-12 20:31:42 +00:00
|
|
|
/* gst_base_parse_handle_and_push_frame:
|
2008-11-13 12:59:34 +00:00
|
|
|
* @parse: #GstBaseParse.
|
|
|
|
* @klass: #GstBaseParseClass.
|
2011-04-15 16:41:02 +00:00
|
|
|
* @frame: (transfer full): a #GstBaseParseFrame
|
2008-11-13 12:59:34 +00:00
|
|
|
*
|
|
|
|
* Parses the frame from given buffer and pushes it forward. Also performs
|
|
|
|
* timestamp handling and checks the segment limits.
|
|
|
|
*
|
|
|
|
* This is called with srcpad STREAM_LOCK held.
|
|
|
|
*
|
|
|
|
* Returns: #GstFlowReturn
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
2011-01-10 14:34:48 +00:00
|
|
|
gst_base_parse_handle_and_push_frame (GstBaseParse * parse,
|
2012-02-13 17:22:37 +00:00
|
|
|
GstBaseParseFrame * frame)
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
2010-11-17 13:30:09 +00:00
|
|
|
gint64 offset;
|
2011-01-10 14:34:48 +00:00
|
|
|
GstBuffer *buffer;
|
|
|
|
|
|
|
|
g_return_val_if_fail (frame != NULL, GST_FLOW_ERROR);
|
|
|
|
|
|
|
|
buffer = frame->buffer;
|
2012-02-13 17:22:37 +00:00
|
|
|
offset = frame->offset;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-01-10 15:56:36 +00:00
|
|
|
/* check if subclass/format can provide ts.
|
2010-11-17 13:30:09 +00:00
|
|
|
* If so, that allows and enables extra seek and duration determining options */
|
2012-02-13 17:22:37 +00:00
|
|
|
if (G_UNLIKELY (parse->priv->first_frame_offset < 0)) {
|
2012-09-03 06:32:50 +00:00
|
|
|
if (GST_BUFFER_PTS_IS_VALID (buffer) && parse->priv->has_timing_info
|
2011-11-18 11:35:46 +00:00
|
|
|
&& parse->priv->pad_mode == GST_PAD_MODE_PULL) {
|
2010-11-17 13:30:09 +00:00
|
|
|
parse->priv->first_frame_offset = offset;
|
2012-09-03 06:32:50 +00:00
|
|
|
parse->priv->first_frame_pts = GST_BUFFER_PTS (buffer);
|
|
|
|
parse->priv->first_frame_dts = GST_BUFFER_DTS (buffer);
|
2012-12-11 15:46:01 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "subclass provided dts %" GST_TIME_FORMAT
|
|
|
|
", pts %" GST_TIME_FORMAT " for first frame at offset %"
|
|
|
|
G_GINT64_FORMAT, GST_TIME_ARGS (parse->priv->first_frame_dts),
|
2012-09-03 06:32:50 +00:00
|
|
|
GST_TIME_ARGS (parse->priv->first_frame_pts),
|
2010-11-17 13:30:09 +00:00
|
|
|
parse->priv->first_frame_offset);
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (parse->priv->duration)) {
|
|
|
|
gint64 off;
|
|
|
|
GstClockTime last_ts = G_MAXINT64;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "no duration; trying scan to determine");
|
|
|
|
gst_base_parse_locate_time (parse, &last_ts, &off);
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (last_ts))
|
|
|
|
gst_base_parse_set_duration (parse, GST_FORMAT_TIME, last_ts, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* disable further checks */
|
|
|
|
parse->priv->first_frame_offset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-09 11:32:02 +00:00
|
|
|
/* interpolating and no valid pts yet,
|
|
|
|
* start with dts and carry on from there */
|
2013-04-23 09:47:54 +00:00
|
|
|
if (parse->priv->infer_ts && parse->priv->pts_interpolate
|
|
|
|
&& !GST_CLOCK_TIME_IS_VALID (parse->priv->next_pts))
|
2013-02-09 11:32:02 +00:00
|
|
|
parse->priv->next_pts = parse->priv->next_dts;
|
|
|
|
|
2011-01-10 16:07:38 +00:00
|
|
|
/* again use default handler to add missing metadata;
|
|
|
|
* we may have new information on frame properties */
|
2011-01-10 14:34:48 +00:00
|
|
|
gst_base_parse_parse_frame (parse, frame);
|
2012-09-03 06:32:50 +00:00
|
|
|
|
|
|
|
parse->priv->next_pts = GST_CLOCK_TIME_NONE;
|
|
|
|
if (GST_BUFFER_DTS_IS_VALID (buffer) && GST_BUFFER_DURATION_IS_VALID (buffer)) {
|
|
|
|
parse->priv->next_dts =
|
|
|
|
GST_BUFFER_DTS (buffer) + GST_BUFFER_DURATION (buffer);
|
2012-09-13 05:44:37 +00:00
|
|
|
if (parse->priv->pts_interpolate && GST_BUFFER_PTS_IS_VALID (buffer)) {
|
2012-09-03 06:32:50 +00:00
|
|
|
GstClockTime next_pts =
|
|
|
|
GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer);
|
|
|
|
if (next_pts >= parse->priv->next_dts)
|
|
|
|
parse->priv->next_pts = next_pts;
|
|
|
|
}
|
2009-11-23 14:48:25 +00:00
|
|
|
} else {
|
|
|
|
/* we lost track, do not produce bogus time next time around
|
|
|
|
* (probably means parser subclass has given up on parsing as well) */
|
|
|
|
GST_DEBUG_OBJECT (parse, "no next fallback timestamp");
|
2012-09-03 06:32:50 +00:00
|
|
|
parse->priv->next_dts = GST_CLOCK_TIME_NONE;
|
2009-11-23 14:48:25 +00:00
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-11-17 15:23:42 +00:00
|
|
|
if (parse->priv->upstream_seekable && parse->priv->exact_position &&
|
2012-09-03 06:32:50 +00:00
|
|
|
GST_BUFFER_PTS_IS_VALID (buffer))
|
2010-11-17 15:23:42 +00:00
|
|
|
gst_base_parse_add_index_entry (parse, offset,
|
2012-09-03 06:32:50 +00:00
|
|
|
GST_BUFFER_PTS (buffer),
|
2010-11-17 15:23:42 +00:00
|
|
|
!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT), FALSE);
|
|
|
|
|
2011-04-02 12:02:01 +00:00
|
|
|
/* All OK, push queued frames if there are any */
|
2011-04-02 13:04:42 +00:00
|
|
|
if (G_UNLIKELY (!g_queue_is_empty (&parse->priv->queued_frames))) {
|
|
|
|
GstBaseParseFrame *queued_frame;
|
|
|
|
|
|
|
|
while ((queued_frame = g_queue_pop_head (&parse->priv->queued_frames))) {
|
|
|
|
gst_base_parse_push_frame (parse, queued_frame);
|
|
|
|
}
|
2011-04-02 12:02:01 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 14:34:48 +00:00
|
|
|
return gst_base_parse_push_frame (parse, frame);
|
2009-07-14 12:08:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-01-10 14:34:48 +00:00
|
|
|
* gst_base_parse_push_frame:
|
2009-07-14 12:08:04 +00:00
|
|
|
* @parse: #GstBaseParse.
|
2012-02-13 17:22:37 +00:00
|
|
|
* @frame: (transfer none): a #GstBaseParseFrame
|
2009-07-14 12:08:04 +00:00
|
|
|
*
|
2012-02-13 17:22:37 +00:00
|
|
|
* Pushes the frame's buffer downstream, sends any pending events and
|
|
|
|
* does some timestamp and segment handling. Takes ownership of
|
|
|
|
* frame's buffer, though caller retains ownership of @frame.
|
2009-07-14 12:08:04 +00:00
|
|
|
*
|
2011-01-10 14:34:48 +00:00
|
|
|
* This must be called with sinkpad STREAM_LOCK held.
|
2009-07-14 12:08:04 +00:00
|
|
|
*
|
|
|
|
* Returns: #GstFlowReturn
|
|
|
|
*/
|
|
|
|
GstFlowReturn
|
2011-01-10 14:34:48 +00:00
|
|
|
gst_base_parse_push_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
|
2009-07-14 12:08:04 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2010-03-26 17:19:00 +00:00
|
|
|
GstClockTime last_start = GST_CLOCK_TIME_NONE;
|
2009-07-14 12:08:04 +00:00
|
|
|
GstClockTime last_stop = GST_CLOCK_TIME_NONE;
|
2010-09-17 15:21:46 +00:00
|
|
|
GstBaseParseClass *klass = GST_BASE_PARSE_GET_CLASS (parse);
|
2011-01-10 14:34:48 +00:00
|
|
|
GstBuffer *buffer;
|
2011-04-11 08:53:39 +00:00
|
|
|
gsize size;
|
2011-01-10 14:34:48 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (frame != NULL, GST_FLOW_ERROR);
|
|
|
|
g_return_val_if_fail (frame->buffer != NULL, GST_FLOW_ERROR);
|
|
|
|
|
2011-04-15 17:38:46 +00:00
|
|
|
GST_TRACE_OBJECT (parse, "pushing frame %p", frame);
|
|
|
|
|
2011-01-10 14:34:48 +00:00
|
|
|
buffer = frame->buffer;
|
2009-07-14 12:08:04 +00:00
|
|
|
|
2009-11-23 14:48:25 +00:00
|
|
|
GST_LOG_OBJECT (parse,
|
2012-12-11 15:46:01 +00:00
|
|
|
"processing buffer of size %" G_GSIZE_FORMAT " with dts %" GST_TIME_FORMAT
|
|
|
|
", pts %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT,
|
|
|
|
gst_buffer_get_size (buffer),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DTS (buffer)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
|
2009-11-23 14:48:25 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
|
|
|
|
|
|
|
|
/* update stats */
|
2012-02-13 17:22:37 +00:00
|
|
|
parse->priv->bytecount += frame->size;
|
2011-01-10 14:34:48 +00:00
|
|
|
if (G_LIKELY (!(frame->flags & GST_BASE_PARSE_FRAME_FLAG_NO_FRAME))) {
|
2009-12-16 17:38:33 +00:00
|
|
|
parse->priv->framecount++;
|
|
|
|
if (GST_BUFFER_DURATION_IS_VALID (buffer)) {
|
|
|
|
parse->priv->acc_duration += GST_BUFFER_DURATION (buffer);
|
|
|
|
}
|
|
|
|
}
|
2011-01-21 13:53:39 +00:00
|
|
|
/* 0 means disabled */
|
|
|
|
if (parse->priv->update_interval < 0)
|
|
|
|
parse->priv->update_interval = 50;
|
|
|
|
else if (parse->priv->update_interval > 0 &&
|
2009-11-23 14:48:25 +00:00
|
|
|
(parse->priv->framecount % parse->priv->update_interval) == 0)
|
|
|
|
gst_base_parse_update_duration (parse);
|
|
|
|
|
2012-12-11 15:46:01 +00:00
|
|
|
if (GST_BUFFER_PTS_IS_VALID (buffer))
|
|
|
|
last_start = last_stop = GST_BUFFER_PTS (buffer);
|
2010-03-26 17:19:00 +00:00
|
|
|
if (last_start != GST_CLOCK_TIME_NONE
|
|
|
|
&& GST_BUFFER_DURATION_IS_VALID (buffer))
|
|
|
|
last_stop = last_start + GST_BUFFER_DURATION (buffer);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2009-03-31 14:07:46 +00:00
|
|
|
/* should have caps by now */
|
2012-01-02 14:39:02 +00:00
|
|
|
if (!gst_pad_has_current_caps (parse->srcpad))
|
|
|
|
goto no_caps;
|
2009-03-31 14:07:46 +00:00
|
|
|
|
2012-03-05 13:41:12 +00:00
|
|
|
if (G_UNLIKELY (parse->priv->pending_segment)) {
|
|
|
|
/* have caps; check identity */
|
|
|
|
gst_base_parse_check_media (parse);
|
|
|
|
}
|
|
|
|
|
2012-12-14 14:22:27 +00:00
|
|
|
/* Push pending events, including SEGMENT events */
|
2012-03-05 13:23:17 +00:00
|
|
|
if (G_UNLIKELY (parse->priv->pending_events)) {
|
2012-09-03 17:30:08 +00:00
|
|
|
GList *r = g_list_reverse (parse->priv->pending_events);
|
2012-03-05 13:23:17 +00:00
|
|
|
GList *l;
|
|
|
|
|
2012-09-03 17:30:08 +00:00
|
|
|
parse->priv->pending_events = NULL;
|
|
|
|
for (l = r; l != NULL; l = l->next) {
|
2012-03-05 13:23:17 +00:00
|
|
|
gst_pad_push_event (parse->srcpad, GST_EVENT (l->data));
|
|
|
|
}
|
2012-09-03 17:30:08 +00:00
|
|
|
g_list_free (r);
|
2012-03-05 13:41:12 +00:00
|
|
|
parse->priv->pending_segment = FALSE;
|
2012-03-05 13:23:17 +00:00
|
|
|
}
|
|
|
|
|
2010-09-21 11:57:10 +00:00
|
|
|
/* segment adjustment magic; only if we are running the whole show */
|
2011-04-06 16:43:27 +00:00
|
|
|
if (!parse->priv->passthrough && parse->segment.rate > 0.0 &&
|
2011-11-18 11:35:46 +00:00
|
|
|
(parse->priv->pad_mode == GST_PAD_MODE_PULL ||
|
2010-09-21 11:57:10 +00:00
|
|
|
parse->priv->upstream_seekable)) {
|
2012-03-05 13:23:17 +00:00
|
|
|
/* handle gaps */
|
2011-05-13 16:07:24 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (parse->segment.position) &&
|
2010-09-21 11:57:10 +00:00
|
|
|
GST_CLOCK_TIME_IS_VALID (last_start)) {
|
|
|
|
GstClockTimeDiff diff;
|
|
|
|
|
|
|
|
/* only send newsegments with increasing start times,
|
|
|
|
* otherwise if these go back and forth downstream (sinks) increase
|
|
|
|
* accumulated time and running_time */
|
2011-05-13 16:07:24 +00:00
|
|
|
diff = GST_CLOCK_DIFF (parse->segment.position, last_start);
|
2011-03-13 23:38:12 +00:00
|
|
|
if (G_UNLIKELY (diff > 2 * GST_SECOND
|
|
|
|
&& last_start > parse->segment.start
|
|
|
|
&& (!GST_CLOCK_TIME_IS_VALID (parse->segment.stop)
|
|
|
|
|| last_start < parse->segment.stop))) {
|
2011-05-13 16:07:24 +00:00
|
|
|
|
2010-09-21 11:57:10 +00:00
|
|
|
GST_DEBUG_OBJECT (parse,
|
2011-03-13 23:38:12 +00:00
|
|
|
"Gap of %" G_GINT64_FORMAT " ns detected in stream " "(%"
|
|
|
|
GST_TIME_FORMAT " -> %" GST_TIME_FORMAT "). "
|
2012-12-14 14:22:27 +00:00
|
|
|
"Sending updated SEGMENT events", diff,
|
2011-05-13 16:07:24 +00:00
|
|
|
GST_TIME_ARGS (parse->segment.position),
|
2010-09-21 11:57:10 +00:00
|
|
|
GST_TIME_ARGS (last_start));
|
2011-05-13 16:07:24 +00:00
|
|
|
|
2012-03-08 09:19:52 +00:00
|
|
|
/* skip gap FIXME */
|
2012-03-05 13:23:17 +00:00
|
|
|
gst_pad_push_event (parse->srcpad,
|
2012-03-08 09:19:52 +00:00
|
|
|
gst_event_new_segment (&parse->segment));
|
|
|
|
|
2011-05-13 16:07:24 +00:00
|
|
|
parse->segment.position = last_start;
|
2010-09-21 11:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-21 17:18:39 +00:00
|
|
|
}
|
|
|
|
|
2010-10-11 15:49:46 +00:00
|
|
|
/* update bitrates and optionally post corresponding tags
|
|
|
|
* (following newsegment) */
|
2011-01-10 14:34:48 +00:00
|
|
|
gst_base_parse_update_bitrates (parse, frame);
|
2010-10-11 15:49:46 +00:00
|
|
|
|
2011-01-10 14:34:48 +00:00
|
|
|
if (klass->pre_push_frame) {
|
|
|
|
ret = klass->pre_push_frame (parse, frame);
|
|
|
|
} else {
|
|
|
|
frame->flags |= GST_BASE_PARSE_FRAME_FLAG_CLIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* take final ownership of frame buffer */
|
2012-02-13 17:22:37 +00:00
|
|
|
if (frame->out_buffer) {
|
|
|
|
buffer = frame->out_buffer;
|
|
|
|
frame->out_buffer = NULL;
|
|
|
|
gst_buffer_replace (&frame->buffer, NULL);
|
|
|
|
} else {
|
|
|
|
buffer = frame->buffer;
|
|
|
|
frame->buffer = NULL;
|
|
|
|
}
|
2011-01-10 14:34:48 +00:00
|
|
|
|
|
|
|
/* subclass must play nice */
|
|
|
|
g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
|
|
|
|
|
2012-02-13 17:22:37 +00:00
|
|
|
size = gst_buffer_get_size (buffer);
|
|
|
|
|
2010-11-08 18:58:31 +00:00
|
|
|
parse->priv->seen_keyframe |= parse->priv->is_video &&
|
|
|
|
!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
|
2011-01-10 14:34:48 +00:00
|
|
|
if (frame->flags & GST_BASE_PARSE_FRAME_FLAG_CLIP) {
|
2010-09-17 15:21:46 +00:00
|
|
|
if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer) &&
|
|
|
|
GST_CLOCK_TIME_IS_VALID (parse->segment.stop) &&
|
2010-09-22 13:07:09 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buffer) >
|
|
|
|
parse->segment.stop + parse->priv->lead_out_ts) {
|
2010-09-17 15:21:46 +00:00
|
|
|
GST_LOG_OBJECT (parse, "Dropped frame, after segment");
|
2011-10-10 09:33:51 +00:00
|
|
|
ret = GST_FLOW_EOS;
|
2010-09-17 15:21:46 +00:00
|
|
|
} else if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer) &&
|
|
|
|
GST_BUFFER_DURATION_IS_VALID (buffer) &&
|
|
|
|
GST_CLOCK_TIME_IS_VALID (parse->segment.start) &&
|
2010-09-22 13:07:09 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer) +
|
|
|
|
parse->priv->lead_in_ts < parse->segment.start) {
|
2010-11-08 18:58:31 +00:00
|
|
|
if (parse->priv->seen_keyframe) {
|
|
|
|
GST_LOG_OBJECT (parse, "Frame before segment, after keyframe");
|
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (parse, "Dropped frame, before segment");
|
|
|
|
ret = GST_BASE_PARSE_FLOW_DROPPED;
|
|
|
|
}
|
2010-09-17 15:21:46 +00:00
|
|
|
} else {
|
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == GST_BASE_PARSE_FLOW_DROPPED) {
|
2011-04-11 08:53:39 +00:00
|
|
|
GST_LOG_OBJECT (parse, "frame (%" G_GSIZE_FORMAT " bytes) dropped", size);
|
2008-11-13 12:59:34 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2010-09-17 15:21:46 +00:00
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
} else if (ret == GST_FLOW_OK) {
|
2010-09-29 14:12:42 +00:00
|
|
|
if (parse->segment.rate > 0.0) {
|
2011-07-21 14:49:13 +00:00
|
|
|
GST_LOG_OBJECT (parse, "pushing frame (%" G_GSIZE_FORMAT " bytes) now..",
|
|
|
|
size);
|
2010-11-16 16:04:35 +00:00
|
|
|
ret = gst_pad_push (parse->srcpad, buffer);
|
2011-07-07 13:57:18 +00:00
|
|
|
GST_LOG_OBJECT (parse, "frame pushed, flow %s", gst_flow_get_name (ret));
|
2010-09-25 12:32:06 +00:00
|
|
|
} else {
|
2011-04-11 08:53:39 +00:00
|
|
|
GST_LOG_OBJECT (parse, "frame (%" G_GSIZE_FORMAT " bytes) queued for now",
|
|
|
|
size);
|
2010-09-29 14:12:42 +00:00
|
|
|
parse->priv->buffers_queued =
|
|
|
|
g_slist_prepend (parse->priv->buffers_queued, buffer);
|
|
|
|
ret = GST_FLOW_OK;
|
2010-09-25 12:32:06 +00:00
|
|
|
}
|
2010-09-17 15:21:46 +00:00
|
|
|
} else {
|
2011-04-11 08:53:39 +00:00
|
|
|
GST_LOG_OBJECT (parse, "frame (%" G_GSIZE_FORMAT " bytes) not pushed: %s",
|
|
|
|
size, gst_flow_get_name (ret));
|
2011-07-07 13:57:18 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2010-09-21 11:57:10 +00:00
|
|
|
/* if we are not sufficiently in control, let upstream decide on EOS */
|
2013-08-07 16:24:40 +00:00
|
|
|
if (ret == GST_FLOW_EOS && !parse->priv->disable_passthrough &&
|
2011-04-06 16:43:27 +00:00
|
|
|
(parse->priv->passthrough ||
|
2011-11-18 11:35:46 +00:00
|
|
|
(parse->priv->pad_mode == GST_PAD_MODE_PUSH &&
|
2010-09-21 11:57:10 +00:00
|
|
|
!parse->priv->upstream_seekable)))
|
|
|
|
ret = GST_FLOW_OK;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update current running segment position */
|
2010-09-21 11:57:10 +00:00
|
|
|
if (ret == GST_FLOW_OK && last_stop != GST_CLOCK_TIME_NONE &&
|
2011-05-13 16:07:24 +00:00
|
|
|
parse->segment.position < last_stop)
|
|
|
|
parse->segment.position = last_stop;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
return ret;
|
2012-01-02 14:39:02 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_caps:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (parse, STREAM, DECODE, ("No caps set"), (NULL));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
2012-02-13 17:22:37 +00:00
|
|
|
/**
|
|
|
|
* gst_base_parse_finish_frame:
|
|
|
|
* @parse: a #GstBaseParse
|
|
|
|
* @frame: a #GstBaseParseFrame
|
|
|
|
* @size: consumed input data represented by frame
|
|
|
|
*
|
|
|
|
* Collects parsed data and pushes this downstream.
|
|
|
|
* Source pad caps must be set when this is called.
|
|
|
|
*
|
|
|
|
* If @frame's out_buffer is set, that will be used as subsequent frame data.
|
|
|
|
* Otherwise, @size samples will be taken from the input and used for output,
|
|
|
|
* and the output's metadata (timestamps etc) will be taken as (optionally)
|
2012-02-15 16:12:09 +00:00
|
|
|
* set by the subclass on @frame's (input) buffer (which is otherwise
|
|
|
|
* ignored for any but the above purpose/information).
|
2012-02-13 17:22:37 +00:00
|
|
|
*
|
|
|
|
* Note that the latter buffer is invalidated by this call, whereas the
|
|
|
|
* caller retains ownership of @frame.
|
|
|
|
*
|
|
|
|
* Returns: a #GstFlowReturn that should be escalated to caller (of caller)
|
|
|
|
*/
|
|
|
|
GstFlowReturn
|
|
|
|
gst_base_parse_finish_frame (GstBaseParse * parse, GstBaseParseFrame * frame,
|
|
|
|
gint size)
|
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
|
|
|
|
g_return_val_if_fail (frame != NULL, GST_FLOW_ERROR);
|
|
|
|
g_return_val_if_fail (frame->buffer != NULL, GST_FLOW_ERROR);
|
|
|
|
g_return_val_if_fail (size > 0 || frame->out_buffer, GST_FLOW_ERROR);
|
|
|
|
g_return_val_if_fail (gst_adapter_available (parse->priv->adapter) >= size,
|
|
|
|
GST_FLOW_ERROR);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (parse, "finished frame at offset %" G_GUINT64_FORMAT ", "
|
|
|
|
"flushing size %d", frame->offset, size);
|
|
|
|
|
2012-07-15 11:59:44 +00:00
|
|
|
/* some one-time start-up */
|
|
|
|
if (G_UNLIKELY (parse->priv->framecount == 0)) {
|
|
|
|
gst_base_parse_check_seekability (parse);
|
|
|
|
gst_base_parse_check_upstream (parse);
|
|
|
|
}
|
|
|
|
|
2012-07-24 11:49:36 +00:00
|
|
|
parse->priv->flushed += size;
|
|
|
|
|
2012-02-13 17:22:37 +00:00
|
|
|
if (parse->priv->scanning && frame->buffer) {
|
|
|
|
if (!parse->priv->scanned_frame) {
|
|
|
|
parse->priv->scanned_frame = gst_base_parse_frame_copy (frame);
|
|
|
|
}
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* either PUSH or PULL mode arranges for adapter data */
|
|
|
|
/* ensure output buffer */
|
|
|
|
if (!frame->out_buffer) {
|
|
|
|
GstBuffer *src, *dest;
|
|
|
|
|
|
|
|
frame->out_buffer = gst_adapter_take_buffer (parse->priv->adapter, size);
|
|
|
|
dest = frame->out_buffer;
|
|
|
|
src = frame->buffer;
|
|
|
|
GST_BUFFER_PTS (dest) = GST_BUFFER_PTS (src);
|
|
|
|
GST_BUFFER_DTS (dest) = GST_BUFFER_DTS (src);
|
|
|
|
GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET (src);
|
|
|
|
GST_BUFFER_DURATION (dest) = GST_BUFFER_DURATION (src);
|
|
|
|
GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_END (src);
|
|
|
|
GST_MINI_OBJECT_FLAGS (dest) = GST_MINI_OBJECT_FLAGS (src);
|
|
|
|
} else {
|
|
|
|
gst_adapter_flush (parse->priv->adapter, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* use as input for subsequent processing */
|
|
|
|
gst_buffer_replace (&frame->buffer, frame->out_buffer);
|
|
|
|
gst_buffer_unref (frame->out_buffer);
|
|
|
|
frame->out_buffer = NULL;
|
|
|
|
|
2012-02-15 09:58:08 +00:00
|
|
|
/* mark input size consumed */
|
|
|
|
frame->size = size;
|
|
|
|
|
2012-02-13 17:22:37 +00:00
|
|
|
/* subclass might queue frames/data internally if it needs more
|
|
|
|
* frames to decide on the format, or might request us to queue here. */
|
|
|
|
if (frame->flags & GST_BASE_PARSE_FRAME_FLAG_DROP) {
|
|
|
|
gst_buffer_replace (&frame->buffer, NULL);
|
|
|
|
goto exit;
|
|
|
|
} else if (frame->flags & GST_BASE_PARSE_FRAME_FLAG_QUEUE) {
|
|
|
|
GstBaseParseFrame *copy;
|
|
|
|
|
|
|
|
copy = gst_base_parse_frame_copy (frame);
|
|
|
|
copy->flags &= ~GST_BASE_PARSE_FRAME_FLAG_QUEUE;
|
|
|
|
gst_base_parse_queue_frame (parse, copy);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gst_base_parse_handle_and_push_frame (parse, frame);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-03-31 14:50:22 +00:00
|
|
|
/* gst_base_parse_drain:
|
2008-11-13 12:59:34 +00:00
|
|
|
*
|
|
|
|
* Drains the adapter until it is empty. It decreases the min_frame_size to
|
|
|
|
* match the current adapter size and calls chain method until the adapter
|
|
|
|
* is emptied or chain returns with error.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_base_parse_drain (GstBaseParse * parse)
|
|
|
|
{
|
|
|
|
guint avail;
|
|
|
|
|
2009-08-07 11:07:17 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "draining");
|
2009-10-28 13:06:13 +00:00
|
|
|
parse->priv->drain = TRUE;
|
2009-08-07 11:07:17 +00:00
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
for (;;) {
|
2011-03-13 23:43:52 +00:00
|
|
|
avail = gst_adapter_available (parse->priv->adapter);
|
2008-11-13 12:59:34 +00:00
|
|
|
if (!avail)
|
|
|
|
break;
|
|
|
|
|
2011-11-17 11:40:45 +00:00
|
|
|
if (gst_base_parse_chain (parse->sinkpad, GST_OBJECT_CAST (parse),
|
|
|
|
NULL) != GST_FLOW_OK) {
|
2008-11-13 12:59:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-08-07 11:07:17 +00:00
|
|
|
|
|
|
|
/* nothing changed, maybe due to truncated frame; break infinite loop */
|
2011-03-13 23:43:52 +00:00
|
|
|
if (avail == gst_adapter_available (parse->priv->adapter)) {
|
2009-08-07 11:07:17 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "no change during draining; flushing");
|
2011-03-13 23:43:52 +00:00
|
|
|
gst_adapter_clear (parse->priv->adapter);
|
2009-08-07 11:07:17 +00:00
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
2009-10-28 13:06:13 +00:00
|
|
|
|
|
|
|
parse->priv->drain = FALSE;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 14:50:22 +00:00
|
|
|
/* gst_base_parse_send_buffers
|
2011-01-14 14:16:04 +00:00
|
|
|
*
|
|
|
|
* Sends buffers collected in send_buffers downstream, and ensures that list
|
|
|
|
* is empty at the end (errors or not).
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_parse_send_buffers (GstBaseParse * parse)
|
|
|
|
{
|
|
|
|
GSList *send = NULL;
|
|
|
|
GstBuffer *buf;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
|
|
|
|
send = parse->priv->buffers_send;
|
|
|
|
|
|
|
|
/* send buffers */
|
|
|
|
while (send) {
|
|
|
|
buf = GST_BUFFER_CAST (send->data);
|
2012-12-11 15:46:01 +00:00
|
|
|
GST_LOG_OBJECT (parse, "pushing buffer %p, dts %"
|
|
|
|
GST_TIME_FORMAT ", pts %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT
|
2011-01-14 14:16:04 +00:00
|
|
|
", offset %" G_GINT64_FORMAT, buf,
|
2012-12-11 15:46:01 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_DTS (buf)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_PTS (buf)),
|
2011-01-14 14:16:04 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), GST_BUFFER_OFFSET (buf));
|
|
|
|
|
|
|
|
/* iterate output queue an push downstream */
|
|
|
|
ret = gst_pad_push (parse->srcpad, buf);
|
|
|
|
send = g_slist_delete_link (send, send);
|
|
|
|
|
|
|
|
/* clear any leftover if error */
|
|
|
|
if (G_UNLIKELY (ret != GST_FLOW_OK)) {
|
|
|
|
while (send) {
|
|
|
|
buf = GST_BUFFER_CAST (send->data);
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
send = g_slist_delete_link (send, send);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parse->priv->buffers_send = send;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-02-14 18:33:46 +00:00
|
|
|
/* gst_base_parse_start_fragment:
|
|
|
|
*
|
|
|
|
* Prepares for processing a reverse playback (forward) fragment
|
|
|
|
* by (re)setting proper state variables.
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_parse_start_fragment (GstBaseParse * parse)
|
|
|
|
{
|
|
|
|
GST_LOG_OBJECT (parse, "starting fragment");
|
|
|
|
|
|
|
|
/* invalidate so no fall-back timestamping is performed;
|
|
|
|
* ok if taken from subclass or upstream */
|
2012-09-03 06:32:50 +00:00
|
|
|
parse->priv->next_pts = GST_CLOCK_TIME_NONE;
|
|
|
|
parse->priv->prev_pts = GST_CLOCK_TIME_NONE;
|
|
|
|
parse->priv->next_dts = GST_CLOCK_TIME_NONE;
|
|
|
|
parse->priv->prev_dts = GST_CLOCK_TIME_NONE;
|
2012-02-14 18:33:46 +00:00
|
|
|
/* prevent it hanging around stop all the time */
|
|
|
|
parse->segment.position = GST_CLOCK_TIME_NONE;
|
|
|
|
/* mark next run */
|
|
|
|
parse->priv->discont = TRUE;
|
|
|
|
|
|
|
|
/* head of previous fragment is now pending tail of current fragment */
|
|
|
|
parse->priv->buffers_pending = parse->priv->buffers_head;
|
|
|
|
parse->priv->buffers_head = NULL;
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* gst_base_parse_finish_fragment:
|
2010-09-29 14:12:42 +00:00
|
|
|
*
|
|
|
|
* Processes a reverse playback (forward) fragment:
|
|
|
|
* - append head of last fragment that was skipped to current fragment data
|
|
|
|
* - drain the resulting current fragment data (i.e. repeated chain)
|
|
|
|
* - add time/duration (if needed) to frames queued by chain
|
|
|
|
* - push queued data
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
2012-02-14 18:33:46 +00:00
|
|
|
gst_base_parse_finish_fragment (GstBaseParse * parse, gboolean prev_head)
|
2010-09-29 14:12:42 +00:00
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2011-01-14 14:16:04 +00:00
|
|
|
gboolean seen_key = FALSE, seen_delta = FALSE;
|
2010-09-29 14:12:42 +00:00
|
|
|
|
2012-02-14 18:33:46 +00:00
|
|
|
GST_LOG_OBJECT (parse, "finishing fragment");
|
2010-09-29 14:12:42 +00:00
|
|
|
|
|
|
|
/* restore order */
|
|
|
|
parse->priv->buffers_pending = g_slist_reverse (parse->priv->buffers_pending);
|
|
|
|
while (parse->priv->buffers_pending) {
|
|
|
|
buf = GST_BUFFER_CAST (parse->priv->buffers_pending->data);
|
2012-02-14 18:33:46 +00:00
|
|
|
if (prev_head) {
|
|
|
|
GST_LOG_OBJECT (parse, "adding pending buffer (size %" G_GSIZE_FORMAT ")",
|
|
|
|
gst_buffer_get_size (buf));
|
|
|
|
gst_adapter_push (parse->priv->adapter, buf);
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (parse, "discarding head buffer");
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
2010-09-29 14:12:42 +00:00
|
|
|
parse->priv->buffers_pending =
|
|
|
|
g_slist_delete_link (parse->priv->buffers_pending,
|
|
|
|
parse->priv->buffers_pending);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* chain looks for frames and queues resulting ones (in stead of pushing) */
|
|
|
|
/* initial skipped data is added to buffers_pending */
|
|
|
|
gst_base_parse_drain (parse);
|
|
|
|
|
2011-01-14 14:16:04 +00:00
|
|
|
if (parse->priv->buffers_send) {
|
|
|
|
buf = GST_BUFFER_CAST (parse->priv->buffers_send->data);
|
|
|
|
seen_key |= !GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
}
|
|
|
|
|
2010-09-29 14:12:42 +00:00
|
|
|
/* add metadata (if needed to queued buffers */
|
|
|
|
GST_LOG_OBJECT (parse, "last timestamp: %" GST_TIME_FORMAT,
|
2012-09-03 06:32:50 +00:00
|
|
|
GST_TIME_ARGS (parse->priv->last_pts));
|
2010-09-29 14:12:42 +00:00
|
|
|
while (parse->priv->buffers_queued) {
|
|
|
|
buf = GST_BUFFER_CAST (parse->priv->buffers_queued->data);
|
|
|
|
|
|
|
|
/* no touching if upstream or parsing provided time */
|
2012-09-03 06:32:50 +00:00
|
|
|
if (GST_BUFFER_PTS_IS_VALID (buf)) {
|
2010-09-29 14:12:42 +00:00
|
|
|
GST_LOG_OBJECT (parse, "buffer has time %" GST_TIME_FORMAT,
|
2012-09-03 06:32:50 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_PTS (buf)));
|
|
|
|
} else if (GST_BUFFER_DURATION_IS_VALID (buf)) {
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (parse->priv->last_pts)) {
|
|
|
|
if (G_LIKELY (GST_BUFFER_DURATION (buf) <= parse->priv->last_pts))
|
|
|
|
parse->priv->last_pts -= GST_BUFFER_DURATION (buf);
|
|
|
|
else
|
|
|
|
parse->priv->last_pts = 0;
|
|
|
|
GST_BUFFER_PTS (buf) = parse->priv->last_pts;
|
|
|
|
GST_LOG_OBJECT (parse, "applied time %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_PTS (buf)));
|
|
|
|
}
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (parse->priv->last_dts)) {
|
|
|
|
if (G_LIKELY (GST_BUFFER_DURATION (buf) <= parse->priv->last_dts))
|
|
|
|
parse->priv->last_dts -= GST_BUFFER_DURATION (buf);
|
|
|
|
else
|
|
|
|
parse->priv->last_dts = 0;
|
|
|
|
GST_BUFFER_DTS (buf) = parse->priv->last_dts;
|
|
|
|
GST_LOG_OBJECT (parse, "applied dts %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DTS (buf)));
|
|
|
|
}
|
2010-09-29 14:12:42 +00:00
|
|
|
} else {
|
|
|
|
/* no idea, very bad */
|
|
|
|
GST_WARNING_OBJECT (parse, "could not determine time for buffer");
|
|
|
|
}
|
|
|
|
|
2012-09-03 06:32:50 +00:00
|
|
|
parse->priv->last_pts = GST_BUFFER_PTS (buf);
|
|
|
|
parse->priv->last_dts = GST_BUFFER_DTS (buf);
|
2011-01-14 14:16:04 +00:00
|
|
|
|
2010-09-29 14:12:42 +00:00
|
|
|
/* reverse order for ascending sending */
|
2011-01-14 14:16:04 +00:00
|
|
|
/* send downstream at keyframe not preceded by a keyframe
|
|
|
|
* (e.g. that should identify start of collection of IDR nals) */
|
|
|
|
if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT)) {
|
|
|
|
if (seen_key) {
|
|
|
|
ret = gst_base_parse_send_buffers (parse);
|
|
|
|
/* if a problem, throw all to sending */
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
parse->priv->buffers_send =
|
|
|
|
g_slist_reverse (parse->priv->buffers_queued);
|
|
|
|
parse->priv->buffers_queued = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
seen_key = FALSE;
|
|
|
|
}
|
|
|
|
seen_delta = TRUE;
|
2012-02-13 17:09:51 +00:00
|
|
|
} else {
|
|
|
|
seen_key = TRUE;
|
2011-01-14 14:16:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parse->priv->buffers_send =
|
|
|
|
g_slist_prepend (parse->priv->buffers_send, buf);
|
2010-09-29 14:12:42 +00:00
|
|
|
parse->priv->buffers_queued =
|
|
|
|
g_slist_delete_link (parse->priv->buffers_queued,
|
|
|
|
parse->priv->buffers_queued);
|
|
|
|
}
|
|
|
|
|
2011-01-14 14:16:04 +00:00
|
|
|
/* audio may have all marked as keyframe, so arrange to send here */
|
|
|
|
if (!seen_delta)
|
|
|
|
ret = gst_base_parse_send_buffers (parse);
|
2010-09-29 14:12:42 +00:00
|
|
|
|
|
|
|
/* any trailing unused no longer usable (ideally none) */
|
2011-03-13 23:43:52 +00:00
|
|
|
if (G_UNLIKELY (gst_adapter_available (parse->priv->adapter))) {
|
2011-08-10 09:01:58 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "discarding %" G_GSIZE_FORMAT " trailing bytes",
|
2011-03-13 23:43:52 +00:00
|
|
|
gst_adapter_available (parse->priv->adapter));
|
|
|
|
gst_adapter_clear (parse->priv->adapter);
|
2010-09-29 14:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-20 14:39:37 +00:00
|
|
|
/* small helper that checks whether we have been trying to resync too long */
|
|
|
|
static inline GstFlowReturn
|
|
|
|
gst_base_parse_check_sync (GstBaseParse * parse)
|
|
|
|
{
|
|
|
|
if (G_UNLIKELY (parse->priv->discont &&
|
|
|
|
parse->priv->offset - parse->priv->sync_offset > 2 * 1024 * 1024)) {
|
|
|
|
GST_ELEMENT_ERROR (parse, STREAM, DECODE,
|
|
|
|
("Failed to parse stream"), (NULL));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
static GstFlowReturn
|
2011-11-17 11:40:45 +00:00
|
|
|
gst_base_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
|
|
|
GstBaseParseClass *bclass;
|
|
|
|
GstBaseParse *parse;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
GstBuffer *tmpbuf = NULL;
|
2011-01-12 13:40:37 +00:00
|
|
|
guint fsize = 1;
|
2008-11-13 12:59:34 +00:00
|
|
|
gint skip = -1;
|
|
|
|
const guint8 *data;
|
2012-02-13 17:22:37 +00:00
|
|
|
guint min_size, av;
|
2012-09-03 06:32:50 +00:00
|
|
|
GstClockTime pts, dts;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-11-17 11:40:45 +00:00
|
|
|
parse = GST_BASE_PARSE (parent);
|
2008-11-13 12:59:34 +00:00
|
|
|
bclass = GST_BASE_PARSE_GET_CLASS (parse);
|
2011-10-20 06:31:18 +00:00
|
|
|
|
|
|
|
if (parse->priv->detecting) {
|
|
|
|
GstBuffer *detect_buf;
|
|
|
|
|
|
|
|
if (parse->priv->detect_buffers_size == 0) {
|
|
|
|
detect_buf = gst_buffer_ref (buffer);
|
|
|
|
} else {
|
|
|
|
GList *l;
|
|
|
|
guint offset = 0;
|
|
|
|
|
2011-10-21 08:52:46 +00:00
|
|
|
detect_buf = gst_buffer_new ();
|
|
|
|
|
2011-10-20 06:31:18 +00:00
|
|
|
for (l = parse->priv->detect_buffers; l; l = l->next) {
|
2011-10-21 08:52:46 +00:00
|
|
|
gsize tmpsize = gst_buffer_get_size (l->data);
|
|
|
|
|
|
|
|
gst_buffer_copy_into (detect_buf, GST_BUFFER_CAST (l->data),
|
|
|
|
GST_BUFFER_COPY_MEMORY, offset, tmpsize);
|
|
|
|
offset += tmpsize;
|
2011-10-20 06:31:18 +00:00
|
|
|
}
|
|
|
|
if (buffer)
|
2011-10-21 08:52:46 +00:00
|
|
|
gst_buffer_copy_into (detect_buf, buffer, GST_BUFFER_COPY_MEMORY,
|
|
|
|
offset, gst_buffer_get_size (buffer));
|
2011-10-20 06:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = bclass->detect (parse, detect_buf);
|
|
|
|
gst_buffer_unref (detect_buf);
|
|
|
|
|
|
|
|
if (ret == GST_FLOW_OK) {
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
/* Detected something */
|
|
|
|
parse->priv->detecting = FALSE;
|
|
|
|
|
|
|
|
for (l = parse->priv->detect_buffers; l; l = l->next) {
|
|
|
|
if (ret == GST_FLOW_OK && !parse->priv->flushing)
|
|
|
|
ret =
|
|
|
|
gst_base_parse_chain (GST_BASE_PARSE_SINK_PAD (parse),
|
2011-11-17 11:40:45 +00:00
|
|
|
parent, GST_BUFFER_CAST (l->data));
|
2011-10-20 06:31:18 +00:00
|
|
|
else
|
|
|
|
gst_buffer_unref (GST_BUFFER_CAST (l->data));
|
|
|
|
}
|
|
|
|
g_list_free (parse->priv->detect_buffers);
|
|
|
|
parse->priv->detect_buffers = NULL;
|
|
|
|
parse->priv->detect_buffers_size = 0;
|
|
|
|
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle the current buffer */
|
|
|
|
} else if (ret == GST_FLOW_NOT_NEGOTIATED) {
|
|
|
|
/* Still detecting, append buffer or error out if draining */
|
|
|
|
|
|
|
|
if (parse->priv->drain) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "Draining but did not detect format yet");
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
} else if (parse->priv->flushing) {
|
|
|
|
g_list_foreach (parse->priv->detect_buffers, (GFunc) gst_buffer_unref,
|
|
|
|
NULL);
|
|
|
|
g_list_free (parse->priv->detect_buffers);
|
|
|
|
parse->priv->detect_buffers = NULL;
|
|
|
|
parse->priv->detect_buffers_size = 0;
|
|
|
|
} else {
|
|
|
|
parse->priv->detect_buffers =
|
|
|
|
g_list_append (parse->priv->detect_buffers, buffer);
|
2011-10-21 08:52:46 +00:00
|
|
|
parse->priv->detect_buffers_size += gst_buffer_get_size (buffer);
|
2011-10-20 06:31:18 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Something went wrong, subclass responsible for error reporting */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And now handle the current buffer if detection worked */
|
|
|
|
}
|
|
|
|
|
2009-02-27 09:24:37 +00:00
|
|
|
if (G_LIKELY (buffer)) {
|
2011-08-10 09:01:58 +00:00
|
|
|
GST_LOG_OBJECT (parse,
|
2012-12-11 15:46:01 +00:00
|
|
|
"buffer size: %" G_GSIZE_FORMAT ", offset = %" G_GINT64_FORMAT
|
|
|
|
", dts %" GST_TIME_FORMAT ", pts %" GST_TIME_FORMAT,
|
|
|
|
gst_buffer_get_size (buffer), GST_BUFFER_OFFSET (buffer),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DTS (buffer)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_PTS (buffer)));
|
|
|
|
|
2013-08-07 16:24:40 +00:00
|
|
|
if (G_UNLIKELY (!parse->priv->disable_passthrough
|
|
|
|
&& parse->priv->passthrough)) {
|
2012-02-13 17:22:37 +00:00
|
|
|
GstBaseParseFrame frame;
|
|
|
|
|
|
|
|
gst_base_parse_frame_init (&frame);
|
|
|
|
frame.buffer = gst_buffer_make_writable (buffer);
|
|
|
|
ret = gst_base_parse_push_frame (parse, &frame);
|
|
|
|
gst_base_parse_frame_free (&frame);
|
|
|
|
return ret;
|
2010-09-29 14:12:42 +00:00
|
|
|
}
|
|
|
|
/* upstream feeding us in reverse playback;
|
2012-02-14 18:33:46 +00:00
|
|
|
* finish previous fragment and start new upon DISCONT */
|
2010-09-29 14:12:42 +00:00
|
|
|
if (parse->segment.rate < 0.0) {
|
|
|
|
if (G_UNLIKELY (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT))) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "buffer starts new reverse playback fragment");
|
2012-02-14 18:33:46 +00:00
|
|
|
ret = gst_base_parse_finish_fragment (parse, TRUE);
|
|
|
|
gst_base_parse_start_fragment (parse);
|
2010-09-29 14:12:42 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-13 23:43:52 +00:00
|
|
|
gst_adapter_push (parse->priv->adapter, buffer);
|
2009-02-27 09:24:37 +00:00
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
/* Parse and push as many frames as possible */
|
|
|
|
/* Stop either when adapter is empty or we are flushing */
|
|
|
|
while (!parse->priv->flushing) {
|
2012-02-13 17:22:37 +00:00
|
|
|
gint flush = 0;
|
2011-05-17 20:17:14 +00:00
|
|
|
|
2012-02-14 18:33:50 +00:00
|
|
|
/* note: if subclass indicates MAX fsize,
|
|
|
|
* this will not likely be available anyway ... */
|
|
|
|
min_size = MAX (parse->priv->min_frame_size, fsize);
|
|
|
|
av = gst_adapter_available (parse->priv->adapter);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (parse->priv->drain)) {
|
|
|
|
min_size = av;
|
|
|
|
GST_DEBUG_OBJECT (parse, "draining, data left: %d", min_size);
|
|
|
|
if (G_UNLIKELY (!min_size)) {
|
2008-11-13 12:59:34 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2012-02-14 18:33:50 +00:00
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2012-02-14 18:33:50 +00:00
|
|
|
/* Collect at least min_frame_size bytes */
|
|
|
|
if (av < min_size) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "not enough data available (only %d bytes)", av);
|
|
|
|
goto done;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
2012-02-14 18:33:50 +00:00
|
|
|
/* move along with upstream timestamp (if any),
|
|
|
|
* but interpolate in between */
|
2012-09-03 06:32:50 +00:00
|
|
|
pts = gst_adapter_prev_pts (parse->priv->adapter, NULL);
|
|
|
|
dts = gst_adapter_prev_dts (parse->priv->adapter, NULL);
|
2012-12-13 12:47:29 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (pts) && (parse->priv->prev_pts != pts))
|
2012-09-03 06:32:50 +00:00
|
|
|
parse->priv->prev_pts = parse->priv->next_pts = pts;
|
2012-12-13 12:47:29 +00:00
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (dts) && (parse->priv->prev_dts != dts))
|
2012-09-03 06:32:50 +00:00
|
|
|
parse->priv->prev_dts = parse->priv->next_dts = dts;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2013-02-26 18:58:49 +00:00
|
|
|
/* we can mess with, erm interpolate, timestamps,
|
|
|
|
* and incoming stuff has PTS but no DTS seen so far,
|
|
|
|
* then pick up DTS from PTS and hope for the best ... */
|
|
|
|
if (parse->priv->infer_ts &&
|
2013-04-23 09:47:54 +00:00
|
|
|
parse->priv->pts_interpolate &&
|
2013-02-26 18:58:49 +00:00
|
|
|
!GST_CLOCK_TIME_IS_VALID (dts) &&
|
|
|
|
!GST_CLOCK_TIME_IS_VALID (parse->priv->prev_dts) &&
|
|
|
|
GST_CLOCK_TIME_IS_VALID (pts))
|
|
|
|
parse->priv->next_dts = pts;
|
|
|
|
|
2012-02-14 18:33:50 +00:00
|
|
|
/* always pass all available data */
|
|
|
|
data = gst_adapter_map (parse->priv->adapter, av);
|
|
|
|
/* arrange for actual data to be copied if subclass tries to,
|
|
|
|
* since what is passed is tied to the adapter */
|
2012-03-20 16:08:28 +00:00
|
|
|
tmpbuf = gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY |
|
|
|
|
GST_MEMORY_FLAG_NO_SHARE, (gpointer) data, av, 0, av, NULL, NULL);
|
2012-02-14 18:33:50 +00:00
|
|
|
|
|
|
|
/* keep the adapter mapped, so keep track of what has to be flushed */
|
|
|
|
ret = gst_base_parse_handle_buffer (parse, tmpbuf, &skip, &flush);
|
|
|
|
tmpbuf = NULL;
|
|
|
|
|
|
|
|
/* probably already implicitly unmapped due to adapter operation,
|
|
|
|
* but for good measure ... */
|
|
|
|
gst_adapter_unmap (parse->priv->adapter);
|
2012-04-02 13:13:24 +00:00
|
|
|
if (ret != GST_FLOW_OK && ret != GST_FLOW_NOT_LINKED) {
|
2012-02-14 18:33:50 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (skip == 0 && flush == 0) {
|
|
|
|
GST_LOG_OBJECT (parse, "nothing skipped and no frames finished, "
|
|
|
|
"breaking to get more data");
|
|
|
|
goto done;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
GST_LOG_OBJECT (parse, "chain leaving");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-18 20:02:40 +00:00
|
|
|
/* pull @size bytes at current offset,
|
|
|
|
* i.e. at least try to and possibly return a shorter buffer if near the end */
|
2008-11-13 12:59:34 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_parse_pull_range (GstBaseParse * parse, guint size,
|
|
|
|
GstBuffer ** buffer)
|
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
|
|
|
|
g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
|
|
|
|
|
|
|
|
/* Caching here actually makes much less difference than one would expect.
|
|
|
|
* We do it mainly to avoid pulling buffers of 1 byte all the time */
|
|
|
|
if (parse->priv->cache) {
|
2010-06-15 13:33:37 +00:00
|
|
|
gint64 cache_offset = GST_BUFFER_OFFSET (parse->priv->cache);
|
2011-04-11 08:53:39 +00:00
|
|
|
gint cache_size = gst_buffer_get_size (parse->priv->cache);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
if (cache_offset <= parse->priv->offset &&
|
2009-12-18 12:30:07 +00:00
|
|
|
(parse->priv->offset + size) <= (cache_offset + cache_size)) {
|
2011-04-11 08:53:39 +00:00
|
|
|
*buffer = gst_buffer_copy_region (parse->priv->cache, GST_BUFFER_COPY_ALL,
|
2008-11-13 12:59:34 +00:00
|
|
|
parse->priv->offset - cache_offset, size);
|
|
|
|
GST_BUFFER_OFFSET (*buffer) = parse->priv->offset;
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
/* not enough data in the cache, free cache and get a new one */
|
|
|
|
gst_buffer_unref (parse->priv->cache);
|
|
|
|
parse->priv->cache = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* refill the cache */
|
|
|
|
ret =
|
|
|
|
gst_pad_pull_range (parse->sinkpad, parse->priv->offset, MAX (size,
|
|
|
|
64 * 1024), &parse->priv->cache);
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
parse->priv->cache = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-11 08:53:39 +00:00
|
|
|
if (gst_buffer_get_size (parse->priv->cache) >= size) {
|
|
|
|
*buffer =
|
|
|
|
gst_buffer_copy_region (parse->priv->cache, GST_BUFFER_COPY_ALL, 0,
|
|
|
|
size);
|
2008-11-13 12:59:34 +00:00
|
|
|
GST_BUFFER_OFFSET (*buffer) = parse->priv->offset;
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not possible to get enough data, try a last time with
|
|
|
|
* requesting exactly the size we need */
|
|
|
|
gst_buffer_unref (parse->priv->cache);
|
|
|
|
parse->priv->cache = NULL;
|
|
|
|
|
|
|
|
ret = gst_pad_pull_range (parse->sinkpad, parse->priv->offset, size,
|
|
|
|
&parse->priv->cache);
|
|
|
|
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "pull_range returned %d", ret);
|
|
|
|
*buffer = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-11 08:53:39 +00:00
|
|
|
if (gst_buffer_get_size (parse->priv->cache) < size) {
|
2009-12-18 20:02:40 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "Returning short buffer at offset %"
|
2011-08-10 09:01:58 +00:00
|
|
|
G_GUINT64_FORMAT ": wanted %u bytes, got %" G_GSIZE_FORMAT " bytes",
|
|
|
|
parse->priv->offset, size, gst_buffer_get_size (parse->priv->cache));
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2009-12-18 20:02:40 +00:00
|
|
|
*buffer = parse->priv->cache;
|
2008-11-13 12:59:34 +00:00
|
|
|
parse->priv->cache = NULL;
|
|
|
|
|
2009-12-18 20:02:40 +00:00
|
|
|
return GST_FLOW_OK;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
2011-04-11 08:53:39 +00:00
|
|
|
*buffer =
|
|
|
|
gst_buffer_copy_region (parse->priv->cache, GST_BUFFER_COPY_ALL, 0, size);
|
2008-11-13 12:59:34 +00:00
|
|
|
GST_BUFFER_OFFSET (*buffer) = parse->priv->offset;
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-29 14:12:42 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_parse_handle_previous_fragment (GstBaseParse * parse)
|
|
|
|
{
|
|
|
|
gint64 offset = 0;
|
|
|
|
GstClockTime ts = 0;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstFlowReturn ret;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "fragment ended; last_ts = %" GST_TIME_FORMAT
|
2012-09-03 06:32:50 +00:00
|
|
|
", last_offset = %" G_GINT64_FORMAT,
|
|
|
|
GST_TIME_ARGS (parse->priv->last_pts), parse->priv->last_offset);
|
2010-09-29 14:12:42 +00:00
|
|
|
|
2012-09-03 06:32:50 +00:00
|
|
|
if (!parse->priv->last_offset
|
|
|
|
|| parse->priv->last_pts <= parse->segment.start) {
|
2010-09-29 14:12:42 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "past start of segment %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (parse->segment.start));
|
2011-10-10 09:33:51 +00:00
|
|
|
ret = GST_FLOW_EOS;
|
2010-09-29 14:12:42 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* last fragment started at last_offset / last_ts;
|
|
|
|
* seek back 10s capped at 1MB */
|
2012-09-03 06:32:50 +00:00
|
|
|
if (parse->priv->last_pts >= 10 * GST_SECOND)
|
|
|
|
ts = parse->priv->last_pts - 10 * GST_SECOND;
|
2010-09-29 14:12:42 +00:00
|
|
|
/* if we are exact now, we will be more so going backwards */
|
|
|
|
if (parse->priv->exact_position) {
|
|
|
|
offset = gst_base_parse_find_offset (parse, ts, TRUE, NULL);
|
|
|
|
} else {
|
2012-03-20 16:08:28 +00:00
|
|
|
if (!gst_base_parse_convert (parse, GST_FORMAT_TIME, ts,
|
2011-07-26 23:26:43 +00:00
|
|
|
GST_FORMAT_BYTES, &offset)) {
|
2010-09-29 14:12:42 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "conversion failed, only BYTE based");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
offset = CLAMP (offset, parse->priv->last_offset - 1024 * 1024,
|
|
|
|
parse->priv->last_offset - 1024);
|
|
|
|
offset = MAX (0, offset);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "next fragment from offset %" G_GINT64_FORMAT,
|
|
|
|
offset);
|
|
|
|
parse->priv->offset = offset;
|
|
|
|
|
|
|
|
ret = gst_base_parse_pull_range (parse, parse->priv->last_offset - offset,
|
|
|
|
&buffer);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto exit;
|
|
|
|
|
2010-12-10 14:59:49 +00:00
|
|
|
/* offset will increase again as fragment is processed/parsed */
|
|
|
|
parse->priv->last_offset = offset;
|
|
|
|
|
2012-02-14 18:33:46 +00:00
|
|
|
gst_base_parse_start_fragment (parse);
|
2011-03-13 23:43:52 +00:00
|
|
|
gst_adapter_push (parse->priv->adapter, buffer);
|
2012-02-14 18:33:46 +00:00
|
|
|
ret = gst_base_parse_finish_fragment (parse, TRUE);
|
2010-09-29 14:12:42 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto exit;
|
|
|
|
|
2010-12-10 14:59:49 +00:00
|
|
|
/* force previous fragment */
|
|
|
|
parse->priv->offset = -1;
|
|
|
|
|
2010-09-29 14:12:42 +00:00
|
|
|
exit:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-16 16:06:14 +00:00
|
|
|
/* PULL mode:
|
|
|
|
* pull and scan for next frame starting from current offset
|
|
|
|
* ajusts sync, drain and offset going along */
|
|
|
|
static GstFlowReturn
|
2012-07-24 11:48:39 +00:00
|
|
|
gst_base_parse_scan_frame (GstBaseParse * parse, GstBaseParseClass * klass)
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
2012-02-14 18:33:46 +00:00
|
|
|
GstBuffer *buffer;
|
2010-11-16 16:06:14 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2012-02-13 17:22:37 +00:00
|
|
|
guint fsize, min_size;
|
|
|
|
gint flushed = 0;
|
2008-11-13 12:59:34 +00:00
|
|
|
gint skip = 0;
|
|
|
|
|
2011-01-07 14:58:49 +00:00
|
|
|
GST_LOG_OBJECT (parse, "scanning for frame at offset %" G_GUINT64_FORMAT
|
|
|
|
" (%#" G_GINT64_MODIFIER "x)", parse->priv->offset, parse->priv->offset);
|
|
|
|
|
2011-05-17 20:15:38 +00:00
|
|
|
/* let's make this efficient for all subclass once and for all;
|
|
|
|
* maybe it does not need this much, but in the latter case, we know we are
|
|
|
|
* in pull mode here and might as well try to read and supply more anyway
|
|
|
|
* (so does the buffer caching mechanism) */
|
|
|
|
fsize = 64 * 1024;
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
while (TRUE) {
|
2011-01-06 10:41:44 +00:00
|
|
|
min_size = MAX (parse->priv->min_frame_size, fsize);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2012-02-14 18:33:46 +00:00
|
|
|
GST_LOG_OBJECT (parse, "reading buffer size %u", min_size);
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
ret = gst_base_parse_pull_range (parse, min_size, &buffer);
|
2010-09-29 14:12:42 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto done;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2009-12-18 20:02:40 +00:00
|
|
|
/* if we got a short read, inform subclass we are draining leftover
|
|
|
|
* and no more is to be expected */
|
2012-02-14 18:33:46 +00:00
|
|
|
if (gst_buffer_get_size (buffer) < min_size) {
|
|
|
|
GST_LOG_OBJECT (parse, "... but did not get that; marked draining");
|
2009-12-18 20:02:40 +00:00
|
|
|
parse->priv->drain = TRUE;
|
2012-02-14 18:33:46 +00:00
|
|
|
}
|
2009-12-18 20:02:40 +00:00
|
|
|
|
2011-10-20 06:31:18 +00:00
|
|
|
if (parse->priv->detecting) {
|
|
|
|
ret = klass->detect (parse, buffer);
|
|
|
|
if (ret == GST_FLOW_NOT_NEGOTIATED) {
|
|
|
|
/* If draining we error out, otherwise request a buffer
|
|
|
|
* with 64kb more */
|
|
|
|
if (parse->priv->drain) {
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
GST_ERROR_OBJECT (parse, "Failed to detect format but draining");
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
} else {
|
|
|
|
fsize += 64 * 1024;
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if (ret != GST_FLOW_OK) {
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
GST_ERROR_OBJECT (parse, "detect() returned %s",
|
|
|
|
gst_flow_get_name (ret));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Else handle this buffer normally */
|
|
|
|
}
|
|
|
|
|
2012-02-13 17:22:37 +00:00
|
|
|
ret = gst_base_parse_handle_buffer (parse, buffer, &skip, &flushed);
|
|
|
|
if (ret != GST_FLOW_OK)
|
2008-11-13 12:59:34 +00:00
|
|
|
break;
|
2012-02-13 17:22:37 +00:00
|
|
|
|
2012-02-14 18:33:46 +00:00
|
|
|
/* something flushed means something happened,
|
2012-02-13 17:22:37 +00:00
|
|
|
* and we should bail out of this loop so as not to occupy
|
|
|
|
* the task thread indefinitely */
|
|
|
|
if (flushed) {
|
|
|
|
GST_LOG_OBJECT (parse, "frame finished, breaking loop");
|
|
|
|
break;
|
2010-09-20 14:39:37 +00:00
|
|
|
}
|
2012-02-13 17:22:37 +00:00
|
|
|
/* nothing flushed, no skip and draining, so nothing left to do */
|
|
|
|
if (!skip && parse->priv->drain) {
|
|
|
|
GST_LOG_OBJECT (parse, "no activity or result when draining; "
|
|
|
|
"breaking loop and marking EOS");
|
2011-10-10 09:33:51 +00:00
|
|
|
ret = GST_FLOW_EOS;
|
2012-02-13 17:22:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-02-14 18:33:46 +00:00
|
|
|
/* otherwise, get some more data
|
|
|
|
* note that is checked this does not happen indefinitely */
|
|
|
|
if (!skip) {
|
|
|
|
GST_LOG_OBJECT (parse, "getting some more data");
|
|
|
|
fsize += 64 * 1024;
|
2010-11-16 16:06:14 +00:00
|
|
|
}
|
2012-02-14 18:33:46 +00:00
|
|
|
parse->priv->drain = FALSE;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 16:06:14 +00:00
|
|
|
done:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 14:50:22 +00:00
|
|
|
/* Loop that is used in pull mode to retrieve data from upstream */
|
2010-11-16 16:06:14 +00:00
|
|
|
static void
|
|
|
|
gst_base_parse_loop (GstPad * pad)
|
|
|
|
{
|
|
|
|
GstBaseParse *parse;
|
|
|
|
GstBaseParseClass *klass;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
|
|
|
|
parse = GST_BASE_PARSE (gst_pad_get_parent (pad));
|
|
|
|
klass = GST_BASE_PARSE_GET_CLASS (parse);
|
|
|
|
|
2012-09-26 05:01:42 +00:00
|
|
|
GST_LOG_OBJECT (parse, "Entering parse loop");
|
2012-07-11 08:26:13 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (parse->priv->push_stream_start)) {
|
2012-07-29 12:25:34 +00:00
|
|
|
gchar *stream_id;
|
2013-07-22 10:06:08 +00:00
|
|
|
GstEvent *event;
|
2012-07-29 12:25:34 +00:00
|
|
|
|
|
|
|
stream_id =
|
|
|
|
gst_pad_create_stream_id (parse->srcpad, GST_ELEMENT_CAST (parse),
|
|
|
|
NULL);
|
|
|
|
|
2013-07-22 10:06:08 +00:00
|
|
|
event = gst_event_new_stream_start (stream_id);
|
|
|
|
gst_event_set_group_id (event, gst_util_group_id_next ());
|
|
|
|
|
2012-07-11 08:26:13 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "Pushing STREAM_START");
|
2013-07-22 10:06:08 +00:00
|
|
|
gst_pad_push_event (parse->srcpad, event);
|
2012-07-11 08:26:13 +00:00
|
|
|
parse->priv->push_stream_start = FALSE;
|
2012-07-29 12:25:34 +00:00
|
|
|
g_free (stream_id);
|
2012-07-11 08:26:13 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 16:06:14 +00:00
|
|
|
/* reverse playback:
|
|
|
|
* first fragment (closest to stop time) is handled normally below,
|
|
|
|
* then we pull in fragments going backwards */
|
|
|
|
if (parse->segment.rate < 0.0) {
|
2010-12-10 14:59:49 +00:00
|
|
|
/* check if we jumped back to a previous fragment,
|
|
|
|
* which is a post-first fragment */
|
|
|
|
if (parse->priv->offset < 0) {
|
2010-11-16 16:06:14 +00:00
|
|
|
ret = gst_base_parse_handle_previous_fragment (parse);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-24 11:48:39 +00:00
|
|
|
ret = gst_base_parse_scan_frame (parse, klass);
|
2010-11-16 16:06:14 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto done;
|
|
|
|
|
2010-09-29 14:12:42 +00:00
|
|
|
/* eat expected eos signalling past segment in reverse playback */
|
2011-10-10 09:33:51 +00:00
|
|
|
if (parse->segment.rate < 0.0 && ret == GST_FLOW_EOS &&
|
2011-05-13 16:07:24 +00:00
|
|
|
parse->segment.position >= parse->segment.stop) {
|
2010-09-29 14:12:42 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "downstream has reached end of segment");
|
|
|
|
/* push what was accumulated during loop run */
|
2012-02-14 18:33:46 +00:00
|
|
|
gst_base_parse_finish_fragment (parse, FALSE);
|
2010-12-10 14:59:49 +00:00
|
|
|
/* force previous fragment */
|
|
|
|
parse->priv->offset = -1;
|
2010-09-29 14:12:42 +00:00
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-20 14:39:37 +00:00
|
|
|
done:
|
2011-10-10 09:33:51 +00:00
|
|
|
if (ret == GST_FLOW_EOS)
|
2010-09-29 14:12:42 +00:00
|
|
|
goto eos;
|
|
|
|
else if (ret != GST_FLOW_OK)
|
|
|
|
goto pause;
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
gst_object_unref (parse);
|
|
|
|
return;
|
|
|
|
|
2010-09-21 11:57:10 +00:00
|
|
|
/* ERRORS */
|
|
|
|
eos:
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
2011-10-10 09:33:51 +00:00
|
|
|
ret = GST_FLOW_EOS;
|
2010-09-21 11:57:10 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "eos");
|
|
|
|
/* fall-through */
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
2010-09-21 11:57:10 +00:00
|
|
|
pause:
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
2010-09-21 11:57:10 +00:00
|
|
|
gboolean push_eos = FALSE;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "pausing task, reason %s",
|
|
|
|
gst_flow_get_name (ret));
|
|
|
|
gst_pad_pause_task (parse->sinkpad);
|
|
|
|
|
2011-10-10 09:33:51 +00:00
|
|
|
if (ret == GST_FLOW_EOS) {
|
2010-09-21 11:57:10 +00:00
|
|
|
/* handle end-of-stream/segment */
|
2012-07-09 20:51:07 +00:00
|
|
|
if (parse->segment.flags & GST_SEGMENT_FLAG_SEGMENT) {
|
2010-09-21 11:57:10 +00:00
|
|
|
gint64 stop;
|
|
|
|
|
|
|
|
if ((stop = parse->segment.stop) == -1)
|
|
|
|
stop = parse->segment.duration;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "sending segment_done");
|
|
|
|
|
|
|
|
gst_element_post_message
|
|
|
|
(GST_ELEMENT_CAST (parse),
|
|
|
|
gst_message_new_segment_done (GST_OBJECT_CAST (parse),
|
|
|
|
GST_FORMAT_TIME, stop));
|
2012-07-05 11:03:10 +00:00
|
|
|
gst_pad_push_event (parse->srcpad,
|
|
|
|
gst_event_new_segment_done (GST_FORMAT_TIME, stop));
|
2010-09-21 11:57:10 +00:00
|
|
|
} else {
|
|
|
|
/* If we STILL have zero frames processed, fire an error */
|
|
|
|
if (parse->priv->framecount == 0) {
|
|
|
|
GST_ELEMENT_ERROR (parse, STREAM, WRONG_TYPE,
|
|
|
|
("No valid frames found before end of stream"), (NULL));
|
|
|
|
}
|
|
|
|
push_eos = TRUE;
|
|
|
|
}
|
2011-10-10 09:33:51 +00:00
|
|
|
} else if (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_EOS) {
|
2010-09-21 11:57:10 +00:00
|
|
|
/* for fatal errors we post an error message, wrong-state is
|
|
|
|
* not fatal because it happens due to flushes and only means
|
|
|
|
* that we should stop now. */
|
|
|
|
GST_ELEMENT_ERROR (parse, STREAM, FAILED, (NULL),
|
|
|
|
("streaming stopped, reason %s", gst_flow_get_name (ret)));
|
|
|
|
push_eos = TRUE;
|
|
|
|
}
|
|
|
|
if (push_eos) {
|
2012-12-14 14:22:27 +00:00
|
|
|
/* Push pending events, including SEGMENT events */
|
2012-03-05 13:41:12 +00:00
|
|
|
if (G_UNLIKELY (parse->priv->pending_events)) {
|
2012-09-03 17:30:08 +00:00
|
|
|
GList *r = g_list_reverse (parse->priv->pending_events);
|
2012-03-05 13:41:12 +00:00
|
|
|
GList *l;
|
|
|
|
|
2012-09-03 17:30:08 +00:00
|
|
|
parse->priv->pending_events = NULL;
|
|
|
|
for (l = r; l != NULL; l = l->next) {
|
2012-03-05 13:41:12 +00:00
|
|
|
gst_pad_push_event (parse->srcpad, GST_EVENT (l->data));
|
|
|
|
}
|
2012-09-03 17:30:08 +00:00
|
|
|
g_list_free (r);
|
2012-03-05 13:41:12 +00:00
|
|
|
parse->priv->pending_segment = FALSE;
|
2010-09-21 11:57:10 +00:00
|
|
|
}
|
2012-03-05 13:41:12 +00:00
|
|
|
|
2010-09-21 11:57:10 +00:00
|
|
|
gst_pad_push_event (parse->srcpad, gst_event_new_eos ());
|
|
|
|
}
|
|
|
|
gst_object_unref (parse);
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-18 12:46:46 +00:00
|
|
|
gst_base_parse_sink_activate (GstPad * sinkpad, GstObject * parent)
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
2012-09-10 20:39:32 +00:00
|
|
|
GstSchedulingFlags sched_flags;
|
2008-11-13 12:59:34 +00:00
|
|
|
GstBaseParse *parse;
|
2011-05-24 15:36:24 +00:00
|
|
|
GstQuery *query;
|
|
|
|
gboolean pull_mode;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-11-18 12:46:46 +00:00
|
|
|
parse = GST_BASE_PARSE (parent);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "sink activate");
|
|
|
|
|
2011-05-24 15:36:24 +00:00
|
|
|
query = gst_query_new_scheduling ();
|
2012-02-15 11:19:13 +00:00
|
|
|
if (!gst_pad_peer_query (sinkpad, query)) {
|
|
|
|
gst_query_unref (query);
|
|
|
|
goto baseparse_push;
|
2011-05-24 15:36:24 +00:00
|
|
|
}
|
2012-02-15 11:19:13 +00:00
|
|
|
|
2012-09-10 20:39:32 +00:00
|
|
|
gst_query_parse_scheduling (query, &sched_flags, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
pull_mode = gst_query_has_scheduling_mode (query, GST_PAD_MODE_PULL)
|
|
|
|
&& ((sched_flags & GST_SCHEDULING_FLAG_SEEKABLE) != 0);
|
|
|
|
|
2011-05-24 15:36:24 +00:00
|
|
|
gst_query_unref (query);
|
|
|
|
|
2012-02-15 11:19:13 +00:00
|
|
|
if (!pull_mode)
|
|
|
|
goto baseparse_push;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "trying to activate in pull mode");
|
|
|
|
if (!gst_pad_activate_mode (sinkpad, GST_PAD_MODE_PULL, TRUE))
|
|
|
|
goto baseparse_push;
|
|
|
|
|
2012-07-11 08:26:13 +00:00
|
|
|
parse->priv->push_stream_start = TRUE;
|
|
|
|
|
2012-02-15 11:19:13 +00:00
|
|
|
return gst_pad_start_task (sinkpad, (GstTaskFunction) gst_base_parse_loop,
|
2012-06-20 08:31:49 +00:00
|
|
|
sinkpad, NULL);
|
2012-02-15 11:19:13 +00:00
|
|
|
/* fallback */
|
|
|
|
baseparse_push:
|
|
|
|
{
|
2008-11-13 12:59:34 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "trying to activate in push mode");
|
2012-02-15 11:19:13 +00:00
|
|
|
return gst_pad_activate_mode (sinkpad, GST_PAD_MODE_PUSH, TRUE);
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_base_parse_activate (GstBaseParse * parse, gboolean active)
|
|
|
|
{
|
|
|
|
GstBaseParseClass *klass;
|
2011-09-26 10:36:46 +00:00
|
|
|
gboolean result = TRUE;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-01-11 14:24:23 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "activate %d", active);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
klass = GST_BASE_PARSE_GET_CLASS (parse);
|
|
|
|
|
|
|
|
if (active) {
|
2011-11-18 11:35:46 +00:00
|
|
|
if (parse->priv->pad_mode == GST_PAD_MODE_NONE && klass->start)
|
2008-11-13 12:59:34 +00:00
|
|
|
result = klass->start (parse);
|
2011-10-20 06:31:18 +00:00
|
|
|
|
|
|
|
/* If the subclass implements ::detect we want to
|
|
|
|
* call it for the first buffers now */
|
|
|
|
parse->priv->detecting = (klass->detect != NULL);
|
2008-11-13 12:59:34 +00:00
|
|
|
} else {
|
|
|
|
/* We must make sure streaming has finished before resetting things
|
|
|
|
* and calling the ::stop vfunc */
|
|
|
|
GST_PAD_STREAM_LOCK (parse->sinkpad);
|
|
|
|
GST_PAD_STREAM_UNLOCK (parse->sinkpad);
|
|
|
|
|
2011-11-18 11:35:46 +00:00
|
|
|
if (parse->priv->pad_mode != GST_PAD_MODE_NONE && klass->stop)
|
2008-11-13 12:59:34 +00:00
|
|
|
result = klass->stop (parse);
|
|
|
|
|
2011-11-18 11:35:46 +00:00
|
|
|
parse->priv->pad_mode = GST_PAD_MODE_NONE;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
2011-01-11 14:24:23 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "activate return: %d", result);
|
2008-11-13 12:59:34 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-21 12:29:05 +00:00
|
|
|
gst_base_parse_sink_activate_mode (GstPad * pad, GstObject * parent,
|
|
|
|
GstPadMode mode, gboolean active)
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
2012-02-15 11:19:13 +00:00
|
|
|
gboolean result;
|
2008-11-13 12:59:34 +00:00
|
|
|
GstBaseParse *parse;
|
|
|
|
|
2011-11-18 12:46:46 +00:00
|
|
|
parse = GST_BASE_PARSE (parent);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2012-09-11 18:49:58 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "sink %sactivate in %s mode",
|
|
|
|
(active) ? "" : "de", gst_pad_mode_get_name (mode));
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2012-02-15 11:19:13 +00:00
|
|
|
if (!gst_base_parse_activate (parse, active))
|
|
|
|
goto activate_failed;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2012-02-15 11:19:13 +00:00
|
|
|
switch (mode) {
|
|
|
|
case GST_PAD_MODE_PULL:
|
|
|
|
if (active) {
|
2012-03-08 09:19:52 +00:00
|
|
|
parse->priv->pending_events =
|
2012-09-03 17:30:08 +00:00
|
|
|
g_list_prepend (parse->priv->pending_events,
|
2012-03-08 09:19:52 +00:00
|
|
|
gst_event_new_segment (&parse->segment));
|
|
|
|
parse->priv->pending_segment = TRUE;
|
2012-02-15 11:19:13 +00:00
|
|
|
result = TRUE;
|
|
|
|
} else {
|
|
|
|
result = gst_pad_stop_task (pad);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = TRUE;
|
|
|
|
break;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
if (result)
|
2011-11-21 12:29:05 +00:00
|
|
|
parse->priv->pad_mode = active ? mode : GST_PAD_MODE_NONE;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-11-21 12:29:05 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "sink activate return: %d", result);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
return result;
|
2012-02-15 11:19:13 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
activate_failed:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (parse, "activate failed");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_base_parse_set_duration:
|
|
|
|
* @parse: #GstBaseParse.
|
|
|
|
* @fmt: #GstFormat.
|
|
|
|
* @duration: duration value.
|
2011-03-31 14:50:22 +00:00
|
|
|
* @interval: how often to update the duration estimate based on bitrate, or 0.
|
2008-11-13 12:59:34 +00:00
|
|
|
*
|
|
|
|
* Sets the duration of the currently playing media. Subclass can use this
|
2010-09-22 12:13:17 +00:00
|
|
|
* when it is able to determine duration and/or notices a change in the media
|
|
|
|
* duration. Alternatively, if @interval is non-zero (default), then stream
|
|
|
|
* duration is determined based on estimated bitrate, and updated every @interval
|
2011-03-31 14:50:22 +00:00
|
|
|
* frames.
|
|
|
|
*/
|
2008-11-13 12:59:34 +00:00
|
|
|
void
|
|
|
|
gst_base_parse_set_duration (GstBaseParse * parse,
|
2010-09-22 12:13:17 +00:00
|
|
|
GstFormat fmt, gint64 duration, gint interval)
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (parse != NULL);
|
|
|
|
|
2010-10-29 12:08:58 +00:00
|
|
|
if (parse->priv->upstream_has_duration) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "using upstream duration; discarding update");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
if (duration != parse->priv->duration) {
|
|
|
|
GstMessage *m;
|
|
|
|
|
2012-09-02 01:04:14 +00:00
|
|
|
m = gst_message_new_duration_changed (GST_OBJECT (parse));
|
2008-11-13 12:59:34 +00:00
|
|
|
gst_element_post_message (GST_ELEMENT (parse), m);
|
|
|
|
|
|
|
|
/* TODO: what about duration tag? */
|
|
|
|
}
|
|
|
|
parse->priv->duration = duration;
|
|
|
|
parse->priv->duration_fmt = fmt;
|
2009-10-11 09:22:11 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "set duration: %" G_GINT64_FORMAT, duration);
|
2010-09-22 12:13:17 +00:00
|
|
|
if (fmt == GST_FORMAT_TIME && GST_CLOCK_TIME_IS_VALID (duration)) {
|
|
|
|
if (interval != 0) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "valid duration provided, disabling estimate");
|
|
|
|
interval = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GST_DEBUG_OBJECT (parse, "set update interval: %d", interval);
|
|
|
|
parse->priv->update_interval = interval;
|
2010-10-29 12:08:58 +00:00
|
|
|
exit:
|
2010-12-10 13:40:05 +00:00
|
|
|
return;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
2010-09-17 16:24:22 +00:00
|
|
|
/**
|
2011-03-31 13:48:47 +00:00
|
|
|
* gst_base_parse_set_average_bitrate:
|
2010-09-17 16:24:22 +00:00
|
|
|
* @parse: #GstBaseParse.
|
2011-03-31 14:50:22 +00:00
|
|
|
* @bitrate: average bitrate in bits/second
|
2010-09-17 16:24:22 +00:00
|
|
|
*
|
2011-03-31 13:48:47 +00:00
|
|
|
* Optionally sets the average bitrate detected in media (if non-zero),
|
2010-09-17 16:24:22 +00:00
|
|
|
* e.g. based on metadata, as it will be posted to the application.
|
|
|
|
*
|
2011-03-31 13:48:47 +00:00
|
|
|
* By default, announced average bitrate is estimated. The average bitrate
|
|
|
|
* is used to estimate the total duration of the stream and to estimate
|
2011-04-16 14:20:08 +00:00
|
|
|
* a seek position, if there's no index and the format is syncable
|
|
|
|
* (see gst_base_parse_set_syncable()).
|
2010-09-17 16:24:22 +00:00
|
|
|
*/
|
|
|
|
void
|
2011-03-31 13:48:47 +00:00
|
|
|
gst_base_parse_set_average_bitrate (GstBaseParse * parse, guint bitrate)
|
2010-09-17 16:24:22 +00:00
|
|
|
{
|
|
|
|
parse->priv->bitrate = bitrate;
|
2011-03-31 13:48:47 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "bitrate %u", bitrate);
|
2010-09-17 16:24:22 +00:00
|
|
|
}
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
/**
|
|
|
|
* gst_base_parse_set_min_frame_size:
|
|
|
|
* @parse: #GstBaseParse.
|
|
|
|
* @min_size: Minimum size of the data that this base class should give to
|
|
|
|
* subclass.
|
|
|
|
*
|
|
|
|
* Subclass can use this function to tell the base class that it needs to
|
|
|
|
* give at least #min_size buffers.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_base_parse_set_min_frame_size (GstBaseParse * parse, guint min_size)
|
|
|
|
{
|
|
|
|
g_return_if_fail (parse != NULL);
|
|
|
|
|
|
|
|
parse->priv->min_frame_size = min_size;
|
|
|
|
GST_LOG_OBJECT (parse, "set frame_min_size: %d", min_size);
|
|
|
|
}
|
|
|
|
|
2009-11-23 14:48:25 +00:00
|
|
|
/**
|
2011-04-08 14:31:14 +00:00
|
|
|
* gst_base_parse_set_frame_rate:
|
2009-11-23 14:48:25 +00:00
|
|
|
* @parse: the #GstBaseParse to set
|
|
|
|
* @fps_num: frames per second (numerator).
|
|
|
|
* @fps_den: frames per second (denominator).
|
2010-09-22 13:07:09 +00:00
|
|
|
* @lead_in: frames needed before a segment for subsequent decode
|
|
|
|
* @lead_out: frames needed after a segment
|
2009-11-23 14:48:25 +00:00
|
|
|
*
|
2010-09-20 11:31:57 +00:00
|
|
|
* If frames per second is configured, parser can take care of buffer duration
|
2010-09-22 13:07:09 +00:00
|
|
|
* and timestamping. When performing segment clipping, or seeking to a specific
|
|
|
|
* location, a corresponding decoder might need an initial @lead_in and a
|
|
|
|
* following @lead_out number of frames to ensure the desired segment is
|
|
|
|
* entirely filled upon decoding.
|
2009-11-23 14:48:25 +00:00
|
|
|
*/
|
|
|
|
void
|
2011-04-08 14:31:14 +00:00
|
|
|
gst_base_parse_set_frame_rate (GstBaseParse * parse, guint fps_num,
|
2010-09-22 13:07:09 +00:00
|
|
|
guint fps_den, guint lead_in, guint lead_out)
|
2009-11-23 14:48:25 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (parse != NULL);
|
|
|
|
|
|
|
|
parse->priv->fps_num = fps_num;
|
|
|
|
parse->priv->fps_den = fps_den;
|
|
|
|
if (!fps_num || !fps_den) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "invalid fps (%d/%d), ignoring parameters",
|
|
|
|
fps_num, fps_den);
|
|
|
|
fps_num = fps_den = 0;
|
|
|
|
parse->priv->frame_duration = GST_CLOCK_TIME_NONE;
|
2010-09-22 13:07:09 +00:00
|
|
|
parse->priv->lead_in = parse->priv->lead_out = 0;
|
|
|
|
parse->priv->lead_in_ts = parse->priv->lead_out_ts = 0;
|
2009-11-23 14:48:25 +00:00
|
|
|
} else {
|
|
|
|
parse->priv->frame_duration =
|
2010-09-22 13:07:09 +00:00
|
|
|
gst_util_uint64_scale (GST_SECOND, fps_den, fps_num);
|
|
|
|
parse->priv->lead_in = lead_in;
|
|
|
|
parse->priv->lead_out = lead_out;
|
|
|
|
parse->priv->lead_in_ts =
|
|
|
|
gst_util_uint64_scale (GST_SECOND, fps_den * lead_in, fps_num);
|
|
|
|
parse->priv->lead_out_ts =
|
|
|
|
gst_util_uint64_scale (GST_SECOND, fps_den * lead_out, fps_num);
|
2011-01-21 13:53:39 +00:00
|
|
|
/* aim for about 1.5s to estimate duration */
|
|
|
|
if (parse->priv->update_interval < 0) {
|
|
|
|
parse->priv->update_interval = fps_num * 3 / (fps_den * 2);
|
|
|
|
GST_LOG_OBJECT (parse, "estimated update interval to %d frames",
|
|
|
|
parse->priv->update_interval);
|
|
|
|
}
|
2009-11-23 14:48:25 +00:00
|
|
|
}
|
2009-12-11 18:25:16 +00:00
|
|
|
GST_LOG_OBJECT (parse, "set fps: %d/%d => duration: %" G_GINT64_FORMAT " ms",
|
|
|
|
fps_num, fps_den, parse->priv->frame_duration / GST_MSECOND);
|
2010-09-22 13:07:09 +00:00
|
|
|
GST_LOG_OBJECT (parse, "set lead in: %d frames = %" G_GUINT64_FORMAT " ms, "
|
|
|
|
"lead out: %d frames = %" G_GUINT64_FORMAT " ms",
|
|
|
|
lead_in, parse->priv->lead_in_ts / GST_MSECOND,
|
|
|
|
lead_out, parse->priv->lead_out_ts / GST_MSECOND);
|
2009-11-23 14:48:25 +00:00
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-04-06 16:43:27 +00:00
|
|
|
/**
|
|
|
|
* gst_base_parse_set_has_timing_info:
|
|
|
|
* @parse: a #GstBaseParse
|
|
|
|
* @has_timing: whether frames carry timing information
|
|
|
|
*
|
|
|
|
* Set if frames carry timing information which the subclass can (generally)
|
|
|
|
* parse and provide. In particular, intrinsic (rather than estimated) time
|
|
|
|
* can be obtained following a seek.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_base_parse_set_has_timing_info (GstBaseParse * parse, gboolean has_timing)
|
|
|
|
{
|
|
|
|
parse->priv->has_timing_info = has_timing;
|
|
|
|
GST_INFO_OBJECT (parse, "has_timing: %s", (has_timing) ? "yes" : "no");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_base_parse_set_syncable:
|
|
|
|
* @parse: a #GstBaseParse
|
|
|
|
* @syncable: set if frame starts can be identified
|
|
|
|
*
|
|
|
|
* Set if frame starts can be identified. This is set by default and
|
|
|
|
* determines whether seeking based on bitrate averages
|
|
|
|
* is possible for a format/stream.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_base_parse_set_syncable (GstBaseParse * parse, gboolean syncable)
|
|
|
|
{
|
|
|
|
parse->priv->syncable = syncable;
|
|
|
|
GST_INFO_OBJECT (parse, "syncable: %s", (syncable) ? "yes" : "no");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_base_parse_set_passthrough:
|
|
|
|
* @parse: a #GstBaseParse
|
2011-05-03 10:55:43 +00:00
|
|
|
* @passthrough: %TRUE if parser should run in passthrough mode
|
2011-04-06 16:43:27 +00:00
|
|
|
*
|
|
|
|
* Set if the nature of the format or configuration does not allow (much)
|
|
|
|
* parsing, and the parser should operate in passthrough mode (which only
|
|
|
|
* applies when operating in push mode). That is, incoming buffers are
|
|
|
|
* pushed through unmodified, i.e. no @check_valid_frame or @parse_frame
|
2011-10-20 14:59:01 +00:00
|
|
|
* callbacks will be invoked, but @pre_push_frame will still be invoked,
|
2011-04-06 16:43:27 +00:00
|
|
|
* so subclass can perform as much or as little is appropriate for
|
2011-10-20 14:59:01 +00:00
|
|
|
* passthrough semantics in @pre_push_frame.
|
2011-04-06 16:43:27 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_base_parse_set_passthrough (GstBaseParse * parse, gboolean passthrough)
|
|
|
|
{
|
|
|
|
parse->priv->passthrough = passthrough;
|
|
|
|
GST_INFO_OBJECT (parse, "passthrough: %s", (passthrough) ? "yes" : "no");
|
|
|
|
}
|
|
|
|
|
2012-09-13 05:44:37 +00:00
|
|
|
/**
|
|
|
|
* gst_base_parse_set_pts_interpolation:
|
|
|
|
* @parse: a #GstBaseParse
|
2012-10-10 08:36:32 +00:00
|
|
|
* @pts_interpolate: %TRUE if parser should interpolate PTS timestamps
|
2012-09-13 05:44:37 +00:00
|
|
|
*
|
|
|
|
* By default, the base class will guess PTS timestamps using a simple
|
|
|
|
* interpolation (previous timestamp + duration), which is incorrect for
|
|
|
|
* data streams with reordering, where PTS can go backward. Sub-classes
|
|
|
|
* implementing such formats should disable PTS interpolation.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_base_parse_set_pts_interpolation (GstBaseParse * parse,
|
|
|
|
gboolean pts_interpolate)
|
|
|
|
{
|
|
|
|
parse->priv->pts_interpolate = pts_interpolate;
|
|
|
|
GST_INFO_OBJECT (parse, "PTS interpolation: %s",
|
|
|
|
(pts_interpolate) ? "yes" : "no");
|
|
|
|
}
|
|
|
|
|
2013-02-26 18:58:49 +00:00
|
|
|
/**
|
|
|
|
* gst_base_parse_set_infer_ts:
|
|
|
|
* @parse: a #GstBaseParse
|
|
|
|
* @infer_ts: %TRUE if parser should infer DTS/PTS from each other
|
|
|
|
*
|
|
|
|
* By default, the base class might try to infer PTS from DTS and vice
|
|
|
|
* versa. While this is generally correct for audio data, it may not
|
|
|
|
* be otherwise. Sub-classes implementing such formats should disable
|
|
|
|
* timestamp infering.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_base_parse_set_infer_ts (GstBaseParse * parse, gboolean infer_ts)
|
|
|
|
{
|
|
|
|
parse->priv->infer_ts = infer_ts;
|
|
|
|
GST_INFO_OBJECT (parse, "TS infering: %s", (infer_ts) ? "yes" : "no");
|
|
|
|
}
|
|
|
|
|
2011-05-12 09:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_base_parse_set_latency:
|
|
|
|
* @parse: a #GstBaseParse
|
|
|
|
* @min_latency: minimum parse latency
|
|
|
|
* @max_latency: maximum parse latency
|
|
|
|
*
|
|
|
|
* Sets the minimum and maximum (which may likely be equal) latency introduced
|
|
|
|
* by the parsing process. If there is such a latency, which depends on the
|
|
|
|
* particular parsing of the format, it typically corresponds to 1 frame duration.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_base_parse_set_latency (GstBaseParse * parse, GstClockTime min_latency,
|
|
|
|
GstClockTime max_latency)
|
|
|
|
{
|
|
|
|
GST_OBJECT_LOCK (parse);
|
|
|
|
parse->priv->min_latency = min_latency;
|
|
|
|
parse->priv->max_latency = max_latency;
|
|
|
|
GST_OBJECT_UNLOCK (parse);
|
|
|
|
GST_INFO_OBJECT (parse, "min/max latency %" GST_TIME_FORMAT ", %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (min_latency),
|
|
|
|
GST_TIME_ARGS (max_latency));
|
|
|
|
}
|
|
|
|
|
2010-09-16 16:35:47 +00:00
|
|
|
static gboolean
|
|
|
|
gst_base_parse_get_duration (GstBaseParse * parse, GstFormat format,
|
|
|
|
GstClockTime * duration)
|
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (duration != NULL, FALSE);
|
|
|
|
|
|
|
|
*duration = GST_CLOCK_TIME_NONE;
|
|
|
|
if (parse->priv->duration != -1 && format == parse->priv->duration_fmt) {
|
|
|
|
GST_LOG_OBJECT (parse, "using provided duration");
|
|
|
|
*duration = parse->priv->duration;
|
|
|
|
res = TRUE;
|
|
|
|
} else if (parse->priv->duration != -1) {
|
|
|
|
GST_LOG_OBJECT (parse, "converting provided duration");
|
2010-09-16 16:56:46 +00:00
|
|
|
res = gst_base_parse_convert (parse, parse->priv->duration_fmt,
|
2010-09-16 16:35:47 +00:00
|
|
|
parse->priv->duration, format, (gint64 *) duration);
|
|
|
|
} else if (format == GST_FORMAT_TIME && parse->priv->estimated_duration != -1) {
|
|
|
|
GST_LOG_OBJECT (parse, "using estimated duration");
|
|
|
|
*duration = parse->priv->estimated_duration;
|
|
|
|
res = TRUE;
|
2012-02-15 09:11:35 +00:00
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (parse, "cannot estimate duration");
|
2010-09-16 16:35:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (parse, "res: %d, duration %" GST_TIME_FORMAT, res,
|
|
|
|
GST_TIME_ARGS (*duration));
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
static gboolean
|
2013-01-13 14:45:31 +00:00
|
|
|
gst_base_parse_src_query_default (GstBaseParse * parse, GstQuery * query)
|
2008-11-13 12:59:34 +00:00
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
2013-01-13 14:45:31 +00:00
|
|
|
GstPad *pad;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2013-01-13 14:45:31 +00:00
|
|
|
pad = GST_BASE_PARSE_SRC_PAD (parse);
|
2010-09-16 16:35:47 +00:00
|
|
|
|
2011-05-17 09:20:05 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
2008-11-13 12:59:34 +00:00
|
|
|
case GST_QUERY_POSITION:
|
|
|
|
{
|
|
|
|
gint64 dest_value;
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "position query");
|
2011-05-17 09:20:05 +00:00
|
|
|
gst_query_parse_position (query, &format, NULL);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-09-26 12:14:42 +00:00
|
|
|
/* try upstream first */
|
2013-01-13 14:45:31 +00:00
|
|
|
res = gst_pad_query_default (pad, GST_OBJECT_CAST (parse), query);
|
2011-09-26 12:14:42 +00:00
|
|
|
if (!res) {
|
|
|
|
/* Fall back on interpreting segment */
|
|
|
|
GST_OBJECT_LOCK (parse);
|
|
|
|
if (format == GST_FORMAT_BYTES) {
|
|
|
|
dest_value = parse->priv->offset;
|
|
|
|
res = TRUE;
|
|
|
|
} else if (format == parse->segment.format &&
|
2011-10-03 08:06:17 +00:00
|
|
|
GST_CLOCK_TIME_IS_VALID (parse->segment.position)) {
|
2011-09-26 12:14:42 +00:00
|
|
|
dest_value = gst_segment_to_stream_time (&parse->segment,
|
2011-10-03 08:06:17 +00:00
|
|
|
parse->segment.format, parse->segment.position);
|
2011-09-26 12:14:42 +00:00
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (parse);
|
2010-09-16 16:35:47 +00:00
|
|
|
if (!res) {
|
|
|
|
/* no precise result, upstream no idea either, then best estimate */
|
|
|
|
/* priv->offset is updated in both PUSH/PULL modes */
|
2010-09-16 16:56:46 +00:00
|
|
|
res = gst_base_parse_convert (parse,
|
|
|
|
GST_FORMAT_BYTES, parse->priv->offset, format, &dest_value);
|
2010-09-16 16:35:47 +00:00
|
|
|
}
|
2011-09-30 14:25:20 +00:00
|
|
|
if (res)
|
|
|
|
gst_query_set_position (query, format, dest_value);
|
2010-09-16 16:35:47 +00:00
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_DURATION:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
2010-09-16 16:35:47 +00:00
|
|
|
GstClockTime duration;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "duration query");
|
2011-05-17 09:20:05 +00:00
|
|
|
gst_query_parse_duration (query, &format, NULL);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-16 16:35:47 +00:00
|
|
|
/* consult upstream */
|
2013-01-13 14:45:31 +00:00
|
|
|
res = gst_pad_query_default (pad, GST_OBJECT_CAST (parse), query);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-16 16:35:47 +00:00
|
|
|
/* otherwise best estimate from us */
|
|
|
|
if (!res) {
|
|
|
|
res = gst_base_parse_get_duration (parse, format, &duration);
|
2011-05-17 09:20:05 +00:00
|
|
|
if (res)
|
|
|
|
gst_query_set_duration (query, format, duration);
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_SEEKING:
|
|
|
|
{
|
|
|
|
GstFormat fmt;
|
2010-09-16 16:35:47 +00:00
|
|
|
GstClockTime duration = GST_CLOCK_TIME_NONE;
|
2008-11-13 12:59:34 +00:00
|
|
|
gboolean seekable = FALSE;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "seeking query");
|
2011-05-17 09:20:05 +00:00
|
|
|
gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-16 16:35:47 +00:00
|
|
|
/* consult upstream */
|
2013-01-13 14:45:31 +00:00
|
|
|
res = gst_pad_query_default (pad, GST_OBJECT_CAST (parse), query);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-16 16:35:47 +00:00
|
|
|
/* we may be able to help if in TIME */
|
2011-03-31 13:48:47 +00:00
|
|
|
if (fmt == GST_FORMAT_TIME && gst_base_parse_is_seekable (parse)) {
|
2011-05-17 09:20:05 +00:00
|
|
|
gst_query_parse_seeking (query, &fmt, &seekable, NULL, NULL);
|
2010-09-16 16:35:47 +00:00
|
|
|
/* already OK if upstream takes care */
|
|
|
|
GST_LOG_OBJECT (parse, "upstream handled %d, seekable %d",
|
|
|
|
res, seekable);
|
|
|
|
if (!(res && seekable)) {
|
|
|
|
if (!gst_base_parse_get_duration (parse, GST_FORMAT_TIME, &duration)
|
|
|
|
|| duration == -1) {
|
2011-02-07 13:46:57 +00:00
|
|
|
/* seekable if we still have a chance to get duration later on */
|
|
|
|
seekable =
|
|
|
|
parse->priv->upstream_seekable && parse->priv->update_interval;
|
2010-09-16 16:35:47 +00:00
|
|
|
} else {
|
2010-09-25 12:40:54 +00:00
|
|
|
seekable = parse->priv->upstream_seekable;
|
|
|
|
GST_LOG_OBJECT (parse, "already determine upstream seekabled: %d",
|
|
|
|
seekable);
|
2010-09-16 16:35:47 +00:00
|
|
|
}
|
2011-05-17 09:20:05 +00:00
|
|
|
gst_query_set_seeking (query, GST_FORMAT_TIME, seekable, 0, duration);
|
2010-09-16 16:35:47 +00:00
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_FORMATS:
|
2011-05-17 09:20:05 +00:00
|
|
|
gst_query_set_formatsv (query, 3, fmtlist);
|
2008-11-13 12:59:34 +00:00
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_QUERY_CONVERT:
|
|
|
|
{
|
|
|
|
GstFormat src_format, dest_format;
|
|
|
|
gint64 src_value, dest_value;
|
|
|
|
|
2011-05-17 09:20:05 +00:00
|
|
|
gst_query_parse_convert (query, &src_format, &src_value,
|
2008-11-13 12:59:34 +00:00
|
|
|
&dest_format, &dest_value);
|
|
|
|
|
2010-09-16 16:56:46 +00:00
|
|
|
res = gst_base_parse_convert (parse, src_format, src_value,
|
2008-11-13 12:59:34 +00:00
|
|
|
dest_format, &dest_value);
|
|
|
|
if (res) {
|
2011-05-17 09:20:05 +00:00
|
|
|
gst_query_set_convert (query, src_format, src_value,
|
2008-11-13 12:59:34 +00:00
|
|
|
dest_format, dest_value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-05-12 09:55:20 +00:00
|
|
|
case GST_QUERY_LATENCY:
|
|
|
|
{
|
|
|
|
if ((res = gst_pad_peer_query (parse->sinkpad, query))) {
|
|
|
|
gboolean live;
|
|
|
|
GstClockTime min_latency, max_latency;
|
|
|
|
|
|
|
|
gst_query_parse_latency (query, &live, &min_latency, &max_latency);
|
|
|
|
GST_DEBUG_OBJECT (parse, "Peer latency: live %d, min %"
|
|
|
|
GST_TIME_FORMAT " max %" GST_TIME_FORMAT, live,
|
|
|
|
GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (parse);
|
|
|
|
/* add our latency */
|
|
|
|
if (min_latency != -1)
|
|
|
|
min_latency += parse->priv->min_latency;
|
|
|
|
if (max_latency != -1)
|
|
|
|
max_latency += parse->priv->max_latency;
|
|
|
|
GST_OBJECT_UNLOCK (parse);
|
|
|
|
|
|
|
|
gst_query_set_latency (query, live, min_latency, max_latency);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-29 08:48:30 +00:00
|
|
|
case GST_QUERY_SEGMENT:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
gint64 start, stop;
|
|
|
|
|
|
|
|
format = parse->segment.format;
|
|
|
|
|
|
|
|
start =
|
|
|
|
gst_segment_to_stream_time (&parse->segment, format,
|
|
|
|
parse->segment.start);
|
|
|
|
if ((stop = parse->segment.stop) == -1)
|
|
|
|
stop = parse->segment.duration;
|
|
|
|
else
|
|
|
|
stop = gst_segment_to_stream_time (&parse->segment, format, stop);
|
|
|
|
|
|
|
|
gst_query_set_segment (query, parse->segment.rate, format, start, stop);
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
default:
|
2013-01-13 14:45:31 +00:00
|
|
|
res = gst_pad_query_default (pad, GST_OBJECT_CAST (parse), query);
|
2008-11-13 12:59:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-11-17 13:30:09 +00:00
|
|
|
/* scans for a cluster start from @pos,
|
|
|
|
* return GST_FLOW_OK and frame position/time in @pos/@time if found */
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_parse_find_frame (GstBaseParse * parse, gint64 * pos,
|
|
|
|
GstClockTime * time, GstClockTime * duration)
|
|
|
|
{
|
|
|
|
GstBaseParseClass *klass;
|
|
|
|
gint64 orig_offset;
|
|
|
|
gboolean orig_drain, orig_discont;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
GstBuffer *buf = NULL;
|
2012-02-13 17:22:37 +00:00
|
|
|
GstBaseParseFrame *sframe = NULL;
|
2010-11-17 13:30:09 +00:00
|
|
|
|
2011-04-25 09:10:47 +00:00
|
|
|
g_return_val_if_fail (pos != NULL, GST_FLOW_ERROR);
|
|
|
|
g_return_val_if_fail (time != NULL, GST_FLOW_ERROR);
|
|
|
|
g_return_val_if_fail (duration != NULL, GST_FLOW_ERROR);
|
2010-11-17 13:30:09 +00:00
|
|
|
|
|
|
|
klass = GST_BASE_PARSE_GET_CLASS (parse);
|
|
|
|
|
|
|
|
*time = GST_CLOCK_TIME_NONE;
|
|
|
|
*duration = GST_CLOCK_TIME_NONE;
|
|
|
|
|
|
|
|
/* save state */
|
|
|
|
orig_offset = parse->priv->offset;
|
|
|
|
orig_discont = parse->priv->discont;
|
|
|
|
orig_drain = parse->priv->drain;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "scanning for frame starting at %" G_GINT64_FORMAT
|
|
|
|
" (%#" G_GINT64_MODIFIER "x)", *pos, *pos);
|
|
|
|
|
|
|
|
/* jump elsewhere and locate next frame */
|
|
|
|
parse->priv->offset = *pos;
|
2012-02-13 17:22:37 +00:00
|
|
|
/* mark as scanning so frames don't get processed all the way */
|
|
|
|
parse->priv->scanning = TRUE;
|
2012-07-24 11:48:39 +00:00
|
|
|
ret = gst_base_parse_scan_frame (parse, klass);
|
2012-02-13 17:22:37 +00:00
|
|
|
parse->priv->scanning = FALSE;
|
|
|
|
/* retrieve frame found during scan */
|
|
|
|
sframe = parse->priv->scanned_frame;
|
|
|
|
parse->priv->scanned_frame = NULL;
|
|
|
|
|
|
|
|
if (ret != GST_FLOW_OK || !sframe)
|
2010-11-17 13:30:09 +00:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* get offset first, subclass parsing might dump other stuff in there */
|
2012-02-13 17:22:37 +00:00
|
|
|
*pos = sframe->offset;
|
|
|
|
buf = sframe->buffer;
|
|
|
|
g_assert (buf);
|
2010-11-17 13:30:09 +00:00
|
|
|
|
|
|
|
/* but it should provide proper time */
|
|
|
|
*time = GST_BUFFER_TIMESTAMP (buf);
|
|
|
|
*duration = GST_BUFFER_DURATION (buf);
|
2011-04-15 16:41:02 +00:00
|
|
|
|
2010-11-17 13:30:09 +00:00
|
|
|
GST_LOG_OBJECT (parse,
|
|
|
|
"frame with time %" GST_TIME_FORMAT " at offset %" G_GINT64_FORMAT,
|
|
|
|
GST_TIME_ARGS (*time), *pos);
|
|
|
|
|
|
|
|
done:
|
2012-02-13 17:22:37 +00:00
|
|
|
if (sframe)
|
|
|
|
gst_base_parse_frame_free (sframe);
|
|
|
|
|
2010-11-17 13:30:09 +00:00
|
|
|
/* restore state */
|
|
|
|
parse->priv->offset = orig_offset;
|
|
|
|
parse->priv->discont = orig_discont;
|
|
|
|
parse->priv->drain = orig_drain;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bisect and scan through file for frame starting before @time,
|
|
|
|
* returns OK and @time/@offset if found, NONE and/or error otherwise
|
|
|
|
* If @time == G_MAXINT64, scan for duration ( == last frame) */
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_parse_locate_time (GstBaseParse * parse, GstClockTime * _time,
|
|
|
|
gint64 * _offset)
|
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
gint64 lpos, hpos, newpos;
|
|
|
|
GstClockTime time, ltime, htime, newtime, dur;
|
|
|
|
gboolean cont = TRUE;
|
|
|
|
const GstClockTime tolerance = TARGET_DIFFERENCE;
|
|
|
|
const guint chunk = 4 * 1024;
|
|
|
|
|
|
|
|
g_return_val_if_fail (_time != NULL, GST_FLOW_ERROR);
|
|
|
|
g_return_val_if_fail (_offset != NULL, GST_FLOW_ERROR);
|
|
|
|
|
2011-12-07 17:57:49 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "Bisecting for time %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (*_time));
|
|
|
|
|
2010-11-17 13:30:09 +00:00
|
|
|
/* TODO also make keyframe aware if useful some day */
|
|
|
|
|
|
|
|
time = *_time;
|
|
|
|
|
|
|
|
/* basic cases */
|
|
|
|
if (time == 0) {
|
|
|
|
*_offset = 0;
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time == -1) {
|
|
|
|
*_offset = -1;
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do not know at first */
|
|
|
|
*_offset = -1;
|
2010-11-30 14:40:28 +00:00
|
|
|
*_time = GST_CLOCK_TIME_NONE;
|
2010-11-17 13:30:09 +00:00
|
|
|
|
|
|
|
/* need initial positions; start and end */
|
|
|
|
lpos = parse->priv->first_frame_offset;
|
2012-09-03 06:32:50 +00:00
|
|
|
ltime = parse->priv->first_frame_pts;
|
2011-12-07 17:57:49 +00:00
|
|
|
if (!gst_base_parse_get_duration (parse, GST_FORMAT_TIME, &htime)) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "Unknown time duration, cannot bisect");
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2010-11-17 13:30:09 +00:00
|
|
|
hpos = parse->priv->upstream_size;
|
|
|
|
|
2011-12-07 17:57:49 +00:00
|
|
|
GST_DEBUG_OBJECT (parse,
|
|
|
|
"Bisection initial bounds: bytes %" G_GINT64_FORMAT " %" G_GINT64_FORMAT
|
|
|
|
", times %" GST_TIME_FORMAT " %" GST_TIME_FORMAT, lpos, htime,
|
|
|
|
GST_TIME_ARGS (ltime), GST_TIME_ARGS (htime));
|
|
|
|
|
2010-11-17 13:30:09 +00:00
|
|
|
/* check preconditions are satisfied;
|
|
|
|
* start and end are needed, except for special case where we scan for
|
|
|
|
* last frame to determine duration */
|
2011-11-18 11:35:46 +00:00
|
|
|
if (parse->priv->pad_mode != GST_PAD_MODE_PULL || !hpos ||
|
2010-11-17 13:30:09 +00:00
|
|
|
!GST_CLOCK_TIME_IS_VALID (ltime) ||
|
|
|
|
(!GST_CLOCK_TIME_IS_VALID (htime) && time != G_MAXINT64)) {
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* shortcut cases */
|
|
|
|
if (time < ltime) {
|
|
|
|
goto exit;
|
|
|
|
} else if (time < ltime + tolerance) {
|
|
|
|
*_offset = lpos;
|
|
|
|
*_time = ltime;
|
|
|
|
goto exit;
|
|
|
|
} else if (time >= htime) {
|
|
|
|
*_offset = hpos;
|
|
|
|
*_time = htime;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (htime > ltime && cont) {
|
|
|
|
GST_LOG_OBJECT (parse,
|
|
|
|
"lpos: %" G_GUINT64_FORMAT ", ltime: %" GST_TIME_FORMAT, lpos,
|
|
|
|
GST_TIME_ARGS (ltime));
|
|
|
|
GST_LOG_OBJECT (parse,
|
|
|
|
"hpos: %" G_GUINT64_FORMAT ", htime: %" GST_TIME_FORMAT, hpos,
|
|
|
|
GST_TIME_ARGS (htime));
|
|
|
|
if (G_UNLIKELY (time == G_MAXINT64)) {
|
|
|
|
newpos = hpos;
|
|
|
|
} else if (G_LIKELY (hpos > lpos)) {
|
|
|
|
newpos =
|
|
|
|
gst_util_uint64_scale (hpos - lpos, time - ltime, htime - ltime) +
|
|
|
|
lpos - chunk;
|
|
|
|
} else {
|
2011-01-14 13:08:38 +00:00
|
|
|
/* should mean lpos == hpos, since lpos <= hpos is invariant */
|
2010-11-17 13:30:09 +00:00
|
|
|
newpos = lpos;
|
|
|
|
/* we check this case once, but not forever, so break loop */
|
|
|
|
cont = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ensure */
|
|
|
|
newpos = CLAMP (newpos, lpos, hpos);
|
|
|
|
GST_LOG_OBJECT (parse,
|
|
|
|
"estimated _offset for %" GST_TIME_FORMAT ": %" G_GINT64_FORMAT,
|
|
|
|
GST_TIME_ARGS (time), newpos);
|
|
|
|
|
|
|
|
ret = gst_base_parse_find_frame (parse, &newpos, &newtime, &dur);
|
2011-10-10 09:33:51 +00:00
|
|
|
if (ret == GST_FLOW_EOS) {
|
2010-11-17 13:30:09 +00:00
|
|
|
/* heuristic HACK */
|
|
|
|
hpos = MAX (lpos, hpos - chunk);
|
|
|
|
continue;
|
|
|
|
} else if (ret != GST_FLOW_OK) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newtime == -1 || newpos == -1) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "subclass did not provide metadata; aborting");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_UNLIKELY (time == G_MAXINT64)) {
|
|
|
|
*_offset = newpos;
|
|
|
|
*_time = newtime;
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (dur))
|
|
|
|
*_time += dur;
|
|
|
|
break;
|
|
|
|
} else if (newtime > time) {
|
|
|
|
/* overshoot */
|
2011-01-14 13:08:38 +00:00
|
|
|
hpos = (newpos >= hpos) ? MAX (lpos, hpos - chunk) : MAX (lpos, newpos);
|
2010-11-17 13:30:09 +00:00
|
|
|
htime = newtime;
|
|
|
|
} else if (newtime + tolerance > time) {
|
|
|
|
/* close enough undershoot */
|
|
|
|
*_offset = newpos;
|
|
|
|
*_time = newtime;
|
|
|
|
break;
|
|
|
|
} else if (newtime < ltime) {
|
|
|
|
/* so a position beyond lpos resulted in earlier time than ltime ... */
|
|
|
|
GST_DEBUG_OBJECT (parse, "non-ascending time; aborting");
|
2011-01-14 13:08:38 +00:00
|
|
|
break;
|
2010-11-17 13:30:09 +00:00
|
|
|
} else {
|
|
|
|
/* undershoot too far */
|
2011-01-14 13:08:38 +00:00
|
|
|
newpos += newpos == lpos ? chunk : 0;
|
2010-11-17 13:30:09 +00:00
|
|
|
lpos = CLAMP (newpos, lpos, hpos);
|
|
|
|
ltime = newtime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
GST_LOG_OBJECT (parse, "return offset %" G_GINT64_FORMAT ", time %"
|
|
|
|
GST_TIME_FORMAT, *_offset, GST_TIME_ARGS (*_time));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-22 10:13:12 +00:00
|
|
|
static gint64
|
|
|
|
gst_base_parse_find_offset (GstBaseParse * parse, GstClockTime time,
|
|
|
|
gboolean before, GstClockTime * _ts)
|
|
|
|
{
|
|
|
|
gint64 bytes = 0, ts = 0;
|
|
|
|
GstIndexEntry *entry = NULL;
|
|
|
|
|
|
|
|
if (time == GST_CLOCK_TIME_NONE) {
|
|
|
|
ts = time;
|
|
|
|
bytes = -1;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2011-12-04 13:35:38 +00:00
|
|
|
GST_BASE_PARSE_INDEX_LOCK (parse);
|
2010-09-22 10:13:12 +00:00
|
|
|
if (parse->priv->index) {
|
|
|
|
/* Let's check if we have an index entry for that time */
|
|
|
|
entry = gst_index_get_assoc_entry (parse->priv->index,
|
|
|
|
parse->priv->index_id,
|
|
|
|
before ? GST_INDEX_LOOKUP_BEFORE : GST_INDEX_LOOKUP_AFTER,
|
2011-12-30 15:31:17 +00:00
|
|
|
GST_INDEX_ASSOCIATION_FLAG_KEY_UNIT, GST_FORMAT_TIME, time);
|
2010-09-22 10:13:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (entry) {
|
|
|
|
gst_index_entry_assoc_map (entry, GST_FORMAT_BYTES, &bytes);
|
|
|
|
gst_index_entry_assoc_map (entry, GST_FORMAT_TIME, &ts);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "found index entry for %" GST_TIME_FORMAT
|
|
|
|
" at %" GST_TIME_FORMAT ", offset %" G_GINT64_FORMAT,
|
|
|
|
GST_TIME_ARGS (time), GST_TIME_ARGS (ts), bytes);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (parse, "no index entry found for %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (time));
|
|
|
|
if (!before) {
|
|
|
|
bytes = -1;
|
|
|
|
ts = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
}
|
2011-12-04 13:35:38 +00:00
|
|
|
GST_BASE_PARSE_INDEX_UNLOCK (parse);
|
2010-09-22 10:13:12 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
if (_ts)
|
|
|
|
*_ts = ts;
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
2011-03-31 14:50:22 +00:00
|
|
|
/* returns TRUE if seek succeeded */
|
2008-11-13 12:59:34 +00:00
|
|
|
static gboolean
|
|
|
|
gst_base_parse_handle_seek (GstBaseParse * parse, GstEvent * event)
|
|
|
|
{
|
|
|
|
gdouble rate;
|
|
|
|
GstFormat format;
|
|
|
|
GstSeekFlags flags;
|
2012-07-27 13:19:57 +00:00
|
|
|
GstSeekType start_type = GST_SEEK_TYPE_NONE, stop_type;
|
2010-09-22 10:13:12 +00:00
|
|
|
gboolean flush, update, res = TRUE, accurate;
|
2012-07-27 13:19:57 +00:00
|
|
|
gint64 start, stop, seekpos, seekstop;
|
2008-11-13 12:59:34 +00:00
|
|
|
GstSegment seeksegment = { 0, };
|
2010-09-22 10:13:12 +00:00
|
|
|
GstClockTime start_ts;
|
2013-07-25 15:20:14 +00:00
|
|
|
guint32 seqnum;
|
|
|
|
GstEvent *segment_event;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2012-08-10 21:58:56 +00:00
|
|
|
/* try upstream first, unless we're driving the streaming thread ourselves */
|
|
|
|
if (parse->priv->pad_mode != GST_PAD_MODE_PULL) {
|
|
|
|
res = gst_pad_push_event (parse->sinkpad, gst_event_ref (event));
|
|
|
|
if (res)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
gst_event_parse_seek (event, &rate, &format, &flags,
|
2012-07-27 13:19:57 +00:00
|
|
|
&start_type, &start, &stop_type, &stop);
|
2013-07-25 15:20:14 +00:00
|
|
|
seqnum = gst_event_get_seqnum (event);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-09-29 14:12:42 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "seek to format %s, rate %f, "
|
2010-06-15 13:32:34 +00:00
|
|
|
"start type %d at %" GST_TIME_FORMAT ", end type %d at %"
|
2010-09-29 14:12:42 +00:00
|
|
|
GST_TIME_FORMAT, gst_format_get_name (format), rate,
|
2012-07-27 13:19:57 +00:00
|
|
|
start_type, GST_TIME_ARGS (start), stop_type, GST_TIME_ARGS (stop));
|
2010-06-15 13:32:34 +00:00
|
|
|
|
2012-08-19 16:51:00 +00:00
|
|
|
/* we can only handle TIME, so check if subclass can convert
|
|
|
|
* to TIME format if it's some other format (such as DEFAULT) */
|
|
|
|
if (format != GST_FORMAT_TIME) {
|
|
|
|
if (!gst_base_parse_convert (parse, format, start, GST_FORMAT_TIME, &start)
|
|
|
|
|| !gst_base_parse_convert (parse, format, stop, GST_FORMAT_TIME,
|
|
|
|
&stop))
|
|
|
|
goto no_convert_to_time;
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (parse, "converted %s format to start time "
|
|
|
|
"%" GST_TIME_FORMAT " and stop time %" GST_TIME_FORMAT,
|
|
|
|
gst_format_get_name (format), GST_TIME_ARGS (start),
|
|
|
|
GST_TIME_ARGS (stop));
|
|
|
|
|
|
|
|
format = GST_FORMAT_TIME;
|
|
|
|
}
|
2012-08-10 21:58:56 +00:00
|
|
|
|
|
|
|
/* no negative rates in push mode (unless upstream takes care of that, but
|
|
|
|
* we've already tried upstream and it didn't handle the seek request) */
|
2011-11-18 11:35:46 +00:00
|
|
|
if (rate < 0.0 && parse->priv->pad_mode == GST_PAD_MODE_PUSH)
|
2008-11-13 12:59:34 +00:00
|
|
|
goto negative_rate;
|
|
|
|
|
2012-08-10 21:58:56 +00:00
|
|
|
if (rate < 0.0 && parse->priv->pad_mode == GST_PAD_MODE_PULL)
|
|
|
|
goto negative_rate_pull_mode;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2012-07-27 13:19:57 +00:00
|
|
|
if (start_type != GST_SEEK_TYPE_SET ||
|
2012-07-13 10:05:15 +00:00
|
|
|
(stop_type != GST_SEEK_TYPE_SET && stop_type != GST_SEEK_TYPE_NONE))
|
|
|
|
goto wrong_type;
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
/* get flush flag */
|
|
|
|
flush = flags & GST_SEEK_FLAG_FLUSH;
|
|
|
|
|
2010-06-15 13:32:34 +00:00
|
|
|
/* copy segment, we need this because we still need the old
|
|
|
|
* segment when we close the current segment. */
|
2011-05-13 16:07:24 +00:00
|
|
|
gst_segment_copy_into (&parse->segment, &seeksegment);
|
2010-06-15 13:32:34 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "configuring seek");
|
2011-05-13 16:07:24 +00:00
|
|
|
gst_segment_do_seek (&seeksegment, rate, format, flags,
|
2012-07-27 13:19:57 +00:00
|
|
|
start_type, start, stop_type, stop, &update);
|
2010-06-15 13:32:34 +00:00
|
|
|
|
2010-09-22 10:13:12 +00:00
|
|
|
/* accurate seeking implies seek tables are used to obtain position,
|
|
|
|
* and the requested segment is maintained exactly, not adjusted any way */
|
|
|
|
accurate = flags & GST_SEEK_FLAG_ACCURATE;
|
|
|
|
|
|
|
|
/* maybe we can be accurate for (almost) free */
|
2011-05-13 16:07:24 +00:00
|
|
|
gst_base_parse_find_offset (parse, seeksegment.position, TRUE, &start_ts);
|
|
|
|
if (seeksegment.position <= start_ts + TARGET_DIFFERENCE) {
|
2010-11-17 13:30:09 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "accurate seek possible");
|
2010-09-22 10:13:12 +00:00
|
|
|
accurate = TRUE;
|
|
|
|
}
|
|
|
|
if (accurate) {
|
2011-05-13 16:07:24 +00:00
|
|
|
GstClockTime startpos = seeksegment.position;
|
2010-09-22 13:07:09 +00:00
|
|
|
|
|
|
|
/* accurate requested, so ... seek a bit before target */
|
|
|
|
if (startpos < parse->priv->lead_in_ts)
|
|
|
|
startpos = 0;
|
|
|
|
else
|
|
|
|
startpos -= parse->priv->lead_in_ts;
|
|
|
|
seekpos = gst_base_parse_find_offset (parse, startpos, TRUE, &start_ts);
|
2010-09-22 10:13:12 +00:00
|
|
|
seekstop = gst_base_parse_find_offset (parse, seeksegment.stop, FALSE,
|
|
|
|
NULL);
|
|
|
|
} else {
|
2011-05-13 16:07:24 +00:00
|
|
|
start_ts = seeksegment.position;
|
2012-03-20 16:08:28 +00:00
|
|
|
if (!gst_base_parse_convert (parse, format, seeksegment.position,
|
2011-07-26 23:26:43 +00:00
|
|
|
GST_FORMAT_BYTES, &seekpos))
|
2010-09-22 10:13:12 +00:00
|
|
|
goto convert_failed;
|
2012-03-20 16:08:28 +00:00
|
|
|
if (!gst_base_parse_convert (parse, format, seeksegment.stop,
|
2011-07-26 23:26:43 +00:00
|
|
|
GST_FORMAT_BYTES, &seekstop))
|
2010-09-22 10:13:12 +00:00
|
|
|
goto convert_failed;
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2009-10-11 09:22:11 +00:00
|
|
|
GST_DEBUG_OBJECT (parse,
|
2010-09-29 14:12:42 +00:00
|
|
|
"seek position %" G_GINT64_FORMAT " in bytes: %" G_GINT64_FORMAT,
|
|
|
|
start_ts, seekpos);
|
2010-09-22 10:13:12 +00:00
|
|
|
GST_DEBUG_OBJECT (parse,
|
|
|
|
"seek stop %" G_GINT64_FORMAT " in bytes: %" G_GINT64_FORMAT,
|
|
|
|
seeksegment.stop, seekstop);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-11-18 11:35:46 +00:00
|
|
|
if (parse->priv->pad_mode == GST_PAD_MODE_PULL) {
|
2008-11-13 12:59:34 +00:00
|
|
|
gint64 last_stop;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "seek in PULL mode");
|
|
|
|
|
|
|
|
if (flush) {
|
|
|
|
if (parse->srcpad) {
|
2013-07-25 15:20:14 +00:00
|
|
|
GstEvent *fevent = gst_event_new_flush_start ();
|
2008-11-13 12:59:34 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "sending flush start");
|
2013-07-25 15:20:14 +00:00
|
|
|
|
|
|
|
gst_event_set_seqnum (fevent, seqnum);
|
|
|
|
|
|
|
|
gst_pad_push_event (parse->srcpad, gst_event_ref (fevent));
|
2010-11-16 16:04:35 +00:00
|
|
|
/* unlock upstream pull_range */
|
2013-07-25 15:20:14 +00:00
|
|
|
gst_pad_push_event (parse->sinkpad, fevent);
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gst_pad_pause_task (parse->sinkpad);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we should now be able to grab the streaming thread because we stopped it
|
|
|
|
* with the above flush/pause code */
|
|
|
|
GST_PAD_STREAM_LOCK (parse->sinkpad);
|
|
|
|
|
|
|
|
/* save current position */
|
2011-05-13 16:07:24 +00:00
|
|
|
last_stop = parse->segment.position;
|
2008-11-13 12:59:34 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "stopped streaming at %" G_GINT64_FORMAT,
|
|
|
|
last_stop);
|
|
|
|
|
2010-06-15 13:32:34 +00:00
|
|
|
/* now commit to new position */
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
/* prepare for streaming again */
|
|
|
|
if (flush) {
|
2013-07-25 15:20:14 +00:00
|
|
|
GstEvent *fevent = gst_event_new_flush_stop (TRUE);
|
2008-11-13 12:59:34 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "sending flush stop");
|
2013-07-25 15:20:14 +00:00
|
|
|
gst_event_set_seqnum (fevent, seqnum);
|
|
|
|
gst_pad_push_event (parse->srcpad, gst_event_ref (fevent));
|
|
|
|
gst_pad_push_event (parse->sinkpad, fevent);
|
2010-09-29 14:12:42 +00:00
|
|
|
gst_base_parse_clear_queues (parse);
|
2008-11-13 12:59:34 +00:00
|
|
|
} else {
|
2011-05-13 16:07:24 +00:00
|
|
|
/* keep track of our position */
|
|
|
|
seeksegment.base = gst_segment_to_running_time (&seeksegment,
|
|
|
|
seeksegment.format, parse->segment.position);
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (&parse->segment, &seeksegment, sizeof (GstSegment));
|
|
|
|
|
|
|
|
/* store the newsegment event so it can be sent from the streaming thread. */
|
|
|
|
/* This will be sent later in _loop() */
|
2012-03-05 13:41:12 +00:00
|
|
|
parse->priv->pending_segment = TRUE;
|
2013-07-25 15:20:14 +00:00
|
|
|
segment_event = gst_event_new_segment (&parse->segment);
|
|
|
|
gst_event_set_seqnum (segment_event, seqnum);
|
2012-03-08 09:19:52 +00:00
|
|
|
parse->priv->pending_events =
|
2013-07-25 15:20:14 +00:00
|
|
|
g_list_prepend (parse->priv->pending_events, segment_event);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "Created newseg format %d, "
|
|
|
|
"start = %" GST_TIME_FORMAT ", stop = %" GST_TIME_FORMAT
|
2012-12-11 15:46:01 +00:00
|
|
|
", time = %" GST_TIME_FORMAT, format,
|
2010-09-29 14:12:42 +00:00
|
|
|
GST_TIME_ARGS (parse->segment.start),
|
|
|
|
GST_TIME_ARGS (parse->segment.stop),
|
2012-12-11 15:46:01 +00:00
|
|
|
GST_TIME_ARGS (parse->segment.time));
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2010-11-17 13:30:09 +00:00
|
|
|
/* one last chance in pull mode to stay accurate;
|
|
|
|
* maybe scan and subclass can find where to go */
|
|
|
|
if (!accurate) {
|
|
|
|
gint64 scanpos;
|
2011-05-13 16:07:24 +00:00
|
|
|
GstClockTime ts = seeksegment.position;
|
2010-11-17 13:30:09 +00:00
|
|
|
|
|
|
|
gst_base_parse_locate_time (parse, &ts, &scanpos);
|
|
|
|
if (scanpos >= 0) {
|
|
|
|
accurate = TRUE;
|
|
|
|
seekpos = scanpos;
|
|
|
|
/* running collected index now consists of several intervals,
|
|
|
|
* so optimized check no longer possible */
|
|
|
|
parse->priv->index_last_valid = FALSE;
|
|
|
|
parse->priv->index_last_offset = 0;
|
|
|
|
parse->priv->index_last_ts = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
/* mark discont if we are going to stream from another position. */
|
2010-09-20 14:39:37 +00:00
|
|
|
if (seekpos != parse->priv->offset) {
|
2008-11-13 12:59:34 +00:00
|
|
|
GST_DEBUG_OBJECT (parse,
|
|
|
|
"mark DISCONT, we did a seek to another position");
|
2010-09-20 14:39:37 +00:00
|
|
|
parse->priv->offset = seekpos;
|
2010-09-29 14:12:42 +00:00
|
|
|
parse->priv->last_offset = seekpos;
|
2010-11-08 18:58:31 +00:00
|
|
|
parse->priv->seen_keyframe = FALSE;
|
2008-11-13 12:59:34 +00:00
|
|
|
parse->priv->discont = TRUE;
|
2012-09-26 04:23:52 +00:00
|
|
|
parse->priv->next_dts = start_ts;
|
2013-07-03 19:23:44 +00:00
|
|
|
parse->priv->next_pts = GST_CLOCK_TIME_NONE;
|
2012-09-03 06:32:50 +00:00
|
|
|
parse->priv->last_dts = GST_CLOCK_TIME_NONE;
|
|
|
|
parse->priv->last_pts = GST_CLOCK_TIME_NONE;
|
2010-09-20 14:39:37 +00:00
|
|
|
parse->priv->sync_offset = seekpos;
|
2010-09-22 10:13:12 +00:00
|
|
|
parse->priv->exact_position = accurate;
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Start streaming thread if paused */
|
|
|
|
gst_pad_start_task (parse->sinkpad,
|
2012-06-20 08:31:49 +00:00
|
|
|
(GstTaskFunction) gst_base_parse_loop, parse->sinkpad, NULL);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
GST_PAD_STREAM_UNLOCK (parse->sinkpad);
|
2011-01-11 11:05:13 +00:00
|
|
|
|
|
|
|
/* handled seek */
|
|
|
|
res = TRUE;
|
2008-11-13 12:59:34 +00:00
|
|
|
} else {
|
|
|
|
GstEvent *new_event;
|
2010-09-22 10:13:12 +00:00
|
|
|
GstBaseParseSeek *seek;
|
2011-08-25 21:26:08 +00:00
|
|
|
GstSeekFlags flags = (flush ? GST_SEEK_FLAG_FLUSH : GST_SEEK_FLAG_NONE);
|
2010-09-21 11:57:10 +00:00
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
/* The only thing we need to do in PUSH-mode is to send the
|
|
|
|
seek event (in bytes) to upstream. Segment / flush handling happens
|
|
|
|
in corresponding src event handlers */
|
|
|
|
GST_DEBUG_OBJECT (parse, "seek in PUSH mode");
|
2011-06-22 15:05:27 +00:00
|
|
|
if (seekstop >= 0 && seekstop <= seekpos)
|
2010-11-16 16:04:35 +00:00
|
|
|
seekstop = seekpos;
|
2011-08-25 21:26:08 +00:00
|
|
|
new_event = gst_event_new_seek (rate, GST_FORMAT_BYTES, flags,
|
2010-09-22 10:13:12 +00:00
|
|
|
GST_SEEK_TYPE_SET, seekpos, stop_type, seekstop);
|
2013-07-25 15:20:14 +00:00
|
|
|
gst_event_set_seqnum (new_event, seqnum);
|
2010-09-22 10:13:12 +00:00
|
|
|
|
|
|
|
/* store segment info so its precise details can be reconstructed when
|
|
|
|
* receiving newsegment;
|
|
|
|
* this matters for all details when accurate seeking,
|
|
|
|
* is most useful to preserve NONE stop time otherwise */
|
|
|
|
seek = g_new0 (GstBaseParseSeek, 1);
|
|
|
|
seek->segment = seeksegment;
|
|
|
|
seek->accurate = accurate;
|
|
|
|
seek->offset = seekpos;
|
|
|
|
seek->start_ts = start_ts;
|
|
|
|
GST_OBJECT_LOCK (parse);
|
|
|
|
/* less optimal, but preserves order */
|
|
|
|
parse->priv->pending_seeks =
|
|
|
|
g_slist_append (parse->priv->pending_seeks, seek);
|
|
|
|
GST_OBJECT_UNLOCK (parse);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
res = gst_pad_push_event (parse->sinkpad, new_event);
|
2010-09-22 10:13:12 +00:00
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
GST_OBJECT_LOCK (parse);
|
|
|
|
parse->priv->pending_seeks =
|
|
|
|
g_slist_remove (parse->priv->pending_seeks, seek);
|
|
|
|
GST_OBJECT_UNLOCK (parse);
|
|
|
|
g_free (seek);
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2012-08-10 21:58:56 +00:00
|
|
|
gst_event_unref (event);
|
2008-11-13 12:59:34 +00:00
|
|
|
return res;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2012-08-10 21:58:56 +00:00
|
|
|
negative_rate_pull_mode:
|
|
|
|
{
|
|
|
|
GST_FIXME_OBJECT (parse, "negative playback in pull mode needs fixing");
|
|
|
|
res = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
negative_rate:
|
|
|
|
{
|
2011-01-14 14:16:04 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "negative playback rates delegated upstream.");
|
2008-11-13 12:59:34 +00:00
|
|
|
res = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
wrong_type:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (parse, "unsupported seek type.");
|
|
|
|
res = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
2012-08-19 16:51:00 +00:00
|
|
|
no_convert_to_time:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (parse, "seek in %s format was requested, but subclass "
|
|
|
|
"couldn't convert that into TIME format", gst_format_get_name (format));
|
|
|
|
res = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
2010-09-21 11:57:10 +00:00
|
|
|
convert_failed:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (parse, "conversion TIME to BYTES failed.");
|
|
|
|
res = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 14:50:22 +00:00
|
|
|
/* Checks if bitrates are available from upstream tags so that we don't
|
2010-03-25 11:22:58 +00:00
|
|
|
* override them later
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_base_parse_handle_tag (GstBaseParse * parse, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstTagList *taglist = NULL;
|
|
|
|
guint tmp;
|
|
|
|
|
|
|
|
gst_event_parse_tag (event, &taglist);
|
|
|
|
|
2012-07-27 21:52:12 +00:00
|
|
|
/* We only care about stream tags here */
|
|
|
|
if (gst_tag_list_get_scope (taglist) != GST_TAG_SCOPE_STREAM)
|
|
|
|
return;
|
|
|
|
|
2010-10-25 12:13:51 +00:00
|
|
|
if (gst_tag_list_get_uint (taglist, GST_TAG_MINIMUM_BITRATE, &tmp)) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "upstream min bitrate %d", tmp);
|
2010-03-25 11:22:58 +00:00
|
|
|
parse->priv->post_min_bitrate = FALSE;
|
2010-10-25 12:13:51 +00:00
|
|
|
}
|
|
|
|
if (gst_tag_list_get_uint (taglist, GST_TAG_BITRATE, &tmp)) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "upstream avg bitrate %d", tmp);
|
2010-03-25 11:22:58 +00:00
|
|
|
parse->priv->post_avg_bitrate = FALSE;
|
2010-10-25 12:13:51 +00:00
|
|
|
}
|
|
|
|
if (gst_tag_list_get_uint (taglist, GST_TAG_MAXIMUM_BITRATE, &tmp)) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "upstream max bitrate %d", tmp);
|
2010-03-25 11:22:58 +00:00
|
|
|
parse->priv->post_max_bitrate = FALSE;
|
2010-10-25 12:13:51 +00:00
|
|
|
}
|
2010-03-25 11:22:58 +00:00
|
|
|
}
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-12-30 15:03:02 +00:00
|
|
|
#if 0
|
2010-09-21 08:57:04 +00:00
|
|
|
static void
|
|
|
|
gst_base_parse_set_index (GstElement * element, GstIndex * index)
|
|
|
|
{
|
|
|
|
GstBaseParse *parse = GST_BASE_PARSE (element);
|
|
|
|
|
2011-12-04 13:35:38 +00:00
|
|
|
GST_BASE_PARSE_INDEX_LOCK (parse);
|
2010-09-21 08:57:04 +00:00
|
|
|
if (parse->priv->index)
|
|
|
|
gst_object_unref (parse->priv->index);
|
|
|
|
if (index) {
|
|
|
|
parse->priv->index = gst_object_ref (index);
|
2011-04-19 12:05:53 +00:00
|
|
|
gst_index_get_writer_id (index, GST_OBJECT_CAST (element),
|
2010-09-21 08:57:04 +00:00
|
|
|
&parse->priv->index_id);
|
|
|
|
parse->priv->own_index = FALSE;
|
2011-04-19 12:05:53 +00:00
|
|
|
} else {
|
2010-09-21 08:57:04 +00:00
|
|
|
parse->priv->index = NULL;
|
2011-04-19 12:05:53 +00:00
|
|
|
}
|
2011-12-04 13:35:38 +00:00
|
|
|
GST_BASE_PARSE_INDEX_UNLOCK (parse);
|
2010-09-21 08:57:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstIndex *
|
|
|
|
gst_base_parse_get_index (GstElement * element)
|
|
|
|
{
|
|
|
|
GstBaseParse *parse = GST_BASE_PARSE (element);
|
|
|
|
GstIndex *result = NULL;
|
|
|
|
|
2011-12-04 13:35:38 +00:00
|
|
|
GST_BASE_PARSE_INDEX_LOCK (parse);
|
2010-09-21 08:57:04 +00:00
|
|
|
if (parse->priv->index)
|
|
|
|
result = gst_object_ref (parse->priv->index);
|
2011-12-04 13:35:38 +00:00
|
|
|
GST_BASE_PARSE_INDEX_UNLOCK (parse);
|
2010-09-21 08:57:04 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2011-12-30 15:03:02 +00:00
|
|
|
#endif
|
2010-09-21 08:57:04 +00:00
|
|
|
|
2010-09-21 07:59:56 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_base_parse_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstBaseParse *parse;
|
|
|
|
GstStateChangeReturn result;
|
|
|
|
|
|
|
|
parse = GST_BASE_PARSE (element);
|
|
|
|
|
2010-09-21 08:57:04 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
/* If this is our own index destroy it as the
|
|
|
|
* old entries might be wrong for the new stream */
|
2011-12-04 13:35:38 +00:00
|
|
|
GST_BASE_PARSE_INDEX_LOCK (parse);
|
2010-09-21 08:57:04 +00:00
|
|
|
if (parse->priv->own_index) {
|
|
|
|
gst_object_unref (parse->priv->index);
|
|
|
|
parse->priv->index = NULL;
|
|
|
|
parse->priv->own_index = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If no index was created, generate one */
|
|
|
|
if (G_UNLIKELY (!parse->priv->index)) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "no index provided creating our own");
|
|
|
|
|
2011-12-30 15:03:02 +00:00
|
|
|
parse->priv->index = g_object_new (gst_mem_index_get_type (), NULL);
|
2010-09-21 08:57:04 +00:00
|
|
|
gst_index_get_writer_id (parse->priv->index, GST_OBJECT (parse),
|
|
|
|
&parse->priv->index_id);
|
|
|
|
parse->priv->own_index = TRUE;
|
|
|
|
}
|
2011-12-04 13:35:38 +00:00
|
|
|
GST_BASE_PARSE_INDEX_UNLOCK (parse);
|
2010-09-21 08:57:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-21 07:59:56 +00:00
|
|
|
result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
gst_base_parse_reset (parse);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2013-02-12 00:51:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_base_parse_set_ts_at_offset:
|
|
|
|
* @parse: a #GstBaseParse
|
|
|
|
* @offset: offset into current buffer
|
|
|
|
*
|
|
|
|
* This function should only be called from a @handle_frame implementation.
|
|
|
|
*
|
|
|
|
* GstBaseParse creates initial timestamps for frames by using the last
|
|
|
|
* timestamp seen in the stream before the frame starts. In certain
|
|
|
|
* cases, the correct timestamps will occur in the stream after the
|
|
|
|
* start of the frame, but before the start of the actual picture data.
|
|
|
|
* This function can be used to set the timestamps based on the offset
|
|
|
|
* into the frame data that the picture starts.
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_base_parse_set_ts_at_offset (GstBaseParse * parse, gsize offset)
|
|
|
|
{
|
|
|
|
GstClockTime pts, dts;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_BASE_PARSE (parse));
|
|
|
|
g_return_if_fail (offset >= 0);
|
|
|
|
|
|
|
|
pts = gst_adapter_prev_pts_at_offset (parse->priv->adapter, offset, NULL);
|
|
|
|
dts = gst_adapter_prev_dts_at_offset (parse->priv->adapter, offset, NULL);
|
|
|
|
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (pts) || !GST_CLOCK_TIME_IS_VALID (dts)) {
|
|
|
|
GST_DEBUG_OBJECT (parse,
|
|
|
|
"offset adapter timestamps dts=%" GST_TIME_FORMAT " pts=%"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (dts), GST_TIME_ARGS (pts));
|
|
|
|
}
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (pts) && (parse->priv->prev_pts != pts))
|
|
|
|
parse->priv->prev_pts = parse->priv->next_pts = pts;
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (dts) && (parse->priv->prev_dts != dts))
|
|
|
|
parse->priv->prev_dts = parse->priv->next_dts = dts;
|
|
|
|
}
|