RTPRTCP (Real Time Transfer ProtocolReal Time Transfer Control Protocol) Custom Related C Structure (Reference)

xiaoxiao2021-03-06  43

The RTP / RTCP (Real Time Transfer Protocol / Real Time Transfer Control Protocol) of WGSCD is based on the protocol derived by UDP and increases the control of real-time transmission. Generally used for online transmission real-time video data, such as remote video surveillance, video on demand, etc. There is a detailed introduction to the structure and principles of this 2 protocols in the book called "Multimedia Network Transmission Protocol", as is the publishing of Tsinghua University Press. When I did a remote video surveillance system last year, I used the Wonsock tool to encapsulate a network transmission dynamic connection library based on the Wonsock tool, which is specifically used for LAN to broadcast real-time video data. The following is a related C structure I defined for this 2 protocol. / * 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 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 frame: 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 in actets) * / 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; / * OCTS 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} r;} r;

转载请注明原文地址:https://www.9cbs.com/read-54299.html

New Post(0)