/*****************************************************************************
* Copyright	 : Video Surveillance Telecom Co. Ltd, Shenzhen R&D Center
* Version	   : 0.0.1
*
* File Name	 : tptcppacket.h
* Description   : The defination of file headers
*
* Creation:	 : Cham Li, 04/04/2007
* Modification  :
*
******************************************************************************/



#ifndef __TPTCPPACKET_H__
#define __TPTCPPACKET_H__



#include "ssi.h"
#include "device_info.h"
#include "table_structs.h"

//TCP包头
#define VS_TCP_MAGIC	0x69707673 //"ipvs"

#define VS_TCP_SRC_CLIENT	0
#define VS_TCP_SRC_IPC		1

#define VS_TCP_PACKET_NOTIFY		0
#define VS_TCP_PACKET_REPORT		1
#define VS_TCP_PACKET_MEDIADATA	2
typedef struct
{
	U32 magic;		//VS_TCP_MAGIC(0x69707673; //"ipvs")
	U32 nSvrInst;		//VSS session ID，根据此ID可找到IPC/Client的所有信息
	U8 nDataSrc;		//0: Client	1: IPC
	U8 nPacketType;	//0: 通知消息 1: 媒体状态报告	 2: MediaData
	U16 nDataLength;	//后续数据包的长度
}VsTcpPacketHeader;

//媒体包发送/接收报告
/*
typedef struct
{
	U32	nPacket;	//已接收/发送媒体包个数
	U32 nPacketSeq;	//当前接收/发送媒体包序号
	U32	nLostPacketCnt;	//丢包数量（VSS仅从序号连续情况判断）
}VsMediaPacketReport;
*/

typedef struct
{
	U32 nSendLength;        //本次统计发送方发送的总数据长度，单位字节，由前端填写，服务器带回
	U32 nRecvLength;        //本次统计接收方接收的数据总长度，单位字节，由服务器填写
	U32 nUsedTime;                      //本次统计耗时，单位毫秒，由服务器填写，用于计算码率
	U32 nSendLengthTotal;           //仅供参考
	U32 nRecvLengthTotal;            //仅供参考
	U32 nUsedTimeTotal;               //仅供参考
	U32 nReportTime;                    //本次统计报告的生成时间，前端填写，服务器带回
}VsMediaPacketReport;

 



#define TP_VAR_MAX_LEN                      4096
#define TP_MSG_MAX_LEN                      sizeof(TP_MSG)

typedef struct 
{
    VsTcpPacketHeader	hdr;
    S8					data[TP_VAR_MAX_LEN];
} TP_MSG, *LPTP_MSG;

#define TP_HDR_SIZE					        sizeof(VsTcpPacketHeader)
#define TP_EXT_DATA_P(pMsg)					((S8*)(pMsg) + TP_HDR_SIZE)
#define TP_EXT_DATA_LEN(pMsg)					(((VsTcpPacketHeader*)(pMsg))->nDataLength)
#define TP_MSG_LEN(pMsg)						(TP_EXT_DATA_LEN(pMsg)+TP_HDR_SIZE)
#define IS_TP_MSG(pMsg)						(((VsTcpPacketHeader*)(pMsg))->magic==VS_TCP_MAGIC) 

#define TP_SET_EXT_DATA_LEN(pMsg,val)        (TP_EXT_DATA_LEN(pMsg) = (val))        
#define TP_SET_TYPE(pMsg, val)                (((VsTcpPacketHeader*)(pMsg))->nPacketType = (val))
#define TP_MSG_TYPE(pMsg)                     (((VsTcpPacketHeader*)(pMsg))->nPacketType)   


#define TP_ZERO_HDR_P(pMsg) \
do { memset((void*)(pMsg), 0, TP_HDR_SIZE); } while(0)

#define TP_INIT_MSG(pMsg)	\
do {  memset((void*)(pMsg), 0, TP_MSG_MAX_LEN); }while(0)
	
#define TP_HB_INTERVAL              10

#endif

