mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Merge code.
Conflicts: trunk/configure trunk/src/app/srs_app_source.cpp trunk/src/kernel/srs_kernel_error.hpp
This commit is contained in:
commit
e57bda8908
90 changed files with 4584 additions and 3576 deletions
|
@ -43,6 +43,7 @@ SrsAacEncoder::SrsAacEncoder()
|
|||
_fs = NULL;
|
||||
got_sequence_header = false;
|
||||
tag_stream = new SrsStream();
|
||||
aac_object = SrsAacObjectTypeReserved;
|
||||
}
|
||||
|
||||
SrsAacEncoder::~SrsAacEncoder()
|
||||
|
@ -114,7 +115,7 @@ int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size)
|
|||
// 1.6.2.1 AudioSpecificConfig, in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 33.
|
||||
//
|
||||
// only need to decode the first 2bytes:
|
||||
// audioObjectType, aac_profile, 5bits.
|
||||
// audioObjectType, 5bits.
|
||||
// samplingFrequencyIndex, aac_sample_rate, 4bits.
|
||||
// channelConfiguration, aac_channels, 4bits
|
||||
if (!stream->require(2)) {
|
||||
|
@ -123,12 +124,14 @@ int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size)
|
|||
return ret;
|
||||
}
|
||||
|
||||
aac_profile = stream->read_1bytes();
|
||||
int8_t audioObjectType = stream->read_1bytes();
|
||||
aac_sample_rate = stream->read_1bytes();
|
||||
|
||||
aac_channels = (aac_sample_rate >> 3) & 0x0f;
|
||||
aac_sample_rate = ((aac_profile << 1) & 0x0e) | ((aac_sample_rate >> 7) & 0x01);
|
||||
aac_profile = (aac_profile >> 3) & 0x1f;
|
||||
aac_sample_rate = ((audioObjectType << 1) & 0x0e) | ((aac_sample_rate >> 7) & 0x01);
|
||||
|
||||
audioObjectType = (audioObjectType >> 3) & 0x1f;
|
||||
aac_object = (SrsAacObjectType)audioObjectType;
|
||||
|
||||
got_sequence_header = true;
|
||||
|
||||
|
@ -177,16 +180,14 @@ int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size)
|
|||
// protection_absent 1 bslbf
|
||||
*pp++ = 0xf1;
|
||||
|
||||
// Profile_ObjectType 2 uimsbf
|
||||
// profile 2 uimsbf
|
||||
// sampling_frequency_index 4 uimsbf
|
||||
// private_bit 1 bslbf
|
||||
// channel_configuration 3 uimsbf
|
||||
// original/copy 1 bslbf
|
||||
// home 1 bslbf
|
||||
int8_t fh_Profile_ObjectType = aac_profile - 1;
|
||||
*pp++ = ((fh_Profile_ObjectType << 6) & 0xc0) | ((aac_sample_rate << 2) & 0x3c) | ((aac_channels >> 2) & 0x01);
|
||||
// @remark, Emphasis is removed,
|
||||
// @see https://github.com/winlinvip/simple-rtmp-server/issues/212#issuecomment-64154736
|
||||
SrsAacProfile aac_profile = srs_codec_aac_rtmp2ts(aac_object);
|
||||
*pp++ = ((aac_profile << 6) & 0xc0) | ((aac_sample_rate << 2) & 0x3c) | ((aac_channels >> 2) & 0x01);
|
||||
// 4bits left.
|
||||
// adts_variable_header(), 1.A.2.2.2 Variable Header of ADTS
|
||||
// copyright_identification_bit 1 bslbf
|
||||
|
|
|
@ -31,6 +31,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#include <string>
|
||||
|
||||
#include <srs_kernel_codec.hpp>
|
||||
|
||||
class SrsStream;
|
||||
class SrsFileWriter;
|
||||
class SrsFileReader;
|
||||
|
@ -43,7 +45,7 @@ class SrsAacEncoder
|
|||
private:
|
||||
SrsFileWriter* _fs;
|
||||
private:
|
||||
int8_t aac_profile;
|
||||
SrsAacObjectType aac_object;
|
||||
int8_t aac_sample_rate;
|
||||
int8_t aac_channels;
|
||||
bool got_sequence_header;
|
||||
|
|
|
@ -32,6 +32,154 @@ using namespace std;
|
|||
#include <srs_kernel_stream.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
|
||||
string srs_codec_video2str(SrsCodecVideo codec)
|
||||
{
|
||||
switch (codec) {
|
||||
case SrsCodecVideoAVC:
|
||||
return "H264";
|
||||
case SrsCodecVideoOn2VP6:
|
||||
case SrsCodecVideoOn2VP6WithAlphaChannel:
|
||||
return "VP6";
|
||||
case SrsCodecVideoReserved:
|
||||
case SrsCodecVideoReserved1:
|
||||
case SrsCodecVideoReserved2:
|
||||
case SrsCodecVideoDisabled:
|
||||
case SrsCodecVideoSorensonH263:
|
||||
case SrsCodecVideoScreenVideo:
|
||||
case SrsCodecVideoScreenVideoVersion2:
|
||||
default:
|
||||
return "Other";
|
||||
}
|
||||
}
|
||||
|
||||
string srs_codec_audio2str(SrsCodecAudio codec)
|
||||
{
|
||||
switch (codec) {
|
||||
case SrsCodecAudioAAC:
|
||||
return "AAC";
|
||||
case SrsCodecAudioMP3:
|
||||
return "MP3";
|
||||
case SrsCodecAudioReserved1:
|
||||
case SrsCodecAudioLinearPCMPlatformEndian:
|
||||
case SrsCodecAudioADPCM:
|
||||
case SrsCodecAudioLinearPCMLittleEndian:
|
||||
case SrsCodecAudioNellymoser16kHzMono:
|
||||
case SrsCodecAudioNellymoser8kHzMono:
|
||||
case SrsCodecAudioNellymoser:
|
||||
case SrsCodecAudioReservedG711AlawLogarithmicPCM:
|
||||
case SrsCodecAudioReservedG711MuLawLogarithmicPCM:
|
||||
case SrsCodecAudioReserved:
|
||||
case SrsCodecAudioSpeex:
|
||||
case SrsCodecAudioReservedMP3_8kHz:
|
||||
case SrsCodecAudioReservedDeviceSpecificSound:
|
||||
default:
|
||||
return "Other";
|
||||
}
|
||||
}
|
||||
|
||||
string srs_codec_aac_profile2str(SrsAacProfile aac_profile)
|
||||
{
|
||||
switch (aac_profile) {
|
||||
case SrsAacProfileMain: return "Main";
|
||||
case SrsAacProfileLC: return "LC";
|
||||
case SrsAacProfileSSR: return "SSR";
|
||||
default: return "Other";
|
||||
}
|
||||
}
|
||||
|
||||
string srs_codec_aac_object2str(SrsAacObjectType aac_object)
|
||||
{
|
||||
switch (aac_object) {
|
||||
case SrsAacObjectTypeAacMain: return "Main";
|
||||
case SrsAacObjectTypeHE: return "HE";
|
||||
case SrsAacObjectTypeHEV2: return "HEv2";
|
||||
case SrsAacObjectTypeAacLC: return "LC";
|
||||
case SrsAacObjectTypeAacSSR: return "SSR";
|
||||
default: return "Other";
|
||||
}
|
||||
}
|
||||
|
||||
SrsAacObjectType srs_codec_aac_ts2rtmp(SrsAacProfile profile)
|
||||
{
|
||||
switch (profile) {
|
||||
case SrsAacProfileMain: return SrsAacObjectTypeAacMain;
|
||||
case SrsAacProfileLC: return SrsAacObjectTypeAacLC;
|
||||
case SrsAacProfileSSR: return SrsAacObjectTypeAacSSR;
|
||||
default: return SrsAacObjectTypeReserved;
|
||||
}
|
||||
}
|
||||
|
||||
SrsAacProfile srs_codec_aac_rtmp2ts(SrsAacObjectType object_type)
|
||||
{
|
||||
switch (object_type) {
|
||||
case SrsAacObjectTypeAacMain: return SrsAacProfileMain;
|
||||
case SrsAacObjectTypeHE:
|
||||
case SrsAacObjectTypeHEV2:
|
||||
case SrsAacObjectTypeAacLC: return SrsAacProfileLC;
|
||||
case SrsAacObjectTypeAacSSR: return SrsAacProfileSSR;
|
||||
default: return SrsAacProfileReserved;
|
||||
}
|
||||
}
|
||||
|
||||
string srs_codec_avc_profile2str(SrsAvcProfile profile)
|
||||
{
|
||||
switch (profile) {
|
||||
case SrsAvcProfileBaseline: return "Baseline";
|
||||
case SrsAvcProfileConstrainedBaseline: return "Baseline(Constrained)";
|
||||
case SrsAvcProfileMain: return "Main";
|
||||
case SrsAvcProfileExtended: return "Extended";
|
||||
case SrsAvcProfileHigh: return "High";
|
||||
case SrsAvcProfileHigh10: return "High(10)";
|
||||
case SrsAvcProfileHigh10Intra: return "High(10+Intra)";
|
||||
case SrsAvcProfileHigh422: return "High(422)";
|
||||
case SrsAvcProfileHigh422Intra: return "High(422+Intra)";
|
||||
case SrsAvcProfileHigh444: return "High(444)";
|
||||
case SrsAvcProfileHigh444Predictive: return "High(444+Predictive)";
|
||||
case SrsAvcProfileHigh444Intra: return "High(444+Intra)";
|
||||
default: return "Other";
|
||||
}
|
||||
}
|
||||
|
||||
string srs_codec_avc_level2str(SrsAvcLevel level)
|
||||
{
|
||||
switch (level) {
|
||||
case SrsAvcLevel_1: return "1";
|
||||
case SrsAvcLevel_11: return "1.1";
|
||||
case SrsAvcLevel_12: return "1.2";
|
||||
case SrsAvcLevel_13: return "1.3";
|
||||
case SrsAvcLevel_2: return "2";
|
||||
case SrsAvcLevel_21: return "2.1";
|
||||
case SrsAvcLevel_22: return "2.2";
|
||||
case SrsAvcLevel_3: return "3";
|
||||
case SrsAvcLevel_31: return "3.1";
|
||||
case SrsAvcLevel_32: return "3.2";
|
||||
case SrsAvcLevel_4: return "4";
|
||||
case SrsAvcLevel_41: return "4.1";
|
||||
case SrsAvcLevel_5: return "5";
|
||||
case SrsAvcLevel_51: return "5.1";
|
||||
default: return "Other";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* the public data, event HLS disable, others can use it.
|
||||
*/
|
||||
// 0 = 5.5 kHz = 5512 Hz
|
||||
// 1 = 11 kHz = 11025 Hz
|
||||
// 2 = 22 kHz = 22050 Hz
|
||||
// 3 = 44 kHz = 44100 Hz
|
||||
int flv_sample_rates[] = {5512, 11025, 22050, 44100};
|
||||
|
||||
// the sample rates in the codec,
|
||||
// in the sequence header.
|
||||
int aac_sample_rates[] =
|
||||
{
|
||||
96000, 88200, 64000, 48000,
|
||||
44100, 32000, 24000, 22050,
|
||||
16000, 12000, 11025, 8000,
|
||||
7350, 0, 0, 0
|
||||
};
|
||||
|
||||
SrsFlvCodec::SrsFlvCodec()
|
||||
{
|
||||
}
|
||||
|
@ -184,9 +332,9 @@ SrsAvcAacCodec::SrsAvcAacCodec()
|
|||
audio_data_rate = 0;
|
||||
audio_codec_id = 0;
|
||||
|
||||
avc_profile = 0;
|
||||
avc_level = 0;
|
||||
aac_profile = 0;
|
||||
avc_profile = SrsAvcProfileReserved;
|
||||
avc_level = SrsAvcLevelReserved;
|
||||
aac_object = SrsAacObjectTypeReserved;
|
||||
aac_sample_rate = __SRS_AAC_SAMPLE_RATE_UNSET; // sample rate ignored
|
||||
aac_channels = 0;
|
||||
avc_extra_size = 0;
|
||||
|
@ -384,20 +532,9 @@ int SrsAvcAacCodec::audio_aac_sequence_header_demux(char* data, int size)
|
|||
// set the aac sample rate.
|
||||
aac_sample_rate = samplingFrequencyIndex;
|
||||
|
||||
// the profile = object_id + 1
|
||||
// @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 78,
|
||||
// Table 1. A.9 ¨C MPEG-2 Audio profiles and MPEG-4 Audio object types
|
||||
aac_profile = profile_ObjectType + 1;
|
||||
|
||||
// the valid aac profile:
|
||||
// MPEG-2 profile
|
||||
// Main profile (ID == 1)
|
||||
// Low Complexity profile (LC) (ID == 2)
|
||||
// Scalable Sampling Rate profile (SSR) (ID == 3)
|
||||
// (reserved) (ID == 4)
|
||||
// @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 78,
|
||||
// Table 1. A.9 ¨C MPEG-2 Audio profiles and MPEG-4 Audio object types
|
||||
if (aac_profile > 4) {
|
||||
// convert the object type in sequence header to aac profile of ADTS.
|
||||
aac_object = (SrsAacObjectType)profile_ObjectType;
|
||||
if (aac_object == SrsAacObjectTypeReserved) {
|
||||
ret = ERROR_HLS_DECODE_ERROR;
|
||||
srs_error("audio codec decode aac sequence header failed, "
|
||||
"adts object=%d invalid. ret=%d", profile_ObjectType, ret);
|
||||
|
@ -554,11 +691,11 @@ int SrsAvcAacCodec::avc_demux_sps_pps(SrsStream* stream)
|
|||
//int8_t configurationVersion = stream->read_1bytes();
|
||||
stream->read_1bytes();
|
||||
//int8_t AVCProfileIndication = stream->read_1bytes();
|
||||
avc_profile = stream->read_1bytes();
|
||||
avc_profile = (SrsAvcProfile)stream->read_1bytes();
|
||||
//int8_t profile_compatibility = stream->read_1bytes();
|
||||
stream->read_1bytes();
|
||||
//int8_t AVCLevelIndication = stream->read_1bytes();
|
||||
avc_level = stream->read_1bytes();
|
||||
avc_level = (SrsAvcLevel)stream->read_1bytes();
|
||||
|
||||
// parse the NALU size.
|
||||
int8_t lengthSizeMinusOne = stream->read_1bytes();
|
||||
|
|
|
@ -110,6 +110,7 @@ enum SrsCodecVideo
|
|||
SrsCodecVideoScreenVideoVersion2 = 6,
|
||||
SrsCodecVideoAVC = 7,
|
||||
};
|
||||
std::string srs_codec_video2str(SrsCodecVideo codec);
|
||||
|
||||
// SoundFormat UB [4]
|
||||
// Format of SoundData. The following values are defined:
|
||||
|
@ -150,6 +151,7 @@ enum SrsCodecAudio
|
|||
SrsCodecAudioReservedMP3_8kHz = 14,
|
||||
SrsCodecAudioReservedDeviceSpecificSound = 15,
|
||||
};
|
||||
std::string srs_codec_audio2str(SrsCodecAudio codec);
|
||||
|
||||
/**
|
||||
* the FLV/RTMP supported audio sample rate.
|
||||
|
@ -373,6 +375,98 @@ enum SrsAvcPayloadFormat
|
|||
SrsAvcPayloadFormatIbmf,
|
||||
};
|
||||
|
||||
/**
|
||||
* the aac profile, for ADTS(HLS/TS)
|
||||
* @see https://github.com/winlinvip/simple-rtmp-server/issues/310
|
||||
*/
|
||||
enum SrsAacProfile
|
||||
{
|
||||
SrsAacProfileReserved = 3,
|
||||
|
||||
// @see 7.1 Profiles, aac-iso-13818-7.pdf, page 40
|
||||
SrsAacProfileMain = 0,
|
||||
SrsAacProfileLC = 1,
|
||||
SrsAacProfileSSR = 2,
|
||||
};
|
||||
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
|
||||
*/
|
||||
enum SrsAacObjectType
|
||||
{
|
||||
SrsAacObjectTypeReserved = 0,
|
||||
|
||||
// Table 1.1 – Audio Object Type definition
|
||||
// @see @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 23
|
||||
SrsAacObjectTypeAacMain = 1,
|
||||
SrsAacObjectTypeAacLC = 2,
|
||||
SrsAacObjectTypeAacSSR = 3,
|
||||
|
||||
// AAC HE = LC+SBR
|
||||
SrsAacObjectTypeHE = 5,
|
||||
// AAC HEv2 = LC+SBR+PS
|
||||
SrsAacObjectTypeHEV2 = 29,
|
||||
};
|
||||
std::string srs_codec_aac_object2str(SrsAacObjectType aac_object);
|
||||
// ts/hls/adts audio header profile to RTMP sequence header object type.
|
||||
SrsAacObjectType srs_codec_aac_ts2rtmp(SrsAacProfile profile);
|
||||
// RTMP sequence header object type to ts/hls/adts audio header profile.
|
||||
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.
|
||||
*/
|
||||
enum SrsAvcProfile
|
||||
{
|
||||
SrsAvcProfileReserved = 0,
|
||||
|
||||
// @see ffmpeg, libavcodec/avcodec.h:2713
|
||||
SrsAvcProfileBaseline = 66,
|
||||
// FF_PROFILE_H264_CONSTRAINED (1<<9) // 8+1; constraint_set1_flag
|
||||
// FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
|
||||
SrsAvcProfileConstrainedBaseline = 578,
|
||||
SrsAvcProfileMain = 77,
|
||||
SrsAvcProfileExtended = 88,
|
||||
SrsAvcProfileHigh = 100,
|
||||
SrsAvcProfileHigh10 = 110,
|
||||
SrsAvcProfileHigh10Intra = 2158,
|
||||
SrsAvcProfileHigh422 = 122,
|
||||
SrsAvcProfileHigh422Intra = 2170,
|
||||
SrsAvcProfileHigh444 = 144,
|
||||
SrsAvcProfileHigh444Predictive = 244,
|
||||
SrsAvcProfileHigh444Intra = 2192,
|
||||
};
|
||||
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.
|
||||
*/
|
||||
enum SrsAvcLevel
|
||||
{
|
||||
SrsAvcLevelReserved = 0,
|
||||
|
||||
SrsAvcLevel_1 = 10,
|
||||
SrsAvcLevel_11 = 11,
|
||||
SrsAvcLevel_12 = 12,
|
||||
SrsAvcLevel_13 = 13,
|
||||
SrsAvcLevel_2 = 20,
|
||||
SrsAvcLevel_21 = 21,
|
||||
SrsAvcLevel_22 = 22,
|
||||
SrsAvcLevel_3 = 30,
|
||||
SrsAvcLevel_31 = 31,
|
||||
SrsAvcLevel_32 = 32,
|
||||
SrsAvcLevel_4 = 40,
|
||||
SrsAvcLevel_41 = 41,
|
||||
SrsAvcLevel_5 = 50,
|
||||
SrsAvcLevel_51 = 51,
|
||||
};
|
||||
std::string srs_codec_avc_level2str(SrsAvcLevel level);
|
||||
|
||||
/**
|
||||
* the h264/avc and aac codec, for media stream.
|
||||
*
|
||||
|
@ -410,9 +504,9 @@ public:
|
|||
* video specified
|
||||
*/
|
||||
// profile_idc, H.264-AVC-ISO_IEC_14496-10.pdf, page 45.
|
||||
u_int8_t avc_profile;
|
||||
SrsAvcProfile avc_profile;
|
||||
// level_idc, H.264-AVC-ISO_IEC_14496-10.pdf, page 45.
|
||||
u_int8_t avc_level;
|
||||
SrsAvcLevel avc_level;
|
||||
// lengthSizeMinusOne, H.264-AVC-ISO_IEC_14496-15.pdf, page 16
|
||||
int8_t NAL_unit_length;
|
||||
u_int16_t sequenceParameterSetLength;
|
||||
|
@ -429,7 +523,7 @@ public:
|
|||
* 1.5.1.1 Audio object type definition, page 23,
|
||||
* in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf.
|
||||
*/
|
||||
u_int8_t aac_profile;
|
||||
SrsAacObjectType aac_object;
|
||||
/**
|
||||
* samplingFrequencyIndex
|
||||
*/
|
||||
|
|
|
@ -213,13 +213,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#define ERROR_HTTP_DVR_REQUEST 3051
|
||||
#define ERROR_HTTP_JSON_REQUIRED 3052
|
||||
#define ERROR_HTTP_DVR_CREATE_REQUEST 3053
|
||||
#define ERROR_HTTP_DVR_NO_TAEGET 3054
|
||||
#define ERROR_ADTS_ID_NOT_AAC 3055
|
||||
|
||||
// HDS error code
|
||||
#define ERROR_HDS_OPEN_F4M_FAILED 3054
|
||||
#define ERROR_HDS_WRITE_F4M_FAILED 3055
|
||||
#define ERROR_HDS_OPEN_BOOTSTRAP_FAILED 3056
|
||||
#define ERROR_HDS_WRITE_BOOTSTRAP_FAILED 3057
|
||||
#define ERROR_HDS_OPEN_FRAGMENT_FAILED 3058
|
||||
#define ERROR_HDS_WRITE_FRAGMENT_FAILED 3059
|
||||
#define ERROR_HDS_OPEN_F4M_FAILED 3056
|
||||
#define ERROR_HDS_WRITE_F4M_FAILED 3057
|
||||
#define ERROR_HDS_OPEN_BOOTSTRAP_FAILED 3058
|
||||
#define ERROR_HDS_WRITE_BOOTSTRAP_FAILED 3059
|
||||
#define ERROR_HDS_OPEN_FRAGMENT_FAILED 3060
|
||||
#define ERROR_HDS_WRITE_FRAGMENT_FAILED 3061
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
// HTTP/StreamCaster protocol error.
|
||||
|
@ -249,6 +252,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#define ERROR_STREAM_CASTER_AVC_SPS 4022
|
||||
#define ERROR_STREAM_CASTER_AVC_PPS 4023
|
||||
#define ERROR_STREAM_CASTER_FLV_TAG 4024
|
||||
#define ERROR_HTTP_RESPONSE_EOF 4025
|
||||
#define ERROR_HTTP_INVALID_CHUNK_HEADER 4026
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
// user-define error.
|
||||
///////////////////////////////////////////////////////
|
||||
#define ERROR_USER_START 9000
|
||||
#define ERROR_USER_END 9999
|
||||
|
||||
/**
|
||||
* whether the error code is an system control error.
|
||||
|
|
|
@ -82,6 +82,7 @@ public:
|
|||
virtual int open(std::string file);
|
||||
virtual void close();
|
||||
public:
|
||||
// TODO: FIXME: extract interface.
|
||||
virtual bool is_open();
|
||||
virtual int64_t tellg();
|
||||
virtual void skip(int64_t size);
|
||||
|
|
|
@ -36,6 +36,7 @@ using namespace std;
|
|||
#include <srs_kernel_error.hpp>
|
||||
#include <srs_kernel_stream.hpp>
|
||||
#include <srs_kernel_file.hpp>
|
||||
#include <srs_kernel_codec.hpp>
|
||||
|
||||
#define SRS_FLV_TAG_HEADER_SIZE 11
|
||||
#define SRS_FLV_PREVIOUS_TAG_SIZE 4
|
||||
|
@ -149,7 +150,7 @@ int SrsFlvEncoder::write_audio(int64_t timestamp, char* data, int size)
|
|||
|
||||
// 11bytes tag header
|
||||
static char tag_header[] = {
|
||||
(char)8, // TagType UB [5], 8 = audio
|
||||
(char)SrsCodecFlvTagAudio, // TagType UB [5], 8 = audio
|
||||
(char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message.
|
||||
(char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies.
|
||||
(char)0x00, // TimestampExtended UI8
|
||||
|
@ -183,7 +184,7 @@ int SrsFlvEncoder::write_video(int64_t timestamp, char* data, int size)
|
|||
|
||||
// 11bytes tag header
|
||||
static char tag_header[] = {
|
||||
(char)9, // TagType UB [5], 9 = video
|
||||
(char)SrsCodecFlvTagVideo, // TagType UB [5], 9 = video
|
||||
(char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message.
|
||||
(char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies.
|
||||
(char)0x00, // TimestampExtended UI8
|
||||
|
|
|
@ -67,6 +67,7 @@ public:
|
|||
/**
|
||||
* write flv metadata.
|
||||
* @param type, the type of data, or other message type.
|
||||
* @see SrsCodecFlvTag
|
||||
* @param data, the amf0 metadata which serialize from:
|
||||
* AMF0 string: onMetaData,
|
||||
* AMF0 object: the metadata object.
|
||||
|
|
|
@ -56,25 +56,6 @@ using namespace std;
|
|||
#define TS_AUDIO_AAC_PID 0x102
|
||||
#define TS_AUDIO_MP3_PID 0x103
|
||||
|
||||
/**
|
||||
* the public data, event HLS disable, others can use it.
|
||||
*/
|
||||
// 0 = 5.5 kHz = 5512 Hz
|
||||
// 1 = 11 kHz = 11025 Hz
|
||||
// 2 = 22 kHz = 22050 Hz
|
||||
// 3 = 44 kHz = 44100 Hz
|
||||
int flv_sample_rates[] = {5512, 11025, 22050, 44100};
|
||||
|
||||
// the sample rates in the codec,
|
||||
// in the sequence header.
|
||||
int aac_sample_rates[] =
|
||||
{
|
||||
96000, 88200, 64000, 48000,
|
||||
44100, 32000, 24000, 22050,
|
||||
16000, 12000, 11025, 8000,
|
||||
7350, 0, 0, 0
|
||||
};
|
||||
|
||||
string srs_ts_stream2string(SrsTsStream stream)
|
||||
{
|
||||
switch (stream) {
|
||||
|
@ -1130,7 +1111,7 @@ int SrsTsAdaptationField::encode(SrsStream* stream)
|
|||
// @see https://github.com/winlinvip/simple-rtmp-server/issues/250#issuecomment-71349370
|
||||
int64_t pcrv = program_clock_reference_extension & 0x1ff;
|
||||
pcrv |= (const1_value0 << 9) & 0x7E00;
|
||||
pcrv |= (program_clock_reference_base << 15) & 0x1FFFFFFFF000000;
|
||||
pcrv |= (program_clock_reference_base << 15) & 0x1FFFFFFFF000000LL;
|
||||
|
||||
pp = (char*)&pcrv;
|
||||
*p++ = pp[5];
|
||||
|
@ -2783,20 +2764,6 @@ int SrsTsCache::do_cache_aac(SrsAvcAacCodec* codec, SrsCodecSample* sample)
|
|||
srs_error("invalid aac frame length=%d, ret=%d", size, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// the profile = object_id + 1
|
||||
// @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 78,
|
||||
// Table 1. A.9 ¨C MPEG-2 Audio profiles and MPEG-4 Audio object types
|
||||
// the valid object type:
|
||||
// AAC Main(ID == 0)
|
||||
// AAC LC(ID == 1)
|
||||
// AAC SSR(ID == 2)
|
||||
// AAC LTP(ID == 3)
|
||||
u_int8_t profile_ObjectType = codec->aac_profile - 1;
|
||||
|
||||
// TODO: FIXME: only support Main or LC.
|
||||
// @see https://github.com/winlinvip/simple-rtmp-server/issues/310
|
||||
profile_ObjectType = srs_min(1, profile_ObjectType);
|
||||
|
||||
// the frame length is the AAC raw data plus the adts header size.
|
||||
int32_t frame_length = size + 7;
|
||||
|
@ -2805,12 +2772,12 @@ int SrsTsCache::do_cache_aac(SrsAvcAacCodec* codec, SrsCodecSample* sample)
|
|||
// 6.2 Audio Data Transport Stream, ADTS
|
||||
// in aac-iso-13818-7.pdf, page 26.
|
||||
// fixed 7bytes header
|
||||
static u_int8_t adts_header[7] = {0xff, 0xf1, 0x00, 0x00, 0x00, 0x0f, 0xfc};
|
||||
static u_int8_t adts_header[7] = {0xff, 0xf9, 0x00, 0x00, 0x00, 0x0f, 0xfc};
|
||||
/*
|
||||
// adts_fixed_header
|
||||
// 2B, 16bits
|
||||
int16_t syncword; //12bits, '1111 1111 1111'
|
||||
int8_t ID; //1bit, '0'
|
||||
int8_t ID; //1bit, '1'
|
||||
int8_t layer; //2bits, '00'
|
||||
int8_t protection_absent; //1bit, can be '1'
|
||||
// 12bits
|
||||
|
@ -2830,7 +2797,8 @@ int SrsTsCache::do_cache_aac(SrsAvcAacCodec* codec, SrsCodecSample* sample)
|
|||
int8_t number_of_raw_data_blocks_in_frame; //2bits, 0 indicating 1 raw_data_block()
|
||||
*/
|
||||
// profile, 2bits
|
||||
adts_header[2] = (profile_ObjectType << 6) & 0xc0;
|
||||
SrsAacProfile aac_profile = srs_codec_aac_rtmp2ts(codec->aac_object);
|
||||
adts_header[2] = (aac_profile << 6) & 0xc0;
|
||||
// sampling_frequency_index 4bits
|
||||
adts_header[2] |= (codec->aac_sample_rate << 2) & 0x3c;
|
||||
// channel_configuration 3bits
|
||||
|
|
|
@ -437,7 +437,9 @@ u_int32_t srs_crc32(const void* buf, int size)
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef UINT_MAX
|
||||
#define UINT_MAX 0xffffffff
|
||||
#endif
|
||||
|
||||
#ifndef AV_RB32
|
||||
# define AV_RB32(x) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue