织梦CMS - 轻松建站从此开始!

罗索

关于对ORTP协议栈的分析

jackyhwei 发布于 2011-03-30 09:41 点击:次 
首先进行RTP的初始化,函数为ortp_init(),标志位initialized设为TRUE,然后调用一个av_profile_init函数进行profile的初始化包括设置payload的各种类型
TAG:

首先进行RTP的初始化,函数为ortp_init(),标志位initialized设为TRUE,然后调用一个av_profile_init函数进行profile的初始化包括设置payload的各种类型,在这里就包含了第一个比较重要的结构体就是:

 

  1. struct _RtpProfile 
  2.        char *name; 
  3.        PayloadType *payload[RTP_PROFILE_MAX_PAYLOADS]; 
  4. }; 

然后市ortp_global_stats_reset()函数来对ortp中的全局的统计参数做一个reset。这里出现了第二个重要的结构体就是:

 

  1. typedef struct rtp_stats 
  2.        uint64_t packet_sent; 
  3.        uint64_t sent;
  4. /* bytes sent */ 
  5.        uint64_t recv;
  6. /* bytes of payload received and delivered in time to the application */ 
  7.        uint64_t hw_recv;
  8. /* bytes of payload received */ 
  9.        uint64_t packet_recv;
  10. /* number of packets received */ 
  11.        uint64_t unavaillable;
  12. /* packets not availlable when they were queried */ 
  13.        uint64_t outoftime;
  14. /* number of packets that were received too late */ 
  15.        uint64_t cum_packet_loss;
  16. /* cumulative number of packet lost */ 
  17.        uint64_t bad;
  18. /* packets that did not appear to be RTP */ 
  19.        uint64_t discarded;
  20. /* incoming packets discarded because the queue exceeds its max size */ 
  21. } rtp_stats_t; 

最后一个在ortp_init()中调用的是Init_random_number_generator()函数它主要完成一个随即数的初始化工作。至此ortp_init的工作就完成了。

接下去是scheduler的初始化这里出现了第三个重要的结构体:

 

  1. struct _RtpScheduler { 
  2.        RtpSession *list;
  3. /* list of scheduled sessions*/ 
  4.        SessionSet all_sessions;
  5. /* mask of scheduled sessions */ 
  6.        int all_max;
  7. /* the highest pos in the all mask */ 
  8.        SessionSet  r_sessions;
  9. /* mask of sessions that have a recv event */ 
  10.        int r_max; 
  11.        SessionSet w_sessions;
  12. /* mask of sessions that have a send event */ 
  13.        int w_max; 
  14.        SessionSet e_sessions;
  15. /* mask of session that have error event */ 
  16.        int e_max; 
  17.        int max_sessions;
  18. /* the number of position in the masks */ 
  19.   /* GMutex  *unblock_select_mutex; */ 
  20.        ortp_cond_t   unblock_select_cond; 
  21.        ortp_mutex_t    lock; 
  22.        ortp_thread_t thread
  23.        int thread_running; 
  24.        struct _RtpTimer *timer; 
  25.        uint32_t time_;
  26. /*number of miliseconds elapsed since the start of the thread */ 
  27.        uint32_t timer_inc;
  28. /* the timer increment in milisec */ 
  29. }; 

typedef struct _RtpScheduler RtpScheduler;

其中首先调用rtp_scheduler_new()来分配内存然后把结构体的参数清零,再设置自定的初始值和一些互斥锁的参数。至此scheduler_init的内容初始化完成。

日志的初始化是由ortp_set_log_level_mask()函数如果你不想有日志功能那就不需要这一步了。

接下来就是一个很重要的函数就是rtp_session_new这个函数这个函数用来创建一个新的rtp会话。其中最重要的一个结构体就是:

 

  1. struct _RtpSession 
  2.        RtpSession *next;
  3. /* next RtpSession, when the session are enqueued by the scheduler */ 
  4.        int mask_pos;
  5. /* the position in the scheduler mask of RtpSession : do not move this field:
  6.  it is part of the ABI since the session_set macros use it*/ 
  7.         struct { 
  8.          RtpProfile *profile; 
  9.          int pt; 
  10.          int ssrc; 
  11.          WaitPoint wp; 
  12.          int telephone_events_pt;/* the payload type used for telephony events */ 
  13.        } snd,rcv; 
  14.        int hw_recv_pt; /* recv payload type before jitter buffer */ 
  15.        int recv_buf_size; 
  16.        RtpSignalTable on_ssrc_changed; 
  17.        RtpSignalTable on_payload_type_changed; 
  18.        RtpSignalTable on_telephone_event_packet; 
  19.        RtpSignalTable on_telephone_event; 
  20.        RtpSignalTable on_timestamp_jump; 
  21.        RtpSignalTable on_network_error; 
  22.        RtpSignalTable on_rtcp_bye; 
  23.        struct _OList *signal_tables; 
  24.        struct _OList *eventqs; 
  25.        RtpStream rtp; 
  26.        RtcpStream rtcp; 
  27.        RtpSessionMode mode; 
  28.        struct _RtpScheduler *sched; 
  29.        uint32_t flags; 
  30.        int dscp; 
  31.        int multicast_ttl; 
  32.        int multicast_loopback; 
  33.        void * user_data; 
  34.        /* FIXME: Should be a table for all session participants. */ 
  35.        struct timeval last_recv_time; /*Time of receiving the RTP/RTCP packet.*/ 
  36.  
  37.        /* telephony events extension */ 
  38.        mblk_t *current_tev; /* the pending telephony events */ 
  39.        mblk_t *sd; 
  40.        queue_t contributing_sources; 
  41.        bool_t symmetric_rtp; 
  42.        bool_t permissive; /*use the permissive algorithm*/ 
  43.        bool_t use_connect; /* use connect() on the socket */ 
  44. }; 

在这个函数里首先给rtpsession结构体分配内存然后调用rtp_session_init函数来初始化。在这个函数里首先设置好最大队列数,和模式。判断模式是只读还是只写还是只读只写,根据模式设置flag,设置随机数random,设置源的描述,信号的设置,互斥锁的设置,设置send payload和receive payload type,设置jitter(这个还不知道是干什么的),设置最大接受单元等等。

 

 

Rtp_Session_set_remote_addr函数来设置远端的地址对。首先判断socket是否等于负一,如果是的话说明还没有设置本地地址,所以要去设置本地地址调用的是rtp_session_set_local_addr函数.在这个函数里首先去创建RTP要用到的socket的族系列参数和RTCP需要用到的族系列参数。以及设置支持多播方式的TTL和LOOPBACK和DSCP的值。接着就是绑定socket

 然后就是设置payload的类型值调用的是rtp_session_set_payload_type()

(cuishinankobe)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201103/11138.html]
本文出处:CSDN博客 作者:cuishinankobe
顶一下
(2)
100%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容