blob: 8c543cac0c3497789243e3d7407e407c53b274eb [file] [log] [blame]
Niels Möllera8370302019-09-02 15:16:49 +02001/*
2 * Copyright 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 API_TRANSPORT_RTP_RTP_SOURCE_H_
12#define API_TRANSPORT_RTP_RTP_SOURCE_H_
13
14#include <stdint.h>
15
16#include "absl/types/optional.h"
Ruslan Burakovd51cc7b2019-11-20 16:48:34 +010017#include "api/rtp_headers.h"
Niels Möllera8370302019-09-02 15:16:49 +020018#include "rtc_base/checks.h"
19
20namespace webrtc {
21
22enum class RtpSourceType {
23 SSRC,
24 CSRC,
25};
26
27class RtpSource {
28 public:
Ruslan Burakovd51cc7b2019-11-20 16:48:34 +010029 struct Extensions {
30 absl::optional<uint8_t> audio_level;
31 absl::optional<AbsoluteCaptureTime> absolute_capture_time;
32 };
33
Niels Möllera8370302019-09-02 15:16:49 +020034 RtpSource() = delete;
35
Ruslan Burakovd51cc7b2019-11-20 16:48:34 +010036 // TODO(bugs.webrtc.org/10739): Remove this constructor once all clients
37 // migrate to the version with absolute capture time.
Niels Möllera8370302019-09-02 15:16:49 +020038 RtpSource(int64_t timestamp_ms,
39 uint32_t source_id,
40 RtpSourceType source_type,
41 absl::optional<uint8_t> audio_level,
42 uint32_t rtp_timestamp)
Ruslan Burakovd51cc7b2019-11-20 16:48:34 +010043 : RtpSource(timestamp_ms,
44 source_id,
45 source_type,
46 rtp_timestamp,
47 {audio_level, absl::nullopt}) {}
48
49 RtpSource(int64_t timestamp_ms,
50 uint32_t source_id,
51 RtpSourceType source_type,
52 uint32_t rtp_timestamp,
53 const RtpSource::Extensions& extensions)
Niels Möllera8370302019-09-02 15:16:49 +020054 : timestamp_ms_(timestamp_ms),
55 source_id_(source_id),
56 source_type_(source_type),
Ruslan Burakovd51cc7b2019-11-20 16:48:34 +010057 extensions_(extensions),
Niels Möllera8370302019-09-02 15:16:49 +020058 rtp_timestamp_(rtp_timestamp) {}
59
60 RtpSource(const RtpSource&) = default;
61 RtpSource& operator=(const RtpSource&) = default;
62 ~RtpSource() = default;
63
64 int64_t timestamp_ms() const { return timestamp_ms_; }
65 void update_timestamp_ms(int64_t timestamp_ms) {
66 RTC_DCHECK_LE(timestamp_ms_, timestamp_ms);
67 timestamp_ms_ = timestamp_ms;
68 }
69
70 // The identifier of the source can be the CSRC or the SSRC.
71 uint32_t source_id() const { return source_id_; }
72
73 // The source can be either a contributing source or a synchronization source.
74 RtpSourceType source_type() const { return source_type_; }
75
Ruslan Burakovd51cc7b2019-11-20 16:48:34 +010076 absl::optional<uint8_t> audio_level() const {
77 return extensions_.audio_level;
78 }
79
Niels Möllera8370302019-09-02 15:16:49 +020080 void set_audio_level(const absl::optional<uint8_t>& level) {
Ruslan Burakovd51cc7b2019-11-20 16:48:34 +010081 extensions_.audio_level = level;
Niels Möllera8370302019-09-02 15:16:49 +020082 }
83
84 uint32_t rtp_timestamp() const { return rtp_timestamp_; }
85
Ruslan Burakovd51cc7b2019-11-20 16:48:34 +010086 absl::optional<AbsoluteCaptureTime> absolute_capture_time() const {
87 return extensions_.absolute_capture_time;
88 }
89
Niels Möllera8370302019-09-02 15:16:49 +020090 bool operator==(const RtpSource& o) const {
91 return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() &&
Ruslan Burakovd51cc7b2019-11-20 16:48:34 +010092 source_type_ == o.source_type() &&
93 extensions_.audio_level == o.extensions_.audio_level &&
94 extensions_.absolute_capture_time ==
95 o.extensions_.absolute_capture_time &&
Niels Möllera8370302019-09-02 15:16:49 +020096 rtp_timestamp_ == o.rtp_timestamp();
97 }
98
99 private:
100 int64_t timestamp_ms_;
101 uint32_t source_id_;
102 RtpSourceType source_type_;
Ruslan Burakovd51cc7b2019-11-20 16:48:34 +0100103 RtpSource::Extensions extensions_;
Niels Möllera8370302019-09-02 15:16:49 +0200104 uint32_t rtp_timestamp_;
105};
106
107} // namespace webrtc
108
109#endif // API_TRANSPORT_RTP_RTP_SOURCE_H_