Niels Möller | af17595 | 2018-08-13 13:23:08 +0200 | [diff] [blame] | 1 | /* |
| 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 Gerey | 2e00abc | 2018-10-05 15:39:24 +0200 | [diff] [blame] | 21 | #include "api/rtpreceiverinterface.h" // For RtpSource |
| 22 | #include "rtc_base/timeutils.h" // For kNumMillisecsPerSec |
Niels Möller | af17595 | 2018-08-13 13:23:08 +0200 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | class ContributingSources { |
| 27 | public: |
Niels Möller | 30b4839 | 2018-08-15 15:05:26 +0200 | [diff] [blame] | 28 | // 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öller | af17595 | 2018-08-13 13:23:08 +0200 | [diff] [blame] | 32 | ContributingSources(); |
| 33 | ~ContributingSources(); |
| 34 | |
Jonas Oreland | 967f7d5 | 2018-11-06 07:35:06 +0100 | [diff] [blame] | 35 | void Update(int64_t now_ms, rtc::ArrayView<const uint32_t> csrcs, |
| 36 | absl::optional<uint8_t> audio_level); |
Niels Möller | af17595 | 2018-08-13 13:23:08 +0200 | [diff] [blame] | 37 | |
| 38 | // Returns contributing sources seen the last 10 s. |
| 39 | std::vector<RtpSource> GetSources(int64_t now_ms) const; |
| 40 | |
| 41 | private: |
Jonas Oreland | 967f7d5 | 2018-11-06 07:35:06 +0100 | [diff] [blame] | 42 | 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öller | af17595 | 2018-08-13 13:23:08 +0200 | [diff] [blame] | 50 | void DeleteOldEntries(int64_t now_ms); |
| 51 | |
| 52 | // Indexed by csrc. |
Jonas Oreland | 967f7d5 | 2018-11-06 07:35:06 +0100 | [diff] [blame] | 53 | std::map<uint32_t, Entry> active_csrcs_; |
Niels Möller | af17595 | 2018-08-13 13:23:08 +0200 | [diff] [blame] | 54 | absl::optional<int64_t> next_pruning_ms_; |
| 55 | }; |
| 56 | |
| 57 | } // namespace webrtc |
| 58 | |
| 59 | #endif // MODULES_RTP_RTCP_SOURCE_CONTRIBUTING_SOURCES_H_ |