]> sigrok.org Git - pulseview.git/blobdiff - pv/sigsession.cpp
Initialise sample_rate in pv::SigSession::feed_in_header
[pulseview.git] / pv / sigsession.cpp
index 348d40c1e5b3b09da676184fb12f49ce48b6c566..6a69fdca2b99970aa0a86234a92fc0336dcb33c0 100644 (file)
@@ -72,13 +72,10 @@ SigSession::capture_state SigSession::get_capture_state() const
 }
 
 void SigSession::start_capture(struct sr_dev_inst *sdi,
 }
 
 void SigSession::start_capture(struct sr_dev_inst *sdi,
-       uint64_t record_length, uint64_t sample_rate)
+       uint64_t record_length)
 {
        stop_capture();
 
 {
        stop_capture();
 
-       lock_guard<mutex> lock(_sampling_mutex);
-       _sample_rate = sample_rate;
-
        _sampling_thread.reset(new boost::thread(
                &SigSession::sample_thread_proc, this, sdi,
                record_length));
        _sampling_thread.reset(new boost::thread(
                &SigSession::sample_thread_proc, this, sdi,
                record_length));
@@ -140,10 +137,6 @@ void SigSession::load_thread_proc(const string name)
 void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
        uint64_t record_length)
 {
 void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
        uint64_t record_length)
 {
-       shared_ptr<view::Signal> signal;
-       unsigned int logic_probe_count = 0;
-       unsigned int analog_probe_count = 0;
-
        assert(sdi);
 
        sr_session_new();
        assert(sdi);
 
        sr_session_new();
@@ -163,17 +156,26 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
                return;
        }
 
                return;
        }
 
-       // Set the samplerate
-       {
-               lock_guard<mutex> lock(_sampling_mutex);
-               if (sr_config_set(sdi, SR_CONF_SAMPLERATE,
-                       &_sample_rate) != SR_OK) {
-                       qDebug() << "Failed to configure samplerate.";
-                       sr_session_destroy();
-                       return;
-               }
+       if (sr_session_start() != SR_OK) {
+               qDebug() << "Failed to start session.";
+               return;
        }
 
        }
 
+       set_capture_state(Running);
+
+       sr_session_run();
+       sr_session_destroy();
+
+       set_capture_state(Stopped);
+}
+
+void SigSession::feed_in_header(const sr_dev_inst *sdi)
+{
+       shared_ptr<view::Signal> signal;
+       uint64_t *sample_rate = NULL;
+       unsigned int logic_probe_count = 0;
+       unsigned int analog_probe_count = 0;
+
        // Detect what data types we will receive
        for (const GSList *l = sdi->probes; l; l = l->next) {
                const sr_probe *const probe = (const sr_probe *)l->data;
        // Detect what data types we will receive
        for (const GSList *l = sdi->probes; l; l = l->next) {
                const sr_probe *const probe = (const sr_probe *)l->data;
@@ -191,19 +193,23 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
                }
        }
 
                }
        }
 
+       // Read out the sample rate
+       assert(sdi->driver);
+       assert(sr_config_get(sdi->driver, SR_CONF_SAMPLERATE,
+               (const void**)&sample_rate, sdi) == SR_OK);
+
        // Create data containers for the coming data snapshots
        {
                lock_guard<mutex> data_lock(_data_mutex);
        // Create data containers for the coming data snapshots
        {
                lock_guard<mutex> data_lock(_data_mutex);
-               lock_guard<mutex> sampling_lock(_sampling_mutex);
 
                if (logic_probe_count != 0) {
                        _logic_data.reset(new data::Logic(
 
                if (logic_probe_count != 0) {
                        _logic_data.reset(new data::Logic(
-                               logic_probe_count, _sample_rate));
+                               logic_probe_count, *sample_rate));
                        assert(_logic_data);
                }
 
                if (analog_probe_count != 0) {
                        assert(_logic_data);
                }
 
                if (analog_probe_count != 0) {
-                       _analog_data.reset(new data::Analog(_sample_rate));
+                       _analog_data.reset(new data::Analog(*sample_rate));
                        assert(_analog_data);
                }
        }
                        assert(_analog_data);
                }
        }
@@ -240,23 +246,13 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
 
                signals_changed();
        }
 
                signals_changed();
        }
-
-       if (sr_session_start() != SR_OK) {
-               qDebug() << "Failed to start session.";
-               return;
-       }
-
-       set_capture_state(Running);
-
-       sr_session_run();
-       sr_session_destroy();
-
-       set_capture_state(Stopped);
 }
 
 void SigSession::feed_in_meta(const sr_dev_inst *sdi,
        const sr_datafeed_meta &meta)
 {
 }
 
 void SigSession::feed_in_meta(const sr_dev_inst *sdi,
        const sr_datafeed_meta &meta)
 {
+       (void)sdi;
+
        for (const GSList *l = meta.config; l; l = l->next) {
                const sr_config *const src = (const sr_config*)l->data;
                switch (src->key) {
        for (const GSList *l = meta.config; l; l = l->next) {
                const sr_config *const src = (const sr_config*)l->data;
                switch (src->key) {
@@ -321,6 +317,7 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
 
        switch (packet->type) {
        case SR_DF_HEADER:
 
        switch (packet->type) {
        case SR_DF_HEADER:
+               feed_in_header(sdi);
                break;
 
        case SR_DF_META:
                break;
 
        case SR_DF_META: