📄 myvoipctl.cpp
字号:
{
MessageBox("RTP注册异步事件失败!");
::PostQuitMessage(WM_QUIT);
return;
}
}
// the method of record
void CMyvoipCtrl::Record(LPCTSTR scrIP, LPCTSTR scrID)
{
// TODO: Add your dispatch handler code here
DWORD dwDXVersion = GetDXVersion();
if( dwDXVersion!=0x801 )
{
AfxMessageBox("请您安装directx8.1以上的版本");
return ;
}
if(!bRecord)
{
destIP=scrIP;
destID=scrID;
hWnd=this->m_hWnd;
InitSock();
InitDirectSound();
OnFormatsOK();
CreateOutputBuffer();
StartBuffers();
//SetTimer(1,10000,NULL);
AfxBeginThread(ComputeThreadProc,hWnd,THREAD_PRIORITY_NORMAL);
}
else
{
AfxMessageBox("语音已开启!");
}
}
// stop the record Uninitialize
void CMyvoipCtrl::Stop()
{
// TODO: Add your dispatch handler code here
if( g_pDSBCapture && g_pDSBOutput )
{
g_pDSBCapture->Stop();
g_pDSBOutput->Stop();
FreeDirectSound();
CloseHandle( g_hNotificationEvent );
}
bRecord=false;
WSAAsyncSelect(Sock.m_hSocket,this->m_hWnd,0,0);
Sock.Close();
}
// receive voice package
void CMyvoipCtrl::RecMsg(WPARAM wParam, LPARAM lParam)
{
int iEvent;
iEvent = WSAGETSELECTEVENT(lParam);
switch(iEvent)
{
case FD_READ:
{
CString dataIP;
UINT dataPort;
DWORD dwStatus;
HRESULT hr;
DWORD dwDSOutputLockedBufferSize;
VOID* pDSOutputLockedBuffer= NULL;
g_pDSBOutput->GetStatus( &dwStatus ) ;
if( dwStatus & DSBSTATUS_BUFFERLOST )
{
StartBuffers() ;
}
if( FAILED( hr = g_pDSBOutput->Lock( g_dwNextOutputOffset, g_dwNotifySize,
&pDSOutputLockedBuffer,
&dwDSOutputLockedBufferSize,
NULL, NULL, 0L ) ) )
DXTRACE_ERR( TEXT("ss"), hr );
voicepacket voice;
int receiveLen =Sock.ReceiveFrom(&voice, dwDSOutputLockedBufferSize+20,dataIP,dataPort,0);
memcpy(pDSOutputLockedBuffer,voice.buff,dwDSOutputLockedBufferSize);
g_pDSBOutput->Unlock( pDSOutputLockedBuffer, dwDSOutputLockedBufferSize,
NULL, 0 );
g_dwNextOutputOffset += dwDSOutputLockedBufferSize;
g_dwNextOutputOffset %= g_dwOutputBufferSize; // Circular buffer
}
}
}
//check the version of directx
DWORD CMyvoipCtrl::GetDXVersion()
{
DIRECTDRAWCREATE DirectDrawCreate = NULL;
DIRECTDRAWCREATEEX DirectDrawCreateEx = NULL;
DIRECTINPUTCREATE DirectInputCreate = NULL;
HINSTANCE hDDrawDLL = NULL;
HINSTANCE hDInputDLL = NULL;
HINSTANCE hD3D8DLL = NULL;
HINSTANCE hDPNHPASTDLL = NULL;
LPDIRECTDRAW pDDraw = NULL;
LPDIRECTDRAW2 pDDraw2 = NULL;
LPDIRECTDRAWSURFACE pSurf = NULL;
LPDIRECTDRAWSURFACE3 pSurf3 = NULL;
LPDIRECTDRAWSURFACE4 pSurf4 = NULL;
DWORD dwDXVersion = 0;
HRESULT hr;
// First see if DDRAW.DLL even exists.
hDDrawDLL = LoadLibrary( "DDRAW.DLL" );
if( hDDrawDLL == NULL )
{
dwDXVersion = 0;
OutputDebugString( "Couldn't LoadLibrary DDraw\r\n" );
return dwDXVersion;
}
// See if we can create the DirectDraw object.
DirectDrawCreate = (DIRECTDRAWCREATE)GetProcAddress( hDDrawDLL, "DirectDrawCreate" );
if( DirectDrawCreate == NULL )
{
dwDXVersion = 0;
FreeLibrary( hDDrawDLL );
OutputDebugString( "Couldn't GetProcAddress DirectDrawCreate\r\n" );
return dwDXVersion;
}
hr = DirectDrawCreate( NULL, &pDDraw, NULL );
if( FAILED(hr) )
{
dwDXVersion = 0;
FreeLibrary( hDDrawDLL );
OutputDebugString( "Couldn't create DDraw\r\n" );
return dwDXVersion;
}
// So DirectDraw exists. We are at least DX1.
dwDXVersion = 0x100;
// Let's see if IID_IDirectDraw2 exists.
hr = pDDraw->QueryInterface( IID_IDirectDraw2, (VOID**)&pDDraw2 );
if( FAILED(hr) )
{
// No IDirectDraw2 exists... must be DX1
pDDraw->Release();
FreeLibrary( hDDrawDLL );
OutputDebugString( "Couldn't QI DDraw2\r\n" );
return dwDXVersion;
}
// IDirectDraw2 exists. We must be at least DX2
pDDraw2->Release();
dwDXVersion = 0x200;
//-------------------------------------------------------------------------
// DirectX 3.0 Checks
//-------------------------------------------------------------------------
// DirectInput was added for DX3
hDInputDLL = LoadLibrary( "DINPUT.DLL" );
if( hDInputDLL == NULL )
{
// No DInput... must not be DX3
pDDraw->Release();
FreeLibrary( hDDrawDLL );
OutputDebugString( "Couldn't LoadLibrary DInput\r\n" );
return dwDXVersion;
}
DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( hDInputDLL,
"DirectInputCreateA" );
if( DirectInputCreate == NULL )
{
// No DInput... must be DX2
FreeLibrary( hDInputDLL );
pDDraw->Release();
FreeLibrary( hDDrawDLL );
OutputDebugString( "Couldn't GetProcAddress DInputCreate\r\n" );
return dwDXVersion;
}
// DirectInputCreate exists. We are at least DX3
dwDXVersion = 0x300;
FreeLibrary( hDInputDLL );
// Can do checks for 3a vs 3b here
//-------------------------------------------------------------------------
// DirectX 5.0 Checks
//-------------------------------------------------------------------------
// We can tell if DX5 is present by checking for the existence of
// IDirectDrawSurface3. First, we need a surface to QI off of.
DDSURFACEDESC ddsd;
ZeroMemory( &ddsd, sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = pDDraw->SetCooperativeLevel( NULL, DDSCL_NORMAL );
if( FAILED(hr) )
{
// Failure. This means DDraw isn't properly installed.
pDDraw->Release();
FreeLibrary( hDDrawDLL );
dwDXVersion = 0;
OutputDebugString( "Couldn't Set coop level\r\n" );
return dwDXVersion;
}
hr = pDDraw->CreateSurface( &ddsd, &pSurf, NULL );
if( FAILED(hr) )
{
// Failure. This means DDraw isn't properly installed.
pDDraw->Release();
FreeLibrary( hDDrawDLL );
dwDXVersion = 0;
OutputDebugString( "Couldn't CreateSurface\r\n" );
return dwDXVersion;
}
// Query for the IDirectDrawSurface3 interface
if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface3,
(VOID**)&pSurf3 ) ) )
{
pSurf->Release();
pDDraw->Release();
FreeLibrary( hDDrawDLL );
OutputDebugString( "Couldn't QI DDS3\r\n" );
return dwDXVersion;
}
// QI for IDirectDrawSurface3 succeeded. We must be at least DX5
dwDXVersion = 0x500;
pSurf3->Release();
//-------------------------------------------------------------------------
// DirectX 6.0 Checks
//-------------------------------------------------------------------------
// The IDirectDrawSurface4 interface was introduced with DX 6.0
if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface4,
(VOID**)&pSurf4 ) ) )
{
pSurf->Release();
pDDraw->Release();
FreeLibrary( hDDrawDLL );
OutputDebugString( "Couldn't QI DDS4\r\n" );
return dwDXVersion;
}
// IDirectDrawSurface4 was create successfully. We must be at least DX6
dwDXVersion = 0x600;
pSurf4->Release();
pSurf->Release();
pDDraw->Release();
//-------------------------------------------------------------------------
// DirectX 6.1 Checks
//-------------------------------------------------------------------------
// Check for DMusic, which was introduced with DX6.1
LPDIRECTMUSIC pDMusic = NULL;
CoInitialize( NULL );
hr = CoCreateInstance( CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER,
IID_IDirectMusic, (VOID**)&pDMusic );
if( FAILED(hr) )
{
FreeLibrary( hDDrawDLL );
OutputDebugString( "Couldn't create CLSID_DirectMusic\r\n" );
return dwDXVersion;
}
// DirectMusic was created successfully. We must be at least DX6.1
dwDXVersion = 0x601;
pDMusic->Release();
CoUninitialize();
//-------------------------------------------------------------------------
// DirectX 7.0 Checks
//-------------------------------------------------------------------------
// Check for DirectX 7 by creating a DDraw7 object
LPDIRECTDRAW7 pDD7;
DirectDrawCreateEx = (DIRECTDRAWCREATEEX)GetProcAddress( hDDrawDLL,
"DirectDrawCreateEx" );
if( NULL == DirectDrawCreateEx )
{
FreeLibrary( hDDrawDLL );
OutputDebugString( "Couldn't GetProcAddress DirectDrawCreateEx\r\n" );
return dwDXVersion;
}
if( FAILED( DirectDrawCreateEx( NULL, (VOID**)&pDD7, IID_IDirectDraw7,
NULL ) ) )
{
FreeLibrary( hDDrawDLL );
OutputDebugString( "Couldn't DirectDrawCreateEx\r\n" );
return dwDXVersion;
}
// DDraw7 was created successfully. We must be at least DX7.0
dwDXVersion = 0x700;
pDD7->Release();
//-------------------------------------------------------------------------
// DirectX 8.0 Checks
//-------------------------------------------------------------------------
// Simply see if D3D8.dll exists.
hD3D8DLL = LoadLibrary( "D3D8.DLL" );
if( hD3D8DLL == NULL )
{
FreeLibrary( hDDrawDLL );
OutputDebugString( "Couldn't LoadLibrary D3D8.DLL\r\n" );
return dwDXVersion;
}
// D3D8.dll exists. We must be at least DX8.0
dwDXVersion = 0x800;
//-------------------------------------------------------------------------
// DirectX 8.1 Checks
//-------------------------------------------------------------------------
// Simply see if dpnhpast.dll exists.
hDPNHPASTDLL = LoadLibrary( "dpnhpast.dll" );
if( hDPNHPASTDLL == NULL )
{
FreeLibrary( hDPNHPASTDLL );
OutputDebugString( "Couldn't LoadLibrary dpnhpast.dll\r\n" );
return dwDXVersion;
}
// dpnhpast.dll exists. We must be at least DX8.1
dwDXVersion = 0x801;
//-------------------------------------------------------------------------
// End of checking for versions of DirectX
//-------------------------------------------------------------------------
// Close open libraries and return
FreeLibrary( hDDrawDLL );
FreeLibrary( hD3D8DLL );
return dwDXVersion;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -