Some work on PCM.

This commit is contained in:
Damiano Galassi committed 2016-09-12 17:31:51 +02:00
1 parent 1125e84048
commit ae0c27b8a8
4 files changed
+61 -15

No files matched your search

+17 -1
View File
@@ -65,6 +65,22 @@ void FFInitFFmpeg()
REGISTER_DECODER(dca);
REGISTER_DECODER(truehd);
REGISTER_DECODER(mlp);
REGISTER_DECODER(pcm_f32be);
REGISTER_DECODER(pcm_f32le);
REGISTER_DECODER(pcm_f64be);
REGISTER_DECODER(pcm_f64le);
REGISTER_DECODER(pcm_s16be);
REGISTER_DECODER(pcm_s16le);
REGISTER_DECODER(pcm_s16le_planar);
REGISTER_DECODER(pcm_s24be);
REGISTER_DECODER(pcm_s24le);
REGISTER_DECODER(pcm_s32be);
REGISTER_DECODER(pcm_s32le);
REGISTER_DECODER(pcm_s8);
REGISTER_DECODER(pcm_u16be);
REGISTER_DECODER(pcm_u16le);
REGISTER_DECODER(pcm_u24be);
REGISTER_DECODER(pcm_u24le);
});
}
@@ -88,7 +104,7 @@ static const struct {
{ 'DTS ', AV_CODEC_ID_DTS },
{ 'trhd', AV_CODEC_ID_TRUEHD },
{ 'mlp ', AV_CODEC_ID_MLP },
{ kAudioFormatLinearPCM, AV_CODEC_ID_PCM_S16LE },
{ kAudioFormatLinearPCM, AV_CODEC_ID_PCM_S16BE },
{ kAudioFormatLinearPCM, AV_CODEC_ID_PCM_U8 },
{ kAudioFormatALaw, AV_CODEC_ID_PCM_ALAW },
{ kAudioFormatULaw, AV_CODEC_ID_PCM_MULAW },
-2
View File
@@ -9,8 +9,6 @@
#import <Foundation/Foundation.h>
#import "MP42FileImporter.h"
@class AVAsset;
@interface MP42AVFImporter : MP42FileImporter
@end
+20 -5
View File
@@ -25,8 +25,8 @@
@interface AVFDemuxHelper : NSObject {
@public
int64_t currentTime;
int64_t minDisplayOffset;
int64_t currentTime;
int64_t minDisplayOffset;
AVAssetReaderOutput *assetReaderOutput;
MP42EditListsReconstructor *editsConstructor;
@@ -49,7 +49,7 @@
}
+ (NSArray<NSString *> *)supportedFileFormats {
return @[@"mov", @"mp4", @"m4v", @"m4a", @"m2ts", @"ts", @"mts", @"ac3", @"eac3", @"ec3", @"webvtt", @"vtt"];
return @[@"mov", @"mp4", @"m4v", @"m4a", @"m2ts", @"ts", @"mts", @"ac3", @"eac3", @"ec3", @"webvtt", @"vtt", @"caf", @"aif", @"aiff"];
}
- (FourCharCode)formatForTrack:(AVAssetTrack *)track {
@@ -725,6 +725,22 @@
return nil;
}
- (AudioStreamBasicDescription)audioDescriptionForTrack:(MP42AudioTrack *)track
{
AudioStreamBasicDescription result;
bzero(&result, sizeof(AudioStreamBasicDescription));
AVAssetTrack *assetTrack = [_localAsset trackWithTrackID:track.sourceId];
CMFormatDescriptionRef formatDescription = (CMFormatDescriptionRef)assetTrack.formatDescriptions.firstObject;
if (formatDescription) {
const AudioStreamBasicDescription *asbd = CMAudioFormatDescriptionGetStreamBasicDescription(formatDescription);
memcpy(&result, asbd, sizeof(AudioStreamBasicDescription));
}
return result;
}
- (void)demux {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -754,7 +770,7 @@
demuxHelper->assetReaderOutput = assetReaderOutput;
demuxHelper->editsConstructor = [[MP42EditListsReconstructor alloc] initWithMediaFormat:track.format];
totalDataLength += [track dataLength];
totalDataLength += track.dataLength;
}
}
@@ -936,7 +952,6 @@
if ([dict valueForKey:(NSString*)kCMSampleAttachmentKey_DoNotDisplay]) {
doNotDisplay = YES;
}
}
}
+24 -7
View File
@@ -131,6 +131,12 @@ typedef struct MP42DecodeContext MP42DecodeContext;
av_dict_set(&av_opts, "drc_scale", drc_scale, 0);
}
if (asbd.mFormatID == kAudioFormatLinearPCM)
{
_avctx->channels = asbd.mChannelsPerFrame;
_avctx->sample_rate = asbd.mSampleRate;
}
if (avcodec_open2(_avctx, _codec, &av_opts)) {
NSLog(@"Error opening audio decoder");
av_freep(&_avctx);
@@ -271,6 +277,11 @@ static void configureDescriptors(MP42DecodeContext *context, AVFrame *frame)
int nb_channels = av_get_channel_layout_nb_channels(frame->channel_layout);
int sample_rate = frame->sample_rate;
// FIXME PCM
if (nb_channels == 0) {
nb_channels = context->inputFormat->mChannelsPerFrame;
}
// Reset the channels per frame and sample rate
if (context->inputFormat->mChannelsPerFrame == context->outputFormat->mChannelsPerFrame) {
context->outputFormat->mChannelsPerFrame = nb_channels;
@@ -296,7 +307,7 @@ static void configureDescriptors(MP42DecodeContext *context, AVFrame *frame)
context->out_layout = AV_CH_LAYOUT_MONO;
}
}
else {
else if (frame->channel_layout) {
context->out_layout = frame->channel_layout;
}
@@ -352,12 +363,18 @@ static int resample(MP42DecodeContext *context, AVFrame *frame, uint8_t **output
center_mix_level,
downmix_info->lfe_mix_level);
}
hb_audio_resample_set_channel_layout(context->resampler,
frame->channel_layout);
hb_audio_resample_set_sample_rate(context->resampler,
frame->sample_rate);
hb_audio_resample_set_sample_fmt(context->resampler,
frame->format);
if (frame->channel_layout) {
hb_audio_resample_set_channel_layout(context->resampler,
frame->channel_layout);
}
if (frame->sample_rate) {
hb_audio_resample_set_sample_rate(context->resampler,
frame->sample_rate);
}
if (frame->format) {
hb_audio_resample_set_sample_fmt(context->resampler,
frame->format);
}
if (hb_audio_resample_update(context->resampler))
{
NSLog(@"decavcodec: hb_audio_resample_update() failed");