Reland Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies.

This CL removes copy and assign support from Buffer and changes various
parameters from Buffer to CopyOnWriteBuffer so they can be passed along
and copied without actually copying the underlying data.

With this changed some parameters to be "const" and fixed an issue when
creating a CopyOnWriteBuffer with empty data.

BUG=webrtc:5155

Review URL: https://codereview.webrtc.org/1823503002

Cr-Original-Commit-Position: refs/heads/master@{#12062}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: eec21bdae34bd63ebf568430488d6e25d8db9b4a
diff --git a/media/engine/webrtcvideoengine2.cc b/media/engine/webrtcvideoengine2.cc
index 83f81f0..122edfe 100644
--- a/media/engine/webrtcvideoengine2.cc
+++ b/media/engine/webrtcvideoengine2.cc
@@ -14,7 +14,7 @@
 #include <set>
 #include <string>
 
-#include "webrtc/base/buffer.h"
+#include "webrtc/base/copyonwritebuffer.h"
 #include "webrtc/base/logging.h"
 #include "webrtc/base/stringutils.h"
 #include "webrtc/base/timeutils.h"
@@ -1300,14 +1300,14 @@
 }
 
 void WebRtcVideoChannel2::OnPacketReceived(
-    rtc::Buffer* packet,
+    rtc::CopyOnWriteBuffer* packet,
     const rtc::PacketTime& packet_time) {
   const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp,
                                               packet_time.not_before);
   const webrtc::PacketReceiver::DeliveryStatus delivery_result =
       call_->Receiver()->DeliverPacket(
           webrtc::MediaType::VIDEO,
-          reinterpret_cast<const uint8_t*>(packet->data()), packet->size(),
+          packet->cdata(), packet->size(),
           webrtc_packet_time);
   switch (delivery_result) {
     case webrtc::PacketReceiver::DELIVERY_OK:
@@ -1319,12 +1319,12 @@
   }
 
   uint32_t ssrc = 0;
-  if (!GetRtpSsrc(packet->data(), packet->size(), &ssrc)) {
+  if (!GetRtpSsrc(packet->cdata(), packet->size(), &ssrc)) {
     return;
   }
 
   int payload_type = 0;
-  if (!GetRtpPayloadType(packet->data(), packet->size(), &payload_type)) {
+  if (!GetRtpPayloadType(packet->cdata(), packet->size(), &payload_type)) {
     return;
   }
 
@@ -1350,7 +1350,7 @@
 
   if (call_->Receiver()->DeliverPacket(
           webrtc::MediaType::VIDEO,
-          reinterpret_cast<const uint8_t*>(packet->data()), packet->size(),
+          packet->cdata(), packet->size(),
           webrtc_packet_time) != webrtc::PacketReceiver::DELIVERY_OK) {
     LOG(LS_WARNING) << "Failed to deliver RTP packet on re-delivery.";
     return;
@@ -1358,7 +1358,7 @@
 }
 
 void WebRtcVideoChannel2::OnRtcpReceived(
-    rtc::Buffer* packet,
+    rtc::CopyOnWriteBuffer* packet,
     const rtc::PacketTime& packet_time) {
   const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp,
                                               packet_time.not_before);
@@ -1368,7 +1368,7 @@
   // logging failures spam the log).
   call_->Receiver()->DeliverPacket(
       webrtc::MediaType::VIDEO,
-      reinterpret_cast<const uint8_t*>(packet->data()), packet->size(),
+      packet->cdata(), packet->size(),
       webrtc_packet_time);
 }
 
@@ -1424,14 +1424,14 @@
 bool WebRtcVideoChannel2::SendRtp(const uint8_t* data,
                                   size_t len,
                                   const webrtc::PacketOptions& options) {
-  rtc::Buffer packet(data, len, kMaxRtpPacketLen);
+  rtc::CopyOnWriteBuffer packet(data, len, kMaxRtpPacketLen);
   rtc::PacketOptions rtc_options;
   rtc_options.packet_id = options.packet_id;
   return MediaChannel::SendPacket(&packet, rtc_options);
 }
 
 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) {
-  rtc::Buffer packet(data, len, kMaxRtpPacketLen);
+  rtc::CopyOnWriteBuffer packet(data, len, kMaxRtpPacketLen);
   return MediaChannel::SendRtcp(&packet, rtc::PacketOptions());
 }