2005-07-06 15:27:17 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2005 Wim Taymans <wim@fluendo.com>
|
|
|
|
*
|
2013-12-20 21:54:39 +00:00
|
|
|
* gstaudiobasesrc.c:
|
2005-07-06 15:27:17 +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 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2005-07-06 15:27:17 +00:00
|
|
|
*/
|
|
|
|
|
2006-09-27 11:05:08 +00:00
|
|
|
/**
|
2011-11-11 11:00:52 +00:00
|
|
|
* SECTION:gstaudiobasesrc
|
2017-01-23 19:36:11 +00:00
|
|
|
* @title: GstAudioBaseSrc
|
2006-09-27 11:05:08 +00:00
|
|
|
* @short_description: Base class for audio sources
|
2011-11-11 10:21:41 +00:00
|
|
|
* @see_also: #GstAudioSrc, #GstAudioRingBuffer.
|
2006-09-27 11:05:08 +00:00
|
|
|
*
|
|
|
|
* This is the base class for audio sources. Subclasses need to implement the
|
|
|
|
* ::create_ringbuffer vmethod. This base class will then take care of
|
|
|
|
* reading samples from the ringbuffer, synchronisation and flushing.
|
|
|
|
*/
|
|
|
|
|
2007-04-25 08:54:34 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-12-12 17:13:10 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2011-11-11 11:00:52 +00:00
|
|
|
#include "gstaudiobasesrc.h"
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2007-04-25 08:54:34 +00:00
|
|
|
#include "gst/gst-i18n-plugin.h"
|
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_audio_base_src_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_audio_base_src_debug
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
#define GST_AUDIO_BASE_SRC_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_AUDIO_BASE_SRC, GstAudioBaseSrcPrivate))
|
2007-09-10 22:10:54 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
struct _GstAudioBaseSrcPrivate
|
2007-09-10 22:10:54 +00:00
|
|
|
{
|
2008-04-28 08:51:38 +00:00
|
|
|
/* the clock slaving algorithm in use */
|
2011-11-11 10:52:47 +00:00
|
|
|
GstAudioBaseSrcSlaveMethod slave_method;
|
2007-09-10 22:10:54 +00:00
|
|
|
};
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
/* BaseAudioSrc signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2013-12-20 21:41:59 +00:00
|
|
|
/* FIXME: 2.0, handle BUFFER_TIME and LATENCY in nanoseconds */
|
2006-07-06 15:54:50 +00:00
|
|
|
#define DEFAULT_BUFFER_TIME ((200 * GST_MSECOND) / GST_USECOND)
|
|
|
|
#define DEFAULT_LATENCY_TIME ((10 * GST_MSECOND) / GST_USECOND)
|
2008-05-31 18:10:47 +00:00
|
|
|
#define DEFAULT_ACTUAL_BUFFER_TIME -1
|
|
|
|
#define DEFAULT_ACTUAL_LATENCY_TIME -1
|
2007-09-10 22:10:54 +00:00
|
|
|
#define DEFAULT_PROVIDE_CLOCK TRUE
|
2011-11-11 10:52:47 +00:00
|
|
|
#define DEFAULT_SLAVE_METHOD GST_AUDIO_BASE_SRC_SLAVE_SKEW
|
2006-07-06 15:54:50 +00:00
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_BUFFER_TIME,
|
|
|
|
PROP_LATENCY_TIME,
|
2008-05-31 18:10:47 +00:00
|
|
|
PROP_ACTUAL_BUFFER_TIME,
|
|
|
|
PROP_ACTUAL_LATENCY_TIME,
|
2008-04-28 08:51:38 +00:00
|
|
|
PROP_PROVIDE_CLOCK,
|
|
|
|
PROP_SLAVE_METHOD,
|
|
|
|
PROP_LAST
|
2005-07-06 15:27:17 +00:00
|
|
|
};
|
|
|
|
|
2007-04-25 08:54:34 +00:00
|
|
|
static void
|
|
|
|
_do_init (GType type)
|
|
|
|
{
|
2011-11-11 11:00:52 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_audio_base_src_debug, "audiobasesrc", 0,
|
|
|
|
"audiobasesrc element");
|
2007-04-25 08:54:34 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_NLS
|
|
|
|
GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
|
|
|
|
LOCALEDIR);
|
|
|
|
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
|
2008-08-07 15:58:58 +00:00
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
2007-04-25 08:54:34 +00:00
|
|
|
#endif /* ENABLE_NLS */
|
|
|
|
}
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
#define gst_audio_base_src_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstAudioBaseSrc, gst_audio_base_src, GST_TYPE_PUSH_SRC,
|
2011-04-19 08:52:00 +00:00
|
|
|
_do_init (g_define_type_id));
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
static void gst_audio_base_src_set_property (GObject * object, guint prop_id,
|
2005-07-06 15:27:17 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2011-11-11 10:52:47 +00:00
|
|
|
static void gst_audio_base_src_get_property (GObject * object, guint prop_id,
|
2005-07-06 15:27:17 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
2011-11-11 10:52:47 +00:00
|
|
|
static void gst_audio_base_src_dispose (GObject * object);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
static GstStateChangeReturn gst_audio_base_src_change_state (GstElement *
|
2005-09-02 15:43:18 +00:00
|
|
|
element, GstStateChange transition);
|
2012-12-17 20:28:12 +00:00
|
|
|
static gboolean gst_audio_base_src_post_message (GstElement * element,
|
|
|
|
GstMessage * message);
|
2011-11-11 10:52:47 +00:00
|
|
|
static GstClock *gst_audio_base_src_provide_clock (GstElement * elem);
|
|
|
|
static GstClockTime gst_audio_base_src_get_time (GstClock * clock,
|
|
|
|
GstAudioBaseSrc * src);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
static GstFlowReturn gst_audio_base_src_create (GstBaseSrc * bsrc,
|
2006-07-06 15:54:50 +00:00
|
|
|
guint64 offset, guint length, GstBuffer ** buf);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
static gboolean gst_audio_base_src_event (GstBaseSrc * bsrc, GstEvent * event);
|
|
|
|
static void gst_audio_base_src_get_times (GstBaseSrc * bsrc,
|
2005-07-06 15:27:17 +00:00
|
|
|
GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
|
2011-11-11 10:52:47 +00:00
|
|
|
static gboolean gst_audio_base_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
|
|
|
|
static gboolean gst_audio_base_src_query (GstBaseSrc * bsrc, GstQuery * query);
|
2012-03-11 18:04:41 +00:00
|
|
|
static GstCaps *gst_audio_base_src_fixate (GstBaseSrc * bsrc, GstCaps * caps);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
/* static guint gst_audio_base_src_signals[LAST_SIGNAL] = { 0 }; */
|
2005-07-06 15:27:17 +00:00
|
|
|
|
|
|
|
static void
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_class_init (GstAudioBaseSrcClass * klass)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
GstBaseSrcClass *gstbasesrc_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
gstbasesrc_class = (GstBaseSrcClass *) klass;
|
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstAudioBaseSrcPrivate));
|
2007-09-10 22:10:54 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
gobject_class->set_property = gst_audio_base_src_set_property;
|
|
|
|
gobject_class->get_property = gst_audio_base_src_get_property;
|
|
|
|
gobject_class->dispose = gst_audio_base_src_dispose;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2013-12-20 21:41:59 +00:00
|
|
|
/* FIXME: 2.0, handle BUFFER_TIME and LATENCY in nanoseconds */
|
2006-07-06 15:54:50 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_BUFFER_TIME,
|
|
|
|
g_param_spec_int64 ("buffer-time", "Buffer Time",
|
2013-12-20 22:48:06 +00:00
|
|
|
"Size of audio buffer in microseconds. This is the maximum amount "
|
2012-09-14 14:06:50 +00:00
|
|
|
"of data that is buffered in the device and the maximum latency that "
|
2014-12-27 09:14:51 +00:00
|
|
|
"the source reports. This value might be ignored by the element if "
|
|
|
|
"necessary; see \"actual-buffer-time\"",
|
|
|
|
1, G_MAXINT64, DEFAULT_BUFFER_TIME,
|
2008-03-22 15:00:53 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2006-07-06 15:54:50 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_LATENCY_TIME,
|
|
|
|
g_param_spec_int64 ("latency-time", "Latency Time",
|
2013-12-20 21:53:13 +00:00
|
|
|
"The minimum amount of data to read in each iteration in "
|
2014-12-27 09:14:51 +00:00
|
|
|
"microseconds. This is the minimum latency that the source reports. "
|
|
|
|
"This value might be ignored by the element if necessary; see "
|
|
|
|
"\"actual-latency-time\"", 1, G_MAXINT64, DEFAULT_LATENCY_TIME,
|
2008-03-22 15:00:53 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2008-05-31 19:57:57 +00:00
|
|
|
/**
|
2011-11-11 10:52:47 +00:00
|
|
|
* GstAudioBaseSrc:actual-buffer-time:
|
2008-05-31 19:57:57 +00:00
|
|
|
*
|
|
|
|
* Actual configured size of audio buffer in microseconds.
|
|
|
|
**/
|
2008-05-31 18:10:47 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ACTUAL_BUFFER_TIME,
|
|
|
|
g_param_spec_int64 ("actual-buffer-time", "Actual Buffer Time",
|
|
|
|
"Actual configured size of audio buffer in microseconds",
|
|
|
|
DEFAULT_ACTUAL_BUFFER_TIME, G_MAXINT64, DEFAULT_ACTUAL_BUFFER_TIME,
|
2010-10-13 13:12:38 +00:00
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2008-05-31 18:10:47 +00:00
|
|
|
|
2008-05-31 19:57:57 +00:00
|
|
|
/**
|
2011-11-11 10:52:47 +00:00
|
|
|
* GstAudioBaseSrc:actual-latency-time:
|
2008-05-31 19:57:57 +00:00
|
|
|
*
|
|
|
|
* Actual configured audio latency in microseconds.
|
|
|
|
**/
|
2008-05-31 18:10:47 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ACTUAL_LATENCY_TIME,
|
|
|
|
g_param_spec_int64 ("actual-latency-time", "Actual Latency Time",
|
|
|
|
"Actual configured audio latency in microseconds",
|
|
|
|
DEFAULT_ACTUAL_LATENCY_TIME, G_MAXINT64, DEFAULT_ACTUAL_LATENCY_TIME,
|
2010-10-13 13:12:38 +00:00
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2008-05-31 18:10:47 +00:00
|
|
|
|
2007-09-10 22:10:54 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PROVIDE_CLOCK,
|
|
|
|
g_param_spec_boolean ("provide-clock", "Provide Clock",
|
|
|
|
"Provide a clock to be used as the global pipeline clock",
|
2008-03-22 15:00:53 +00:00
|
|
|
DEFAULT_PROVIDE_CLOCK, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2007-09-10 22:10:54 +00:00
|
|
|
|
2008-04-28 08:51:38 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SLAVE_METHOD,
|
|
|
|
g_param_spec_enum ("slave-method", "Slave Method",
|
2013-12-20 22:48:06 +00:00
|
|
|
"Algorithm used to match the rate of the masterclock",
|
2011-11-11 10:52:47 +00:00
|
|
|
GST_TYPE_AUDIO_BASE_SRC_SLAVE_METHOD, DEFAULT_SLAVE_METHOD,
|
2008-04-28 08:51:38 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
gstelement_class->change_state =
|
2011-11-11 10:52:47 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_audio_base_src_change_state);
|
2005-09-28 13:41:29 +00:00
|
|
|
gstelement_class->provide_clock =
|
2011-11-11 10:52:47 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_audio_base_src_provide_clock);
|
2012-12-17 20:28:12 +00:00
|
|
|
gstelement_class->post_message =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_audio_base_src_post_message);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_audio_base_src_setcaps);
|
|
|
|
gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_audio_base_src_event);
|
|
|
|
gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_audio_base_src_query);
|
2005-07-10 12:03:58 +00:00
|
|
|
gstbasesrc_class->get_times =
|
2011-11-11 10:52:47 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_audio_base_src_get_times);
|
|
|
|
gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_audio_base_src_create);
|
|
|
|
gstbasesrc_class->fixate = GST_DEBUG_FUNCPTR (gst_audio_base_src_fixate);
|
2008-01-10 17:55:53 +00:00
|
|
|
|
|
|
|
/* ref class from a thread-safe context to work around missing bit of
|
|
|
|
* thread-safety in GObject */
|
|
|
|
g_type_class_ref (GST_TYPE_AUDIO_CLOCK);
|
2011-11-11 10:21:41 +00:00
|
|
|
g_type_class_ref (GST_TYPE_AUDIO_RING_BUFFER);
|
2005-07-06 15:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-11 11:00:52 +00:00
|
|
|
gst_audio_base_src_init (GstAudioBaseSrc * audiobasesrc)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
2011-11-11 11:00:52 +00:00
|
|
|
audiobasesrc->priv = GST_AUDIO_BASE_SRC_GET_PRIVATE (audiobasesrc);
|
2007-09-10 22:10:54 +00:00
|
|
|
|
2011-11-11 11:00:52 +00:00
|
|
|
audiobasesrc->buffer_time = DEFAULT_BUFFER_TIME;
|
|
|
|
audiobasesrc->latency_time = DEFAULT_LATENCY_TIME;
|
2011-11-28 16:51:41 +00:00
|
|
|
if (DEFAULT_PROVIDE_CLOCK)
|
|
|
|
GST_OBJECT_FLAG_SET (audiobasesrc, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
|
|
|
|
else
|
|
|
|
GST_OBJECT_FLAG_UNSET (audiobasesrc, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
|
2011-11-11 11:00:52 +00:00
|
|
|
audiobasesrc->priv->slave_method = DEFAULT_SLAVE_METHOD;
|
2013-12-20 21:54:39 +00:00
|
|
|
/* reset blocksize we use latency time to calculate a more useful
|
2006-07-06 15:54:50 +00:00
|
|
|
* value based on negotiated format. */
|
2011-11-11 11:00:52 +00:00
|
|
|
GST_BASE_SRC (audiobasesrc)->blocksize = 0;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 11:00:52 +00:00
|
|
|
audiobasesrc->clock = gst_audio_clock_new ("GstAudioSrcClock",
|
|
|
|
(GstAudioClockGetTimeFunc) gst_audio_base_src_get_time, audiobasesrc,
|
2011-11-10 12:50:08 +00:00
|
|
|
NULL);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-28 16:51:41 +00:00
|
|
|
|
2006-07-06 15:54:50 +00:00
|
|
|
/* we are always a live source */
|
2011-11-11 11:00:52 +00:00
|
|
|
gst_base_src_set_live (GST_BASE_SRC (audiobasesrc), TRUE);
|
2006-09-27 11:05:08 +00:00
|
|
|
/* we operate in time */
|
2011-11-11 11:00:52 +00:00
|
|
|
gst_base_src_set_format (GST_BASE_SRC (audiobasesrc), GST_FORMAT_TIME);
|
2005-07-06 15:27:17 +00:00
|
|
|
}
|
|
|
|
|
2007-02-15 12:06:25 +00:00
|
|
|
static void
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_dispose (GObject * object)
|
2007-02-15 12:06:25 +00:00
|
|
|
{
|
2011-11-11 10:52:47 +00:00
|
|
|
GstAudioBaseSrc *src;
|
2007-02-15 12:06:25 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
src = GST_AUDIO_BASE_SRC (object);
|
2007-02-15 12:06:25 +00:00
|
|
|
|
2008-05-31 18:10:47 +00:00
|
|
|
GST_OBJECT_LOCK (src);
|
2010-09-07 16:09:12 +00:00
|
|
|
if (src->clock) {
|
2015-10-15 10:52:27 +00:00
|
|
|
gst_audio_clock_invalidate (GST_AUDIO_CLOCK (src->clock));
|
2007-02-15 12:06:25 +00:00
|
|
|
gst_object_unref (src->clock);
|
2010-09-07 16:09:12 +00:00
|
|
|
src->clock = NULL;
|
|
|
|
}
|
2007-02-15 12:06:25 +00:00
|
|
|
|
|
|
|
if (src->ringbuffer) {
|
|
|
|
gst_object_unparent (GST_OBJECT_CAST (src->ringbuffer));
|
|
|
|
src->ringbuffer = NULL;
|
|
|
|
}
|
2008-05-31 18:10:47 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
2007-02-15 12:06:25 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
static GstClock *
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_provide_clock (GstElement * elem)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
2011-11-11 10:52:47 +00:00
|
|
|
GstAudioBaseSrc *src;
|
2006-07-06 15:54:50 +00:00
|
|
|
GstClock *clock;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
src = GST_AUDIO_BASE_SRC (elem);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2006-07-06 15:54:50 +00:00
|
|
|
/* we have no ringbuffer (must be NULL state) */
|
|
|
|
if (src->ringbuffer == NULL)
|
|
|
|
goto wrong_state;
|
|
|
|
|
2012-09-10 10:12:48 +00:00
|
|
|
if (gst_audio_ring_buffer_is_flushing (src->ringbuffer))
|
2006-07-06 15:54:50 +00:00
|
|
|
goto wrong_state;
|
|
|
|
|
2007-09-10 22:10:54 +00:00
|
|
|
GST_OBJECT_LOCK (src);
|
2012-09-10 10:12:48 +00:00
|
|
|
|
2011-11-28 16:51:41 +00:00
|
|
|
if (!GST_OBJECT_FLAG_IS_SET (src, GST_ELEMENT_FLAG_PROVIDE_CLOCK))
|
2007-09-10 22:10:54 +00:00
|
|
|
goto clock_disabled;
|
|
|
|
|
2006-07-06 15:54:50 +00:00
|
|
|
clock = GST_CLOCK_CAST (gst_object_ref (src->clock));
|
2007-09-10 22:10:54 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
2006-07-06 15:54:50 +00:00
|
|
|
|
|
|
|
return clock;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
wrong_state:
|
|
|
|
{
|
2012-09-10 10:12:48 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "ringbuffer is flushing");
|
2006-07-06 15:54:50 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-09-10 22:10:54 +00:00
|
|
|
clock_disabled:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (src, "clock provide disabled");
|
|
|
|
GST_OBJECT_UNLOCK (src);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-07-06 15:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstClockTime
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_get_time (GstClock * clock, GstAudioBaseSrc * src)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
guint64 raw, samples;
|
|
|
|
guint delay;
|
2005-07-06 15:27:17 +00:00
|
|
|
GstClockTime result;
|
|
|
|
|
2011-08-18 17:15:03 +00:00
|
|
|
if (G_UNLIKELY (src->ringbuffer == NULL
|
|
|
|
|| src->ringbuffer->spec.info.rate == 0))
|
2006-07-06 15:54:50 +00:00
|
|
|
return GST_CLOCK_TIME_NONE;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:21:41 +00:00
|
|
|
raw = samples = gst_audio_ring_buffer_samples_done (src->ringbuffer);
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
|
|
|
|
/* the number of samples not yet processed, this is still queued in the
|
|
|
|
* device (not yet read for capture). */
|
2011-11-11 10:21:41 +00:00
|
|
|
delay = gst_audio_ring_buffer_delay (src->ringbuffer);
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
|
|
|
|
samples += delay;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2006-01-25 09:27:01 +00:00
|
|
|
result = gst_util_uint64_scale_int (samples, GST_SECOND,
|
2011-08-18 17:15:03 +00:00
|
|
|
src->ringbuffer->spec.info.rate);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
GST_DEBUG_OBJECT (src,
|
2009-10-09 12:07:24 +00:00
|
|
|
"processed samples: raw %" G_GUINT64_FORMAT ", delay %u, real %"
|
|
|
|
G_GUINT64_FORMAT ", time %" GST_TIME_FORMAT, raw, delay, samples,
|
|
|
|
GST_TIME_ARGS (result));
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
Expose methods for some object properties so that subclasses can more easily configure them.
Original commit message from CVS:
* docs/libs/gst-plugins-base-libs-sections.txt:
* gst-libs/gst/audio/gstbaseaudiosink.c: (slave_method_get_type),
(gst_base_audio_sink_set_provide_clock),
(gst_base_audio_sink_get_provide_clock),
(gst_base_audio_sink_set_slave_method),
(gst_base_audio_sink_get_slave_method),
(gst_base_audio_sink_set_property),
(gst_base_audio_sink_get_property), (gst_base_audio_sink_drain),
(gst_base_audio_sink_none_slaving),
(gst_base_audio_sink_handle_slaving):
* gst-libs/gst/audio/gstbaseaudiosink.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
Added slave method none, that completely disables slaving to the
internal clock.
API: gst_base_audio_sink_set_provide_clock()
API: gst_base_audio_sink_get_provide_clock()
API: gst_base_audio_sink_set_slave_method()
API: gst_base_audio_sink_get_slave_method()
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_set_provide_clock),
(gst_base_audio_src_get_provide_clock),
(gst_base_audio_src_set_property),
(gst_base_audio_src_get_property), (gst_base_audio_src_create):
* gst-libs/gst/audio/gstbaseaudiosrc.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
API: gst_base_audio_src_set_provide_clock()
API: gst_base_audio_src_get_provide_clock()
2007-11-21 13:04:17 +00:00
|
|
|
/**
|
2011-11-11 10:52:47 +00:00
|
|
|
* gst_audio_base_src_set_provide_clock:
|
|
|
|
* @src: a #GstAudioBaseSrc
|
Expose methods for some object properties so that subclasses can more easily configure them.
Original commit message from CVS:
* docs/libs/gst-plugins-base-libs-sections.txt:
* gst-libs/gst/audio/gstbaseaudiosink.c: (slave_method_get_type),
(gst_base_audio_sink_set_provide_clock),
(gst_base_audio_sink_get_provide_clock),
(gst_base_audio_sink_set_slave_method),
(gst_base_audio_sink_get_slave_method),
(gst_base_audio_sink_set_property),
(gst_base_audio_sink_get_property), (gst_base_audio_sink_drain),
(gst_base_audio_sink_none_slaving),
(gst_base_audio_sink_handle_slaving):
* gst-libs/gst/audio/gstbaseaudiosink.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
Added slave method none, that completely disables slaving to the
internal clock.
API: gst_base_audio_sink_set_provide_clock()
API: gst_base_audio_sink_get_provide_clock()
API: gst_base_audio_sink_set_slave_method()
API: gst_base_audio_sink_get_slave_method()
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_set_provide_clock),
(gst_base_audio_src_get_provide_clock),
(gst_base_audio_src_set_property),
(gst_base_audio_src_get_property), (gst_base_audio_src_create):
* gst-libs/gst/audio/gstbaseaudiosrc.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
API: gst_base_audio_src_set_provide_clock()
API: gst_base_audio_src_get_provide_clock()
2007-11-21 13:04:17 +00:00
|
|
|
* @provide: new state
|
|
|
|
*
|
2013-12-20 21:54:39 +00:00
|
|
|
* Controls whether @src will provide a clock or not. If @provide is %TRUE,
|
Expose methods for some object properties so that subclasses can more easily configure them.
Original commit message from CVS:
* docs/libs/gst-plugins-base-libs-sections.txt:
* gst-libs/gst/audio/gstbaseaudiosink.c: (slave_method_get_type),
(gst_base_audio_sink_set_provide_clock),
(gst_base_audio_sink_get_provide_clock),
(gst_base_audio_sink_set_slave_method),
(gst_base_audio_sink_get_slave_method),
(gst_base_audio_sink_set_property),
(gst_base_audio_sink_get_property), (gst_base_audio_sink_drain),
(gst_base_audio_sink_none_slaving),
(gst_base_audio_sink_handle_slaving):
* gst-libs/gst/audio/gstbaseaudiosink.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
Added slave method none, that completely disables slaving to the
internal clock.
API: gst_base_audio_sink_set_provide_clock()
API: gst_base_audio_sink_get_provide_clock()
API: gst_base_audio_sink_set_slave_method()
API: gst_base_audio_sink_get_slave_method()
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_set_provide_clock),
(gst_base_audio_src_get_provide_clock),
(gst_base_audio_src_set_property),
(gst_base_audio_src_get_property), (gst_base_audio_src_create):
* gst-libs/gst/audio/gstbaseaudiosrc.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
API: gst_base_audio_src_set_provide_clock()
API: gst_base_audio_src_get_provide_clock()
2007-11-21 13:04:17 +00:00
|
|
|
* gst_element_provide_clock() will return a clock that reflects the datarate
|
|
|
|
* of @src. If @provide is %FALSE, gst_element_provide_clock() will return NULL.
|
|
|
|
*/
|
|
|
|
void
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_set_provide_clock (GstAudioBaseSrc * src, gboolean provide)
|
Expose methods for some object properties so that subclasses can more easily configure them.
Original commit message from CVS:
* docs/libs/gst-plugins-base-libs-sections.txt:
* gst-libs/gst/audio/gstbaseaudiosink.c: (slave_method_get_type),
(gst_base_audio_sink_set_provide_clock),
(gst_base_audio_sink_get_provide_clock),
(gst_base_audio_sink_set_slave_method),
(gst_base_audio_sink_get_slave_method),
(gst_base_audio_sink_set_property),
(gst_base_audio_sink_get_property), (gst_base_audio_sink_drain),
(gst_base_audio_sink_none_slaving),
(gst_base_audio_sink_handle_slaving):
* gst-libs/gst/audio/gstbaseaudiosink.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
Added slave method none, that completely disables slaving to the
internal clock.
API: gst_base_audio_sink_set_provide_clock()
API: gst_base_audio_sink_get_provide_clock()
API: gst_base_audio_sink_set_slave_method()
API: gst_base_audio_sink_get_slave_method()
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_set_provide_clock),
(gst_base_audio_src_get_provide_clock),
(gst_base_audio_src_set_property),
(gst_base_audio_src_get_property), (gst_base_audio_src_create):
* gst-libs/gst/audio/gstbaseaudiosrc.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
API: gst_base_audio_src_set_provide_clock()
API: gst_base_audio_src_get_provide_clock()
2007-11-21 13:04:17 +00:00
|
|
|
{
|
2011-11-11 10:52:47 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIO_BASE_SRC (src));
|
Expose methods for some object properties so that subclasses can more easily configure them.
Original commit message from CVS:
* docs/libs/gst-plugins-base-libs-sections.txt:
* gst-libs/gst/audio/gstbaseaudiosink.c: (slave_method_get_type),
(gst_base_audio_sink_set_provide_clock),
(gst_base_audio_sink_get_provide_clock),
(gst_base_audio_sink_set_slave_method),
(gst_base_audio_sink_get_slave_method),
(gst_base_audio_sink_set_property),
(gst_base_audio_sink_get_property), (gst_base_audio_sink_drain),
(gst_base_audio_sink_none_slaving),
(gst_base_audio_sink_handle_slaving):
* gst-libs/gst/audio/gstbaseaudiosink.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
Added slave method none, that completely disables slaving to the
internal clock.
API: gst_base_audio_sink_set_provide_clock()
API: gst_base_audio_sink_get_provide_clock()
API: gst_base_audio_sink_set_slave_method()
API: gst_base_audio_sink_get_slave_method()
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_set_provide_clock),
(gst_base_audio_src_get_provide_clock),
(gst_base_audio_src_set_property),
(gst_base_audio_src_get_property), (gst_base_audio_src_create):
* gst-libs/gst/audio/gstbaseaudiosrc.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
API: gst_base_audio_src_set_provide_clock()
API: gst_base_audio_src_get_provide_clock()
2007-11-21 13:04:17 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (src);
|
2011-11-28 16:51:41 +00:00
|
|
|
if (provide)
|
|
|
|
GST_OBJECT_FLAG_SET (src, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
|
|
|
|
else
|
|
|
|
GST_OBJECT_FLAG_UNSET (src, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
|
Expose methods for some object properties so that subclasses can more easily configure them.
Original commit message from CVS:
* docs/libs/gst-plugins-base-libs-sections.txt:
* gst-libs/gst/audio/gstbaseaudiosink.c: (slave_method_get_type),
(gst_base_audio_sink_set_provide_clock),
(gst_base_audio_sink_get_provide_clock),
(gst_base_audio_sink_set_slave_method),
(gst_base_audio_sink_get_slave_method),
(gst_base_audio_sink_set_property),
(gst_base_audio_sink_get_property), (gst_base_audio_sink_drain),
(gst_base_audio_sink_none_slaving),
(gst_base_audio_sink_handle_slaving):
* gst-libs/gst/audio/gstbaseaudiosink.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
Added slave method none, that completely disables slaving to the
internal clock.
API: gst_base_audio_sink_set_provide_clock()
API: gst_base_audio_sink_get_provide_clock()
API: gst_base_audio_sink_set_slave_method()
API: gst_base_audio_sink_get_slave_method()
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_set_provide_clock),
(gst_base_audio_src_get_provide_clock),
(gst_base_audio_src_set_property),
(gst_base_audio_src_get_property), (gst_base_audio_src_create):
* gst-libs/gst/audio/gstbaseaudiosrc.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
API: gst_base_audio_src_set_provide_clock()
API: gst_base_audio_src_get_provide_clock()
2007-11-21 13:04:17 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-11-11 10:52:47 +00:00
|
|
|
* gst_audio_base_src_get_provide_clock:
|
|
|
|
* @src: a #GstAudioBaseSrc
|
Expose methods for some object properties so that subclasses can more easily configure them.
Original commit message from CVS:
* docs/libs/gst-plugins-base-libs-sections.txt:
* gst-libs/gst/audio/gstbaseaudiosink.c: (slave_method_get_type),
(gst_base_audio_sink_set_provide_clock),
(gst_base_audio_sink_get_provide_clock),
(gst_base_audio_sink_set_slave_method),
(gst_base_audio_sink_get_slave_method),
(gst_base_audio_sink_set_property),
(gst_base_audio_sink_get_property), (gst_base_audio_sink_drain),
(gst_base_audio_sink_none_slaving),
(gst_base_audio_sink_handle_slaving):
* gst-libs/gst/audio/gstbaseaudiosink.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
Added slave method none, that completely disables slaving to the
internal clock.
API: gst_base_audio_sink_set_provide_clock()
API: gst_base_audio_sink_get_provide_clock()
API: gst_base_audio_sink_set_slave_method()
API: gst_base_audio_sink_get_slave_method()
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_set_provide_clock),
(gst_base_audio_src_get_provide_clock),
(gst_base_audio_src_set_property),
(gst_base_audio_src_get_property), (gst_base_audio_src_create):
* gst-libs/gst/audio/gstbaseaudiosrc.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
API: gst_base_audio_src_set_provide_clock()
API: gst_base_audio_src_get_provide_clock()
2007-11-21 13:04:17 +00:00
|
|
|
*
|
|
|
|
* Queries whether @src will provide a clock or not. See also
|
2011-11-11 10:52:47 +00:00
|
|
|
* gst_audio_base_src_set_provide_clock.
|
Expose methods for some object properties so that subclasses can more easily configure them.
Original commit message from CVS:
* docs/libs/gst-plugins-base-libs-sections.txt:
* gst-libs/gst/audio/gstbaseaudiosink.c: (slave_method_get_type),
(gst_base_audio_sink_set_provide_clock),
(gst_base_audio_sink_get_provide_clock),
(gst_base_audio_sink_set_slave_method),
(gst_base_audio_sink_get_slave_method),
(gst_base_audio_sink_set_property),
(gst_base_audio_sink_get_property), (gst_base_audio_sink_drain),
(gst_base_audio_sink_none_slaving),
(gst_base_audio_sink_handle_slaving):
* gst-libs/gst/audio/gstbaseaudiosink.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
Added slave method none, that completely disables slaving to the
internal clock.
API: gst_base_audio_sink_set_provide_clock()
API: gst_base_audio_sink_get_provide_clock()
API: gst_base_audio_sink_set_slave_method()
API: gst_base_audio_sink_get_slave_method()
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_set_provide_clock),
(gst_base_audio_src_get_provide_clock),
(gst_base_audio_src_set_property),
(gst_base_audio_src_get_property), (gst_base_audio_src_create):
* gst-libs/gst/audio/gstbaseaudiosrc.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
API: gst_base_audio_src_set_provide_clock()
API: gst_base_audio_src_get_provide_clock()
2007-11-21 13:04:17 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if @src will provide a clock.
|
|
|
|
*/
|
|
|
|
gboolean
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_get_provide_clock (GstAudioBaseSrc * src)
|
Expose methods for some object properties so that subclasses can more easily configure them.
Original commit message from CVS:
* docs/libs/gst-plugins-base-libs-sections.txt:
* gst-libs/gst/audio/gstbaseaudiosink.c: (slave_method_get_type),
(gst_base_audio_sink_set_provide_clock),
(gst_base_audio_sink_get_provide_clock),
(gst_base_audio_sink_set_slave_method),
(gst_base_audio_sink_get_slave_method),
(gst_base_audio_sink_set_property),
(gst_base_audio_sink_get_property), (gst_base_audio_sink_drain),
(gst_base_audio_sink_none_slaving),
(gst_base_audio_sink_handle_slaving):
* gst-libs/gst/audio/gstbaseaudiosink.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
Added slave method none, that completely disables slaving to the
internal clock.
API: gst_base_audio_sink_set_provide_clock()
API: gst_base_audio_sink_get_provide_clock()
API: gst_base_audio_sink_set_slave_method()
API: gst_base_audio_sink_get_slave_method()
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_set_provide_clock),
(gst_base_audio_src_get_provide_clock),
(gst_base_audio_src_set_property),
(gst_base_audio_src_get_property), (gst_base_audio_src_create):
* gst-libs/gst/audio/gstbaseaudiosrc.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
API: gst_base_audio_src_set_provide_clock()
API: gst_base_audio_src_get_provide_clock()
2007-11-21 13:04:17 +00:00
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_BASE_SRC (src), FALSE);
|
Expose methods for some object properties so that subclasses can more easily configure them.
Original commit message from CVS:
* docs/libs/gst-plugins-base-libs-sections.txt:
* gst-libs/gst/audio/gstbaseaudiosink.c: (slave_method_get_type),
(gst_base_audio_sink_set_provide_clock),
(gst_base_audio_sink_get_provide_clock),
(gst_base_audio_sink_set_slave_method),
(gst_base_audio_sink_get_slave_method),
(gst_base_audio_sink_set_property),
(gst_base_audio_sink_get_property), (gst_base_audio_sink_drain),
(gst_base_audio_sink_none_slaving),
(gst_base_audio_sink_handle_slaving):
* gst-libs/gst/audio/gstbaseaudiosink.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
Added slave method none, that completely disables slaving to the
internal clock.
API: gst_base_audio_sink_set_provide_clock()
API: gst_base_audio_sink_get_provide_clock()
API: gst_base_audio_sink_set_slave_method()
API: gst_base_audio_sink_get_slave_method()
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_set_provide_clock),
(gst_base_audio_src_get_provide_clock),
(gst_base_audio_src_set_property),
(gst_base_audio_src_get_property), (gst_base_audio_src_create):
* gst-libs/gst/audio/gstbaseaudiosrc.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
API: gst_base_audio_src_set_provide_clock()
API: gst_base_audio_src_get_provide_clock()
2007-11-21 13:04:17 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (src);
|
2011-11-28 16:51:41 +00:00
|
|
|
result = GST_OBJECT_FLAG_IS_SET (src, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
|
Expose methods for some object properties so that subclasses can more easily configure them.
Original commit message from CVS:
* docs/libs/gst-plugins-base-libs-sections.txt:
* gst-libs/gst/audio/gstbaseaudiosink.c: (slave_method_get_type),
(gst_base_audio_sink_set_provide_clock),
(gst_base_audio_sink_get_provide_clock),
(gst_base_audio_sink_set_slave_method),
(gst_base_audio_sink_get_slave_method),
(gst_base_audio_sink_set_property),
(gst_base_audio_sink_get_property), (gst_base_audio_sink_drain),
(gst_base_audio_sink_none_slaving),
(gst_base_audio_sink_handle_slaving):
* gst-libs/gst/audio/gstbaseaudiosink.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
Added slave method none, that completely disables slaving to the
internal clock.
API: gst_base_audio_sink_set_provide_clock()
API: gst_base_audio_sink_get_provide_clock()
API: gst_base_audio_sink_set_slave_method()
API: gst_base_audio_sink_get_slave_method()
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_set_provide_clock),
(gst_base_audio_src_get_provide_clock),
(gst_base_audio_src_set_property),
(gst_base_audio_src_get_property), (gst_base_audio_src_create):
* gst-libs/gst/audio/gstbaseaudiosrc.h:
Expose methods for some object properties so that subclasses can more
easily configure them.
API: gst_base_audio_src_set_provide_clock()
API: gst_base_audio_src_get_provide_clock()
2007-11-21 13:04:17 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-04-28 08:51:38 +00:00
|
|
|
/**
|
2011-11-11 10:52:47 +00:00
|
|
|
* gst_audio_base_src_set_slave_method:
|
|
|
|
* @src: a #GstAudioBaseSrc
|
2008-04-28 08:51:38 +00:00
|
|
|
* @method: the new slave method
|
|
|
|
*
|
2011-11-28 16:51:41 +00:00
|
|
|
* Controls how clock slaving will be performed in @src.
|
2008-04-28 08:51:38 +00:00
|
|
|
*/
|
|
|
|
void
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_set_slave_method (GstAudioBaseSrc * src,
|
|
|
|
GstAudioBaseSrcSlaveMethod method)
|
2008-04-28 08:51:38 +00:00
|
|
|
{
|
2011-11-11 10:52:47 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIO_BASE_SRC (src));
|
2008-04-28 08:51:38 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (src);
|
|
|
|
src->priv->slave_method = method;
|
|
|
|
GST_OBJECT_UNLOCK (src);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-11-11 10:52:47 +00:00
|
|
|
* gst_audio_base_src_get_slave_method:
|
|
|
|
* @src: a #GstAudioBaseSrc
|
2008-04-28 08:51:38 +00:00
|
|
|
*
|
|
|
|
* Get the current slave method used by @src.
|
|
|
|
*
|
|
|
|
* Returns: The current slave method used by @src.
|
|
|
|
*/
|
2011-11-11 10:52:47 +00:00
|
|
|
GstAudioBaseSrcSlaveMethod
|
|
|
|
gst_audio_base_src_get_slave_method (GstAudioBaseSrc * src)
|
2008-04-28 08:51:38 +00:00
|
|
|
{
|
2011-11-11 10:52:47 +00:00
|
|
|
GstAudioBaseSrcSlaveMethod result;
|
2008-04-28 08:51:38 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_BASE_SRC (src), -1);
|
2008-04-28 08:51:38 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (src);
|
|
|
|
result = src->priv->slave_method;
|
|
|
|
GST_OBJECT_UNLOCK (src);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
static void
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_set_property (GObject * object, guint prop_id,
|
2005-07-06 15:27:17 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2011-11-11 10:52:47 +00:00
|
|
|
GstAudioBaseSrc *src;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
src = GST_AUDIO_BASE_SRC (object);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_BUFFER_TIME:
|
|
|
|
src->buffer_time = g_value_get_int64 (value);
|
|
|
|
break;
|
|
|
|
case PROP_LATENCY_TIME:
|
|
|
|
src->latency_time = g_value_get_int64 (value);
|
|
|
|
break;
|
2007-09-10 22:10:54 +00:00
|
|
|
case PROP_PROVIDE_CLOCK:
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_set_provide_clock (src, g_value_get_boolean (value));
|
2007-09-10 22:10:54 +00:00
|
|
|
break;
|
2008-04-28 08:51:38 +00:00
|
|
|
case PROP_SLAVE_METHOD:
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_set_slave_method (src, g_value_get_enum (value));
|
2008-04-28 08:51:38 +00:00
|
|
|
break;
|
2005-07-06 15:27:17 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_get_property (GObject * object, guint prop_id,
|
2005-07-10 12:03:58 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
2011-11-11 10:52:47 +00:00
|
|
|
GstAudioBaseSrc *src;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
src = GST_AUDIO_BASE_SRC (object);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_BUFFER_TIME:
|
|
|
|
g_value_set_int64 (value, src->buffer_time);
|
|
|
|
break;
|
|
|
|
case PROP_LATENCY_TIME:
|
|
|
|
g_value_set_int64 (value, src->latency_time);
|
|
|
|
break;
|
2008-05-31 18:10:47 +00:00
|
|
|
case PROP_ACTUAL_BUFFER_TIME:
|
|
|
|
GST_OBJECT_LOCK (src);
|
|
|
|
if (src->ringbuffer && src->ringbuffer->acquired)
|
|
|
|
g_value_set_int64 (value, src->ringbuffer->spec.buffer_time);
|
|
|
|
else
|
|
|
|
g_value_set_int64 (value, DEFAULT_ACTUAL_BUFFER_TIME);
|
|
|
|
GST_OBJECT_UNLOCK (src);
|
|
|
|
break;
|
|
|
|
case PROP_ACTUAL_LATENCY_TIME:
|
|
|
|
GST_OBJECT_LOCK (src);
|
|
|
|
if (src->ringbuffer && src->ringbuffer->acquired)
|
|
|
|
g_value_set_int64 (value, src->ringbuffer->spec.latency_time);
|
|
|
|
else
|
|
|
|
g_value_set_int64 (value, DEFAULT_ACTUAL_LATENCY_TIME);
|
|
|
|
GST_OBJECT_UNLOCK (src);
|
|
|
|
break;
|
2007-09-10 22:10:54 +00:00
|
|
|
case PROP_PROVIDE_CLOCK:
|
2011-11-11 10:52:47 +00:00
|
|
|
g_value_set_boolean (value, gst_audio_base_src_get_provide_clock (src));
|
2007-09-10 22:10:54 +00:00
|
|
|
break;
|
2008-04-28 08:51:38 +00:00
|
|
|
case PROP_SLAVE_METHOD:
|
2011-11-11 10:52:47 +00:00
|
|
|
g_value_set_enum (value, gst_audio_base_src_get_slave_method (src));
|
2008-04-28 08:51:38 +00:00
|
|
|
break;
|
2005-07-06 15:27:17 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-11 18:04:41 +00:00
|
|
|
static GstCaps *
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
|
|
|
GstStructure *s;
|
|
|
|
|
2012-03-11 18:04:41 +00:00
|
|
|
caps = gst_caps_make_writable (caps);
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
s = gst_caps_get_structure (caps, 0);
|
|
|
|
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
/* fields for all formats */
|
2011-08-18 17:15:03 +00:00
|
|
|
gst_structure_fixate_field_nearest_int (s, "rate", GST_AUDIO_DEF_RATE);
|
|
|
|
gst_structure_fixate_field_nearest_int (s, "channels",
|
|
|
|
GST_AUDIO_DEF_CHANNELS);
|
|
|
|
gst_structure_fixate_field_string (s, "format", GST_AUDIO_DEF_FORMAT);
|
2011-08-17 15:24:35 +00:00
|
|
|
|
2012-03-11 18:04:41 +00:00
|
|
|
caps = GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps);
|
|
|
|
|
|
|
|
return caps;
|
2005-07-06 15:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
2011-11-11 10:52:47 +00:00
|
|
|
GstAudioBaseSrc *src = GST_AUDIO_BASE_SRC (bsrc);
|
2011-11-11 10:21:41 +00:00
|
|
|
GstAudioRingBufferSpec *spec;
|
2011-08-18 17:15:03 +00:00
|
|
|
gint bpf, rate;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2014-01-02 15:18:20 +00:00
|
|
|
spec = &src->ringbuffer->spec;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (spec->caps && gst_caps_is_equal (spec->caps, caps))) {
|
|
|
|
GST_DEBUG_OBJECT (src,
|
|
|
|
"Ringbuffer caps haven't changed, skipping reconfiguration");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-03-22 12:41:17 +00:00
|
|
|
GST_DEBUG ("release old ringbuffer");
|
|
|
|
gst_audio_ring_buffer_release (src->ringbuffer);
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
spec->buffer_time = src->buffer_time;
|
|
|
|
spec->latency_time = src->latency_time;
|
|
|
|
|
2011-02-23 09:55:12 +00:00
|
|
|
GST_OBJECT_LOCK (src);
|
2011-11-11 10:21:41 +00:00
|
|
|
if (!gst_audio_ring_buffer_parse_caps (spec, caps)) {
|
2011-02-23 09:55:12 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
2005-07-06 15:27:17 +00:00
|
|
|
goto parse_error;
|
2011-02-23 09:55:12 +00:00
|
|
|
}
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-08-18 17:15:03 +00:00
|
|
|
bpf = GST_AUDIO_INFO_BPF (&spec->info);
|
|
|
|
rate = GST_AUDIO_INFO_RATE (&spec->info);
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
/* calculate suggested segsize and segtotal */
|
2011-08-18 17:15:03 +00:00
|
|
|
spec->segsize = rate * bpf * spec->latency_time / GST_MSECOND;
|
2005-07-06 15:27:17 +00:00
|
|
|
spec->segtotal = spec->buffer_time / spec->latency_time;
|
|
|
|
|
2011-02-23 09:55:12 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
|
|
|
|
2011-11-11 10:21:41 +00:00
|
|
|
gst_audio_ring_buffer_debug_spec_buff (spec);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("acquire new ringbuffer");
|
|
|
|
|
2011-11-11 10:21:41 +00:00
|
|
|
if (!gst_audio_ring_buffer_acquire (src->ringbuffer, spec))
|
2005-07-06 15:27:17 +00:00
|
|
|
goto acquire_error;
|
|
|
|
|
|
|
|
/* calculate actual latency and buffer times */
|
2011-08-18 17:15:03 +00:00
|
|
|
spec->latency_time = spec->segsize * GST_MSECOND / (rate * bpf);
|
2005-07-06 15:27:17 +00:00
|
|
|
spec->buffer_time =
|
2011-08-18 17:15:03 +00:00
|
|
|
spec->segtotal * spec->segsize * GST_MSECOND / (rate * bpf);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:21:41 +00:00
|
|
|
gst_audio_ring_buffer_debug_spec_buff (spec);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2008-05-31 18:10:47 +00:00
|
|
|
g_object_notify (G_OBJECT (src), "actual-buffer-time");
|
|
|
|
g_object_notify (G_OBJECT (src), "actual-latency-time");
|
|
|
|
|
2015-12-01 17:57:10 +00:00
|
|
|
gst_element_post_message (GST_ELEMENT_CAST (bsrc),
|
|
|
|
gst_message_new_latency (GST_OBJECT (bsrc)));
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
parse_error:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("could not parse caps");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
acquire_error:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("could not acquire ringbuffer");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_get_times (GstBaseSrc * bsrc, GstBuffer * buffer,
|
2005-07-06 15:27:17 +00:00
|
|
|
GstClockTime * start, GstClockTime * end)
|
|
|
|
{
|
2013-12-20 22:48:06 +00:00
|
|
|
/* No need to sync to a clock here. We schedule the samples based
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
* on our own clock for the moment. */
|
2005-07-06 15:27:17 +00:00
|
|
|
*start = GST_CLOCK_TIME_NONE;
|
|
|
|
*end = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
|
2007-02-15 12:06:25 +00:00
|
|
|
static gboolean
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_query (GstBaseSrc * bsrc, GstQuery * query)
|
2007-02-15 12:06:25 +00:00
|
|
|
{
|
2011-11-11 10:52:47 +00:00
|
|
|
GstAudioBaseSrc *src = GST_AUDIO_BASE_SRC (bsrc);
|
2007-02-15 12:06:25 +00:00
|
|
|
gboolean res = FALSE;
|
|
|
|
|
2011-05-17 09:25:31 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
2007-02-15 12:06:25 +00:00
|
|
|
case GST_QUERY_LATENCY:
|
|
|
|
{
|
|
|
|
GstClockTime min_latency, max_latency;
|
2011-11-11 10:21:41 +00:00
|
|
|
GstAudioRingBufferSpec *spec;
|
2011-08-18 17:15:03 +00:00
|
|
|
gint bpf, rate;
|
2007-02-15 12:06:25 +00:00
|
|
|
|
2011-01-22 22:09:32 +00:00
|
|
|
GST_OBJECT_LOCK (src);
|
2007-02-15 12:06:25 +00:00
|
|
|
if (G_UNLIKELY (src->ringbuffer == NULL
|
2011-08-18 17:15:03 +00:00
|
|
|
|| src->ringbuffer->spec.info.rate == 0)) {
|
2011-01-22 22:09:32 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
2007-02-15 12:06:25 +00:00
|
|
|
goto done;
|
2011-01-22 22:09:32 +00:00
|
|
|
}
|
2007-02-15 12:06:25 +00:00
|
|
|
|
|
|
|
spec = &src->ringbuffer->spec;
|
2011-08-18 17:15:03 +00:00
|
|
|
rate = GST_AUDIO_INFO_RATE (&spec->info);
|
|
|
|
bpf = GST_AUDIO_INFO_BPF (&spec->info);
|
2007-02-15 12:06:25 +00:00
|
|
|
|
2007-02-28 15:02:25 +00:00
|
|
|
/* we have at least 1 segment of latency */
|
2007-02-15 12:06:25 +00:00
|
|
|
min_latency =
|
2011-08-18 17:15:03 +00:00
|
|
|
gst_util_uint64_scale_int (spec->segsize, GST_SECOND, rate * bpf);
|
2007-02-28 15:02:25 +00:00
|
|
|
/* we cannot delay more than the buffersize else we lose data */
|
2007-02-15 12:06:25 +00:00
|
|
|
max_latency =
|
|
|
|
gst_util_uint64_scale_int (spec->segtotal * spec->segsize, GST_SECOND,
|
2011-08-18 17:15:03 +00:00
|
|
|
rate * bpf);
|
2011-01-22 22:09:32 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
2007-02-15 12:06:25 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src,
|
|
|
|
"report latency min %" GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
|
|
|
|
|
|
|
|
/* we are always live, the min latency is 1 segment and the max latency is
|
|
|
|
* the complete buffer of segments. */
|
2011-05-17 09:25:31 +00:00
|
|
|
gst_query_set_latency (query, TRUE, min_latency, max_latency);
|
2007-02-15 12:06:25 +00:00
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2011-05-24 15:37:45 +00:00
|
|
|
case GST_QUERY_SCHEDULING:
|
|
|
|
{
|
2013-12-20 22:48:06 +00:00
|
|
|
/* We allow limited pull base operation. Basically, pulling can be
|
2011-11-18 16:58:58 +00:00
|
|
|
* done on any number of bytes as long as the offset is -1 or
|
|
|
|
* sequentially increasing. */
|
|
|
|
gst_query_set_scheduling (query, GST_SCHEDULING_FLAG_SEQUENTIAL, 1, -1,
|
|
|
|
0);
|
|
|
|
gst_query_add_scheduling_mode (query, GST_PAD_MODE_PULL);
|
|
|
|
gst_query_add_scheduling_mode (query, GST_PAD_MODE_PUSH);
|
2011-05-24 15:37:45 +00:00
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2007-02-15 12:06:25 +00:00
|
|
|
default:
|
|
|
|
res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
static gboolean
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_event (GstBaseSrc * bsrc, GstEvent * event)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
2011-11-11 10:52:47 +00:00
|
|
|
GstAudioBaseSrc *src = GST_AUDIO_BASE_SRC (bsrc);
|
2011-11-10 15:24:12 +00:00
|
|
|
gboolean res, forward;
|
2009-06-15 10:57:39 +00:00
|
|
|
|
2011-11-10 15:24:12 +00:00
|
|
|
res = FALSE;
|
|
|
|
forward = TRUE;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2005-07-27 19:13:27 +00:00
|
|
|
case GST_EVENT_FLUSH_START:
|
2009-06-15 10:57:39 +00:00
|
|
|
GST_DEBUG_OBJECT (bsrc, "flush-start");
|
2011-11-11 10:21:41 +00:00
|
|
|
gst_audio_ring_buffer_pause (src->ringbuffer);
|
|
|
|
gst_audio_ring_buffer_clear_all (src->ringbuffer);
|
2005-07-27 19:13:27 +00:00
|
|
|
break;
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
2009-06-15 10:57:39 +00:00
|
|
|
GST_DEBUG_OBJECT (bsrc, "flush-stop");
|
2005-10-06 15:15:04 +00:00
|
|
|
/* always resync on sample after a flush */
|
|
|
|
src->next_sample = -1;
|
2011-11-11 10:21:41 +00:00
|
|
|
gst_audio_ring_buffer_clear_all (src->ringbuffer);
|
2005-07-06 15:27:17 +00:00
|
|
|
break;
|
2009-06-15 10:57:39 +00:00
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
GST_DEBUG_OBJECT (bsrc, "refuse to seek");
|
2011-11-10 15:24:12 +00:00
|
|
|
forward = FALSE;
|
2009-06-15 10:57:39 +00:00
|
|
|
break;
|
2005-07-06 15:27:17 +00:00
|
|
|
default:
|
2011-11-10 15:24:12 +00:00
|
|
|
GST_DEBUG_OBJECT (bsrc, "forward event %p", event);
|
2005-07-06 15:27:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-11-10 15:24:12 +00:00
|
|
|
if (forward)
|
|
|
|
res = GST_BASE_SRC_CLASS (parent_class)->event (bsrc, event);
|
|
|
|
|
2009-06-15 10:57:39 +00:00
|
|
|
return res;
|
2005-07-06 15:27:17 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 22:48:06 +00:00
|
|
|
/* Get the next offset in the ringbuffer for reading samples.
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
* If the next sample is too far away, this function will position itself to the
|
|
|
|
* next most recent sample, creating discontinuity */
|
|
|
|
static guint64
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_get_offset (GstAudioBaseSrc * src)
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
{
|
|
|
|
guint64 sample;
|
|
|
|
gint readseg, segdone, segtotal, sps;
|
|
|
|
gint diff;
|
|
|
|
|
|
|
|
/* assume we can append to the previous sample */
|
|
|
|
sample = src->next_sample;
|
|
|
|
|
|
|
|
sps = src->ringbuffer->samples_per_seg;
|
|
|
|
segtotal = src->ringbuffer->spec.segtotal;
|
|
|
|
|
|
|
|
/* get the currently processed segment */
|
|
|
|
segdone = g_atomic_int_get (&src->ringbuffer->segdone)
|
|
|
|
- src->ringbuffer->segbase;
|
|
|
|
|
2009-11-06 11:19:47 +00:00
|
|
|
if (sample != -1) {
|
2009-11-21 15:47:26 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "at segment %d and sample %" G_GUINT64_FORMAT,
|
|
|
|
segdone, sample);
|
2009-11-06 11:19:47 +00:00
|
|
|
/* figure out the segment and the offset inside the segment where
|
|
|
|
* the sample should be read from. */
|
|
|
|
readseg = sample / sps;
|
|
|
|
|
2013-12-20 22:48:06 +00:00
|
|
|
/* See how far away it is from the read segment. Normally, segdone (where
|
|
|
|
* new data is written in the ringbuffer) is bigger than readseg
|
|
|
|
* (where we are reading). */
|
2009-11-06 11:19:47 +00:00
|
|
|
diff = segdone - readseg;
|
|
|
|
if (diff >= segtotal) {
|
|
|
|
GST_DEBUG_OBJECT (src, "dropped, align to segment %d", segdone);
|
|
|
|
/* sample would be dropped, position to next playable position */
|
|
|
|
sample = ((guint64) (segdone)) * sps;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* no previous sample, go to the current position */
|
|
|
|
GST_DEBUG_OBJECT (src, "first sample, align to current %d", segdone);
|
2009-06-17 12:00:23 +00:00
|
|
|
sample = ((guint64) (segdone)) * sps;
|
2009-11-18 11:37:44 +00:00
|
|
|
readseg = segdone;
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
}
|
|
|
|
|
2009-11-06 11:19:47 +00:00
|
|
|
GST_DEBUG_OBJECT (src,
|
|
|
|
"reading from %d, we are at %d, sample %" G_GUINT64_FORMAT, readseg,
|
|
|
|
segdone, sample);
|
|
|
|
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
return sample;
|
|
|
|
}
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
static GstFlowReturn
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_create (GstBaseSrc * bsrc, guint64 offset, guint length,
|
2006-07-06 15:54:50 +00:00
|
|
|
GstBuffer ** outbuf)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
2011-08-04 16:08:49 +00:00
|
|
|
GstFlowReturn ret;
|
2011-11-11 10:52:47 +00:00
|
|
|
GstAudioBaseSrc *src = GST_AUDIO_BASE_SRC (bsrc);
|
2005-07-06 15:27:17 +00:00
|
|
|
GstBuffer *buf;
|
2012-01-20 15:11:54 +00:00
|
|
|
GstMapInfo info;
|
|
|
|
guint8 *ptr;
|
2007-09-10 22:10:54 +00:00
|
|
|
guint samples, total_samples;
|
2005-10-06 15:15:04 +00:00
|
|
|
guint64 sample;
|
2011-08-18 17:15:03 +00:00
|
|
|
gint bpf, rate;
|
2011-11-11 10:21:41 +00:00
|
|
|
GstAudioRingBuffer *ringbuffer;
|
|
|
|
GstAudioRingBufferSpec *spec;
|
2006-09-27 13:52:14 +00:00
|
|
|
guint read;
|
2008-03-10 17:19:56 +00:00
|
|
|
GstClockTime timestamp, duration;
|
2012-09-10 09:26:38 +00:00
|
|
|
GstClockTime rb_timestamp = GST_CLOCK_TIME_NONE;
|
2007-09-10 22:10:54 +00:00
|
|
|
GstClock *clock;
|
2012-09-10 09:26:38 +00:00
|
|
|
gboolean first;
|
2011-08-02 13:11:14 +00:00
|
|
|
gboolean first_sample = src->next_sample == -1;
|
2006-01-25 09:27:01 +00:00
|
|
|
|
|
|
|
ringbuffer = src->ringbuffer;
|
2007-09-10 22:10:54 +00:00
|
|
|
spec = &ringbuffer->spec;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:21:41 +00:00
|
|
|
if (G_UNLIKELY (!gst_audio_ring_buffer_is_acquired (ringbuffer)))
|
2005-07-06 15:27:17 +00:00
|
|
|
goto wrong_state;
|
|
|
|
|
2011-08-18 17:15:03 +00:00
|
|
|
bpf = GST_AUDIO_INFO_BPF (&spec->info);
|
|
|
|
rate = GST_AUDIO_INFO_RATE (&spec->info);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2006-07-06 15:54:50 +00:00
|
|
|
if ((length == 0 && bsrc->blocksize == 0) || length == -1)
|
|
|
|
/* no length given, use the default segment size */
|
2007-09-10 22:10:54 +00:00
|
|
|
length = spec->segsize;
|
2006-07-06 15:54:50 +00:00
|
|
|
else
|
|
|
|
/* make sure we round down to an integral number of samples */
|
2011-08-18 17:15:03 +00:00
|
|
|
length -= length % bpf;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
/* figure out the offset in the ringbuffer */
|
2006-07-06 15:54:50 +00:00
|
|
|
if (G_UNLIKELY (offset != -1)) {
|
2011-08-18 17:15:03 +00:00
|
|
|
sample = offset / bpf;
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
/* if a specific offset was given it must be the next sequential
|
|
|
|
* offset we expect or we fail for now. */
|
|
|
|
if (src->next_sample != -1 && sample != src->next_sample)
|
2006-07-06 15:54:50 +00:00
|
|
|
goto wrong_offset;
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
} else {
|
2013-12-20 22:48:06 +00:00
|
|
|
/* Calculate the sequentially-next sample we need to read. This can jump and
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
* create a DISCONT. */
|
2011-11-11 10:52:47 +00:00
|
|
|
sample = gst_audio_base_src_get_offset (src);
|
2005-10-06 15:15:04 +00:00
|
|
|
}
|
|
|
|
|
2011-08-04 16:08:49 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "reading from sample %" G_GUINT64_FORMAT " length %u",
|
|
|
|
sample, length);
|
2007-05-21 10:25:44 +00:00
|
|
|
|
2006-07-06 15:54:50 +00:00
|
|
|
/* get the number of samples to read */
|
2011-08-18 17:15:03 +00:00
|
|
|
total_samples = samples = length / bpf;
|
2006-07-06 15:54:50 +00:00
|
|
|
|
2011-08-04 16:08:49 +00:00
|
|
|
/* use the basesrc allocation code to use bufferpools or custom allocators */
|
|
|
|
ret = GST_BASE_SRC_CLASS (parent_class)->alloc (bsrc, offset, length, &buf);
|
|
|
|
if (G_UNLIKELY (ret != GST_FLOW_OK))
|
|
|
|
goto alloc_failed;
|
|
|
|
|
2012-01-20 15:11:54 +00:00
|
|
|
gst_buffer_map (buf, &info, GST_MAP_WRITE);
|
|
|
|
ptr = info.data;
|
2012-09-10 09:26:38 +00:00
|
|
|
first = TRUE;
|
2006-09-27 13:52:14 +00:00
|
|
|
do {
|
2012-12-20 15:41:48 +00:00
|
|
|
GstClockTime tmp_ts = GST_CLOCK_TIME_NONE;
|
2012-09-10 09:26:38 +00:00
|
|
|
|
|
|
|
read =
|
|
|
|
gst_audio_ring_buffer_read (ringbuffer, sample, ptr, samples, &tmp_ts);
|
|
|
|
if (first && GST_CLOCK_TIME_IS_VALID (tmp_ts)) {
|
|
|
|
first = FALSE;
|
|
|
|
rb_timestamp = tmp_ts;
|
|
|
|
}
|
2006-09-27 13:52:14 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "read %u of %u", read, samples);
|
|
|
|
/* if we read all, we're done */
|
|
|
|
if (read == samples)
|
|
|
|
break;
|
|
|
|
|
2012-12-17 20:28:12 +00:00
|
|
|
if (g_atomic_int_get (&ringbuffer->state) ==
|
|
|
|
GST_AUDIO_RING_BUFFER_STATE_ERROR)
|
|
|
|
goto got_error;
|
|
|
|
|
2006-09-27 13:52:14 +00:00
|
|
|
/* else something interrupted us and we wait for playing again. */
|
2007-12-17 16:44:51 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "wait playing");
|
2006-09-27 13:52:14 +00:00
|
|
|
if (gst_base_src_wait_playing (bsrc) != GST_FLOW_OK)
|
|
|
|
goto stopped;
|
|
|
|
|
2007-12-17 16:44:51 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "continue playing");
|
|
|
|
|
2006-09-27 13:52:14 +00:00
|
|
|
/* read next samples */
|
|
|
|
sample += read;
|
|
|
|
samples -= read;
|
2011-08-18 17:15:03 +00:00
|
|
|
ptr += read * bpf;
|
2006-09-27 13:52:14 +00:00
|
|
|
} while (TRUE);
|
2012-01-20 15:11:54 +00:00
|
|
|
gst_buffer_unmap (buf, &info);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
/* mark discontinuity if needed */
|
|
|
|
if (G_UNLIKELY (sample != src->next_sample) && src->next_sample != -1) {
|
|
|
|
GST_WARNING_OBJECT (src,
|
|
|
|
"create DISCONT of %" G_GUINT64_FORMAT " samples at sample %"
|
|
|
|
G_GUINT64_FORMAT, sample - src->next_sample, sample);
|
2007-04-25 08:54:34 +00:00
|
|
|
GST_ELEMENT_WARNING (src, CORE, CLOCK,
|
|
|
|
(_("Can't record audio fast enough")),
|
2009-03-25 11:27:44 +00:00
|
|
|
("Dropped %" G_GUINT64_FORMAT " samples. This is most likely because "
|
|
|
|
"downstream can't keep up and is consuming samples too slowly.",
|
|
|
|
sample - src->next_sample));
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
}
|
|
|
|
|
2008-03-10 17:19:56 +00:00
|
|
|
src->next_sample = sample + samples;
|
|
|
|
|
|
|
|
/* get the normal timestamp to get the duration. */
|
2011-08-18 17:15:03 +00:00
|
|
|
timestamp = gst_util_uint64_scale_int (sample, GST_SECOND, rate);
|
2008-03-10 17:19:56 +00:00
|
|
|
duration = gst_util_uint64_scale_int (src->next_sample, GST_SECOND,
|
2011-08-18 17:15:03 +00:00
|
|
|
rate) - timestamp;
|
2008-03-10 17:19:56 +00:00
|
|
|
|
2007-09-10 22:10:54 +00:00
|
|
|
GST_OBJECT_LOCK (src);
|
2008-08-13 09:17:38 +00:00
|
|
|
if (!(clock = GST_ELEMENT_CLOCK (src)))
|
|
|
|
goto no_sync;
|
|
|
|
|
2013-05-07 05:49:00 +00:00
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (rb_timestamp) && clock != src->clock) {
|
2008-08-13 09:17:38 +00:00
|
|
|
/* we are slaved, check how to handle this */
|
2008-04-28 08:51:38 +00:00
|
|
|
switch (src->priv->slave_method) {
|
2011-11-11 10:52:47 +00:00
|
|
|
case GST_AUDIO_BASE_SRC_SLAVE_RESAMPLE:
|
2013-12-20 22:48:06 +00:00
|
|
|
/* Not implemented, use skew algorithm. This algorithm should
|
|
|
|
* work on the readout pointer and produce more or less samples based
|
2008-04-28 08:51:38 +00:00
|
|
|
* on the clock drift */
|
2011-11-11 10:52:47 +00:00
|
|
|
case GST_AUDIO_BASE_SRC_SLAVE_SKEW:
|
2008-10-08 09:12:36 +00:00
|
|
|
{
|
|
|
|
GstClockTime running_time;
|
|
|
|
GstClockTime base_time;
|
|
|
|
GstClockTime current_time;
|
|
|
|
guint64 running_time_sample;
|
|
|
|
gint running_time_segment;
|
2009-09-08 10:59:20 +00:00
|
|
|
gint last_read_segment;
|
2008-10-08 09:12:36 +00:00
|
|
|
gint segment_skew;
|
|
|
|
gint sps;
|
2009-09-08 10:59:20 +00:00
|
|
|
gint segments_written;
|
|
|
|
gint last_written_segment;
|
|
|
|
|
|
|
|
/* get the amount of segments written from the device by now */
|
|
|
|
segments_written = g_atomic_int_get (&ringbuffer->segdone);
|
|
|
|
|
|
|
|
/* subtract the base to segments_written to get the number of the
|
2013-12-20 21:53:13 +00:00
|
|
|
* last written segment in the ringbuffer
|
|
|
|
* (one segment written = segment 0) */
|
2009-09-08 10:59:20 +00:00
|
|
|
last_written_segment = segments_written - ringbuffer->segbase - 1;
|
2008-10-08 09:12:36 +00:00
|
|
|
|
|
|
|
/* samples per segment */
|
|
|
|
sps = ringbuffer->samples_per_seg;
|
|
|
|
|
|
|
|
/* get the current time */
|
|
|
|
current_time = gst_clock_get_time (clock);
|
|
|
|
|
|
|
|
/* get the basetime */
|
|
|
|
base_time = GST_ELEMENT_CAST (src)->base_time;
|
|
|
|
|
|
|
|
/* get the running_time */
|
|
|
|
running_time = current_time - base_time;
|
|
|
|
|
2013-12-20 21:53:13 +00:00
|
|
|
/* the running_time converted to a sample
|
|
|
|
* (relative to the ringbuffer) */
|
2008-10-08 09:12:36 +00:00
|
|
|
running_time_sample =
|
2011-08-18 17:15:03 +00:00
|
|
|
gst_util_uint64_scale_int (running_time, rate, GST_SECOND);
|
2008-10-08 09:12:36 +00:00
|
|
|
|
2011-09-13 19:10:43 +00:00
|
|
|
/* the segmentnr corresponding to running_time, round down */
|
2008-10-08 09:12:36 +00:00
|
|
|
running_time_segment = running_time_sample / sps;
|
|
|
|
|
|
|
|
/* the segment currently read from the ringbuffer */
|
2009-09-08 10:59:20 +00:00
|
|
|
last_read_segment = sample / sps;
|
|
|
|
|
2013-12-20 21:53:13 +00:00
|
|
|
/* the skew we have between running_time and the ringbuffertime
|
|
|
|
* (last written to) */
|
2009-09-08 10:59:20 +00:00
|
|
|
segment_skew = running_time_segment - last_written_segment;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bsrc,
|
|
|
|
"\n running_time = %"
|
|
|
|
GST_TIME_FORMAT
|
|
|
|
"\n timestamp = %"
|
|
|
|
GST_TIME_FORMAT
|
|
|
|
"\n running_time_segment = %d"
|
|
|
|
"\n last_written_segment = %d"
|
|
|
|
"\n segment_skew (running time segment - last_written_segment) = %d"
|
|
|
|
"\n last_read_segment = %d",
|
|
|
|
GST_TIME_ARGS (running_time), GST_TIME_ARGS (timestamp),
|
|
|
|
running_time_segment, last_written_segment, segment_skew,
|
|
|
|
last_read_segment);
|
2008-10-08 09:12:36 +00:00
|
|
|
|
|
|
|
/* Resync the ringbuffer if:
|
|
|
|
*
|
2009-09-08 10:59:20 +00:00
|
|
|
* 1. We are more than the length of the ringbuffer behind.
|
2008-10-08 09:12:36 +00:00
|
|
|
* The length of the ringbuffer then gets to dictate
|
2011-09-13 19:10:43 +00:00
|
|
|
* the threshold for what is considered "too late"
|
2008-10-08 09:12:36 +00:00
|
|
|
*
|
2009-09-08 10:59:20 +00:00
|
|
|
* 2. If this is our first buffer.
|
2008-10-08 09:12:36 +00:00
|
|
|
* We know that we should catch up to running_time
|
|
|
|
* the first time we are ran.
|
|
|
|
*/
|
2009-09-08 10:59:20 +00:00
|
|
|
if ((segment_skew >= ringbuffer->spec.segtotal) ||
|
2011-08-02 13:11:14 +00:00
|
|
|
(last_read_segment == 0) || first_sample) {
|
2009-09-08 10:59:20 +00:00
|
|
|
gint new_read_segment;
|
2008-10-08 09:12:36 +00:00
|
|
|
gint segment_diff;
|
|
|
|
guint64 new_sample;
|
|
|
|
|
2009-09-08 10:59:20 +00:00
|
|
|
/* the difference between running_time and the last written segment */
|
|
|
|
segment_diff = running_time_segment - last_written_segment;
|
2008-10-08 09:12:36 +00:00
|
|
|
|
2009-09-08 10:59:20 +00:00
|
|
|
/* advance the ringbuffer */
|
2011-11-11 10:21:41 +00:00
|
|
|
gst_audio_ring_buffer_advance (ringbuffer, segment_diff);
|
2008-10-08 09:12:36 +00:00
|
|
|
|
2009-09-08 10:59:20 +00:00
|
|
|
/* we move the new read segment to the last known written segment */
|
|
|
|
new_read_segment =
|
|
|
|
g_atomic_int_get (&ringbuffer->segdone) - ringbuffer->segbase;
|
2008-10-08 09:12:36 +00:00
|
|
|
|
|
|
|
/* we calculate the new sample value */
|
2009-09-08 10:59:20 +00:00
|
|
|
new_sample = ((guint64) new_read_segment) * sps;
|
2008-10-08 09:12:36 +00:00
|
|
|
|
|
|
|
/* and get the relative time to this -> our new timestamp */
|
2011-08-18 17:15:03 +00:00
|
|
|
timestamp = gst_util_uint64_scale_int (new_sample, GST_SECOND, rate);
|
2008-10-08 09:12:36 +00:00
|
|
|
|
|
|
|
/* we update the next sample accordingly */
|
|
|
|
src->next_sample = new_sample + samples;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bsrc,
|
|
|
|
"Timeshifted the ringbuffer with %d segments: "
|
2008-10-08 15:30:33 +00:00
|
|
|
"Updating the timestamp to %" GST_TIME_FORMAT ", "
|
|
|
|
"and src->next_sample to %" G_GUINT64_FORMAT, segment_diff,
|
2008-10-08 09:12:36 +00:00
|
|
|
GST_TIME_ARGS (timestamp), src->next_sample);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-04-09 08:48:27 +00:00
|
|
|
case GST_AUDIO_BASE_SRC_SLAVE_RE_TIMESTAMP:
|
2008-04-28 08:51:38 +00:00
|
|
|
{
|
|
|
|
GstClockTime base_time, latency;
|
|
|
|
|
2013-12-20 22:48:06 +00:00
|
|
|
/* We are slaved to another clock. Take running time of the pipeline
|
2013-12-20 21:53:13 +00:00
|
|
|
* clock and timestamp against it. Somebody else in the pipeline should
|
|
|
|
* figure out the clock drift. We keep the duration we calculated
|
|
|
|
* above. */
|
2008-04-28 08:51:38 +00:00
|
|
|
timestamp = gst_clock_get_time (clock);
|
|
|
|
base_time = GST_ELEMENT_CAST (src)->base_time;
|
|
|
|
|
2009-10-13 16:14:41 +00:00
|
|
|
if (GST_CLOCK_DIFF (timestamp, base_time) < 0)
|
2008-04-28 08:51:38 +00:00
|
|
|
timestamp -= base_time;
|
|
|
|
else
|
|
|
|
timestamp = 0;
|
|
|
|
|
|
|
|
/* subtract latency */
|
2011-08-18 17:15:03 +00:00
|
|
|
latency = gst_util_uint64_scale_int (total_samples, GST_SECOND, rate);
|
2008-04-28 08:51:38 +00:00
|
|
|
if (timestamp > latency)
|
|
|
|
timestamp -= latency;
|
|
|
|
else
|
|
|
|
timestamp = 0;
|
|
|
|
}
|
2011-11-11 10:52:47 +00:00
|
|
|
case GST_AUDIO_BASE_SRC_SLAVE_NONE:
|
2008-04-28 08:51:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-08-13 09:17:38 +00:00
|
|
|
} else {
|
|
|
|
GstClockTime base_time;
|
|
|
|
|
2012-09-10 09:26:38 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (rb_timestamp)) {
|
|
|
|
/* the read method returned a timestamp so we use this instead */
|
|
|
|
timestamp = rb_timestamp;
|
|
|
|
} else {
|
2013-12-20 21:53:13 +00:00
|
|
|
/* to get the timestamp against the clock we also need to add our
|
|
|
|
* offset */
|
2015-10-15 10:52:27 +00:00
|
|
|
timestamp = gst_audio_clock_adjust (GST_AUDIO_CLOCK (clock), timestamp);
|
2012-09-10 09:26:38 +00:00
|
|
|
}
|
2009-04-14 11:16:14 +00:00
|
|
|
|
2008-08-13 09:17:38 +00:00
|
|
|
/* we are not slaved, subtract base_time */
|
|
|
|
base_time = GST_ELEMENT_CAST (src)->base_time;
|
|
|
|
|
2009-10-13 16:14:41 +00:00
|
|
|
if (GST_CLOCK_DIFF (timestamp, base_time) < 0) {
|
2008-08-13 09:17:38 +00:00
|
|
|
timestamp -= base_time;
|
2009-05-05 12:37:54 +00:00
|
|
|
GST_LOG_OBJECT (src,
|
|
|
|
"buffer timestamp %" GST_TIME_FORMAT " (base_time %" GST_TIME_FORMAT
|
|
|
|
")", GST_TIME_ARGS (timestamp), GST_TIME_ARGS (base_time));
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (src,
|
|
|
|
"buffer timestamp 0, ts %" GST_TIME_FORMAT " <= base_time %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (timestamp),
|
|
|
|
GST_TIME_ARGS (base_time));
|
2008-08-13 09:17:38 +00:00
|
|
|
timestamp = 0;
|
2009-05-05 12:37:54 +00:00
|
|
|
}
|
2007-09-10 22:10:54 +00:00
|
|
|
}
|
2008-08-13 09:17:38 +00:00
|
|
|
|
|
|
|
no_sync:
|
2007-09-10 22:10:54 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
2007-05-21 10:25:44 +00:00
|
|
|
|
|
|
|
GST_BUFFER_TIMESTAMP (buf) = timestamp;
|
2008-03-10 17:19:56 +00:00
|
|
|
GST_BUFFER_DURATION (buf) = duration;
|
gst-libs/gst/audio/: Do the delay calculation in the source/sink base classes as this is specific for the capture/pla...
Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_get_time), (gst_base_audio_sink_callback):
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_get_time), (gst_base_audio_src_fixate),
(gst_base_audio_src_get_times), (gst_base_audio_src_get_offset),
(gst_base_audio_src_create), (gst_base_audio_src_change_state):
Do the delay calculation in the source/sink base classes as this is
specific for the capture/playback mode.
Try to fixate a bit better, like round depth up to a multiple of 8
bigger than width.
Handle underruns correctly by marking DISCONT on buffers and adjusting
timestamps to handle the gap.
Set offset/offset_end correctly on buffers.
* gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_pause),
(gst_ring_buffer_samples_done), (gst_ring_buffer_commit),
(gst_ring_buffer_read):
Remove resync and underrun recovery from the ringbuffer.
Fix ringbuffer read code on under/overrun.
2006-09-15 14:53:44 +00:00
|
|
|
GST_BUFFER_OFFSET (buf) = sample;
|
|
|
|
GST_BUFFER_OFFSET_END (buf) = sample + samples;
|
2005-10-06 15:15:04 +00:00
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
*outbuf = buf;
|
|
|
|
|
2012-09-10 09:26:38 +00:00
|
|
|
GST_LOG_OBJECT (src, "Pushed buffer timestamp %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
2006-07-06 15:54:50 +00:00
|
|
|
/* ERRORS */
|
2005-07-06 15:27:17 +00:00
|
|
|
wrong_state:
|
|
|
|
{
|
2006-07-06 15:54:50 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "ringbuffer in wrong state");
|
2012-02-08 14:17:49 +00:00
|
|
|
return GST_FLOW_FLUSHING;
|
2005-07-06 15:27:17 +00:00
|
|
|
}
|
2006-07-06 15:54:50 +00:00
|
|
|
wrong_offset:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, SEEK,
|
|
|
|
(NULL), ("resource can only be operated on sequentially but offset %"
|
|
|
|
G_GUINT64_FORMAT " was given", offset));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2011-08-04 16:08:49 +00:00
|
|
|
alloc_failed:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (src, "alloc failed: %s", gst_flow_get_name (ret));
|
|
|
|
return ret;
|
|
|
|
}
|
2005-07-06 15:27:17 +00:00
|
|
|
stopped:
|
|
|
|
{
|
2013-06-17 14:34:26 +00:00
|
|
|
gst_buffer_unmap (buf, &info);
|
2005-07-06 15:27:17 +00:00
|
|
|
gst_buffer_unref (buf);
|
2006-07-06 15:54:50 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "ringbuffer stopped");
|
2012-02-08 14:17:49 +00:00
|
|
|
return GST_FLOW_FLUSHING;
|
2005-07-06 15:27:17 +00:00
|
|
|
}
|
2012-12-17 20:28:12 +00:00
|
|
|
got_error:
|
|
|
|
{
|
2013-06-17 14:34:26 +00:00
|
|
|
gst_buffer_unmap (buf, &info);
|
2012-12-17 20:28:12 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
GST_DEBUG_OBJECT (src, "ringbuffer was in error state, bailing out");
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2005-07-06 15:27:17 +00:00
|
|
|
}
|
|
|
|
|
2006-09-27 11:05:08 +00:00
|
|
|
/**
|
2011-11-11 10:52:47 +00:00
|
|
|
* gst_audio_base_src_create_ringbuffer:
|
|
|
|
* @src: a #GstAudioBaseSrc.
|
2006-09-27 11:05:08 +00:00
|
|
|
*
|
2013-12-20 21:53:13 +00:00
|
|
|
* Create and return the #GstAudioRingBuffer for @src. This function will call
|
|
|
|
* the ::create_ringbuffer vmethod and will set @src as the parent of the
|
|
|
|
* returned buffer (see gst_object_set_parent()).
|
2006-09-27 11:05:08 +00:00
|
|
|
*
|
2012-07-13 10:11:06 +00:00
|
|
|
* Returns: (transfer none): The new ringbuffer of @src.
|
2006-09-27 11:05:08 +00:00
|
|
|
*/
|
2011-11-11 10:21:41 +00:00
|
|
|
GstAudioRingBuffer *
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_create_ringbuffer (GstAudioBaseSrc * src)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
2011-11-11 10:52:47 +00:00
|
|
|
GstAudioBaseSrcClass *bclass;
|
2011-11-11 10:21:41 +00:00
|
|
|
GstAudioRingBuffer *buffer = NULL;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2011-11-11 10:52:47 +00:00
|
|
|
bclass = GST_AUDIO_BASE_SRC_GET_CLASS (src);
|
2005-07-06 15:27:17 +00:00
|
|
|
if (bclass->create_ringbuffer)
|
|
|
|
buffer = bclass->create_ringbuffer (src);
|
|
|
|
|
2006-07-06 15:54:50 +00:00
|
|
|
if (G_LIKELY (buffer))
|
|
|
|
gst_object_set_parent (GST_OBJECT_CAST (buffer), GST_OBJECT_CAST (src));
|
2005-07-06 15:27:17 +00:00
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2005-09-02 15:43:18 +00:00
|
|
|
static GstStateChangeReturn
|
2011-11-11 10:52:47 +00:00
|
|
|
gst_audio_base_src_change_state (GstElement * element,
|
2005-09-02 15:43:18 +00:00
|
|
|
GstStateChange transition)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
2005-09-02 15:43:18 +00:00
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
2011-11-11 10:52:47 +00:00
|
|
|
GstAudioBaseSrc *src = GST_AUDIO_BASE_SRC (element);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
2014-12-22 09:45:37 +00:00
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:{
|
|
|
|
GstAudioRingBuffer *rb;
|
|
|
|
|
2007-12-17 16:44:51 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "NULL->READY");
|
2014-12-22 09:45:37 +00:00
|
|
|
gst_audio_clock_reset (GST_AUDIO_CLOCK (src->clock), 0);
|
|
|
|
rb = gst_audio_base_src_create_ringbuffer (src);
|
|
|
|
if (rb == NULL)
|
|
|
|
goto create_failed;
|
|
|
|
|
2008-05-31 18:10:47 +00:00
|
|
|
GST_OBJECT_LOCK (src);
|
2014-12-22 09:45:37 +00:00
|
|
|
src->ringbuffer = rb;
|
2008-05-31 18:10:47 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
2014-12-22 09:45:37 +00:00
|
|
|
|
2015-04-09 11:59:38 +00:00
|
|
|
if (!gst_audio_ring_buffer_open_device (src->ringbuffer)) {
|
|
|
|
GST_OBJECT_LOCK (src);
|
|
|
|
gst_object_unparent (GST_OBJECT_CAST (src->ringbuffer));
|
|
|
|
src->ringbuffer = NULL;
|
|
|
|
GST_OBJECT_UNLOCK (src);
|
2007-02-15 12:06:25 +00:00
|
|
|
goto open_failed;
|
2015-04-09 11:59:38 +00:00
|
|
|
}
|
2005-07-06 15:27:17 +00:00
|
|
|
break;
|
2014-12-22 09:45:37 +00:00
|
|
|
}
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2007-12-17 16:44:51 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "READY->PAUSED");
|
2007-02-15 12:06:25 +00:00
|
|
|
src->next_sample = -1;
|
2011-11-11 10:21:41 +00:00
|
|
|
gst_audio_ring_buffer_set_flushing (src->ringbuffer, FALSE);
|
|
|
|
gst_audio_ring_buffer_may_start (src->ringbuffer, FALSE);
|
2010-07-09 15:15:35 +00:00
|
|
|
/* Only post clock-provide messages if this is the clock that
|
|
|
|
* we've created. If the subclass has overriden it the subclass
|
|
|
|
* should post this messages whenever necessary */
|
|
|
|
if (src->clock && GST_IS_AUDIO_CLOCK (src->clock) &&
|
|
|
|
GST_AUDIO_CLOCK_CAST (src->clock)->func ==
|
2011-11-11 10:52:47 +00:00
|
|
|
(GstAudioClockGetTimeFunc) gst_audio_base_src_get_time)
|
2010-07-09 15:15:35 +00:00
|
|
|
gst_element_post_message (element,
|
|
|
|
gst_message_new_clock_provide (GST_OBJECT_CAST (element),
|
|
|
|
src->clock, TRUE));
|
2005-07-06 15:27:17 +00:00
|
|
|
break;
|
2010-08-04 13:18:37 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
|
|
GST_DEBUG_OBJECT (src, "PAUSED->PLAYING");
|
2011-11-11 10:21:41 +00:00
|
|
|
gst_audio_ring_buffer_may_start (src->ringbuffer, TRUE);
|
2010-08-04 13:18:37 +00:00
|
|
|
break;
|
2007-12-17 16:44:51 +00:00
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
|
|
GST_DEBUG_OBJECT (src, "PLAYING->PAUSED");
|
2011-11-11 10:21:41 +00:00
|
|
|
gst_audio_ring_buffer_may_start (src->ringbuffer, FALSE);
|
|
|
|
gst_audio_ring_buffer_pause (src->ringbuffer);
|
2010-08-04 13:18:37 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
GST_DEBUG_OBJECT (src, "PAUSED->READY");
|
2010-07-09 15:15:35 +00:00
|
|
|
/* Only post clock-lost messages if this is the clock that
|
|
|
|
* we've created. If the subclass has overriden it the subclass
|
|
|
|
* should post this messages whenever necessary */
|
|
|
|
if (src->clock && GST_IS_AUDIO_CLOCK (src->clock) &&
|
|
|
|
GST_AUDIO_CLOCK_CAST (src->clock)->func ==
|
2011-11-11 10:52:47 +00:00
|
|
|
(GstAudioClockGetTimeFunc) gst_audio_base_src_get_time)
|
2010-07-09 15:15:35 +00:00
|
|
|
gst_element_post_message (element,
|
|
|
|
gst_message_new_clock_lost (GST_OBJECT_CAST (element), src->clock));
|
2011-11-11 10:21:41 +00:00
|
|
|
gst_audio_ring_buffer_set_flushing (src->ringbuffer, TRUE);
|
2007-02-15 12:06:25 +00:00
|
|
|
break;
|
2005-07-06 15:27:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-09-02 15:43:18 +00:00
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2007-12-17 16:44:51 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "PAUSED->READY");
|
2011-11-11 10:21:41 +00:00
|
|
|
gst_audio_ring_buffer_release (src->ringbuffer);
|
2005-07-06 15:27:17 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2007-12-17 16:44:51 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "READY->NULL");
|
2011-11-11 10:21:41 +00:00
|
|
|
gst_audio_ring_buffer_close_device (src->ringbuffer);
|
2008-05-31 18:10:47 +00:00
|
|
|
GST_OBJECT_LOCK (src);
|
2006-03-23 16:29:58 +00:00
|
|
|
gst_object_unparent (GST_OBJECT_CAST (src->ringbuffer));
|
2005-08-16 15:53:59 +00:00
|
|
|
src->ringbuffer = NULL;
|
2008-05-31 18:10:47 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
2005-07-06 15:27:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2007-02-15 12:06:25 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2014-12-22 09:45:37 +00:00
|
|
|
create_failed:
|
|
|
|
{
|
|
|
|
/* subclass must post a meaningful error message */
|
|
|
|
GST_DEBUG_OBJECT (src, "create failed");
|
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
|
|
|
}
|
2007-02-15 12:06:25 +00:00
|
|
|
open_failed:
|
|
|
|
{
|
2011-09-13 19:10:43 +00:00
|
|
|
/* subclass must post a meaningful error message */
|
2007-02-15 12:06:25 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "open failed");
|
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
|
|
|
}
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
}
|
2012-12-17 20:28:12 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_audio_base_src_post_message (GstElement * element, GstMessage * message)
|
|
|
|
{
|
|
|
|
GstAudioBaseSrc *src = GST_AUDIO_BASE_SRC (element);
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR) {
|
|
|
|
GstAudioRingBuffer *ringbuffer;
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (element, "subclass posted error");
|
|
|
|
|
|
|
|
ringbuffer = gst_object_ref (src->ringbuffer);
|
|
|
|
|
|
|
|
/* post message first before signalling the error to the ringbuffer, to
|
|
|
|
* make sure it ends up on the bus before the generic basesrc internal
|
|
|
|
* flow error message */
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->post_message (element, message);
|
|
|
|
|
|
|
|
g_atomic_int_set (&ringbuffer->state, GST_AUDIO_RING_BUFFER_STATE_ERROR);
|
|
|
|
GST_AUDIO_RING_BUFFER_SIGNAL (ringbuffer);
|
|
|
|
gst_object_unref (ringbuffer);
|
|
|
|
} else {
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->post_message (element, message);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|