Question

How would I go about sending a live audio stream to a server? I currently can access raw PCM data as soon as it is being played from the iPhone speaker and want to allow others to grab it and stream it from a URL. Sort of like when you access an IceCast stream URL and it starts grabbing the stream.

I would like to clarify I am streaming from an iOS device to my server, so that if I were to type in a URL to my server it would start downloading where ever that stream on the phone is at and if the iDevice wasn't streaming then there would be nothing.

Was it helpful?

Solution

See Apple's documentation on output streams here

Note on iOS that you must set up an NSOutputStream as a CFStream (then cast via toll-free bridging) like so:

CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)[website host], 80, &readStream, &writeStream);

NSInputStream *inputStream = (__bridge_transfer NSInputStream *)readStream;
NSOutputStream *outputStream = (__bridge_transfer NSOutputStream *)writeStream;

Other than that, the documentation gives you all the necessary information–keep in mind that PCM is very high bitrate, so there might be stream stuttering.

I'm not sure which framework you're using for microphone access, but when the delegate function is called indicating that a buffer is ready, just immediately write the contents of the buffer to the stream (example in the - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode function).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top