Commit 1032db93b15f0a5fd38d6cfe0aacf021102c0ee0
1 parent
67c30b3a
Per @jklontz's suggestion, replace the look-ahead scheme with a sentinel
Instead of maintaining a lookahead buffer so that the last frame number can be known before processing it, just push an empty FrameData through the stream when the DataSource breaks.
Showing
1 changed file
with
5 additions
and
36 deletions
openbr/plugins/stream.cpp
| @@ -647,28 +647,6 @@ public: | @@ -647,28 +647,6 @@ public: | ||
| 647 | return false; | 647 | return false; |
| 648 | } | 648 | } |
| 649 | 649 | ||
| 650 | - // Try to get a frame from the global pool | ||
| 651 | - FrameData * firstFrame = allFrames.tryGetItem(); | ||
| 652 | - | ||
| 653 | - // If this fails, things have gone pretty badly. | ||
| 654 | - if (firstFrame == NULL) { | ||
| 655 | - is_broken = true; | ||
| 656 | - return false; | ||
| 657 | - } | ||
| 658 | - | ||
| 659 | - // Read a frame from the video source | ||
| 660 | - bool res = getNextFrame(*firstFrame); | ||
| 661 | - | ||
| 662 | - // the data source broke already, we couldn't even get one frame | ||
| 663 | - // from it even though it claimed to have opened successfully. | ||
| 664 | - if (!res) { | ||
| 665 | - is_broken = true; | ||
| 666 | - return false; | ||
| 667 | - } | ||
| 668 | - | ||
| 669 | - // We read one frame ahead of the last one returned, this allows | ||
| 670 | - // us to know which frame is the final frame when we return it. | ||
| 671 | - lookAhead.append(firstFrame); | ||
| 672 | return true; | 650 | return true; |
| 673 | } | 651 | } |
| 674 | 652 | ||
| @@ -698,26 +676,17 @@ public: | @@ -698,26 +676,17 @@ public: | ||
| 698 | if (!res) | 676 | if (!res) |
| 699 | { | 677 | { |
| 700 | QMutexLocker lock(&last_frame_update); | 678 | QMutexLocker lock(&last_frame_update); |
| 701 | - final_frame = lookAhead.back()->sequenceNumber; | ||
| 702 | - allFrames.addItem(aFrame); | 679 | + final_frame = aFrame->sequenceNumber; |
| 680 | + aFrame->data().clear(); | ||
| 703 | } | 681 | } |
| 704 | - else { | ||
| 705 | - lookAhead.push_back(aFrame); | ||
| 706 | - } | ||
| 707 | - | ||
| 708 | - // we will return the first frame on the lookAhead buffer | ||
| 709 | - FrameData * rVal = lookAhead.first(); | ||
| 710 | - lookAhead.pop_front(); | ||
| 711 | - if (rVal->data.empty()) | ||
| 712 | - qDebug("returning empty frame from look ahead!"); | ||
| 713 | 682 | ||
| 714 | // If this is the last frame, say so | 683 | // If this is the last frame, say so |
| 715 | - if (rVal->sequenceNumber == final_frame) { | 684 | + if (aFrame->sequenceNumber == final_frame) { |
| 716 | last_frame = true; | 685 | last_frame = true; |
| 717 | is_broken = true; | 686 | is_broken = true; |
| 718 | } | 687 | } |
| 719 | 688 | ||
| 720 | - return rVal; | 689 | + return aFrame; |
| 721 | } | 690 | } |
| 722 | 691 | ||
| 723 | // Return a frame to the pool, returns true if the frame returned was the last | 692 | // Return a frame to the pool, returns true if the frame returned was the last |
| @@ -845,6 +814,7 @@ protected: | @@ -845,6 +814,7 @@ protected: | ||
| 845 | // couldn't get the next template? nothing to do, otherwise we try to read | 814 | // couldn't get the next template? nothing to do, otherwise we try to read |
| 846 | // a frame at the top of this loop. | 815 | // a frame at the top of this loop. |
| 847 | if (!open_res) { | 816 | if (!open_res) { |
| 817 | + output.sequenceNumber = next_sequence_number; | ||
| 848 | return false; | 818 | return false; |
| 849 | } | 819 | } |
| 850 | } | 820 | } |
| @@ -870,7 +840,6 @@ protected: | @@ -870,7 +840,6 @@ protected: | ||
| 870 | bool allReturned; | 840 | bool allReturned; |
| 871 | 841 | ||
| 872 | DoubleBuffer allFrames; | 842 | DoubleBuffer allFrames; |
| 873 | - QList<FrameData *> lookAhead; | ||
| 874 | 843 | ||
| 875 | QWaitCondition lastReturned; | 844 | QWaitCondition lastReturned; |
| 876 | QMutex last_frame_update; | 845 | QMutex last_frame_update; |