2 * This file is part of the PulseView project.
4 * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
5 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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/>.
21 #ifndef PULSEVIEW_PV_DATA_SEGMENT_HPP
22 #define PULSEVIEW_PV_DATA_SEGMENT_HPP
24 #include "pv/util.hpp"
32 using std::recursive_mutex;
35 namespace SegmentTest {
36 struct SmallSize8Single;
37 struct MediumSize8Single;
38 struct MaxSize8Single;
39 struct MediumSize24Single;
40 struct MediumSize32Single;
41 struct MaxSize32Single;
42 struct MediumSize32Multi;
43 struct MaxSize32Multi;
44 struct MaxSize32MultiAtOnce;
45 struct MaxSize32MultiIterated;
46 } // namespace SegmentTest
52 uint64_t sample_index, chunk_num, chunk_offs;
55 } SegmentRawDataIterator;
57 class Segment : public QObject
62 static const uint64_t MaxChunkSize;
65 Segment(uint32_t segment_id, uint64_t samplerate, unsigned int unit_size);
69 uint64_t get_sample_count() const;
71 const pv::util::Timestamp& start_time() const;
73 double samplerate() const;
74 void set_samplerate(double samplerate);
76 unsigned int unit_size() const;
78 uint32_t segment_id() const;
81 bool is_complete() const;
83 void free_unused_memory();
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;
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);
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_;
102 uint64_t chunk_size_;
103 unsigned int unit_size_;
105 bool mem_optimization_requested_;
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;
123 #endif // PULSEVIEW_PV_DATA_SEGMENT_HPP