Objective
Reading m4a
file bought from iTunes Store via AVAssetReader
.
Stream via HTTP
and consumed by MobileVLCKit
.
What I've tried
As far as I know, AVAssetReader
only generates audio raw data, so I guess I should add ADTS header in front of every sample.
NSError *error = nil;
AVAssetReader* reader = [[AVAssetReader alloc] initWithAsset:asset error:&error];
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
return -1;
}
AVAssetTrack* track = [asset.tracks objectAtIndex:0];
AVAssetReaderTrackOutput *readerOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:track
outputSettings:nil];
[reader addOutput:readerOutput];
[reader startReading];
while (reader.status == AVAssetReaderStatusReading){
AVAssetReaderTrackOutput * trackOutput = (AVAssetReaderTrackOutput *)[reader.outputs objectAtIndex:0];
CMSampleBufferRef sampleBufferRef;
@synchronized(self) {
sampleBufferRef = [trackOutput copyNextSampleBuffer];
}
CMItemCount = CMSampleBufferGetNumSamples(sampleBufferRef);
...
}
So, my question is, how do I loop every sample and add ADTS header?