X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=dd06cfed360a2bd6a45e65577d2441e30404639e;hp=e258f6db8e189fb410bcd696d123f31fb295f40e;hb=4e86ec7042631d4b54876cba89c01a73abaf7213;hpb=419ec4e11ee29e27566d1c0c17741fcad85dbdf6 diff --git a/pv/session.cpp b/pv/session.cpp index e258f6db..dd06cfed 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -622,8 +622,6 @@ void Session::register_view(shared_ptr view) switch (signalbase->type()) { case data::SignalBase::AnalogChannel: case data::SignalBase::LogicChannel: - case data::SignalBase::A2LChannel: - break; case data::SignalBase::DecodeChannel: #ifdef ENABLE_DECODE trace_view->add_decode_signal( @@ -679,6 +677,18 @@ double Session::get_samplerate() const return samplerate; } +int Session::get_segment_count() const +{ + int min_val = INT_MAX; + + // Find the lowest common number of segments + for (shared_ptr data : all_signal_data_) + if (data->get_segment_count() < min_val) + min_val = data->get_segment_count(); + + return (min_val != INT_MAX) ? min_val : 0; +} + const unordered_set< shared_ptr > Session::signalbases() const { return signalbases_; @@ -890,6 +900,13 @@ void Session::sample_thread_proc(function error_handler) out_of_memory_ = false; + { + lock_guard lock(data_mutex_); + cur_logic_segment_.reset(); + cur_analog_segments_.clear(); + } + highest_segment_id_ = -1; + try { device_->start(); } catch (Error e) { @@ -941,9 +958,39 @@ void Session::free_unused_memory() } } +void Session::signal_new_segment() +{ + int new_segment_id = 1; + + if ((cur_logic_segment_ != nullptr) || !cur_analog_segments_.empty()) { + + // Determine new frame/segment number, assuming that all + // signals have the same number of frames/segments + if (cur_logic_segment_) { + new_segment_id = logic_data_->get_segment_count(); + } else { + shared_ptr any_channel = + (*cur_analog_segments_.begin()).first; + + shared_ptr base = signalbase_from_channel(any_channel); + assert(base); + + shared_ptr data(base->analog_data()); + assert(data); + + new_segment_id = data->get_segment_count(); + } + } + + if (new_segment_id > highest_segment_id_) { + highest_segment_id_ = new_segment_id; + new_segment(highest_segment_id_); + } +} + void Session::feed_in_header() { - cur_samplerate_ = device_->read_config(ConfigKey::SAMPLERATE); + // Nothing to do here for now } void Session::feed_in_meta(shared_ptr meta) @@ -992,12 +1039,26 @@ void Session::feed_in_trigger() void Session::feed_in_frame_begin() { - if (cur_logic_segment_ || !cur_analog_segments_.empty()) - frame_began(); + frame_began_ = true; +} + +void Session::feed_in_frame_end() +{ + { + lock_guard lock(data_mutex_); + cur_logic_segment_.reset(); + cur_analog_segments_.clear(); + } + + if (frame_began_) + frame_began_ = false; } void Session::feed_in_logic(shared_ptr logic) { + if (!cur_samplerate_) + cur_samplerate_ = device_->read_config(ConfigKey::SAMPLERATE); + lock_guard lock(data_mutex_); if (!logic_data_) { @@ -1016,11 +1077,7 @@ void Session::feed_in_logic(shared_ptr logic) *logic_data_, logic->unit_size(), cur_samplerate_); logic_data_->push_segment(cur_logic_segment_); - // @todo Putting this here means that only listeners querying - // for logic will be notified. Currently the only user of - // frame_began is DecoderStack, but in future we need to signal - // this after both analog and logic sweeps have begun. - frame_began(); + signal_new_segment(); } cur_logic_segment_->append_payload(logic); @@ -1030,6 +1087,9 @@ void Session::feed_in_logic(shared_ptr logic) void Session::feed_in_analog(shared_ptr analog) { + if (!cur_samplerate_) + cur_samplerate_ = device_->read_config(ConfigKey::SAMPLERATE); + lock_guard lock(data_mutex_); const vector> channels = analog->channels(); @@ -1072,6 +1132,8 @@ void Session::feed_in_analog(shared_ptr analog) // Push the segment into the analog data. data->push_segment(segment); + + signal_new_segment(); } assert(segment); @@ -1092,8 +1154,6 @@ void Session::feed_in_analog(shared_ptr analog) void Session::data_feed_in(shared_ptr device, shared_ptr packet) { - static bool frame_began = false; - (void)device; assert(device); @@ -1113,11 +1173,6 @@ void Session::data_feed_in(shared_ptr device, feed_in_trigger(); break; - case SR_DF_FRAME_BEGIN: - feed_in_frame_begin(); - frame_began = true; - break; - case SR_DF_LOGIC: try { feed_in_logic(dynamic_pointer_cast(packet->payload())); @@ -1136,20 +1191,25 @@ void Session::data_feed_in(shared_ptr device, } break; + case SR_DF_FRAME_BEGIN: + feed_in_frame_begin(); + break; + case SR_DF_FRAME_END: + feed_in_frame_end(); + break; + case SR_DF_END: - { + // Strictly speaking, this is performed when a frame end marker was + // received, so there's no point doing this again. However, not all + // devices use frames, and for those devices, we need to do it here. { lock_guard lock(data_mutex_); cur_logic_segment_.reset(); cur_analog_segments_.clear(); } - if (frame_began) { - frame_began = false; - frame_ended(); - } break; - } + default: break; }