]> sigrok.org Git - pulseview.git/commitdiff
Unify get_samples() semantics for AnalogSegment and LogicSegment
authorSoeren Apel <redacted>
Sun, 22 Jan 2017 20:32:05 +0000 (21:32 +0100)
committerUwe Hermann <redacted>
Thu, 2 Feb 2017 21:57:35 +0000 (22:57 +0100)
pv/data/decoderstack.cpp
pv/data/logicsegment.cpp
pv/data/logicsegment.hpp
pv/storesession.cpp

index 2b07936840f49df3d76160f2b6250ed051278003..5402df4f8539f4ebd51728277562f33342d1ffd2 100644 (file)
@@ -304,8 +304,6 @@ void DecoderStack::decode_data(
        const int64_t sample_count, const unsigned int unit_size,
        srd_session *const session)
 {
-       uint8_t chunk[DecodeChunkLength];
-
        const unsigned int chunk_sample_count =
                DecodeChunkLength / segment_->unit_size();
 
@@ -314,7 +312,7 @@ void DecoderStack::decode_data(
 
                const int64_t chunk_end = min(
                        i + chunk_sample_count, sample_count);
-               segment_->get_samples(chunk, i, chunk_end);
+               const uint8_t* chunk = segment_->get_samples(i, chunk_end);
 
                if (srd_session_send(session, i, chunk_end, chunk,
                                (chunk_end - i) * unit_size, unit_size) != SRD_OK) {
index aee09bd70b1808df035b3f4cf49099e8caa1ceb5..dab6b91dee295194f343115c7f2cdeecec5657e6 100644 (file)
@@ -152,10 +152,9 @@ void LogicSegment::append_payload(shared_ptr<Logic> logic)
        append_payload_to_mipmap();
 }
 
-void LogicSegment::get_samples(uint8_t *const data,
-       int64_t start_sample, int64_t end_sample) const
+const uint8_t* LogicSegment::get_samples(int64_t start_sample,
+       int64_t end_sample) const
 {
-       assert(data);
        assert(start_sample >= 0);
        assert(start_sample <= (int64_t)sample_count_);
        assert(end_sample >= 0);
@@ -164,8 +163,10 @@ void LogicSegment::get_samples(uint8_t *const data,
 
        lock_guard<recursive_mutex> lock(mutex_);
 
+       uint8_t* data = new uint8_t[end_sample - start_sample];
        const size_t size = (end_sample - start_sample) * unit_size_;
-       memcpy(data, (const uint8_t*)data_.data() + start_sample * unit_size_, size);
+       memcpy(data, (uint8_t*)data_.data() + start_sample * unit_size_, size);
+       return data;
 }
 
 void LogicSegment::reallocate_mipmap_level(MipMapLevel &m)
index 59cca86eca3a282b8baf0e0f3f24d1b141be8a10..0931e2c46c9f6ed86a9c1d8f8706c8477cc56a26 100644 (file)
@@ -68,8 +68,7 @@ public:
 
        void append_payload(std::shared_ptr<sigrok::Logic> logic);
 
-       void get_samples(uint8_t *const data,
-               int64_t start_sample, int64_t end_sample) const;
+       const uint8_t* get_samples(int64_t start_sample, int64_t end_sample) const;
 
 private:
        uint64_t unpack_sample(const uint8_t *ptr) const;
index eaa17ea5f98096519f88f44be1373a8a697c171c..55b199a3380bfee054f1152000c7c87c380b55c9 100644 (file)
@@ -217,10 +217,6 @@ void StoreSession::store_proc(vector< shared_ptr<data::SignalBase> > achannel_li
 {
        unsigned progress_scale = 0;
 
-       /// TODO: Wrap this in a std::unique_ptr when we transition to C++11
-       uint8_t *const ldata = new uint8_t[BlockSize];
-       assert(ldata);
-
        int aunit_size = 0;
        int lunit_size = 0;
        unsigned int lsamples_per_block = INT_MAX;
@@ -278,14 +274,17 @@ void StoreSession::store_proc(vector< shared_ptr<data::SignalBase> > achannel_li
                        }
 
                        if (lsegment) {
-                               lsegment->get_samples(ldata, start_sample_, start_sample_ + packet_len);
+                               const uint8_t* ldata =
+                                       lsegment->get_samples(start_sample_, start_sample_ + packet_len);
 
                                const size_t length = packet_len * lunit_size;
-                               auto logic = context->create_logic_packet(ldata, length, lunit_size);
+                               auto logic = context->create_logic_packet((void*)ldata, length, lunit_size);
                                const string ldata_str = output_->receive(logic);
 
                                if (output_stream_.is_open())
                                        output_stream_ << ldata_str;
+
+                               delete[] ldata;
                        }
                } catch (Error error) {
                        error_ = tr("Error while saving: ") + error.what();
@@ -305,8 +304,6 @@ void StoreSession::store_proc(vector< shared_ptr<data::SignalBase> > achannel_li
 
        output_.reset();
        output_stream_.close();
-
-       delete[] ldata;
 }
 
 } // pv