redribben icon

callback

redribben | PRO | 02/09/15 09:33:51 PM UTC | 0 ⭐ | 455 👁️ | Never ⏰ | []
Objective C |

0 B

|

None

|

0 👍

/

0 👎

void ReadStreamClientCallBack(CFReadStreamRef   stream,
                          CFStreamEventType     type,
                          void*                 clientCallBackInfo) {
    BMHttpAudioStreamManager *manager = (__bridge BMHttpAudioStreamManager*) clientCallBackInfo;
    [manager readStreamClientCallBackWithData:stream withType:type];
}
 
- (void) readStreamClientCallBackWithData:(CFReadStreamRef) stream
                                 withType:(CFStreamEventType) type {
    
    if(type == kCFStreamEventHasBytesAvailable) {
        UInt8 buffer[2048];
        CFIndex bytesRead = CFReadStreamRead(stream, buffer, sizeof(buffer));
        
        if (bytesRead < 0) {
            //nothing
        }
        // If zero bytes were read, wait for the EOF to come.
        else if (bytesRead) {
            // parse the data. this will call MyPropertyListenerProc and MyPacketsProc
            // AudioFileStreamParseBytes function called when you have data to pass to the parser.
            // Send the data to the parser sequentially and, if possible, without gaps.
            OSStatus err = AudioFileStreamParseBytes(_audioData->audioFileStream, bytesRead, buffer, 0);
/*   This is what I had before, before I changed it to work 10.13.14
            OSStatus err = AudioFileStreamParseBytes(((AudioData *) audioData)->audioFileStream, bytesRead, buffer, 0);
*/
            if (err) PRINTERROR("AudioFileStreamParseBytes");
        }
    }
}
 
 
 
function that calls the above:
if (!CFReadStreamSetClient(stream8, kNetworkEvents, ReadStreamClientCallBack, &ctxt)) {...}

Comments