void MyPropertyListenerProc(void *inUserData,
AudioFileStreamID inAudioFileStream,
AudioFileStreamPropertyID inPropertyID,
UInt32 *ioFlags) {
BMHttpAudioStreamManager *manager = (__bridge BMHttpAudioStreamManager*) inUserData;
[manager myPropertyListenerProcForStreamID:inAudioFileStream forPropertyID:inPropertyID forIOFlags:ioFlags];
}
- (void) myPropertyListenerProcForStreamID:(AudioFileStreamID) inAudioFileStream
forPropertyID:(AudioFileStreamPropertyID) inPropertyID
forIOFlags:(UInt32 *) ioFlags {
// this is called by audio file stream when it finds property values
OSStatus err = noErr;
printf("found property '%c%c%c%c'\n", (char)(inPropertyID>>24)&255, (char)(inPropertyID>>16)&255, (char)(inPropertyID>>8)&255, (char)inPropertyID&255);
switch (inPropertyID) {
case kAudioFileStreamProperty_ReadyToProducePackets:{
// the file stream parser is now ready to produce audio packets.
// get the stream format.
AudioStreamBasicDescription asbd;
UInt32 asbdSize = sizeof(asbd);
err = AudioFileStreamGetProperty(inAudioFileStream, kAudioFileStreamProperty_DataFormat, &asbdSize, &asbd);
if (err) {
PRINTERROR("get kAudioFileStreamProperty_DataFormat");
_audioData->failed = true;
return;
}
// create the audio queue
err = AudioQueueNewOutput(&asbd, MyAudioQueueOutputCallback, (__bridge void *)(self), NULL, NULL, 0, &(_audioData->audioQueue));
if (err) { PRINTERROR("AudioQueueNewOutput");
#warning ERROR 1718449215 is printed here: kAudioFormatUnsupportedDataFormatError
_audioData->failed = true;
return;
}
// allocate audio queue buffers
for (unsigned int i = 0; i < kNumAQBufs; ++i) {
err = AudioQueueAllocateBuffer(_audioData->audioQueue, kAQBufSize, &_audioData->audioQueueBuffer[i]);
if (err) { PRINTERROR("AudioQueueAllocateBuffer");
_audioData->failed = true;
break;
}
}
// get the cookie size
UInt32 cookieSize;
Boolean writable;
err = AudioFileStreamGetPropertyInfo(inAudioFileStream, kAudioFileStreamProperty_MagicCookieData, &cookieSize, &writable);
if (err) {
PRINTERROR("ERROR: info kAudioFileStreamProperty_MagicCookieData");
NSLog(@"Error %@ occured, with code %d", [self checkstatus:err], err);
return;
}
printf("cookieSize %d\n", (unsigned int)cookieSize);
// get the cookie data
void* cookieData = calloc(1, cookieSize);
err = AudioFileStreamGetProperty(inAudioFileStream, kAudioFileStreamProperty_MagicCookieData, &cookieSize, cookieData);
if (err == noErr) {
PRINTERROR("get kAudioFileStreamProperty_MagicCookieData");
NSLog(@"%@", [self checkstatus:err]);
free(cookieData);
return;
}
// set the cookie on the queue.
err = AudioQueueSetProperty(_audioData->audioQueue, kAudioQueueProperty_MagicCookie, cookieData, cookieSize);
free(cookieData);
if (err) {
PRINTERROR("set kAudioQueueProperty_MagicCookie");
NSLog(@"%@", [self checkstatus:err]);
return;
}
// listen for kAudioQueueProperty_IsRunning
err = AudioQueueAddPropertyListener(_audioData->audioQueue, kAudioQueueProperty_IsRunning, MyAudioQueueIsRunningCallback, _audioData);
if (err) { PRINTERROR("AudioQueueAddPropertyListener");
NSLog(@"%@", [self checkstatus:err]);
_audioData->failed = true;
break;
}
}
case kAudioFileStreamProperty_DataOffset:{
// if (inPropertyID == kAudioFileStreamProperty_DataOffset) {
SInt64 offset;
UInt32 offsetSize = sizeof(offset);
err = AudioFileStreamGetProperty(inAudioFileStream,
kAudioFileStreamProperty_DataOffset,
&offsetSize,
&offset);
if (dataOffset == 0) {
dataOffset = offset;
}
else {
NSLog(@"offset");
}
if (err)
NSLog(@"get kAudioFileStreamProperty_DataOffset failed: %d", err);
break;
}
case kAudioFileStreamProperty_DataFormat:
case kAudioFileStreamProperty_FileFormat:
break;
default:
{
/*NSLog(@"Audio stream unhandled property change: %c%c%c%c",
(propertyID>>24)&255,
(propertyID>>16)&255,
(propertyID>>8)&255,
propertyID&255);*/
}
}
}
Comments
0 B
|👍
/👎
0 B
|👍
/👎