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