winlin

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

... ... @@ -108,7 +108,7 @@ SrsAvcAacCodec::SrsAvcAacCodec()
avc_profile = 0;
avc_level = 0;
aac_profile = 0;
aac_sample_rate = 0;
aac_sample_rate = _SRS_AAC_SAMPLE_RATE_UNSET; // sample rate ignored
aac_channels = 0;
avc_extra_size = 0;
avc_extra_data = NULL;
... ... @@ -166,25 +166,6 @@ int SrsAvcAacCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* samp
sample->sound_rate = (SrsCodecAudioSampleRate)sound_rate;
sample->sound_size = (SrsCodecAudioSampleSize)sound_size;
// reset the sample rate by sequence header
static int aac_sample_rates[] = {
96000, 88200, 64000, 48000,
44100, 32000, 24000, 22050,
16000, 12000, 11025, 8000,
7350, 0, 0, 0
};
switch (aac_sample_rates[aac_sample_rate]) {
case 11025:
sample->sound_rate = SrsCodecAudioSampleRate11025;
break;
case 22050:
sample->sound_rate = SrsCodecAudioSampleRate22050;
break;
case 44100:
sample->sound_rate = SrsCodecAudioSampleRate44100;
break;
};
// only support aac
if (audio_codec_id != SrsCodecAudioAAC) {
ret = ERROR_HLS_DECODE_ERROR;
... ... @@ -261,6 +242,27 @@ int SrsAvcAacCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* samp
// ignored.
}
// reset 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
};
switch (aac_sample_rates[aac_sample_rate]) {
case 11025:
sample->sound_rate = SrsCodecAudioSampleRate11025;
break;
case 22050:
sample->sound_rate = SrsCodecAudioSampleRate22050;
break;
case 44100:
sample->sound_rate = SrsCodecAudioSampleRate44100;
break;
};
}
srs_info("audio decoded, type=%d, codec=%d, asize=%d, rate=%d, format=%d, size=%d",
sound_type, audio_codec_id, sound_size, sound_rate, sound_format, size);
... ...
... ... @@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class SrsStream;
#define SRS_MAX_CODEC_SAMPLE 128
#define _SRS_AAC_SAMPLE_RATE_UNSET 15
// Sampling rate. The following values are defined:
// 0 = 5.5 kHz = 5512 Hz
... ...
... ... @@ -365,7 +365,7 @@ SrsHlsAacJitter::~SrsHlsAacJitter()
{
}
int64_t SrsHlsAacJitter::on_buffer_start(int64_t flv_pts, int sample_rate)
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
... ... @@ -374,6 +374,17 @@ int64_t SrsHlsAacJitter::on_buffer_start(int64_t flv_pts, int sample_rate)
static int flv_sample_rates[] = {5512, 11025, 22050, 44100};
int flv_sample_rate = flv_sample_rates[sample_rate & 0x03];
// reset 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];
}
// sync time set to 0, donot adjust the aac timestamp.
if (!sync_ms) {
return flv_pts;
... ... @@ -1016,7 +1027,7 @@ int SrsHlsCache::write_audio(SrsAvcAacCodec* codec, SrsHlsMuxer* muxer, int64_t
// start buffer, set the af
if (ab->size == 0) {
pts = aac_jitter->on_buffer_start(pts, sample->sound_rate);
pts = aac_jitter->on_buffer_start(pts, sample->sound_rate, codec->aac_sample_rate);
af->dts = af->pts = audio_buffer_start_pts = pts;
af->pid = TS_AUDIO_PID;
... ...
... ... @@ -66,9 +66,11 @@ public:
/**
* when buffer start, calc the "correct" pts for ts,
* @param flv_pts, the flv pts calc from flv header timestamp,
* @param sample_rate, the sample rate in format(flv/RTMP packet header).
* @param aac_sample_rate, the sample rate in codec(sequence header).
* @return the calc correct pts.
*/
virtual int64_t on_buffer_start(int64_t flv_pts, int sample_rate);
virtual int64_t on_buffer_start(int64_t flv_pts, int sample_rate, int aac_sample_rate);
/**
* when buffer continue, muxer donot write to file,
* 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.
// current release version
#define VERSION_MAJOR "0"
#define VERSION_MINOR "9"
#define VERSION_REVISION "149"
#define VERSION_REVISION "150"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info.
#define RTMP_SIG_SRS_KEY "SRS"
... ...
... ... @@ -33,6 +33,7 @@ using namespace std;
SrsFileWriter::SrsFileWriter()
{
fd = -1;
}
SrsFileWriter::~SrsFileWriter()
... ...