]> sigrok.org Git - pulseview.git/commitdiff
DecodeSignal: avoid specifying a zero samplerate to libsigrokdecode
authorGerhard Sittig <redacted>
Sat, 12 May 2018 06:31:52 +0000 (08:31 +0200)
committerUwe Hermann <redacted>
Thu, 17 May 2018 21:08:31 +0000 (23:08 +0200)
When the sample rate is not known, avoid claiming the value would be
zero and calling setup routines in backend libraries. Although the call
is not strictly fatal, this simple check avoids potential log messages
at callee's for this unexpected condition.

pv/data/decodesignal.cpp

index d60c53e48b6e8df403d7350deaf091d94e866740..e70947b2c4989a11ddaf0cdaee38b3af946afa07 100644 (file)
@@ -1020,9 +1020,12 @@ void DecodeSignal::start_srd_session()
                terminate_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(segments_.at(current_segment_id_).samplerate));
+                               g_variant_new_uint64(samplerate));
                for (const shared_ptr<decode::Decoder> &dec : stack_)
                        dec->apply_all_options();
                srd_session_start(srd_session_);
@@ -1077,9 +1080,12 @@ void DecodeSignal::terminate_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(segments_.at(current_segment_id_).samplerate));
+                               g_variant_new_uint64(samplerate));
                for (const shared_ptr<decode::Decoder> &dec : stack_)
                        dec->apply_all_options();
        }