Commit 900bdb55486c64ace715331e25eed77bf5ae43b8
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 | 241 | } |
| 242 | 242 | |
| 243 | 243 | virtual void close() = 0; |
| 244 | - virtual bool open(Template & output) = 0; | |
| 244 | + virtual bool open(Template & output, int start_index=0) = 0; | |
| 245 | 245 | virtual bool isOpen() = 0; |
| 246 | 246 | |
| 247 | 247 | virtual bool getNext(FrameData & input) = 0; |
| ... | ... | @@ -262,13 +262,13 @@ class VideoDataSource : public DataSource |
| 262 | 262 | public: |
| 263 | 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 | 267 | final_frame = -1; |
| 268 | 268 | last_issued = -2; |
| 269 | 269 | last_received = -3; |
| 270 | 270 | |
| 271 | - next_idx = 0; | |
| 271 | + next_idx = start_index; | |
| 272 | 272 | basis = input; |
| 273 | 273 | bool is_int = false; |
| 274 | 274 | int anInt = input.file.name.toInt(&is_int); |
| ... | ... | @@ -336,11 +336,11 @@ public: |
| 336 | 336 | } |
| 337 | 337 | bool data_ok; |
| 338 | 338 | |
| 339 | - bool open(Template &input) | |
| 339 | + bool open(Template &input, int start_index=0) | |
| 340 | 340 | { |
| 341 | 341 | basis = input; |
| 342 | 342 | current_idx = 0; |
| 343 | - next_sequence = 0; | |
| 343 | + next_sequence = start_index; | |
| 344 | 344 | final_frame = -1; |
| 345 | 345 | last_issued = -2; |
| 346 | 346 | last_received = -3; |
| ... | ... | @@ -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 | 419 | close(); |
| 412 | 420 | final_frame = -1; |
| 413 | 421 | last_issued = -2; |
| 414 | 422 | last_received = -3; |
| 423 | + next_frame = start_index; | |
| 415 | 424 | |
| 416 | 425 | // Input has no matrices? Its probably a video that hasn't been loaded yet |
| 417 | 426 | if (input.empty()) { |
| 418 | 427 | actualSource = new VideoDataSource(0); |
| 419 | - actualSource->open(input); | |
| 428 | + actualSource->open(input, next_frame); | |
| 420 | 429 | } |
| 421 | 430 | else { |
| 422 | 431 | // create frame dealer |
| 423 | 432 | actualSource = new TemplateDataSource(0); |
| 424 | - actualSource->open(input); | |
| 433 | + actualSource->open(input, next_frame); | |
| 425 | 434 | } |
| 426 | 435 | if (!isOpen()) { |
| 427 | 436 | delete actualSource; |
| ... | ... | @@ -434,10 +443,31 @@ public: |
| 434 | 443 | bool isOpen() { return !actualSource ? false : actualSource->isOpen(); } |
| 435 | 444 | |
| 436 | 445 | protected: |
| 446 | + int currentIdx; | |
| 447 | + int next_frame; | |
| 448 | + TemplateList templates; | |
| 437 | 449 | DataSource * actualSource; |
| 438 | 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 | 826 | // start processing |
| 797 | 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 | 829 | dst = src; |
| 803 | - bool res = readStage->dataSource.open(dst[0]); | |
| 830 | + | |
| 831 | + bool res = readStage->dataSource.open(dst); | |
| 804 | 832 | if (!res) return; |
| 805 | 833 | |
| 806 | 834 | QThreadPool::globalInstance()->releaseThread(); | ... | ... |