Add implicit conversion between rtc:PacketTime and int64_t.

This is a preparation for deleting rtc::PacketTime. Next step, after
downstream code has been updated to not access the |timestamp| member,
is to make rtc::PacketTime an alias for int64_t.

Also delete the unused member rtc::PacketTime::not_before.

Bug: webrtc:9584
Change-Id: Iba9d2d55047d69565ad62b1beb525591fd432ae2
Reviewed-on: https://webrtc-review.googlesource.com/c/108860
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25468}
diff --git a/media/base/fakenetworkinterface.h b/media/base/fakenetworkinterface.h
index 0f14659..dfd3407 100644
--- a/media/base/fakenetworkinterface.h
+++ b/media/base/fakenetworkinterface.h
@@ -169,9 +169,9 @@
         static_cast<rtc::TypedMessageData<rtc::CopyOnWriteBuffer>*>(msg->pdata);
     if (dest_) {
       if (msg->message_id == ST_RTP) {
-        dest_->OnPacketReceived(&msg_data->data(), rtc::CreatePacketTime(0));
+        dest_->OnPacketReceived(&msg_data->data(), rtc::TimeMicros());
       } else {
-        dest_->OnRtcpReceived(&msg_data->data(), rtc::CreatePacketTime(0));
+        dest_->OnRtcpReceived(&msg_data->data(), rtc::TimeMicros());
       }
     }
     delete msg_data;
diff --git a/media/engine/webrtcvideoengine.cc b/media/engine/webrtcvideoengine.cc
index d0f12c0..e376667 100644
--- a/media/engine/webrtcvideoengine.cc
+++ b/media/engine/webrtcvideoengine.cc
@@ -1379,7 +1379,7 @@
                                           const rtc::PacketTime& packet_time) {
   const webrtc::PacketReceiver::DeliveryStatus delivery_result =
       call_->Receiver()->DeliverPacket(webrtc::MediaType::VIDEO, *packet,
-                                       packet_time.timestamp);
+                                       packet_time);
   switch (delivery_result) {
     case webrtc::PacketReceiver::DELIVERY_OK:
       return;
@@ -1427,7 +1427,7 @@
   }
 
   if (call_->Receiver()->DeliverPacket(webrtc::MediaType::VIDEO, *packet,
-                                       packet_time.timestamp) !=
+                                       packet_time) !=
       webrtc::PacketReceiver::DELIVERY_OK) {
     RTC_LOG(LS_WARNING) << "Failed to deliver RTP packet on re-delivery.";
     return;
@@ -1441,7 +1441,7 @@
   // filter RTCP anymore incoming RTCP packets could've been going to audio (so
   // logging failures spam the log).
   call_->Receiver()->DeliverPacket(webrtc::MediaType::VIDEO, *packet,
-                                   packet_time.timestamp);
+                                   packet_time);
 }
 
 void WebRtcVideoChannel::OnReadyToSend(bool ready) {
diff --git a/media/engine/webrtcvoiceengine.cc b/media/engine/webrtcvoiceengine.cc
index 4fc25cb..f63eb3e 100644
--- a/media/engine/webrtcvoiceengine.cc
+++ b/media/engine/webrtcvoiceengine.cc
@@ -2036,7 +2036,7 @@
 
   webrtc::PacketReceiver::DeliveryStatus delivery_result =
       call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, *packet,
-                                       packet_time.timestamp);
+                                       packet_time);
   if (delivery_result != webrtc::PacketReceiver::DELIVERY_UNKNOWN_SSRC) {
     return;
   }
@@ -2088,8 +2088,8 @@
     SetRawAudioSink(ssrc, std::move(proxy_sink));
   }
 
-  delivery_result = call_->Receiver()->DeliverPacket(
-      webrtc::MediaType::AUDIO, *packet, packet_time.timestamp);
+  delivery_result = call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO,
+                                                     *packet, packet_time);
   RTC_DCHECK_NE(webrtc::PacketReceiver::DELIVERY_UNKNOWN_SSRC, delivery_result);
 }
 
@@ -2100,7 +2100,7 @@
 
   // Forward packet to Call as well.
   call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, *packet,
-                                   packet_time.timestamp);
+                                   packet_time);
 }
 
 void WebRtcVoiceMediaChannel::OnNetworkRouteChanged(
diff --git a/p2p/base/asyncstuntcpsocket.cc b/p2p/base/asyncstuntcpsocket.cc
index 8bb796f..d0185c3 100644
--- a/p2p/base/asyncstuntcpsocket.cc
+++ b/p2p/base/asyncstuntcpsocket.cc
@@ -112,7 +112,7 @@
     }
 
     SignalReadPacket(this, data, expected_pkt_len, remote_addr,
-                     rtc::CreatePacketTime(0));
+                     rtc::TimeMicros());
 
     *len -= actual_length;
     if (*len > 0) {
diff --git a/p2p/base/dtlstransport.cc b/p2p/base/dtlstransport.cc
index eaf0540..9b74c1c 100644
--- a/p2p/base/dtlstransport.cc
+++ b/p2p/base/dtlstransport.cc
@@ -652,7 +652,7 @@
     do {
       ret = dtls_->Read(buf, sizeof(buf), &read, &read_error);
       if (ret == rtc::SR_SUCCESS) {
-        SignalReadPacket(this, buf, read, rtc::CreatePacketTime(0), 0);
+        SignalReadPacket(this, buf, read, rtc::TimeMicros(), 0);
       } else if (ret == rtc::SR_EOS) {
         // Remote peer shut down the association with no error.
         RTC_LOG(LS_INFO) << ToString() << ": DTLS transport closed";
diff --git a/p2p/base/fakeicetransport.h b/p2p/base/fakeicetransport.h
index 646aed4..652e69d 100644
--- a/p2p/base/fakeicetransport.h
+++ b/p2p/base/fakeicetransport.h
@@ -266,7 +266,7 @@
     if (dest_) {
       last_sent_packet_ = packet;
       dest_->SignalReadPacket(dest_, packet.data<char>(), packet.size(),
-                              rtc::CreatePacketTime(0), 0);
+                              rtc::TimeMicros(), 0);
     }
   }
 
diff --git a/p2p/base/fakepackettransport.h b/p2p/base/fakepackettransport.h
index e57bc17..52b3921 100644
--- a/p2p/base/fakepackettransport.h
+++ b/p2p/base/fakepackettransport.h
@@ -119,7 +119,7 @@
     last_sent_packet_ = packet;
     if (dest_) {
       dest_->SignalReadPacket(dest_, packet.data<char>(), packet.size(),
-                              CreatePacketTime(0), 0);
+                              TimeMicros(), 0);
     }
   }
 
diff --git a/p2p/base/p2ptransportchannel_unittest.cc b/p2p/base/p2ptransportchannel_unittest.cc
index ce89b99..99151cb 100644
--- a/p2p/base/p2ptransportchannel_unittest.cc
+++ b/p2p/base/p2ptransportchannel_unittest.cc
@@ -3203,7 +3203,7 @@
     msg.AddFingerprint();
     rtc::ByteBufferWriter buf;
     msg.Write(&buf);
-    conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0));
+    conn->OnReadPacket(buf.Data(), buf.Length(), rtc::TimeMicros());
   }
 
   void OnReadyToSend(rtc::PacketTransportInternal* transport) {
@@ -3612,7 +3612,7 @@
 
   clock.AdvanceTime(webrtc::TimeDelta::seconds(1));
   conn1->ReceivedPing();
-  conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
+  conn1->OnReadPacket("ABC", 3, rtc::TimeMicros());
   EXPECT_TRUE_SIMULATED_WAIT(ch.receiving(), kShortTimeout, clock);
   EXPECT_TRUE_SIMULATED_WAIT(!ch.receiving(), kShortTimeout, clock);
 }
@@ -3803,7 +3803,7 @@
   Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
   ASSERT_TRUE(conn2 != nullptr);
   conn2->ReceivedPingResponse(LOW_RTT, "id");  // Become writable and receiving.
-  conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
+  conn2->OnReadPacket("ABC", 3, rtc::TimeMicros());
   EXPECT_EQ(conn2, ch.selected_connection());
   conn2->ReceivedPingResponse(LOW_RTT, "id");  // Become writable.
 
@@ -3831,7 +3831,7 @@
   // selected connection was nominated by the controlling side.
   conn2->ReceivedPing();
   conn2->ReceivedPingResponse(LOW_RTT, "id");
-  conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
+  conn2->OnReadPacket("XYZ", 3, rtc::TimeMicros());
   EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout);
 }
 
@@ -3860,12 +3860,12 @@
   // Advance the clock by 1ms so that the last data receiving timestamp of
   // conn2 is larger.
   SIMULATED_WAIT(false, 1, clock);
-  conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
+  conn2->OnReadPacket("XYZ", 3, rtc::TimeMicros());
   EXPECT_EQ(1, reset_selected_candidate_pair_switches());
   EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn2));
 
   // conn1 also receives data; it becomes selected due to priority again.
-  conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
+  conn1->OnReadPacket("XYZ", 3, rtc::TimeMicros());
   EXPECT_EQ(1, reset_selected_candidate_pair_switches());
   EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn2));
 
@@ -3874,7 +3874,7 @@
   SIMULATED_WAIT(false, 1, clock);
   // Need to become writable again because it was pruned.
   conn2->ReceivedPingResponse(LOW_RTT, "id");
-  conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
+  conn2->OnReadPacket("XYZ", 3, rtc::TimeMicros());
   EXPECT_EQ(1, reset_selected_candidate_pair_switches());
   EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn2));
 
@@ -3904,7 +3904,7 @@
   // conn1 received data; it is the selected connection.
   // Advance the clock to have a non-zero last-data-receiving time.
   SIMULATED_WAIT(false, 1, clock);
-  conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
+  conn1->OnReadPacket("XYZ", 3, rtc::TimeMicros());
   EXPECT_EQ(1, reset_selected_candidate_pair_switches());
   EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn1));
 
@@ -4125,7 +4125,7 @@
   // conn2.
   NominateConnection(conn1);
   SIMULATED_WAIT(false, 1, clock);
-  conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
+  conn1->OnReadPacket("XYZ", 3, rtc::TimeMicros());
   SIMULATED_WAIT(conn2->pruned(), 100, clock);
   EXPECT_FALSE(conn2->pruned());
 }
diff --git a/p2p/base/turnport_unittest.cc b/p2p/base/turnport_unittest.cc
index 16f89e9..6100dbe 100644
--- a/p2p/base/turnport_unittest.cc
+++ b/p2p/base/turnport_unittest.cc
@@ -1031,8 +1031,7 @@
   std::string test_packet = "Test packet";
   EXPECT_FALSE(turn_port_->HandleIncomingPacket(
       socket_.get(), test_packet.data(), test_packet.size(),
-      rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0),
-      rtc::CreatePacketTime(0)));
+      rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), rtc::TimeMicros()));
 }
 
 // Tests that a shared-socket-TurnPort creates its own socket after
diff --git a/pc/channel.cc b/pc/channel.cc
index 8e1d5ff..6a16eb3 100644
--- a/pc/channel.cc
+++ b/pc/channel.cc
@@ -446,9 +446,8 @@
   if (parsed_packet.arrival_time_ms() > 0) {
     timestamp = parsed_packet.arrival_time_ms() * 1000;
   }
-  rtc::PacketTime packet_time(timestamp, /*not_before=*/0);
 
-  OnPacketReceived(/*rtcp=*/false, parsed_packet.Buffer(), packet_time);
+  OnPacketReceived(/*rtcp=*/false, parsed_packet.Buffer(), timestamp);
 }
 
 void BaseChannel::UpdateRtpHeaderExtensionMap(
diff --git a/pc/rtptransport.cc b/pc/rtptransport.cc
index 9e994e9..c510359 100644
--- a/pc/rtptransport.cc
+++ b/pc/rtptransport.cc
@@ -195,8 +195,8 @@
     return;
   }
 
-  if (time.timestamp != -1) {
-    parsed_packet.set_arrival_time_ms((time.timestamp + 500) / 1000);
+  if (time != -1) {
+    parsed_packet.set_arrival_time_ms((time + 500) / 1000);
   }
   rtp_demuxer_.OnRtpPacket(parsed_packet);
 }
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index e16648a..3f02fb7 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -699,6 +699,9 @@
   defines = []
   deps = [
     ":checks",
+
+    # For deprecation of rtc::PacketTime, in asyncpacketsocket.h.
+    ":deprecation",
     ":stringutils",
     "..:webrtc_common",
     "../api:array_view",
diff --git a/rtc_base/asyncpacketsocket.h b/rtc_base/asyncpacketsocket.h
index bb0b3bc..e671f0d 100644
--- a/rtc_base/asyncpacketsocket.h
+++ b/rtc_base/asyncpacketsocket.h
@@ -12,6 +12,7 @@
 #define RTC_BASE_ASYNCPACKETSOCKET_H_
 
 #include "rtc_base/constructormagic.h"
+#include "rtc_base/deprecation.h"
 #include "rtc_base/dscp.h"
 #include "rtc_base/socket.h"
 #include "rtc_base/third_party/sigslot/sigslot.h"
@@ -53,21 +54,21 @@
 // This structure will have the information about when packet is actually
 // received by socket.
 struct PacketTime {
-  PacketTime() : timestamp(-1), not_before(-1) {}
-  PacketTime(int64_t timestamp, int64_t not_before)
-      : timestamp(timestamp), not_before(not_before) {}
+  PacketTime() : timestamp(-1) {}
+  // Intentionally implicit.
+  PacketTime(int64_t timestamp) : timestamp(timestamp) {}
+  // Deprecated
+  PacketTime(int64_t timestamp, int64_t /* not_before */)
+      : timestamp(timestamp) {}
+
+  operator int64_t() const { return timestamp; }
 
   int64_t timestamp;  // Receive time after socket delivers the data.
-
-  // Earliest possible time the data could have arrived, indicating the
-  // potential error in the |timestamp| value, in case the system, is busy. For
-  // example, the time of the last select() call.
-  // If unknown, this value will be set to zero.
-  int64_t not_before;
 };
 
-inline PacketTime CreatePacketTime(int64_t not_before) {
-  return PacketTime(TimeMicros(), not_before);
+// Deprecated
+inline PacketTime CreatePacketTime(int64_t /* not_before */) {
+  return TimeMicros();
 }
 
 // Provides the ability to receive packets asynchronously. Sends are not
diff --git a/rtc_base/asynctcpsocket.cc b/rtc_base/asynctcpsocket.cc
index 087a98e..666b335 100644
--- a/rtc_base/asynctcpsocket.cc
+++ b/rtc_base/asynctcpsocket.cc
@@ -321,7 +321,7 @@
       return;
 
     SignalReadPacket(this, data + kPacketLenSize, pkt_len, remote_addr,
-                     CreatePacketTime(0));
+                     TimeMicros());
 
     *len -= kPacketLenSize + pkt_len;
     if (*len > 0) {
diff --git a/rtc_base/asyncudpsocket.cc b/rtc_base/asyncudpsocket.cc
index 9cd9e14..2f9011c 100644
--- a/rtc_base/asyncudpsocket.cc
+++ b/rtc_base/asyncudpsocket.cc
@@ -122,9 +122,8 @@
 
   // TODO: Make sure that we got all of the packet.
   // If we did not, then we should resize our buffer to be large enough.
-  SignalReadPacket(
-      this, buf_, static_cast<size_t>(len), remote_addr,
-      (timestamp > -1 ? PacketTime(timestamp, 0) : CreatePacketTime(0)));
+  SignalReadPacket(this, buf_, static_cast<size_t>(len), remote_addr,
+                   (timestamp > -1 ? timestamp : TimeMicros()));
 }
 
 void AsyncUDPSocket::OnWriteEvent(AsyncSocket* socket) {
diff --git a/rtc_base/testclient.cc b/rtc_base/testclient.cc
index 7c151c7..56a9f8c 100644
--- a/rtc_base/testclient.cc
+++ b/rtc_base/testclient.cc
@@ -97,7 +97,7 @@
   std::unique_ptr<Packet> packet = NextPacket(kTimeoutMs);
   if (packet) {
     res = (packet->size == size && memcmp(packet->buf, buf, size) == 0 &&
-           CheckTimestamp(packet->packet_time.timestamp));
+           CheckTimestamp(packet->packet_time));
     if (addr)
       *addr = packet->addr;
   }
diff --git a/rtc_tools/network_tester/test_controller.cc b/rtc_tools/network_tester/test_controller.cc
index e5bd92e..4bdc993 100644
--- a/rtc_tools/network_tester/test_controller.cc
+++ b/rtc_tools/network_tester/test_controller.cc
@@ -109,7 +109,7 @@
       break;
     }
     case NetworkTesterPacket::TEST_DATA: {
-      packet.set_arrival_timestamp(packet_time.timestamp);
+      packet.set_arrival_timestamp(packet_time);
       packet.set_packet_size(len);
       packet_logger_.LogPacket(packet);
       break;