henrik.lundin@webrtc.org | 9a40081 | 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 | |
| 11 | #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ4_PACKET_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_CODING_NETEQ4_PACKET_H_ |
| 13 | |
| 14 | #include <list> |
| 15 | |
| 16 | #include "webrtc/modules/interface/module_common_types.h" |
| 17 | #include "webrtc/typedefs.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | // Struct for holding RTP packets. |
| 22 | struct Packet { |
| 23 | RTPHeader header; |
| 24 | uint8_t* payload; // Datagram excluding RTP header and header extension. |
| 25 | int payload_length; |
| 26 | bool primary; // Primary, i.e., not redundant payload. |
| 27 | int waiting_time; |
| 28 | |
| 29 | // Constructor. |
| 30 | Packet() |
| 31 | : payload(NULL), |
| 32 | payload_length(0), |
| 33 | primary(true), |
| 34 | waiting_time(0) { |
| 35 | } |
| 36 | |
| 37 | // Comparison operators. Establish a packet ordering based on (1) timestamp, |
| 38 | // (2) sequence number, and (3) redundancy. Timestamp and sequence numbers |
| 39 | // are compared taking wrap-around into account. If both timestamp and |
| 40 | // sequence numbers are identical, a primary payload is considered "smaller" |
| 41 | // than a secondary. |
| 42 | bool operator==(const Packet& rhs) const { |
| 43 | return (this->header.timestamp == rhs.header.timestamp && |
| 44 | this->header.sequenceNumber == rhs.header.sequenceNumber && |
| 45 | this->primary == rhs.primary); |
| 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) { |
| 51 | // Timestamp and sequence numbers are identical. Deem left hand side |
| 52 | // to be "smaller" (i.e., "earlier") if it is primary, and right hand |
| 53 | // side is not. |
| 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); } |
| 65 | }; |
| 66 | |
| 67 | // A list of packets. |
| 68 | typedef std::list<Packet*> PacketList; |
| 69 | |
| 70 | } // namespace webrtc |
| 71 | #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ4_PACKET_H_ |