Skip to content

Commit

Permalink
Fixed error output and handling of packet too large error.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Gallagher committed Jul 27, 2009
1 parent c061aa3 commit 0aec125
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 630 deletions.
5 changes: 3 additions & 2 deletions Classes/AudioStreamer.h
Expand Up @@ -22,7 +22,7 @@
#include <AudioToolbox/AudioToolbox.h>

#define kNumAQBufs 32 // number of audio queue buffers we allocate
#define kAQBufSize 1024 // number of bytes in each audio queue buffer
#define kAQBufSize 2048 // number of bytes in each audio queue buffer
#define kAQMaxPacketDescs 512 // number of packet descriptions in our array

typedef enum
Expand Down Expand Up @@ -69,7 +69,8 @@ typedef enum
AS_AUDIO_QUEUE_STOP_FAILED,
AS_AUDIO_QUEUE_FLUSH_FAILED,
AS_AUDIO_STREAMER_FAILED,
AS_GET_AUDIO_TIME_FAILED
AS_GET_AUDIO_TIME_FAILED,
AS_AUDIO_BUFFER_TOO_SMALL
} AudioStreamerErrorCode;

extern NSString * const ASStatusChangedNotification;
Expand Down
29 changes: 21 additions & 8 deletions Classes/AudioStreamer.m
Expand Up @@ -40,6 +40,7 @@
NSString * const AS_GET_AUDIO_TIME_FAILED_STRING = @"Audio queue get current time failed.";
NSString * const AS_AUDIO_STREAMER_FAILED_STRING = @"Audio playback failed";
NSString * const AS_NETWORK_CONNECTION_FAILED_STRING = @"Network connection failed";
NSString * const AS_AUDIO_BUFFER_TOO_SMALL_STRING = @"Audio packets are larger than kAQBufSize.";

@interface AudioStreamer ()
@property (readwrite) AudioStreamerState state;
Expand Down Expand Up @@ -335,6 +336,8 @@ + (NSString *)stringForErrorCode:(AudioStreamerErrorCode)anErrorCode
return AS_AUDIO_QUEUE_STOP_FAILED_STRING;
case AS_AUDIO_STREAMER_FAILED:
return AS_AUDIO_STREAMER_FAILED_STRING;
case AS_AUDIO_BUFFER_TOO_SMALL:
return AS_AUDIO_BUFFER_TOO_SMALL_STRING;
default:
return AS_AUDIO_STREAMER_FAILED_STRING;
}
Expand Down Expand Up @@ -388,7 +391,7 @@ - (void)failWithErrorCode:(AudioStreamerErrorCode)anErrorCode
UIAlertView *alert =
[[[UIAlertView alloc]
initWithTitle:NSLocalizedStringFromTable(@"Audio Error", @"Errors", nil)
message:NSLocalizedStringFromTable(@"Attempt to play streaming audio failed.", @"Errors", nil)
message:NSLocalizedStringFromTable([AudioStreamer stringForErrorCode:self.errorCode], @"Errors", nil)
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil]
Expand All @@ -405,7 +408,7 @@ - (void)failWithErrorCode:(AudioStreamerErrorCode)anErrorCode
defaultButton:NSLocalizedString(@"OK", @"")
alternateButton:nil
otherButton:nil
informativeTextWithFormat:@"Attempt to play streaming audio failed."];
informativeTextWithFormat:[AudioStreamer stringForErrorCode:self.errorCode]];
[alert
performSelector:@selector(runModal)
onThread:[NSThread mainThread]
Expand Down Expand Up @@ -726,16 +729,18 @@ - (void)startInternal

@synchronized(self)
{
if (state == AS_STOPPING)
if (state != AS_STARTING_FILE_THREAD)
{
if (state != AS_STOPPING &&
state != AS_STOPPED)
{
NSLog(@"### Not starting audio thread. State code is: %ld", state);
}
self.state = AS_INITIALIZED;
[pool release];
return;
}

NSAssert(state == AS_STARTING_FILE_THREAD,
@"Start illegally invoked on an audio stream that has already started.");

#ifdef TARGET_OS_IPHONE
//
// Set the audio session category so that we continue to play if the
Expand Down Expand Up @@ -1373,6 +1378,7 @@ - (void)handleAudioPackets:(const void *)inInputData
{
SInt64 packetOffset = inPacketDescriptions[i].mStartOffset;
SInt64 packetSize = inPacketDescriptions[i].mDataByteSize;
size_t bufSpaceRemaining;

@synchronized(self)
{
Expand All @@ -1391,11 +1397,18 @@ - (void)handleAudioPackets:(const void *)inInputData
{
return;
}

if (packetSize > kAQBufSize)
{
[self failWithErrorCode:AS_AUDIO_BUFFER_TOO_SMALL];
}

bufSpaceRemaining = kAQBufSize - bytesFilled;
}

// if the space remaining in the buffer is not enough for this packet, then enqueue the buffer.
size_t bufSpaceRemaining = kAQBufSize - bytesFilled;
if (bufSpaceRemaining < packetSize) {
if (bufSpaceRemaining < packetSize)
{
[self enqueueBuffer];
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/MacStreamingPlayerController.m
Expand Up @@ -131,7 +131,7 @@ - (void)spinButton
CABasicAnimation *animation;
animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat:2 * M_PI];
animation.toValue = [NSNumber numberWithFloat:-2 * M_PI];
animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
animation.delegate = self;
[button.layer addAnimation:animation forKey:@"rotationAnimation"];
Expand Down
30 changes: 0 additions & 30 deletions Info.plist

This file was deleted.

206 changes: 0 additions & 206 deletions Resources/MainWindow.xib

This file was deleted.

0 comments on commit 0aec125

Please sign in to comment.