2013-11-23 03:36:07 +00:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
2014-12-31 12:32:09 +00:00
|
|
|
Copyright (c) 2013-2015 winlin
|
2013-11-23 03:36:07 +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.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
2014-05-28 09:37:15 +00:00
|
|
|
#include <srs_kernel_codec.hpp>
|
2013-11-23 03:36:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
2014-06-08 14:36:17 +00:00
|
|
|
// AACPacketType IF SoundFormat == 10 UI8
|
|
|
|
// The following values are defined:
|
|
|
|
// 0 = AAC sequence header
|
|
|
|
// 1 = AAC raw
|
|
|
|
enum SrsCodecAudioType
|
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.
|
|
|
|
SrsCodecAudioTypeReserved = 2,
|
|
|
|
|
2014-06-08 14:36:17 +00:00
|
|
|
SrsCodecAudioTypeSequenceHeader = 0,
|
|
|
|
SrsCodecAudioTypeRawData = 1,
|
2013-11-24 04:39:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// E.4.3.1 VIDEODATA
|
|
|
|
// Frame Type UB [4]
|
|
|
|
// Type of video frame. The following values are defined:
|
2014-03-18 03:32:58 +00:00
|
|
|
// 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
|
2013-11-24 04:39:47 +00:00
|
|
|
enum SrsCodecVideoAVCFrame
|
|
|
|
{
|
2014-07-06 01:59:41 +00:00
|
|
|
// set to the max value to reserved, for array map.
|
2014-03-18 03:32:58 +00:00
|
|
|
SrsCodecVideoAVCFrameReserved = 0,
|
2014-07-06 01:59:41 +00:00
|
|
|
SrsCodecVideoAVCFrameReserved1 = 6,
|
2014-03-18 03:32:58 +00:00
|
|
|
|
|
|
|
SrsCodecVideoAVCFrameKeyFrame = 1,
|
|
|
|
SrsCodecVideoAVCFrameInterFrame = 2,
|
|
|
|
SrsCodecVideoAVCFrameDisposableInterFrame = 3,
|
|
|
|
SrsCodecVideoAVCFrameGeneratedKeyFrame = 4,
|
|
|
|
SrsCodecVideoAVCFrameVideoInfoFrame = 5,
|
2013-11-24 04:39:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// AVCPacketType IF CodecID == 7 UI8
|
|
|
|
// The following values are defined:
|
2014-03-18 03:32:58 +00:00
|
|
|
// 0 = AVC sequence header
|
|
|
|
// 1 = AVC NALU
|
|
|
|
// 2 = AVC end of sequence (lower level NALU sequence ender is
|
|
|
|
// not required or supported)
|
2013-11-24 04:39:47 +00:00
|
|
|
enum SrsCodecVideoAVCType
|
|
|
|
{
|
2014-07-06 01:59:41 +00:00
|
|
|
// set to the max value to reserved, for array map.
|
|
|
|
SrsCodecVideoAVCTypeReserved = 3,
|
2014-03-18 03:32:58 +00:00
|
|
|
|
|
|
|
SrsCodecVideoAVCTypeSequenceHeader = 0,
|
|
|
|
SrsCodecVideoAVCTypeNALU = 1,
|
|
|
|
SrsCodecVideoAVCTypeSequenceHeaderEOF = 2,
|
2013-11-24 04:39:47 +00:00
|
|
|
};
|
|
|
|
|
2014-06-08 14:36:17 +00:00
|
|
|
// E.4.3.1 VIDEODATA
|
|
|
|
// CodecID UB [4]
|
|
|
|
// Codec Identifier. The following values are defined:
|
|
|
|
// 2 = Sorenson H.263
|
|
|
|
// 3 = Screen video
|
|
|
|
// 4 = On2 VP6
|
|
|
|
// 5 = On2 VP6 with alpha channel
|
|
|
|
// 6 = Screen video version 2
|
|
|
|
// 7 = AVC
|
|
|
|
enum SrsCodecVideo
|
|
|
|
{
|
2014-07-06 01:59:41 +00:00
|
|
|
// set to the max value to reserved, for array map.
|
2014-06-08 14:36:17 +00:00
|
|
|
SrsCodecVideoReserved = 0,
|
2014-07-06 01:59:41 +00:00
|
|
|
SrsCodecVideoReserved1 = 1,
|
|
|
|
SrsCodecVideoReserved2 = 8,
|
2014-06-08 14:36:17 +00:00
|
|
|
|
|
|
|
SrsCodecVideoSorensonH263 = 2,
|
|
|
|
SrsCodecVideoScreenVideo = 3,
|
|
|
|
SrsCodecVideoOn2VP6 = 4,
|
|
|
|
SrsCodecVideoOn2VP6WithAlphaChannel = 5,
|
|
|
|
SrsCodecVideoScreenVideoVersion2 = 6,
|
|
|
|
SrsCodecVideoAVC = 7,
|
|
|
|
};
|
|
|
|
|
2013-11-24 04:39:47 +00:00
|
|
|
// SoundFormat UB [4]
|
|
|
|
// Format of SoundData. The following values are defined:
|
2014-03-18 03:32:58 +00:00
|
|
|
// 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
|
2013-11-24 04:39:47 +00:00
|
|
|
// 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 SrsCodecAudio
|
|
|
|
{
|
2014-07-06 01:59:41 +00:00
|
|
|
// set to the max value to reserved, for array map.
|
|
|
|
SrsCodecAudioReserved1 = 16,
|
|
|
|
|
2014-03-18 03:32:58 +00:00
|
|
|
SrsCodecAudioLinearPCMPlatformEndian = 0,
|
|
|
|
SrsCodecAudioADPCM = 1,
|
|
|
|
SrsCodecAudioMP3 = 2,
|
|
|
|
SrsCodecAudioLinearPCMLittleEndian = 3,
|
|
|
|
SrsCodecAudioNellymoser16kHzMono = 4,
|
|
|
|
SrsCodecAudioNellymoser8kHzMono = 5,
|
|
|
|
SrsCodecAudioNellymoser = 6,
|
|
|
|
SrsCodecAudioReservedG711AlawLogarithmicPCM = 7,
|
|
|
|
SrsCodecAudioReservedG711MuLawLogarithmicPCM = 8,
|
|
|
|
SrsCodecAudioReserved = 9,
|
|
|
|
SrsCodecAudioAAC = 10,
|
|
|
|
SrsCodecAudioSpeex = 11,
|
|
|
|
SrsCodecAudioReservedMP3_8kHz = 14,
|
|
|
|
SrsCodecAudioReservedDeviceSpecificSound = 15,
|
2013-11-24 04:39:47 +00:00
|
|
|
};
|
|
|
|
|
2014-11-24 08:28:52 +00:00
|
|
|
/**
|
|
|
|
* the FLV/RTMP supported audio sample rate.
|
|
|
|
* Sampling rate. The following values are defined:
|
|
|
|
* 0 = 5.5 kHz = 5512 Hz
|
|
|
|
* 1 = 11 kHz = 11025 Hz
|
|
|
|
* 2 = 22 kHz = 22050 Hz
|
|
|
|
* 3 = 44 kHz = 44100 Hz
|
|
|
|
*/
|
|
|
|
enum SrsCodecAudioSampleRate
|
|
|
|
{
|
|
|
|
// set to the max value to reserved, for array map.
|
|
|
|
SrsCodecAudioSampleRateReserved = 4,
|
|
|
|
|
|
|
|
SrsCodecAudioSampleRate5512 = 0,
|
|
|
|
SrsCodecAudioSampleRate11025 = 1,
|
|
|
|
SrsCodecAudioSampleRate22050 = 2,
|
|
|
|
SrsCodecAudioSampleRate44100 = 3,
|
|
|
|
};
|
|
|
|
|
2013-11-23 03:36:07 +00:00
|
|
|
/**
|
|
|
|
* Annex E. The FLV File Format
|
2014-06-08 14:36:17 +00:00
|
|
|
* @see SrsAvcAacCodec for the media stream codec.
|
2013-11-23 03:36:07 +00:00
|
|
|
*/
|
2014-06-08 14:36:17 +00:00
|
|
|
class SrsFlvCodec
|
2013-11-23 03:36:07 +00:00
|
|
|
{
|
2013-11-24 04:39:47 +00:00
|
|
|
public:
|
2014-06-08 14:36:17 +00:00
|
|
|
SrsFlvCodec();
|
|
|
|
virtual ~SrsFlvCodec();
|
2013-11-24 04:39:47 +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
|
|
|
/**
|
|
|
|
* only check the frame_type, not check the codec type.
|
|
|
|
*/
|
2014-07-11 10:08:34 +00:00
|
|
|
static bool video_is_keyframe(char* data, int size);
|
2014-03-18 03:32:58 +00:00
|
|
|
/**
|
|
|
|
* check codec h264, keyframe, sequence header
|
|
|
|
*/
|
2014-07-11 10:08:34 +00:00
|
|
|
static bool video_is_sequence_header(char* data, int size);
|
2014-03-18 03:32:58 +00:00
|
|
|
/**
|
|
|
|
* check codec aac, sequence header
|
|
|
|
*/
|
2014-07-11 10:08:34 +00:00
|
|
|
static bool audio_is_sequence_header(char* data, int size);
|
2014-03-18 03:32:58 +00:00
|
|
|
/**
|
|
|
|
* check codec h264.
|
|
|
|
*/
|
2014-07-11 10:08:34 +00:00
|
|
|
static bool video_is_h264(char* data, int size);
|
2014-03-18 03:32:58 +00:00
|
|
|
/**
|
|
|
|
* check codec aac.
|
|
|
|
*/
|
2014-07-11 10:08:34 +00:00
|
|
|
static bool audio_is_aac(char* data, int size);
|
2013-11-23 03:36:07 +00:00
|
|
|
};
|
|
|
|
|
2014-08-02 14:18:39 +00:00
|
|
|
#endif
|