X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fdevices%2Finputfile.cpp;h=4ffd2dfa22cbc702d6ad7dfeb476042ec2d73639;hb=727083851e431c1a0303347550d5ace9ea6962d1;hp=7c981f1acd926bfd13054e186292b60d36d3a971;hpb=efdec55aec1a137460fa362a381ed1904182bfed;p=pulseview.git diff --git a/pv/devices/inputfile.cpp b/pv/devices/inputfile.cpp index 7c981f1..4ffd2df 100644 --- a/pv/devices/inputfile.cpp +++ b/pv/devices/inputfile.cpp @@ -19,20 +19,32 @@ #include #include +#include #include #include "inputfile.hpp" +using std::map; +using std::shared_ptr; +using std::streamsize; +using std::string; +using std::ifstream; +using std::ios; +using std::vector; + namespace pv { namespace devices { -const std::streamsize InputFile::BufferSize = 16384; +// Use a 4MB chunk size for reading a file into memory. Larger values don't +// seem to provide any substancial performance improvements, but can cause +// UI lag and a visually "stuttering" display of the data currently loading. +const streamsize InputFile::BufferSize = (4 * 1024 * 1024); -InputFile::InputFile(const std::shared_ptr &context, - const std::string &file_name, - std::shared_ptr format, - const std::map &options) : +InputFile::InputFile(const shared_ptr &context, + const string &file_name, + shared_ptr format, + const map &options) : File(file_name), context_(context), format_(format), @@ -55,19 +67,20 @@ void InputFile::open() // open() should add the input device to the session but // we can't open the device without sending some data first - f = new std::ifstream(file_name_, std::ios::binary); + f = new ifstream(file_name_, ios::binary); + + vector buffer(BufferSize); - char buffer[BufferSize]; - f->read(buffer, BufferSize); - const std::streamsize size = f->gcount(); + f->read(buffer.data(), BufferSize); + const streamsize size = f->gcount(); if (size == 0) return; - input_->send(buffer, size); + input_->send(buffer.data(), size); try { device_ = input_->device(); - } catch (sigrok::Error) { + } catch (sigrok::Error&) { return; } @@ -86,22 +99,22 @@ void InputFile::start() void InputFile::run() { - char buffer[BufferSize]; - if (!f) { // Previous call to run() processed the entire file already - f = new std::ifstream(file_name_, std::ios::binary); + f = new ifstream(file_name_, ios::binary); input_->reset(); } + vector buffer(BufferSize); + interrupt_ = false; while (!interrupt_ && !f->eof()) { - f->read(buffer, BufferSize); - const std::streamsize size = f->gcount(); + f->read(buffer.data(), BufferSize); + const streamsize size = f->gcount(); if (size == 0) break; - input_->send(buffer, size); + input_->send(buffer.data(), size); if (size != BufferSize) break;