Muleiple vorbis bitstreams in one file for streaming. Bitstreams can be different formats. (!)
parent
aafb021a80
commit
c810d2f492
|
@ -20,6 +20,7 @@
|
||||||
//Temporary for callback use
|
//Temporary for callback use
|
||||||
void *inputBuffer;
|
void *inputBuffer;
|
||||||
int inputBufferSize;
|
int inputBufferSize;
|
||||||
|
BOOL needsReset;
|
||||||
//end
|
//end
|
||||||
|
|
||||||
int outputSize;
|
int outputSize;
|
||||||
|
|
|
@ -46,10 +46,13 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
|
||||||
converter->inputBufferSize = 0;
|
converter->inputBufferSize = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
NSLog(@"RETURNING 0");
|
|
||||||
ioData->mBuffers[0].mData = NULL;
|
ioData->mBuffers[0].mData = NULL;
|
||||||
ioData->mBuffers[0].mDataByteSize = 0;
|
ioData->mBuffers[0].mDataByteSize = 0;
|
||||||
|
ioData->mNumberBuffers = 1;
|
||||||
*ioNumberDataPackets = 0;
|
*ioNumberDataPackets = 0;
|
||||||
|
|
||||||
|
//Reset the converter's internal bufferrs.
|
||||||
|
converter->needsReset = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
@ -62,20 +65,20 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
|
||||||
|
|
||||||
OSStatus err;
|
OSStatus err;
|
||||||
|
|
||||||
|
needsReset = NO;
|
||||||
|
|
||||||
ioNumberFrames = outputSize/outputFormat.mBytesPerFrame;
|
ioNumberFrames = outputSize/outputFormat.mBytesPerFrame;
|
||||||
ioData.mBuffers[0].mData = outputBuffer;
|
ioData.mBuffers[0].mData = outputBuffer;
|
||||||
ioData.mBuffers[0].mDataByteSize = outputSize;
|
ioData.mBuffers[0].mDataByteSize = outputSize;
|
||||||
ioData.mBuffers[0].mNumberChannels = outputFormat.mChannelsPerFrame;
|
ioData.mBuffers[0].mNumberChannels = outputFormat.mChannelsPerFrame;
|
||||||
ioData.mNumberBuffers = 1;
|
ioData.mNumberBuffers = 1;
|
||||||
|
|
||||||
inputBuffer = input;
|
inputBuffer = input;
|
||||||
inputBufferSize = inputSize;
|
inputBufferSize = inputSize;
|
||||||
|
|
||||||
err = AudioConverterFillComplexBuffer(converter, ACInputProc, self, &ioNumberFrames, &ioData, NULL);
|
err = AudioConverterFillComplexBuffer(converter, ACInputProc, self, &ioNumberFrames, &ioData, NULL);
|
||||||
if (err == kAudioConverterErr_InvalidInputSize) //It returns insz at EOS at times...so run it again to make sure all data is converted
|
if (err != noErr || needsReset) //It returns insz at EOS at times...so run it again to make sure all data is converted
|
||||||
{
|
{
|
||||||
NSLog(@"WOAH NELLY THIS SHOULDNT BE A-HAPPENIN");
|
AudioConverterReset(converter);
|
||||||
// return [self convert:input amount:inputSize];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ioData.mBuffers[0].mDataByteSize;
|
return ioData.mBuffers[0].mDataByteSize;
|
||||||
|
@ -115,7 +118,11 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
|
||||||
(void*)&outputSize);
|
(void*)&outputSize);
|
||||||
|
|
||||||
if (outputBuffer)
|
if (outputBuffer)
|
||||||
|
{
|
||||||
|
NSLog(@"FREEING");
|
||||||
free(outputBuffer);
|
free(outputBuffer);
|
||||||
|
NSLog(@"FREED");
|
||||||
|
}
|
||||||
outputBuffer = malloc(outputSize);
|
outputBuffer = malloc(outputSize);
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,9 +140,10 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
|
||||||
|
|
||||||
- (void)cleanUp
|
- (void)cleanUp
|
||||||
{
|
{
|
||||||
if (outputBuffer)
|
if (outputBuffer) {
|
||||||
free(outputBuffer);
|
free(outputBuffer);
|
||||||
|
outputBuffer = NULL;
|
||||||
|
}
|
||||||
AudioConverterDispose(converter);
|
AudioConverterDispose(converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,12 +95,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
amountRead = [decoder fillBuffer:inputBuffer ofSize:CHUNK_SIZE];
|
amountRead = [decoder fillBuffer:inputBuffer ofSize:CHUNK_SIZE];
|
||||||
|
|
||||||
amountConverted = [converter convert:inputBuffer amount:amountRead]; //Convert fills in converter buffer, til the next call
|
amountConverted = [converter convert:inputBuffer amount:amountRead]; //Convert fills in converter buffer, til the next call
|
||||||
if (amountConverted <= 0)
|
if (amountConverted <= 0)
|
||||||
{
|
{
|
||||||
endOfStream = YES;
|
endOfStream = YES;
|
||||||
DBLog(@"END OF INPUT WAS REACHED");
|
|
||||||
[controller endOfInputReached];
|
[controller endOfInputReached];
|
||||||
break; //eof
|
break; //eof
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,14 +80,6 @@ long sourceTell(void *datasource)
|
||||||
- (int)fillBuffer:(void *)buf ofSize:(UInt32)size
|
- (int)fillBuffer:(void *)buf ofSize:(UInt32)size
|
||||||
{
|
{
|
||||||
int numread;
|
int numread;
|
||||||
int total = 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
lastSection = currentSection;
|
|
||||||
numread = ov_read(&vorbisRef, &((char *)buf)[total], size - total, 0, bitsPerSample/8, 1, ¤tSection);
|
|
||||||
if (numread > 0) {
|
|
||||||
total += numread;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentSection != lastSection) {
|
if (currentSection != lastSection) {
|
||||||
vorbis_info *vi;
|
vorbis_info *vi;
|
||||||
|
@ -99,11 +91,20 @@ long sourceTell(void *datasource)
|
||||||
frequency = vi->rate;
|
frequency = vi->rate;
|
||||||
|
|
||||||
NSLog(@"Format changed...");
|
NSLog(@"Format changed...");
|
||||||
|
[self willChangeValueForKey:@"properties"];
|
||||||
|
[self didChangeValueForKey:@"properties"];
|
||||||
|
NSLog(@"Done with format change...");
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (total != size && numread != 0);
|
lastSection = currentSection;
|
||||||
|
do {
|
||||||
|
numread = ov_read(&vorbisRef, (char *)buf, size, 0, bitsPerSample/8, 1, ¤tSection);
|
||||||
|
if (numread < 0) {
|
||||||
|
NSLog(@"SOME KINDA ERROR!");
|
||||||
|
}
|
||||||
|
} while (numread < 0);
|
||||||
|
|
||||||
return total;
|
return numread;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)close
|
- (void)close
|
||||||
|
|
Loading…
Reference in New Issue