]> git.sesse.net Git - vlc/commitdiff
aout_TimeReport: feedback timing from audio output to audio decoder
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 6 Aug 2011 20:50:27 +0000 (23:50 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 6 Aug 2011 20:50:27 +0000 (23:50 +0300)
Currently, this is used to trigger resampling in the audio "input"
(i.e. filters) as before.

include/vlc_aout.h
src/audio_output/dec.c
src/libvlccore.sym

index f5eaafb7f676bd8e368f8c7b50751ef1a3b1d0ba..b3d49542ba0993f4f87852bfd26e8873ef605bcb 100644 (file)
@@ -244,6 +244,8 @@ VLC_API void aout_VolumeSoftInit( audio_output_t * );
 VLC_API void aout_VolumeHardInit( audio_output_t *, aout_volume_cb );
 VLC_API void aout_VolumeHardSet( audio_output_t *, float, bool );
 
+VLC_API void aout_TimeReport(audio_output_t *, mtime_t);
+
 VLC_API int aout_ChannelsRestart( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * );
 
 /* */
index 0f3addafc796b4e15bfcbb3bc102a9e8f78e153f..d22807d25447a57892cac72633fe5fa22220e59e 100644 (file)
@@ -311,3 +311,46 @@ bool aout_DecIsEmpty (audio_output_t *aout)
     aout_unlock (aout);
     return end_date == VLC_TS_INVALID || end_date <= mdate();
 }
+
+/**
+ * Notifies the audio input of the drift from the requested audio
+ * playback timestamp (@ref block_t.i_pts) to the anticipated playback time
+ * as reported by the audio output hardware.
+ * Depending on the drift amplitude, the input core may ignore the drift
+ * trigger upsampling or downsampling, or even discard samples.
+ * Future VLC versions may instead adjust the input decoding speed.
+ *
+ * The audio output plugin is responsible for estimating the ideal current
+ * playback time defined as follows:
+ *  ideal time = buffer timestamp - (output latency + pending buffer duration)
+ *
+ * Practically, this is the PTS (block_t.i_pts) of the current buffer minus
+ * the latency reported by the output programming interface.
+ * Computing the estimated drift directly would probably be more intuitive.
+ * However the use of an absolute time value does not introduce extra
+ * measurement errors due to the CPU scheduling jitter and clock resolution.
+ * Furthermore, the ideal while it is an abstract value, is easy for most
+ * audio output plugins to compute.
+ * The following definition is equivalent but depends on the clock time:
+ *  ideal time = real time + drift
+
+ * @note If aout_LatencyReport() is never called, the core will assume that
+ * there is no drift.
+ *
+ * @param ideal estimated ideal time as defined above.
+ */
+void aout_TimeReport (audio_output_t *aout, mtime_t ideal)
+{
+    mtime_t delta = mdate() - ideal /* = -drift */;
+
+    aout_assert_locked (aout);
+    if (delta < -AOUT_MAX_PTS_ADVANCE || +AOUT_MAX_PTS_DELAY < delta)
+    {
+        aout_owner_t *owner = aout_owner (aout);
+
+        msg_Warn (aout, "not synchronized (%"PRId64" us), resampling",
+                  delta);
+        if (date_Get (&owner->sync.date) != VLC_TS_INVALID)
+            date_Move (&owner->sync.date, delta);
+    }
+}
index 9f6a0ff121670c185de2e463c20fa8cb4d143d31..f6216c945ffd66d81438a1610de87421a9ada5d7 100644 (file)
@@ -29,6 +29,7 @@ aout_VolumeUp
 aout_ToggleMute
 aout_IsMuted
 aout_SetMute
+aout_TimeReport
 aout_VolumeNoneInit
 aout_VolumeSoftInit
 aout_VolumeHardInit