2008-11-09 12:43:27 +01:00
|
|
|
/*
|
2015-03-07 21:32:58 +01:00
|
|
|
* aac.c: Frontend Status Monitor plugin for the Video Disk Recorder
|
2008-11-09 12:43:27 +01:00
|
|
|
*
|
|
|
|
* See the README file for copyright information and how to reach the author.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-03-07 21:32:58 +01:00
|
|
|
#include "tools.h"
|
|
|
|
#include "aac.h"
|
2008-11-09 12:43:27 +01:00
|
|
|
|
|
|
|
#define IS_HEAAC_AUDIO(buf) (((buf)[0] == 0xFF) && (((buf)[1] & 0xF6) == 0xF0))
|
|
|
|
|
2015-03-07 17:22:02 +01:00
|
|
|
int cFemonAAC::sampleRateS[16] =
|
2008-11-09 12:43:27 +01:00
|
|
|
{
|
|
|
|
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, -1, -1, -1, -1
|
|
|
|
};
|
|
|
|
|
2015-03-07 17:22:02 +01:00
|
|
|
cFemonAAC::cFemonAAC(cFemonAudioIf *audioHandlerP)
|
|
|
|
: audioHandlerM(audioHandlerP)
|
2008-11-09 12:43:27 +01:00
|
|
|
{
|
2009-08-25 19:22:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cFemonAAC::~cFemonAAC()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-07 17:22:02 +01:00
|
|
|
bool cFemonAAC::processAudio(const uint8_t *bufP, int lenP)
|
2009-08-25 19:22:06 +02:00
|
|
|
{
|
2015-03-07 17:22:02 +01:00
|
|
|
cFemonBitStream bs(bufP, lenP * 8);
|
2009-08-25 19:22:06 +02:00
|
|
|
|
2015-03-07 17:22:02 +01:00
|
|
|
if (!audioHandlerM)
|
2008-11-09 12:43:27 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* ADTS Fixed Header:
|
|
|
|
* syncword 12b always: '111111111111'
|
|
|
|
* id 1b 0: MPEG-4, 1: MPEG-2
|
|
|
|
* layer 2b always: '00'
|
|
|
|
* protection_absent 1b
|
|
|
|
* profile 2b 0: Main profile AAC MAIN 1: Low Complexity profile (LC) AAC LC 2: Scalable Sample Rate profile (SSR) AAC SSR 3: (reserved) AAC LTP
|
|
|
|
* sampling_frequency_index 4b
|
|
|
|
* private_bit 1b
|
|
|
|
* channel_configuration 3b
|
|
|
|
* original/copy 1b
|
|
|
|
* home 1b
|
|
|
|
* emphasis 2b only if ID == 0 (ie MPEG-4)
|
|
|
|
*/
|
|
|
|
|
2009-08-25 19:22:06 +02:00
|
|
|
// skip PES header
|
2015-03-07 17:22:02 +01:00
|
|
|
if (!PesLongEnough(lenP))
|
2009-08-25 19:22:06 +02:00
|
|
|
return false;
|
2015-03-07 17:22:02 +01:00
|
|
|
bs.SkipBits(8 * PesPayloadOffset(bufP));
|
2009-08-25 19:22:06 +02:00
|
|
|
|
|
|
|
// HE-AAC audio detection
|
2011-11-19 15:02:16 +01:00
|
|
|
if (bs.GetBits(12) != 0xFFF) // syncword
|
2009-08-25 19:22:06 +02:00
|
|
|
return false;
|
|
|
|
|
2011-11-19 15:02:16 +01:00
|
|
|
bs.SkipBit(); // id
|
2009-08-25 19:22:06 +02:00
|
|
|
|
|
|
|
// layer must be 0
|
2011-11-19 15:02:16 +01:00
|
|
|
if (bs.GetBits(2)) // layer
|
2009-08-25 19:22:06 +02:00
|
|
|
return false;
|
|
|
|
|
2011-11-19 15:02:16 +01:00
|
|
|
bs.SkipBit(); // protection_absent
|
|
|
|
bs.SkipBits(2); // profile
|
|
|
|
int sampling_frequency_index = bs.GetBits(4); // sampling_frequency_index
|
|
|
|
bs.SkipBit(); // private pid
|
|
|
|
int channel_configuration = bs.GetBits(3); // channel_configuration
|
2008-11-09 12:43:27 +01:00
|
|
|
|
2015-03-07 17:22:02 +01:00
|
|
|
audioHandlerM->SetAudioCodec(AUDIO_CODEC_HEAAC);
|
|
|
|
audioHandlerM->SetAudioBitrate(AUDIO_BITRATE_RESERVED);
|
2008-11-09 12:43:27 +01:00
|
|
|
|
|
|
|
switch (channel_configuration) {
|
|
|
|
case 0:
|
2015-03-07 17:22:02 +01:00
|
|
|
audioHandlerM->SetAudioChannel(AUDIO_CHANNEL_MODE_STEREO);
|
2008-11-09 12:43:27 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2015-03-07 17:22:02 +01:00
|
|
|
audioHandlerM->SetAudioChannel(AUDIO_CHANNEL_MODE_JOINT_STEREO);
|
2008-11-09 12:43:27 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2015-03-07 17:22:02 +01:00
|
|
|
audioHandlerM->SetAudioChannel(AUDIO_CHANNEL_MODE_DUAL);
|
2008-11-09 12:43:27 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2015-03-07 17:22:02 +01:00
|
|
|
audioHandlerM->SetAudioChannel(AUDIO_CHANNEL_MODE_SINGLE);
|
2008-11-09 12:43:27 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-03-07 17:22:02 +01:00
|
|
|
audioHandlerM->SetAudioChannel(AUDIO_CHANNEL_MODE_INVALID);
|
2008-11-09 12:43:27 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (sampling_frequency_index) {
|
|
|
|
case 0xC ... 0xF:
|
2015-03-07 17:22:02 +01:00
|
|
|
audioHandlerM->SetAudioSamplingFrequency(AUDIO_SAMPLING_FREQUENCY_RESERVED);
|
2008-11-09 12:43:27 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-03-07 17:22:02 +01:00
|
|
|
audioHandlerM->SetAudioSamplingFrequency(sampleRateS[sampling_frequency_index]);
|
2008-11-09 12:43:27 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|