Skip to content

Commit

Permalink
Using information available instead of getting it again in the Proces…
Browse files Browse the repository at this point in the history
…sFrame Functions
  • Loading branch information
smasherprog committed Jul 11, 2017
1 parent b9e1bf5 commit a6addc3
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 95 deletions.
183 changes: 93 additions & 90 deletions include/Internal/ThreadManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,109 +12,112 @@ using namespace std::chrono_literals;
// this is internal stuff..
namespace SL
{
namespace Screen_Capture
{
class ThreadManager
namespace Screen_Capture
{
class ThreadManager
{

std::vector<std::thread> m_ThreadHandles;
std::shared_ptr<std::atomic_bool> TerminateThreadsEvent;
std::vector<std::thread> m_ThreadHandles;
std::shared_ptr<std::atomic_bool> TerminateThreadsEvent;

public:
ThreadManager();
~ThreadManager();
void Init(const std::shared_ptr<Thread_Data>& settings);
void Join();
};
template <class T, class F> bool TryCaptureMouse(const F& data)
{
T frameprocessor;
auto ret = frameprocessor.Init(data);
if(ret != DUPL_RETURN_SUCCESS) {
return false;
}
frameprocessor.ImageBufferSize = frameprocessor.MaxCursurorSize * frameprocessor.MaxCursurorSize * PixelStride;
public:
ThreadManager();
~ThreadManager();
void Init(const std::shared_ptr<Thread_Data>& settings);
void Join();
};
template <class T, class F> bool TryCaptureMouse(const F& data)
{
T frameprocessor;
auto ret = frameprocessor.Init(data);
if (ret != DUPL_RETURN_SUCCESS) {
return false;
}
frameprocessor.ImageBufferSize = frameprocessor.MaxCursurorSize * frameprocessor.MaxCursurorSize * PixelStride;

frameprocessor.OldImageBuffer = std::make_unique<unsigned char[]>(frameprocessor.ImageBufferSize);
frameprocessor.NewImageBuffer = std::make_unique<unsigned char[]>(frameprocessor.ImageBufferSize);
frameprocessor.OldImageBuffer = std::make_unique<unsigned char[]>(frameprocessor.ImageBufferSize);
frameprocessor.NewImageBuffer = std::make_unique<unsigned char[]>(frameprocessor.ImageBufferSize);

while(!data->TerminateThreadsEvent) {
// get a copy of the shared_ptr in a safe way
auto timer = std::atomic_load(&data->Mouse_Capture_Timer);
timer->start();
// Process Frame
ret = frameprocessor.ProcessFrame();
if(ret != DUPL_RETURN_SUCCESS) {
if(ret == DUPL_RETURN_ERROR_EXPECTED) {
// The system is in a transition state so request the duplication be restarted
data->ExpectedErrorEvent = true;
std::cout << "Exiting Thread due to expected error " << std::endl;
} else {
// Unexpected error so exit the application
data->UnexpectedErrorEvent = true;
std::cout << "Exiting Thread due to Unexpected error " << std::endl;
while (!data->TerminateThreadsEvent) {
// get a copy of the shared_ptr in a safe way
auto timer = std::atomic_load(&data->Mouse_Capture_Timer);
timer->start();
// Process Frame
ret = frameprocessor.ProcessFrame();
if (ret != DUPL_RETURN_SUCCESS) {
if (ret == DUPL_RETURN_ERROR_EXPECTED) {
// The system is in a transition state so request the duplication be restarted
data->ExpectedErrorEvent = true;
std::cout << "Exiting Thread due to expected error " << std::endl;
}
else {
// Unexpected error so exit the application
data->UnexpectedErrorEvent = true;
std::cout << "Exiting Thread due to Unexpected error " << std::endl;
}
return true;
}
timer->wait();
while (data->Paused) {
std::this_thread::sleep_for(50ms);
}
return true;
}
timer->wait();
while(data->Paused) {
std::this_thread::sleep_for(50ms);
}
return true;
}
return true;
}


template <class T, class F> bool TryCaptureMonitor(const F& data, Monitor& monitor)
{
T frameprocessor;
auto ret = frameprocessor.Init(data, monitor);
if(ret != DUPL_RETURN_SUCCESS) {
return false;
}
frameprocessor.ImageBufferSize = Width(monitor) * Height(monitor) * PixelStride;
if(data->CaptureDifMonitor) { // only need the old buffer if difs are needed. If no dif is needed, then the
// image is always new
frameprocessor.OldImageBuffer = std::make_unique<unsigned char[]>(frameprocessor.ImageBufferSize);
frameprocessor.NewImageBuffer = std::make_unique<unsigned char[]>(frameprocessor.ImageBufferSize);
}
if((data->CaptureEntireMonitor) && !frameprocessor.NewImageBuffer) {

frameprocessor.NewImageBuffer = std::make_unique<unsigned char[]>(frameprocessor.ImageBufferSize);
}
while(!data->TerminateThreadsEvent) {
// get a copy of the shared_ptr in a safe way
auto timer = std::atomic_load(&data->Monitor_Capture_Timer);
timer->start();
auto monitors = GetMonitors();
if(isMonitorInsideBounds(monitors, monitor)) {
ret = frameprocessor.ProcessFrame();
} else {
// something happened, rebuild
ret = DUPL_RETURN_ERROR_EXPECTED;

template <class T, class F> bool TryCaptureMonitor(const F& data, Monitor& monitor)
{
T frameprocessor;
auto ret = frameprocessor.Init(data, monitor);
if (ret != DUPL_RETURN_SUCCESS) {
return false;
}
frameprocessor.ImageBufferSize = Width(monitor) * Height(monitor) * PixelStride;
if (data->CaptureDifMonitor) { // only need the old buffer if difs are needed. If no dif is needed, then the
// image is always new
frameprocessor.OldImageBuffer = std::make_unique<unsigned char[]>(frameprocessor.ImageBufferSize);
frameprocessor.NewImageBuffer = std::make_unique<unsigned char[]>(frameprocessor.ImageBufferSize);
}
if ((data->CaptureEntireMonitor) && !frameprocessor.NewImageBuffer) {

if(ret != DUPL_RETURN_SUCCESS) {
if(ret == DUPL_RETURN_ERROR_EXPECTED) {
// The system is in a transition state so request the duplication be restarted
data->ExpectedErrorEvent = true;
std::cout << "Exiting Thread due to expected error " << std::endl;
} else {
// Unexpected error so exit the application
data->UnexpectedErrorEvent = true;
std::cout << "Exiting Thread due to Unexpected error " << std::endl;
}
return true;
frameprocessor.NewImageBuffer = std::make_unique<unsigned char[]>(frameprocessor.ImageBufferSize);
}
timer->wait();
while(data->Paused) {
std::this_thread::sleep_for(50ms);
while (!data->TerminateThreadsEvent) {
// get a copy of the shared_ptr in a safe way
auto timer = std::atomic_load(&data->Monitor_Capture_Timer);
timer->start();
auto monitors = GetMonitors();
if (isMonitorInsideBounds(monitors, monitor)) {
ret = frameprocessor.ProcessFrame(monitors[Index(monitor)]);
}
else {
// something happened, rebuild
ret = DUPL_RETURN_ERROR_EXPECTED;
}

if (ret != DUPL_RETURN_SUCCESS) {
if (ret == DUPL_RETURN_ERROR_EXPECTED) {
// The system is in a transition state so request the duplication be restarted
data->ExpectedErrorEvent = true;
std::cout << "Exiting Thread due to expected error " << std::endl;
}
else {
// Unexpected error so exit the application
data->UnexpectedErrorEvent = true;
std::cout << "Exiting Thread due to Unexpected error " << std::endl;
}
return true;
}
timer->wait();
while (data->Paused) {
std::this_thread::sleep_for(50ms);
}
}
return true;
}
return true;
}

void RunCaptureMonitor(std::shared_ptr<Thread_Data> data, Monitor monitor);
void RunCaptureMouse(std::shared_ptr<Thread_Data> data);
}
void RunCaptureMonitor(std::shared_ptr<Thread_Data> data, Monitor monitor);
void RunCaptureMouse(std::shared_ptr<Thread_Data> data);
}
}
2 changes: 1 addition & 1 deletion include/windows/DXFrameProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace SL {

public:
DUPL_RETURN Init(std::shared_ptr<Thread_Data> data, Monitor& monitor);
DUPL_RETURN ProcessFrame();
DUPL_RETURN ProcessFrame(const Monitor& currentmonitorinfo);

};

Expand Down
2 changes: 1 addition & 1 deletion include/windows/GDIFrameProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace SL {
std::shared_ptr<Thread_Data> Data;
public:
DUPL_RETURN Init(std::shared_ptr<Thread_Data> data, Monitor& monitor);
DUPL_RETURN ProcessFrame();
DUPL_RETURN ProcessFrame(const Monitor& currentmonitorinfo);

};
}
Expand Down
4 changes: 2 additions & 2 deletions src/windows/DXFrameProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ namespace SL {
// Process a given frame and its metadata
//

DUPL_RETURN DXFrameProcessor::ProcessFrame()
DUPL_RETURN DXFrameProcessor::ProcessFrame(const Monitor& currentmonitorinfo)
{
auto Ret = DUPL_RETURN_SUCCESS;

Expand Down Expand Up @@ -394,7 +394,7 @@ namespace SL {
return ProcessFailure(Device.Get(), L"Failed to create staging texture for move rects", L"Error", hr, SystemTransitionsExpectedErrors);
}
}
if (ThisDesc.Width == Width(SelectedMonitor) && ThisDesc.Height == Height(SelectedMonitor)) {
if (Width(currentmonitorinfo) == Width(SelectedMonitor) && Height(currentmonitorinfo) == Height(SelectedMonitor)) {
DeviceContext->CopyResource(StagingSurf.Get(), aquireddesktopimage.Get());
}
else {
Expand Down
3 changes: 2 additions & 1 deletion src/windows/GDIFrameProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ namespace SL {
//
// Process a given frame and its metadata
//
DUPL_RETURN GDIFrameProcessor::ProcessFrame()
DUPL_RETURN GDIFrameProcessor::ProcessFrame(const Monitor& currentmonitorinfo)
{

auto Ret = DUPL_RETURN_SUCCESS;

ImageRect ret;
Expand Down

0 comments on commit a6addc3

Please sign in to comment.