DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> AJAX入門 >> AJAX詳解 >> RTP/RTCP(實時傳輸協議/實時傳輸控制協議)自定義的相關C結構(參考)
RTP/RTCP(實時傳輸協議/實時傳輸控制協議)自定義的相關C結構(參考)
編輯:AJAX詳解     

wgscd轉摘的
RTP/RTCP(實時傳輸協議/實時傳輸控制協議)基於UDP派生出的協議,並增加了對實時傳輸的控制。一般用於網上傳輸實時視頻數據,比如遠程視頻監控,視頻點播等。有一本名叫《多媒體網絡傳輸協議》的書上對此2個協議的結構和原理做了比較詳細的介紹,好象是清華大學出版社出版的。
    我去年做遠程視頻監控系統時,曾用基於2個協議,用Wonsock工具封裝了一個網絡傳輸動態連接庫,專門用於局域網組播傳輸實時視頻數據。以下是我針對此2個協議定義的相關C結構。
    /*Current protocol version. */
#define RTP_VERSION    2
#define MIN_SEQUENTIAL  1
#define RTP_SEQ_MOD (1<<16)
#define RTP_MAX_SDES 255      /* maximum text length for SDES */
#define MID_BUFFER_NUM   2
#define MAX_DROPOUT   25

typedef enum {
    RTCP_SR   = 200,
    RTCP_RR   = 201,
    RTCP_SDES = 202,
    RTCP_BYE  = 203,
    RTCP_APP  = 204
} rtcp_type_t;

typedef enum {
   RTCP_SDES_END   = 0,
   RTCP_SDES_CNAME = 1,
   RTCP_SDES_NAME  = 2,
   RTCP_SDES_EMAIL = 3,
   RTCP_SDES_PHONE = 4,
   RTCP_SDES_LOC   = 5,
   RTCP_SDES_TOOL  = 6,
   RTCP_SDES_NOTE  = 7,
   RTCP_SDES_PRIV  = 8
} rtcp_sdes_type_t;

/*
 * RTP data header
 */
typedef struct {
   unsigned int version:2;   /* protocol version */
   unsigned int p:1;         /* padding flag */
   unsigned int x:1;         /* header extension flag */
   unsigned int cc:4;        /* CSRC count */
   unsigned int m:1;         /* marker bit */
   unsigned int pt:7;        /* payload type */
   u_int16 seq;              /* sequence number */
   u_int32 ts;               /* timestamp */
   u_int32 ssrc;             /* synchronization source */
   u_int32 csrc[1];          /* optional CSRC list */
} rtp_hdr_t;

/*
 * RTCP common header Word
 */
typedef struct {
   unsigned int version:2;   /* protocol version */
   unsigned int p:1;         /* padding flag */
   unsigned int count:5;     /* varIEs by packet type */
   unsigned int pt:8;        /* RTCP packet type */
   u_int16 length;           /* pkt len in words, w/o this Word */
} rtcp_common_t;

/*
 * Big-endian mask for version, padding bit and packet type pair
 */
#define RTCP_VALID_MASK (0xc000 | 0x2000 | 0xfe)
#define RTCP_VALID_VALUE ((RTP_VERSION << 14) | RTCP_SR)

/*
 * Reception report block
 */
typedef struct {
   u_int32 ssrc;             /* data source being reported */
   unsigned int fraction:8;  /* fraction lost since last SR/RR */
   int lost:24;              /* cumul. no. pkts lost (signed!) */
   u_int32 last_seq;         /* extended last seq. no. received */
   u_int32 jitter;           /* interarrival jitter */
   u_int32 lsr;              /* last SR packet from this source */
   u_int32 dlsr;             /* delay since last SR packet */
} rtcp_rr_t;

/*
 * SDES item
 */
typedef struct {
   u_int8 type;              /* type of item (rtcp_sdes_type_t) */
   u_int8 length;            /* length of item (in octets) */
   char data[1];             /* text, not null-terminated */
} rtcp_sdes_item_t;

/*
 * One RTCP packet
 */
typedef struct {
   rtcp_common_t common;     /* common header */
   union {
      /* sender report (SR) */
      struct {
u_int32 ssrc;     /* sender generating this report */
         u_int32 ntp_sec;  /* NTP timestamp */
         u_int32 ntp_frac;
         u_int32 rtp_ts;   /* RTP timestamp */
         u_int32 psent;    /* packets sent */
         u_int32 osent;    /* octets sent */
         rtcp_rr_t rr[1];  /* variable-length list */
       } sr;

       /* reception report (RR) */
       struct {
          u_int32 ssrc;     /* receiver generating this report */
          rtcp_rr_t rr[1];  /* variable-length list */
       } rr;

       /* source description (SDES) */
       struct rtcp_sdes {
          u_int32 src;      /* first SSRC/CSRC */
          rtcp_sdes_item_t item[1]; /* list of SDES items */
       } sdes;

       /* BYE */
       struct {
          u_int32 src[1];   /* list of sources */
                           /* can't express trailing text for reason */
       } bye;
   } r;
} rtcp_t;

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved