From 3cbffdcf7c99c9722f9ba7b8b9e483c2f6132b68 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 1 Mar 2014 16:30:07 +0000 Subject: [PATCH 01/16] SamplingBar: Only use DefaultSampleCount if the _sample_count widget is unset. This fixes bug #324 --- pv/toolbars/samplingbar.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pv/toolbars/samplingbar.cpp b/pv/toolbars/samplingbar.cpp index be29e74..dce7aa3 100644 --- a/pv/toolbars/samplingbar.cpp +++ b/pv/toolbars/samplingbar.cpp @@ -264,10 +264,13 @@ void SamplingBar::update_sample_count_selector() if (_sample_count_supported) { - uint64_t sample_count = DefaultSampleCount; + uint64_t sample_count = _sample_count.value(); uint64_t min_sample_count = 0; uint64_t max_sample_count = MaxSampleCount; + if (sample_count == 0) + sample_count = DefaultSampleCount; + if ((gvar = dev_inst->list_config(NULL, SR_CONF_LIMIT_SAMPLES))) { g_variant_get(gvar, "(tt)", -- 2.30.2 From ddee4cf8c09fa27c329084b8706a984995648056 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 16 Feb 2014 10:55:27 +0000 Subject: [PATCH 02/16] Added LogicSignal::get_data --- pv/data/decode/decoder.cpp | 16 ++++++++++++++++ pv/data/decode/decoder.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/pv/data/decode/decoder.cpp b/pv/data/decode/decoder.cpp index 8cde226..89d19b3 100644 --- a/pv/data/decode/decoder.cpp +++ b/pv/data/decode/decoder.cpp @@ -26,6 +26,7 @@ #include using boost::shared_ptr; +using std::set; using std::map; using std::string; @@ -97,6 +98,21 @@ bool Decoder::have_required_probes() const return true; } +set< shared_ptr > Decoder::get_data() +{ + set< shared_ptr > data; + for(map >:: + const_iterator i = _probes.begin(); + i != _probes.end(); i++) + { + shared_ptr signal((*i).second); + assert(signal); + data.insert(signal->logic_data()); + } + + return data; +} + srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session, int unit_size) const { GHashTable *const opt_hash = g_hash_table_new_full(g_str_hash, diff --git a/pv/data/decode/decoder.h b/pv/data/decode/decoder.h index d8ed469..0c3662c 100644 --- a/pv/data/decode/decoder.h +++ b/pv/data/decode/decoder.h @@ -22,6 +22,7 @@ #define PULSEVIEW_PV_DATA_DECODE_DECODER_H #include +#include #include @@ -39,6 +40,9 @@ class LogicSignal; } namespace data { + +class Logic; + namespace decode { class Decoder @@ -67,6 +71,8 @@ public: srd_decoder_inst* create_decoder_inst( srd_session *session, int unit_size) const; + std::set< boost::shared_ptr > get_data(); + private: const srd_decoder *const _decoder; -- 2.30.2 From bdc5c3b09d09781aa50ae3b128b2a7c6e2a53d5b Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 16 Feb 2014 11:01:30 +0000 Subject: [PATCH 03/16] Added a reference to the SigSession in DecoderStack --- pv/data/decoderstack.cpp | 4 +++- pv/data/decoderstack.h | 6 +++++- pv/sigsession.cpp | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 9707d8d..2c68ef8 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -58,7 +58,9 @@ const int64_t DecoderStack::DecodeChunkLength = 4096; mutex DecoderStack::_global_decode_mutex; -DecoderStack::DecoderStack(const srd_decoder *const dec) : +DecoderStack::DecoderStack(pv::SigSession &session, + const srd_decoder *const dec) : + _session(session), _samples_decoded(0) { _stack.push_back(shared_ptr( diff --git a/pv/data/decoderstack.h b/pv/data/decoderstack.h index 339c1e0..6391e6a 100644 --- a/pv/data/decoderstack.h +++ b/pv/data/decoderstack.h @@ -45,6 +45,8 @@ class TwoDecoderStack; namespace pv { +class SigSession; + namespace view { class LogicSignal; } @@ -68,7 +70,8 @@ private: static const int64_t DecodeChunkLength; public: - DecoderStack(const srd_decoder *const decoder); + DecoderStack(pv::SigSession &_session, + const srd_decoder *const decoder); virtual ~DecoderStack(); @@ -106,6 +109,7 @@ signals: void new_decode_data(); private: + pv::SigSession &_session; /** * This mutex prevents more than one decode operation occuring diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index cbb3192..92118b4 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -215,7 +215,7 @@ bool SigSession::add_decoder(srd_decoder *const dec) // Create the decoder decoder_stack = shared_ptr( - new data::DecoderStack(dec)); + new data::DecoderStack(*this, dec)); // Make a list of all the probes std::vector all_probes; -- 2.30.2 From 82f50b10f8fd45a772f9ba40c4ef1f888ed6b8b1 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 16 Feb 2014 11:46:21 +0000 Subject: [PATCH 04/16] Begin a new decode session when a new frame begins --- pv/data/decoderstack.cpp | 8 ++++++++ pv/data/decoderstack.h | 3 +++ pv/sigsession.cpp | 16 ++++++++++++++++ pv/sigsession.h | 4 ++++ 4 files changed, 31 insertions(+) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 2c68ef8..e73cfc3 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include using boost::lock_guard; @@ -63,6 +64,8 @@ DecoderStack::DecoderStack(pv::SigSession &session, _session(session), _samples_decoded(0) { + connect(&_session, SIGNAL(frame_began()), this, SLOT(on_new_frame())); + _stack.push_back(shared_ptr( new decode::Decoder(dec))); } @@ -373,5 +376,10 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder) d->new_decode_data(); } +void DecoderStack::on_new_frame() +{ + begin_decode(); +} + } // namespace data } // namespace pv diff --git a/pv/data/decoderstack.h b/pv/data/decoderstack.h index 6391e6a..ad2a17b 100644 --- a/pv/data/decoderstack.h +++ b/pv/data/decoderstack.h @@ -105,6 +105,9 @@ private: static void annotation_callback(srd_proto_data *pdata, void *decoder); +private slots: + void on_new_frame(); + signals: void new_decode_data(); diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 92118b4..1a5ac8c 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -493,6 +493,12 @@ void SigSession::feed_in_meta(const sr_dev_inst *sdi, signals_changed(); } +void SigSession::feed_in_frame_begin() +{ + if (_cur_logic_snapshot || !_cur_analog_snapshots.empty()) + frame_began(); +} + void SigSession::feed_in_logic(const sr_datafeed_logic &logic) { lock_guard lock(_data_mutex); @@ -512,6 +518,12 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic) _cur_logic_snapshot = shared_ptr( new data::LogicSnapshot(logic, _dev_inst->get_sample_limit())); _logic_data->push_snapshot(_cur_logic_snapshot); + + // @todo Putting this here means that only listeners querying + // for logic will be notified. Currently the only user of + // frame_began is DecoderStack, but in future we need to signal + // this after both analog and logic sweeps have begun. + frame_began(); } else { @@ -600,6 +612,10 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, *(const sr_datafeed_meta*)packet->payload); break; + case SR_DF_FRAME_BEGIN: + feed_in_frame_begin(); + break; + case SR_DF_LOGIC: assert(packet->payload); feed_in_logic(*(const sr_datafeed_logic*)packet->payload); diff --git a/pv/sigsession.h b/pv/sigsession.h index 7e61d8d..6a8da06 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -145,6 +145,8 @@ private: void feed_in_meta(const sr_dev_inst *sdi, const sr_datafeed_meta &meta); + void feed_in_frame_begin(); + void feed_in_logic(const sr_datafeed_logic &logic); void feed_in_analog(const sr_datafeed_analog &analog); @@ -184,6 +186,8 @@ signals: void signals_changed(); + void frame_began(); + void data_updated(); private: -- 2.30.2 From f67d9e9b4b37e62c1ac2edae18c048f3bff5c075 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 16 Feb 2014 15:22:25 +0000 Subject: [PATCH 05/16] Moved inner decode loop into DecoderStack::decode_data --- pv/data/decoderstack.cpp | 70 +++++++++++++++++++++++----------------- pv/data/decoderstack.h | 7 ++++ 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index e73cfc3..716d778 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -247,10 +247,45 @@ uint64_t DecoderStack::get_max_sample_count() const return max_sample_count; } +void DecoderStack::decode_data( + const shared_ptr &snapshot, + srd_session *const session) +{ + uint8_t chunk[DecodeChunkLength]; + + const int64_t sample_count = snapshot->get_sample_count(); + const unsigned int unit_size = snapshot->unit_size(); + const unsigned int chunk_sample_count = + DecodeChunkLength / snapshot->unit_size(); + + for (int64_t i = 0; + !boost::this_thread::interruption_requested() && + i < sample_count; + i += chunk_sample_count) + { + lock_guard decode_lock(_global_decode_mutex); + + const int64_t chunk_end = min( + i + chunk_sample_count, sample_count); + snapshot->get_samples(chunk, i, chunk_end); + + if (srd_session_send(session, i, i + sample_count, chunk, + (chunk_end - i) * unit_size) != SRD_OK) { + _error_message = tr("Decoder reported an error"); + break; + } + + { + lock_guard lock(_mutex); + _samples_decoded = chunk_end; + } + } + +} + void DecoderStack::decode_proc(shared_ptr data) { srd_session *session; - uint8_t chunk[DecodeChunkLength]; srd_decoder_inst *prev_di = NULL; assert(data); @@ -266,18 +301,14 @@ void DecoderStack::decode_proc(shared_ptr data) if (!dec->have_required_probes()) return; - const shared_ptr &snapshot = - snapshots.front(); - const int64_t sample_count = snapshot->get_sample_count(); - const unsigned int unit_size = snapshot->unit_size(); - const unsigned int chunk_sample_count = - DecodeChunkLength / unit_size; - // Create the session srd_session_new(&session); assert(session); // Create the decoders + const shared_ptr &snapshot = snapshots.front(); + const unsigned int unit_size = snapshot->unit_size(); + BOOST_FOREACH(const shared_ptr &dec, _stack) { srd_decoder_inst *const di = dec->create_decoder_inst(session, unit_size); @@ -304,28 +335,7 @@ void DecoderStack::decode_proc(shared_ptr data) srd_session_start(session); - for (int64_t i = 0; - !boost::this_thread::interruption_requested() && - i < sample_count; - i += chunk_sample_count) - { - lock_guard decode_lock(_global_decode_mutex); - - const int64_t chunk_end = min( - i + chunk_sample_count, sample_count); - snapshot->get_samples(chunk, i, chunk_end); - - if (srd_session_send(session, i, i + sample_count, chunk, - (chunk_end - i) * unit_size) != SRD_OK) { - _error_message = tr("Decoder reported an error"); - break; - } - - { - lock_guard lock(_mutex); - _samples_decoded = chunk_end; - } - } + decode_data(snapshot, session); // Destroy the session srd_session_destroy(session); diff --git a/pv/data/decoderstack.h b/pv/data/decoderstack.h index ad2a17b..4399618 100644 --- a/pv/data/decoderstack.h +++ b/pv/data/decoderstack.h @@ -38,6 +38,7 @@ struct srd_decoder; struct srd_decoder_annotation_row; struct srd_probe; struct srd_proto_data; +struct srd_session; namespace DecoderStackTest { class TwoDecoderStack; @@ -53,6 +54,8 @@ class LogicSignal; namespace data { +class LogicSnapshot; + namespace decode { class Annotation; class Decoder; @@ -100,6 +103,10 @@ public: void begin_decode(); private: + void decode_data( + const boost::shared_ptr &snapshot, + srd_session *const session); + void decode_proc(boost::shared_ptr data); static void annotation_callback(srd_proto_data *pdata, -- 2.30.2 From 1f3740351a99b9c5cb4cb8a3537e27db9f2e6f60 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 16 Feb 2014 21:24:44 +0000 Subject: [PATCH 06/16] Renamed SigSession::data_updated signal to data_received, and added the frame_ended signal --- pv/sigsession.cpp | 6 +++--- pv/sigsession.h | 4 +++- pv/view/view.cpp | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 1a5ac8c..b93ecc8 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -531,7 +531,7 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic) _cur_logic_snapshot->append_payload(logic); } - data_updated(); + data_received(); } void SigSession::feed_in_analog(const sr_datafeed_analog &analog) @@ -592,7 +592,7 @@ void SigSession::feed_in_analog(const sr_datafeed_analog &analog) set_capture_state(Running); } - data_updated(); + data_received(); } void SigSession::data_feed_in(const struct sr_dev_inst *sdi, @@ -633,7 +633,7 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, _cur_logic_snapshot.reset(); _cur_analog_snapshots.clear(); } - data_updated(); + frame_ended(); break; } } diff --git a/pv/sigsession.h b/pv/sigsession.h index 6a8da06..1dacc09 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -188,7 +188,9 @@ signals: void frame_began(); - void data_updated(); + void data_received(); + + void frame_ended(); private: // TODO: This should not be necessary. Multiple concurrent diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 2b0f04a..2195433 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -92,7 +92,9 @@ View::View(SigSession &session, QWidget *parent) : connect(&_session, SIGNAL(signals_changed()), this, SLOT(signals_changed())); - connect(&_session, SIGNAL(data_updated()), + connect(&_session, SIGNAL(data_received()), + this, SLOT(data_updated())); + connect(&_session, SIGNAL(frame_ended()), this, SLOT(data_updated())); connect(_cursors.first().get(), SIGNAL(time_changed()), -- 2.30.2 From 28b9cc08aa62c02fd64dfb09eff4b9bfdb01f518 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 2 Mar 2014 16:26:29 +0000 Subject: [PATCH 07/16] Renamed DecoderStack::_mutex to _output_mutex --- pv/data/decoderstack.cpp | 12 ++++++------ pv/data/decoderstack.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 716d778..3bb1328 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -106,13 +106,13 @@ void DecoderStack::remove(int index) int64_t DecoderStack::samples_decoded() const { - lock_guard decode_lock(_mutex); + lock_guard decode_lock(_output_mutex); return _samples_decoded; } std::vector DecoderStack::get_visible_rows() const { - lock_guard lock(_mutex); + lock_guard lock(_output_mutex); vector rows; @@ -147,7 +147,7 @@ void DecoderStack::get_annotation_subset( const Row &row, uint64_t start_sample, uint64_t end_sample) const { - lock_guard lock(_mutex); + lock_guard lock(_output_mutex); std::map::const_iterator iter = _rows.find(row); @@ -158,7 +158,7 @@ void DecoderStack::get_annotation_subset( QString DecoderStack::error_message() { - lock_guard lock(_mutex); + lock_guard lock(_output_mutex); return _error_message; } @@ -276,7 +276,7 @@ void DecoderStack::decode_data( } { - lock_guard lock(_mutex); + lock_guard lock(_output_mutex); _samples_decoded = chunk_end; } } @@ -349,7 +349,7 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder) DecoderStack *const d = (DecoderStack*)decoder; assert(d); - lock_guard lock(d->_mutex); + lock_guard lock(d->_output_mutex); const Annotation a(pdata); diff --git a/pv/data/decoderstack.h b/pv/data/decoderstack.h index 4399618..308dce6 100644 --- a/pv/data/decoderstack.h +++ b/pv/data/decoderstack.h @@ -131,7 +131,7 @@ private: std::list< boost::shared_ptr > _stack; - mutable boost::mutex _mutex; + mutable boost::mutex _output_mutex; int64_t _samples_decoded; std::map _rows; -- 2.30.2 From f70d8673a56471c7e4b22159b99684da7d6c4be1 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 2 Mar 2014 17:27:12 +0000 Subject: [PATCH 08/16] Implemented threaded decode --- pv/data/decoderstack.cpp | 79 ++++++++++++++++++++++++++++++++-------- pv/data/decoderstack.h | 19 ++++++++-- 2 files changed, 80 insertions(+), 18 deletions(-) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 3bb1328..87ac326 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -38,7 +38,9 @@ using boost::lock_guard; using boost::mutex; +using boost::optional; using boost::shared_ptr; +using boost::unique_lock; using std::deque; using std::make_pair; using std::max; @@ -62,9 +64,16 @@ mutex DecoderStack::_global_decode_mutex; DecoderStack::DecoderStack(pv::SigSession &session, const srd_decoder *const dec) : _session(session), + _sample_count(0), + _frame_complete(false), _samples_decoded(0) { - connect(&_session, SIGNAL(frame_began()), this, SLOT(on_new_frame())); + connect(&_session, SIGNAL(frame_began()), + this, SLOT(on_new_frame())); + connect(&_session, SIGNAL(data_received()), + this, SLOT(on_data_received())); + connect(&_session, SIGNAL(frame_ended()), + this, SLOT(on_frame_ended())); _stack.push_back(shared_ptr( new decode::Decoder(dec))); @@ -164,6 +173,8 @@ QString DecoderStack::error_message() void DecoderStack::clear() { + _sample_count = 0; + _frame_complete = false; _samples_decoded = 0; _error_message = QString(); _rows.clear(); @@ -225,6 +236,13 @@ void DecoderStack::begin_decode() if (!data) return; + // Check we have a snapshot of data + const deque< shared_ptr > &snapshots = + data->get_snapshots(); + if (snapshots.empty()) + return; + _snapshot = snapshots.front(); + // Get the samplerate and start time _start_time = data->get_start_time(); _samplerate = data->samplerate(); @@ -247,16 +265,26 @@ uint64_t DecoderStack::get_max_sample_count() const return max_sample_count; } +optional DecoderStack::wait_for_data() const +{ + unique_lock input_lock(_input_mutex); + while(!boost::this_thread::interruption_requested() && + !_frame_complete && _samples_decoded >= _sample_count) + _input_cond.wait(input_lock); + return boost::make_optional( + !boost::this_thread::interruption_requested() && + (_samples_decoded < _sample_count || !_frame_complete), + _sample_count); +} + void DecoderStack::decode_data( - const shared_ptr &snapshot, + const int64_t sample_count, const unsigned int unit_size, srd_session *const session) { uint8_t chunk[DecodeChunkLength]; - const int64_t sample_count = snapshot->get_sample_count(); - const unsigned int unit_size = snapshot->unit_size(); const unsigned int chunk_sample_count = - DecodeChunkLength / snapshot->unit_size(); + DecodeChunkLength / _snapshot->unit_size(); for (int64_t i = 0; !boost::this_thread::interruption_requested() && @@ -267,7 +295,7 @@ void DecoderStack::decode_data( const int64_t chunk_end = min( i + chunk_sample_count, sample_count); - snapshot->get_samples(chunk, i, chunk_end); + _snapshot->get_samples(chunk, i, chunk_end); if (srd_session_send(session, i, i + sample_count, chunk, (chunk_end - i) * unit_size) != SRD_OK) { @@ -285,16 +313,12 @@ void DecoderStack::decode_data( void DecoderStack::decode_proc(shared_ptr data) { + optional sample_count; srd_session *session; srd_decoder_inst *prev_di = NULL; assert(data); - - // Check we have a snapshot of data - const deque< shared_ptr > &snapshots = - data->get_snapshots(); - if (snapshots.empty()) - return; + assert(_snapshot); // Check that all decoders have the required probes BOOST_FOREACH(const shared_ptr &dec, _stack) @@ -306,8 +330,7 @@ void DecoderStack::decode_proc(shared_ptr data) assert(session); // Create the decoders - const shared_ptr &snapshot = snapshots.front(); - const unsigned int unit_size = snapshot->unit_size(); + const unsigned int unit_size = _snapshot->unit_size(); BOOST_FOREACH(const shared_ptr &dec, _stack) { @@ -326,6 +349,12 @@ void DecoderStack::decode_proc(shared_ptr data) prev_di = di; } + // Get the intial sample count + { + unique_lock input_lock(_input_mutex); + sample_count = _sample_count = _snapshot->get_sample_count(); + } + // Start the session srd_session_metadata_set(session, SRD_CONF_SAMPLERATE, g_variant_new_uint64((uint64_t)_samplerate)); @@ -335,7 +364,9 @@ void DecoderStack::decode_proc(shared_ptr data) srd_session_start(session); - decode_data(snapshot, session); + do { + decode_data(*sample_count, unit_size, session); + } while(_error_message.isEmpty() && (sample_count = wait_for_data())); // Destroy the session srd_session_destroy(session); @@ -391,5 +422,23 @@ void DecoderStack::on_new_frame() begin_decode(); } +void DecoderStack::on_data_received() +{ + { + unique_lock lock(_input_mutex); + _sample_count = _snapshot->get_sample_count(); + } + _input_cond.notify_one(); +} + +void DecoderStack::on_frame_ended() +{ + { + unique_lock lock(_input_mutex); + _frame_complete = true; + } + _input_cond.notify_one(); +} + } // namespace data } // namespace pv diff --git a/pv/data/decoderstack.h b/pv/data/decoderstack.h index 308dce6..073f269 100644 --- a/pv/data/decoderstack.h +++ b/pv/data/decoderstack.h @@ -25,6 +25,7 @@ #include +#include #include #include @@ -103,9 +104,10 @@ public: void begin_decode(); private: - void decode_data( - const boost::shared_ptr &snapshot, - srd_session *const session); + boost::optional wait_for_data() const; + + void decode_data(const int64_t sample_count, + const unsigned int unit_size, srd_session *const session); void decode_proc(boost::shared_ptr data); @@ -115,6 +117,10 @@ private: private slots: void on_new_frame(); + void on_data_received(); + + void on_frame_ended(); + signals: void new_decode_data(); @@ -131,6 +137,13 @@ private: std::list< boost::shared_ptr > _stack; + boost::shared_ptr _snapshot; + + mutable boost::mutex _input_mutex; + mutable boost::condition_variable _input_cond; + int64_t _sample_count; + bool _frame_complete; + mutable boost::mutex _output_mutex; int64_t _samples_decoded; -- 2.30.2 From 19f511a492b5fb917802b84a8ae81b4c8073c747 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 2 Mar 2014 19:50:52 +0000 Subject: [PATCH 09/16] Enable decode support by default --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b9c7d1..11767a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ project(pulseview) option(DISABLE_WERROR "Build without -Werror" FALSE) option(ENABLE_SIGNALS "Build with UNIX signals" TRUE) -option(ENABLE_DECODE "Build with libsigrokdecode" FALSE) +option(ENABLE_DECODE "Build with libsigrokdecode" TRUE) option(ENABLE_COTIRE "Enable cotire" FALSE) option(ENABLE_TESTS "Enable unit tests" FALSE) option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE) -- 2.30.2 From 1c5fb7593d34daeca31148eb48de4ff7a0c6aa05 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 2 Mar 2014 21:40:13 +0000 Subject: [PATCH 10/16] Notify repaint after decode_data instead of inside annotation_callback --- pv/data/decoderstack.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 87ac326..2344804 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -309,6 +309,7 @@ void DecoderStack::decode_data( } } + new_decode_data(); } void DecoderStack::decode_proc(shared_ptr data) @@ -413,8 +414,6 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder) // Add the annotation (*row_iter).second.push_annotation(a); - - d->new_decode_data(); } void DecoderStack::on_new_frame() -- 2.30.2 From c1b2865ea8b10c4b41360b2fd1974a8bebaa0dea Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Mon, 3 Mar 2014 09:10:37 +0000 Subject: [PATCH 11/16] Removed unused parameter in DecoderStack::decode_proc Change-Id: I6ac5ef33b616f8e15628eb8888148140b19ad8e1 --- pv/data/decoderstack.cpp | 5 ++--- pv/data/decoderstack.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 2344804..8284c79 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -249,8 +249,7 @@ void DecoderStack::begin_decode() if (_samplerate == 0.0) _samplerate = 1.0; - _decode_thread = boost::thread(&DecoderStack::decode_proc, this, - data); + _decode_thread = boost::thread(&DecoderStack::decode_proc, this); } uint64_t DecoderStack::get_max_sample_count() const @@ -312,7 +311,7 @@ void DecoderStack::decode_data( new_decode_data(); } -void DecoderStack::decode_proc(shared_ptr data) +void DecoderStack::decode_proc() { optional sample_count; srd_session *session; diff --git a/pv/data/decoderstack.h b/pv/data/decoderstack.h index 073f269..9c960e5 100644 --- a/pv/data/decoderstack.h +++ b/pv/data/decoderstack.h @@ -109,7 +109,7 @@ private: void decode_data(const int64_t sample_count, const unsigned int unit_size, srd_session *const session); - void decode_proc(boost::shared_ptr data); + void decode_proc(); static void annotation_callback(srd_proto_data *pdata, void *decoder); -- 2.30.2 From fc921b20cc5fb90862e1e358cbb00b567d52e72d Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Mon, 3 Mar 2014 18:51:14 +0000 Subject: [PATCH 12/16] Added an error message there are some unspecified required probes --- pv/data/decoderstack.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 8284c79..f642b11 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -322,8 +322,11 @@ void DecoderStack::decode_proc() // Check that all decoders have the required probes BOOST_FOREACH(const shared_ptr &dec, _stack) - if (!dec->have_required_probes()) + if (!dec->have_required_probes()) { + _error_message = tr("One or more required probes " + "have not been specified"); return; + } // Create the session srd_session_new(&session); -- 2.30.2 From df4c1a0691f6d3a457a475e496186d5a9decc54a Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Mon, 3 Mar 2014 22:03:57 +0000 Subject: [PATCH 13/16] Check required probes before starting the decode thread --- pv/data/decoderstack.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index f642b11..c197e01 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -193,6 +193,14 @@ void DecoderStack::begin_decode() clear(); + // Check that all decoders have the required probes + BOOST_FOREACH(const shared_ptr &dec, _stack) + if (!dec->have_required_probes()) { + _error_message = tr("One or more required probes " + "have not been specified"); + return; + } + // Add classes BOOST_FOREACH (const shared_ptr &dec, _stack) { @@ -320,14 +328,6 @@ void DecoderStack::decode_proc() assert(data); assert(_snapshot); - // Check that all decoders have the required probes - BOOST_FOREACH(const shared_ptr &dec, _stack) - if (!dec->have_required_probes()) { - _error_message = tr("One or more required probes " - "have not been specified"); - return; - } - // Create the session srd_session_new(&session); assert(session); -- 2.30.2 From 46bf6027eacaec6d922be0e72e8403a10bbc25be Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Mon, 3 Mar 2014 22:13:40 +0000 Subject: [PATCH 14/16] Only update the decode state when decoding --- pv/data/decoderstack.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index c197e01..b252877 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -427,7 +427,8 @@ void DecoderStack::on_data_received() { { unique_lock lock(_input_mutex); - _sample_count = _snapshot->get_sample_count(); + if (_snapshot) + _sample_count = _snapshot->get_sample_count(); } _input_cond.notify_one(); } @@ -436,7 +437,8 @@ void DecoderStack::on_frame_ended() { { unique_lock lock(_input_mutex); - _frame_complete = true; + if (_snapshot) + _frame_complete = true; } _input_cond.notify_one(); } -- 2.30.2 From 4c581c790c0e9d378a0074c2b2802a0d7f5c7579 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Mon, 3 Mar 2014 22:27:50 +0000 Subject: [PATCH 15/16] Fixed non-painting decode --- pv/data/decoderstack.cpp | 4 ++++ pv/data/decoderstack.h | 1 + 2 files changed, 5 insertions(+) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index b252877..4b2a905 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -58,6 +58,7 @@ namespace data { const double DecoderStack::DecodeMargin = 1.0; const double DecoderStack::DecodeThreshold = 0.2; const int64_t DecoderStack::DecodeChunkLength = 4096; +const unsigned int DecoderStack::DecodeNotifyPeriod = 65536; mutex DecoderStack::_global_decode_mutex; @@ -314,6 +315,9 @@ void DecoderStack::decode_data( lock_guard lock(_output_mutex); _samples_decoded = chunk_end; } + + if (i % DecodeNotifyPeriod == 0) + new_decode_data(); } new_decode_data(); diff --git a/pv/data/decoderstack.h b/pv/data/decoderstack.h index 9c960e5..4b27172 100644 --- a/pv/data/decoderstack.h +++ b/pv/data/decoderstack.h @@ -72,6 +72,7 @@ private: static const double DecodeMargin; static const double DecodeThreshold; static const int64_t DecodeChunkLength; + static const unsigned int DecodeNotifyPeriod; public: DecoderStack(pv::SigSession &_session, -- 2.30.2 From 1ae8a74b45011027c3719d84f4c5ace5b9ba22d9 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Tue, 4 Mar 2014 19:04:41 +0000 Subject: [PATCH 16/16] Removed assert from DecoderStack --- pv/data/decoderstack.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 4b2a905..9a13769 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -329,7 +329,6 @@ void DecoderStack::decode_proc() srd_session *session; srd_decoder_inst *prev_di = NULL; - assert(data); assert(_snapshot); // Create the session -- 2.30.2