From e1068c1bc911fa6db3d7cdcee549eead5305f64a Mon Sep 17 00:00:00 2001 From: Elad Alon Date: Tue, 23 Apr 2019 14:37:48 +0200 Subject: [PATCH] Small change to LibvpxVp8Encoder::Release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function iterated over two containers, destroyed their elements and popped those elements one at a time. It's more efficient to destroy all of the elements, then clear() the container. Bug: None Change-Id: I17aa88694ee41df64c5793b08b96899b7ff04071 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/133901 Reviewed-by: Erik Språng Commit-Queue: Elad Alon Cr-Commit-Position: refs/heads/master@{#27730} --- .../codecs/vp8/libvpx_vp8_encoder.cc | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc b/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc index a6ac532520..57611f22c4 100644 --- a/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc +++ b/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc @@ -271,6 +271,8 @@ LibvpxVp8Encoder::LibvpxVp8Encoder( "WebRTC-VP8VariableFramerateScreenshare")), framerate_controller_(variable_framerate_experiment_.framerate_limit), num_steady_state_frames_(0) { + // TODO(eladalon/ilnik): These reservations might be wasting memory. + // InitEncode() is resizing to the actual size, which might be smaller. raw_images_.reserve(kMaxSimulcastStreams); encoded_images_.reserve(kMaxSimulcastStreams); send_stream_.reserve(kMaxSimulcastStreams); @@ -289,22 +291,24 @@ int LibvpxVp8Encoder::Release() { encoded_images_.clear(); - while (!encoders_.empty()) { - vpx_codec_ctx_t& encoder = encoders_.back(); - if (inited_) { - if (libvpx_->codec_destroy(&encoder)) { + if (inited_) { + for (auto it = encoders_.rbegin(); it != encoders_.rend(); ++it) { + if (libvpx_->codec_destroy(&*it)) { ret_val = WEBRTC_VIDEO_CODEC_MEMORY; } } - encoders_.pop_back(); } + encoders_.clear(); + configurations_.clear(); send_stream_.clear(); cpu_speed_.clear(); - while (!raw_images_.empty()) { - libvpx_->img_free(&raw_images_.back()); - raw_images_.pop_back(); + + for (auto it = raw_images_.rbegin(); it != raw_images_.rend(); ++it) { + libvpx_->img_free(&*it); } + raw_images_.clear(); + frame_buffer_controller_.reset(); inited_ = false; return ret_val;