#include "version.h"
#include "PalmType.h"
#include "PalmChip.h"
#include "p_util.h"
#include "p_rtp.h"

#if defined CALL_SIP || defined CALL_MGCP

 CCHAR Sdp_cMAudio[] = "m=audio";
 CCHAR Sdp_cV0[] = "v=0";
 CCHAR Sdp_cRtpmap[] = "a=rtpmap:";
 CCHAR Sdp_cFmtp[] = "a=fmtp:";
 CCHAR Sdp_cRtcp[] = "a=rtcp:";
 CCHAR Sdp_cTelEvent[] = "telephone-event";

 CCHAR _cSampleRate[] = "/8000";

 CCHAR Sdp_cAudioMap[CODEC_NULL][5] = {
"G729", "G723", "PCMU", "PCMA", "GSM", "iLBC"
};
/*
static CCHAR _cYesLabel[] = "yes";
static CCHAR _cNoLabel[] = "no";
"a=silenceSupp:off - - - -"
*/
 void SdpAddAudioCode()
{
	DCHAR i;

	p_line_add_val(RtpGetLocalRtpType(Sys_pCodecType[0]));
	for (i = 1; i < SYS_CODEC_NUM; i ++)
	{
		if (Sys_pCodecType[i] != CODEC_NULL)
		{
			p_line_add_space();		
			p_line_add_val(RtpGetLocalRtpType(Sys_pCodecType[i]));
		}
	}
}

 void SdpAddDtmfType(UCHAR iDtmfPayload)
{
	p_line_add_c(Sdp_cRtpmap);
	p_line_add_val(iDtmfPayload);
	p_line_add_space();
	p_line_add_c(Sdp_cTelEvent);
	p_line_add_c(_cSampleRate);
	p_line_add_newline();
}

 void SdpAddDtmfFmtp(UCHAR iDtmfPayload)
{
	p_line_add_c(Sdp_cFmtp);
	p_line_add_val(iDtmfPayload);
	p_line_add_space();
	p_line_add_c((PCCHAR)"0-15");
	p_line_add_newline();
}

/*
void SdpAddPTime(UCHAR iPTime)
{
	p_line_add_c((PCCHAR)"a=ptime:");
	p_line_add_val((USHORT)iPTime);
	p_line_add_newline();
}
*/

 void SdpAddRtpMap(UCHAR iType)
{
	p_line_add_c(Sdp_cRtpmap);
	p_line_add_val(RtpGetLocalRtpType(iType));
	p_line_add_space();
	p_line_add_c(Sdp_cAudioMap[iType]);
	p_line_add_c(_cSampleRate);
	p_line_add_newline();
/*	if (iType == CODEC_G729)
	{
		p_line_add_c(Sdp_cFmtp);
		p_line_add_val(RtpGetLocalRtpType(iType));
		p_line_add_c((PCCHAR)" annexb=");
		if (Dsp_iOptions & USE_VAD_OR)
		{
			p_line_add_c(_cYesLabel);
		}
		else
		{
			p_line_add_c(_cNoLabel);
		}
		p_line_add_newline();
	}
*/
}

 void SdpAddRtpMapList()
{
	DCHAR i;

	for (i = 0; i < CODEC_NULL; i ++)
	{
		if (Sys_pCodecType[i] != CODEC_NULL)
		{
			SdpAddRtpMap(Sys_pCodecType[i]);
		}
	}
}


 UCHAR SdpAudioMatch(UCHAR iType)
{
	DCHAR i;

	if (iType < CODEC_NULL)
	{
		for (i = 0; i < SYS_CODEC_NUM; i ++)
		{
			if (Sys_pCodecType[i] != CODEC_NULL && Sys_pCodecType[i] == iType)
			{
				return iType;
			}
		}
	}
	return CODEC_NULL;
}

#endif
