1
0
mirror of https://github.com/rofafor/vdr-plugin-femon.git synced 2023-10-10 13:36:53 +02:00
vdr-plugin-femon/femonlatm.c

113 lines
3.0 KiB
C
Raw Normal View History

2010-06-23 11:16:17 +02:00
/*
* Frontend Status Monitor plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include "femontools.h"
#include "femonlatm.h"
2015-03-07 17:22:02 +01:00
int cFemonLATM::bitrateS[3][16] =
2010-06-23 11:16:17 +02:00
{
{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, -1}, // MPEG-2 Layer I
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, -1}, // MPEG-2 Layer II/III
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, -1} // MPEG-2 Layer II/III
};
2015-03-07 17:22:02 +01:00
int cFemonLATM::sampleRateS[4] =
2010-06-23 11:16:17 +02:00
{
22050, 24000, 16000, -1
};
2015-03-07 17:22:02 +01:00
cFemonLATM::cFemonLATM(cFemonAudioIf *audioHandlerP)
: audioHandlerM(audioHandlerP)
2010-06-23 11:16:17 +02:00
{
}
cFemonLATM::~cFemonLATM()
{
}
2015-03-07 17:22:02 +01:00
bool cFemonLATM::processAudio(const uint8_t *bufP, int lenP)
2010-06-23 11:16:17 +02:00
{
2015-03-07 17:22:02 +01:00
cFemonBitStream bs(bufP, lenP * 8);
2010-06-23 11:16:17 +02:00
2015-03-07 17:22:02 +01:00
if (!audioHandlerM)
2010-06-23 11:16:17 +02:00
return false;
// skip PES header
2015-03-07 17:22:02 +01:00
if (!PesLongEnough(lenP))
2010-06-23 11:16:17 +02:00
return false;
2015-03-07 17:22:02 +01:00
bs.SkipBits(8 * PesPayloadOffset(bufP));
2010-06-23 11:16:17 +02:00
// MPEG audio detection
2011-11-19 15:02:16 +01:00
if (bs.GetBits(12) != 0x56E) // syncword
2010-06-23 11:16:17 +02:00
return false;
2015-03-07 17:22:02 +01:00
audioHandlerM->SetAudioCodec(AUDIO_CODEC_LATM);
2010-06-23 19:12:35 +02:00
2011-11-19 15:02:16 +01:00
if (bs.GetBit() == 0) // id: MPEG-1=1, extension to lower sampling frequencies=0
2010-06-23 19:12:35 +02:00
return true; // @todo: lower sampling frequencies support
2011-11-19 15:02:16 +01:00
int layer = 3 - bs.GetBits(2); // layer: I=11, II=10, III=01
bs.SkipBit(); // protection bit
int bit_rate_index = bs.GetBits(4); // bitrate index
int sampling_frequency = bs.GetBits(2); // sampling frequency
bs.SkipBit(); // padding bit
bs.SkipBit(); // private pid
int mode = bs.GetBits(2); // mode
2010-06-23 11:16:17 +02:00
switch (mode) {
case 0:
2015-03-07 17:22:02 +01:00
audioHandlerM->SetAudioChannel(AUDIO_CHANNEL_MODE_STEREO);
2010-06-23 11:16:17 +02:00
break;
case 1:
2015-03-07 17:22:02 +01:00
audioHandlerM->SetAudioChannel(AUDIO_CHANNEL_MODE_JOINT_STEREO);
2010-06-23 11:16:17 +02:00
break;
case 2:
2015-03-07 17:22:02 +01:00
audioHandlerM->SetAudioChannel(AUDIO_CHANNEL_MODE_DUAL);
2010-06-23 11:16:17 +02:00
break;
case 3:
2015-03-07 17:22:02 +01:00
audioHandlerM->SetAudioChannel(AUDIO_CHANNEL_MODE_SINGLE);
2010-06-23 11:16:17 +02:00
break;
default:
2015-03-07 17:22:02 +01:00
audioHandlerM->SetAudioChannel(AUDIO_CHANNEL_MODE_INVALID);
2010-06-23 11:16:17 +02:00
break;
}
if (layer == 3) {
2015-03-07 17:22:02 +01:00
audioHandlerM->SetAudioBitrate(AUDIO_BITRATE_FREE);
2010-06-23 11:16:17 +02:00
}
else {
switch (bit_rate_index) {
case 0:
2015-03-07 17:22:02 +01:00
audioHandlerM->SetAudioBitrate(AUDIO_BITRATE_FREE);
2010-06-23 11:16:17 +02:00
break;
case 0xF:
2015-03-07 17:22:02 +01:00
audioHandlerM->SetAudioBitrate(AUDIO_BITRATE_RESERVED);
2010-06-23 11:16:17 +02:00
break;
default:
2015-03-07 17:22:02 +01:00
audioHandlerM->SetAudioBitrate(1000 * bitrateS[layer][bit_rate_index]);
2010-06-23 11:16:17 +02:00
break;
}
}
switch (sampling_frequency) {
case 3:
2015-03-07 17:22:02 +01:00
audioHandlerM->SetAudioSamplingFrequency(AUDIO_SAMPLING_FREQUENCY_RESERVED);
2010-06-23 11:16:17 +02:00
break;
default:
2015-03-07 17:22:02 +01:00
audioHandlerM->SetAudioSamplingFrequency(sampleRateS[sampling_frequency]);
2010-06-23 11:16:17 +02:00
break;
}
return true;
}