JRTPLIB库的使用
文档:
http://research.edm.uhasselt.be/jori/jrtplib/documentation/index.html
一些介绍:

http://doserver.net/read.php?1028
http://doserver.net/read.php/1027.htm
http://doserver.net/read.php/1685.htm
如今開始对几个example分析一下,只是,就没有文档吗?
这里,具体的解释了几个样例:
http://hi.baidu.com/hanyuejun2006/blog/item/8a8ed939a9e344f53b87ce23.html
这里算一个:
http://xiyong8260.blog.163.com/blog/static/665146212008824112748499/
重要的是里面还讲了一些嵌入式方面的内容。
收和发的样例:
http://blog.chinaunix.net/u2/61880/showart_728528.html
比較具体的系列文章:http://www.cnitblog.com/tinnal/archive/2009/01/01/53342.html
PS:关于POLL的问题,发现仅仅有调用者这个函数的时候,才会查询是否有包发过来,才会接收包。
If you're not using the poll thread, this function must be called regularly to process incoming data and to send RTCP data when necessary.

关于例程能够分为下面几个部分:

(一)BASIC USAGE:
1)SET PARAMS
    关于会话的參数
2)SET TRANSPARAMS
    关于传输层的參数
3)CREATE SESSION
    创建会话
4)SET PACKET ATTRIBUTES
    包的属性设置
5)ADD DESTINATION
    加入目的地址 
6)PREPARE DATA
    准备数据
7)SEND PACKET
    发送包
8)DATAACCESS
    数据处理(锁定操作,是指此时POLL线程不能改变正在处理的数据)
9)BYE
    退出会话
example:
#include "rtpsession.h"
#include "rtppacket.h"
#include "rtpudpv4transmitter.h"
#include "rtpsessionparams.h"
#include "rtperrors.h"
#include "rtpipv4address.h"
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>

void checkerror(int rtperr)
{
    if(rtperr < 0)
    {
        std::cout<<"ERROR:"<<RTPGetErrorString(rtperr)<<std::endl;
        exit(-1);
    }
}

int main()
{
    RTPSession sess;
    uint16_t portbase;
    int status;

//set params

RTPSessionParams sessparams;
    sessparams.SetOwnTimestampUnit(1.0/10.0);
    sessparams.SetAcceptOwnPackets(true);

//set transparams

RTPUDPv4TransmissionParams transparams;
    transparams.SetPortbase(8000);

//create a session

status = sess.Create(sessparams, &transparams);
    checkerror(status);

//set default packet attributes

sess.SetDefaultPayloadType(0);
    sess.SetDefaultMark(false);
    sess.SetDefaultTimestampIncrement(10);

//destination address

uint16_t destport;
    uint32_t destip;
    std::string ipstr;
    std::cout<<"Enter the IP: "<<std::endl;
    std::cin>>ipstr;
    destip = inet_addr(ipstr.c_str());
    if(destip == INADDR_NONE)
    {
        std::cerr<<"Bad IP"<<std::endl;
        exit(-1);
    }
    destip = ntohl(destip);
    //uint8_t localip[] = {192, 168, 0, 3};

RTPIPv4Address addr(destip, 8000);

//add destination

status = sess.AddDestination(addr);
    checkerror(status);

//prepare payload data

uint8_t silencebuffer[160];
    for(int i = 0; i < 160; i++)
    {
        silencebuffer[i] = 128;
    }

//for time checking

RTPTime delay(0.020);
    RTPTime starttime = RTPTime::CurrentTime();

bool done = false;
    sess.Poll();

while(!done)
    {
        status = sess.SendPacket(silencebuffer, 160);
        checkerror(status);

//receive data

sess.BeginDataAccess();
        if(sess.GotoFirstSource())
        {
            do
            {
                RTPPacket *pack;
                while((pack = sess.GetNextPacket()) != NULL)
                {
                    std::cout<<"Got packet!"<<std::endl;
                    std::cout<<"sequence number: "<<pack->GetSequenceNumber()<<std::endl;
                    std::cout<<"Extended SN: "<<pack->GetExtendedSequenceNumber()<<std::endl;
                    std::cout<<"SSRC: "<<pack->GetSSRC()<<std::endl;
                    std::cout<<"Data: "<<pack->GetPayloadData()<<std::endl;
                    sess.DeletePacket(pack);
                }
            }while(sess.GotoNextSource());
        }
        sess.EndDataAccess();
        
        RTPTime::Wait(delay);
    
        RTPTime t = RTPTime::CurrentTime();
        t -= starttime;
        if(t > RTPTime(6, 0))
        {
            done = true;
        }
    }
    
    delay = RTPTime(10.0);
    sess.BYEDestroy(delay, "Time's up", 9);
    return(0);
}

