Convert all webrtc code to not access EncodedImage::_size directly.

Read using capacity() method, write using set_buffer() method. This is
a preparation for making the member private, and renaming it to
capacity_.

Bug: webrtc:9378
Change-Id: I2f96679d052a83fe81be40301bd9863c87074640
Reviewed-on: https://webrtc-review.googlesource.com/c/113520
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25934}
diff --git a/modules/video_coding/codecs/vp9/vp9_impl.cc b/modules/video_coding/codecs/vp9/vp9_impl.cc
index 7bb2ea2..3fc0cd8 100644
--- a/modules/video_coding/codecs/vp9/vp9_impl.cc
+++ b/modules/video_coding/codecs/vp9/vp9_impl.cc
@@ -395,9 +395,9 @@
   if (encoded_image_._buffer != nullptr) {
     delete[] encoded_image_._buffer;
   }
-  encoded_image_._size =
+  size_t frame_capacity =
       CalcBufferSize(VideoType::kI420, codec_.width, codec_.height);
-  encoded_image_._buffer = new uint8_t[encoded_image_._size];
+  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)) {
@@ -1257,10 +1257,10 @@
     DeliverBufferedFrame(end_of_picture);
   }
 
-  if (pkt->data.frame.sz > encoded_image_._size) {
+  if (pkt->data.frame.sz > encoded_image_.capacity()) {
     delete[] encoded_image_._buffer;
-    encoded_image_._size = pkt->data.frame.sz;
-    encoded_image_._buffer = new uint8_t[encoded_image_._size];
+    encoded_image_.set_buffer(new uint8_t[pkt->data.frame.sz],
+                              pkt->data.frame.sz);
   }
   memcpy(encoded_image_._buffer, pkt->data.frame.buf, pkt->data.frame.sz);
   encoded_image_._length = pkt->data.frame.sz;
@@ -1276,7 +1276,7 @@
     encoded_image_._frameType = kVideoFrameKey;
     force_key_frame_ = false;
   }
-  RTC_DCHECK_LE(encoded_image_._length, encoded_image_._size);
+  RTC_DCHECK_LE(encoded_image_._length, encoded_image_.capacity());
 
   memset(&codec_specific_, 0, sizeof(codec_specific_));
   absl::optional<int> spatial_index;