rtp打包减少一次内存拷贝

This commit is contained in:
xiongziliang 2019-09-06 15:16:22 +08:00
parent ca8e295ada
commit 39e3c89848
19 changed files with 37 additions and 16 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -265,11 +265,22 @@ void H264RtpEncoder::inputFrame(const Frame::Ptr &frame) {
} else { } else {
s_e_r_type = s_e_r_Mid + naluType; s_e_r_type = s_e_r_Mid + naluType;
} }
memcpy(_aucSectionBuf, &f_nri_type, 1);
memcpy(_aucSectionBuf + 1, &s_e_r_type, 1); {
memcpy(_aucSectionBuf + 2, (unsigned char *) pcData + nOffset, iSize); //传入nullptr先不做payload的内存拷贝
auto rtp = makeRtp(getTrackType(), nullptr, iSize + 2, mark, uiStamp);
//rtp payload 负载部分
uint8_t *payload = (uint8_t*)rtp->data() + rtp->offset;
//FU-A 第1个字节
memcpy(payload, &f_nri_type, 1);
//FU-A 第2个字节
memcpy(payload + 1, &s_e_r_type, 1);
//H264 数据
memcpy(payload + 2, (unsigned char *) pcData + nOffset, iSize);
//输入到rtp环形缓存
RtpCodec::inputRtp(rtp,bFirst && naluType == H264Frame::NAL_IDR);
}
nOffset += iSize; nOffset += iSize;
makeH264Rtp(naluType,_aucSectionBuf, iSize + 2, mark,bFirst, uiStamp);
bFirst = false; bFirst = false;
} }
} else { } else {

View File

@ -97,8 +97,6 @@ public:
void inputFrame(const Frame::Ptr &frame) override; void inputFrame(const Frame::Ptr &frame) override;
private: private:
void makeH264Rtp(int nal_type,const void *pData, unsigned int uiLen, bool bMark, bool first_packet, uint32_t uiStamp); void makeH264Rtp(int nal_type,const void *pData, unsigned int uiLen, bool bMark, bool first_packet, uint32_t uiStamp);
private:
unsigned char _aucSectionBuf[1600];
}; };
}//namespace mediakit{ }//namespace mediakit{

View File

@ -194,13 +194,24 @@ void H265RtpEncoder::inputFrame(const Frame::Ptr &frame) {
s_e_type = naluType; s_e_type = naluType;
} }
//FU type {
_aucSectionBuf[0] = 49 << 1; //传入nullptr先不做payload的内存拷贝
_aucSectionBuf[1] = 1; auto rtp = makeRtp(getTrackType(), nullptr, maxSize + 3, mark, uiStamp);
_aucSectionBuf[2] = s_e_type; //rtp payload 负载部分
memcpy(_aucSectionBuf + 3, pcData + nOffset, maxSize); uint8_t *payload = (uint8_t*)rtp->data() + rtp->offset;
//FU-A 第1个字节
payload[0] = 49 << 1;
//FU-A 第2个字节貌似固定为1
payload[1] = 1;
//FU-A 第3个字节
payload[2] = s_e_type;
//H265 数据
memcpy(payload + 3,pcData + nOffset, maxSize);
//输入到rtp环形缓存
RtpCodec::inputRtp(rtp,bFirst && H265Frame::isKeyFrame(naluType));
}
nOffset += maxSize; nOffset += maxSize;
makeH265Rtp(naluType,_aucSectionBuf, maxSize + 3, mark,bFirst, uiStamp);
bFirst = false; bFirst = false;
} }
} else { } else {

View File

@ -98,8 +98,6 @@ public:
void inputFrame(const Frame::Ptr &frame) override; void inputFrame(const Frame::Ptr &frame) override;
private: private:
void makeH265Rtp(int nal_type,const void *pData, unsigned int uiLen, bool bMark, bool first_packet,uint32_t uiStamp); void makeH265Rtp(int nal_type,const void *pData, unsigned int uiLen, bool bMark, bool first_packet,uint32_t uiStamp);
private:
unsigned char _aucSectionBuf[1600];
}; };
}//namespace mediakit{ }//namespace mediakit{

View File

@ -49,8 +49,11 @@ RtpPacket::Ptr RtpInfo::makeRtp(TrackType type, const void* data, unsigned int l
memcpy(&pucRtp[8], &ts, 4); memcpy(&pucRtp[8], &ts, 4);
//ssrc //ssrc
memcpy(&pucRtp[12], &sc, 4); memcpy(&pucRtp[12], &sc, 4);
if(data){
//playload //playload
memcpy(&pucRtp[16], data, len); memcpy(&pucRtp[16], data, len);
}
rtppkt->PT = _ui8PlayloadType; rtppkt->PT = _ui8PlayloadType;
rtppkt->interleaved = _ui8Interleaved; rtppkt->interleaved = _ui8Interleaved;