28 #import <AudioToolbox/AudioToolbox.h>
63 AudioQueueBufferRef inBuffer)
67 for (
int i = 0;
i < 2;
i++) {
68 if (inBuffer ==
ctx->buffer[
i]) {
78 CFStringRef device_UID =
NULL;
79 AudioDeviceID *devices;
85 AudioObjectPropertyAddress prop;
86 prop.mSelector = kAudioHardwarePropertyDevices;
87 prop.mScope = kAudioObjectPropertyScopeGlobal;
88 #
if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000
89 prop.mElement = kAudioObjectPropertyElementMain;
91 prop.mElement = kAudioObjectPropertyElementMaster;
93 err = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0,
NULL, &data_size);
94 if (
check_status(avctx, &err,
"AudioObjectGetPropertyDataSize devices"))
97 num_devices = data_size /
sizeof(AudioDeviceID);
99 devices = (AudioDeviceID*)(
av_malloc(data_size));
100 err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0,
NULL, &data_size, devices);
101 if (
check_status(avctx, &err,
"AudioObjectGetPropertyData devices")) {
107 if (
ctx->list_devices) {
108 CFStringRef device_name =
NULL;
109 prop.mScope = kAudioDevicePropertyScopeInput;
112 for(UInt32
i = 0;
i < num_devices; ++
i) {
114 data_size =
sizeof(device_UID);
115 prop.mSelector = kAudioDevicePropertyDeviceUID;
116 err = AudioObjectGetPropertyData(devices[
i], &prop, 0,
NULL, &data_size, &device_UID);
117 if (
check_status(avctx, &err,
"AudioObjectGetPropertyData UID"))
121 data_size =
sizeof(device_name);
122 prop.mSelector = kAudioDevicePropertyDeviceNameCFString;
123 err = AudioObjectGetPropertyData(devices[
i], &prop, 0,
NULL, &data_size, &device_name);
124 if (
check_status(avctx, &err,
"AudioObjecTGetPropertyData name"))
128 CFStringGetCStringPtr(device_name, kCFStringEncodingMacRoman),
129 CFStringGetCStringPtr(device_UID, kCFStringEncodingMacRoman));
135 const char *stream_name = avctx->
url;
136 if (stream_name &&
ctx->audio_device_index == -1) {
137 sscanf(stream_name,
"%d", &
ctx->audio_device_index);
140 if (
ctx->audio_device_index >= 0) {
142 data_size =
sizeof(device_UID);
143 prop.mSelector = kAudioDevicePropertyDeviceUID;
144 err = AudioObjectGetPropertyData(devices[
ctx->audio_device_index], &prop, 0,
NULL, &data_size, &device_UID);
145 if (
check_status(avctx, &err,
"AudioObjecTGetPropertyData UID")) {
156 av_log(
ctx,
AV_LOG_DEBUG,
"UID: %s\n", CFStringGetCStringPtr(device_UID, kCFStringEncodingMacRoman));
168 AudioStreamBasicDescription device_format = {0};
170 device_format.mFormatID = kAudioFormatLinearPCM;
183 device_format.mBytesPerFrame = (device_format.mBitsPerChannel >> 3) * device_format.mChannelsPerFrame;
184 device_format.mFramesPerPacket = 1;
185 device_format.mBytesPerPacket = device_format.mBytesPerFrame * device_format.mFramesPerPacket;
186 device_format.mReserved = 0;
210 NULL, kCFRunLoopCommonModes,
213 if (err == kAudioFormatUnsupportedDataFormatError)
219 if (device_UID !=
NULL) {
220 err = AudioQueueSetProperty(
ctx->queue, kAudioQueueProperty_CurrentDevice, &device_UID,
sizeof(device_UID));
221 if (
check_status(avctx, &err,
"AudioQueueSetProperty output UID"))
226 err = AudioQueueStart(
ctx->queue,
NULL);
240 OSStatus err = noErr;
243 ctx->cur_buf = !
ctx->cur_buf;
250 if (!
ctx->buffer[
ctx->cur_buf] ||
ctx->buffer[
ctx->cur_buf]->mAudioDataBytesCapacity !=
pkt->
size) {
251 err = AudioQueueAllocateBuffer(
ctx->queue,
pkt->
size, &
ctx->buffer[
ctx->cur_buf]);
252 if (
check_status(avctx, &err,
"AudioQueueAllocateBuffer")) {
258 AudioQueueBufferRef buf =
ctx->buffer[ctx->
cur_buf];
261 memcpy(buf->mAudioData,
pkt->
data, buf->mAudioDataBytesCapacity);
262 buf->mAudioDataByteSize = buf->mAudioDataBytesCapacity;
263 err = AudioQueueEnqueueBuffer(
ctx->queue, buf, 0,
NULL);
264 if (
check_status(avctx, &err,
"AudioQueueEnqueueBuffer")) {
275 OSStatus err = noErr;
280 err = AudioQueueFlush(
ctx->queue);
282 err = AudioQueueDispose(
ctx->queue,
true);
303 .
p.
name =
"audiotoolbox",