Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 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_RTP_PACKET_INFO_H_ |
| 12 | #define API_RTP_PACKET_INFO_H_ |
| 13 | |
| 14 | #include <cstdint> |
| 15 | #include <utility> |
| 16 | #include <vector> |
| 17 | |
| 18 | #include "absl/types/optional.h" |
| 19 | #include "api/rtp_headers.h" |
| 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | // Structure to hold information about a received |RtpPacket|. |
| 24 | class RtpPacketInfo { |
| 25 | public: |
| 26 | RtpPacketInfo(); |
| 27 | |
| 28 | RtpPacketInfo(uint32_t ssrc, |
| 29 | std::vector<uint32_t> csrcs, |
| 30 | uint16_t sequence_number, |
| 31 | uint32_t rtp_timestamp, |
| 32 | absl::optional<uint8_t> audio_level, |
| 33 | int64_t receive_time_ms); |
| 34 | |
| 35 | RtpPacketInfo(const RTPHeader& rtp_header, int64_t receive_time_ms); |
| 36 | |
| 37 | RtpPacketInfo(const RtpPacketInfo& other) = default; |
| 38 | RtpPacketInfo(RtpPacketInfo&& other) = default; |
| 39 | RtpPacketInfo& operator=(const RtpPacketInfo& other) = default; |
| 40 | RtpPacketInfo& operator=(RtpPacketInfo&& other) = default; |
| 41 | |
| 42 | uint32_t ssrc() const { return ssrc_; } |
| 43 | void set_ssrc(uint32_t value) { ssrc_ = value; } |
| 44 | |
| 45 | const std::vector<uint32_t>& csrcs() const { return csrcs_; } |
| 46 | void set_csrcs(std::vector<uint32_t> value) { csrcs_ = std::move(value); } |
| 47 | |
| 48 | uint16_t sequence_number() const { return sequence_number_; } |
| 49 | void set_sequence_number(uint16_t value) { sequence_number_ = value; } |
| 50 | |
| 51 | uint32_t rtp_timestamp() const { return rtp_timestamp_; } |
| 52 | void set_rtp_timestamp(uint32_t value) { rtp_timestamp_ = value; } |
| 53 | |
| 54 | absl::optional<uint8_t> audio_level() const { return audio_level_; } |
| 55 | void set_audio_level(absl::optional<uint8_t> value) { audio_level_ = value; } |
| 56 | |
| 57 | int64_t receive_time_ms() const { return receive_time_ms_; } |
| 58 | void set_receive_time_ms(int64_t value) { receive_time_ms_ = value; } |
| 59 | |
| 60 | private: |
| 61 | // Fields from the RTP header: |
| 62 | // https://tools.ietf.org/html/rfc3550#section-5.1 |
| 63 | uint32_t ssrc_; |
| 64 | std::vector<uint32_t> csrcs_; |
| 65 | uint16_t sequence_number_; |
| 66 | uint32_t rtp_timestamp_; |
| 67 | |
| 68 | // Fields from the Audio Level header extension: |
| 69 | // https://tools.ietf.org/html/rfc6464#section-3 |
| 70 | absl::optional<uint8_t> audio_level_; |
| 71 | |
| 72 | // Local |webrtc::Clock|-based timestamp of when the packet was received. |
| 73 | int64_t receive_time_ms_; |
| 74 | }; |
| 75 | |
| 76 | bool operator==(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs); |
| 77 | |
| 78 | inline bool operator!=(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs) { |
| 79 | return !(lhs == rhs); |
| 80 | } |
| 81 | |
| 82 | } // namespace webrtc |
| 83 | |
| 84 | #endif // API_RTP_PACKET_INFO_H_ |