Commit d87ff6d8 authored by Felix Paul Kühne's avatar Felix Paul Kühne

audioqueue: clean-up

parent 08ec4920
...@@ -26,20 +26,19 @@ ...@@ -26,20 +26,19 @@
* Preamble * Preamble
*****************************************************************************/ *****************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # import "config.h"
#endif #endif
#include <vlc_common.h> #import <vlc_common.h>
#include <vlc_plugin.h> #import <vlc_plugin.h>
#include <vlc_aout.h> #import <vlc_aout.h>
#import <AudioToolBox/AudioQueue.h>
#include <AudioToolBox/AudioToolBox.h>
/***************************************************************************** /*****************************************************************************
* aout_sys_t: AudioQueue audio output method descriptor * aout_sys_t: private audio output method descriptor
***************************************************************************** *****************************************************************************
* This structure is part of the audio output thread descriptor. * This structure is part of the audio output thread descriptor.
* It describes the specific properties of an audio device. * It describes the AudioQueue specific properties of an output thread.
*****************************************************************************/ *****************************************************************************/
struct aout_sys_t struct aout_sys_t
{ {
...@@ -61,7 +60,11 @@ static void Play (audio_output_t *, block_t *); ...@@ -61,7 +60,11 @@ static void Play (audio_output_t *, block_t *);
static void Pause (audio_output_t *p_aout, bool pause, mtime_t date); static void Pause (audio_output_t *p_aout, bool pause, mtime_t date);
static void Flush (audio_output_t *p_aout, bool wait); static void Flush (audio_output_t *p_aout, bool wait);
static int TimeGet (audio_output_t *aout, mtime_t *); static int TimeGet (audio_output_t *aout, mtime_t *);
static void AudioQueueCallback (void *, AudioQueueRef, AudioQueueBufferRef); static void UnusedAudioQueueCallback (void *, AudioQueueRef, AudioQueueBufferRef);
static int Start(audio_output_t *, audio_sample_format_t *);
static void Stop(audio_output_t *);
static int VolumeSet(audio_output_t *, float );
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
...@@ -76,6 +79,52 @@ add_shortcut("audioqueue") ...@@ -76,6 +79,52 @@ add_shortcut("audioqueue")
set_callbacks(Open, Close) set_callbacks(Open, Close)
vlc_module_end () vlc_module_end ()
/*****************************************************************************
* Module management
*****************************************************************************/
static int Open(vlc_object_t *obj)
{
audio_output_t *aout = (audio_output_t *)obj;
aout_sys_t *sys = malloc(sizeof (*sys));
if (unlikely(sys == NULL))
return VLC_ENOMEM;
aout->sys = sys;
aout->start = Start;
aout->stop = Stop;
aout->volume_set = VolumeSet;
/* reset volume */
aout_VolumeReport(aout, 1.0);
return VLC_SUCCESS;
}
static void Close(vlc_object_t *obj)
{
audio_output_t *aout = (audio_output_t *)obj;
msg_Dbg( aout, "audioqueue: Close");
aout_sys_t *sys = aout->sys;
free(sys);
}
static int VolumeSet(audio_output_t * p_aout, float volume)
{
struct aout_sys_t *p_sys = p_aout->sys;
OSStatus ostatus;
aout_VolumeReport(p_aout, volume);
p_sys->f_volume = volume;
/* Set volume for output unit */
ostatus = AudioQueueSetParameter(p_sys->audioQueue, kAudioQueueParam_Volume, volume * volume * volume);
return ostatus;
}
/***************************************************************************** /*****************************************************************************
* Start: open the audio device * Start: open the audio device
*****************************************************************************/ *****************************************************************************/
...@@ -83,30 +132,30 @@ vlc_module_end () ...@@ -83,30 +132,30 @@ vlc_module_end ()
static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt) static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
{ {
aout_sys_t *p_sys = p_aout->sys; aout_sys_t *p_sys = p_aout->sys;
OSStatus status = 0; OSStatus error = 0;
// Setup the audio device. // prepare the format description for our output
AudioStreamBasicDescription deviceFormat; AudioStreamBasicDescription streamDescription;
deviceFormat.mSampleRate = fmt->i_rate; streamDescription.mSampleRate = fmt->i_rate;
deviceFormat.mFormatID = kAudioFormatLinearPCM; streamDescription.mFormatID = kAudioFormatLinearPCM;
deviceFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked; // FL32 streamDescription.mFormatFlags = kAudioFormatFlagsNativeFloatPacked; // FL32
deviceFormat.mFramesPerPacket = 1; streamDescription.mFramesPerPacket = 1;
deviceFormat.mChannelsPerFrame = 2; streamDescription.mChannelsPerFrame = 2;
deviceFormat.mBitsPerChannel = 32; streamDescription.mBitsPerChannel = 32;
deviceFormat.mBytesPerFrame = deviceFormat.mBitsPerChannel * deviceFormat.mChannelsPerFrame / 8; streamDescription.mBytesPerFrame = streamDescription.mBitsPerChannel * streamDescription.mChannelsPerFrame / 8;
deviceFormat.mBytesPerPacket = deviceFormat.mBytesPerFrame * deviceFormat.mFramesPerPacket; streamDescription.mBytesPerPacket = streamDescription.mBytesPerFrame * streamDescription.mFramesPerPacket;
// Create a new output AudioQueue for the device. // init new output instance
status = AudioQueueNewOutput(&deviceFormat, // Format error = AudioQueueNewOutput(&streamDescription, // Format
AudioQueueCallback, // Callback UnusedAudioQueueCallback, // Unused Callback, which needs to be provided to have a proper instance
NULL, // User data, passed to the callback NULL, // User data, passed to the callback
NULL, // RunLoop NULL, // RunLoop
kCFRunLoopCommonModes, // RunLoop mode kCFRunLoopCommonModes, // RunLoop mode
0, // Flags ; must be zero (per documentation)... 0, // Flags ; must be zero (per documentation)...
&(p_sys->audioQueue)); // Output &(p_sys->audioQueue)); // Output
msg_Dbg(p_aout, "New AudioQueue output created (status = %li)", status); msg_Dbg(p_aout, "New AudioQueue output created (status = %li)", error);
if (status != noErr) if (error != noErr)
return VLC_EGENERIC; return VLC_EGENERIC;
fmt->i_format = VLC_CODEC_FL32; fmt->i_format = VLC_CODEC_FL32;
...@@ -116,20 +165,22 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt) ...@@ -116,20 +165,22 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
p_aout->sys->b_stopped = false; p_aout->sys->b_stopped = false;
p_aout->sys->i_rate = fmt->i_rate; p_aout->sys->i_rate = fmt->i_rate;
status = AudioQueueStart(p_sys->audioQueue, NULL); // start queue
msg_Dbg(p_aout, "Starting AudioQueue (status = %li)", status); error = AudioQueueStart(p_sys->audioQueue, NULL);
msg_Dbg(p_aout, "Starting AudioQueue (status = %li)", error);
// start timeline for synchro
error = AudioQueueCreateTimeline(p_sys->audioQueue, &p_sys->outTimeline);
msg_Dbg(p_aout, "AudioQueue Timeline started (status = %li)", error);
status = AudioQueueCreateTimeline(p_sys->audioQueue, &p_sys->outTimeline); if (error != noErr)
msg_Dbg(p_aout, "AudioQueue Timeline started (status = %li)", status); return VLC_EGENERIC;
p_aout->time_get = TimeGet; p_aout->time_get = TimeGet;
p_aout->play = Play; p_aout->play = Play;
p_aout->pause = Pause; p_aout->pause = Pause;
p_aout->flush = Flush; p_aout->flush = Flush;
if (status != noErr)
return VLC_EGENERIC;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -137,24 +188,23 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt) ...@@ -137,24 +188,23 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
* Stop: close the audio device * Stop: close the audio device
*****************************************************************************/ *****************************************************************************/
static void Stop (audio_output_t *p_aout) static void Stop(audio_output_t *p_aout)
{ {
p_aout->sys->b_stopped = true; p_aout->sys->b_stopped = true;
p_aout->sys->i_played_length = 0; p_aout->sys->i_played_length = 0;
msg_Dbg(p_aout, "Stopping AudioQueue timeline");
AudioQueueDisposeTimeline(p_aout->sys->audioQueue, p_aout->sys->outTimeline); AudioQueueDisposeTimeline(p_aout->sys->audioQueue, p_aout->sys->outTimeline);
msg_Dbg(p_aout, "Stopping AudioQueue");
AudioQueueStop(p_aout->sys->audioQueue, true); AudioQueueStop(p_aout->sys->audioQueue, true);
msg_Dbg(p_aout, "Disposing AudioQueue");
AudioQueueDispose(p_aout->sys->audioQueue, true); AudioQueueDispose(p_aout->sys->audioQueue, true);
msg_Dbg(p_aout, "audioqueue stopped and disposed");
} }
/***************************************************************************** /*****************************************************************************
* actual playback * actual playback
*****************************************************************************/ *****************************************************************************/
static void Play (audio_output_t *p_aout, block_t *p_block) static void Play(audio_output_t *p_aout, block_t *p_block)
{ {
AudioQueueBufferRef inBuffer = NULL; AudioQueueBufferRef inBuffer = NULL;
OSStatus status; OSStatus status;
...@@ -177,7 +227,7 @@ static void Play (audio_output_t *p_aout, block_t *p_block) ...@@ -177,7 +227,7 @@ static void Play (audio_output_t *p_aout, block_t *p_block)
block_Release(p_block); block_Release(p_block);
} }
void AudioQueueCallback(void * inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer) { void UnusedAudioQueueCallback(void * inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer) {
/* this function does nothing, but needs to be here to make the AudioQueue API happy. /* 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. */ * without a callback, it will refuse to create an AudioQueue instance. */
VLC_UNUSED(inUserData); VLC_UNUSED(inUserData);
...@@ -185,7 +235,7 @@ void AudioQueueCallback(void * inUserData, AudioQueueRef inAQ, AudioQueueBufferR ...@@ -185,7 +235,7 @@ void AudioQueueCallback(void * inUserData, AudioQueueRef inAQ, AudioQueueBufferR
VLC_UNUSED(inBuffer); VLC_UNUSED(inBuffer);
} }
static void Pause (audio_output_t *p_aout, bool pause, mtime_t date) static void Pause(audio_output_t *p_aout, bool pause, mtime_t date)
{ {
VLC_UNUSED(date); VLC_UNUSED(date);
...@@ -195,7 +245,7 @@ static void Pause (audio_output_t *p_aout, bool pause, mtime_t date) ...@@ -195,7 +245,7 @@ static void Pause (audio_output_t *p_aout, bool pause, mtime_t date)
AudioQueueStart(p_aout->sys->audioQueue, NULL); AudioQueueStart(p_aout->sys->audioQueue, NULL);
} }
static void Flush (audio_output_t *p_aout, bool wait) static void Flush(audio_output_t *p_aout, bool wait)
{ {
if (p_aout->sys->b_stopped || !p_aout->sys->audioQueue) if (p_aout->sys->b_stopped || !p_aout->sys->audioQueue)
return; return;
...@@ -212,7 +262,7 @@ static void Flush (audio_output_t *p_aout, bool wait) ...@@ -212,7 +262,7 @@ static void Flush (audio_output_t *p_aout, bool wait)
AudioQueueCreateTimeline(p_aout->sys->audioQueue, &p_aout->sys->outTimeline); AudioQueueCreateTimeline(p_aout->sys->audioQueue, &p_aout->sys->outTimeline);
} }
static int TimeGet (audio_output_t *p_aout, mtime_t *restrict delay) static int TimeGet(audio_output_t *p_aout, mtime_t *restrict delay)
{ {
AudioTimeStamp outTimeStamp; AudioTimeStamp outTimeStamp;
Boolean b_discontinuity; Boolean b_discontinuity;
...@@ -229,53 +279,3 @@ static int TimeGet (audio_output_t *p_aout, mtime_t *restrict delay) ...@@ -229,53 +279,3 @@ static int TimeGet (audio_output_t *p_aout, mtime_t *restrict delay)
return 0; return 0;
} }
/*****************************************************************************
* Module management
*****************************************************************************/
static int VolumeSet(audio_output_t * p_aout, float volume)
{
struct aout_sys_t *p_sys = p_aout->sys;
OSStatus ostatus;
aout_VolumeReport(p_aout, volume);
p_sys->f_volume = volume;
/* Set volume for output unit */
ostatus = AudioQueueSetParameter(p_sys->audioQueue, kAudioQueueParam_Volume, volume * volume * volume);
return ostatus;
}
/*****************************************************************************
* Module management
*****************************************************************************/
static int Open(vlc_object_t *obj)
{
audio_output_t *aout = (audio_output_t *)obj;
aout_sys_t *sys = malloc(sizeof (*sys));
if (unlikely(sys == NULL))
return VLC_ENOMEM;
aout->sys = sys;
aout->start = Start;
aout->stop = Stop;
aout->volume_set = VolumeSet;
/* reset volume */
aout_VolumeReport(aout, 1.0);
return VLC_SUCCESS;
}
static void Close(vlc_object_t *obj)
{
audio_output_t *aout = (audio_output_t *)obj;
msg_Dbg( aout, "audioqueue: Close");
aout_sys_t *sys = aout->sys;
free(sys);
}
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