1 /*
2  *  Copyright (c) 2016 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 MODULES_RTP_RTCP_SOURCE_RTP_PACKET_RECEIVED_H_
11 #define MODULES_RTP_RTCP_SOURCE_RTP_PACKET_RECEIVED_H_
12 
13 #include <stdint.h>
14 
15 #include <vector>
16 
17 #include "api/array_view.h"
18 #include "api/rtp_headers.h"
19 #include "modules/rtp_rtcp/source/rtp_packet.h"
20 #include "system_wrappers/include/ntp_time.h"
21 
22 namespace webrtc {
23 // Class to hold rtp packet with metadata for receiver side.
24 class RtpPacketReceived : public RtpPacket {
25  public:
26   RtpPacketReceived();
27   explicit RtpPacketReceived(const ExtensionManager* extensions);
28   RtpPacketReceived(const RtpPacketReceived& packet);
29   RtpPacketReceived(RtpPacketReceived&& packet);
30 
31   RtpPacketReceived& operator=(const RtpPacketReceived& packet);
32   RtpPacketReceived& operator=(RtpPacketReceived&& packet);
33 
34   ~RtpPacketReceived();
35 
36   // TODO(danilchap): Remove this function when all code update to use RtpPacket
37   // directly. Function is there just for easier backward compatibilty.
38   void GetHeader(RTPHeader* header) const;
39 
40   // Time in local time base as close as it can to packet arrived on the
41   // network.
arrival_time_ms()42   int64_t arrival_time_ms() const { return arrival_time_ms_; }
set_arrival_time_ms(int64_t time)43   void set_arrival_time_ms(int64_t time) { arrival_time_ms_ = time; }
44 
45   // Estimated from Timestamp() using rtcp Sender Reports.
capture_ntp_time()46   NtpTime capture_ntp_time() const { return capture_time_; }
set_capture_ntp_time(NtpTime time)47   void set_capture_ntp_time(NtpTime time) { capture_time_ = time; }
48 
49   // Flag if packet was recovered via RTX or FEC.
recovered()50   bool recovered() const { return recovered_; }
set_recovered(bool value)51   void set_recovered(bool value) { recovered_ = value; }
52 
payload_type_frequency()53   int payload_type_frequency() const { return payload_type_frequency_; }
set_payload_type_frequency(int value)54   void set_payload_type_frequency(int value) {
55     payload_type_frequency_ = value;
56   }
57 
58   // Additional data bound to the RTP packet for use in application code,
59   // outside of WebRTC.
application_data()60   rtc::ArrayView<const uint8_t> application_data() const {
61     return application_data_;
62   }
set_application_data(rtc::ArrayView<const uint8_t> data)63   void set_application_data(rtc::ArrayView<const uint8_t> data) {
64     application_data_.assign(data.begin(), data.end());
65   }
66 
67  private:
68   NtpTime capture_time_;
69   int64_t arrival_time_ms_ = 0;
70   int payload_type_frequency_ = 0;
71   bool recovered_ = false;
72   std::vector<uint8_t> application_data_;
73 };
74 
75 }  // namespace webrtc
76 #endif  // MODULES_RTP_RTCP_SOURCE_RTP_PACKET_RECEIVED_H_
77