JRtplib开发笔记(四):JRtplib的VS开发环境搭建以及Demo

原博主博客地址:https://blog.csdn.net/qq21497936本文章博客地址:https://blog.csdn.net/qq21497936/article/details/84957708《JRtplib开发笔记(一):JRtplib简介、JThread库编译》:https://blog.csdn.net/qq21497936/article/details/8478…

大家好,又见面了,我是你们的朋友全栈君。

原博主博客地址:https://blog.csdn.net/qq21497936
本文章博客地址:https://blog.csdn.net/qq21497936/article/details/84957708

JRtplib开发笔记(一):JRtplib简介、JThread库编译》: https://blog.csdn.net/qq21497936/article/details/84785284
JRtplib开发笔记(二):JRtplib库编译、示例演示》: https://blog.csdn.net/qq21497936/article/details/84785593
JRtplib开发笔记(三):JRtplib库编程使用说明》: https://blog.csdn.net/qq21497936/article/details/84957120
JRtplib开发笔记(四):JRtplib的VS开发环境搭建以及Demo》: https://blog.csdn.net/qq21497936/article/details/84957708

 

      JRtplib开发笔记(四):JRtplib的VS开发环境搭建以及Demo

 

前话

        前面介绍了JRtplib的使用,接下来介绍如何加入到工程项目中,并使用该工程项目写一个简单的使用Demo。

 

搭建JRtplib开发环境(VS2017,VC++)

        因为没有带Fec,所以传输数据还是会有丢包的情况,这点需要提醒读者,但是如果是局域网有线网络,基本可以忽略丢包的问题,但是如果是使用无线网AP那么首先AP要支持组播,其次组播丢包那是很严重的,如果传图基本是很难收完整的。

        下面介绍写了一个简单的rtp接受端和客户端,接受端只发送,客户端只接收。在使用jrtplib之前需要将其添加进工程,当前我们以VS作为IDE,写一个VC程序(使用C语言调用C++),其他IDE参考VS即可,调用外部库不外乎就是三点:

  • 引用时需要的头文件
  • 编译时需要的dll/lib/.a(此处需要dll与运行时需要的dll一样)
  • 运行时需要的dll(此处与编译时需要的dll一样)

步骤一:新建JrtplibDemo工程

        使用VS2017新建VC++空工程,移除创建的项目,然后再添加sender和recver两个项目:

        JRtplib开发笔记(四):JRtplib的VS开发环境搭建以及Demo

        JRtplib开发笔记(四):JRtplib的VS开发环境搭建以及Demo

 

        为了调试方便,我们启用多个项目调试,即运行时可设置运行调试哪些项目,如下图:

         JRtplib开发笔记(四):JRtplib的VS开发环境搭建以及Demo

        运行时,如下图:

        JRtplib开发笔记(四):JRtplib的VS开发环境搭建以及Demo

步骤二:项目引用Jrtplib头文件和库文件

        将之前的modules模块文件夹引入到工程中,

       JRtplib开发笔记(四):JRtplib的VS开发环境搭建以及Demo

        引入头文件:

       JRtplib开发笔记(四):JRtplib的VS开发环境搭建以及Demo

       引入库文件

       JRtplib开发笔记(四):JRtplib的VS开发环境搭建以及Demo

       复制库文件(运行时也需要使用库,所以需要将库dll文件复制到exe输出目录下)

       JRtplib开发笔记(四):JRtplib的VS开发环境搭建以及Demo

 

Demo演示

    可以设置时间戳,包间间隔,负载类型等等,此Demo未附带

发送端源码

#include <stdio.h>
#include <stdlib.h>

// rtp库依赖socket,必须再rtp库引入之前添加,否则会出各种错误
#include <WinSock2.h>
#pragma comment(lib, "ws2_32.lib")

// rtp库引入
#include "rtpsession.h"
#include "rtpudpv4transmitter.h"
#include "rtpipv4address.h"
#include "rtpsessionparams.h"
#include "rtperrors.h"
#pragma comment(lib, "jrtplib.lib")

using namespace jrtplib;

int main(void)
{
  RTPSession  rtpSession;
  R TPSessionParams rtpSessionParams;
  RTPUDPv4TransmissionParams rtpUdpv4Transmissionparams;

  char buf[1024] = { 0x00 };
  char ip[16] = { 0x00 };
  int port = 0;
  int ret = 0;
  
  // 容易忽略,因为自写代码中没有调用socket,rtp有调用但是没有初始化
  WSADATA dat;
  WSAStartup(MAKEWORD(2, 2), &dat);

  printf("This is sender!!!\n");

  printf("Input destination ip:");
  scanf("%s", ip);
  printf("Input destination port:");
  scanf("%d", &port);
  printf("Destination %s:%d\n", ip, port);

  rtpSessionParams.SetOwnTimestampUnit(1.0 / 1);
  rtpSessionParams.SetUsePollThread(true);
  rtpSessionParams.SetAcceptOwnPackets(false);
  ret = rtpSession.Create(rtpSessionParams, &rtpUdpv4Transmissionparams);
  if (ret < 0)
  {
    printf("Failed to RtpSession::Create, ret=%d\n", ret);
  }

  RTPIPv4Address addr(ntohl(inet_addr(ip)), port);
  rtpSession.AddDestination(addr);

  while (true)
  {
    printf("Input message:");
    scanf("%s", buf);
    if (strcmp(buf, "exit") == 0)
    {
      break;
    }
    ret = rtpSession.SendPacket((void *)buf, strlen(buf), 0, false, 1);
    if (ret < 0)
    {
      printf("Failed to RtpSession::SendPacket, ret=%d\n", ret);
      continue;
    }
    else {
      printf("Succeed to RtpSession::SendPacket!!!\n");
    }
    RTPTime::Wait(RTPTime(0, 100));
  }
  return 0;
}

