mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
支持超大rtp包
This commit is contained in:
parent
cc7b19dedc
commit
9039f8c1f6
@ -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()));
|
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));
|
player->play(stringFromJstring(env,url));
|
||||||
|
|
||||||
return (jlong)(ret);
|
return (jlong)(ret);
|
||||||
|
@ -45,9 +45,9 @@ RtpReceiver::~RtpReceiver() {}
|
|||||||
bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char *pucData, unsigned int uiLen) {
|
bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char *pucData, unsigned int uiLen) {
|
||||||
auto pt_ptr=_pktPool.obtain();
|
auto pt_ptr=_pktPool.obtain();
|
||||||
auto &rtppt=*pt_ptr;
|
auto &rtppt=*pt_ptr;
|
||||||
rtppt.interleaved = track->_interleaved;
|
auto length = uiLen + 4;
|
||||||
rtppt.length = uiLen + 4;
|
|
||||||
|
|
||||||
|
rtppt.interleaved = track->_interleaved;
|
||||||
rtppt.mark = pucData[1] >> 7;
|
rtppt.mark = pucData[1] >> 7;
|
||||||
rtppt.PT = pucData[1] & 0x7F;
|
rtppt.PT = pucData[1] & 0x7F;
|
||||||
//序列号
|
//序列号
|
||||||
@ -81,12 +81,8 @@ bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char
|
|||||||
}
|
}
|
||||||
_aui32SsrcErrorCnt[iTrackidx] = 0;
|
_aui32SsrcErrorCnt[iTrackidx] = 0;
|
||||||
|
|
||||||
rtppt.payload[0] = '$';
|
//获取rtp中媒体数据偏移量
|
||||||
rtppt.payload[1] = rtppt.interleaved;
|
rtppt.offset = 12 + 4;
|
||||||
rtppt.payload[2] = uiLen >> 8;
|
|
||||||
rtppt.payload[3] = (uiLen & 0x00FF);
|
|
||||||
|
|
||||||
rtppt.offset = 16;
|
|
||||||
int csrc = pucData[0] & 0x0f;
|
int csrc = pucData[0] & 0x0f;
|
||||||
int ext = pucData[0] & 0x10;
|
int ext = pucData[0] & 0x10;
|
||||||
rtppt.offset += 4 * csrc;
|
rtppt.offset += 4 * csrc;
|
||||||
@ -99,16 +95,20 @@ bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char
|
|||||||
rtppt.offset += ext;
|
rtppt.offset += ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rtppt.length - rtppt.offset <= 0){
|
if(length - rtppt.offset <= 0){
|
||||||
WarnL << "无有效负载的rtp包:" << rtppt.length << "<=" << (int)rtppt.offset;
|
WarnL << "无有效负载的rtp包:" << length << "<=" << (int)rtppt.offset;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(uiLen > sizeof(rtppt.payload) - 4){
|
rtppt.setCapacity(length);
|
||||||
WarnL << "超长的rtp包:" << uiLen << ">" << sizeof(rtppt.payload) - 4;
|
rtppt.setSize(length);
|
||||||
return false;
|
uint8_t *payload_ptr = (uint8_t *)rtppt.data();
|
||||||
}
|
payload_ptr[0] = '$';
|
||||||
memcpy(rtppt.payload + 4, pucData, uiLen);
|
payload_ptr[1] = rtppt.interleaved;
|
||||||
|
payload_ptr[2] = uiLen >> 8;
|
||||||
|
payload_ptr[3] = (uiLen & 0x00FF);
|
||||||
|
//拷贝rtp负载
|
||||||
|
memcpy(payload_ptr + 4, pucData, uiLen);
|
||||||
|
|
||||||
/////////////////////////////////RTP排序逻辑///////////////////////////////////
|
/////////////////////////////////RTP排序逻辑///////////////////////////////////
|
||||||
if(rtppt.sequence != _aui16LastSeq[iTrackidx] + 1 && _aui16LastSeq[iTrackidx] != 0){
|
if(rtppt.sequence != _aui16LastSeq[iTrackidx] + 1 && _aui16LastSeq[iTrackidx] != 0){
|
||||||
|
@ -732,7 +732,7 @@ void RtspPlayer::onRecvRTP_l(const RtpPacket::Ptr &pkt, const SdpTrack::Ptr &tra
|
|||||||
//send rtcp every 5 second
|
//send rtcp every 5 second
|
||||||
counter.lastTimeStamp = counter.timeStamp;
|
counter.lastTimeStamp = counter.timeStamp;
|
||||||
//直接保存网络字节序
|
//直接保存网络字节序
|
||||||
memcpy(&counter.timeStamp, pkt->payload + 8 , 4);
|
memcpy(&counter.timeStamp, pkt->data() + 8 , 4);
|
||||||
if(counter.lastTimeStamp != 0){
|
if(counter.lastTimeStamp != 0){
|
||||||
sendReceiverReport(_eType == Rtsp::RTP_TCP,iTrackIndex);
|
sendReceiverReport(_eType == Rtsp::RTP_TCP,iTrackIndex);
|
||||||
ticker.resetTime();
|
ticker.resetTime();
|
||||||
|
@ -57,10 +57,10 @@ public:
|
|||||||
virtual ~BufferRtp(){}
|
virtual ~BufferRtp(){}
|
||||||
|
|
||||||
char *data() const override {
|
char *data() const override {
|
||||||
return (char *)_rtp->payload + _offset;
|
return (char *)_rtp->data() + _offset;
|
||||||
}
|
}
|
||||||
uint32_t size() const override {
|
uint32_t size() const override {
|
||||||
return _rtp->length - _offset;
|
return _rtp->size() - _offset;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
RtpPacket::Ptr _rtp;
|
RtpPacket::Ptr _rtp;
|
||||||
|
@ -105,10 +105,10 @@ bool AACRtpDecoder::inputRtp(const RtpPacket::Ptr &rtppack, bool key_pos) {
|
|||||||
RtpCodec::inputRtp(rtppack, false);
|
RtpCodec::inputRtp(rtppack, false);
|
||||||
|
|
||||||
// 获取rtp数据长度
|
// 获取rtp数据长度
|
||||||
int length = rtppack->length - rtppack->offset;
|
int length = rtppack->size() - rtppack->offset;
|
||||||
|
|
||||||
// 获取rtp数据
|
// 获取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
|
do
|
||||||
{
|
{
|
||||||
|
@ -91,8 +91,8 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
|
|||||||
* Type==8:PPS frame
|
* Type==8:PPS frame
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const uint8_t *frame = (uint8_t *) rtppack->payload + rtppack->offset;
|
const uint8_t *frame = (uint8_t *) rtppack->data() + rtppack->offset;
|
||||||
int length = rtppack->length - rtppack->offset;
|
int length = rtppack->size() - rtppack->offset;
|
||||||
NALU nal;
|
NALU nal;
|
||||||
MakeNalu(*frame, nal);
|
MakeNalu(*frame, nal);
|
||||||
|
|
||||||
|
@ -82,8 +82,8 @@ bool H265RtpDecoder::inputRtp(const RtpPacket::Ptr &rtp, bool key_pos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool H265RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
|
bool H265RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
|
||||||
const uint8_t *frame = (uint8_t *) rtppack->payload + rtppack->offset;
|
const uint8_t *frame = (uint8_t *) rtppack->data() + rtppack->offset;
|
||||||
int length = rtppack->length - rtppack->offset;
|
int length = rtppack->size() - rtppack->offset;
|
||||||
int nal = H265_TYPE(frame[0]);
|
int nal = H265_TYPE(frame[0]);
|
||||||
|
|
||||||
if (nal > 50){
|
if (nal > 50){
|
||||||
|
@ -35,7 +35,10 @@ RtpPacket::Ptr RtpInfo::makeRtp(TrackType type, const void* data, unsigned int l
|
|||||||
uint32_t sc = htonl(_ui32Ssrc);
|
uint32_t sc = htonl(_ui32Ssrc);
|
||||||
|
|
||||||
auto rtppkt = ResourcePoolHelper<RtpPacket>::obtainObj();
|
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[0] = '$';
|
||||||
pucRtp[1] = _ui8Interleaved;
|
pucRtp[1] = _ui8Interleaved;
|
||||||
pucRtp[2] = ui16RtpLen >> 8;
|
pucRtp[2] = ui16RtpLen >> 8;
|
||||||
@ -52,7 +55,6 @@ RtpPacket::Ptr RtpInfo::makeRtp(TrackType type, const void* data, unsigned int l
|
|||||||
rtppkt->PT = _ui8PlayloadType;
|
rtppkt->PT = _ui8PlayloadType;
|
||||||
rtppkt->interleaved = _ui8Interleaved;
|
rtppkt->interleaved = _ui8Interleaved;
|
||||||
rtppkt->mark = mark;
|
rtppkt->mark = mark;
|
||||||
rtppkt->length = len + 16;
|
|
||||||
rtppkt->sequence = _ui16Sequence;
|
rtppkt->sequence = _ui16Sequence;
|
||||||
rtppkt->timeStamp = uiStamp;
|
rtppkt->timeStamp = uiStamp;
|
||||||
rtppkt->ssrc = _ui32Ssrc;
|
rtppkt->ssrc = _ui32Ssrc;
|
||||||
|
@ -35,27 +35,18 @@ using namespace toolkit;
|
|||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
class RtpPacket : public Buffer{
|
class RtpPacket : public BufferRaw{
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<RtpPacket> Ptr;
|
typedef std::shared_ptr<RtpPacket> Ptr;
|
||||||
uint8_t interleaved;
|
uint8_t interleaved;
|
||||||
uint8_t PT;
|
uint8_t PT;
|
||||||
bool mark;
|
bool mark;
|
||||||
uint32_t length;
|
|
||||||
//时间戳,单位毫秒
|
//时间戳,单位毫秒
|
||||||
uint32_t timeStamp;
|
uint32_t timeStamp;
|
||||||
uint16_t sequence;
|
uint16_t sequence;
|
||||||
uint32_t ssrc;
|
uint32_t ssrc;
|
||||||
uint8_t payload[1604];
|
|
||||||
uint8_t offset;
|
uint8_t offset;
|
||||||
TrackType type;
|
TrackType type;
|
||||||
|
|
||||||
char *data() const override {
|
|
||||||
return (char *)payload;
|
|
||||||
}
|
|
||||||
uint32_t size() const override {
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RtpRingInterface {
|
class RtpRingInterface {
|
||||||
|
Loading…
Reference in New Issue
Block a user