DWORD WINAPI CVideoManager::WorkThread( LPVOID lparam ) { static DWORD dwLastScreen = GetTickCount(); CVideoManager *pThis = (CVideoManager *)lparam; if (!pThis->Initialize()) { pThis->Destroy(); pThis->m_pClient->Disconnect(); return -1; } pThis->sendBITMAPINFO(); // 等控制端对话框打开 pThis->WaitForDialogOpen(); while (pThis->m_bIsWorking) { // 限制速度 if ((GetTickCount() - dwLastScreen) < 150) Sleep(100); dwLastScreen = GetTickCount(); pThis->sendNextScreen(); } // 销毁已经存在实例,方便重新调整 pThis->Destroy(); return 0; }
DWORD WINAPI CVideoManager::WorkThread( LPVOID lparam ) { static DWORD dwLastScreen = GetTickCount(); CVideoManager *pThis = (CVideoManager *)lparam; if (pThis->Initialize()) //转到Initialize { //pThis->Destroy(); //pThis->m_pClient->Disconnect(); //return -1; pThis->m_bIsCompress=true; //如果初始化成功就设置可以压缩 } pThis->sendBITMAPINFO(); // 等控制端对话框打开 pThis->WaitForDialogOpen(); while (pThis->m_bIsWorking) { // 限制速度 if ((GetTickCount() - dwLastScreen) < 150) Sleep(100); dwLastScreen = GetTickCount(); pThis->sendNextScreen(); //这里没有压缩相关的代码了,我们到sendNextScreen 看看 } // 销毁已经存在实例,方便重新调整 pThis->Destroy(); return 0; }
bool CVideoRenderer::Initialize ( const char * szFile ) { IBaseFilter * pDSound, * pXVID, * pVorbis; IBaseFilter * pSource; IFileSourceFilter * pFileSource; HRESULT hr; // Get the codecs CVideoManager *pManager = CVideoManager::GetSingletonPtr (); if ( pManager->CreateCodecSource ( &pSource ) != S_OK ) return false; if ( pManager->CreateCodecVorbis ( &pVorbis ) != S_OK ) return false; if ( pManager->CreateCodecXVID ( &pXVID ) != S_OK ) return false; // Check for a valid device if ( !m_pDevice ) return false; // Lock so we don't f**k up Lock (); CCore::GetSingleton ().GetConsole ()->Printf ( "Creating DirectShow graph instance" ); // Initialize the graph builder CoCreateInstance ( CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, reinterpret_cast < void** > ( &m_pGraph ) ); if ( m_pGraph == NULL ) return false; CCore::GetSingleton ().GetConsole ()->Printf ( "Creating DirectSound renderer instance" ); // Initialize the DirectSound filter CoCreateInstance ( CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, reinterpret_cast < void** > ( &pDSound ) ); if ( pDSound == NULL ) return false; #ifdef MTA_DEBUG CCore::GetSingleton ().GetConsole ()->Printf ( "Adding ROT for debug stuff" ); // Enable GraphView debugging AddToROT(m_pGraph); #endif CCore::GetSingleton ().GetConsole ()->Printf ( "Creating video renderer instance" ); // Create an instance of the texture renderer and add it to the graph m_pFilter = CreateTextureRenderer ( &hr, m_pDevice, this ); if ( hr != S_OK ) return false; // Add the source file filter to the grap h int iBufferSize = MultiByteToWideChar ( CP_ACP, 0, szFile, -1, NULL, 0 ); wchar_t *wszFile = new wchar_t[iBufferSize]; MultiByteToWideChar ( CP_ACP, 0, szFile, -1, wszFile, iBufferSize ); CCore::GetSingleton ().GetConsole ()->Printf ( "Registering filter (Matroska)" ); // Add the filters to the graph m_pGraph->AddFilter ( pSource, L"[MTA] MKV source" ); CCore::GetSingleton ().GetConsole ()->Printf ( "Loading video file" ); pSource->QueryInterface ( IID_IFileSourceFilter, reinterpret_cast < void** > ( &pFileSource ) ); if ( pFileSource->Load ( wszFile, NULL ) != S_OK ) return false; CCore::GetSingleton ().GetConsole ()->Printf ( "Registering filter (Output)" ); m_pGraph->AddFilter ( m_pFilter, L"[MTA] Texture renderer" ); CCore::GetSingleton ().GetConsole ()->Printf ( "Registering filter (Vorbis)" ); m_pGraph->AddFilter ( pVorbis, L"[MTA] Vorbis decoder" ); CCore::GetSingleton ().GetConsole ()->Printf ( "Registering filter (XVID)" ); m_pGraph->AddFilter ( pXVID, L"[MTA] XVID codec" ); CCore::GetSingleton ().GetConsole ()->Printf ( "Registering filter (DirectSound)" ); m_pGraph->AddFilter ( pDSound, L"[MTA] DirectSound renderer" ); CCore::GetSingleton ().GetConsole ()->Printf ( "Connecting video renderer" ); // Connect the video pins IPin *pOut, *pSourceOut; hr = ConnectFilters ( m_pGraph, pSource, pXVID, &pSourceOut ); // MKV Source -> XVID assert ( hr == S_OK ); hr = ConnectFilters ( m_pGraph, pXVID, m_pFilter, &pOut ); // XVID -> Texture Renderer assert ( hr == S_OK ); // Connect the audio pins (not necessary) hr = ConnectFilters ( m_pGraph, pSource, pVorbis, &pOut ); // MKV Source -> Vorbis Decoder hr = ConnectFilters ( m_pGraph, pVorbis, pDSound, &pOut ); // Vorbis Decoder -> DirectSound renderer m_pGraph->QueryInterface ( IID_IMediaSeeking, reinterpret_cast < void** > ( &m_pMediaSeeking ) ); assert ( m_pMediaSeeking != NULL ); m_pGraph->QueryInterface ( IID_IMediaControl, reinterpret_cast < void** > ( &m_pMediaControl ) ); if ( m_pMediaControl == NULL || m_pMediaSeeking == NULL ) return false; m_pGraph->QueryInterface ( IID_IBasicAudio, reinterpret_cast < void** > ( &m_pBasicAudio ) ); if ( m_pBasicAudio == NULL ) return false; CCore::GetSingleton ().GetConsole ()->Printf ( "Successfully loaded video renderer" ); m_pBasicAudio->get_Volume ( &lDefaultVolume ); // Clean up delete [] wszFile; // m_pGraph->Release (); // Unlock the mutex Unlock (); return true; }