Index: webrtc/modules/audio_coding/neteq/packet.h |
diff --git a/webrtc/modules/audio_coding/neteq/packet.h b/webrtc/modules/audio_coding/neteq/packet.h |
index 4e17a88dcd5c12bc5f90ee95702371b8cab93646..14b00e32a17dcbe9c160d7806b489af36cfce5a5 100644 |
--- a/webrtc/modules/audio_coding/neteq/packet.h |
+++ b/webrtc/modules/audio_coding/neteq/packet.h |
@@ -24,10 +24,47 @@ namespace webrtc { |
// Struct for holding RTP packets. |
struct Packet { |
+ struct Priority { |
+ Priority() : codec_level(0), red_level(0) {} |
+ Priority(int codec_level, int red_level) |
+ : codec_level(codec_level), red_level(red_level) { |
+ RTC_DCHECK_GE(codec_level, 0); |
+ RTC_DCHECK_GE(red_level, 0); |
+ } |
+ |
+ 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 { |
+ RTC_DCHECK_GE(codec_level, 0); |
+ RTC_DCHECK_GE(red_level, 0); |
kwiberg-webrtc
2016/09/20 14:56:23
It's probably just as important to check the level
ossu
2016/09/20 15:45:21
Alright!
ossu
2016/09/21 10:23:12
Called it CheckInvariant to mimic ArrayView. Maybe
kwiberg-webrtc
2016/09/21 10:59:13
Yes. Although if intended to be generic, it should
|
+ if (codec_level == b.codec_level) |
+ return red_level < b.red_level; |
+ |
+ return codec_level < b.codec_level; |
+ } |
+ bool operator==(const Priority& b) const { |
+ RTC_DCHECK_GE(codec_level, 0); |
+ RTC_DCHECK_GE(red_level, 0); |
+ 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); } |
+ }; |
+ |
RTPHeader header; |
// Datagram excluding RTP header and header extension. |
rtc::Buffer payload; |
- bool primary = true; // Primary, i.e., not redundant payload. |
+ Priority priority; |
std::unique_ptr<TickTimer::Stopwatch> waiting_time; |
std::unique_ptr<AudioDecoder::EncodedAudioFrame> frame; |
@@ -41,17 +78,16 @@ struct Packet { |
// primary payload is considered "smaller" than a secondary. |
bool operator==(const Packet& rhs) const { |
return (this->header.timestamp == rhs.header.timestamp && |
- this->header.sequenceNumber == rhs.header.sequenceNumber && |
- this->primary == rhs.primary); |
+ this->header.sequenceNumber == rhs.header.sequenceNumber && |
+ this->priority == rhs.priority); |
} |
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) { |
- // Timestamp and sequence numbers are identical - deem the left |
- // hand side to be "smaller" (i.e., "earlier") if it is primary, and |
- // right hand side is not. |
- return (this->primary && !rhs.primary); |
+ // 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; |
} |
return (static_cast<uint16_t>(rhs.header.sequenceNumber |
- this->header.sequenceNumber) < 0xFFFF / 2); |