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