X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=0ac5bb7286dbe2cd6c76dbd07ca967ec2d289176;hp=e6fb52fd7dd0d589342ed877ee573cbb572a4755;hb=a3f678a7cad210fe796f4a76370996a1284da6d4;hpb=35750e4dc619d538f105ed024f3a72b630108234 diff --git a/pv/session.cpp b/pv/session.cpp index e6fb52fd..0ac5bb72 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -222,6 +222,25 @@ set< shared_ptr > Session::get_data() const return data; } +double Session::get_samplerate() const +{ + double samplerate = 0.0; + + for (const shared_ptr d : get_data()) { + assert(d); + const vector< shared_ptr > segments = + d->segments(); + for (const shared_ptr &s : segments) + samplerate = std::max(samplerate, s->samplerate()); + } + + // If there is no sample rate given we use samples as unit + if (samplerate == 0.0) + samplerate = 1.0; + + return samplerate; +} + const unordered_set< shared_ptr > Session::signals() const { shared_lock lock(signals_mutex_); @@ -305,9 +324,14 @@ void Session::remove_decode_signal(view::DecodeTrace *signal) void Session::set_capture_state(capture_state state) { - lock_guard lock(sampling_mutex_); - const bool changed = capture_state_ != state; - capture_state_ = state; + bool changed; + + { + lock_guard lock(sampling_mutex_); + changed = capture_state_ != state; + capture_state_ = state; + } + if (changed) capture_state_changed(state); } @@ -462,6 +486,11 @@ void Session::feed_in_meta(shared_ptr meta) for (auto entry : meta->config()) { switch (entry.first->id()) { case SR_CONF_SAMPLERATE: + // We can't rely on the header to always contain the sample rate, + // so in case it's supplied via a meta packet, we use it. + if (!cur_samplerate_) + cur_samplerate_ = g_variant_get_uint64(entry.second.gobj()); + /// @todo handle samplerate changes break; default: @@ -473,6 +502,27 @@ void Session::feed_in_meta(shared_ptr meta) signals_changed(); } +void Session::feed_in_trigger() +{ + // The channel containing most samples should be most accurate + uint64_t sample_count = 0; + + for (const shared_ptr d : get_data()) { + assert(d); + uint64_t temp_count = 0; + + const vector< shared_ptr > segments = + d->segments(); + for (const shared_ptr &s : segments) + temp_count += s->get_sample_count(); + + if (temp_count > sample_count) + sample_count = temp_count; + } + + trigger_event(sample_count / get_samplerate()); +} + void Session::feed_in_frame_begin() { if (cur_logic_segment_ || !cur_analog_segments_.empty()) @@ -529,6 +579,10 @@ void Session::feed_in_analog(shared_ptr analog) const float *data = static_cast(analog->data_pointer()); bool sweep_beginning = false; + if (signals_.empty()) { + update_signals(); + } + for (auto channel : channels) { shared_ptr segment; @@ -597,6 +651,10 @@ void Session::data_feed_in(shared_ptr device, feed_in_meta(dynamic_pointer_cast(packet->payload())); break; + case SR_DF_TRIGGER: + feed_in_trigger(); + break; + case SR_DF_FRAME_BEGIN: feed_in_frame_begin(); break;