2002-02-03 20:07:09 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wim.taymans@chello.be>
|
|
|
|
*
|
2003-07-16 15:49:40 +00:00
|
|
|
* gstsystemclock.c: Default clock, uses the system clock
|
2002-02-03 20:07:09 +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.
|
|
|
|
*/
|
|
|
|
|
2004-04-28 23:26:06 +00:00
|
|
|
#include <time.h>
|
2002-02-03 20:07:09 +00:00
|
|
|
|
|
|
|
#include "gst_private.h"
|
2003-06-29 14:05:49 +00:00
|
|
|
#include "gstinfo.h"
|
2002-02-03 20:07:09 +00:00
|
|
|
|
|
|
|
#include "gstsystemclock.h"
|
|
|
|
|
|
|
|
static GstClock *_the_system_clock = NULL;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_system_clock_class_init (GstSystemClockClass * klass);
|
|
|
|
static void gst_system_clock_init (GstSystemClock * clock);
|
|
|
|
static void gst_system_clock_dispose (GObject * object);
|
2002-02-03 20:07:09 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static GstClockTime gst_system_clock_get_internal_time (GstClock * clock);
|
|
|
|
static guint64 gst_system_clock_get_resolution (GstClock * clock);
|
|
|
|
static GstClockEntryStatus gst_system_clock_wait (GstClock * clock,
|
|
|
|
GstClockEntry * entry);
|
|
|
|
static void gst_system_clock_unlock (GstClock * clock, GstClockEntry * entry);
|
2002-02-03 20:07:09 +00:00
|
|
|
|
2003-05-10 14:38:48 +00:00
|
|
|
static GStaticMutex _gst_sysclock_mutex = G_STATIC_MUTEX_INIT;
|
2002-02-03 20:07:09 +00:00
|
|
|
|
|
|
|
static GstClockClass *parent_class = NULL;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-02-03 20:07:09 +00:00
|
|
|
/* static guint gst_system_clock_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_system_clock_get_type (void)
|
|
|
|
{
|
|
|
|
static GType clock_type = 0;
|
|
|
|
|
|
|
|
if (!clock_type) {
|
|
|
|
static const GTypeInfo clock_info = {
|
|
|
|
sizeof (GstSystemClockClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_system_clock_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstSystemClock),
|
2004-04-09 19:05:03 +00:00
|
|
|
0,
|
2002-02-03 20:07:09 +00:00
|
|
|
(GInstanceInitFunc) gst_system_clock_init,
|
|
|
|
NULL
|
|
|
|
};
|
2004-03-15 19:27:17 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
clock_type = g_type_register_static (GST_TYPE_CLOCK, "GstSystemClock",
|
2004-03-15 19:27:17 +00:00
|
|
|
&clock_info, 0);
|
2002-02-03 20:07:09 +00:00
|
|
|
}
|
|
|
|
return clock_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_system_clock_class_init (GstSystemClockClass * klass)
|
2002-02-03 20:07:09 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstObjectClass *gstobject_class;
|
|
|
|
GstClockClass *gstclock_class;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstobject_class = (GstObjectClass *) klass;
|
|
|
|
gstclock_class = (GstClockClass *) klass;
|
2002-02-03 20:07:09 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_CLOCK);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gobject_class->dispose = gst_system_clock_dispose;
|
2003-02-02 19:19:39 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gstclock_class->get_internal_time = gst_system_clock_get_internal_time;
|
|
|
|
gstclock_class->get_resolution = gst_system_clock_get_resolution;
|
|
|
|
gstclock_class->wait = gst_system_clock_wait;
|
|
|
|
gstclock_class->unlock = gst_system_clock_unlock;
|
2002-02-03 20:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_system_clock_init (GstSystemClock * clock)
|
2002-02-03 20:07:09 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
clock->mutex = g_mutex_new ();
|
2003-05-10 14:38:48 +00:00
|
|
|
clock->cond = g_cond_new ();
|
2002-02-03 20:07:09 +00:00
|
|
|
}
|
|
|
|
|
2003-02-02 19:19:39 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_system_clock_dispose (GObject * object)
|
2003-02-02 19:19:39 +00:00
|
|
|
{
|
2003-05-10 11:11:29 +00:00
|
|
|
GstClock *clock = (GstClock *) object;
|
2003-05-10 14:38:48 +00:00
|
|
|
GstSystemClock *sysclock = (GstSystemClock *) object;
|
2003-02-02 19:19:39 +00:00
|
|
|
|
2003-05-10 11:11:29 +00:00
|
|
|
/* there are subclasses of GstSystemClock running around... */
|
|
|
|
if (_the_system_clock == clock) {
|
|
|
|
g_warning ("disposing systemclock!");
|
|
|
|
|
|
|
|
/* no parent dispose here, this is bad enough already */
|
|
|
|
} else {
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2003-05-10 14:38:48 +00:00
|
|
|
|
|
|
|
/* FIXME: Notifying before freeing? */
|
|
|
|
g_cond_free (sysclock->cond);
|
|
|
|
g_mutex_free (sysclock->mutex);
|
2003-05-10 11:11:29 +00:00
|
|
|
}
|
2003-02-02 19:19:39 +00:00
|
|
|
}
|
|
|
|
|
2002-03-31 14:04:50 +00:00
|
|
|
/**
|
|
|
|
* gst_system_clock_obtain
|
|
|
|
*
|
|
|
|
* Get a handle to the default system clock.
|
|
|
|
*
|
|
|
|
* Returns: the default clock.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstClock *
|
2002-02-03 20:07:09 +00:00
|
|
|
gst_system_clock_obtain (void)
|
|
|
|
{
|
2003-02-02 19:19:39 +00:00
|
|
|
GstClock *clock = _the_system_clock;
|
|
|
|
|
|
|
|
if (clock == NULL) {
|
2003-05-10 14:38:48 +00:00
|
|
|
g_static_mutex_lock (&_gst_sysclock_mutex);
|
|
|
|
if (_the_system_clock != NULL) {
|
|
|
|
clock = _the_system_clock;
|
|
|
|
g_static_mutex_unlock (&_gst_sysclock_mutex);
|
2003-05-10 11:11:29 +00:00
|
|
|
goto have_clock;
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-02-02 19:19:39 +00:00
|
|
|
clock = GST_CLOCK (g_object_new (GST_TYPE_SYSTEM_CLOCK, NULL));
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-02-02 19:19:39 +00:00
|
|
|
gst_object_set_name (GST_OBJECT (clock), "GstSystemClock");
|
2003-01-17 18:48:17 +00:00
|
|
|
|
2003-02-02 19:19:39 +00:00
|
|
|
gst_object_ref (GST_OBJECT (clock));
|
|
|
|
gst_object_sink (GST_OBJECT (clock));
|
|
|
|
|
|
|
|
_the_system_clock = clock;
|
2003-05-10 14:38:48 +00:00
|
|
|
g_static_mutex_unlock (&_gst_sysclock_mutex);
|
2002-02-03 20:07:09 +00:00
|
|
|
}
|
2003-02-02 19:19:39 +00:00
|
|
|
|
2003-05-10 11:11:29 +00:00
|
|
|
have_clock:
|
|
|
|
gst_object_ref (GST_OBJECT (clock));
|
2003-02-02 19:19:39 +00:00
|
|
|
return clock;
|
2002-02-03 20:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstClockTime
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_system_clock_get_internal_time (GstClock * clock)
|
2002-02-03 20:07:09 +00:00
|
|
|
{
|
|
|
|
GTimeVal timeval;
|
2002-05-26 21:54:27 +00:00
|
|
|
|
2002-03-30 17:05:03 +00:00
|
|
|
g_get_current_time (&timeval);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-03-30 17:05:03 +00:00
|
|
|
return GST_TIMEVAL_TO_TIME (timeval);
|
2002-02-03 20:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static guint64
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_system_clock_get_resolution (GstClock * clock)
|
2002-02-03 20:07:09 +00:00
|
|
|
{
|
2002-05-26 21:54:27 +00:00
|
|
|
return 1 * GST_USECOND;
|
2002-02-03 20:07:09 +00:00
|
|
|
}
|
|
|
|
|
2002-12-11 21:33:07 +00:00
|
|
|
static GstClockEntryStatus
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_system_clock_wait (GstClock * clock, GstClockEntry * entry)
|
2002-11-02 13:54:34 +00:00
|
|
|
{
|
2002-12-27 04:11:59 +00:00
|
|
|
GstClockEntryStatus res;
|
2002-11-02 13:54:34 +00:00
|
|
|
GstClockTime current, target;
|
2002-12-27 04:11:59 +00:00
|
|
|
gint64 diff;
|
2003-05-10 14:38:48 +00:00
|
|
|
GstSystemClock *sysclock = GST_SYSTEM_CLOCK (clock);
|
2002-12-11 21:33:07 +00:00
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
current = gst_clock_get_time (clock);
|
2002-12-27 04:11:59 +00:00
|
|
|
diff = GST_CLOCK_ENTRY_TIME (entry) - current;
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
if (diff + clock->max_diff < 0) {
|
gst/gstcaps.c: add sanity checks
Original commit message from CVS:
2003-12-27 Benjamin Otte <in7y118@public.uni-hamburg.de>
* gst/gstcaps.c: (gst_caps_append):
add sanity checks
* gst/gstcaps.h: (gst_caps_debug):
remove, it doesn't exist anymore.
* gst/gstelement.c: (gst_element_threadsafe_properties_pre_run),
(gst_element_threadsafe_properties_post_run):
make debugging messages not clutter up THREAD debug category
(gst_element_negotiate_pads), (gst_element_clear_pad_caps),
(gst_element_change_state):
update to new caps API
* gst/gstinterface.c: (gst_implements_interface_cast):
don't put vital code in g_return_if_fail
* gst/gstpad.c: (gst_pad_link_try), (gst_pad_try_set_caps),
(gst_pad_link_filtered):
add pst_pad_try_link and use it.
(gst_pad_perform_negotiate), (gst_pad_renegotiate):
implement correctly, deprecate first one.
(gst_pad_link_unnegotiate), (gst_pad_unnegotiate):
add and implement.
(gst_pad_try_relink_filtered), (gst_pad_relink_filtered):
implement.
(gst_pad_get_negotiated_caps):
add and implement. Make GST_PAD_CAPS call this function.
(gst_pad_get_caps):
remove unneeded check..
(gst_pad_recover_caps_error):
disable, always return FALSE.
(gst_real_pad_dispose):
don't free caps and appfilter anymore, they're unused.
* gst/gstpad.h:
Reflect changes mentioned above.
* gst/gstsystemclock.c: (gst_system_clock_wait):
Make 'clock is way behind' a debugging message.
* gst/gstthread.c: (gst_thread_change_state):
Fix debugging message
2003-12-27 13:51:31 +00:00
|
|
|
GST_WARNING_OBJECT (clock, "clock is way behind: %" G_GINT64_FORMAT
|
2004-03-15 19:27:17 +00:00
|
|
|
"s (max allowed is %" G_GINT64_FORMAT "s", -diff, clock->max_diff);
|
2002-12-27 04:11:59 +00:00
|
|
|
return GST_CLOCK_ENTRY_EARLY;
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-12-27 04:11:59 +00:00
|
|
|
target = gst_system_clock_get_internal_time (clock) + diff;
|
2002-12-11 21:33:07 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CLOCK, "real_target %" G_GUINT64_FORMAT
|
2004-03-13 15:27:01 +00:00
|
|
|
" target %" G_GUINT64_FORMAT
|
|
|
|
" now %" G_GUINT64_FORMAT, target, GST_CLOCK_ENTRY_TIME (entry), current);
|
2002-12-11 21:33:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (((gint64) target) > 0) {
|
2002-11-02 13:54:34 +00:00
|
|
|
GTimeVal tv;
|
|
|
|
|
|
|
|
GST_TIME_TO_TIMEVAL (target, tv);
|
2003-05-10 14:38:48 +00:00
|
|
|
g_mutex_lock (sysclock->mutex);
|
|
|
|
g_cond_timed_wait (sysclock->cond, sysclock->mutex, &tv);
|
|
|
|
g_mutex_unlock (sysclock->mutex);
|
2002-12-27 04:11:59 +00:00
|
|
|
res = entry->status;
|
2004-03-13 15:27:01 +00:00
|
|
|
} else {
|
2002-11-02 13:54:34 +00:00
|
|
|
res = GST_CLOCK_ENTRY_EARLY;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2002-02-03 20:07:09 +00:00
|
|
|
|
2002-12-27 04:11:59 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_system_clock_unlock (GstClock * clock, GstClockEntry * entry)
|
2002-12-27 04:11:59 +00:00
|
|
|
{
|
2003-05-10 14:38:48 +00:00
|
|
|
GstSystemClock *sysclock = GST_SYSTEM_CLOCK (clock);
|
|
|
|
|
|
|
|
g_mutex_lock (sysclock->mutex);
|
|
|
|
g_cond_broadcast (sysclock->cond);
|
|
|
|
g_mutex_unlock (sysclock->mutex);
|
2002-12-27 04:11:59 +00:00
|
|
|
}
|