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 282077 f5080b93ad6faf3f9ebb708c44df303fc1132f89
parent 282076 cc5c3cf9f4d60c99a17524fedda335f5a03cc859
child 282078 c5bedbd20067353873377da658e7eae957812272
push id5003
push userryanvm@gmail.com
push dateFri, 28 Aug 2015 15:43:16 +0000
treeherdermozilla-beta@c5bedbd20067 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, sledru
bugs1198107
milestone41.0
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;
 }