zoukankan      html  css  js  c++  java
  • rtp

    dows 下资料
          http://www.cnblogs.com/skyseraph/archive/2012/04/07/2435540.html

    一,安装Cmake
    二,在 jrtplib-3.9.1_1 中运行 cmake . 生成Makefile
    三,然后 make 
            接着 make install
            头文件被安装在 /usr/local/include/jrtplib3/ 所以编译程序时候需要添加 -I /usr/local/include/jrtplib3/
            库文件被安装在 /usr/local/lib/libjrtp.a 所以编译程序时候需要添加 -ljrtp
    四,编译 example1
            g++ -o test example1.cpp -ljrtp -I /usr/local/include/jrtplib3/

           报错:./test: error while loading shared libraries: libjrtp.so.3.9.1: cannot open shared object file: No such file or directory
           分析:已经将 jrtp 安装完毕,为什么找不到动态库呢?
           解决:将 usr/local/lib/libjrtp.so.3.9.1 拷贝到 usr/lib 下面就可以执行了
    五,调试
          报错:The specified port base is not an even number

          分析:jrtp 不支持奇数端口

    附:

    发送端代码:send.cpp

    [html] view plain copy
     
    1. /*  
    2.    Here's a small IPv4 example: it asks for a portbase and a destination and   
    3.    starts sending packets to that destination.  
    4. */  
    5.   
    6. #include "jrtplib3/rtpsession.h"  
    7. #include "jrtplib3/rtpudpv4transmitter.h"  
    8. #include "jrtplib3/rtpipv4address.h"  
    9. #include "jrtplib3/rtpsessionparams.h"  
    10. #include "jrtplib3/rtperrors.h"  
    11. #ifndef WIN32  
    12.     #include <netinet/in.h>  
    13.     #include <arpa/inet.h>  
    14. #else  
    15.     #include <winsock2.h>  
    16. #endif // WIN32  
    17. #include <stdlib.h>  
    18. #include <stdio.h>  
    19. #include <iostream>  
    20. #include <string>  
    21.   
    22. using namespace jrtplib;  
    23.   
    24. void checkerror(int rtperr)  
    25. {  
    26.     if (rtperr 0) //如果为负数 则返回失败信息  
    27.     {  
    28.         std::cout << "ERROR: " <RTPGetErrorString(rtperr) <std::endl;  
    29.         exit(-1);  
    30.     }  
    31. }  
    32.   
    33. int main(void)  
    34. {  
    35. #ifdef WIN32  
    36.     WSADATA dat;  
    37.     WSAStartup(MAKEWORD(2,2),&dat);  
    38. #endif // WIN32  
    39.       
    40.     RTPSession sess;  
    41.           
    42.     uint16_t portbase=8000,destport=7800;  
    43.     uint32_t destip;  
    44.     std::string ipstr="127.0.0.1";  
    45.     int status,i,num=10;      
    46.       
    47.     destip = inet_addr(ipstr.c_str());//IP地址的建立  
    48.     if (destip == INADDR_NONE)  
    49.     {  
    50.         std::cerr << "Bad IP address specified" <std::endl;  
    51.         return -1;  
    52.     }  
    53.       
    54.     destip = ntohl(destip);  
    55.       
    56.       
    57.     RTPUDPv4TransmissionParams transparams;  
    58.     RTPSessionParams sessparams;  
    59.   
    60.     sessparams.SetOwnTimestampUnit(1.0/10.0);         
    61.       
    62.     sessparams.SetAcceptOwnPackets(true);  
    63.     transparams.SetPortbase(portbase);  
    64.           
    65.     status = sess.Create(sessparams,&transparams);    
    66.     checkerror(status);//检查RTP会话创建过程是否失败  
    67.       
    68.     RTPIPv4Address addr(destip,destport);//套接字  
    69.       
    70.     status = sess.AddDestination(addr);//设置数据发送的目标地址(允许有多个目的地址)  
    71.     checkerror(status);  
    72.       
    73.     for (i = 1 ; i <= num ; i++)  
    74.     {  
    75.         printf(" Sending packet %d/%d ",i,num);  
    76.           
    77.         status = sess.SendPacket((void *)"1234567890",10,0,false,10);  
    78.         checkerror(status);  
    79.           
    80.   
    81.                // #ifndef RTP_SUPPORT_THREAD  
    82.          //     status = sess.Poll();  
    83.          //     checkerror(status);  
    84.               //  #endif // RTP_SUPPORT_THREAD  
    85.           
    86.         RTPTime::Wait(RTPTime(1,0));  
    87.     }  
    88.       
    89.     sess.BYEDestroy(RTPTime(10,0),0,0);  
    90.   
    91. #ifdef WIN32  
    92.     WSACleanup();  
    93. #endif // WIN32  
    94.     return 0;  
    95. }  

    编译:g++ -o send send.cpp  -ljrtp -I /usr/local/include/jrtplib3/

    接受端代码:

    [html] view plain copy
     
    1. #include "jrtplib3/rtpsession.h"  
    2. #include "jrtplib3/rtpudpv4transmitter.h"  
    3. #include "jrtplib3/rtpipv4address.h"  
    4. #include "jrtplib3/rtpsessionparams.h"  
    5. #include "jrtplib3/rtperrors.h"  
    6.   
    7. #ifndef WIN32  
    8.     #include <netinet/in.h>  
    9.     #include <arpa/inet.h>  
    10. #else  
    11.     #include <winsock2.h>  
    12. #endif // WIN32  
    13.   
    14. #include <stdlib.h>  
    15. #include <stdio.h>  
    16. #include <iostream>  
    17. #include <string>  
    18.   
    19. using namespace jrtplib;  
    20.   
    21. // 错误处理函数  
    22. void checkerror(int rtperr)  
    23. {  
    24.     if (rtperr 0) //如果为负数 则返回失败信息  
    25.     {  
    26.         std::cout << "ERROR: " <RTPGetErrorString(rtperr) <std::endl;  
    27.         exit(-1);  
    28.     }  
    29. }  
    30.   
    31.   
    32. int main(int argc, char** argv)  
    33. {  
    34.        
    35.   RTPSession sess;  
    36.   int localport;  
    37.   int portbase = 7800;  
    38.   int status;  
    39.   
    40.     
    41.     
    42.   // 创建RTP会话  
    43.         RTPUDPv4TransmissionParams transparams;  
    44.     RTPSessionParams sessparams;  
    45.       
    46.     sessparams.SetOwnTimestampUnit(1.0/10.0);         
    47.       
    48.     sessparams.SetAcceptOwnPackets(true);  
    49.     transparams.SetPortbase(portbase);  
    50.           
    51.     status = sess.Create(sessparams,&transparams);  
    52.         checkerror(status);  
    53.     
    54.           
    55.         uint32_t destip;  
    56.     std::string ipstr="127.0.0.1";  
    57.         int destport=7800;  
    58.     destip = inet_addr(ipstr.c_str());//IP地址的建立  
    59.     if (destip == INADDR_NONE)  
    60.     {  
    61.         std::cerr << "Bad IP address specified" <std::endl;  
    62.         return -1;  
    63.     }  
    64.     destip = ntohl(destip);  
    65.         RTPIPv4Address addr(destip,destport);//套接字  
    66.           
    67.         sess.AddToAcceptList(addr);  
    68.           
    69.         std::cout<<"Begin receive:  ";  
    70.           
    71.         sess.BeginDataAccess();  
    72.           
    73.         do{  
    74.                   status = sess.Poll();  
    75.                   checkerror(status);  
    76.              
    77.         if (sess.GotoFirstSourceWithData())  
    78.         {          
    79.             do  
    80.             {  
    81.                 RTPPacket *pack;  
    82.                   
    83.                 while ((pack = sess.GetNextPacket()) != NULL)  
    84.                 {  
    85.                     // You can examine the data here  
    86.                     printf("Got packet ! ");  
    87.                       
    88.                     // we don't longer need the packet, so  
    89.                     // we'll delete it  
    90.                     sess.DeletePacket(pack);  
    91.                 }  
    92.             } while (sess.GotoNextSourceWithData());  
    93.         }  
    94.         }  
    95.         while(1);  
    96.         sess.EndDataAccess();  
    97.                   
    98.     
    99.     
    100.   return 0;  
    101. }  

    编译:g++ -o receive  receive.cpp  -ljrtp -I /usr/local/include/jrtplib3/

  • 相关阅读:
    《程序员修炼之道+从小工到专家》读后感2
    java在子类中,调用父类中被覆盖的方法
    长按文本全复制
    NSTimer 定时器总结
    对URL编码
    Mysql find_in_set 效率问题
    php 运算符优先级
    使用layui上传控件问题
    xcode11发版一直卡在App Store验证过不去
    iOS13禁用深色模式
  • 原文地址:https://www.cnblogs.com/oracleloyal/p/6076946.html
Copyright © 2011-2022 走看看