From: Soeren Apel Date: Sun, 22 Jan 2017 20:32:05 +0000 (+0100) Subject: Unify get_samples() semantics for AnalogSegment and LogicSegment X-Git-Tag: pulseview-0.4.0~201 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=038a14278afb24e10cd59991c2cafd97264fd3a5;p=pulseview.git Unify get_samples() semantics for AnalogSegment and LogicSegment --- diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 2b079368..5402df4f 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -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) { diff --git a/pv/data/logicsegment.cpp b/pv/data/logicsegment.cpp index aee09bd7..dab6b91d 100644 --- a/pv/data/logicsegment.cpp +++ b/pv/data/logicsegment.cpp @@ -152,10 +152,9 @@ void LogicSegment::append_payload(shared_ptr 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 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) diff --git a/pv/data/logicsegment.hpp b/pv/data/logicsegment.hpp index 59cca86e..0931e2c4 100644 --- a/pv/data/logicsegment.hpp +++ b/pv/data/logicsegment.hpp @@ -68,8 +68,7 @@ public: void append_payload(std::shared_ptr 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; diff --git a/pv/storesession.cpp b/pv/storesession.cpp index eaa17ea5..55b199a3 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -217,10 +217,6 @@ void StoreSession::store_proc(vector< shared_ptr > 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 > 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 > achannel_li output_.reset(); output_stream_.close(); - - delete[] ldata; } } // pv