]> sigrok.org Git - pulseview.git/blame - pv/data/decodesignal.cpp
Make sure PD row colors remain constant by adding a row index
[pulseview.git] / pv / data / decodesignal.cpp
CommitLineData
ad908057
SA
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
0c5fe73e
SA
20#include <limits>
21
47747218
SA
22#include <QDebug>
23
ad908057
SA
24#include "logic.hpp"
25#include "logicsegment.hpp"
26#include "decodesignal.hpp"
27#include "signaldata.hpp"
28
29#include <pv/binding/decoder.hpp>
30#include <pv/data/decode/decoder.hpp>
ecd07c20 31#include <pv/data/decode/row.hpp>
d3feec23 32#include <pv/globalsettings.hpp>
ad908057
SA
33#include <pv/session.hpp>
34
47747218
SA
35using std::lock_guard;
36using std::make_pair;
ad908057 37using std::make_shared;
0c5fe73e 38using std::min;
5ecf957f 39using std::out_of_range;
ad908057 40using std::shared_ptr;
47747218
SA
41using std::unique_lock;
42using pv::data::decode::Annotation;
ad908057 43using pv::data::decode::Decoder;
ecd07c20 44using pv::data::decode::Row;
ad908057
SA
45
46namespace pv {
47namespace data {
48
47747218
SA
49const double DecodeSignal::DecodeMargin = 1.0;
50const double DecodeSignal::DecodeThreshold = 0.2;
3fbddf7f 51const int64_t DecodeSignal::DecodeChunkLength = 256 * 1024;
ad908057 52
ad908057 53
47747218
SA
54DecodeSignal::DecodeSignal(pv::Session &session) :
55 SignalBase(nullptr, SignalBase::DecodeChannel),
56 session_(session),
e91883bb 57 srd_session_(nullptr),
47747218 58 logic_mux_data_invalid_(false),
e3202557 59 stack_config_changed_(true),
8a603e13 60 current_segment_id_(0)
ad908057 61{
47747218
SA
62 connect(&session_, SIGNAL(capture_state_changed(int)),
63 this, SLOT(on_capture_state_changed(int)));
ad908057
SA
64}
65
47747218 66DecodeSignal::~DecodeSignal()
ad908057 67{
8ce0e732 68 reset_decode(true);
ad908057
SA
69}
70
47747218 71const vector< shared_ptr<Decoder> >& DecodeSignal::decoder_stack() const
ecd07c20 72{
47747218 73 return stack_;
ecd07c20
SA
74}
75
c8e60bdf 76void DecodeSignal::stack_decoder(const srd_decoder *decoder)
ad908057
SA
77{
78 assert(decoder);
762ab7a4
SA
79 const shared_ptr<Decoder> dec = make_shared<decode::Decoder>(decoder);
80
81 stack_.push_back(dec);
47747218
SA
82
83 // Set name if this decoder is the first in the list
84 if (stack_.size() == 1)
85 set_name(QString::fromUtf8(decoder->name));
132a5c6d 86
27a3f09b 87 // Include the newly created decode channels in the channel lists
9f97b357 88 update_channel_list();
132a5c6d 89
e3202557 90 stack_config_changed_ = true;
762ab7a4 91 auto_assign_signals(dec);
27a3f09b 92 commit_decoder_channels();
47747218 93 begin_decode();
ad908057
SA
94}
95
96void DecodeSignal::remove_decoder(int index)
97{
47747218
SA
98 assert(index >= 0);
99 assert(index < (int)stack_.size());
100
101 // Find the decoder in the stack
102 auto iter = stack_.begin();
103 for (int i = 0; i < index; i++, iter++)
104 assert(iter != stack_.end());
105
106 // Delete the element
107 stack_.erase(iter);
108
109 // Update channels and decoded data
e3202557 110 stack_config_changed_ = true;
9f97b357 111 update_channel_list();
47747218 112 begin_decode();
ad908057
SA
113}
114
115bool DecodeSignal::toggle_decoder_visibility(int index)
116{
47747218 117 auto iter = stack_.cbegin();
ad908057 118 for (int i = 0; i < index; i++, iter++)
47747218 119 assert(iter != stack_.end());
ad908057
SA
120
121 shared_ptr<Decoder> dec = *iter;
122
123 // Toggle decoder visibility
124 bool state = false;
125 if (dec) {
126 state = !dec->shown();
127 dec->show(state);
128 }
129
130 return state;
131}
132
8ce0e732 133void DecodeSignal::reset_decode(bool shutting_down)
47747218 134{
8ce0e732 135 if (stack_config_changed_ || shutting_down)
e3202557
SA
136 stop_srd_session();
137 else
138 terminate_srd_session();
ce0b6a40 139
1b56c646
SA
140 if (decode_thread_.joinable()) {
141 decode_interrupt_ = true;
142 decode_input_cond_.notify_one();
143 decode_thread_.join();
144 }
145
146 if (logic_mux_thread_.joinable()) {
147 logic_mux_interrupt_ = true;
148 logic_mux_cond_.notify_one();
149 logic_mux_thread_.join();
150 }
151
47747218 152 class_rows_.clear();
8a603e13 153 current_segment_id_ = 0;
72435789 154 segments_.clear();
1b56c646
SA
155
156 logic_mux_data_.reset();
157 logic_mux_data_invalid_ = true;
eee3eab9 158
403c3e87
SA
159 if (!error_message_.isEmpty()) {
160 error_message_ = QString();
fe060a48
SA
161 // TODO Emulate noquote()
162 qDebug().nospace() << name() << ": Error cleared";
403c3e87 163 }
72435789 164
eee3eab9 165 decode_reset();
47747218
SA
166}
167
946b52e1
SA
168void DecodeSignal::begin_decode()
169{
47747218
SA
170 if (decode_thread_.joinable()) {
171 decode_interrupt_ = true;
172 decode_input_cond_.notify_one();
173 decode_thread_.join();
174 }
175
176 if (logic_mux_thread_.joinable()) {
177 logic_mux_interrupt_ = true;
178 logic_mux_cond_.notify_one();
179 logic_mux_thread_.join();
180 }
181
182 reset_decode();
183
27a3f09b 184 if (stack_.size() == 0) {
403c3e87 185 set_error_message(tr("No decoders"));
27a3f09b
SA
186 return;
187 }
188
189 assert(channels_.size() > 0);
190
191 if (get_assigned_signal_count() == 0) {
403c3e87 192 set_error_message(tr("There are no channels assigned to this decoder"));
27a3f09b
SA
193 return;
194 }
195
04627946
SA
196 // Make sure that all assigned channels still provide logic data
197 // (can happen when a converted signal was assigned but the
198 // conversion removed in the meanwhile)
199 for (data::DecodeChannel &ch : channels_)
200 if (ch.assigned_signal && !(ch.assigned_signal->logic_data() != nullptr))
201 ch.assigned_signal = nullptr;
202
47747218
SA
203 // Check that all decoders have the required channels
204 for (const shared_ptr<decode::Decoder> &dec : stack_)
205 if (!dec->have_required_channels()) {
403c3e87
SA
206 set_error_message(tr("One or more required channels "
207 "have not been specified"));
47747218
SA
208 return;
209 }
210
4913560f 211 // Map out all the annotation classes
f9807084 212 int row_index = 0;
47747218
SA
213 for (const shared_ptr<decode::Decoder> &dec : stack_) {
214 assert(dec);
215 const srd_decoder *const decc = dec->decoder();
216 assert(dec->decoder());
217
47747218
SA
218 for (const GSList *l = decc->annotation_rows; l; l = l->next) {
219 const srd_decoder_annotation_row *const ann_row =
220 (srd_decoder_annotation_row *)l->data;
221 assert(ann_row);
222
f9807084 223 const Row row(row_index++, decc, ann_row);
47747218 224
47747218
SA
225 for (const GSList *ll = ann_row->ann_classes;
226 ll; ll = ll->next)
227 class_rows_[make_pair(decc,
228 GPOINTER_TO_INT(ll->data))] = row;
229 }
230 }
231
27a3f09b
SA
232 // Free the logic data and its segment(s) if it needs to be updated
233 if (logic_mux_data_invalid_)
234 logic_mux_data_.reset();
235
236 if (!logic_mux_data_) {
72435789 237 const uint32_t ch_count = get_assigned_signal_count();
ed535cd7 238 logic_mux_unit_size_ = (ch_count + 7) / 8;
27a3f09b 239 logic_mux_data_ = make_shared<Logic>(ch_count);
27a3f09b 240 }
47747218 241
ed535cd7
SA
242 // Receive notifications when new sample data is available
243 connect_input_notifiers();
244
8a603e13 245 if (get_input_segment_count() == 0) {
403c3e87 246 set_error_message(tr("No input data"));
ed535cd7
SA
247 return;
248 }
249
27a3f09b
SA
250 // Make sure the logic output data is complete and up-to-date
251 logic_mux_interrupt_ = false;
252 logic_mux_thread_ = std::thread(&DecodeSignal::logic_mux_proc, this);
253
254 // Decode the muxed logic data
47747218
SA
255 decode_interrupt_ = false;
256 decode_thread_ = std::thread(&DecodeSignal::decode_proc, this);
946b52e1
SA
257}
258
ecd07c20
SA
259QString DecodeSignal::error_message() const
260{
47747218
SA
261 lock_guard<mutex> lock(output_mutex_);
262 return error_message_;
ecd07c20
SA
263}
264
47747218 265const vector<data::DecodeChannel> DecodeSignal::get_channels() const
9f97b357
SA
266{
267 return channels_;
268}
269
762ab7a4 270void DecodeSignal::auto_assign_signals(const shared_ptr<Decoder> dec)
132a5c6d 271{
47747218
SA
272 bool new_assignment = false;
273
132a5c6d
SA
274 // Try to auto-select channels that don't have signals assigned yet
275 for (data::DecodeChannel &ch : channels_) {
762ab7a4
SA
276 // If a decoder is given, auto-assign only its channels
277 if (dec && (ch.decoder_ != dec))
278 continue;
279
132a5c6d
SA
280 if (ch.assigned_signal)
281 continue;
282
a8030bb0
SA
283 const QString ch_name = ch.name.toLower();
284
285 shared_ptr<data::SignalBase> match;
692f6093 286 for (shared_ptr<data::SignalBase> s : session_.signalbases()) {
f9ebf303
SA
287 if (!s->enabled())
288 continue;
289
692f6093
SA
290 const QString s_name = s->name().toLower();
291
292 if (s->logic_data() &&
293 ((ch_name.contains(s_name)) || (s_name.contains(ch_name)))) {
a8030bb0
SA
294 if (!match)
295 match = s;
296 else {
297 // Only replace an existing match if it matches more characters
298 int old_unmatched = ch_name.length() - match->name().length();
299 int new_unmatched = ch_name.length() - s->name().length();
300 if (abs(new_unmatched) < abs(old_unmatched))
301 match = s;
302 }
47747218 303 }
692f6093 304 }
a8030bb0
SA
305
306 if (match) {
307 ch.assigned_signal = match.get();
308 new_assignment = true;
309 }
47747218
SA
310 }
311
312 if (new_assignment) {
313 logic_mux_data_invalid_ = true;
e3202557 314 stack_config_changed_ = true;
27a3f09b 315 commit_decoder_channels();
47747218 316 channels_updated();
132a5c6d
SA
317 }
318}
319
9f97b357
SA
320void DecodeSignal::assign_signal(const uint16_t channel_id, const SignalBase *signal)
321{
322 for (data::DecodeChannel &ch : channels_)
47747218 323 if (ch.id == channel_id) {
9f97b357 324 ch.assigned_signal = signal;
47747218
SA
325 logic_mux_data_invalid_ = true;
326 }
9f97b357 327
e3202557 328 stack_config_changed_ = true;
27a3f09b 329 commit_decoder_channels();
9f97b357 330 channels_updated();
47747218 331 begin_decode();
9f97b357
SA
332}
333
27a3f09b
SA
334int DecodeSignal::get_assigned_signal_count() const
335{
336 // Count all channels that have a signal assigned to them
337 return count_if(channels_.begin(), channels_.end(),
338 [](data::DecodeChannel ch) { return ch.assigned_signal; });
339}
340
9f97b357
SA
341void DecodeSignal::set_initial_pin_state(const uint16_t channel_id, const int init_state)
342{
343 for (data::DecodeChannel &ch : channels_)
344 if (ch.id == channel_id)
345 ch.initial_pin_state = init_state;
346
e3202557 347 stack_config_changed_ = true;
9f97b357 348 channels_updated();
47747218 349 begin_decode();
9f97b357
SA
350}
351
ff83d980
SA
352double DecodeSignal::samplerate() const
353{
72435789
SA
354 double result = 0;
355
356 // TODO For now, we simply return the first samplerate that we have
8a603e13
SA
357 if (segments_.size() > 0)
358 result = segments_.front().samplerate;
72435789
SA
359
360 return result;
ff83d980
SA
361}
362
72435789 363const pv::util::Timestamp DecodeSignal::start_time() const
ff83d980 364{
72435789
SA
365 pv::util::Timestamp result;
366
367 // TODO For now, we simply return the first start time that we have
8a603e13
SA
368 if (segments_.size() > 0)
369 result = segments_.front().start_time;
72435789
SA
370
371 return result;
ff83d980
SA
372}
373
5ecf957f 374int64_t DecodeSignal::get_working_sample_count(uint32_t segment_id) const
0c5fe73e
SA
375{
376 // The working sample count is the highest sample number for
ed535cd7
SA
377 // which all used signals have data available, so go through all
378 // channels and use the lowest overall sample count of the segment
0c5fe73e 379
0c5fe73e
SA
380 int64_t count = std::numeric_limits<int64_t>::max();
381 bool no_signals_assigned = true;
382
383 for (const data::DecodeChannel &ch : channels_)
384 if (ch.assigned_signal) {
385 no_signals_assigned = false;
386
387 const shared_ptr<Logic> logic_data = ch.assigned_signal->logic_data();
388 if (!logic_data || logic_data->logic_segments().empty())
389 return 0;
390
5ecf957f
SA
391 try {
392 const shared_ptr<LogicSegment> segment = logic_data->logic_segments().at(segment_id);
393 count = min(count, (int64_t)segment->get_sample_count());
30677c13 394 } catch (out_of_range&) {
5ecf957f
SA
395 return 0;
396 }
0c5fe73e
SA
397 }
398
399 return (no_signals_assigned ? 0 : count);
400}
401
b82908ab
SA
402int64_t DecodeSignal::get_decoded_sample_count(uint32_t segment_id,
403 bool include_processing) const
ff83d980 404{
47747218 405 lock_guard<mutex> decode_lock(output_mutex_);
5ecf957f
SA
406
407 int64_t result = 0;
408
72435789
SA
409 try {
410 const DecodeSegment *segment = &(segments_.at(segment_id));
b82908ab
SA
411 if (include_processing)
412 result = segment->samples_decoded_incl;
413 else
414 result = segment->samples_decoded_excl;
30677c13 415 } catch (out_of_range&) {
72435789
SA
416 // Do nothing
417 }
5ecf957f
SA
418
419 return result;
ff83d980
SA
420}
421
ecd07c20
SA
422vector<Row> DecodeSignal::visible_rows() const
423{
47747218
SA
424 lock_guard<mutex> lock(output_mutex_);
425
426 vector<Row> rows;
427
428 for (const shared_ptr<decode::Decoder> &dec : stack_) {
429 assert(dec);
430 if (!dec->shown())
431 continue;
432
433 const srd_decoder *const decc = dec->decoder();
434 assert(dec->decoder());
435
f9807084 436 int row_index = 0;
47747218
SA
437 // Add a row for the decoder if it doesn't have a row list
438 if (!decc->annotation_rows)
f9807084 439 rows.emplace_back(row_index++, decc);
47747218
SA
440
441 // Add the decoder rows
442 for (const GSList *l = decc->annotation_rows; l; l = l->next) {
443 const srd_decoder_annotation_row *const ann_row =
444 (srd_decoder_annotation_row *)l->data;
445 assert(ann_row);
f9807084 446 rows.emplace_back(row_index++, decc, ann_row);
47747218
SA
447 }
448 }
449
450 return rows;
ecd07c20
SA
451}
452
453void DecodeSignal::get_annotation_subset(
454 vector<pv::data::decode::Annotation> &dest,
72435789 455 const decode::Row &row, uint32_t segment_id, uint64_t start_sample,
ecd07c20
SA
456 uint64_t end_sample) const
457{
47747218
SA
458 lock_guard<mutex> lock(output_mutex_);
459
72435789
SA
460 try {
461 const DecodeSegment *segment = &(segments_.at(segment_id));
462 const map<const decode::Row, decode::RowData> *rows =
463 &(segment->annotation_rows);
464
465 const auto iter = rows->find(row);
466 if (iter != rows->end())
467 (*iter).second.get_annotation_subset(dest,
468 start_sample, end_sample);
30677c13 469 } catch (out_of_range&) {
72435789
SA
470 // Do nothing
471 }
47747218
SA
472}
473
474void DecodeSignal::save_settings(QSettings &settings) const
475{
476 SignalBase::save_settings(settings);
477
c8e60bdf
SA
478 settings.setValue("decoders", (int)(stack_.size()));
479
8b5ea5a1 480 // Save decoder stack
c8e60bdf
SA
481 int decoder_idx = 0;
482 for (shared_ptr<decode::Decoder> decoder : stack_) {
483 settings.beginGroup("decoder" + QString::number(decoder_idx++));
484
485 settings.setValue("id", decoder->decoder()->id);
486
d3feec23
SA
487 // Save decoder options
488 const map<string, GVariant*>& options = decoder->options();
489
490 settings.setValue("options", (int)options.size());
491
492 // Note: decode::Decoder::options() returns only the options
493 // that differ from the default. See binding::Decoder::getter()
494 int i = 0;
495 for (auto option : options) {
496 settings.beginGroup("option" + QString::number(i));
497 settings.setValue("name", QString::fromStdString(option.first));
498 GlobalSettings::store_gvariant(settings, option.second);
499 settings.endGroup();
500 i++;
501 }
502
c8e60bdf
SA
503 settings.endGroup();
504 }
505
8b5ea5a1
SA
506 // Save channel mapping
507 settings.setValue("channels", (int)channels_.size());
508
509 for (unsigned int channel_id = 0; channel_id < channels_.size(); channel_id++) {
510 auto channel = find_if(channels_.begin(), channels_.end(),
511 [&](data::DecodeChannel ch) { return ch.id == channel_id; });
512
513 if (channel == channels_.end()) {
514 qDebug() << "ERROR: Gap in channel index:" << channel_id;
515 continue;
516 }
517
518 settings.beginGroup("channel" + QString::number(channel_id));
519
520 settings.setValue("name", channel->name); // Useful for debugging
521 settings.setValue("initial_pin_state", channel->initial_pin_state);
522
523 if (channel->assigned_signal)
524 settings.setValue("assigned_signal_name", channel->assigned_signal->name());
525
526 settings.endGroup();
527 }
47747218
SA
528}
529
530void DecodeSignal::restore_settings(QSettings &settings)
531{
532 SignalBase::restore_settings(settings);
533
8b5ea5a1 534 // Restore decoder stack
c8e60bdf
SA
535 GSList *dec_list = g_slist_copy((GSList*)srd_decoder_list());
536
537 int decoders = settings.value("decoders").toInt();
538
539 for (int decoder_idx = 0; decoder_idx < decoders; decoder_idx++) {
540 settings.beginGroup("decoder" + QString::number(decoder_idx));
541
542 QString id = settings.value("id").toString();
543
544 for (GSList *entry = dec_list; entry; entry = entry->next) {
545 const srd_decoder *dec = (srd_decoder*)entry->data;
546 if (!dec)
547 continue;
548
549 if (QString::fromUtf8(dec->id) == id) {
d3feec23
SA
550 shared_ptr<decode::Decoder> decoder =
551 make_shared<decode::Decoder>(dec);
552
553 stack_.push_back(decoder);
554
555 // Restore decoder options that differ from their default
556 int options = settings.value("options").toInt();
557
558 for (int i = 0; i < options; i++) {
559 settings.beginGroup("option" + QString::number(i));
560 QString name = settings.value("name").toString();
561 GVariant *value = GlobalSettings::restore_gvariant(settings);
562 decoder->set_option(name.toUtf8(), value);
563 settings.endGroup();
564 }
c8e60bdf
SA
565
566 // Include the newly created decode channels in the channel lists
567 update_channel_list();
568 break;
569 }
570 }
571
572 settings.endGroup();
4ca06ec3 573 channels_updated();
c8e60bdf
SA
574 }
575
8b5ea5a1
SA
576 // Restore channel mapping
577 unsigned int channels = settings.value("channels").toInt();
578
579 const unordered_set< shared_ptr<data::SignalBase> > signalbases =
580 session_.signalbases();
581
582 for (unsigned int channel_id = 0; channel_id < channels; channel_id++) {
583 auto channel = find_if(channels_.begin(), channels_.end(),
584 [&](data::DecodeChannel ch) { return ch.id == channel_id; });
585
586 if (channel == channels_.end()) {
587 qDebug() << "ERROR: Non-existant channel index:" << channel_id;
588 continue;
589 }
590
591 settings.beginGroup("channel" + QString::number(channel_id));
592
593 QString assigned_signal_name = settings.value("assigned_signal_name").toString();
594
595 for (shared_ptr<data::SignalBase> signal : signalbases)
596 if (signal->name() == assigned_signal_name)
597 channel->assigned_signal = signal.get();
598
599 channel->initial_pin_state = settings.value("initial_pin_state").toInt();
600
601 settings.endGroup();
602 }
603
aa71890d 604 // Update the internal structures
e3202557 605 stack_config_changed_ = true;
aa71890d
SA
606 update_channel_list();
607 commit_decoder_channels();
608
8b5ea5a1 609 begin_decode();
47747218
SA
610}
611
403c3e87
SA
612void DecodeSignal::set_error_message(QString msg)
613{
614 error_message_ = msg;
fe060a48
SA
615 // TODO Emulate noquote()
616 qDebug().nospace() << name() << ": " << msg;
403c3e87
SA
617}
618
8a603e13
SA
619uint32_t DecodeSignal::get_input_segment_count() const
620{
621 uint64_t count = std::numeric_limits<uint64_t>::max();
622 bool no_signals_assigned = true;
623
624 for (const data::DecodeChannel &ch : channels_)
625 if (ch.assigned_signal) {
626 no_signals_assigned = false;
627
628 const shared_ptr<Logic> logic_data = ch.assigned_signal->logic_data();
629 if (!logic_data || logic_data->logic_segments().empty())
630 return 0;
631
632 // Find the min value of all segment counts
633 if ((uint64_t)(logic_data->logic_segments().size()) < count)
634 count = logic_data->logic_segments().size();
635 }
636
637 return (no_signals_assigned ? 0 : count);
638}
639
640uint32_t DecodeSignal::get_input_samplerate(uint32_t segment_id) const
641{
642 double samplerate = 0;
643
644 for (const data::DecodeChannel &ch : channels_)
645 if (ch.assigned_signal) {
646 const shared_ptr<Logic> logic_data = ch.assigned_signal->logic_data();
647 if (!logic_data || logic_data->logic_segments().empty())
648 continue;
649
650 try {
651 const shared_ptr<LogicSegment> segment = logic_data->logic_segments().at(segment_id);
652 samplerate = segment->samplerate();
30677c13 653 } catch (out_of_range&) {
8a603e13
SA
654 // Do nothing
655 }
656 break;
657 }
658
659 return samplerate;
660}
661
9f97b357
SA
662void DecodeSignal::update_channel_list()
663{
47747218 664 vector<data::DecodeChannel> prev_channels = channels_;
9f97b357
SA
665 channels_.clear();
666
667 uint16_t id = 0;
668
669 // Copy existing entries, create new as needed
47747218 670 for (shared_ptr<Decoder> decoder : stack_) {
9f97b357
SA
671 const srd_decoder* srd_d = decoder->decoder();
672 const GSList *l;
673
674 // Mandatory channels
675 for (l = srd_d->channels; l; l = l->next) {
676 const struct srd_channel *const pdch = (struct srd_channel *)l->data;
677 bool ch_added = false;
678
679 // Copy but update ID if this channel was in the list before
47747218 680 for (data::DecodeChannel &ch : prev_channels)
9f97b357
SA
681 if (ch.pdch_ == pdch) {
682 ch.id = id++;
683 channels_.push_back(ch);
684 ch_added = true;
685 break;
686 }
687
688 if (!ch_added) {
689 // Create new entry without a mapped signal
6e7a4a00 690 data::DecodeChannel ch = {id++, 0, false, nullptr,
9f97b357
SA
691 QString::fromUtf8(pdch->name), QString::fromUtf8(pdch->desc),
692 SRD_INITIAL_PIN_SAME_AS_SAMPLE0, decoder, pdch};
693 channels_.push_back(ch);
694 }
695 }
696
697 // Optional channels
698 for (l = srd_d->opt_channels; l; l = l->next) {
699 const struct srd_channel *const pdch = (struct srd_channel *)l->data;
700 bool ch_added = false;
701
702 // Copy but update ID if this channel was in the list before
47747218 703 for (data::DecodeChannel &ch : prev_channels)
9f97b357
SA
704 if (ch.pdch_ == pdch) {
705 ch.id = id++;
706 channels_.push_back(ch);
707 ch_added = true;
708 break;
709 }
710
711 if (!ch_added) {
712 // Create new entry without a mapped signal
6e7a4a00 713 data::DecodeChannel ch = {id++, 0, true, nullptr,
9f97b357
SA
714 QString::fromUtf8(pdch->name), QString::fromUtf8(pdch->desc),
715 SRD_INITIAL_PIN_SAME_AS_SAMPLE0, decoder, pdch};
716 channels_.push_back(ch);
717 }
718 }
719 }
720
47747218
SA
721 // Invalidate the logic output data if the channel assignment changed
722 if (prev_channels.size() != channels_.size()) {
723 // The number of channels changed, there's definitely a difference
724 logic_mux_data_invalid_ = true;
725 } else {
726 // Same number but assignment may still differ, so compare all channels
727 for (size_t i = 0; i < channels_.size(); i++) {
728 const data::DecodeChannel &p_ch = prev_channels[i];
729 const data::DecodeChannel &ch = channels_[i];
730
731 if ((p_ch.pdch_ != ch.pdch_) ||
732 (p_ch.assigned_signal != ch.assigned_signal)) {
733 logic_mux_data_invalid_ = true;
734 break;
735 }
736 }
737
738 }
739
9f97b357
SA
740 channels_updated();
741}
742
27a3f09b 743void DecodeSignal::commit_decoder_channels()
ad908057 744{
27a3f09b
SA
745 // Submit channel list to every decoder, containing only the relevant channels
746 for (shared_ptr<decode::Decoder> dec : stack_) {
747 vector<data::DecodeChannel*> channel_list;
748
749 for (data::DecodeChannel &ch : channels_)
750 if (ch.decoder_ == dec)
751 channel_list.push_back(&ch);
47747218 752
27a3f09b
SA
753 dec->set_channels(channel_list);
754 }
aa71890d
SA
755
756 // Channel bit IDs must be in sync with the channel's apperance in channels_
757 int id = 0;
758 for (data::DecodeChannel &ch : channels_)
759 if (ch.assigned_signal)
760 ch.bit_id = id++;
47747218
SA
761}
762
ed535cd7 763void DecodeSignal::mux_logic_samples(uint32_t segment_id, const int64_t start, const int64_t end)
47747218 764{
27a3f09b
SA
765 // Enforce end to be greater than start
766 if (end <= start)
767 return;
768
ed535cd7 769 // Fetch the channel segments and their data
27a3f09b
SA
770 vector<shared_ptr<LogicSegment> > segments;
771 vector<const uint8_t*> signal_data;
772 vector<uint8_t> signal_in_bytepos;
773 vector<uint8_t> signal_in_bitpos;
774
775 for (data::DecodeChannel &ch : channels_)
776 if (ch.assigned_signal) {
777 const shared_ptr<Logic> logic_data = ch.assigned_signal->logic_data();
ed535cd7
SA
778
779 shared_ptr<LogicSegment> segment;
780 try {
781 segment = logic_data->logic_segments().at(segment_id);
30677c13 782 } catch (out_of_range&) {
ed535cd7
SA
783 qDebug() << "Muxer error for" << name() << ":" << ch.assigned_signal->name() \
784 << "has no logic segment" << segment_id;
785 return;
786 }
27a3f09b 787 segments.push_back(segment);
b82243f7
SA
788
789 uint8_t* data = new uint8_t[(end - start) * segment->unit_size()];
790 segment->get_samples(start, end, data);
791 signal_data.push_back(data);
27a3f09b
SA
792
793 const int bitpos = ch.assigned_signal->logic_bit_index();
794 signal_in_bytepos.push_back(bitpos / 8);
795 signal_in_bitpos.push_back(bitpos % 8);
796 }
797
ed535cd7
SA
798
799 shared_ptr<LogicSegment> output_segment;
800 try {
801 output_segment = logic_mux_data_->logic_segments().at(segment_id);
30677c13 802 } catch (out_of_range&) {
ed535cd7
SA
803 qDebug() << "Muxer error for" << name() << ": no logic mux segment" \
804 << segment_id << "in mux_logic_samples(), mux segments size is" \
805 << logic_mux_data_->logic_segments().size();
806 return;
807 }
808
27a3f09b 809 // Perform the muxing of signal data into the output data
8a603e13 810 uint8_t* output = new uint8_t[(end - start) * output_segment->unit_size()];
27a3f09b
SA
811 unsigned int signal_count = signal_data.size();
812
3b5282a2
SA
813 for (int64_t sample_cnt = 0; !logic_mux_interrupt_ && (sample_cnt < (end - start));
814 sample_cnt++) {
815
27a3f09b
SA
816 int bitpos = 0;
817 uint8_t bytepos = 0;
818
8a603e13
SA
819 const int out_sample_pos = sample_cnt * output_segment->unit_size();
820 for (unsigned int i = 0; i < output_segment->unit_size(); i++)
27a3f09b 821 output[out_sample_pos + i] = 0;
47747218 822
27a3f09b
SA
823 for (unsigned int i = 0; i < signal_count; i++) {
824 const int in_sample_pos = sample_cnt * segments[i]->unit_size();
825 const uint8_t in_sample = 1 &
826 ((signal_data[i][in_sample_pos + signal_in_bytepos[i]]) >> (signal_in_bitpos[i]));
47747218 827
27a3f09b
SA
828 const uint8_t out_sample = output[out_sample_pos + bytepos];
829
830 output[out_sample_pos + bytepos] = out_sample | (in_sample << bitpos);
831
832 bitpos++;
833 if (bitpos > 7) {
834 bitpos = 0;
835 bytepos++;
836 }
837 }
47747218
SA
838 }
839
8a603e13 840 output_segment->append_payload(output, (end - start) * output_segment->unit_size());
27a3f09b
SA
841 delete[] output;
842
843 for (const uint8_t* data : signal_data)
844 delete[] data;
845}
846
847void DecodeSignal::logic_mux_proc()
848{
ed535cd7
SA
849 uint32_t segment_id = 0;
850
8a603e13
SA
851 assert(logic_mux_data_);
852
65efd025
SA
853 // Create initial logic mux segment
854 shared_ptr<LogicSegment> output_segment =
85a70280
SA
855 make_shared<LogicSegment>(*logic_mux_data_, segment_id,
856 logic_mux_unit_size_, 0);
65efd025 857 logic_mux_data_->push_segment(output_segment);
8a603e13
SA
858
859 output_segment->set_samplerate(get_input_samplerate(0));
ed535cd7 860
27a3f09b 861 do {
ed535cd7 862 const uint64_t input_sample_count = get_working_sample_count(segment_id);
8a603e13 863 const uint64_t output_sample_count = output_segment->get_sample_count();
27a3f09b
SA
864
865 const uint64_t samples_to_process =
866 (input_sample_count > output_sample_count) ?
867 (input_sample_count - output_sample_count) : 0;
868
869 // Process the samples if necessary...
870 if (samples_to_process > 0) {
8a603e13 871 const uint64_t unit_size = output_segment->unit_size();
27a3f09b
SA
872 const uint64_t chunk_sample_count = DecodeChunkLength / unit_size;
873
874 uint64_t processed_samples = 0;
875 do {
876 const uint64_t start_sample = output_sample_count + processed_samples;
877 const uint64_t sample_count =
878 min(samples_to_process - processed_samples, chunk_sample_count);
879
ed535cd7 880 mux_logic_samples(segment_id, start_sample, start_sample + sample_count);
27a3f09b
SA
881 processed_samples += sample_count;
882
883 // ...and process the newly muxed logic data
884 decode_input_cond_.notify_one();
3b5282a2 885 } while (!logic_mux_interrupt_ && (processed_samples < samples_to_process));
27a3f09b
SA
886 }
887
1ec191ed 888 if (samples_to_process == 0) {
ed535cd7
SA
889 // TODO Optimize this by caching the input segment count and only
890 // querying it when the cached value was reached
891 if (segment_id < get_input_segment_count() - 1) {
892 // Process next segment
893 segment_id++;
894
65efd025 895 output_segment =
85a70280
SA
896 make_shared<LogicSegment>(*logic_mux_data_, segment_id,
897 logic_mux_unit_size_, 0);
65efd025 898 logic_mux_data_->push_segment(output_segment);
ba5f2186 899
8a603e13
SA
900 output_segment->set_samplerate(get_input_samplerate(segment_id));
901
ed535cd7
SA
902 } else {
903 // All segments have been processed
904 logic_mux_data_invalid_ = false;
905
906 // Wait for more input
907 unique_lock<mutex> logic_mux_lock(logic_mux_mutex_);
908 logic_mux_cond_.wait(logic_mux_lock);
909 }
27a3f09b 910 }
1ae18301 911
1ec191ed 912 } while (!logic_mux_interrupt_);
47747218
SA
913}
914
915void DecodeSignal::decode_data(
8a603e13
SA
916 const int64_t abs_start_samplenum, const int64_t sample_count,
917 const shared_ptr<LogicSegment> input_segment)
47747218 918{
8a603e13 919 const int64_t unit_size = input_segment->unit_size();
27a3f09b 920 const int64_t chunk_sample_count = DecodeChunkLength / unit_size;
47747218
SA
921
922 for (int64_t i = abs_start_samplenum;
1ae18301
SA
923 error_message_.isEmpty() && !decode_interrupt_ &&
924 (i < (abs_start_samplenum + sample_count));
47747218
SA
925 i += chunk_sample_count) {
926
927 const int64_t chunk_end = min(i + chunk_sample_count,
928 abs_start_samplenum + sample_count);
929
e06cf18d
SA
930 {
931 lock_guard<mutex> lock(output_mutex_);
b82908ab
SA
932 // Update the sample count showing the samples including currently processed ones
933 segments_.at(current_segment_id_).samples_decoded_incl = chunk_end;
e06cf18d
SA
934 }
935
b82243f7
SA
936 int64_t data_size = (chunk_end - i) * unit_size;
937 uint8_t* chunk = new uint8_t[data_size];
8a603e13 938 input_segment->get_samples(i, chunk_end, chunk);
47747218 939
e91883bb 940 if (srd_session_send(srd_session_, i, chunk_end, chunk,
1ae18301 941 data_size, unit_size) != SRD_OK)
403c3e87 942 set_error_message(tr("Decoder reported an error"));
a3ebd556 943
47747218
SA
944 delete[] chunk;
945
b82908ab
SA
946 {
947 lock_guard<mutex> lock(output_mutex_);
948 // Now that all samples are processed, the exclusive sample count catches up
949 segments_.at(current_segment_id_).samples_decoded_excl = chunk_end;
950 }
951
1b56c646
SA
952 // Notify the frontend that we processed some data and
953 // possibly have new annotations as well
954 new_annotations();
47747218
SA
955 }
956}
957
958void DecodeSignal::decode_proc()
959{
65efd025
SA
960 current_segment_id_ = 0;
961
962 // If there is no input data available yet, wait until it is or we're interrupted
963 if (logic_mux_data_->logic_segments().size() == 0) {
964 unique_lock<mutex> input_wait_lock(input_mutex_);
965 decode_input_cond_.wait(input_wait_lock);
966 }
a3ebd556
SA
967
968 if (decode_interrupt_)
969 return;
970
8a603e13 971 shared_ptr<LogicSegment> input_segment = logic_mux_data_->logic_segments().front();
8a603e13 972 assert(input_segment);
65efd025
SA
973
974 // Create the initial segment and set its sample rate so that we can pass it to SRD
975 create_decode_segment();
8a603e13 976 segments_.at(current_segment_id_).samplerate = input_segment->samplerate();
65efd025 977 segments_.at(current_segment_id_).start_time = input_segment->start_time();
8a603e13 978
65efd025
SA
979 start_srd_session();
980
981 uint64_t sample_count = 0;
27a3f09b 982 uint64_t abs_start_samplenum = 0;
47747218 983 do {
27a3f09b
SA
984 // Keep processing new samples until we exhaust the input data
985 do {
767bf4e7 986 lock_guard<mutex> input_lock(input_mutex_);
8a603e13 987 sample_count = input_segment->get_sample_count() - abs_start_samplenum;
27a3f09b
SA
988
989 if (sample_count > 0) {
8a603e13 990 decode_data(abs_start_samplenum, sample_count, input_segment);
27a3f09b
SA
991 abs_start_samplenum += sample_count;
992 }
1b56c646
SA
993 } while (error_message_.isEmpty() && (sample_count > 0) && !decode_interrupt_);
994
8a603e13
SA
995 if (error_message_.isEmpty() && !decode_interrupt_ && sample_count == 0) {
996 if (current_segment_id_ < logic_mux_data_->logic_segments().size() - 1) {
997 // Process next segment
998 current_segment_id_++;
999
1000 try {
1001 input_segment = logic_mux_data_->logic_segments().at(current_segment_id_);
30677c13 1002 } catch (out_of_range&) {
8a603e13
SA
1003 qDebug() << "Decode error for" << name() << ": no logic mux segment" \
1004 << current_segment_id_ << "in decode_proc(), mux segments size is" \
1005 << logic_mux_data_->logic_segments().size();
1006 return;
1007 }
1008 abs_start_samplenum = 0;
1009
65efd025
SA
1010 // Create the next segment and set its metadata
1011 create_decode_segment();
8a603e13 1012 segments_.at(current_segment_id_).samplerate = input_segment->samplerate();
65efd025 1013 segments_.at(current_segment_id_).start_time = input_segment->start_time();
8a603e13 1014
90ca4cc8
SA
1015 // Reset decoder state but keep the decoder stack intact
1016 terminate_srd_session();
8a603e13
SA
1017 } else {
1018 // All segments have been processed
1b56c646 1019 decode_finished();
27a3f09b 1020
8a603e13
SA
1021 // Wait for new input data or an interrupt was requested
1022 unique_lock<mutex> input_wait_lock(input_mutex_);
1023 decode_input_cond_.wait(input_wait_lock);
1024 }
27a3f09b
SA
1025 }
1026 } while (error_message_.isEmpty() && !decode_interrupt_);
ce0b6a40
GS
1027
1028 // Potentially reap decoders when the application no longer is
1029 // interested in their (pending) results.
1030 if (decode_interrupt_)
1031 terminate_srd_session();
e91883bb
SA
1032}
1033
1034void DecodeSignal::start_srd_session()
1035{
8ce0e732
SA
1036 // If there were stack changes, the session has been destroyed by now, so if
1037 // it hasn't been destroyed, we can just reset and re-use it
ce0b6a40
GS
1038 if (srd_session_) {
1039 // When a decoder stack was created before, re-use it
1040 // for the next stream of input data, after terminating
1041 // potentially still executing operations, and resetting
1042 // internal state. Skip the rather expensive (teardown
1043 // and) construction of another decoder stack.
1044
1045 // TODO Reduce redundancy, use a common code path for
72486b78 1046 // the meta/start sequence?
ce0b6a40 1047 terminate_srd_session();
72486b78
SA
1048
1049 // Metadata is cleared also, so re-set it
ba5b52e1 1050 uint64_t samplerate = 0;
7dd518b8 1051 if (segments_.size() > 0)
ba5b52e1
GS
1052 samplerate = segments_.at(current_segment_id_).samplerate;
1053 if (samplerate)
7dd518b8 1054 srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE,
ba5b52e1 1055 g_variant_new_uint64(samplerate));
72486b78
SA
1056 for (const shared_ptr<decode::Decoder> &dec : stack_)
1057 dec->apply_all_options();
ce0b6a40 1058 srd_session_start(srd_session_);
72486b78 1059
ce0b6a40
GS
1060 return;
1061 }
e91883bb 1062
a3ebd556
SA
1063 // Create the session
1064 srd_session_new(&srd_session_);
1065 assert(srd_session_);
47747218 1066
a3ebd556
SA
1067 // Create the decoders
1068 srd_decoder_inst *prev_di = nullptr;
1069 for (const shared_ptr<decode::Decoder> &dec : stack_) {
1070 srd_decoder_inst *const di = dec->create_decoder_inst(srd_session_);
e91883bb 1071
a3ebd556 1072 if (!di) {
403c3e87 1073 set_error_message(tr("Failed to create decoder instance"));
a3ebd556 1074 srd_session_destroy(srd_session_);
c5f9553c 1075 srd_session_ = nullptr;
a3ebd556
SA
1076 return;
1077 }
e91883bb 1078
a3ebd556
SA
1079 if (prev_di)
1080 srd_inst_stack(srd_session_, prev_di, di);
e91883bb 1081
a3ebd556 1082 prev_di = di;
e91883bb 1083 }
a3ebd556
SA
1084
1085 // Start the session
7dd518b8
SA
1086 if (segments_.size() > 0)
1087 srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE,
1088 g_variant_new_uint64(segments_.at(current_segment_id_).samplerate));
a3ebd556
SA
1089
1090 srd_pd_output_callback_add(srd_session_, SRD_OUTPUT_ANN,
1091 DecodeSignal::annotation_callback, this);
1092
1093 srd_session_start(srd_session_);
e3202557
SA
1094
1095 // We just recreated the srd session, so all stack changes are applied now
1096 stack_config_changed_ = false;
e91883bb 1097}
47747218 1098
ce0b6a40
GS
1099void DecodeSignal::terminate_srd_session()
1100{
1101 // Call the "terminate and reset" routine for the decoder stack
1102 // (if available). This does not harm those stacks which already
1103 // have completed their operation, and reduces response time for
1104 // those stacks which still are processing data while the
1105 // application no longer wants them to.
72486b78 1106 if (srd_session_) {
ce0b6a40 1107 srd_session_terminate_reset(srd_session_);
72486b78
SA
1108
1109 // Metadata is cleared also, so re-set it
ba5b52e1 1110 uint64_t samplerate = 0;
7dd518b8 1111 if (segments_.size() > 0)
ba5b52e1
GS
1112 samplerate = segments_.at(current_segment_id_).samplerate;
1113 if (samplerate)
7dd518b8 1114 srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE,
ba5b52e1 1115 g_variant_new_uint64(samplerate));
72486b78
SA
1116 for (const shared_ptr<decode::Decoder> &dec : stack_)
1117 dec->apply_all_options();
1118 }
ce0b6a40
GS
1119}
1120
e91883bb
SA
1121void DecodeSignal::stop_srd_session()
1122{
1123 if (srd_session_) {
1124 // Destroy the session
1125 srd_session_destroy(srd_session_);
1126 srd_session_ = nullptr;
8ce0e732
SA
1127
1128 // Mark the decoder instances as non-existant since they were deleted
1129 for (const shared_ptr<decode::Decoder> &dec : stack_)
1130 dec->invalidate_decoder_inst();
e91883bb 1131 }
47747218
SA
1132}
1133
a8a9222d
SA
1134void DecodeSignal::connect_input_notifiers()
1135{
1136 // Disconnect the notification slot from the previous set of signals
1b56c646 1137 disconnect(this, SLOT(on_data_cleared()));
a8a9222d
SA
1138 disconnect(this, SLOT(on_data_received()));
1139
1140 // Connect the currently used signals to our slot
1141 for (data::DecodeChannel &ch : channels_) {
1142 if (!ch.assigned_signal)
1143 continue;
1144
1b56c646
SA
1145 const data::SignalBase *signal = ch.assigned_signal;
1146 connect(signal, SIGNAL(samples_cleared()),
1147 this, SLOT(on_data_cleared()));
b10b58f4 1148 connect(signal, SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)),
a8a9222d
SA
1149 this, SLOT(on_data_received()));
1150 }
1151}
1152
65efd025 1153void DecodeSignal::create_decode_segment()
4913560f 1154{
65efd025
SA
1155 // Create annotation segment
1156 segments_.emplace_back(DecodeSegment());
72435789 1157
65efd025
SA
1158 // Add annotation classes
1159 for (const shared_ptr<decode::Decoder> &dec : stack_) {
1160 assert(dec);
1161 const srd_decoder *const decc = dec->decoder();
1162 assert(dec->decoder());
4913560f 1163
f9807084 1164 int row_index = 0;
65efd025
SA
1165 // Add a row for the decoder if it doesn't have a row list
1166 if (!decc->annotation_rows)
f9807084 1167 (segments_.back().annotation_rows)[Row(row_index++, decc)] =
65efd025 1168 decode::RowData();
4913560f 1169
65efd025
SA
1170 // Add the decoder rows
1171 for (const GSList *l = decc->annotation_rows; l; l = l->next) {
1172 const srd_decoder_annotation_row *const ann_row =
1173 (srd_decoder_annotation_row *)l->data;
1174 assert(ann_row);
4913560f 1175
f9807084 1176 const Row row(row_index++, decc, ann_row);
4913560f 1177
65efd025
SA
1178 // Add a new empty row data object
1179 (segments_.back().annotation_rows)[row] =
1180 decode::RowData();
4913560f
SA
1181 }
1182 }
1183}
1184
47747218
SA
1185void DecodeSignal::annotation_callback(srd_proto_data *pdata, void *decode_signal)
1186{
1187 assert(pdata);
b21501d6 1188 assert(decode_signal);
47747218
SA
1189
1190 DecodeSignal *const ds = (DecodeSignal*)decode_signal;
1191 assert(ds);
1192
3b5282a2
SA
1193 if (ds->decode_interrupt_)
1194 return;
1195
47747218
SA
1196 lock_guard<mutex> lock(ds->output_mutex_);
1197
47747218
SA
1198 // Find the row
1199 assert(pdata->pdo);
1200 assert(pdata->pdo->di);
1201 const srd_decoder *const decc = pdata->pdo->di->decoder;
1202 assert(decc);
1203
1becee23
UH
1204 const srd_proto_data_annotation *const pda =
1205 (const srd_proto_data_annotation*)pdata->data;
1206 assert(pda);
1207
8a603e13 1208 auto row_iter = ds->segments_.at(ds->current_segment_id_).annotation_rows.end();
47747218
SA
1209
1210 // Try looking up the sub-row of this class
1becee23
UH
1211 const auto format = pda->ann_class;
1212 const auto r = ds->class_rows_.find(make_pair(decc, format));
47747218 1213 if (r != ds->class_rows_.end())
8a603e13 1214 row_iter = ds->segments_.at(ds->current_segment_id_).annotation_rows.find((*r).second);
47747218
SA
1215 else {
1216 // Failing that, use the decoder as a key
f9807084 1217 row_iter = ds->segments_.at(ds->current_segment_id_).annotation_rows.find(Row(0, decc));
47747218
SA
1218 }
1219
8a603e13 1220 if (row_iter == ds->segments_.at(ds->current_segment_id_).annotation_rows.end()) {
47747218 1221 qDebug() << "Unexpected annotation: decoder = " << decc <<
1becee23 1222 ", format = " << format;
47747218
SA
1223 assert(false);
1224 return;
1225 }
1226
1227 // Add the annotation
1becee23 1228 (*row_iter).second.emplace_annotation(pdata);
47747218
SA
1229}
1230
1231void DecodeSignal::on_capture_state_changed(int state)
1232{
1233 // If a new acquisition was started, we need to start decoding from scratch
ba5f2186
SA
1234 if (state == Session::Running) {
1235 logic_mux_data_invalid_ = true;
47747218 1236 begin_decode();
ba5f2186 1237 }
47747218
SA
1238}
1239
1b56c646
SA
1240void DecodeSignal::on_data_cleared()
1241{
1242 reset_decode();
1243}
1244
47747218
SA
1245void DecodeSignal::on_data_received()
1246{
5620539c
SA
1247 // If we detected a lack of input data when trying to start decoding,
1248 // we have set an error message. Only try again if we now have data
1249 // to work with
1250 if ((!error_message_.isEmpty()) && (get_input_segment_count() == 0))
1251 return;
1252
1b56c646
SA
1253 if (!logic_mux_thread_.joinable())
1254 begin_decode();
1255 else
1256 logic_mux_cond_.notify_one();
47747218
SA
1257}
1258
ad908057
SA
1259} // namespace data
1260} // namespace pv