gst_plugins_base/gst-libs/gst/audio/gstaudioclock.c
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
    36 #ifdef HAVE_CONFIG_H
    36 #ifdef HAVE_CONFIG_H
    37 #include "config.h"
    37 #include "config.h"
    38 #endif
    38 #endif
    39 
    39 
    40 #include "gstaudioclock.h"
    40 #include "gstaudioclock.h"
    41 
       
    42 GST_DEBUG_CATEGORY_STATIC (gst_audio_clock_debug);
       
    43 #define GST_CAT_DEFAULT gst_audio_clock_debug
       
    44 
    41 
    45 static void gst_audio_clock_class_init (GstAudioClockClass * klass);
    42 static void gst_audio_clock_class_init (GstAudioClockClass * klass);
    46 static void gst_audio_clock_init (GstAudioClock * clock);
    43 static void gst_audio_clock_init (GstAudioClock * clock);
    47 
    44 
    48 static GstClockTime gst_audio_clock_get_internal_time (GstClock * clock);
    45 static GstClockTime gst_audio_clock_get_internal_time (GstClock * clock);
    93   gstclock_class = (GstClockClass *) klass;
    90   gstclock_class = (GstClockClass *) klass;
    94 
    91 
    95   parent_class = g_type_class_peek_parent (klass);
    92   parent_class = g_type_class_peek_parent (klass);
    96 
    93 
    97   gstclock_class->get_internal_time = gst_audio_clock_get_internal_time;
    94   gstclock_class->get_internal_time = gst_audio_clock_get_internal_time;
    98 
       
    99   GST_DEBUG_CATEGORY_INIT (gst_audio_clock_debug, "audioclock", 0,
       
   100       "audioclock");
       
   101 }
    95 }
   102 
    96 
   103 static void
    97 static void
   104 gst_audio_clock_init (GstAudioClock * clock)
    98 gst_audio_clock_init (GstAudioClock * clock)
   105 {
    99 {
   106   clock->last_time = 0;
   100   clock->last_time = 0;
   107   clock->abidata.ABI.time_offset = 0;
       
   108   GST_OBJECT_FLAG_SET (clock, GST_CLOCK_FLAG_CAN_SET_MASTER);
   101   GST_OBJECT_FLAG_SET (clock, GST_CLOCK_FLAG_CAN_SET_MASTER);
   109 }
   102 }
   110 
   103 
   111 /**
   104 /**
   112  * gst_audio_clock_new:
   105  * gst_audio_clock_new:
   123 #ifdef __SYMBIAN32__
   116 #ifdef __SYMBIAN32__
   124 EXPORT_C
   117 EXPORT_C
   125 #endif
   118 #endif
   126 
   119 
   127 GstClock *
   120 GstClock *
   128 gst_audio_clock_new (const gchar * name, GstAudioClockGetTimeFunc func,
   121 gst_audio_clock_new (gchar * name, GstAudioClockGetTimeFunc func,
   129     gpointer user_data)
   122     gpointer user_data)
   130 {
   123 {
   131   GstAudioClock *aclock =
   124   GstAudioClock *aclock =
   132       GST_AUDIO_CLOCK (g_object_new (GST_TYPE_AUDIO_CLOCK, "name", name, NULL));
   125       GST_AUDIO_CLOCK (g_object_new (GST_TYPE_AUDIO_CLOCK, "name", name, NULL));
   133 
   126 
   135   aclock->user_data = user_data;
   128   aclock->user_data = user_data;
   136 
   129 
   137   return (GstClock *) aclock;
   130   return (GstClock *) aclock;
   138 }
   131 }
   139 
   132 
   140 /**
       
   141  * gst_audio_clock_reset:
       
   142  * @clock: a #GstAudioClock
       
   143  * @time: a #GstClockTime
       
   144  *
       
   145  * Inform @clock that future calls to #GstAudioClockGetTimeFunc will return values
       
   146  * starting from @time. The clock will update an internal offset to make sure that
       
   147  * future calls to internal_time will return an increasing result as required by
       
   148  * the #GstClock object.
       
   149  */
       
   150 #ifdef __SYMBIAN32__
       
   151 EXPORT_C
       
   152 #endif
       
   153 
       
   154 void
       
   155 gst_audio_clock_reset (GstAudioClock * clock, GstClockTime time)
       
   156 {
       
   157   GstClockTimeDiff time_offset;
       
   158 
       
   159   if (clock->last_time >= time)
       
   160     time_offset = clock->last_time - time;
       
   161   else
       
   162     time_offset = -(time - clock->last_time);
       
   163 
       
   164   clock->abidata.ABI.time_offset = time_offset;
       
   165 
       
   166   GST_DEBUG_OBJECT (clock,
       
   167       "reset clock to %" GST_TIME_FORMAT ", offset %" GST_TIME_FORMAT,
       
   168       GST_TIME_ARGS (time), GST_TIME_ARGS (time_offset));
       
   169 }
       
   170 
       
   171 static GstClockTime
   133 static GstClockTime
   172 gst_audio_clock_get_internal_time (GstClock * clock)
   134 gst_audio_clock_get_internal_time (GstClock * clock)
   173 {
   135 {
   174   GstAudioClock *aclock;
   136   GstAudioClock *aclock = GST_AUDIO_CLOCK (clock);
   175   GstClockTime result;
   137   GstClockTime result;
   176 
   138 
   177   aclock = GST_AUDIO_CLOCK_CAST (clock);
       
   178 
       
   179   result = aclock->func (clock, aclock->user_data);
   139   result = aclock->func (clock, aclock->user_data);
   180   if (result == GST_CLOCK_TIME_NONE) {
   140   if (result == GST_CLOCK_TIME_NONE)
   181     result = aclock->last_time;
   141     result = aclock->last_time;
   182   } else {
   142   else
   183     result += aclock->abidata.ABI.time_offset;
   143     aclock->last_time = result;
   184     /* clock must be increasing */
       
   185     if (aclock->last_time < result)
       
   186       aclock->last_time = result;
       
   187     else
       
   188       result = aclock->last_time;
       
   189   }
       
   190 
       
   191   GST_DEBUG_OBJECT (clock,
       
   192       "result %" GST_TIME_FORMAT ", last_time %" GST_TIME_FORMAT,
       
   193       GST_TIME_ARGS (result), GST_TIME_ARGS (aclock->last_time));
       
   194 
   144 
   195   return result;
   145   return result;
   196 }
   146 }
   197 
       
   198 /**
       
   199  * gst_audio_clock_get_time:
       
   200  * @clock: a #GstAudioClock
       
   201  *
       
   202  * Report the time as returned by the #GstAudioClockGetTimeFunc without applying
       
   203  * any offsets. 
       
   204  *
       
   205  * Returns: the time as reported by the time function of the audio clock
       
   206  *
       
   207  * Since: 0.10.23
       
   208  */
       
   209 #ifdef __SYMBIAN32__
       
   210 EXPORT_C
       
   211 #endif
       
   212 
       
   213 GstClockTime
       
   214 gst_audio_clock_get_time (GstClock * clock)
       
   215 {
       
   216   GstAudioClock *aclock;
       
   217   GstClockTime result;
       
   218 
       
   219   aclock = GST_AUDIO_CLOCK_CAST (clock);
       
   220 
       
   221   result = aclock->func (clock, aclock->user_data);
       
   222   if (result == GST_CLOCK_TIME_NONE) {
       
   223     result = aclock->last_time - aclock->abidata.ABI.time_offset;
       
   224   }
       
   225 
       
   226   return result;
       
   227 }
       
   228 
       
   229 /**
       
   230  * gst_audio_clock_adjust:
       
   231  * @clock: a #GstAudioClock
       
   232  * @time: a #GstClockTime
       
   233  *
       
   234  * Adjust @time with the internal offset of the audio clock.
       
   235  *
       
   236  * Returns: @time adjusted with the internal offset.
       
   237  *
       
   238  * Since: 0.10.23
       
   239  */
       
   240 #ifdef __SYMBIAN32__
       
   241 EXPORT_C
       
   242 #endif
       
   243 
       
   244 GstClockTime
       
   245 gst_audio_clock_adjust (GstClock * clock, GstClockTime time)
       
   246 {
       
   247   GstAudioClock *aclock;
       
   248   GstClockTime result;
       
   249 
       
   250   aclock = GST_AUDIO_CLOCK_CAST (clock);
       
   251 
       
   252   result = time + aclock->abidata.ABI.time_offset;
       
   253 
       
   254   return result;
       
   255 }