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., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, 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)
86 GST_OBJECT_FLAG_SET (clock, GST_CLOCK_FLAG_CAN_SET_MASTER);
91 * @name: the name of the clock
93 * Create a new #Gst1394Clock instance.
95 * Returns: a new #Gst1394Clock
98 gst_1394_clock_new (const gchar * name)
100 Gst1394Clock *_1394clock =
101 GST_1394_CLOCK (g_object_new (GST_TYPE_1394_CLOCK, "name", name, NULL));
107 gst_1394_clock_get_internal_time (GstClock * clock)
109 Gst1394Clock *_1394clock;
114 _1394clock = GST_1394_CLOCK_CAST (clock);
116 if (_1394clock->handle != NULL) {
117 raw1394_read_cycle_timer (_1394clock->handle, &cycle_timer, &local_time);
119 if (cycle_timer < _1394clock->cycle_timer_lo) {
120 GST_LOG_OBJECT (clock, "overflow %u to %u",
121 _1394clock->cycle_timer_lo, cycle_timer);
123 _1394clock->cycle_timer_hi++;
125 _1394clock->cycle_timer_lo = cycle_timer;
127 /* get the seconds from the cycleSeconds counter */
128 result = (((((guint64) _1394clock->cycle_timer_hi) << 32) |
129 cycle_timer) >> 25) * GST_SECOND;
130 /* add the microseconds from the cycleCount counter */
131 result += (((cycle_timer >> 12) & 0x1fff) * 125) * GST_USECOND;
133 GST_LOG_OBJECT (clock, "result %" GST_TIME_FORMAT, GST_TIME_ARGS (result));
135 result = GST_CLOCK_TIME_NONE;
142 gst_1394_clock_set_handle (Gst1394Clock * clock, raw1394handle_t handle)
144 clock->handle = handle;
145 clock->cycle_timer_lo = 0;
146 clock->cycle_timer_hi = 0;
150 gst_1394_clock_unset_handle (Gst1394Clock * clock)
152 clock->handle = NULL;