2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef PULSEVIEW_PV_DATA_DECODERSTACK_HPP
21 #define PULSEVIEW_PV_DATA_DECODERSTACK_HPP
23 #include "signaldata.hpp"
26 #include <condition_variable>
32 #include <boost/optional.hpp>
37 #include <pv/data/decode/row.hpp>
38 #include <pv/data/decode/rowdata.hpp>
39 #include <pv/util.hpp>
42 using std::condition_variable;
47 using std::shared_ptr;
51 struct srd_decoder_annotation_row;
53 struct srd_proto_data;
56 namespace DecoderStackTest {
57 struct TwoDecoderStack;
79 class DecoderStack : public QObject
84 static const double DecodeMargin;
85 static const double DecodeThreshold;
86 static const int64_t DecodeChunkLength;
87 static const unsigned int DecodeNotifyPeriod;
90 DecoderStack(pv::Session &session, const srd_decoder *const dec);
92 virtual ~DecoderStack();
94 const list< shared_ptr<decode::Decoder> >& stack() const;
95 void push(shared_ptr<decode::Decoder> decoder);
96 void remove(int index);
98 double samplerate() const;
100 const pv::util::Timestamp& start_time() const;
102 int64_t samples_decoded() const;
104 vector<decode::Row> get_visible_rows() const;
107 * Extracts sorted annotations between two period into a vector.
109 void get_annotation_subset(
110 vector<pv::data::decode::Annotation> &dest,
111 const decode::Row &row, uint64_t start_sample,
112 uint64_t end_sample) const;
114 QString error_message();
118 uint64_t max_sample_count() const;
123 boost::optional<int64_t> wait_for_data() const;
125 void decode_data(const int64_t abs_start_samplenum, const int64_t sample_count,
126 const unsigned int unit_size, srd_session *const session);
130 static void annotation_callback(srd_proto_data *pdata,
136 void on_data_received();
138 void on_frame_ended();
141 void new_decode_data();
144 pv::Session &session_;
146 pv::util::Timestamp start_time_;
150 * This mutex prevents more than one thread from accessing
151 * libsigrokdecode concurrently.
152 * @todo A proper solution should be implemented to allow multiple
153 * decode operations in parallel.
155 static mutex global_srd_mutex_;
157 list< shared_ptr<decode::Decoder> > stack_;
159 shared_ptr<pv::data::LogicSegment> segment_;
161 mutable mutex input_mutex_;
162 mutable condition_variable input_cond_;
163 int64_t sample_count_;
164 bool frame_complete_;
166 mutable mutex output_mutex_;
167 int64_t samples_decoded_;
169 map<const decode::Row, decode::RowData> rows_;
171 map<pair<const srd_decoder*, int>, decode::Row> class_rows_;
173 QString error_message_;
175 std::thread decode_thread_;
176 atomic<bool> interrupt_;
178 friend struct DecoderStackTest::TwoDecoderStack;
184 #endif // PULSEVIEW_PV_DATA_DECODERSTACK_HPP