OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include <algorithm> |
| 12 |
| 13 #include "webrtc/base/gunit.h" |
| 14 #include "webrtc/media/base/fakertp.h" |
| 15 |
| 16 void CompareHeaderExtensions(const char* packet1, size_t packet1_size, |
| 17 const char* packet2, size_t packet2_size, |
| 18 const std::vector<int> encrypted_headers, bool expect_equal) { |
| 19 // Sanity check: packets must be large enough to contain the RTP header and |
| 20 // extensions header. |
| 21 RTC_CHECK_GE(packet1_size, 12 + 4); |
| 22 RTC_CHECK_GE(packet2_size, 12 + 4); |
| 23 // RTP extension headers are the same. |
| 24 EXPECT_EQ(0, memcmp(packet1 + 12, packet2 + 12, 4)); |
| 25 // Check for one-byte header extensions. |
| 26 EXPECT_EQ('\xBE', packet1[12]); |
| 27 EXPECT_EQ('\xDE', packet1[13]); |
| 28 // Determine position and size of extension headers. |
| 29 size_t extension_words = packet1[14] << 8 | packet1[15]; |
| 30 const char* extension_data1 = packet1 + 12 + 4; |
| 31 const char* extension_end1 = extension_data1 + extension_words * 4; |
| 32 const char* extension_data2 = packet2 + 12 + 4; |
| 33 // Sanity check: packets must be large enough to contain the RTP header |
| 34 // extensions. |
| 35 RTC_CHECK_GE(packet1_size, 12 + 4 + extension_words * 4); |
| 36 RTC_CHECK_GE(packet2_size, 12 + 4 + extension_words * 4); |
| 37 while (extension_data1 < extension_end1) { |
| 38 uint8_t id = (*extension_data1 & 0xf0) >> 4; |
| 39 uint8_t len = (*extension_data1 & 0x0f) +1; |
| 40 extension_data1++; |
| 41 extension_data2++; |
| 42 EXPECT_LE(extension_data1, extension_end1); |
| 43 if (id == 15) { |
| 44 // Finished parsing. |
| 45 break; |
| 46 } |
| 47 |
| 48 // The header extension doesn't get encrypted if the id is not in the |
| 49 // list of header extensions to encrypt. |
| 50 if (expect_equal || |
| 51 std::find(encrypted_headers.begin(), encrypted_headers.end(), id) |
| 52 == encrypted_headers.end()) { |
| 53 EXPECT_EQ(0, memcmp(extension_data1, extension_data2, len)); |
| 54 } else { |
| 55 EXPECT_NE(0, memcmp(extension_data1, extension_data2, len)); |
| 56 } |
| 57 |
| 58 extension_data1 += len; |
| 59 extension_data2 += len; |
| 60 // Skip padding. |
| 61 while (extension_data1 < extension_end1 && *extension_data1 == 0) { |
| 62 extension_data1++; |
| 63 extension_data2++; |
| 64 } |
| 65 } |
| 66 } |
OLD | NEW |