#include "gstlog.h"
#include "gstmemchunk.h"
+#define DEFAULT_MAX_DIFF (2 * GST_SECOND)
+
enum {
ARG_0,
ARG_STATS,
+ ARG_MAX_DIFF,
};
static GstMemChunk *_gst_clock_entries_chunk;
requested = GST_CLOCK_ENTRY_TIME (entry);
if (requested == GST_CLOCK_TIME_NONE) {
- res = GST_CLOCK_TIMEOUT;
- goto done;
+ return GST_CLOCK_TIMEOUT;
}
-
+
clock = GST_CLOCK_ENTRY_CLOCK (entry);
cclass = GST_CLOCK_GET_CLASS (clock);
if (cclass->wait) {
GstClockTime now;
+
+ GST_LOCK (clock);
+ clock->entries = g_list_prepend (clock->entries, entry);
+ GST_UNLOCK (clock);
do {
res = cclass->wait (clock, entry);
}
while (res == GST_CLOCK_ENTRY_RESTART);
+ GST_LOCK (clock);
+ clock->entries = g_list_remove (clock->entries, entry);
+ GST_UNLOCK (clock);
+
if (jitter) {
now = gst_clock_get_time (clock);
*jitter = now - requested;
}
}
-done:
- if (entry->type == GST_CLOCK_ENTRY_SINGLE) {
- gst_clock_id_free (id);
- }
-
return res;
}
return res;
}
+static void
+gst_clock_reschedule_func (GstClockEntry *entry)
+{
+ entry->status = GST_CLOCK_ENTRY_OK;
+
+ gst_clock_id_unlock ((GstClockID)entry);
+}
+
/**
* gst_clock_id_unschedule:
* @id: The id to unschedule
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STATS,
g_param_spec_boolean ("stats", "Stats", "Enable clock stats",
FALSE, G_PARAM_READWRITE));
+ 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));
}
static void
gst_clock_init (GstClock *clock)
{
+ clock->max_diff = DEFAULT_MAX_DIFF;
+
clock->speed = 1.0;
clock->active = FALSE;
clock->start_time = 0;
clock->last_time = time - clock->start_time;
clock->accept_discont = FALSE;
}
+ g_list_foreach (clock->entries, (GFunc) gst_clock_reschedule_func, NULL);
GST_UNLOCK (clock);
g_mutex_lock (clock->active_mutex);
clock->active = FALSE;
clock->start_time = time;
clock->last_time = 0LL;
+ g_list_foreach (clock->entries, (GFunc) gst_clock_reschedule_func, NULL);
GST_UNLOCK (clock);
}
clock->start_time = itime - time;
clock->last_time = time;
clock->accept_discont = FALSE;
+ g_list_foreach (clock->entries, (GFunc) gst_clock_reschedule_func, NULL);
GST_UNLOCK (clock);
GST_DEBUG (GST_CAT_CLOCK, "new time %" G_GUINT64_FORMAT,
case ARG_STATS:
clock->stats = g_value_get_boolean (value);
break;
+ case ARG_MAX_DIFF:
+ clock->max_diff = g_value_get_int64 (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case ARG_STATS:
g_value_set_boolean (value, clock->stats);
break;
+ case ARG_MAX_DIFF:
+ g_value_set_int64 (value, clock->max_diff);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
/* #define GST_DEBUG_ENABLED */
#include "gst_private.h"
+#include "gstlog.h"
#include "gstsystemclock.h"
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);
static GCond *_gst_sysclock_cond = NULL;
static GMutex *_gst_sysclock_mutex = NULL;
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;
_gst_sysclock_cond = g_cond_new ();
_gst_sysclock_mutex = g_mutex_new ();
static GstClockEntryStatus
gst_system_clock_wait (GstClock *clock, GstClockEntry *entry)
{
- GstClockEntryStatus res = GST_CLOCK_ENTRY_OK;
+ GstClockEntryStatus res;
GstClockTime current, target;
+ gint64 diff;
current = gst_clock_get_time (clock);
- target = gst_system_clock_get_internal_time (clock) +
- GST_CLOCK_ENTRY_TIME (entry) - current;
+ diff = GST_CLOCK_ENTRY_TIME (entry) - current;
+
+ if (ABS (diff) > clock->max_diff) {
+ g_warning ("abnormal clock request diff: %lld > %lld", diff, clock->max_diff);
+ return GST_CLOCK_ENTRY_EARLY;
+ }
+
+ target = gst_system_clock_get_internal_time (clock) + diff;
GST_DEBUG (GST_CAT_CLOCK, "real_target %" G_GUINT64_FORMAT
" target %" G_GUINT64_FORMAT
g_mutex_lock (_gst_sysclock_mutex);
g_cond_timed_wait (_gst_sysclock_cond, _gst_sysclock_mutex, &tv);
g_mutex_unlock (_gst_sysclock_mutex);
+ res = entry->status;
}
else {
res = GST_CLOCK_ENTRY_EARLY;
return res;
}
+static void
+gst_system_clock_unlock (GstClock *clock, GstClockEntry *entry)
+{
+ g_mutex_lock (_gst_sysclock_mutex);
+ g_cond_broadcast (_gst_sysclock_cond);
+ g_mutex_unlock (_gst_sysclock_mutex);
+}