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> |
kwiberg | 2d0c332 | 2016-02-14 09:28:33 -0800 | [diff] [blame] | 15 | #include <memory> |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 16 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 17 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "rtc_base/constructormagic.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 19 | #include "typedefs.h" // NOLINT(build/include) |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | class RtpHeaderParser; |
| 24 | |
| 25 | namespace test { |
| 26 | |
| 27 | // Class for handling RTP packets in test applications. |
| 28 | class Packet { |
| 29 | public: |
| 30 | // Creates a packet, with the packet payload (including header bytes) in |
| 31 | // |packet_memory|. The length of |packet_memory| is |allocated_bytes|. |
| 32 | // The new object assumes ownership of |packet_memory| and will delete it |
| 33 | // when the Packet object is deleted. The |time_ms| is an extra time |
| 34 | // associated with this packet, typically used to denote arrival time. |
| 35 | // The first bytes in |packet_memory| will be parsed using |parser|. |
| 36 | Packet(uint8_t* packet_memory, |
| 37 | size_t allocated_bytes, |
| 38 | double time_ms, |
| 39 | const RtpHeaderParser& parser); |
| 40 | |
| 41 | // Same as above, but with the extra argument |virtual_packet_length_bytes|. |
| 42 | // This is typically used when reading RTP dump files that only contain the |
| 43 | // RTP headers, and no payload (a.k.a RTP dummy files or RTP light). The |
| 44 | // |virtual_packet_length_bytes| tells what size the packet had on wire, |
| 45 | // including the now discarded payload, whereas |allocated_bytes| is the |
| 46 | // length of the remaining payload (typically only the RTP header). |
| 47 | Packet(uint8_t* packet_memory, |
| 48 | size_t allocated_bytes, |
| 49 | size_t virtual_packet_length_bytes, |
| 50 | double time_ms, |
| 51 | const RtpHeaderParser& parser); |
| 52 | |
| 53 | // The following two constructors are the same as above, but without a |
| 54 | // parser. Note that when the object is constructed using any of these |
| 55 | // methods, the header will be parsed using a default RtpHeaderParser object. |
| 56 | // In particular, RTP header extensions won't be parsed. |
| 57 | Packet(uint8_t* packet_memory, size_t allocated_bytes, double time_ms); |
| 58 | |
| 59 | Packet(uint8_t* packet_memory, |
| 60 | size_t allocated_bytes, |
| 61 | size_t virtual_packet_length_bytes, |
| 62 | double time_ms); |
| 63 | |
kwiberg | b8e56ee | 2016-08-29 06:37:33 -0700 | [diff] [blame] | 64 | virtual ~Packet(); |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 65 | |
| 66 | // Parses the first bytes of the RTP payload, interpreting them as RED headers |
| 67 | // according to RFC 2198. The headers will be inserted into |headers|. The |
| 68 | // caller of the method assumes ownership of the objects in the list, and |
| 69 | // must delete them properly. |
| 70 | bool ExtractRedHeaders(std::list<RTPHeader*>* headers) const; |
| 71 | |
| 72 | // Deletes all RTPHeader objects in |headers|, but does not delete |headers| |
| 73 | // itself. |
| 74 | static void DeleteRedHeaders(std::list<RTPHeader*>* headers); |
| 75 | |
| 76 | const uint8_t* payload() const { return payload_; } |
| 77 | |
| 78 | size_t packet_length_bytes() const { return packet_length_bytes_; } |
| 79 | |
| 80 | size_t payload_length_bytes() const { return payload_length_bytes_; } |
| 81 | |
| 82 | size_t virtual_packet_length_bytes() const { |
| 83 | return virtual_packet_length_bytes_; |
| 84 | } |
| 85 | |
| 86 | size_t virtual_payload_length_bytes() const { |
| 87 | return virtual_payload_length_bytes_; |
| 88 | } |
| 89 | |
| 90 | const RTPHeader& header() const { return header_; } |
| 91 | |
| 92 | void set_time_ms(double time) { time_ms_ = time; } |
| 93 | double time_ms() const { return time_ms_; } |
| 94 | bool valid_header() const { return valid_header_; } |
| 95 | |
| 96 | private: |
| 97 | bool ParseHeader(const RtpHeaderParser& parser); |
| 98 | void CopyToHeader(RTPHeader* destination) const; |
| 99 | |
| 100 | RTPHeader header_; |
kwiberg | 2d0c332 | 2016-02-14 09:28:33 -0800 | [diff] [blame] | 101 | std::unique_ptr<uint8_t[]> payload_memory_; |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 102 | const uint8_t* payload_; // First byte after header. |
| 103 | const size_t packet_length_bytes_; // Total length of packet. |
| 104 | size_t payload_length_bytes_; // Length of the payload, after RTP header. |
| 105 | // Zero for dummy RTP packets. |
| 106 | // Virtual lengths are used when parsing RTP header files (dummy RTP files). |
| 107 | const size_t virtual_packet_length_bytes_; |
| 108 | size_t virtual_payload_length_bytes_; |
| 109 | double time_ms_; // Used to denote a packet's arrival time. |
| 110 | bool valid_header_; // Set by the RtpHeaderParser. |
| 111 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 112 | RTC_DISALLOW_COPY_AND_ASSIGN(Packet); |
henrik.lundin@webrtc.org | 810acbc | 2014-04-14 18:42:23 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | } // namespace test |
| 116 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 117 | #endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_PACKET_H_ |