修复rtp不支持csrc、ext字段的bug

This commit is contained in:
xiongziliang 2018-07-30 11:58:39 +08:00
parent efdc740fb4
commit 3a5bf616ff
6 changed files with 42 additions and 19 deletions

View File

@ -91,7 +91,7 @@ inline void RtpMaker_AAC::makeAACRtp(const void *pData, unsigned int uiLen, bool
rtppkt.timeStamp = m_ui32TimeStamp;
rtppkt.ssrc = m_ui32Ssrc;
rtppkt.type = TrackAudio;
rtppkt.offset = 16;
memcpy(rtppkt.payload + 16, pData, uiLen);
onMakeRtp(pRtppkt, false);
m_ui16Sequence++;

View File

@ -108,8 +108,9 @@ inline void RtpMaker_H264::makeH264Rtp(const void* data, unsigned int len, bool
rtppkt.timeStamp = m_ui32TimeStamp;
rtppkt.ssrc = m_ui32Ssrc;
rtppkt.type = TrackVideo;
uint8_t type = ((uint8_t *) (data))[0] & 0x1F;
rtppkt.offset = 16;
memcpy(rtppkt.payload + 16, data, len);
uint8_t type = ((uint8_t *) (data))[0] & 0x1F;
onMakeRtp(pRtppkt, type == 5);
m_ui16Sequence++;
//InfoL<<timeStamp<<" "<<time<<" "<<sampleRate;

View File

@ -111,18 +111,18 @@ bool RtpParser::inputRtp(const RtpPacket& rtp) {
inline bool RtpParser::inputVideo(const RtpPacket& rtppack,
const RtspTrack& track) {
const char *frame = (char *) rtppack.payload + 16;
int length = rtppack.length - 16;
const uint8_t *frame = (uint8_t *) rtppack.payload + rtppack.offset;
int length = rtppack.length - rtppack.offset;
NALU nal;
MakeNalu(*frame, nal);
//Type==1:P frame
//Type==6:SEI frame
//Type==7:SPS frame
//Type==8:PPS frame
if (nal.type > 0 && nal.type < 24) {
if (nal.type >= 0 && nal.type < 24) {
//a full frame
m_h264frame.data.assign("\x0\x0\x0\x1", 4);
m_h264frame.data.append(frame, length);
m_h264frame.data.append((char *)frame, length);
m_h264frame.type = nal.type;
m_h264frame.timeStamp = rtppack.timeStamp / 90;
m_h264frame.sequence = rtppack.sequence;
@ -139,7 +139,7 @@ inline bool RtpParser::inputVideo(const RtpPacket& rtppack,
char tmp = (nal.forbidden_zero_bit << 7 | nal.nal_ref_idc << 5 | fu.type);
m_h264frame.data.assign("\x0\x0\x0\x1", 4);
m_h264frame.data.push_back(tmp);
m_h264frame.data.append(frame + 2, length - 2);
m_h264frame.data.append((char *)frame + 2, length - 2);
m_h264frame.type = fu.type;
m_h264frame.timeStamp = rtppack.timeStamp / 90;
m_h264frame.sequence = rtppack.sequence;
@ -154,17 +154,17 @@ inline bool RtpParser::inputVideo(const RtpPacket& rtppack,
m_h264frame.sequence = rtppack.sequence;
if (fu.E == 1) {
//FU-A end
m_h264frame.data.append(frame + 2, length - 2);
m_h264frame.data.append((char *)frame + 2, length - 2);
m_h264frame.timeStamp = rtppack.timeStamp / 90;
_onGetH264(m_h264frame);
m_h264frame.data.clear();
return false;
}
//FU-A mid
m_h264frame.data.append(frame + 2, length - 2);
m_h264frame.data.append((char *)frame + 2, length - 2);
return false;
}
WarnL << nal.type;
WarnL << nal.type << " " << rtppack.sequence;
return false;
// 29 FU-B 单NAL单元B模式
// 24 STAP-A 单一时间的组合包
@ -239,8 +239,8 @@ inline void RtpParser::onGetVideoTrack(const RtspTrack& video) {
inline bool RtpParser::inputAudio(const RtpPacket& rtppack,
const RtspTrack& track) {
char *frame = (char *) rtppack.payload + 16;
int length = rtppack.length - 16;
char *frame = (char *) rtppack.payload + rtppack.offset;
int length = rtppack.length - rtppack.offset;
if (m_adts.aac_frame_length + length - 4 > sizeof(AdtsFrame::data)) {
m_adts.aac_frame_length = 7;
@ -271,9 +271,8 @@ inline void RtpParser::_onGetH264(H264Frame& frame) {
insertedFrame.timeStamp = frame.timeStamp;
insertedFrame.data = m_strPPS;
onGetH264(insertedFrame);
}
case 1: //P
onGetH264(frame);
}
break;
case 7: {//SPS
m_strSPS = frame.data;
@ -284,8 +283,10 @@ inline void RtpParser::_onGetH264(H264Frame& frame) {
}
break;
case 8://PPS
m_strPPS=frame.data;break;
m_strPPS=frame.data;
break;
default:
onGetH264(frame);
break;
}
}

View File

@ -99,7 +99,7 @@ int parserSDP(const string& sdp, RtspTrack Track[2]) {
// parserSDP(str,track);
// track[0].inited=true;
//});
bool MakeNalu(char in, NALU &nal) {
bool MakeNalu(uint8_t in, NALU &nal) {
nal.forbidden_zero_bit = in >> 7;
if (nal.forbidden_zero_bit) {
return false;
@ -108,7 +108,7 @@ bool MakeNalu(char in, NALU &nal) {
nal.type = in & 0x1f;
return true;
}
bool MakeFU(char in, FU &fu) {
bool MakeFU(uint8_t in, FU &fu) {
fu.S = in >> 7;
fu.E = (in >> 6) & 0x01;
fu.R = (in >> 5) & 0x01;

View File

@ -64,6 +64,7 @@ public:
uint16_t sequence;
uint32_t ssrc;
uint8_t payload[1560];
uint8_t offset;
TrackType type;
};
@ -211,8 +212,8 @@ typedef struct {
unsigned type :5;
} FU;
bool MakeNalu(char in, NALU &nal) ;
bool MakeFU(char in, FU &fu) ;
bool MakeNalu(uint8_t in, NALU &nal) ;
bool MakeFU(uint8_t in, FU &fu) ;
#endif //RTSP_RTSP_H_

View File

@ -583,6 +583,12 @@ void RtspPlayer::splitRtp(unsigned char* pucRtp, unsigned int uiLen) {
}
}
# define AV_RB16(x) \
((((const uint8_t*)(x))[0] << 8) | \
((const uint8_t*)(x))[1])
bool RtspPlayer::handleOneRtp(int iTrackidx, unsigned char *pucData, unsigned int uiLen) {
auto &track = m_aTrackInfo[iTrackidx];
auto pt_ptr=m_pktPool.obtain();
@ -620,6 +626,20 @@ bool RtspPlayer::handleOneRtp(int iTrackidx, unsigned char *pucData, unsigned in
rtppt.payload[1] = rtppt.interleaved;
rtppt.payload[2] = (uiLen & 0xFF00) >> 8;
rtppt.payload[3] = (uiLen & 0x00FF);
rtppt.offset = 16;
int csrc = pucData[0] & 0x0f;
int ext = pucData[0] & 0x10;
rtppt.offset += 4 * csrc;
if (ext) {
if(uiLen < rtppt.offset){
return false;
}
/* calculate the header extension length (stored as number of 32-bit words) */
ext = (AV_RB16(pucData + rtppt.offset - 2) + 1) << 2;
rtppt.offset += ext;
}
memcpy(rtppt.payload + 4, pucData, uiLen);
/////////////////////////////////RTP排序逻辑///////////////////////////////////