資源簡(jiǎn)介
linux 使用jrtplib收發(fā)h.264視頻文件 詳細(xì)內(nèi)容見博客:http://blog.csdn.net/li_wen01/article/details/70435005

代碼片段和文件信息
/*=============================================================================??
?*?????FileName:?receive.cpp??
?*?????????Desc:?reveive?h.264?from?RTP?server?
?*???????Author:?licaibiao??
?*???LastChange:?2017-04-22??
?*?=============================================================================*/
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
using?namespace?jrtplib;
void?checkerror(int?rtperr)
{
if?(rtperr?0)
{
std::cout?<“ERROR:?“?< exit(-1);
}
}
int?main(void)
{
RTPSession?sess;
uint16_t?portbase?=?6664;
int?status;
bool?done?=?false;
RTPUDPv4TransmissionParams?transparams;
RTPSessionParams?sessparams;
sessparams.SetOwnTimestampUnit(1.0/10.0);
sessparams.SetAcceptOwnPackets(true);
transparams.SetPortbase(portbase);
status?=?sess.Create(sessparams&transparams);
checkerror(status);
sess.BeginDataAccess();
RTPTime?delay(0.001);
RTPTime?starttime?=?RTPTime::CurrentTime();
FILE?*fd;
size_t?len;
uint8_t?*loaddata;
RTPPacket?*pack;
uint8_t?buff[1024*100]?=?{0};
int?pos?=?0;
fd?=?fopen(“./test_recv.h264““wb+“);
while?(!done)
{
status?=?sess.Poll();
checkerror(status);
if?(sess.GotoFirstSourceWithData())
{
do
{
while?((pack?=?sess.GetNextPacket())?!=?NULL)
{
loaddata?=?pack->GetPayloadData();
len ?=?pack->GetPayloadLength();
if(pack->GetPayloadType()?==?96)?//H264
{
if(pack->HasMarker())?//?the?last?packet
{
memcpy(&buff[pos]loaddatalen);
fwrite(buff?1?pos+len?fd);
pos?=?0;
}
else
{
memcpy(&buff[pos]loaddatalen);
pos?=?pos?+?len;
}
}else
{
printf(“!!!??GetPayloadType?=?%d?!!!!?\n?“pack->GetPayloadType());
}
sess.DeletePacket(pack);
}
}?while?(sess.GotoNextSourceWithData());
}
RTPTime::Wait(delay);
RTPTime?t?=?RTPTime::CurrentTime();
t?-=?starttime;
if?(t?>?RTPTime(40.0))
done?=?true;
}
fclose(fd);
sess.EndDataAccess();
delay?=?RTPTime(10.0);
sess.BYEDestroy(delay00);
????
return?0;
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????122??2017-04-21?20:39??jrtplib_send_recv_h264\Makefile
?????文件???????2396??2017-04-22?14:52??jrtplib_send_recv_h264\receive.cpp
?????文件???????6023??2017-04-22?11:49??jrtplib_send_recv_h264\sender.cpp
?????文件????2263679??2015-07-03?01:36??jrtplib_send_recv_h264\test.h264
?????目錄??????????0??2017-04-22?15:16??jrtplib_send_recv_h264
-----------?---------??----------?-----??----
??????????????2272220????????????????????5
評(píng)論
共有 條評(píng)論