diff options
Diffstat (limited to 'audio/out')
-rw-r--r-- | audio/out/ao.c | 74 | ||||
-rw-r--r-- | audio/out/ao.h | 18 | ||||
-rw-r--r-- | audio/out/ao_alsa.c | 17 | ||||
-rw-r--r-- | audio/out/ao_coreaudio.c | 1320 | ||||
-rw-r--r-- | audio/out/ao_dsound.c | 14 | ||||
-rw-r--r-- | audio/out/ao_jack.c | 50 | ||||
-rw-r--r-- | audio/out/ao_lavc.c | 13 | ||||
-rw-r--r-- | audio/out/ao_null.c | 17 | ||||
-rw-r--r-- | audio/out/ao_openal.c | 3 | ||||
-rw-r--r-- | audio/out/ao_oss.c | 52 | ||||
-rw-r--r-- | audio/out/ao_pcm.c | 3 | ||||
-rw-r--r-- | audio/out/ao_portaudio.c | 68 | ||||
-rw-r--r-- | audio/out/ao_pulse.c | 2 | ||||
-rw-r--r-- | audio/out/ao_rsound.c | 2 | ||||
-rw-r--r-- | audio/out/ao_sdl.c | 46 | ||||
-rw-r--r-- | audio/out/audio_out_internal.h | 66 |
16 files changed, 795 insertions, 970 deletions
diff --git a/audio/out/ao.c b/audio/out/ao.c index 10badcfa07..7abb33f89f 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -25,6 +25,7 @@ #include "config.h" #include "ao.h" +#include "audio/format.h" #include "core/mp_msg.h" @@ -106,8 +107,7 @@ void list_audio_out(void) struct ao *ao_create(struct MPOpts *opts, struct input_ctx *input) { struct ao *r = talloc(NULL, struct ao); - *r = (struct ao){.outburst = 512, .buffersize = -1, - .opts = opts, .input_ctx = input }; + *r = (struct ao){.opts = opts, .input_ctx = input }; return r; } @@ -115,7 +115,11 @@ static bool ao_try_init(struct ao *ao, char *params) { if (ao->driver->encode != !!ao->encode_lavc_ctx) return false; - return ao->driver->init(ao, params) >= 0; + if (ao->driver->init(ao, params) < 0) + return false; + ao->bps = ao->channels.num * ao->samplerate * af_fmt2bits(ao->format) / 8; + ao->initialized = true; + return true; } void ao_init(struct ao *ao, char **ao_list) @@ -156,11 +160,8 @@ void ao_init(struct ao *ao, char **ao_list) if (audio_out) { // name matches, try it ao->driver = audio_out; - if (ao_try_init(ao, params)) { - ao->driver = audio_out; - ao->initialized = true; + if (ao_try_init(ao, params)) return; - } mp_tmsg(MSGT_AO, MSGL_WARN, "Failed to initialize audio driver '%s'\n", ao_name); talloc_free_children(ao); @@ -182,11 +183,8 @@ void ao_init(struct ao *ao, char **ao_list) const struct ao_driver *audio_out = audio_out_drivers[i]; ao->driver = audio_out; ao->probing = true; - if (ao_try_init(ao, NULL)) { - ao->initialized = true; - ao->driver = audio_out; + if (ao_try_init(ao, NULL)) return; - } talloc_free_children(ao); *ao = backup; } @@ -261,57 +259,3 @@ bool ao_chmap_sel_get_def(struct ao *ao, const struct mp_chmap_sel *s, { return mp_chmap_sel_get_def(s, map, num); } - -int old_ao_init(struct ao *ao, char *params) -{ - assert(!global_ao); - global_ao = ao; - ao_subdevice = params ? talloc_strdup(ao, params) : NULL; - if (ao->driver->old_functions->init(ao->samplerate, &ao->channels, - ao->format, 0) == 0) { - global_ao = NULL; - return -1; - } - return 0; -} - -void old_ao_uninit(struct ao *ao, bool cut_audio) -{ - ao->driver->old_functions->uninit(cut_audio); - global_ao = NULL; -} - -int old_ao_play(struct ao *ao, void *data, int len, int flags) -{ - return ao->driver->old_functions->play(data, len, flags); -} - -int old_ao_control(struct ao *ao, enum aocontrol cmd, void *arg) -{ - return ao->driver->old_functions->control(cmd, arg); -} - -float old_ao_get_delay(struct ao *ao) -{ - return ao->driver->old_functions->get_delay(); -} - -int old_ao_get_space(struct ao *ao) -{ - return ao->driver->old_functions->get_space(); -} - -void old_ao_reset(struct ao *ao) -{ - ao->driver->old_functions->reset(); -} - -void old_ao_pause(struct ao *ao) -{ - ao->driver->old_functions->pause(); -} - -void old_ao_resume(struct ao *ao) -{ - ao->driver->old_functions->resume(); -} diff --git a/audio/out/ao.h b/audio/out/ao.h index d908841457..146c35f823 100644 --- a/audio/out/ao.h +++ b/audio/out/ao.h @@ -89,13 +89,11 @@ struct ao { int samplerate; struct mp_chmap channels; int format; - int bps; // bytes per second - int outburst; - int buffersize; - double pts; + int bps; // bytes per second + double pts; // some mplayer.c state (why is this here?) struct bstr buffer; int buffer_playable_size; - bool probing; + bool probing; // if true, don't fail loudly on init bool initialized; bool untimed; bool no_persistent_volume; // the AO does the equivalent of af_volume @@ -127,14 +125,4 @@ bool ao_chmap_sel_adjust(struct ao *ao, const struct mp_chmap_sel *s, bool ao_chmap_sel_get_def(struct ao *ao, const struct mp_chmap_sel *s, struct mp_chmap *map, int num); -int old_ao_control(struct ao *ao, enum aocontrol cmd, void *arg); -int old_ao_init(struct ao *ao, char *params); -void old_ao_uninit(struct ao *ao, bool cut_audio); -void old_ao_reset(struct ao*ao); -int old_ao_get_space(struct ao *ao); -int old_ao_play(struct ao *ao, void *data, int len, int flags); -float old_ao_get_delay(struct ao *ao); -void old_ao_pause(struct ao *ao); -void old_ao_resume(struct ao *ao); - #endif /* MPLAYER_AUDIO_OUT_H */ diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c index a8952e4547..bbd4603d18 100644 --- a/audio/out/ao_alsa.c +++ b/audio/out/ao_alsa.c @@ -57,6 +57,8 @@ struct priv { int can_pause; snd_pcm_sframes_t prepause_frames; float delay_before_pause; + int buffersize; + int outburst; }; #define BUFFER_TIME 500000 // 0.5 s @@ -560,7 +562,6 @@ static int init(struct ao *ao, char *params) p->bytes_per_sample = af_fmt2bits(ao->format) / 8; p->bytes_per_sample *= ao->channels.num; - ao->bps = ao->samplerate * p->bytes_per_sample; err = snd_pcm_hw_params_set_buffer_time_near (p->alsa, alsa_hwparams, &(unsigned int){BUFFER_TIME}, NULL); @@ -580,15 +581,15 @@ static int init(struct ao *ao, char *params) err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams, &bufsize); CHECK_ALSA_ERROR("Unable to get buffersize"); - ao->buffersize = bufsize * p->bytes_per_sample; + p->buffersize = bufsize * p->bytes_per_sample; mp_msg(MSGT_AO, MSGL_V, "alsa-init: got buffersize=%i\n", - ao->buffersize); + p->buffersize); err = snd_pcm_hw_params_get_period_size(alsa_hwparams, &chunk_size, NULL); CHECK_ALSA_ERROR("Unable to get period size"); mp_msg(MSGT_AO, MSGL_V, "alsa-init: got period size %li\n", chunk_size); - ao->outburst = chunk_size * p->bytes_per_sample; + p->outburst = chunk_size * p->bytes_per_sample; /* setting software parameters */ err = snd_pcm_sw_params_current(p->alsa, alsa_swparams); @@ -622,7 +623,7 @@ static int init(struct ao *ao, char *params) mp_msg(MSGT_AO, MSGL_V, "alsa: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n", ao->samplerate, ao->channels.num, (int)p->bytes_per_sample, - ao->buffersize, snd_pcm_format_description(p->alsa_fmt)); + p->buffersize, snd_pcm_format_description(p->alsa_fmt)); return 0; @@ -734,7 +735,7 @@ static int play(struct ao *ao, void *data, int len, int flags) int num_frames; snd_pcm_sframes_t res = 0; if (!(flags & AOPLAY_FINAL_CHUNK)) - len = len / ao->outburst * ao->outburst; + len = len / p->outburst * p->outburst; num_frames = len / p->bytes_per_sample; //mp_msg(MSGT_AO,MSGL_ERR,"alsa-play: frames=%i, len=%i\n",num_frames,len); @@ -790,8 +791,8 @@ static int get_space(struct ao *ao) CHECK_ALSA_ERROR("cannot get pcm status"); unsigned space = snd_pcm_status_get_avail(status) * p->bytes_per_sample; - if (space > ao->buffersize) // Buffer underrun? - space = ao->buffersize; + if (space > p->buffersize) // Buffer underrun? + space = p->buffersize; return space; alsa_error: diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c index bec849d8ca..38c7c7fc29 100644 --- a/audio/out/ao_coreaudio.c +++ b/audio/out/ao_coreaudio.c @@ -30,9 +30,6 @@ * simpler frameworks do. This is due to the fact that CoreAudio pulls * audio samples rather than having them pushed at it (which is nice * when you are wanting to do good buffering of audio). - * - * AC-3 and MPEG audio passthrough is possible, but has never been tested - * due to lack of a soundcard that supports it. */ #include <CoreServices/CoreServices.h> @@ -49,95 +46,58 @@ #include "core/mp_msg.h" #include "ao.h" -#include "audio_out_internal.h" #include "audio/format.h" #include "osdep/timer.h" -#include "libavutil/fifo.h" #include "core/subopt-helper.h" +#include "core/mp_ring.h" -static const ao_info_t info = - { - "Darwin/Mac OS X native audio output", - "coreaudio", - "Timothy J. Wood & Dan Christiansen & Chris Roccati", - "" - }; - -LIBAO_EXTERN(coreaudio) - -/* Prefix for all mp_msg() calls */ -#define ao_msg(a, b, c...) mp_msg(a, b, "AO: [coreaudio] " c) - -#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1040 -/* AudioDeviceIOProcID does not exist in Mac OS X 10.4. We can emulate - * this by using AudioDeviceAddIOProc() and AudioDeviceRemoveIOProc(). */ -#define AudioDeviceIOProcID AudioDeviceIOProc -#define AudioDeviceDestroyIOProcID AudioDeviceRemoveIOProc -static OSStatus AudioDeviceCreateIOProcID(AudioDeviceID dev, - AudioDeviceIOProc proc, - void *data, - AudioDeviceIOProcID *procid) -{ - *procid = proc; - return AudioDeviceAddIOProc(dev, proc, data); -} -#endif +#define ca_msg(a, b, c ...) mp_msg(a, b, "AO: [coreaudio] " c) -typedef struct ao_coreaudio_s +static void audio_pause(struct ao *ao); +static void audio_resume(struct ao *ao); +static void reset(struct ao *ao); + +static void print_buffer(struct mp_ring *buffer) { - AudioDeviceID i_selected_dev; /* Keeps DeviceID of the selected device. */ - int b_supports_digital; /* Does the currently selected device support digital mode? */ - int b_digital; /* Are we running in digital mode? */ - int b_muted; /* Are we muted in digital mode? */ - - AudioDeviceIOProcID renderCallback; /* Render callback used for SPDIF */ - - /* AudioUnit */ - AudioUnit theOutputUnit; - - /* CoreAudio SPDIF mode specific */ - pid_t i_hog_pid; /* Keeps the pid of our hog status. */ - AudioStreamID i_stream_id; /* The StreamID that has a cac3 streamformat */ - int i_stream_index; /* The index of i_stream_id in an AudioBufferList */ - AudioStreamBasicDescription stream_format;/* The format we changed the stream to */ - AudioStreamBasicDescription sfmt_revert; /* The original format of the stream */ - int b_revert; /* Whether we need to revert the stream format */ - int b_changed_mixing; /* Whether we need to set the mixing mode back */ - int b_stream_format_changed; /* Flag for main thread to reset stream's format to digital and reset buffer */ - - /* Original common part */ - int packetSize; - int paused; - - /* Ring-buffer */ - AVFifoBuffer *buffer; - unsigned int buffer_len; ///< must always be num_chunks * chunk_size - unsigned int num_chunks; - unsigned int chunk_size; -} ao_coreaudio_t; - -static ao_coreaudio_t *ao = NULL; - -/** - * \brief add data to ringbuffer - */ -static int write_buffer(unsigned char* data, int len){ - int free = ao->buffer_len - av_fifo_size(ao->buffer); - if (len > free) len = free; - return av_fifo_generic_write(ao->buffer, data, len, NULL); + void *tctx = talloc_new(NULL); + ca_msg(MSGT_AO, MSGL_V, "%s\n", mp_ring_repr(buffer, tctx)); + talloc_free(tctx); } -/** - * \brief remove data from ringbuffer - */ -static int read_buffer(unsigned char* data,int len){ - int buffered = av_fifo_size(ao->buffer); - if (len > buffered) len = buffered; - if (data) - av_fifo_generic_read(ao->buffer, data, len, NULL); - else - av_fifo_drain(ao->buffer, len); - return len; + +struct priv +{ + AudioDeviceID i_selected_dev; /* Keeps DeviceID of the selected device. */ + int b_supports_digital; /* Does the currently selected device support digital mode? */ + int b_digital; /* Are we running in digital mode? */ + int b_muted; /* Are we muted in digital mode? */ + + AudioDeviceIOProcID renderCallback; /* Render callback used for SPDIF */ + + /* AudioUnit */ + AudioUnit theOutputUnit; + + /* CoreAudio SPDIF mode specific */ + pid_t i_hog_pid; /* Keeps the pid of our hog status. */ + AudioStreamID i_stream_id; /* The StreamID that has a cac3 streamformat */ + int i_stream_index; /* The index of i_stream_id in an AudioBufferList */ + AudioStreamBasicDescription stream_format; /* The format we changed the stream to */ + AudioStreamBasicDescription sfmt_revert; /* The original format of the stream */ + int b_revert; /* Whether we need to revert the stream format */ + int b_changed_mixing; /* Whether we need to set the mixing mode back */ + int b_stream_format_changed; /* Flag for main thread to reset stream's format to digital and reset buffer */ + + /* Original common part */ + int packetSize; + int paused; + + struct mp_ring *buffer; +}; + +static int get_ring_size(struct ao *ao) +{ + return af_fmt_seconds_to_bytes( + ao->format, 0.5, ao->channels.num, ao->samplerate); } static OSStatus theRenderProc(void *inRefCon, @@ -146,100 +106,115 @@ static OSStatus theRenderProc(void *inRefCon, UInt32 inBusNumber, UInt32 inNumFrames, AudioBufferList *ioData) { -int amt=av_fifo_size(ao->buffer); -int req=(inNumFrames)*ao->packetSize; + struct ao *ao = inRefCon; + struct priv *p = ao->priv; + + int buffered = mp_ring_buffered(p->buffer); + int requested = inNumFrames * p->packetSize; - if(amt>req) - amt=req; + if (buffered > requested) + buffered = requested; + + if (buffered) { + mp_ring_read(p->buffer, + (unsigned char *)ioData->mBuffers[0].mData, + buffered); + } else { + audio_pause(ao); + } - if(amt) - read_buffer((unsigned char *)ioData->mBuffers[0].mData, amt); - else audio_pause(); - ioData->mBuffers[0].mDataByteSize = amt; + ioData->mBuffers[0].mDataByteSize = buffered; - return noErr; + return noErr; } -static int control(int cmd,void *arg){ -ao_control_vol_t *control_vol; -OSStatus err; -Float32 vol; - switch (cmd) { - case AOCONTROL_GET_VOLUME: - control_vol = (ao_control_vol_t*)arg; - if (ao->b_digital) { - // Digital output has no volume adjust. - int vol = ao->b_muted ? 0 : 100; - *control_vol = (ao_control_vol_t) { - .left = vol, .right = vol, - }; - return CONTROL_TRUE; - } - err = AudioUnitGetParameter(ao->theOutputUnit, kHALOutputParam_Volume, kAudioUnitScope_Global, 0, &vol); - - if(err==0) { - // printf("GET VOL=%f\n", vol); - control_vol->left=control_vol->right=vol*100.0/4.0; - return CONTROL_TRUE; - } - else { - ao_msg(MSGT_AO, MSGL_WARN, "could not get HAL output volume: [%4.4s]\n", (char *)&err); - return CONTROL_FALSE; - } - - case AOCONTROL_SET_VOLUME: - control_vol = (ao_control_vol_t*)arg; - - if (ao->b_digital) { - // Digital output can not set volume. Here we have to return true - // to make mixer forget it. Else mixer will add a soft filter, - // that's not we expected and the filter not support ac3 stream - // will cause mplayer die. - - // Although not support set volume, but at least we support mute. - // MPlayer set mute by set volume to zero, we handle it. - if (control_vol->left == 0 && control_vol->right == 0) - ao->b_muted = 1; - else - ao->b_muted = 0; - return CONTROL_TRUE; - } - - vol=(control_vol->left+control_vol->right)*4.0/200.0; - err = AudioUnitSetParameter(ao->theOutputUnit, kHALOutputParam_Volume, kAudioUnitScope_Global, 0, vol, 0); - if(err==0) { - // printf("SET VOL=%f\n", vol); - return CONTROL_TRUE; - } - else { - ao_msg(MSGT_AO, MSGL_WARN, "could not set HAL output volume: [%4.4s]\n", (char *)&err); - return CONTROL_FALSE; - } - /* Everything is currently unimplemented */ - default: - return CONTROL_FALSE; - } +static int control(struct ao *ao, enum aocontrol cmd, void *arg) +{ + struct priv *p = ao->priv; + ao_control_vol_t *control_vol; + OSStatus err; + Float32 vol; + switch (cmd) { + case AOCONTROL_GET_VOLUME: + control_vol = (ao_control_vol_t *)arg; + if (p->b_digital) { + // Digital output has no volume adjust. + int vol = p->b_muted ? 0 : 100; + *control_vol = (ao_control_vol_t) { + .left = vol, .right = vol, + }; + return CONTROL_TRUE; + } + err = AudioUnitGetParameter(p->theOutputUnit, kHALOutputParam_Volume, + kAudioUnitScope_Global, 0, &vol); + + if (err == 0) { + // printf("GET VOL=%f\n", vol); + control_vol->left = control_vol->right = vol * 100.0 / 4.0; + return CONTROL_TRUE; + } else { + ca_msg(MSGT_AO, MSGL_WARN, + "could not get HAL output volume: [%4.4s]\n", (char *)&err); + return CONTROL_FALSE; + } + + case AOCONTROL_SET_VOLUME: + control_vol = (ao_control_vol_t *)arg; + + if (p->b_digital) { + // Digital output can not set volume. Here we have to return true + // to make mixer forget it. Else mixer will add a soft filter, + // that's not we expected and the filter not support ac3 stream + // will cause mplayer die. + + // Although not support set volume, but at least we support mute. + // MPlayer set mute by set volume to zero, we handle it. + if (control_vol->left == 0 && control_vol->right == 0) + p->b_muted = 1; + else + p->b_muted = 0; + return CONTROL_TRUE; + } + + vol = (control_vol->left + control_vol->right) * 4.0 / 200.0; + err = AudioUnitSetParameter(p->theOutputUnit, kHALOutputParam_Volume, + kAudioUnitScope_Global, 0, vol, 0); + if (err == 0) { + // printf("SET VOL=%f\n", vol); + return CONTROL_TRUE; + } else { + ca_msg(MSGT_AO, MSGL_WARN, + "could not set HAL output volume: [%4.4s]\n", (char *)&err); + return CONTROL_FALSE; + } + /* Everything is currently unimplemented */ + default: + return CONTROL_FALSE; + } } -static void print_format(int lev, const char* str, const AudioStreamBasicDescription *f){ - uint32_t flags=(uint32_t) f->mFormatFlags; - ao_msg(MSGT_AO,lev, "%s %7.1fHz %"PRIu32"bit [%c%c%c%c][%"PRIu32"][%"PRIu32"][%"PRIu32"][%"PRIu32"][%"PRIu32"] %s %s %s%s%s%s\n", - str, f->mSampleRate, f->mBitsPerChannel, - (int)(f->mFormatID & 0xff000000) >> 24, - (int)(f->mFormatID & 0x00ff0000) >> 16, - (int)(f->mFormatID & 0x0000ff00) >> 8, - (int)(f->mFormatID & 0x000000ff) >> 0, - f->mFormatFlags, f->mBytesPerPacket, - f->mFramesPerPacket, f->mBytesPerFrame, - f->mChannelsPerFrame, - (flags&kAudioFormatFlagIsFloat) ? "float" : "int", - (flags&kAudioFormatFlagIsBigEndian) ? "BE" : "LE", - (flags&kAudioFormatFlagIsSignedInteger) ? "S" : "U", - (flags&kAudioFormatFlagIsPacked) ? " packed" : "", - (flags&kAudioFormatFlagIsAlignedHigh) ? " aligned" : "", - (flags&kAudioFormatFlagIsNonInterleaved) ? " ni" : "" ); +static void print_format(int lev, const char *str, + const AudioStreamBasicDescription *f) +{ + uint32_t flags = (uint32_t) f->mFormatFlags; + ca_msg(MSGT_AO, lev, + "%s %7.1fHz %" PRIu32 "bit [%c%c%c%c][%" PRIu32 "][%" PRIu32 "][%" PRIu32 "][%" PRIu32 "][%" PRIu32 "] %s %s %s%s%s%s\n", + str, f->mSampleRate, f->mBitsPerChannel, + (int)(f->mFormatID & 0xff000000) >> 24, + (int)(f->mFormatID & 0x00ff0000) >> 16, + (int)(f->mFormatID & 0x0000ff00) >> 8, + (int)(f->mFormatID & 0x000000ff) >> 0, + f->mFormatFlags, f->mBytesPerPacket, + f->mFramesPerPacket, f->mBytesPerFrame, + f->mChannelsPerFrame, + (flags & kAudioFormatFlagIsFloat) ? "float" : "int", + (flags & kAudioFormatFlagIsBigEndian) ? "BE" : "LE", + (flags & kAudioFormatFlagIsSignedInteger) ? "S" : "U", + (flags & kAudioFormatFlagIsPacked) ? " packed" : "", + (flags & kAudioFormatFlagIsAlignedHigh) ? " aligned" : "", + (flags & kAudioFormatFlagIsNonInterleaved) ? " ni" : ""); } static OSStatus GetAudioProperty(AudioObjectID id, @@ -252,7 +227,8 @@ static OSStatus GetAudioProperty(AudioObjectID id, property_address.mScope = kAudioObjectPropertyScopeGlobal; property_address.mElement = kAudioObjectPropertyElementMaster; - return AudioObjectGetPropertyData(id, &property_address, 0, NULL, &outSize, outData); + return AudioObjectGetPropertyData(id, &property_address, 0, NULL, &outSize, + outData); } static UInt32 GetAudioPropertyArray(AudioObjectID id, @@ -268,7 +244,8 @@ static UInt32 GetAudioPropertyArray(AudioObjectID id, property_address.mScope = scope; property_address.mElement = kAudioObjectPropertyElementMaster; - err = AudioObjectGetPropertyDataSize(id, &property_address, 0, NULL, &i_param_size); + err = AudioObjectGetPropertyDataSize(id, &property_address, 0, NULL, + &i_param_size); if (err != noErr) return 0; @@ -276,7 +253,8 @@ static UInt32 GetAudioPropertyArray(AudioObjectID id, *outData = malloc(i_param_size); - err = AudioObjectGetPropertyData(id, &property_address, 0, NULL, &i_param_size, *outData); + err = AudioObjectGetPropertyData(id, &property_address, 0, NULL, + &i_param_size, *outData); if (err != noErr) { free(*outData); @@ -290,7 +268,8 @@ static UInt32 GetGlobalAudioPropertyArray(AudioObjectID id, AudioObjectPropertySelector selector, void **outData) { - return GetAudioPropertyArray(id, selector, kAudioObjectPropertyScopeGlobal, outData); + return GetAudioPropertyArray(id, selector, kAudioObjectPropertyScopeGlobal, + outData); } static OSStatus GetAudioPropertyString(AudioObjectID id, @@ -308,14 +287,16 @@ static OSStatus GetAudioPropertyString(AudioObjectID id, property_address.mElement = kAudioObjectPropertyElementMaster; i_param_size = sizeof(CFStringRef); - err = AudioObjectGetPropertyData(id, &property_address, 0, NULL, &i_param_size, &string); + err = AudioObjectGetPropertyData(id, &property_address, 0, NULL, + &i_param_size, &string); if (err != noErr) return err; string_length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(string), kCFStringEncodingASCII); *outData = malloc(string_length + 1); - CFStringGetCString(string, *outData, string_length + 1, kCFStringEncodingASCII); + CFStringGetCString(string, *outData, string_length + 1, + kCFStringEncodingASCII); CFRelease(string); @@ -332,7 +313,8 @@ static OSStatus SetAudioProperty(AudioObjectID id, property_address.mScope = kAudioObjectPropertyScopeGlobal; property_address.mElement = kAudioObjectPropertyElementMaster; - return AudioObjectSetPropertyData(id, &property_address, 0, NULL, inDataSize, inData); + return AudioObjectSetPropertyData(id, &property_address, 0, NULL, + inDataSize, inData); } static Boolean IsAudioPropertySettable(AudioObjectID id, @@ -348,25 +330,26 @@ static Boolean IsAudioPropertySettable(AudioObjectID id, return AudioObjectIsPropertySettable(id, &property_address, outData); } -static int AudioDeviceSupportsDigital( AudioDeviceID i_dev_id ); -static int AudioStreamSupportsDigital( AudioStreamID i_stream_id ); -static int OpenSPDIF(void); -static int AudioStreamChangeFormat( AudioStreamID i_stream_id, AudioStreamBasicDescription change_format ); -static OSStatus RenderCallbackSPDIF( AudioDeviceID inDevice, - const AudioTimeStamp * inNow, - const void * inInputData, - const AudioTimeStamp * inInputTime, - AudioBufferList * outOutputData, - const AudioTimeStamp * inOutputTime, - void * threadGlobals ); -static OSStatus StreamListener( AudioObjectID inObjectID, - UInt32 inNumberAddresses, - const AudioObjectPropertyAddress inAddresses[], - void *inClientData ); -static OSStatus DeviceListener( AudioObjectID inObjectID, - UInt32 inNumberAddresses, - const AudioObjectPropertyAddress inAddresses[], - void *inClientData ); +static int AudioDeviceSupportsDigital(AudioDeviceID i_dev_id); +static int AudioStreamSupportsDigital(AudioStreamID i_stream_id); +static int OpenSPDIF(struct ao *ao); +static int AudioStreamChangeFormat(AudioStreamID i_stream_id, + AudioStreamBasicDescription change_format); +static OSStatus RenderCallbackSPDIF(AudioDeviceID inDevice, + const AudioTimeStamp *inNow, + const void *inInputData, + const AudioTimeStamp *inInputTime, + AudioBufferList *outOutputData, + const AudioTimeStamp *inOutputTime, + void *threadGlobals); +static OSStatus StreamListener(AudioObjectID inObjectID, + UInt32 inNumberAddresses, + const AudioObjectPropertyAddress inAddresses[], + void *inClientData); +static OSStatus DeviceListener(AudioObjectID inObjectID, + UInt32 inNumberAddresses, + const AudioObjectPropertyAddress inAddresses[], + void *inClientData); static void print_help(void) { @@ -388,7 +371,9 @@ static void print_help(void) "\n" "Available output devices:\n"); - i_param_size = GetGlobalAudioPropertyArray(kAudioObjectSystemObject, kAudioHardwarePropertyDevices, (void **)&devids); + i_param_size = GetGlobalAudioPropertyArray(kAudioObjectSystemObject, + kAudioHardwarePropertyDevices, + (void **)&devids); if (!i_param_size) { mp_msg(MSGT_AO, MSGL_FATAL, "Failed to get list of output devices.\n"); @@ -398,13 +383,16 @@ static void print_help(void) num_devices = i_param_size / sizeof(AudioDeviceID); for (int i = 0; i < num_devices; ++i) { - err = GetAudioPropertyString(devids[i], kAudioObjectPropertyName, &device_name); + err = GetAudioPropertyString(devids[i], kAudioObjectPropertyName, + &device_name); if (err == noErr) { - mp_msg(MSGT_AO, MSGL_FATAL, "%s (id: %"PRIu32")\n", device_name, devids[i]); + mp_msg(MSGT_AO, MSGL_FATAL, "%s (id: %" PRIu32 ")\n", device_name, + devids[i]); free(device_name); } else - mp_msg(MSGT_AO, MSGL_FATAL, "Unknown (id: %"PRIu32")\n", devids[i]); + mp_msg(MSGT_AO, MSGL_FATAL, "Unknown (id: %" PRIu32 ")\n", + devids[i]); } mp_msg(MSGT_AO, MSGL_FATAL, "\n"); @@ -412,21 +400,25 @@ static void print_help(void) free(devids); } -static int init(int rate,const struct mp_chmap *channels,int format,int flags) +static int init(struct ao *ao, char *params) { -AudioStreamBasicDescription inDesc; -AudioComponentDescription desc; -AudioComponent comp; -AURenderCallbackStruct renderCallback; -OSStatus err; -UInt32 size, maxFrames, b_alive; -char *psz_name; -AudioDeviceID devid_def = 0; -int device_id, display_help = 0; + // int rate, int channels, int format, int flags) + struct priv *p = talloc_zero(ao, struct priv); + ao->priv = p; + + AudioStreamBasicDescription inDesc; + AudioComponentDescription desc; + AudioComponent comp; + AURenderCallbackStruct renderCallback; + OSStatus err; + UInt32 size, maxFrames, b_alive; + char *psz_name; + AudioDeviceID devid_def = 0; + int device_id, display_help = 0; const opt_t subopts[] = { - {"device_id", OPT_ARG_INT, &device_id, NULL}, - {"help", OPT_ARG_BOOL, &display_help, NULL}, + {"device_id", OPT_ARG_INT, &device_id, NULL}, + {"help", OPT_ARG_BOOL, &display_help, NULL}, {NULL} }; @@ -439,32 +431,32 @@ int device_id, display_help = 0; return 0; } - ao_msg(MSGT_AO,MSGL_V, "init([%dHz][%dch][%s][%d])\n", rate, ao_data.channels.num, af_fmt2str_short(format), flags); + ca_msg(MSGT_AO, MSGL_V, "init([%dHz][%dch][%s][%d])\n", + ao->samplerate, ao->channels.num, af_fmt2str_short(ao->format), 0); - ao = calloc(1, sizeof(ao_coreaudio_t)); + p->i_selected_dev = 0; + p->b_supports_digital = 0; + p->b_digital = 0; + p->b_muted = 0; + p->b_stream_format_changed = 0; + p->i_hog_pid = -1; + p->i_stream_id = 0; + p->i_stream_index = -1; + p->b_revert = 0; + p->b_changed_mixing = 0; - ao->i_selected_dev = 0; - ao->b_supports_digital = 0; - ao->b_digital = 0; - ao->b_muted = 0; - ao->b_stream_format_changed = 0; - ao->i_hog_pid = -1; - ao->i_stream_id = 0; - ao->i_stream_index = -1; - ao->b_revert = 0; - ao->b_changed_mixing = 0; - - global_ao->per_application_mixer = true; - global_ao->no_persistent_volume = true; + ao->per_application_mixer = true; + ao->no_persistent_volume = true; if (device_id == 0) { /* Find the ID of the default Device. */ err = GetAudioProperty(kAudioObjectSystemObject, kAudioHardwarePropertyDefaultOutputDevice, sizeof(UInt32), &devid_def); - if (err != noErr) - { - ao_msg(MSGT_AO, MSGL_WARN, "could not get default audio device: [%4.4s]\n", (char *)&err); + if (err != noErr) { + ca_msg(MSGT_AO, MSGL_WARN, + "could not get default audio device: [%4.4s]\n", + (char *)&err); goto err_out; } } else { @@ -475,201 +467,219 @@ int device_id, display_help = 0; err = GetAudioPropertyString(devid_def, kAudioObjectPropertyName, &psz_name); - if (err != noErr) - { - ao_msg(MSGT_AO, MSGL_WARN, "could not get default audio device name: [%4.4s]\n", (c |