Bug 1198107 - Destroy VP8 encoder context before re-initing on resolution change to avoid leaking memory. r=jesup, a=sledru
--- 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;
}