jrtplib传输:请问各位高手,我想将下面的程序改成在vc下能运行的,需要怎么修改,不胜感激!!望有成功者留一个联系方式给我,我做毕设,想请教一下!不胜感激!
来源:互联网 发布:mac退出百度云同步盘 编辑:程序博客网 时间:2024/05/02 02:30
//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;
}
- jrtplib传输:请问各位高手,我想将下面的程序改成在vc下能运行的,需要怎么修改,不胜感激!!望有成功者留一个联系方式给我,我做毕设,想请教一下!不胜感激!
- 各位高手帮忙看一下我的电脑配置单,请大虾多提建议,小弟不胜感激!
- 我的vc6.0怎么不能运行内联汇编呢!谁能帮我解释一下,不胜感激。
- 有谁能给我讲一下网页制作中的字体和字号的概念啊????不胜感激
- 为什么总抛出空指针异常,请各位大师帮我改进一下,我将不胜感激
- 请内行人给指点一下,不胜感激
- 哪位高手帮我制作一下以下代码 在下不胜感激 跪求
- 公司突然要进行考试,给了java样例试题,我一道都不会,我平时只写jsp页面的,恳请高人帮忙一下,不胜感激!
- 想学手机网站和应用程序设计开发,希望您能给我指点指点,不胜感激
- java 请JAVA高手回答一下小弟这个简单的问题 不胜感激啊
- java的设计模式那位兄弟有心得给共享一下! 不胜感激!!
- 在DLL中启动模态对话框时的错误,请高手帮忙 -- 不胜感激
- 想写个net+AJAX的省、市、县 下拉框级联..有这方面资源的请让我参考下..不胜感激!(百度的都差强人意)
- 题目遇到问题,有高手解决,不胜感激!
- 急急急!!!!!!!!!!帮助我拿下意见,不胜感激!
- birt报表中设置数据集sql的问题,希望有人帮我解决这个疑问,不胜感激!
- 我在学JAVA struts 和 hibernate 和 spring 框架集成,现在刚刚开启TOMCAT就报错?求各位大大帮忙解决下,不胜感激。
- 请大牛指出这段js代码的可读性到底差在哪里。不胜感激
- #error WINDOWS.H already included. MFC apps must not #include
- 在ARM-Linux平台上移植SQLite(下)
- 2010十大移动趋势(1/3):开发设计篇
- 2010十大移动趋势(2/3):应用篇
- ASP.NET页面揭秘(二)
- jrtplib传输:请问各位高手,我想将下面的程序改成在vc下能运行的,需要怎么修改,不胜感激!!望有成功者留一个联系方式给我,我做毕设,想请教一下!不胜感激!
- 用选择法对10个整数由大到小排列
- 2010十大移动趋势(3//3):新兴市场篇
- FORALL与BULK COLLECT的使用方法:
- bat之for循环
- CGI之C语言篇
- Foj 1649 Prime number or not
- FindControl的几种用法(zzfrom:http://hi.baidu.com/stylelee/blog/item/290817a774160396d1435831.html)
- 轻量级 Web 服务器(转)