blob: bc5b3d841ad81a5728c9266ace1698bc547574b6 [file] [log] [blame]
kwiberg@webrtc.org67186fe2015-03-09 22:21:531/*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 17:11:0011#include "rtc_base/async_packet_socket.h"
Jonas Olssona4d87372019-07-05 17:08:3312
Per K4ac37182023-11-15 09:43:3213#include "rtc_base/checks.h"
14
kwiberg@webrtc.org67186fe2015-03-09 22:21:5315namespace rtc {
16
Qingsi Wang6e641e62018-04-12 03:14:1717PacketTimeUpdateParams::PacketTimeUpdateParams() = default;
18
19PacketTimeUpdateParams::PacketTimeUpdateParams(
20 const PacketTimeUpdateParams& other) = default;
kwiberg@webrtc.org67186fe2015-03-09 22:21:5321
22PacketTimeUpdateParams::~PacketTimeUpdateParams() = default;
23
Qingsi Wang6e641e62018-04-12 03:14:1724PacketOptions::PacketOptions() = default;
25PacketOptions::PacketOptions(DiffServCodePoint dscp) : dscp(dscp) {}
26PacketOptions::PacketOptions(const PacketOptions& other) = default;
27PacketOptions::~PacketOptions() = default;
kwiberg@webrtc.org67186fe2015-03-09 22:21:5328
Qingsi Wang6e641e62018-04-12 03:14:1729AsyncPacketSocket::~AsyncPacketSocket() = default;
30
Tommi2afd2842023-09-05 07:36:2431void AsyncPacketSocket::SubscribeCloseEvent(
Tomas Gunnarssonf15189d2022-04-13 09:03:5232 const void* removal_tag,
33 std::function<void(AsyncPacketSocket*, int)> callback) {
34 RTC_DCHECK_RUN_ON(&network_checker_);
35 on_close_.AddReceiver(removal_tag, std::move(callback));
36}
37
Tommi2afd2842023-09-05 07:36:2438void AsyncPacketSocket::UnsubscribeCloseEvent(const void* removal_tag) {
Tomas Gunnarssonf15189d2022-04-13 09:03:5239 RTC_DCHECK_RUN_ON(&network_checker_);
40 on_close_.RemoveReceivers(removal_tag);
41}
42
Per K4ac37182023-11-15 09:43:3243void AsyncPacketSocket::RegisterReceivedPacketCallback(
44 absl::AnyInvocable<void(AsyncPacketSocket*, const rtc::ReceivedPacket&)>
45 received_packet_callback) {
46 RTC_DCHECK_RUN_ON(&network_checker_);
47 RTC_CHECK(!received_packet_callback_);
Per K4ac37182023-11-15 09:43:3248 received_packet_callback_ = std::move(received_packet_callback);
49}
50
51void AsyncPacketSocket::DeregisterReceivedPacketCallback() {
52 RTC_DCHECK_RUN_ON(&network_checker_);
Per K4ac37182023-11-15 09:43:3253 received_packet_callback_ = nullptr;
54}
55
56void AsyncPacketSocket::NotifyPacketReceived(
57 const rtc::ReceivedPacket& packet) {
58 RTC_DCHECK_RUN_ON(&network_checker_);
59 if (received_packet_callback_) {
60 received_packet_callback_(this, packet);
61 return;
62 }
Per K4ac37182023-11-15 09:43:3263}
64
Qingsi Wang6e641e62018-04-12 03:14:1765void CopySocketInformationToPacketInfo(size_t packet_size_bytes,
66 const AsyncPacketSocket& socket_from,
67 rtc::PacketInfo* info) {
68 info->packet_size_bytes = packet_size_bytes;
Sebastian Janssondb5d7e42020-03-02 10:32:2369 info->ip_overhead_bytes = socket_from.GetLocalAddress().ipaddr().overhead();
kwiberg@webrtc.org67186fe2015-03-09 22:21:5370}
71
Nico Weber22f99252019-02-20 15:13:1672} // namespace rtc