X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=df09ff3b2ebc0b924a9158158de9a2362ab385db;hp=773cf8047956d9cd062d5e3d65b3c2e11ecd0c7e;hb=0a4162a4bd844574319f8b26b05f4fcdf837bb70;hpb=fd22c71c1a9cc470b53c71c0ee131a4b2d645f80 diff --git a/pv/session.cpp b/pv/session.cpp index 773cf804..df09ff3b 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program; if not, see . */ #ifdef _WIN32 @@ -106,7 +105,8 @@ Session::Session(DeviceManager &device_manager, QString name) : default_name_(name), name_(name), capture_state_(Stopped), - cur_samplerate_(0) + cur_samplerate_(0), + data_saved_(true) { } @@ -173,6 +173,11 @@ shared_ptr Session::main_bar() const return main_bar_; } +bool Session::data_saved() const +{ + return data_saved_; +} + void Session::save_settings(QSettings &settings) const { map dev_info; @@ -852,10 +857,31 @@ void Session::sample_thread_proc(function error_handler) assert(0); } + // Optimize memory usage + free_unused_memory(); + + // We now have unsaved data unless we just "captured" from a file + shared_ptr file_device = + dynamic_pointer_cast(device_); + + if (!file_device) + data_saved_ = false; + if (out_of_memory_) error_handler(tr("Out of memory, acquisition stopped.")); } +void Session::free_unused_memory() +{ + for (shared_ptr data : all_signal_data_) { + const vector< shared_ptr > segments = data->segments(); + + for (shared_ptr segment : segments) { + segment->free_unused_memory(); + } + } +} + void Session::feed_in_header() { cur_samplerate_ = device_->read_config(ConfigKey::SAMPLERATE); @@ -915,8 +941,6 @@ void Session::feed_in_logic(shared_ptr logic) { lock_guard lock(data_mutex_); - const size_t sample_count = logic->data_length() / logic->unit_size(); - if (!logic_data_) { // The only reason logic_data_ would not have been created is // if it was not possible to determine the signals when the @@ -930,8 +954,7 @@ void Session::feed_in_logic(shared_ptr logic) // Create a new data segment cur_logic_segment_ = shared_ptr( - new data::LogicSegment( - logic, cur_samplerate_, sample_count)); + new data::LogicSegment(logic, cur_samplerate_)); logic_data_->push_segment(cur_logic_segment_); // @todo Putting this here means that only listeners querying @@ -976,8 +999,7 @@ void Session::feed_in_analog(shared_ptr analog) // Create a segment, keep it in the maps of channels segment = shared_ptr( - new data::AnalogSegment( - cur_samplerate_, sample_count)); + new data::AnalogSegment(cur_samplerate_)); cur_analog_segments_[channel] = segment; // Find the analog data associated with the channel @@ -1009,6 +1031,8 @@ void Session::feed_in_analog(shared_ptr analog) void Session::data_feed_in(shared_ptr device, shared_ptr packet) { + static bool frame_began=false; + (void)device; assert(device); @@ -1030,6 +1054,7 @@ void Session::data_feed_in(shared_ptr device, case SR_DF_FRAME_BEGIN: feed_in_frame_begin(); + frame_began = true; break; case SR_DF_LOGIC: @@ -1050,6 +1075,7 @@ void Session::data_feed_in(shared_ptr device, } break; + case SR_DF_FRAME_END: case SR_DF_END: { { @@ -1057,7 +1083,10 @@ void Session::data_feed_in(shared_ptr device, cur_logic_segment_.reset(); cur_analog_segments_.clear(); } - frame_ended(); + if (frame_began) { + frame_began = false; + frame_ended(); + } break; } default: @@ -1065,4 +1094,9 @@ void Session::data_feed_in(shared_ptr device, } } +void Session::on_data_saved() +{ + data_saved_ = true; +} + } // namespace pv