#ifndef _RTP__H
#define _RTP__H

#define RTP_MAX_NUM_OF_SAP		4
#define RTP_MAX_NUM_OF_PORT		1024
#define RTP_MAX_NUM_OF_PORT_1	1023

#define RTP_MAX_USER_NAME_LEN	16
#define RTP_MAX_PAYLOAD_SIZE	1024

#define RTP_MODE_INACTIVE		0
#define RTP_MODE_RECVONLY		1
#define RTP_MODE_SENDONLY		2
#define RTP_MODE_SENDRECV		3

typedef struct _RTP_SAP
{
	char	name[RTP_MAX_USER_NAME_LEN];	// User name
	  
	// Having received a RTP packet, the RTP module calls this function to send payloads to the user
	// If the user doesn't need to receive RTP packets, can leave the pointer to be NULL
	int 	(*rtp_recv)(WORD usrPort, WORD hdlPort, BYTE pt, WORD sn, BYTE *payload, WORD len);
    // Handshake every 10 seconds
	int		(*rtp_handshake)(WORD usrPort, WORD hdlPort, WORD rtpPort);
}RTP_SAP;

typedef struct _RTP_SESSION
{
	DWORD		dstIp;
	WORD		dstPort;
			
	BYTE		plType;		// Payload type
	BYTE		interval;	// RTP interval in ms
}RTP_SESSION;

typedef struct _RTP_PAYLOAD
{
	BYTE		padding[12];
	BYTE		payload[RTP_MAX_PAYLOAD_SIZE];
}RTP_PAYLOAD;

void rtp_init(void);
void rtp_timer(void);

int rtp_bind(RTP_SAP *sap);
int rtp_unbind(RTP_SAP *sap, BYTE sapIndex);

int rtp_set_mode(BYTE sapIndex, WORD usrPort, WORD hdlPort, BYTE mode);
int rtp_sess_update(BYTE sapIndex, WORD usrPort, WORD hdlPort, RTP_SESSION *sess);

int rtp_allocate_port(BYTE sapIndex, WORD usrPort, WORD *rtpPort);
int rtp_release_port(BYTE sapIndex, WORD usrPort, WORD rtpPort, WORD hdlPort);

int rtp_send(BYTE sapIndex, WORD usrPort, WORD hdlPort, WORD sn, RTP_PAYLOAD *payload, WORD len);

#endif
