Commit fac7a2326bde311c5ec53d707e91d77dba9cf1c9
1 parent
db273407
Drop exlicit stream modes, just use galleries for everything. This simplifies st…
…ream.cpp a little, and allows us to use less indirection.
Showing
1 changed file
with
11 additions
and
98 deletions
openbr/plugins/stream.cpp
| ... | ... | @@ -19,17 +19,6 @@ using namespace std; |
| 19 | 19 | namespace br |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | -class Idiocy : public QObject | |
| 23 | -{ | |
| 24 | - Q_OBJECT | |
| 25 | -public: | |
| 26 | - enum StreamModes { DistributeFrames, | |
| 27 | - StreamGallery | |
| 28 | - }; | |
| 29 | - | |
| 30 | - Q_ENUMS(StreamModes) | |
| 31 | -}; | |
| 32 | - | |
| 33 | 22 | class FrameData |
| 34 | 23 | { |
| 35 | 24 | public: |
| ... | ... | @@ -194,21 +183,9 @@ private: |
| 194 | 183 | QList<FrameData *> buffer2; |
| 195 | 184 | }; |
| 196 | 185 | |
| 197 | -// Given a template as input, return N templates as output, one at a time on subsequent | |
| 198 | -// calls to getNext | |
| 199 | -class TemplateProcessor | |
| 200 | -{ | |
| 201 | -public: | |
| 202 | - virtual ~TemplateProcessor() {} | |
| 203 | - virtual bool open(Template &input)=0; | |
| 204 | - virtual bool isOpen()=0; | |
| 205 | - virtual void close()=0; | |
| 206 | - virtual bool getNextTemplate(Template &output)=0; | |
| 207 | -protected: | |
| 208 | - Template basis; | |
| 209 | -}; | |
| 210 | - | |
| 211 | -struct StreamGallery : public TemplateProcessor | |
| 186 | +// Given a template as input, open the file contained as a gallery, and return templates one at a time on | |
| 187 | +// calls to getNextTemplate | |
| 188 | +struct StreamGallery | |
| 212 | 189 | { |
| 213 | 190 | bool open(Template &input) |
| 214 | 191 | { |
| ... | ... | @@ -265,45 +242,6 @@ protected: |
| 265 | 242 | |
| 266 | 243 | TemplateList currentData; |
| 267 | 244 | int nextIdx; |
| 268 | - | |
| 269 | -}; | |
| 270 | - | |
| 271 | -class DirectReturn : public TemplateProcessor | |
| 272 | -{ | |
| 273 | -public: | |
| 274 | - DirectReturn() | |
| 275 | - { | |
| 276 | - data_ok = false; | |
| 277 | - } | |
| 278 | - | |
| 279 | - // We don't do anything, just prepare to return input when getNext is called. | |
| 280 | - bool open(Template &input) | |
| 281 | - { | |
| 282 | - basis = input; | |
| 283 | - data_ok =true; | |
| 284 | - return data_ok; | |
| 285 | - } | |
| 286 | - | |
| 287 | - bool isOpen() { return data_ok; } | |
| 288 | - | |
| 289 | - void close() | |
| 290 | - { | |
| 291 | - data_ok = false; | |
| 292 | - basis.clear(); | |
| 293 | - } | |
| 294 | - | |
| 295 | - bool getNextTemplate(Template &output) | |
| 296 | - { | |
| 297 | - if (!data_ok) | |
| 298 | - return false; | |
| 299 | - output = basis; | |
| 300 | - data_ok = false; | |
| 301 | - return true; | |
| 302 | - } | |
| 303 | - | |
| 304 | -protected: | |
| 305 | - // Have we sent our template yet? | |
| 306 | - bool data_ok; | |
| 307 | 245 | }; |
| 308 | 246 | |
| 309 | 247 | // Interface for sequentially getting data from some data source. |
| ... | ... | @@ -320,7 +258,6 @@ public: |
| 320 | 258 | { |
| 321 | 259 | allFrames.addItem(new FrameData()); |
| 322 | 260 | } |
| 323 | - frameSource = NULL; | |
| 324 | 261 | } |
| 325 | 262 | |
| 326 | 263 | virtual ~DataSource() |
| ... | ... | @@ -336,12 +273,7 @@ public: |
| 336 | 273 | |
| 337 | 274 | void close() |
| 338 | 275 | { |
| 339 | - if (this->frameSource) | |
| 340 | - { | |
| 341 | - frameSource->close(); | |
| 342 | - delete frameSource; | |
| 343 | - frameSource = NULL; | |
| 344 | - } | |
| 276 | + frameSource.close(); | |
| 345 | 277 | } |
| 346 | 278 | |
| 347 | 279 | int size() |
| ... | ... | @@ -349,12 +281,11 @@ public: |
| 349 | 281 | return this->templates.size(); |
| 350 | 282 | } |
| 351 | 283 | |
| 352 | - bool open(const TemplateList &input, br::Idiocy::StreamModes _mode) | |
| 284 | + bool open(const TemplateList &input) | |
| 353 | 285 | { |
| 354 | 286 | // Set up variables specific to us |
| 355 | 287 | current_template_idx = 0; |
| 356 | 288 | templates = input; |
| 357 | - mode = _mode; | |
| 358 | 289 | |
| 359 | 290 | is_broken = false; |
| 360 | 291 | allReturned = false; |
| ... | ... | @@ -465,21 +396,11 @@ protected: |
| 465 | 396 | bool open_res = false; |
| 466 | 397 | while (!open_res) |
| 467 | 398 | { |
| 468 | - if (frameSource) | |
| 469 | - frameSource->close(); | |
| 399 | + frameSource.close(); | |
| 470 | 400 | |
| 471 | 401 | Template curr = this->templates[current_template_idx]; |
| 472 | - if (mode == br::Idiocy::DistributeFrames) | |
| 473 | - { | |
| 474 | - if (!frameSource) | |
| 475 | - frameSource = new DirectReturn(); | |
| 476 | - } | |
| 477 | - else if (mode == br::Idiocy::StreamGallery) | |
| 478 | - { | |
| 479 | - if (!frameSource) | |
| 480 | - frameSource = new StreamGallery(); | |
| 481 | - } | |
| 482 | - open_res = frameSource->open(curr); | |
| 402 | + | |
| 403 | + open_res = frameSource.open(curr); | |
| 483 | 404 | if (!open_res) |
| 484 | 405 | { |
| 485 | 406 | current_template_idx++; |
| ... | ... | @@ -498,7 +419,7 @@ protected: |
| 498 | 419 | |
| 499 | 420 | while (!got_frame) |
| 500 | 421 | { |
| 501 | - got_frame = frameSource->getNextTemplate(aTemplate); | |
| 422 | + got_frame = frameSource.getNextTemplate(aTemplate); | |
| 502 | 423 | |
| 503 | 424 | // OK we got a frame |
| 504 | 425 | if (got_frame) { |
| ... | ... | @@ -529,14 +450,11 @@ protected: |
| 529 | 450 | // Index of the template in the templatelist we are currently reading from |
| 530 | 451 | int current_template_idx; |
| 531 | 452 | |
| 532 | - // What do we do to each template | |
| 533 | - br::Idiocy::StreamModes mode; | |
| 534 | - | |
| 535 | 453 | // list of templates we are workign from |
| 536 | 454 | TemplateList templates; |
| 537 | 455 | |
| 538 | 456 | // processor for the current template |
| 539 | - TemplateProcessor *frameSource; | |
| 457 | + StreamGallery frameSource; | |
| 540 | 458 | |
| 541 | 459 | int next_sequence_number; |
| 542 | 460 | int final_frame; |
| ... | ... | @@ -972,10 +890,8 @@ class DirectStreamTransform : public CompositeTransform |
| 972 | 890 | |
| 973 | 891 | public: |
| 974 | 892 | Q_PROPERTY(int activeFrames READ get_activeFrames WRITE set_activeFrames RESET reset_activeFrames) |
| 975 | - Q_PROPERTY(br::Idiocy::StreamModes readMode READ get_readMode WRITE set_readMode RESET reset_readMode) | |
| 976 | 893 | Q_PROPERTY(br::Transform* endPoint READ get_endPoint WRITE set_endPoint RESET reset_endPoint STORED true) |
| 977 | 894 | BR_PROPERTY(int, activeFrames, 100) |
| 978 | - BR_PROPERTY(br::Idiocy::StreamModes, readMode, br::Idiocy::StreamGallery) | |
| 979 | 895 | BR_PROPERTY(br::Transform*, endPoint, make("CollectOutput")) |
| 980 | 896 | |
| 981 | 897 | friend class StreamTransfrom; |
| ... | ... | @@ -1079,7 +995,7 @@ public: |
| 1079 | 995 | if (src.empty()) |
| 1080 | 996 | return; |
| 1081 | 997 | |
| 1082 | - bool res = readStage->dataSource.open(src,readMode); | |
| 998 | + bool res = readStage->dataSource.open(src); | |
| 1083 | 999 | if (!res) { |
| 1084 | 1000 | qDebug("stream failed to open %s", qPrintable(dst[0].file.name)); |
| 1085 | 1001 | return; |
| ... | ... | @@ -1290,10 +1206,8 @@ public: |
| 1290 | 1206 | |
| 1291 | 1207 | Q_PROPERTY(br::Transform* endPoint READ get_endPoint WRITE set_endPoint RESET reset_endPoint STORED true) |
| 1292 | 1208 | Q_PROPERTY(int activeFrames READ get_activeFrames WRITE set_activeFrames RESET reset_activeFrames) |
| 1293 | - Q_PROPERTY(br::Idiocy::StreamModes readMode READ get_readMode WRITE set_readMode RESET reset_readMode) | |
| 1294 | 1209 | |
| 1295 | 1210 | BR_PROPERTY(int, activeFrames, 100) |
| 1296 | - BR_PROPERTY(br::Idiocy::StreamModes, readMode, br::Idiocy::StreamGallery) | |
| 1297 | 1211 | BR_PROPERTY(br::Transform*, endPoint, make("CollectOutput")) |
| 1298 | 1212 | |
| 1299 | 1213 | bool timeVarying() const { return true; } |
| ... | ... | @@ -1335,7 +1249,6 @@ public: |
| 1335 | 1249 | basis = QSharedPointer<DirectStreamTransform>((DirectStreamTransform *) Transform::make("DirectStream",this)); |
| 1336 | 1250 | basis->transforms.clear(); |
| 1337 | 1251 | basis->activeFrames = this->activeFrames; |
| 1338 | - basis->readMode = this->readMode; | |
| 1339 | 1252 | basis->endPoint = this->endPoint; |
| 1340 | 1253 | |
| 1341 | 1254 | // We need at least a CompositeTransform * to acess transform's children. | ... | ... |