Niels Möller | 7008287 | 2018-08-07 11:03:12 +0200 | [diff] [blame] | 1 | /* |
| 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 Gunnarsson | a722d2a | 2021-01-19 09:00:18 +0100 | [diff] [blame] | 14 | #include <functional> |
Niels Möller | 7008287 | 2018-08-07 11:03:12 +0200 | [diff] [blame] | 15 | #include <memory> |
| 16 | #include <string> |
Tomas Gunnarsson | a722d2a | 2021-01-19 09:00:18 +0100 | [diff] [blame] | 17 | #include <utility> |
Niels Möller | 7008287 | 2018-08-07 11:03:12 +0200 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "api/media_types.h" |
| 21 | #include "rtc_base/copy_on_write_buffer.h" |
Niels Möller | 7008287 | 2018-08-07 11:03:12 +0200 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | class PacketReceiver { |
| 26 | public: |
| 27 | enum DeliveryStatus { |
| 28 | DELIVERY_OK, |
| 29 | DELIVERY_UNKNOWN_SSRC, |
| 30 | DELIVERY_PACKET_ERROR, |
| 31 | }; |
| 32 | |
Tomas Gunnarsson | a722d2a | 2021-01-19 09:00:18 +0100 | [diff] [blame] | 33 | // 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öller | 7008287 | 2018-08-07 11:03:12 +0200 | [diff] [blame] | 59 | virtual DeliveryStatus DeliverPacket(MediaType media_type, |
| 60 | rtc::CopyOnWriteBuffer packet, |
Niels Möller | f189c48 | 2018-08-17 09:49:20 +0200 | [diff] [blame] | 61 | int64_t packet_time_us) = 0; |
Niels Möller | 7008287 | 2018-08-07 11:03:12 +0200 | [diff] [blame] | 62 | |
| 63 | protected: |
| 64 | virtual ~PacketReceiver() {} |
| 65 | }; |
| 66 | |
| 67 | } // namespace webrtc |
| 68 | |
| 69 | #endif // CALL_PACKET_RECEIVER_H_ |