Started removing legacy AudioQueue code
This commit is contained in:
parent
6df11418f7
commit
15b18069e3
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
/* Begin PBXBuildFile section */
|
||||
A1BF65D2189A6582004DD08C /* STKQueueEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = A1BF65D1189A6582004DD08C /* STKQueueEntry.m */; };
|
||||
A1BF65D5189A65C6004DD08C /* NSMutableArray+STKAudioPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = A1BF65D4189A65C6004DD08C /* NSMutableArray+STKAudioPlayer.m */; };
|
||||
A1C9767718981BFE0057F881 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1C9767618981BFE0057F881 /* AudioUnit.framework */; };
|
||||
A1E7C4CC188D57F50010896F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1E7C4CB188D57F50010896F /* Foundation.framework */; };
|
||||
A1E7C4DA188D57F60010896F /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1E7C4D9188D57F60010896F /* XCTest.framework */; };
|
||||
|
|
@ -50,6 +51,8 @@
|
|||
/* Begin PBXFileReference section */
|
||||
A1BF65D0189A6582004DD08C /* STKQueueEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STKQueueEntry.h; sourceTree = "<group>"; };
|
||||
A1BF65D1189A6582004DD08C /* STKQueueEntry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STKQueueEntry.m; sourceTree = "<group>"; };
|
||||
A1BF65D3189A65C6004DD08C /* NSMutableArray+STKAudioPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableArray+STKAudioPlayer.h"; sourceTree = "<group>"; };
|
||||
A1BF65D4189A65C6004DD08C /* NSMutableArray+STKAudioPlayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableArray+STKAudioPlayer.m"; sourceTree = "<group>"; };
|
||||
A1C9767618981BFE0057F881 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; };
|
||||
A1E7C4C8188D57F50010896F /* libStreamingKit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libStreamingKit.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
A1E7C4CB188D57F50010896F /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
||||
|
|
@ -147,9 +150,11 @@
|
|||
A1E7C4FC188D5E550010896F /* STKHTTPDataSource.m */,
|
||||
A1E7C4FD188D5E550010896F /* STKLocalFileDataSource.h */,
|
||||
A1E7C4FE188D5E550010896F /* STKLocalFileDataSource.m */,
|
||||
A1E7C4CE188D57F50010896F /* Supporting Files */,
|
||||
A1BF65D0189A6582004DD08C /* STKQueueEntry.h */,
|
||||
A1BF65D1189A6582004DD08C /* STKQueueEntry.m */,
|
||||
A1BF65D3189A65C6004DD08C /* NSMutableArray+STKAudioPlayer.h */,
|
||||
A1BF65D4189A65C6004DD08C /* NSMutableArray+STKAudioPlayer.m */,
|
||||
A1E7C4CE188D57F50010896F /* Supporting Files */,
|
||||
);
|
||||
path = StreamingKit;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -269,6 +274,7 @@
|
|||
A1E7C504188D5E550010896F /* STKHTTPDataSource.m in Sources */,
|
||||
A1E7C503188D5E550010896F /* STKDataSourceWrapper.m in Sources */,
|
||||
A1E7C502188D5E550010896F /* STKDataSource.m in Sources */,
|
||||
A1BF65D5189A65C6004DD08C /* NSMutableArray+STKAudioPlayer.m in Sources */,
|
||||
A1E7C500188D5E550010896F /* STKAutoRecoveringHTTPDataSource.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@
|
|||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NSMutableArray (STKAudioPlayer)
|
||||
|
||||
@interface NSMutableArray(STKAudioPlayer)
|
||||
-(void) enqueue:(id)obj;
|
||||
-(void) skipQueue:(id)obj;
|
||||
-(id) dequeue;
|
||||
-(id) peek;
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -8,6 +8,45 @@
|
|||
|
||||
#import "NSMutableArray+STKAudioPlayer.h"
|
||||
|
||||
@implementation NSMutableArray (STKAudioPlayer)
|
||||
@implementation NSMutableArray(STKAudioPlayer)
|
||||
|
||||
-(void) enqueue:(id)obj
|
||||
{
|
||||
[self insertObject:obj atIndex:0];
|
||||
}
|
||||
|
||||
-(void) skipQueue:(id)obj
|
||||
{
|
||||
[self addObject:obj];
|
||||
}
|
||||
|
||||
-(id) dequeue
|
||||
{
|
||||
if ([self count] == 0)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
id retval = [self lastObject];
|
||||
|
||||
[self removeLastObject];
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
-(id) peek
|
||||
{
|
||||
return [self lastObject];
|
||||
}
|
||||
|
||||
-(id) peekRecent
|
||||
{
|
||||
if (self.count == 0)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [self objectAtIndex:0];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -123,7 +123,6 @@ STKAudioPlayerErrorCode;
|
|||
@property (readwrite) STKAudioPlayerState state;
|
||||
@property (readonly) STKAudioPlayerStopReason stopReason;
|
||||
@property (readwrite, unsafe_unretained) id<STKAudioPlayerDelegate> delegate;
|
||||
@property (readwrite) BOOL meteringEnabled;
|
||||
|
||||
-(id) init;
|
||||
-(id) initWithNumberOfAudioQueueBuffers:(int)numberOfAudioQueueBuffers andReadBufferSize:(int)readBufferSizeIn;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -6,8 +6,43 @@
|
|||
// Copyright (c) 2014 Thong Nguyen. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "STKDataSource.h"
|
||||
#import "AudioToolbox/AudioToolbox.h"
|
||||
|
||||
@interface STKQueueEntry : NSobject
|
||||
@interface STKQueueEntry : NSObject
|
||||
{
|
||||
@public
|
||||
BOOL parsedHeader;
|
||||
double sampleRate;
|
||||
double lastProgress;
|
||||
double packetDuration;
|
||||
UInt64 audioDataOffset;
|
||||
UInt64 audioDataByteCount;
|
||||
UInt32 packetBufferSize;
|
||||
volatile BOOL cancel;
|
||||
volatile int processedPacketsCount;
|
||||
volatile int processedPacketsSizeTotal;
|
||||
AudioStreamBasicDescription audioStreamBasicDescription;
|
||||
}
|
||||
|
||||
@end
|
||||
@property (readwrite, retain) NSObject* queueItemId;
|
||||
@property (readwrite, retain) STKDataSource* dataSource;
|
||||
@property (readwrite) Float64 seekTime;
|
||||
@property (readwrite) int bytesBuffered;
|
||||
@property (readwrite) int lastByteIndex;
|
||||
@property (readwrite) Float64 lastFrameIndex;
|
||||
@property (readwrite) Float64 timeWhenLastBufferReturned;
|
||||
@property (readwrite) Float64 firstFrameIndex;
|
||||
@property (readonly) UInt64 audioDataLengthInBytes;
|
||||
|
||||
-(double) duration;
|
||||
-(double) calculatedBitRate;
|
||||
-(void) updateAudioDataSource;
|
||||
-(BOOL) isDefinitelyCompatible:(AudioStreamBasicDescription*)basicDescription;
|
||||
-(BOOL) isKnownToBeIncompatible:(AudioStreamBasicDescription*)basicDescription;
|
||||
-(BOOL) couldBeIncompatible:(AudioStreamBasicDescription*)basicDescription;
|
||||
-(Float64) calculateProgressWithTotalFramesPlayed:(Float64)framesPlayed;
|
||||
|
||||
-(id) initWithDataSource:(STKDataSource*)dataSource andQueueItemId:(NSObject*)queueItemId;
|
||||
|
||||
@end
|
||||
|
|
@ -7,7 +7,148 @@
|
|||
//
|
||||
|
||||
#import "STKQueueEntry.h"
|
||||
#import "STKDataSource.h"
|
||||
|
||||
#define STK_BIT_RATE_ESTIMATION_MIN_PACKETS (64)
|
||||
|
||||
@implementation STKQueueEntry
|
||||
|
||||
@end
|
||||
-(id) initWithDataSource:(STKDataSource*)dataSourceIn andQueueItemId:(NSObject*)queueItemIdIn
|
||||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
self.dataSource = dataSourceIn;
|
||||
self.queueItemId = queueItemIdIn;
|
||||
self.lastFrameIndex = -1;
|
||||
self.lastByteIndex = -1;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(double) calculatedBitRate
|
||||
{
|
||||
double retval;
|
||||
|
||||
if (packetDuration && processedPacketsCount > STK_BIT_RATE_ESTIMATION_MIN_PACKETS)
|
||||
{
|
||||
double averagePacketByteSize = processedPacketsSizeTotal / processedPacketsCount;
|
||||
|
||||
retval = averagePacketByteSize / packetDuration * 8;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
retval = (audioStreamBasicDescription.mBytesPerFrame * audioStreamBasicDescription.mSampleRate) * 8;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
-(void) updateAudioDataSource
|
||||
{
|
||||
if ([self.dataSource conformsToProtocol:@protocol(AudioDataSource)])
|
||||
{
|
||||
double calculatedBitrate = [self calculatedBitRate];
|
||||
|
||||
id<AudioDataSource> audioDataSource = (id<AudioDataSource>)self.dataSource;
|
||||
|
||||
audioDataSource.averageBitRate = calculatedBitrate;
|
||||
audioDataSource.audioDataOffset = audioDataOffset;
|
||||
}
|
||||
}
|
||||
|
||||
-(Float64) calculateProgressWithTotalFramesPlayed:(Float64)framesPlayed
|
||||
{
|
||||
return (Float64)self.seekTime + ((framesPlayed - self.firstFrameIndex) / (Float64)self->audioStreamBasicDescription.mSampleRate);
|
||||
}
|
||||
|
||||
-(double) calculateProgressWithBytesPlayed:(Float64)bytesPlayed
|
||||
{
|
||||
double retval = lastProgress;
|
||||
|
||||
if (self->sampleRate > 0)
|
||||
{
|
||||
double calculatedBitrate = [self calculatedBitRate];
|
||||
|
||||
retval = bytesPlayed / calculatedBitrate * 8;
|
||||
|
||||
retval = self.seekTime + retval;
|
||||
|
||||
[self updateAudioDataSource];
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
-(double) duration
|
||||
{
|
||||
if (self->sampleRate <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
UInt64 audioDataLengthInBytes = [self audioDataLengthInBytes];
|
||||
|
||||
double calculatedBitRate = [self calculatedBitRate];
|
||||
|
||||
if (calculatedBitRate < 1.0 || self.dataSource.length == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return audioDataLengthInBytes / (calculatedBitRate / 8);
|
||||
}
|
||||
|
||||
-(UInt64) audioDataLengthInBytes
|
||||
{
|
||||
if (audioDataByteCount)
|
||||
{
|
||||
return audioDataByteCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!self.dataSource.length)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return self.dataSource.length - audioDataOffset;
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL) isDefinitelyCompatible:(AudioStreamBasicDescription*)basicDescription
|
||||
{
|
||||
if (self->audioStreamBasicDescription.mSampleRate == 0)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
return (memcmp(&(self->audioStreamBasicDescription), basicDescription, sizeof(*basicDescription)) == 0);
|
||||
}
|
||||
|
||||
-(BOOL) isKnownToBeIncompatible:(AudioStreamBasicDescription*)basicDescription
|
||||
{
|
||||
if (self->audioStreamBasicDescription.mSampleRate == 0)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
return (memcmp(&(self->audioStreamBasicDescription), basicDescription, sizeof(*basicDescription)) != 0);
|
||||
}
|
||||
|
||||
-(BOOL) couldBeIncompatible:(AudioStreamBasicDescription*)basicDescription
|
||||
{
|
||||
if (self->audioStreamBasicDescription.mSampleRate == 0)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
return memcmp(&(self->audioStreamBasicDescription), basicDescription, sizeof(*basicDescription)) != 0;
|
||||
}
|
||||
|
||||
-(NSString*) description
|
||||
{
|
||||
return [[self queueItemId] description];
|
||||
}
|
||||
|
||||
@end
|
||||
Loading…
Reference in New Issue