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>
|
|
|
|
*
|
|
|
|
* gstbaseaudiosrc.c:
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2006-09-27 11:05:08 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstbaseaudiosrc
|
|
|
|
* @short_description: Base class for audio sources
|
|
|
|
* @see_also: #GstAudioSrc, #GstRingBuffer.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Last reviewed on 2006-09-27 (0.10.12)
|
|
|
|
*/
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
#include "gstbaseaudiosrc.h"
|
|
|
|
|
2007-04-25 08:54:34 +00:00
|
|
|
#include "gst/gst-i18n-plugin.h"
|
|
|
|
|
2005-07-10 12:03:58 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_base_audio_src_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_base_audio_src_debug
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2008-12-19 13:03:00 +00:00
|
|
|
GType
|
2008-12-13 06:57:09 +00:00
|
|
|
gst_base_audio_src_slave_method_get_type (void)
|
2008-04-28 08:51:38 +00:00
|
|
|
{
|
2010-10-08 08:48:50 +00:00
|
|
|
static volatile gsize slave_method_type = 0;
|
2010-10-08 08:45:30 +00:00
|
|
|
/* FIXME 0.11: nick should be "retimestamp" not "re-timestamp" */
|
2008-04-28 08:51:38 +00:00
|
|
|
static const GEnumValue slave_method[] = {
|
2010-10-08 08:45:30 +00:00
|
|
|
{GST_BASE_AUDIO_SRC_SLAVE_RESAMPLE,
|
|
|
|
"GST_BASE_AUDIO_SRC_SLAVE_RESAMPLE", "resample"},
|
|
|
|
{GST_BASE_AUDIO_SRC_SLAVE_RETIMESTAMP,
|
|
|
|
"GST_BASE_AUDIO_SRC_SLAVE_RETIMESTAMP", "re-timestamp"},
|
|
|
|
{GST_BASE_AUDIO_SRC_SLAVE_SKEW, "GST_BASE_AUDIO_SRC_SLAVE_SKEW", "skew"},
|
|
|
|
{GST_BASE_AUDIO_SRC_SLAVE_NONE, "GST_BASE_AUDIO_SRC_SLAVE_NONE", "none"},
|
2008-04-28 08:51:38 +00:00
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
2010-10-08 08:48:50 +00:00
|
|
|
if (g_once_init_enter (&slave_method_type)) {
|
|
|
|
GType tmp =
|
2008-04-28 08:51:38 +00:00
|
|
|
g_enum_register_static ("GstBaseAudioSrcSlaveMethod", slave_method);
|
2010-10-08 08:48:50 +00:00
|
|
|
g_once_init_leave (&slave_method_type, tmp);
|
2008-04-28 08:51:38 +00:00
|
|
|
}
|
2010-10-08 08:48:50 +00:00
|
|
|
return (GType) slave_method_type;
|
2008-04-28 08:51:38 +00:00
|
|
|
}
|
|
|
|
|
2007-09-10 22:10:54 +00:00
|
|
|
#define GST_BASE_AUDIO_SRC_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BASE_AUDIO_SRC, GstBaseAudioSrcPrivate))
|
|
|
|
|
|
|
|
struct _GstBaseAudioSrcPrivate
|
|
|
|
{
|
|
|
|
gboolean provide_clock;
|
2008-04-28 08:51:38 +00:00
|
|
|
|
|
|
|
/* the clock slaving algorithm in use */
|
|
|
|
GstBaseAudioSrcSlaveMethod 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
|
|
|
|
};
|
|
|
|
|
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
|
2009-08-06 10:58:58 +00:00
|
|
|
#define DEFAULT_SLAVE_METHOD GST_BASE_AUDIO_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)
|
|
|
|
{
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_base_audio_src_debug, "baseaudiosrc", 0,
|
|
|
|
"baseaudiosrc element");
|
|
|
|
|
|
|
|
#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
|
|
|
|
2005-07-10 12:03:58 +00:00
|
|
|
GST_BOILERPLATE_FULL (GstBaseAudioSrc, gst_base_audio_src, GstPushSrc,
|
2005-07-14 09:35:11 +00:00
|
|
|
GST_TYPE_PUSH_SRC, _do_init);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2005-07-10 12:03:58 +00:00
|
|
|
static void gst_base_audio_src_set_property (GObject * object, guint prop_id,
|
2005-07-06 15:27:17 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2005-07-10 12:03:58 +00:00
|
|
|
static void gst_base_audio_src_get_property (GObject * object, guint prop_id,
|
2005-07-06 15:27:17 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
2007-02-15 12:06:25 +00:00
|
|
|
static void gst_base_audio_src_dispose (GObject * object);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2005-09-02 15:43:18 +00:00
|
|
|
static GstStateChangeReturn gst_base_audio_src_change_state (GstElement *
|
|
|
|
element, GstStateChange transition);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2005-09-28 13:41:29 +00:00
|
|
|
static GstClock *gst_base_audio_src_provide_clock (GstElement * elem);
|
2005-07-10 12:03:58 +00:00
|
|
|
static GstClockTime gst_base_audio_src_get_time (GstClock * clock,
|
2005-07-06 15:27:17 +00:00
|
|
|
GstBaseAudioSrc * src);
|
|
|
|
|
2006-07-06 15:54:50 +00:00
|
|
|
static GstFlowReturn gst_base_audio_src_create (GstBaseSrc * bsrc,
|
|
|
|
guint64 offset, guint length, GstBuffer ** buf);
|
|
|
|
static gboolean gst_base_audio_src_check_get_range (GstBaseSrc * bsrc);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2005-07-10 12:03:58 +00:00
|
|
|
static gboolean gst_base_audio_src_event (GstBaseSrc * bsrc, GstEvent * event);
|
|
|
|
static void gst_base_audio_src_get_times (GstBaseSrc * bsrc,
|
2005-07-06 15:27:17 +00:00
|
|
|
GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
|
2005-07-10 12:03:58 +00:00
|
|
|
static gboolean gst_base_audio_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
|
2007-02-15 12:06:25 +00:00
|
|
|
static gboolean gst_base_audio_src_query (GstBaseSrc * bsrc, GstQuery * query);
|
2007-01-12 21:19:35 +00:00
|
|
|
static void gst_base_audio_src_fixate (GstBaseSrc * bsrc, GstCaps * caps);
|
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
|
|
|
/* static guint gst_base_audio_src_signals[LAST_SIGNAL] = { 0 }; */
|
2005-07-06 15:27:17 +00:00
|
|
|
|
|
|
|
static void
|
2005-07-10 12:03:58 +00:00
|
|
|
gst_base_audio_src_base_init (gpointer g_class)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-07-10 12:03:58 +00:00
|
|
|
gst_base_audio_src_class_init (GstBaseAudioSrcClass * 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;
|
|
|
|
|
2007-09-10 22:10:54 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstBaseAudioSrcPrivate));
|
|
|
|
|
2009-10-28 00:59:35 +00:00
|
|
|
gobject_class->set_property = gst_base_audio_src_set_property;
|
|
|
|
gobject_class->get_property = gst_base_audio_src_get_property;
|
|
|
|
gobject_class->dispose = gst_base_audio_src_dispose;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
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",
|
|
|
|
"Size of audio buffer in microseconds", 1,
|
2008-03-22 15:00:53 +00:00
|
|
|
G_MAXINT64, DEFAULT_BUFFER_TIME,
|
|
|
|
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",
|
|
|
|
"Audio latency in microseconds", 1,
|
2008-03-22 15:00:53 +00:00
|
|
|
G_MAXINT64, DEFAULT_LATENCY_TIME,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2008-05-31 19:57:57 +00:00
|
|
|
/**
|
|
|
|
* GstBaseAudioSrc:actual-buffer-time:
|
|
|
|
*
|
|
|
|
* Actual configured size of audio buffer in microseconds.
|
|
|
|
*
|
|
|
|
* Since: 0.10.20
|
|
|
|
**/
|
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
|
|
|
/**
|
|
|
|
* GstBaseAudioSrc:actual-latency-time:
|
|
|
|
*
|
|
|
|
* Actual configured audio latency in microseconds.
|
|
|
|
*
|
|
|
|
* Since: 0.10.20
|
|
|
|
**/
|
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",
|
|
|
|
"Algorithm to use to match the rate of the masterclock",
|
2008-12-13 06:57:09 +00:00
|
|
|
GST_TYPE_BASE_AUDIO_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 =
|
2005-07-10 12:03:58 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_base_audio_src_change_state);
|
2005-09-28 13:41:29 +00:00
|
|
|
gstelement_class->provide_clock =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_audio_src_provide_clock);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2005-07-10 12:03:58 +00:00
|
|
|
gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_base_audio_src_setcaps);
|
|
|
|
gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_base_audio_src_event);
|
2007-02-15 12:06:25 +00:00
|
|
|
gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_base_audio_src_query);
|
2005-07-10 12:03:58 +00:00
|
|
|
gstbasesrc_class->get_times =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_audio_src_get_times);
|
2006-07-06 15:54:50 +00:00
|
|
|
gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_base_audio_src_create);
|
|
|
|
gstbasesrc_class->check_get_range =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_audio_src_check_get_range);
|
2007-01-12 21:19:35 +00:00
|
|
|
gstbasesrc_class->fixate = GST_DEBUG_FUNCPTR (gst_base_audio_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);
|
2008-04-06 20:16:27 +00:00
|
|
|
g_type_class_ref (GST_TYPE_RING_BUFFER);
|
2005-07-06 15:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-08-28 17:52:45 +00:00
|
|
|
gst_base_audio_src_init (GstBaseAudioSrc * baseaudiosrc,
|
|
|
|
GstBaseAudioSrcClass * g_class)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
2007-09-10 22:10:54 +00:00
|
|
|
baseaudiosrc->priv = GST_BASE_AUDIO_SRC_GET_PRIVATE (baseaudiosrc);
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
baseaudiosrc->buffer_time = DEFAULT_BUFFER_TIME;
|
|
|
|
baseaudiosrc->latency_time = DEFAULT_LATENCY_TIME;
|
2007-09-10 22:10:54 +00:00
|
|
|
baseaudiosrc->priv->provide_clock = DEFAULT_PROVIDE_CLOCK;
|
2008-04-28 08:51:38 +00:00
|
|
|
baseaudiosrc->priv->slave_method = DEFAULT_SLAVE_METHOD;
|
2006-07-06 15:54:50 +00:00
|
|
|
/* reset blocksize we use latency time to calculate a more useful
|
|
|
|
* value based on negotiated format. */
|
|
|
|
GST_BASE_SRC (baseaudiosrc)->blocksize = 0;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2010-09-07 16:09:12 +00:00
|
|
|
baseaudiosrc->clock = gst_audio_clock_new ("GstAudioSrcClock",
|
|
|
|
(GstAudioClockGetTimeFunc) gst_base_audio_src_get_time, baseaudiosrc);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2006-07-06 15:54:50 +00:00
|
|
|
/* we are always a live source */
|
2006-04-28 14:37:46 +00:00
|
|
|
gst_base_src_set_live (GST_BASE_SRC (baseaudiosrc), TRUE);
|
2006-09-27 11:05:08 +00:00
|
|
|
/* we operate in time */
|
2006-01-25 09:27:01 +00:00
|
|
|
gst_base_src_set_format (GST_BASE_SRC (baseaudiosrc), GST_FORMAT_TIME);
|
2005-07-06 15:27:17 +00:00
|
|
|
}
|
|
|
|
|
2007-02-15 12:06:25 +00:00
|
|
|
static void
|
|
|
|
gst_base_audio_src_dispose (GObject * object)
|
|
|
|
{
|
|
|
|
GstBaseAudioSrc *src;
|
|
|
|
|
|
|
|
src = GST_BASE_AUDIO_SRC (object);
|
|
|
|
|
2008-05-31 18:10:47 +00:00
|
|
|
GST_OBJECT_LOCK (src);
|
2010-09-07 16:09:12 +00:00
|
|
|
if (src->clock) {
|
|
|
|
gst_audio_clock_invalidate (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 *
|
2005-09-28 13:41:29 +00:00
|
|
|
gst_base_audio_src_provide_clock (GstElement * elem)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
|
|
|
GstBaseAudioSrc *src;
|
2006-07-06 15:54:50 +00:00
|
|
|
GstClock *clock;
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2005-07-10 12:03:58 +00:00
|
|
|
src = GST_BASE_AUDIO_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;
|
|
|
|
|
|
|
|
if (!gst_ring_buffer_is_acquired (src->ringbuffer))
|
|
|
|
goto wrong_state;
|
|
|
|
|
2007-09-10 22:10:54 +00:00
|
|
|
GST_OBJECT_LOCK (src);
|
|
|
|
if (!src->priv->provide_clock)
|
|
|
|
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:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (src, "ringbuffer not acquired");
|
|
|
|
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
|
2005-07-10 12:03:58 +00:00
|
|
|
gst_base_audio_src_get_time (GstClock * clock, GstBaseAudioSrc * 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;
|
|
|
|
|
2006-07-06 15:54:50 +00:00
|
|
|
if (G_UNLIKELY (src->ringbuffer == NULL || src->ringbuffer->spec.rate == 0))
|
|
|
|
return GST_CLOCK_TIME_NONE;
|
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
|
|
|
raw = samples = gst_ring_buffer_samples_done (src->ringbuffer);
|
|
|
|
|
|
|
|
/* the number of samples not yet processed, this is still queued in the
|
|
|
|
* device (not yet read for capture). */
|
|
|
|
delay = gst_ring_buffer_delay (src->ringbuffer);
|
|
|
|
|
|
|
|
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,
|
|
|
|
src->ringbuffer->spec.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;
|
|
|
|
}
|
|
|
|
|
2006-07-06 15:54:50 +00:00
|
|
|
static gboolean
|
|
|
|
gst_base_audio_src_check_get_range (GstBaseSrc * bsrc)
|
|
|
|
{
|
|
|
|
/* we allow limited pull base operation of which the details
|
|
|
|
* will eventually exposed in an as of yet non-existing query.
|
|
|
|
* Basically pulling can be done on any number of bytes as long
|
|
|
|
* as the offset is -1 or sequentially increasing. */
|
|
|
|
return 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_base_audio_src_set_provide_clock:
|
|
|
|
* @src: a #GstBaseAudioSrc
|
|
|
|
* @provide: new state
|
|
|
|
*
|
|
|
|
* Controls whether @src will provide a clock or not. If @provide is %TRUE,
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Since: 0.10.16
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_base_audio_src_set_provide_clock (GstBaseAudioSrc * src, gboolean provide)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_BASE_AUDIO_SRC (src));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (src);
|
|
|
|
src->priv->provide_clock = provide;
|
|
|
|
GST_OBJECT_UNLOCK (src);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_base_audio_src_get_provide_clock:
|
|
|
|
* @src: a #GstBaseAudioSrc
|
|
|
|
*
|
|
|
|
* Queries whether @src will provide a clock or not. See also
|
|
|
|
* gst_base_audio_src_set_provide_clock.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @src will provide a clock.
|
|
|
|
*
|
|
|
|
* Since: 0.10.16
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_base_audio_src_get_provide_clock (GstBaseAudioSrc * src)
|
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_BASE_AUDIO_SRC (src), FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (src);
|
|
|
|
result = src->priv->provide_clock;
|
|
|
|
GST_OBJECT_UNLOCK (src);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-04-28 08:51:38 +00:00
|
|
|
/**
|
|
|
|
* gst_base_audio_src_set_slave_method:
|
|
|
|
* @src: a #GstBaseAudioSrc
|
|
|
|
* @method: the new slave method
|
|
|
|
*
|
|
|
|
* Controls how clock slaving will be performed in @src.
|
|
|
|
*
|
|
|
|
* Since: 0.10.20
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_base_audio_src_set_slave_method (GstBaseAudioSrc * src,
|
|
|
|
GstBaseAudioSrcSlaveMethod method)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_BASE_AUDIO_SRC (src));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (src);
|
|
|
|
src->priv->slave_method = method;
|
|
|
|
GST_OBJECT_UNLOCK (src);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_base_audio_src_get_slave_method:
|
|
|
|
* @src: a #GstBaseAudioSrc
|
|
|
|
*
|
|
|
|
* Get the current slave method used by @src.
|
|
|
|
*
|
|
|
|
* Returns: The current slave method used by @src.
|
|
|
|
*
|
|
|
|
* Since: 0.10.20
|
|
|
|
*/
|
|
|
|
GstBaseAudioSrcSlaveMethod
|
|
|
|
gst_base_audio_src_get_slave_method (GstBaseAudioSrc * src)
|
|
|
|
{
|
|
|
|
GstBaseAudioSrcSlaveMethod result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_BASE_AUDIO_SRC (src), -1);
|
|
|
|
|
|
|
|
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
|
2005-07-10 12:03:58 +00:00
|
|
|
gst_base_audio_src_set_property (GObject * object, guint prop_id,
|
2005-07-06 15:27:17 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstBaseAudioSrc *src;
|
|
|
|
|
2005-07-10 12:03:58 +00:00
|
|
|
src = GST_BASE_AUDIO_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:
|
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_base_audio_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:
|
|
|
|
gst_base_audio_src_set_slave_method (src, g_value_get_enum (value));
|
|
|
|
break;
|
2005-07-06 15:27:17 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-07-10 12:03:58 +00:00
|
|
|
gst_base_audio_src_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
|
|
|
GstBaseAudioSrc *src;
|
|
|
|
|
2005-07-10 12:03:58 +00:00
|
|
|
src = GST_BASE_AUDIO_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:
|
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
|
|
|
g_value_set_boolean (value, gst_base_audio_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:
|
|
|
|
g_value_set_enum (value, gst_base_audio_src_get_slave_method (src));
|
|
|
|
break;
|
2005-07-06 15:27:17 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-01-12 21:19:35 +00:00
|
|
|
gst_base_audio_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
|
|
|
GstStructure *s;
|
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
|
|
|
gint width, depth;
|
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 */
|
2005-11-21 14:29:53 +00:00
|
|
|
gst_structure_fixate_field_nearest_int (s, "rate", 44100);
|
|
|
|
gst_structure_fixate_field_nearest_int (s, "channels", 2);
|
2011-09-10 17:30:55 +00:00
|
|
|
|
|
|
|
/* fields for int and/or float, but maybe not others like alaw/mulaw */
|
|
|
|
if (gst_structure_has_field (s, "width")) {
|
|
|
|
gst_structure_fixate_field_nearest_int (s, "width", 16);
|
|
|
|
|
|
|
|
if (gst_structure_has_field (s, "depth")) {
|
|
|
|
gst_structure_get_int (s, "width", &width);
|
|
|
|
/* round width to nearest multiple of 8 for the depth */
|
|
|
|
depth = GST_ROUND_UP_8 (width);
|
|
|
|
gst_structure_fixate_field_nearest_int (s, "depth", depth);
|
|
|
|
}
|
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 (gst_structure_has_field (s, "signed"))
|
|
|
|
gst_structure_fixate_field_boolean (s, "signed", TRUE);
|
2005-08-23 13:29:17 +00:00
|
|
|
if (gst_structure_has_field (s, "endianness"))
|
2005-11-21 14:29:53 +00:00
|
|
|
gst_structure_fixate_field_nearest_int (s, "endianness", G_BYTE_ORDER);
|
2005-07-06 15:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2005-07-10 12:03:58 +00:00
|
|
|
gst_base_audio_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
2005-07-10 12:03:58 +00:00
|
|
|
GstBaseAudioSrc *src = GST_BASE_AUDIO_SRC (bsrc);
|
2005-07-06 15:27:17 +00:00
|
|
|
GstRingBufferSpec *spec;
|
|
|
|
|
|
|
|
spec = &src->ringbuffer->spec;
|
|
|
|
|
|
|
|
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-09-10 17:30:55 +00:00
|
|
|
if (!gst_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
|
|
|
|
|
|
|
/* calculate suggested segsize and segtotal */
|
|
|
|
spec->segsize =
|
|
|
|
spec->rate * spec->bytes_per_sample * spec->latency_time / GST_MSECOND;
|
|
|
|
spec->segtotal = spec->buffer_time / spec->latency_time;
|
|
|
|
|
2011-02-23 09:55:12 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
|
|
|
|
2005-07-06 15:27:17 +00:00
|
|
|
GST_DEBUG ("release old ringbuffer");
|
|
|
|
|
2005-07-10 12:03:58 +00:00
|
|
|
gst_ring_buffer_release (src->ringbuffer);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
2005-07-10 12:03:58 +00:00
|
|
|
gst_ring_buffer_debug_spec_buff (spec);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("acquire new ringbuffer");
|
|
|
|
|
2005-07-10 12:03:58 +00:00
|
|
|
if (!gst_ring_buffer_acquire (src->ringbuffer, spec))
|
2005-07-06 15:27:17 +00:00
|
|
|
goto acquire_error;
|
|
|
|
|
|
|
|
/* calculate actual latency and buffer times */
|
|
|
|
spec->latency_time =
|
|
|
|
spec->segsize * GST_MSECOND / (spec->rate * spec->bytes_per_sample);
|
|
|
|
spec->buffer_time =
|
|
|
|
spec->segtotal * spec->segsize * GST_MSECOND / (spec->rate *
|
|
|
|
spec->bytes_per_sample);
|
|
|
|
|
2005-07-10 12:03:58 +00:00
|
|
|
gst_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");
|
|
|
|
|
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
|
2005-07-10 12:03:58 +00:00
|
|
|
gst_base_audio_src_get_times (GstBaseSrc * bsrc, GstBuffer * buffer,
|
2005-07-06 15:27:17 +00:00
|
|
|
GstClockTime * start, GstClockTime * end)
|
|
|
|
{
|
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
|
|
|
/* no need to sync to a clock here, we schedule the samples based
|
|
|
|
* 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
|
|
|
|
gst_base_audio_src_query (GstBaseSrc * bsrc, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstBaseAudioSrc *src = GST_BASE_AUDIO_SRC (bsrc);
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_LATENCY:
|
|
|
|
{
|
|
|
|
GstClockTime min_latency, max_latency;
|
|
|
|
GstRingBufferSpec *spec;
|
|
|
|
|
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-01-22 22:09:32 +00:00
|
|
|
|| src->ringbuffer->spec.rate == 0)) {
|
|
|
|
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;
|
|
|
|
|
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 =
|
|
|
|
gst_util_uint64_scale_int (spec->segsize, GST_SECOND,
|
|
|
|
spec->rate * spec->bytes_per_sample);
|
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,
|
|
|
|
spec->rate * spec->bytes_per_sample);
|
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. */
|
|
|
|
gst_query_set_latency (query, TRUE, min_latency, max_latency);
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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
|
2005-07-10 12:03:58 +00:00
|
|
|
gst_base_audio_src_event (GstBaseSrc * bsrc, GstEvent * event)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
2005-07-10 12:03:58 +00:00
|
|
|
GstBaseAudioSrc *src = GST_BASE_AUDIO_SRC (bsrc);
|
2009-06-15 10:57:39 +00:00
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
res = 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");
|
2005-07-27 19:13:27 +00:00
|
|
|
gst_ring_buffer_pause (src->ringbuffer);
|
2005-10-06 15:15:04 +00:00
|
|
|
gst_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;
|
|
|
|
gst_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");
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2005-07-06 15:27:17 +00:00
|
|
|
default:
|
2009-06-15 10:57:39 +00:00
|
|
|
GST_DEBUG_OBJECT (bsrc, "dropping event %p", event);
|
2005-07-06 15:27:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-06-15 10:57:39 +00:00
|
|
|
return res;
|
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
|
|
|
/* get the next offset in the ringbuffer for reading samples.
|
|
|
|
* If the next sample is too far away, this function will position itself to the
|
|
|
|
* next most recent sample, creating discontinuity */
|
|
|
|
static guint64
|
|
|
|
gst_base_audio_src_get_offset (GstBaseAudioSrc * src)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* 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). */
|
|
|
|
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
|
2006-07-06 15:54:50 +00:00
|
|
|
gst_base_audio_src_create (GstBaseSrc * bsrc, guint64 offset, guint length,
|
|
|
|
GstBuffer ** outbuf)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
2006-07-06 15:54:50 +00:00
|
|
|
GstBaseAudioSrc *src = GST_BASE_AUDIO_SRC (bsrc);
|
2005-07-06 15:27:17 +00:00
|
|
|
GstBuffer *buf;
|
|
|
|
guchar *data;
|
2007-09-10 22:10:54 +00:00
|
|
|
guint samples, total_samples;
|
2005-10-06 15:15:04 +00:00
|
|
|
guint64 sample;
|
2006-07-06 15:54:50 +00:00
|
|
|
gint bps;
|
2006-01-25 09:27:01 +00:00
|
|
|
GstRingBuffer *ringbuffer;
|
2007-09-10 22:10:54 +00:00
|
|
|
GstRingBufferSpec *spec;
|
2006-09-27 13:52:14 +00:00
|
|
|
guint read;
|
2008-03-10 17:19:56 +00:00
|
|
|
GstClockTime timestamp, duration;
|
2007-09-10 22:10:54 +00:00
|
|
|
GstClock *clock;
|
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
|
|
|
|
2006-07-06 15:54:50 +00:00
|
|
|
if (G_UNLIKELY (!gst_ring_buffer_is_acquired (ringbuffer)))
|
2005-07-06 15:27:17 +00:00
|
|
|
goto wrong_state;
|
|
|
|
|
2007-09-10 22:10:54 +00:00
|
|
|
bps = spec->bytes_per_sample;
|
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 */
|
|
|
|
length -= length % bps;
|
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)) {
|
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
|
|
|
sample = offset / bps;
|
|
|
|
/* 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 {
|
|
|
|
/* calculate the sequentially next sample we need to read. This can jump and
|
|
|
|
* create a DISCONT. */
|
|
|
|
sample = gst_base_audio_src_get_offset (src);
|
2005-10-06 15:15:04 +00:00
|
|
|
}
|
|
|
|
|
2007-05-21 10:25:44 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "reading from sample %" G_GUINT64_FORMAT, sample);
|
|
|
|
|
2006-07-06 15:54:50 +00:00
|
|
|
/* get the number of samples to read */
|
2007-09-10 22:10:54 +00:00
|
|
|
total_samples = samples = length / bps;
|
2006-07-06 15:54:50 +00:00
|
|
|
|
|
|
|
/* FIXME, using a bufferpool would be nice here */
|
|
|
|
buf = gst_buffer_new_and_alloc (length);
|
|
|
|
data = GST_BUFFER_DATA (buf);
|
2005-10-11 18:32:01 +00:00
|
|
|
|
2006-09-27 13:52:14 +00:00
|
|
|
do {
|
|
|
|
read = gst_ring_buffer_read (ringbuffer, sample, data, samples);
|
|
|
|
GST_DEBUG_OBJECT (src, "read %u of %u", read, samples);
|
|
|
|
/* if we read all, we're done */
|
|
|
|
if (read == samples)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
data += read * bps;
|
|
|
|
} while (TRUE);
|
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. */
|
|
|
|
timestamp = gst_util_uint64_scale_int (sample, GST_SECOND, spec->rate);
|
|
|
|
duration = gst_util_uint64_scale_int (src->next_sample, GST_SECOND,
|
|
|
|
spec->rate) - timestamp;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (clock != src->clock) {
|
|
|
|
/* we are slaved, check how to handle this */
|
2008-04-28 08:51:38 +00:00
|
|
|
switch (src->priv->slave_method) {
|
|
|
|
case GST_BASE_AUDIO_SRC_SLAVE_RESAMPLE:
|
2008-10-08 09:12:36 +00:00
|
|
|
/* not implemented, use skew algorithm. This algorithm should
|
2008-04-28 08:51:38 +00:00
|
|
|
* work on the readout pointer and produces more or less samples based
|
|
|
|
* on the clock drift */
|
|
|
|
case GST_BASE_AUDIO_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
|
|
|
|
last written segment in the ringbuffer (one segment written = segment 0) */
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* the running_time converted to a sample (relative to the ringbuffer) */
|
|
|
|
running_time_sample =
|
|
|
|
gst_util_uint64_scale_int (running_time, spec->rate, GST_SECOND);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* the skew we have between running_time and the ringbuffertime (last written to) */
|
|
|
|
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) ||
|
|
|
|
(last_read_segment == 0)) {
|
|
|
|
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 */
|
|
|
|
gst_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 */
|
|
|
|
timestamp =
|
|
|
|
gst_util_uint64_scale_int (new_sample, GST_SECOND, spec->rate);
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
2008-04-28 08:51:38 +00:00
|
|
|
case GST_BASE_AUDIO_SRC_SLAVE_RETIMESTAMP:
|
|
|
|
{
|
|
|
|
GstClockTime base_time, latency;
|
|
|
|
|
|
|
|
/* We are slaved to another clock, take running time of the pipeline clock and
|
|
|
|
* timestamp against it. Somebody else in the pipeline should figure out the
|
|
|
|
* clock drift. We keep the duration we calculated above. */
|
|
|
|
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 */
|
|
|
|
latency =
|
|
|
|
gst_util_uint64_scale_int (total_samples, GST_SECOND, spec->rate);
|
|
|
|
if (timestamp > latency)
|
|
|
|
timestamp -= latency;
|
|
|
|
else
|
|
|
|
timestamp = 0;
|
|
|
|
}
|
|
|
|
case GST_BASE_AUDIO_SRC_SLAVE_NONE:
|
|
|
|
break;
|
|
|
|
}
|
2008-08-13 09:17:38 +00:00
|
|
|
} else {
|
|
|
|
GstClockTime base_time;
|
|
|
|
|
2009-04-14 11:16:14 +00:00
|
|
|
/* to get the timestamp against the clock we also need to add our offset */
|
|
|
|
timestamp = gst_audio_clock_adjust (clock, timestamp);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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");
|
2005-07-06 15:27:17 +00:00
|
|
|
return GST_FLOW_WRONG_STATE;
|
|
|
|
}
|
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;
|
|
|
|
}
|
2005-07-06 15:27:17 +00:00
|
|
|
stopped:
|
|
|
|
{
|
|
|
|
gst_buffer_unref (buf);
|
2006-07-06 15:54:50 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "ringbuffer stopped");
|
2005-07-06 15:27:17 +00:00
|
|
|
return GST_FLOW_WRONG_STATE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-27 11:05:08 +00:00
|
|
|
/**
|
|
|
|
* gst_base_audio_src_create_ringbuffer:
|
|
|
|
* @src: a #GstBaseAudioSrc.
|
|
|
|
*
|
|
|
|
* Create and return the #GstRingBuffer 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()).
|
|
|
|
*
|
|
|
|
* Returns: The new ringbuffer of @src.
|
|
|
|
*/
|
2005-07-06 15:27:17 +00:00
|
|
|
GstRingBuffer *
|
2005-07-10 12:03:58 +00:00
|
|
|
gst_base_audio_src_create_ringbuffer (GstBaseAudioSrc * src)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
|
|
|
GstBaseAudioSrcClass *bclass;
|
|
|
|
GstRingBuffer *buffer = NULL;
|
|
|
|
|
2005-07-10 12:03:58 +00:00
|
|
|
bclass = GST_BASE_AUDIO_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
|
|
|
|
gst_base_audio_src_change_state (GstElement * element,
|
|
|
|
GstStateChange transition)
|
2005-07-06 15:27:17 +00:00
|
|
|
{
|
2005-09-02 15:43:18 +00:00
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
2005-07-10 12:03:58 +00:00
|
|
|
GstBaseAudioSrc *src = GST_BASE_AUDIO_SRC (element);
|
2005-07-06 15:27:17 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2007-12-17 16:44:51 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "NULL->READY");
|
2008-05-31 18:10:47 +00:00
|
|
|
GST_OBJECT_LOCK (src);
|
2005-08-16 15:53:59 +00:00
|
|
|
if (src->ringbuffer == NULL) {
|
2008-05-27 16:20:17 +00:00
|
|
|
gst_audio_clock_reset (GST_AUDIO_CLOCK (src->clock), 0);
|
2005-08-16 15:53:59 +00:00
|
|
|
src->ringbuffer = gst_base_audio_src_create_ringbuffer (src);
|
|
|
|
}
|
2008-05-31 18:10:47 +00:00
|
|
|
GST_OBJECT_UNLOCK (src);
|
2005-08-16 15:53:59 +00:00
|
|
|
if (!gst_ring_buffer_open_device (src->ringbuffer))
|
2007-02-15 12:06:25 +00:00
|
|
|
goto open_failed;
|
2005-07-06 15:27:17 +00:00
|
|
|
break;
|
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;
|
2005-11-17 14:40:12 +00:00
|
|
|
gst_ring_buffer_set_flushing (src->ringbuffer, FALSE);
|
2007-12-17 16:44:51 +00:00
|
|
|
gst_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 ==
|
|
|
|
(GstAudioClockGetTimeFunc) gst_base_audio_src_get_time)
|
|
|
|
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");
|
|
|
|
gst_ring_buffer_may_start (src->ringbuffer, TRUE);
|
|
|
|
break;
|
2007-12-17 16:44:51 +00:00
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
|
|
GST_DEBUG_OBJECT (src, "PLAYING->PAUSED");
|
2010-08-04 13:18:37 +00:00
|
|
|
gst_ring_buffer_may_start (src->ringbuffer, FALSE);
|
|
|
|
gst_ring_buffer_pause (src->ringbuffer);
|
|
|
|
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 ==
|
|
|
|
(GstAudioClockGetTimeFunc) gst_base_audio_src_get_time)
|
|
|
|
gst_element_post_message (element,
|
|
|
|
gst_message_new_clock_lost (GST_OBJECT_CAST (element), src->clock));
|
2007-02-15 12:06:25 +00:00
|
|
|
gst_ring_buffer_set_flushing (src->ringbuffer, TRUE);
|
|
|
|
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");
|
2005-07-10 12:03:58 +00:00
|
|
|
gst_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");
|
2005-08-16 15:53:59 +00:00
|
|
|
gst_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 */
|
|
|
|
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
|
|
|
}
|