blob: 1a4a572d8f54431ba6a523e40f5d33af01f8fb22 [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"
Oleh Prypin96a0f612018-10-05 13:13:38 +000021#include "api/rtpreceiverinterface.h"
Niels Mölleraf175952018-08-13 13:23:08 +020022
23namespace webrtc {
24
25class ContributingSources {
26 public:
Niels Möller30b48392018-08-15 15:05:26 +020027 // Set by the spec, see
28 // https://www.w3.org/TR/webrtc/#dom-rtcrtpreceiver-getcontributingsources
29 static constexpr int64_t kHistoryMs = 10 * rtc::kNumMillisecsPerSec;
30
Niels Mölleraf175952018-08-13 13:23:08 +020031 ContributingSources();
32 ~ContributingSources();
33
34 // TODO(bugs.webrtc.org/3333): Needs to be extended with audio-level, to
35 // support RFC6465.
36 void Update(int64_t now_ms, rtc::ArrayView<const uint32_t> csrcs);
37
38 // Returns contributing sources seen the last 10 s.
39 std::vector<RtpSource> GetSources(int64_t now_ms) const;
40
41 private:
42 void DeleteOldEntries(int64_t now_ms);
43
44 // Indexed by csrc.
45 std::map<uint32_t, int64_t> last_seen_ms_;
46 absl::optional<int64_t> next_pruning_ms_;
47};
48
49} // namespace webrtc
50
51#endif // MODULES_RTP_RTCP_SOURCE_CONTRIBUTING_SOURCES_H_