henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_PACKET_H_ |
| 12 | #define MODULES_AUDIO_CODING_NETEQ_TOOLS_PACKET_H_ |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 13 | |
| 14 | #include <list> |
| 15 | |
Danil Chapovalov | b4100ad | 2021-06-16 14:23:22 +0200 | [diff] [blame] | 16 | #include "api/array_view.h" |
| 17 | #include "api/rtp_headers.h" |
Tommi | 25eb47c | 2019-08-29 16:39:05 +0200 | [diff] [blame] | 18 | #include "modules/rtp_rtcp/include/rtp_header_extension_map.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 19 | #include "rtc_base/constructor_magic.h" |
Danil Chapovalov | b4100ad | 2021-06-16 14:23:22 +0200 | [diff] [blame] | 20 | #include "rtc_base/copy_on_write_buffer.h" |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 23 | namespace test { |
| 24 | |
| 25 | // Class for handling RTP packets in test applications. |
| 26 | class Packet { |
| 27 | public: |
| 28 | // Creates a packet, with the packet payload (including header bytes) in |
Danil Chapovalov | b4100ad | 2021-06-16 14:23:22 +0200 | [diff] [blame] | 29 | // `packet`. The `time_ms` is an extra time associated with this packet, |
| 30 | // typically used to denote arrival time. |
| 31 | // `virtual_packet_length_bytes` is typically used when reading RTP dump files |
Tommi | 25eb47c | 2019-08-29 16:39:05 +0200 | [diff] [blame] | 32 | // that only contain the RTP headers, and no payload (a.k.a RTP dummy files or |
Danil Chapovalov | b4100ad | 2021-06-16 14:23:22 +0200 | [diff] [blame] | 33 | // RTP light). The `virtual_packet_length_bytes` tells what size the packet |
| 34 | // had on wire, including the now discarded payload. |
| 35 | Packet(rtc::CopyOnWriteBuffer packet, |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 36 | size_t virtual_packet_length_bytes, |
| 37 | double time_ms, |
Tommi | 25eb47c | 2019-08-29 16:39:05 +0200 | [diff] [blame] | 38 | const RtpHeaderExtensionMap* extension_map = nullptr); |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 39 | |
Danil Chapovalov | b4100ad | 2021-06-16 14:23:22 +0200 | [diff] [blame] | 40 | Packet(rtc::CopyOnWriteBuffer packet, |
| 41 | double time_ms, |
| 42 | const RtpHeaderExtensionMap* extension_map = nullptr) |
| 43 | : Packet(packet, packet.size(), time_ms, extension_map) {} |
| 44 | |
Bjorn Terelius | 5350d1c | 2018-10-11 16:51:23 +0200 | [diff] [blame] | 45 | // Same as above, but creates the packet from an already parsed RTPHeader. |
| 46 | // This is typically used when reading RTP dump files that only contain the |
Danil Chapovalov | b4100ad | 2021-06-16 14:23:22 +0200 | [diff] [blame] | 47 | // RTP headers, and no payload. The `virtual_packet_length_bytes` tells what |
Bjorn Terelius | 5350d1c | 2018-10-11 16:51:23 +0200 | [diff] [blame] | 48 | // size the packet had on wire, including the now discarded payload, |
Danil Chapovalov | b4100ad | 2021-06-16 14:23:22 +0200 | [diff] [blame] | 49 | // The `virtual_payload_length_bytes` tells the size of the payload. |
Bjorn Terelius | 5350d1c | 2018-10-11 16:51:23 +0200 | [diff] [blame] | 50 | Packet(const RTPHeader& header, |
| 51 | size_t virtual_packet_length_bytes, |
| 52 | size_t virtual_payload_length_bytes, |
| 53 | double time_ms); |
| 54 | |
kwiberg | b8e56ee | 2016-08-29 06:37:33 -0700 | [diff] [blame] | 55 | virtual ~Packet(); |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 56 | |
| 57 | // Parses the first bytes of the RTP payload, interpreting them as RED headers |
| 58 | // according to RFC 2198. The headers will be inserted into |headers|. The |
| 59 | // caller of the method assumes ownership of the objects in the list, and |
| 60 | // must delete them properly. |
| 61 | bool ExtractRedHeaders(std::list<RTPHeader*>* headers) const; |
| 62 | |
| 63 | // Deletes all RTPHeader objects in |headers|, but does not delete |headers| |
| 64 | // itself. |
| 65 | static void DeleteRedHeaders(std::list<RTPHeader*>* headers); |
| 66 | |
Danil Chapovalov | b4100ad | 2021-06-16 14:23:22 +0200 | [diff] [blame] | 67 | const uint8_t* payload() const { return rtp_payload_.data(); } |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 68 | |
Danil Chapovalov | b4100ad | 2021-06-16 14:23:22 +0200 | [diff] [blame] | 69 | size_t packet_length_bytes() const { return packet_.size(); } |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 70 | |
Danil Chapovalov | b4100ad | 2021-06-16 14:23:22 +0200 | [diff] [blame] | 71 | size_t payload_length_bytes() const { return rtp_payload_.size(); } |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 72 | |
| 73 | size_t virtual_packet_length_bytes() const { |
| 74 | return virtual_packet_length_bytes_; |
| 75 | } |
| 76 | |
| 77 | size_t virtual_payload_length_bytes() const { |
| 78 | return virtual_payload_length_bytes_; |
| 79 | } |
| 80 | |
| 81 | const RTPHeader& header() const { return header_; } |
| 82 | |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 83 | double time_ms() const { return time_ms_; } |
| 84 | bool valid_header() const { return valid_header_; } |
| 85 | |
| 86 | private: |
Danil Chapovalov | b4100ad | 2021-06-16 14:23:22 +0200 | [diff] [blame] | 87 | bool ParseHeader(const RtpHeaderExtensionMap* extension_map); |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 88 | void CopyToHeader(RTPHeader* destination) const; |
| 89 | |
| 90 | RTPHeader header_; |
Danil Chapovalov | b4100ad | 2021-06-16 14:23:22 +0200 | [diff] [blame] | 91 | const rtc::CopyOnWriteBuffer packet_; |
| 92 | rtc::ArrayView<const uint8_t> rtp_payload_; // Empty for dummy RTP packets. |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 93 | // Virtual lengths are used when parsing RTP header files (dummy RTP files). |
| 94 | const size_t virtual_packet_length_bytes_; |
Tommi | 25eb47c | 2019-08-29 16:39:05 +0200 | [diff] [blame] | 95 | size_t virtual_payload_length_bytes_ = 0; |
| 96 | const double time_ms_; // Used to denote a packet's arrival time. |
Danil Chapovalov | b4100ad | 2021-06-16 14:23:22 +0200 | [diff] [blame] | 97 | const bool valid_header_; |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 98 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 99 | RTC_DISALLOW_COPY_AND_ASSIGN(Packet); |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | } // namespace test |
| 103 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 104 | #endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_PACKET_H_ |