From: Soeren Apel Date: Fri, 4 May 2018 06:58:59 +0000 (+0200) Subject: DecodeSignal: Re-set decoder metadata after stack termination X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=72486b789078f024e4f3404f81118c03b03e2b70;p=pulseview.git DecodeSignal: Re-set decoder metadata after stack termination --- diff --git a/pv/data/decode/decoder.cpp b/pv/data/decode/decoder.cpp index 6ce60da8..f86c5d08 100644 --- a/pv/data/decode/decoder.cpp +++ b/pv/data/decode/decoder.cpp @@ -87,6 +87,11 @@ void Decoder::set_option(const char *id, GVariant *value) options_[id] = value; // If we have a decoder instance, apply option value immediately + apply_all_options(); +} + +void Decoder::apply_all_options() +{ if (decoder_inst_) { GHashTable *const opt_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref); diff --git a/pv/data/decode/decoder.hpp b/pv/data/decode/decoder.hpp index 02f3f04b..55742c60 100644 --- a/pv/data/decode/decoder.hpp +++ b/pv/data/decode/decoder.hpp @@ -65,6 +65,8 @@ public: void set_option(const char *id, GVariant *value); + void apply_all_options(); + bool have_required_channels() const; srd_decoder_inst* create_decoder_inst(srd_session *session); diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index 4739b606..d17c883c 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -1006,8 +1006,6 @@ 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_) { @@ -1018,13 +1016,16 @@ 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(); + + // Metadata is cleared also, so re-set it 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); + for (const shared_ptr &dec : stack_) + dec->apply_all_options(); srd_session_start(srd_session_); + return; } @@ -1051,10 +1052,8 @@ void DecodeSignal::start_srd_session() } // Start the session - samplerate = segments_.at(current_segment_id_).samplerate; - if (samplerate) - srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE, - g_variant_new_uint64(samplerate)); + 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); @@ -1072,8 +1071,15 @@ 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 + srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE, + g_variant_new_uint64(segments_.at(current_segment_id_).samplerate)); + for (const shared_ptr &dec : stack_) + dec->apply_all_options(); + } } void DecodeSignal::stop_srd_session()