+ // Return value is valid if we're not aborting the decode,
+ return boost::make_optional(!interrupt_ &&
+ // and there's more work to do...
+ (samples_decoded_ < sample_count_ || !frame_complete_) &&
+ // and if the end of the data hasn't been reached yet
+ (!((samples_decoded_ >= sample_count_) && (session_.get_capture_state() == Session::Stopped))),
+ sample_count_);
+}
+
+void DecoderStack::decode_data(
+ const int64_t abs_start_samplenum, const int64_t sample_count, const unsigned int unit_size,
+ srd_session *const session)
+{
+ const unsigned int chunk_sample_count =
+ DecodeChunkLength / segment_->unit_size();
+
+ for (int64_t i = abs_start_samplenum; !interrupt_ && i < sample_count;
+ i += chunk_sample_count) {
+
+ const int64_t chunk_end = min(
+ i + chunk_sample_count, sample_count);
+ const uint8_t* chunk = segment_->get_samples(i, chunk_end);
+
+ if (srd_session_send(session, i, chunk_end, chunk,
+ (chunk_end - i) * unit_size, unit_size) != SRD_OK) {
+ error_message_ = tr("Decoder reported an error");
+ delete[] chunk;
+ break;
+ }
+ delete[] chunk;
+
+ {
+ lock_guard<mutex> lock(output_mutex_);
+ samples_decoded_ = chunk_end;
+ }
+
+ if (i % DecodeNotifyPeriod == 0)
+ new_decode_data();
+ }
+
+ new_decode_data();
+}
+
+void DecoderStack::decode_proc()
+{
+ optional<int64_t> sample_count;
+ srd_session *session;
+ srd_decoder_inst *prev_di = nullptr;
+
+ assert(segment_);
+
+ // Prevent any other decode threads from accessing libsigrokdecode
+ lock_guard<mutex> srd_lock(global_srd_mutex_);