#ifndef _PUB_SDP__H
#define _PUB_SDP__H

#define PUB_SDP_MAX_USER_NAME_LEN	64
#define PUB_SDP_MAX_SESS_ID_LEN		32
#define PUB_SDP_MAX_SESS_VER_LEN	16
#define PUB_SDP_MAX_ADDR_LEN		64
#define PUB_SDP_MAX_SESS_NAME_LEN	64
#define PUB_SDP_MAX_SESS_INFO_LEN	64
#define PUB_SDP_MAX_PAYLOAD_NUM		8
#define PUB_SDP_MAX_MEDIA_NUM		8
#define PUB_SDP_MAX_ATTR_NUM		16
#define PUB_SDP_MAX_ATTR_LEN		32

#define PUB_SDP_FLAG_V				0x00000001
#define PUB_SDP_FLAG_O				0x00000002
#define PUB_SDP_FLAG_S				0x00000004
#define PUB_SDP_FLAG_I				0x00000008
#define PUB_SDP_FLAG_U				0x00000010
#define PUB_SDP_FLAG_E				0x00000020
#define PUB_SDP_FLAG_P				0x00000040
#define PUB_SDP_FLAG_C				0x00000080
#define PUB_SDP_FLAG_B				0x00000100
#define PUB_SDP_FLAG_Z				0x00000200
#define PUB_SDP_FLAG_K				0x00000400
#define PUB_SDP_FLAG_A			0x00000800
#define PUB_SDP_FLAG_T				0x00001000
#define PUB_SDP_FLAG_R				0x00002000
#define PUB_SDP_FLAG_M				0x00004000

#define PUB_MGCP_PARA_FLAG_TFO      0x00000800

#define PUB_SDP_STR_TO_API			1
#define PUB_SDP_API_TO_STR			2

#define PUB_SDP_NET_TYPE_IN			1

#define PUB_SDP_ADDR_TYPE_IPV4		1
#define PUB_SDP_ADDR_TYPE_IPV6		2

#define PUB_SDP_ATTR_TYPE_RTPMAP	1
#define PUB_SDP_ATTR_TYPE_PTIME		2
#define PUB_SDP_ATTR_TYPE_FMTP		3
#define PUB_SDP_ATTR_TYPE_RECVONLY	4
#define PUB_SDP_ATTR_TYPE_SENDONLY	5
#define PUB_SDP_ATTR_TYPE_SENDRECV	6

#define PUB_SDP_MEDIA_TYPE_AUDIO	1
#define PUB_SDP_MEDIA_TYPE_VIDEO	2

#define PUB_SDP_PROTO_TYPE_RTP_AVP	1

typedef struct _PUB_SDP_V
{
	BYTE	value;
}PUB_SDP_V;

typedef struct _PUB_SDP_O
{
	char	userName[PUB_SDP_MAX_USER_NAME_LEN];
	char	sessId[PUB_SDP_MAX_SESS_ID_LEN];
	char	sessVer[PUB_SDP_MAX_SESS_VER_LEN];
	BYTE	netType;
	BYTE	addrType;
	char	addr[PUB_SDP_MAX_ADDR_LEN];
}PUB_SDP_O;

typedef struct _PUB_SDP_S
{
	char	sessName[PUB_SDP_MAX_SESS_NAME_LEN];
}PUB_SDP_S;

typedef struct _PUB_SDP_I
{
	char	info[PUB_SDP_MAX_SESS_INFO_LEN];
}PUB_SDP_I;

typedef struct _PUB_SDP_U
{
}PUB_SDP_U;

typedef struct _PUB_SDP_E
{
}PUB_SDP_E;

typedef struct _PUB_SDP_P
{
}PUB_SDP_P;

typedef struct _PUB_SDP_C
{
	BYTE	netType;
	BYTE	addrType;
	char	addr[PUB_SDP_MAX_ADDR_LEN];
}PUB_SDP_C;

typedef struct _PUB_SDP_B
{
}PUB_SDP_B;

typedef struct _PUB_SDP_Z
{
}PUB_SDP_Z;

typedef struct _PUB_SDP_K
{
}PUB_SDP_K;

typedef struct _PUB_SDP_T
{
	DWORD	startTime;
	DWORD	stopTime;
}PUB_SDP_T;

typedef struct _PUB_SDP_R
{
}PUB_SDP_R;

typedef struct _PUB_SDP_M
{
	BYTE					media;
	WORD					port;
	BYTE					portNum;
	BYTE					proto;
	BYTE					plNum;
	BYTE					payloads[PUB_SDP_MAX_PAYLOAD_NUM];
}PUB_SDP_M;

typedef struct _PUB_SDP_A
{
	BYTE					aType;
	char					aValue[PUB_SDP_MAX_ATTR_LEN];
}PUB_SDP_A;

typedef struct _PUB_SDP_ATTRS
{
	BYTE					num;
	PUB_SDP_A				attrs[PUB_SDP_MAX_ATTR_NUM];
}PUB_SDP_ATTRS;

typedef struct _PUB_SDP_MEDIA
{
	DWORD					flag;
	
	PUB_SDP_M				m;
	PUB_SDP_I				i;
	PUB_SDP_C				c;
	PUB_SDP_B		 		b;
	PUB_SDP_K				k;
	PUB_SDP_ATTRS			attrs;
}PUB_SDP_MEDIA;

typedef struct _PUB_SDP_MEDIAS
{
	BYTE					num;
	PUB_SDP_MEDIA			medias[PUB_SDP_MAX_MEDIA_NUM];
}PUB_SDP_MEDIAS;

typedef struct _PUB_SDP_MSG
{
	DWORD				flag;
	
	PUB_SDP_V 			v;
	PUB_SDP_O 			o;
	PUB_SDP_S 			s;
	PUB_SDP_I			i;
	PUB_SDP_U			u;
	PUB_SDP_E			e;
	PUB_SDP_P			p;
	PUB_SDP_C			c;
	PUB_SDP_B			b;
	PUB_SDP_Z			z;
	PUB_SDP_K			k;
	PUB_SDP_A			a;
	
	PUB_SDP_T			t;
	PUB_SDP_R			r;
	
	PUB_SDP_MEDIAS 		medias;
}PUB_SDP_MSG;

void pub_replace_all_lws(char *msg);
char *pub_strncpy(char *dest, const char *src, WORD length);
int pub_set_next_token(char *dest, char *buf, int endSeparator, char **next);

int pub_sdp_msg_init(PUB_SDP_MSG *sdp);
int pub_sdp_parse(PUB_SDP_MSG *sdp, char *buf, char **nextMsg, DWORD flag);
int pub_sdp_encode(PUB_SDP_MSG *sdp, char *dest, WORD flag);

int pub_sdp_net_type_conv(char *str, BYTE *netType, BYTE flag);
int pub_sdp_addr_type_conv(char *str, BYTE *addrType, BYTE flag);
int pub_sdp_attr_type_conv(char *str, BYTE *attrType, BYTE flag);
int pub_sdp_media_type_conv(char *str, BYTE *mediaType, BYTE flag);
int pub_sdp_proto_type_conv(char *str, BYTE *protoType, BYTE flag);

#endif
