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, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef PULSEVIEW_PV_DATA_DECODERSTACK_HPP
22 #define PULSEVIEW_PV_DATA_DECODERSTACK_HPP
24 #include "signaldata.hpp"
27 #include <condition_variable>
33 #include <boost/optional.hpp>
38 #include <pv/data/decode/row.hpp>
39 #include <pv/data/decode/rowdata.hpp>
40 #include <pv/util.hpp>
43 struct srd_decoder_annotation_row;
45 struct srd_proto_data;
48 namespace DecoderStackTest {
49 struct TwoDecoderStack;
71 class DecoderStack : public QObject
76 static const double DecodeMargin;
77 static const double DecodeThreshold;
78 static const int64_t DecodeChunkLength;
79 static const unsigned int DecodeNotifyPeriod;
82 DecoderStack(pv::Session &session, const srd_decoder *const dec);
84 virtual ~DecoderStack();
86 const std::list< std::shared_ptr<decode::Decoder> >& stack() const;
87 void push(std::shared_ptr<decode::Decoder> decoder);
88 void remove(int index);
90 double samplerate() const;
92 const pv::util::Timestamp& start_time() const;
94 int64_t samples_decoded() const;
96 std::vector<decode::Row> get_visible_rows() const;
99 * Extracts sorted annotations between two period into a vector.
101 void get_annotation_subset(
102 std::vector<pv::data::decode::Annotation> &dest,
103 const decode::Row &row, uint64_t start_sample,
104 uint64_t end_sample) const;
106 QString error_message();
110 uint64_t max_sample_count() const;
115 boost::optional<int64_t> wait_for_data() const;
117 void decode_data(const int64_t sample_count,
118 const unsigned int unit_size, srd_session *const session);
122 static void annotation_callback(srd_proto_data *pdata,
128 void on_data_received();
130 void on_frame_ended();
133 void new_decode_data();
136 pv::Session &session_;
138 pv::util::Timestamp start_time_;
142 * This mutex prevents more than one thread from accessing
143 * libsigrokdecode concurrently.
144 * @todo A proper solution should be implemented to allow multiple
145 * decode operations in parallel.
147 static std::mutex global_srd_mutex_;
149 std::list< std::shared_ptr<decode::Decoder> > stack_;
151 std::shared_ptr<pv::data::LogicSegment> segment_;
153 mutable std::mutex input_mutex_;
154 mutable std::condition_variable input_cond_;
155 int64_t sample_count_;
156 bool frame_complete_;
158 mutable std::mutex output_mutex_;
159 int64_t samples_decoded_;
161 std::map<const decode::Row, decode::RowData> rows_;
163 std::map<std::pair<const srd_decoder*, int>, decode::Row> class_rows_;
165 QString error_message_;
167 std::thread decode_thread_;
168 std::atomic<bool> interrupt_;
170 friend struct DecoderStackTest::TwoDecoderStack;
176 #endif // PULSEVIEW_PV_DATA_DECODERSTACK_HPP