2013-01-29 12:09:21 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-06-09 08:10:28 +00:00
|
|
|
#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_
|
|
|
|
|
#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
#include <list>
|
2016-04-26 07:45:16 -07:00
|
|
|
#include <memory>
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2016-08-31 08:51:13 -07:00
|
|
|
#include "webrtc/base/buffer.h"
|
2016-09-20 01:38:00 -07:00
|
|
|
#include "webrtc/modules/audio_coding/codecs/audio_decoder.h"
|
2016-04-26 07:45:16 -07:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/tick_timer.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/include/module_common_types.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
#include "webrtc/typedefs.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// Struct for holding RTP packets.
|
|
|
|
|
struct Packet {
|
2016-09-22 02:06:28 -07:00
|
|
|
struct Priority {
|
|
|
|
|
Priority() : codec_level(0), red_level(0) {}
|
|
|
|
|
Priority(int codec_level, int red_level)
|
|
|
|
|
: codec_level(codec_level), red_level(red_level) {
|
|
|
|
|
CheckInvariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int codec_level;
|
|
|
|
|
int red_level;
|
|
|
|
|
|
|
|
|
|
// Priorities are sorted low-to-high, first on the level the codec
|
|
|
|
|
// prioritizes it, then on the level of RED packet it is; i.e. if it is a
|
|
|
|
|
// primary or secondary payload of a RED packet. For example: with Opus, an
|
|
|
|
|
// Fec packet (which the decoder prioritizes lower than a regular packet)
|
|
|
|
|
// will not be used if there is _any_ RED payload for the same
|
|
|
|
|
// timeframe. The highest priority packet will have levels {0, 0}. Negative
|
|
|
|
|
// priorities are not allowed.
|
|
|
|
|
bool operator<(const Priority& b) const {
|
|
|
|
|
CheckInvariant();
|
|
|
|
|
b.CheckInvariant();
|
|
|
|
|
if (codec_level == b.codec_level)
|
|
|
|
|
return red_level < b.red_level;
|
|
|
|
|
|
|
|
|
|
return codec_level < b.codec_level;
|
|
|
|
|
}
|
|
|
|
|
bool operator==(const Priority& b) const {
|
|
|
|
|
CheckInvariant();
|
|
|
|
|
b.CheckInvariant();
|
|
|
|
|
return codec_level == b.codec_level && red_level == b.red_level;
|
|
|
|
|
}
|
|
|
|
|
bool operator!=(const Priority& b) const { return !(*this == b); }
|
|
|
|
|
bool operator>(const Priority& b) const { return b < *this; }
|
|
|
|
|
bool operator<=(const Priority& b) const { return !(b > *this); }
|
|
|
|
|
bool operator>=(const Priority& b) const { return !(b < *this); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void CheckInvariant() const {
|
|
|
|
|
RTC_DCHECK_GE(codec_level, 0);
|
|
|
|
|
RTC_DCHECK_GE(red_level, 0);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
RTPHeader header;
|
2016-04-26 07:45:16 -07:00
|
|
|
// Datagram excluding RTP header and header extension.
|
2016-08-31 08:51:13 -07:00
|
|
|
rtc::Buffer payload;
|
2016-09-22 02:06:28 -07:00
|
|
|
Priority priority;
|
2016-04-26 07:45:16 -07:00
|
|
|
std::unique_ptr<TickTimer::Stopwatch> waiting_time;
|
2016-09-20 01:38:00 -07:00
|
|
|
std::unique_ptr<AudioDecoder::EncodedAudioFrame> frame;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2016-04-26 07:45:16 -07:00
|
|
|
Packet();
|
|
|
|
|
~Packet();
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Comparison operators. Establish a packet ordering based on (1) timestamp,
|
2016-09-08 04:52:55 -07:00
|
|
|
// (2) sequence number and (3) redundancy.
|
2013-09-26 00:27:56 +00:00
|
|
|
// Timestamp and sequence numbers are compared taking wrap-around into
|
2016-09-08 04:52:55 -07:00
|
|
|
// account. For two packets with the same sequence number and timestamp a
|
|
|
|
|
// primary payload is considered "smaller" than a secondary.
|
2013-01-29 12:09:21 +00:00
|
|
|
bool operator==(const Packet& rhs) const {
|
|
|
|
|
return (this->header.timestamp == rhs.header.timestamp &&
|
2016-09-22 02:06:28 -07:00
|
|
|
this->header.sequenceNumber == rhs.header.sequenceNumber &&
|
|
|
|
|
this->priority == rhs.priority);
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
bool operator!=(const Packet& rhs) const { return !operator==(rhs); }
|
|
|
|
|
bool operator<(const Packet& rhs) const {
|
|
|
|
|
if (this->header.timestamp == rhs.header.timestamp) {
|
|
|
|
|
if (this->header.sequenceNumber == rhs.header.sequenceNumber) {
|
2016-09-22 02:06:28 -07:00
|
|
|
// Timestamp and sequence numbers are identical - deem the left hand
|
|
|
|
|
// side to be "smaller" (i.e., "earlier") if it has higher priority.
|
|
|
|
|
return this->priority < rhs.priority;
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
return (static_cast<uint16_t>(rhs.header.sequenceNumber
|
|
|
|
|
- this->header.sequenceNumber) < 0xFFFF / 2);
|
|
|
|
|
}
|
|
|
|
|
return (static_cast<uint32_t>(rhs.header.timestamp
|
|
|
|
|
- this->header.timestamp) < 0xFFFFFFFF / 2);
|
|
|
|
|
}
|
|
|
|
|
bool operator>(const Packet& rhs) const { return rhs.operator<(*this); }
|
|
|
|
|
bool operator<=(const Packet& rhs) const { return !operator>(rhs); }
|
|
|
|
|
bool operator>=(const Packet& rhs) const { return !operator<(rhs); }
|
2016-09-20 01:38:00 -07:00
|
|
|
|
|
|
|
|
bool empty() const { return !frame && payload.empty(); }
|
2013-01-29 12:09:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// A list of packets.
|
|
|
|
|
typedef std::list<Packet*> PacketList;
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
2014-06-09 08:10:28 +00:00
|
|
|
#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_
|