jrtplib传输:请问各位高手,我想将下面的程序改成在vc下能运行的,需要怎么修改,不胜感激!!望有成功者留一个联系方式给我,我做毕设,想请教一下!不胜感激!
//JRTPLIB sender on ADSP-BF537
//wangsu820@163.com 2008-06-30
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <iostream>
#include <sys/socket.h>
#include "rtpsession.h"
#include "rtpsessionparams.h"
#include "rtpudpv4transmitter.h"
#include "rtpipv4address.h"
#include "rtperrors.h"
using namespace std;
//调试信息功能
#define DEBUG
void checkerror( int errorcode )
{
if( errorcode < 0 )
{
std::cout<< "ERROR:" << RTPGetErrorString( errorcode ) << std::endl;
exit( -1 );
}
}
void usage( void )
{
std::cout << "Usage: ./bf537_send DestinationIPAddress DestinationPort FilePath" << std::endl;
}
long getfilelen( FILE *fp )
{
long cur_pos;
long len;
if( NULL == fp )
{
printf( "FILE fp is NULL/n" );
exit(-1);
}
cur_pos = ftell( fp );
fseek( fp, 0, SEEK_END );
len = ftell( fp );
fseek( fp, cur_pos, SEEK_SET );
return len;
}
int main( int argc, char **argv )
{
RTPSession rtpsess;
RTPSessionParams sessionparams;
RTPUDPv4TransmissionParams transparams;
unsigned long destip;
int destport, srcport = 8000;
char *filepath;
FILE *fp;
long filelength, templength, maxpacket, sendsize;
unsigned char *mem;
int status;
//命令行参数解析
if( argc != 4 )
{
usage();
return -1;
}
destip = inet_addr( argv[1] );
if( INADDR_NONE == destip )
{
cerr << "Bad IP Address" << endl;
return -1;
}
destip = ntohl( destip );
cout << "Destination IP Address:"
<< argv[1]
<< endl;
destport = atoi( argv[2] );
cout << "Destination Port:"
<< destport
<< endl;
strcpy( filepath, argv[3] );
cout << "FilePath:"
<< filepath
<< endl;
//创建会话
sessionparams.SetOwnTimestampUnit( 1.0 / 8000.0 );
transparams.SetPortbase( srcport );
status = rtpsess.Create( sessionparams, &transparams );
#ifdef DEBUG
cout << "check if Create Session error" << endl;
#endif
checkerror( status );
//将目标地址添加到发送地址列表中
RTPIPv4Address addr( destip, destport );
status = rtpsess.AddDestination( addr );
#ifdef DEBUG
cout << "check if AddDestination error" << endl;
#endif
checkerror( status );
//设置RTP包的默认参数
rtpsess.SetDefaultPayloadType( 0 );
rtpsess.SetDefaultMark( false );
rtpsess.SetDefaultTimestampIncrement( 10 );
//打开文件
fp = fopen( filepath, "rb" );
if( NULL == fp )
{
perror( "fopen:" );
exit(-1);
}
//获取文件大小
filelength = getfilelen( fp );
#ifdef DEBUG
printf( "the size of %s is %ldKB/n", filepath, (filelength / 1024) );
#endif
//获取所允许的最大包的大小
maxpacket = sessionparams.GetMaximumPacketSize();
#ifdef DEBUG
printf( "maximum packet size is %ldKB/n", (maxpacket / 1024) );
#endif
maxpacket -= 12;
#ifdef DEBUG
printf( "maximum payload size per packet is %ldKB(%ldB)/n", (maxpacket / 1024), maxpacket );
#endif
//分配内存空间,存放整个文件
mem = (unsigned char *)malloc( filelength );
#ifdef DEBUG
printf( "memory buffer is 0x%8x/n", (int)mem );
#endif
//读取文件内容到内存
templength = fread( mem, 1, filelength, fp );
if( templength != filelength )
{
printf( "fread error: templength=%ld, filelength=%ld/n", templength, filelength );
exit(-1);
}
#ifdef DEBUG
printf( "Have fread %ldKB/n", (templength / 1024) );
#endif
//关闭文件
fclose( fp );
sendsize = filelength;
//发送文件
if( filelength <= maxpacket )
{
#ifdef DEBUG
printf( "we will send data in a single packet/n" );
#endif
status = rtpsess.SendPacket( mem, filelength );
checkerror( status );
printf( "Sent %s...[%ldKB/%ldKB]", filepath, (filelength / 1024), (filelength / 1024) );
}
else//filelength > maxpacket文件大于最大包大小,须分包发送
{
#ifdef DEBUG
printf( "we will divide data into serval packets to send/n" );
#endif
while(1)
{
if( sendsize <= maxpacket )
{
status = rtpsess.SendPacket( mem, sendsize );
checkerror( status );
printf( "Sent %s...[%ldKB/%ldKB]/n", filepath,
(filelength / 1024), (filelength / 1024) );
break;
}
status = rtpsess.SendPacket( (void *)mem, maxpacket );
checkerror( status );
sendsize -= maxpacket;
printf( "Sent %s...[%ldKB/%ldKB]/n", filepath,
((filelength - sendsize) / 1024), (filelength / 1024) );
mem += maxpacket;
RTPTime::Wait( RTPTime( 0, 200 ) );
}
}
//离开会话
rtpsess.BYEDestroy( RTPTime( 10, 0 ), 0, 0 );
#ifdef DEBUG
cout << "GoodBye RTP Session" << endl;
#endif
return 0;
}
- 点赞
- 收藏
- 分享
- 文章举报
- 运行一个EXE文件时,出现下面的文字,但程序能正常跑,请问怎么查找哪地方出现内存溢出?
- C primer plus 第七章 练习8:修改练习7,假设a,使程序提供一个选择工资等级的菜单,用switch选择工资等级,程序运行的开头应该像下面这样:
- 请教各位C/VC高手一个极其郁闷的问题
- 编写一个C语言语句,要求输出这个程序需要运行的时间(用clock()做) 该怎么写?
- C++实现线程同步的几种方式 线程同步是指同一进程中的多个线程互相协调工作从而达到一致性。之所以需要线程同步,是因为多个线程同时对一个数据对象进行修改操作时,可能会对数据造成破坏,下面是多
- 求助求助——请教各位高手,抽出一点宝贵的时间根据这个实例讲解一下应该如何分层呢?
- VC 修改main函数名;让程序后台运行(无窗口)
- 创建一个学生系统,实现一下功能; * 1:增加学生 * 2:显示学生 * 3:修改学生 * 4:删除学生 * 5:查找学生 * 6:退出程序 * 请输入选择(
- 经过测试的 可以使用的远程注入代码!!!!!我的VC里面缺少一个stdafx.h需要拷贝一个到程序
- VC++.Net在Release方式下单步调试时需要修改一些设置,否则变量会有错位或乱码
- 一个C程序怎么就可以神奇的运行起来那?
- 请教一下各位 第一次安装mac 版的android studio 出现了一个奇怪的问题
- 这几天做一个小程序需要用到线程的暂停与恢复 ,搞来搞去用Thread.Suspend和Thread.Resume总达不到想要的结果。后来百度一下 总结写了一个方法,共享一下 ~~~~~~~~~~
- VC程序只运行一个实例,并在打开多个时激活原窗口
- VC 实现程序只运行一个实例
- 玩转VC++实现程序开机运行及注册表修改
- linux 使用非当前登录运行程序方式,如root登录用test运行一个test.sh
- 请教一下各位 第一次安装mac 版的android studio 出现了一个奇怪的问题
- VC++编译出错,错误代码:error C1189,请各位高手指点一下。
- VC防止同一个程序运行两个实例