| 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 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 // Creates a RED packet, with |num_payloads| payloads, with payload types given | 74 // Creates a RED packet, with |num_payloads| payloads, with payload types given |
| 75 // by the values in array |payload_types| (which must be of length | 75 // by the values in array |payload_types| (which must be of length |
| 76 // |num_payloads|). Each redundant payload is |timestamp_offset| samples | 76 // |num_payloads|). Each redundant payload is |timestamp_offset| samples |
| 77 // "behind" the the previous payload. | 77 // "behind" the the previous payload. |
| 78 Packet* CreateRedPayload(size_t num_payloads, | 78 Packet* CreateRedPayload(size_t num_payloads, |
| 79 uint8_t* payload_types, | 79 uint8_t* payload_types, |
| 80 int timestamp_offset, | 80 int timestamp_offset, |
| 81 bool embed_opus_fec = false) { | 81 bool embed_opus_fec = false) { |
| 82 Packet* packet = new Packet; | 82 Packet* packet = new Packet; |
| 83 packet->header.payloadType = kRedPayloadType; | 83 packet->payload_type = kRedPayloadType; |
| 84 packet->header.timestamp = kBaseTimestamp; | 84 packet->timestamp = kBaseTimestamp; |
| 85 packet->header.sequenceNumber = kSequenceNumber; | 85 packet->sequence_number = kSequenceNumber; |
| 86 packet->payload.SetSize((kPayloadLength + 1) + | 86 packet->payload.SetSize((kPayloadLength + 1) + |
| 87 (num_payloads - 1) * | 87 (num_payloads - 1) * |
| 88 (kPayloadLength + kRedHeaderLength)); | 88 (kPayloadLength + kRedHeaderLength)); |
| 89 uint8_t* payload_ptr = packet->payload.data(); | 89 uint8_t* payload_ptr = packet->payload.data(); |
| 90 for (size_t i = 0; i < num_payloads; ++i) { | 90 for (size_t i = 0; i < num_payloads; ++i) { |
| 91 // Write the RED headers. | 91 // Write the RED headers. |
| 92 if (i == num_payloads - 1) { | 92 if (i == num_payloads - 1) { |
| 93 // Special case for last payload. | 93 // Special case for last payload. |
| 94 *payload_ptr = payload_types[i] & 0x7F; // F = 0; | 94 *payload_ptr = payload_types[i] & 0x7F; // F = 0; |
| 95 ++payload_ptr; | 95 ++payload_ptr; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 120 } | 120 } |
| 121 return packet; | 121 return packet; |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Create a packet with all payload bytes set to |payload_value|. | 124 // Create a packet with all payload bytes set to |payload_value|. |
| 125 Packet* CreatePacket(uint8_t payload_type, | 125 Packet* CreatePacket(uint8_t payload_type, |
| 126 size_t payload_length, | 126 size_t payload_length, |
| 127 uint8_t payload_value, | 127 uint8_t payload_value, |
| 128 bool opus_fec = false) { | 128 bool opus_fec = false) { |
| 129 Packet* packet = new Packet; | 129 Packet* packet = new Packet; |
| 130 packet->header.payloadType = payload_type; | 130 packet->payload_type = payload_type; |
| 131 packet->header.timestamp = kBaseTimestamp; | 131 packet->timestamp = kBaseTimestamp; |
| 132 packet->header.sequenceNumber = kSequenceNumber; | 132 packet->sequence_number = kSequenceNumber; |
| 133 packet->payload.SetSize(payload_length); | 133 packet->payload.SetSize(payload_length); |
| 134 if (opus_fec) { | 134 if (opus_fec) { |
| 135 CreateOpusFecPayload(packet->payload.data(), packet->payload.size(), | 135 CreateOpusFecPayload(packet->payload.data(), packet->payload.size(), |
| 136 payload_value); | 136 payload_value); |
| 137 } else { | 137 } else { |
| 138 memset(packet->payload.data(), payload_value, packet->payload.size()); | 138 memset(packet->payload.data(), payload_value, packet->payload.size()); |
| 139 } | 139 } |
| 140 return packet; | 140 return packet; |
| 141 } | 141 } |
| 142 | 142 |
| 143 // Checks that |packet| has the attributes given in the remaining parameters. | 143 // Checks that |packet| has the attributes given in the remaining parameters. |
| 144 void VerifyPacket(const Packet* packet, | 144 void VerifyPacket(const Packet* packet, |
| 145 size_t payload_length, | 145 size_t payload_length, |
| 146 uint8_t payload_type, | 146 uint8_t payload_type, |
| 147 uint16_t sequence_number, | 147 uint16_t sequence_number, |
| 148 uint32_t timestamp, | 148 uint32_t timestamp, |
| 149 uint8_t payload_value, | 149 uint8_t payload_value, |
| 150 Packet::Priority priority) { | 150 Packet::Priority priority) { |
| 151 EXPECT_EQ(payload_length, packet->payload.size()); | 151 EXPECT_EQ(payload_length, packet->payload.size()); |
| 152 EXPECT_EQ(payload_type, packet->header.payloadType); | 152 EXPECT_EQ(payload_type, packet->payload_type); |
| 153 EXPECT_EQ(sequence_number, packet->header.sequenceNumber); | 153 EXPECT_EQ(sequence_number, packet->sequence_number); |
| 154 EXPECT_EQ(timestamp, packet->header.timestamp); | 154 EXPECT_EQ(timestamp, packet->timestamp); |
| 155 EXPECT_EQ(priority, packet->priority); | 155 EXPECT_EQ(priority, packet->priority); |
| 156 ASSERT_FALSE(packet->payload.empty()); | 156 ASSERT_FALSE(packet->payload.empty()); |
| 157 for (size_t i = 0; i < packet->payload.size(); ++i) { | 157 for (size_t i = 0; i < packet->payload.size(); ++i) { |
| 158 ASSERT_EQ(payload_value, packet->payload.data()[i]); | 158 ASSERT_EQ(payload_value, packet->payload.data()[i]); |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 | 161 |
| 162 void VerifyPacket(const Packet* packet, | 162 void VerifyPacket(const Packet* packet, |
| 163 size_t payload_length, | 163 size_t payload_length, |
| 164 uint8_t payload_type, | 164 uint8_t payload_type, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 TEST(RedPayloadSplitter, TwoPacketsOnePayload) { | 206 TEST(RedPayloadSplitter, TwoPacketsOnePayload) { |
| 207 uint8_t payload_types[] = {0}; | 207 uint8_t payload_types[] = {0}; |
| 208 const int kTimestampOffset = 160; | 208 const int kTimestampOffset = 160; |
| 209 // Create first packet, with a single RED payload. | 209 // Create first packet, with a single RED payload. |
| 210 Packet* packet = CreateRedPayload(1, payload_types, kTimestampOffset); | 210 Packet* packet = CreateRedPayload(1, payload_types, kTimestampOffset); |
| 211 PacketList packet_list; | 211 PacketList packet_list; |
| 212 packet_list.push_back(packet); | 212 packet_list.push_back(packet); |
| 213 // Create second packet, with a single RED payload. | 213 // Create second packet, with a single RED payload. |
| 214 packet = CreateRedPayload(1, payload_types, kTimestampOffset); | 214 packet = CreateRedPayload(1, payload_types, kTimestampOffset); |
| 215 // Manually change timestamp and sequence number of second packet. | 215 // Manually change timestamp and sequence number of second packet. |
| 216 packet->header.timestamp += kTimestampOffset; | 216 packet->timestamp += kTimestampOffset; |
| 217 packet->header.sequenceNumber++; | 217 packet->sequence_number++; |
| 218 packet_list.push_back(packet); | 218 packet_list.push_back(packet); |
| 219 RedPayloadSplitter splitter; | 219 RedPayloadSplitter splitter; |
| 220 EXPECT_TRUE(splitter.SplitRed(&packet_list)); | 220 EXPECT_TRUE(splitter.SplitRed(&packet_list)); |
| 221 ASSERT_EQ(2u, packet_list.size()); | 221 ASSERT_EQ(2u, packet_list.size()); |
| 222 // Check first packet. | 222 // Check first packet. |
| 223 packet = packet_list.front(); | 223 packet = packet_list.front(); |
| 224 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, | 224 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, |
| 225 kBaseTimestamp, 0, true); | 225 kBaseTimestamp, 0, true); |
| 226 delete packet; | 226 delete packet; |
| 227 packet_list.pop_front(); | 227 packet_list.pop_front(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 244 TEST(RedPayloadSplitter, TwoPacketsThreePayloads) { | 244 TEST(RedPayloadSplitter, TwoPacketsThreePayloads) { |
| 245 uint8_t payload_types[] = {2, 1, 0}; // Primary is the last one. | 245 uint8_t payload_types[] = {2, 1, 0}; // Primary is the last one. |
| 246 const int kTimestampOffset = 160; | 246 const int kTimestampOffset = 160; |
| 247 // Create first packet, with 3 RED payloads. | 247 // Create first packet, with 3 RED payloads. |
| 248 Packet* packet = CreateRedPayload(3, payload_types, kTimestampOffset); | 248 Packet* packet = CreateRedPayload(3, payload_types, kTimestampOffset); |
| 249 PacketList packet_list; | 249 PacketList packet_list; |
| 250 packet_list.push_back(packet); | 250 packet_list.push_back(packet); |
| 251 // Create first packet, with 3 RED payloads. | 251 // Create first packet, with 3 RED payloads. |
| 252 packet = CreateRedPayload(3, payload_types, kTimestampOffset); | 252 packet = CreateRedPayload(3, payload_types, kTimestampOffset); |
| 253 // Manually change timestamp and sequence number of second packet. | 253 // Manually change timestamp and sequence number of second packet. |
| 254 packet->header.timestamp += kTimestampOffset; | 254 packet->timestamp += kTimestampOffset; |
| 255 packet->header.sequenceNumber++; | 255 packet->sequence_number++; |
| 256 packet_list.push_back(packet); | 256 packet_list.push_back(packet); |
| 257 RedPayloadSplitter splitter; | 257 RedPayloadSplitter splitter; |
| 258 EXPECT_TRUE(splitter.SplitRed(&packet_list)); | 258 EXPECT_TRUE(splitter.SplitRed(&packet_list)); |
| 259 ASSERT_EQ(6u, packet_list.size()); | 259 ASSERT_EQ(6u, packet_list.size()); |
| 260 // Check first packet, A1. | 260 // Check first packet, A1. |
| 261 packet = packet_list.front(); | 261 packet = packet_list.front(); |
| 262 VerifyPacket(packet, kPayloadLength, payload_types[2], kSequenceNumber, | 262 VerifyPacket(packet, kPayloadLength, payload_types[2], kSequenceNumber, |
| 263 kBaseTimestamp, 2, {0, 0}); | 263 kBaseTimestamp, 2, {0, 0}); |
| 264 delete packet; | 264 delete packet; |
| 265 packet_list.pop_front(); | 265 packet_list.pop_front(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 ASSERT_EQ(1u, packet_list.size()); | 352 ASSERT_EQ(1u, packet_list.size()); |
| 353 // Check first packet. | 353 // Check first packet. |
| 354 packet = packet_list.front(); | 354 packet = packet_list.front(); |
| 355 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, | 355 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, |
| 356 kBaseTimestamp - 2 * kTimestampOffset, 0, {0, 2}); | 356 kBaseTimestamp - 2 * kTimestampOffset, 0, {0, 2}); |
| 357 delete packet; | 357 delete packet; |
| 358 packet_list.pop_front(); | 358 packet_list.pop_front(); |
| 359 } | 359 } |
| 360 | 360 |
| 361 } // namespace webrtc | 361 } // namespace webrtc |
| OLD | NEW |