From 92e7c69c28b4893686fe484e4b1e7c17759b4577 Mon Sep 17 00:00:00 2001 From: Niels Moller Date: Thu, 14 Feb 2019 14:15:32 +0000 Subject: [PATCH] Revert "Update VP9EncoderImpl to use EncodedImage::Allocate" This reverts commit e12778cb3a7c35b4d3b9d25104841dccd67dc59b. Reason for revert: Suspect for performance regression. Bug: chromium:931692 Original change's description: > Update VP9EncoderImpl to use EncodedImage::Allocate > > Bug: webrtc:9378 > Change-Id: I009138b4dc50c4ceb8f94fee6a958bbfa4d7e326 > Reviewed-on: https://webrtc-review.googlesource.com/c/121771 > Reviewed-by: Rasmus Brandt > Reviewed-by: Philip Eliasson > Commit-Queue: Niels Moller > Cr-Commit-Position: refs/heads/master@{#26593} TBR=brandtr@webrtc.org,nisse@webrtc.org,philipel@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:9378 Change-Id: If056d5604f11b0b77b3f98a3e18d2a5790230760 Reviewed-on: https://webrtc-review.googlesource.com/c/123065 Reviewed-by: Niels Moller Reviewed-by: Philip Eliasson Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#26688} --- modules/video_coding/codecs/vp9/vp9_impl.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/video_coding/codecs/vp9/vp9_impl.cc b/modules/video_coding/codecs/vp9/vp9_impl.cc index b882a4ebca..5feca0b0a9 100644 --- a/modules/video_coding/codecs/vp9/vp9_impl.cc +++ b/modules/video_coding/codecs/vp9/vp9_impl.cc @@ -185,7 +185,10 @@ VP9EncoderImpl::~VP9EncoderImpl() { int VP9EncoderImpl::Release() { int ret_val = WEBRTC_VIDEO_CODEC_OK; - encoded_image_.Allocate(0); + if (encoded_image_.buffer() != nullptr) { + delete[] encoded_image_.buffer(); + encoded_image_.set_buffer(nullptr, 0); + } if (encoder_ != nullptr) { if (inited_) { if (vpx_codec_destroy(encoder_)) { @@ -387,9 +390,12 @@ int VP9EncoderImpl::InitEncode(const VideoCodec* inst, is_svc_ = (num_spatial_layers_ > 1 || num_temporal_layers_ > 1); // Allocate memory for encoded image + if (encoded_image_.data() != nullptr) { + delete[] encoded_image_.data(); + } size_t frame_capacity = CalcBufferSize(VideoType::kI420, codec_.width, codec_.height); - encoded_image_.Allocate(frame_capacity); + encoded_image_.set_buffer(new uint8_t[frame_capacity], frame_capacity); encoded_image_._completeFrame = true; // Populate encoder configuration with default values. if (vpx_codec_enc_config_default(vpx_codec_vp9_cx(), config_, 0)) { @@ -1260,7 +1266,9 @@ int VP9EncoderImpl::GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt) { } if (pkt->data.frame.sz > encoded_image_.capacity()) { - encoded_image_.Allocate(pkt->data.frame.sz); + delete[] encoded_image_.buffer(); + encoded_image_.set_buffer(new uint8_t[pkt->data.frame.sz], + pkt->data.frame.sz); } memcpy(encoded_image_.data(), pkt->data.frame.buf, pkt->data.frame.sz); encoded_image_.set_size(pkt->data.frame.sz);