summaryrefslogtreecommitdiffstats
path: root/gst-libs/gst/audio
diff options
context:
space:
mode:
Diffstat (limited to 'gst-libs/gst/audio')
-rw-r--r--gst-libs/gst/audio/Makefile.am4
-rw-r--r--gst-libs/gst/audio/audio.c2
-rw-r--r--gst-libs/gst/audio/audio.h2
-rw-r--r--gst-libs/gst/audio/audioclock.c194
-rw-r--r--gst-libs/gst/audio/audioclock.h83
5 files changed, 282 insertions, 3 deletions
diff --git a/gst-libs/gst/audio/Makefile.am b/gst-libs/gst/audio/Makefile.am
index 059f79e5..fa9abaf4 100644
--- a/gst-libs/gst/audio/Makefile.am
+++ b/gst-libs/gst/audio/Makefile.am
@@ -2,10 +2,10 @@ librarydir = $(libdir)/gstreamer-@GST_MAJORMINOR@
library_LTLIBRARIES = libgstaudio.la
-libgstaudio_la_SOURCES = audio.c
+libgstaudio_la_SOURCES = audio.c audioclock.c
libgstaudioincludedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/audio
-libgstaudioinclude_HEADERS = audio.h
+libgstaudioinclude_HEADERS = audio.h audioclock.h
libgstaudio_la_LIBADD =
libgstaudio_la_CFLAGS = $(GST_CFLAGS) $(GST_OPT_CFLAGS)
diff --git a/gst-libs/gst/audio/audio.c b/gst-libs/gst/audio/audio.c
index cdc339e7..3190edc2 100644
--- a/gst-libs/gst/audio/audio.c
+++ b/gst-libs/gst/audio/audio.c
@@ -177,7 +177,7 @@ gst_audio_is_buffer_framed (GstPad* pad, GstBuffer* buf)
static gboolean
plugin_init (GModule *module, GstPlugin *plugin)
{
- gst_plugin_set_longname (plugin, "Convenience routines for audio plugins");
+ gst_plugin_set_longname (plugin, "Support services for audio plugins");
return TRUE;
}
diff --git a/gst-libs/gst/audio/audio.h b/gst-libs/gst/audio/audio.h
index 4bf62d49..a737e468 100644
--- a/gst-libs/gst/audio/audio.h
+++ b/gst-libs/gst/audio/audio.h
@@ -20,6 +20,8 @@
#include <gst/gst.h>
+#include <gst/audio/audioclock.h>
+
/* For people that are looking at this source: the purpose of these defines is
* to make GstCaps a bit easier, in that you don't have to know all of the
* properties that need to be defined. you can just use these macros. currently
diff --git a/gst-libs/gst/audio/audioclock.c b/gst-libs/gst/audio/audioclock.c
new file mode 100644
index 00000000..342009ff
--- /dev/null
+++ b/gst-libs/gst/audio/audioclock.c
@@ -0,0 +1,194 @@
+/* GStreamer
+ * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
+ * 2000 Wim Taymans <wtay@chello.be>
+ *
+ * audioclock.c: Clock for use by audio plugins
+ *
+ * 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.
+ */
+
+#include "audioclock.h"
+
+static void gst_audio_clock_class_init (GstAudioClockClass *klass);
+static void gst_audio_clock_init (GstAudioClock *clock);
+
+static GstClockTime gst_audio_clock_get_internal_time (GstClock *clock);
+static GstClockReturn gst_audio_clock_id_wait_async (GstClock *clock,
+ GstClockEntry *entry);
+static void gst_audio_clock_id_unschedule (GstClock *clock,
+ GstClockEntry *entry);
+
+static GstSystemClockClass *parent_class = NULL;
+/* static guint gst_audio_clock_signals[LAST_SIGNAL] = { 0 }; */
+
+GType
+gst_audio_clock_get_type (void)
+{
+ static GType clock_type = 0;
+
+ if (!clock_type) {
+ static const GTypeInfo clock_info = {
+ sizeof (GstAudioClockClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) gst_audio_clock_class_init,
+ NULL,
+ NULL,
+ sizeof (GstAudioClock),
+ 4,
+ (GInstanceInitFunc) gst_audio_clock_init,
+ NULL
+ };
+ clock_type = g_type_register_static (GST_TYPE_SYSTEM_CLOCK, "GstAudioClock",
+ &clock_info, 0);
+ }
+ return clock_type;
+}
+
+
+static void
+gst_audio_clock_class_init (GstAudioClockClass *klass)
+{
+ GObjectClass *gobject_class;
+ GstObjectClass *gstobject_class;
+ GstClockClass *gstclock_class;
+
+ gobject_class = (GObjectClass*) klass;
+ gstobject_class = (GstObjectClass*) klass;
+ gstclock_class = (GstClockClass*) klass;
+
+ parent_class = g_type_class_ref (GST_TYPE_SYSTEM_CLOCK);
+
+ gstclock_class->get_internal_time = gst_audio_clock_get_internal_time;
+ gstclock_class->wait_async = gst_audio_clock_id_wait_async;
+ gstclock_class->unschedule = gst_audio_clock_id_unschedule;
+}
+
+static void
+gst_audio_clock_init (GstAudioClock *clock)
+{
+ gst_object_set_name (GST_OBJECT (clock), "GstAudioClock");
+
+ clock->prev1 = 0;
+ clock->prev2 = 0;
+}
+
+GstClock*
+gst_audio_clock_new (gchar *name, GstAudioClockGetTimeFunc func, gpointer user_data)
+{
+ GstAudioClock *aclock = GST_AUDIO_CLOCK (g_object_new (GST_TYPE_AUDIO_CLOCK, NULL));
+
+ aclock->func = func;
+ aclock->user_data = user_data;
+ aclock->adjust = 0;
+
+ return (GstClock*)aclock;
+}
+
+void
+gst_audio_clock_set_active (GstAudioClock *aclock, gboolean active)
+{
+ GTimeVal timeval;
+ GstClockTime time;
+ GstClockTime audiotime;
+
+ g_get_current_time (&timeval);
+ time = GST_TIMEVAL_TO_TIME (timeval);
+ audiotime = aclock->func ((GstClock*)aclock, aclock->user_data);
+
+ if (active) {
+ aclock->adjust = time - audiotime;
+ }
+ else {
+ aclock->adjust = audiotime - time;
+ }
+
+ aclock->active = active;
+}
+
+static GstClockTime
+gst_audio_clock_get_internal_time (GstClock *clock)
+{
+ GstAudioClock *aclock = GST_AUDIO_CLOCK (clock);
+
+ if (aclock->active) {
+ GstClockTime audiotime;
+
+ audiotime = aclock->func (clock, aclock->user_data) + aclock->adjust;
+
+ return audiotime;
+ }
+ else {
+ GstClockTime time;
+ GTimeVal timeval;
+
+ g_get_current_time (&timeval);
+ time = GST_TIMEVAL_TO_TIME (timeval);
+
+ return time;
+ }
+}
+
+void
+gst_audio_clock_update_time (GstAudioClock *aclock, GstClockTime time)
+{
+ /* I don't know of a purpose in updating these; perhaps they can be removed */
+ aclock->prev2 = aclock->prev1;
+ aclock->prev1 = time;
+
+ /* FIXME: the wait_async subsystem should be made threadsafe, but I don't want
+ * to lock and unlock a mutex on every iteration... */
+ while (aclock->async_entries) {
+ GstClockEntry *entry = (GstClockEntry*)aclock->async_entries->data;
+
+ if (entry->time > time)
+ break;
+
+ entry->func ((GstClock*)aclock, time, entry, entry->user_data);
+
+ aclock->async_entries = g_slist_delete_link (aclock->async_entries,
+ aclock->async_entries);
+ /* do I need to free the entry? */
+ }
+}
+
+static gint
+compare_clock_entries (GstClockEntry *entry1, GstClockEntry *entry2)
+{
+ return entry1->time - entry2->time;
+}
+
+static GstClockReturn
+gst_audio_clock_id_wait_async (GstClock *clock, GstClockEntry *entry)
+{
+ GstAudioClock *aclock = (GstAudioClock*)clock;
+
+ aclock->async_entries = g_slist_insert_sorted (aclock->async_entries,
+ entry,
+ (GCompareFunc)compare_clock_entries);
+
+ /* is this the proper return val? */
+ return GST_CLOCK_EARLY;
+}
+
+static void
+gst_audio_clock_id_unschedule (GstClock *clock, GstClockEntry *entry)
+{
+ GstAudioClock *aclock = (GstAudioClock*)clock;
+
+ aclock->async_entries = g_slist_remove (aclock->async_entries,
+ entry);
+}
diff --git a/gst-libs/gst/audio/audioclock.h b/gst-libs/gst/audio/audioclock.h
new file mode 100644
index 00000000..8ac984b7
--- /dev/null
+++ b/gst-libs/gst/audio/audioclock.h
@@ -0,0 +1,83 @@
+/* GStreamer
+ * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
+ * 2000 Wim Taymans <wtay@chello.be>
+ *
+ * audioclock.h: Clock for use by audio plugins
+ *
+ * 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.
+ */
+
+
+#ifndef __GST_AUDIO_CLOCK_H__
+#define __GST_AUDIO_CLOCK_H__
+
+#include <gst/gstsystemclock.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+#define GST_TYPE_AUDIO_CLOCK \
+ (gst_audio_clock_get_type())
+#define GST_AUDIO_CLOCK(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_CLOCK,GstAudioClock))
+#define GST_AUDIO_CLOCK_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_CLOCK,GstAudioClockClass))
+#define GST_IS_AUDIO_CLOCK(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_CLOCK))
+#define GST_IS_AUDIO_CLOCK_CLASS(obj) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_CLOCK))
+
+typedef struct _GstAudioClock GstAudioClock;
+typedef struct _GstAudioClockClass GstAudioClockClass;
+
+typedef GstClockTime (*GstAudioClockGetTimeFunc) (GstClock *clock, gpointer user_data);
+
+
+struct _GstAudioClock {
+ GstSystemClock clock;
+
+ GstClockTime prev1, prev2;
+
+ /* --- protected --- */
+ GstAudioClockGetTimeFunc func;
+ gpointer user_data;
+
+ GstClockTimeDiff adjust;
+
+ GSList *async_entries;
+
+ gboolean active;
+};
+
+struct _GstAudioClockClass {
+ GstSystemClockClass parent_class;
+};
+
+GType gst_audio_clock_get_type (void);
+GstClock* gst_audio_clock_new (gchar *name, GstAudioClockGetTimeFunc func,
+ gpointer user_data);
+void gst_audio_clock_set_active (GstAudioClock *aclock, gboolean active);
+
+void gst_audio_clock_update_time (GstAudioClock *aclock, GstClockTime time);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+
+#endif /* __GST_AUDIO_CLOCK_H__ */