(二)Your Own Session:
能够继承session创建MySession加入自己定制的处理, 这些处理是由session的protected methods 定义的。參考文档能够确定要定制的处理。

example:

#include "rtpsession.h"
#include "rtppacket.h"
#include "rtpudpv4transmitter.h"
#include "rtpipv4address.h"
#include "rtpsessionparams.h"
#include "rtperrors.h"
#include "rtpsourcedata.h"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>

class MyRTPSession : public RTPSession
{
    protected:

//what to do on new source?
        void OnNewSource(RTPSourceData *dat)
        {
            if(dat->IsOwnSSRC())
            {
                return;
            }
            uint32_t ip;
            uint16_t port;
            if(dat->GetRTPDataAddress() != 0)
            {
                const RTPIPv4Address *addr = (const RTPIPv4Address *)
                (dat->GetRTPDataAddress());
                ip = addr->GetIP();
                port = addr->GetPort();
            }
            else if(dat->GetRTCPDataAddress() != 0)
            {
                const RTPIPv4Address *addr = (const RTPIPv4Address *)
                    (dat->GetRTCPDataAddress());
                ip = addr->GetIP();
                port = addr->GetPort()-1;
            }
            else
            {
                return;
            }
            RTPIPv4Address dest(ip, port);
            AddDestination(dest);

struct in_addr inaddr;
            inaddr.s_addr = htonl(ip);
            std::cout<<"Adding destination"<<std::string(inet_ntoa(inaddr))
                <<":"<<port<<std::endl;
        }
//what to do on byepacket?
        void OnBYEPacket(RTPSourceData *dat)
        {
            std::cout<<"OnBYEPacket"<<std::endl;
            if(dat->IsOwnSSRC())
            {
                return;
            }
            uint32_t ip;
            uint16_t port;
            if(dat->GetRTPDataAddress() != 0)
            {
                const RTPIPv4Address *addr = (const RTPIPv4Address *)
                    (dat->GetRTPDataAddress());
                ip = addr->GetIP();
                port = addr->GetPort();
            }
            else if(dat->GetRTCPDataAddress() != 0)
            {
                const RTPIPv4Address *addr = (const RTPIPv4Address *)
                    (dat->GetRTCPDataAddress());
                ip = addr->GetIP();
                port = addr->GetPort()-1;
            }
            else
            {
                return;
            }
            RTPIPv4Address dest(ip, port);
            DeleteDestination(dest);
            
            struct in_addr inaddr;
            inaddr.s_addr = htonl(ip);
            std::cout<<"Deleting destination"
                <<std::string(inet_ntoa(inaddr))
                <<":"<<port<<std::endl;
        }
//what to do on remove source?
        void OnRemoveSource(RTPSourceData *dat)
        {
            std::cout<<"OnRemoveSource"<<std::endl;
            if(dat->IsOwnSSRC())
            {
                return;
            }
            if(dat->ReceivedBYE())
            {
                return;
            }
            uint32_t ip;
            uint16_t port;
            if(dat->GetRTPDataAddress() != 0)
            {
                const RTPIPv4Address *addr = (const RTPIPv4Address *)
                    (dat->GetRTPDataAddress());
                ip = addr->GetIP();
                port = addr->GetPort();
            }
            else if(dat->GetRTCPDataAddress() != 0)
            {
                const RTPIPv4Address *addr = (const RTPIPv4Address *)
                    (dat->GetRTCPDataAddress());
                ip = addr->GetIP();
                port = addr->GetPort()-1;
            }
            else
            {
                return;
            }
            RTPIPv4Address dest(ip, port);
            DeleteDestination(dest);
            
            struct in_addr inaddr;
            inaddr.s_addr = htonl(ip);
            std::cout<<"Deleting destination"
                <<std::string(inet_ntoa(inaddr))
                <<":"<<port<<std::endl;
        }
};

(三)Important Classes:
分析參数:RTPSourceData-HOW TO KNOW RTCP?
从(二)中,你可能已经了解到了On...等定义了session在收发包时的动作,而为了分析这些包的參数,你须要的是RTPSourceData这个參数。Source指的是一个会话的參与者,在本地保存了一个參与者列表,和与之相关的信息。这些信息是从该源发送的RTCP信息提取的。
为了便于和理论分析比較,如今将5中RTCP分组报告和它们的实现列出:
指的注意的是:据我眼下的理解是,本地维护一个源的列表,而这些RTCP分组,并没有它们的实体,而是得到这些分组后就分析为和一个源描写叙述符,即RTPSource关联的数据。应该是遍历这个源列表,而获得它们的信息。而怎样遍历的问题,稍后讨论。

发送者报告(SR)

V| P| RC| PT=SR=200| LEN|


发送者SSRC (已关联)


