]> sigrok.org Git - pulseview.git/blobdiff - pv/storesession.cpp
Fix #615 by opening the output stream only if needed
[pulseview.git] / pv / storesession.cpp
index 1a27e5654dd9e8e66ec96fb0d773a96ad83536f0..9a30c24379b37a691af0750640997211ee725603 100644 (file)
@@ -55,6 +55,7 @@ using Glib::VariantBase;
 using sigrok::ConfigKey;
 using sigrok::Error;
 using sigrok::OutputFormat;
+using sigrok::OutputFlag;
 
 namespace pv {
 
@@ -91,12 +92,15 @@ const QString& StoreSession::error() const
 
 bool StoreSession::start()
 {
-       set< shared_ptr<data::SignalData> > data_set =
-               session_.get_data();
-
        shared_lock<shared_mutex> lock(session_.signals_mutex());
-       const unordered_set< shared_ptr<view::Signal> > &sigs(
-               session_.signals());
+       const unordered_set< shared_ptr<view::Signal> > &sigs(session_.signals());
+
+       // Add enabled channels to the data set
+       set< shared_ptr<data::SignalData> > data_set;
+
+       for (shared_ptr<view::Signal> signal : sigs)
+               if (signal->enabled())
+                       data_set.insert(signal->data());
 
        // Check we have logic data
        if (data_set.empty() || sigs.empty()) {
@@ -114,7 +118,7 @@ bool StoreSession::start()
        shared_ptr<data::Logic> data;
        if (!(data = dynamic_pointer_cast<data::Logic>(*data_set.begin()))) {
                error_ = tr("PulseView currently only has support for "
-                       "storing logic data.");
+                       "storing logic data.");
                return false;
        }
 
@@ -137,17 +141,11 @@ bool StoreSession::start()
 
                map<string, Glib::VariantBase> options = options_;
 
-               // If the output has the capability to write files, use it.
-               // Otherwise, open the output stream.
-               const auto opt_list = output_format_->options();
-               if (opt_list.find("filename") != opt_list.end())
-                       options["filename"] =
-                               Glib::Variant<Glib::ustring>::create(file_name_);
-               else
+               if (!output_format_->test_flag(OutputFlag::INTERNAL_IO_HANDLING))
                        output_stream_.open(file_name_, ios_base::binary |
-                               ios_base::trunc | ios_base::out);
+                                       ios_base::trunc | ios_base::out);
 
-               output_ = output_format_->create_output(device, options);
+               output_ = output_format_->create_output(file_name_, device, options);
                auto meta = context->create_meta_packet(
                        {{ConfigKey::SAMPLERATE, Glib::Variant<guint64>::create(
                                segment->samplerate())}});
@@ -205,7 +203,7 @@ void StoreSession::store_proc(shared_ptr<data::LogicSegment> segment)
                        start_sample + samples_per_block, sample_count);
                segment->get_samples(data, start_sample, end_sample);
 
-               size_t length = end_sample - start_sample;
+               size_t length = (end_sample - start_sample) * unit_size;
 
                try {
                        const auto context = session_.device_manager().context();