summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2013-04-18 21:25:02 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2013-06-16 18:20:38 +0200
commit74eb98279a7ed94804bad683fdbdad7abcad1835 (patch)
treecdca0107d84ec9fbf81c78f279d46993a806266c
parentfee0b990475fad20a40711ecbe2926070a67af2b (diff)
downloadmpv-74eb98279a7ed94804bad683fdbdad7abcad1835.tar.bz2
mpv-74eb98279a7ed94804bad683fdbdad7abcad1835.tar.xz
ao_coreaudio: uncrustify
uncrustify -l C -c TOOLS/uncrustify.cfg --no-backup --replace \ audio/out/ao_coreaudio.c
-rw-r--r--audio/out/ao_coreaudio.c1044
1 files changed, 553 insertions, 491 deletions
diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c
index bec849d8ca..6389cbec6f 100644
--- a/audio/out/ao_coreaudio.c
+++ b/audio/out/ao_coreaudio.c
@@ -56,17 +56,17 @@
#include "core/subopt-helper.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)
+#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
@@ -78,42 +78,42 @@ static OSStatus AudioDeviceCreateIOProcID(AudioDeviceID dev,
void *data,
AudioDeviceIOProcID *procid)
{
- *procid = proc;
- return AudioDeviceAddIOProc(dev, proc, data);
+ *procid = proc;
+ return AudioDeviceAddIOProc(dev, proc, data);
}
#endif
typedef struct ao_coreaudio_s
{
- 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;
+ 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;
@@ -121,23 +121,27 @@ 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);
+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);
}
/**
* \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;
+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;
}
static OSStatus theRenderProc(void *inRefCon,
@@ -146,100 +150,107 @@ static OSStatus theRenderProc(void *inRefCon,
UInt32 inBusNumber, UInt32 inNumFrames,
AudioBufferList *ioData)
{
-int amt=av_fifo_size(ao->buffer);
-int req=(inNumFrames)*ao->packetSize;
+ int amt = av_fifo_size(ao->buffer);
+ int req = (inNumFrames) * ao->packetSize;
- if(amt>req)
- amt=req;
+ if (amt > req)
+ amt = req;
- if(amt)
- read_buffer((unsigned char *)ioData->mBuffers[0].mData, amt);
- else audio_pause();
- ioData->mBuffers[0].mDataByteSize = amt;
+ if (amt)
+ read_buffer((unsigned char *)ioData->mBuffers[0].mData, amt);
+ else
+ audio_pause();
+ ioData->mBuffers[0].mDataByteSize = amt;
- 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(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 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;
+ 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 OSStatus GetAudioProperty(AudioObjectID id,
@@ -252,7 +263,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 +280,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 +289,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 +304,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 +323,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 +349,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 +366,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 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 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 +407,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 +419,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 +436,21 @@ static void print_help(void)
free(devids);
}
-static int init(int rate,const struct mp_chmap *channels,int format,int flags)
+static int init(int rate, const struct mp_chmap *channels, int format, int flags)
{
-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;
+ 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,7 +463,8 @@ 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);
+ ao_msg(MSGT_AO,MSGL_V, "init([%dHz][%dch][%s][%d])\n",
+ rate, ao_data.channels.num, af_fmt2str_short(format), flags);
ao = calloc(1, sizeof(ao_coreaudio_t));
@@ -462,36 +487,37 @@ int device_id, display_help = 0;
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) {
+ ao_msg(MSGT_AO, MSGL_WARN,
+ "could not get default audio device: [%4.4s]\n",
+ (char *)&err);
goto err_out;
}
- } else {
+ } else
devid_def = device_id;
- }
/* Retrieve the name of the device. */
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", (char *)&err);
+ if (err != noErr) {
+ ao_msg(MSGT_AO, MSGL_WARN,
+ "could not get default audio device name: [%4.4s]\n",
+ (char *)&err);
goto err_out;
}
- ao_msg(MSGT_AO,MSGL_V, "got audio output device ID: %"PRIu32" Name: %s\n", devid_def, psz_name );
+ ao_msg(MSGT_AO, MSGL_V,
+ "got audio output device ID: %" PRIu32 " Name: %s\n", devid_def,
+ psz_name);
/* Probe whether device support S/PDIF stream output if input is AC3 stream. */
if (AF_FORMAT_IS_AC3(format)) {
if (AudioDeviceSupportsDigital(devid_def))
- {
ao->b_supports_digital = 1;
- }
ao_msg(MSGT_AO, MSGL_V,
"probe default audio output device about support for digital s/pdif output: %d\n",
- ao->b_supports_digital );
+ ao->b_supports_digital);
}
free(psz_name);
@@ -504,133 +530,160 @@ int device_id, display_help = 0;
if (!ao_chmap_sel_adjust(&ao_data, &chmap_sel, &ao_data.channels))
goto err_out;
- // Build Description for the input format
- inDesc.mSampleRate=rate;
- inDesc.mFormatID=ao->b_supports_digital ? kAudioFormat60958AC3 : kAudioFormatLinearPCM;
- inDesc.mChannelsPerFrame=ao_data.channels.num;
- inDesc.mBitsPerChannel=af_fmt2bits(format);
-
- if((format&AF_FORMAT_POINT_MASK)==AF_FORMAT_F) {
- // float
- inDesc.mFormatFlags = kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked;
- }
- else if((format&AF_FORMAT_SIGN_MASK)==AF_FORMAT_SI) {
- // signed int
- inDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger|kAudioFormatFlagIsPacked;
- }
- else {
- // unsigned int
- inDesc.mFormatFlags = kAudioFormatFlagIsPacked;
+ // Build Description for the input format
+ inDesc.mSampleRate = rate;
+ inDesc.mFormatID =
+ ao->b_supports_digital ? kAudioFormat60958AC3 : kAudioFormatLinearPCM;
+ inDesc.mChannelsPerFrame = ao_data.channels.num;
+ inDesc.mBitsPerChannel = af_fmt2bits(format);
+
+ if ((format & AF_FORMAT_POINT_MASK) == AF_FORMAT_F) {
+ // float
+ inDesc.mFormatFlags = kAudioFormatFlagIsFloat |
+ kAudioFormatFlagIsPacked;
+ } else if ((format & AF_FORMAT_SIGN_MASK) == AF_FORMAT_SI) {
+ // signed int
+ inDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger |
+ kAudioFormatFlagIsPacked;
+ } else {
+ // unsigned int
+ inDesc.mFormatFlags = kAudioFormatFlagIsPacked;
}
if ((format & AF_FORMAT_END_MASK) == AF_FORMAT_BE)
inDesc.mFormatFlags |= kAudioFormatFlagIsBigEndian;
inDesc.mFramesPerPacket = 1;
- ao->packetSize = inDesc.mBytesPerPacket = inDesc.mBytesPerFrame = inDesc.mFramesPerPacket*ao_data.channels.num*(inDesc.mBitsPerChannel/8);
- print_format(MSGL_V, "source:",&inDesc);
+ ao->packetSize = inDesc.mBytesPerPacket = inDesc.mBytesPerFrame =
+ inDesc.mFramesPerPacket *
+ ao_data.channels.num *
+ (inDesc.mBitsPerChannel / 8);
+ print_format(MSGL_V, "source:", &inDesc);
- if (ao->b_supports_digital)
- {
+ if (ao->b_supports_digital) {
b_alive = 1;
err = GetAudioProperty(ao->i_selected_dev,
kAudioDevicePropertyDeviceIsAlive,
sizeof(UInt32), &b_alive);
if (err != noErr)
- ao_msg(MSGT_AO, MSGL_WARN, "could not check whether device is alive: [%4.4s]\n", (char *)&err);
+ ao_msg(MSGT_AO, MSGL_WARN,
+ "could not check whether device is alive: [%4.4s]\n",
+ (char *)&err);
if (!b_alive)
- ao_msg(MSGT_AO, MSGL_WARN, "device is not alive\n" );
+ ao_msg(MSGT_AO, MSGL_WARN, "device is not alive\n");
/* S/PDIF output need device in HogMode. */
err = GetAudioProperty(ao->i_selected_dev,
kAudioDevicePropertyHogMode,
sizeof(pid_t), &ao->i_hog_pid);
- if (err != noErr)
- {
+ if (err != noErr) {
/* This is not a fatal error. Some drivers simply don't support this property. */
- ao_msg(MSGT_AO, MSGL_WARN, "could not check whether device is hogged: [%4.4s]\n",
- (char *)&err);
+ ao_msg(MSGT_AO, MSGL_WARN,
+ "could not check whether device is hogged: [%4.4s]\n",
+ (char *)&err);
ao->i_hog_pid = -1;
}
- if (ao->i_hog_pid != -1 && ao->i_hog_pid != getpid())
- {
- ao_msg(MSGT_AO, MSGL_WARN, "Selected audio device is exclusively in use by another program.\n" );
+ if (ao->i_hog_pid != -1 && ao->i_hog_pid != getpid()) {
+ ao_msg(MSGT_AO, MSGL_WARN,
+ "Selected audio device is exclusively in use by another program.\n");
goto err_out;
}
ao->stream_format = inDesc;
return OpenSPDIF();
}
- /* original analog output code */
- desc.componentType = kAudioUnitType_Output;
- desc.componentSubType = (device_id == 0) ? kAudioUnitSubType_DefaultOutput : kAudioUnitSubType_HALOutput;
- desc.componentManufacturer = kAudioUnitManufacturer_Apple;
- desc.componentFlags = 0;
- desc.componentFlagsMask = 0;
-
- comp = AudioComponentFindNext(NULL, &desc); //Finds an component that meets the desc spec's
- if (comp == NULL) {
- ao_msg(MSGT_AO, MSGL_WARN, "Unable to find Output Unit component\n");
- goto err_out;
- }
-
- err = AudioComponentInstanceNew(comp, &(ao->theOutputUnit)); //gains access to the services provided by the component
- if (err) {
- ao_msg(MSGT_AO, MSGL_WARN, "Unable to open Output Unit component: [%4.4s]\n", (char *)&err);
- goto err_out;
- }
-
- // Initialize AudioUnit
- err = AudioUnitInitialize(ao->theOutputUnit);
- if (err) {
- ao_msg(MSGT_AO, MSGL_WARN, "Unable to initialize Output Unit component: [%4.4s]\n", (char *)&err);
- goto err_out1;
- }
-
- size = sizeof(AudioStreamBasicDescription);
- err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &inDesc, size);
-
- if (err) {
- ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the input format: [%4.4s]\n", (char *)&err);
- goto err_out2;
- }
-
- size = sizeof(UInt32);
- err = AudioUnitGetProperty(ao->theOutputUnit, kAudioDevicePropertyBufferSize, kAudioUnitScope_Input, 0, &maxFrames, &size);
-
- if (err)
- {
- ao_msg(MSGT_AO,MSGL_WARN, "AudioUnitGetProperty returned [%4.4s] when getting kAudioDevicePropertyBufferSize\n", (char *)&err);
- goto err_out2;
- }
-
- //Set the Current Device to the Default Output Unit.
- err = AudioUnitSetProperty(ao->theOutputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &ao->i_selected_dev, sizeof(ao->i_selected_dev));
-
- ao->chunk_size = maxFrames;//*inDesc.mBytesPerFrame;
-
- ao_data.samplerate = inDesc.mSampleRate;
- if (!ao_chmap_sel_get_def(&ao_data, &chmap_sel, &ao_data.channels, inDesc.mChannelsPerFrame))
- goto err_out2;
+ /* original analog output code */
+ desc.componentType = kAudioUnitType_Output;
+ desc.componentSubType =
+ (device_id ==
+ 0) ? kAudioUnitSubType_DefaultOutput : kAudioUnitSubType_HALOutput;
+ desc.componentManufacturer = kAudioUnitManufacturer_Apple;
+ desc.componentFlags = 0;
+ desc.componentFlagsMask = 0;
+
+ comp = AudioComponentFindNext(NULL, &desc); //Finds an component that meets the desc spec's
+ if (comp == NULL) {
+ ao_msg(MSGT_AO, MSGL_WARN, "Unable to find Output Unit component\n");
+ goto err_out;
+ }
+
+ err = AudioComponentInstanceNew(comp, &(ao->theOutputUnit)); //gains access to the services provided by the component
+ if (err) {
+ ao_msg(MSGT_AO, MSGL_WARN,
+ "Unable to open Output Unit component: [%4.4s]\n", (char *)&err);
+ goto err_out;
+ }
+
+ // Initialize AudioUnit
+ err = AudioUnitInitialize(ao->theOutputUnit);
+ if (err) {
+ ao_msg(MSGT_AO, MSGL_WARN,
+ "Unable to initialize Output Unit component: [%4.4s]\n",
+ (char *)&err);
+ goto err_out1;
+ }
+
+ size = sizeof(AudioStreamBasicDescription);
+ err = AudioUnitSetProperty(ao->theOutputUnit,
+ kAudioUnitProperty_StreamFormat,
+ kAudioUnitScope_Input, 0, &inDesc, size);
+
+ if (err) {
+ ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the input format: [%4.4s]\n",
+ (char *)&err);
+ goto err_out2;
+ }
+
+ size = sizeof(UInt32);
+ err = AudioUnitGetProperty(ao->theOutputUnit,
+ kAudioDevicePropertyBufferSize,
+ kAudioUnitScope_Input, 0, &maxFrames, &size);
+
+ if (err) {
+ ao_msg(MSGT_AO, MSGL_WARN,
+ "AudioUnitGetProperty returned [%4.4s] when getting kAudioDevicePropertyBufferSize\n",
+ (char *)&err);
+ goto err_out2;
+ }
+
+ //Set the Current Device to the Default Output Unit.
+ err = AudioUnitSetProperty(ao->theOutputUnit,
+ kAudioOutputUnitProperty_CurrentDevice,
+ kAudioUnitScope_Global, 0, &ao->i_selected_dev,
+ sizeof(ao->i_selected_dev));
+
+ ao->chunk_size = maxFrames; //*inDesc.mBytesPerFrame;
+
+ ao_data.samplerate = inDesc.mSampleRate;
+ if (!ao_chmap_sel_get_def(&ao_data, &chmap_sel, &ao_data.channels,
+ inDesc.mChannelsPerFrame))
+ goto err_out2;
+ ao_data.channels.num = inDesc.mChannelsPerFrame;
ao_data.bps = ao_data.samplerate * inDesc.mBytesPerFrame;
ao_data.outburst = ao->chunk_size;
- ao_data.buffersize = ao_data.bps;
+ ao_data.buffersize = ao_data.bps;
- ao->num_chunks = (ao_data.bps+ao->chunk_size-1)/ao->chunk_size;
+ ao->num_chunks = (ao_data.bps + ao->chunk_size - 1) / ao->chunk_size;
ao->buffer_len = ao->num_chunks * ao->chunk_size;
ao->buffer = av_fifo_alloc(ao->buffer_len);
- ao_msg(MSGT_AO,MSGL_V, "using %5d chunks of %d bytes (buffer len %d bytes)\n", (int)ao->num_chunks, (int)ao->chunk_size, (int)ao->buffer_len);
+ ao_msg(MSGT_AO, MSGL_V,
+ "using %5d chunks of %d bytes (buffer len %d bytes)\n",
+ (int)ao->num_chunks, (int)ao->chunk_size, (int)ao->buffer_len);
renderCallback.inputProc = theRenderProc;
renderCallback.inputProcRefCon = 0;
- err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &renderCallback, sizeof(AURenderCallbackStruct));
- if (err) {
- ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the render callback: [%4.4s]\n", (char *)&err);
- goto err_out2;
- }
+ err = AudioUnitSetProperty(ao->theOutputUnit,
+ kAudioUnitProperty_SetRenderCallback,
+ kAudioUnitScope_Input, 0, &renderCallback,
+ sizeof(AURenderCallbackStruct));
+ if (err) {
+ ao_msg(MSGT_AO, MSGL_WARN,
+ "Unable to set the render callback: [%4.4s]\n", (char *)&err);
+ goto err_out2;
+ }
- reset();
+ reset();
return CONTROL_OK;
@@ -646,29 +699,29 @@ err_out:
}
/*****************************************************************************
- * Setup a encoded digital stream (SPDIF)
- *****************************************************************************/
+* Setup a encoded digital stream (SPDIF)
+*****************************************************************************/
static int OpenSPDIF(void)
{
- OSStatus err = noErr;
- UInt32 i_param_size, b_mix = 0;
- Boolean b_writeable = 0;
- AudioStreamID *p_streams = NULL;
- int i, i_streams = 0;
- AudioObjectPropertyAddress property_address;
+ OSStatus err = noErr;
+ UInt32 i_param_size, b_mix = 0;
+ Boolean b_writeable = 0;
+ AudioStreamID *p_streams = NULL;
+ int i, i_streams = 0;
+ AudioObjectPropertyAddress property_address;
/* Start doing the SPDIF setup process. */
ao->b_digital = 1;
/* Hog the device. */
- ao->i_hog_pid = getpid() ;
+ ao->i_hog_pid = getpid();
err = SetAudioProperty(ao->i_selected_dev,
kAudioDevicePropertyHogMode,
sizeof(ao->i_hog_pid), &ao->i_hog_pid);
- if (err != noErr)
- {
- ao_msg(MSGT_AO, MSGL_WARN, "failed to set hogmode: [%4.4s]\n", (char *)&err);
+ if (err != noErr) {
+ ao_msg(MSGT_AO, MSGL_WARN, "failed to set hogmode: [%4.4s]\n",
+ (char *)&err);
ao->i_hog_pid = -1;
goto err_out;
<