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
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* #define GST_DEBUG_ENABLED */
|
2000-12-28 22:12:02 +00:00
|
|
|
#include "gst_private.h"
|
|
|
|
|
2000-12-15 01:57:34 +00:00
|
|
|
#include "gstclock.h"
|
2000-04-09 21:38:17 +00:00
|
|
|
|
2002-02-03 20:07:09 +00:00
|
|
|
#define CLASS(clock) GST_CLOCK_CLASS (G_OBJECT_GET_CLASS (clock))
|
2000-12-28 22:12:02 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
static GstObjectClass *parent_class = NULL;
|
|
|
|
/* static guint gst_clock_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
|
|
|
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 = {
|
|
|
|
sizeof (GstObjectClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_clock_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstObject),
|
|
|
|
4,
|
|
|
|
(GInstanceInitFunc) gst_clock_init,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
clock_type = g_type_register_static (GST_TYPE_OBJECT, "GstClock",
|
|
|
|
&clock_info, G_TYPE_FLAG_ABSTRACT);
|
|
|
|
}
|
|
|
|
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);
|
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-02-03 20:07:09 +00:00
|
|
|
clock->speed = 1.0;
|
|
|
|
clock->active = FALSE;
|
|
|
|
clock->start_time = 0;
|
|
|
|
|
|
|
|
clock->active_mutex = g_mutex_new ();
|
|
|
|
clock->active_cond = g_cond_new ();
|
2000-04-09 21:38:17 +00:00
|
|
|
}
|
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
void
|
2002-02-03 20:07:09 +00:00
|
|
|
gst_clock_reset (GstClock *clock)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2002-02-03 20:07:09 +00:00
|
|
|
g_return_if_fail (GST_IS_CLOCK (clock));
|
|
|
|
|
|
|
|
clock->start_time = 0;
|
|
|
|
clock->active = FALSE;
|
|
|
|
|
|
|
|
if (CLASS (clock)->reset)
|
|
|
|
CLASS (clock)->reset (clock);
|
2000-04-09 21:38:17 +00:00
|
|
|
}
|
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
void
|
2002-02-03 20:07:09 +00:00
|
|
|
gst_clock_activate (GstClock *clock, gboolean active)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2002-02-03 20:07:09 +00:00
|
|
|
g_return_if_fail (GST_IS_CLOCK (clock));
|
|
|
|
|
|
|
|
clock->active = active;
|
|
|
|
|
|
|
|
if (CLASS (clock)->activate)
|
|
|
|
CLASS (clock)->activate (clock, active);
|
|
|
|
|
|
|
|
g_mutex_lock (clock->active_mutex);
|
|
|
|
g_cond_signal (clock->active_cond);
|
|
|
|
g_mutex_unlock (clock->active_mutex);
|
|
|
|
|
2000-07-12 22:52:42 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
void
|
2002-02-03 20:07:09 +00:00
|
|
|
gst_clock_set_time (GstClock *clock, GstClockTime time)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2002-02-03 20:07:09 +00:00
|
|
|
g_return_if_fail (GST_IS_CLOCK (clock));
|
|
|
|
|
|
|
|
if (CLASS (clock)->set_time)
|
|
|
|
CLASS (clock)->set_time (clock, time);
|
2000-04-09 21:38:17 +00:00
|
|
|
}
|
|
|
|
|
2002-02-03 20:07:09 +00:00
|
|
|
GstClockTime
|
|
|
|
gst_clock_get_time (GstClock *clock)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_CLOCK (clock), 0LL);
|
|
|
|
|
|
|
|
if (CLASS (clock)->get_time)
|
|
|
|
return CLASS (clock)->get_time (clock);
|
|
|
|
|
|
|
|
return 0LL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstClockReturn
|
|
|
|
gst_clock_wait (GstClock *clock, GstClockTime time)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2002-02-03 20:07:09 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CLOCK (clock), GST_CLOCK_STOPPED);
|
|
|
|
|
|
|
|
if (!clock->active) {
|
|
|
|
g_mutex_lock (clock->active_mutex);
|
|
|
|
g_cond_wait (clock->active_cond, clock->active_mutex);
|
|
|
|
g_mutex_unlock (clock->active_mutex);
|
2000-04-09 21:38:17 +00:00
|
|
|
}
|
2002-02-03 20:07:09 +00:00
|
|
|
if (CLASS (clock)->wait)
|
|
|
|
return CLASS (clock)->wait (clock, time);
|
|
|
|
|
|
|
|
return GST_CLOCK_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_clock_set_resolution (GstClock *clock, guint64 resolution)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_CLOCK (clock));
|
|
|
|
|
|
|
|
if (CLASS (clock)->set_resolution)
|
|
|
|
CLASS (clock)->set_resolution (clock, resolution);
|
2000-04-09 21:38:17 +00:00
|
|
|
}
|
2002-02-03 20:07:09 +00:00
|
|
|
|
|
|
|
guint64
|
|
|
|
gst_clock_get_resolution (GstClock *clock)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_CLOCK (clock), 0LL);
|
|
|
|
|
|
|
|
if (CLASS (clock)->get_resolution)
|
|
|
|
return CLASS (clock)->get_resolution (clock);
|
|
|
|
|
|
|
|
return 0LL;
|
|
|
|
}
|
|
|
|
|