 Chromium Code Reviews
 Chromium Code Reviews Issue 2342443005:
  Moved Opus-specific payload splitting into AudioDecoderOpus.  (Closed)
    
  
    Issue 2342443005:
  Moved Opus-specific payload splitting into AudioDecoderOpus.  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 
| 3 * | 3 * | 
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found | 
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may | 
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. | 
| 9 */ | 9 */ | 
| 10 | 10 | 
| 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_ | 
| 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_ | 
| 13 | 13 | 
| 14 #include <list> | 14 #include <list> | 
| 15 #include <memory> | 15 #include <memory> | 
| 16 | 16 | 
| 17 #include "webrtc/base/buffer.h" | 17 #include "webrtc/base/buffer.h" | 
| 18 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" | 18 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" | 
| 19 #include "webrtc/modules/audio_coding/neteq/tick_timer.h" | 19 #include "webrtc/modules/audio_coding/neteq/tick_timer.h" | 
| 20 #include "webrtc/modules/include/module_common_types.h" | 20 #include "webrtc/modules/include/module_common_types.h" | 
| 21 #include "webrtc/typedefs.h" | 21 #include "webrtc/typedefs.h" | 
| 22 | 22 | 
| 23 namespace webrtc { | 23 namespace webrtc { | 
| 24 | 24 | 
| 25 // Struct for holding RTP packets. | 25 // Struct for holding RTP packets. | 
| 26 struct Packet { | 26 struct Packet { | 
| 27 struct Priority { | |
| 28 Priority() : codec_level(0), red_level(0) {} | |
| 29 Priority(int codec_level, int red_level) | |
| 30 : codec_level(codec_level), red_level(red_level) {} | |
| 31 | |
| 32 int codec_level; | |
| 33 int red_level; | |
| 34 | |
| 35 // Priorities are sorted low-to-high, first on the level the codec | |
| 36 // prioritizes it, then on the level of RED packet it is; i.e. if it is a | |
| 37 // primary or secondary payload of a RED packet. For example: with Opus, an | |
| 38 // Fec packet (which the decoder prioritizes lower than a regular packet) | |
| 39 // will not be used if there is _any_ RED payload for the same | |
| 40 // timeframe. The highest priority packet will have levels {0, 0}. | |
| 
kwiberg-webrtc
2016/09/20 09:14:45
It's probably a good idea to DCHECK that the level
 
ossu
2016/09/20 13:51:56
Acknowledged.
 | |
| 41 bool operator<(const Priority& b) const { | |
| 42 if (codec_level == b.codec_level) | |
| 43 return red_level < b.red_level; | |
| 44 | |
| 45 return codec_level < b.codec_level; | |
| 46 } | |
| 47 bool operator==(const Priority& b) const { | |
| 48 return codec_level == b.codec_level && red_level == b.red_level; | |
| 49 } | |
| 50 bool operator!=(const Priority& b) const { return !(*this == b); } | |
| 51 bool operator>(const Priority& b) const { return b < *this; } | |
| 52 bool operator<=(const Priority& b) const { return !(b > *this); } | |
| 53 bool operator>=(const Priority& b) const { return !(b < *this); } | |
| 54 }; | |
| 55 | |
| 27 RTPHeader header; | 56 RTPHeader header; | 
| 28 // Datagram excluding RTP header and header extension. | 57 // Datagram excluding RTP header and header extension. | 
| 29 rtc::Buffer payload; | 58 rtc::Buffer payload; | 
| 30 bool primary = true; // Primary, i.e., not redundant payload. | 59 Priority priority; | 
| 31 std::unique_ptr<TickTimer::Stopwatch> waiting_time; | 60 std::unique_ptr<TickTimer::Stopwatch> waiting_time; | 
| 32 std::unique_ptr<AudioDecoder::EncodedAudioFrame> frame; | 61 std::unique_ptr<AudioDecoder::EncodedAudioFrame> frame; | 
| 33 | 62 | 
| 34 Packet(); | 63 Packet(); | 
| 35 ~Packet(); | 64 ~Packet(); | 
| 36 | 65 | 
| 37 // Comparison operators. Establish a packet ordering based on (1) timestamp, | 66 // Comparison operators. Establish a packet ordering based on (1) timestamp, | 
| 38 // (2) sequence number and (3) redundancy. | 67 // (2) sequence number and (3) redundancy. | 
| 39 // Timestamp and sequence numbers are compared taking wrap-around into | 68 // Timestamp and sequence numbers are compared taking wrap-around into | 
| 40 // account. For two packets with the same sequence number and timestamp a | 69 // account. For two packets with the same sequence number and timestamp a | 
| 41 // primary payload is considered "smaller" than a secondary. | 70 // primary payload is considered "smaller" than a secondary. | 
| 42 bool operator==(const Packet& rhs) const { | 71 bool operator==(const Packet& rhs) const { | 
| 43 return (this->header.timestamp == rhs.header.timestamp && | 72 return (this->header.timestamp == rhs.header.timestamp && | 
| 44 this->header.sequenceNumber == rhs.header.sequenceNumber && | 73 this->header.sequenceNumber == rhs.header.sequenceNumber && | 
| 45 this->primary == rhs.primary); | 74 this->priority == rhs.priority); | 
| 46 } | 75 } | 
| 47 bool operator!=(const Packet& rhs) const { return !operator==(rhs); } | 76 bool operator!=(const Packet& rhs) const { return !operator==(rhs); } | 
| 48 bool operator<(const Packet& rhs) const { | 77 bool operator<(const Packet& rhs) const { | 
| 49 if (this->header.timestamp == rhs.header.timestamp) { | 78 if (this->header.timestamp == rhs.header.timestamp) { | 
| 50 if (this->header.sequenceNumber == rhs.header.sequenceNumber) { | 79 if (this->header.sequenceNumber == rhs.header.sequenceNumber) { | 
| 51 // Timestamp and sequence numbers are identical - deem the left | 80 // Timestamp and sequence numbers are identical - deem the left hand | 
| 52 // hand side to be "smaller" (i.e., "earlier") if it is primary, and | 81 // side to be "smaller" (i.e., "earlier") if it has higher priority. | 
| 53 // right hand side is not. | 82 return this->priority < rhs.priority; | 
| 54 return (this->primary && !rhs.primary); | |
| 55 } | 83 } | 
| 56 return (static_cast<uint16_t>(rhs.header.sequenceNumber | 84 return (static_cast<uint16_t>(rhs.header.sequenceNumber | 
| 57 - this->header.sequenceNumber) < 0xFFFF / 2); | 85 - this->header.sequenceNumber) < 0xFFFF / 2); | 
| 58 } | 86 } | 
| 59 return (static_cast<uint32_t>(rhs.header.timestamp | 87 return (static_cast<uint32_t>(rhs.header.timestamp | 
| 60 - this->header.timestamp) < 0xFFFFFFFF / 2); | 88 - this->header.timestamp) < 0xFFFFFFFF / 2); | 
| 61 } | 89 } | 
| 62 bool operator>(const Packet& rhs) const { return rhs.operator<(*this); } | 90 bool operator>(const Packet& rhs) const { return rhs.operator<(*this); } | 
| 63 bool operator<=(const Packet& rhs) const { return !operator>(rhs); } | 91 bool operator<=(const Packet& rhs) const { return !operator>(rhs); } | 
| 64 bool operator>=(const Packet& rhs) const { return !operator<(rhs); } | 92 bool operator>=(const Packet& rhs) const { return !operator<(rhs); } | 
| 65 | 93 | 
| 66 bool empty() const { return !frame && payload.empty(); } | 94 bool empty() const { return !frame && payload.empty(); } | 
| 67 }; | 95 }; | 
| 68 | 96 | 
| 69 // A list of packets. | 97 // A list of packets. | 
| 70 typedef std::list<Packet*> PacketList; | 98 typedef std::list<Packet*> PacketList; | 
| 71 | 99 | 
| 72 } // namespace webrtc | 100 } // namespace webrtc | 
| 73 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_ | 101 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_ | 
| OLD | NEW |