From d612a21bad8d235eda3aae21ae939073bbdd216e Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 12 Feb 2017 20:46:24 +0800 Subject: [PATCH] for #299, refine audio codec object name --- trunk/src/app/srs_app_dvr.cpp | 4 +- trunk/src/app/srs_app_rtsp.cpp | 4 +- trunk/src/app/srs_app_statistic.cpp | 4 +- trunk/src/app/srs_app_statistic.hpp | 4 +- trunk/src/kernel/srs_kernel_codec.cpp | 22 +++++------ trunk/src/kernel/srs_kernel_codec.hpp | 56 ++++++++++++++------------- trunk/src/kernel/srs_kernel_mp4.cpp | 24 ++++++------ trunk/src/kernel/srs_kernel_mp4.hpp | 8 ++-- trunk/src/libs/srs_librtmp.hpp | 4 +- 9 files changed, 66 insertions(+), 64 deletions(-) diff --git a/trunk/src/app/srs_app_dvr.cpp b/trunk/src/app/srs_app_dvr.cpp index d2c3720208..2eb9a9c72d 100644 --- a/trunk/src/app/srs_app_dvr.cpp +++ b/trunk/src/app/srs_app_dvr.cpp @@ -536,8 +536,8 @@ int SrsDvrMp4Segmenter::encode_audio(SrsSharedPtrMessage* audio) uint8_t v = buffer->read_1bytes(); SrsAudioCodecId sound_format = (SrsAudioCodecId)((v >> 4) & 0x0f); SrsAudioSampleRate sound_rate = (SrsAudioSampleRate)((v >> 2) & 0x03); - SrsAudioSampleSize sound_size = (SrsAudioSampleSize)((v >> 1) & 0x01); - SrsAudioSoundType channels = (SrsAudioSoundType)(v&0x01); + SrsAudioSampleBits sound_size = (SrsAudioSampleBits)((v >> 1) & 0x01); + SrsAudioChannels channels = (SrsAudioChannels)(v&0x01); uint16_t ct = 0x00; if (sound_format == SrsAudioCodecIdAAC) { diff --git a/trunk/src/app/srs_app_rtsp.cpp b/trunk/src/app/srs_app_rtsp.cpp index 9affc2f8ab..11bc30bb7e 100644 --- a/trunk/src/app/srs_app_rtsp.cpp +++ b/trunk/src/app/srs_app_rtsp.cpp @@ -521,8 +521,8 @@ int SrsRtspConn::write_sequence_header() SrsAudioCodecConfig* dec = format->acodec; acodec->sound_format = SrsAudioCodecIdAAC; - acodec->sound_type = (dec->aac_channels == 2)? SrsAudioSoundTypeStereo : SrsAudioSoundTypeMono; - acodec->sound_size = SrsAudioSampleSize16bit; + acodec->sound_type = (dec->aac_channels == 2)? SrsAudioChannelsStereo : SrsAudioChannelsMono; + acodec->sound_size = SrsAudioSampleBits16bit; acodec->aac_packet_type = 0; static int srs_aac_srates[] = { diff --git a/trunk/src/app/srs_app_statistic.cpp b/trunk/src/app/srs_app_statistic.cpp index 9da8af040f..3d708a084e 100644 --- a/trunk/src/app/srs_app_statistic.cpp +++ b/trunk/src/app/srs_app_statistic.cpp @@ -106,7 +106,7 @@ SrsStatisticStream::SrsStatisticStream() has_audio = false; acodec = SrsAudioCodecIdReserved1; asample_rate = SrsAudioSampleRateReserved; - asound_type = SrsAudioSoundTypeReserved; + asound_type = SrsAudioChannelsReserved; aac_object = SrsAacObjectTypeReserved; width = 0; height = 0; @@ -329,7 +329,7 @@ int SrsStatistic::on_video_info(SrsRequest* req, } int SrsStatistic::on_audio_info(SrsRequest* req, - SrsAudioCodecId acodec, SrsAudioSampleRate asample_rate, SrsAudioSoundType asound_type, + SrsAudioCodecId acodec, SrsAudioSampleRate asample_rate, SrsAudioChannels asound_type, SrsAacObjectType aac_object ) { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_statistic.hpp b/trunk/src/app/srs_app_statistic.hpp index 0c3bae9b3a..d6e2f6ef27 100644 --- a/trunk/src/app/srs_app_statistic.hpp +++ b/trunk/src/app/srs_app_statistic.hpp @@ -92,7 +92,7 @@ struct SrsStatisticStream bool has_audio; SrsAudioCodecId acodec; SrsAudioSampleRate asample_rate; - SrsAudioSoundType asound_type; + SrsAudioChannels asound_type; /** * audio specified * audioObjectType, in 1.6.2.1 AudioSpecificConfig, page 33, @@ -177,7 +177,7 @@ class SrsStatistic * when got audio info for stream. */ virtual int on_audio_info(SrsRequest* req, - SrsAudioCodecId acodec, SrsAudioSampleRate asample_rate, SrsAudioSoundType asound_type, + SrsAudioCodecId acodec, SrsAudioSampleRate asample_rate, SrsAudioChannels asound_type, SrsAacObjectType aac_object ); /** diff --git a/trunk/src/kernel/srs_kernel_codec.cpp b/trunk/src/kernel/srs_kernel_codec.cpp index c5050ff4da..187d61f602 100644 --- a/trunk/src/kernel/srs_kernel_codec.cpp +++ b/trunk/src/kernel/srs_kernel_codec.cpp @@ -78,7 +78,7 @@ string srs_audio_codec_id2str(SrsAudioCodecId codec) } } -string srs_codec_audio_samplerate2str(SrsAudioSampleRate v) +string srs_audio_sample_rate2str(SrsAudioSampleRate v) { switch (v) { case SrsAudioSampleRate5512: return "5512"; @@ -215,20 +215,20 @@ int srs_aac_srates[] = 7350, 0, 0, 0 }; -string srs_audio_samplesize2str(SrsAudioSampleSize v) +string srs_audio_sample_bits2str(SrsAudioSampleBits v) { switch (v) { - case SrsAudioSampleSize16bit: return "16bits"; - case SrsAudioSampleSize8bit: return "8bits"; + case SrsAudioSampleBits16bit: return "16bits"; + case SrsAudioSampleBits8bit: return "8bits"; default: return "Other"; } } -string srs_audio_channels2str(SrsAudioSoundType v) +string srs_audio_channels2str(SrsAudioChannels v) { switch (v) { - case SrsAudioSoundTypeStereo: return "Stereo"; - case SrsAudioSoundTypeMono: return "Mono"; + case SrsAudioChannelsStereo: return "Stereo"; + case SrsAudioChannelsMono: return "Mono"; default: return "Other"; } } @@ -363,8 +363,8 @@ SrsAudioCodecConfig::SrsAudioCodecConfig() { id = SrsAudioCodecIdForbidden; sound_rate = SrsAudioSampleRateForbidden; - sound_size = SrsAudioSampleSizeForbidden; - sound_type = SrsAudioSoundTypeForbidden; + sound_size = SrsAudioSampleBitsForbidden; + sound_type = SrsAudioChannelsForbidden; audio_data_rate = 0; @@ -1270,9 +1270,9 @@ int SrsFormat::audio_aac_demux(SrsBuffer* stream, int64_t timestamp) SrsAudioCodecId codec_id = (SrsAudioCodecId)sound_format; acodec->id = codec_id; - acodec->sound_type = (SrsAudioSoundType)sound_type; + acodec->sound_type = (SrsAudioChannels)sound_type; acodec->sound_rate = (SrsAudioSampleRate)sound_rate; - acodec->sound_size = (SrsAudioSampleSize)sound_size; + acodec->sound_size = (SrsAudioSampleBits)sound_size; // we support h.264+mp3 for hls. if (codec_id == SrsAudioCodecIdMP3) { diff --git a/trunk/src/kernel/srs_kernel_codec.hpp b/trunk/src/kernel/srs_kernel_codec.hpp index c48d52fb08..22c7564d48 100644 --- a/trunk/src/kernel/srs_kernel_codec.hpp +++ b/trunk/src/kernel/srs_kernel_codec.hpp @@ -199,7 +199,7 @@ enum SrsAudioSampleRate SrsAudioSampleRate22050 = 2, SrsAudioSampleRate44100 = 3, }; -std::string srs_codec_audio_samplerate2str(SrsAudioSampleRate v); +std::string srs_audio_sample_rate2str(SrsAudioSampleRate v); /** * The frame type, for example, audio, video or data. @@ -291,40 +291,42 @@ extern int srs_aac_srates[]; #define SrsMaxNbSamples 256 /** -* the FLV/RTMP supported audio sample size. -* Size of each audio sample. This parameter only pertains to -* uncompressed formats. Compressed formats always decode -* to 16 bits internally. -* 0 = 8-bit samples -* 1 = 16-bit samples -*/ -enum SrsAudioSampleSize + * The audio sample size in bits. + * @doc video_file_format_spec_v10_1.pdf, page 76, E.4.2 Audio Tags + * Size of each audio sample. This parameter only pertains to + * uncompressed formats. Compressed formats always decode + * to 16 bits internally. + * 0 = 8-bit samples + * 1 = 16-bit samples + */ +enum SrsAudioSampleBits { // set to the max value to reserved, for array map. - SrsAudioSampleSizeReserved = 2, - SrsAudioSampleSizeForbidden = 2, + SrsAudioSampleBitsReserved = 2, + SrsAudioSampleBitsForbidden = 2, - SrsAudioSampleSize8bit = 0, - SrsAudioSampleSize16bit = 1, + SrsAudioSampleBits8bit = 0, + SrsAudioSampleBits16bit = 1, }; -std::string srs_audio_samplesize2str(SrsAudioSampleSize v); +std::string srs_audio_sample_bits2str(SrsAudioSampleBits v); /** -* the FLV/RTMP supported audio sound type/channel. -* Mono or stereo sound -* 0 = Mono sound -* 1 = Stereo sound -*/ -enum SrsAudioSoundType + * The audio channels. + * @doc video_file_format_spec_v10_1.pdf, page 77, E.4.2 Audio Tags + * Mono or stereo sound + * 0 = Mono sound + * 1 = Stereo sound + */ +enum SrsAudioChannels { // set to the max value to reserved, for array map. - SrsAudioSoundTypeReserved = 2, - SrsAudioSoundTypeForbidden = 2, + SrsAudioChannelsReserved = 2, + SrsAudioChannelsForbidden = 2, - SrsAudioSoundTypeMono = 0, - SrsAudioSoundTypeStereo = 1, + SrsAudioChannelsMono = 0, + SrsAudioChannelsStereo = 1, }; -std::string srs_audio_channels2str(SrsAudioSoundType v); +std::string srs_audio_channels2str(SrsAudioChannels v); /** * Table 7-1 - NAL unit type codes, syntax element categories, and NAL unit type classes @@ -518,8 +520,8 @@ class SrsAudioCodecConfig : public SrsCodecConfig SrsAudioCodecId id; // audio aac specified. SrsAudioSampleRate sound_rate; - SrsAudioSampleSize sound_size; - SrsAudioSoundType sound_type; + SrsAudioSampleBits sound_size; + SrsAudioChannels sound_type; int audio_data_rate; // in bps public: /** diff --git a/trunk/src/kernel/srs_kernel_mp4.cpp b/trunk/src/kernel/srs_kernel_mp4.cpp index 7171668f11..0b16bc4798 100644 --- a/trunk/src/kernel/srs_kernel_mp4.cpp +++ b/trunk/src/kernel/srs_kernel_mp4.cpp @@ -3861,8 +3861,8 @@ SrsMp4Decoder::SrsMp4Decoder() pasc = pavcc = NULL; asc_written = avcc_written = false; sample_rate = SrsAudioSampleRateForbidden; - sound_bits = SrsAudioSampleSizeForbidden; - channels = SrsAudioSoundTypeForbidden; + sound_bits = SrsAudioSampleBitsForbidden; + channels = SrsAudioChannelsForbidden; samples = new SrsMp4SampleManager(); current_index = 0; current_offset = 0; @@ -4062,15 +4062,15 @@ int SrsMp4Decoder::parse_moov(SrsMp4MovieBox* moov) } if (mp4a->samplesize == 16) { - sound_bits = SrsAudioSampleSize16bit; + sound_bits = SrsAudioSampleBits16bit; } else { - sound_bits = SrsAudioSampleSize8bit; + sound_bits = SrsAudioSampleBits8bit; } if (mp4a->channelcount == 2) { - channels = SrsAudioSoundTypeStereo; + channels = SrsAudioChannelsStereo; } else { - channels = SrsAudioSoundTypeMono; + channels = SrsAudioChannelsMono; } } @@ -4117,8 +4117,8 @@ int SrsMp4Decoder::parse_moov(SrsMp4MovieBox* moov) ss << ", soun=" << moov->nb_soun_tracks() << "(" << srs_audio_codec_id2str(acodec) << "," << nb_asc << "BSH" << "," << srs_audio_channels2str(channels) - << "," << srs_audio_samplesize2str(sound_bits) - << "," << srs_codec_audio_samplerate2str(sample_rate) + << "," << srs_audio_sample_bits2str(sound_bits) + << "," << srs_audio_sample_rate2str(sample_rate) << ")"; srs_trace("MP4 moov %s", ss.str().c_str()); @@ -4233,8 +4233,8 @@ SrsMp4Encoder::SrsMp4Encoder() acodec = SrsAudioCodecIdForbidden; sample_rate = SrsAudioSampleRateForbidden; - sound_bits = SrsAudioSampleSizeForbidden; - channels = SrsAudioSoundTypeForbidden; + sound_bits = SrsAudioSampleBitsForbidden; + channels = SrsAudioChannelsForbidden; vcodec = SrsVideoCodecIdForbidden; } @@ -4494,12 +4494,12 @@ int SrsMp4Encoder::flush() SrsMp4AudioSampleEntry* mp4a = new SrsMp4AudioSampleEntry(); mp4a->samplerate = uint32_t(srs_flv_srates[sample_rate]) << 16; - if (sound_bits == SrsAudioSampleSize16bit) { + if (sound_bits == SrsAudioSampleBits16bit) { mp4a->samplesize = 16; } else { mp4a->samplesize = 8; } - if (channels == SrsAudioSoundTypeStereo) { + if (channels == SrsAudioChannelsStereo) { mp4a->channelcount = 2; } else { mp4a->channelcount = 1; diff --git a/trunk/src/kernel/srs_kernel_mp4.hpp b/trunk/src/kernel/srs_kernel_mp4.hpp index 6daa2be3b0..04a4b69f21 100644 --- a/trunk/src/kernel/srs_kernel_mp4.hpp +++ b/trunk/src/kernel/srs_kernel_mp4.hpp @@ -1579,9 +1579,9 @@ class SrsMp4Decoder // The audio sample rate. SrsAudioSampleRate sample_rate; // The audio sound bits. - SrsAudioSampleSize sound_bits; + SrsAudioSampleBits sound_bits; // The audio sound type. - SrsAudioSoundType channels; + SrsAudioChannels channels; private: // For AAC, the asc in esds box. int nb_asc; @@ -1652,9 +1652,9 @@ class SrsMp4Encoder // The audio sample rate. SrsAudioSampleRate sample_rate; // The audio sound bits. - SrsAudioSampleSize sound_bits; + SrsAudioSampleBits sound_bits; // The audio sound type. - SrsAudioSoundType channels; + SrsAudioChannels channels; private: // For AAC, the asc in esds box. int nb_asc; diff --git a/trunk/src/libs/srs_librtmp.hpp b/trunk/src/libs/srs_librtmp.hpp index 90e2e6e3fa..b73a110091 100644 --- a/trunk/src/libs/srs_librtmp.hpp +++ b/trunk/src/libs/srs_librtmp.hpp @@ -536,9 +536,9 @@ typedef struct { // The audio sample rate, it's SrsAudioSampleRate. uint8_t sample_rate; - // The audio sound bits, it's SrsAudioSampleSize. + // The audio sound bits, it's SrsAudioSampleBits. uint8_t sound_bits; - // The audio sound type, it's SrsAudioSoundType. + // The audio sound type, it's SrsAudioChannels. uint8_t channels; // The size of sample payload in bytes.