winlin

fix #81: support all aac sample rate, for instance, 48000. to 0.9.150

@@ -108,7 +108,7 @@ SrsAvcAacCodec::SrsAvcAacCodec() @@ -108,7 +108,7 @@ SrsAvcAacCodec::SrsAvcAacCodec()
108 avc_profile = 0; 108 avc_profile = 0;
109 avc_level = 0; 109 avc_level = 0;
110 aac_profile = 0; 110 aac_profile = 0;
111 - aac_sample_rate = 0; 111 + aac_sample_rate = _SRS_AAC_SAMPLE_RATE_UNSET; // sample rate ignored
112 aac_channels = 0; 112 aac_channels = 0;
113 avc_extra_size = 0; 113 avc_extra_size = 0;
114 avc_extra_data = NULL; 114 avc_extra_data = NULL;
@@ -166,25 +166,6 @@ int SrsAvcAacCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* samp @@ -166,25 +166,6 @@ int SrsAvcAacCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* samp
166 sample->sound_rate = (SrsCodecAudioSampleRate)sound_rate; 166 sample->sound_rate = (SrsCodecAudioSampleRate)sound_rate;
167 sample->sound_size = (SrsCodecAudioSampleSize)sound_size; 167 sample->sound_size = (SrsCodecAudioSampleSize)sound_size;
168 168
169 - // reset the sample rate by sequence header  
170 - static int aac_sample_rates[] = {  
171 - 96000, 88200, 64000, 48000,  
172 - 44100, 32000, 24000, 22050,  
173 - 16000, 12000, 11025, 8000,  
174 - 7350, 0, 0, 0  
175 - };  
176 - switch (aac_sample_rates[aac_sample_rate]) {  
177 - case 11025:  
178 - sample->sound_rate = SrsCodecAudioSampleRate11025;  
179 - break;  
180 - case 22050:  
181 - sample->sound_rate = SrsCodecAudioSampleRate22050;  
182 - break;  
183 - case 44100:  
184 - sample->sound_rate = SrsCodecAudioSampleRate44100;  
185 - break;  
186 - };  
187 -  
188 // only support aac 169 // only support aac
189 if (audio_codec_id != SrsCodecAudioAAC) { 170 if (audio_codec_id != SrsCodecAudioAAC) {
190 ret = ERROR_HLS_DECODE_ERROR; 171 ret = ERROR_HLS_DECODE_ERROR;
@@ -261,6 +242,27 @@ int SrsAvcAacCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* samp @@ -261,6 +242,27 @@ int SrsAvcAacCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* samp
261 // ignored. 242 // ignored.
262 } 243 }
263 244
  245 + // reset the sample rate by sequence header
  246 + if (aac_sample_rate != _SRS_AAC_SAMPLE_RATE_UNSET) {
  247 + static int aac_sample_rates[] = {
  248 + 96000, 88200, 64000, 48000,
  249 + 44100, 32000, 24000, 22050,
  250 + 16000, 12000, 11025, 8000,
  251 + 7350, 0, 0, 0
  252 + };
  253 + switch (aac_sample_rates[aac_sample_rate]) {
  254 + case 11025:
  255 + sample->sound_rate = SrsCodecAudioSampleRate11025;
  256 + break;
  257 + case 22050:
  258 + sample->sound_rate = SrsCodecAudioSampleRate22050;
  259 + break;
  260 + case 44100:
  261 + sample->sound_rate = SrsCodecAudioSampleRate44100;
  262 + break;
  263 + };
  264 + }
  265 +
264 srs_info("audio decoded, type=%d, codec=%d, asize=%d, rate=%d, format=%d, size=%d", 266 srs_info("audio decoded, type=%d, codec=%d, asize=%d, rate=%d, format=%d, size=%d",
265 sound_type, audio_codec_id, sound_size, sound_rate, sound_format, size); 267 sound_type, audio_codec_id, sound_size, sound_rate, sound_format, size);
266 268
@@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 class SrsStream; 35 class SrsStream;
36 36
37 #define SRS_MAX_CODEC_SAMPLE 128 37 #define SRS_MAX_CODEC_SAMPLE 128
  38 +#define _SRS_AAC_SAMPLE_RATE_UNSET 15
