gst_plugins_base/gst-libs/gst/audio/gstaudioclock.c
changeset 0 0e761a78d257
child 8 4a7fac7dd34a
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     1 /* GStreamer
       
     2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
       
     3  *                    2000 Wim Taymans <wtay@chello.be>
       
     4  *
       
     5  * audioclock.c: Clock for use by audio plugins
       
     6  *
       
     7  * This library is free software; you can redistribute it and/or
       
     8  * modify it under the terms of the GNU Library General Public
       
     9  * License as published by the Free Software Foundation; either
       
    10  * version 2 of the License, or (at your option) any later version.
       
    11  *
       
    12  * This library is distributed in the hope that it will be useful,
       
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    15  * Library General Public License for more details.
       
    16  *
       
    17  * You should have received a copy of the GNU Library General Public
       
    18  * License along with this library; if not, write to the
       
    19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    20  * Boston, MA 02111-1307, USA.
       
    21  */
       
    22 
       
    23 /**
       
    24  * SECTION:gstaudioclock
       
    25  * @short_description: Helper object for implementing audio clocks
       
    26  * @see_also: #GstBaseAudioSink, #GstSystemClock
       
    27  *
       
    28  * #GstAudioClock makes it easy for elements to implement a #GstClock, they
       
    29  * simply need to provide a function that returns the current clock time.
       
    30  *
       
    31  * This object is internally used to implement the clock in #GstBaseAudioSink.
       
    32  *
       
    33  * Last reviewed on 2006-09-27 (0.10.12)
       
    34  */
       
    35 
       
    36 #ifdef HAVE_CONFIG_H
       
    37 #include "config.h"
       
    38 #endif
       
    39 
       
    40 #include "gstaudioclock.h"
       
    41 
       
    42 static void gst_audio_clock_class_init (GstAudioClockClass * klass);
       
    43 static void gst_audio_clock_init (GstAudioClock * clock);
       
    44 
       
    45 static GstClockTime gst_audio_clock_get_internal_time (GstClock * clock);
       
    46 
       
    47 static GstSystemClockClass *parent_class = NULL;
       
    48 
       
    49 /* static guint gst_audio_clock_signals[LAST_SIGNAL] = { 0 }; */
       
    50 #ifdef __SYMBIAN32__
       
    51 EXPORT_C
       
    52 #endif
       
    53 
       
    54 
       
    55 GType
       
    56 gst_audio_clock_get_type (void)
       
    57 {
       
    58   static GType clock_type = 0;
       
    59 
       
    60   if (!clock_type) {
       
    61     static const GTypeInfo clock_info = {
       
    62       sizeof (GstAudioClockClass),
       
    63       NULL,
       
    64       NULL,
       
    65       (GClassInitFunc) gst_audio_clock_class_init,
       
    66       NULL,
       
    67       NULL,
       
    68       sizeof (GstAudioClock),
       
    69       4,
       
    70       (GInstanceInitFunc) gst_audio_clock_init,
       
    71       NULL
       
    72     };
       
    73 
       
    74     clock_type = g_type_register_static (GST_TYPE_SYSTEM_CLOCK, "GstAudioClock",
       
    75         &clock_info, 0);
       
    76   }
       
    77   return clock_type;
       
    78 }
       
    79 
       
    80 
       
    81 static void
       
    82 gst_audio_clock_class_init (GstAudioClockClass * klass)
       
    83 {
       
    84   GObjectClass *gobject_class;
       
    85   GstObjectClass *gstobject_class;
       
    86   GstClockClass *gstclock_class;
       
    87 
       
    88   gobject_class = (GObjectClass *) klass;
       
    89   gstobject_class = (GstObjectClass *) klass;
       
    90   gstclock_class = (GstClockClass *) klass;
       
    91 
       
    92   parent_class = g_type_class_peek_parent (klass);
       
    93 
       
    94   gstclock_class->get_internal_time = gst_audio_clock_get_internal_time;
       
    95 }
       
    96 
       
    97 static void
       
    98 gst_audio_clock_init (GstAudioClock * clock)
       
    99 {
       
   100   clock->last_time = 0;
       
   101   GST_OBJECT_FLAG_SET (clock, GST_CLOCK_FLAG_CAN_SET_MASTER);
       
   102 }
       
   103 
       
   104 /**
       
   105  * gst_audio_clock_new:
       
   106  * @name: the name of the clock
       
   107  * @func: a function
       
   108  * @user_data: user data
       
   109  *
       
   110  * Create a new #GstAudioClock instance. Whenever the clock time should be
       
   111  * calculated it will call @func with @user_data. When @func returns
       
   112  * #GST_CLOCK_TIME_NONE, the clock will return the last reported time.
       
   113  *
       
   114  * Returns: a new #GstAudioClock casted to a #GstClock.
       
   115  */
       
   116 #ifdef __SYMBIAN32__
       
   117 EXPORT_C
       
   118 #endif
       
   119 
       
   120 GstClock *
       
   121 gst_audio_clock_new (gchar * name, GstAudioClockGetTimeFunc func,
       
   122     gpointer user_data)
       
   123 {
       
   124   GstAudioClock *aclock =
       
   125       GST_AUDIO_CLOCK (g_object_new (GST_TYPE_AUDIO_CLOCK, "name", name, NULL));
       
   126 
       
   127   aclock->func = func;
       
   128   aclock->user_data = user_data;
       
   129 
       
   130   return (GstClock *) aclock;
       
   131 }
       
   132 
       
   133 static GstClockTime
       
   134 gst_audio_clock_get_internal_time (GstClock * clock)
       
   135 {
       
   136   GstAudioClock *aclock = GST_AUDIO_CLOCK (clock);
       
   137   GstClockTime result;
       
   138 
       
   139   result = aclock->func (clock, aclock->user_data);
       
   140   if (result == GST_CLOCK_TIME_NONE)
       
   141     result = aclock->last_time;
       
   142   else
       
   143     aclock->last_time = result;
       
   144 
       
   145   return result;
       
   146 }