blob: b6201ce79428cdddc9028e594173620a99315547 [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
35 // TODO(bugs.webrtc.org/3333): Needs to be extended with audio-level, to
36 // support RFC6465.
37 void Update(int64_t now_ms, rtc::ArrayView<const uint32_t> csrcs);
38
39 // Returns contributing sources seen the last 10 s.
40 std::vector<RtpSource> GetSources(int64_t now_ms) const;
41
42 private:
43 void DeleteOldEntries(int64_t now_ms);
44
45 // Indexed by csrc.
46 std::map<uint32_t, int64_t> last_seen_ms_;
47 absl::optional<int64_t> next_pruning_ms_;
48};
49
50} // namespace webrtc
51
52#endif // MODULES_RTP_RTCP_SOURCE_CONTRIBUTING_SOURCES_H_