NTP时间戳(高32位) SR_GetNTPTimestamp ()

NTP时间戳(低32位)


RTP时间戳 SR_GetRTPTimestamp ()


发送者分组计数器 SR_GetPacketCount()


发送者字节计数器 SR_GetByteCount ()


...(以下是这个发送者所发送的接收者报告,在以下和RR一起讨论)


附加信息:

这个源是否有发送发送者报告

SR_HasInfo ()

这个发送者报告接收的时间

SR_GetReceiveTime ()

以及以SR_Prev_开头的,获得倒数第二个发送者报告的信息。

接收者报告(RR)

V| P| RC| PT=SR=201| LEN|


SSRC1(第一个接收者报告块所关联的发送者) (已关联)

分组丢失率 | 丢失分组总数|

扩展的最高序号

间隔抖动

最新的发送者报告时间戳(LSR)

SR最新间隔(DLSR)

附加信息:
这个源是否有发送接收者报告
接收者报告接收时间
以及以RR_Prev_开头的,获得倒数第二个接收者报告的信息。

源描叙分组(SDES)

V| P| RC| PT=SR=202| LEN|


SSRC/CSRC1 (已关联)


SDES项

由SDES_Get...等描写叙述

能够推断的是存在一种机制,能够在本地定制自己要发送的SDES包括的信息。

BYE分组(BYE)

V| P| RC| PT=SR=202| LEN|


SSRC/CSRC (已关联)


原因长度| 退出会话原因
GetBYEReason (size_t *len)


附加信息(见文档)
依据以上的信息,大概知道了怎样获取一个源的信息;问题是怎样遍历这个源列表来处理一个源?
其实,在大多数的样例里,使用的类仅仅是RTPSession,通过这个类能够管理会话的大部分细节。
管理会话:RTPSession-MANAGE A SESSION
对一次会话的管理,大概有下面几方面:
*创建会话
*退出会话
*管理目的地址(加入,忽略)
*发送和接收数据包(用户仅仅须要关心RTP包),另外,APP包也是由用户负责的
*时间戳设定
*管理SDES信息项
*管理源列表
*管理广播组
...
一般来说,使用一个类都是使用它的public接口,可是你能够像(二)描写叙述的那样,通过继承来定制自己的一些行为。On...
着重讲的是管理源列表。
bool  GotoFirstSource ()
  Starts the iteration over the participants by going to the first member in the table.
bool  GotoNextSource ()
  Sets the current source to be the next source in the table.
bool  GotoPreviousSource ()
  Sets the current source to be the previous source in the table.
bool  GotoFirstSourceWithData ()
  Sets the current source to be the first source in the table which has RTPPacket instances that we haven't extracted yet.
bool  GotoNextSourceWithData ()
  Sets the current source to be the next source in the table which has RTPPacket instances that we haven't extracted yet.
bool  GotoPreviousSourceWithData ()
  Sets the current source to be the previous source in the table which has RTPPacket instances that we haven't extracted yet.
RTPSourceData GetCurrentSourceInfo ()
  Returns the RTPSourceData instance for the currently selected participant.
RTPSourceData GetSourceInfo (uint32_t ssrc)
  Returns the RTPSourceData instance for the participant identified by ssrc, or NULL if no such entry exists. 
bool  GotEntry (uint32_t ssrc)
  Returns true if an entry for participant ssrc exists and false otherwise.
RTPSourceData GetOwnSourceInfo ()
  If present, it returns the RTPSourceData instance of the entry which was created by CreateOwnSSRC. 

迭代的例程:

非常明显,这是C++风格,使用了迭代器的抽象。而GetCurrentSourceInfo ()和GetSourceInfo (uint32_t ssrc)的返回类型-RTPSourceData能够使我们得以获取源列表的RTCP信息。
使用这样的迭代的例程:
 sess.BeginDataAccess();
        if(sess.GotoFirstSource())
        {
            do
            {
                RTPPacket *pack;
                while((pack = sess.GetNextPacket()) != NULL)
                {
            //deal with the packet
                    sess.DeletePacket(pack);
                }
            }while(sess.GotoNextSource());
        }
sess.EndDataAccess();
以上,我们能够获得訪问源的信息的机制。

