]>
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 | |
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 | |
19 | */ | |
20 | ||
6e89374a JH |
21 | #ifndef PULSEVIEW_PV_DATA_DECODERSTACK_H |
22 | #define PULSEVIEW_PV_DATA_DECODERSTACK_H | |
119aff65 JH |
23 | |
24 | #include "signaldata.h" | |
25 | ||
7491a29f | 26 | #include <list> |
708c5523 | 27 | |
f70d8673 | 28 | #include <boost/optional.hpp> |
708c5523 | 29 | #include <boost/shared_ptr.hpp> |
640d69ce | 30 | #include <boost/thread.hpp> |
708c5523 | 31 | |
e0fc5810 | 32 | #include <QObject> |
b6b267bb | 33 | #include <QString> |
e0fc5810 | 34 | |
f9101a91 JH |
35 | #include <pv/data/decode/row.h> |
36 | #include <pv/data/decode/rowdata.h> | |
37 | ||
119aff65 | 38 | struct srd_decoder; |
f9101a91 | 39 | struct srd_decoder_annotation_row; |
708c5523 | 40 | struct srd_probe; |
b213ef09 | 41 | struct srd_proto_data; |
f67d9e9b | 42 | struct srd_session; |
b6b267bb | 43 | |
6e89374a JH |
44 | namespace DecoderStackTest { |
45 | class TwoDecoderStack; | |
b6b267bb | 46 | } |
119aff65 JH |
47 | |
48 | namespace pv { | |
708c5523 | 49 | |
bdc5c3b0 JH |
50 | class SigSession; |
51 | ||
708c5523 | 52 | namespace view { |
3045c869 | 53 | class LogicSignal; |
708c5523 JH |
54 | } |
55 | ||
119aff65 JH |
56 | namespace data { |
57 | ||
f67d9e9b JH |
58 | class LogicSnapshot; |
59 | ||
7491a29f | 60 | namespace decode { |
06e810f2 | 61 | class Annotation; |
7491a29f JH |
62 | class Decoder; |
63 | } | |
64 | ||
640d69ce JH |
65 | class Logic; |
66 | ||
6e89374a | 67 | class DecoderStack : public QObject, public SignalData |
119aff65 | 68 | { |
e0fc5810 JH |
69 | Q_OBJECT |
70 | ||
71 | private: | |
72 | static const double DecodeMargin; | |
73 | static const double DecodeThreshold; | |
74 | static const int64_t DecodeChunkLength; | |
4c581c79 | 75 | static const unsigned int DecodeNotifyPeriod; |
e0fc5810 | 76 | |
119aff65 | 77 | public: |
bdc5c3b0 JH |
78 | DecoderStack(pv::SigSession &_session, |
79 | const srd_decoder *const decoder); | |
119aff65 | 80 | |
6e89374a | 81 | virtual ~DecoderStack(); |
640d69ce | 82 | |
7491a29f JH |
83 | const std::list< boost::shared_ptr<decode::Decoder> >& stack() const; |
84 | void push(boost::shared_ptr<decode::Decoder> decoder); | |
613d097c | 85 | void remove(int index); |
119aff65 | 86 | |
5dfeb70f JH |
87 | int64_t samples_decoded() const; |
88 | ||
dd048a7e | 89 | std::vector<decode::Row> get_visible_rows() const; |
f9101a91 | 90 | |
92421299 JH |
91 | /** |
92 | * Extracts sorted annotations between two period into a vector. | |
93 | */ | |
94 | void get_annotation_subset( | |
95 | std::vector<pv::data::decode::Annotation> &dest, | |
f9101a91 JH |
96 | const decode::Row &row, uint64_t start_sample, |
97 | uint64_t end_sample) const; | |
640d69ce | 98 | |
b6b267bb JH |
99 | QString error_message(); |
100 | ||
caabb84c | 101 | void clear(); |
119aff65 | 102 | |
a007f5ad JH |
103 | uint64_t get_max_sample_count() const; |
104 | ||
e0fc5810 JH |
105 | void begin_decode(); |
106 | ||
7491a29f | 107 | private: |
f70d8673 JH |
108 | boost::optional<int64_t> wait_for_data() const; |
109 | ||
110 | void decode_data(const int64_t sample_count, | |
111 | const unsigned int unit_size, srd_session *const session); | |
f67d9e9b | 112 | |
c1b2865e | 113 | void decode_proc(); |
640d69ce | 114 | |
e0fc5810 JH |
115 | static void annotation_callback(srd_proto_data *pdata, |
116 | void *decoder); | |
117 | ||
82f50b10 JH |
118 | private slots: |
119 | void on_new_frame(); | |
120 | ||
f70d8673 JH |
121 | void on_data_received(); |
122 | ||
123 | void on_frame_ended(); | |
124 | ||
9cef9567 JH |
125 | signals: |
126 | void new_decode_data(); | |
127 | ||
119aff65 | 128 | private: |
bdc5c3b0 | 129 | pv::SigSession &_session; |
fe89c961 JH |
130 | |
131 | /** | |
132 | * This mutex prevents more than one decode operation occuring | |
133 | * concurrently. | |
134 | * @todo A proper solution should be implemented to allow multiple | |
135 | * decode operations. | |
136 | */ | |
137 | static boost::mutex _global_decode_mutex; | |
138 | ||
7491a29f | 139 | std::list< boost::shared_ptr<decode::Decoder> > _stack; |
e332f6d3 | 140 | |
f70d8673 JH |
141 | boost::shared_ptr<pv::data::LogicSnapshot> _snapshot; |
142 | ||
143 | mutable boost::mutex _input_mutex; | |
144 | mutable boost::condition_variable _input_cond; | |
145 | int64_t _sample_count; | |
146 | bool _frame_complete; | |
147 | ||
28b9cc08 | 148 | mutable boost::mutex _output_mutex; |
5dfeb70f | 149 | int64_t _samples_decoded; |
92421299 | 150 | |
f9101a91 JH |
151 | std::map<const decode::Row, decode::RowData> _rows; |
152 | ||
153 | std::map<std::pair<const srd_decoder*, int>, decode::Row> _class_rows; | |
92421299 | 154 | |
b6b267bb | 155 | QString _error_message; |
e0fc5810 | 156 | |
640d69ce | 157 | boost::thread _decode_thread; |
b6b267bb | 158 | |
6e89374a | 159 | friend class DecoderStackTest::TwoDecoderStack; |
119aff65 JH |
160 | }; |
161 | ||
162 | } // namespace data | |
163 | } // namespace pv | |
164 | ||
6e89374a | 165 | #endif // PULSEVIEW_PV_DATA_DECODERSTACK_H |