]>
Commit | Line | Data |
---|---|---|
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 | |
8c339741 SA |
30 | #include <QObject> |
31 | ||
6f925ba9 UH |
32 | using std::recursive_mutex; |
33 | using std::vector; | |
34 | ||
26a883ed SA |
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; | |
207ae8f6 | 44 | struct MaxSize32MultiAtOnce; |
26a883ed | 45 | struct MaxSize32MultiIterated; |
870ea3db | 46 | } // namespace SegmentTest |
26a883ed | 47 | |
51e77110 | 48 | namespace pv { |
1b1ec774 | 49 | namespace data { |
51e77110 | 50 | |
26a883ed SA |
51 | typedef struct { |
52 | uint64_t sample_index, chunk_num, chunk_offs; | |
53 | uint8_t* chunk; | |
54 | uint8_t* value; | |
55 | } SegmentRawDataIterator; | |
56 | ||
8c339741 | 57 | class Segment : public QObject |
28a4c9c5 | 58 | { |
8c339741 SA |
59 | Q_OBJECT |
60 | ||
26a883ed | 61 | private: |
dd3f9a41 | 62 | static const uint64_t MaxChunkSize; |
26a883ed | 63 | |
28a4c9c5 | 64 | public: |
85a70280 | 65 | Segment(uint32_t segment_id, uint64_t samplerate, unsigned int unit_size); |
f556bc6a | 66 | |
f3d66e52 | 67 | virtual ~Segment(); |
28a4c9c5 | 68 | |
e7c6e898 | 69 | uint64_t get_sample_count() const; |
28a4c9c5 | 70 | |
60d9b99a | 71 | const pv::util::Timestamp& start_time() const; |
7f4038d6 | 72 | |
ff008de6 JH |
73 | double samplerate() const; |
74 | void set_samplerate(double samplerate); | |
75 | ||
5ad3b48b | 76 | unsigned int unit_size() const; |
6fd14a32 | 77 | |
85a70280 SA |
78 | uint32_t segment_id() const; |
79 | ||
558ad6ce SA |
80 | void set_complete(); |
81 | bool is_complete() const; | |
82 | ||
5e6967cb SA |
83 | void free_unused_memory(); |
84 | ||
28a4c9c5 | 85 | protected: |
26a883ed SA |
86 | void append_single_sample(void *data); |
87 | void append_samples(void *data, uint64_t samples); | |
b82243f7 | 88 | void get_raw_samples(uint64_t start, uint64_t count, uint8_t *dest) const; |
26a883ed | 89 | |
c70e3464 SA |
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); | |
f556bc6a | 93 | |
85a70280 | 94 | uint32_t segment_id_; |
6f925ba9 UH |
95 | mutable recursive_mutex mutex_; |
96 | vector<uint8_t*> data_chunks_; | |
26a883ed SA |
97 | uint8_t* current_chunk_; |
98 | uint64_t used_samples_, unused_samples_; | |
8dbbc7f0 | 99 | uint64_t sample_count_; |
60d9b99a | 100 | pv::util::Timestamp start_time_; |
ff008de6 | 101 | double samplerate_; |
26a883ed | 102 | uint64_t chunk_size_; |
8dbbc7f0 | 103 | unsigned int unit_size_; |
c70e3464 SA |
104 | int iterator_count_; |
105 | bool mem_optimization_requested_; | |
558ad6ce | 106 | bool is_complete_; |
26a883ed SA |
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; | |
207ae8f6 | 116 | friend struct SegmentTest::MaxSize32MultiAtOnce; |
26a883ed | 117 | friend struct SegmentTest::MaxSize32MultiIterated; |
28a4c9c5 | 118 | }; |
51e77110 | 119 | |
1b1ec774 | 120 | } // namespace data |
51e77110 | 121 | } // namespace pv |
640d091b | 122 | |
a38268f0 | 123 | #endif // PULSEVIEW_PV_DATA_SEGMENT_HPP |