Skip to content

Commit

Permalink
Merge pull request mipops#835 from mipops/linux-capture-rebased
Browse files Browse the repository at this point in the history
Linux capture rebased
  • Loading branch information
dericed authored Mar 26, 2024
2 parents a209b1f + 0e4473c commit c5b7171
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 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,20 +406,20 @@ void LinuxWrapper::StartCaptureSession()
ProcessFrameThread = new thread([this]() {
do
{
FrameBufferLock.lock();
if (Wrapper && !FrameBuffer.empty())
unique_lock Lock(FrameBufferLock);
FrameBufferCondition.wait_for(Lock, chrono::milliseconds(100));
while (!FrameBuffer.empty())
{
frame Cur = FrameBuffer.back();
frame Cur = FrameBuffer.front();
FrameBuffer.pop();

Wrapper->Parse_Buffer(Cur.Data, Cur.Size);
if (Wrapper)
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 Expand Up @@ -452,7 +453,7 @@ void LinuxWrapper::StopCaptureSession()
FrameBufferLock.lock();
while (!FrameBuffer.empty())
{
delete[] FrameBuffer.back().Data;
delete[] FrameBuffer.front().Data;
FrameBuffer.pop();
}
FrameBufferLock.unlock();
Expand Down

0 comments on commit c5b7171

Please sign in to comment.