// DlgVideoConfig.cpp : implementation file
//

#include "stdafx.h"
#include "MsSDKTest.h"
#include "DlgVideoConfig.h"
#include "MsSDKTestDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgVideoConfig dialog


CDlgVideoConfig::CDlgVideoConfig(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgVideoConfig::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgVideoConfig)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_ficker = 1;
	memset(m_productmodel, 0, sizeof(m_productmodel));
	m_bIsAmba = FALSE;
	m_bIsHisi = FALSE;
	m_bIsTi = FALSE;

	m_bIs5M = FALSE;
	m_bIs4M = FALSE;
	m_bIs3M = FALSE;

	m_bIsH264 = FALSE;
	m_bIsH265 = FALSE;
	m_bIsMpeg4 = FALSE;
	m_bIsMjpeg = FALSE;

	m_bIsSubMjpeg = FALSE;
}


void CDlgVideoConfig::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgVideoConfig)
	DDX_Control(pDX, IDC_COMBO_BITRATECONTROL_SUB, m_cbSubBitCtrl);
	DDX_Control(pDX, IDC_COMBO_BITRATECONTROL_MAIN, m_cbMainBitCtrl);
	DDX_Control(pDX, IDC_EDIT_TEXT, m_edText);
	DDX_Control(pDX, IDC_EDIT_IFRAME_SUB, m_edSubIFrm);
	DDX_Control(pDX, IDC_EDIT_IFRAME_MAIN, m_edMainIFrm);
	DDX_Control(pDX, IDC_COMBO_TEXT_POS, m_cbTextPos);
	DDX_Control(pDX, IDC_COMBO_DATE_POS, m_cbDatePos);
	DDX_Control(pDX, IDC_COMBO_RES_SUB, m_cbSubRes);
	DDX_Control(pDX, IDC_COMBO_RES_MAIN, m_cbMainRes);
	DDX_Control(pDX, IDC_COMBO_FRAMERATE_SUB, m_cbSubFrmRate);
	DDX_Control(pDX, IDC_COMBO_FRAMERATE_MAIN, m_cbMainFrmRate);
	DDX_Control(pDX, IDC_COMBO_DATE_FORMAT, m_cbDateFmt);
	DDX_Control(pDX, IDC_COMBO_CODEC_SUB, m_cbSubCodec);
	DDX_Control(pDX, IDC_COMBO_CODEC_MAIN, m_cbMainCodec);
	DDX_Control(pDX, IDC_COMBO_BITRATE_SUB, m_cbSubBitrate);
	DDX_Control(pDX, IDC_COMBO_BITRATE_MAIN, m_cbMainBitrate);
	DDX_Control(pDX, IDC_CHK_ENABLE_SUB, m_ChkEnableSub);
	DDX_Control(pDX, IDC_CHK_DISPLAY_TEXT, m_ChkOsdText);
	DDX_Control(pDX, IDC_CHK_DISPLAY_DATE, m_ChkOsdDate);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDlgVideoConfig, CDialog)
	//{{AFX_MSG_MAP(CDlgVideoConfig)
	ON_BN_CLICKED(IDC_CHK_DISPLAY_TEXT, OnChkEnableOsdText)
	ON_BN_CLICKED(IDC_CHK_DISPLAY_DATE, OnChkEnableOsdDate)
	ON_BN_CLICKED(IDC_CHK_ENABLE_SUB, OnChkEnableSub)
	ON_CBN_SELCHANGE(IDC_COMBO_CODEC_MAIN, OnMainChangeCodec)
	ON_CBN_SELCHANGE(IDC_COMBO_RES_MAIN, OnMainChangeRes)
	ON_CBN_SELCHANGE(IDC_COMBO_CODEC_SUB, OnSubChangeCodec)
	ON_CBN_SELCHANGE(IDC_COMBO_RES_SUB, OnSubChangeRes)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgVideoConfig message handlers
BOOL CDlgVideoConfig::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	Ms_Ipc_SystemInfo systemInfo = {0};
	if(!Ms_Ipc_GetSystemInfo(m_nUserId, &systemInfo))
		memcpy(m_productmodel, systemInfo.sModel, min(sizeof(m_productmodel), sizeof(systemInfo.sModel)));

	InitOsdInfo();
	OnChkEnableOsdText();
	OnChkEnableOsdDate();

	m_cbMainCodec.InsertString(0, "H.264");
	m_cbMainCodec.InsertString(1, "MPEG4");
	m_cbMainCodec.InsertString(2, "MJPEG");
	m_cbMainCodec.InsertString(3, "H.265");
	//m_cbMainCodec.SetCurSel(0);
	SelectComboString(CT_MAIN_CODEC, "H.264");
	m_cbMainBitCtrl.InsertString(0, "CBR");
	m_cbMainBitCtrl.InsertString(1, "VBR");
	//m_cbMainBitCtrl.SetCurSel(1);
	SelectComboValue(CT_MAIN_BITCTRL, 1);
	m_edMainIFrm.LimitText(2);
	m_edMainIFrm.SetWindowText("20");

	m_cbSubCodec.InsertString(0, "H.264");
	m_cbSubCodec.InsertString(1, "MPEG4");
	m_cbSubCodec.InsertString(3, "H.265");
	//m_cbSubCodec.SetCurSel(0);
	SelectComboString(CT_SUB_CODEC, "H.264");
	m_cbSubBitCtrl.InsertString(0, "CBR");
	m_cbSubBitCtrl.InsertString(1, "VBR");
	//m_cbSubBitCtrl.SetCurSel(1);
	SelectComboValue(CT_SUB_BITCTRL, 1);
	m_edSubIFrm.LimitText(2);
	m_edSubIFrm.SetWindowText("30");

 	InitMainStream();
 	InitSubStream();

	OnChkEnableSub();

	SetTimer(1001, 1000, NULL);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgVideoConfig::InitOsdInfo()
{
	m_edText.LimitText(22);
	m_cbTextPos.InsertString(0, "Top-Left");
	m_cbTextPos.InsertString(1, "Top-Right");
	m_cbTextPos.SetCurSel(0);

	m_cbDatePos.InsertString(0, "Top-Left");
	m_cbDatePos.InsertString(1, "Top-Right");
	m_cbDatePos.InsertString(2, "Bottom-Left");
	m_cbDatePos.InsertString(3, "Bottom-Right");
	m_cbDatePos.SetCurSel(1);

	m_cbDateFmt.InsertString(0, "YYYY/MM/DD");
	m_cbDateFmt.InsertString(1, "MM/DD/YYYY");
	m_cbDateFmt.InsertString(2, "DD/MM/YYYY");
	m_cbDateFmt.SetCurSel(1);
	
	Ms_Ipc_OSD osdInfo = {0};
	if(Ms_Ipc_GetOSD(m_nUserId, &osdInfo))
	{
		CMsSDKTestDlg::OutputTips("Init osd info failed. Please try again...");
		return;
	}
	m_ChkOsdText.SetCheck(osdInfo.bDisplayText==0?FALSE:TRUE);
	char szText[128] = {0};
	CMsSDKTestDlg::UTF8ToMB(szText, osdInfo.sText, sizeof(osdInfo.sText));
	m_edText.SetWindowText(szText);
	m_cbTextPos.SetCurSel(osdInfo.nTextPos);
	
	m_ChkOsdDate.SetCheck(osdInfo.bDisplayDate==0?FALSE:TRUE);
	m_cbDatePos.SetCurSel(osdInfo.nDatePos);
	m_cbDateFmt.SetCurSel(osdInfo.nDateFormat);
}

void CDlgVideoConfig::InitMainStream()
{
	int nSelIndex = -1;
	char sValue[64] = {0};
	Ms_Ipc_VideoConfig videoConfig = {0};
	videoConfig.nStreamIndex = IPC_STREAM_TYPE_MAIN;
	if(Ms_Ipc_GetVideoConfig(m_nUserId, &videoConfig))
	{
		CMsSDKTestDlg::OutputTips("Init primary stream info failed. Please try again...");
		return;
	}
	if(!IsTiIPC(m_productmodel))
	{
		videoConfig.nCodecType = (videoConfig.nCodecType==1?2:videoConfig.nCodecType);
	}
	int nIndex = 0;
	m_cbMainCodec.ResetContent();
	if(IsHisiIPC(m_productmodel))
	{
		m_cbMainCodec.InsertString(nIndex++, "H.265");
	}
	m_cbMainCodec.InsertString(nIndex++, "H.264");
	if(IsTiIPC(m_productmodel))
	{
		m_cbMainCodec.InsertString(nIndex++, "MPEG4");
	}
	m_cbMainCodec.InsertString(nIndex++, "MJPEG");
	//m_cbMainCodec.SetCurSel(videoConfig.nCodecType);
	SelectComboValue(CT_MAIN_CODEC, videoConfig.nCodecType);

	OnMainChangeCodec();
	//m_cbMainBitCtrl.SetCurSel(videoConfig.nBitRateControl);
	SelectComboValue(CT_MAIN_BITCTRL, videoConfig.nBitRateControl);
	_snprintf(sValue, sizeof(sValue)-1, "%d", videoConfig.nIFrameInterval);
	m_edMainIFrm.SetWindowText(sValue);
	_snprintf(sValue, sizeof(sValue)-1, "%d", videoConfig.nRtspPort);
	GetDlgItem(IDC_EDIT_RTSPPORT_MAIN)->SetWindowText(sValue);
	return;
}

void CDlgVideoConfig::InitSubStream()
{
	int nSelIndex = -1;
	char sValue[64] = {0};
	Ms_Ipc_VideoConfig videoConfig = {0};
	videoConfig.nStreamIndex = IPC_STREAM_TYPE_SUB;
	if(Ms_Ipc_GetVideoConfig(m_nUserId, &videoConfig))
	{
		CMsSDKTestDlg::OutputTips("Init secondary stream info failed. Please try again...");
		return;
	}
	if(!IsTiIPC(m_productmodel))
	{
		videoConfig.nCodecType = (videoConfig.nCodecType==1?2:videoConfig.nCodecType);
	}
	m_ChkEnableSub.SetCheck((videoConfig.bEnableSubStream==0?FALSE:TRUE)&&!(m_cbMainCodec.GetCurSel()==0 && m_cbMainRes.GetCurSel()==0));
	int nIndex = 0;
	m_cbSubCodec.ResetContent();
	if(IsHisiIPC(m_productmodel))
	{
		m_cbSubCodec.InsertString(nIndex++, _T("H.265"));
	}
	m_cbSubCodec.InsertString(nIndex++, "H.264");
	if(IsTiIPC(m_productmodel))
	{
		m_cbSubCodec.InsertString(nIndex++, "MPEG4");
	}
	m_cbSubCodec.InsertString(nIndex++, "MJPEG");
// 	if(m_cbSubCodec.GetCount() < 3 && videoConfig.nCodecType == 2)
// 		m_cbSubCodec.SetCurSel(0);
// 	else
// 		m_cbSubCodec.SetCurSel(videoConfig.nCodecType);
	SelectComboValue(CT_SUB_CODEC, videoConfig.nCodecType);

	//m_cbSubBitCtrl.SetCurSel(videoConfig.nBitRateControl);
	SelectComboValue(CT_SUB_BITCTRL, videoConfig.nBitRateControl);
	OnSubChangeCodec();
	OnSubChangeRes();
	InitSubFrameRate();
	InitSubBitrate();
	_snprintf(sValue, sizeof(sValue)-1, "%d", videoConfig.nIFrameInterval);
	m_edSubIFrm.SetWindowText(sValue);
	_snprintf(sValue, sizeof(sValue)-1, "%d", videoConfig.nRtspPort);
	GetDlgItem(IDC_EDIT_RTSPPORT_SUB)->SetWindowText(sValue);
	return;
}

void CDlgVideoConfig::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(TRUE);
	Ms_Ipc_OSD osdInfo = {0};
	osdInfo.bDisplayText = m_ChkOsdText.GetCheck();
	m_edText.GetWindowText(osdInfo.sText, sizeof(osdInfo.sText)-1);
	osdInfo.nTextPos = m_cbTextPos.GetCurSel();	
	osdInfo.bDisplayDate = m_ChkOsdDate.GetCheck();
	osdInfo.nDatePos = m_cbDatePos.GetCurSel();
	osdInfo.nDateFormat = m_cbDateFmt.GetCurSel();

	if(Ms_Ipc_SetOSD(m_nUserId, &osdInfo)){
		AfxMessageBox("Failed...");
		return;
	}else{
		CMsSDKTestDlg::OutputTips("Set Osd Successfully...");
	}

	Ms_Ipc_VideoConfig videoConfigMain = {0};
	Ms_Ipc_VideoConfig videoConfigSub = {0};
	//main
	{
		int nSelIndex = -1;
		char sValue[64] = {0};
		videoConfigMain.nStreamIndex = IPC_STREAM_TYPE_MAIN;
		//videoConfigMain.nCodecType = m_cbMainCodec.GetCurSel();
		m_cbMainCodec.GetWindowText(sValue, sizeof(sValue));
		if(!strcmp(sValue, "H.264")){
			videoConfigMain.nCodecType = 0;
		}else if(!strcmp(sValue, "MPEG4")){
			videoConfigMain.nCodecType = 1;
		}else if(!strcmp(sValue, "MJPEG")){
			videoConfigMain.nCodecType = 2;
		}else if(!strcmp(sValue, "H.265")){
			videoConfigMain.nCodecType = 3;
		}
		videoConfigMain.bEnableSubStream = m_ChkEnableSub.GetCheck();
		m_cbMainRes.GetWindowText(sValue, sizeof(sValue));
		if(!strcmp(sValue, "5M(2560*1920)")){
			videoConfigMain.nResWidth = 2560;
			videoConfigMain.nResHeight = 1920;
		}else if(!strcmp(sValue, "4M(2592*1520)")){
			videoConfigMain.nResWidth = 2592;
			videoConfigMain.nResHeight = 1520;
		}else if(!strcmp(sValue, "3M(2048*1536)")){
			videoConfigMain.nResWidth = 2048;
			videoConfigMain.nResHeight = 1536;
		}else if(!strcmp(sValue, "3M(2304*1296)")){
			videoConfigMain.nResWidth = 2304;
			videoConfigMain.nResHeight = 1296;
		}else if(!strcmp(sValue, "1080P(1920*1080)")){
			videoConfigMain.nResWidth = 1920;
			videoConfigMain.nResHeight = 1080;
		}else if(!strcmp(sValue, "2M(1600*1200)")){
			videoConfigMain.nResWidth = 1600;
			videoConfigMain.nResHeight = 1200;
		}else if(!strcmp(sValue, "1.3M(1280*960)")){
			videoConfigMain.nResWidth = 1280;
			videoConfigMain.nResHeight = 960;
		}else if(!strcmp(sValue, "720P(1280*720)")){
			videoConfigMain.nResWidth = 1280;
			videoConfigMain.nResHeight = 720;
		}else if(!strcmp(sValue, "D1(704*576)")){
			videoConfigMain.nResWidth = 704;
			videoConfigMain.nResHeight = 576;
		}else{ // 720P
			videoConfigMain.nResWidth = 1280;
			videoConfigMain.nResHeight = 720;
		}

		m_cbMainFrmRate.GetWindowText(sValue, sizeof(sValue));
		if(atoi(sValue) > 0){
			videoConfigMain.nMaxFrameRate = atoi(sValue);
		}else{
			videoConfigMain.nMaxFrameRate = 8;
		}

		m_cbMainBitrate.GetWindowText(sValue, sizeof(sValue));
		if(atoi(sValue) > 0){
			videoConfigMain.nBitRate = atoi(sValue);
		}else{
			videoConfigMain.nBitRate = 2048;
		}

		videoConfigMain.nBitRateControl = (BYTE)m_cbMainBitCtrl.GetCurSel()/*==1?1:2*/;//同步网页
		m_edMainIFrm.GetWindowText(sValue, sizeof(sValue));
		videoConfigMain.nIFrameInterval = atoi(sValue);
		//GetDlgItem(IDC_EDIT_RTSPPORT_MAIN)->GetWindowText(sValue, sizeof(sValue));
		videoConfigMain.nRtspPort = 554/*atoi(sValue)*/;
	}
	//sub
	{
		int nSelIndex = -1;
		char sValue[64] = {0};
		videoConfigSub.nStreamIndex = IPC_STREAM_TYPE_SUB;
		//videoConfigSub.nCodecType = m_cbSubCodec.GetCurSel();
		m_cbSubCodec.GetWindowText(sValue, sizeof(sValue));
		if(!strcmp(sValue, "H.264")){
			videoConfigSub.nCodecType = 0;
		}else if(!strcmp(sValue, "MPEG4")){
			videoConfigSub.nCodecType = 1;
		}else if(!strcmp(sValue, "MJPEG")){
			videoConfigSub.nCodecType = 2;
		}else if(!strcmp(sValue, "H.265")){
			videoConfigSub.nCodecType = 3;
		}
		videoConfigSub.bEnableSubStream = m_ChkEnableSub.GetCheck();
// 		if(m_cbSubRes.GetCount() < 5) // no 352*288 option
// 		{
// 			if(m_cbSubRes.GetCurSel() >= 2){
// 				videoConfigSub.nResolution = m_cbSubRes.GetCurSel() + 1;
// 			}else{
// 				videoConfigSub.nResolution = m_cbSubRes.GetCurSel();
// 			}
// 		}else{
// 			videoConfigSub.nResolution = m_cbSubRes.GetCurSel();
// 		}
		m_cbSubRes.GetWindowText(sValue, sizeof(sValue));
		if(!strcmp(sValue, "704*576")){
			videoConfigSub.nResWidth = 704;
			videoConfigSub.nResHeight = 576;
		}else if(!strcmp(sValue, "640*480")){
			videoConfigSub.nResWidth = 640;
			videoConfigSub.nResHeight = 480;
		}else if(!strcmp(sValue, "640*360")){
			videoConfigSub.nResWidth = 640;
			videoConfigSub.nResHeight = 360;
		}else if(!strcmp(sValue, "352*288")){
			videoConfigSub.nResWidth = 352;
			videoConfigSub.nResHeight = 288;
		}else if(!strcmp(sValue, "320*240")){
			videoConfigSub.nResWidth = 320;
			videoConfigSub.nResHeight = 240;
		}else if(!strcmp(sValue, "320*192")){
			videoConfigSub.nResWidth = 320;
			videoConfigSub.nResHeight = 192;
		}else if(!strcmp(sValue, "320*176")){
			videoConfigSub.nResWidth = 320;
			videoConfigSub.nResHeight = 176;
		}else{ // 720P
			videoConfigSub.nResWidth = 320;
			videoConfigSub.nResHeight = 240;
		}

		m_cbSubFrmRate.GetWindowText(sValue, sizeof(sValue));
		if(atoi(sValue) > 0){
			videoConfigSub.nMaxFrameRate = atoi(sValue);
		}else{
			videoConfigSub.nMaxFrameRate = 8;
		}

		m_cbSubBitrate.GetWindowText(sValue, sizeof(sValue));
		if(atoi(sValue) > 0){
			videoConfigSub.nBitRate = atoi(sValue);
		}else{
			videoConfigSub.nBitRate = 512;
		}

		videoConfigSub.nBitRateControl = (BYTE)m_cbSubBitCtrl.GetCurSel()/*==1?1:2*/;//同步网页
		m_edSubIFrm.GetWindowText(sValue, sizeof(sValue));
		videoConfigSub.nIFrameInterval = atoi(sValue);
		//GetDlgItem(IDC_EDIT_RTSPPORT_SUB)->GetWindowText(sValue, sizeof(sValue));
		videoConfigSub.nRtspPort = 554/*atoi(sValue)*/;
	}

	if(Ms_Ipc_SetVideoConfig(m_nUserId, &videoConfigSub)){
		AfxMessageBox("Failed...");
		return;
	}else{
		CMsSDKTestDlg::OutputTips("Set Secondary Video Config Successfully.");
	}
	if(Ms_Ipc_SetVideoConfig(m_nUserId, &videoConfigMain)){
		AfxMessageBox("Failed...");
		return;
	}else{
		CMsSDKTestDlg::OutputTips("Set Primary Video Config Successfully.");
	}
	if(IsTiIPC(m_productmodel))
		CMsSDKTestDlg::OutputTips("Set video parameters now. Wait a moment for reboot ipc...");
	CDialog::OnOK();
}

int CDlgVideoConfig::checkMegapixel()
{
	if(m_productmodel[0] == '\0')
		return -1;
	int nMmodel = 0;
	sscanf(m_productmodel, "MS-C%d", &nMmodel);	
	int productmodel[4] = {0};
	productmodel[0] = nMmodel/1000;
	productmodel[1] = (nMmodel%1000)/100;
	productmodel[2] = (nMmodel%100)/10;
	productmodel[3] = nMmodel%10;
	if(!IsHisiIPC(m_productmodel))
	{
		BOOL ms_130 = nMmodel == 2151 || nMmodel == 2251 || nMmodel == 2551 || nMmodel == 2351
			|| nMmodel == 2451 || nMmodel == 2651 || nMmodel == 2361 || nMmodel == 2661
			|| nMmodel == 2162 || nMmodel == 2262 || nMmodel == 2562 || nMmodel == 2362
			|| nMmodel == 2662 || nMmodel == 2471 || nMmodel == 2671 || nMmodel == 2172
			|| nMmodel == 2272 || nMmodel == 2572 || nMmodel == 2672 || nMmodel == 2372
			|| nMmodel == 2181 || nMmodel == 2581 || nMmodel == 2381 || nMmodel == 2681
			|| nMmodel == 2182 || nMmodel == 2582 || nMmodel == 2382 || nMmodel == 2682
			|| nMmodel == 2163 || nMmodel == 2263 || nMmodel == 2563 || nMmodel == 2363
			|| nMmodel == 2663 || nMmodel == 2191 || nMmodel == 2291 || nMmodel == 2591
			|| nMmodel == 2152 || nMmodel == 2153 || nMmodel == 2161 || nMmodel == 2171
			|| nMmodel == 2173 || nMmodel == 2153 || nMmodel == 2183 || nMmodel == 2192
			|| nMmodel == 2193 || nMmodel == 2452 || nMmodel == 2453 || nMmodel == 2463
			|| nMmodel == 2472 || nMmodel == 2473 || nMmodel == 2481 || nMmodel == 2482
			|| nMmodel == 2483 || nMmodel == 2491 || nMmodel == 2492 || nMmodel == 2493;
	
		BOOL ms_200 = nMmodel == 3251 || nMmodel == 3252 || nMmodel == 3253 || nMmodel == 3551 || nMmodel == 3351 || nMmodel == 3651
			|| nMmodel == 3361 || nMmodel == 3661 || nMmodel == 3262 || nMmodel == 3562
			|| nMmodel == 3362 || nMmodel == 3662 || nMmodel == 3671 || nMmodel == 3272
			|| nMmodel == 3572 || nMmodel == 3672 || nMmodel == 3372 || nMmodel == 3581
			|| nMmodel == 3381 || nMmodel == 3681 || nMmodel == 3582 || nMmodel == 3382
			|| nMmodel == 3682 || nMmodel == 3263 || nMmodel == 3563 || nMmodel == 3363		// A5s66 - MS-C6XXX xcb 
			|| nMmodel == 3663 || nMmodel == 3291 || nMmodel == 3591 || (productmodel[0] == 6 && productmodel[3] <= 3)
			|| nMmodel == 3261 || nMmodel == 3551 || nMmodel == 3271 || nMmodel == 3273
			|| nMmodel == 3281 || nMmodel == 3282 || nMmodel == 3283 || nMmodel == 3292
			|| nMmodel == 3293 || nMmodel == 3352 || nMmodel == 3353 || nMmodel == 3371
			|| nMmodel == 3373 || nMmodel == 3383 || nMmodel == 3391 || nMmodel == 3392
			|| nMmodel == 3393 || nMmodel == 3552 || nMmodel == 3553 || nMmodel == 3561
			|| nMmodel == 3571 || nMmodel == 3573 || nMmodel == 3583 || nMmodel == 3592
			|| nMmodel == 3593 || nMmodel == 3862 || nMmodel == 3863 || nMmodel == 3872
			|| nMmodel == 3962 || nMmodel == 3963 || nMmodel == 3972;
		
		BOOL ms_300 = nMmodel == 3556 || nMmodel == 3356 || nMmodel == 3656 || nMmodel == 3566
			|| nMmodel == 3366 || nMmodel == 3666 || nMmodel == 3576 || nMmodel == 3376
			|| nMmodel == 3586 || nMmodel == 3386 || nMmodel == 3686 || nMmodel == 3587
			|| nMmodel == 3387 || nMmodel == 3687 || nMmodel == 3567 || nMmodel == 3367		//A5s88  MS-C8XXX
			|| nMmodel == 3667 || nMmodel == 3596 || (productmodel[0] == 8 && (productmodel[3] == 6 || productmodel[3] == 7))
			|| nMmodel == 3557 || nMmodel == 3357 || nMmodel == 3577 || nMmodel == 3377
			|| nMmodel == 3396 || nMmodel == 3597 || nMmodel == 3397;

		BOOL ms_400 = nMmodel == 3468 || nMmodel == 3469 || nMmodel == 3478;
		
		BOOL ms_500 = nMmodel == 3658 || nMmodel == 3668 || nMmodel == 3678 || nMmodel == 3676
			|| nMmodel == 3678 || nMmodel == 3688 || nMmodel == 3689 || nMmodel == 3669
			|| nMmodel == 3659 || nMmodel == 3679 || nMmodel == 3698 || nMmodel == 3699;
	 			
		if(ms_130)
			return 1;//1.3M
		else if(ms_200)
			return 2;//2M
		else if(ms_300)
			return 3;//3M
		else if(ms_400)
			return 4;//4M
		else if(ms_500)
			return 0;//5M
				
		if(productmodel[1] == 9)//OV9712 720P
		{
			return -1;
		}								//1.3M || A5s55  MS-C5XXX --- 720P
		else if(productmodel[0] == 2 || (productmodel[0] == 5 && productmodel[3] <= 3))
		{
			return 1;
		}
		else
		{	//>1.3M
			int i = productmodel[2];
			int j = productmodel[3];
			if((i == 5||i == 6||i == 7)&&(j == 1 || j == 2 || j == 3)){//2M
				return 2;
			}else if((i == 5|| i == 6 || i == 7)&&(j == 6 || j == 7) || (nMmodel == 3681 || nMmodel == 3682)){//3M
				return 3;
			}else{//5M
				return 0;
			}
		}
	}
	else
	{
		BOOL ms_200 = nMmodel == 3862 || nMmodel == 3863 || nMmodel == 3872 || nMmodel == 2862
					|| nMmodel == 2863 || nMmodel == 2872 || nMmodel == 2962 || nMmodel == 2963
					|| nMmodel == 2972;
		BOOL ms_400 = nMmodel == 4462 || nMmodel == 4463 || nMmodel == 4472;
		
		if(ms_200)
			return 2;
		else if(ms_400)
			return 4;
		if(productmodel[0] == 1)
		{
			return 1;
		}
		else if(productmodel[0] == 2)
		{
			return 2;
		}
		else if(productmodel[0] == 3)
		{
			return 3;
		}
		else if(productmodel[0] == 4)
		{
			return 4;
		}
		else 
			return 0;
	}
}

void CDlgVideoConfig::OnChkEnableOsdText() 
{
	// TODO: Add your control notification handler code here
	if(m_ChkOsdText.GetCheck())
	{
		m_edText.EnableWindow(TRUE);
		m_cbTextPos.EnableWindow(TRUE);
	}
	else{
		m_edText.EnableWindow(FALSE);
		m_cbTextPos.EnableWindow(FALSE);
	}
}

void CDlgVideoConfig::OnChkEnableOsdDate() 
{
	// TODO: Add your control notification handler code here
	if(m_ChkOsdDate.GetCheck())
	{
		m_cbDatePos.EnableWindow(TRUE);
		m_cbDateFmt.EnableWindow(TRUE);
	}
	else{
		m_cbDatePos.EnableWindow(FALSE);
		m_cbDateFmt.EnableWindow(FALSE);
	}	
}

void CDlgVideoConfig::OnChkEnableSub() 
{
	// TODO: Add your control notification handler code here
	int nSubCodecIndex = m_cbSubCodec.GetCurSel();
	BOOL bIsAmba = IsAmbaIPC(m_productmodel);
	if(m_ChkEnableSub.GetCheck())
	{
		m_cbSubCodec.EnableWindow(TRUE);
		m_cbSubRes.EnableWindow(TRUE);
		m_cbSubFrmRate.EnableWindow(TRUE);
		m_cbSubBitrate.EnableWindow(!m_bIsSubMjpeg);
		m_cbSubBitCtrl.EnableWindow(!m_bIsSubMjpeg);
		m_edSubIFrm.EnableWindow(!m_bIsSubMjpeg);
	}
	else{
		m_cbSubCodec.EnableWindow(FALSE);
		m_cbSubRes.EnableWindow(FALSE);
		m_cbSubFrmRate.EnableWindow(FALSE);
		m_cbSubBitrate.EnableWindow(FALSE);
		m_cbSubBitCtrl.EnableWindow(FALSE);
		m_edSubIFrm.EnableWindow(FALSE);
	}	
}

void CDlgVideoConfig::OnMainChangeCodec() 
{
	// TODO: Add your control notification handler code here
	Ms_Ipc_VideoConfig videoConfig = {0};
	videoConfig.nStreamIndex = IPC_STREAM_TYPE_MAIN;
	Ms_Ipc_GetVideoConfig(m_nUserId, &videoConfig);
	if(!IsTiIPC(m_productmodel))
	{
		videoConfig.nCodecType = (videoConfig.nCodecType==1?2:videoConfig.nCodecType);
	}

	//int codecIndex = m_cbMainCodec.GetCurSel();
	UpdateInformation();
	m_cbMainRes.ResetContent();
	//BOOL bIsAmba = IsAmbaIPC(m_productmodel);
//	if(codecIndex == 0 || codecIndex == 1)
	{//H.264 MPEG4
		int productMegapixel = checkMegapixel();
		if(productMegapixel == -1){ // 720P
			m_cbMainRes.InsertString(0, "720P(1280*720)");
			m_cbMainRes.InsertString(1, "D1(704*576)");
			
// 			m_cbMainRes.SetCurSel(0);
// 
// 			if (videoConfig.nResolution == RESOLUTION_720P)
// 			{
// 				m_cbMainRes.SelectString(-1, "720P(1280*720)");
// 			} 
// 			else if (videoConfig.nResolution == RESOLUTION_D1)
// 			{
// 				m_cbMainRes.SelectString(-1, "D1(704*576)");
// 			}
		}else if(productMegapixel == 1){ // 1.3M
			m_cbMainRes.InsertString(0, "1.3M(1280*960)");
			m_cbMainRes.InsertString(1, "720P(1280*720)");
			m_cbMainRes.InsertString(2, "D1(704*576)");
			
// 			m_cbMainRes.SetCurSel(0);
// 
// 			if (videoConfig.nResolution == RESOLUTION_1_3M)
// 			{
// 				m_cbMainRes.SetCurSel(0);
// 			} 
// 			else if(videoConfig.nResolution == RESOLUTION_720P)
// 			{
// 				m_cbMainRes.SetCurSel(1);
// 			}
// 			else if (videoConfig.nResolution == RESOLUTION_D1)
// 			{
// 				m_cbMainRes.SetCurSel(2);
// 			}
		}
		else if(productMegapixel == 2){ // 2M, 1080P
			int n2MResIndex = 0;
			m_cbMainRes.InsertString(n2MResIndex++, "1080P(1920*1080)");
			if(!IsHisiIPC(m_productmodel))
				m_cbMainRes.InsertString(n2MResIndex++, "2M(1600*1200)");
			m_cbMainRes.InsertString(n2MResIndex++, "1.3M(1280*960)");
			m_cbMainRes.InsertString(n2MResIndex++, "720P(1280*720)");
			m_cbMainRes.InsertString(n2MResIndex++, "D1(704*576)");
			
// 			m_cbMainRes.SetCurSel(0);
// 
// 			if (videoConfig.nResolution == RESOLUTION_1080P)
// 			{
// 				m_cbMainRes.SetCurSel(0);
// 			} 
// 			else if (videoConfig.nResolution == RESOLUTION_2M)
// 			{
// 				m_cbMainRes.SetCurSel(1);
// 			} 
// 			else if (videoConfig.nResolution == RESOLUTION_1_3M)
// 			{
// 				m_cbMainRes.SetCurSel(2);
// 			} 
// 			else if(videoConfig.nResolution == RESOLUTION_720P)
// 			{
// 				m_cbMainRes.SetCurSel(3);
// 			}
// 			else if (videoConfig.nResolution == RESOLUTION_D1)
// 			{
// 				m_cbMainRes.SetCurSel(4);
// 			}
		}
		else if(productMegapixel == 3)
		{ // 3M
			int n3MResIndex = 0;
			if(!m_bIsMpeg4)// !MPEG4
			{
				if(m_bIsHisi)
					m_cbMainRes.InsertString(n3MResIndex++, "3M(2304*1296)");
				else
					m_cbMainRes.InsertString(n3MResIndex++, "3M(2048*1536)");
			}
			m_cbMainRes.InsertString(n3MResIndex++, "1080P(1920*1080)");
			if(!IsHisiIPC(m_productmodel))
				m_cbMainRes.InsertString(n3MResIndex++, "2M(1600*1200)");
			m_cbMainRes.InsertString(n3MResIndex++, "1.3M(1280*960)");
			m_cbMainRes.InsertString(n3MResIndex++, "720P(1280*720)");
			m_cbMainRes.InsertString(n3MResIndex++, "D1(704*576)");
			
// 			m_cbMainRes.SetCurSel(0);
// 
// 			if ((codecIndex == 0 || ((!bIsAmba && codecIndex == 2) || (bIsAmba && codecIndex == 1))) && videoConfig.nResolution == RESOLUTION_3M)
// 			{
// 				m_cbMainRes.SetCurSel(n3MResIndex-6);
// 			} 
// 			else if (videoConfig.nResolution == RESOLUTION_1080P)
// 			{
// 				m_cbMainRes.SetCurSel(n3MResIndex-5);
// 			} 
// 			else if (videoConfig.nResolution == RESOLUTION_2M)
// 			{
// 				m_cbMainRes.SetCurSel(n3MResIndex-4);
// 			} 
// 			else if (videoConfig.nResolution == RESOLUTION_1_3M)
// 			{
// 				m_cbMainRes.SetCurSel(n3MResIndex-3);
// 			} 
// 			else if(videoConfig.nResolution == RESOLUTION_720P)
// 			{
// 				m_cbMainRes.SetCurSel(n3MResIndex-2);
// 			}
// 			else if (videoConfig.nResolution == RESOLUTION_D1)
// 			{
// 				m_cbMainRes.SetCurSel(n3MResIndex-1);
// 			}
		}
		else if(productMegapixel == 4)
		{ // 4M
			int n4MResIndex = 0;
			if(m_bIsHisi)
			{
				m_cbMainRes.InsertString(n4MResIndex++, "4M(2592*1520)");
			}
			if(!m_bIsMpeg4)// !MPEG4
			{
				if(m_bIsHisi)
					m_cbMainRes.InsertString(n4MResIndex++, "3M(2304*1296)");
				else
					m_cbMainRes.InsertString(n4MResIndex++, "3M(2048*1536)");
			}
			m_cbMainRes.InsertString(n4MResIndex++, "1080P(1920*1080)");
			if(!IsHisiIPC(m_productmodel))
				m_cbMainRes.InsertString(n4MResIndex++, "2M(1600*1200)");
			m_cbMainRes.InsertString(n4MResIndex++, "1.3M(1280*960)");
			m_cbMainRes.InsertString(n4MResIndex++, "720P(1280*720)");
			m_cbMainRes.InsertString(n4MResIndex++, "D1(704*576)");
		}
		else
		{
			int n5MResIndex = 0;
			if(m_bIsH264)
			{
				m_cbMainRes.InsertString(n5MResIndex++, "5M(2560*1920)");
			}
			if(m_bIsHisi)
			{
				m_cbMainRes.InsertString(n5MResIndex++, "4M(2592*1520)");
			}
			if(!m_bIsMpeg4)//H264  MJPEG H265
			{
				if(m_bIsHisi)
					m_cbMainRes.InsertString(n5MResIndex++, "3M(2304*1296)");
				else
					m_cbMainRes.InsertString(n5MResIndex++, "3M(2048*1536)");
			}
			m_cbMainRes.InsertString(n5MResIndex++, "1080P(1920*1080)");
			if(!IsHisiIPC(m_productmodel))
				m_cbMainRes.InsertString(n5MResIndex++, "2M(1600*1200)");
			m_cbMainRes.InsertString(n5MResIndex++, "1.3M(1280*960)");
			m_cbMainRes.InsertString(n5MResIndex++, "720P(1280*720)");
			m_cbMainRes.InsertString(n5MResIndex++, "D1(704*576)");
			
// 			m_cbMainRes.SetCurSel(0);
// 
// 			if (codecIndex == 0 && videoConfig.nResolution == RESOLUTION_5M)
// 			{
// 				if(n5MResIndex-7 >= 0){
// 					m_cbMainRes.SetCurSel(n5MResIndex-7);
// 				}else if(n5MResIndex-7 < 0){
// 					m_cbMainRes.SetCurSel(n5MResIndex-6);
// 				}
// 			} 
// 			else if ((codecIndex == 0 || ((!bIsAmba && codecIndex == 2) || (bIsAmba && codecIndex == 1))) && videoConfig.nResolution == RESOLUTION_3M)
// 			{
// 				m_cbMainRes.SetCurSel(n5MResIndex-6);
// 			} 
// 			else if (videoConfig.nResolution == RESOLUTION_1080P)
// 			{
// 				m_cbMainRes.SetCurSel(n5MResIndex-5);
// 			} 
// 			else if (videoConfig.nResolution == RESOLUTION_2M)
// 			{
// 				m_cbMainRes.SetCurSel(n5MResIndex-4);
// 			} 
// 			else if (videoConfig.nResolution == RESOLUTION_1_3M)
// 			{
// 				m_cbMainRes.SetCurSel(n5MResIndex-3);
// 			} 
// 			else if (videoConfig.nResolution == RESOLUTION_720P)
// 			{
// 				m_cbMainRes.SetCurSel(n5MResIndex-2);
// 			}
// 			else if (videoConfig.nResolution == RESOLUTION_D1)
// 			{
// 				m_cbMainRes.SetCurSel(n5MResIndex-1);
// 			}
		}
		char sResString[64] = {0};
		_snprintf(sResString, sizeof(sResString)-1, "%d*%d", videoConfig.nResWidth, videoConfig.nResHeight);
		SelectComboString(CT_MAIN_RES, sResString);
	}
/*	else{//MJPEG
		//mainBitRate.options[4].selected = true;//2048
		((CComboBox*)GetDlgItem(IDC_COMBO5))->EnableWindow(FALSE);
// 		mainBitRate.disabled = true;
// 		mainBitRateControl.options[0].selected = true;
// 		mainBitRateControl.disabled = true; 
		m_cbMainRes.InsertString(0, _T("3M(2048*1536)"));
		m_cbMainRes.InsertString(1, _T("2M(1600*1200)"));

		if(strcmp(_IpcViewInfo.sResolution, "2048*1536") == 0)
		{
			m_cbMainRes.SetCurSel(0);
		}
		else if (strcmp(_IpcViewInfo.sResolution, "1600*1200") == 0)
		{
			m_cbMainRes.SetCurSel(1);
		}
 	}	
*/	
	
	OnMainChangeRes();
}

void CDlgVideoConfig::OnMainChangeRes() 
{
	// TODO: Add your control notification handler code here
	Ms_Ipc_VideoConfig videoConfig = {0};
	videoConfig.nStreamIndex = IPC_STREAM_TYPE_MAIN;
	Ms_Ipc_GetVideoConfig(m_nUserId, &videoConfig);
	if(!IsTiIPC(m_productmodel))
	{
		videoConfig.nCodecType = (videoConfig.nCodecType==1?2:videoConfig.nCodecType);
	}

	int productMegapixel = checkMegapixel();
	UpdateInformation();
// 	int codecIndex = m_cbMainCodec.GetCurSel();
// 	int resIndex = m_cbMainRes.GetCurSel();
// 	BOOL bIsAmba = IsAmbaIPC(m_productmodel);
	if(m_bIsTi)
	{
		if(m_cbSubCodec.GetCount() <= 2)
		{
			m_cbSubCodec.ResetContent();
			m_cbSubCodec.InsertString(0, "H.264");
			m_cbSubCodec.InsertString(1, "MPEG4");
			m_cbSubCodec.InsertString(2, "MJPEG");
			//m_cbSubCodec.SetCurSel(0);
			SelectComboValue(CT_SUB_CODEC, videoConfig.nCodecType);
		}
	}
	if(m_bIsMjpeg)
	{
		m_cbMainBitrate.EnableWindow(FALSE);
		m_cbMainBitCtrl.EnableWindow(FALSE);
		m_edMainIFrm.EnableWindow(FALSE);
	}
	else
	{
		m_cbMainBitrate.EnableWindow(TRUE);
		m_cbMainBitCtrl.EnableWindow(TRUE);
		m_edMainIFrm.EnableWindow(TRUE);
	}

	m_cbMainFrmRate.ResetContent();
//	if(codecIndex == 0 || codecIndex == 1)
	{//H.264 or MPEG4
		int nIndex = 0;
		m_cbMainFrmRate.InsertString(nIndex++, "1");
		m_cbMainFrmRate.InsertString(nIndex++, "2");
		m_cbMainFrmRate.InsertString(nIndex++, "3");
		m_cbMainFrmRate.InsertString(nIndex++, "4");
		m_cbMainFrmRate.InsertString(nIndex++, "5");
		m_cbMainFrmRate.InsertString(nIndex++, "6");
		m_cbMainFrmRate.InsertString(nIndex++, "7");
		m_cbMainFrmRate.InsertString(nIndex++, "8");
		if(productMegapixel == 0 && m_bIs5M){//5M
			//m_cbMainFrmRate.SelectString(-1, "8");
			SelectComboValue(CT_MAIN_FRAME, 8);
		}else if(((productMegapixel == 3 || productMegapixel == 0)/*Support 5M||3M*/ && m_bIs3M && !m_bIsHisi) || (productMegapixel == 4 && m_bIs4M)){// AMBA or Ti select 3M, or Hisi select 4M
			m_cbMainFrmRate.InsertString(nIndex++, "9");
			m_cbMainFrmRate.InsertString(nIndex++, "10");
			m_cbMainFrmRate.InsertString(nIndex++, "11");
			m_cbMainFrmRate.InsertString(nIndex++, "12");
			m_cbMainFrmRate.InsertString(nIndex++, "13");
			m_cbMainFrmRate.InsertString(nIndex++, "14");
			m_cbMainFrmRate.InsertString(nIndex++, "15");
			// 3M主码流，主码流帧率增加到20fps
			m_cbMainFrmRate.InsertString(nIndex++, "16");
			m_cbMainFrmRate.InsertString(nIndex++, "17");
			m_cbMainFrmRate.InsertString(nIndex++, "18");
			m_cbMainFrmRate.InsertString(nIndex++, "19");
			m_cbMainFrmRate.InsertString(nIndex++, "20");
// 			char sFrameRate[256] = {0};
// 			_snprintf(sFrameRate, sizeof(sFrameRate), "%d", videoConfig.nMaxFrameRate);
// 			if(CB_ERR == m_cbMainFrmRate.SelectString(-1, sFrameRate))
//  				m_cbMainFrmRate.SelectString(-1, "20");
			SelectComboValue(CT_MAIN_FRAME, videoConfig.nMaxFrameRate);
		}else{
			m_cbMainFrmRate.InsertString(nIndex++, "9");
			m_cbMainFrmRate.InsertString(nIndex++, "10");
			m_cbMainFrmRate.InsertString(nIndex++, "11");
			m_cbMainFrmRate.InsertString(nIndex++, "12");
			m_cbMainFrmRate.InsertString(nIndex++, "13");
			m_cbMainFrmRate.InsertString(nIndex++, "14");
			m_cbMainFrmRate.InsertString(nIndex++, "15");
			m_cbMainFrmRate.InsertString(nIndex++, "16");
			m_cbMainFrmRate.InsertString(nIndex++, "17");
			m_cbMainFrmRate.InsertString(nIndex++, "18");
			m_cbMainFrmRate.InsertString(nIndex++, "19");
			m_cbMainFrmRate.InsertString(nIndex++, "20");
			m_cbMainFrmRate.InsertString(nIndex++, "21");
			m_cbMainFrmRate.InsertString(nIndex++, "22");
			m_cbMainFrmRate.InsertString(nIndex++, "23");
			m_cbMainFrmRate.InsertString(nIndex++, "24");
			m_cbMainFrmRate.InsertString(nIndex++, "25");
			if(m_ficker == 1){//50HZ
// 				char sFrameRate[256] = {0};
// 				_snprintf(sFrameRate, sizeof(sFrameRate), "%d", videoConfig.nMaxFrameRate);
// 				if(CB_ERR == m_cbMainFrmRate.SelectString(-1, sFrameRate))
// 					m_cbMainFrmRate.SelectString(-1, "25");
				SelectComboValue(CT_MAIN_FRAME, videoConfig.nMaxFrameRate);
			}else{
				m_cbMainFrmRate.InsertString(nIndex++, "26");
				m_cbMainFrmRate.InsertString(nIndex++, "27");
				m_cbMainFrmRate.InsertString(nIndex++, "28");
				m_cbMainFrmRate.InsertString(nIndex++, "29");
				m_cbMainFrmRate.InsertString(nIndex++, "30");

// 				char sFrameRate[256] = {0};
// 				_snprintf(sFrameRate, sizeof(sFrameRate), "%d", videoConfig.nMaxFrameRate);
// 				if(CB_ERR == m_cbMainFrmRate.SelectString(-1, sFrameRate))
// 					m_cbMainFrmRate.SelectString(-1, "30");
				SelectComboValue(CT_MAIN_FRAME, videoConfig.nMaxFrameRate);
			}	
		}
	}

	//if((productMegapixel == 0 && mainResolution.selectedIndex == 0) || (productMegapixel == 3 && mainResolution.selectedIndex == 0)||(productMegapixel == 0 && mainResolution.selectedIndex == 1)){//5M,3M
	if((productMegapixel == 0 && m_bIs5M)){//5M
		//bruce.milesight add for disable substream
		m_ChkEnableSub.SetCheck(FALSE);
		m_ChkEnableSub.EnableWindow(FALSE);
		OnChkEnableSub();
		//end disable substream
	}
	else{
		m_ChkEnableSub.EnableWindow(TRUE);
		//m_ChkEnableSub.SetCheck(m_subVideoConfig.bEnableSubStream==0?FALSE:TRUE);
		//OnChkEnableSub();
		m_cbSubFrmRate.ResetContent();
		int nIndex = 0;
		m_cbSubFrmRate.InsertString(nIndex++, "1");
		m_cbSubFrmRate.InsertString(nIndex++, "2");
		m_cbSubFrmRate.InsertString(nIndex++, "3");
		m_cbSubFrmRate.InsertString(nIndex++, "4");
		m_cbSubFrmRate.InsertString(nIndex++, "5");
		m_cbSubFrmRate.InsertString(nIndex++, "6");
		m_cbSubFrmRate.InsertString(nIndex++, "7");
		m_cbSubFrmRate.InsertString(nIndex++, "8");
		m_cbSubFrmRate.InsertString(nIndex++, "9");
		m_cbSubFrmRate.InsertString(nIndex++, "10");
		m_cbSubFrmRate.InsertString(nIndex++, "11");
		m_cbSubFrmRate.InsertString(nIndex++, "12");
		m_cbSubFrmRate.InsertString(nIndex++, "13");
		m_cbSubFrmRate.InsertString(nIndex++, "14");
		m_cbSubFrmRate.InsertString(nIndex++, "15");
// 		if((productMegapixel == 3 && ((!bIsAmba && codecIndex == 2) || (bIsAmba && codecIndex == 1)) && resIndex == 0) || (productMegapixel == 0 &&  ((codecIndex == 0 && resIndex == 1) || (codecIndex == 2 && resIndex == 0)))){//主码流3M，限制次码流帧率
// 			m_cbSubFrmRate.SelectString(-1, "15");
// 		}
// 		else if(m_cbSubFrmRate.GetCount() <= 15){
			m_cbSubFrmRate.InsertString(nIndex++, "16");
			m_cbSubFrmRate.InsertString(nIndex++, "17");
			m_cbSubFrmRate.InsertString(nIndex++, "18");
			m_cbSubFrmRate.InsertString(nIndex++, "19");
			m_cbSubFrmRate.InsertString(nIndex++, "20");
			if(!(m_bIs4M && m_bIsHisi))
			{
				m_cbSubFrmRate.InsertString(nIndex++, "21");
				m_cbSubFrmRate.InsertString(nIndex++, "22");
				m_cbSubFrmRate.InsertString(nIndex++, "23");
				m_cbSubFrmRate.InsertString(nIndex++, "24");
				m_cbSubFrmRate.InsertString(nIndex++, "25");

				if(m_ficker == 1){//50HZ
					//m_cbSubFrmRate.SelectString(-1, "25");
					SelectComboValue(CT_SUB_FRAME, 25);
				}else{
					m_cbSubFrmRate.InsertString(nIndex++, "26");
					m_cbSubFrmRate.InsertString(nIndex++, "27");
					m_cbSubFrmRate.InsertString(nIndex++, "28");
					m_cbSubFrmRate.InsertString(nIndex++, "29");
					m_cbSubFrmRate.InsertString(nIndex++, "30");

					//m_cbSubFrmRate.SelectString(-1, "30");
					SelectComboValue(CT_SUB_FRAME, 30);
				}
			}
// 		}
	}
	InitMainBitrate();//bruce add 3.0.07
	InitSubFrameRate();
	
	if(m_bIsTi && (m_bIsMpeg4 || m_bIsMjpeg)) // Amba 主次码流可同时为MJPEG
	{
	//	m_cbMainBitrate.SetCurSel(8);
		m_cbSubCodec.ResetContent();
		m_cbSubCodec.InsertString(0, "H.264");
// 		m_cbSubCodec.InsertString(1, "MPEG4");
// 		m_cbSubCodec.SetCurSel(0);
		SelectComboString(CT_SUB_CODEC, _T("H.264"));
		OnSubChangeCodec();
	}
	if(m_bIsMjpeg)
		SelectComboValue(CT_MAIN_BITRATE, 4096); // 4096
}

void CDlgVideoConfig::InitMainBitrate()
{
	Ms_Ipc_VideoConfig videoConfig = {0};
	videoConfig.nStreamIndex = IPC_STREAM_TYPE_MAIN;
	Ms_Ipc_GetVideoConfig(m_nUserId, &videoConfig);
	if(!IsTiIPC(m_productmodel))
	{
		videoConfig.nCodecType = (videoConfig.nCodecType==1?2:videoConfig.nCodecType);
	}

	int productMegapixel = checkMegapixel();
	UpdateInformation();
	BOOL bIsAmba = IsAmbaIPC(m_productmodel);
	m_cbMainBitrate.ResetContent();
	int nMainBitrateIndex = 0;
	m_cbMainBitrate.InsertString(nMainBitrateIndex++, "16");
	m_cbMainBitrate.InsertString(nMainBitrateIndex++, "32");
	m_cbMainBitrate.InsertString(nMainBitrateIndex++, "64");
	m_cbMainBitrate.InsertString(nMainBitrateIndex++, "128");
	m_cbMainBitrate.InsertString(nMainBitrateIndex++, "256");
	m_cbMainBitrate.InsertString(nMainBitrateIndex++, "512");
	m_cbMainBitrate.InsertString(nMainBitrateIndex++, "1024");
	m_cbMainBitrate.InsertString(nMainBitrateIndex++, "1536");
	m_cbMainBitrate.InsertString(nMainBitrateIndex++, "2048"); // index = 8
	m_cbMainBitrate.InsertString(nMainBitrateIndex++, "3072");
	m_cbMainBitrate.InsertString(nMainBitrateIndex++, "4096");
	m_cbMainBitrate.InsertString(nMainBitrateIndex++, "5120");
	m_cbMainBitrate.InsertString(nMainBitrateIndex++, "6144");
	
	int codecIndex = m_cbMainCodec.GetCurSel();
	int resIndex = m_cbMainRes.GetCurSel();
	if((productMegapixel == 0 && m_bIs5M) || ((productMegapixel == 3 || productMegapixel == 0) && m_bIs3M)){//5M,3M
// 		char sMainBitrate[32] = {0};
// 		itoa(videoConfig.nBitRate, sMainBitrate, 10);
// 		m_cbMainBitrate.SetCurSel(getMainBitRateIndex(sMainBitrate));
// 		if((!bIsAmba && codecIndex == 2) || (bIsAmba && codecIndex == 1))
// 			m_cbMainBitrate.SetCurSel(8); // 2048
		SelectComboValue(CT_MAIN_BITRATE, videoConfig.nBitRate);
	}else{
		m_cbMainBitrate.InsertString(nMainBitrateIndex++, "7168");
		m_cbMainBitrate.InsertString(nMainBitrateIndex++, "8192");
		m_cbMainBitrate.InsertString(nMainBitrateIndex++, "10240");
		m_cbMainBitrate.InsertString(nMainBitrateIndex++, "12288");
		m_cbMainBitrate.InsertString(nMainBitrateIndex++, "14336");
		m_cbMainBitrate.InsertString(nMainBitrateIndex++, "16384");
// 		char sMainBitrate[32] = {0};
// 		itoa(videoConfig.nBitRate, sMainBitrate, 10);
// 		m_cbMainBitrate.SetCurSel(getMainBitRateIndex(sMainBitrate));	
		SelectComboValue(CT_MAIN_BITRATE, videoConfig.nBitRate);
	}
}

// int CDlgVideoConfig::getMainBitRateIndex(char* bitRate)
// {
// 	if(strcmp(bitRate, "16") == 0) return 0;
// 	else if(strcmp(bitRate, "32") == 0) return 1;
// 	else if(strcmp(bitRate, "64") == 0) return 2;
// 	else if(strcmp(bitRate, "128") == 0) return 3;
// 	else if(strcmp(bitRate, "256") == 0) return 4;
// 	else if(strcmp(bitRate, "512") == 0) return 5;
// 	else if(strcmp(bitRate, "1024") == 0) return 6;
// 	else if(strcmp(bitRate, "1536") == 0) return 7;
// 	else if(strcmp(bitRate, "2048") == 0) return 8;
// 	else if(strcmp(bitRate, "3072") == 0) return 9;
// 	else if(strcmp(bitRate, "4096") == 0) return 10;
// 	else if(strcmp(bitRate, "5120") == 0) return 11;
// 	else if(strcmp(bitRate, "6144") == 0) return 12;
// 	else if(strcmp(bitRate, "7168") == 0) return 13;
// 	else if(strcmp(bitRate, "8192") == 0) return 14;
// 	else if(strcmp(bitRate, "10240") == 0) return 15;
// 	else if(strcmp(bitRate, "12288") == 0) return 16;
// 	else if(strcmp(bitRate, "14336") == 0) return 17;
// 	else if(strcmp(bitRate, "16384") == 0) return 18;
// 	else return 10;
// }

void CDlgVideoConfig::OnSubChangeCodec() 
{
	// TODO: Add your control notification handler code here
	Ms_Ipc_VideoConfig videoConfig = {0};
	videoConfig.nStreamIndex = IPC_STREAM_TYPE_SUB;
	Ms_Ipc_GetVideoConfig(m_nUserId, &videoConfig);
	if(!IsTiIPC(m_productmodel))
	{
		videoConfig.nCodecType = (videoConfig.nCodecType==1?2:videoConfig.nCodecType);
	}
	
	UpdateInformation();
// 	int nSubCodecIndex = m_cbSubCodec.GetCurSel();
// 	BOOL bIsAmba = IsAmbaIPC(m_productmodel);
	if(m_bIsSubMjpeg)
	{
// 		m_cbSubBitrate.SetCurSel(6);//512
// 		m_cbSubBitCtrl.SetCurSel(0);
		SelectComboValue(CT_SUB_BITRATE, 512);
		SelectComboValue(CT_SUB_BITCTRL, 0);
		m_cbSubBitCtrl.EnableWindow(FALSE);
		m_cbSubBitrate.EnableWindow(FALSE);
	}
	else
	{
		m_cbSubBitCtrl.EnableWindow(m_ChkEnableSub.GetCheck());
		m_cbSubBitrate.EnableWindow(m_ChkEnableSub.GetCheck());
	}
	m_cbSubRes.ResetContent();
	int nSubResIndex = 0;
	if(!m_bIsTi)
		m_cbSubRes.InsertString(nSubResIndex++, "704*576");
	m_cbSubRes.InsertString(nSubResIndex++, "640*480");
	m_cbSubRes.InsertString(nSubResIndex++, "640*360");
	if(!m_bIsTi)
		m_cbSubRes.InsertString(nSubResIndex++, "352*288");
	m_cbSubRes.InsertString(nSubResIndex++, "320*240");
	m_cbSubRes.InsertString(nSubResIndex++, "320*192");
	if(!m_bIsTi)
		m_cbSubRes.InsertString(nSubResIndex++, "320*176");
// 	if (videoConfig.nResolution == RESOLUTION_640_480)
// 	{
// 		m_cbSubRes.SetCurSel(0);
// 	} 
// 	else if(videoConfig.nResolution == RESOLUTION_640_360)
// 	{
// 		m_cbSubRes.SetCurSel(1);
// 	}
// 	else if(videoConfig.nResolution == RESOLUTION_352_288)
// 	{
// 		m_cbSubRes.SetCurSel(2);
// 	}
// 	else if (videoConfig.nResolution == RESOLUTION_320_192)
// 	{
// 		m_cbSubRes.SetCurSel(nSubResIndex-1);
// 	}
// 	else
// 	{
// 		m_cbSubRes.SetCurSel(nSubResIndex-2);
// 	}
	char sResString[64] = {0};
	_snprintf(sResString, sizeof(sResString)-1, "%d*%d", videoConfig.nResWidth, videoConfig.nResHeight);
	SelectComboString(CT_SUB_RES, sResString);
}

void CDlgVideoConfig::OnSubChangeRes() 
{
	// TODO: Add your control notification handler code here
// 	Ms_Ipc_VideoConfig videoConfig = {0};
// 	videoConfig.bMainStream = 0;
// 	Ms_Ipc_GetVideoConfig(m_nUserId, &videoConfig);
	
}

void CDlgVideoConfig::InitSubFrameRate()
{
	Ms_Ipc_VideoConfig VideoConfig = {0};
	VideoConfig.nStreamIndex = IPC_STREAM_TYPE_SUB;
	Ms_Ipc_GetVideoConfig(m_nUserId, &VideoConfig);
	if(!IsTiIPC(m_productmodel))
	{
		VideoConfig.nCodecType = (VideoConfig.nCodecType==1?2:VideoConfig.nCodecType);
	}

	if (m_cbSubFrmRate.GetCount() > 15)
	{
		if(m_ficker == 1){//50HZ
// 			char sFrameRate[256] = {0};
// 			_snprintf(sFrameRate, sizeof(sFrameRate), "%d", VideoConfig.nMaxFrameRate);
// 			if(CB_ERR == m_cbSubFrmRate.SelectString(-1, sFrameRate))
// 				m_cbSubFrmRate.SelectString(-1, "25");
			SelectComboValue(CT_SUB_FRAME, VideoConfig.nMaxFrameRate);
		}else{			
// 			char sFrameRate[256] = {0};
// 			_snprintf(sFrameRate, sizeof(sFrameRate), "%d", VideoConfig.nMaxFrameRate);
// 			if(CB_ERR == m_cbSubFrmRate.SelectString(-1, sFrameRate))
// 				m_cbSubFrmRate.SelectString(-1, "30");
			SelectComboValue(CT_SUB_FRAME, VideoConfig.nMaxFrameRate);
		}
	}
	else
	{
// 		char sFrameRate[256] = {0};
// 		_snprintf(sFrameRate, sizeof(sFrameRate), "%d", VideoConfig.nMaxFrameRate);
// 		if(CB_ERR == m_cbSubFrmRate.SelectString(-1, sFrameRate))
// 			m_cbSubFrmRate.SelectString(-1, "15");
		SelectComboValue(CT_SUB_FRAME, VideoConfig.nMaxFrameRate);
	}
}

void CDlgVideoConfig::InitSubBitrate()
{
	Ms_Ipc_VideoConfig videoConfig = {0};
	videoConfig.nStreamIndex = IPC_STREAM_TYPE_SUB;
	Ms_Ipc_GetVideoConfig(m_nUserId, &videoConfig);
	if(!IsTiIPC(m_productmodel))
	{
		videoConfig.nCodecType = (videoConfig.nCodecType==1?2:videoConfig.nCodecType);
	}
//	BOOL bIsAmba = IsAmbaIPC(m_productmodel);
	UpdateInformation();
	m_cbSubBitrate.ResetContent();
	int nSubBitrateIndex = 0;
	m_cbSubBitrate.InsertString(nSubBitrateIndex++, "16");
	m_cbSubBitrate.InsertString(nSubBitrateIndex++, "32");
	m_cbSubBitrate.InsertString(nSubBitrateIndex++, "64");
	m_cbSubBitrate.InsertString(nSubBitrateIndex++, "128");
	if(m_bIsTi)
		m_cbSubBitrate.InsertString(nSubBitrateIndex++, "192");
	m_cbSubBitrate.InsertString(nSubBitrateIndex++, "256");
	if(m_bIsTi)
		m_cbSubBitrate.InsertString(nSubBitrateIndex++, "320");
	m_cbSubBitrate.InsertString(nSubBitrateIndex++, "384");
	if(m_bIsTi)
		m_cbSubBitrate.InsertString(nSubBitrateIndex++, "448");
	m_cbSubBitrate.InsertString(nSubBitrateIndex++, "512");
	m_cbSubBitrate.InsertString(nSubBitrateIndex++, "768");
	m_cbSubBitrate.InsertString(nSubBitrateIndex++, "1024");
	if(!m_bIsTi){
		m_cbSubBitrate.InsertString(nSubBitrateIndex++, "1536");
		m_cbSubBitrate.InsertString(nSubBitrateIndex++, "2048");
	}
	
/*	m_cbSubBitrate.InsertString(nSubBitrateIndex++, "3072");
	m_cbSubBitrate.InsertString(nSubBitrateIndex++, "4096");
*/
// 	char sSubBitrate[32] = {0};
// 	itoa(videoConfig.nBitRate, sSubBitrate, 10);
//	m_cbSubBitrate.SetCurSel(getSubBitRateIndex(sSubBitrate));
	SelectComboValue(CT_SUB_BITRATE, videoConfig.nBitRate);
	if(m_bIsSubMjpeg)
		SelectComboValue(CT_SUB_BITRATE, 512); // 512
}

// int CDlgVideoConfig::getSubBitRateIndex(char* bitRate)
// {
// 	if(strcmp(bitRate, "16") == 0) return 0;
// 	else if(strcmp(bitRate, "32") == 0) return 1;
// 	else if(strcmp(bitRate, "64") == 0) return 2;
// 	else if(strcmp(bitRate, "128") == 0) return 3;
// 	else if(strcmp(bitRate, "256") == 0) return 4;
// 	else if(strcmp(bitRate, "384") == 0) return 5;
// 	else if(strcmp(bitRate, "512") == 0) return 6;
// 	else if(strcmp(bitRate, "768") == 0) return 7;
// 	else if(strcmp(bitRate, "1024") == 0) return 8;
// 	else if(strcmp(bitRate, "1536") == 0) return 9;
// 	else if(strcmp(bitRate, "2048") == 0) return 10;
// /*
// 	else if(strcmp(bitRate, "3072") == 0) return 11;
// 	else if(strcmp(bitRate, "4096") == 0) return 12;
// */
// 	else return 6;
// }