jrtplib的使用的更多相关文章

  1. jrtplib跨网络通讯NAT穿透问题解决方法

    前几篇文章讲了使用jrtplib在Android和pc端进行通讯的方法 在实际项目中,手机端和pc端一般不会在同一个子网内,两者之间联络可能要走路由器之类的NAT(网络地址转换 Network Add ...

  2. 流媒體】jrtplib—VS2010下RTP开源协议库JRTPLIB3.9.1编译

    一.JRTPLIB简介 老外用C++编写的开源RTP协议库,用来进行实时数据传输,可以运行在 Windows.Linux. FreeBSD.Solaris.Unix和VxWorks 等多种操作系统上, ...

  3. 关于开源的RTP——jrtplib的使用

    session.BeginDataAccess(); if (session.GotoFirstSource()){ do{ RTPPacket *packet; while ((packet = s ...

  4. jrtplib使用注意事项

    一.说明 RTP 现在的问题是要解决的流媒体的实时传输的问题的最佳方法.和JRTPLIB 是一个用C++语言实现的RTP库.包含UDP通讯.刚使用JRTPLIB,对JRTPLIB的理解还不够深,当做使 ...

  5. 一个基于JRTPLIB的轻量级RTSP客户端(myRTSPClient)——实现篇:(一)概览

    myRTSPClient主要可以分成3个部分: 1. RTSPClient用户接口层: 2. RTP 音视频传输解析层: 3. RTP传输层. "RTSPClient用户接口层": ...

  6. 一个基于JRTPLIB的轻量级RTSP客户端(myRTSPClient)——收流篇:(一)简介

    关于实时流媒体传输的开源库,目前流行的主要有两个:live555和jrtplib. 其中live555将rtp.rtcp和rtsp的传输协议实现集于一身,功能齐全,是个超强的集合体.但是对于嵌入式系统 ...

  7. 测试库的接收到的数据是否完整(jrtplib为列)

    最近使用jrtplib来接收RTP包,然后解码播放 发现解码出来的是绿屏,马赛克 于是开始排查 首先直接用wireshark抓进来的包,转为可以被vlc播放的文件 操作如下 http://blog.c ...

  8. 一个基于JRTPLIB的轻量级RTSP客户端(myRTSPClient)——实现篇:(十)使用JRTPLIB传输RTP数据

    myRtspClient通过简单修改JRTPLIB的官方例程作为其RTP传输层实现.因为JRTPLIB使用的是CMAKE编译工具,这就是为什么编译myRtspClient时需要预装CMAKE. 该部分 ...

  9. hi3516a arm-hisiv300-linux-gcc jrtplib交叉编译

    1.进入JThread-1.2.1文件夹 2../configure --prefix=/home/suxuandong/Documents/qth264/hi3516/jrtpjthreadhisi ...

随机推荐

  1. Centos 7 静态学习IP建立

    该研究主要集中在 Centos 7.0.1406 学习整理版! 1.编者 ifcfg-eth0 档,vim 同时尽量减少未安装安装,你并不需要自己安装叙述性说明. # vim /etc/sysconf ...

  2. SQLServer数据类型优先级对性能的影响

    原文:SQLServer数据类型优先级对性能的影响 译自: http://www.mssqltips.com/sqlservertip/2749/sql-server-data-type-preced ...

  3. C、C++用指针引用的差异

    1:并引述之间的区别在概念的指针 参考是可变的别名.例如 int m; int &n=m; 引用作为一个别名.它在逻辑上不是独立的.它的存在具有依附性.所以引用必须在一開始就被初始化.并且其引 ...

  4. 无法Debug SQL: Unable to start T-SQL Debugging. Could not attach to SQL Server process on

    今天SSMS debug SQL当脚本,突然错误: Unable to start T-SQL Debugging. Could not attach to SQL Server process on ...

  5. tornado的GET POST方法样品展示

    举例说明get和post该方法的用途: 一.演示样例用的GET方法: import tornado.ioloop import tornado.web class MainHandler(tornad ...

  6. c#委托实例化和调用语句

    系统訪问数据或调用方法有两种操作方式:一种是通过名称訪问或调用,还有一种是通过所在的内存地址来訪问调用.为了系统的安全与稳定,NET Framework的CLR库不同意程序通过指针来直接操作内存中数据 ...

  7. SQL入门学习6-集合运算

    7-1 表的加减法 集合运算 集合运算就是对满足同一规则的记录,进行的加减等四则运算. 1.1 表的加法--UNION 表之间进行并集运算. 语法: SELECT 对应列1,对应列2-- FROM 表 ...

  8. HDU 3788 和九度OJ 1006测试数据是不一样的

    ZOJ问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  9. Struts2大约Action系统培训6大约action的接受三个参数的方法

    我们知道,action在web它在控制器的发展起到了一定作用,通过接收client来到参数,运行不同的模块只实现运营,因此,接收参数是非常重要的组成部分,有接收到的参数的仅前端.操作权限运行数据库后端 ...

  10. paip.自适应网页设计 同 响应 与设计的原理的差and实践总结

    paip.自适应网页设计 同 响应 与设计的原理的差and实践总结 响应式Web设计(Responsive Web design)的理念是: 1 #-----------自适应布局VS响应式布局 2 ...