X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fstoresession.cpp;h=5500292a8df777563b624a5365a241bd7e93978b;hp=aa2902375e02bd84e479d382b20e1ab32e4e3951;hb=3d79f521396c8e908fd237f5328153165099f5c3;hpb=a38268f064687eff3e5395da6bb7f39e55dcd60f diff --git a/pv/storesession.cpp b/pv/storesession.cpp index aa290237..5500292a 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -20,6 +20,14 @@ #include +#ifdef _WIN32 +// Windows: Avoid boost/thread namespace pollution (which includes windows.h). +#define NOGDI +#define NORESOURCE +#endif +#include +#include + #include "storesession.hpp" #include @@ -55,6 +63,7 @@ using Glib::VariantBase; using sigrok::ConfigKey; using sigrok::Error; using sigrok::OutputFormat; +using sigrok::OutputFlag; namespace pv { @@ -62,10 +71,13 @@ const size_t StoreSession::BlockSize = 1024 * 1024; StoreSession::StoreSession(const std::string &file_name, const shared_ptr &output_format, - const map &options, const Session &session) : + const map &options, + const std::pair sample_range, + const Session &session) : file_name_(file_name), output_format_(output_format), options_(options), + sample_range_(sample_range), session_(session), interrupt_(false), units_stored_(0), @@ -91,8 +103,7 @@ const QString& StoreSession::error() const bool StoreSession::start() { - shared_lock lock(session_.signals_mutex()); - const unordered_set< shared_ptr > &sigs(session_.signals()); + const unordered_set< shared_ptr > sigs(session_.signals()); // Add enabled channels to the data set set< shared_ptr > data_set; @@ -133,6 +144,15 @@ bool StoreSession::start() const shared_ptr segment(segments.front()); assert(segment); + // Check whether the user wants to export a certain sample range + if (sample_range_.first == sample_range_.second) { + start_sample_ = 0; + sample_count_ = segment->get_sample_count(); + } else { + start_sample_ = std::min(sample_range_.first, sample_range_.second); + sample_count_ = std::abs(sample_range_.second - sample_range_.first); + } + // Begin storing try { const auto context = session_.device_manager().context(); @@ -140,8 +160,9 @@ bool StoreSession::start() map options = options_; - output_stream_.open(file_name_, ios_base::binary | - ios_base::trunc | ios_base::out); + if (!output_format_->test_flag(OutputFlag::INTERNAL_IO_HANDLING)) + output_stream_.open(file_name_, ios_base::binary | + ios_base::trunc | ios_base::out); output_ = output_format_->create_output(file_name_, device, options); auto meta = context->create_meta_packet( @@ -172,7 +193,6 @@ void StoreSession::store_proc(shared_ptr segment) { assert(segment); - uint64_t start_sample = 0, sample_count; unsigned progress_scale = 0; /// TODO: Wrap this in a std::unique_ptr when we transition to C++11 @@ -182,26 +202,25 @@ void StoreSession::store_proc(shared_ptr segment) const int unit_size = segment->unit_size(); assert(unit_size != 0); - sample_count = segment->get_sample_count(); - - // Qt needs the progress values to fit inside an int. If they would + // Qt needs the progress values to fit inside an int. If they would // not, scale the current and max values down until they do. - while ((sample_count >> progress_scale) > INT_MAX) + while ((sample_count_ >> progress_scale) > INT_MAX) progress_scale ++; - unit_count_ = sample_count >> progress_scale; + unit_count_ = sample_count_ >> progress_scale; const unsigned int samples_per_block = BlockSize / unit_size; - while (!interrupt_ && start_sample < sample_count) + while (!interrupt_ && sample_count_) { progress_updated(); - const uint64_t end_sample = min( - start_sample + samples_per_block, sample_count); - segment->get_samples(data, start_sample, end_sample); + const uint64_t packet_len = + std::min((uint64_t)samples_per_block, sample_count_); + + segment->get_samples(data, start_sample_, start_sample_ + packet_len); - size_t length = (end_sample - start_sample) * unit_size; + size_t length = packet_len * unit_size; try { const auto context = session_.device_manager().context(); @@ -214,8 +233,9 @@ void StoreSession::store_proc(shared_ptr segment) break; } - start_sample = end_sample; - units_stored_ = start_sample >> progress_scale; + sample_count_ -= packet_len; + start_sample_ += packet_len; + units_stored_ = unit_count_ - (sample_count_ >> progress_scale); } // Zeroing the progress variables indicates completion