21 #include <libsigrokdecode/libsigrokdecode.h>
36 using std::lock_guard;
38 using boost::optional;
39 using std::unique_lock;
47 using std::shared_ptr;
63 const srd_decoder *
const dec) :
68 frame_complete_(false),
71 connect(&
session_, SIGNAL(frame_began()),
73 connect(&
session_, SIGNAL(data_received()),
75 connect(&
session_, SIGNAL(frame_ended()),
78 stack_.push_back(shared_ptr<decode::Decoder>(
91 const std::list< std::shared_ptr<decode::Decoder> >&
100 stack_.push_back(decoder);
106 assert(index < (
int)
stack_.size());
109 auto iter =
stack_.begin();
110 for (
int i = 0; i < index; i++, iter++)
111 assert(iter !=
stack_.end());
139 for (
const shared_ptr<decode::Decoder> &dec :
stack_) {
144 const srd_decoder *
const decc = dec->decoder();
145 assert(dec->decoder());
148 if (!decc->annotation_rows)
149 rows.push_back(
Row(decc));
152 for (
const GSList *l = decc->annotation_rows; l; l = l->next) {
153 const srd_decoder_annotation_row *
const ann_row =
154 (srd_decoder_annotation_row *)l->data;
156 rows.push_back(
Row(decc, ann_row));
164 std::vector<pv::data::decode::Annotation> &dest,
165 const Row &row, uint64_t start_sample,
166 uint64_t end_sample)
const
170 const auto iter =
rows_.find(row);
171 if (iter !=
rows_.end())
172 (*iter).second.get_annotation_subset(dest,
173 start_sample, end_sample);
194 shared_ptr<pv::view::LogicSignal> logic_signal;
195 shared_ptr<pv::data::Logic> data;
206 for (
const shared_ptr<decode::Decoder> &dec :
stack_)
207 if (!dec->have_required_channels()) {
209 "have not been specified");
214 for (
const shared_ptr<decode::Decoder> &dec : stack_) {
216 const srd_decoder *
const decc = dec->decoder();
217 assert(dec->decoder());
220 if (!decc->annotation_rows)
224 for (
const GSList *l = decc->annotation_rows; l; l = l->next) {
225 const srd_decoder_annotation_row *
const ann_row =
226 (srd_decoder_annotation_row *)l->data;
229 const Row row(decc, ann_row);
235 for (
const GSList *ll = ann_row->ann_classes;
238 GPOINTER_TO_INT(ll->data))] = row;
245 for (
const shared_ptr<decode::Decoder> &dec : stack_)
246 if (dec && !dec->channels().empty() &&
247 ((logic_signal = (*dec->channels().begin()).second)) &&
248 ((data = logic_signal->logic_data())))
255 const deque< shared_ptr<pv::data::LogicSegment> > &segments =
256 data->logic_segments();
257 if (segments.empty())
275 for (
auto i =
rows_.cbegin(); i !=
rows_.end(); i++)
276 max_sample_count = max(max_sample_count,
277 (*i).second.get_max_sample());
294 const int64_t sample_count,
const unsigned int unit_size,
295 srd_session *
const session)
299 const unsigned int chunk_sample_count =
302 for (int64_t i = 0; !
interrupt_ && i < sample_count;
303 i += chunk_sample_count) {
306 const int64_t chunk_end = min(
307 i + chunk_sample_count, sample_count);
308 segment_->get_samples(chunk, i, chunk_end);
310 if (srd_session_send(session, i, chunk_end, chunk,
311 (chunk_end - i) * unit_size, unit_size) != SRD_OK) {
330 optional<int64_t> sample_count;
331 srd_session *session;
332 srd_decoder_inst *prev_di =
nullptr;
337 srd_session_new(&session);
341 const unsigned int unit_size =
segment_->unit_size();
343 for (
const shared_ptr<decode::Decoder> &dec :
stack_) {
344 srd_decoder_inst *
const di = dec->create_decoder_inst(session);
348 srd_session_destroy(session);
353 srd_inst_stack (session, prev_di, di);
365 srd_session_metadata_set(session, SRD_CONF_SAMPLERATE,
368 srd_pd_output_callback_add(session, SRD_OUTPUT_ANN,
371 srd_session_start(session);
378 srd_session_destroy(session);
395 assert(pdata->pdo->di);
396 const srd_decoder *
const decc = pdata->pdo->di->decoder;
399 auto row_iter = d->
rows_.end();
404 row_iter = d->
rows_.find((*r).second);
407 row_iter = d->
rows_.find(
Row(decc));
410 assert(row_iter != d->
rows_.end());
411 if (row_iter == d->
rows_.end()) {
412 qDebug() <<
"Unexpected annotation: decoder = " << decc <<
413 ", format = " << a.
format();
419 (*row_iter).second.push_annotation(a);
static void annotation_callback(srd_proto_data *pdata, void *decoder)
void decode_data(const int64_t sample_count, const unsigned int unit_size, srd_session *const session)
void push(std::shared_ptr< decode::Decoder > decoder)
static std::mutex global_decode_mutex_
double samplerate() const
pv::util::Timestamp start_time_
void get_annotation_subset(std::vector< pv::data::decode::Annotation > &dest, const decode::Row &row, uint64_t start_sample, uint64_t end_sample) const
std::thread decode_thread_
static const double DecodeThreshold
DecoderStack(pv::Session &session_, const srd_decoder *const decoder)
uint64_t max_sample_count() const
std::shared_ptr< pv::data::LogicSegment > segment_
static const double DecodeMargin
boost::optional< int64_t > wait_for_data() const
const std::list< std::shared_ptr< decode::Decoder > > & stack() const
static const int64_t DecodeChunkLength
std::map< const decode::Row, decode::RowData > rows_
std::atomic< bool > interrupt_
std::list< std::shared_ptr< decode::Decoder > > stack_
int64_t samples_decoded() const
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 24 >, boost::multiprecision::et_off > Timestamp
Timestamp type providing yoctosecond resolution.
static const unsigned int DecodeNotifyPeriod
std::map< std::pair< const srd_decoder *, int >, decode::Row > class_rows_
std::vector< decode::Row > get_visible_rows() const
std::condition_variable input_cond_
const pv::util::Timestamp & start_time() const