blob: f18ee65c7076873ed8b2373e7b82ff1d829ebdd1 [file] [log] [blame]
Niels Möller70082872018-08-07 11:03:12 +02001/*
2 * Copyright (c) 2018 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#ifndef CALL_PACKET_RECEIVER_H_
11#define CALL_PACKET_RECEIVER_H_
12
13#include <algorithm>
Tomas Gunnarssona722d2a2021-01-19 09:00:18 +010014#include <functional>
Niels Möller70082872018-08-07 11:03:12 +020015#include <memory>
16#include <string>
Tomas Gunnarssona722d2a2021-01-19 09:00:18 +010017#include <utility>
Niels Möller70082872018-08-07 11:03:12 +020018#include <vector>
19
Steve Anton10542f22019-01-11 09:11:00 -080020#include "api/media_types.h"
21#include "rtc_base/copy_on_write_buffer.h"
Niels Möller70082872018-08-07 11:03:12 +020022
23namespace webrtc {
24
25class PacketReceiver {
26 public:
27 enum DeliveryStatus {
28 DELIVERY_OK,
29 DELIVERY_UNKNOWN_SSRC,
30 DELIVERY_PACKET_ERROR,
31 };
32
Tomas Gunnarssona722d2a2021-01-19 09:00:18 +010033 // Definition of the callback to execute when packet delivery is complete.
34 // The callback will be issued on the same thread as called DeliverPacket.
35 typedef std::function<
36 void(DeliveryStatus, MediaType, rtc::CopyOnWriteBuffer, int64_t)>
37 PacketCallback;
38
39 // Asynchronously handle packet delivery and report back to the caller when
40 // delivery of the packet has completed.
41 // Note that if the packet is invalid or can be processed without the need of
42 // asynchronous operations that the |callback| may have been called before
43 // the function returns.
44 // TODO(bugs.webrtc.org/11993): This function is meant to be called on the
45 // network thread exclusively but while the code is being updated to align
46 // with those goals, it may be called either on the worker or network threads.
47 // Update docs etc when the work has been completed. Once we're done with the
48 // updates, we might be able to go back to returning the status from this
49 // function instead of having to report it via a callback.
50 virtual void DeliverPacketAsync(MediaType media_type,
51 rtc::CopyOnWriteBuffer packet,
52 int64_t packet_time_us,
53 PacketCallback callback) {
54 DeliveryStatus status = DeliverPacket(media_type, packet, packet_time_us);
55 if (callback)
56 callback(status, media_type, std::move(packet), packet_time_us);
57 }
58
Niels Möller70082872018-08-07 11:03:12 +020059 virtual DeliveryStatus DeliverPacket(MediaType media_type,
60 rtc::CopyOnWriteBuffer packet,
Niels Möllerf189c482018-08-17 09:49:20 +020061 int64_t packet_time_us) = 0;
Niels Möller70082872018-08-07 11:03:12 +020062
63 protected:
64 virtual ~PacketReceiver() {}
65};
66
67} // namespace webrtc
68
69#endif // CALL_PACKET_RECEIVER_H_