]> sigrok.org Git - pulseview.git/commitdiff
DecodeSignal: Re-set decoder metadata after stack termination
authorSoeren Apel <redacted>
Fri, 4 May 2018 06:58:59 +0000 (08:58 +0200)
committerSoeren Apel <redacted>
Fri, 4 May 2018 06:58:59 +0000 (08:58 +0200)
pv/data/decode/decoder.cpp
pv/data/decode/decoder.hpp
pv/data/decodesignal.cpp

index 6ce60da8559c96e1e81e7b4e974ba4a6d42874a5..f86c5d08dc86d9261718ab92e2005b1b30dbd914 100644 (file)
@@ -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);
index 02f3f04bfb11385d17bab9abb0a888396ff50bde..55742c6070e5a020c00042b2c8894e744b13986e 100644 (file)
@@ -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);
index 4739b60675ab3e97ee9496ebc1a1d642ccf12bca..d17c883c4b380eaac155ae1d04c88d7cfa16330b 100644 (file)
@@ -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<decode::Decoder> &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<decode::Decoder> &dec : stack_)
+                       dec->apply_all_options();
+       }
 }
 
 void DecodeSignal::stop_srd_session()