]>
Commit | Line | Data |
---|---|---|
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 | ||
32 | using std::recursive_mutex; | |
33 | using std::vector; | |
34 | ||
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 | |
47 | ||
48 | namespace pv { | |
49 | namespace data { | |
50 | ||
51 | typedef struct { | |
52 | uint64_t sample_index, chunk_num, chunk_offs; | |
53 | uint8_t* chunk; | |
54 | } SegmentDataIterator; | |
55 | ||
56 | class Segment : public QObject | |
57 | { | |
58 | Q_OBJECT | |
59 | ||
60 | private: | |
61 | static const uint64_t MaxChunkSize; | |
62 | ||
63 | public: | |
64 | Segment(uint32_t segment_id, uint64_t samplerate, unsigned int unit_size); | |
65 | ||
66 | virtual ~Segment(); | |
67 | ||
68 | uint64_t get_sample_count() const; | |
69 | ||
70 | const pv::util::Timestamp& start_time() const; | |
71 | ||
72 | double samplerate() const; | |
73 | void set_samplerate(double samplerate); | |
74 | ||
75 | unsigned int unit_size() const; | |
76 | ||
77 | uint32_t segment_id() const; | |
78 | ||
79 | void set_complete(); | |
80 | bool is_complete() const; | |
81 | ||
82 | void free_unused_memory(); | |
83 | ||
84 | protected: | |
85 | void append_single_sample(void *data); | |
86 | void append_samples(void *data, uint64_t samples); | |
87 | void get_raw_samples(uint64_t start, uint64_t count, uint8_t *dest) const; | |
88 | ||
89 | SegmentDataIterator* begin_sample_iteration(uint64_t start); | |
90 | void continue_sample_iteration(SegmentDataIterator* it, uint64_t increase); | |
91 | void end_sample_iteration(SegmentDataIterator* it); | |
92 | uint8_t* get_iterator_value(SegmentDataIterator* it); | |
93 | uint64_t get_iterator_valid_length(SegmentDataIterator* it); | |
94 | ||
95 | uint32_t segment_id_; | |
96 | mutable recursive_mutex mutex_; | |
97 | vector<uint8_t*> data_chunks_; | |
98 | uint8_t* current_chunk_; | |
99 | uint64_t used_samples_, unused_samples_; | |
100 | uint64_t sample_count_; | |
101 | pv::util::Timestamp start_time_; | |
102 | double samplerate_; | |
103 | uint64_t chunk_size_; | |
104 | unsigned int unit_size_; | |
105 | int iterator_count_; | |
106 | bool mem_optimization_requested_; | |
107 | bool is_complete_; | |
108 | ||
109 | friend struct SegmentTest::SmallSize8Single; | |
110 | friend struct SegmentTest::MediumSize8Single; | |
111 | friend struct SegmentTest::MaxSize8Single; | |
112 | friend struct SegmentTest::MediumSize24Single; | |
113 | friend struct SegmentTest::MediumSize32Single; | |
114 | friend struct SegmentTest::MaxSize32Single; | |
115 | friend struct SegmentTest::MediumSize32Multi; | |
116 | friend struct SegmentTest::MaxSize32Multi; | |
117 | friend struct SegmentTest::MaxSize32MultiAtOnce; | |
118 | friend struct SegmentTest::MaxSize32MultiIterated; | |
119 | }; | |
120 | ||
121 | } // namespace data | |
122 | } // namespace pv | |
123 | ||
124 | #endif // PULSEVIEW_PV_DATA_SEGMENT_HPP |