Bug 1198107 - Destroy VP8 encoder context before re-initing on resolution change to avoid leaking memory. r=jesup, a=sledru
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 25 Aug 2015 16:55:28 +0800
changeset 288950 cf044859a757e0a34fc2078e5e10d4567bb31704
parent 288949 6929efd5d98edc882c7261c0c589b59beee5e6e5
child 288951 80c9f107c3aedea0da43ef1c3769b644b83ec654
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, sledru
bugs1198107
milestone42.0a2
Bug 1198107 - Destroy VP8 encoder context before re-initing on resolution change to avoid leaking memory. r=jesup, a=sledru
media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc
--- a/media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc
+++ b/media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc
@@ -425,16 +425,26 @@ int VP8EncoderImpl::UpdateCodecFrameSize
   // Change of frame size will automatically trigger a key frame.
   config_->g_w = codec_.width;
   config_->g_h = codec_.height;
 #ifndef LIBVPX_ENCODER_CONFIG_ON_RESIZE
   //work around for bug 1030324
   // doing only a configuration change causes
   // horizontal streaking and distortion in the output.
   vpx_codec_flags_t flags = VPX_CODEC_USE_OUTPUT_PARTITION;
+
+  // Re-initing will leak memory so we have to destroy the old context first.
+  if (vpx_codec_destroy(encoder_)) {
+    return WEBRTC_VIDEO_CODEC_MEMORY;
+  }
+
+  // For full paranoia satisfaction we also do a full reset of |encoder_|.
+  delete encoder_;
+  encoder_ = new vpx_codec_ctx_t;
+
   if (vpx_codec_enc_init(encoder_, vpx_codec_vp8_cx(), config_, flags)) {
 #else
   if (vpx_codec_enc_config_set(encoder_, config_)) {
 #endif
     return WEBRTC_VIDEO_CODEC_ERROR;
   }
   return WEBRTC_VIDEO_CODEC_OK;
 }