关于JRTPLIB接收的问题

咋了啦 2007-07-10 12:42:02
我今天调试了JRTPLIB3.71中的sample1,可我发现接收不到数据.
不知道为什么?那位给点建议,我把代码贴出来。
/*
Here's a small IPv4 example: it asks for a portbase and a destination and
starts sending packets to that destination.
*/

#include "rtpsession.h"
#include "rtppacket.h"
#include "rtpudpv4transmitter.h"
#include "rtpipv4address.h"
#include "rtpsessionparams.h"
#include "rtperrors.h"
#ifndef WIN32
#include <netinet/in.h>
#include <arpa/inet.h>
#else
#include <winsock2.h>
#endif // WIN32
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>

//
// This function checks if there was a RTP error. If so, it displays an error
// message and exists.
//

void checkerror(int rtperr)
{
if (rtperr < 0)
{
std::cout << "ERROR: " << RTPGetErrorString(rtperr) <<std::endl;
exit(-1);
}
}

//
// The main routine
//

int main(void)
{
#ifdef WIN32
WSADATA dat;
WSAStartup(MAKEWORD(2,2),&dat);
#endif // WIN32

RTPSession sess;
uint16_t portbase,destport;
uint32_t destip;
std::string ipstr;
int status,i,num;

// First, we'll ask for the necessary information

std::cout << "Enter local portbase:" << std::endl;
std::cin >> portbase;
std::cout << std::endl;
std::cout << "Enter the destination IP address" << std::endl;
std::cin >> ipstr;
destip = inet_addr(ipstr.c_str());
if (destip == INADDR_NONE)
{
std::cerr << "Bad IP address specified" << std::endl;
return -1;
}

// The inet_addr function returns a value in network byte order, but
// we need the IP address in host byte order, so we use a call toz
// ntohl
destip = ntohl(destip);

std::cout << "Enter the destination port" << std::endl;
std::cin >> destport;

std::cout << std::endl;
std::cout << "Number of packets you wish to be sent:" <<std::endl;
std::cin >> num;

// Now, we'll create a RTP session, set the destination, send some
// packets and poll for incoming data.

RTPUDPv4TransmissionParams transparams;
RTPSessionParams sessparams;

// IMPORTANT: The local timestamp unit MUST be set, otherwise
//RTCP Sender Report info will be calculated wrong
// In this case, we'll be sending 10 samples each second, so we'll
// put the timestamp unit to (1.0/10.0)

sessparams.SetOwnTimestampUnit(1.0/10.0);

sessparams.SetAcceptOwnPackets(true);
transparams.SetPortbase(portbase);
status = sess.Create(sessparams,&transparams);
checkerror(status);

RTPIPv4Address addr(destip,destport);

status = sess.AddDestination(addr);
checkerror(status);

for (i = 1 ; i <= num ; i++)
{
printf("\nSending packet %d/%d\n",i,num);

// send the packet
status = sess.SendPacket((void *)"1234567890",10,0,false,10);
checkerror(status);

sess.BeginDataAccess();

// check incoming packets
if (sess.GotoFirstSourceWithData())
{
do
{
RTPPacket *pack;

while ((pack = sess.GetNextPacket()) != NULL)
{
// You can examine the data here
printf("Got packet !\n");

// we don't longer need the packet, so
// we'll delete it

sess.DeletePacket(pack);
}
} while (sess.GotoNextSourceWithData());
}
sess.EndDataAccess();

#ifndef RTP_SUPPORT_THREAD
status = sess.Poll();
checkerror(status);
#endif // RTP_SUPPORT_THREAD

RTPTime::Wait(RTPTime(1,0));
}

sess.BYEDestroy(RTPTime(10,0),0,0);

#ifdef WIN32
WSACleanup();
#endif // WIN32
return 0;
}

...全文
463 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhxhz 2008-02-24
  • 打赏
  • 举报
回复
Enter lical portbase:
7000

Enter the destination IP address
127.0.0.1 (改成本机的IP 192.168.1.2结果也一样)
Enter the destination port
7002 ///此处应输入为7000而不是7002
panther124 2007-07-26
  • 打赏
  • 举报
回复
我的输入是这样的:哪里出错了,哪位大侠出来指教下,谢谢了。
Enter lical portbase:
7000

Enter the destination IP address
127.0.0.1 (改成本机的IP 192.168.1.2结果也一样)
Enter the destination port
7002

Number of packets you wish to be sent:
4

Sending pecket 1/4

Sending pecket 1/4

Sending pecket 1/4

Sending pecket 1/4
咋了啦 2007-07-19
  • 打赏
  • 举报
回复
呵呵~~~~~~~~
不好意思,是我对他的理解有点问题,在输入的时候弄错 了,现在好了。不过还是谢谢大家的回帖啊
zhaowing 2007-07-18
  • 打赏
  • 举报
回复
应该不是程序的是,看看别的地方吧,环境什么的。
rocker9527 2007-07-12
  • 打赏
  • 举报
回复
这个例子是可以的啊

2,543

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