Removed buffering work (now in different branch)

This commit is contained in:
Thong Nguyen 2014-03-24 16:32:38 +00:00
parent d7d583c3ba
commit ca928dfe1e
6 changed files with 2 additions and 375 deletions

View File

@ -2013,7 +2013,7 @@ static BOOL GetHardwareCodecClassDesc(UInt32 formatId, AudioClassDescription* cl
AudioComponentInstance convertUnit;
CHECK_STATUS_AND_RETURN_VALUE(AUGraphAddNode(audioGraph, &convertUnitDescription, &convertNode), 0);
CHECK_STATUS_AND_RETURN_VALUE(status = AUGraphNodeInfo(audioGraph, convertNode, &mixerDescription, &convertUnit), 0);
CHECK_STATUS_AND_RETURN_VALUE(AUGraphNodeInfo(audioGraph, convertNode, &mixerDescription, &convertUnit), 0);
CHECK_STATUS_AND_RETURN_VALUE(AudioUnitSetProperty(convertUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &srcFormat, sizeof(srcFormat)), 0);
CHECK_STATUS_AND_RETURN_VALUE(AudioUnitSetProperty(convertUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &desFormat, sizeof(desFormat)), 0);
CHECK_STATUS_AND_RETURN_VALUE(AudioUnitSetProperty(convertUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, &maxFramesPerSlice, sizeof(maxFramesPerSlice)), 0);

View File

@ -1,22 +0,0 @@
//
// STKBufferChunk.h
// StreamingKit
//
// Created by Thong Nguyen on 24/02/2014.
// Copyright (c) 2014 Thong Nguyen. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface STKBufferChunk : NSObject
{
@public
UInt32 key;
UInt32 size;
UInt32 position;
UInt8* buffer;
}
-(id) initWithBufferSize:(UInt32)sizeIn;
@end

View File

@ -1,30 +0,0 @@
//
// STKBufferChunk.m
// StreamingKit
//
// Created by Thong Nguyen on 24/02/2014.
// Copyright (c) 2014 Thong Nguyen. All rights reserved.
//
#import "STKBufferChunk.h"
@implementation STKBufferChunk
-(id) initWithBufferSize:(UInt32)sizeIn
{
if (self = [super init])
{
self->size = sizeIn;
self->buffer = calloc(sizeof(UInt8), sizeIn);
}
return self;
}
-(void) dealloc
{
free(self->buffer);
}
@end

View File

@ -1,44 +0,0 @@
/**********************************************************************************
STKBufferingDataSource.h
Created by Thong Nguyen on 16/10/2012.
https://github.com/tumtumtum/audjustable
Copyright (c) 2012-2014 Thong Nguyen (tumtumtum@gmail.com). All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by Thong Nguyen (tumtumtum@gmail.com)
4. Neither the name of Thong Nguyen nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY Thong Nguyen ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THONG NGUYEN BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************************/
#import "STKDataSource.h"
@interface STKBufferingDataSource : STKDataSource
@property (readonly) SInt64 position;
@property (readonly) SInt64 length;
-(id) initWithDataSource:(STKDataSource*)dataSourceIn withMaxSize:(int)maxSizeIn;
@end

View File

@ -1,277 +0,0 @@
/**********************************************************************************
STKBufferingDataSource.m
Created by Thong Nguyen on 16/10/2012.
https://github.com/tumtumtum/audjustable
Copyright (c) 2012-2014 Thong Nguyen (tumtumtum@gmail.com). All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by Thong Nguyen (tumtumtum@gmail.com)
4. Neither the name of Thong Nguyen nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY Thong Nguyen ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THONG NGUYEN BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************************/
#import "STKBufferingDataSource.h"
#import "STKBufferChunk.h"
#import <pthread.h>
#define STK_BUFFER_CHUNK_SIZE (128 * 1024)
@interface STKBufferingDataSource()
{
@private
NSRunLoop* runLoop;
SInt32 maxSize;
UInt32 chunkSize;
UInt32 chunkCount;
SInt64 position;
pthread_mutex_t mutex;
pthread_cond_t condition;
STKBufferChunk* __strong * bufferChunks;
STKDataSource* dataSource;
}
@end
@interface STKBufferingDataSourceThread : NSThread
{
@private
NSRunLoop* runLoop;
NSConditionLock* threadStartedLock;
}
@end
@implementation STKBufferingDataSourceThread
-(id) init
{
if (self = [super init])
{
threadStartedLock = [[NSConditionLock alloc] initWithCondition:0];
}
return self;
}
-(NSRunLoop*) runLoop
{
[threadStartedLock lockWhenCondition:1];
[threadStartedLock unlockWithCondition:0];
return self->runLoop;
}
-(void) main
{
runLoop = [NSRunLoop currentRunLoop];
[threadStartedLock lockWhenCondition:0];
[threadStartedLock unlockWithCondition:1];
[runLoop addPort:[NSPort port] forMode:NSDefaultRunLoopMode];
while (true)
{
NSDate* date = [[NSDate alloc] initWithTimeIntervalSinceNow:10];
[runLoop runMode:NSDefaultRunLoopMode beforeDate:date];
}
}
@end
static STKBufferingDataSourceThread* thread;
@implementation STKBufferingDataSource
+(void) initialize
{
thread = [[STKBufferingDataSourceThread alloc] init];
[thread start];
}
-(id) initWithDataSource:(STKDataSource*)dataSourceIn withMaxSize:(int)maxSizeIn
{
if (self = [super init])
{
self->maxSize = maxSizeIn;
self->dataSource = dataSourceIn;
self->chunkSize = STK_BUFFER_CHUNK_SIZE;
self->dataSource.delegate = self.delegate;
[self->dataSource registerForEvents:[thread runLoop]];
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&self->mutex, &attr);
pthread_cond_init(&self->condition, NULL);
}
return self;
}
-(void) dealloc
{
self->dataSource.delegate = nil;
for (int i = 0; i < self->chunkCount; i++)
{
self->bufferChunks[i] = nil;
}
free(self->bufferChunks);
pthread_mutex_destroy(&self->mutex);
pthread_cond_destroy(&self->condition);
}
-(void) createBuffer
{
if (self->bufferChunks == nil)
{
int length = (int)MIN(self.length == 0? 1024 * 1024 : self.length, self->maxSize);
self->chunkCount = (int)((length / self->chunkSize) + 1);
self->bufferChunks = (__strong STKBufferChunk**)calloc(sizeof(STKBufferChunk*), self->chunkCount);
}
}
-(STKBufferChunk*) chunkForPosition:(SInt64)positionIn createIfNotExist:(BOOL)createIfNotExist
{
int chunkIndex = (int)(positionIn / chunkCount);
if (self->bufferChunks[chunkIndex] == nil && createIfNotExist)
{
self->bufferChunks[chunkIndex] = [[STKBufferChunk alloc] initWithBufferSize:STK_BUFFER_CHUNK_SIZE];
}
return self->bufferChunks[chunkIndex];
}
-(SInt64) length
{
return self->dataSource.length;
}
-(void) seekToOffset:(SInt64)offset
{
pthread_mutex_lock(&mutex);
[self seekToNextGap];
pthread_mutex_unlock(&mutex);
}
-(BOOL) hasBytesAvailable
{
return NO;
}
-(int) readIntoBuffer:(UInt8*)bufferIn withSize:(int)size
{
return 0;
}
-(BOOL) registerForEvents:(NSRunLoop*)runLoopIn
{
runLoop = runLoopIn;
[dataSource registerForEvents:[thread runLoop]];
return YES;
}
-(void) unregisterForEvents
{
runLoop = nil;
[dataSource unregisterForEvents];
}
-(void) close
{
[dataSource unregisterForEvents];
[dataSource close];
}
-(void) seekToNextGap
{
}
-(void) dataSourceDataAvailable:(STKDataSource*)dataSourceIn
{
if (![dataSourceIn hasBytesAvailable])
{
return;
}
pthread_mutex_lock(&mutex);
if (self->bufferChunks == nil)
{
[self createBuffer];
}
SInt64 sourcePosition = dataSourceIn.position;
STKBufferChunk* chunk = [self chunkForPosition:sourcePosition createIfNotExist:YES];
if (chunk->position >= chunk->size)
{
[self seekToNextGap];
return;
}
int offset = dataSourceIn.position % self->chunkSize;
if (offset > chunk->position)
{
[self seekToNextGap];
return;
}
int bytesToRead = self->chunkSize - offset;
int bytesRead = [dataSourceIn readIntoBuffer:(chunk->buffer + offset) withSize:bytesToRead];
chunk->position = offset + bytesRead;
pthread_mutex_unlock(&mutex);
}
-(void) dataSourceErrorOccured:(STKDataSource*)dataSourceIn
{
[self.delegate dataSourceErrorOccured:self];
}
-(void) dataSourceEof:(STKDataSource*)dataSourceIn
{
}
@end

View File

@ -153,7 +153,7 @@
{
httpHeaders = (__bridge_transfer NSDictionary*)CFHTTPMessageCopyAllHeaderFields((CFHTTPMessageRef)response);
self->httpStatusCode = CFHTTPMessageGetResponseStatusCode((CFHTTPMessageRef)response);
self->httpStatusCode = (UInt32)CFHTTPMessageGetResponseStatusCode((CFHTTPMessageRef)response);
CFRelease(response);
}