From 8f5caeb86d38aa66107ae83181b3eb1872be7875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Brzezi=C5=84ski?= Date: Fri, 8 Nov 2024 12:06:28 +0100 Subject: [PATCH] osxaudiosrc: Work around timestamps on iOS not starting from 0 On macOS, you always get your own 'timeline' for the AudioUnit session, so timestamps start from 0. On iOS however, AudioUnit seems to give you a 'shared' timeline so timestamps start at a later, non-0 point in time. Simply offsetting seems to do the trick. This was causing osxaudiosrc to not output any sound on iOS. Regressed in 2df9283d3f2ea06af5ebd6db03a6d545cac52f19 Part-of: --- .../sys/osxaudio/gstosxaudiosrc.c | 18 ++++++++++++++++++ .../sys/osxaudio/gstosxcoreaudio.h | 1 + 2 files changed, 19 insertions(+) diff --git a/subprojects/gst-plugins-good/sys/osxaudio/gstosxaudiosrc.c b/subprojects/gst-plugins-good/sys/osxaudio/gstosxaudiosrc.c index 1fc708b5a1..9615f10fb6 100644 --- a/subprojects/gst-plugins-good/sys/osxaudio/gstosxaudiosrc.c +++ b/subprojects/gst-plugins-good/sys/osxaudio/gstosxaudiosrc.c @@ -274,6 +274,13 @@ gst_osx_audio_src_change_state (GstElement * element, GstStateChange transition) GST_OBJECT_UNLOCK (osxsrc); break; } +#ifdef HAVE_IOS + case GST_STATE_CHANGE_PAUSED_TO_PLAYING: + ringbuffer = + GST_OSX_AUDIO_RING_BUFFER (GST_AUDIO_BASE_SRC (osxsrc)->ringbuffer); + ringbuffer->core_audio->first_sample_time = -1; + break; +#endif default: break; } @@ -436,6 +443,17 @@ gst_osx_audio_src_io_proc (GstOsxAudioRingBuffer * buf, remaining = buf->core_audio->recBufferList->mBuffers[0].mDataByteSize; sample_position = inTimeStamp->mSampleTime; +#ifdef HAVE_IOS + /* Timestamps don't always start from 0 on iOS, have to offset */ + if (buf->core_audio->first_sample_time == -1) { + GST_ERROR ("Setting first CoreAudio timestamp to %f", + inTimeStamp->mSampleTime); + buf->core_audio->first_sample_time = inTimeStamp->mSampleTime; + } + + sample_position -= buf->core_audio->first_sample_time; +#endif + while (remaining) { if (!gst_audio_ring_buffer_prepare_read (GST_AUDIO_RING_BUFFER (buf), &writeseg, &writeptr, &len)) diff --git a/subprojects/gst-plugins-good/sys/osxaudio/gstosxcoreaudio.h b/subprojects/gst-plugins-good/sys/osxaudio/gstosxcoreaudio.h index dae7d0ed7a..c38eb1bb46 100644 --- a/subprojects/gst-plugins-good/sys/osxaudio/gstosxcoreaudio.h +++ b/subprojects/gst-plugins-good/sys/osxaudio/gstosxcoreaudio.h @@ -121,6 +121,7 @@ struct _GstCoreAudio float rate_scalar; #ifdef HAVE_IOS + gdouble first_sample_time; gboolean configure_session; #endif };