Skip to content

Commit 946b48d

Browse files
committed
Fix multi-monitor capturing
1 parent 1b2898b commit 946b48d

File tree

3 files changed

+91
-36
lines changed

3 files changed

+91
-36
lines changed

Diff for: build.sh

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ if [[ "$CI_NAME" == 'osx' || "$CI_NAME" == 'darwin' ]]; then
123123
BUILD_OPTION="-DUSE_CCACHE_CACHING=OFF"
124124
fi
125125

126+
if [[ $CI_TYPE == "github_action" ]]; then
127+
BUILD_OPTION="${BUILD_OPTION} -DCPACK_COMMAND_HDIUTIL=""/usr/bin/sudo /usr/bin/hdiutil"""
128+
fi
129+
126130
echo "Build option: ${BUILD_OPTION}"
127131

128132
mkdir -p build/.ccache

Diff for: sources/base/Grabber.cpp

+38-6
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,24 @@ void Grabber::setEnabled(bool enable)
101101

102102
void Grabber::setMonitorNits(int nits)
103103
{
104-
_targetMonitorNits = nits;
104+
if (_targetMonitorNits != nits)
105+
{
106+
_targetMonitorNits = nits;
107+
108+
Debug(_log, "Set nits to %i", _targetMonitorNits);
109+
110+
if (_initialized && !_blocked)
111+
{
112+
Debug(_log, "Restarting video grabber");
113+
uninit();
114+
start();
115+
}
116+
else
117+
{
118+
Info(_log, "Delayed restart of the grabber due to change of monitor nits value");
119+
_restartNeeded = true;
120+
}
121+
}
105122
}
106123

107124
void Grabber::setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom)
@@ -128,7 +145,24 @@ void Grabber::setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTo
128145

129146
void Grabber::enableHardwareAcceleration(bool hardware)
130147
{
131-
_hardware = hardware;
148+
if (_hardware != hardware)
149+
{
150+
_hardware = hardware;
151+
152+
Debug(_log, "Set hardware acceleration to %s", _hardware ? "enabled" : "disabled");
153+
154+
if (_initialized && !_blocked)
155+
{
156+
Debug(_log, "Restarting video grabber");
157+
uninit();
158+
start();
159+
}
160+
else
161+
{
162+
Info(_log, "Delayed restart of the grabber due to change of the hardware acceleration");
163+
_restartNeeded = true;
164+
}
165+
}
132166
}
133167

134168
bool Grabber::trySetInput(int input)
@@ -520,10 +554,8 @@ int Grabber::getTargetSystemFrameDimension(int& targetSizeX, int& targetSizeY)
520554

