Skip to content

Commit

Permalink
for #299, refine audio codec object name
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 12, 2017
1 parent caf69f1 commit d612a21
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 64 deletions.
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_dvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_rtsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_statistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_statistic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
);
/**
Expand Down
22 changes: 11 additions & 11 deletions trunk/src/kernel/srs_kernel_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
}
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
56 changes: 29 additions & 27 deletions trunk/src/kernel/srs_kernel_codec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
/**
Expand Down
24 changes: 12 additions & 12 deletions trunk/src/kernel/srs_kernel_mp4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -4233,8 +4233,8 @@ SrsMp4Encoder::SrsMp4Encoder()

acodec = SrsAudioCodecIdForbidden;
sample_rate = SrsAudioSampleRateForbidden;
sound_bits = SrsAudioSampleSizeForbidden;
channels = SrsAudioSoundTypeForbidden;
sound_bits = SrsAudioSampleBitsForbidden;
channels = SrsAudioChannelsForbidden;
vcodec = SrsVideoCodecIdForbidden;
}

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions trunk/src/kernel/srs_kernel_mp4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/libs/srs_librtmp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d612a21

Please sign in to comment.