1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

for #299, refine docs.

This commit is contained in:
winlin 2017-01-26 17:28:49 +08:00
parent e8353cba3b
commit 136a7ef488
22 changed files with 73 additions and 70 deletions

View file

@ -114,7 +114,7 @@ int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size)
SrsCodecAudioType aac_packet_type = (SrsCodecAudioType)stream->read_1bytes();
if (aac_packet_type == SrsCodecAudioTypeSequenceHeader) {
// AudioSpecificConfig
// 1.6.2.1 AudioSpecificConfig, in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 33.
// 1.6.2.1 AudioSpecificConfig, in ISO_IEC_14496-3-AAC-2001.pdf, page 33.
//
// only need to decode the first 2bytes:
// audioObjectType, 5bits.
@ -150,7 +150,7 @@ int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size)
int16_t aac_raw_length = stream->size() - stream->pos();
// write the ADTS header.
// @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 75,
// @see ISO_IEC_14496-3-AAC-2001.pdf, page 75,
// 1.A.2.2 Audio_Data_Transport_Stream frame, ADTS
// @see https://github.com/ossrs/srs/issues/212#issuecomment-64145885
// byte_alignment()

View file

@ -500,7 +500,7 @@ int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample
if (aac_packet_type == SrsCodecAudioTypeSequenceHeader) {
// AudioSpecificConfig
// 1.6.2.1 AudioSpecificConfig, in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 33.
// 1.6.2.1 AudioSpecificConfig, in ISO_IEC_14496-3-AAC-2001.pdf, page 33.
aac_extra_size = stream->size() - stream->pos();
if (aac_extra_size > 0) {
srs_freepa(aac_extra_data);
@ -721,7 +721,7 @@ int SrsAvcAacCodec::video_nalu_demux(SrsBuffer* stream, SrsCodecSample* sample)
// guess for the first time.
if (payload_format == SrsAvcPayloadFormatGuess) {
// One or more NALUs (Full frames are required)
// try "AnnexB" from H.264-AVC-ISO_IEC_14496-10.pdf, page 211.
// try "AnnexB" from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
if ((ret = avc_demux_annexb_format(stream, sample)) != ERROR_SUCCESS) {
// stop try when system error.
if (ret != ERROR_HLS_AVC_TRY_OTHERS) {
@ -729,7 +729,7 @@ int SrsAvcAacCodec::video_nalu_demux(SrsBuffer* stream, SrsCodecSample* sample)
return ret;
}
// try "ISO Base Media File Format" from H.264-AVC-ISO_IEC_14496-15.pdf, page 20
// try "ISO Base Media File Format" from ISO_IEC_14496-15-AVC-format-2012.pdf, page 20
if ((ret = avc_demux_ibmf_format(stream, sample)) != ERROR_SUCCESS) {
return ret;
} else {
@ -741,14 +741,14 @@ int SrsAvcAacCodec::video_nalu_demux(SrsBuffer* stream, SrsCodecSample* sample)
srs_info("hls guess avc payload is annexb format.");
}
} else if (payload_format == SrsAvcPayloadFormatIbmf) {
// try "ISO Base Media File Format" from H.264-AVC-ISO_IEC_14496-15.pdf, page 20
// try "ISO Base Media File Format" from ISO_IEC_14496-15-AVC-format-2012.pdf, page 20
if ((ret = avc_demux_ibmf_format(stream, sample)) != ERROR_SUCCESS) {
return ret;
}
srs_info("hls decode avc payload in ibmf format.");
} else {
// One or more NALUs (Full frames are required)
// try "AnnexB" from H.264-AVC-ISO_IEC_14496-10.pdf, page 211.
// try "AnnexB" from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
if ((ret = avc_demux_annexb_format(stream, sample)) != ERROR_SUCCESS) {
// ok, we guess out the payload is annexb, but maybe changed to ibmf.
if (ret != ERROR_HLS_AVC_TRY_OTHERS) {
@ -756,7 +756,7 @@ int SrsAvcAacCodec::video_nalu_demux(SrsBuffer* stream, SrsCodecSample* sample)
return ret;
}
// try "ISO Base Media File Format" from H.264-AVC-ISO_IEC_14496-15.pdf, page 20
// try "ISO Base Media File Format" from ISO_IEC_14496-15-AVC-format-2012.pdf, page 20
if ((ret = avc_demux_ibmf_format(stream, sample)) != ERROR_SUCCESS) {
return ret;
} else {
@ -775,7 +775,7 @@ int SrsAvcAacCodec::avc_demux_sps_pps(SrsBuffer* stream)
int ret = ERROR_SUCCESS;
// AVCDecoderConfigurationRecord
// 5.2.4.1.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 16
// 5.2.4.1.1 Syntax, ISO_IEC_14496-15-AVC-format-2012.pdf, page 16
avc_extra_size = stream->size() - stream->pos();
if (avc_extra_size > 0) {
srs_freepa(avc_extra_data);
@ -802,7 +802,7 @@ int SrsAvcAacCodec::avc_demux_sps_pps(SrsBuffer* stream)
lengthSizeMinusOne &= 0x03;
NAL_unit_length = lengthSizeMinusOne;
// 5.3.4.2.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 16
// 5.3.4.2.1 Syntax, ISO_IEC_14496-15-AVC-format-2012.pdf, page 16
// 5.2.4.1 AVC decoder configuration record
// 5.2.4.1.2 Semantics
// The value of this field shall be one of 0, 1, or 3 corresponding to a
@ -814,7 +814,7 @@ int SrsAvcAacCodec::avc_demux_sps_pps(SrsBuffer* stream)
}
// 1 sps, 7.3.2.1 Sequence parameter set RBSP syntax
// H.264-AVC-ISO_IEC_14496-10.pdf, page 45.
// ISO_IEC_14496-10-AVC-2003.pdf, page 45.
if (!stream->require(1)) {
ret = ERROR_HLS_DECODE_ERROR;
srs_error("avc decode sequenc header sps failed. ret=%d", ret);
@ -890,7 +890,7 @@ int SrsAvcAacCodec::avc_demux_sps()
}
// for NALU, 7.3.1 NAL unit syntax
// H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 61.
// ISO_IEC_14496-10-AVC-2012.pdf, page 61.
if (!stream.require(1)) {
ret = ERROR_HLS_DECODE_ERROR;
srs_error("avc decode sps failed. ret=%d", ret);
@ -916,7 +916,7 @@ int SrsAvcAacCodec::avc_demux_sps()
}
// 7.4.1 NAL unit semantics
// H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 61.
// ISO_IEC_14496-10-AVC-2012.pdf, page 61.
// nal_unit_type specifies the type of RBSP data structure contained in the NAL unit as specified in Table 7-1.
SrsAvcNaluType nal_unit_type = (SrsAvcNaluType)(nutv & 0x1f);
if (nal_unit_type != 7) {
@ -970,7 +970,7 @@ int SrsAvcAacCodec::avc_demux_sps_rbsp(char* rbsp, int nb_rbsp)
}
// for SPS, 7.3.2.1.1 Sequence parameter set data syntax
// H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 62.
// ISO_IEC_14496-10-AVC-2012.pdf, page 62.
if (!stream.require(3)) {
ret = ERROR_HLS_DECODE_ERROR;
srs_error("sps shall atleast 3bytes. ret=%d", ret);
@ -1143,7 +1143,7 @@ int SrsAvcAacCodec::avc_demux_annexb_format(SrsBuffer* stream, SrsCodecSample* s
// AnnexB
// B.1.1 Byte stream NAL unit syntax,
// H.264-AVC-ISO_IEC_14496-10.pdf, page 211.
// ISO_IEC_14496-10-AVC-2003.pdf, page 211.
while (!stream->empty()) {
// find start code
int nb_start_code = 0;
@ -1191,14 +1191,14 @@ int SrsAvcAacCodec::avc_demux_ibmf_format(SrsBuffer* stream, SrsCodecSample* sam
int PictureLength = stream->size() - stream->pos();
// 5.3.4.2.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 16
// 5.3.4.2.1 Syntax, ISO_IEC_14496-15-AVC-format-2012.pdf, page 16
// 5.2.4.1 AVC decoder configuration record
// 5.2.4.1.2 Semantics
// The value of this field shall be one of 0, 1, or 3 corresponding to a
// length encoded with 1, 2, or 4 bytes, respectively.
srs_assert(NAL_unit_length != 2);
// 5.3.4.2.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 20
// 5.3.4.2.1 Syntax, ISO_IEC_14496-15-AVC-format-2012.pdf, page 20
for (int i = 0; i < PictureLength;) {
// unsigned int((NAL_unit_length+1)*8) NALUnitLength;
if (!stream->require(NAL_unit_length + 1)) {
@ -1229,7 +1229,7 @@ int SrsAvcAacCodec::avc_demux_ibmf_format(SrsBuffer* stream, SrsCodecSample* sam
srs_error("avc decode NALU data failed. ret=%d", ret);
return ret;
}
// 7.3.1 NAL unit syntax, H.264-AVC-ISO_IEC_14496-10.pdf, page 44.
// 7.3.1 NAL unit syntax, ISO_IEC_14496-10-AVC-2003.pdf, page 44.
if ((ret = sample->add_sample_unit(stream->data() + stream->pos(), NALUnitLength)) != ERROR_SUCCESS) {
srs_error("avc add video sample failed. ret=%d", ret);
return ret;

View file

@ -283,7 +283,7 @@ enum SrsCodecAudioSoundType
/**
* Table 7-1 - NAL unit type codes, syntax element categories, and NAL unit type classes
* H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 83.
* ISO_IEC_14496-10-AVC-2012.pdf, page 83.
*/
enum SrsAvcNaluType
{
@ -452,15 +452,15 @@ std::string srs_codec_aac_profile2str(SrsAacProfile aac_profile);
/**
* the aac object type, for RTMP sequence header
* for AudioSpecificConfig, @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 33
* for audioObjectType, @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 23
* for AudioSpecificConfig, @see ISO_IEC_14496-3-AAC-2001.pdf, page 33
* for audioObjectType, @see ISO_IEC_14496-3-AAC-2001.pdf, page 23
*/
enum SrsAacObjectType
{
SrsAacObjectTypeReserved = 0,
// Table 1.1 - Audio Object Type definition
// @see @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 23
// @see @see ISO_IEC_14496-3-AAC-2001.pdf, page 23
SrsAacObjectTypeAacMain = 1,
SrsAacObjectTypeAacLC = 2,
SrsAacObjectTypeAacSSR = 3,
@ -478,7 +478,7 @@ SrsAacProfile srs_codec_aac_rtmp2ts(SrsAacObjectType object_type);
/**
* the profile for avc/h.264.
* @see Annex A Profiles and levels, H.264-AVC-ISO_IEC_14496-10.pdf, page 205.
* @see Annex A Profiles and levels, ISO_IEC_14496-10-AVC-2003.pdf, page 205.
*/
enum SrsAvcProfile
{
@ -504,7 +504,7 @@ std::string srs_codec_avc_profile2str(SrsAvcProfile profile);
/**
* the level for avc/h.264.
* @see Annex A Profiles and levels, H.264-AVC-ISO_IEC_14496-10.pdf, page 207.
* @see Annex A Profiles and levels, ISO_IEC_14496-10-AVC-2003.pdf, page 207.
*/
enum SrsAvcLevel
{
@ -565,11 +565,11 @@ public:
/**
* video specified
*/
// profile_idc, H.264-AVC-ISO_IEC_14496-10.pdf, page 45.
// profile_idc, ISO_IEC_14496-10-AVC-2003.pdf, page 45.
SrsAvcProfile avc_profile;
// level_idc, H.264-AVC-ISO_IEC_14496-10.pdf, page 45.
// level_idc, ISO_IEC_14496-10-AVC-2003.pdf, page 45.
SrsAvcLevel avc_level;
// lengthSizeMinusOne, H.264-AVC-ISO_IEC_14496-15.pdf, page 16
// lengthSizeMinusOne, ISO_IEC_14496-15-AVC-format-2012.pdf, page 16
int8_t NAL_unit_length;
u_int16_t sequenceParameterSetLength;
char* sequenceParameterSetNALUnit;
@ -583,7 +583,7 @@ public:
* audio specified
* audioObjectType, in 1.6.2.1 AudioSpecificConfig, page 33,
* 1.5.1.1 Audio object type definition, page 23,
* in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf.
* in ISO_IEC_14496-3-AAC-2001.pdf.
*/
SrsAacObjectType aac_object;
/**
@ -658,12 +658,12 @@ private:
virtual int avc_demux_sps_rbsp(char* rbsp, int nb_rbsp);
/**
* demux the avc NALU in "AnnexB"
* from H.264-AVC-ISO_IEC_14496-10.pdf, page 211.
* from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
*/
virtual int avc_demux_annexb_format(SrsBuffer* stream, SrsCodecSample* sample);
/**
* demux the avc NALU in "ISO Base Media File Format"
* from H.264-AVC-ISO_IEC_14496-15.pdf, page 20
* from ISO_IEC_14496-15-AVC-format-2012.pdf, page 20
*/
virtual int avc_demux_ibmf_format(SrsBuffer* stream, SrsCodecSample* sample);
};

View file

@ -2942,7 +2942,7 @@ int SrsTsCache::do_cache_aac(SrsAvcAacCodec* codec, SrsCodecSample* sample)
void srs_avc_insert_aud(SrsSimpleStream* payload, bool& aud_inserted)
{
// mux the samples in annexb format,
// H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 324.
// ISO_IEC_14496-10-AVC-2012.pdf, page 324.
/**
* 00 00 00 01 // header
* xxxxxxx // data bytes
@ -2951,7 +2951,7 @@ void srs_avc_insert_aud(SrsSimpleStream* payload, bool& aud_inserted)
*
* nal_unit_type specifies the type of RBSP data structure contained in the NAL unit as specified in Table 7-1.
* Table 7-1 - NAL unit type codes, syntax element categories, and NAL unit type classes
* H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 83.
* ISO_IEC_14496-10-AVC-2012.pdf, page 83.
* 1, Coded slice of a non-IDR picture slice_layer_without_partitioning_rbsp( )
* 2, Coded slice data partition A slice_data_partition_a_layer_rbsp( )
* 3, Coded slice data partition B slice_data_partition_b_layer_rbsp( )
@ -3006,7 +3006,7 @@ int SrsTsCache::do_cache_avc(SrsAvcAacCodec* codec, SrsCodecSample* sample)
if (!sample->has_aud) {
// the aud(access unit delimiter) before each frame.
// 7.3.2.4 Access unit delimiter RBSP syntax
// H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 66.
// ISO_IEC_14496-10-AVC-2012.pdf, page 66.
//
// primary_pic_type u(3), the first 3bits, primary_pic_type indicates that the slice_type values
// for all slices of the primary coded picture are members of the set listed in Table 7-5 for
@ -3020,7 +3020,7 @@ int SrsTsCache::do_cache_avc(SrsAvcAacCodec* codec, SrsCodecSample* sample)
// 6, slice_type 0, 2, 3, 4, 5, 7, 8, 9
// 7, slice_type 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
// 7.4.2.4 Access unit delimiter RBSP semantics
// H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 102.
// ISO_IEC_14496-10-AVC-2012.pdf, page 102.
//
// slice_type specifies the coding type of the slice according to Table 7-6.
// 0, P (P slice)
@ -3033,7 +3033,7 @@ int SrsTsCache::do_cache_avc(SrsAvcAacCodec* codec, SrsCodecSample* sample)
// 7, I (I slice)
// 8, SP (SP slice)
// 9, SI (SI slice)
// H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 105.
// ISO_IEC_14496-10-AVC-2012.pdf, page 105.
static u_int8_t default_aud_nalu[] = { 0x09, 0xf0};
srs_avc_insert_aud(video->payload, aud_inserted);
video->payload->append((const char*)default_aud_nalu, 2);
@ -3051,7 +3051,7 @@ int SrsTsCache::do_cache_avc(SrsAvcAacCodec* codec, SrsCodecSample* sample)
}
// 5bits, 7.3.1 NAL unit syntax,
// H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 83.
// ISO_IEC_14496-10-AVC-2012.pdf, page 83.
SrsAvcNaluType nal_unit_type = (SrsAvcNaluType)(sample_unit->bytes[0] & 0x1f);
// Insert sps/pps before IDR when there is no sps/pps in samples.

View file

@ -58,7 +58,7 @@ int srs_avc_nalu_read_uev(SrsBitBuffer* stream, int32_t& v)
}
// ue(v) in 9.1 Parsing process for Exp-Golomb codes
// H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 227.
// ISO_IEC_14496-10-AVC-2012.pdf, page 227.
// Syntax elements coded as ue(v), me(v), or se(v) are Exp-Golomb-coded.
// leadingZeroBits = -1;
// for( b = 0; !b; leadingZeroBits++ )

View file

@ -112,7 +112,7 @@ extern std::string srs_path_filext(std::string path);
/**
* whether stream starts with the avc NALU in "AnnexB"
* from H.264-AVC-ISO_IEC_14496-10.pdf, page 211.
* from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
* start code must be "N[00] 00 00 01" where N>=0
* @param pnb_start_code output the size of start code, must >=3.
* NULL to ignore.
@ -121,7 +121,7 @@ extern bool srs_avc_startswith_annexb(SrsBuffer* stream, int* pnb_start_code = N
/**
* whether stream starts with the aac ADTS
* from aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 75, 1.A.2.2 ADTS.
* from ISO_IEC_14496-3-AAC-2001.pdf, page 75, 1.A.2.2 ADTS.
* start code must be '1111 1111 1111'B, that is 0xFFF
*/
extern bool srs_aac_startswith_adts(SrsBuffer* stream);