支持超大rtp包

This commit is contained in:
xiongziliang 2019-06-24 16:07:44 +08:00
parent cc7b19dedc
commit 9039f8c1f6
9 changed files with 30 additions and 37 deletions

View File

@ -203,7 +203,7 @@ JNI_API(jlong,createMediaPlayer,jstring url,jobject callback){
emitEvent((jobject)globalWeakRef,"onShutdown","(ILjava/lang/String;)V",(jint)ex.getErrCode(),env->NewStringUTF(ex.what()));
});
(*player)[Client::kRtpType] = Rtsp::RTP_UDP;
(*player)[Client::kRtpType] = Rtsp::RTP_TCP;
player->play(stringFromJstring(env,url));
return (jlong)(ret);

View File

@ -45,9 +45,9 @@ RtpReceiver::~RtpReceiver() {}
bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char *pucData, unsigned int uiLen) {
auto pt_ptr=_pktPool.obtain();
auto &rtppt=*pt_ptr;
rtppt.interleaved = track->_interleaved;
rtppt.length = uiLen + 4;
auto length = uiLen + 4;
rtppt.interleaved = track->_interleaved;
rtppt.mark = pucData[1] >> 7;
rtppt.PT = pucData[1] & 0x7F;
//序列号
@ -81,12 +81,8 @@ bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char
}
_aui32SsrcErrorCnt[iTrackidx] = 0;
rtppt.payload[0] = '$';
rtppt.payload[1] = rtppt.interleaved;
rtppt.payload[2] = uiLen >> 8;
rtppt.payload[3] = (uiLen & 0x00FF);
rtppt.offset = 16;
//获取rtp中媒体数据偏移量
rtppt.offset = 12 + 4;
int csrc = pucData[0] & 0x0f;
int ext = pucData[0] & 0x10;
rtppt.offset += 4 * csrc;
@ -99,16 +95,20 @@ bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char
rtppt.offset += ext;
}
if(rtppt.length - rtppt.offset <= 0){
WarnL << "无有效负载的rtp包:" << rtppt.length << "<=" << (int)rtppt.offset;
if(length - rtppt.offset <= 0){
WarnL << "无有效负载的rtp包:" << length << "<=" << (int)rtppt.offset;
return false;
}
if(uiLen > sizeof(rtppt.payload) - 4){
WarnL << "超长的rtp包:" << uiLen << ">" << sizeof(rtppt.payload) - 4;
return false;
}
memcpy(rtppt.payload + 4, pucData, uiLen);
rtppt.setCapacity(length);
rtppt.setSize(length);
uint8_t *payload_ptr = (uint8_t *)rtppt.data();
payload_ptr[0] = '$';
payload_ptr[1] = rtppt.interleaved;
payload_ptr[2] = uiLen >> 8;
payload_ptr[3] = (uiLen & 0x00FF);
//拷贝rtp负载
memcpy(payload_ptr + 4, pucData, uiLen);
/////////////////////////////////RTP排序逻辑///////////////////////////////////
if(rtppt.sequence != _aui16LastSeq[iTrackidx] + 1 && _aui16LastSeq[iTrackidx] != 0){

View File

@ -732,7 +732,7 @@ void RtspPlayer::onRecvRTP_l(const RtpPacket::Ptr &pkt, const SdpTrack::Ptr &tra
//send rtcp every 5 second
counter.lastTimeStamp = counter.timeStamp;
//直接保存网络字节序
memcpy(&counter.timeStamp, pkt->payload + 8 , 4);
memcpy(&counter.timeStamp, pkt->data() + 8 , 4);
if(counter.lastTimeStamp != 0){
sendReceiverReport(_eType == Rtsp::RTP_TCP,iTrackIndex);
ticker.resetTime();

View File

@ -57,10 +57,10 @@ public:
virtual ~BufferRtp(){}
char *data() const override {
return (char *)_rtp->payload + _offset;
return (char *)_rtp->data() + _offset;
}
uint32_t size() const override {
return _rtp->length - _offset;
return _rtp->size() - _offset;
}
private:
RtpPacket::Ptr _rtp;

View File

@ -105,10 +105,10 @@ bool AACRtpDecoder::inputRtp(const RtpPacket::Ptr &rtppack, bool key_pos) {
RtpCodec::inputRtp(rtppack, false);
// 获取rtp数据长度
int length = rtppack->length - rtppack->offset;
int length = rtppack->size() - rtppack->offset;
// 获取rtp数据
const uint8_t *rtp_packet_buf = (uint8_t *)rtppack->payload + rtppack->offset;
const uint8_t *rtp_packet_buf = (uint8_t *)rtppack->data() + rtppack->offset;
do
{

View File

@ -91,8 +91,8 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
* Type==8:PPS frame
*/
const uint8_t *frame = (uint8_t *) rtppack->payload + rtppack->offset;
int length = rtppack->length - rtppack->offset;
const uint8_t *frame = (uint8_t *) rtppack->data() + rtppack->offset;
int length = rtppack->size() - rtppack->offset;
NALU nal;
MakeNalu(*frame, nal);

View File

@ -82,8 +82,8 @@ bool H265RtpDecoder::inputRtp(const RtpPacket::Ptr &rtp, bool key_pos) {
}
bool H265RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
const uint8_t *frame = (uint8_t *) rtppack->payload + rtppack->offset;
int length = rtppack->length - rtppack->offset;
const uint8_t *frame = (uint8_t *) rtppack->data() + rtppack->offset;
int length = rtppack->size() - rtppack->offset;
int nal = H265_TYPE(frame[0]);
if (nal > 50){

View File

@ -35,7 +35,10 @@ RtpPacket::Ptr RtpInfo::makeRtp(TrackType type, const void* data, unsigned int l
uint32_t sc = htonl(_ui32Ssrc);
auto rtppkt = ResourcePoolHelper<RtpPacket>::obtainObj();
unsigned char *pucRtp = rtppkt->payload;
rtppkt->setCapacity(len + 16);
rtppkt->setSize(len + 16);
unsigned char *pucRtp = (unsigned char *)rtppkt->data();
pucRtp[0] = '$';
pucRtp[1] = _ui8Interleaved;
pucRtp[2] = ui16RtpLen >> 8;
@ -52,7 +55,6 @@ RtpPacket::Ptr RtpInfo::makeRtp(TrackType type, const void* data, unsigned int l
rtppkt->PT = _ui8PlayloadType;
rtppkt->interleaved = _ui8Interleaved;
rtppkt->mark = mark;
rtppkt->length = len + 16;
rtppkt->sequence = _ui16Sequence;
rtppkt->timeStamp = uiStamp;
rtppkt->ssrc = _ui32Ssrc;

View File

@ -35,27 +35,18 @@ using namespace toolkit;
namespace mediakit{
class RtpPacket : public Buffer{
class RtpPacket : public BufferRaw{
public:
typedef std::shared_ptr<RtpPacket> Ptr;
uint8_t interleaved;
uint8_t PT;
bool mark;
uint32_t length;
//时间戳,单位毫秒
uint32_t timeStamp;
uint16_t sequence;
uint32_t ssrc;
uint8_t payload[1604];
uint8_t offset;
TrackType type;
char *data() const override {
return (char *)payload;
}
uint32_t size() const override {
return length;
}
};
class RtpRingInterface {