mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-03 04:52:28 +00:00
osxaudio: Don't set the format on an initialized AudioUnit
We need to initialize the AudioUnit early to be able to probe the underlying device, but according to the AudioUnitInitialize() and AudioUnitUninitialize() documentation, format changes should be done while the AudioUnit is uninitialized. So we explicitly uninitialize the AudioUnit during a format change and reinitialize it when we're done.
This commit is contained in:
parent
22f6d62796
commit
691ecebe22
4 changed files with 47 additions and 3 deletions
|
@ -168,7 +168,8 @@ gst_core_audio_open (GstCoreAudio * core_audio)
|
|||
"listener for AudioUnit: %d", (int) status);
|
||||
}
|
||||
|
||||
/* Initialize the AudioUnit */
|
||||
/* Initialize the AudioUnit. We keep the audio unit initialized early so that
|
||||
* we can probe the underlying device. */
|
||||
status = AudioUnitInitialize (core_audio->audiounit);
|
||||
if (status) {
|
||||
GST_ERROR_OBJECT (core_audio, "Failed to initialize AudioUnit: %d",
|
||||
|
|
|
@ -238,6 +238,7 @@ _core_audio_set_property (GstCoreAudio * core_audio, AudioUnitPropertyID inID,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/* The AudioUnit must be uninitialized before calling this */
|
||||
gboolean
|
||||
gst_core_audio_set_channel_layout (GstCoreAudio * core_audio,
|
||||
gint channels, GstCaps * caps)
|
||||
|
@ -297,6 +298,7 @@ gst_core_audio_set_channel_layout (GstCoreAudio * core_audio,
|
|||
return ret;
|
||||
}
|
||||
|
||||
/* The AudioUnit must be uninitialized before calling this */
|
||||
gboolean
|
||||
gst_core_audio_set_format (GstCoreAudio * core_audio,
|
||||
AudioStreamBasicDescription format)
|
||||
|
|
|
@ -1123,6 +1123,15 @@ gst_core_audio_initialize_impl (GstCoreAudio * core_audio,
|
|||
gboolean is_passthrough, guint32 * frame_size)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
OSStatus status;
|
||||
|
||||
/* Uninitialize the AudioUnit before changing formats */
|
||||
status = AudioUnitUninitialize (core_audio->audiounit);
|
||||
if (status) {
|
||||
GST_ERROR_OBJECT (core_audio, "Failed to uninitialize AudioUnit: %d",
|
||||
(int) status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
core_audio->is_passthrough = is_passthrough;
|
||||
if (is_passthrough) {
|
||||
|
@ -1157,9 +1166,18 @@ gst_core_audio_initialize_impl (GstCoreAudio * core_audio,
|
|||
ret = TRUE;
|
||||
|
||||
done:
|
||||
/* Format changed, initialise the AudioUnit again */
|
||||
status = AudioUnitInitialize (core_audio->audiounit);
|
||||
if (status) {
|
||||
GST_ERROR_OBJECT (core_audio, "Failed to initialize AudioUnit: %d",
|
||||
(int) status);
|
||||
ret = FALSE;
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
GST_DEBUG_OBJECT (core_audio, "osxbuf ring buffer acquired");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -84,10 +84,22 @@ gst_core_audio_initialize_impl (GstCoreAudio * core_audio,
|
|||
AudioStreamBasicDescription format, GstCaps * caps,
|
||||
gboolean is_passthrough, guint32 * frame_size)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
OSStatus status;
|
||||
|
||||
/* Uninitialize the AudioUnit before changing formats */
|
||||
status = AudioUnitUninitialize (core_audio->audiounit);
|
||||
if (status) {
|
||||
GST_ERROR_OBJECT (core_audio, "Failed to uninitialize AudioUnit: %d",
|
||||
(int) status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
core_audio->is_passthrough = is_passthrough;
|
||||
core_audio->stream_idx = 0;
|
||||
|
||||
if (!gst_core_audio_set_format (core_audio, format))
|
||||
return FALSE;
|
||||
goto done;
|
||||
|
||||
/* FIXME: Use kAudioSessionProperty_CurrentHardwareSampleRate and
|
||||
* kAudioSessionProperty_CurrentHardwareIOBufferDuration with property
|
||||
|
@ -96,7 +108,18 @@ gst_core_audio_initialize_impl (GstCoreAudio * core_audio,
|
|||
*frame_size = 4196;
|
||||
|
||||
GST_DEBUG_OBJECT (core_audio, "osxbuf ring buffer acquired");
|
||||
return TRUE;
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
/* Format changed, initialise the AudioUnit again */
|
||||
status = AudioUnitInitialize (core_audio->audiounit);
|
||||
if (status) {
|
||||
GST_ERROR_OBJECT (core_audio, "Failed to initialize AudioUnit: %d",
|
||||
(int) status);
|
||||
ret = FALSE;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
Loading…
Reference in a new issue