henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | |
henrik.lundin@webrtc.org | 9c55f0f | 2014-06-09 08:10:28 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_ |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 13 | |
| 14 | #include <list> |
henrik.lundin | 84f8cd6 | 2016-04-26 07:45:16 -0700 | [diff] [blame] | 15 | #include <memory> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 16 | |
ossu | dc431ce | 2016-08-31 08:51:13 -0700 | [diff] [blame] | 17 | #include "webrtc/base/buffer.h" |
ossu | 61a208b | 2016-09-20 01:38:00 -0700 | [diff] [blame] | 18 | #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" |
henrik.lundin | 84f8cd6 | 2016-04-26 07:45:16 -0700 | [diff] [blame] | 19 | #include "webrtc/modules/audio_coding/neteq/tick_timer.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 20 | #include "webrtc/modules/include/module_common_types.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 21 | #include "webrtc/typedefs.h" |
| 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | // Struct for holding RTP packets. |
| 26 | struct Packet { |
| 27 | RTPHeader header; |
henrik.lundin | 84f8cd6 | 2016-04-26 07:45:16 -0700 | [diff] [blame] | 28 | // Datagram excluding RTP header and header extension. |
ossu | dc431ce | 2016-08-31 08:51:13 -0700 | [diff] [blame] | 29 | rtc::Buffer payload; |
henrik.lundin | 84f8cd6 | 2016-04-26 07:45:16 -0700 | [diff] [blame] | 30 | bool primary = true; // Primary, i.e., not redundant payload. |
henrik.lundin | 84f8cd6 | 2016-04-26 07:45:16 -0700 | [diff] [blame] | 31 | std::unique_ptr<TickTimer::Stopwatch> waiting_time; |
ossu | 61a208b | 2016-09-20 01:38:00 -0700 | [diff] [blame] | 32 | std::unique_ptr<AudioDecoder::EncodedAudioFrame> frame; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 33 | |
henrik.lundin | 84f8cd6 | 2016-04-26 07:45:16 -0700 | [diff] [blame] | 34 | Packet(); |
| 35 | ~Packet(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 36 | |
| 37 | // Comparison operators. Establish a packet ordering based on (1) timestamp, |
ossu | 17e3fa1 | 2016-09-08 04:52:55 -0700 | [diff] [blame] | 38 | // (2) sequence number and (3) redundancy. |
turaj@webrtc.org | 7b75ac6 | 2013-09-26 00:27:56 +0000 | [diff] [blame] | 39 | // Timestamp and sequence numbers are compared taking wrap-around into |
ossu | 17e3fa1 | 2016-09-08 04:52:55 -0700 | [diff] [blame] | 40 | // account. For two packets with the same sequence number and timestamp a |
| 41 | // primary payload is considered "smaller" than a secondary. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 42 | bool operator==(const Packet& rhs) const { |
| 43 | return (this->header.timestamp == rhs.header.timestamp && |
| 44 | this->header.sequenceNumber == rhs.header.sequenceNumber && |
ossu | 17e3fa1 | 2016-09-08 04:52:55 -0700 | [diff] [blame] | 45 | this->primary == rhs.primary); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 46 | } |
| 47 | bool operator!=(const Packet& rhs) const { return !operator==(rhs); } |
| 48 | bool operator<(const Packet& rhs) const { |
| 49 | if (this->header.timestamp == rhs.header.timestamp) { |
| 50 | if (this->header.sequenceNumber == rhs.header.sequenceNumber) { |
ossu | 17e3fa1 | 2016-09-08 04:52:55 -0700 | [diff] [blame] | 51 | // Timestamp and sequence numbers are identical - deem the left |
| 52 | // hand side to be "smaller" (i.e., "earlier") if it is primary, and |
| 53 | // right hand side is not. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 54 | return (this->primary && !rhs.primary); |
| 55 | } |
| 56 | return (static_cast<uint16_t>(rhs.header.sequenceNumber |
| 57 | - this->header.sequenceNumber) < 0xFFFF / 2); |
| 58 | } |
| 59 | return (static_cast<uint32_t>(rhs.header.timestamp |
| 60 | - this->header.timestamp) < 0xFFFFFFFF / 2); |
| 61 | } |
| 62 | bool operator>(const Packet& rhs) const { return rhs.operator<(*this); } |
| 63 | bool operator<=(const Packet& rhs) const { return !operator>(rhs); } |
| 64 | bool operator>=(const Packet& rhs) const { return !operator<(rhs); } |
ossu | 61a208b | 2016-09-20 01:38:00 -0700 | [diff] [blame] | 65 | |
| 66 | bool empty() const { return !frame && payload.empty(); } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | // A list of packets. |
| 70 | typedef std::list<Packet*> PacketList; |
| 71 | |
| 72 | } // namespace webrtc |
henrik.lundin@webrtc.org | 9c55f0f | 2014-06-09 08:10:28 +0000 | [diff] [blame] | 73 | #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_ |