mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-29 22:55:52 +08:00
修复拼写错误
This commit is contained in:
parent
06d61cf195
commit
893564d0be
@ -173,21 +173,21 @@ public:
|
|||||||
* 构造函数
|
* 构造函数
|
||||||
* @param aac_cfg aac两个字节的配置描述
|
* @param aac_cfg aac两个字节的配置描述
|
||||||
* @param sample_rate 音频采样率
|
* @param sample_rate 音频采样率
|
||||||
* @param playload_type rtp playload type 默认98
|
* @param payload_type rtp payload type 默认98
|
||||||
* @param bitrate 比特率
|
* @param bitrate 比特率
|
||||||
*/
|
*/
|
||||||
AACSdp(const string &aac_cfg,
|
AACSdp(const string &aac_cfg,
|
||||||
int sample_rate,
|
int sample_rate,
|
||||||
int channels,
|
int channels,
|
||||||
int playload_type = 98,
|
int payload_type = 98,
|
||||||
int bitrate = 128) : Sdp(sample_rate,playload_type){
|
int bitrate = 128) : Sdp(sample_rate,payload_type){
|
||||||
_printer << "m=audio 0 RTP/AVP " << playload_type << "\r\n";
|
_printer << "m=audio 0 RTP/AVP " << payload_type << "\r\n";
|
||||||
_printer << "b=AS:" << bitrate << "\r\n";
|
_printer << "b=AS:" << bitrate << "\r\n";
|
||||||
_printer << "a=rtpmap:" << playload_type << " MPEG4-GENERIC/" << sample_rate << "/" << channels << "\r\n";
|
_printer << "a=rtpmap:" << payload_type << " MPEG4-GENERIC/" << sample_rate << "/" << channels << "\r\n";
|
||||||
|
|
||||||
char configStr[32] = {0};
|
char configStr[32] = {0};
|
||||||
snprintf(configStr, sizeof(configStr), "%02X%02X", (uint8_t)aac_cfg[0], (uint8_t)aac_cfg[1]);
|
snprintf(configStr, sizeof(configStr), "%02X%02X", (uint8_t)aac_cfg[0], (uint8_t)aac_cfg[1]);
|
||||||
_printer << "a=fmtp:" << playload_type << " streamtype=5;profile-level-id=1;mode=AAC-hbr;"
|
_printer << "a=fmtp:" << payload_type << " streamtype=5;profile-level-id=1;mode=AAC-hbr;"
|
||||||
<< "sizelength=13;indexlength=3;indexdeltalength=3;config=" << configStr << "\r\n";
|
<< "sizelength=13;indexlength=3;indexdeltalength=3;config=" << configStr << "\r\n";
|
||||||
_printer << "a=control:trackID=" << (int)TrackAudio << "\r\n";
|
_printer << "a=control:trackID=" << (int)TrackAudio << "\r\n";
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,12 @@ namespace mediakit{
|
|||||||
AACRtpEncoder::AACRtpEncoder(uint32_t ui32Ssrc,
|
AACRtpEncoder::AACRtpEncoder(uint32_t ui32Ssrc,
|
||||||
uint32_t ui32MtuSize,
|
uint32_t ui32MtuSize,
|
||||||
uint32_t ui32SampleRate,
|
uint32_t ui32SampleRate,
|
||||||
uint8_t ui8PlayloadType,
|
uint8_t ui8PayloadType,
|
||||||
uint8_t ui8Interleaved) :
|
uint8_t ui8Interleaved) :
|
||||||
RtpInfo(ui32Ssrc,
|
RtpInfo(ui32Ssrc,
|
||||||
ui32MtuSize,
|
ui32MtuSize,
|
||||||
ui32SampleRate,
|
ui32SampleRate,
|
||||||
ui8PlayloadType,
|
ui8PayloadType,
|
||||||
ui8Interleaved){
|
ui8Interleaved){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,13 +56,13 @@ public:
|
|||||||
* @param ui32Ssrc ssrc
|
* @param ui32Ssrc ssrc
|
||||||
* @param ui32MtuSize mtu 大小
|
* @param ui32MtuSize mtu 大小
|
||||||
* @param ui32SampleRate 采样率
|
* @param ui32SampleRate 采样率
|
||||||
* @param ui8PlayloadType pt类型
|
* @param ui8PayloadType pt类型
|
||||||
* @param ui8Interleaved rtsp interleaved 值
|
* @param ui8Interleaved rtsp interleaved 值
|
||||||
*/
|
*/
|
||||||
AACRtpEncoder(uint32_t ui32Ssrc,
|
AACRtpEncoder(uint32_t ui32Ssrc,
|
||||||
uint32_t ui32MtuSize,
|
uint32_t ui32MtuSize,
|
||||||
uint32_t ui32SampleRate,
|
uint32_t ui32SampleRate,
|
||||||
uint8_t ui8PlayloadType = 97,
|
uint8_t ui8PayloadType = 97,
|
||||||
uint8_t ui8Interleaved = TrackAudio * 2);
|
uint8_t ui8Interleaved = TrackAudio * 2);
|
||||||
~AACRtpEncoder() {}
|
~AACRtpEncoder() {}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ RtpCodec::Ptr Factory::getRtpEncoderBySdp(const Sdp::Ptr &sdp) {
|
|||||||
}
|
}
|
||||||
auto mtu = (sdp->getTrackType() == TrackVideo ? video_mtu : audio_mtu);
|
auto mtu = (sdp->getTrackType() == TrackVideo ? video_mtu : audio_mtu);
|
||||||
auto sample_rate = sdp->getSampleRate();
|
auto sample_rate = sdp->getSampleRate();
|
||||||
auto pt = sdp->getPlayloadType();
|
auto pt = sdp->getPayloadType();
|
||||||
auto interleaved = sdp->getTrackType() * 2;
|
auto interleaved = sdp->getTrackType() * 2;
|
||||||
auto codec_id = sdp->getCodecId();
|
auto codec_id = sdp->getCodecId();
|
||||||
switch (codec_id){
|
switch (codec_id){
|
||||||
|
@ -83,16 +83,16 @@ public:
|
|||||||
* G711采样率固定为8000
|
* G711采样率固定为8000
|
||||||
* @param codecId G711A G711U
|
* @param codecId G711A G711U
|
||||||
* @param sample_rate 音频采样率
|
* @param sample_rate 音频采样率
|
||||||
* @param playload_type rtp playload
|
* @param payload_type rtp payload
|
||||||
* @param bitrate 比特率
|
* @param bitrate 比特率
|
||||||
*/
|
*/
|
||||||
G711Sdp(CodecId codecId,
|
G711Sdp(CodecId codecId,
|
||||||
int sample_rate,
|
int sample_rate,
|
||||||
int channels,
|
int channels,
|
||||||
int playload_type = 98,
|
int payload_type = 98,
|
||||||
int bitrate = 128) : Sdp(sample_rate,playload_type), _codecId(codecId){
|
int bitrate = 128) : Sdp(sample_rate,payload_type), _codecId(codecId){
|
||||||
_printer << "m=audio 0 RTP/AVP " << playload_type << "\r\n";
|
_printer << "m=audio 0 RTP/AVP " << payload_type << "\r\n";
|
||||||
_printer << "a=rtpmap:" << playload_type << (codecId == CodecG711A ? " PCMA/" : " PCMU/") << sample_rate << "/" << channels << "\r\n";
|
_printer << "a=rtpmap:" << payload_type << (codecId == CodecG711A ? " PCMA/" : " PCMU/") << sample_rate << "/" << channels << "\r\n";
|
||||||
_printer << "a=control:trackID=" << (int)TrackAudio << "\r\n";
|
_printer << "a=control:trackID=" << (int)TrackAudio << "\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,12 +62,12 @@ void G711RtpDecoder::onGetG711(const G711Frame::Ptr &frame) {
|
|||||||
G711RtpEncoder::G711RtpEncoder(uint32_t ui32Ssrc,
|
G711RtpEncoder::G711RtpEncoder(uint32_t ui32Ssrc,
|
||||||
uint32_t ui32MtuSize,
|
uint32_t ui32MtuSize,
|
||||||
uint32_t ui32SampleRate,
|
uint32_t ui32SampleRate,
|
||||||
uint8_t ui8PlayloadType,
|
uint8_t ui8PayloadType,
|
||||||
uint8_t ui8Interleaved) :
|
uint8_t ui8Interleaved) :
|
||||||
RtpInfo(ui32Ssrc,
|
RtpInfo(ui32Ssrc,
|
||||||
ui32MtuSize,
|
ui32MtuSize,
|
||||||
ui32SampleRate,
|
ui32SampleRate,
|
||||||
ui8PlayloadType,
|
ui8PayloadType,
|
||||||
ui8Interleaved) {
|
ui8Interleaved) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,13 +58,13 @@ public:
|
|||||||
* @param ui32Ssrc ssrc
|
* @param ui32Ssrc ssrc
|
||||||
* @param ui32MtuSize mtu 大小
|
* @param ui32MtuSize mtu 大小
|
||||||
* @param ui32SampleRate 采样率
|
* @param ui32SampleRate 采样率
|
||||||
* @param ui8PlayloadType pt类型
|
* @param ui8PayloadType pt类型
|
||||||
* @param ui8Interleaved rtsp interleaved 值
|
* @param ui8Interleaved rtsp interleaved 值
|
||||||
*/
|
*/
|
||||||
G711RtpEncoder(uint32_t ui32Ssrc,
|
G711RtpEncoder(uint32_t ui32Ssrc,
|
||||||
uint32_t ui32MtuSize,
|
uint32_t ui32MtuSize,
|
||||||
uint32_t ui32SampleRate,
|
uint32_t ui32SampleRate,
|
||||||
uint8_t ui8PlayloadType = 0,
|
uint8_t ui8PayloadType = 0,
|
||||||
uint8_t ui8Interleaved = TrackAudio * 2);
|
uint8_t ui8Interleaved = TrackAudio * 2);
|
||||||
~G711RtpEncoder() {}
|
~G711RtpEncoder() {}
|
||||||
|
|
||||||
|
@ -289,18 +289,18 @@ public:
|
|||||||
*
|
*
|
||||||
* @param sps 264 sps,不带0x00000001头
|
* @param sps 264 sps,不带0x00000001头
|
||||||
* @param pps 264 pps,不带0x00000001头
|
* @param pps 264 pps,不带0x00000001头
|
||||||
* @param playload_type rtp playload type 默认96
|
* @param payload_type rtp payload type 默认96
|
||||||
* @param bitrate 比特率
|
* @param bitrate 比特率
|
||||||
*/
|
*/
|
||||||
H264Sdp(const string &strSPS,
|
H264Sdp(const string &strSPS,
|
||||||
const string &strPPS,
|
const string &strPPS,
|
||||||
int playload_type = 96,
|
int payload_type = 96,
|
||||||
int bitrate = 4000) : Sdp(90000,playload_type) {
|
int bitrate = 4000) : Sdp(90000,payload_type) {
|
||||||
//视频通道
|
//视频通道
|
||||||
_printer << "m=video 0 RTP/AVP " << playload_type << "\r\n";
|
_printer << "m=video 0 RTP/AVP " << payload_type << "\r\n";
|
||||||
_printer << "b=AS:" << bitrate << "\r\n";
|
_printer << "b=AS:" << bitrate << "\r\n";
|
||||||
_printer << "a=rtpmap:" << playload_type << " H264/" << 90000 << "\r\n";
|
_printer << "a=rtpmap:" << payload_type << " H264/" << 90000 << "\r\n";
|
||||||
_printer << "a=fmtp:" << playload_type << " packetization-mode=1; profile-level-id=";
|
_printer << "a=fmtp:" << payload_type << " packetization-mode=1; profile-level-id=";
|
||||||
|
|
||||||
char strTemp[100];
|
char strTemp[100];
|
||||||
uint32_t profile_level_id = 0;
|
uint32_t profile_level_id = 0;
|
||||||
|
@ -204,12 +204,12 @@ void H264RtpDecoder::onGetH264(const H264Frame::Ptr &frame) {
|
|||||||
H264RtpEncoder::H264RtpEncoder(uint32_t ui32Ssrc,
|
H264RtpEncoder::H264RtpEncoder(uint32_t ui32Ssrc,
|
||||||
uint32_t ui32MtuSize,
|
uint32_t ui32MtuSize,
|
||||||
uint32_t ui32SampleRate,
|
uint32_t ui32SampleRate,
|
||||||
uint8_t ui8PlayloadType,
|
uint8_t ui8PayloadType,
|
||||||
uint8_t ui8Interleaved) :
|
uint8_t ui8Interleaved) :
|
||||||
RtpInfo(ui32Ssrc,
|
RtpInfo(ui32Ssrc,
|
||||||
ui32MtuSize,
|
ui32MtuSize,
|
||||||
ui32SampleRate,
|
ui32SampleRate,
|
||||||
ui8PlayloadType,
|
ui8PayloadType,
|
||||||
ui8Interleaved) {
|
ui8Interleaved) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,13 +62,13 @@ public:
|
|||||||
* @param ui32Ssrc ssrc
|
* @param ui32Ssrc ssrc
|
||||||
* @param ui32MtuSize mtu大小
|
* @param ui32MtuSize mtu大小
|
||||||
* @param ui32SampleRate 采样率,强制为90000
|
* @param ui32SampleRate 采样率,强制为90000
|
||||||
* @param ui8PlayloadType pt类型
|
* @param ui8PayloadType pt类型
|
||||||
* @param ui8Interleaved rtsp interleaved
|
* @param ui8Interleaved rtsp interleaved
|
||||||
*/
|
*/
|
||||||
H264RtpEncoder(uint32_t ui32Ssrc,
|
H264RtpEncoder(uint32_t ui32Ssrc,
|
||||||
uint32_t ui32MtuSize = 1400,
|
uint32_t ui32MtuSize = 1400,
|
||||||
uint32_t ui32SampleRate = 90000,
|
uint32_t ui32SampleRate = 90000,
|
||||||
uint8_t ui8PlayloadType = 96,
|
uint8_t ui8PayloadType = 96,
|
||||||
uint8_t ui8Interleaved = TrackVideo * 2);
|
uint8_t ui8Interleaved = TrackVideo * 2);
|
||||||
~H264RtpEncoder() {}
|
~H264RtpEncoder() {}
|
||||||
|
|
||||||
|
@ -315,19 +315,19 @@ public:
|
|||||||
* 构造函数
|
* 构造函数
|
||||||
* @param sps 265 sps,不带0x00000001头
|
* @param sps 265 sps,不带0x00000001头
|
||||||
* @param pps 265 pps,不带0x00000001头
|
* @param pps 265 pps,不带0x00000001头
|
||||||
* @param playload_type rtp playload type 默认96
|
* @param payload_type rtp payload type 默认96
|
||||||
* @param bitrate 比特率
|
* @param bitrate 比特率
|
||||||
*/
|
*/
|
||||||
H265Sdp(const string &strVPS,
|
H265Sdp(const string &strVPS,
|
||||||
const string &strSPS,
|
const string &strSPS,
|
||||||
const string &strPPS,
|
const string &strPPS,
|
||||||
int playload_type = 96,
|
int payload_type = 96,
|
||||||
int bitrate = 4000) : Sdp(90000,playload_type) {
|
int bitrate = 4000) : Sdp(90000,payload_type) {
|
||||||
//视频通道
|
//视频通道
|
||||||
_printer << "m=video 0 RTP/AVP " << playload_type << "\r\n";
|
_printer << "m=video 0 RTP/AVP " << payload_type << "\r\n";
|
||||||
_printer << "b=AS:" << bitrate << "\r\n";
|
_printer << "b=AS:" << bitrate << "\r\n";
|
||||||
_printer << "a=rtpmap:" << playload_type << " H265/" << 90000 << "\r\n";
|
_printer << "a=rtpmap:" << payload_type << " H265/" << 90000 << "\r\n";
|
||||||
_printer << "a=fmtp:" << playload_type << " ";
|
_printer << "a=fmtp:" << payload_type << " ";
|
||||||
_printer << "sprop-vps=";
|
_printer << "sprop-vps=";
|
||||||
_printer << encodeBase64(strVPS) << "; ";
|
_printer << encodeBase64(strVPS) << "; ";
|
||||||
_printer << "sprop-sps=";
|
_printer << "sprop-sps=";
|
||||||
|
@ -140,12 +140,12 @@ void H265RtpDecoder::onGetH265(const H265Frame::Ptr &frame) {
|
|||||||
H265RtpEncoder::H265RtpEncoder(uint32_t ui32Ssrc,
|
H265RtpEncoder::H265RtpEncoder(uint32_t ui32Ssrc,
|
||||||
uint32_t ui32MtuSize,
|
uint32_t ui32MtuSize,
|
||||||
uint32_t ui32SampleRate,
|
uint32_t ui32SampleRate,
|
||||||
uint8_t ui8PlayloadType,
|
uint8_t ui8PayloadType,
|
||||||
uint8_t ui8Interleaved) :
|
uint8_t ui8Interleaved) :
|
||||||
RtpInfo(ui32Ssrc,
|
RtpInfo(ui32Ssrc,
|
||||||
ui32MtuSize,
|
ui32MtuSize,
|
||||||
ui32SampleRate,
|
ui32SampleRate,
|
||||||
ui8PlayloadType,
|
ui8PayloadType,
|
||||||
ui8Interleaved) {
|
ui8Interleaved) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,13 +63,13 @@ public:
|
|||||||
* @param ui32Ssrc ssrc
|
* @param ui32Ssrc ssrc
|
||||||
* @param ui32MtuSize mtu大小
|
* @param ui32MtuSize mtu大小
|
||||||
* @param ui32SampleRate 采样率,强制为90000
|
* @param ui32SampleRate 采样率,强制为90000
|
||||||
* @param ui8PlayloadType pt类型
|
* @param ui8PayloadType pt类型
|
||||||
* @param ui8Interleaved rtsp interleaved
|
* @param ui8Interleaved rtsp interleaved
|
||||||
*/
|
*/
|
||||||
H265RtpEncoder(uint32_t ui32Ssrc,
|
H265RtpEncoder(uint32_t ui32Ssrc,
|
||||||
uint32_t ui32MtuSize = 1400,
|
uint32_t ui32MtuSize = 1400,
|
||||||
uint32_t ui32SampleRate = 90000,
|
uint32_t ui32SampleRate = 90000,
|
||||||
uint8_t ui8PlayloadType = 96,
|
uint8_t ui8PayloadType = 96,
|
||||||
uint8_t ui8Interleaved = TrackVideo * 2);
|
uint8_t ui8Interleaved = TrackVideo * 2);
|
||||||
~H265RtpEncoder() {}
|
~H265RtpEncoder() {}
|
||||||
|
|
||||||
|
@ -80,15 +80,15 @@ public:
|
|||||||
/**
|
/**
|
||||||
* 构造opus sdp
|
* 构造opus sdp
|
||||||
* @param sample_rate 音频采样率
|
* @param sample_rate 音频采样率
|
||||||
* @param playload_type rtp playload
|
* @param payload_type rtp payload
|
||||||
* @param bitrate 比特率
|
* @param bitrate 比特率
|
||||||
*/
|
*/
|
||||||
OpusSdp(int sample_rate,
|
OpusSdp(int sample_rate,
|
||||||
int channels,
|
int channels,
|
||||||
int playload_type = 98,
|
int payload_type = 98,
|
||||||
int bitrate = 128) : Sdp(sample_rate,playload_type){
|
int bitrate = 128) : Sdp(sample_rate,payload_type){
|
||||||
_printer << "m=audio 0 RTP/AVP " << playload_type << "\r\n";
|
_printer << "m=audio 0 RTP/AVP " << payload_type << "\r\n";
|
||||||
_printer << "a=rtpmap:" << playload_type << " opus/" << sample_rate << "/" << channels << "\r\n";
|
_printer << "a=rtpmap:" << payload_type << " opus/" << sample_rate << "/" << channels << "\r\n";
|
||||||
_printer << "a=control:trackID=" << (int)TrackAudio << "\r\n";
|
_printer << "a=control:trackID=" << (int)TrackAudio << "\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ protected:
|
|||||||
//WebSocketSplitter override
|
//WebSocketSplitter override
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 收到一个webSocket数据包包头,后续将继续触发onWebSocketDecodePlayload回调
|
* 收到一个webSocket数据包包头,后续将继续触发onWebSocketDecodePayload回调
|
||||||
* @param header 数据包头
|
* @param header 数据包头
|
||||||
*/
|
*/
|
||||||
void onWebSocketDecodeHeader(const WebSocketHeader &header) override{
|
void onWebSocketDecodeHeader(const WebSocketHeader &header) override{
|
||||||
@ -205,9 +205,9 @@ protected:
|
|||||||
* @param header 数据包包头
|
* @param header 数据包包头
|
||||||
* @param ptr 负载数据指针
|
* @param ptr 负载数据指针
|
||||||
* @param len 负载数据长度
|
* @param len 负载数据长度
|
||||||
* @param recved 已接收数据长度(包含本次数据长度),等于header._playload_len时则接受完毕
|
* @param recved 已接收数据长度(包含本次数据长度),等于header._payload_len时则接受完毕
|
||||||
*/
|
*/
|
||||||
void onWebSocketDecodePlayload(const WebSocketHeader &header, const uint8_t *ptr, uint64_t len, uint64_t recved) override{
|
void onWebSocketDecodePayload(const WebSocketHeader &header, const uint8_t *ptr, uint64_t len, uint64_t recved) override{
|
||||||
_payload.append((char *)ptr,len);
|
_payload.append((char *)ptr,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ protected:
|
|||||||
* @param len
|
* @param len
|
||||||
* @param recved
|
* @param recved
|
||||||
*/
|
*/
|
||||||
void onWebSocketDecodePlayload(const WebSocketHeader &packet,const uint8_t *ptr,uint64_t len,uint64_t recved) override {
|
void onWebSocketDecodePayload(const WebSocketHeader &packet,const uint8_t *ptr,uint64_t len,uint64_t recved) override {
|
||||||
_remian_data.append((char *)ptr,len);
|
_remian_data.append((char *)ptr,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,16 +72,16 @@ begin_decode:
|
|||||||
|
|
||||||
CHECK_LEN(1);
|
CHECK_LEN(1);
|
||||||
_mask_flag = (*ptr & 0x80) >> 7;
|
_mask_flag = (*ptr & 0x80) >> 7;
|
||||||
_playload_len = (*ptr & 0x7F);
|
_payload_len = (*ptr & 0x7F);
|
||||||
ptr += 1;
|
ptr += 1;
|
||||||
|
|
||||||
if (_playload_len == 126) {
|
if (_payload_len == 126) {
|
||||||
CHECK_LEN(2);
|
CHECK_LEN(2);
|
||||||
_playload_len = (*ptr << 8) | *(ptr + 1);
|
_payload_len = (*ptr << 8) | *(ptr + 1);
|
||||||
ptr += 2;
|
ptr += 2;
|
||||||
} else if (_playload_len == 127) {
|
} else if (_payload_len == 127) {
|
||||||
CHECK_LEN(8);
|
CHECK_LEN(8);
|
||||||
_playload_len = ((uint64_t) ptr[0] << (8 * 7)) |
|
_payload_len = ((uint64_t) ptr[0] << (8 * 7)) |
|
||||||
((uint64_t) ptr[1] << (8 * 6)) |
|
((uint64_t) ptr[1] << (8 * 6)) |
|
||||||
((uint64_t) ptr[2] << (8 * 5)) |
|
((uint64_t) ptr[2] << (8 * 5)) |
|
||||||
((uint64_t) ptr[3] << (8 * 4)) |
|
((uint64_t) ptr[3] << (8 * 4)) |
|
||||||
@ -98,9 +98,9 @@ begin_decode:
|
|||||||
}
|
}
|
||||||
_got_header = true;
|
_got_header = true;
|
||||||
_mask_offset = 0;
|
_mask_offset = 0;
|
||||||
_playload_offset = 0;
|
_payload_offset = 0;
|
||||||
onWebSocketDecodeHeader(*this);
|
onWebSocketDecodeHeader(*this);
|
||||||
if(_playload_len == 0){
|
if(_payload_len == 0){
|
||||||
onWebSocketDecodeComplete(*this);
|
onWebSocketDecodeComplete(*this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,19 +109,19 @@ begin_decode:
|
|||||||
|
|
||||||
uint64_t remain = len - (ptr - data);
|
uint64_t remain = len - (ptr - data);
|
||||||
if(remain > 0){
|
if(remain > 0){
|
||||||
uint64_t playload_slice_len = remain;
|
uint64_t payload_slice_len = remain;
|
||||||
if(playload_slice_len + _playload_offset > _playload_len){
|
if(payload_slice_len + _payload_offset > _payload_len){
|
||||||
playload_slice_len = _playload_len - _playload_offset;
|
payload_slice_len = _payload_len - _payload_offset;
|
||||||
}
|
}
|
||||||
_playload_offset += playload_slice_len;
|
_payload_offset += payload_slice_len;
|
||||||
onPlayloadData(ptr,playload_slice_len);
|
onPayloadData(ptr, payload_slice_len);
|
||||||
|
|
||||||
if(_playload_offset == _playload_len){
|
if(_payload_offset == _payload_len){
|
||||||
onWebSocketDecodeComplete(*this);
|
onWebSocketDecodeComplete(*this);
|
||||||
|
|
||||||
//这是下一个包
|
//这是下一个包
|
||||||
remain -= playload_slice_len;
|
remain -= payload_slice_len;
|
||||||
ptr += playload_slice_len;
|
ptr += payload_slice_len;
|
||||||
_got_header = false;
|
_got_header = false;
|
||||||
|
|
||||||
if(remain > 0){
|
if(remain > 0){
|
||||||
@ -138,14 +138,14 @@ begin_decode:
|
|||||||
_remain_data.clear();
|
_remain_data.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebSocketSplitter::onPlayloadData(uint8_t *ptr, uint64_t len) {
|
void WebSocketSplitter::onPayloadData(uint8_t *data, uint64_t len) {
|
||||||
if(_mask_flag){
|
if(_mask_flag){
|
||||||
for(int i = 0; i < len ; ++i,++ptr){
|
for(int i = 0; i < len ; ++i,++data){
|
||||||
*(ptr) ^= _mask[(i + _mask_offset) % 4];
|
*(data) ^= _mask[(i + _mask_offset) % 4];
|
||||||
}
|
}
|
||||||
_mask_offset = (_mask_offset + len) % 4;
|
_mask_offset = (_mask_offset + len) % 4;
|
||||||
}
|
}
|
||||||
onWebSocketDecodePlayload(*this, _mask_flag ? ptr - len : ptr, len, _playload_offset);
|
onWebSocketDecodePayload(*this, _mask_flag ? data - len : data, len, _payload_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebSocketSplitter::encode(const WebSocketHeader &header,const Buffer::Ptr &buffer) {
|
void WebSocketSplitter::encode(const WebSocketHeader &header,const Buffer::Ptr &buffer) {
|
||||||
|
@ -51,7 +51,7 @@ public:
|
|||||||
uint8_t _reserved;
|
uint8_t _reserved;
|
||||||
Type _opcode;
|
Type _opcode;
|
||||||
bool _mask_flag;
|
bool _mask_flag;
|
||||||
uint64_t _playload_len;
|
uint64_t _payload_len;
|
||||||
vector<uint8_t > _mask;
|
vector<uint8_t > _mask;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入数据以便解包webSocket数据以及处理粘包问题
|
* 输入数据以便解包webSocket数据以及处理粘包问题
|
||||||
* 可能触发onWebSocketDecodeHeader和onWebSocketDecodePlayload回调
|
* 可能触发onWebSocketDecodeHeader和onWebSocketDecodePayload回调
|
||||||
* @param data 需要解包的数据,可能是不完整的包或多个包
|
* @param data 需要解包的数据,可能是不完整的包或多个包
|
||||||
* @param len 数据长度
|
* @param len 数据长度
|
||||||
*/
|
*/
|
||||||
@ -77,7 +77,7 @@ public:
|
|||||||
void encode(const WebSocketHeader &header,const Buffer::Ptr &buffer);
|
void encode(const WebSocketHeader &header,const Buffer::Ptr &buffer);
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* 收到一个webSocket数据包包头,后续将继续触发onWebSocketDecodePlayload回调
|
* 收到一个webSocket数据包包头,后续将继续触发onWebSocketDecodePayload回调
|
||||||
* @param header 数据包头
|
* @param header 数据包头
|
||||||
*/
|
*/
|
||||||
virtual void onWebSocketDecodeHeader(const WebSocketHeader &header) {};
|
virtual void onWebSocketDecodeHeader(const WebSocketHeader &header) {};
|
||||||
@ -87,9 +87,9 @@ protected:
|
|||||||
* @param header 数据包包头
|
* @param header 数据包包头
|
||||||
* @param ptr 负载数据指针
|
* @param ptr 负载数据指针
|
||||||
* @param len 负载数据长度
|
* @param len 负载数据长度
|
||||||
* @param recved 已接收数据长度(包含本次数据长度),等于header._playload_len时则接受完毕
|
* @param recved 已接收数据长度(包含本次数据长度),等于header._payload_len时则接受完毕
|
||||||
*/
|
*/
|
||||||
virtual void onWebSocketDecodePlayload(const WebSocketHeader &header, const uint8_t *ptr, uint64_t len, uint64_t recved) {};
|
virtual void onWebSocketDecodePayload(const WebSocketHeader &header, const uint8_t *ptr, uint64_t len, uint64_t recved) {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,12 +105,12 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual void onWebSocketEncodeData(const Buffer::Ptr &buffer){};
|
virtual void onWebSocketEncodeData(const Buffer::Ptr &buffer){};
|
||||||
private:
|
private:
|
||||||
void onPlayloadData(uint8_t *data,uint64_t len);
|
void onPayloadData(uint8_t *data, uint64_t len);
|
||||||
private:
|
private:
|
||||||
string _remain_data;
|
string _remain_data;
|
||||||
int _mask_offset = 0;
|
int _mask_offset = 0;
|
||||||
bool _got_header = false;
|
bool _got_header = false;
|
||||||
uint64_t _playload_offset = 0;
|
uint64_t _payload_offset = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace mediakit */
|
} /* namespace mediakit */
|
||||||
|
@ -28,18 +28,18 @@ RtpPacket::Ptr RtpInfo::makeRtp(TrackType type, const void* data, unsigned int l
|
|||||||
pucRtp[2] = ui16RtpLen >> 8;
|
pucRtp[2] = ui16RtpLen >> 8;
|
||||||
pucRtp[3] = ui16RtpLen & 0x00FF;
|
pucRtp[3] = ui16RtpLen & 0x00FF;
|
||||||
pucRtp[4] = 0x80;
|
pucRtp[4] = 0x80;
|
||||||
pucRtp[5] = (mark << 7) | _ui8PlayloadType;
|
pucRtp[5] = (mark << 7) | _ui8PayloadType;
|
||||||
memcpy(&pucRtp[6], &sq, 2);
|
memcpy(&pucRtp[6], &sq, 2);
|
||||||
memcpy(&pucRtp[8], &ts, 4);
|
memcpy(&pucRtp[8], &ts, 4);
|
||||||
//ssrc
|
//ssrc
|
||||||
memcpy(&pucRtp[12], &sc, 4);
|
memcpy(&pucRtp[12], &sc, 4);
|
||||||
|
|
||||||
if(data){
|
if(data){
|
||||||
//playload
|
//payload
|
||||||
memcpy(&pucRtp[16], data, len);
|
memcpy(&pucRtp[16], data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
rtppkt->PT = _ui8PlayloadType;
|
rtppkt->PT = _ui8PayloadType;
|
||||||
rtppkt->interleaved = _ui8Interleaved;
|
rtppkt->interleaved = _ui8Interleaved;
|
||||||
rtppkt->mark = mark;
|
rtppkt->mark = mark;
|
||||||
rtppkt->sequence = _ui16Sequence;
|
rtppkt->sequence = _ui16Sequence;
|
||||||
|
@ -66,7 +66,7 @@ public:
|
|||||||
RtpInfo(uint32_t ui32Ssrc,
|
RtpInfo(uint32_t ui32Ssrc,
|
||||||
uint32_t ui32MtuSize,
|
uint32_t ui32MtuSize,
|
||||||
uint32_t ui32SampleRate,
|
uint32_t ui32SampleRate,
|
||||||
uint8_t ui8PlayloadType,
|
uint8_t ui8PayloadType,
|
||||||
uint8_t ui8Interleaved) {
|
uint8_t ui8Interleaved) {
|
||||||
if(ui32Ssrc == 0){
|
if(ui32Ssrc == 0){
|
||||||
ui32Ssrc = ((uint64_t)this) & 0xFFFFFFFF;
|
ui32Ssrc = ((uint64_t)this) & 0xFFFFFFFF;
|
||||||
@ -74,7 +74,7 @@ public:
|
|||||||
_ui32Ssrc = ui32Ssrc;
|
_ui32Ssrc = ui32Ssrc;
|
||||||
_ui32SampleRate = ui32SampleRate;
|
_ui32SampleRate = ui32SampleRate;
|
||||||
_ui32MtuSize = ui32MtuSize;
|
_ui32MtuSize = ui32MtuSize;
|
||||||
_ui8PlayloadType = ui8PlayloadType;
|
_ui8PayloadType = ui8PayloadType;
|
||||||
_ui8Interleaved = ui8Interleaved;
|
_ui8Interleaved = ui8Interleaved;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,8 +84,8 @@ public:
|
|||||||
return _ui8Interleaved;
|
return _ui8Interleaved;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getPlayloadType() const {
|
int getPayloadType() const {
|
||||||
return _ui8PlayloadType;
|
return _ui8PayloadType;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSampleRate() const {
|
int getSampleRate() const {
|
||||||
@ -110,7 +110,7 @@ protected:
|
|||||||
uint32_t _ui32Ssrc;
|
uint32_t _ui32Ssrc;
|
||||||
uint32_t _ui32SampleRate;
|
uint32_t _ui32SampleRate;
|
||||||
uint32_t _ui32MtuSize;
|
uint32_t _ui32MtuSize;
|
||||||
uint8_t _ui8PlayloadType;
|
uint8_t _ui8PayloadType;
|
||||||
uint8_t _ui8Interleaved;
|
uint8_t _ui8Interleaved;
|
||||||
uint16_t _ui16Sequence = 0;
|
uint16_t _ui16Sequence = 0;
|
||||||
uint32_t _ui32TimeStamp = 0;
|
uint32_t _ui32TimeStamp = 0;
|
||||||
|
@ -188,11 +188,11 @@ public:
|
|||||||
/**
|
/**
|
||||||
* 构造sdp
|
* 构造sdp
|
||||||
* @param sample_rate 采样率
|
* @param sample_rate 采样率
|
||||||
* @param playload_type pt类型
|
* @param payload_type pt类型
|
||||||
*/
|
*/
|
||||||
Sdp(uint32_t sample_rate, uint8_t playload_type){
|
Sdp(uint32_t sample_rate, uint8_t payload_type){
|
||||||
_sample_rate = sample_rate;
|
_sample_rate = sample_rate;
|
||||||
_playload_type = playload_type;
|
_payload_type = payload_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Sdp(){}
|
virtual ~Sdp(){}
|
||||||
@ -207,8 +207,8 @@ public:
|
|||||||
* 获取pt
|
* 获取pt
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
uint8_t getPlayloadType() const{
|
uint8_t getPayloadType() const{
|
||||||
return _playload_type;
|
return _payload_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -219,7 +219,7 @@ public:
|
|||||||
return _sample_rate;
|
return _sample_rate;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
uint8_t _playload_type;
|
uint8_t _payload_type;
|
||||||
uint32_t _sample_rate;
|
uint32_t _sample_rate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user