#include "XNetSDKTest.h"
#include "XNetSDKSyn.h"
#include "AVEnc_VideoWidget.h"

USE_NS_NETSDK_CFG
int TestOSDInfo()
{
	printf("%s\r\n", __FUNCTION__);
	char c = 0;
	while((c = getchar()) != 'q')
	{
		switch(c)
		{	
			//获取视频叠加
		case 'a':
			{
				char szOutBuffer[4096] = {0};
				char outbuffer[100] = {0};
				int len = 0;
				int  nInOutSize = sizeof(szOutBuffer);
				int nRet = 0;
				nRet =XSDK_DevGetSysConfigSyn(g_hDevice, JK_AVEnc_VideoWidget, szOutBuffer, &nInOutSize, 4000, EXCMD_CONFIG_GET);

				if(nRet >= 0)
				{
					JObjArrayObject<AVEnc_VideoWidget> cfg(NULL, JK_AVEnc_VideoWidget);
					cfg.Parse(szOutBuffer);

					if(cfg.objs.Size() > 0)
					{
						printf("CoversNum = %d\r\n", cfg.objs[0].CoversNum.Value());

						///设置通道名称
						cfg.objs[0].mChannelTitle.Name.SetValue("CAM02");
						
						/////设置通道名称的左位置（时间位置设置类似）
						int left = (1 / 20) * 8192;
						cfg.objs[0].mChannelTitleAttribute.RelativePos[0].SetValue(left);
						const char *pCfg = cfg.ToString();

						nRet = XSDK_DevSetChnConfigSyn(g_hDevice, 0, JK_Camera_Param, pCfg, strlen(pCfg), outbuffer, &len, 5000, EXCMD_CONFIG_SET);

						if(nRet >= 0)
						{
							printf("Set Success!\r\n");
						}
					}
				}
			}
			break;
			////设置设备时间
		case 'b':
			{
				char buf[32] = {0};
				time_t tNow = time(NULL);
				struct tm tmNow = *localtime(&tNow);
				sprintf(buf, "%04d-%02d-%02d %d:%d:%d", tmNow.tm_year + 1900, tmNow.tm_mon + 1, tmNow.tm_mday, tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec);

				XSDK_DevSynTime(g_hDevice, buf, 1);
			}
			break;
		}
	}
	return 0;
}
