redribben

callback

Feb 9th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void ReadStreamClientCallBack(CFReadStreamRef   stream,
  2.                           CFStreamEventType     type,
  3.                           void*                 clientCallBackInfo) {
  4.     BMHttpAudioStreamManager *manager = (__bridge BMHttpAudioStreamManager*) clientCallBackInfo;
  5.     [manager readStreamClientCallBackWithData:stream withType:type];
  6. }
  7.  
  8. - (void) readStreamClientCallBackWithData:(CFReadStreamRef) stream
  9.                                  withType:(CFStreamEventType) type {
  10.    
  11.     if(type == kCFStreamEventHasBytesAvailable) {
  12.         UInt8 buffer[2048];
  13.         CFIndex bytesRead = CFReadStreamRead(stream, buffer, sizeof(buffer));
  14.        
  15.         if (bytesRead < 0) {
  16.             //nothing
  17.         }
  18.         // If zero bytes were read, wait for the EOF to come.
  19.         else if (bytesRead) {
  20.             // parse the data. this will call MyPropertyListenerProc and MyPacketsProc
  21.             // AudioFileStreamParseBytes function called when you have data to pass to the parser.
  22.             // Send the data to the parser sequentially and, if possible, without gaps.
  23.             OSStatus err = AudioFileStreamParseBytes(_audioData->audioFileStream, bytesRead, buffer, 0);
  24. /*   This is what I had before, before I changed it to work 10.13.14
  25.             OSStatus err = AudioFileStreamParseBytes(((AudioData *) audioData)->audioFileStream, bytesRead, buffer, 0);
  26. */
  27.             if (err) PRINTERROR("AudioFileStreamParseBytes");
  28.         }
  29.     }
  30. }
  31.  
  32.  
  33.  
  34. function that calls the above:
  35. if (!CFReadStreamSetClient(stream8, kNetworkEvents, ReadStreamClientCallBack, &ctxt)) {...}
Advertisement
Add Comment
Please, Sign In to add comment