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" | |
21 #include "webrtc/typedefs.h" | 20 #include "webrtc/typedefs.h" |
22 | 21 |
23 namespace webrtc { | 22 namespace webrtc { |
24 | 23 |
25 // Struct for holding RTP packets. | 24 // Struct for holding RTP packets. |
26 struct Packet { | 25 struct Packet { |
27 struct Priority { | 26 struct Priority { |
28 Priority() : codec_level(0), red_level(0) {} | 27 Priority() : codec_level(0), red_level(0) {} |
29 Priority(int codec_level, int red_level) | 28 Priority(int codec_level, int red_level) |
30 : codec_level(codec_level), red_level(red_level) { | 29 : codec_level(codec_level), red_level(red_level) { |
(...skipping 28 matching lines...) Expand all Loading... |
59 bool operator<=(const Priority& b) const { return !(b > *this); } | 58 bool operator<=(const Priority& b) const { return !(b > *this); } |
60 bool operator>=(const Priority& b) const { return !(b < *this); } | 59 bool operator>=(const Priority& b) const { return !(b < *this); } |
61 | 60 |
62 private: | 61 private: |
63 void CheckInvariant() const { | 62 void CheckInvariant() const { |
64 RTC_DCHECK_GE(codec_level, 0); | 63 RTC_DCHECK_GE(codec_level, 0); |
65 RTC_DCHECK_GE(red_level, 0); | 64 RTC_DCHECK_GE(red_level, 0); |
66 } | 65 } |
67 }; | 66 }; |
68 | 67 |
69 RTPHeader header; | 68 uint32_t timestamp; |
| 69 uint16_t sequence_number; |
| 70 uint8_t payload_type; |
70 // Datagram excluding RTP header and header extension. | 71 // Datagram excluding RTP header and header extension. |
71 rtc::Buffer payload; | 72 rtc::Buffer payload; |
72 Priority priority; | 73 Priority priority; |
73 std::unique_ptr<TickTimer::Stopwatch> waiting_time; | 74 std::unique_ptr<TickTimer::Stopwatch> waiting_time; |
74 std::unique_ptr<AudioDecoder::EncodedAudioFrame> frame; | 75 std::unique_ptr<AudioDecoder::EncodedAudioFrame> frame; |
75 | 76 |
76 Packet(); | 77 Packet(); |
77 ~Packet(); | 78 ~Packet(); |
78 | 79 |
79 // Comparison operators. Establish a packet ordering based on (1) timestamp, | 80 // Comparison operators. Establish a packet ordering based on (1) timestamp, |
80 // (2) sequence number and (3) redundancy. | 81 // (2) sequence number and (3) redundancy. |
81 // Timestamp and sequence numbers are compared taking wrap-around into | 82 // Timestamp and sequence numbers are compared taking wrap-around into |
82 // account. For two packets with the same sequence number and timestamp a | 83 // account. For two packets with the same sequence number and timestamp a |
83 // primary payload is considered "smaller" than a secondary. | 84 // primary payload is considered "smaller" than a secondary. |
84 bool operator==(const Packet& rhs) const { | 85 bool operator==(const Packet& rhs) const { |
85 return (this->header.timestamp == rhs.header.timestamp && | 86 return (this->timestamp == rhs.timestamp && |
86 this->header.sequenceNumber == rhs.header.sequenceNumber && | 87 this->sequence_number == rhs.sequence_number && |
87 this->priority == rhs.priority); | 88 this->priority == rhs.priority); |
88 } | 89 } |
89 bool operator!=(const Packet& rhs) const { return !operator==(rhs); } | 90 bool operator!=(const Packet& rhs) const { return !operator==(rhs); } |
90 bool operator<(const Packet& rhs) const { | 91 bool operator<(const Packet& rhs) const { |
91 if (this->header.timestamp == rhs.header.timestamp) { | 92 if (this->timestamp == rhs.timestamp) { |
92 if (this->header.sequenceNumber == rhs.header.sequenceNumber) { | 93 if (this->sequence_number == rhs.sequence_number) { |
93 // Timestamp and sequence numbers are identical - deem the left hand | 94 // Timestamp and sequence numbers are identical - deem the left hand |
94 // side to be "smaller" (i.e., "earlier") if it has higher priority. | 95 // side to be "smaller" (i.e., "earlier") if it has higher priority. |
95 return this->priority < rhs.priority; | 96 return this->priority < rhs.priority; |
96 } | 97 } |
97 return (static_cast<uint16_t>(rhs.header.sequenceNumber | 98 return (static_cast<uint16_t>(rhs.sequence_number - |
98 - this->header.sequenceNumber) < 0xFFFF / 2); | 99 this->sequence_number) < 0xFFFF / 2); |
99 } | 100 } |
100 return (static_cast<uint32_t>(rhs.header.timestamp | 101 return (static_cast<uint32_t>(rhs.timestamp - this->timestamp) < |
101 - this->header.timestamp) < 0xFFFFFFFF / 2); | 102 0xFFFFFFFF / 2); |
102 } | 103 } |
103 bool operator>(const Packet& rhs) const { return rhs.operator<(*this); } | 104 bool operator>(const Packet& rhs) const { return rhs.operator<(*this); } |
104 bool operator<=(const Packet& rhs) const { return !operator>(rhs); } | 105 bool operator<=(const Packet& rhs) const { return !operator>(rhs); } |
105 bool operator>=(const Packet& rhs) const { return !operator<(rhs); } | 106 bool operator>=(const Packet& rhs) const { return !operator<(rhs); } |
106 | 107 |
107 bool empty() const { return !frame && payload.empty(); } | 108 bool empty() const { return !frame && payload.empty(); } |
108 }; | 109 }; |
109 | 110 |
110 // A list of packets. | 111 // A list of packets. |
111 typedef std::list<Packet*> PacketList; | 112 typedef std::list<Packet*> PacketList; |
112 | 113 |
113 } // namespace webrtc | 114 } // namespace webrtc |
114 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_ | 115 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_H_ |
OLD | NEW |