⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 syn.h

📁 linux环境下用纯c写的RTP协议的通用开发库
💻 H
字号:
/*------------------------------------------------------------------------- * syn.h - tseq, tsgt, tslt, tsmax, tsmin *------------------------------------------------------------------------- */#ifndef SYN_H#define SYN_H#include <rtp.h>#include <pthread.h>#include <semaphore.h>#include <hash.h>#include <time.h>/* Macros to compare timestamps */#define SYN_TSWINDOW (1 << ((sizeof(mediatime_t) * 8) - 1))#define tseq(x, y) (x == y)#define tsgt(x, y) (x > y ? (x - y < SYN_TSWINDOW ? TRUE : FALSE) : (y - x < SYN_TSWINDOW ? FALSE : TRUE))#define tslt(x, y) (tsgt(y, x))#define tsmax(x, y) (tsgt(x, y) ? x : y)#define tsmin(x, y) (tslt(x, y) ? x : y)/* Read constants */#define SYN_CONTINUE                1#define SYN_NODATA		   -2#define SYN_BUFFERING		   -3#define SYN_READ_FLUSH		    0x1	/* Skip stale data */#define SYN_READ_BLOCK		    0x2/* Constants for synsynchronize */#define SYN_EXTERNALAHEAD          -2#define SYN_NOTADJUSTED             1#define SYN_ADJUSTED                2/* Commands for synctl */#define SYN_CTL_GETRTPSESSION       1#define SYN_CTL_ADDSYNCFD           2#define SYN_CTL_REMSYNCFD           3#define SYN_CTL_STREAM_SETREADFLAGS 4#define SYN_CTL_STREAM_GETREADFLAGS 5#define SYN_CTL_STREAM_ISBUFFERING  6#define SYN_CTL_STREAM_GETCLKRT     7#define SYN_CTL_STREAM_GETTYPE      8#define SYN_CTL_STREAM_GETLASTREAD  9#define SYN_CTL_STREAM_GETPARAM     10#define SYN_CTL_STREAM_GETLEEWAY    11	/* microsec */#define SYN_CTL_STREAM_SETLEEWAY    12	/* microsec */#define SYN_CTL_STREAM_GETJITTHRESH 13#define SYN_CTL_STREAM_SETJITTHRESH 14#define SYN_CTL_STREAM_GETBUFSPAN   15/* Constants for synsession */#define SYN_SSRCHTSZ		    11#define SYN_DFLTEVENTBUFSZ	    1024#define SYN_DFLTEVENTBUFCNT	    32#define SYN_DEFAULT_LEEWAY	    10000 /* microsec */#define SYN_FDCNT		    10#define SYN_BADFD                  -1struct synsession {  pthread_mutex_t       ssn_mutex;  pthread_cond_t        ssn_cond;  struct ht		*ssn_ssrcs;	/* hashtable ssrc -> synstream **/  struct eventqueue	ssn_events; /* event queue for internal use	*/  struct session	*ssn_session;	/* associated RTP layer session	*/  pthread_t		ssn_eventthr;	/* thread to run event loop	*/  int                   ssn_eventthrstat;  pthread_mutex_t       ssn_eventthrmutex;  pthread_t             ssn_recvthr;  int                   ssn_recvthrstat;  pthread_mutex_t       ssn_recvthrmutex;  pthread_mutex_t	ssn_getstreammutex;  int			ssn_syncfds[SYN_FDCNT];/* FDs to other synch sessions	*/};/* Stream types */#define SYN_STREAMTYPE_PACKET	0#define SYN_STREAMTYPE_SAMPLE	1#define SYN_STREAMTYPE_FRAME	2/* structure to hold state for receive stream */struct synstream {  int			sstm_type;	/* type of stream (e.g. sample)	*/  ssrc_t		sstm_ssrc;	/* stream's synchronization src */    int			sstm_readflags;	/* stream's readflags		*/  bool			sstm_buffering;	/* stream is still buffering	*/  bool			sstm_zombie;	/* marked for removal if true	*/  int			sstm_clkrt;	/* stream's clock rate		*/  int			sstm_refcnt;	/* to prevent bad pointers	*/  pthread_cond_t	sstm_readcond;	/* cond var for blocking read	*/  pthread_mutex_t	sstm_readmutex;	/* mutex associated with above	*/  mediatime_t		sstm_lastread;	/* timestamp of last data read	*/  struct timespec	sstm_clkx;	/* local time stamp		*/  mediatime_t		sstm_clky;	/* equivelant media time stamp	*/  mediatime_t		sstm_leeway;	/* how early data can be retn'd	*/  struct timespec	sstm_leewayts;	/* leeway in timespec format	*/  mediatime_t           sstm_jitthresh; /* jitter buffer (media ticks)  */  void *		sstm_parameters;/* type-dependant parameters	*/};  /* structure for passing synsynchto args between processes */struct synsyncargs {  char			sa_cname[256];  struct timespec	sa_ntp;  struct timespec	sa_localtime;};/* API Calls */  struct synsession *synopen(struct in_addr, int, int, int);int synclose(struct synsession *);int synstreamon(struct synsession *, ssrc_t, int, int, mediatime_t, void *);int synstreamoff(struct synsession *, ssrc_t);int synrebuffer(struct synsession *, ssrc_t);int synctl(struct synsession *, int, char *, ssrc_t);int synsources(struct synsession *, ssrc_t *, int);int synread(struct synsession *, ssrc_t, struct timespec *, mediatime_t *, char *, int, void *);/* Internal functions */int synbufspan(struct synsession *, struct synstream *, mediatime_t *, mediatime_t *);struct synstream *syngetstream(struct synsession *, ssrc_t);int synreleasestream(struct synsession *, struct synstream *);void syneventloop(struct synsession *);int synprocessevent(struct synsession *, struct event *, int);void synstreamdestroy(struct synstream *);int synnewdata(struct synsession *, ssrc_t);int synreadnextpacket(struct synsession *, struct synstream *, struct rtpln **);int synreadwait(struct synsession *, struct synstream *, struct rtpln *, mediatime_t, struct timespec, mediatime_t, struct timespec *);/* synchronization functions */void synsyncrecvthr(struct synsession *);int synsyncrecv(struct synsession *, int);int synsynchronize(struct synsession *, char *);int synsyncto(struct synsession *, struct cnamelist *, struct timespec *, struct timespec *);#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -