// VideoSetting.cpp : 实现文件
//

#include "stdafx.h"
#include "LT_UVC_MFC.h"
#include "VideoSetting.h"
#include "afxdialogex.h"


// CVideoSetting 对话框
extern Video_Parame g_VideoSystemParamter;
IMPLEMENT_DYNAMIC(CVideoSetting, CDialogEx)

CVideoSetting::CVideoSetting(CWnd* pParent /*=NULL*/)
	: CDialogEx(CVideoSetting::IDD, pParent)
{

}

CVideoSetting::~CVideoSetting()
{
}

void CVideoSetting::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_VIDEO_NAME_COM, m_video_name_com);
	DDX_Control(pDX, IDC_AUDIO_COM, m_audio_name_com);
	DDX_Control(pDX, IDC_VIDEO_RES_COM, m_video_res_com);
	DDX_Control(pDX, IDC_AUTO_PLAY_CHECK, m_auto_play_check);
}


BEGIN_MESSAGE_MAP(CVideoSetting, CDialogEx)
	ON_BN_CLICKED(ID_SET_OK, &CVideoSetting::OnBnClickedSetOk)
	ON_BN_CLICKED(ID_SET_NG, &CVideoSetting::OnBnClickedSetNg)
	ON_CBN_SELCHANGE(IDC_VIDEO_NAME_COM, &CVideoSetting::OnCbnSelchangeVideoNameCom)
	ON_CBN_SELCHANGE(IDC_VIDEO_RES_COM, &CVideoSetting::OnCbnSelchangeVideoResCom)
	ON_CBN_SELCHANGE(IDC_AUDIO_COM, &CVideoSetting::OnCbnSelchangeAudioCom)
	ON_BN_CLICKED(IDC_AUTO_PLAY_CHECK, &CVideoSetting::OnBnClickedAutoPlayCheck)
END_MESSAGE_MAP()


// CVideoSetting 消息处理程序


void CVideoSetting::OnBnClickedSetOk()
{
	// TODO: 在此添加控件通知处理程序代码
	m_pParent->OpenVideo(m_currIndex);
	int ret =m_pParent->OpenAudio(m_currIndex);
	if(ret ==1)
	{
		if(m_auto_play ==1)
		{
			AudioOutPlay(m_currIndex);
		}
	}
	CDialog::OnOK();
}


void CVideoSetting::OnBnClickedSetNg()
{
	// TODO: 在此添加控件通知处理程序代码
	CDialog::OnOK();
}


BOOL CVideoSetting::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	m_auto_play =1;
	ShowForm();
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}
void CVideoSetting::ShowForm()
{
	int ch, index;
	CString strname;
	int ResSize;
	char video_audio_name[MAX_PATH];
	int m_videoIndex,m_audioIndex;
	int m_videoResIndex;
	m_video_name_com.ResetContent();
	m_audio_name_com.ResetContent();
	m_video_res_com.ResetContent();
	m_videoIndex = g_VideoSystemParamter.m_VideoIndex[m_currIndex];
	m_audioIndex = g_VideoSystemParamter.m_AudioIndex[m_currIndex];
	m_videoResIndex = g_VideoSystemParamter.m_VideoResIndex[m_currIndex];
	//m_video_name_com.AddString("None");
	for(index=0; index<	g_VideoSystemParamter.m_Max_Video_Channels; index++)
	{
		memset(video_audio_name,0x00,MAX_PATH);
		GetVideoNameByIndex(index,video_audio_name);
		strname.Format("%s",video_audio_name);
		m_video_name_com.AddString(strname);
	}
	if(m_videoIndex < (g_VideoSystemParamter.m_Max_Video_Channels+1))
	{
		m_video_name_com.SetCurSel(m_videoIndex);
	}
	else
	{
		m_video_name_com.SetCurSel(0);
		g_VideoSystemParamter.m_VideoIndex[m_currIndex] =0;
	}
	if(m_videoIndex>=0)
	{
		//m_videoIndex = m_videoIndex-1;
		ResSize= GetVideoMaxResIndex(m_videoIndex);
		if(ResSize>0)
		{
			for(int k=0; k<ResSize;k++)
			{
				 int width,height,fps;
				 GetVideoMaxResSizeByIndex(m_videoIndex,k,&width,&height,&fps);
				 memset(video_audio_name,0x00,MAX_PATH);
				 strname.Format("%dx%d(%d)",width,height,fps);
				 m_video_res_com.AddString(strname);
			}
		}
	}
	else
	{
	}
	m_video_res_com.SetCurSel(m_videoResIndex);
	//m_audio_name_com.AddString("None");
	for(index=0; index<	g_VideoSystemParamter.m_Max_Audio_Channels; index++)
	{
		memset(video_audio_name,0x00,MAX_PATH);
		GetAudioNameByIndex(index,video_audio_name);
		strname.Format("%s",video_audio_name);
		m_audio_name_com.AddString(strname);
	}
	m_audio_name_com.SetCurSel(m_audioIndex);
	if(m_auto_play)
	{
		m_auto_play_check.SetCheck(TRUE);
	}
	else
	{
		m_auto_play_check.SetCheck(FALSE);
	}
}

void CVideoSetting::OnCbnSelchangeVideoNameCom()
{
	// TODO: 在此添加控件通知处理程序代码
	g_VideoSystemParamter.m_VideoIndex[m_currIndex] = m_video_name_com.GetCurSel();
	ShowForm();
}


void CVideoSetting::OnCbnSelchangeVideoResCom()
{
	// TODO: 在此添加控件通知处理程序代码
	g_VideoSystemParamter.m_VideoResIndex[m_currIndex] = m_video_res_com.GetCurSel();
	ShowForm();
}


void CVideoSetting::OnCbnSelchangeAudioCom()
{
	// TODO: 在此添加控件通知处理程序代码
	g_VideoSystemParamter.m_AudioIndex[m_currIndex]= m_audio_name_com.GetCurSel();
	ShowForm();
}


void CVideoSetting::OnBnClickedAutoPlayCheck()
{
	// TODO: 在此添加控件通知处理程序代码
	if(m_auto_play_check.GetCheck())
	{
		m_auto_play =1;
	}
	else
	{
		m_auto_play =0;
	}
}
