multimedia/client/qt_gl_/yuvgl/main.cpp

269 lines
6.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "mainwindow.h"
#include <QApplication>
#include "cplaywidget.h"
#include <QTimer>
#include "CameraCapture.h"
#include "mainwindow.h"
#include <qlibrary.h>
#include <qsysinfo.h>
#include <qt_windows.h>
#include "media/screen_capture.h"
#include "media/DXGICapture.h"
#include <QVector>
#include <stdio.h>
#include <tchar.h>
#include <shlobj.h>
#include <D3D9.h>
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
#ifdef __MINGW32__
#include <Tlhelp32.h>
#include "winuser.h"
#endif
int RegiesterOwnType(){
return 0;
}
IDirect3DDevice9* g_pd3dDevice = nullptr;
// 全???======================================================
// 建立D3DDevice
LPDIRECT3D9 g_pD3D = nullptr; // Used to create the D3DDevice
// (我?的?)render?置,用??生最後影像的?置
// =============================================================
HRESULT ScreenGrab(LPDIRECT3DDEVICE9 pDev)
{
HRESULT hr;
D3DDISPLAYMODE mode;
if (FAILED(hr=pDev->GetDisplayMode(0, &mode))) //第一???是Swap Chain跟?重???有防止破碎
return hr;
IDirect3DSurface9* pSurface;
if (FAILED(hr=pDev->CreateOffscreenPlainSurface(mode.Width,mode.Height,
D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pSurface, NULL)))
return hr;
if (FAILED(hr=pDev->GetFrontBufferData(0,pSurface))) {
pSurface->Release();
return hr;
}
D3DLOCKED_RECT lockedRect;
if(FAILED(pSurface->LockRect(&lockedRect,NULL,D3DLOCK_NO_DIRTY_UPDATE|D3DLOCK_NOSYSLOCK|D3DLOCK_READONLY)))
{
printf("Unable to Lock Front Buffer Surface");
return 1;
}
BYTE* pBits = new BYTE[2960*1440*3];
for(int i=0;i<mode.Height;i++)
{
memcpy((BYTE*)pBits+(mode.Height-i-1)*mode.Width*3/8,(BYTE*)lockedRect.pBits+i*lockedRect.Pitch,
mode.Width*3/8);//g_d3dpp.BackBufferHeight*g_d3dpp.BackBufferWidth*4);
}
pSurface->UnlockRect();
SetCursor(LoadCursor(NULL,IDC_ARROW));
// release the image surface
// ?放影像表面
pSurface->Release();
// return status of save operation to caller
// 回?Handler
return hr;
}
QVector<tagDublicatorMonitorInfo> GetMonitors()
{
QVector<tagDublicatorMonitorInfo> ret;
HRESULT hr = S_OK;
CDXGICapture dxgiCapture;
hr = dxgiCapture.Initialize();
if (FAILED(hr)) {
printf("Error[0x%08X]: CDXGICapture::Initialize failed.\n", hr);
return ret;
}
int nMonitorCount = dxgiCapture.GetDublicatorMonitorInfoCount();
printf("{\n");
if (nMonitorCount > 0) {
printf(" \"count\" : %u,\n", nMonitorCount);
printf(" \"monitors\" : [\n");
for (int i = 0; i < nMonitorCount; ++i) {
const tagDublicatorMonitorInfo *pInfo = dxgiCapture.GetDublicatorMonitorInfo(i);
if (nullptr != pInfo) {
printf(" {\n");
printf(" \"idx\" : %u,\n", pInfo->Idx);
printf(" \"name\" : \"%S\",\n", pInfo->DisplayName);
printf(" \"x\" : %d,\n", pInfo->Bounds.X);
printf(" \"y\" : %d,\n", pInfo->Bounds.Y);
printf(" \"width\" : %d,\n", pInfo->Bounds.Width);
printf(" \"height\" : %d,\n", pInfo->Bounds.Height);
printf(" \"rotation\" : %d\n", pInfo->RotationDegrees);
if (i < (nMonitorCount - 1)) {
printf(" },\n");
}
else {
printf(" }\n");
}
ret.push_back(*pInfo);
}
}
printf(" ]\n");
}
else {
printf(" \"count\" : %u\n", nMonitorCount);
}
printf("}\n");
dxgiCapture.Terminate();
return ret;
}
HRESULT InitD3D( HWND hWnd )
{
// Create the D3D object, which is needed to create the D3DDevice.
// D3DDevice所需要的D3D物件Direct3DCreate9回?D3DDevice?入值?使用者安?DirectX的版本
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
return E_FAIL;
// Set up the structure used to create the D3DDevice. Most parameters are
// zeroed out. We set Windowed to TRUE, since we want to do D3D in a
// window, and then set the SwapEffect to "discard", which is the most
// efficient method of presenting the back buffer to the display. And
// we request a back buffer format that matches the current desktop display
// format.
/*
用?建立D3DDevice的??。大多????0。
?定是否?"?窗化"?真,就是?示??窗化。
如果?D3D於?窗?行,?SwapEffect定"discard"??在後端??呈???最有效率。
?且我?要求後端??的?示格式??在的?面相符。
*/
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof( d3dpp ) ); //初始化d3d的??
d3dpp.Windowed = TRUE; //?定?窗化
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //提高效率
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; //??有呈??面相符格式(竟然是?定未知= =)
// Create the Direct3D device. Here we are using the default adapter (most
// systems only have one, unless they have multiple graphics hardware cards
// installed) and requesting the HAL (which is saying we want the hardware
// device rather than a software one). Software vertex processing is
// specified since we know it will work on all cards. On cards that support
// hardware vertex processing, though, we would see a big performance gain
// by specifying hardware vertex processing.
/*
建立Direct3D?置。我?使用??的adapter(?似?置的意思= =)。
?大多?的使用者??只有一??置(?示卡),除非他?有其多的?示卡。
?且要求HAL也就是?先用?示卡?示,而不是用???理。
既然我?知道????(角)?理的?理方式被定?所有?示卡。
於支援硬????理的?示卡上,我??看到?佳的?行效率。
*/
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, //??adapter
D3DDEVTYPE_HAL, //硬?加速
hWnd, //Handler名?
//D3DCREATE_SOFTWARE_VERTEXPROCESSING, //最後竟然用??
D3DCREATE_HARDWARE_VERTEXPROCESSING, //改用硬?加速吧
&d3dpp, //D3D??
&g_pd3dDevice //D3D最後?示?置??
) ) )
{
return E_FAIL;
}
// Device state would normally be set here
return S_OK;
}
int main(int argc, char *argv[])
{
setbuf(stdout, NULL);//让printf立即输出
QssEventFilter filter;
QApplication app(argc, argv);
MainWindow main;
InitD3D((HWND)main.winId());
ScreenGrab( g_pd3dDevice);
main.setWindowTitle("流媒体测试工具");
main.setFixedSize(1920,1080);
main.show();
return app.exec();
}