2000-12-28 22:12:02 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gstclock.c: Clock subsystem for maintaining time sync
|
2000-04-09 21:38: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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
2000-12-28 22:12:02 +00:00
|
|
|
|
|
|
|
#include "gst_private.h"
|
2003-06-29 14:05:49 +00:00
|
|
|
|
2000-12-15 01:57:34 +00:00
|
|
|
#include "gstclock.h"
|
2003-06-29 14:05:49 +00:00
|
|
|
#include "gstinfo.h"
|
2002-07-08 19:22:02 +00:00
|
|
|
#include "gstmemchunk.h"
|
2000-04-09 21:38:17 +00:00
|
|
|
|
2003-02-10 20:32:32 +00:00
|
|
|
#ifndef GST_DISABLE_TRACE
|
2003-02-02 19:21:06 +00:00
|
|
|
/* #define GST_WITH_ALLOC_TRACE */
|
2003-02-10 20:32:32 +00:00
|
|
|
#include "gsttrace.h"
|
|
|
|
static GstAllocTrace *_gst_clock_entry_trace;
|
|
|
|
#endif
|
2003-02-02 19:21:06 +00:00
|
|
|
|
2002-12-27 04:11:59 +00:00
|
|
|
#define DEFAULT_MAX_DIFF (2 * GST_SECOND)
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_STATS,
|
2003-05-15 22:46:37 +00:00
|
|
|
ARG_MAX_DIFF
|
2002-11-02 13:54:34 +00:00
|
|
|
};
|
|
|
|
|
2003-02-02 19:21:06 +00:00
|
|
|
static GstMemChunk *_gst_clock_entries_chunk;
|
2000-04-09 21:38:17 +00:00
|
|
|
|
2002-02-03 20:07:09 +00:00
|
|
|
static void gst_clock_class_init (GstClockClass *klass);
|
|
|
|
static void gst_clock_init (GstClock *clock);
|
2003-02-02 19:21:06 +00:00
|
|
|
static void gst_clock_dispose (GObject *object);
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
static void gst_clock_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_clock_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec * pspec);
|
|
|
|
static void gst_clock_update_stats (GstClock *clock);
|
2002-02-03 20:07:09 +00:00
|
|
|
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2002-02-03 20:07:09 +00:00
|
|
|
static GstObjectClass *parent_class = NULL;
|
|
|
|
/* static guint gst_clock_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
2003-01-15 18:29:40 +00:00
|
|
|
static GstClockID
|
2002-11-02 13:54:34 +00:00
|
|
|
gst_clock_entry_new (GstClock *clock, GstClockTime time,
|
|
|
|
GstClockTime interval, GstClockEntryType type)
|
|
|
|
{
|
|
|
|
GstClockEntry *entry;
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
entry = gst_mem_chunk_alloc (_gst_clock_entries_chunk);
|
2003-02-10 20:32:32 +00:00
|
|
|
#ifndef GST_DISABLE_TRACE
|
2003-02-02 19:21:06 +00:00
|
|
|
gst_alloc_trace_new (_gst_clock_entry_trace, entry);
|
2003-02-10 20:32:32 +00:00
|
|
|
#endif
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
entry->clock = clock;
|
|
|
|
entry->time = time;
|
|
|
|
entry->interval = time;
|
|
|
|
entry->type = type;
|
|
|
|
entry->status = GST_CLOCK_ENTRY_OK;
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
return (GstClockID) entry;
|
|
|
|
}
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
/**
|
|
|
|
* gst_clock_new_single_shot_id
|
|
|
|
* @clock: The clockid to get a single shot notification from
|
|
|
|
* @time: the requested time
|
|
|
|
*
|
|
|
|
* Get an ID from the given clock to trigger a single shot
|
|
|
|
* notification at the requested time.
|
|
|
|
*
|
|
|
|
* Returns: An id that can be used to request the time notification.
|
|
|
|
*/
|
|
|
|
GstClockID
|
|
|
|
gst_clock_new_single_shot_id (GstClock *clock, GstClockTime time)
|
|
|
|
{
|
2002-11-27 20:47:39 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CLOCK (clock), NULL);
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
return gst_clock_entry_new (clock,
|
|
|
|
time,
|
|
|
|
GST_CLOCK_TIME_NONE,
|
|
|
|
GST_CLOCK_ENTRY_SINGLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2002-12-14 13:02:16 +00:00
|
|
|
* gst_clock_new_periodic_id
|
2002-11-02 13:54:34 +00:00
|
|
|
* @clock: The clockid to get a periodic notification id from
|
|
|
|
* @start_time: the requested start time
|
|
|
|
* @interval: the requested interval
|
|
|
|
*
|
|
|
|
* Get an ID from the given clock to trigger a periodic notification.
|
|
|
|
* The periodeic notifications will be start at time start_time and
|
|
|
|
* will then be fired with the given interval.
|
|
|
|
*
|
|
|
|
* Returns: An id that can be used to request the time notification.
|
|
|
|
*/
|
|
|
|
GstClockID
|
|
|
|
gst_clock_new_periodic_id (GstClock *clock, GstClockTime start_time,
|
|
|
|
GstClockTime interval)
|
|
|
|
{
|
2002-11-27 20:47:39 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CLOCK (clock), NULL);
|
2003-04-13 03:07:07 +00:00
|
|
|
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (start_time), NULL);
|
2002-11-27 20:47:39 +00:00
|
|
|
g_return_val_if_fail (interval != 0, NULL);
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
return gst_clock_entry_new (clock,
|
|
|
|
start_time,
|
|
|
|
interval,
|
|
|
|
GST_CLOCK_ENTRY_PERIODIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_clock_id_get_time
|
|
|
|
* @id: The clockid to query
|
|
|
|
*
|
|
|
|
* Get the time of the clock ID
|
|
|
|
*
|
|
|
|
* Returns: the time of the given clock id
|
|
|
|
*/
|
|
|
|
GstClockTime
|
|
|
|
gst_clock_id_get_time (GstClockID id)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (id != NULL, GST_CLOCK_TIME_NONE);
|
|
|
|
|
|
|
|
return GST_CLOCK_ENTRY_TIME ((GstClockEntry *)id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_clock_id_wait
|
|
|
|
* @id: The clockid to wait on
|
|
|
|
* @jitter: A pointer that will contain the jitter
|
|
|
|
*
|
|
|
|
* Perform a blocking wait on the given ID. The jitter arg can be
|
|
|
|
* NULL
|
|
|
|
*
|
|
|
|
* Returns: the result of the blocking wait.
|
|
|
|
*/
|
|
|
|
GstClockReturn
|
|
|
|
gst_clock_id_wait (GstClockID id, GstClockTimeDiff *jitter)
|
2002-03-30 17:05:03 +00:00
|
|
|
{
|
|
|
|
GstClockEntry *entry;
|
2002-11-02 13:54:34 +00:00
|
|
|
GstClock *clock;
|
|
|
|
GstClockReturn res = GST_CLOCK_UNSUPPORTED;
|
|
|
|
GstClockTime requested;
|
2002-12-19 21:31:03 +00:00
|
|
|
GstClockClass *cclass;
|
2002-11-02 13:54:34 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (id != NULL, GST_CLOCK_ERROR);
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
entry = (GstClockEntry *) id;
|
|
|
|
requested = GST_CLOCK_ENTRY_TIME (entry);
|
2002-11-27 20:47:39 +00:00
|
|
|
|
2003-04-13 03:07:07 +00:00
|
|
|
if (! GST_CLOCK_TIME_IS_VALID (requested)) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CLOCK, "invalid time requested, returning _TIMEOUT");
|
2002-12-27 04:11:59 +00:00
|
|
|
return GST_CLOCK_TIMEOUT;
|
2002-11-27 20:47:39 +00:00
|
|
|
}
|
2002-12-27 04:11:59 +00:00
|
|
|
|
2002-11-27 20:47:39 +00:00
|
|
|
clock = GST_CLOCK_ENTRY_CLOCK (entry);
|
2002-12-19 21:31:03 +00:00
|
|
|
cclass = GST_CLOCK_GET_CLASS (clock);
|
2002-11-02 13:54:34 +00:00
|
|
|
|
2002-12-19 21:31:03 +00:00
|
|
|
if (cclass->wait) {
|
2002-11-02 13:54:34 +00:00
|
|
|
GstClockTime now;
|
2002-12-27 04:11:59 +00:00
|
|
|
|
|
|
|
GST_LOCK (clock);
|
|
|
|
clock->entries = g_list_prepend (clock->entries, entry);
|
|
|
|
GST_UNLOCK (clock);
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CLOCK, "waiting on clock");
|
2002-11-02 13:54:34 +00:00
|
|
|
do {
|
2002-12-19 21:31:03 +00:00
|
|
|
res = cclass->wait (clock, entry);
|
2002-11-02 13:54:34 +00:00
|
|
|
}
|
|
|
|
while (res == GST_CLOCK_ENTRY_RESTART);
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CLOCK, "done waiting");
|
2002-11-02 13:54:34 +00:00
|
|
|
|
2002-12-27 04:11:59 +00:00
|
|
|
GST_LOCK (clock);
|
|
|
|
clock->entries = g_list_remove (clock->entries, entry);
|
|
|
|
GST_UNLOCK (clock);
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
if (jitter) {
|
|
|
|
now = gst_clock_get_time (clock);
|
|
|
|
*jitter = now - requested;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clock->stats) {
|
|
|
|
gst_clock_update_stats (clock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2002-12-14 13:02:16 +00:00
|
|
|
* gst_clock_id_wait_async:
|
|
|
|
* @id: a #GstClockID to wait on
|
2002-11-02 13:54:34 +00:00
|
|
|
* @func: The callback function
|
|
|
|
* @user_data: User data passed in the calback
|
|
|
|
*
|
2002-12-14 13:02:16 +00:00
|
|
|
* Register a callback on the given clockid with the given
|
|
|
|
* function and user_data.
|
2002-11-02 13:54:34 +00:00
|
|
|
*
|
2002-11-27 20:47:39 +00:00
|
|
|
* Returns: the result of the non blocking wait.
|
2002-11-02 13:54:34 +00:00
|
|
|
*/
|
|
|
|
GstClockReturn
|
|
|
|
gst_clock_id_wait_async (GstClockID id,
|
|
|
|
GstClockCallback func, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstClockEntry *entry;
|
|
|
|
GstClock *clock;
|
|
|
|
GstClockReturn res = GST_CLOCK_UNSUPPORTED;
|
2002-12-19 21:31:03 +00:00
|
|
|
GstClockClass *cclass;
|
2002-11-02 13:54:34 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (id != NULL, GST_CLOCK_ERROR);
|
2002-11-27 20:47:39 +00:00
|
|
|
g_return_val_if_fail (func != NULL, GST_CLOCK_ERROR);
|
2002-11-02 13:54:34 +00:00
|
|
|
|
|
|
|
entry = (GstClockEntry *) id;
|
|
|
|
clock = entry->clock;
|
|
|
|
|
2003-04-13 03:07:07 +00:00
|
|
|
if (! GST_CLOCK_TIME_IS_VALID (GST_CLOCK_ENTRY_TIME (entry))) {
|
2002-11-27 20:47:39 +00:00
|
|
|
(func) (clock, GST_CLOCK_TIME_NONE, id, user_data);
|
|
|
|
return GST_CLOCK_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
2002-12-19 21:31:03 +00:00
|
|
|
cclass = GST_CLOCK_GET_CLASS (clock);
|
|
|
|
|
|
|
|
if (cclass->wait_async) {
|
|
|
|
entry->func = func;
|
|
|
|
entry->user_data = user_data;
|
|
|
|
|
|
|
|
res = cclass->wait_async (clock, entry);
|
2002-11-02 13:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-12-27 04:11:59 +00:00
|
|
|
static void
|
|
|
|
gst_clock_reschedule_func (GstClockEntry *entry)
|
|
|
|
{
|
|
|
|
entry->status = GST_CLOCK_ENTRY_OK;
|
|
|
|
|
|
|
|
gst_clock_id_unlock ((GstClockID)entry);
|
|
|
|
}
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
/**
|
2002-12-14 13:02:16 +00:00
|
|
|
* gst_clock_id_unschedule:
|
|
|
|
* @id: The id to unschedule
|
2002-11-02 13:54:34 +00:00
|
|
|
*
|
|
|
|
* Cancel an outstanding async notification request with the given ID.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_clock_id_unschedule (GstClockID id)
|
|
|
|
{
|
|
|
|
GstClockEntry *entry;
|
|
|
|
GstClock *clock;
|
2002-12-19 21:31:03 +00:00
|
|
|
GstClockClass *cclass;
|
2002-11-02 13:54:34 +00:00
|
|
|
|
|
|
|
g_return_if_fail (id != NULL);
|
|
|
|
|
|
|
|
entry = (GstClockEntry *) id;
|
|
|
|
clock = entry->clock;
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2002-12-19 21:31:03 +00:00
|
|
|
cclass = GST_CLOCK_GET_CLASS (clock);
|
|
|
|
|
|
|
|
if (cclass->unschedule)
|
|
|
|
cclass->unschedule (clock, entry);
|
2002-03-30 17:05:03 +00:00
|
|
|
}
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
/**
|
2002-12-14 13:02:16 +00:00
|
|
|
* gst_clock_id_free:
|
2002-11-02 13:54:34 +00:00
|
|
|
* @id: The clockid to free
|
|
|
|
*
|
|
|
|
* Free the resources held by the given id
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_clock_id_free (GstClockID id)
|
2002-03-30 17:05:03 +00:00
|
|
|
{
|
2002-11-27 20:47:39 +00:00
|
|
|
g_return_if_fail (id != NULL);
|
|
|
|
|
2003-02-10 20:32:32 +00:00
|
|
|
#ifndef GST_DISABLE_TRACE
|
2003-02-02 19:21:06 +00:00
|
|
|
gst_alloc_trace_free (_gst_clock_entry_trace, id);
|
2003-02-10 20:32:32 +00:00
|
|
|
#endif
|
2002-11-02 13:54:34 +00:00
|
|
|
gst_mem_chunk_free (_gst_clock_entries_chunk, id);
|
|
|
|
}
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
/**
|
2002-12-14 13:02:16 +00:00
|
|
|
* gst_clock_id_unlock:
|
2002-11-02 13:54:34 +00:00
|
|
|
* @id: The clockid to unlock
|
|
|
|
*
|
|
|
|
* Unlock the givan ClockID.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_clock_id_unlock (GstClockID id)
|
|
|
|
{
|
|
|
|
GstClockEntry *entry;
|
|
|
|
GstClock *clock;
|
2002-12-19 21:31:03 +00:00
|
|
|
GstClockClass *cclass;
|
2002-11-02 13:54:34 +00:00
|
|
|
|
|
|
|
g_return_if_fail (id != NULL);
|
|
|
|
|
|
|
|
entry = (GstClockEntry *) id;
|
|
|
|
clock = entry->clock;
|
|
|
|
|
2002-12-19 21:31:03 +00:00
|
|
|
cclass = GST_CLOCK_GET_CLASS (clock);
|
|
|
|
|
|
|
|
if (cclass->unlock)
|
|
|
|
cclass->unlock (clock, entry);
|
2002-03-30 17:05:03 +00:00
|
|
|
}
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstClock abstract base class implementation
|
|
|
|
*/
|
2002-02-03 20:07:09 +00:00
|
|
|
GType
|
|
|
|
gst_clock_get_type (void)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2002-02-03 20:07:09 +00:00
|
|
|
static GType clock_type = 0;
|
|
|
|
|
|
|
|
if (!clock_type) {
|
|
|
|
static const GTypeInfo clock_info = {
|
2002-03-30 17:05:03 +00:00
|
|
|
sizeof (GstClockClass),
|
2002-02-03 20:07:09 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_clock_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2002-03-30 17:05:03 +00:00
|
|
|
sizeof (GstClock),
|
2002-02-03 20:07:09 +00:00
|
|
|
4,
|
|
|
|
(GInstanceInitFunc) gst_clock_init,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
clock_type = g_type_register_static (GST_TYPE_OBJECT, "GstClock",
|
2002-03-30 17:05:03 +00:00
|
|
|
&clock_info, G_TYPE_FLAG_ABSTRACT);
|
2002-02-03 20:07:09 +00:00
|
|
|
}
|
|
|
|
return clock_type;
|
|
|
|
}
|
2001-01-29 00:06:02 +00:00
|
|
|
|
2002-02-03 20:07:09 +00:00
|
|
|
static void
|
|
|
|
gst_clock_class_init (GstClockClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstObjectClass *gstobject_class;
|
2001-01-29 00:06:02 +00:00
|
|
|
|
2002-02-03 20:07:09 +00:00
|
|
|
gobject_class = (GObjectClass*) klass;
|
|
|
|
gstobject_class = (GstObjectClass*) klass;
|
2001-01-29 00:06:02 +00:00
|
|
|
|
2002-02-03 20:07:09 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_OBJECT);
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2002-03-31 14:04:50 +00:00
|
|
|
if (!g_thread_supported ())
|
|
|
|
g_thread_init (NULL);
|
|
|
|
|
2002-07-08 19:22:02 +00:00
|
|
|
_gst_clock_entries_chunk = gst_mem_chunk_new ("GstClockEntries",
|
2002-03-30 17:05:03 +00:00
|
|
|
sizeof (GstClockEntry), sizeof (GstClockEntry) * 32,
|
|
|
|
G_ALLOC_AND_FREE);
|
2002-11-02 13:54:34 +00:00
|
|
|
|
2003-02-10 20:32:32 +00:00
|
|
|
#ifndef GST_DISABLE_TRACE
|
2003-02-02 19:21:06 +00:00
|
|
|
_gst_clock_entry_trace = gst_alloc_trace_register (GST_CLOCK_ENTRY_TRACE_NAME);
|
2003-02-10 20:32:32 +00:00
|
|
|
#endif
|
2002-11-02 13:54:34 +00:00
|
|
|
|
2003-02-02 19:21:06 +00:00
|
|
|
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_clock_dispose);
|
2002-11-02 13:54:34 +00:00
|
|
|
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_clock_set_property);
|
|
|
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_clock_get_property);
|
|
|
|
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STATS,
|
|
|
|
g_param_spec_boolean ("stats", "Stats", "Enable clock stats",
|
|
|
|
FALSE, G_PARAM_READWRITE));
|
2002-12-27 04:11:59 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_DIFF,
|
|
|
|
g_param_spec_int64 ("max-diff", "Max diff", "The maximum amount of time to wait in nanoseconds",
|
|
|
|
0, G_MAXINT64, DEFAULT_MAX_DIFF, G_PARAM_READWRITE));
|
2000-04-09 21:38:17 +00:00
|
|
|
}
|
|
|
|
|
2002-02-03 20:07:09 +00:00
|
|
|
static void
|
|
|
|
gst_clock_init (GstClock *clock)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2002-12-27 04:11:59 +00:00
|
|
|
clock->max_diff = DEFAULT_MAX_DIFF;
|
|
|
|
|
2002-02-03 20:07:09 +00:00
|
|
|
clock->speed = 1.0;
|
|
|
|
clock->active = FALSE;
|
|
|
|
clock->start_time = 0;
|
2002-03-30 17:05:03 +00:00
|
|
|
clock->last_time = 0;
|
|
|
|
clock->entries = NULL;
|
2002-11-02 13:54:34 +00:00
|
|
|
clock->flags = 0;
|
|
|
|
clock->stats = FALSE;
|
2002-02-03 20:07:09 +00:00
|
|
|
|
|
|
|
clock->active_mutex = g_mutex_new ();
|
|
|
|
clock->active_cond = g_cond_new ();
|
2000-04-09 21:38:17 +00:00
|
|
|
}
|
|
|
|
|
2003-02-02 19:21:06 +00:00
|
|
|
static void
|
|
|
|
gst_clock_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GstClock *clock = GST_CLOCK (object);
|
|
|
|
|
|
|
|
g_mutex_free (clock->active_mutex);
|
|
|
|
g_cond_free (clock->active_cond);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2002-03-31 14:04:50 +00:00
|
|
|
/**
|
|
|
|
* gst_clock_set_speed
|
2002-04-23 15:01:56 +00:00
|
|
|
* @clock: a #GstClock to modify
|
|
|
|
* @speed: the speed to set on the clock
|
2002-03-31 14:04:50 +00:00
|
|
|
*
|
2002-04-23 15:01:56 +00:00
|
|
|
* Sets the speed on the given clock. 1.0 is the default
|
2002-03-31 14:04:50 +00:00
|
|
|
* speed.
|
2002-11-02 13:54:34 +00:00
|
|
|
*
|
|
|
|
* Returns: the new speed of the clock.
|
2002-03-31 14:04:50 +00:00
|
|
|
*/
|
2002-11-02 13:54:34 +00:00
|
|
|
gdouble
|
2002-03-31 14:04:50 +00:00
|
|
|
gst_clock_set_speed (GstClock *clock, gdouble speed)
|
|
|
|
{
|
2002-12-19 21:31:03 +00:00
|
|
|
GstClockClass *cclass;
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CLOCK (clock), 0.0);
|
|
|
|
|
2002-12-19 21:31:03 +00:00
|
|
|
cclass = GST_CLOCK_GET_CLASS (clock);
|
|
|
|
|
|
|
|
if (cclass->change_speed)
|
|
|
|
clock->speed = cclass->change_speed (clock, clock->speed, speed);
|
2002-03-31 14:04:50 +00:00
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
return clock->speed;
|
2002-03-31 14:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_clock_get_speed
|
2002-04-23 15:01:56 +00:00
|
|
|
* @clock: a #GstClock to query
|
2002-03-31 14:04:50 +00:00
|
|
|
*
|
2002-04-23 15:01:56 +00:00
|
|
|
* Gets the speed of the given clock.
|
2002-03-31 14:04:50 +00:00
|
|
|
*
|
|
|
|
* Returns: the speed of the clock.
|
|
|
|
*/
|
|
|
|
gdouble
|
|
|
|
gst_clock_get_speed (GstClock *clock)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_CLOCK (clock), 0.0);
|
|
|
|
|
|
|
|
return clock->speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2002-11-02 13:54:34 +00:00
|
|
|
* gst_clock_set_resolution
|
|
|
|
* @clock: The clock set the resolution on
|
|
|
|
* @resolution: The resolution to set
|
2002-03-31 14:04:50 +00:00
|
|
|
*
|
2002-11-02 13:54:34 +00:00
|
|
|
* Set the accuracy of the clock.
|
|
|
|
*
|
|
|
|
* Returns: the new resolution of the clock.
|
2002-03-31 14:04:50 +00:00
|
|
|
*/
|
2002-11-02 13:54:34 +00:00
|
|
|
guint64
|
|
|
|
gst_clock_set_resolution (GstClock *clock, guint64 resolution)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2002-12-19 21:31:03 +00:00
|
|
|
GstClockClass *cclass;
|
|
|
|
|
2003-02-10 20:32:32 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CLOCK (clock), G_GINT64_CONSTANT (0));
|
|
|
|
g_return_val_if_fail (resolution != 0, G_GINT64_CONSTANT (0));
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2002-12-19 21:31:03 +00:00
|
|
|
cclass = GST_CLOCK_GET_CLASS (clock);
|
|
|
|
|
|
|
|
if (cclass->change_resolution)
|
|
|
|
clock->resolution = cclass->change_resolution (clock, clock->resolution, resolution);
|
2002-02-03 20:07:09 +00:00
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
return clock->resolution;
|
|
|
|
}
|
2002-02-03 20:07:09 +00:00
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
/**
|
|
|
|
* gst_clock_get_resolution
|
|
|
|
* @clock: The clock get the resolution of
|
|
|
|
*
|
|
|
|
* Get the accuracy of the clock.
|
|
|
|
*
|
|
|
|
* Returns: the resolution of the clock in microseconds.
|
|
|
|
*/
|
|
|
|
guint64
|
|
|
|
gst_clock_get_resolution (GstClock *clock)
|
|
|
|
{
|
2002-12-19 21:31:03 +00:00
|
|
|
GstClockClass *cclass;
|
|
|
|
|
2003-02-10 20:32:32 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CLOCK (clock), G_GINT64_CONSTANT (0));
|
2002-11-02 13:54:34 +00:00
|
|
|
|
2002-12-19 21:31:03 +00:00
|
|
|
cclass = GST_CLOCK_GET_CLASS (clock);
|
|
|
|
|
|
|
|
if (cclass->get_resolution)
|
|
|
|
return cclass->get_resolution (clock);
|
2002-11-02 13:54:34 +00:00
|
|
|
|
2003-02-10 20:32:32 +00:00
|
|
|
return G_GINT64_CONSTANT (1);
|
2000-04-09 21:38:17 +00:00
|
|
|
}
|
|
|
|
|
2002-03-31 14:04:50 +00:00
|
|
|
/**
|
2002-04-23 15:01:56 +00:00
|
|
|
* gst_clock_set_active
|
|
|
|
* @clock: a #GstClock to set state of
|
|
|
|
* @active: flag indicating if the clock should be activated (TRUE) or deactivated
|
2002-03-31 14:04:50 +00:00
|
|
|
*
|
2002-04-23 15:01:56 +00:00
|
|
|
* Activates or deactivates the clock based on the active parameter.
|
2002-03-31 14:04:50 +00:00
|
|
|
* As soon as the clock is activated, the time will start ticking.
|
|
|
|
*/
|
2001-01-29 00:06:02 +00:00
|
|
|
void
|
2002-04-23 15:01:56 +00:00
|
|
|
gst_clock_set_active (GstClock *clock, gboolean active)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2003-02-10 20:32:32 +00:00
|
|
|
GstClockTime time = G_GINT64_CONSTANT (0);
|
2002-12-19 21:31:03 +00:00
|
|
|
GstClockClass *cclass;
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2002-02-03 20:07:09 +00:00
|
|
|
g_return_if_fail (GST_IS_CLOCK (clock));
|
|
|
|
|
|
|
|
clock->active = active;
|
2002-12-19 21:31:03 +00:00
|
|
|
|
|
|
|
cclass = GST_CLOCK_GET_CLASS (clock);
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2002-12-19 21:31:03 +00:00
|
|
|
if (cclass->get_internal_time) {
|
|
|
|
time = cclass->get_internal_time (clock);
|
2002-03-30 17:05:03 +00:00
|
|
|
}
|
2002-02-03 20:07:09 +00:00
|
|
|
|
2002-03-30 17:05:03 +00:00
|
|
|
GST_LOCK (clock);
|
|
|
|
if (active) {
|
2002-05-26 21:54:27 +00:00
|
|
|
clock->start_time = time - clock->last_time;
|
|
|
|
clock->accept_discont = TRUE;
|
2002-03-30 17:05:03 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
clock->last_time = time - clock->start_time;
|
2002-05-26 21:54:27 +00:00
|
|
|
clock->accept_discont = FALSE;
|
2002-03-30 17:05:03 +00:00
|
|
|
}
|
2002-12-27 04:11:59 +00:00
|
|
|
g_list_foreach (clock->entries, (GFunc) gst_clock_reschedule_func, NULL);
|
2002-03-30 17:05:03 +00:00
|
|
|
GST_UNLOCK (clock);
|
2002-02-03 20:07:09 +00:00
|
|
|
|
|
|
|
g_mutex_lock (clock->active_mutex);
|
2002-03-30 17:05:03 +00:00
|
|
|
g_cond_broadcast (clock->active_cond);
|
2002-02-03 20:07:09 +00:00
|
|
|
g_mutex_unlock (clock->active_mutex);
|
2000-07-12 22:52:42 +00:00
|
|
|
}
|
|
|
|
|
2002-03-31 14:04:50 +00:00
|
|
|
/**
|
|
|
|
* gst_clock_is_active
|
2002-04-23 15:01:56 +00:00
|
|
|
* @clock: a #GstClock to query
|
2002-03-31 14:04:50 +00:00
|
|
|
*
|
|
|
|
* Checks if the given clock is active.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the clock is active.
|
|
|
|
*/
|
2002-02-03 20:07:09 +00:00
|
|
|
gboolean
|
|
|
|
gst_clock_is_active (GstClock *clock)
|
2000-07-12 22:52:42 +00:00
|
|
|
{
|
2002-02-03 20:07:09 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CLOCK (clock), FALSE);
|
2000-07-12 22:52:42 +00:00
|
|
|
|
2002-02-03 20:07:09 +00:00
|
|
|
return clock->active;
|
2000-04-09 21:38:17 +00:00
|
|
|
}
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
/**
|
|
|
|
* gst_clock_reset
|
|
|
|
* @clock: a #GstClock to reset
|
|
|
|
*
|
|
|
|
* Reset the clock to time 0.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_clock_reset (GstClock *clock)
|
|
|
|
{
|
2003-02-10 20:32:32 +00:00
|
|
|
GstClockTime time = G_GINT64_CONSTANT (0);
|
2002-12-19 21:31:03 +00:00
|
|
|
GstClockClass *cclass;
|
2002-11-02 13:54:34 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_CLOCK (clock));
|
|
|
|
|
2002-12-19 21:31:03 +00:00
|
|
|
cclass = GST_CLOCK_GET_CLASS (clock);
|
|
|
|
|
|
|
|
if (cclass->get_internal_time) {
|
|
|
|
time = cclass->get_internal_time (clock);
|
2002-11-02 13:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOCK (clock);
|
|
|
|
clock->active = FALSE;
|
|
|
|
clock->start_time = time;
|
2003-02-10 20:32:32 +00:00
|
|
|
clock->last_time = G_GINT64_CONSTANT (0);
|
2002-12-27 04:11:59 +00:00
|
|
|
g_list_foreach (clock->entries, (GFunc) gst_clock_reschedule_func, NULL);
|
2002-11-02 13:54:34 +00:00
|
|
|
GST_UNLOCK (clock);
|
|
|
|
}
|
|
|
|
|
2002-06-12 22:26:36 +00:00
|
|
|
/**
|
|
|
|
* gst_clock_handle_discont
|
|
|
|
* @clock: a #GstClock to notify of the discontinuity
|
|
|
|
* @time: The new time
|
|
|
|
*
|
|
|
|
* Notifies the clock of a discontinuity in time.
|
2002-12-11 21:33:07 +00:00
|
|
|
*
|
2002-06-12 22:26:36 +00:00
|
|
|
* Returns: TRUE if the clock was updated. It is possible that
|
|
|
|
* the clock was not updated by this call because only the first
|
|
|
|
* discontinuitity in the pipeline is honoured.
|
|
|
|
*/
|
2002-05-26 21:54:27 +00:00
|
|
|
gboolean
|
|
|
|
gst_clock_handle_discont (GstClock *clock, guint64 time)
|
|
|
|
{
|
2003-02-10 20:32:32 +00:00
|
|
|
GstClockTime itime = G_GINT64_CONSTANT (0);
|
2002-12-11 21:33:07 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CLOCK, "clock discont %" G_GUINT64_FORMAT
|
2002-12-11 21:33:07 +00:00
|
|
|
" %" G_GUINT64_FORMAT " %d",
|
|
|
|
time, clock->start_time, clock->accept_discont);
|
2002-05-26 21:54:27 +00:00
|
|
|
|
2003-04-13 03:07:07 +00:00
|
|
|
if (! GST_CLOCK_TIME_IS_VALID (time))
|
2002-11-27 20:47:39 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
GST_LOCK (clock);
|
|
|
|
if (clock->accept_discont) {
|
2002-12-19 21:31:03 +00:00
|
|
|
GstClockClass *cclass;
|
|
|
|
|
|
|
|
cclass = GST_CLOCK_GET_CLASS (clock);
|
|
|
|
|
|
|
|
if (cclass->get_internal_time) {
|
|
|
|
itime = cclass->get_internal_time (clock);
|
2002-05-26 21:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GST_UNLOCK (clock);
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CLOCK, "clock discont refused %" G_GUINT64_FORMAT
|
2002-12-11 21:33:07 +00:00
|
|
|
" %" G_GUINT64_FORMAT,
|
|
|
|
time, clock->start_time);
|
2002-05-26 21:54:27 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
clock->start_time = itime - time;
|
|
|
|
clock->last_time = time;
|
|
|
|
clock->accept_discont = FALSE;
|
2002-12-27 04:11:59 +00:00
|
|
|
g_list_foreach (clock->entries, (GFunc) gst_clock_reschedule_func, NULL);
|
2002-05-26 21:54:27 +00:00
|
|
|
GST_UNLOCK (clock);
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CLOCK, "new time %" G_GUINT64_FORMAT,
|
2002-12-11 21:33:07 +00:00
|
|
|
gst_clock_get_time (clock));
|
2002-05-26 21:54:27 +00:00
|
|
|
|
2002-12-11 21:33:07 +00:00
|
|
|
g_mutex_lock (clock->active_mutex);
|
|
|
|
g_cond_broadcast (clock->active_cond);
|
|
|
|
g_mutex_unlock (clock->active_mutex);
|
2002-05-26 21:54:27 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-03-31 14:04:50 +00:00
|
|
|
/**
|
|
|
|
* gst_clock_get_time
|
2002-04-23 15:01:56 +00:00
|
|
|
* @clock: a #GstClock to query
|
2002-03-31 14:04:50 +00:00
|
|
|
*
|
2002-04-23 15:01:56 +00:00
|
|
|
* Gets the current time of the given clock. The time is always
|
2002-03-31 14:04:50 +00:00
|
|
|
* monotonically increasing.
|
2002-12-11 21:33:07 +00:00
|
|
|
*
|
2002-03-31 14:04:50 +00:00
|
|
|
* Returns: the time of the clock.
|
|
|
|
*/
|
2002-02-03 20:07:09 +00:00
|
|
|
GstClockTime
|
|
|
|
gst_clock_get_time (GstClock *clock)
|
|
|
|
{
|
2003-02-10 20:32:32 +00:00
|
|
|
GstClockTime ret = G_GINT64_CONSTANT (0);
|
2002-03-30 17:05:03 +00:00
|
|
|
|
2003-02-10 20:32:32 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CLOCK (clock), G_GINT64_CONSTANT (0));
|
2002-02-03 20:07:09 +00:00
|
|
|
|
2002-03-30 17:05:03 +00:00
|
|
|
if (!clock->active) {
|
2003-02-02 19:21:06 +00:00
|
|
|
/* clock is not active return previous time */
|
2002-03-30 17:05:03 +00:00
|
|
|
ret = clock->last_time;
|
|
|
|
}
|
|
|
|
else {
|
2002-12-19 21:31:03 +00:00
|
|
|
GstClockClass *cclass;
|
|
|
|
|
|
|
|
cclass = GST_CLOCK_GET_CLASS (clock);
|
|
|
|
|
|
|
|
if (cclass->get_internal_time) {
|
|
|
|
ret = cclass->get_internal_time (clock) - clock->start_time;
|
2002-03-30 17:05:03 +00:00
|
|
|
}
|
|
|
|
/* make sure the time is increasing, else return last_time */
|
2002-05-26 21:54:27 +00:00
|
|
|
if ((gint64) ret < (gint64) clock->last_time) {
|
2002-03-30 17:05:03 +00:00
|
|
|
ret = clock->last_time;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
clock->last_time = ret;
|
|
|
|
}
|
|
|
|
}
|
2002-02-03 20:07:09 +00:00
|
|
|
|
2002-03-30 17:05:03 +00:00
|
|
|
return ret;
|
2002-02-03 20:07:09 +00:00
|
|
|
}
|
|
|
|
|
2002-03-31 14:04:50 +00:00
|
|
|
/**
|
|
|
|
* gst_clock_get_next_id
|
|
|
|
* @clock: The clock to query
|
|
|
|
*
|
|
|
|
* Get the clockid of the next event.
|
|
|
|
*
|
|
|
|
* Returns: a clockid or NULL is no event is pending.
|
|
|
|
*/
|
2002-03-30 17:05:03 +00:00
|
|
|
GstClockID
|
|
|
|
gst_clock_get_next_id (GstClock *clock)
|
|
|
|
{
|
|
|
|
GstClockEntry *entry = NULL;
|
|
|
|
|
2002-11-27 20:47:39 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CLOCK (clock), NULL);
|
|
|
|
|
2002-03-30 17:05:03 +00:00
|
|
|
GST_LOCK (clock);
|
|
|
|
if (clock->entries)
|
|
|
|
entry = GST_CLOCK_ENTRY (clock->entries->data);
|
|
|
|
GST_UNLOCK (clock);
|
|
|
|
|
|
|
|
return (GstClockID *) entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-11-02 13:54:34 +00:00
|
|
|
gst_clock_update_stats (GstClock *clock)
|
2002-03-30 17:05:03 +00:00
|
|
|
{
|
2002-02-03 20:07:09 +00:00
|
|
|
}
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
static void
|
|
|
|
gst_clock_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
2002-02-03 20:07:09 +00:00
|
|
|
{
|
2002-11-02 13:54:34 +00:00
|
|
|
GstClock *clock;
|
|
|
|
|
|
|
|
clock = GST_CLOCK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_STATS:
|
|
|
|
clock->stats = g_value_get_boolean (value);
|
|
|
|
break;
|
2002-12-27 04:11:59 +00:00
|
|
|
case ARG_MAX_DIFF:
|
|
|
|
clock->max_diff = g_value_get_int64 (value);
|
|
|
|
break;
|
2002-11-02 13:54:34 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2000-04-09 21:38:17 +00:00
|
|
|
}
|
2002-02-03 20:07:09 +00:00
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
static void
|
|
|
|
gst_clock_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec * pspec)
|
2002-02-03 20:07:09 +00:00
|
|
|
{
|
2002-11-02 13:54:34 +00:00
|
|
|
GstClock *clock;
|
|
|
|
|
|
|
|
clock = GST_CLOCK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_STATS:
|
|
|
|
g_value_set_boolean (value, clock->stats);
|
|
|
|
break;
|
2002-12-27 04:11:59 +00:00
|
|
|
case ARG_MAX_DIFF:
|
|
|
|
g_value_set_int64 (value, clock->max_diff);
|
|
|
|
break;
|
2002-11-02 13:54:34 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2002-02-03 20:07:09 +00:00
|
|
|
}
|