mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-25 19:21:06 +00:00
osxaudio: Avoid using private APIs on iOS
Turns out AudioConvertHostTimeToNanos and AudioGetCurrentHostTime are macOS-only APIs, which prevents apps using GStreamer on iOS from being accepted into App Store. This commit replaces those functions with a manual version of what they do - mach_absolute_time() for the current time, and data from mach_timebase_info() at the beginning to convert host timestamps to nanoseconds. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6899>
This commit is contained in:
parent
47afb4564b
commit
cdaf50de8f
3 changed files with 28 additions and 6 deletions
|
@ -65,6 +65,7 @@ gst_core_audio_init (GstCoreAudio * core_audio)
|
||||||
core_audio->disabled_mixing = FALSE;
|
core_audio->disabled_mixing = FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
mach_timebase_info (&core_audio->timebase);
|
||||||
g_mutex_init (&core_audio->timing_lock);
|
g_mutex_init (&core_audio->timing_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +109,21 @@ _audio_unit_property_listener (void *inRefCon, AudioUnit inUnit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GstClockTime
|
||||||
|
_current_time_ns (GstCoreAudio * core_audio)
|
||||||
|
{
|
||||||
|
guint64 mach_t = mach_absolute_time ();
|
||||||
|
return gst_util_uint64_scale (mach_t, core_audio->timebase.numer,
|
||||||
|
core_audio->timebase.denom);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstClockTime
|
||||||
|
_host_time_to_ns (GstCoreAudio * core_audio, uint64_t host_time)
|
||||||
|
{
|
||||||
|
return gst_util_uint64_scale (host_time, core_audio->timebase.numer,
|
||||||
|
core_audio->timebase.denom);
|
||||||
|
}
|
||||||
|
|
||||||
/**************************
|
/**************************
|
||||||
* Public API *
|
* Public API *
|
||||||
*************************/
|
*************************/
|
||||||
|
@ -214,7 +230,7 @@ gboolean
|
||||||
gst_core_audio_get_samples_and_latency (GstCoreAudio * core_audio,
|
gst_core_audio_get_samples_and_latency (GstCoreAudio * core_audio,
|
||||||
gdouble rate, guint * samples, gdouble * latency)
|
gdouble rate, guint * samples, gdouble * latency)
|
||||||
{
|
{
|
||||||
uint64_t now_ns = AudioConvertHostTimeToNanos (AudioGetCurrentHostTime ());
|
uint64_t now_ns = _current_time_ns (core_audio);
|
||||||
gboolean ret = gst_core_audio_get_samples_and_latency_impl (core_audio, rate,
|
gboolean ret = gst_core_audio_get_samples_and_latency_impl (core_audio, rate,
|
||||||
samples, latency);
|
samples, latency);
|
||||||
|
|
||||||
|
@ -224,8 +240,7 @@ gst_core_audio_get_samples_and_latency (GstCoreAudio * core_audio,
|
||||||
CORE_AUDIO_TIMING_LOCK (core_audio);
|
CORE_AUDIO_TIMING_LOCK (core_audio);
|
||||||
|
|
||||||
uint32_t samples_remain = 0;
|
uint32_t samples_remain = 0;
|
||||||
uint64_t anchor_ns =
|
uint64_t anchor_ns = core_audio->anchor_hosttime_ns;
|
||||||
AudioConvertHostTimeToNanos (core_audio->anchor_hosttime);
|
|
||||||
|
|
||||||
if (core_audio->is_src) {
|
if (core_audio->is_src) {
|
||||||
int64_t captured_ns =
|
int64_t captured_ns =
|
||||||
|
@ -292,14 +307,15 @@ gst_core_audio_update_timing (GstCoreAudio * core_audio,
|
||||||
kAudioTimeStampSampleHostTimeValid | kAudioTimeStampRateScalarValid;
|
kAudioTimeStampSampleHostTimeValid | kAudioTimeStampRateScalarValid;
|
||||||
|
|
||||||
if ((inTimeStamp->mFlags & target_flags) == target_flags) {
|
if ((inTimeStamp->mFlags & target_flags) == target_flags) {
|
||||||
core_audio->anchor_hosttime = inTimeStamp->mHostTime;
|
core_audio->anchor_hosttime_ns =
|
||||||
|
_host_time_to_ns (core_audio, inTimeStamp->mHostTime);
|
||||||
core_audio->anchor_pend_samples = inNumberFrames;
|
core_audio->anchor_pend_samples = inNumberFrames;
|
||||||
core_audio->rate_scalar = inTimeStamp->mRateScalar;
|
core_audio->rate_scalar = inTimeStamp->mRateScalar;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (core_audio,
|
GST_DEBUG_OBJECT (core_audio,
|
||||||
"anchor hosttime_ns %" G_GUINT64_FORMAT
|
"anchor hosttime_ns %" G_GUINT64_FORMAT
|
||||||
" scalar_rate %f anchor_pend_samples %u",
|
" scalar_rate %f anchor_pend_samples %u",
|
||||||
AudioConvertHostTimeToNanos (core_audio->anchor_hosttime),
|
core_audio->anchor_hosttime_ns,
|
||||||
core_audio->rate_scalar, core_audio->anchor_pend_samples);
|
core_audio->rate_scalar, core_audio->anchor_pend_samples);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#include <AudioUnit/AudioUnit.h>
|
#include <AudioUnit/AudioUnit.h>
|
||||||
|
#include <mach/mach_time.h>
|
||||||
#include "gstosxaudioelement.h"
|
#include "gstosxaudioelement.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,8 +112,9 @@ struct _GstCoreAudio
|
||||||
AudioDeviceIOProcID procID;
|
AudioDeviceIOProcID procID;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
mach_timebase_info_data_t timebase;
|
||||||
GMutex timing_lock;
|
GMutex timing_lock;
|
||||||
uint64_t anchor_hosttime;
|
uint64_t anchor_hosttime_ns;
|
||||||
uint32_t anchor_pend_samples;
|
uint32_t anchor_pend_samples;
|
||||||
float rate_scalar;
|
float rate_scalar;
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include "gstosxcoreaudio.h"
|
#include "gstosxcoreaudio.h"
|
||||||
#include <gst/audio/audio-channels.h>
|
#include <gst/audio/audio-channels.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
GMutex lock;
|
GMutex lock;
|
||||||
|
@ -64,3 +66,5 @@ OSStatus gst_core_audio_render_notify (GstCoreAudio * core_a
|
||||||
AudioChannelLabel gst_audio_channel_position_to_core_audio (GstAudioChannelPosition position, int channel);
|
AudioChannelLabel gst_audio_channel_position_to_core_audio (GstAudioChannelPosition position, int channel);
|
||||||
|
|
||||||
GstAudioChannelPosition gst_core_audio_channel_label_to_gst (AudioChannelLabel label, int channel, gboolean warn);
|
GstAudioChannelPosition gst_core_audio_channel_label_to_gst (AudioChannelLabel label, int channel, gboolean warn);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
Loading…
Reference in a new issue