Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(531)

Side by Side Diff: webrtc/modules/audio_coding/neteq/packet.h

Issue 2342443005: Moved Opus-specific payload splitting into AudioDecoderOpus. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 uint8_t codec_level;
ossu 2016/09/15 12:22:53 I'm not super psyched about the naming here, but i
hlundin-webrtc 2016/09/16 07:51:27 Nope.
29 uint8_t red_level;
30
31 // Priorities are sorted low-to-high, first on the level the codec
32 // prioritizes it, then on the level of RED packet it is; i.e. if it is a
33 // primary or secondary payload of a RED packet. For example: with Opus, an
34 // Fec packet (which the decoder prioritizes lower than a regular packet)
35 // will not be used if there is _any_ RED payload for the same
36 // timeframe. The highest priority packet will have levels {0, 0}.
37 bool operator<(const Priority& b) const {
38 if (codec_level == b.codec_level)
39 return red_level < b.red_level;
40
41 return codec_level < b.codec_level;
42 }
43 bool operator==(const Priority& b) const {
44 return codec_level == b.codec_level && red_level == b.red_level;
45 }
46 bool operator!=(const Priority& b) const { return !(*this == b); }
47 bool operator>(const Priority& b) const { return b < *this; }
48 bool operator<=(const Priority& b) const { return !(b > *this); }
49 bool operator>=(const Priority& b) const { return !(b < *this); }
50 };
51
52 static constexpr Priority kHighestPriority = {0, 0};
kwiberg-webrtc 2016/09/19 11:07:49 I'm a bit suspicious about this constant. Why is i
ossu 2016/09/19 11:41:01 I was thinking it would be clearer to set somethin
kwiberg-webrtc 2016/09/19 11:55:16 Makes sense as a short-hand---*if* priority values
ossu 2016/09/19 14:07:34 I think stats is one reason. To me it makes sense
53
27 RTPHeader header; 54 RTPHeader header;
28 // Datagram excluding RTP header and header extension. 55 // Datagram excluding RTP header and header extension.
29 rtc::Buffer payload; 56 rtc::Buffer payload;
30 bool primary = true; // Primary, i.e., not redundant payload. 57 Priority priority = kHighestPriority;
31 std::unique_ptr<TickTimer::Stopwatch> waiting_time; 58 std::unique_ptr<TickTimer::Stopwatch> waiting_time;
32 std::unique_ptr<AudioDecoder::EncodedAudioFrame> frame; 59 std::unique_ptr<AudioDecoder::EncodedAudioFrame> frame;
33 60
34 Packet(); 61 Packet();
35 ~Packet(); 62 ~Packet();
36 63
37 // Comparison operators. Establish a packet ordering based on (1) timestamp, 64 // Comparison operators. Establish a packet ordering based on (1) timestamp,
38 // (2) sequence number and (3) redundancy. 65 // (2) sequence number and (3) redundancy.
39 // Timestamp and sequence numbers are compared taking wrap-around into 66 // Timestamp and sequence numbers are compared taking wrap-around into
40 // account. For two packets with the same sequence number and timestamp a 67 // account. For two packets with the same sequence number and timestamp a
41 // primary payload is considered "smaller" than a secondary. 68 // primary payload is considered "smaller" than a secondary.
42 bool operator==(const Packet& rhs) const { 69 bool operator==(const Packet& rhs) const {
43 return (this->header.timestamp == rhs.header.timestamp && 70 return (this->header.timestamp == rhs.header.timestamp &&
44 this->header.sequenceNumber == rhs.header.sequenceNumber && 71 this->header.sequenceNumber == rhs.header.sequenceNumber &&
45 this->primary == rhs.primary); 72 this->priority == rhs.priority);
46 } 73 }
47 bool operator!=(const Packet& rhs) const { return !operator==(rhs); } 74 bool operator!=(const Packet& rhs) const { return !operator==(rhs); }
48 bool operator<(const Packet& rhs) const { 75 bool operator<(const Packet& rhs) const {
49 if (this->header.timestamp == rhs.header.timestamp) { 76 if (this->header.timestamp == rhs.header.timestamp) {
50 if (this->header.sequenceNumber == rhs.header.sequenceNumber) { 77 if (this->header.sequenceNumber == rhs.header.sequenceNumber) {
51 // Timestamp and sequence numbers are identical - deem the left 78 // Timestamp and sequence numbers are identical - deem the left hand
52 // hand side to be "smaller" (i.e., "earlier") if it is primary, and 79 // side to be "smaller" (i.e., "earlier") if it has higher priority.
53 // right hand side is not. 80 return this->priority < rhs.priority;
54 return (this->primary && !rhs.primary);
55 } 81 }
56 return (static_cast<uint16_t>(rhs.header.sequenceNumber 82 return (static_cast<uint16_t>(rhs.header.sequenceNumber
57 - this->header.sequenceNumber) < 0xFFFF / 2); 83 - this->header.sequenceNumber) < 0xFFFF / 2);
58 } 84 }
59 return (static_cast<uint32_t>(rhs.header.timestamp 85 return (static_cast<uint32_t>(rhs.header.timestamp
60 - this->header.timestamp) < 0xFFFFFFFF / 2); 86 - this->header.timestamp) < 0xFFFFFFFF / 2);
61 } 87 }
62 bool operator>(const Packet& rhs) const { return rhs.operator<(*this); } 88 bool operator>(const Packet& rhs) const { return rhs.operator<(*this); }
63 bool operator<=(const Packet& rhs) const { return !operator>(rhs); } 89 bool operator<=(const Packet& rhs) const { return !operator>(rhs); }
64 bool operator>=(const Packet& rhs) const { return !operator<(rhs); } 90 bool operator>=(const Packet& rhs) const { return !operator<(rhs); }
65 91
66 bool empty() const { return !frame && payload.empty(); } 92 bool empty() const { return !frame && payload.empty(); }
67 }; 93 };
68 94
69 // A list of packets. 95 // A list of packets.
70 typedef std::list<Packet*> PacketList; 96 typedef std::list<Packet*> PacketList;
71 97
72 } // namespace webrtc 98 } // namespace webrtc
73 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_ 99 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698