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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7856>
This commit is contained in:
Piotr Brzeziński 2024-11-08 12:06:28 +01:00 committed by GStreamer Marge Bot
parent 212290baf0
commit 8f5caeb86d
2 changed files with 19 additions and 0 deletions

View File

@ -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))

View File

@ -121,6 +121,7 @@ struct _GstCoreAudio
float rate_scalar;
#ifdef HAVE_IOS
gdouble first_sample_time;
gboolean configure_session;
#endif
};