📄 rtp.h
字号:
/* rtp.h - Real Time Protocol *//* *//* This program is free software; you can redistribute it and/or modify *//* it under the terms of the GNU General Public License as published by *//* the Free Software Foundation; either version 2, or (at your option) *//* any later version. *//* *//* This program is distributed in the hope that it will be useful, *//* but WITHOUT ANY WARRANTY; without even the implied warranty of *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *//* GNU General Public License for more details. *//* *//* You should have received a copy of the GNU General Public License *//* along with this program; if not, write to the Free Software *//* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA *//* 02111-1307, USA. */#ifndef RTP_H#define RTP_H#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/time.h>#include <netinet/in.h>#include "config.h"#include "alloc.h"#include "seterror.h"#include "rand32.h"#include "ohtbl.h"#include "vstr.h"#include "phtbl.h"/* RTP build flags */#define RTP_SENDER 0x01#define RTP_MIXER 0x02/* RTP defaults */#define RTP_VERSION 2#define RTP_MTU_SIZE 1500#define RTP_MAX_QUEUE 32#define RTP_SOLVE_TIME 1024#define RTP_SDES_MAX 255#define RTP_MAX_FAIL_COUNT 5#define RTP_HEADER_SIZE 3*sizeof(uint32_t)#define RTCP_HEADER_SIZE 2*sizeof(uint32_t)#define RTCP_SR_SIZE 5*sizeof(uint32_t)#define RTCP_RR_SIZE 6*sizeof(uint32_t)#define RTCP_SDES_HEADER_SIZE 2*sizeof(uint16_t)#define RTCP_SDES_ITEM_SIZE 2*sizeof(uint8_t)/* Total number of sources (hash = 103, tolerance = 50) */#define RTP_HASH_SIZE 103#define RTP_HASH_TOLERANCE 50/* RTP flags */#define FLAG_MARKER 0x01#define FLAG_PADDING 0x02#define FLAG_EXTENSION 0x04/* RTCP Reports */#define RTCP_SR 200#define RTCP_RR 201#define RTCP_SDES 202#define RTCP_BYE 203#define RTCP_APP 204/* Check for valid RTCP types */#define RTCP_TYPE_MIN 72 /* 200 & 0x7F */#define RTCP_TYPE_MAX 76 /* 200 & 0x7F *//* RTCP Source Description Reports */#define RTCP_SDES_END 0#define RTCP_SDES_CNAME 1#define RTCP_SDES_NAME 2#define RTCP_SDES_EMAIL 3#define RTCP_SDES_PHONE 4#define RTCP_SDES_LOC 5#define RTCP_SDES_TOOL 6#define RTCP_SDES_NOTE 7#define RTCP_SDES_LAST 8/* RTCP indexes */#define CNAME 0#define NAME 1#define EMAIL 2#define PHONE 3#define LOC 4#define TOOL 5#define NOTE 6/* rtcp_sdes interface: flags */#define SDES_CNAME 0x0001#define SDES_NAME 0x0002#define SDES_EMAIL 0x0004#define SDES_PHONE 0x0008#define SDES_LOC 0x0010#define SDES_TOOL 0x0020#define SDES_NOTE 0x0040#define SDES_ALL 0x007F/* correct memory allocation for direct mapping */#define RTP_PACKET_IDX 2*sizeof(uint32_t)+sizeof(int)+sizeof(void *)#define RTP_PACKET_SIZE RTP_PACKET_IDX+RTP_MTU_SIZE#define RTCP_PACKET_IDX 31*(7*sizeof(rtcp_sdes_item_t *)+sizeof(rtcp_sdes_t *))#define RTCP_PACKET_SIZE RTCP_PACKET_IDX+RTP_MTU_SIZE#define RTCP_BYE_IDX sizeof(rtcp_bye_t)-sizeof(uint8_t)-sizeof(uint8_t *)#define RTCP_BYE_SIZE RTCP_BYE_IDX+RTP_MTU_SIZE#define RTCP_APP_IDX sizeof(rtcp_app_t)-sizeof(char *)#define RTCP_APP_SIZE RTCP_APP_IDX+RTP_MTU_SIZE/* RTP packet */typedef struct { uint16_t xdef; /* defined by profile */ uint16_t xlen; /* lenght (32-bit words minus one) */ uint32_t *xhdr; /* extra fields */ int pay_len; /* Payload lenght */ void *payload; /* RTP payload */#ifdef WORDS_BIGENDIAN unsigned int ver: 2; /* RTP 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 */#else unsigned int cc: 4; /* CSRC count */ unsigned int x: 1; /* header extension flag */ unsigned int p: 1; /* padding flag */ unsigned int ver: 2; /* RTP version */ unsigned int pt: 7; /* payload type */ unsigned int m: 1; /* marker bit */#endif uint16_t seq; /* sequence number */ uint32_t ts; /* timestamp */ uint32_t ssrc; /* synchronization source */ uint32_t csrc[1]; /* optional CSRC list */} rtp_packet_t; /* RTP packet *//* RTCP report block */typedef struct { uint32_t ssrc; /* SSRC identifier of the source */#ifdef WORDS_BIGENDIAN uint8_t frac; /* fraction of packets lost */ unsigned int lost: 24; /* packets lost */#else unsigned int lost: 24; /* packets lost */ uint8_t frac; /* fraction of packets lost */#endif uint32_t last_seq; /* extended last sequence number received */ uint32_t jitter; /* interarrival jitter */ uint32_t lsr; /* last sender report */ uint32_t dlsr; /* delay since last sender report */} rtcp_report_t;/* RTCP SR */typedef struct { uint32_t ssrc; /* sender generating this report */ uint32_t ntp_sec; /* NTP timestamp (seconds) */ uint32_t ntp_frac; /* NTP timestamp (fraction of second) */ uint32_t rtp_ts; /* RTP timestamp */ uint32_t pcount; /* sender's packet count */ uint32_t ocount; /* sender's octet count */ rtcp_report_t rr[1]; /* reception report block list */} rtcp_sr_t;/* RTCP RR */typedef struct { uint32_t ssrc; /* receiver generating this report */ rtcp_report_t rr[1]; /* reception report block list */} rtcp_rr_t;/* RTCP SDES (item) */typedef struct { uint8_t type; /* type of item */ uint8_t length; /* length of item (in octets) */ char data[1]; /* text, not null-terminated */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -