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] = '\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

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

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • apache 转发 配置_url导入配置

    apache 转发 配置_url导入配置本文主要测试通过配置Apachehttpd实现url转发,以及配置ssl协议实现支持https转发。

    2022年10月18日
    0
  • pytorch学习笔记(十):MLP[通俗易懂]

    pytorch学习笔记(十):MLP[通俗易懂]文章目录1.隐藏层2.激活函数2.1ReLU函数2.2sigmoid函数2.3tanh函数3多层感知机4.代码实现MLP4.1获取和读取数据4.2定义模型参数4.3定义激活函数4.4定义模型4.5定义损失函数4.6训练模型小结1.隐藏层多层感知机(multilayerperceptron,MLP)在单层神经网络的基础上引入了一到多个隐藏层(hiddenlayer)。隐藏层位于输入层和输出层之间。图3.3展示了一个多层感知机的神经网络图,它含有一个隐藏层,该层中有5个隐

    2022年6月16日
    30
  • header Content-Type类型

    header Content-Type类型简介:这是headerContent-Type类型的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。class='pingjiaF'frameborder=

    2022年7月2日
    20
  • 二叉树性质[通俗易懂]

    二叉树性质[通俗易懂]转载skywang12345 http://www.cnblogs.com/skywang12345/p/3576328.html树的介绍1.树的定义树是一种数据结构,它是由n(n>=1)个有限节点组成一个具有层次关系的集合。把它叫做“树”是因为它看起来像一棵倒挂的树,也就是说它是根朝上,而叶朝下的。它具有以下的特点:(01)每个节点有零个或多个子

    2022年5月31日
    34
  • navicat激活码最新【2021最新】

    (navicat激活码最新)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~https://javaforall.net/100143.htmlIntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,上面是详细链接哦~TR…

    2022年3月22日
    95
  • 微信web开发者工具详解_微信web开发者工具官方下载

    微信web开发者工具详解_微信web开发者工具官方下载一、微信小程序web开发工具下载地址 1.1 在微信公众平台-小程序里边去下载开发工具下载地址。1.2下载后安装一下就可以使用了:二、创建项目 2.1 微信小程序web开发工具需要扫码登陆,所以必…

    2025年5月27日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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