2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * Copyright (C) 2009 David Schleef <ds@schleef.org>
6 * gst1394clock.c: Clock for use by IEEE 1394 plugins
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
28 #include "gst1394clock.h"
30 GST_DEBUG_CATEGORY_STATIC (gst_1394_clock_debug);
31 #define GST_CAT_DEFAULT gst_1394_clock_debug
33 static void gst_1394_clock_class_init (Gst1394ClockClass * klass);
34 static void gst_1394_clock_init (Gst1394Clock * clock);
36 static GstClockTime gst_1394_clock_get_internal_time (GstClock * clock);
38 static GstSystemClockClass *parent_class = NULL;
40 /* static guint gst_1394_clock_signals[LAST_SIGNAL] = { 0 }; */
43 gst_1394_clock_get_type (void)
45 static GType clock_type = 0;
48 static const GTypeInfo clock_info = {
49 sizeof (Gst1394ClockClass),
52 (GClassInitFunc) gst_1394_clock_class_init,
55 sizeof (Gst1394Clock),
57 (GInstanceInitFunc) gst_1394_clock_init,
61 clock_type = g_type_register_static (GST_TYPE_SYSTEM_CLOCK, "Gst1394Clock",
69 gst_1394_clock_class_init (Gst1394ClockClass * klass)
71 GstClockClass *gstclock_class;
73 gstclock_class = (GstClockClass *) klass;
75 parent_class = g_type_class_peek_parent (klass);
77 gstclock_class->get_internal_time = gst_1394_clock_get_internal_time;
79 GST_DEBUG_CATEGORY_INIT (gst_1394_clock_debug, "1394clock", 0, "1394clock");
83 gst_1394_clock_init (Gst1394Clock * clock)
85 GST_OBJECT_FLAG_SET (clock, GST_CLOCK_FLAG_CAN_SET_MASTER);
90 * @name: the name of the clock
92 * Create a new #Gst1394Clock instance.
94 * Returns: a new #Gst1394Clock
97 gst_1394_clock_new (const gchar * name)
99 Gst1394Clock *_1394clock =
100 GST_1394_CLOCK (g_object_new (GST_TYPE_1394_CLOCK, "name", name,
101 "clock-type", GST_CLOCK_TYPE_OTHER, NULL));
103 /* Clear floating flag */
104 gst_object_ref_sink (_1394clock);
110 gst_1394_clock_get_internal_time (GstClock * clock)
112 Gst1394Clock *_1394clock;
117 _1394clock = GST_1394_CLOCK_CAST (clock);
119 if (_1394clock->handle != NULL) {
120 GST_OBJECT_LOCK (clock);
121 raw1394_read_cycle_timer (_1394clock->handle, &cycle_timer, &local_time);
123 if (cycle_timer < _1394clock->cycle_timer_lo) {
124 GST_LOG_OBJECT (clock, "overflow %u to %u",
125 _1394clock->cycle_timer_lo, cycle_timer);
127 _1394clock->cycle_timer_hi++;
129 _1394clock->cycle_timer_lo = cycle_timer;
131 /* get the seconds from the cycleSeconds counter */
132 result = (((((guint64) _1394clock->cycle_timer_hi) << 32) |
133 cycle_timer) >> 25) * GST_SECOND;
134 /* add the microseconds from the cycleCount counter */
135 result += (((cycle_timer >> 12) & 0x1fff) * 125) * GST_USECOND;
137 GST_LOG_OBJECT (clock, "result %" GST_TIME_FORMAT, GST_TIME_ARGS (result));
138 GST_OBJECT_UNLOCK (clock);
140 result = GST_CLOCK_TIME_NONE;
147 gst_1394_clock_set_handle (Gst1394Clock * clock, raw1394handle_t handle)
149 clock->handle = handle;
150 clock->cycle_timer_lo = 0;
151 clock->cycle_timer_hi = 0;
155 gst_1394_clock_unset_handle (Gst1394Clock * clock)
157 clock->handle = NULL;