blob: 7119c80237969d9314edba23ed2d113dd27df860 [file] [log] [blame]
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +00001/*
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.org9c55f0f2014-06-09 08:10:28 +000011#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_
12#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000013
14#include <list>
henrik.lundin84f8cd62016-04-26 07:45:16 -070015#include <memory>
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000016
ossudc431ce2016-08-31 08:51:13 -070017#include "webrtc/base/buffer.h"
henrik.lundin84f8cd62016-04-26 07:45:16 -070018#include "webrtc/modules/audio_coding/neteq/tick_timer.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010019#include "webrtc/modules/include/module_common_types.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000020#include "webrtc/typedefs.h"
21
22namespace webrtc {
23
24// Struct for holding RTP packets.
25struct Packet {
26 RTPHeader header;
henrik.lundin84f8cd62016-04-26 07:45:16 -070027 // Datagram excluding RTP header and header extension.
ossudc431ce2016-08-31 08:51:13 -070028 rtc::Buffer payload;
henrik.lundin84f8cd62016-04-26 07:45:16 -070029 bool primary = true; // Primary, i.e., not redundant payload.
henrik.lundin84f8cd62016-04-26 07:45:16 -070030 std::unique_ptr<TickTimer::Stopwatch> waiting_time;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000031
henrik.lundin84f8cd62016-04-26 07:45:16 -070032 Packet();
33 ~Packet();
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000034
35 // Comparison operators. Establish a packet ordering based on (1) timestamp,
ossu17e3fa12016-09-08 04:52:55 -070036 // (2) sequence number and (3) redundancy.
turaj@webrtc.org7b75ac62013-09-26 00:27:56 +000037 // Timestamp and sequence numbers are compared taking wrap-around into
ossu17e3fa12016-09-08 04:52:55 -070038 // account. For two packets with the same sequence number and timestamp a
39 // primary payload is considered "smaller" than a secondary.
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000040 bool operator==(const Packet& rhs) const {
41 return (this->header.timestamp == rhs.header.timestamp &&
42 this->header.sequenceNumber == rhs.header.sequenceNumber &&
ossu17e3fa12016-09-08 04:52:55 -070043 this->primary == rhs.primary);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000044 }
45 bool operator!=(const Packet& rhs) const { return !operator==(rhs); }
46 bool operator<(const Packet& rhs) const {
47 if (this->header.timestamp == rhs.header.timestamp) {
48 if (this->header.sequenceNumber == rhs.header.sequenceNumber) {
ossu17e3fa12016-09-08 04:52:55 -070049 // Timestamp and sequence numbers are identical - deem the left
50 // hand side to be "smaller" (i.e., "earlier") if it is primary, and
51 // right hand side is not.
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000052 return (this->primary && !rhs.primary);
53 }
54 return (static_cast<uint16_t>(rhs.header.sequenceNumber
55 - this->header.sequenceNumber) < 0xFFFF / 2);
56 }
57 return (static_cast<uint32_t>(rhs.header.timestamp
58 - this->header.timestamp) < 0xFFFFFFFF / 2);
59 }
60 bool operator>(const Packet& rhs) const { return rhs.operator<(*this); }
61 bool operator<=(const Packet& rhs) const { return !operator>(rhs); }
62 bool operator>=(const Packet& rhs) const { return !operator<(rhs); }
63};
64
65// A list of packets.
66typedef std::list<Packet*> PacketList;
67
68} // namespace webrtc
henrik.lundin@webrtc.org9c55f0f2014-06-09 08:10:28 +000069#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_