1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
/*
* This file is part of the PulseView project.
*
* Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PULSEVIEW_PV_DATA_SEGMENT_HPP
#define PULSEVIEW_PV_DATA_SEGMENT_HPP
#include "pv/util.hpp"
#include <mutex>
#include <thread>
#include <vector>
#include <QObject>
using std::recursive_mutex;
using std::vector;
namespace SegmentTest {
struct SmallSize8Single;
struct MediumSize8Single;
struct MaxSize8Single;
struct MediumSize24Single;
struct MediumSize32Single;
struct MaxSize32Single;
struct MediumSize32Multi;
struct MaxSize32Multi;
struct MaxSize32MultiAtOnce;
struct MaxSize32MultiIterated;
} // namespace SegmentTest
namespace pv {
namespace data {
typedef struct {
uint64_t sample_index, chunk_num, chunk_offs;
uint8_t* chunk;
} SegmentDataIterator;
class Segment : public QObject
{
Q_OBJECT
private:
static const uint64_t MaxChunkSize;
public:
Segment(uint32_t segment_id, uint64_t samplerate, unsigned int unit_size);
virtual ~Segment();
uint64_t get_sample_count() const;
const pv::util::Timestamp& start_time() const;
double samplerate() const;
void set_samplerate(double samplerate);
unsigned int unit_size() const;
uint32_t segment_id() const;
void set_complete();
bool is_complete() const;
void free_unused_memory();
protected:
void append_single_sample(void *data);
void append_samples(void *data, uint64_t samples);
void get_raw_samples(uint64_t start, uint64_t count, uint8_t *dest) const;
SegmentDataIterator* begin_sample_iteration(uint64_t start);
void continue_sample_iteration(SegmentDataIterator* it, uint64_t increase);
void end_sample_iteration(SegmentDataIterator* it);
uint8_t* get_iterator_value(SegmentDataIterator* it);
uint64_t get_iterator_valid_length(SegmentDataIterator* it);
uint32_t segment_id_;
mutable recursive_mutex mutex_;
vector<uint8_t*> data_chunks_;
uint8_t* current_chunk_;
uint64_t used_samples_, unused_samples_;
uint64_t sample_count_;
pv::util::Timestamp start_time_;
double samplerate_;
uint64_t chunk_size_;
unsigned int unit_size_;
int iterator_count_;
bool mem_optimization_requested_;
bool is_complete_;
friend struct SegmentTest::SmallSize8Single;
friend struct SegmentTest::MediumSize8Single;
friend struct SegmentTest::MaxSize8Single;
friend struct SegmentTest::MediumSize24Single;
friend struct SegmentTest::MediumSize32Single;
friend struct SegmentTest::MaxSize32Single;
friend struct SegmentTest::MediumSize32Multi;
friend struct SegmentTest::MaxSize32Multi;
friend struct SegmentTest::MaxSize32MultiAtOnce;
friend struct SegmentTest::MaxSize32MultiIterated;
};
} // namespace data
} // namespace pv
#endif // PULSEVIEW_PV_DATA_SEGMENT_HPP
|