Jonas Oreland | 6d83592 | 2019-03-18 10:59:40 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 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 | |
| 11 | #ifndef MEDIA_ENGINE_UNHANDLED_PACKETS_BUFFER_H_ |
| 12 | #define MEDIA_ENGINE_UNHANDLED_PACKETS_BUFFER_H_ |
| 13 | |
| 14 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 15 | |
Jonas Oreland | 6d83592 | 2019-03-18 10:59:40 +0100 | [diff] [blame] | 16 | #include <functional> |
| 17 | #include <tuple> |
| 18 | #include <utility> |
| 19 | #include <vector> |
| 20 | |
| 21 | #include "rtc_base/copy_on_write_buffer.h" |
| 22 | |
| 23 | namespace cricket { |
| 24 | |
| 25 | class UnhandledPacketsBuffer { |
| 26 | public: |
| 27 | // Visible for testing. |
| 28 | static constexpr size_t kMaxStashedPackets = 50; |
| 29 | |
| 30 | UnhandledPacketsBuffer(); |
| 31 | ~UnhandledPacketsBuffer(); |
| 32 | |
| 33 | // Store packet in buffer. |
| 34 | void AddPacket(uint32_t ssrc, |
| 35 | int64_t packet_time_us, |
| 36 | rtc::CopyOnWriteBuffer packet); |
| 37 | |
| 38 | // Feed all packets with |ssrcs| into |consumer|. |
| 39 | void BackfillPackets( |
| 40 | rtc::ArrayView<const uint32_t> ssrcs, |
| 41 | std::function<void(uint32_t, int64_t, rtc::CopyOnWriteBuffer)> consumer); |
| 42 | |
| 43 | private: |
| 44 | size_t insert_pos_ = 0; |
| 45 | struct PacketWithMetadata { |
| 46 | uint32_t ssrc; |
| 47 | int64_t packet_time_us; |
| 48 | rtc::CopyOnWriteBuffer packet; |
| 49 | }; |
| 50 | std::vector<PacketWithMetadata> buffer_; |
| 51 | }; |
| 52 | |
| 53 | } // namespace cricket |
| 54 | |
| 55 | #endif // MEDIA_ENGINE_UNHANDLED_PACKETS_BUFFER_H_ |