Commit a799753e authored by Paulo Vitor Magacho da Silva's avatar Paulo Vitor Magacho da Silva Committed by Felix Paul Kühne
Browse files

iOS Audio Unit: added mute, replaced deprecated methods with modern ObjC counterparts


Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent 371695c6
......@@ -104,9 +104,9 @@ libauhal_plugin_la_LDFLAGS = $(AM_LDFLAGS) -Wl,-framework,CoreAudio,-framework,A
if HAVE_OSX
aout_LTLIBRARIES += libauhal_plugin.la
endif
libaudiounit_ios_plugin_la_SOURCES = audio_output/audiounit_ios.c \
audio_output/TPCircularBuffer.h audio_output/TPCircularBuffer.c
libaudiounit_ios_plugin_la_LDFLAGS = $(libauhal_plugin_la_LDFLAGS)
libaudiounit_ios_plugin_la_SOURCES = audio_output/audiounit_ios.m \
audio_output/TPCircularBuffer.h audio_output/TPCircularBuffer.c
libaudiounit_ios_plugin_la_LDFLAGS = $(AM_LDFLAGS) -Wl,-framework,CoreAudio,-framework,AudioUnit,-framework,AudioToolbox,-framework,CoreServices,-framework,UIKit,-framework,AVFoundation -rpath '$(aoutdir)'
if HAVE_IOS
aout_LTLIBRARIES += libaudiounit_ios_plugin.la
endif
......
/*****************************************************************************
* audiounit_ios.c: AudioUnit output plugin for iOS
* audiounit_ios.m: AudioUnit output plugin for iOS
*****************************************************************************
* Copyright (C) 2012 - 2015 VLC authors and VideoLAN
* $Id$
......@@ -33,13 +33,13 @@
#import <AudioUnit/AudioUnit.h>
#import <CoreAudio/CoreAudioTypes.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import <mach/mach_time.h>
#import "TPCircularBuffer.h"
#import <TargetConditionals.h>
#pragma mark -
#pragma mark private declarations
......@@ -86,6 +86,7 @@ static void Stop (audio_output_t *);
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 *,
......@@ -148,8 +149,10 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict 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 VLC_SUCCESS;
}
......@@ -254,22 +257,6 @@ static int StartAnalog(audio_output_t *p_aout, audio_sample_format_t *fmt)
return false;
}
/* setup circular buffer */
TPCircularBufferInit(&p_sys->circular_buffer, AUDIO_BUFFER_SIZE_IN_SECONDS * fmt->i_rate * fmt->i_bytes_per_frame);
#if !TARGET_OS_TV
/* start audio session so playback continues if mute switch is on */
AudioSessionInitialize (NULL,
kCFRunLoopCommonModes,
NULL,
NULL);
/* Set audio session to mediaplayback */
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory),&sessionCategory);
AudioSessionSetActive(true);
#endif
/* AU init */
status = AudioUnitInitialize(p_sys->au_unit);
if (status != noErr) {
......@@ -277,6 +264,18 @@ static int StartAnalog(audio_output_t *p_aout, audio_sample_format_t *fmt)
return false;
}
/* setup circular buffer */
TPCircularBufferInit(&p_sys->circular_buffer, AUDIO_BUFFER_SIZE_IN_SECONDS * fmt->i_rate * fmt->i_bytes_per_frame);
/* start audio session so playback continues if mute switch is on */
AVAudioSession *instance = [AVAudioSession sharedInstance];
/* Set audio session to mediaplayback */
NSError *error = nil;
[instance setCategory:AVAudioSessionCategoryPlayback error:&error];
[instance setMode:AVAudioSessionModeMoviePlayback error:&error];
[instance setActive:YES error:&error];
/* start the unit */
status = AudioOutputUnitStart(p_sys->au_unit);
msg_Dbg(p_aout, "audio output unit started: %i", (int)status);
......@@ -289,9 +288,7 @@ static void Stop(audio_output_t *p_aout)
struct aout_sys_t *p_sys = p_aout->sys;
OSStatus status;
#if !TARGET_OS_TV
AudioSessionSetActive(false);
#endif
[[AVAudioSession sharedInstance] setActive:NO error:nil];
if (p_sys->au_unit) {
status = AudioOutputUnitStop(p_sys->au_unit);
......@@ -340,6 +337,10 @@ static void Pause (audio_output_t *p_aout, bool pause, mtime_t date)
p_sys->b_paused = pause;
vlc_mutex_unlock(&p_sys->lock);
if (p_sys->au_unit == NULL) {
return;
}
/* 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
......@@ -348,17 +349,26 @@ static void Pause (audio_output_t *p_aout, bool pause, mtime_t date)
* show a playing state despite we are paused, same for lock screen */
if (pause) {
AudioOutputUnitStop(p_sys->au_unit);
#if !TARGET_OS_TV
AudioSessionSetActive(false);
#endif
} else {
#if !TARGET_OS_TV
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory),&sessionCategory);
AudioSessionSetActive(true);
#endif
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 Flush(audio_output_t *p_aout, bool wait)
......@@ -447,4 +457,3 @@ static OSStatus RenderCallback(vlc_object_t *p_obj,
return noErr;
}
......@@ -324,7 +324,7 @@ modules/audio_output/alsa.c
modules/audio_output/amem.c
modules/audio_output/audioqueue.c
modules/audio_output/audiotrack.c
modules/audio_output/audiounit_ios.c
modules/audio_output/audiounit_ios.m
modules/audio_output/auhal.c
modules/audio_output/directsound.c
modules/audio_output/file.c
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment