2004-06-17 13:45:50 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* 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 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2004-06-17 13:45:50 +00:00
|
|
|
*/
|
|
|
|
|
2009-12-15 18:50:56 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-audiorate
|
2017-01-23 19:36:11 +00:00
|
|
|
* @title: audiorate
|
2009-12-15 18:50:56 +00:00
|
|
|
* @see_also: #GstVideoRate
|
|
|
|
*
|
|
|
|
* This element takes an incoming stream of timestamped raw audio frames and
|
|
|
|
* produces a perfect stream by inserting or dropping samples as needed.
|
|
|
|
*
|
|
|
|
* This operation may be of use to link to elements that require or otherwise
|
|
|
|
* implicitly assume a perfect stream as they do not store timestamps,
|
|
|
|
* but derive this by some means (e.g. bitrate for some AVI cases).
|
|
|
|
*
|
|
|
|
* The properties #GstAudioRate:in, #GstAudioRate:out, #GstAudioRate:add
|
|
|
|
* and #GstAudioRate:drop can be read to obtain information about number of
|
2009-12-15 17:41:38 +00:00
|
|
|
* input samples, output samples, dropped samples (i.e. the number of unused
|
|
|
|
* input samples) and inserted samples (i.e. the number of samples added to
|
|
|
|
* stream).
|
2009-12-15 18:50:56 +00:00
|
|
|
*
|
|
|
|
* When the #GstAudioRate:silent property is set to FALSE, a GObject property
|
|
|
|
* notification will be emitted whenever one of the #GstAudioRate:add or
|
|
|
|
* #GstAudioRate:drop values changes.
|
|
|
|
* This can potentially cause performance degradation.
|
|
|
|
* Note that property notification will happen from the streaming thread, so
|
|
|
|
* applications should be prepared for this.
|
|
|
|
*
|
2009-12-15 17:41:38 +00:00
|
|
|
* If the #GstAudioRate:tolerance property is non-zero, and an incoming buffer's
|
|
|
|
* timestamp deviates less than the property indicates from what would make a
|
|
|
|
* 'perfect time', then no samples will be added or dropped.
|
|
|
|
* Note that the output is still guaranteed to be a perfect stream, which means
|
|
|
|
* that the incoming data is then simply shifted (by less than the indicated
|
|
|
|
* tolerance) to a perfect time.
|
|
|
|
*
|
2017-01-23 19:36:11 +00:00
|
|
|
* ## Example pipelines
|
2009-12-15 18:50:56 +00:00
|
|
|
* |[
|
2015-05-09 21:33:26 +00:00
|
|
|
* gst-launch-1.0 -v autoaudiosrc ! audiorate ! audioconvert ! wavenc ! filesink location=alsa.wav
|
2017-01-23 19:36:11 +00:00
|
|
|
* ]|
|
|
|
|
* Capture audio from the sound card and turn it into a perfect stream
|
2009-12-15 18:50:56 +00:00
|
|
|
* for saving in a raw audio file.
|
2015-05-09 21:33:26 +00:00
|
|
|
* |[
|
|
|
|
* gst-launch-1.0 -v uridecodebin uri=file:///path/to/audio.file ! audiorate ! audioconvert ! wavenc ! filesink location=alsa.wav
|
2017-01-23 19:36:11 +00:00
|
|
|
* ]|
|
|
|
|
* Decodes an audio file and transforms it into a perfect stream for saving
|
2015-05-09 21:33:26 +00:00
|
|
|
* in a raw audio WAV file. Without the audio rate, the timing might not be
|
|
|
|
* preserved correctly in the WAV file in case the decoded stream is jittery
|
|
|
|
* or there are samples missing.
|
2017-01-23 19:36:11 +00:00
|
|
|
*
|
2009-12-15 18:50:56 +00:00
|
|
|
*/
|
|
|
|
|
2004-06-17 13:45:50 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2007-09-17 17:24:55 +00:00
|
|
|
|
2004-06-17 13:45:50 +00:00
|
|
|
#include <string.h>
|
2007-09-17 17:24:55 +00:00
|
|
|
#include <stdlib.h>
|
2004-06-17 13:45:50 +00:00
|
|
|
|
2009-12-15 15:52:44 +00:00
|
|
|
#include "gstaudiorate.h"
|
2004-06-17 13:45:50 +00:00
|
|
|
|
2006-01-10 15:47:48 +00:00
|
|
|
#define GST_CAT_DEFAULT audio_rate_debug
|
2006-05-23 20:38:56 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (audio_rate_debug);
|
2006-01-10 15:47:48 +00:00
|
|
|
|
2005-12-01 01:12:55 +00:00
|
|
|
/* GstAudioRate signals and args */
|
2004-06-17 13:45:50 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2009-12-15 17:41:38 +00:00
|
|
|
#define DEFAULT_SILENT TRUE
|
2012-09-09 14:58:36 +00:00
|
|
|
#define DEFAULT_TOLERANCE (40 * GST_MSECOND)
|
2011-02-21 11:40:36 +00:00
|
|
|
#define DEFAULT_SKIP_TO_FIRST FALSE
|
2004-06-23 11:06:10 +00:00
|
|
|
|
2004-06-17 13:45:50 +00:00
|
|
|
enum
|
|
|
|
{
|
2015-04-27 10:26:10 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_IN,
|
|
|
|
PROP_OUT,
|
|
|
|
PROP_ADD,
|
|
|
|
PROP_DROP,
|
|
|
|
PROP_SILENT,
|
|
|
|
PROP_TOLERANCE,
|
|
|
|
PROP_SKIP_TO_FIRST
|
2004-06-17 13:45:50 +00:00
|
|
|
};
|
|
|
|
|
2005-12-01 01:12:55 +00:00
|
|
|
static GstStaticPadTemplate gst_audio_rate_src_template =
|
2011-08-18 17:15:03 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2004-06-17 13:45:50 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2011-12-31 13:31:08 +00:00
|
|
|
GST_STATIC_CAPS (GST_AUDIO_CAPS_MAKE (GST_AUDIO_FORMATS_ALL)
|
|
|
|
", layout = (string) { interleaved, non-interleaved }")
|
2004-06-17 13:45:50 +00:00
|
|
|
);
|
|
|
|
|
2005-12-01 01:12:55 +00:00
|
|
|
static GstStaticPadTemplate gst_audio_rate_sink_template =
|
2011-08-18 17:15:03 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
2004-06-17 13:45:50 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2011-12-31 13:31:08 +00:00
|
|
|
GST_STATIC_CAPS (GST_AUDIO_CAPS_MAKE (GST_AUDIO_FORMATS_ALL)
|
|
|
|
", layout = (string) { interleaved, non-interleaved }")
|
2004-06-17 13:45:50 +00:00
|
|
|
);
|
|
|
|
|
2011-11-17 11:48:25 +00:00
|
|
|
static gboolean gst_audio_rate_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
|
|
|
static gboolean gst_audio_rate_src_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
|
|
|
static GstFlowReturn gst_audio_rate_chain (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buf);
|
2004-06-17 13:45:50 +00:00
|
|
|
|
2005-12-01 01:12:55 +00:00
|
|
|
static void gst_audio_rate_set_property (GObject * object,
|
2004-06-17 13:45:50 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
2005-12-01 01:12:55 +00:00
|
|
|
static void gst_audio_rate_get_property (GObject * object,
|
2004-06-17 13:45:50 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
|
2005-12-01 01:12:55 +00:00
|
|
|
static GstStateChangeReturn gst_audio_rate_change_state (GstElement * element,
|
2005-09-02 15:43:18 +00:00
|
|
|
GstStateChange transition);
|
2004-06-17 13:45:50 +00:00
|
|
|
|
2005-12-01 01:12:55 +00:00
|
|
|
/*static guint gst_audio_rate_signals[LAST_SIGNAL] = { 0 }; */
|
2004-06-17 13:45:50 +00:00
|
|
|
|
2010-10-07 19:54:32 +00:00
|
|
|
static GParamSpec *pspec_drop = NULL;
|
|
|
|
static GParamSpec *pspec_add = NULL;
|
|
|
|
|
2011-04-19 09:35:53 +00:00
|
|
|
#define gst_audio_rate_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstAudioRate, gst_audio_rate, GST_TYPE_ELEMENT);
|
2021-03-29 12:06:00 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (audiorate, "audiorate", GST_RANK_NONE,
|
|
|
|
GST_TYPE_AUDIO_RATE, GST_DEBUG_CATEGORY_INIT (audio_rate_debug, "audiorate",
|
|
|
|
0, "AudioRate stream fixer"));
|
2009-10-22 11:40:01 +00:00
|
|
|
|
2004-06-17 13:45:50 +00:00
|
|
|
static void
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_audio_rate_class_init (GstAudioRateClass * klass)
|
2004-06-17 13:45:50 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
2005-12-01 01:12:55 +00:00
|
|
|
object_class->set_property = gst_audio_rate_set_property;
|
|
|
|
object_class->get_property = gst_audio_rate_get_property;
|
2005-05-06 03:32:51 +00:00
|
|
|
|
2015-04-27 10:26:10 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_IN,
|
2004-06-17 13:45:50 +00:00
|
|
|
g_param_spec_uint64 ("in", "In",
|
2008-03-22 15:00:53 +00:00
|
|
|
"Number of input samples", 0, G_MAXUINT64, 0,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2015-04-27 10:26:10 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_OUT,
|
2008-03-22 15:00:53 +00:00
|
|
|
g_param_spec_uint64 ("out", "Out", "Number of output samples", 0,
|
|
|
|
G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2010-10-07 19:54:32 +00:00
|
|
|
pspec_add = g_param_spec_uint64 ("add", "Add", "Number of added samples",
|
|
|
|
0, G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
2015-04-27 10:26:10 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_ADD, pspec_add);
|
2010-10-07 19:54:32 +00:00
|
|
|
pspec_drop = g_param_spec_uint64 ("drop", "Drop", "Number of dropped samples",
|
|
|
|
0, G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
2015-04-27 10:26:10 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_DROP, pspec_drop);
|
|
|
|
g_object_class_install_property (object_class, PROP_SILENT,
|
2004-06-23 11:06:10 +00:00
|
|
|
g_param_spec_boolean ("silent", "silent",
|
2008-03-22 15:00:53 +00:00
|
|
|
"Don't emit notify for dropped and duplicated frames", DEFAULT_SILENT,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-12-21 17:45:58 +00:00
|
|
|
/**
|
2013-11-16 13:06:37 +00:00
|
|
|
* GstAudioRate:tolerance:
|
2009-12-21 17:45:58 +00:00
|
|
|
*
|
|
|
|
* The difference between incoming timestamp and next timestamp must exceed
|
|
|
|
* the given value for audiorate to add or drop samples.
|
2013-11-16 13:06:37 +00:00
|
|
|
*/
|
2015-04-27 10:26:10 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_TOLERANCE,
|
2009-12-15 17:41:38 +00:00
|
|
|
g_param_spec_uint64 ("tolerance", "tolerance",
|
|
|
|
"Only act if timestamp jitter/imperfection exceeds indicated tolerance (ns)",
|
|
|
|
0, G_MAXUINT64, DEFAULT_TOLERANCE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2004-06-23 11:06:10 +00:00
|
|
|
|
2011-02-21 11:40:36 +00:00
|
|
|
/**
|
|
|
|
* GstAudioRate:skip-to-first:
|
|
|
|
*
|
|
|
|
* Don't produce buffers before the first one we receive.
|
2013-11-16 13:06:37 +00:00
|
|
|
*/
|
2015-04-27 10:26:10 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_SKIP_TO_FIRST,
|
2011-02-21 11:40:36 +00:00
|
|
|
g_param_spec_boolean ("skip-to-first", "Skip to first buffer",
|
|
|
|
"Don't produce buffers before the first one we receive",
|
|
|
|
DEFAULT_SKIP_TO_FIRST, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-04-09 23:45:16 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class,
|
2011-04-19 09:35:53 +00:00
|
|
|
"Audio rate adjuster", "Filter/Effect/Audio",
|
|
|
|
"Drops/duplicates/adjusts timestamps on audio samples to make a perfect stream",
|
|
|
|
"Wim Taymans <wim@fluendo.com>");
|
|
|
|
|
2016-03-03 07:46:24 +00:00
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&gst_audio_rate_sink_template);
|
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&gst_audio_rate_src_template);
|
2011-04-19 09:35:53 +00:00
|
|
|
|
2005-12-01 01:12:55 +00:00
|
|
|
element_class->change_state = gst_audio_rate_change_state;
|
2004-06-17 13:45:50 +00:00
|
|
|
}
|
|
|
|
|
2006-08-28 16:08:18 +00:00
|
|
|
static void
|
|
|
|
gst_audio_rate_reset (GstAudioRate * audiorate)
|
|
|
|
{
|
|
|
|
audiorate->next_offset = -1;
|
2006-11-16 12:55:08 +00:00
|
|
|
audiorate->next_ts = -1;
|
2006-08-28 16:08:18 +00:00
|
|
|
audiorate->discont = TRUE;
|
2006-09-28 10:49:56 +00:00
|
|
|
gst_segment_init (&audiorate->sink_segment, GST_FORMAT_UNDEFINED);
|
|
|
|
gst_segment_init (&audiorate->src_segment, GST_FORMAT_TIME);
|
2006-08-28 16:08:18 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (audiorate, "handle reset");
|
|
|
|
}
|
|
|
|
|
2005-05-05 14:57:20 +00:00
|
|
|
static gboolean
|
2011-06-07 08:58:27 +00:00
|
|
|
gst_audio_rate_setcaps (GstAudioRate * audiorate, GstCaps * caps)
|
2004-06-17 13:45:50 +00:00
|
|
|
{
|
2011-08-18 17:15:03 +00:00
|
|
|
GstAudioInfo info;
|
2019-11-07 13:00:03 +00:00
|
|
|
gint prev_rate = 0;
|
2004-06-17 13:45:50 +00:00
|
|
|
|
2011-08-18 17:15:03 +00:00
|
|
|
if (!gst_audio_info_from_caps (&info, caps))
|
2006-08-28 16:08:18 +00:00
|
|
|
goto wrong_caps;
|
2005-05-05 14:57:20 +00:00
|
|
|
|
2019-11-07 13:00:03 +00:00
|
|
|
prev_rate = audiorate->info.rate;
|
2011-08-18 17:15:03 +00:00
|
|
|
audiorate->info = info;
|
2006-08-28 16:08:18 +00:00
|
|
|
|
2019-11-07 13:00:03 +00:00
|
|
|
if (audiorate->next_offset >= 0 && prev_rate > 0 && prev_rate != info.rate) {
|
|
|
|
GST_DEBUG_OBJECT (audiorate,
|
|
|
|
"rate changed from %d to %d", prev_rate, info.rate);
|
|
|
|
|
|
|
|
/* calculate next_offset based on new rate value */
|
|
|
|
audiorate->next_offset =
|
|
|
|
gst_util_uint64_scale_int_round (audiorate->next_ts,
|
|
|
|
info.rate, GST_SECOND);
|
|
|
|
}
|
|
|
|
|
2011-06-07 08:58:27 +00:00
|
|
|
return TRUE;
|
2006-08-28 16:08:18 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
wrong_caps:
|
|
|
|
{
|
2011-08-18 17:15:03 +00:00
|
|
|
GST_DEBUG_OBJECT (audiorate, "could not parse caps");
|
2011-06-07 08:58:27 +00:00
|
|
|
return FALSE;
|
2006-08-28 16:08:18 +00:00
|
|
|
}
|
2004-06-17 13:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_audio_rate_init (GstAudioRate * audiorate)
|
2004-06-17 13:45:50 +00:00
|
|
|
{
|
|
|
|
audiorate->sinkpad =
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_pad_new_from_static_template (&gst_audio_rate_sink_template, "sink");
|
2006-08-28 16:08:18 +00:00
|
|
|
gst_pad_set_event_function (audiorate->sinkpad, gst_audio_rate_sink_event);
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_pad_set_chain_function (audiorate->sinkpad, gst_audio_rate_chain);
|
2011-11-15 15:30:38 +00:00
|
|
|
GST_PAD_SET_PROXY_CAPS (audiorate->sinkpad);
|
2006-08-28 16:08:18 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (audiorate), audiorate->sinkpad);
|
2004-06-17 13:45:50 +00:00
|
|
|
|
|
|
|
audiorate->srcpad =
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_pad_new_from_static_template (&gst_audio_rate_src_template, "src");
|
2006-08-28 16:08:18 +00:00
|
|
|
gst_pad_set_event_function (audiorate->srcpad, gst_audio_rate_src_event);
|
2011-11-15 15:30:38 +00:00
|
|
|
GST_PAD_SET_PROXY_CAPS (audiorate->srcpad);
|
2006-08-28 16:08:18 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (audiorate), audiorate->srcpad);
|
2004-06-17 13:45:50 +00:00
|
|
|
|
|
|
|
audiorate->in = 0;
|
|
|
|
audiorate->out = 0;
|
|
|
|
audiorate->drop = 0;
|
|
|
|
audiorate->add = 0;
|
2004-06-23 11:06:10 +00:00
|
|
|
audiorate->silent = DEFAULT_SILENT;
|
2009-12-15 17:41:38 +00:00
|
|
|
audiorate->tolerance = DEFAULT_TOLERANCE;
|
2004-06-17 13:45:50 +00:00
|
|
|
}
|
|
|
|
|
2009-12-14 17:47:27 +00:00
|
|
|
static void
|
|
|
|
gst_audio_rate_fill_to_time (GstAudioRate * audiorate, GstClockTime time)
|
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (audiorate, "next_ts: %" GST_TIME_FORMAT
|
|
|
|
", filling to %" GST_TIME_FORMAT, GST_TIME_ARGS (audiorate->next_ts),
|
|
|
|
GST_TIME_ARGS (time));
|
|
|
|
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (time) ||
|
|
|
|
!GST_CLOCK_TIME_IS_VALID (audiorate->next_ts))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* feed an empty buffer to chain with the given timestamp,
|
|
|
|
* it will take care of filling */
|
|
|
|
buf = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buf) = time;
|
2011-11-17 11:48:25 +00:00
|
|
|
gst_audio_rate_chain (audiorate->sinkpad, GST_OBJECT_CAST (audiorate), buf);
|
2009-12-14 17:47:27 +00:00
|
|
|
}
|
|
|
|
|
2006-08-28 16:08:18 +00:00
|
|
|
static gboolean
|
2011-11-17 11:48:25 +00:00
|
|
|
gst_audio_rate_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2006-08-28 16:08:18 +00:00
|
|
|
{
|
|
|
|
gboolean res;
|
|
|
|
GstAudioRate *audiorate;
|
|
|
|
|
2011-11-17 11:48:25 +00:00
|
|
|
audiorate = GST_AUDIO_RATE (parent);
|
2006-08-28 16:08:18 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2011-06-07 08:58:27 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
if ((res = gst_audio_rate_setcaps (audiorate, caps))) {
|
|
|
|
res = gst_pad_push_event (audiorate->srcpad, event);
|
|
|
|
} else {
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-08-28 16:08:18 +00:00
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
GST_DEBUG_OBJECT (audiorate, "handling FLUSH_STOP");
|
|
|
|
gst_audio_rate_reset (audiorate);
|
|
|
|
res = gst_pad_push_event (audiorate->srcpad, event);
|
|
|
|
break;
|
2011-05-16 11:48:11 +00:00
|
|
|
case GST_EVENT_SEGMENT:
|
2006-08-28 16:08:18 +00:00
|
|
|
{
|
2011-05-18 15:23:18 +00:00
|
|
|
gst_event_copy_segment (event, &audiorate->sink_segment);
|
2006-08-28 16:08:18 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (audiorate, "handle NEWSEGMENT");
|
2011-05-16 11:48:11 +00:00
|
|
|
#if 0
|
2009-12-14 17:47:27 +00:00
|
|
|
/* FIXME: bad things will likely happen if rate < 0 ... */
|
2006-08-28 16:08:18 +00:00
|
|
|
if (!update) {
|
|
|
|
/* a new segment starts. We need to figure out what will be the next
|
|
|
|
* sample offset. We mark the offsets as invalid so that the _chain
|
|
|
|
* function will perform this calculation. */
|
2009-12-14 17:47:27 +00:00
|
|
|
gst_audio_rate_fill_to_time (audiorate, audiorate->src_segment.stop);
|
2011-05-16 11:48:11 +00:00
|
|
|
#endif
|
2006-08-28 16:08:18 +00:00
|
|
|
audiorate->next_offset = -1;
|
2006-11-16 12:55:08 +00:00
|
|
|
audiorate->next_ts = -1;
|
2011-05-16 11:48:11 +00:00
|
|
|
#if 0
|
2009-12-14 17:47:27 +00:00
|
|
|
} else {
|
|
|
|
gst_audio_rate_fill_to_time (audiorate, audiorate->src_segment.start);
|
2006-08-28 16:08:18 +00:00
|
|
|
}
|
2011-05-16 11:48:11 +00:00
|
|
|
#endif
|
2006-08-28 16:08:18 +00:00
|
|
|
|
2006-09-28 10:49:56 +00:00
|
|
|
GST_DEBUG_OBJECT (audiorate, "updated segment: %" GST_SEGMENT_FORMAT,
|
|
|
|
&audiorate->sink_segment);
|
|
|
|
|
2011-05-16 11:48:11 +00:00
|
|
|
if (audiorate->sink_segment.format == GST_FORMAT_TIME) {
|
2006-09-28 10:49:56 +00:00
|
|
|
/* TIME formats can be copied to src and forwarded */
|
|
|
|
res = gst_pad_push_event (audiorate->srcpad, event);
|
2011-05-16 11:48:11 +00:00
|
|
|
gst_segment_copy_into (&audiorate->sink_segment,
|
|
|
|
&audiorate->src_segment);
|
2006-09-28 10:49:56 +00:00
|
|
|
} else {
|
|
|
|
/* other formats will be handled in the _chain function */
|
|
|
|
gst_event_unref (event);
|
|
|
|
res = TRUE;
|
|
|
|
}
|
2006-08-28 16:08:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_EOS:
|
2010-09-01 09:37:37 +00:00
|
|
|
/* Fill segment until the end */
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (audiorate->src_segment.stop))
|
|
|
|
gst_audio_rate_fill_to_time (audiorate, audiorate->src_segment.stop);
|
2006-09-28 10:49:56 +00:00
|
|
|
res = gst_pad_push_event (audiorate->srcpad, event);
|
|
|
|
break;
|
2013-07-28 21:38:17 +00:00
|
|
|
case GST_EVENT_GAP:
|
2014-12-09 02:18:37 +00:00
|
|
|
{
|
|
|
|
/* Fill until end of gap */
|
|
|
|
GstClockTime timestamp, duration;
|
|
|
|
gst_event_parse_gap (event, ×tamp, &duration);
|
2013-07-28 21:38:17 +00:00
|
|
|
gst_event_unref (event);
|
2014-12-09 02:18:37 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (duration))
|
|
|
|
timestamp += duration;
|
|
|
|
gst_audio_rate_fill_to_time (audiorate, timestamp);
|
|
|
|
}
|
2013-07-28 21:38:17 +00:00
|
|
|
res = TRUE;
|
|
|
|
break;
|
2014-12-09 02:18:37 +00:00
|
|
|
}
|
2006-08-28 16:08:18 +00:00
|
|
|
default:
|
2012-02-03 08:56:56 +00:00
|
|
|
res = gst_pad_event_default (pad, parent, event);
|
2006-08-28 16:08:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-17 11:48:25 +00:00
|
|
|
gst_audio_rate_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2006-08-28 16:08:18 +00:00
|
|
|
{
|
|
|
|
gboolean res;
|
|
|
|
GstAudioRate *audiorate;
|
|
|
|
|
2011-11-17 11:48:25 +00:00
|
|
|
audiorate = GST_AUDIO_RATE (parent);
|
2006-08-28 16:08:18 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
default:
|
|
|
|
res = gst_pad_push_event (audiorate->sinkpad, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-09-28 10:49:56 +00:00
|
|
|
static gboolean
|
|
|
|
gst_audio_rate_convert (GstAudioRate * audiorate,
|
2011-05-16 11:48:11 +00:00
|
|
|
GstFormat src_fmt, guint64 src_val, GstFormat dest_fmt, guint64 * dest_val)
|
2006-09-28 10:49:56 +00:00
|
|
|
{
|
2011-09-06 10:06:39 +00:00
|
|
|
return gst_audio_info_convert (&audiorate->info, src_fmt, src_val, dest_fmt,
|
|
|
|
(gint64 *) dest_val);
|
2006-09-28 10:49:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_audio_rate_convert_segments (GstAudioRate * audiorate)
|
|
|
|
{
|
|
|
|
GstFormat src_fmt, dst_fmt;
|
|
|
|
|
|
|
|
src_fmt = audiorate->sink_segment.format;
|
|
|
|
dst_fmt = audiorate->src_segment.format;
|
|
|
|
|
|
|
|
#define CONVERT_VAL(field) gst_audio_rate_convert (audiorate, \
|
|
|
|
src_fmt, audiorate->sink_segment.field, \
|
|
|
|
dst_fmt, &audiorate->src_segment.field);
|
|
|
|
|
|
|
|
audiorate->sink_segment.rate = audiorate->src_segment.rate;
|
|
|
|
audiorate->sink_segment.flags = audiorate->src_segment.flags;
|
|
|
|
audiorate->sink_segment.applied_rate = audiorate->src_segment.applied_rate;
|
|
|
|
CONVERT_VAL (start);
|
|
|
|
CONVERT_VAL (stop);
|
|
|
|
CONVERT_VAL (time);
|
2011-05-16 11:48:11 +00:00
|
|
|
CONVERT_VAL (base);
|
|
|
|
CONVERT_VAL (position);
|
2006-09-28 10:49:56 +00:00
|
|
|
#undef CONVERT_VAL
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-10-07 19:54:32 +00:00
|
|
|
static void
|
|
|
|
gst_audio_rate_notify_drop (GstAudioRate * audiorate)
|
|
|
|
{
|
|
|
|
g_object_notify_by_pspec ((GObject *) audiorate, pspec_drop);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_audio_rate_notify_add (GstAudioRate * audiorate)
|
|
|
|
{
|
|
|
|
g_object_notify_by_pspec ((GObject *) audiorate, pspec_add);
|
|
|
|
}
|
|
|
|
|
2005-05-05 14:57:20 +00:00
|
|
|
static GstFlowReturn
|
2011-11-17 11:48:25 +00:00
|
|
|
gst_audio_rate_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
|
2004-06-17 13:45:50 +00:00
|
|
|
{
|
2005-12-01 01:12:55 +00:00
|
|
|
GstAudioRate *audiorate;
|
2009-12-15 18:29:29 +00:00
|
|
|
GstClockTime in_time;
|
2006-09-28 10:49:56 +00:00
|
|
|
guint64 in_offset, in_offset_end, in_samples;
|
2006-01-10 15:47:48 +00:00
|
|
|
guint in_size;
|
2005-11-26 11:34:15 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2009-12-15 17:41:38 +00:00
|
|
|
GstClockTimeDiff diff;
|
2011-08-18 17:15:03 +00:00
|
|
|
gint rate, bpf;
|
2018-02-12 12:45:44 +00:00
|
|
|
GstAudioMeta *meta;
|
2004-06-17 13:45:50 +00:00
|
|
|
|
2011-11-17 11:48:25 +00:00
|
|
|
audiorate = GST_AUDIO_RATE (parent);
|
2004-06-17 13:45:50 +00:00
|
|
|
|
2011-08-18 17:15:03 +00:00
|
|
|
rate = GST_AUDIO_INFO_RATE (&audiorate->info);
|
|
|
|
bpf = GST_AUDIO_INFO_BPF (&audiorate->info);
|
|
|
|
|
2006-09-28 10:49:56 +00:00
|
|
|
/* need to be negotiated now */
|
2011-08-18 17:15:03 +00:00
|
|
|
if (bpf == 0)
|
2006-08-28 16:08:18 +00:00
|
|
|
goto not_negotiated;
|
|
|
|
|
2006-09-28 10:49:56 +00:00
|
|
|
/* we have a new pending segment */
|
|
|
|
if (audiorate->next_offset == -1) {
|
2006-08-28 16:08:18 +00:00
|
|
|
gint64 pos;
|
|
|
|
|
2006-09-28 10:49:56 +00:00
|
|
|
/* update the TIME segment */
|
|
|
|
gst_audio_rate_convert_segments (audiorate);
|
|
|
|
|
2006-08-28 16:08:18 +00:00
|
|
|
/* first buffer, we are negotiated and we have a segment, calculate the
|
2006-09-28 10:49:56 +00:00
|
|
|
* current expected offsets based on the segment.start, which is the first
|
2006-08-28 16:08:18 +00:00
|
|
|
* media time of the segment and should match the media time of the first
|
|
|
|
* buffer in that segment, which is the offset expressed in DEFAULT units.
|
|
|
|
*/
|
2006-09-28 10:49:56 +00:00
|
|
|
/* convert first timestamp of segment to sample position */
|
2014-12-02 20:58:00 +00:00
|
|
|
pos = gst_util_uint64_scale_int_round (audiorate->src_segment.start,
|
2011-08-18 17:15:03 +00:00
|
|
|
GST_AUDIO_INFO_RATE (&audiorate->info), GST_SECOND);
|
2006-09-28 10:49:56 +00:00
|
|
|
|
2006-08-28 16:08:18 +00:00
|
|
|
GST_DEBUG_OBJECT (audiorate, "resync to offset %" G_GINT64_FORMAT, pos);
|
2006-09-28 10:49:56 +00:00
|
|
|
|
2009-12-14 20:17:57 +00:00
|
|
|
/* resyncing is a discont */
|
|
|
|
audiorate->discont = TRUE;
|
|
|
|
|
2006-08-28 16:08:18 +00:00
|
|
|
audiorate->next_offset = pos;
|
2014-12-02 20:58:00 +00:00
|
|
|
audiorate->next_ts =
|
|
|
|
gst_util_uint64_scale_int_round (audiorate->next_offset, GST_SECOND,
|
|
|
|
GST_AUDIO_INFO_RATE (&audiorate->info));
|
2011-02-21 11:40:36 +00:00
|
|
|
|
|
|
|
if (audiorate->skip_to_first && GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
|
|
|
|
GST_DEBUG_OBJECT (audiorate, "but skipping to first buffer instead");
|
2014-12-02 20:58:00 +00:00
|
|
|
pos = gst_util_uint64_scale_int_round (GST_BUFFER_TIMESTAMP (buf),
|
2011-08-18 17:15:03 +00:00
|
|
|
GST_AUDIO_INFO_RATE (&audiorate->info), GST_SECOND);
|
2011-02-21 11:40:36 +00:00
|
|
|
GST_DEBUG_OBJECT (audiorate, "so resync to offset %" G_GINT64_FORMAT,
|
|
|
|
pos);
|
|
|
|
audiorate->next_offset = pos;
|
|
|
|
audiorate->next_ts = GST_BUFFER_TIMESTAMP (buf);
|
|
|
|
}
|
2006-08-28 16:08:18 +00:00
|
|
|
}
|
|
|
|
|
2004-06-17 13:45:50 +00:00
|
|
|
in_time = GST_BUFFER_TIMESTAMP (buf);
|
2007-05-03 13:16:21 +00:00
|
|
|
if (in_time == GST_CLOCK_TIME_NONE) {
|
|
|
|
GST_DEBUG_OBJECT (audiorate, "no timestamp, using expected next time");
|
|
|
|
in_time = audiorate->next_ts;
|
|
|
|
}
|
|
|
|
|
2018-02-12 12:45:44 +00:00
|
|
|
meta = gst_buffer_get_audio_meta (buf);
|
2011-03-27 14:35:28 +00:00
|
|
|
in_size = gst_buffer_get_size (buf);
|
2018-02-12 12:45:44 +00:00
|
|
|
in_samples = meta ? meta->samples : in_size / bpf;
|
2012-01-27 16:55:34 +00:00
|
|
|
audiorate->in += in_samples;
|
2006-09-28 10:49:56 +00:00
|
|
|
|
|
|
|
/* calculate the buffer offset */
|
2019-11-07 12:42:25 +00:00
|
|
|
in_offset = gst_util_uint64_scale_int_round (in_time, rate, GST_SECOND);
|
2006-09-28 10:49:56 +00:00
|
|
|
in_offset_end = in_offset + in_samples;
|
2004-06-17 13:45:50 +00:00
|
|
|
|
2006-01-10 15:47:48 +00:00
|
|
|
GST_LOG_OBJECT (audiorate,
|
2009-12-15 18:29:29 +00:00
|
|
|
"in_time:%" GST_TIME_FORMAT ", in_duration:%" GST_TIME_FORMAT
|
2009-10-09 12:20:47 +00:00
|
|
|
", in_size:%u, in_offset:%" G_GUINT64_FORMAT ", in_offset_end:%"
|
2010-05-26 06:51:09 +00:00
|
|
|
G_GUINT64_FORMAT ", ->next_offset:%" G_GUINT64_FORMAT ", ->next_ts:%"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (in_time),
|
2011-08-18 17:15:03 +00:00
|
|
|
GST_TIME_ARGS (GST_FRAMES_TO_CLOCK_TIME (in_samples, rate)),
|
2010-05-26 06:51:09 +00:00
|
|
|
in_size, in_offset, in_offset_end, audiorate->next_offset,
|
|
|
|
GST_TIME_ARGS (audiorate->next_ts));
|
2004-06-23 11:06:10 +00:00
|
|
|
|
2009-12-15 17:41:38 +00:00
|
|
|
diff = in_time - audiorate->next_ts;
|
|
|
|
if (diff <= (GstClockTimeDiff) audiorate->tolerance &&
|
|
|
|
diff >= (GstClockTimeDiff) - audiorate->tolerance) {
|
|
|
|
/* buffer time close enough to expected time,
|
|
|
|
* so produce a perfect stream by simply 'shifting'
|
|
|
|
* it to next ts and offset and sending */
|
|
|
|
GST_LOG_OBJECT (audiorate, "within tolerance %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (audiorate->tolerance));
|
2010-05-26 06:51:09 +00:00
|
|
|
/* The outgoing buffer's offset will be set to ->next_offset, we also
|
|
|
|
* need to adjust the offset_end value accordingly */
|
|
|
|
in_offset_end = audiorate->next_offset + in_samples;
|
2012-01-27 16:55:34 +00:00
|
|
|
audiorate->out += in_samples;
|
2009-12-15 17:41:38 +00:00
|
|
|
goto send;
|
|
|
|
}
|
|
|
|
|
2004-06-17 13:45:50 +00:00
|
|
|
/* do we need to insert samples */
|
|
|
|
if (in_offset > audiorate->next_offset) {
|
|
|
|
GstBuffer *fill;
|
2004-06-23 11:06:10 +00:00
|
|
|
gint fillsize;
|
2004-06-17 13:45:50 +00:00
|
|
|
guint64 fillsamples;
|
|
|
|
|
2007-08-09 15:44:02 +00:00
|
|
|
/* We don't want to allocate a single unreasonably huge buffer - it might
|
|
|
|
be hundreds of megabytes. So, limit each output buffer to one second of
|
|
|
|
audio */
|
2004-06-17 13:45:50 +00:00
|
|
|
fillsamples = in_offset - audiorate->next_offset;
|
|
|
|
|
2007-08-09 15:44:02 +00:00
|
|
|
while (fillsamples > 0) {
|
2011-08-18 17:15:03 +00:00
|
|
|
guint64 cursamples = MIN (fillsamples, rate);
|
2016-01-28 12:29:39 +00:00
|
|
|
GstMapInfo fillmap;
|
2007-08-09 15:44:02 +00:00
|
|
|
|
|
|
|
fillsamples -= cursamples;
|
2011-08-18 17:15:03 +00:00
|
|
|
fillsize = cursamples * bpf;
|
2007-08-09 15:44:02 +00:00
|
|
|
|
|
|
|
fill = gst_buffer_new_and_alloc (fillsize);
|
2011-03-27 14:35:28 +00:00
|
|
|
|
2016-01-28 12:29:39 +00:00
|
|
|
gst_buffer_map (fill, &fillmap, GST_MAP_WRITE);
|
2020-11-24 19:54:49 +00:00
|
|
|
gst_audio_format_info_fill_silence (audiorate->info.finfo, fillmap.data,
|
2016-01-28 12:29:39 +00:00
|
|
|
fillmap.size);
|
|
|
|
gst_buffer_unmap (fill, &fillmap);
|
2007-08-09 15:44:02 +00:00
|
|
|
|
2018-02-12 12:45:44 +00:00
|
|
|
if (audiorate->info.layout == GST_AUDIO_LAYOUT_NON_INTERLEAVED) {
|
|
|
|
gst_buffer_add_audio_meta (fill, &audiorate->info, cursamples, NULL);
|
|
|
|
}
|
|
|
|
|
2009-10-09 12:20:47 +00:00
|
|
|
GST_DEBUG_OBJECT (audiorate, "inserting %" G_GUINT64_FORMAT " samples",
|
|
|
|
cursamples);
|
2007-08-09 15:44:02 +00:00
|
|
|
|
|
|
|
GST_BUFFER_OFFSET (fill) = audiorate->next_offset;
|
|
|
|
audiorate->next_offset += cursamples;
|
|
|
|
GST_BUFFER_OFFSET_END (fill) = audiorate->next_offset;
|
|
|
|
|
|
|
|
/* Use next timestamp, then calculate following timestamp based on
|
2011-09-13 19:10:43 +00:00
|
|
|
* offset to get duration. Necessary complexity to get 'perfect'
|
2007-08-09 15:44:02 +00:00
|
|
|
* streams */
|
|
|
|
GST_BUFFER_TIMESTAMP (fill) = audiorate->next_ts;
|
2019-11-07 12:42:25 +00:00
|
|
|
audiorate->next_ts =
|
|
|
|
gst_util_uint64_scale_int_round (audiorate->next_offset, GST_SECOND,
|
|
|
|
rate);
|
2014-12-02 20:58:00 +00:00
|
|
|
GST_BUFFER_DURATION (fill) =
|
|
|
|
audiorate->next_ts - GST_BUFFER_TIMESTAMP (fill);
|
2007-08-09 15:44:02 +00:00
|
|
|
|
|
|
|
/* we created this buffer to fill a gap */
|
|
|
|
GST_BUFFER_FLAG_SET (fill, GST_BUFFER_FLAG_GAP);
|
|
|
|
/* set discont if it's pending, this is mostly done for the first buffer
|
|
|
|
* and after a flushing seek */
|
|
|
|
if (audiorate->discont) {
|
|
|
|
GST_BUFFER_FLAG_SET (fill, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
audiorate->discont = FALSE;
|
|
|
|
}
|
2004-06-24 12:45:27 +00:00
|
|
|
|
2013-09-27 20:41:28 +00:00
|
|
|
fill = gst_audio_buffer_clip (fill, &audiorate->src_segment, rate, bpf);
|
|
|
|
if (fill)
|
|
|
|
ret = gst_pad_push (audiorate->srcpad, fill);
|
|
|
|
|
2007-08-09 15:44:02 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto beach;
|
2012-01-27 16:55:34 +00:00
|
|
|
audiorate->out += cursamples;
|
2007-08-09 15:44:02 +00:00
|
|
|
audiorate->add += cursamples;
|
2006-11-16 12:55:08 +00:00
|
|
|
|
2007-08-09 15:44:02 +00:00
|
|
|
if (!audiorate->silent)
|
2010-10-07 19:54:32 +00:00
|
|
|
gst_audio_rate_notify_add (audiorate);
|
2006-08-28 16:08:18 +00:00
|
|
|
}
|
2004-06-23 11:06:10 +00:00
|
|
|
|
2004-06-17 13:45:50 +00:00
|
|
|
} else if (in_offset < audiorate->next_offset) {
|
2004-06-23 11:06:10 +00:00
|
|
|
/* need to remove samples */
|
|
|
|
if (in_offset_end <= audiorate->next_offset) {
|
2018-02-12 12:45:44 +00:00
|
|
|
guint64 drop = in_samples;
|
2004-06-24 12:45:27 +00:00
|
|
|
|
|
|
|
audiorate->drop += drop;
|
|
|
|
|
2009-10-09 12:20:47 +00:00
|
|
|
GST_DEBUG_OBJECT (audiorate, "dropping %" G_GUINT64_FORMAT " samples",
|
|
|
|
drop);
|
2004-06-23 11:06:10 +00:00
|
|
|
|
|
|
|
/* we can drop the buffer completely */
|
|
|
|
gst_buffer_unref (buf);
|
2010-04-16 18:03:21 +00:00
|
|
|
buf = NULL;
|
2004-06-23 11:06:10 +00:00
|
|
|
|
|
|
|
if (!audiorate->silent)
|
2010-10-07 19:54:32 +00:00
|
|
|
gst_audio_rate_notify_drop (audiorate);
|
2004-06-23 11:06:10 +00:00
|
|
|
|
2005-11-26 11:34:15 +00:00
|
|
|
goto beach;
|
2004-06-23 11:06:10 +00:00
|
|
|
} else {
|
2018-02-12 12:45:44 +00:00
|
|
|
guint64 truncsamples, leftsamples;
|
2004-06-23 11:06:10 +00:00
|
|
|
|
|
|
|
/* truncate buffer */
|
|
|
|
truncsamples = audiorate->next_offset - in_offset;
|
2018-02-12 12:45:44 +00:00
|
|
|
leftsamples = in_samples - truncsamples;
|
2004-06-23 11:06:10 +00:00
|
|
|
|
2018-02-12 12:45:44 +00:00
|
|
|
buf = gst_audio_buffer_truncate (buf, bpf, truncsamples, leftsamples);
|
2004-06-23 11:06:10 +00:00
|
|
|
|
|
|
|
audiorate->drop += truncsamples;
|
2018-02-12 12:45:44 +00:00
|
|
|
audiorate->out += leftsamples;
|
2009-12-15 18:22:45 +00:00
|
|
|
GST_DEBUG_OBJECT (audiorate, "truncating %" G_GUINT64_FORMAT " samples",
|
|
|
|
truncsamples);
|
|
|
|
|
|
|
|
if (!audiorate->silent)
|
2010-10-07 19:54:32 +00:00
|
|
|
gst_audio_rate_notify_drop (audiorate);
|
2004-06-23 11:06:10 +00:00
|
|
|
}
|
2004-06-17 13:45:50 +00:00
|
|
|
}
|
2006-11-16 12:55:08 +00:00
|
|
|
|
2009-12-26 17:46:50 +00:00
|
|
|
send:
|
2011-03-27 14:35:28 +00:00
|
|
|
if (gst_buffer_get_size (buf) == 0)
|
2009-12-14 17:47:27 +00:00
|
|
|
goto beach;
|
|
|
|
|
2020-12-15 13:07:31 +00:00
|
|
|
buf = gst_buffer_make_writable (buf);
|
|
|
|
|
2006-11-16 12:55:08 +00:00
|
|
|
/* Now calculate parameters for whichever buffer (either the original
|
|
|
|
* or truncated one) we're pushing. */
|
|
|
|
GST_BUFFER_OFFSET (buf) = audiorate->next_offset;
|
|
|
|
GST_BUFFER_OFFSET_END (buf) = in_offset_end;
|
|
|
|
|
|
|
|
GST_BUFFER_TIMESTAMP (buf) = audiorate->next_ts;
|
2019-11-07 12:42:25 +00:00
|
|
|
audiorate->next_ts = gst_util_uint64_scale_int_round (in_offset_end,
|
2011-08-18 17:15:03 +00:00
|
|
|
GST_SECOND, rate);
|
2006-11-16 12:55:08 +00:00
|
|
|
GST_BUFFER_DURATION (buf) = audiorate->next_ts - GST_BUFFER_TIMESTAMP (buf);
|
|
|
|
|
2006-08-28 16:08:18 +00:00
|
|
|
if (audiorate->discont) {
|
|
|
|
/* we need to output a discont buffer, do so now */
|
|
|
|
GST_DEBUG_OBJECT (audiorate, "marking DISCONT on output buffer");
|
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
audiorate->discont = FALSE;
|
|
|
|
} else if (GST_BUFFER_IS_DISCONT (buf)) {
|
|
|
|
/* else we make everything continuous so we can safely remove the DISCONT
|
|
|
|
* flag from the buffer if there was one */
|
|
|
|
GST_DEBUG_OBJECT (audiorate, "removing DISCONT from buffer");
|
|
|
|
GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
}
|
2006-08-29 10:32:34 +00:00
|
|
|
|
2013-09-27 20:41:28 +00:00
|
|
|
buf = gst_audio_buffer_clip (buf, &audiorate->src_segment, rate, bpf);
|
|
|
|
if (buf) {
|
|
|
|
/* set last_stop on segment */
|
|
|
|
audiorate->src_segment.position =
|
|
|
|
GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf);
|
2006-08-29 10:32:34 +00:00
|
|
|
|
2013-09-27 20:41:28 +00:00
|
|
|
ret = gst_pad_push (audiorate->srcpad, buf);
|
|
|
|
}
|
2010-04-16 18:03:21 +00:00
|
|
|
buf = NULL;
|
2004-06-17 13:45:50 +00:00
|
|
|
|
|
|
|
audiorate->next_offset = in_offset_end;
|
2005-11-26 11:34:15 +00:00
|
|
|
beach:
|
2006-08-28 16:08:18 +00:00
|
|
|
|
2010-04-16 18:03:21 +00:00
|
|
|
if (buf)
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
|
2005-11-26 11:34:15 +00:00
|
|
|
return ret;
|
2006-08-28 16:08:18 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
not_negotiated:
|
|
|
|
{
|
2010-04-16 18:03:21 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
|
2006-08-28 16:08:18 +00:00
|
|
|
GST_ELEMENT_ERROR (audiorate, STREAM, FORMAT,
|
|
|
|
(NULL), ("pipeline error, format was not negotiated"));
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
2004-06-17 13:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_audio_rate_set_property (GObject * object,
|
2004-06-17 13:45:50 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2005-12-01 01:12:55 +00:00
|
|
|
GstAudioRate *audiorate = GST_AUDIO_RATE (object);
|
2004-06-17 13:45:50 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2015-04-27 10:26:10 +00:00
|
|
|
case PROP_SILENT:
|
2004-06-23 11:06:10 +00:00
|
|
|
audiorate->silent = g_value_get_boolean (value);
|
|
|
|
break;
|
2015-04-27 10:26:10 +00:00
|
|
|
case PROP_TOLERANCE:
|
2009-12-15 17:41:38 +00:00
|
|
|
audiorate->tolerance = g_value_get_uint64 (value);
|
|
|
|
break;
|
2015-04-27 10:26:10 +00:00
|
|
|
case PROP_SKIP_TO_FIRST:
|
2011-02-21 11:40:36 +00:00
|
|
|
audiorate->skip_to_first = g_value_get_boolean (value);
|
|
|
|
break;
|
2004-06-17 13:45:50 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_audio_rate_get_property (GObject * object,
|
2004-06-17 13:45:50 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2005-12-01 01:12:55 +00:00
|
|
|
GstAudioRate *audiorate = GST_AUDIO_RATE (object);
|
2004-06-17 13:45:50 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2015-04-27 10:26:10 +00:00
|
|
|
case PROP_IN:
|
2004-06-17 13:45:50 +00:00
|
|
|
g_value_set_uint64 (value, audiorate->in);
|
|
|
|
break;
|
2015-04-27 10:26:10 +00:00
|
|
|
case PROP_OUT:
|
2004-06-17 13:45:50 +00:00
|
|
|
g_value_set_uint64 (value, audiorate->out);
|
|
|
|
break;
|
2015-04-27 10:26:10 +00:00
|
|
|
case PROP_ADD:
|
2004-06-17 13:45:50 +00:00
|
|
|
g_value_set_uint64 (value, audiorate->add);
|
|
|
|
break;
|
2015-04-27 10:26:10 +00:00
|
|
|
case PROP_DROP:
|
2004-06-17 13:45:50 +00:00
|
|
|
g_value_set_uint64 (value, audiorate->drop);
|
|
|
|
break;
|
2015-04-27 10:26:10 +00:00
|
|
|
case PROP_SILENT:
|
2004-06-23 11:06:10 +00:00
|
|
|
g_value_set_boolean (value, audiorate->silent);
|
|
|
|
break;
|
2015-04-27 10:26:10 +00:00
|
|
|
case PROP_TOLERANCE:
|
2009-12-15 17:41:38 +00:00
|
|
|
g_value_set_uint64 (value, audiorate->tolerance);
|
|
|
|
break;
|
2015-04-27 10:26:10 +00:00
|
|
|
case PROP_SKIP_TO_FIRST:
|
2011-02-21 11:40:36 +00:00
|
|
|
g_value_set_boolean (value, audiorate->skip_to_first);
|
|
|
|
break;
|
2004-06-17 13:45:50 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-02 15:43:18 +00:00
|
|
|
static GstStateChangeReturn
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_audio_rate_change_state (GstElement * element, GstStateChange transition)
|
2004-06-17 13:45:50 +00:00
|
|
|
{
|
2005-12-01 01:12:55 +00:00
|
|
|
GstAudioRate *audiorate = GST_AUDIO_RATE (element);
|
2004-06-17 13:45:50 +00:00
|
|
|
|
2005-09-02 15:43:18 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2004-06-17 13:45:50 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2006-08-28 16:08:18 +00:00
|
|
|
audiorate->in = 0;
|
|
|
|
audiorate->out = 0;
|
|
|
|
audiorate->drop = 0;
|
|
|
|
audiorate->add = 0;
|
2011-08-18 17:15:03 +00:00
|
|
|
gst_audio_info_init (&audiorate->info);
|
2006-08-28 16:08:18 +00:00
|
|
|
gst_audio_rate_reset (audiorate);
|
2004-06-17 13:45:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-19 09:35:53 +00:00
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
2004-06-17 13:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
2021-03-29 12:06:00 +00:00
|
|
|
return GST_ELEMENT_REGISTER (audiorate, plugin);
|
2004-06-17 13:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-04-05 13:11:05 +00:00
|
|
|
audiorate,
|
2004-06-17 13:45:50 +00:00
|
|
|
"Adjusts audio frames",
|
2005-10-16 13:54:44 +00:00
|
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|