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"
30 namespace SegmentTest {
31 struct SmallSize8Single;
32 struct MediumSize8Single;
33 struct MaxSize8Single;
34 struct MediumSize24Single;
35 struct MediumSize32Single;
36 struct MaxSize32Single;
37 struct MediumSize32Multi;
38 struct MaxSize32Multi;
39 struct MaxSize32MultiIterated;
46 uint64_t sample_index, chunk_num, chunk_offs;
49 } SegmentRawDataIterator;
54 static const uint64_t MaxChunkSize = 10*1024*1024; /* 10MiB */
57 Segment(uint64_t samplerate, unsigned int unit_size);
61 uint64_t get_sample_count() const;
63 const pv::util::Timestamp& start_time() const;
65 double samplerate() const;
66 void set_samplerate(double samplerate);
68 unsigned int unit_size() const;
71 void append_single_sample(void *data);
72 void append_samples(void *data, uint64_t samples);
73 uint8_t* get_raw_samples(uint64_t start, uint64_t count) const;
75 SegmentRawDataIterator* begin_raw_sample_iteration(uint64_t start) const;
76 void continue_raw_sample_iteration(SegmentRawDataIterator* it, uint64_t increase) const;
77 void end_raw_sample_iteration(SegmentRawDataIterator* it) const;
79 mutable std::recursive_mutex mutex_;
80 std::vector<uint8_t*> data_chunks_;
81 uint8_t* current_chunk_;
82 uint64_t used_samples_, unused_samples_;
83 uint64_t sample_count_;
84 pv::util::Timestamp start_time_;
87 unsigned int unit_size_;
89 friend struct SegmentTest::SmallSize8Single;
90 friend struct SegmentTest::MediumSize8Single;
91 friend struct SegmentTest::MaxSize8Single;
92 friend struct SegmentTest::MediumSize24Single;
93 friend struct SegmentTest::MediumSize32Single;
94 friend struct SegmentTest::MaxSize32Single;
95 friend struct SegmentTest::MediumSize32Multi;
96 friend struct SegmentTest::MaxSize32Multi;
97 friend struct SegmentTest::MaxSize32MultiIterated;
103 #endif // PULSEVIEW_PV_DATA_SEGMENT_HPP