Commit 900bdb55486c64ace715331e25eed77bf5ae43b8

Authored by Charles Otto
1 parent 8d78f0db

If multiple templates are passed to stream, display them in sequence

If stream receives a templatelist with multiple templates, display them in
sequence (currently kind of a hack). If this behavior is undesirable, it can
be avoided by using distribute.
Showing 1 changed file with 41 additions and 13 deletions
openbr/plugins/stream.cpp
@@ -241,7 +241,7 @@ public: @@ -241,7 +241,7 @@ public:
241 } 241 }
242 242
243 virtual void close() = 0; 243 virtual void close() = 0;
244 - virtual bool open(Template & output) = 0; 244 + virtual bool open(Template & output, int start_index=0) = 0;
245 virtual bool isOpen() = 0; 245 virtual bool isOpen() = 0;
246 246
247 virtual bool getNext(FrameData & input) = 0; 247 virtual bool getNext(FrameData & input) = 0;
@@ -262,13 +262,13 @@ class VideoDataSource : public DataSource @@ -262,13 +262,13 @@ class VideoDataSource : public DataSource
262 public: 262 public:
263 VideoDataSource(int maxFrames) : DataSource(maxFrames) {} 263 VideoDataSource(int maxFrames) : DataSource(maxFrames) {}
264 264
265 - bool open(Template &input) 265 + bool open(Template &input, int start_index=0)
266 { 266 {
267 final_frame = -1; 267 final_frame = -1;
268 last_issued = -2; 268 last_issued = -2;
269 last_received = -3; 269 last_received = -3;
270 270
271 - next_idx = 0; 271 + next_idx = start_index;
272 basis = input; 272 basis = input;
273 bool is_int = false; 273 bool is_int = false;
274 int anInt = input.file.name.toInt(&is_int); 274 int anInt = input.file.name.toInt(&is_int);
@@ -336,11 +336,11 @@ public: @@ -336,11 +336,11 @@ public:
336 } 336 }
337 bool data_ok; 337 bool data_ok;
338 338
339 - bool open(Template &input) 339 + bool open(Template &input, int start_index=0)
340 { 340 {
341 basis = input; 341 basis = input;
342 current_idx = 0; 342 current_idx = 0;
343 - next_sequence = 0; 343 + next_sequence = start_index;
344 final_frame = -1; 344 final_frame = -1;
345 last_issued = -2; 345 last_issued = -2;
346 last_received = -3; 346 last_received = -3;
@@ -406,22 +406,31 @@ public: @@ -406,22 +406,31 @@ public:
406 } 406 }
407 } 407 }
408 408
409 - bool open(Template & input) 409 + bool open(TemplateList & input)
  410 + {
  411 + currentIdx = 0;
  412 + templates = input;
  413 +
  414 + return open(templates[currentIdx]);
  415 + }
  416 +
  417 + bool open(Template & input, int start_index=0)
410 { 418 {
411 close(); 419 close();
412 final_frame = -1; 420 final_frame = -1;
413 last_issued = -2; 421 last_issued = -2;
414 last_received = -3; 422 last_received = -3;
  423 + next_frame = start_index;
415 424
416 // Input has no matrices? Its probably a video that hasn't been loaded yet 425 // Input has no matrices? Its probably a video that hasn't been loaded yet
417 if (input.empty()) { 426 if (input.empty()) {
418 actualSource = new VideoDataSource(0); 427 actualSource = new VideoDataSource(0);
419 - actualSource->open(input); 428 + actualSource->open(input, next_frame);
420 } 429 }
421 else { 430 else {
422 // create frame dealer 431 // create frame dealer
423 actualSource = new TemplateDataSource(0); 432 actualSource = new TemplateDataSource(0);
424 - actualSource->open(input); 433 + actualSource->open(input, next_frame);
425 } 434 }
426 if (!isOpen()) { 435 if (!isOpen()) {
427 delete actualSource; 436 delete actualSource;
@@ -434,10 +443,31 @@ public: @@ -434,10 +443,31 @@ public:
434 bool isOpen() { return !actualSource ? false : actualSource->isOpen(); } 443 bool isOpen() { return !actualSource ? false : actualSource->isOpen(); }
435 444
436 protected: 445 protected:
  446 + int currentIdx;
  447 + int next_frame;
  448 + TemplateList templates;
437 DataSource * actualSource; 449 DataSource * actualSource;
438 bool getNext(FrameData & output) 450 bool getNext(FrameData & output)
439 { 451 {
440 - return actualSource->getNext(output); 452 + bool res = actualSource->getNext(output);
  453 + if (res) {
  454 + next_frame = output.sequenceNumber+1;
  455 + return true;
  456 + }
  457 +
  458 + while(!res) {
  459 + currentIdx++;
  460 +
  461 + if (currentIdx >= templates.size())
  462 + return false;
  463 + bool open_res = open(templates[currentIdx], next_frame);
  464 + if (!open_res)
  465 + return false;
  466 + res = actualSource->getNext(output);
  467 + }
  468 +
  469 + next_frame = output.sequenceNumber+1;
  470 + return res;
441 } 471 }
442 472
443 }; 473 };
@@ -796,11 +826,9 @@ public: @@ -796,11 +826,9 @@ public:
796 // start processing 826 // start processing
797 void projectUpdate(const TemplateList & src, TemplateList & dst) 827 void projectUpdate(const TemplateList & src, TemplateList & dst)
798 { 828 {
799 - if (src.size() != 1)  
800 - qFatal("Expected single template input to stream");  
801 -  
802 dst = src; 829 dst = src;
803 - bool res = readStage->dataSource.open(dst[0]); 830 +
  831 + bool res = readStage->dataSource.open(dst);
804 if (!res) return; 832 if (!res) return;
805 833
806 QThreadPool::globalInstance()->releaseThread(); 834 QThreadPool::globalInstance()->releaseThread();