- logic_mux_data_invalid_ = false;
-
- // Wait for more input
- unique_lock<mutex> logic_mux_lock(logic_mux_mutex_);
- logic_mux_cond_.wait(logic_mux_lock);
- }
- } while (!logic_mux_interrupt_);
-}
-
-void DecodeSignal::query_input_metadata()
-{
- // Update the samplerate and start time because we cannot start
- // the libsrd session without the current samplerate
-
- // TODO Currently we assume all channels have the same sample rate
- // and start time
- bool samplerate_valid = false;
- data::DecodeChannel *any_channel;
- shared_ptr<Logic> logic_data;
-
- do {
- any_channel = &(*find_if(channels_.begin(), channels_.end(),
- [](data::DecodeChannel ch) { return ch.assigned_signal; }));
-
- logic_data = any_channel->assigned_signal->logic_data();
-
- if (!logic_data) {
- // Wait until input data is available or an interrupt was requested
- unique_lock<mutex> input_wait_lock(input_mutex_);
- decode_input_cond_.wait(input_wait_lock);
- }
- } while (!logic_data && !decode_interrupt_);
-
- if (decode_interrupt_)
- return;
-
- do {
- if (!logic_data->logic_segments().empty()) {
- shared_ptr<LogicSegment> first_segment =
- any_channel->assigned_signal->logic_data()->logic_segments().front();
- start_time_ = first_segment->start_time();
- samplerate_ = first_segment->samplerate();
- if (samplerate_ > 0)
- samplerate_valid = true;
+ // TODO Optimize this by caching the input segment count and only
+ // querying it when the cached value was reached
+ if (segment_id < get_input_segment_count() - 1) {
+ // Process next segment
+ segment_id++;
+
+ output_segment =
+ make_shared<LogicSegment>(*logic_mux_data_, segment_id,
+ logic_mux_unit_size_, 0);
+ logic_mux_data_->push_segment(output_segment);
+
+ output_segment->set_samplerate(get_input_samplerate(segment_id));
+
+ } else {
+ // All segments have been processed
+ logic_mux_data_invalid_ = false;
+
+ // Wait for more input
+ unique_lock<mutex> logic_mux_lock(logic_mux_mutex_);
+ logic_mux_cond_.wait(logic_mux_lock);
+ }