X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fdata%2Fsegment.hpp;h=f5a00c9581530529044cb33d283f52cbb7c1d162;hp=bfb10292f47172edaf1e9cbf4739eb0cc55e8e22;hb=50e56db003055e96c5a12e675889e4afad07b65c;hpb=7a01bd3654ed046216308fa64edfd79be7cd525f diff --git a/pv/data/segment.hpp b/pv/data/segment.hpp index bfb10292..f5a00c95 100644 --- a/pv/data/segment.hpp +++ b/pv/data/segment.hpp @@ -1,6 +1,7 @@ /* * This file is part of the PulseView project. * + * Copyright (C) 2017 Soeren Apel * Copyright (C) 2012 Joel Holdsworth * * This program is free software; you can redistribute it and/or modify @@ -14,77 +15,110 @@ * 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, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program; if not, see . */ -#ifndef PULSEVIEW_PV_DATA_SNAPSHOT_HPP -#define PULSEVIEW_PV_DATA_SNAPSHOT_HPP +#ifndef PULSEVIEW_PV_DATA_SEGMENT_HPP +#define PULSEVIEW_PV_DATA_SEGMENT_HPP + +#include "pv/util.hpp" -#include #include +#include #include +#include + +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 { -class Segment +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(uint64_t samplerate, unsigned int unit_size); + Segment(uint32_t segment_id, uint64_t samplerate, unsigned int unit_size); virtual ~Segment(); uint64_t get_sample_count() const; - double start_time() const; + const pv::util::Timestamp& start_time() const; double samplerate() const; void set_samplerate(double samplerate); unsigned int unit_size() const; - /** - * @brief Increase the capacity of the segment. - * - * Increasing the capacity allows samples to be appended without needing - * to reallocate memory. - * - * For the best efficiency @c set_capacity() should be called once before - * @c append_data() is called to set up the segment with the expected number - * of samples that will be appended in total. - * - * @note The capacity will automatically be increased when @c append_data() - * is called if there is not enough capacity in the buffer to store the samples. - * - * @param[in] new_capacity The new capacity of the segment. If this value is - * smaller or equal than the current capacity then the method has no effect. - */ - void set_capacity(uint64_t new_capacity); - - /** - * @brief Get the current capacity of the segment. - * - * The capacity can be increased by calling @c set_capacity(). - * - * @return The current capacity of the segment. - */ - uint64_t capacity() const; + uint32_t segment_id() const; -protected: - void append_data(void *data, uint64_t samples); + void set_complete(); + bool is_complete() const; + + void free_unused_memory(); protected: - mutable std::recursive_mutex mutex_; - std::vector data_; + 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 data_chunks_; + uint8_t* current_chunk_; + uint64_t used_samples_, unused_samples_; uint64_t sample_count_; - double start_time_; + pv::util::Timestamp start_time_; double samplerate_; - uint64_t capacity_; + 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_SNAPSHOT_HPP +#endif // PULSEVIEW_PV_DATA_SEGMENT_HPP