]> sigrok.org Git - pulseview.git/commitdiff
Session: Rework frame handling
authorSoeren Apel <redacted>
Mon, 14 Aug 2017 15:52:43 +0000 (17:52 +0200)
committerSoeren Apel <redacted>
Mon, 14 Aug 2017 15:52:43 +0000 (17:52 +0200)
pv/session.cpp
pv/session.hpp

index 4dcc2e8b7b77f5da1cfce26781e694d16f23eb7f..ad4c17e246f0609079e470750c9c3f979d3f20cd 100644 (file)
@@ -990,10 +990,26 @@ void Session::feed_in_trigger()
 
 void Session::feed_in_frame_begin()
 {
+       frame_began_ = true;
+
        if (cur_logic_segment_ || !cur_analog_segments_.empty())
                frame_began();
 }
 
+void Session::feed_in_frame_end()
+{
+       {
+               lock_guard<recursive_mutex> lock(data_mutex_);
+               cur_logic_segment_.reset();
+               cur_analog_segments_.clear();
+       }
+
+       if (frame_began_) {
+               frame_began_ = false;
+               frame_ended();
+       }
+}
+
 void Session::feed_in_logic(shared_ptr<Logic> logic)
 {
        lock_guard<recursive_mutex> lock(data_mutex_);
@@ -1090,8 +1106,6 @@ void Session::feed_in_analog(shared_ptr<Analog> analog)
 void Session::data_feed_in(shared_ptr<sigrok::Device> device,
        shared_ptr<Packet> packet)
 {
-       static bool frame_began = false;
-
        (void)device;
 
        assert(device);
@@ -1111,11 +1125,6 @@ void Session::data_feed_in(shared_ptr<sigrok::Device> device,
                feed_in_trigger();
                break;
 
-       case SR_DF_FRAME_BEGIN:
-               feed_in_frame_begin();
-               frame_began = true;
-               break;
-
        case SR_DF_LOGIC:
                try {
                        feed_in_logic(dynamic_pointer_cast<Logic>(packet->payload()));
@@ -1134,20 +1143,25 @@ void Session::data_feed_in(shared_ptr<sigrok::Device> device,
                }
                break;
 
+       case SR_DF_FRAME_BEGIN:
+               feed_in_frame_begin();
+               break;
+
        case SR_DF_FRAME_END:
+               feed_in_frame_end();
+               break;
+
        case SR_DF_END:
-       {
+               // Strictly speaking, this is performed when a frame end marker was
+               // received, so there's no point doing this again. However, not all
+               // devices use frames, and for those devices, we need to do it here.
                {
                        lock_guard<recursive_mutex> lock(data_mutex_);
                        cur_logic_segment_.reset();
                        cur_analog_segments_.clear();
                }
-               if (frame_began) {
-                       frame_began = false;
-                       frame_ended();
-               }
                break;
-       }
+
        default:
                break;
        }
index fa96ce641bd418f4ca7448986d1d66cf10ecc538..9d42a4d98b657896a5e61e18667758052c601e8f 100644 (file)
@@ -201,6 +201,7 @@ private:
        void feed_in_trigger();
 
        void feed_in_frame_begin();
+       void feed_in_frame_end();
 
        void feed_in_logic(shared_ptr<sigrok::Logic> logic);
 
@@ -236,6 +237,7 @@ private:
 
        bool out_of_memory_;
        bool data_saved_;
+       bool frame_began_;
 
 Q_SIGNALS:
        void capture_state_changed(int state);