]>
Commit | Line | Data |
---|---|---|
119aff65 JH |
1 | /* |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
efdec55a | 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
119aff65 JH |
18 | */ |
19 | ||
7a01bd36 JH |
20 | #ifndef PULSEVIEW_PV_DATA_DECODERSTACK_HPP |
21 | #define PULSEVIEW_PV_DATA_DECODERSTACK_HPP | |
119aff65 | 22 | |
2acdb232 | 23 | #include "signaldata.hpp" |
119aff65 | 24 | |
3b68d03d JH |
25 | #include <atomic> |
26 | #include <condition_variable> | |
7491a29f | 27 | #include <list> |
3b68d03d | 28 | #include <map> |
f9abf97e | 29 | #include <memory> |
3b68d03d | 30 | #include <thread> |
708c5523 | 31 | |
f70d8673 | 32 | #include <boost/optional.hpp> |
708c5523 | 33 | |
e0fc5810 | 34 | #include <QObject> |
b6b267bb | 35 | #include <QString> |
e0fc5810 | 36 | |
2acdb232 JH |
37 | #include <pv/data/decode/row.hpp> |
38 | #include <pv/data/decode/rowdata.hpp> | |
60d9b99a | 39 | #include <pv/util.hpp> |
f9101a91 | 40 | |
119aff65 | 41 | struct srd_decoder; |
f9101a91 | 42 | struct srd_decoder_annotation_row; |
8bd26d8b | 43 | struct srd_channel; |
b213ef09 | 44 | struct srd_proto_data; |
f67d9e9b | 45 | struct srd_session; |
b6b267bb | 46 | |
6e89374a | 47 | namespace DecoderStackTest { |
9e587572 | 48 | struct TwoDecoderStack; |
b6b267bb | 49 | } |
119aff65 JH |
50 | |
51 | namespace pv { | |
708c5523 | 52 | |
2b81ae46 | 53 | class Session; |
bdc5c3b0 | 54 | |
708c5523 | 55 | namespace view { |
3045c869 | 56 | class LogicSignal; |
708c5523 JH |
57 | } |
58 | ||
119aff65 JH |
59 | namespace data { |
60 | ||
f3d66e52 | 61 | class LogicSegment; |
f67d9e9b | 62 | |
7491a29f | 63 | namespace decode { |
06e810f2 | 64 | class Annotation; |
7491a29f JH |
65 | class Decoder; |
66 | } | |
67 | ||
640d69ce JH |
68 | class Logic; |
69 | ||
f054289f | 70 | class DecoderStack : public QObject |
119aff65 | 71 | { |
e0fc5810 JH |
72 | Q_OBJECT |
73 | ||
74 | private: | |
75 | static const double DecodeMargin; | |
76 | static const double DecodeThreshold; | |
77 | static const int64_t DecodeChunkLength; | |
4c581c79 | 78 | static const unsigned int DecodeNotifyPeriod; |
e0fc5810 | 79 | |
119aff65 | 80 | public: |
520362f8 | 81 | DecoderStack(pv::Session &session, const srd_decoder *const dec); |
119aff65 | 82 | |
6e89374a | 83 | virtual ~DecoderStack(); |
640d69ce | 84 | |
f9abf97e JH |
85 | const std::list< std::shared_ptr<decode::Decoder> >& stack() const; |
86 | void push(std::shared_ptr<decode::Decoder> decoder); | |
613d097c | 87 | void remove(int index); |
119aff65 | 88 | |
f054289f JH |
89 | double samplerate() const; |
90 | ||
60d9b99a | 91 | const pv::util::Timestamp& start_time() const; |
f054289f | 92 | |
5dfeb70f JH |
93 | int64_t samples_decoded() const; |
94 | ||
dd048a7e | 95 | std::vector<decode::Row> get_visible_rows() const; |
f9101a91 | 96 | |
92421299 JH |
97 | /** |
98 | * Extracts sorted annotations between two period into a vector. | |
99 | */ | |
100 | void get_annotation_subset( | |
101 | std::vector<pv::data::decode::Annotation> &dest, | |
f9101a91 JH |
102 | const decode::Row &row, uint64_t start_sample, |
103 | uint64_t end_sample) const; | |
640d69ce | 104 | |
b6b267bb JH |
105 | QString error_message(); |
106 | ||
caabb84c | 107 | void clear(); |
119aff65 | 108 | |
e45b13b5 | 109 | uint64_t max_sample_count() const; |
a007f5ad | 110 | |
e0fc5810 JH |
111 | void begin_decode(); |
112 | ||
7491a29f | 113 | private: |
f70d8673 JH |
114 | boost::optional<int64_t> wait_for_data() const; |
115 | ||
116 | void decode_data(const int64_t sample_count, | |
117 | const unsigned int unit_size, srd_session *const session); | |
f67d9e9b | 118 | |
c1b2865e | 119 | void decode_proc(); |
640d69ce | 120 | |
e0fc5810 JH |
121 | static void annotation_callback(srd_proto_data *pdata, |
122 | void *decoder); | |
123 | ||
e9213170 | 124 | private Q_SLOTS: |
82f50b10 JH |
125 | void on_new_frame(); |
126 | ||
f70d8673 JH |
127 | void on_data_received(); |
128 | ||
129 | void on_frame_ended(); | |
130 | ||
e9213170 | 131 | Q_SIGNALS: |
9cef9567 JH |
132 | void new_decode_data(); |
133 | ||
119aff65 | 134 | private: |
2b81ae46 | 135 | pv::Session &session_; |
fe89c961 | 136 | |
60d9b99a | 137 | pv::util::Timestamp start_time_; |
f054289f JH |
138 | double samplerate_; |
139 | ||
fe89c961 | 140 | /** |
a1a3656b SA |
141 | * This mutex prevents more than one thread from accessing |
142 | * libsigrokdecode concurrently. | |
fe89c961 | 143 | * @todo A proper solution should be implemented to allow multiple |
a1a3656b | 144 | * decode operations in parallel. |
fe89c961 | 145 | */ |
a1a3656b | 146 | static std::mutex global_srd_mutex_; |
fe89c961 | 147 | |
8dbbc7f0 | 148 | std::list< std::shared_ptr<decode::Decoder> > stack_; |
e332f6d3 | 149 | |
f3d66e52 | 150 | std::shared_ptr<pv::data::LogicSegment> segment_; |
f70d8673 | 151 | |
8dbbc7f0 JH |
152 | mutable std::mutex input_mutex_; |
153 | mutable std::condition_variable input_cond_; | |
154 | int64_t sample_count_; | |
155 | bool frame_complete_; | |
f70d8673 | 156 | |
8dbbc7f0 JH |
157 | mutable std::mutex output_mutex_; |
158 | int64_t samples_decoded_; | |
92421299 | 159 | |
8dbbc7f0 | 160 | std::map<const decode::Row, decode::RowData> rows_; |
f9101a91 | 161 | |
8dbbc7f0 | 162 | std::map<std::pair<const srd_decoder*, int>, decode::Row> class_rows_; |
92421299 | 163 | |
8dbbc7f0 | 164 | QString error_message_; |
e0fc5810 | 165 | |
8dbbc7f0 JH |
166 | std::thread decode_thread_; |
167 | std::atomic<bool> interrupt_; | |
b6b267bb | 168 | |
9e587572 | 169 | friend struct DecoderStackTest::TwoDecoderStack; |
119aff65 JH |
170 | }; |
171 | ||
172 | } // namespace data | |
173 | } // namespace pv | |
174 | ||
7a01bd36 | 175 | #endif // PULSEVIEW_PV_DATA_DECODERSTACK_HPP |