From 96e0273e9985dbd79c2bdd60363228442b0ea103 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 6 Jul 2014 17:32:48 +0800 Subject: [PATCH] refine hls, extract the flv/aac sample rates --- trunk/src/app/srs_app_hls.cpp | 30 ++++++++++++++--------- trunk/src/app/srs_app_hls.hpp | 10 ++++++++ trunk/src/app/srs_app_source.cpp | 7 ------ trunk/src/rtmp/srs_protocol_handshake.hpp | 18 +++++++++++--- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index d7738d812..ea880999b 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -76,6 +76,22 @@ using namespace std; // in ms, for HLS aac flush the audio #define SRS_CONF_DEFAULT_AAC_DELAY 100 +// 0 = 5.5 kHz = 5512 Hz +// 1 = 11 kHz = 11025 Hz +// 2 = 22 kHz = 22050 Hz +// 3 = 44 kHz = 44100 Hz +int flv_sample_rates[] = {5512, 11025, 22050, 44100}; + +// the sample rates in the codec, +// in the sequence header. +int aac_sample_rates[] = +{ + 96000, 88200, 64000, 48000, + 44100, 32000, 24000, 22050, + 16000, 12000, 11025, 8000, + 7350, 0, 0, 0 +}; + // @see: ngx_rtmp_mpegts_header u_int8_t mpegts_header[] = { /* TS */ @@ -377,21 +393,11 @@ SrsHlsAacJitter::~SrsHlsAacJitter() int64_t SrsHlsAacJitter::on_buffer_start(int64_t flv_pts, int sample_rate, int aac_sample_rate) { - // 0 = 5.5 kHz = 5512 Hz - // 1 = 11 kHz = 11025 Hz - // 2 = 22 kHz = 22050 Hz - // 3 = 44 kHz = 44100 Hz - static int flv_sample_rates[] = {5512, 11025, 22050, 44100}; + // use sample rate in flv/RTMP. int flv_sample_rate = flv_sample_rates[sample_rate & 0x03]; - // reset the sample rate by sequence header + // override the sample rate by sequence header if (aac_sample_rate != _SRS_AAC_SAMPLE_RATE_UNSET) { - static int aac_sample_rates[] = { - 96000, 88200, 64000, 48000, - 44100, 32000, 24000, 22050, - 16000, 12000, 11025, 8000, - 7350, 0, 0, 0 - }; flv_sample_rate = aac_sample_rates[aac_sample_rate]; } diff --git a/trunk/src/app/srs_app_hls.hpp b/trunk/src/app/srs_app_hls.hpp index afdeac28d..5e5ab1492 100644 --- a/trunk/src/app/srs_app_hls.hpp +++ b/trunk/src/app/srs_app_hls.hpp @@ -47,6 +47,16 @@ class SrsPithyPrint; class SrsSource; class SrsFileWriter; +/** +* the flv sample rate map +*/ +extern int flv_sample_rates[]; + +/** +* the aac sample rate map +*/ +extern int aac_sample_rates[]; + /** * jitter correct for audio, * the sample rate 44100/32000 will lost precise, diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index cc630542c..33c09f58e 100644 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -1082,15 +1082,8 @@ int SrsSource::on_audio(SrsMessage* audio) return ret; } - static int flv_sample_rates[] = {5512, 11025, 22050, 44100, 0}; static int flv_sample_sizes[] = {8, 16, 0}; static int flv_sound_types[] = {1, 2, 0}; - static int aac_sample_rates[] = { - 96000, 88200, 64000, 48000, - 44100, 32000, 24000, 22050, - 16000, 12000, 11025, 8000, - 7350, 0, 0, 0 - }; srs_trace("%dB audio sh, " "codec(%d, profile=%d, %dchannels, %dkbps, %dHZ), " "flv(%dbits, %dchannels, %dHZ)", diff --git a/trunk/src/rtmp/srs_protocol_handshake.hpp b/trunk/src/rtmp/srs_protocol_handshake.hpp index 852ce1506..7ee9b2e87 100644 --- a/trunk/src/rtmp/srs_protocol_handshake.hpp +++ b/trunk/src/rtmp/srs_protocol_handshake.hpp @@ -41,11 +41,21 @@ namespace _srs_internal /** * the schema type. */ - enum srs_schema_type { - srs_schema0 = 0, // key-digest sequence - // @remark, FMS requires the schema1(digest-key), or connect failed. - srs_schema1 = 1, // digest-key sequence + enum srs_schema_type + { srs_schema_invalid = 2, + + /** + * key-digest sequence + */ + srs_schema0 = 0, + + /** + * digest-key sequence + * @remark, FMS requires the schema1(digest-key), or connect failed. + */ + // + srs_schema1 = 1, }; /**