38 39
39 // Sampling rate. The following values are defined: 40 // Sampling rate. The following values are defined:
40 // 0 = 5.5 kHz = 5512 Hz 41 // 0 = 5.5 kHz = 5512 Hz
@@ -365,7 +365,7 @@ SrsHlsAacJitter::~SrsHlsAacJitter() @@ -365,7 +365,7 @@ SrsHlsAacJitter::~SrsHlsAacJitter()
365 { 365 {
366 } 366 }
367 367
368 -int64_t SrsHlsAacJitter::on_buffer_start(int64_t flv_pts, int sample_rate) 368 +int64_t SrsHlsAacJitter::on_buffer_start(int64_t flv_pts, int sample_rate, int aac_sample_rate)
369 { 369 {
370 // 0 = 5.5 kHz = 5512 Hz 370 // 0 = 5.5 kHz = 5512 Hz
371 // 1 = 11 kHz = 11025 Hz 371 // 1 = 11 kHz = 11025 Hz
@@ -374,6 +374,17 @@ int64_t SrsHlsAacJitter::on_buffer_start(int64_t flv_pts, int sample_rate) @@ -374,6 +374,17 @@ int64_t SrsHlsAacJitter::on_buffer_start(int64_t flv_pts, int sample_rate)
374 static int flv_sample_rates[] = {5512, 11025, 22050, 44100}; 374 static int flv_sample_rates[] = {5512, 11025, 22050, 44100};
375 int flv_sample_rate = flv_sample_rates[sample_rate & 0x03]; 375 int flv_sample_rate = flv_sample_rates[sample_rate & 0x03];
376 376
  377 + // reset the sample rate by sequence header
  378 + if (aac_sample_rate != _SRS_AAC_SAMPLE_RATE_UNSET) {
  379 + static int aac_sample_rates[] = {
  380 + 96000, 88200, 64000, 48000,
  381 + 44100, 32000, 24000, 22050,
  382 + 16000, 12000, 11025, 8000,
  383 + 7350, 0, 0, 0
  384 + };
  385 + flv_sample_rate = aac_sample_rates[aac_sample_rate];
  386 + }
  387 +
377 // sync time set to 0, donot adjust the aac timestamp. 388 // sync time set to 0, donot adjust the aac timestamp.
378 if (!sync_ms) { 389 if (!sync_ms) {
379 return flv_pts; 390 return flv_pts;
@@ -1016,7 +1027,7 @@ int SrsHlsCache::write_audio(SrsAvcAacCodec* codec, SrsHlsMuxer* muxer, int64_t @@ -1016,7 +1027,7 @@ int SrsHlsCache::write_audio(SrsAvcAacCodec* codec, SrsHlsMuxer* muxer, int64_t
1016 1027
1017 // start buffer, set the af 1028 // start buffer, set the af
1018 if (ab->size == 0) { 1029 if (ab->size == 0) {
1019 - pts = aac_jitter->on_buffer_start(pts, sample->sound_rate); 1030 + pts = aac_jitter->on_buffer_start(pts, sample->sound_rate, codec->aac_sample_rate);
1020 1031
1021 af->dts = af->pts = audio_buffer_start_pts = pts; 1032 af->dts = af->pts = audio_buffer_start_pts = pts;
1022 af->pid = TS_AUDIO_PID; 1033 af->pid = TS_AUDIO_PID;
@@ -66,9 +66,11 @@ public: @@ -66,9 +66,11 @@ public:
66 /** 66 /**
67 * when buffer start, calc the "correct" pts for ts, 67 * when buffer start, calc the "correct" pts for ts,
68 * @param flv_pts, the flv pts calc from flv header timestamp, 68 * @param flv_pts, the flv pts calc from flv header timestamp,
  69 + * @param sample_rate, the sample rate in format(flv/RTMP packet header).
  70 + * @param aac_sample_rate, the sample rate in codec(sequence header).
69 * @return the calc correct pts. 71 * @return the calc correct pts.
70 */ 72 */
71 - virtual int64_t on_buffer_start(int64_t flv_pts, int sample_rate); 73 + virtual int64_t on_buffer_start(int64_t flv_pts, int sample_rate, int aac_sample_rate);
72 /** 74 /**
73 * when buffer continue, muxer donot write to file, 75 * when buffer continue, muxer donot write to file,
74 * the audio buffer continue grow and donot need a pts, 76 * the audio buffer continue grow and donot need a pts,
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR "0" 32 #define VERSION_MAJOR "0"
33 #define VERSION_MINOR "9" 33 #define VERSION_MINOR "9"
34 -#define VERSION_REVISION "149" 34 +#define VERSION_REVISION "150"
35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION 35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"
@@ -33,6 +33,7 @@ using namespace std; @@ -33,6 +33,7 @@ using namespace std;
33 33
34 SrsFileWriter::SrsFileWriter() 34 SrsFileWriter::SrsFileWriter()
35 { 35 {
  36 + fd = -1;
36 } 37 }
37 38
38 SrsFileWriter::~SrsFileWriter() 39 SrsFileWriter::~SrsFileWriter()