Refactor Android Voip client to use rtc::ReceivedPackets

Instead of using raw pointers.

Bug: webrtc:11943
Change-Id: I39ce45868d95aca44f32cfed27c91986f9c3278a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/331480
Commit-Queue: Per Kjellander <perkj@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41384}
diff --git a/examples/androidvoip/BUILD.gn b/examples/androidvoip/BUILD.gn
index cea05ea..d390815 100644
--- a/examples/androidvoip/BUILD.gn
+++ b/examples/androidvoip/BUILD.gn
@@ -71,7 +71,7 @@
       "//api/task_queue:default_task_queue_factory",
       "//api/voip:voip_api",
       "//api/voip:voip_engine_factory",
-      "//rtc_base/third_party/sigslot:sigslot",
+      "//rtc_base/network:received_packet",
       "//sdk/android:native_api_audio_device_module",
       "//sdk/android:native_api_base",
       "//sdk/android:native_api_jni",
diff --git a/examples/androidvoip/jni/android_voip_client.cc b/examples/androidvoip/jni/android_voip_client.cc
index 8a0a3ba..6932799 100644
--- a/examples/androidvoip/jni/android_voip_client.cc
+++ b/examples/androidvoip/jni/android_voip_client.cc
@@ -313,8 +313,10 @@
                                             /*isSuccessful=*/false);
     return;
   }
-  rtp_socket_->SignalReadPacket.connect(
-      this, &AndroidVoipClient::OnSignalReadRTPPacket);
+  rtp_socket_->RegisterReceivedPacketCallback(
+      [&](rtc::AsyncPacketSocket* socket, const rtc::ReceivedPacket& packet) {
+        OnSignalReadRTPPacket(socket, packet);
+      });
 
   rtcp_socket_.reset(rtc::AsyncUDPSocket::Create(voip_thread_->socketserver(),
                                                  rtcp_local_address_));
@@ -324,8 +326,10 @@
                                             /*isSuccessful=*/false);
     return;
   }
-  rtcp_socket_->SignalReadPacket.connect(
-      this, &AndroidVoipClient::OnSignalReadRTCPPacket);
+  rtcp_socket_->RegisterReceivedPacketCallback(
+      [&](rtc::AsyncPacketSocket* socket, const rtc::ReceivedPacket& packet) {
+        OnSignalReadRTCPPacket(socket, packet);
+      });
   Java_VoipClient_onStartSessionCompleted(env_, j_voip_client_,
                                           /*isSuccessful=*/true);
 }
@@ -467,12 +471,11 @@
   RTC_CHECK(result == webrtc::VoipResult::kOk);
 }
 
-void AndroidVoipClient::OnSignalReadRTPPacket(rtc::AsyncPacketSocket* socket,
-                                              const char* rtp_packet,
-                                              size_t size,
-                                              const rtc::SocketAddress& addr,
-                                              const int64_t& timestamp) {
-  std::vector<uint8_t> packet_copy(rtp_packet, rtp_packet + size);
+void AndroidVoipClient::OnSignalReadRTPPacket(
+    rtc::AsyncPacketSocket* socket,
+    const rtc::ReceivedPacket& packet) {
+  std::vector<uint8_t> packet_copy(packet.payload().begin(),
+                                   packet.payload().end());
   voip_thread_->PostTask([this, packet_copy = std::move(packet_copy)] {
     ReadRTPPacket(packet_copy);
   });
@@ -492,12 +495,11 @@
   RTC_CHECK(result == webrtc::VoipResult::kOk);
 }
 
-void AndroidVoipClient::OnSignalReadRTCPPacket(rtc::AsyncPacketSocket* socket,
-                                               const char* rtcp_packet,
-                                               size_t size,
-                                               const rtc::SocketAddress& addr,
-                                               const int64_t& timestamp) {
-  std::vector<uint8_t> packet_copy(rtcp_packet, rtcp_packet + size);
+void AndroidVoipClient::OnSignalReadRTCPPacket(
+    rtc::AsyncPacketSocket* socket,
+    const rtc::ReceivedPacket& packet) {
+  std::vector<uint8_t> packet_copy(packet.payload().begin(),
+                                   packet.payload().end());
   voip_thread_->PostTask([this, packet_copy = std::move(packet_copy)] {
     ReadRTCPPacket(packet_copy);
   });
diff --git a/examples/androidvoip/jni/android_voip_client.h b/examples/androidvoip/jni/android_voip_client.h
index e2f1c64..1d9a13b 100644
--- a/examples/androidvoip/jni/android_voip_client.h
+++ b/examples/androidvoip/jni/android_voip_client.h
@@ -23,8 +23,8 @@
 #include "api/voip/voip_engine.h"
 #include "rtc_base/async_packet_socket.h"
 #include "rtc_base/async_udp_socket.h"
+#include "rtc_base/network/received_packet.h"
 #include "rtc_base/socket_address.h"
-#include "rtc_base/third_party/sigslot/sigslot.h"
 #include "rtc_base/thread.h"
 #include "sdk/android/native_api/jni/scoped_java_ref.h"
 
@@ -40,8 +40,7 @@
 // with consistent thread usage requirement with ProcessThread used
 // within VoipEngine, as well as providing asynchronicity to the
 // caller. AndroidVoipClient is meant to be used by Java through JNI.
-class AndroidVoipClient : public webrtc::Transport,
-                          public sigslot::has_slots<> {
+class AndroidVoipClient : public webrtc::Transport {
  public:
   // Returns a pointer to an AndroidVoipClient object. Clients should
   // use this factory method to create AndroidVoipClient objects. The
@@ -122,17 +121,10 @@
                const webrtc::PacketOptions& options) override;
   bool SendRtcp(rtc::ArrayView<const uint8_t> packet) override;
 
-  // Slots for sockets to connect to.
   void OnSignalReadRTPPacket(rtc::AsyncPacketSocket* socket,
-                             const char* rtp_packet,
-                             size_t size,
-                             const rtc::SocketAddress& addr,
-                             const int64_t& timestamp);
+                             const rtc::ReceivedPacket& packet);
   void OnSignalReadRTCPPacket(rtc::AsyncPacketSocket* socket,
-                              const char* rtcp_packet,
-                              size_t size,
-                              const rtc::SocketAddress& addr,
-                              const int64_t& timestamp);
+                              const rtc::ReceivedPacket& packet);
 
  private:
   AndroidVoipClient(JNIEnv* env,