Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 27th, 2012  |  syntax: None  |  size: 2.71 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Dynamically detecting and streaming AAC using AQ's and audiofilestream
  2. // the file stream parser is now ready to produce audio packets.
  3. // get the stream format.
  4. AudioFormatListItem afli = GetFirstPlayableAudioFormatForFile(inAudioFileStream);
  5. AudioStreamBasicDescription asbd = afli.mASBD;
  6. ...
  7. // create the audio queue
  8. err = AudioQueueNewOutput(&asbd, MyAudioQueueOutputCallback, myData, NULL, NULL, 0, &myData->audioQueue);
  9.        
  10. AudioFormatListItem GetFirstPlayableAudioFormatForFile(AudioFileStreamID inAudioFileStream)
  11. {
  12.     AudioFormatListItem *formatListPtr = NULL;
  13.     AudioFormatListItem formatItem = {0};
  14.     UInt32 propertySize;
  15.  
  16.     OSStatus status = noErr;
  17.  
  18.     if (NULL == inAudioFileStream) return formatItem;
  19.  
  20.     status = AudioFileStreamGetPropertyInfo(inAudioFileStream, kAudioFileStreamProperty_FormatList, &propertySize, NULL);
  21.     if (noErr == status) {
  22.  
  23.         // allocate memory for the format list items
  24.         formatListPtr = (AudioFormatListItem *)malloc(propertySize);
  25.         if (NULL == formatListPtr) return formatItem;
  26.  
  27.         // get the list of Audio Format List Item's
  28.         status = AudioFileStreamGetProperty(inAudioFileStream, kAudioFileStreamProperty_FormatList, &propertySize, formatListPtr);
  29.         if (noErr == status) {
  30.             // print out some helpful information
  31.             UInt32 numFormats = propertySize / sizeof(AudioFormatListItem);
  32.             printf ("This file has a %d layered data format:n", (int)numFormats);
  33.             /*for (unsigned int i = 0; i < numFormats; ++i) {
  34.                 CAStreamBasicDescription(formatListPtr[i].mASBD).Print();
  35.             }*/
  36.  
  37.             UInt32 itemIndex;
  38.             UInt32 indexSize = sizeof(itemIndex);
  39.  
  40.             // get the index number of the first playable format -- this index number will be for
  41.             // the highest quality layer the platform is capable of playing
  42.             status = AudioFormatGetProperty(kAudioFormatProperty_FirstPlayableFormatFromList, propertySize,
  43.                                             formatListPtr, &indexSize, &itemIndex);
  44.             if (noErr == status) {
  45.                 printf ("Returning AudioFormatListItem at index %d.n", (int)itemIndex);
  46.                 // copy the format item at index we want returned
  47.                 formatItem =  formatListPtr[itemIndex];
  48.             }
  49.         }
  50.  
  51.         free(formatListPtr);
  52.     } else {
  53.         AudioStreamBasicDescription asbd;
  54.         UInt32 asbdSize = sizeof(asbd);
  55.         /*status = */AudioFileStreamGetProperty(inAudioFileStream, kAudioFileStreamProperty_DataFormat, &asbdSize, &asbd);
  56.         //if (err) { errorDidOccur(myData, err, @"get kAudioFileStreamProperty_DataFormat"); return err; }
  57.  
  58.         formatItem.mASBD = asbd;
  59.     }
  60.  
  61.  
  62.     return formatItem;
  63. }