blob: 5e34539ce477e0b7bedaf80d099a744735114e63 [file] [log] [blame]
Niels Mölleraf175952018-08-13 13:23:08 +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
11#ifndef MODULES_RTP_RTCP_SOURCE_CONTRIBUTING_SOURCES_H_
12#define MODULES_RTP_RTCP_SOURCE_CONTRIBUTING_SOURCES_H_
13
14#include <stdint.h>
15
16#include <map>
17#include <vector>
18
19#include "absl/types/optional.h"
20#include "api/array_view.h"
Yves Gerey2e00abc2018-10-05 15:39:24 +020021#include "api/rtpreceiverinterface.h" // For RtpSource
22#include "rtc_base/timeutils.h" // For kNumMillisecsPerSec
Niels Mölleraf175952018-08-13 13:23:08 +020023
24namespace webrtc {
25
26class ContributingSources {
27 public:
Niels Möller30b48392018-08-15 15:05:26 +020028 // Set by the spec, see
29 // https://www.w3.org/TR/webrtc/#dom-rtcrtpreceiver-getcontributingsources
30 static constexpr int64_t kHistoryMs = 10 * rtc::kNumMillisecsPerSec;
31
Niels Mölleraf175952018-08-13 13:23:08 +020032 ContributingSources();
33 ~ContributingSources();
34
Jonas Oreland967f7d52018-11-06 07:35:06 +010035 void Update(int64_t now_ms, rtc::ArrayView<const uint32_t> csrcs,
36 absl::optional<uint8_t> audio_level);
Niels Mölleraf175952018-08-13 13:23:08 +020037
38 // Returns contributing sources seen the last 10 s.
39 std::vector<RtpSource> GetSources(int64_t now_ms) const;
40
41 private:
Jonas Oreland967f7d52018-11-06 07:35:06 +010042 struct Entry {
43 Entry();
44 Entry(int64_t timestamp_ms, absl::optional<uint8_t> audio_level);
45
46 int64_t last_seen_ms;
47 absl::optional<uint8_t> audio_level;
48 };
49
Niels Mölleraf175952018-08-13 13:23:08 +020050 void DeleteOldEntries(int64_t now_ms);
51
52 // Indexed by csrc.
Jonas Oreland967f7d52018-11-06 07:35:06 +010053 std::map<uint32_t, Entry> active_csrcs_;
Niels Mölleraf175952018-08-13 13:23:08 +020054 absl::optional<int64_t> next_pruning_ms_;
55};
56
57} // namespace webrtc
58
59#endif // MODULES_RTP_RTCP_SOURCE_CONTRIBUTING_SOURCES_H_