接收端源码

#include <stdio.h>
#include <stdlib.h>

// rtp库依赖socket,必须再rtp库引入之前添加,否则会出各种错误
#include <WinSock2.h>
#pragma comment(lib, "ws2_32.lib")

// rtp库引入
#include "rtpsession.h"
#include "rtpudpv4transmitter.h"
#include "rtpipv4address.h"
#include "rtpsessionparams.h"
#include "rtperrors.h"
#include "rtppacket.h"
#pragma comment(lib, "jrtplib.lib")

using namespace jrtplib;

int main(void)
{
  RTPSession  rtpSession;
  RTPSessionParams rtpSessionParams;
  RTPUDPv4TransmissionParams rtpUdpv4Transmissionparams;

  char ip[16] = "127.0.0.1";
  int port = 0;
  int ret = 0;
  char buf[1024] = { 0x00 };

  // 容易忽略,因为自写代码中没有调用socket,rtp有调用但是没有初始化
  WSADATA dat;
  WSAStartup(MAKEWORD(2, 2), &dat);

  printf("This is recver!!!\n");

  printf("Input local port:");
  scanf("%d", &port);
  printf("recv %s:%d\n", ip, port);

  rtpSessionParams.SetOwnTimestampUnit(1.0 / 1);
  rtpSessionParams.SetUsePollThread(true);
  rtpSessionParams.SetAcceptOwnPackets(true);
  rtpUdpv4Transmissionparams.SetPortbase(port);
  ret = rtpSession.Create(rtpSessionParams, &rtpUdpv4Transmissionparams);
  if (ret < 0)
  {
    printf("Failed to RtpSession::Create, ret=%d\n", ret);
  }

  RTPIPv4Address addr(ntohl(inet_addr(ip)), port);
#if 0
  // 组播
  rtpSession.JoinMulticastGroup(addr);
#else
  // 本机接收,127.0.0.1
  rtpSession.AddDestination(addr);
#endif

  while (true)
  {
    rtpSession.BeginDataAccess();
    if (rtpSession.GotoFirstSourceWithData())
    {
      do {
        RTPPacket *packet;
        while ((packet = rtpSession.GetNextPacket()) != NULL)
        {
          unsigned int recvSize = packet->GetPayloadLength();
          unsigned char * recvData = (unsigned char *)packet->GetPayloadData();
          memcpy(buf, recvData, recvSize);
          buf[recvSize] = '
#include <stdio.h>
#include <stdlib.h>
// rtp库依赖socket,必须再rtp库引入之前添加,否则会出各种错误
#include <WinSock2.h>
#pragma comment(lib, "ws2_32.lib")
// rtp库引入
#include "rtpsession.h"
#include "rtpudpv4transmitter.h"
#include "rtpipv4address.h"
#include "rtpsessionparams.h"
#include "rtperrors.h"
#include "rtppacket.h"
#pragma comment(lib, "jrtplib.lib")
using namespace jrtplib;
int main(void)
{
RTPSession  rtpSession;
RTPSessionParams rtpSessionParams;
RTPUDPv4TransmissionParams rtpUdpv4Transmissionparams;
char ip[16] = "127.0.0.1";
int port = 0;
int ret = 0;
char buf[1024] = { 0x00 };
// 容易忽略,因为自写代码中没有调用socket,rtp有调用但是没有初始化
WSADATA dat;
WSAStartup(MAKEWORD(2, 2), &dat);
printf("This is recver!!!\n");
printf("Input local port:");
scanf("%d", &port);
printf("recv %s:%d\n", ip, port);
rtpSessionParams.SetOwnTimestampUnit(1.0 / 1);
rtpSessionParams.SetUsePollThread(true);
rtpSessionParams.SetAcceptOwnPackets(true);
rtpUdpv4Transmissionparams.SetPortbase(port);
ret = rtpSession.Create(rtpSessionParams, &rtpUdpv4Transmissionparams);
if (ret < 0)
{
printf("Failed to RtpSession::Create, ret=%d\n", ret);
}
RTPIPv4Address addr(ntohl(inet_addr(ip)), port);
#if 0
// 组播
rtpSession.JoinMulticastGroup(addr);
#else
// 本机接收,127.0.0.1
rtpSession.AddDestination(addr);
#endif
while (true)
{
rtpSession.BeginDataAccess();
if (rtpSession.GotoFirstSourceWithData())
{
do {
RTPPacket *packet;
while ((packet = rtpSession.GetNextPacket()) != NULL)
{
unsigned int recvSize = packet->GetPayloadLength();
unsigned char * recvData = (unsigned char *)packet->GetPayloadData();
memcpy(buf, recvData, recvSize);
buf[recvSize] = '\0';
printf("recv %d, message: %s\n", recvSize, buf);
rtpSession.DeletePacket(packet);
}
} while (rtpSession.GotoNextSourceWithData());
}
rtpSession.EndDataAccess();
RTPTime::Wait(RTPTime(0, 100));
}
return 0;
}
'; printf("recv %d, message: %s\n", recvSize, buf); rtpSession.DeletePacket(packet); } } while (rtpSession.GotoNextSourceWithData()); } rtpSession.EndDataAccess(); RTPTime::Wait(RTPTime(0, 100)); } return 0; }

运行Demo效果

         JRtplib开发笔记(四):JRtplib的VS开发环境搭建以及Demo

 

Demo下载地址

https://download.csdn.net/download/qq21497936/10843335

 

JRtplib开发笔记(一):JRtplib简介、JThread库编译》: https://blog.csdn.net/qq21497936/article/details/84785284
JRtplib开发笔记(二):JRtplib库编译、示例演示》: https://blog.csdn.net/qq21497936/article/details/84785593
JRtplib开发笔记(三):JRtplib库编程使用说明》: https://blog.csdn.net/qq21497936/article/details/84957120
JRtplib开发笔记(四):JRtplib的VS开发环境搭建以及Demo》: https://blog.csdn.net/qq21497936/article/details/84957708

 

原博主博客地址:https://blog.csdn.net/qq21497936
本文章博客地址:https://blog.csdn.net/qq21497936/article/details/84957708

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/126860.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • [bzoj3884] 上帝与集合的正确用法

    [bzoj3884] 上帝与集合的正确用法

  • 最近使用百度分享的api,引发 了一下问题,微博分享的页面跳转不成功

    最近使用百度分享的api,引发 了一下问题,微博分享的页面跳转不成功1、导致问题的原因有可能是百度分享的服务器有时候无法跳转到微博(个人分析)2、最后我的解决方式,点击事件,让浏览器直接跳转到微博分享的页面window.location.href="http://v.t.sina.com.cn/share/share.php?title=“自定义标题”&amp;pic=“自定义分享图片地址”&amp;searchPic=false"searchP…

  • 培根密码加解密_二进制密码在线解密

    培根密码加解密_二进制密码在线解密0x00介绍培根密码实际上就是一种替换密码,根据所给表一一对应转换即可加密解密它的特殊之处在于:可以通过不明显的特征来隐藏密码信息,比如大小写、正斜体等,只要两个不同的属性,密码即可隐藏0x01代码实现脚本很简单,就是建立对应关系,对密文,或者明文进行相应的替换即可需要注意的是输入的都应该是全小写字母或全大写字母,在脚本里也有说明python脚本如下:#…

    2022年10月25日
  • 回文字符串(Palindromic_String)「建议收藏」

    回文字符串(Palindromic_String)「建议收藏」一、基本概念回文字符串:是一个正读和反读都一样的字符串。二、问题与算法(1)判断思想:1、初始化标志flag=true;2、输入字符串str,并获取其长度len;3、定义并初始化游标i=0,j=len-1,分别指向字符串开头和末尾;4、比较字符str[i]和str[j],若i==j,转至7,否则往下执行5;5、若str[i]和str[j]相等…

  • scratch编程小游戏咬指大冒险

    scratch编程小游戏咬指大冒险咬指大冒险是一款非常好玩的玩具,玩法就是玩家不断按下小动物的牙齿,牙齿中只有一个是危险的,按下后小动物的嘴巴会闭上咬住手指,其余的牙齿都是安全的。今天我们就来用scratch来做一个电子版的咬指大冒险!这里我们选用一个鳄鱼的造型,首先画出鳄鱼的两个造型,一个张嘴和一个闭嘴,张嘴的造型不需要画下牙齿:要画大一点哦!程序:下面是牙齿的造型,一个有三个:牙齿的排列方式是一段弧,可以先排列好后再调整鳄鱼的嘴巴:最后是被咬时血液的程序:注意,这里的自定义模块需要勾选运行时屏幕不刷新,如果不

  • 密码学的基础知识_密码学的基本概念

    密码学的基础知识_密码学的基本概念最近在研究密码学加密,签名方面的东西。经过几天的学习对一些基础知识进行一下整理PKI:PKI是PublicKeyInfrastructure的首字母缩写,翻译过来就是公钥基础设施,在X509标准

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号