]> sigrok.org Git - pulseview.git/commitdiff
Decode: Improve signaling
authorSoeren Apel <redacted>
Tue, 27 Jun 2017 16:32:30 +0000 (18:32 +0200)
committerUwe Hermann <redacted>
Wed, 5 Jul 2017 22:37:08 +0000 (00:37 +0200)
Three issues that were fixed by this:
1) The SignalBase did notify PDs when its conversion changed
and new sample data was generated but this was dismissed as
the samples_cleared() signal was never fired nor used by the
PD stack.

2) The decode_finished() signal was added so that the decode
trace can immediately paint the trace once the PD is done.
Before, a repaint was only triggered when annotations came in,
resulting in a noticeable "unresolved period" visible if the
last stretch of signal didn't contain any annotations as the
trace wasn't repainted quickly enough.

3) The decode trace indirectly looks at the signal's
samples_decoded_ member when drawing the "unresolved period"
bar. Hence we should update this member before triggering the
repaint via new_annotations().

pv/data/decodesignal.cpp
pv/data/decodesignal.hpp
pv/data/signalbase.cpp
pv/views/trace/decodetrace.cpp
pv/views/trace/decodetrace.hpp

index e8206a088bac285077271d0d5f6db08cd442649b..be2ed1616d1bdbed47c4eeb604028ca654f1bfc7 100644 (file)
@@ -69,19 +69,7 @@ DecodeSignal::DecodeSignal(pv::Session &session) :
 
 DecodeSignal::~DecodeSignal()
 {
-       if (decode_thread_.joinable()) {
-               decode_interrupt_ = true;
-               decode_input_cond_.notify_one();
-               decode_thread_.join();
-       }
-
-       if (logic_mux_thread_.joinable()) {
-               logic_mux_interrupt_ = true;
-               logic_mux_cond_.notify_one();
-               logic_mux_thread_.join();
-       }
-
-       stop_srd_session();
+       reset_decode();
 }
 
 const vector< shared_ptr<Decoder> >& DecodeSignal::decoder_stack() const
@@ -144,13 +132,29 @@ bool DecodeSignal::toggle_decoder_visibility(int index)
 
 void DecodeSignal::reset_decode()
 {
+       if (decode_thread_.joinable()) {
+               decode_interrupt_ = true;
+               decode_input_cond_.notify_one();
+               decode_thread_.join();
+       }
+
+       if (logic_mux_thread_.joinable()) {
+               logic_mux_interrupt_ = true;
+               logic_mux_cond_.notify_one();
+               logic_mux_thread_.join();
+       }
+
        stop_srd_session();
 
        frame_complete_ = false;
        samples_decoded_ = 0;
        error_message_ = QString();
+
        rows_.clear();
        class_rows_.clear();
+
+       logic_mux_data_.reset();
+       logic_mux_data_invalid_ = true;
 }
 
 void DecodeSignal::begin_decode()
@@ -674,14 +678,14 @@ void DecodeSignal::decode_data(
 
                delete[] chunk;
 
-               // Notify the frontend that we processed some data and
-               // possibly have new annotations as well
-               new_annotations();
-
                {
                        lock_guard<mutex> lock(output_mutex_);
                        samples_decoded_ = chunk_end;
                }
+
+               // Notify the frontend that we processed some data and
+               // possibly have new annotations as well
+               new_annotations();
        }
 }
 
@@ -711,9 +715,12 @@ void DecodeSignal::decode_proc()
                                decode_data(abs_start_samplenum, sample_count);
                                abs_start_samplenum += sample_count;
                        }
-               } while (error_message_.isEmpty() && (sample_count > 0));
+               } while (error_message_.isEmpty() && (sample_count > 0) && !decode_interrupt_);
+
+               if (error_message_.isEmpty() && !decode_interrupt_) {
+                       if (sample_count == 0)
+                               decode_finished();
 
-               if (error_message_.isEmpty()) {
                        // Wait for new input data or an interrupt was requested
                        unique_lock<mutex> input_wait_lock(input_mutex_);
                        decode_input_cond_.wait(input_wait_lock);
@@ -769,6 +776,7 @@ void DecodeSignal::stop_srd_session()
 void DecodeSignal::connect_input_notifiers()
 {
        // Disconnect the notification slot from the previous set of signals
+       disconnect(this, SLOT(on_data_cleared()));
        disconnect(this, SLOT(on_data_received()));
 
        // Connect the currently used signals to our slot
@@ -776,8 +784,10 @@ void DecodeSignal::connect_input_notifiers()
                if (!ch.assigned_signal)
                        continue;
 
-               shared_ptr<Logic> logic_data = ch.assigned_signal->logic_data();
-               connect(logic_data.get(), SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
+               const data::SignalBase *signal = ch.assigned_signal;
+               connect(signal, SIGNAL(samples_cleared()),
+                       this, SLOT(on_data_cleared()));
+               connect(signal, SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
                        this, SLOT(on_data_received()));
        }
 }
@@ -830,9 +840,17 @@ void DecodeSignal::on_capture_state_changed(int state)
                begin_decode();
 }
 
+void DecodeSignal::on_data_cleared()
+{
+       reset_decode();
+}
+
 void DecodeSignal::on_data_received()
 {
-       logic_mux_cond_.notify_one();
+       if (!logic_mux_thread_.joinable())
+               begin_decode();
+       else
+               logic_mux_cond_.notify_one();
 }
 
 } // namespace data
index 1d6c1ab4debc3d678b7d71c48c9ac8e68702bbe4..86b1931834e29211b83d427814315071144f494e 100644 (file)
@@ -152,10 +152,12 @@ private:
 
 Q_SIGNALS:
        void new_annotations();
+       void decode_finished();
        void channels_updated();
 
 private Q_SLOTS:
        void on_capture_state_changed(int state);
+       void on_data_cleared();
        void on_data_received();
 
 private:
index 173610d945e7b66ff5ce3e1b45e05b1c821a3b2e..3c0305a533b343f79c13627eecb52a35403119af 100644 (file)
@@ -181,6 +181,7 @@ void SignalBase::set_conversion_type(ConversionType t)
 
                // Discard converted data
                converted_data_.reset();
+               samples_cleared();
        }
 
        conversion_type_ = t;
index f4ab55ffa3ee1cbca8246873057ce67b4b8e264b..21d88923ef1c5732f3a0f3ef1394219c2ead7907 100644 (file)
@@ -149,6 +149,8 @@ DecodeTrace::DecodeTrace(pv::Session &session,
 
        connect(decode_signal_.get(), SIGNAL(new_annotations()),
                this, SLOT(on_new_annotations()));
+       connect(decode_signal_.get(), SIGNAL(decode_finished()),
+               this, SLOT(on_decode_finished()));
        connect(decode_signal_.get(), SIGNAL(channels_updated()),
                this, SLOT(on_channels_updated()));
 
@@ -883,6 +885,12 @@ void DecodeTrace::on_delayed_trace_update()
                owner_->row_item_appearance_changed(false, true);
 }
 
+void DecodeTrace::on_decode_finished()
+{
+       if (owner_)
+               owner_->row_item_appearance_changed(false, true);
+}
+
 void DecodeTrace::delete_pressed()
 {
        on_delete();
index 6ba48455fe88a964cf7268ae1fbf021523d23404..26da3ace35ca01a4f291ff1026a1d29b173ba197 100644 (file)
@@ -184,6 +184,7 @@ public:
 private Q_SLOTS:
        void on_new_annotations();
        void on_delayed_trace_update();
+       void on_decode_finished();
 
        void on_delete();