Skip to content

Commit

Permalink
Improve CPU usage for linux capture
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Gervais <[email protected]>
  • Loading branch information
g-maxime committed Mar 20, 2024
1 parent f5c9ddc commit 16daf07
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Source/Common/LinuxWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//---------------------------------------------------------------------------
#include "Common/LinuxWrapper.h"

#include <condition_variable>
#include <ctime>
#include <queue>
#include <vector>
Expand All @@ -17,8 +18,6 @@
#include <libavc1394/avc1394.h>
#include <libavc1394/avc1394_vcr.h>

#include <iostream>

using namespace std;

#define CTLVCR0 AVC1394_CTYPE_CONTROL | AVC1394_SUBUNIT_TYPE_TAPE_RECORDER | AVC1394_SUBUNIT_ID_0
Expand All @@ -37,6 +36,7 @@ atomic<time_t> LastInput;

queue<frame> FrameBuffer;
mutex FrameBufferLock;
condition_variable FrameBufferCondition;


//---------------------------------------------------------------------------
Expand All @@ -53,6 +53,7 @@ static int ReceiveFrame(unsigned char* Data, int Lenght, int, void *UserData)
FrameBufferLock.lock();
FrameBuffer.push(Cur);
FrameBufferLock.unlock();
FrameBufferCondition.notify_all();

return 0;
}
Expand Down Expand Up @@ -405,8 +406,9 @@ void LinuxWrapper::StartCaptureSession()
ProcessFrameThread = new thread([this]() {
do
{
FrameBufferLock.lock();
if (!FrameBuffer.empty())
unique_lock Lock(FrameBufferLock);
FrameBufferCondition.wait_for(Lock, chrono::milliseconds(100));
while (!FrameBuffer.empty())
{
frame Cur = FrameBuffer.front();
FrameBuffer.pop();
Expand All @@ -415,11 +417,9 @@ void LinuxWrapper::StartCaptureSession()
Wrapper->Parse_Buffer(Cur.Data, Cur.Size);
delete[] Cur.Data;
}
FrameBufferLock.unlock();

this_thread::yield();
Lock.unlock();
}
while (!Raw1394PoolingThread_Terminate);
while (!ProcessFrameThread_Terminate);
});
}
}
Expand Down

0 comments on commit 16daf07

Please sign in to comment.