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