X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fdata%2Fdecodesignal.cpp;h=fbbdd793952d4ffd578532944ae4cab9c66ecfe5;hp=f5dc000169611e355e0d13c07182f81de4bffc5e;hb=f9ebf303a853997535eb157f50d1fd28753d76bf;hpb=403c3e87178230339ceeb1927b2ed99d3fde046f diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index f5dc0001..fbbdd793 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -65,7 +65,7 @@ DecodeSignal::DecodeSignal(pv::Session &session) : DecodeSignal::~DecodeSignal() { - reset_decode(); + reset_decode(true); } const vector< shared_ptr >& DecodeSignal::decoder_stack() const @@ -130,9 +130,9 @@ bool DecodeSignal::toggle_decoder_visibility(int index) return state; } -void DecodeSignal::reset_decode() +void DecodeSignal::reset_decode(bool shutting_down) { - if (stack_config_changed_) + if (stack_config_changed_ || shutting_down) stop_srd_session(); else terminate_srd_session(); @@ -158,7 +158,8 @@ void DecodeSignal::reset_decode() if (!error_message_.isEmpty()) { error_message_ = QString(); - qDebug().noquote().nospace() << name() << ": Error cleared"; + // TODO Emulate noquote() + qDebug().nospace() << name() << ": Error cleared"; } decode_reset(); @@ -279,6 +280,9 @@ void DecodeSignal::auto_assign_signals(const shared_ptr dec) continue; for (shared_ptr s : session_.signalbases()) { + if (!s->enabled()) + continue; + const QString ch_name = ch.name.toLower(); const QString s_name = s->name().toLower(); @@ -588,7 +592,8 @@ void DecodeSignal::restore_settings(QSettings &settings) void DecodeSignal::set_error_message(QString msg) { error_message_ = msg; - qDebug().noquote().nospace() << name() << ": " << msg; + // TODO Emulate noquote() + qDebug().nospace() << name() << ": " << msg; } uint32_t DecodeSignal::get_input_segment_count() const @@ -785,7 +790,9 @@ void DecodeSignal::mux_logic_samples(uint32_t segment_id, const int64_t start, c uint8_t* output = new uint8_t[(end - start) * output_segment->unit_size()]; unsigned int signal_count = signal_data.size(); - for (int64_t sample_cnt = 0; sample_cnt < (end - start); sample_cnt++) { + for (int64_t sample_cnt = 0; !logic_mux_interrupt_ && (sample_cnt < (end - start)); + sample_cnt++) { + int bitpos = 0; uint8_t bytepos = 0; @@ -855,7 +862,7 @@ void DecodeSignal::logic_mux_proc() // ...and process the newly muxed logic data decode_input_cond_.notify_one(); - } while (processed_samples < samples_to_process); + } while (!logic_mux_interrupt_ && (processed_samples < samples_to_process)); } if (samples_to_process == 0) { @@ -898,6 +905,13 @@ void DecodeSignal::decode_data( const int64_t chunk_end = min(i + chunk_sample_count, abs_start_samplenum + sample_count); + // Report this chunk as already decoded so that annotations don't + // appear in an area that we claim to not having been been decoded yet + { + lock_guard lock(output_mutex_); + segments_.at(current_segment_id_).samples_decoded = chunk_end; + } + int64_t data_size = (chunk_end - i) * unit_size; uint8_t* chunk = new uint8_t[data_size]; input_segment->get_samples(i, chunk_end, chunk); @@ -911,11 +925,6 @@ void DecodeSignal::decode_data( delete[] chunk; - { - lock_guard lock(output_mutex_); - segments_.at(current_segment_id_).samples_decoded = chunk_end; - } - // Notify the frontend that we processed some data and // possibly have new annotations as well new_annotations(); @@ -979,9 +988,8 @@ void DecodeSignal::decode_proc() segments_.at(current_segment_id_).samplerate = input_segment->samplerate(); segments_.at(current_segment_id_).start_time = input_segment->start_time(); - // Reset decoder state - stop_srd_session(); - start_srd_session(); + // Reset decoder state but keep the decoder stack intact + terminate_srd_session(); } else { // All segments have been processed decode_finished(); @@ -1001,8 +1009,8 @@ void DecodeSignal::decode_proc() void DecodeSignal::start_srd_session() { - uint64_t samplerate; - + // If there were stack changes, the session has been destroyed by now, so if + // it hasn't been destroyed, we can just reset and re-use it if (srd_session_) { // When a decoder stack was created before, re-use it // for the next stream of input data, after terminating @@ -1011,13 +1019,20 @@ void DecodeSignal::start_srd_session() // and) construction of another decoder stack. // TODO Reduce redundancy, use a common code path for - // the meta/cb/start sequence? + // the meta/start sequence? terminate_srd_session(); - srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE, - g_variant_new_uint64(segments_.at(current_segment_id_).samplerate)); - srd_pd_output_callback_add(srd_session_, SRD_OUTPUT_ANN, - DecodeSignal::annotation_callback, this); + + // Metadata is cleared also, so re-set it + uint64_t samplerate = 0; + if (segments_.size() > 0) + samplerate = segments_.at(current_segment_id_).samplerate; + if (samplerate) + srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE, + g_variant_new_uint64(samplerate)); + for (const shared_ptr &dec : stack_) + dec->apply_all_options(); srd_session_start(srd_session_); + return; } @@ -1044,10 +1059,9 @@ void DecodeSignal::start_srd_session() } // Start the session - samplerate = segments_.at(current_segment_id_).samplerate; - if (samplerate) + if (segments_.size() > 0) srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE, - g_variant_new_uint64(samplerate)); + g_variant_new_uint64(segments_.at(current_segment_id_).samplerate)); srd_pd_output_callback_add(srd_session_, SRD_OUTPUT_ANN, DecodeSignal::annotation_callback, this); @@ -1065,8 +1079,19 @@ void DecodeSignal::terminate_srd_session() // have completed their operation, and reduces response time for // those stacks which still are processing data while the // application no longer wants them to. - if (srd_session_) + if (srd_session_) { srd_session_terminate_reset(srd_session_); + + // Metadata is cleared also, so re-set it + uint64_t samplerate = 0; + if (segments_.size() > 0) + samplerate = segments_.at(current_segment_id_).samplerate; + if (samplerate) + srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE, + g_variant_new_uint64(samplerate)); + for (const shared_ptr &dec : stack_) + dec->apply_all_options(); + } } void DecodeSignal::stop_srd_session() @@ -1075,6 +1100,10 @@ void DecodeSignal::stop_srd_session() // Destroy the session srd_session_destroy(srd_session_); srd_session_ = nullptr; + + // Mark the decoder instances as non-existant since they were deleted + for (const shared_ptr &dec : stack_) + dec->invalidate_decoder_inst(); } } @@ -1136,6 +1165,9 @@ void DecodeSignal::annotation_callback(srd_proto_data *pdata, void *decode_signa DecodeSignal *const ds = (DecodeSignal*)decode_signal; assert(ds); + if (ds->decode_interrupt_) + return; + lock_guard lock(ds->output_mutex_); // Find the row @@ -1187,6 +1219,12 @@ void DecodeSignal::on_data_cleared() void DecodeSignal::on_data_received() { + // If we detected a lack of input data when trying to start decoding, + // we have set an error message. Only try again if we now have data + // to work with + if ((!error_message_.isEmpty()) && (get_input_segment_count() == 0)) + return; + if (!logic_mux_thread_.joinable()) begin_decode(); else