Skip to content

Commit

Permalink
Merge pull request #1636 from runner365/3.0release.srt.dev
Browse files Browse the repository at this point in the history
support all aac sample rate in srt2rtmp
  • Loading branch information
winlinvip authored Mar 13, 2020
2 parents 1382337 + f102a59 commit c66f33a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 31 deletions.
19 changes: 5 additions & 14 deletions trunk/src/protocol/srs_raw_avc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,29 +438,20 @@ srs_error_t SrsRawAacStream::adts_demux(SrsBuffer* stream, char** pframe, int* p
srs_error_t SrsRawAacStream::mux_sequence_header(SrsRawAacStreamCodec* codec, string& sh)
{
srs_error_t err = srs_success;

char samplingFrequencyIndex = codec->sampling_frequency_index;

// only support aac profile 1-4.
if (codec->aac_object == SrsAacObjectTypeReserved) {
return srs_error_new(ERROR_AAC_DATA_INVALID, "invalid aac object");
}

SrsAacObjectType audioObjectType = codec->aac_object;
char channelConfiguration = codec->channel_configuration;
char samplingFrequencyIndex = codec->sampling_frequency_index;

// override the aac samplerate by user specified.
// @see https://github.com/ossrs/srs/issues/212#issuecomment-64146899
switch (codec->sound_rate) {
case SrsAudioSampleRate11025:
samplingFrequencyIndex = 0x0a; break;
case SrsAudioSampleRate22050:
samplingFrequencyIndex = 0x07; break;
case SrsAudioSampleRate44100:
samplingFrequencyIndex = 0x04; break;
default:
break;
if (samplingFrequencyIndex >= 16) {
samplingFrequencyIndex = 4;//default 44100
}

char chs[2];
// @see ISO_IEC_14496-3-AAC-2001.pdf
// AudioSpecificConfig (), page 33
Expand Down
5 changes: 5 additions & 0 deletions trunk/src/protocol/srs_raw_avc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@

#include <srs_kernel_codec.hpp>

static const int mpeg4audio_sample_rates[16] = {
96000, 88200, 64000, 48000, 44100, 32000,
24000, 22050, 16000, 12000, 11025, 8000, 7350
};

class SrsBuffer;

// The raw h.264 stream, in annexb.
Expand Down
20 changes: 3 additions & 17 deletions trunk/src/srt/srt_to_rtmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,25 +517,11 @@ srs_error_t rtmp_client::on_ts_video(std::shared_ptr<SrsBuffer> avs_ptr, uint64_
return err;
}

int rtmp_client::get_sample_rate(char sound_rate) {
int rtmp_client::get_sample_rate(char sample_index) {
int sample_rate = 44100;

switch (sound_rate)
{
case SrsAudioSampleRate44100:
sample_rate = 44100;
break;
case SrsAudioSampleRate22050:
sample_rate = 22050;
break;
case SrsAudioSampleRate11025:
sample_rate = 11025;
break;
case SrsAudioSampleRate5512:
sample_rate = 5512;
break;
default:
break;
if ((sample_index >= 0) && (sample_index < 16)) {
sample_rate = mpeg4audio_sample_rates[sample_index];
}
return sample_rate;
}
Expand Down

0 comments on commit c66f33a

Please sign in to comment.