2017-03-25 09:21:39 +00:00
|
|
|
/**
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
2019-12-30 02:10:35 +00:00
|
|
|
* Copyright (c) 2013-2020 Winlin
|
2017-03-25 09:21:39 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2013-11-23 03:36:07 +00:00
|
|
|
|
2014-05-28 09:37:15 +00:00
|
|
|
#ifndef SRS_KERNEL_CODEC_HPP
|
|
|
|
#define SRS_KERNEL_CODEC_HPP
|
2013-11-23 03:36:07 +00:00
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
2015-01-31 13:16:42 +00:00
|
|
|
#include <string>
|
2017-04-24 02:08:57 +00:00
|
|
|
#include <vector>
|
2015-01-31 13:16:42 +00:00
|
|
|
|
2015-09-22 00:57:31 +00:00
|
|
|
class SrsBuffer;
|
2015-01-31 13:16:42 +00:00
|
|
|
|
2017-02-12 12:38:39 +00:00
|
|
|
/**
|
|
|
|
* The video codec id.
|
|
|
|
* @doc video_file_format_spec_v10_1.pdf, page78, E.4.3.1 VIDEODATA
|
|
|
|
* CodecID UB [4]
|
|
|
|
* Codec Identifier. The following values are defined for FLV:
|
|
|
|
* 2 = Sorenson H.263
|
|
|
|
* 3 = Screen video
|
|
|
|
* 4 = On2 VP6
|
|
|
|
* 5 = On2 VP6 with alpha channel
|
|
|
|
* 6 = Screen video version 2
|
|
|
|
* 7 = AVC
|
|
|
|
*/
|
|
|
|
enum SrsVideoCodecId
|
2013-11-24 04:39:47 +00:00
|
|
|
{
|
2015-01-31 11:46:55 +00:00
|
|
|
// set to the zero to reserved, for array map.
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsVideoCodecIdReserved = 0,
|
|
|
|
SrsVideoCodecIdForbidden = 0,
|
|
|
|
SrsVideoCodecIdReserved1 = 1,
|
|
|
|
SrsVideoCodecIdReserved2 = 9,
|
|
|
|
|
|
|
|
// for user to disable video, for example, use pure audio hls.
|
|
|
|
SrsVideoCodecIdDisabled = 8,
|
2014-03-18 03:32:58 +00:00
|
|
|
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsVideoCodecIdSorensonH263 = 2,
|
|
|
|
SrsVideoCodecIdScreenVideo = 3,
|
|
|
|
SrsVideoCodecIdOn2VP6 = 4,
|
|
|
|
SrsVideoCodecIdOn2VP6WithAlphaChannel = 5,
|
|
|
|
SrsVideoCodecIdScreenVideoVersion2 = 6,
|
|
|
|
SrsVideoCodecIdAVC = 7,
|
2019-01-17 01:24:17 +00:00
|
|
|
// See page 79 at @doc https://github.com/CDN-Union/H265/blob/master/Document/video_file_format_spec_v10_1_ksyun_20170615.doc
|
|
|
|
SrsVideoCodecIdHEVC = 12,
|
2020-01-19 03:22:35 +00:00
|
|
|
// https://mp.weixin.qq.com/s/H3qI7zsON5sdf4oDJ9qlkg
|
|
|
|
SrsVideoCodecIdAV1 = 13,
|
2013-11-24 04:39:47 +00:00
|
|
|
};
|
2017-02-12 12:38:39 +00:00
|
|
|
std::string srs_video_codec_id2str(SrsVideoCodecId codec);
|
2013-11-24 04:39:47 +00:00
|
|
|
|
2017-02-12 12:38:39 +00:00
|
|
|
/**
|
|
|
|
* The video AVC frame trait(characteristic).
|
|
|
|
* @doc video_file_format_spec_v10_1.pdf, page79, E.4.3.2 AVCVIDEOPACKET
|
|
|
|
* AVCPacketType IF CodecID == 7 UI8
|
|
|
|
* The following values are defined:
|
|
|
|
* 0 = AVC sequence header
|
|
|
|
* 1 = AVC NALU
|
|
|
|
* 2 = AVC end of sequence (lower level NALU sequence ender is not required or supported)
|
|
|
|
*/
|
|
|
|
enum SrsVideoAvcFrameTrait
|
2013-11-24 04:39:47 +00:00
|
|
|
{
|
2014-07-06 01:59:41 +00:00
|
|
|
// set to the max value to reserved, for array map.
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsVideoAvcFrameTraitReserved = 3,
|
|
|
|
SrsVideoAvcFrameTraitForbidden = 3,
|
2014-03-18 03:32:58 +00:00
|
|
|
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsVideoAvcFrameTraitSequenceHeader = 0,
|
|
|
|
SrsVideoAvcFrameTraitNALU = 1,
|
|
|
|
SrsVideoAvcFrameTraitSequenceHeaderEOF = 2,
|
2013-11-24 04:39:47 +00:00
|
|
|
};
|
|
|
|
|
2017-02-12 12:38:39 +00:00
|
|
|
/**
|
|
|
|
* The video AVC frame type, such as I/P/B.
|
|
|
|
* @doc video_file_format_spec_v10_1.pdf, page78, E.4.3.1 VIDEODATA
|
|
|
|
* Frame Type UB [4]
|
|
|
|
* Type of video frame. The following values are defined:
|
|
|
|
* 1 = key frame (for AVC, a seekable frame)
|
|
|
|
* 2 = inter frame (for AVC, a non-seekable frame)
|
|
|
|
* 3 = disposable inter frame (H.263 only)
|
|
|
|
* 4 = generated key frame (reserved for server use only)
|
|
|
|
* 5 = video info/command frame
|
|
|
|
*/
|
|
|
|
enum SrsVideoAvcFrameType
|
2014-06-08 14:36:17 +00:00
|
|
|
{
|
2015-01-31 11:46:55 +00:00
|
|
|
// set to the zero to reserved, for array map.
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsVideoAvcFrameTypeReserved = 0,
|
|
|
|
SrsVideoAvcFrameTypeForbidden = 0,
|
|
|
|
SrsVideoAvcFrameTypeReserved1 = 6,
|
2014-06-08 14:36:17 +00:00
|
|
|
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsVideoAvcFrameTypeKeyFrame = 1,
|
|
|
|
SrsVideoAvcFrameTypeInterFrame = 2,
|
|
|
|
SrsVideoAvcFrameTypeDisposableInterFrame = 3,
|
|
|
|
SrsVideoAvcFrameTypeGeneratedKeyFrame = 4,
|
|
|
|
SrsVideoAvcFrameTypeVideoInfoFrame = 5,
|
2014-06-08 14:36:17 +00:00
|
|
|
};
|
2017-02-12 12:38:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The audio codec id.
|
|
|
|
* @doc video_file_format_spec_v10_1.pdf, page 76, E.4.2 Audio Tags
|
|
|
|
* SoundFormat UB [4]
|
|
|
|
* Format of SoundData. The following values are defined:
|
|
|
|
* 0 = Linear PCM, platform endian
|
|
|
|
* 1 = ADPCM
|
|
|
|
* 2 = MP3
|
|
|
|
* 3 = Linear PCM, little endian
|
|
|
|
* 4 = Nellymoser 16 kHz mono
|
|
|
|
* 5 = Nellymoser 8 kHz mono
|
|
|
|
* 6 = Nellymoser
|
|
|
|
* 7 = G.711 A-law logarithmic PCM
|
|
|
|
* 8 = G.711 mu-law logarithmic PCM
|
|
|
|
* 9 = reserved
|
|
|
|
* 10 = AAC
|
|
|
|
* 11 = Speex
|
|
|
|
* 14 = MP3 8 kHz
|
|
|
|
* 15 = Device-specific sound
|
|
|
|
* Formats 7, 8, 14, and 15 are reserved.
|
|
|
|
* AAC is supported in Flash Player 9,0,115,0 and higher.
|
|
|
|
* Speex is supported in Flash Player 10 and higher.
|
|
|
|
*/
|
|
|
|
enum SrsAudioCodecId
|
2013-11-24 04:39:47 +00:00
|
|
|
{
|
2014-07-06 01:59:41 +00:00
|
|
|
// set to the max value to reserved, for array map.
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsAudioCodecIdReserved1 = 16,
|
|
|
|
SrsAudioCodecIdForbidden = 16,
|
2014-07-06 01:59:41 +00:00
|
|
|
|
2015-05-29 13:43:17 +00:00
|
|
|
// for user to disable audio, for example, use pure video hls.
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsAudioCodecIdDisabled = 17,
|
2015-05-29 13:43:17 +00:00
|
|
|
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsAudioCodecIdLinearPCMPlatformEndian = 0,
|
|
|
|
SrsAudioCodecIdADPCM = 1,
|
|
|
|
SrsAudioCodecIdMP3 = 2,
|
|
|
|
SrsAudioCodecIdLinearPCMLittleEndian = 3,
|
|
|
|
SrsAudioCodecIdNellymoser16kHzMono = 4,
|
|
|
|
SrsAudioCodecIdNellymoser8kHzMono = 5,
|
|
|
|
SrsAudioCodecIdNellymoser = 6,
|
|
|
|
SrsAudioCodecIdReservedG711AlawLogarithmicPCM = 7,
|
|
|
|
SrsAudioCodecIdReservedG711MuLawLogarithmicPCM = 8,
|
|
|
|
SrsAudioCodecIdReserved = 9,
|
|
|
|
SrsAudioCodecIdAAC = 10,
|
|
|
|
SrsAudioCodecIdSpeex = 11,
|
2019-01-17 01:24:17 +00:00
|
|
|
// For FLV, it's undefined, we define it as Opus for WebRTC.
|
|
|
|
SrsAudioCodecIdOpus = 13,
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsAudioCodecIdReservedMP3_8kHz = 14,
|
|
|
|
SrsAudioCodecIdReservedDeviceSpecificSound = 15,
|
2013-11-24 04:39:47 +00:00
|
|
|
};
|
2017-02-12 12:38:39 +00:00
|
|
|
std::string srs_audio_codec_id2str(SrsAudioCodecId codec);
|
2013-11-24 04:39:47 +00:00
|
|
|
|
2014-11-24 08:28:52 +00:00
|
|
|
/**
|
2017-02-12 12:38:39 +00:00
|
|
|
* The audio AAC frame trait(characteristic).
|
|
|
|
* @doc video_file_format_spec_v10_1.pdf, page 77, E.4.2 Audio Tags
|
2019-01-17 08:01:43 +00:00
|
|
|
* AACPacketType IF SoundFormat == 10 or 13 UI8
|
2017-02-12 12:38:39 +00:00
|
|
|
* The following values are defined:
|
|
|
|
* 0 = AAC sequence header
|
|
|
|
* 1 = AAC raw
|
|
|
|
*/
|
|
|
|
enum SrsAudioAacFrameTrait
|
2014-11-24 08:28:52 +00:00
|
|
|
{
|
|
|
|
// set to the max value to reserved, for array map.
|
2019-01-17 08:01:43 +00:00
|
|
|
SrsAudioAacFrameTraitReserved = 0xff,
|
|
|
|
SrsAudioAacFrameTraitForbidden = 0xff,
|
2014-11-24 08:28:52 +00:00
|
|
|
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsAudioAacFrameTraitSequenceHeader = 0,
|
|
|
|
SrsAudioAacFrameTraitRawData = 1,
|
2019-01-17 08:01:43 +00:00
|
|
|
|
|
|
|
// For Opus, the frame trait, may has more than one traits.
|
|
|
|
SrsAudioOpusFrameTraitRaw = 2,
|
|
|
|
SrsAudioOpusFrameTraitSamplingRate = 4,
|
|
|
|
SrsAudioOpusFrameTraitAudioLevel = 8,
|
2014-11-24 08:28:52 +00:00
|
|
|
};
|
|
|
|
|
2015-01-31 11:46:55 +00:00
|
|
|
/**
|
2017-02-12 12:38:39 +00:00
|
|
|
* The audio sample rate.
|
|
|
|
* @see srs_flv_srates and srs_aac_srates.
|
|
|
|
* @doc video_file_format_spec_v10_1.pdf, page 76, E.4.2 Audio Tags
|
|
|
|
* 0 = 5.5 kHz = 5512 Hz
|
|
|
|
* 1 = 11 kHz = 11025 Hz
|
|
|
|
* 2 = 22 kHz = 22050 Hz
|
|
|
|
* 3 = 44 kHz = 44100 Hz
|
|
|
|
* However, we can extends this table.
|
2017-04-16 13:33:39 +00:00
|
|
|
* @remark Use srs_flv_srates to convert it.
|
2017-02-12 12:38:39 +00:00
|
|
|
*/
|
|
|
|
enum SrsAudioSampleRate
|
|
|
|
{
|
|
|
|
// set to the max value to reserved, for array map.
|
2019-01-17 03:35:15 +00:00
|
|
|
SrsAudioSampleRateReserved = 0xff,
|
|
|
|
SrsAudioSampleRateForbidden = 0xff,
|
2017-02-12 12:38:39 +00:00
|
|
|
|
2019-01-17 03:35:15 +00:00
|
|
|
// For FLV, only support 5, 11, 22, 44KHz sampling rate.
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsAudioSampleRate5512 = 0,
|
|
|
|
SrsAudioSampleRate11025 = 1,
|
|
|
|
SrsAudioSampleRate22050 = 2,
|
|
|
|
SrsAudioSampleRate44100 = 3,
|
2019-01-17 03:35:15 +00:00
|
|
|
|
|
|
|
// For Opus, support 8, 12, 16, 24, 48KHz
|
|
|
|
// We will write a UINT8 sampling rate after FLV audio tag header.
|
|
|
|
// @doc https://tools.ietf.org/html/rfc6716#section-2
|
|
|
|
SrsAudioSampleRateNB8kHz = 8, // NB (narrowband)
|
|
|
|
SrsAudioSampleRateMB12kHz = 12, // MB (medium-band)
|
|
|
|
SrsAudioSampleRateWB16kHz = 16, // WB (wideband)
|
|
|
|
SrsAudioSampleRateSWB24kHz = 24, // SWB (super-wideband)
|
|
|
|
SrsAudioSampleRateFB48kHz = 48, // FB (fullband)
|
2017-02-12 12:38:39 +00:00
|
|
|
};
|
2017-02-12 12:46:24 +00:00
|
|
|
std::string srs_audio_sample_rate2str(SrsAudioSampleRate v);
|
2017-02-12 12:38:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The frame type, for example, audio, video or data.
|
|
|
|
* @doc video_file_format_spec_v10_1.pdf, page 75, E.4.1 FLV Tag
|
|
|
|
*/
|
|
|
|
enum SrsFrameType
|
2015-01-31 11:46:55 +00:00
|
|
|
{
|
|
|
|
// set to the zero to reserved, for array map.
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsFrameTypeReserved = 0,
|
|
|
|
SrsFrameTypeForbidden = 0,
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-01-31 11:46:55 +00:00
|
|
|
// 8 = audio
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsFrameTypeAudio = 8,
|
2015-01-31 11:46:55 +00:00
|
|
|
// 9 = video
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsFrameTypeVideo = 9,
|
2015-01-31 11:46:55 +00:00
|
|
|
// 18 = script data
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsFrameTypeScript = 18,
|
2015-01-31 11:46:55 +00:00
|
|
|
};
|
|
|
|
|
2013-11-23 03:36:07 +00:00
|
|
|
/**
|
2017-02-12 12:38:39 +00:00
|
|
|
* Fast tough the codec of FLV video.
|
|
|
|
* @doc video_file_format_spec_v10_1.pdf, page 78, E.4.3 Video Tags
|
|
|
|
*/
|
|
|
|
class SrsFlvVideo
|
2013-11-23 03:36:07 +00:00
|
|
|
{
|
2013-11-24 04:39:47 +00:00
|
|
|
public:
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsFlvVideo();
|
|
|
|
virtual ~SrsFlvVideo();
|
2017-03-25 09:21:39 +00:00
|
|
|
// the following function used to finger out the flv/rtmp packet detail.
|
2013-11-23 03:36:07 +00:00
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* only check the frame_type, not check the codec type.
|
|
|
|
*/
|
2017-02-12 12:38:39 +00:00
|
|
|
static bool keyframe(char* data, int size);
|
2014-03-18 03:32:58 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* check codec h264, keyframe, sequence header
|
|
|
|
*/
|
2017-06-04 07:10:35 +00:00
|
|
|
// TODO: FIXME: Remove it, use SrsFormat instead.
|
2017-02-12 12:38:39 +00:00
|
|
|
static bool sh(char* data, int size);
|
2014-03-18 03:32:58 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* check codec h264.
|
|
|
|
*/
|
2017-02-12 12:38:39 +00:00
|
|
|
static bool h264(char* data, int size);
|
2015-06-06 13:23:57 +00:00
|
|
|
/**
|
|
|
|
* check the video RTMP/flv header info,
|
|
|
|
* @return true if video RTMP/flv header is ok.
|
|
|
|
* @remark all type of audio is possible, no need to check audio.
|
|
|
|
*/
|
2017-02-12 12:38:39 +00:00
|
|
|
static bool acceptable(char* data, int size);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fast tough the codec of FLV video.
|
|
|
|
* @doc video_file_format_spec_v10_1.pdf, page 76, E.4.2 Audio Tags
|
|
|
|
*/
|
|
|
|
class SrsFlvAudio
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsFlvAudio();
|
|
|
|
virtual ~SrsFlvAudio();
|
2017-03-25 09:21:39 +00:00
|
|
|
// the following function used to finger out the flv/rtmp packet detail.
|
2017-02-12 12:38:39 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* check codec aac, sequence header
|
|
|
|
*/
|
|
|
|
static bool sh(char* data, int size);
|
|
|
|
/**
|
|
|
|
* check codec aac.
|
|
|
|
*/
|
|
|
|
static bool aac(char* data, int size);
|
2013-11-23 03:36:07 +00:00
|
|
|
};
|
|
|
|
|
2015-01-31 13:16:42 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* the public data, event HLS disable, others can use it.
|
|
|
|
*/
|
2015-01-31 13:16:42 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* the flv sample rate map
|
|
|
|
*/
|
2017-02-12 12:38:39 +00:00
|
|
|
extern int srs_flv_srates[];
|
2015-01-31 13:16:42 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* the aac sample rate map
|
|
|
|
*/
|
2017-02-12 12:38:39 +00:00
|
|
|
extern int srs_aac_srates[];
|
2015-01-31 13:16:42 +00:00
|
|
|
|
2017-01-18 03:11:36 +00:00
|
|
|
// The impossible aac sample rate index.
|
2017-02-12 12:38:39 +00:00
|
|
|
#define SrsAacSampleRateUnset 15
|
2015-01-31 13:16:42 +00:00
|
|
|
|
2017-01-18 03:11:36 +00:00
|
|
|
// The max number of NALUs in a video, or aac frame in audio packet.
|
2017-02-12 12:38:39 +00:00
|
|
|
#define SrsMaxNbSamples 256
|
2017-01-18 03:11:36 +00:00
|
|
|
|
2015-01-31 13:16:42 +00:00
|
|
|
/**
|
2017-02-12 12:46:24 +00:00
|
|
|
* 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
|
2015-01-31 13:16:42 +00:00
|
|
|
{
|
|
|
|
// set to the max value to reserved, for array map.
|
2017-02-12 12:46:24 +00:00
|
|
|
SrsAudioSampleBitsReserved = 2,
|
|
|
|
SrsAudioSampleBitsForbidden = 2,
|
2015-01-31 13:16:42 +00:00
|
|
|
|
2017-02-12 12:46:24 +00:00
|
|
|
SrsAudioSampleBits8bit = 0,
|
|
|
|
SrsAudioSampleBits16bit = 1,
|
2015-01-31 13:16:42 +00:00
|
|
|
};
|
2017-02-12 12:46:24 +00:00
|
|
|
std::string srs_audio_sample_bits2str(SrsAudioSampleBits v);
|
2015-01-31 13:16:42 +00:00
|
|
|
|
|
|
|
/**
|
2017-02-12 12:46:24 +00:00
|
|
|
* 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
|
2015-01-31 13:16:42 +00:00
|
|
|
{
|
|
|
|
// set to the max value to reserved, for array map.
|
2017-02-12 12:46:24 +00:00
|
|
|
SrsAudioChannelsReserved = 2,
|
|
|
|
SrsAudioChannelsForbidden = 2,
|
2015-01-31 13:16:42 +00:00
|
|
|
|
2017-02-12 12:46:24 +00:00
|
|
|
SrsAudioChannelsMono = 0,
|
|
|
|
SrsAudioChannelsStereo = 1,
|
2015-01-31 13:16:42 +00:00
|
|
|
};
|
2017-02-12 12:46:24 +00:00
|
|
|
std::string srs_audio_channels2str(SrsAudioChannels v);
|
2015-01-31 13:16:42 +00:00
|
|
|
|
2015-04-04 05:30:13 +00:00
|
|
|
/**
|
2015-05-09 15:12:12 +00:00
|
|
|
* Table 7-1 - NAL unit type codes, syntax element categories, and NAL unit type classes
|
2017-01-26 09:28:49 +00:00
|
|
|
* ISO_IEC_14496-10-AVC-2012.pdf, page 83.
|
2015-04-04 05:30:13 +00:00
|
|
|
*/
|
|
|
|
enum SrsAvcNaluType
|
|
|
|
{
|
|
|
|
// Unspecified
|
|
|
|
SrsAvcNaluTypeReserved = 0,
|
2017-02-11 15:09:23 +00:00
|
|
|
SrsAvcNaluTypeForbidden = 0,
|
2015-04-04 05:30:13 +00:00
|
|
|
|
|
|
|
// Coded slice of a non-IDR picture slice_layer_without_partitioning_rbsp( )
|
|
|
|
SrsAvcNaluTypeNonIDR = 1,
|
|
|
|
// Coded slice data partition A slice_data_partition_a_layer_rbsp( )
|
|
|
|
SrsAvcNaluTypeDataPartitionA = 2,
|
|
|
|
// Coded slice data partition B slice_data_partition_b_layer_rbsp( )
|
|
|
|
SrsAvcNaluTypeDataPartitionB = 3,
|
|
|
|
// Coded slice data partition C slice_data_partition_c_layer_rbsp( )
|
|
|
|
SrsAvcNaluTypeDataPartitionC = 4,
|
|
|
|
// Coded slice of an IDR picture slice_layer_without_partitioning_rbsp( )
|
|
|
|
SrsAvcNaluTypeIDR = 5,
|
|
|
|
// Supplemental enhancement information (SEI) sei_rbsp( )
|
|
|
|
SrsAvcNaluTypeSEI = 6,
|
|
|
|
// Sequence parameter set seq_parameter_set_rbsp( )
|
|
|
|
SrsAvcNaluTypeSPS = 7,
|
|
|
|
// Picture parameter set pic_parameter_set_rbsp( )
|
|
|
|
SrsAvcNaluTypePPS = 8,
|
|
|
|
// Access unit delimiter access_unit_delimiter_rbsp( )
|
|
|
|
SrsAvcNaluTypeAccessUnitDelimiter = 9,
|
|
|
|
// End of sequence end_of_seq_rbsp( )
|
|
|
|
SrsAvcNaluTypeEOSequence = 10,
|
|
|
|
// End of stream end_of_stream_rbsp( )
|
|
|
|
SrsAvcNaluTypeEOStream = 11,
|
|
|
|
// Filler data filler_data_rbsp( )
|
|
|
|
SrsAvcNaluTypeFilterData = 12,
|
|
|
|
// Sequence parameter set extension seq_parameter_set_extension_rbsp( )
|
|
|
|
SrsAvcNaluTypeSPSExt = 13,
|
|
|
|
// Prefix NAL unit prefix_nal_unit_rbsp( )
|
|
|
|
SrsAvcNaluTypePrefixNALU = 14,
|
|
|
|
// Subset sequence parameter set subset_seq_parameter_set_rbsp( )
|
|
|
|
SrsAvcNaluTypeSubsetSPS = 15,
|
|
|
|
// Coded slice of an auxiliary coded picture without partitioning slice_layer_without_partitioning_rbsp( )
|
|
|
|
SrsAvcNaluTypeLayerWithoutPartition = 19,
|
|
|
|
// Coded slice extension slice_layer_extension_rbsp( )
|
|
|
|
SrsAvcNaluTypeCodedSliceExt = 20,
|
|
|
|
};
|
2017-02-12 12:38:39 +00:00
|
|
|
std::string srs_avc_nalu2str(SrsAvcNaluType nalu_type);
|
2015-04-04 05:30:13 +00:00
|
|
|
|
2015-01-31 13:16:42 +00:00
|
|
|
/**
|
2017-02-11 15:09:23 +00:00
|
|
|
* the avc payload format, must be ibmf or annexb format.
|
|
|
|
* we guess by annexb first, then ibmf for the first time,
|
|
|
|
* and we always use the guessed format for the next time.
|
|
|
|
*/
|
2015-02-10 14:37:29 +00:00
|
|
|
enum SrsAvcPayloadFormat
|
|
|
|
{
|
|
|
|
SrsAvcPayloadFormatGuess = 0,
|
|
|
|
SrsAvcPayloadFormatAnnexb,
|
|
|
|
SrsAvcPayloadFormatIbmf,
|
|
|
|
};
|
|
|
|
|
2015-03-08 09:33:52 +00:00
|
|
|
/**
|
2017-02-11 15:09:23 +00:00
|
|
|
* the aac profile, for ADTS(HLS/TS)
|
|
|
|
* @see https://github.com/ossrs/srs/issues/310
|
|
|
|
*/
|
2015-03-08 09:33:52 +00:00
|
|
|
enum SrsAacProfile
|
|
|
|
{
|
|
|
|
SrsAacProfileReserved = 3,
|
|
|
|
|
2017-03-06 02:19:19 +00:00
|
|
|
// @see 7.1 Profiles, ISO_IEC_13818-7-AAC-2004.pdf, page 40
|
2015-03-08 09:33:52 +00:00
|
|
|
SrsAacProfileMain = 0,
|
|
|
|
SrsAacProfileLC = 1,
|
|
|
|
SrsAacProfileSSR = 2,
|
|
|
|
};
|
2017-02-12 12:38:39 +00:00
|
|
|
std::string srs_aac_profile2str(SrsAacProfile aac_profile);
|
2015-03-08 09:33:52 +00:00
|
|
|
|
|
|
|
/**
|
2017-02-11 15:09:23 +00:00
|
|
|
* the aac object type, for RTMP sequence header
|
|
|
|
* for AudioSpecificConfig, @see ISO_IEC_14496-3-AAC-2001.pdf, page 33
|
|
|
|
* for audioObjectType, @see ISO_IEC_14496-3-AAC-2001.pdf, page 23
|
|
|
|
*/
|
2015-03-08 09:33:52 +00:00
|
|
|
enum SrsAacObjectType
|
|
|
|
{
|
|
|
|
SrsAacObjectTypeReserved = 0,
|
2017-02-12 10:18:18 +00:00
|
|
|
SrsAacObjectTypeForbidden = 0,
|
2015-03-08 09:33:52 +00:00
|
|
|
|
2015-05-09 15:12:12 +00:00
|
|
|
// Table 1.1 - Audio Object Type definition
|
2017-01-26 09:28:49 +00:00
|
|
|
// @see @see ISO_IEC_14496-3-AAC-2001.pdf, page 23
|
2015-03-08 09:33:52 +00:00
|
|
|
SrsAacObjectTypeAacMain = 1,
|
|
|
|
SrsAacObjectTypeAacLC = 2,
|
|
|
|
SrsAacObjectTypeAacSSR = 3,
|
2015-03-08 09:36:43 +00:00
|
|
|
|
|
|
|
// AAC HE = LC+SBR
|
2015-03-26 03:31:40 +00:00
|
|
|
SrsAacObjectTypeAacHE = 5,
|
2015-03-08 09:36:43 +00:00
|
|
|
// AAC HEv2 = LC+SBR+PS
|
2015-03-26 03:31:40 +00:00
|
|
|
SrsAacObjectTypeAacHEV2 = 29,
|
2015-03-08 09:33:52 +00:00
|
|
|
};
|
2017-02-12 12:38:39 +00:00
|
|
|
std::string srs_aac_object2str(SrsAacObjectType aac_object);
|
2015-03-08 09:33:52 +00:00
|
|
|
// ts/hls/adts audio header profile to RTMP sequence header object type.
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsAacObjectType srs_aac_ts2rtmp(SrsAacProfile profile);
|
2015-03-08 09:33:52 +00:00
|
|
|
// RTMP sequence header object type to ts/hls/adts audio header profile.
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsAacProfile srs_aac_rtmp2ts(SrsAacObjectType object_type);
|
2015-03-08 07:33:08 +00:00
|
|
|
|
2015-03-08 10:33:35 +00:00
|
|
|
/**
|
2017-02-11 15:09:23 +00:00
|
|
|
* the profile for avc/h.264.
|
|
|
|
* @see Annex A Profiles and levels, ISO_IEC_14496-10-AVC-2003.pdf, page 205.
|
|
|
|
*/
|
2015-03-08 10:33:35 +00:00
|
|
|
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,
|
|
|
|
};
|
2017-02-12 12:38:39 +00:00
|
|
|
std::string srs_avc_profile2str(SrsAvcProfile profile);
|
2015-03-08 10:33:35 +00:00
|
|
|
|
|
|
|
/**
|
2017-02-11 15:09:23 +00:00
|
|
|
* the level for avc/h.264.
|
|
|
|
* @see Annex A Profiles and levels, ISO_IEC_14496-10-AVC-2003.pdf, page 207.
|
|
|
|
*/
|
2015-03-08 10:33:35 +00:00
|
|
|
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,
|
|
|
|
};
|
2017-02-12 12:38:39 +00:00
|
|
|
std::string srs_avc_level2str(SrsAvcLevel level);
|
2015-03-08 10:33:35 +00:00
|
|
|
|
2017-02-11 15:09:23 +00:00
|
|
|
/**
|
|
|
|
* A sample is the unit of frame.
|
|
|
|
* It's a NALU for H.264.
|
|
|
|
* It's the whole AAC raw data for AAC.
|
|
|
|
* @remark Neither SPS/PPS or ASC is sample unit, it's codec sequence header.
|
|
|
|
*/
|
|
|
|
class SrsSample
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// The size of unit.
|
2017-02-12 10:18:18 +00:00
|
|
|
int size;
|
2017-02-11 15:09:23 +00:00
|
|
|
// The ptr of unit, user must manage it.
|
2017-02-12 10:18:18 +00:00
|
|
|
char* bytes;
|
2017-02-11 15:09:23 +00:00
|
|
|
public:
|
|
|
|
SrsSample();
|
|
|
|
virtual ~SrsSample();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The codec is the information of encoder,
|
|
|
|
* corresponding to the sequence header of FLV,
|
|
|
|
* parsed to detail info.
|
|
|
|
*/
|
2017-02-12 12:38:39 +00:00
|
|
|
class SrsCodecConfig
|
2017-02-11 15:09:23 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsCodecConfig();
|
|
|
|
virtual ~SrsCodecConfig();
|
2017-02-11 15:09:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The audio codec info.
|
|
|
|
*/
|
2017-02-12 12:38:39 +00:00
|
|
|
class SrsAudioCodecConfig : public SrsCodecConfig
|
2017-02-11 15:09:23 +00:00
|
|
|
{
|
2017-03-25 09:21:39 +00:00
|
|
|
// In FLV specification.
|
2017-02-11 15:09:23 +00:00
|
|
|
public:
|
2017-03-25 04:52:54 +00:00
|
|
|
// The audio codec id; for FLV, it's SoundFormat.
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsAudioCodecId id;
|
2017-03-25 04:52:54 +00:00
|
|
|
// The audio sample rate; for FLV, it's SoundRate.
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsAudioSampleRate sound_rate;
|
2017-03-25 04:52:54 +00:00
|
|
|
// The audio sample size, such as 16 bits; for FLV, it's SoundSize.
|
2017-02-12 12:46:24 +00:00
|
|
|
SrsAudioSampleBits sound_size;
|
2017-03-25 04:52:54 +00:00
|
|
|
// The audio number of channels; for FLV, it's SoundType.
|
2017-03-05 10:44:37 +00:00
|
|
|
// TODO: FIXME: Rename to sound_channels.
|
2017-02-12 12:46:24 +00:00
|
|
|
SrsAudioChannels sound_type;
|
2017-02-12 10:18:18 +00:00
|
|
|
int audio_data_rate; // in bps
|
2017-03-25 09:21:39 +00:00
|
|
|
// In AAC specification.
|
2017-02-12 10:18:18 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* audio specified
|
|
|
|
* audioObjectType, in 1.6.2.1 AudioSpecificConfig, page 33,
|
|
|
|
* 1.5.1.1 Audio object type definition, page 23,
|
|
|
|
* in ISO_IEC_14496-3-AAC-2001.pdf.
|
|
|
|
*/
|
|
|
|
SrsAacObjectType aac_object;
|
|
|
|
/**
|
|
|
|
* samplingFrequencyIndex
|
|
|
|
*/
|
|
|
|
uint8_t aac_sample_rate;
|
|
|
|
/**
|
|
|
|
* channelConfiguration
|
|
|
|
*/
|
|
|
|
uint8_t aac_channels;
|
2017-03-25 09:21:39 +00:00
|
|
|
// Sequence header payload.
|
2017-02-12 10:18:18 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* the aac extra data, the AAC sequence header,
|
|
|
|
* without the flv codec header,
|
|
|
|
* @see: ffmpeg, AVCodecContext::extradata
|
|
|
|
*/
|
2017-04-24 02:08:57 +00:00
|
|
|
std::vector<char> aac_extra_data;
|
2017-02-11 15:09:23 +00:00
|
|
|
public:
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsAudioCodecConfig();
|
|
|
|
virtual ~SrsAudioCodecConfig();
|
2017-02-11 15:09:23 +00:00
|
|
|
public:
|
2017-02-12 10:18:18 +00:00
|
|
|
virtual bool is_aac_codec_ok();
|
2017-02-11 15:09:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The video codec info.
|
|
|
|
*/
|
2017-02-12 12:38:39 +00:00
|
|
|
class SrsVideoCodecConfig : public SrsCodecConfig
|
2017-02-11 15:09:23 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsVideoCodecId id;
|
2017-02-12 10:18:18 +00:00
|
|
|
int video_data_rate; // in bps
|
|
|
|
double frame_rate;
|
|
|
|
double duration;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* the avc extra data, the AVC sequence header,
|
|
|
|
* without the flv codec header,
|
|
|
|
* @see: ffmpeg, AVCodecContext::extradata
|
|
|
|
*/
|
2017-04-24 02:08:57 +00:00
|
|
|
std::vector<char> avc_extra_data;
|
2017-02-12 10:18:18 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* video specified
|
|
|
|
*/
|
|
|
|
// profile_idc, ISO_IEC_14496-10-AVC-2003.pdf, page 45.
|
|
|
|
SrsAvcProfile avc_profile;
|
|
|
|
// level_idc, ISO_IEC_14496-10-AVC-2003.pdf, page 45.
|
|
|
|
SrsAvcLevel avc_level;
|
|
|
|
// lengthSizeMinusOne, ISO_IEC_14496-15-AVC-format-2012.pdf, page 16
|
|
|
|
int8_t NAL_unit_length;
|
2017-04-24 02:08:57 +00:00
|
|
|
std::vector<char> sequenceParameterSetNALUnit;
|
|
|
|
std::vector<char> pictureParameterSetNALUnit;
|
2017-02-12 10:18:18 +00:00
|
|
|
public:
|
|
|
|
// the avc payload format.
|
|
|
|
SrsAvcPayloadFormat payload_format;
|
2017-02-11 15:09:23 +00:00
|
|
|
public:
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsVideoCodecConfig();
|
|
|
|
virtual ~SrsVideoCodecConfig();
|
2017-02-11 15:09:23 +00:00
|
|
|
public:
|
2017-02-12 10:18:18 +00:00
|
|
|
virtual bool is_avc_codec_ok();
|
2017-02-11 15:09:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-02-12 10:18:18 +00:00
|
|
|
* A frame, consists of a codec and a group of samples.
|
2017-02-11 15:09:23 +00:00
|
|
|
*/
|
|
|
|
class SrsFrame
|
|
|
|
{
|
2017-02-12 10:18:18 +00:00
|
|
|
public:
|
|
|
|
// The DTS/PTS in milliseconds, which is TBN=1000.
|
|
|
|
int64_t dts;
|
|
|
|
// PTS = DTS + CTS.
|
|
|
|
int32_t cts;
|
2017-02-11 15:09:23 +00:00
|
|
|
public:
|
|
|
|
// The codec info of frame.
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsCodecConfig* codec;
|
2017-02-11 15:09:23 +00:00
|
|
|
// The actual parsed number of samples.
|
|
|
|
int nb_samples;
|
|
|
|
// The sampels cache.
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsSample samples[SrsMaxNbSamples];
|
2017-02-11 15:09:23 +00:00
|
|
|
public:
|
|
|
|
SrsFrame();
|
|
|
|
virtual ~SrsFrame();
|
2017-02-12 10:18:18 +00:00
|
|
|
public:
|
|
|
|
// Initialize the frame, to parse sampels.
|
2017-09-23 14:12:33 +00:00
|
|
|
virtual srs_error_t initialize(SrsCodecConfig* c);
|
2017-02-12 10:18:18 +00:00
|
|
|
// Add a sample to frame.
|
2017-09-23 14:12:33 +00:00
|
|
|
virtual srs_error_t add_sample(char* bytes, int size);
|
2017-02-11 15:09:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-02-12 10:18:18 +00:00
|
|
|
* A audio frame, besides a frame, contains the audio frame info, such as frame type.
|
|
|
|
*/
|
|
|
|
class SrsAudioFrame : public SrsFrame
|
2017-02-11 15:09:23 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsAudioAacFrameTrait aac_packet_type;
|
2017-02-11 15:09:23 +00:00
|
|
|
public:
|
2017-02-12 10:18:18 +00:00
|
|
|
SrsAudioFrame();
|
|
|
|
virtual ~SrsAudioFrame();
|
|
|
|
public:
|
2017-02-12 12:38:39 +00:00
|
|
|
virtual SrsAudioCodecConfig* acodec();
|
2017-02-12 10:18:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A video frame, besides a frame, contains the video frame info, such as frame type.
|
|
|
|
*/
|
|
|
|
class SrsVideoFrame : public SrsFrame
|
|
|
|
{
|
2017-02-11 15:09:23 +00:00
|
|
|
public:
|
|
|
|
// video specified
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsVideoAvcFrameType frame_type;
|
|
|
|
SrsVideoAvcFrameTrait avc_packet_type;
|
2017-02-11 15:09:23 +00:00
|
|
|
// whether sample_units contains IDR frame.
|
|
|
|
bool has_idr;
|
|
|
|
// Whether exists AUD NALU.
|
|
|
|
bool has_aud;
|
|
|
|
// Whether exists SPS/PPS NALU.
|
|
|
|
bool has_sps_pps;
|
|
|
|
// The first nalu type.
|
|
|
|
SrsAvcNaluType first_nalu_type;
|
|
|
|
public:
|
2017-02-12 10:18:18 +00:00
|
|
|
SrsVideoFrame();
|
|
|
|
virtual ~SrsVideoFrame();
|
2017-02-11 15:09:23 +00:00
|
|
|
public:
|
2017-02-12 10:18:18 +00:00
|
|
|
// Add the sample without ANNEXB or IBMF header, or RAW AAC or MP3 data.
|
2017-09-23 14:12:33 +00:00
|
|
|
virtual srs_error_t add_sample(char* bytes, int size);
|
2017-02-11 15:09:23 +00:00
|
|
|
public:
|
2017-02-12 12:38:39 +00:00
|
|
|
virtual SrsVideoCodecConfig* vcodec();
|
2017-02-11 15:09:23 +00:00
|
|
|
};
|
2015-10-01 05:04:28 +00:00
|
|
|
|
2015-01-31 13:16:42 +00:00
|
|
|
/**
|
2017-02-12 10:18:18 +00:00
|
|
|
* A codec format, including one or many stream, each stream identified by a frame.
|
|
|
|
* For example, a typical RTMP stream format, consits of a video and audio frame.
|
|
|
|
* Maybe some RTMP stream only has a audio stream, for instance, redio application.
|
|
|
|
*/
|
|
|
|
class SrsFormat
|
2015-01-31 13:16:42 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-02-12 10:18:18 +00:00
|
|
|
SrsAudioFrame* audio;
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsAudioCodecConfig* acodec;
|
2017-02-12 10:18:18 +00:00
|
|
|
SrsVideoFrame* video;
|
2017-02-12 12:38:39 +00:00
|
|
|
SrsVideoCodecConfig* vcodec;
|
2017-06-04 07:10:35 +00:00
|
|
|
public:
|
|
|
|
char* raw;
|
|
|
|
int nb_raw;
|
2015-09-14 10:36:44 +00:00
|
|
|
public:
|
|
|
|
// for sequence header, whether parse the h.264 sps.
|
2017-02-12 10:18:18 +00:00
|
|
|
// TODO: FIXME: Refine it.
|
2019-02-04 04:05:07 +00:00
|
|
|
bool avc_parse_sps;
|
2015-01-31 13:16:42 +00:00
|
|
|
public:
|
2017-02-12 10:18:18 +00:00
|
|
|
SrsFormat();
|
|
|
|
virtual ~SrsFormat();
|
2015-07-20 01:31:46 +00:00
|
|
|
public:
|
2017-02-12 10:18:18 +00:00
|
|
|
// Initialize the format.
|
2017-06-11 01:40:07 +00:00
|
|
|
virtual srs_error_t initialize();
|
2017-02-12 10:18:18 +00:00
|
|
|
// When got a parsed audio packet.
|
2017-02-12 12:38:39 +00:00
|
|
|
// @param data The data in FLV format.
|
2017-09-23 14:12:33 +00:00
|
|
|
virtual srs_error_t on_audio(int64_t timestamp, char* data, int size);
|
2017-02-12 10:18:18 +00:00
|
|
|
// When got a parsed video packet.
|
2017-02-12 12:38:39 +00:00
|
|
|
// @param data The data in FLV format.
|
2017-09-23 14:12:33 +00:00
|
|
|
virtual srs_error_t on_video(int64_t timestamp, char* data, int size);
|
2017-02-12 10:18:18 +00:00
|
|
|
// When got a audio aac sequence header.
|
2017-09-23 14:12:33 +00:00
|
|
|
virtual srs_error_t on_aac_sequence_header(char* data, int size);
|
2015-01-31 13:16:42 +00:00
|
|
|
public:
|
2017-02-12 10:18:18 +00:00
|
|
|
virtual bool is_aac_sequence_header();
|
|
|
|
virtual bool is_avc_sequence_header();
|
2017-01-10 09:17:23 +00:00
|
|
|
private:
|
2017-02-12 10:18:18 +00:00
|
|
|
// Demux the video packet in H.264 codec.
|
|
|
|
// The packet is muxed in FLV format, defined in flv specification.
|
|
|
|
// Demux the sps/pps from sequence header.
|
|
|
|
// Demux the samples from NALUs.
|
2017-09-23 14:12:33 +00:00
|
|
|
virtual srs_error_t video_avc_demux(SrsBuffer* stream, int64_t timestamp);
|
2015-01-31 13:16:42 +00:00
|
|
|
private:
|
2017-02-12 10:18:18 +00:00
|
|
|
// Parse the H.264 SPS/PPS.
|
2017-09-23 14:12:33 +00:00
|
|
|
virtual srs_error_t avc_demux_sps_pps(SrsBuffer* stream);
|
|
|
|
virtual srs_error_t avc_demux_sps();
|
|
|
|
virtual srs_error_t avc_demux_sps_rbsp(char* rbsp, int nb_rbsp);
|
2017-02-12 10:18:18 +00:00
|
|
|
private:
|
|
|
|
// Parse the H.264 NALUs.
|
2017-09-23 14:12:33 +00:00
|
|
|
virtual srs_error_t video_nalu_demux(SrsBuffer* stream);
|
2017-02-12 10:18:18 +00:00
|
|
|
// Demux the avc NALU in "AnnexB" from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
|
2017-09-23 14:12:33 +00:00
|
|
|
virtual srs_error_t avc_demux_annexb_format(SrsBuffer* stream);
|
2017-02-12 10:18:18 +00:00
|
|
|
// Demux the avc NALU in "ISO Base Media File Format" from ISO_IEC_14496-15-AVC-format-2012.pdf, page 20
|
2017-09-23 14:12:33 +00:00
|
|
|
virtual srs_error_t avc_demux_ibmf_format(SrsBuffer* stream);
|
2017-02-12 10:18:18 +00:00
|
|
|
private:
|
|
|
|
// Demux the audio packet in AAC codec.
|
|
|
|
// Demux the asc from sequence header.
|
|
|
|
// Demux the sampels from RAW data.
|
2017-09-23 14:12:33 +00:00
|
|
|
virtual srs_error_t audio_aac_demux(SrsBuffer* stream, int64_t timestamp);
|
|
|
|
virtual srs_error_t audio_mp3_demux(SrsBuffer* stream, int64_t timestamp);
|
2017-02-12 10:18:18 +00:00
|
|
|
public:
|
|
|
|
// Directly demux the sequence header, without RTMP packet header.
|
2017-09-23 14:12:33 +00:00
|
|
|
virtual srs_error_t audio_aac_sequence_header_demux(char* data, int size);
|
2015-01-31 13:16:42 +00:00
|
|
|
};
|
|
|
|
|
2014-08-02 14:18:39 +00:00
|
|
|
#endif
|
2015-10-01 05:04:28 +00:00
|
|
|
|