[vlc-commits] audiounit_ios: remove forward declaration
Thomas Guillem
git at videolan.org
Fri Feb 24 11:41:11 CET 2017
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Feb 24 09:47:23 2017 +0100| [f2df20da38c702b4417df65e07777cae0377f1a6] | committer: Thomas Guillem
audiounit_ios: remove forward declaration
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f2df20da38c702b4417df65e07777cae0377f1a6
---
modules/audio_output/audiounit_ios.m | 362 +++++++++++++++++------------------
1 file changed, 176 insertions(+), 186 deletions(-)
diff --git a/modules/audio_output/audiounit_ios.m b/modules/audio_output/audiounit_ios.m
index 22d8c1b..1b44b41 100644
--- a/modules/audio_output/audiounit_ios.m
+++ b/modules/audio_output/audiounit_ios.m
@@ -40,6 +40,23 @@
#import "TPCircularBuffer.h"
#pragma mark -
+#pragma mark local prototypes & module descriptor
+
+static int Open (vlc_object_t *);
+static void Close (vlc_object_t *);
+
+vlc_module_begin ()
+ set_shortname("audiounit_ios")
+ set_description("AudioUnit output for iOS")
+ set_capability("audio output", 101)
+ set_category(CAT_AUDIO)
+ set_subcategory(SUBCAT_AUDIO_AOUT)
+ set_callbacks(Open, Close)
+vlc_module_end ()
+
+#pragma mark -
+
+#pragma mark -
#pragma mark private declarations
#define STREAM_FORMAT_MSG(pre, sfm) \
@@ -74,93 +91,156 @@ struct aout_sys_t
};
#pragma mark -
-#pragma mark local prototypes & module descriptor
+#pragma mark actual playback
-static int Open (vlc_object_t *);
-static void Close (vlc_object_t *);
-static int Start (audio_output_t *, audio_sample_format_t *);
-static int StartAnalog (audio_output_t *, audio_sample_format_t *);
-static void Stop (audio_output_t *);
+static void Play (audio_output_t * p_aout, block_t * p_block)
+{
+ struct aout_sys_t *p_sys = p_aout->sys;
-static void Play (audio_output_t *, block_t *);
-static void Pause (audio_output_t *, bool, mtime_t);
-static int MuteSet (audio_output_t *aout, bool mute);
-static void Flush (audio_output_t *, bool);
-static int TimeGet (audio_output_t *, mtime_t *);
-static OSStatus RenderCallback (vlc_object_t *, AudioUnitRenderActionFlags *, const AudioTimeStamp *,
- UInt32 , UInt32, AudioBufferList *);
+ if (p_block->i_nb_samples > 0) {
+ /* move data to buffer */
+ if (unlikely(!TPCircularBufferProduceBytes(&p_sys->circular_buffer, p_block->p_buffer, p_block->i_buffer)))
+ msg_Warn(p_aout, "Audio buffer was dropped");
-vlc_module_begin ()
- set_shortname("audiounit_ios")
- set_description("AudioUnit output for iOS")
- set_capability("audio output", 101)
- set_category(CAT_AUDIO)
- set_subcategory(SUBCAT_AUDIO_AOUT)
- set_callbacks(Open, Close)
-vlc_module_end ()
+ if (!p_sys->i_bytes_per_sample)
+ p_sys->i_bytes_per_sample = p_block->i_buffer / p_block->i_nb_samples;
+ }
-#pragma mark -
-#pragma mark initialization
+ block_Release(p_block);
+}
-static int Open(vlc_object_t *obj)
+static void Pause (audio_output_t *p_aout, bool pause, mtime_t date)
{
- audio_output_t *aout = (audio_output_t *)obj;
- aout_sys_t *sys = malloc(sizeof (*sys));
+ struct aout_sys_t * p_sys = p_aout->sys;
+ VLC_UNUSED(date);
- if (unlikely(sys == NULL))
- return VLC_ENOMEM;
+ vlc_mutex_lock(&p_sys->lock);
+ p_sys->b_paused = pause;
+ vlc_mutex_unlock(&p_sys->lock);
- vlc_mutex_init(&sys->lock);
- vlc_cond_init(&sys->cond);
- sys->b_paused = false;
+ if (p_sys->au_unit == NULL) {
+ return;
+ }
- aout->sys = sys;
- aout->start = Start;
- aout->stop = Stop;
+ /* we need to start / stop the audio unit here because otherwise
+ * the OS won't believe us that we stopped the audio output
+ * so in case of an interruption, our unit would be permanently
+ * silenced.
+ * in case of multi-tasking, the multi-tasking view would still
+ * show a playing state despite we are paused, same for lock screen */
+ if (pause) {
+ AudioOutputUnitStop(p_sys->au_unit);
+ } else {
+ AudioOutputUnitStart(p_sys->au_unit);
+
+ [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
+ [[AVAudioSession sharedInstance] setMode:AVAudioSessionModeMoviePlayback error:nil];
+ }
+
+ [[AVAudioSession sharedInstance] setActive:!pause error:nil];
+}
+
+static int MuteSet(audio_output_t *p_aout, bool mute)
+{
+ struct aout_sys_t * p_sys = p_aout->sys;
+
+ if (p_sys != NULL && p_sys->au_unit != NULL) {
+ msg_Dbg(p_aout, "audio output mute set to %d", mute?1:0);
+ Pause(p_aout, mute, 0);
+ }
return VLC_SUCCESS;
}
-static void Close(vlc_object_t *obj)
+static void Flush(audio_output_t *p_aout, bool wait)
{
- audio_output_t *aout = (audio_output_t *)obj;
- aout_sys_t *sys = aout->sys;
+ struct aout_sys_t *p_sys = p_aout->sys;
- vlc_mutex_destroy(&sys->lock);
- vlc_cond_destroy(&sys->cond);
+ int32_t availableBytes;
+ vlc_mutex_lock(&p_sys->lock);
+ TPCircularBufferTail(&p_sys->circular_buffer, &availableBytes);
- free(sys);
+ if (wait) {
+ while (availableBytes > 0) {
+ vlc_cond_wait(&p_sys->cond, &p_sys->lock);
+ TPCircularBufferTail(&p_sys->circular_buffer, &availableBytes);
+ }
+ } else {
+ /* flush circular buffer if data is left */
+ if (availableBytes > 0)
+ TPCircularBufferClear(&p_aout->sys->circular_buffer);
+ }
+
+ vlc_mutex_unlock(&p_sys->lock);
}
-static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
+static int TimeGet(audio_output_t *p_aout, mtime_t *delay)
{
- struct aout_sys_t *p_sys = NULL;
+ struct aout_sys_t * p_sys = p_aout->sys;
- if (aout_FormatNbChannels(fmt) == 0)
- return VLC_EGENERIC;
+ if (!p_sys->i_bytes_per_sample)
+ return -1;
- p_sys = p_aout->sys;
- p_sys->au_unit = NULL;
- p_sys->i_bytes_per_sample = 0;
+ int32_t availableBytes;
+ TPCircularBufferTail(&p_sys->circular_buffer, &availableBytes);
- aout_FormatPrint(p_aout, "VLC is looking for:", fmt);
+ *delay = (availableBytes / p_sys->i_bytes_per_sample) * CLOCK_FREQ / p_sys->i_rate;
- if (StartAnalog(p_aout, fmt)) {
- msg_Dbg(p_aout, "analog AudioUnit output successfully opened");
- p_aout->play = Play;
- p_aout->flush = Flush;
- p_aout->mute_set = MuteSet;
- p_aout->time_get = TimeGet;
- p_aout->pause = Pause;
+ return 0;
+}
- return VLC_SUCCESS;
+/*****************************************************************************
+ * RenderCallback: This function is called everytime the AudioUnit wants
+ * us to provide some more audio data.
+ * Don't print anything during normal playback, calling blocking function from
+ * this callback is not allowed.
+ *****************************************************************************/
+static OSStatus RenderCallback(vlc_object_t *p_obj,
+ AudioUnitRenderActionFlags *ioActionFlags,
+ const AudioTimeStamp *inTimeStamp,
+ UInt32 inBusNumber,
+ UInt32 inNumberFrames,
+ AudioBufferList *ioData) {
+ VLC_UNUSED(ioActionFlags);
+ VLC_UNUSED(inTimeStamp);
+ VLC_UNUSED(inBusNumber);
+ VLC_UNUSED(inNumberFrames);
+
+ audio_output_t * p_aout = (audio_output_t *)p_obj;
+ struct aout_sys_t * p_sys = p_aout->sys;
+
+ int bytesRequested = ioData->mBuffers[0].mDataByteSize;
+ Float32 *targetBuffer = (Float32*)ioData->mBuffers[0].mData;
+
+ vlc_mutex_lock(&p_sys->lock);
+ /* Pull audio from buffer */
+ int32_t availableBytes;
+ Float32 *buffer = TPCircularBufferTail(&p_sys->circular_buffer, &availableBytes);
+ if (unlikely(bytesRequested == 0)) /* cannot be negative */
+ return noErr;
+
+ /* check if we have enough data */
+ if (!availableBytes || p_sys->b_paused) {
+ /* return an empty buffer so silence is played until we have data */
+ memset(targetBuffer, 0, bytesRequested);
+ } else {
+ int32_t bytesToCopy = __MIN(bytesRequested, availableBytes);
+
+ if (likely(bytesToCopy > 0)) {
+ memcpy(targetBuffer, buffer, bytesToCopy);
+ TPCircularBufferConsume(&p_sys->circular_buffer, bytesToCopy);
+ ioData->mBuffers[0].mDataByteSize = bytesToCopy;
+ }
}
- /* If we reach this, this aout has failed */
- msg_Err(p_aout, "opening AudioUnit output failed");
- return VLC_EGENERIC;
+ vlc_cond_signal(&p_sys->cond);
+ vlc_mutex_unlock(&p_sys->lock);
+
+ return noErr;
}
+#pragma mark initialization
+
/*
* StartAnalog: open and setup a HAL AudioUnit to do PCM audio output
*/
@@ -309,151 +389,61 @@ static void Stop(audio_output_t *p_aout)
TPCircularBufferCleanup(&p_sys->circular_buffer);
}
-#pragma mark -
-#pragma mark actual playback
-
-static void Play (audio_output_t * p_aout, block_t * p_block)
-{
- struct aout_sys_t *p_sys = p_aout->sys;
-
- if (p_block->i_nb_samples > 0) {
- /* move data to buffer */
- if (unlikely(!TPCircularBufferProduceBytes(&p_sys->circular_buffer, p_block->p_buffer, p_block->i_buffer)))
- msg_Warn(p_aout, "Audio buffer was dropped");
-
- if (!p_sys->i_bytes_per_sample)
- p_sys->i_bytes_per_sample = p_block->i_buffer / p_block->i_nb_samples;
- }
-
- block_Release(p_block);
-}
-
-static void Pause (audio_output_t *p_aout, bool pause, mtime_t date)
+static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
{
- struct aout_sys_t * p_sys = p_aout->sys;
- VLC_UNUSED(date);
-
- vlc_mutex_lock(&p_sys->lock);
- p_sys->b_paused = pause;
- vlc_mutex_unlock(&p_sys->lock);
-
- if (p_sys->au_unit == NULL) {
- return;
- }
+ struct aout_sys_t *p_sys = NULL;
- /* we need to start / stop the audio unit here because otherwise
- * the OS won't believe us that we stopped the audio output
- * so in case of an interruption, our unit would be permanently
- * silenced.
- * in case of multi-tasking, the multi-tasking view would still
- * show a playing state despite we are paused, same for lock screen */
- if (pause) {
- AudioOutputUnitStop(p_sys->au_unit);
- } else {
- AudioOutputUnitStart(p_sys->au_unit);
+ if (aout_FormatNbChannels(fmt) == 0)
+ return VLC_EGENERIC;
- [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
- [[AVAudioSession sharedInstance] setMode:AVAudioSessionModeMoviePlayback error:nil];
- }
+ p_sys = p_aout->sys;
+ p_sys->au_unit = NULL;
+ p_sys->i_bytes_per_sample = 0;
- [[AVAudioSession sharedInstance] setActive:!pause error:nil];
-}
+ aout_FormatPrint(p_aout, "VLC is looking for:", fmt);
-static int MuteSet(audio_output_t *p_aout, bool mute)
-{
- struct aout_sys_t * p_sys = p_aout->sys;
+ if (StartAnalog(p_aout, fmt)) {
+ msg_Dbg(p_aout, "analog AudioUnit output successfully opened");
+ p_aout->play = Play;
+ p_aout->flush = Flush;
+ p_aout->mute_set = MuteSet;
+ p_aout->time_get = TimeGet;
+ p_aout->pause = Pause;
- if (p_sys != NULL && p_sys->au_unit != NULL) {
- msg_Dbg(p_aout, "audio output mute set to %d", mute?1:0);
- Pause(p_aout, mute, 0);
+ return VLC_SUCCESS;
}
- return VLC_SUCCESS;
+ /* If we reach this, this aout has failed */
+ msg_Err(p_aout, "opening AudioUnit output failed");
+ return VLC_EGENERIC;
}
-static void Flush(audio_output_t *p_aout, bool wait)
+static void Close(vlc_object_t *obj)
{
- struct aout_sys_t *p_sys = p_aout->sys;
-
- int32_t availableBytes;
- vlc_mutex_lock(&p_sys->lock);
- TPCircularBufferTail(&p_sys->circular_buffer, &availableBytes);
+ audio_output_t *aout = (audio_output_t *)obj;
+ aout_sys_t *sys = aout->sys;
- if (wait) {
- while (availableBytes > 0) {
- vlc_cond_wait(&p_sys->cond, &p_sys->lock);
- TPCircularBufferTail(&p_sys->circular_buffer, &availableBytes);
- }
- } else {
- /* flush circular buffer if data is left */
- if (availableBytes > 0)
- TPCircularBufferClear(&p_aout->sys->circular_buffer);
- }
+ vlc_mutex_destroy(&sys->lock);
+ vlc_cond_destroy(&sys->cond);
- vlc_mutex_unlock(&p_sys->lock);
+ free(sys);
}
-static int TimeGet(audio_output_t *p_aout, mtime_t *delay)
+static int Open(vlc_object_t *obj)
{
- struct aout_sys_t * p_sys = p_aout->sys;
-
- if (!p_sys->i_bytes_per_sample)
- return -1;
-
- int32_t availableBytes;
- TPCircularBufferTail(&p_sys->circular_buffer, &availableBytes);
-
- *delay = (availableBytes / p_sys->i_bytes_per_sample) * CLOCK_FREQ / p_sys->i_rate;
-
- return 0;
-}
-
-/*****************************************************************************
- * RenderCallback: This function is called everytime the AudioUnit wants
- * us to provide some more audio data.
- * Don't print anything during normal playback, calling blocking function from
- * this callback is not allowed.
- *****************************************************************************/
-static OSStatus RenderCallback(vlc_object_t *p_obj,
- AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber,
- UInt32 inNumberFrames,
- AudioBufferList *ioData) {
- VLC_UNUSED(ioActionFlags);
- VLC_UNUSED(inTimeStamp);
- VLC_UNUSED(inBusNumber);
- VLC_UNUSED(inNumberFrames);
-
- audio_output_t * p_aout = (audio_output_t *)p_obj;
- struct aout_sys_t * p_sys = p_aout->sys;
-
- int bytesRequested = ioData->mBuffers[0].mDataByteSize;
- Float32 *targetBuffer = (Float32*)ioData->mBuffers[0].mData;
-
- vlc_mutex_lock(&p_sys->lock);
- /* Pull audio from buffer */
- int32_t availableBytes;
- Float32 *buffer = TPCircularBufferTail(&p_sys->circular_buffer, &availableBytes);
- if (unlikely(bytesRequested == 0)) /* cannot be negative */
- return noErr;
+ audio_output_t *aout = (audio_output_t *)obj;
+ aout_sys_t *sys = malloc(sizeof (*sys));
- /* check if we have enough data */
- if (!availableBytes || p_sys->b_paused) {
- /* return an empty buffer so silence is played until we have data */
- memset(targetBuffer, 0, bytesRequested);
- } else {
- int32_t bytesToCopy = __MIN(bytesRequested, availableBytes);
+ if (unlikely(sys == NULL))
+ return VLC_ENOMEM;
- if (likely(bytesToCopy > 0)) {
- memcpy(targetBuffer, buffer, bytesToCopy);
- TPCircularBufferConsume(&p_sys->circular_buffer, bytesToCopy);
- ioData->mBuffers[0].mDataByteSize = bytesToCopy;
- }
- }
+ vlc_mutex_init(&sys->lock);
+ vlc_cond_init(&sys->cond);
+ sys->b_paused = false;
- vlc_cond_signal(&p_sys->cond);
- vlc_mutex_unlock(&p_sys->lock);
+ aout->sys = sys;
+ aout->start = Start;
+ aout->stop = Stop;
- return noErr;
+ return VLC_SUCCESS;
}
More information about the vlc-commits
mailing list