]> sigrok.org Git - pulseview.git/blame - pv/data/segment.hpp
AnalogSignal: Make threshold neutral area darker
[pulseview.git] / pv / data / segment.hpp
CommitLineData
28a4c9c5 1/*
b3f22de0 2 * This file is part of the PulseView project.
28a4c9c5 3 *
26a883ed 4 * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
28a4c9c5
JH
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
efdec55a 18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28a4c9c5
JH
19 */
20
a38268f0
SA
21#ifndef PULSEVIEW_PV_DATA_SEGMENT_HPP
22#define PULSEVIEW_PV_DATA_SEGMENT_HPP
640d091b 23
60d9b99a
JS
24#include "pv/util.hpp"
25
3b68d03d 26#include <mutex>
aca9aa83 27#include <thread>
c82c7e4e 28#include <vector>
7d29656f 29
6f925ba9
UH
30using std::recursive_mutex;
31using std::vector;
32
26a883ed
SA
33namespace SegmentTest {
34struct SmallSize8Single;
35struct MediumSize8Single;
36struct MaxSize8Single;
37struct MediumSize24Single;
38struct MediumSize32Single;
39struct MaxSize32Single;
40struct MediumSize32Multi;
41struct MaxSize32Multi;
207ae8f6 42struct MaxSize32MultiAtOnce;
26a883ed 43struct MaxSize32MultiIterated;
870ea3db 44} // namespace SegmentTest
26a883ed 45
51e77110 46namespace pv {
1b1ec774 47namespace data {
51e77110 48
26a883ed
SA
49typedef struct {
50 uint64_t sample_index, chunk_num, chunk_offs;
51 uint8_t* chunk;
52 uint8_t* value;
53} SegmentRawDataIterator;
54
f3d66e52 55class Segment
28a4c9c5 56{
26a883ed 57private:
dd3f9a41 58 static const uint64_t MaxChunkSize;
26a883ed 59
28a4c9c5 60public:
f3d66e52 61 Segment(uint64_t samplerate, unsigned int unit_size);
f556bc6a 62
f3d66e52 63 virtual ~Segment();
28a4c9c5 64
e7c6e898 65 uint64_t get_sample_count() const;
28a4c9c5 66
60d9b99a 67 const pv::util::Timestamp& start_time() const;
7f4038d6 68
ff008de6
JH
69 double samplerate() const;
70 void set_samplerate(double samplerate);
71
5ad3b48b 72 unsigned int unit_size() const;
6fd14a32 73
5e6967cb
SA
74 void free_unused_memory();
75
28a4c9c5 76protected:
26a883ed
SA
77 void append_single_sample(void *data);
78 void append_samples(void *data, uint64_t samples);
b82243f7 79 void get_raw_samples(uint64_t start, uint64_t count, uint8_t *dest) const;
26a883ed 80
c70e3464
SA
81 SegmentRawDataIterator* begin_raw_sample_iteration(uint64_t start);
82 void continue_raw_sample_iteration(SegmentRawDataIterator* it, uint64_t increase);
83 void end_raw_sample_iteration(SegmentRawDataIterator* it);
f556bc6a 84
6f925ba9
UH
85 mutable recursive_mutex mutex_;
86 vector<uint8_t*> data_chunks_;
26a883ed
SA
87 uint8_t* current_chunk_;
88 uint64_t used_samples_, unused_samples_;
8dbbc7f0 89 uint64_t sample_count_;
60d9b99a 90 pv::util::Timestamp start_time_;
ff008de6 91 double samplerate_;
26a883ed 92 uint64_t chunk_size_;
8dbbc7f0 93 unsigned int unit_size_;
c70e3464
SA
94 int iterator_count_;
95 bool mem_optimization_requested_;
26a883ed
SA
96
97 friend struct SegmentTest::SmallSize8Single;
98 friend struct SegmentTest::MediumSize8Single;
99 friend struct SegmentTest::MaxSize8Single;
100 friend struct SegmentTest::MediumSize24Single;
101 friend struct SegmentTest::MediumSize32Single;
102 friend struct SegmentTest::MaxSize32Single;
103 friend struct SegmentTest::MediumSize32Multi;
104 friend struct SegmentTest::MaxSize32Multi;
207ae8f6 105 friend struct SegmentTest::MaxSize32MultiAtOnce;
26a883ed 106 friend struct SegmentTest::MaxSize32MultiIterated;
28a4c9c5 107};
51e77110 108
1b1ec774 109} // namespace data
51e77110 110} // namespace pv
640d091b 111
a38268f0 112#endif // PULSEVIEW_PV_DATA_SEGMENT_HPP