]> sigrok.org Git - pulseview.git/blame_incremental - pv/data/segment.hpp
DecodeSignal: Unpause reliably
[pulseview.git] / pv / data / segment.hpp
... / ...
CommitLineData
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
5 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef PULSEVIEW_PV_DATA_SEGMENT_HPP
22#define PULSEVIEW_PV_DATA_SEGMENT_HPP
23
24#include "pv/util.hpp"
25
26#include <mutex>
27#include <thread>
28#include <vector>
29
30#include <QObject>
31
32using std::recursive_mutex;
33using std::vector;
34
35namespace SegmentTest {
36struct SmallSize8Single;
37struct MediumSize8Single;
38struct MaxSize8Single;
39struct MediumSize24Single;
40struct MediumSize32Single;
41struct MaxSize32Single;
42struct MediumSize32Multi;
43struct MaxSize32Multi;
44struct MaxSize32MultiAtOnce;
45struct MaxSize32MultiIterated;
46} // namespace SegmentTest
47
48namespace pv {
49namespace data {
50
51typedef struct {
52 uint64_t sample_index, chunk_num, chunk_offs;
53 uint8_t* chunk;
54 uint8_t* value;
55} SegmentRawDataIterator;
56
57class Segment : public QObject
58{
59 Q_OBJECT
60
61private:
62 static const uint64_t MaxChunkSize;
63
64public:
65 Segment(uint32_t segment_id, uint64_t samplerate, unsigned int unit_size);
66
67 virtual ~Segment();
68
69 uint64_t get_sample_count() const;
70
71 const pv::util::Timestamp& start_time() const;
72
73 double samplerate() const;
74 void set_samplerate(double samplerate);
75
76 unsigned int unit_size() const;
77
78 uint32_t segment_id() const;
79
80 void set_complete();
81 bool is_complete() const;
82
83 void free_unused_memory();
84
85protected:
86 void append_single_sample(void *data);
87 void append_samples(void *data, uint64_t samples);
88 void get_raw_samples(uint64_t start, uint64_t count, uint8_t *dest) const;
89
90 SegmentRawDataIterator* begin_raw_sample_iteration(uint64_t start);
91 void continue_raw_sample_iteration(SegmentRawDataIterator* it, uint64_t increase);
92 void end_raw_sample_iteration(SegmentRawDataIterator* it);
93
94 uint32_t segment_id_;
95 mutable recursive_mutex mutex_;
96 vector<uint8_t*> data_chunks_;
97 uint8_t* current_chunk_;
98 uint64_t used_samples_, unused_samples_;
99 uint64_t sample_count_;
100 pv::util::Timestamp start_time_;
101 double samplerate_;
102 uint64_t chunk_size_;
103 unsigned int unit_size_;
104 int iterator_count_;
105 bool mem_optimization_requested_;
106 bool is_complete_;
107
108 friend struct SegmentTest::SmallSize8Single;
109 friend struct SegmentTest::MediumSize8Single;
110 friend struct SegmentTest::MaxSize8Single;
111 friend struct SegmentTest::MediumSize24Single;
112 friend struct SegmentTest::MediumSize32Single;
113 friend struct SegmentTest::MaxSize32Single;
114 friend struct SegmentTest::MediumSize32Multi;
115 friend struct SegmentTest::MaxSize32Multi;
116 friend struct SegmentTest::MaxSize32MultiAtOnce;
117 friend struct SegmentTest::MaxSize32MultiIterated;
118};
119
120} // namespace data
121} // namespace pv
122
123#endif // PULSEVIEW_PV_DATA_SEGMENT_HPP