mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
For #1636, muxing sh, use sound_rate if aac sr not set.
This commit is contained in:
parent
7036f839d2
commit
a7c8980a60
2 changed files with 48 additions and 7 deletions
|
@ -454,9 +454,23 @@ srs_error_t SrsRawAacStream::mux_sequence_header(SrsRawAacStreamCodec* codec, st
|
||||||
// For example, AAC sampling_frequency_index is 3(48000HZ) or 4(44100HZ),
|
// For example, AAC sampling_frequency_index is 3(48000HZ) or 4(44100HZ),
|
||||||
// the sound_rate is always 3(44100HZ), if we covert sound_rate to
|
// the sound_rate is always 3(44100HZ), if we covert sound_rate to
|
||||||
// sampling_frequency_index, we may make mistake.
|
// sampling_frequency_index, we may make mistake.
|
||||||
char samplingFrequencyIndex = codec->sampling_frequency_index;
|
uint8_t samplingFrequencyIndex = (uint8_t)codec->sampling_frequency_index;
|
||||||
if (samplingFrequencyIndex >= SrsAAcSampleRateNumbers) {
|
if (samplingFrequencyIndex >= SrsAacSampleRateUnset) {
|
||||||
samplingFrequencyIndex = 4; // Default to 44100
|
switch (codec->sound_rate) {
|
||||||
|
case SrsAudioSampleRate5512:
|
||||||
|
samplingFrequencyIndex = 0x0c; break;
|
||||||
|
case SrsAudioSampleRate11025:
|
||||||
|
samplingFrequencyIndex = 0x0a; break;
|
||||||
|
case SrsAudioSampleRate22050:
|
||||||
|
samplingFrequencyIndex = 0x07; break;
|
||||||
|
case SrsAudioSampleRate44100:
|
||||||
|
samplingFrequencyIndex = 0x04; break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (samplingFrequencyIndex >= SrsAacSampleRateUnset) {
|
||||||
|
return srs_error_new(ERROR_AAC_DATA_INVALID, "invalid sample index %d", samplingFrequencyIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
char chs[2];
|
char chs[2];
|
||||||
|
@ -470,9 +484,6 @@ srs_error_t SrsRawAacStream::mux_sequence_header(SrsRawAacStreamCodec* codec, st
|
||||||
// samplingFrequencyIndex; 4 bslbf
|
// samplingFrequencyIndex; 4 bslbf
|
||||||
chs[0] |= (samplingFrequencyIndex >> 1) & 0x07;
|
chs[0] |= (samplingFrequencyIndex >> 1) & 0x07;
|
||||||
chs[1] = (samplingFrequencyIndex << 7) & 0x80;
|
chs[1] = (samplingFrequencyIndex << 7) & 0x80;
|
||||||
if (samplingFrequencyIndex == 0x0f) {
|
|
||||||
return srs_error_new(ERROR_AAC_DATA_INVALID, "invalid sampling frequency index");
|
|
||||||
}
|
|
||||||
// 7bits left.
|
// 7bits left.
|
||||||
|
|
||||||
// channelConfiguration; 4 bslbf
|
// channelConfiguration; 4 bslbf
|
||||||
|
|
|
@ -405,6 +405,7 @@ VOID TEST(SrsAVCTest, AACMuxSequenceHeader)
|
||||||
codec.aac_object = SrsAacObjectTypeAacMain;
|
codec.aac_object = SrsAacObjectTypeAacMain;
|
||||||
codec.channel_configuration = 1;
|
codec.channel_configuration = 1;
|
||||||
codec.sound_rate = SrsAudioSampleRate22050;
|
codec.sound_rate = SrsAudioSampleRate22050;
|
||||||
|
codec.sampling_frequency_index = 7;
|
||||||
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
|
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
|
||||||
EXPECT_EQ(2, sh.length());
|
EXPECT_EQ(2, sh.length());
|
||||||
EXPECT_EQ(0x0b, (uint8_t)sh.at(0));
|
EXPECT_EQ(0x0b, (uint8_t)sh.at(0));
|
||||||
|
@ -417,6 +418,7 @@ VOID TEST(SrsAVCTest, AACMuxSequenceHeader)
|
||||||
codec.aac_object = SrsAacObjectTypeAacMain;
|
codec.aac_object = SrsAacObjectTypeAacMain;
|
||||||
codec.channel_configuration = 1;
|
codec.channel_configuration = 1;
|
||||||
codec.sound_rate = SrsAudioSampleRate11025;
|
codec.sound_rate = SrsAudioSampleRate11025;
|
||||||
|
codec.sampling_frequency_index = 0xa;
|
||||||
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
|
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
|
||||||
EXPECT_EQ(2, sh.length());
|
EXPECT_EQ(2, sh.length());
|
||||||
EXPECT_EQ(0x0d, (uint8_t)sh.at(0));
|
EXPECT_EQ(0x0d, (uint8_t)sh.at(0));
|
||||||
|
@ -426,7 +428,8 @@ VOID TEST(SrsAVCTest, AACMuxSequenceHeader)
|
||||||
// Fail for invalid sampling rate.
|
// Fail for invalid sampling rate.
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsRawAacStream h; string sh; SrsRawAacStreamCodec codec;
|
SrsRawAacStream h; string sh; SrsRawAacStreamCodec codec;
|
||||||
codec.sampling_frequency_index = 0xf;
|
codec.aac_object = SrsAacObjectTypeAacMain;
|
||||||
|
codec.sampling_frequency_index = SrsAacSampleRateUnset;
|
||||||
codec.sound_rate = SrsAudioSampleRateReserved;
|
codec.sound_rate = SrsAudioSampleRateReserved;
|
||||||
HELPER_EXPECT_FAILED(h.mux_sequence_header(&codec, sh));
|
HELPER_EXPECT_FAILED(h.mux_sequence_header(&codec, sh));
|
||||||
}
|
}
|
||||||
|
@ -457,6 +460,33 @@ VOID TEST(SrsAVCTest, AACMuxSequenceHeader)
|
||||||
codec.aac_object = SrsAacObjectTypeAacMain;
|
codec.aac_object = SrsAacObjectTypeAacMain;
|
||||||
codec.channel_configuration = 1;
|
codec.channel_configuration = 1;
|
||||||
codec.sound_rate = SrsAudioSampleRate44100;
|
codec.sound_rate = SrsAudioSampleRate44100;
|
||||||
|
codec.sampling_frequency_index = 4;
|
||||||
|
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
|
||||||
|
EXPECT_EQ(2, sh.length());
|
||||||
|
EXPECT_EQ(0x0a, (uint8_t)sh.at(0));
|
||||||
|
EXPECT_EQ(0x08, (uint8_t)sh.at(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// We ignored the sound_rate.
|
||||||
|
if (true) {
|
||||||
|
SrsRawAacStream h; string sh; SrsRawAacStreamCodec codec;
|
||||||
|
codec.aac_object = SrsAacObjectTypeAacMain;
|
||||||
|
codec.channel_configuration = 1;
|
||||||
|
codec.sound_rate = SrsAudioSampleRate22050;
|
||||||
|
codec.sampling_frequency_index = 4;
|
||||||
|
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
|
||||||
|
EXPECT_EQ(2, sh.length());
|
||||||
|
EXPECT_EQ(0x0a, (uint8_t)sh.at(0));
|
||||||
|
EXPECT_EQ(0x08, (uint8_t)sh.at(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use sound_rate if sampling_frequency_index not set.
|
||||||
|
if (true) {
|
||||||
|
SrsRawAacStream h; string sh; SrsRawAacStreamCodec codec;
|
||||||
|
codec.aac_object = SrsAacObjectTypeAacMain;
|
||||||
|
codec.channel_configuration = 1;
|
||||||
|
codec.sound_rate = SrsAudioSampleRate44100;
|
||||||
|
codec.sampling_frequency_index = SrsAacSampleRateUnset;
|
||||||
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
|
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
|
||||||
EXPECT_EQ(2, sh.length());
|
EXPECT_EQ(2, sh.length());
|
||||||
EXPECT_EQ(0x0a, (uint8_t)sh.at(0));
|
EXPECT_EQ(0x0a, (uint8_t)sh.at(0));
|
||||||
|
|
Loading…
Reference in a new issue