refactor: improve webcam thread execution and frame handling
This commit is contained in:
@ -38,12 +38,12 @@ void ProcessWebcamThread::Execute() {
|
||||
bool temp_not_finish = true;
|
||||
bool temp_pause = true;
|
||||
bool temp_record_frame = false;
|
||||
float frame_clock = 0.0f;
|
||||
current_frame_clock = 0.0;
|
||||
//construction LUT pour synchro avec la clock squirrel
|
||||
std::ofstream lutFile(outputVideoName+"_lut.bin", std::ios::binary);
|
||||
__LOG_CAM__ << "NEW RECORDING THREAD "<<videoIndex<<" LAUNCHED \n";
|
||||
|
||||
int frame_index = 0;
|
||||
while (temp_not_finish) {
|
||||
|
||||
mutex_not_finish.Lock();
|
||||
@ -54,17 +54,25 @@ void ProcessWebcamThread::Execute() {
|
||||
temp_pause = pause;
|
||||
mutex_pause.Unlock();
|
||||
|
||||
// Drainer la camera en permanence, meme en pause : si on lit pas, la file
|
||||
// du driver grossit et les frames récupéres ensuite dates du passé, ce qui
|
||||
// decale la video par rapport a la clock (derive qui s'accumule)
|
||||
if (!InputVideo->grab()) {
|
||||
Platform::Get().Sleep(10);
|
||||
continue;
|
||||
}
|
||||
|
||||
mutex_record_frame.Lock();
|
||||
temp_record_frame = record_frame;
|
||||
frame_clock = current_frame_clock;
|
||||
record_frame = false;
|
||||
mutex_record_frame.Unlock();
|
||||
|
||||
if (temp_pause || !temp_record_frame)
|
||||
Platform::Get().Sleep(10);
|
||||
else{
|
||||
InputVideo->read(*im);
|
||||
outputVideo->write(*im);
|
||||
|
||||
lutFile.write(reinterpret_cast<const char*>(¤t_frame_clock),sizeof(float));
|
||||
if (!temp_pause && temp_record_frame) {
|
||||
if (InputVideo->retrieve(*im)) {
|
||||
outputVideo->write(*im);
|
||||
lutFile.write(reinterpret_cast<const char*>(&frame_clock), sizeof(float));
|
||||
}
|
||||
}
|
||||
}
|
||||
__LOG_CAM__ << "THREAD STOPPED "<<videoIndex<<"\n";
|
||||
@ -251,7 +259,9 @@ bool Webcam::Open(int width_, int height_) {
|
||||
int device_id = -1;
|
||||
for (int i = 0; i < id_devices.size(); i++)
|
||||
{
|
||||
InputVideo->open(id_devices[i]);
|
||||
// CAP_DSHOW : meme ordre d'enumeration que la blacklist DirectShow ci-dessus
|
||||
// et pas de waitlist interne qui prend du retard
|
||||
InputVideo->open(id_devices[i] + CAP_DSHOW);
|
||||
if(InputVideo->isOpened()){
|
||||
device_id = id_devices[i];
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user