Added timeout and chillout logic to the HTTP source so it doesn't freak out when there's no data available.
This commit is contained in:
parent
2b55b8978b
commit
bf7b2c0a2b
2 changed files with 27 additions and 4 deletions
|
@ -120,7 +120,7 @@
|
||||||
int framesToRead = (CHUNK_SIZE - amountInBuffer)/bytesPerFrame;
|
int framesToRead = (CHUNK_SIZE - amountInBuffer)/bytesPerFrame;
|
||||||
int framesRead = [decoder readAudio:((char *)inputBuffer) + amountInBuffer frames:framesToRead];
|
int framesRead = [decoder readAudio:((char *)inputBuffer) + amountInBuffer frames:framesToRead];
|
||||||
amountInBuffer += (framesRead * bytesPerFrame);
|
amountInBuffer += (framesRead * bytesPerFrame);
|
||||||
|
|
||||||
if (framesRead <= 0)
|
if (framesRead <= 0)
|
||||||
{
|
{
|
||||||
if (initialBufferFilled == NO) {
|
if (initialBufferFilled == NO) {
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
for(;;) {
|
for(;;) {
|
||||||
int status = _get->get_status();
|
int status = _get->get_status();
|
||||||
|
|
||||||
if (status < 0 || status > 1) {
|
if (status != 0 && status != 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,15 +75,38 @@
|
||||||
{
|
{
|
||||||
int totalRead = 0;
|
int totalRead = 0;
|
||||||
|
|
||||||
|
NSTimeInterval timeout = 30;
|
||||||
|
BOOL timingOut = NO;
|
||||||
|
|
||||||
while (totalRead < amount) {
|
while (totalRead < amount) {
|
||||||
int result = _get->run();
|
int result = _get->run();
|
||||||
int amountRead = _get->get_bytes((char *)((uint8_t *)buffer) + totalRead, amount - totalRead);
|
int amountRead = _get->get_bytes((char *)((uint8_t *)buffer) + totalRead, amount - totalRead);
|
||||||
|
|
||||||
if (result != 0 && 0 == amountRead) break;
|
if (0 == amountRead) {
|
||||||
|
if (0 != result) break;
|
||||||
|
|
||||||
|
if (NO == timingOut) {
|
||||||
|
timingOut = YES;
|
||||||
|
timeout = [NSDate timeIntervalSinceReferenceDate] + 30;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (timeout < [NSDate timeIntervalSinceReferenceDate]) {
|
||||||
|
NSLog(@"Timed out!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sigh. We should just use blocking IO.
|
||||||
|
usleep(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
timingOut = NO;
|
||||||
|
}
|
||||||
|
|
||||||
totalRead += amountRead;
|
totalRead += amountRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
_byteCount += totalRead;
|
_byteCount += totalRead;
|
||||||
|
|
||||||
return totalRead;
|
return totalRead;
|
||||||
|
|
Loading…
Reference in a new issue