#if !defined(AFX_UDPAUDIOTHREAD_H__F2E39461_9FCD_11D4_A856_0010B503CEA7__INCLUDED_)
#define AFX_UDPAUDIOTHREAD_H__F2E39461_9FCD_11D4_A856_0010B503CEA7__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// UdpAudioThread.h : header file
//

#include "TcpSocket.h"
#include "UdpSocket.h"
#include "Waveform.h"
#include "AcmCodec.h"

/////////////////////////////////////////////////////////////////////////////

#define WM_UDP_AUDIO_DISCONNECT		(WM_USER + 0x101)
#define WM_UDP_AUDIO_TEST			(WM_USER + 0x102)

#define AUDIO_TIME			240
#define AUDIO_LENGTH		(AUDIO_TIME*8000*2/1000)

/////////////////////////////////////////////////////////////////////////////
// CUdpAudioWnd window

class CUdpAudioWnd : public CWnd
{
// Construction
public:
	CUdpAudioWnd();

// Attributes
public:
	BOOL Create();
	void DebugTest();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CUdpAudioWnd)
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CUdpAudioWnd();

	// Generated message map functions
protected:
	//{{AFX_MSG(CUdpAudioWnd)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnDestroy();
	//}}AFX_MSG
#if _MSC_VER >= 1300
	afx_msg LRESULT OnUdpData(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnWaveInOpen(WPARAM wParam, LPARAM lParam = 0);
	afx_msg LRESULT OnWaveInClose(WPARAM wParam, LPARAM lParam = 0);
	afx_msg LRESULT OnWaveInData(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnWaveOutOpen(WPARAM wParam, LPARAM lParam = 0);
	afx_msg LRESULT OnWaveOutClose(WPARAM wParam, LPARAM lParam = 0);
	afx_msg LRESULT OnWaveOutDone(WPARAM wParam, LPARAM lParam);
#else
	afx_msg void OnUdpData(WPARAM wParam, LPARAM lParam);
	afx_msg void OnWaveInOpen(WPARAM wParam, LPARAM lParam = 0);
	afx_msg void OnWaveInClose(WPARAM wParam, LPARAM lParam = 0);
	afx_msg void OnWaveInData(WPARAM wParam, LPARAM lParam);
	afx_msg void OnWaveOutOpen(WPARAM wParam, LPARAM lParam = 0);
	afx_msg void OnWaveOutClose(WPARAM wParam, LPARAM lParam = 0);
	afx_msg void OnWaveOutDone(WPARAM wParam, LPARAM lParam);
#endif
	DECLARE_MESSAGE_MAP()

protected:
	void UdpSendStart();
	void UdpSendStop();

protected:
	CUdpSocket	m_udp;
	CWaveIn		m_waveIn;
	CWaveOut	m_waveOut;
	CAcmCodec * m_pDec;
	CAcmCodec * m_pEnc;

	CFile m_file;
	BOOL	m_bAudioSaveFile;
	BOOL	m_bAudioRealtime;
	BOOL	m_bAudioRealtimeOut;
	BOOL	m_bAudioNoAcm;
	BOOL	m_bUseHighRate;
	BOOL	m_bUseVAD;

	int m_iAudioType;

	char m_pPlayData[AUDIO_LENGTH+1024];
	int  m_iPlayDataLength;
};


/////////////////////////////////////////////////////////////////////////////
// CUdpAudioThread thread

class CUdpAudioThread : public CWinThread
{
	DECLARE_DYNCREATE(CUdpAudioThread)
public:
	CUdpAudioThread();

	void operator delete(void* p);

// Attributes
public:
	static HANDLE m_hEventThreadKilled;

	static void PrepareEvent();
	static void UnprepareEvent();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CUdpAudioThread)
	public:
	virtual BOOL InitInstance();
	virtual int ExitInstance();
	//}}AFX_VIRTUAL

// Implementation
protected:
	virtual ~CUdpAudioThread();

	// Generated message map functions
	//{{AFX_MSG(CUdpAudioThread)
		// NOTE - the ClassWizard will add and remove member functions here.
	//}}AFX_MSG
	afx_msg void OnDisconnect(WPARAM wParam = 0, LPARAM lParam = 0);
	afx_msg void OnTest(WPARAM wParam = 0, LPARAM lParam = 0);
	DECLARE_MESSAGE_MAP()

protected:
	CUdpAudioWnd	m_wndUdpAudio;
};

/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_UDPAUDIOTHREAD_H__F2E39461_9FCD_11D4_A856_0010B503CEA7__INCLUDED_)
