Commit 189d2a1da2a1299cd22b2417d1f10a316621b6e7

Authored by Charles Otto
1 parent 4e956a47

Avoid a mysterious crash related to closing VideoCaptures

Don't explicitly release the VideoCapture when it runs out of frames, further
investigation is needed, but this seems to cause an overrun or something

Additionally, make TemplateDataSource behave consistently with VideoDataSource,
breaking only after getNext has been called when no further frames are
available.
Showing 1 changed file with 19 additions and 14 deletions
openbr/plugins/stream.cpp
... ... @@ -11,8 +11,6 @@
11 11 #include "openbr/core/opencvutils.h"
12 12 #include "openbr/core/qtutils.h"
13 13  
14   -#include <iostream>
15   -
16 14 using namespace cv;
17 15  
18 16 namespace br
... ... @@ -258,12 +256,16 @@ public:
258 256 next_idx = 0;
259 257 basis = input;
260 258 video.open(input.file.name.toStdString());
261   - return video.isOpened();
  259 + video_ok = video.isOpened();
  260 + return video_ok;
262 261 }
  262 + bool video_ok;
263 263  
264   - bool isOpen() { return video.isOpened(); }
  264 + bool isOpen() { return video_ok; }
265 265  
266   - void close() { video.release(); }
  266 + void close() {
  267 + video.release();
  268 + }
267 269  
268 270 private:
269 271 bool getNext(FrameData & output)
... ... @@ -279,8 +281,8 @@ private:
279 281  
280 282 bool res = video.read(output.data.last().last());
281 283 if (!res) {
282   - video.release();
283   - return false;
  284 + video_ok = false;
  285 + return video_ok;
284 286 }
285 287 output.data.last().file.set("FrameNumber", output.sequenceNumber);
286 288 return true;
... ... @@ -299,7 +301,9 @@ public:
299 301 TemplateDataSource(int maxFrames) : DataSource(maxFrames)
300 302 {
301 303 current_idx = INT_MAX;
  304 + data_ok = false;
302 305 }
  306 + bool data_ok;
303 307  
304 308 bool open(Template &input)
305 309 {
... ... @@ -309,10 +313,13 @@ public:
309 313 final_frame = -1;
310 314 last_issued = -2;
311 315  
312   - return isOpen();
  316 + data_ok = current_idx < basis.size();
  317 + return data_ok;
313 318 }
314 319  
315   - bool isOpen() { return current_idx < basis.size() ; }
  320 + bool isOpen() {
  321 + return data_ok;
  322 + }
316 323  
317 324 void close()
318 325 {
... ... @@ -323,7 +330,8 @@ public:
323 330 private:
324 331 bool getNext(FrameData & output)
325 332 {
326   - if (!isOpen())
  333 + data_ok = current_idx < basis.size();
  334 + if (!data_ok)
327 335 return false;
328 336  
329 337 output.data.append(basis[current_idx]);
... ... @@ -332,6 +340,7 @@ private:
332 340 output.sequenceNumber = next_sequence;
333 341 next_sequence++;
334 342  
  343 + output.data.last().file.set("FrameNumber", output.sequenceNumber);
335 344 return true;
336 345 }
337 346  
... ... @@ -595,10 +604,6 @@ public:
595 604  
596 605 FrameData * run(FrameData * input, bool & should_continue)
597 606 {
598   - if (input != NULL) {
599   - dataSource.returnFrame(input);
600   - }
601   -
602 607 // Is there anything on our input buffer? If so we should start a thread with that.
603 608 QWriteLocker lock(&statusLock);
604 609 input = dataSource.tryGetFrame();
... ...