* Copyright (C) 2000-2013 VLC authors and VideoLAN
* $Id$
*
- * Authors: Romain Goyet <romain.goyet@likid.org>
- * Felix Paul Kühne <fkuehne at videolan dot org>
+ * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
* Rémi Denis-Courmont
* Rafaël Carré <funman at videolan dot org>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#pragma mark includes
#import <vlc_common.h>
#import <vlc_plugin.h>
#import <vlc_aout.h>
-#import <AudioToolBox/AudioQueue.h>
-#import <AudioToolBox/AudioSession.h>
+#import <AudioToolbox/AudioQueue.h>
#import <TargetConditionals.h>
+#if TARGET_OS_IPHONE
+#import <AudioToolbox/AudioSession.h>
+#else
+#define AudioSessionSetActive(x)
+#endif
#pragma mark -
#pragma mark private declarations
AudioQueueRef audioQueueRef;
AudioQueueTimelineRef timelineRef;
+ bool b_started;
+
mtime_t i_played_length;
int i_rate;
float f_volume;
msg_Dbg(p_aout, "New AudioQueue instance created (status = %li)", error);
if (error != noErr)
return VLC_EGENERIC;
-
fmt->i_format = VLC_CODEC_FL32;
fmt->i_physical_channels = AOUT_CHANS_STEREO;
aout_FormatPrepare(fmt);
if (error != noErr)
return VLC_EGENERIC;
-#ifdef TARGET_OS_IPHONE
+#if TARGET_OS_IPHONE
// start audio session so playback continues if mute switch is on
AudioSessionInitialize (NULL,
kCFRunLoopCommonModes,
AudioSessionSetActive(true);
#endif
+ p_aout->sys->b_started = true;
+
p_aout->time_get = TimeGet;
p_aout->play = Play;
p_aout->pause = Pause;
p_aout->flush = Flush;
-
return VLC_SUCCESS;
}
static void Stop(audio_output_t *p_aout)
{
-#ifdef TARGET_OS_IPHONE
AudioSessionSetActive(false);
-#endif
p_aout->sys->i_played_length = 0;
AudioQueueDisposeTimeline(p_aout->sys->audioQueueRef, p_aout->sys->timelineRef);
void UnusedAudioQueueCallback(void * inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer) {
/* this function does nothing, but needs to be here to make the AudioQueue API happy.
- * without a callback, it will refuse to create an AudioQueue instance. */
+ * additionally, we clean-up after empty buffers */
VLC_UNUSED(inUserData);
- VLC_UNUSED(inAQ);
- VLC_UNUSED(inBuffer);
+ AudioQueueFreeBuffer(inAQ, inBuffer);
}
static void Pause(audio_output_t *p_aout, bool pause, mtime_t date)
if (pause) {
AudioQueuePause(p_aout->sys->audioQueueRef);
-#ifdef TARGET_OS_IPHONE
AudioSessionSetActive(false);
-#endif
} else {
AudioQueueStart(p_aout->sys->audioQueueRef, NULL);
-#ifdef TARGET_OS_IPHONE
AudioSessionSetActive(true);
-#endif
}
}
else
AudioQueueStop(p_aout->sys->audioQueueRef, true);
+ p_aout->sys->b_started = false;
p_aout->sys->i_played_length = 0;
AudioQueueStart(p_aout->sys->audioQueueRef, NULL);
AudioQueueCreateTimeline(p_aout->sys->audioQueueRef, &p_aout->sys->timelineRef);
+ p_aout->sys->b_started = true;
}
static int TimeGet(audio_output_t *p_aout, mtime_t *restrict delay)
if (status != noErr)
return -1;
- if (b_discontinuity)
+ bool b_started = p_aout->sys->b_started;
+
+ if (!b_started)
+ return -1;
+
+ if (b_discontinuity) {
msg_Dbg(p_aout, "detected output discontinuity");
+ return -1;
+ }
mtime_t i_pos = (mtime_t) outTimeStamp.mSampleTime * CLOCK_FREQ / p_aout->sys->i_rate;
- *delay = p_aout->sys->i_played_length - i_pos;
-
- return 0;
+ if (i_pos > 0) {
+ *delay = p_aout->sys->i_played_length - i_pos;
+ return 0;
+ } else
+ return -1;
}