521555
int Grabber::getTargetSystemFrameDimension(int actualWidth, int actualHeight, int& targetSizeX, int& targetSizeY)
522556
{
523-
int startX = _cropLeft;
524-
int startY = _cropTop;
525-
int realSizeX = actualWidth - startX - _cropRight;
526-
int realSizeY = actualHeight - startY - _cropBottom;
557+
int realSizeX = actualWidth;
558+
int realSizeY = actualHeight;
527559

528560
if (realSizeX <= 16 || realSizeY <= 16)
529561
{

Diff for: sources/grabber/windows/DX/DxGrabber.cpp

+49-30
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ bool DxGrabber::initDirectX(QString selectedDeviceName)
314314
_multiMonitor = (selectedDeviceName == multiName);
315315

316316
IDXGIOutput* pOutput;
317-
for (UINT j = 0; pAdapter->EnumOutputs(j, &pOutput) != DXGI_ERROR_NOT_FOUND && (!exitNow || _multiMonitor); j++)
317+
318+
319+
for (UINT j = 0; pAdapter->EnumOutputs(j, &pOutput) != DXGI_ERROR_NOT_FOUND && (!exitNow || (_multiMonitor && result)); j++)
318320
{
319321
DXGI_OUTPUT_DESC oDesc{};
320322
pOutput->GetDesc(&oDesc);
@@ -329,38 +331,46 @@ bool DxGrabber::initDirectX(QString selectedDeviceName)
329331

330332
if (CHECK(pOutput->QueryInterface(__uuidof(IDXGIOutput6), reinterpret_cast<void**>(&pOutput6))))
331333
{
332-
HRESULT findDriver = E_FAIL;
333-
D3D_FEATURE_LEVEL featureLevel;
334-
std::vector<D3D_DRIVER_TYPE> driverTypes{
335-
D3D_DRIVER_TYPE_HARDWARE,
336-
D3D_DRIVER_TYPE_WARP,
337-
D3D_DRIVER_TYPE_REFERENCE,
338-
D3D_DRIVER_TYPE_UNKNOWN
339-
};
340-
341-
CLEAR(featureLevel);
342-
343-
for (auto& driverType : driverTypes)
334+
if (_d3dDevice == nullptr)
344335
{
345-
findDriver = D3D11CreateDevice(pAdapter, driverType,
346-
nullptr, D3D11_CREATE_DEVICE_BGRA_SUPPORT, nullptr, 0,
347-
D3D11_SDK_VERSION, &_d3dDevice, &featureLevel, &_d3dContext);
348-
349-
if (SUCCEEDED(findDriver))
336+
HRESULT findDriver = E_FAIL;
337+
D3D_FEATURE_LEVEL featureLevel;
338+
std::vector<D3D_DRIVER_TYPE> driverTypes{
339+
D3D_DRIVER_TYPE_HARDWARE,
340+
D3D_DRIVER_TYPE_WARP,
341+
D3D_DRIVER_TYPE_REFERENCE,
342+
D3D_DRIVER_TYPE_UNKNOWN
343+
};
344+
345+
CLEAR(featureLevel);
346+
347+
for (auto& driverType : driverTypes)
350348
{
351-
switch (driverType)
349+
findDriver = D3D11CreateDevice(pAdapter, driverType,
350+
nullptr, D3D11_CREATE_DEVICE_BGRA_SUPPORT, nullptr, 0,
351+
D3D11_SDK_VERSION, &_d3dDevice, &featureLevel, &_d3dContext);
352+
353+
if (SUCCEEDED(findDriver))
352354
{
353-
case D3D_DRIVER_TYPE_HARDWARE: Info(_log, "Selected D3D_DRIVER_TYPE_HARDWARE"); break;
354-
case D3D_DRIVER_TYPE_WARP: Info(_log, "Selected D3D_DRIVER_TYPE_WARP"); break;
355-
case D3D_DRIVER_TYPE_REFERENCE: Info(_log, "Selected D3D_DRIVER_TYPE_REFERENCE"); break;
356-
case D3D_DRIVER_TYPE_UNKNOWN: Info(_log, "Selected D3D_DRIVER_TYPE_UNKNOWN"); break;
355+
switch (driverType)
356+
{
357+
case D3D_DRIVER_TYPE_HARDWARE: Info(_log, "Selected D3D_DRIVER_TYPE_HARDWARE"); break;
358+
case D3D_DRIVER_TYPE_WARP: Info(_log, "Selected D3D_DRIVER_TYPE_WARP"); break;
359+
case D3D_DRIVER_TYPE_REFERENCE: Info(_log, "Selected D3D_DRIVER_TYPE_REFERENCE"); break;
360+
case D3D_DRIVER_TYPE_UNKNOWN: Info(_log, "Selected D3D_DRIVER_TYPE_UNKNOWN"); break;
361+
}
362+
363+
break;
357364
}
365+
}
358366

359-
break;
367+
if (!SUCCEEDED(findDriver))
368+
{
369+
_d3dContext = nullptr;
360370
}
361371
}
362372

363-
if (CHECK(findDriver) && _d3dDevice != nullptr)
373+
if (_d3dDevice != nullptr)
364374
{
365375
HRESULT status = E_FAIL;
366376
DXGI_OUTPUT_DESC1 descGamut;
@@ -420,7 +430,7 @@ bool DxGrabber::initDirectX(QString selectedDeviceName)
420430

421431
if (!display->wideGamut)
422432
{
423-
int maxSize = std::max((display->actualWidth - _cropLeft - _cropRight), (display->actualHeight - _cropTop - _cropBottom));
433+
int maxSize = std::max(display->actualWidth, display->actualHeight);
424434

425435
display->actualDivide = 0;
426436
while (maxSize > _width)
@@ -435,7 +445,7 @@ bool DxGrabber::initDirectX(QString selectedDeviceName)
435445
else
436446
{
437447
display->actualDivide = -1;
438-
getTargetSystemFrameDimension(targetSizeX, targetSizeY);
448+
getTargetSystemFrameDimension(display->actualWidth, display->actualHeight, targetSizeX, targetSizeY);
439449
}
440450
}
441451

@@ -479,6 +489,7 @@ bool DxGrabber::initDirectX(QString selectedDeviceName)
479489
else
480490
{
481491
result = true;
492+
_handles.emplace_back(std::move(display));
482493
Info(_log, "The DX11 device has been initialized. Hardware acceleration is disabled");
483494
}
484495
}
@@ -517,6 +528,11 @@ bool DxGrabber::initDirectX(QString selectedDeviceName)
517528

518529
SafeRelease(&pFactory);
519530

531+
if (!result && _handles.size() > 0)
532+
{
533+
uninit();
534+
}
535+
520536
return result;
521537
}
522538

@@ -760,8 +776,11 @@ void DxGrabber::grabFrame()
760776
images.push_back(std::pair<int, Image<ColorRgb>>(width, image));
761777
}
762778

763-
width += display->actualWidth;
764-
height = std::max(display->actualHeight, height);
779+
int targetSizeX = 0, targetSizeY = 0;
780+
int divide = getTargetSystemFrameDimension(display->actualWidth, display->actualHeight, targetSizeX, targetSizeY);
781+
782+
width += targetSizeX;
783+
height = std::max(targetSizeY, height);
765784
}
766785

767786
if (useCache && (_cacheImage.width() != width || _cacheImage.height() != height))
@@ -911,7 +930,7 @@ int DxGrabber::captureFrame(DisplayHandle& display, Image<ColorRgb>& image)
911930
int divide = getTargetSystemFrameDimension(display.actualWidth, display.actualHeight, targetSizeX, targetSizeY);
912931

913932
image = Image<ColorRgb>(targetSizeX, targetSizeY);
914-
FrameDecoder::processSystemImageBGRA(image, targetSizeX, targetSizeY, _cropLeft, _cropTop, (uint8_t*)internalMap.pData, display.actualWidth, display.actualHeight, divide, (_hdrToneMappingEnabled == 0 || !_lutBufferInit || !useLut) ? nullptr : _lut.data(), lineSize);
933+
FrameDecoder::processSystemImageBGRA(image, targetSizeX, targetSizeY, 0, 0, (uint8_t*)internalMap.pData, display.actualWidth, display.actualHeight, divide, (_hdrToneMappingEnabled == 0 || !_lutBufferInit || !useLut) ? nullptr : _lut.data(), lineSize);
915934

916935
result = 1;
917936
_d3dContext->Unmap(display.d3dSourceTexture, 0);

0 commit comments

Comments
 (0)