Add owned data buffer to EncodedImage

Bug: webrtc:9378
Change-Id: I6a66b9301cbadf1d6517bf7a96028099970a20a3
Reviewed-on: https://webrtc-review.googlesource.com/c/117964
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26585}
diff --git a/modules/video_coding/encoded_frame.cc b/modules/video_coding/encoded_frame.cc
index aff9c5a..c18ef13 100644
--- a/modules/video_coding/encoded_frame.cc
+++ b/modules/video_coding/encoded_frame.cc
@@ -31,15 +31,7 @@
 }
 
 VCMEncodedFrame::~VCMEncodedFrame() {
-  Free();
-}
-
-void VCMEncodedFrame::Free() {
   Reset();
-  if (data() != nullptr) {
-    delete[] data();
-    set_buffer(nullptr, 0);
-  }
 }
 
 void VCMEncodedFrame::Reset() {
@@ -156,15 +148,10 @@
 void VCMEncodedFrame::VerifyAndAllocate(size_t minimumSize) {
   size_t old_capacity = capacity();
   if (minimumSize > old_capacity) {
-    // create buffer of sufficient size
-    uint8_t* old_data = data();
-
-    set_buffer(new uint8_t[minimumSize], minimumSize);
-    if (old_data) {
-      // copy old data
-      memcpy(data(), old_data, old_capacity);
-      delete[] old_data;
-    }
+    // TODO(nisse): EncodedImage::Allocate is implemented as
+    // std::vector::resize, which means that old contents is kept. Find out if
+    // any code depends on that behavior.
+    Allocate(minimumSize);
   }
 }