void CDlgVideoConfig::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(nIDEvent == 1001) // validate the input
	{
		char sIFrmValue[16] = {0};
		m_edMainIFrm.GetWindowText(sIFrmValue, sizeof(sIFrmValue));
		if(strlen(sIFrmValue) > 0 && atoi(sIFrmValue) < 1) // 为空的情况单独处理
		{
			_snprintf(sIFrmValue, sizeof(sIFrmValue)-1, "%d", 1);
			m_edMainIFrm.SetWindowText(sIFrmValue);
		}else if(atoi(sIFrmValue) > 60){
			_snprintf(sIFrmValue, sizeof(sIFrmValue)-1, "%d", 60);
			m_edMainIFrm.SetWindowText(sIFrmValue);
		}
		m_edSubIFrm.GetWindowText(sIFrmValue, sizeof(sIFrmValue));
		if(strlen(sIFrmValue) > 0 && atoi(sIFrmValue) < 1)
		{
			_snprintf(sIFrmValue, sizeof(sIFrmValue)-1, "%d", 1);
			m_edSubIFrm.SetWindowText(sIFrmValue);
		}else if(atoi(sIFrmValue) > 60){
			_snprintf(sIFrmValue, sizeof(sIFrmValue)-1, "%d", 60);
			m_edSubIFrm.SetWindowText(sIFrmValue);
		}
	}
	CDialog::OnTimer(nIDEvent);
}

void CDlgVideoConfig::SelectComboString(enum COMBO_TYPE type, LPCTSTR str)
{
	switch(type)
	{
	case CT_MAIN_CODEC:
		{
			if(CB_ERR == m_cbMainCodec.SelectString(-1, str))
				m_cbMainCodec.SetCurSel(0);
		}
		break;
	case CT_MAIN_RES:
		{
			int nIndex = 0;
			char *pPos = NULL;
			while (!pPos && nIndex < m_cbMainRes.GetCount())
			{
				CString strValue = _T("");
				m_cbMainRes.GetLBText(nIndex, strValue);
				pPos = strstr(strValue, str);
				nIndex++;
			}
			if(pPos != NULL)
			{
				m_cbMainRes.SetCurSel(nIndex-1);
			}
			else
				m_cbMainRes.SetCurSel(0);
// 			if(CB_ERR == m_cbMainRes.SelectString(-1, str))
// 				m_cbMainRes.SetCurSel(0);
		}
		break;
	case CT_MAIN_FRAME:
		{
			if(CB_ERR == m_cbMainFrmRate.SelectString(-1, str))
				m_cbMainFrmRate.SetCurSel(m_cbMainFrmRate.GetCount()-1);
		}
		break;
	case CT_MAIN_BITRATE:
		{
			if(CB_ERR == m_cbMainBitrate.SelectString(-1, str))
				m_cbMainBitrate.SelectString(-1, _T("2048"));
		}
		break;
	case CT_MAIN_BITCTRL:
		{
			if(CB_ERR == m_cbMainBitCtrl.SelectString(-1, str))
				m_cbMainBitCtrl.SetCurSel(0);
		}
		break;

	case CT_SUB_CODEC:
		{
			if(CB_ERR == m_cbSubCodec.SelectString(-1, str))
				m_cbSubCodec.SetCurSel(0);
		}
		break;
	case CT_SUB_RES:
		{
			int nIndex = 0;
			char *pPos = NULL;
			while (!pPos && nIndex < m_cbSubRes.GetCount())
			{
				CString strValue = _T("");
				m_cbSubRes.GetLBText(nIndex, strValue);
				pPos = strstr(strValue, str);
				nIndex++;
			}
			if(pPos != NULL)
			{
				m_cbSubRes.SetCurSel(nIndex-1);
			}
			else
				m_cbSubRes.SetCurSel(0);
// 			if(CB_ERR == m_cbSubRes.SelectString(-1, str))
// 				m_cbSubRes.SetCurSel(0);
		}
		break;
	case CT_SUB_FRAME:
		{
			if(CB_ERR == m_cbSubFrmRate.SelectString(-1, str))
				m_cbSubFrmRate.SetCurSel(m_cbSubFrmRate.GetCount()-1);
		}
		break;
	case CT_SUB_BITRATE:
		{
			if(CB_ERR == m_cbSubBitrate.SelectString(-1, str))
				m_cbSubBitrate.SelectString(-1, _T("512"));
		}
		break;
	case CT_SUB_BITCTRL:
		{
			if(CB_ERR == m_cbSubBitCtrl.SelectString(-1, str))
				m_cbSubBitCtrl.SetCurSel(0);
		}
		break;
	}
}

void CDlgVideoConfig::SelectComboValue(enum COMBO_TYPE type, int nValue)
{
	CString strValue = " ";
	switch(type)
	{
	case CT_MAIN_CODEC:
		{
			if(nValue == IPC_VIDEO_ENCODING_MPEG4)
				strValue = "MPEG4";
			else if(nValue == IPC_VIDEO_ENCODING_JPEG)
				strValue = "MJPEG";
			else if(nValue == IPC_VIDEO_ENCODING_H265)
				strValue = "H.265";
			else
				strValue = "H.264";
		}
		break;
	case CT_MAIN_RES:
		{
// 			if(nValue == IPC_RESOLUTION_5M)
// 				strValue = "5M(2560*1920)";
// 			else if(nValue == IPC_RESOLUTION_3M)
// 				if(IsHisiIPC(m_productmodel))
// 					strValue = "3M(2304*1296)";
// 				else
// 					strValue = "3M(2048*1536)";
// 			else if(nValue == IPC_RESOLUTION_1080P)
// 				strValue = "1080P(1920*1080)";
// 			else if(nValue == IPC_RESOLUTION_2M)
// 				strValue = "2M(1600*1200)";
// 			else if(nValue == IPC_RESOLUTION_1_3M)
// 				strValue = "1.3M(1280*960)";
// 			else if(nValue == IPC_RESOLUTION_D1)
// 				strValue = "D1(704*576)";
// 			else //if(nValue == IPC_RESOLUTION_720P)
// 				strValue = "720P(1280*720)";
		}
		break;
	case CT_MAIN_FRAME:
	case CT_MAIN_BITRATE:
		{
			strValue.Format("%d", nValue);
		}
		break;
	case CT_MAIN_BITCTRL:
		{
			if(nValue == 1)
				strValue = "VBR";
			else
				strValue = "CBR";
		}
		break;

	case CT_SUB_CODEC:
		{
			if(nValue == IPC_VIDEO_ENCODING_MPEG4)
				strValue = "MPEG4";
			else if(nValue == IPC_VIDEO_ENCODING_JPEG)
				strValue = "MJPEG";
			else if(nValue == IPC_VIDEO_ENCODING_H265)
				strValue = "H.265";
			else
				strValue = "H.264";
		}
		break;
	case CT_SUB_RES:
		{
// 			if(nValue == IPC_RESOLUTION_640_480)
// 				strValue = "640*480";
// 			else if(nValue == IPC_RESOLUTION_640_360)
// 				strValue = "640*360";
// 			else if(nValue == IPC_RESOLUTION_352_288)
// 				strValue = "352*288";
// 			else if(nValue == IPC_RESOLUTION_320_240)
// 				strValue = "320*240";
// 			else if(nValue == IPC_RESOLUTION_320_192)
// 				strValue = "320*192";
		}
		break;
	case CT_SUB_FRAME:
	case CT_SUB_BITRATE:
		{
			strValue.Format("%d", nValue);
		}
		break;
	case CT_SUB_BITCTRL:
		{
			if(nValue == 1)
				strValue = "VBR";
			else
				strValue = "CBR";
		}
		break;
	}
// 	if(strValue.GetLength() <= 0)
// 		strValue = " "; // to select default item
	SelectComboString(type, strValue);
}

void CDlgVideoConfig::UpdateInformation()
{
	m_bIsAmba = IsAmbaIPC(m_productmodel);
	m_bIsHisi = IsHisiIPC(m_productmodel);
	m_bIsTi = IsTiIPC(m_productmodel);

	char sValue[64] = {0};

	m_bIsH264 = FALSE;
	m_bIsMpeg4 = FALSE;
	m_bIsMjpeg = FALSE;
	m_bIsH265 = FALSE;

	m_cbMainCodec.GetWindowText(sValue, sizeof(sValue));
	if(!strcmp(sValue, "MPEG4")){
		m_bIsMpeg4 = TRUE;
	}else if(!strcmp(sValue, "MJPEG")){
		m_bIsMjpeg = TRUE;
	}else if(!strcmp(sValue, "H.265")){
		m_bIsH265 = TRUE;
	}else{
		m_bIsH264 = TRUE;
	}

	m_bIs3M = FALSE;
	m_bIs4M = FALSE;
	m_bIs5M = FALSE;

	m_cbMainRes.GetWindowText(sValue, sizeof(sValue));
	if(!strcmp(sValue, "5M(2560*1920)")){
		m_bIs5M = TRUE;
	}else if(!strcmp(sValue, "4M(2592*1520)")){
		m_bIs4M = TRUE;
	}else if(!strcmp(sValue, "3M(2048*1536)") || !strcmp(sValue, "3M(2304*1296)")){
		m_bIs3M = TRUE;
	}

	m_bIsSubMjpeg = FALSE;
	
	m_cbSubCodec.GetWindowText(sValue, sizeof(sValue));
	if(!strcmp(sValue, "MJPEG")){
		m_bIsSubMjpeg = TRUE;
	}
}
