void Audio_Queue::handlePropertyChange(AudioFileStreamID inAudioFileStream, AudioFileStreamPropertyID inPropertyID, UInt32 *ioFlags) { OSStatus err = noErr; AQ_TRACE("found property '%lu%lu%lu%lu'\n", (inPropertyID>>24)&255, (inPropertyID>>16)&255, (inPropertyID>>8)&255, inPropertyID&255); switch (inPropertyID) { case kAudioFileStreamProperty_ReadyToProducePackets: { // the file stream parser is now ready to produce audio packets. // get the stream format. AudioStreamBasicDescription asbd; memset(&asbd, 0, sizeof(asbd)); UInt32 asbdSize = sizeof(asbd); err = AudioFileStreamGetProperty(inAudioFileStream, kAudioFileStreamProperty_DataFormat, &asbdSize, &asbd); if (err) { AQ_TRACE("get kAudioFileStreamProperty_DataFormat\n"); m_lastError = err; break; } // create the audio queue err = AudioQueueNewOutput(&asbd, audioQueueOutputCallback, this, NULL, NULL, 0, &m_outAQ); if (err) { AQ_TRACE("AudioQueueNewOutput\n"); m_lastError = err; break; } // allocate audio queue buffers for (unsigned int i = 0; i < AQ_BUFFERS; ++i) { err = AudioQueueAllocateBuffer(m_outAQ, AQ_BUFSIZ, &m_audioQueueBuffer[i]); if (err) { AQ_TRACE("AudioQueueAllocateBuffer\n"); m_lastError = err; break; } } setCookiesForStream(inAudioFileStream); // listen for kAudioQueueProperty_IsRunning err = AudioQueueAddPropertyListener(m_outAQ, kAudioQueueProperty_IsRunning, audioQueueIsRunningCallback, this); if (err) { AQ_TRACE("error in AudioQueueAddPropertyListener"); m_lastError = err; break; } break; } } }
void Audio_Queue::handlePropertyChange(AudioFileStreamID inAudioFileStream, AudioFileStreamPropertyID inPropertyID, UInt32 *ioFlags) { OSStatus err = noErr; AQ_TRACE("found property '%lu%lu%lu%lu'\n", (inPropertyID>>24)&255, (inPropertyID>>16)&255, (inPropertyID>>8)&255, inPropertyID&255); switch (inPropertyID) { case kAudioFileStreamProperty_ReadyToProducePackets: { cleanup(); // the file stream parser is now ready to produce audio packets. // get the stream format. memset(&m_streamDesc, 0, sizeof(m_streamDesc)); UInt32 asbdSize = sizeof(m_streamDesc); err = AudioFileStreamGetProperty(inAudioFileStream, kAudioFileStreamProperty_DataFormat, &asbdSize, &m_streamDesc); if (err) { AQ_TRACE("%s: error in kAudioFileStreamProperty_DataFormat\n", __PRETTY_FUNCTION__); m_lastError = err; break; } // create the audio queue err = AudioQueueNewOutput(&m_streamDesc, audioQueueOutputCallback, this, CFRunLoopGetCurrent(), NULL, 0, &m_outAQ); if (err) { AQ_TRACE("%s: error in AudioQueueNewOutput\n", __PRETTY_FUNCTION__); if (m_delegate) { m_delegate->audioQueueInitializationFailed(); } m_lastError = err; break; } // allocate audio queue buffers for (unsigned int i = 0; i < AQ_BUFFERS; ++i) { err = AudioQueueAllocateBuffer(m_outAQ, AQ_BUFSIZ, &m_audioQueueBuffer[i]); if (err) { /* If allocating the buffers failed, everything else will fail, too. * Dispose the queue so that we can later on detect that this * queue in fact has not been initialized. */ AQ_TRACE("%s: error in AudioQueueAllocateBuffer\n", __PRETTY_FUNCTION__); (void)AudioQueueDispose(m_outAQ, true); m_outAQ = 0; if (m_delegate) { m_delegate->audioQueueInitializationFailed(); } m_lastError = err; break; } } setCookiesForStream(inAudioFileStream); // listen for kAudioQueueProperty_IsRunning err = AudioQueueAddPropertyListener(m_outAQ, kAudioQueueProperty_IsRunning, audioQueueIsRunningCallback, this); if (err) { AQ_TRACE("%s: error in AudioQueueAddPropertyListener\n", __PRETTY_FUNCTION__); m_lastError = err; break; } break; } } }