当前位置: 技术问答>linux和unix
linux 下jrtplib的几个问题
来源: 互联网 发布时间:2016-08-08
本文导语: 本帖最后由 lxq00 于 2010-03-04 16:06:17 编辑 最近做视频流的传输 采用了开源的jrtplib 库 在做的过程中 出现了一个问题 由于视频流比较的大,不断的在发,我每次读取20k的流然后分成1k都的一块一块的网络发送 可是...
在做的过程中 出现了一个问题
由于视频流比较的大,不断的在发,我每次读取20k的流然后分成1k都的一块一块的网络发送
可是如果网络发送的过程中 不暂停一下,接收的时候只能接受到最后一次的数据
具体代码附上:
int init_rtp_send(char * hostname ,int port ,SGRTP *rtp ,int multicast)
{
unsigned long destip;
int destport;
int portbase = rtp->myport;
int status;
RTPUDPv4TransmissionParams transparams;
RTPSessionParams sessparams;
RTPSession *sess = &rtp->sess;
if(hostname==NULL)
return ERROR;
printf("rtp connet %s:%d myport = %dn",hostname,port,portbase);
destip = inet_addr(hostname);
destip = ntohl(destip);
sessparams.SetOwnTimestampUnit(1.0/8000.0);
sessparams.SetAcceptOwnPackets(true);
transparams.SetPortbase(portbase);
transparams.SetMulticastTTL(255);
transparams.SetRTPSendBuffer(64*1024);
status = sess->Create(sessparams,&transparams);
if(checkerror(status))
return ERROR;
if(multicast){
if(sess->SupportsMulticasting()) {
printf("Current jrtplib support multicasting!n");
}
}
RTPIPv4Address addr(destip,port);
status = sess->AddDestination(addr);
if(checkerror(status))
return ERROR;
// 设置RTP会话默认参数
sess->SetDefaultPayloadType(0);
sess->SetDefaultMark(false);
sess->SetDefaultTimestampIncrement(10);
set_crmode(1);
return SUCCESS;
}
int rtp_send_date(char * str,int len,SGRTP *rtp )
{
int status;
RTPSession *sess = &rtp->sess;
status = sess->SendPacket((void *)str,len);
// status = sess->SendPacket((void *)str,len,0,false,len);
if(checkerror(status))
return ERROR;
// status = sess->Poll();
// if(checkerror(status))
// return ERROR;
// RTPTime::Wait(RTPTime(0,100));
return len;
}
int init_rtp_recv(char * hostname ,int port ,SGRTP *rtp ,int multicast)
{
int status;
int multicastip;
uint16_t localport;
RTPUDPv4TransmissionParams transparams;
RTPSessionParams sessparams;
RTPSession *sess = &rtp->sess;
sessparams.SetOwnTimestampUnit(1.0/8000.0);
sessparams.SetAcceptOwnPackets(true);
transparams.SetPortbase(port);
transparams.SetRTPReceiveBuffer(64*1024);
status = sess->Create(sessparams,&transparams);
printf("recv hostname = %s port = %d myport = %dn",hostname,port,rtp->myport);
if(checkerror(status))
return ERROR;
if(multicast)
{
multicastip = ntohl(inet_addr(hostname));
printf("hostname = %s multicastip = %d hton = %dn",hostname,multicastip,htonl(multicastip));
RTPIPv4Address addr(multicastip, port);
status = sess->JoinMulticastGroup(addr);
if(checkerror(status))
return ERROR;
}
return SUCCESS;
}
int rtp_recv_date(char *buf,SGRTP *rtp )
{
RTPPacket *pack;
uint32_t packetLen;
uint8_t *packetData;
uint8_t j = 11;
int len = 0;
int status;
RTPSession *sess = &rtp->sess;
sess->BeginDataAccess();
if (sess->GotoFirstSourceWithData()){
do {
while ((pack = sess->GetNextPacket()) != NULL)
{
packetLen = pack->GetPacketLength() - 1;
packetData = pack->GetPacketData();
len = packetLen -j;
memcpy(buf,packetData+12,len);
sess->DeletePacket(pack);
}
} while (sess->GotoNextSourceWithData());
}
sess->EndDataAccess();
status = sess->Poll();
// if(checkerror(status))
// return ERROR;
return len;
}
int send_video(char * buf,int len,NETVIDEOURL *node,int board_num)
{
int Max_Udp_Mtu = (netvoid_codec->cfg_parser[board_num]->MTU_size > 60*1024)?
60*1024:netvoid_codec->cfg_parser[board_num]->MTU_size;
char * p_buf = buf;
int file_bytes = len;
int sendlen , num_bytes;
if(!node->IsInit)
return FALSE;
while(file_bytes >0){
if(file_bytes > Max_Udp_Mtu)
sendlen = Max_Udp_Mtu;
else
sendlen = file_bytes;
if(node->nettype == UDP)
num_bytes = udp_send_data(p_buf,sendlen,&node->netsock);
else if(node->nettype == RTP)
{
num_bytes = rtp_send_date((char *)p_buf,sendlen, &node->rtpsock);
//在这必须要停一下
// usleep(1/1000);
}
else
break;
if(num_bytes > 0){
file_bytes -= sendlen;
p_buf += sendlen;
}else
break;
}
return TRUE;
}
int recv_video(char * buf,NETVIDEOURL *node,int board_num)
{
int recvsize;
int timeout = 0;
char *p_buf = buf;
char *p;
if(!node->IsInit)
return FALSE;
while(1){
if(node->nettype == UDP){
recvsize = udp_recv_data((char *)p_buf,MAX_UDP_RECV_SIZE,&node->netsock);
}else if(node->nettype == RTP){
recvsize = rtp_recv_date((char *)p_buf,&node->rtpsock);
}else if(node->nettype == TCP){
recvsize = tftp_recv_data((char *)p_buf,MAX_TCP_RECV_SIZE,node->netsock.sock_fd);
}
if(recvsize= 100)
break;
nap(1/1000);
}else{
No_Video_Times[board_num] = 0;
if(Is_PS_Osd_Stream(p_buf)){
/*这是PS 流的osd*/
p = p_buf + 14;
memcpy(&disp_osd_pack[board_num],p,recvsize-14);
}else if(Is_TS_Osd_Stream(p_buf)){
/*这是TS 流 的osd*/
p = p_buf + 10;
memcpy(&disp_osd_pack[board_num],p,recvsize-10);
}else
break;
}
}
//如果上面那不停 每次发只能收到最后的一条
printf("recvsize = %dn",recvsize);
return recvsize;
}
请使用过jrtplib 的兄弟朋友看看,看看应该怎么修改 谢谢
|
你就做个实验,发送两个包,即只调用两次rtp_send_date((char *)p_buf,sendlen, &node->rtpsock);
看能否正确收到。
另外netvoid_codec->cfg_parser[board_num]->MTU_size的值为多少啊?
看能否正确收到。
另外netvoid_codec->cfg_parser[board_num]->MTU_size的值为多少啊?
|
自己解决了是最好的结果呀!
|
没有使用过 可不可以只帮顶?
|
一般看到代码都比较头痛。
没使用过的漂过………………
没使用过的漂过………………