rtp_source.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  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. #ifndef API_TRANSPORT_RTP_RTP_SOURCE_H_
  11. #define API_TRANSPORT_RTP_RTP_SOURCE_H_
  12. #include <stdint.h>
  13. #include "absl/types/optional.h"
  14. #include "api/rtp_headers.h"
  15. #include "rtc_base/checks.h"
  16. namespace webrtc {
  17. enum class RtpSourceType {
  18. SSRC,
  19. CSRC,
  20. };
  21. class RtpSource {
  22. public:
  23. struct Extensions {
  24. absl::optional<uint8_t> audio_level;
  25. absl::optional<AbsoluteCaptureTime> absolute_capture_time;
  26. };
  27. RtpSource() = delete;
  28. // TODO(bugs.webrtc.org/10739): Remove this constructor once all clients
  29. // migrate to the version with absolute capture time.
  30. RtpSource(int64_t timestamp_ms,
  31. uint32_t source_id,
  32. RtpSourceType source_type,
  33. absl::optional<uint8_t> audio_level,
  34. uint32_t rtp_timestamp)
  35. : RtpSource(timestamp_ms,
  36. source_id,
  37. source_type,
  38. rtp_timestamp,
  39. {audio_level, absl::nullopt}) {}
  40. RtpSource(int64_t timestamp_ms,
  41. uint32_t source_id,
  42. RtpSourceType source_type,
  43. uint32_t rtp_timestamp,
  44. const RtpSource::Extensions& extensions)
  45. : timestamp_ms_(timestamp_ms),
  46. source_id_(source_id),
  47. source_type_(source_type),
  48. extensions_(extensions),
  49. rtp_timestamp_(rtp_timestamp) {}
  50. RtpSource(const RtpSource&) = default;
  51. RtpSource& operator=(const RtpSource&) = default;
  52. ~RtpSource() = default;
  53. int64_t timestamp_ms() const { return timestamp_ms_; }
  54. void update_timestamp_ms(int64_t timestamp_ms) {
  55. RTC_DCHECK_LE(timestamp_ms_, timestamp_ms);
  56. timestamp_ms_ = timestamp_ms;
  57. }
  58. // The identifier of the source can be the CSRC or the SSRC.
  59. uint32_t source_id() const { return source_id_; }
  60. // The source can be either a contributing source or a synchronization source.
  61. RtpSourceType source_type() const { return source_type_; }
  62. absl::optional<uint8_t> audio_level() const {
  63. return extensions_.audio_level;
  64. }
  65. void set_audio_level(const absl::optional<uint8_t>& level) {
  66. extensions_.audio_level = level;
  67. }
  68. uint32_t rtp_timestamp() const { return rtp_timestamp_; }
  69. absl::optional<AbsoluteCaptureTime> absolute_capture_time() const {
  70. return extensions_.absolute_capture_time;
  71. }
  72. bool operator==(const RtpSource& o) const {
  73. return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() &&
  74. source_type_ == o.source_type() &&
  75. extensions_.audio_level == o.extensions_.audio_level &&
  76. extensions_.absolute_capture_time ==
  77. o.extensions_.absolute_capture_time &&
  78. rtp_timestamp_ == o.rtp_timestamp();
  79. }
  80. private:
  81. int64_t timestamp_ms_;
  82. uint32_t source_id_;
  83. RtpSourceType source_type_;
  84. RtpSource::Extensions extensions_;
  85. uint32_t rtp_timestamp_;
  86. };
  87. } // namespace webrtc
  88. #endif // API_TRANSPORT_RTP_RTP_SOURCE_H_