]> sigrok.org Git - pulseview.git/blobdiff - pv/data/decodesignal.cpp
Fix #1629 by not reallocating DecodeSegments
[pulseview.git] / pv / data / decodesignal.cpp
index 12077a96f5b766c14c5839196195585e0e745ca4..640e58148ef751e3aa7557dca2d7af5d526c2240 100644 (file)
@@ -308,7 +308,13 @@ void DecodeSignal::auto_assign_signals(const shared_ptr<Decoder> dec)
                        }
                }
 
-               if (match) {
+               // Prevent using a signal more than once as D1 would match e.g. D1 and D10
+               bool signal_not_already_used = true;
+               for (decode::DecodeChannel& ch : channels_)
+                       if (ch.assigned_signal && (ch.assigned_signal == match))
+                               signal_not_already_used = false;
+
+               if (match && signal_not_already_used) {
                        ch.assigned_signal = match;
                        new_assignment = true;
                }
@@ -1009,7 +1015,6 @@ void DecodeSignal::mux_logic_samples(uint32_t segment_id, const int64_t start, c
                return;
 
        // Fetch the channel segments and their data
-       bool segment_missing = false;
        vector<shared_ptr<const LogicSegment> > segments;
        vector<const uint8_t*> signal_data;
        vector<uint8_t> signal_in_bytepos;
@@ -1020,19 +1025,17 @@ void DecodeSignal::mux_logic_samples(uint32_t segment_id, const int64_t start, c
                        const shared_ptr<Logic> logic_data = ch.assigned_signal->logic_data();
 
                        shared_ptr<const LogicSegment> segment;
-                       try {
+                       if (segment_id < logic_data->logic_segments().size()) {
                                segment = logic_data->logic_segments().at(segment_id)->get_shared_ptr();
-                       } catch (out_of_range&) {
+                       } else {
                                qDebug() << "Muxer error for" << name() << ":" << ch.assigned_signal->name() \
                                        << "has no logic segment" << segment_id;
                                logic_mux_interrupt_ = true;
                                return;
                        }
 
-                       if (!segment) {
-                               segment_missing = true;
-                               break;
-                       }
+                       if (!segment)
+                               return;
 
                        segments.push_back(segment);
 
@@ -1045,9 +1048,6 @@ void DecodeSignal::mux_logic_samples(uint32_t segment_id, const int64_t start, c
                        signal_in_bitpos.push_back(bitpos % 8);
                }
 
-       if (segment_missing)
-               return;
-
        shared_ptr<LogicSegment> output_segment;
        try {
                output_segment = logic_mux_data_->logic_segments().at(segment_id);
@@ -1173,11 +1173,11 @@ void DecodeSignal::logic_mux_proc()
                                        logic_mux_data_->push_segment(output_segment);
 
                                        output_segment->set_samplerate(get_input_samplerate(segment_id));
+                               } else {
+                                       // Wait for more input data if we're processing the currently last segment
+                                       unique_lock<mutex> logic_mux_lock(logic_mux_mutex_);
+                                       logic_mux_cond_.wait(logic_mux_lock);
                                }
-                       } else {
-                               // Wait for more input
-                               unique_lock<mutex> logic_mux_lock(logic_mux_mutex_);
-                               logic_mux_cond_.wait(logic_mux_lock);
                        }
                }
        } while (!logic_mux_interrupt_);
@@ -1191,8 +1191,7 @@ void DecodeSignal::decode_data(
        const int64_t chunk_sample_count = DecodeChunkLength / unit_size;
 
        for (int64_t i = abs_start_samplenum;
-               error_message_.isEmpty() && !decode_interrupt_ &&
-                       (i < (abs_start_samplenum + sample_count));
+               !decode_interrupt_ && (i < (abs_start_samplenum + sample_count));
                i += chunk_sample_count) {
 
                const int64_t chunk_end = min(i + chunk_sample_count,
@@ -1278,7 +1277,7 @@ void DecodeSignal::decode_proc()
 
                        // If the input segment is complete, we've exhausted this segment
                        if (input_segment->is_complete()) {
-                               if (current_segment_id_ < logic_mux_data_->logic_segments().size() - 1) {
+                               if (current_segment_id_ < (logic_mux_data_->logic_segments().size() - 1)) {
                                        // Process next segment
                                        current_segment_id_++;
 
@@ -1302,20 +1301,17 @@ void DecodeSignal::decode_proc()
                                        terminate_srd_session();
                                } else {
                                        // All segments have been processed
-                                       decode_finished();
+                                       if (!decode_interrupt_)
+                                               decode_finished();
+
+                                       // Wait for more input data
+                                       unique_lock<mutex> input_wait_lock(input_mutex_);
+                                       decode_input_cond_.wait(input_wait_lock);
                                }
-                       } else {
-                               // Wait for more input data
-                               unique_lock<mutex> input_wait_lock(input_mutex_);
-                               decode_input_cond_.wait(input_wait_lock);
                        }
+
                }
        } while (!decode_interrupt_);
-
-       // Potentially reap decoders when the application no longer is
-       // interested in their (pending) results.
-       if (decode_interrupt_)
-               terminate_srd_session();
 }
 
 void DecodeSignal::start_srd_session()
@@ -1635,6 +1631,11 @@ void DecodeSignal::on_data_received()
        // to work with
        if ((!error_message_.isEmpty()) && (get_input_segment_count() == 0))
                return;
+       else {
+               error_message_.clear();
+               // TODO Emulate noquote()
+               qDebug().nospace() << name() << ": Error cleared";
+       }
 
        if (!logic_mux_thread_.joinable())
                begin_decode();