场景
接收到的数据无法进行分析出H265码流格式,通过抓包是发现有视频数据发送过来
排查
1 怀疑缓存不够大
SetRTPReceiveBuffer(1024 * 1024 * 12)
2 查看RTP包格式
std::cout << "是否有扩展:" << pack->HasExtension() << std::endl;
std::cout << "是否有扩展:" << pack->GetExtensionLength() << std::endl;
std::cout << "负载类型:" << pack->GetPayloadType() << std::endl;
3 强制打印RTP负载内容
std::cout << "查看数据:" << std::endl;
uint8_t* pPayloadBuffer = pack->GetPayloadData();
int i = 0;
//2强制转换符号char为无符号char打印
while (i < 45)
{
printf(" %02x", (unsigned char)pPayloadBuffer[i]);
i++;
}
数据打印如下:
ff ff fe ff ff fe ff ff ff ff ff ff ff ff fe
4 抓包过滤数据
过滤条件:udp contains ff:ff:fe:ff:ff:fe
最终确认接收到的是音频数据
5发现问题根源
接收视频的端口错误传递了音频的端口,导致接收到的是音频数据,所以解析不出来H265码流
设置接收代码
session_params.SetReceiveMode(RTPTransmitter::ReceiveMode::AcceptAll);
session_params.SetOwnTimestampUnit(1 / 90000);
session_params.SetAcceptOwnPackets(true);
session_params.SetUsePollThread(true);
trans_params.SetPortbase(rtp_port);
trans_params.SetBindIP(ntohl(inet_addr(addr_mine.c_str())));
trans_params.SetRTPReceiveBuffer(1024 * 1024 * 3);
int e = session.Create(session_params, &trans_params);
循环接收处理代码
while (!m_Exit)
{
bool is_data_available = false;
RTPTime delay(0.100);
session.WaitForIncomingData(delay, &is_data_available);
if (is_data_available)
{
session.Poll();
session.BeginDataAccess();
if (session.GotoFirstSourceWithData())
{
do
{
RTPPacket * pkt = NULL;
while ((pkt = session.GetNextPacket()) != NULL)
{
if (!isRecvPacket)
{
std::stringstream ss;
ss << "接收到第一个RTP数据包,接收端口:" << m_UdpPort;
isRecvPacket = true;
}
std::uint32_t id = pkt->GetSSRC();
if (ssrc == INVALID_SSRC)
{
ssrc = id;
}
// 如果不是同一份流就忽略
if (ssrc != INVALID_SSRC && ssrc != id)
{
session.DeletePacket(pkt);
continue;
}
if (seq != seq_num + 1 && !seq_num)
{
std::stringstream ss;
ss << "出现RTP丢包情况,当前接收RTP序号:" << seq << ",上一个RTP序号:" << seq_num << std::endl;;
DebugView(ss.str());
}
seq_num = seq;
auto data = pkt->GetPayloadData();
auto size = pkt->GetPayloadLength();
auto type = pkt->GetPayloadType();
session.DeletePacket(pkt);
}
} while (session.GotoNextSourceWithData());
}
session.EndDataAccess();
}
}
session.Destroy();