Commit f4927d54e55c0782e76c8b6a5e902d488a7546c9
1 parent
e4df7143
Hacks to make stream work even when sending empty matrices
Showing
1 changed file
with
60 additions
and
5 deletions
openbr/plugins/stream.cpp
| ... | ... | @@ -468,6 +468,7 @@ public: |
| 468 | 468 | current_matrix_idx = 0; |
| 469 | 469 | |
| 470 | 470 | data_ok = current_matrix_idx < basis.size(); |
| 471 | + qDebug("concrete open res is %d %d %d", data_ok, current_matrix_idx, basis.size()); | |
| 471 | 472 | return data_ok; |
| 472 | 473 | } |
| 473 | 474 | |
| ... | ... | @@ -488,7 +489,9 @@ private: |
| 488 | 489 | if (!data_ok) |
| 489 | 490 | return false; |
| 490 | 491 | |
| 492 | + | |
| 491 | 493 | output.data.append(basis[current_matrix_idx]); |
| 494 | + output.data.last().file = basis.file; | |
| 492 | 495 | current_matrix_idx++; |
| 493 | 496 | |
| 494 | 497 | output.sequenceNumber = next_sequence_number; |
| ... | ... | @@ -506,6 +509,52 @@ private: |
| 506 | 509 | bool data_ok; |
| 507 | 510 | }; |
| 508 | 511 | |
| 512 | +class SingleDataSource : public DataSource | |
| 513 | +{ | |
| 514 | +public: | |
| 515 | + SingleDataSource(int maxFrames) : DataSource(maxFrames) | |
| 516 | + { | |
| 517 | + data_ok = false; | |
| 518 | + } | |
| 519 | + | |
| 520 | + // To "open" it we just set appropriate indices, we assume that if this | |
| 521 | + // is an image, it is already loaded into memory. | |
| 522 | + bool concreteOpen(Template &input) | |
| 523 | + { | |
| 524 | + basis = input; | |
| 525 | +// basis.file.name = (Globals->path.isEmpty() ? "" : Globals->path + "/") + basis.file.name; | |
| 526 | + | |
| 527 | + data_ok =true; | |
| 528 | + return data_ok; | |
| 529 | + } | |
| 530 | + | |
| 531 | + bool isOpen() { | |
| 532 | + return data_ok; | |
| 533 | + } | |
| 534 | + | |
| 535 | + void close() | |
| 536 | + { | |
| 537 | + data_ok = false; | |
| 538 | + basis.clear(); | |
| 539 | + } | |
| 540 | + | |
| 541 | +private: | |
| 542 | + bool getNext(FrameData & output) | |
| 543 | + { | |
| 544 | + if (!data_ok) | |
| 545 | + return false; | |
| 546 | + | |
| 547 | + output.data.append(basis); | |
| 548 | + data_ok = false; | |
| 549 | + return true; | |
| 550 | + } | |
| 551 | + | |
| 552 | + Template basis; | |
| 553 | + | |
| 554 | + // Have we sent our template yet? | |
| 555 | + bool data_ok; | |
| 556 | +}; | |
| 557 | + | |
| 509 | 558 | |
| 510 | 559 | class ProcessingStage; |
| 511 | 560 | |
| ... | ... | @@ -1153,14 +1202,20 @@ public: |
| 1153 | 1202 | |
| 1154 | 1203 | bool open_res = false; |
| 1155 | 1204 | |
| 1205 | + if (mode == DirectStreamTransform::DistributeFrames) | |
| 1206 | + { | |
| 1207 | + actualSource = new SingleDataSource(0); | |
| 1208 | + open_res = actualSource->concreteOpen(input); | |
| 1209 | + } | |
| 1156 | 1210 | // Input has no matrices? Its probably a video that hasn't been loaded yet |
| 1157 | - if (mode == DirectStreamTransform::StreamVideo || mode ~= DirectStreamTransform::DistributeFrames && input.empty()) { | |
| 1211 | + else if (mode == DirectStreamTransform::StreamVideo || (mode == DirectStreamTransform::Auto && input.empty()) ) { | |
| 1158 | 1212 | actualSource = new VideoDataSource(0); |
| 1159 | 1213 | open_res = actualSource->concreteOpen(input); |
| 1160 | 1214 | } |
| 1161 | 1215 | // If the input is not empty, we assume it is a set of frames already |
| 1162 | 1216 | // in memory. |
| 1163 | 1217 | else { |
| 1218 | + qDebug("in template open"); | |
| 1164 | 1219 | actualSource = new TemplateDataSource(0); |
| 1165 | 1220 | open_res = actualSource->concreteOpen(input); |
| 1166 | 1221 | } |
| ... | ... | @@ -1194,8 +1249,8 @@ protected: |
| 1194 | 1249 | // Override the sequence number set by actualSource |
| 1195 | 1250 | output.data.last().file.set("FrameNumber", output.sequenceNumber); |
| 1196 | 1251 | next_sequence_number++; |
| 1197 | - if (output.data.last().last().empty()) | |
| 1198 | - qDebug("broken matrix"); | |
| 1252 | +// if (output.data.last().last().empty()) | |
| 1253 | +// qDebug("broken matrix"); | |
| 1199 | 1254 | return true; |
| 1200 | 1255 | } |
| 1201 | 1256 | |
| ... | ... | @@ -1223,8 +1278,8 @@ protected: |
| 1223 | 1278 | output.sequenceNumber = next_sequence_number++; |
| 1224 | 1279 | output.data.last().file.set("FrameNumber", output.sequenceNumber); |
| 1225 | 1280 | |
| 1226 | - if (output.data.last().last().empty()) | |
| 1227 | - qDebug("broken matrix"); | |
| 1281 | +// if (output.data.last().last().empty()) | |
| 1282 | +// qDebug("broken matrix"); | |
| 1228 | 1283 | |
| 1229 | 1284 | return res; |
| 1230 | 1285 | } | ... | ... |