OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 | 11 |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 #include "webrtc/base/arraysize.h" | 16 #include "webrtc/base/arraysize.h" |
17 #include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h" | 17 #include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h" |
18 | 18 |
| 19 #if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) |
| 20 |
19 namespace webrtc { | 21 namespace webrtc { |
20 | 22 |
21 static const uint8_t NALU_TEST_DATA_0[] = {0xAA, 0xBB, 0xCC}; | 23 static const uint8_t NALU_TEST_DATA_0[] = {0xAA, 0xBB, 0xCC}; |
22 static const uint8_t NALU_TEST_DATA_1[] = {0xDE, 0xAD, 0xBE, 0xEF}; | 24 static const uint8_t NALU_TEST_DATA_1[] = {0xDE, 0xAD, 0xBE, 0xEF}; |
23 | 25 |
| 26 TEST(H264VideoToolboxNaluTest, TestHasVideoFormatDescription) { |
| 27 const uint8_t sps_buffer[] = {0x00, 0x00, 0x00, 0x01, 0x27}; |
| 28 EXPECT_TRUE(H264AnnexBBufferHasVideoFormatDescription(sps_buffer, |
| 29 arraysize(sps_buffer))); |
| 30 const uint8_t other_buffer[] = {0x00, 0x00, 0x00, 0x01, 0x28}; |
| 31 EXPECT_FALSE(H264AnnexBBufferHasVideoFormatDescription( |
| 32 other_buffer, arraysize(other_buffer))); |
| 33 } |
| 34 |
| 35 TEST(H264VideoToolboxNaluTest, TestCreateVideoFormatDescription) { |
| 36 const uint8_t sps_pps_buffer[] = { |
| 37 // SPS nalu. |
| 38 0x00, 0x00, 0x00, 0x01, |
| 39 0x27, 0x42, 0x00, 0x1E, 0xAB, 0x40, 0xF0, 0x28, 0xD3, 0x70, 0x20, 0x20, |
| 40 0x20, 0x20, |
| 41 // PPS nalu. |
| 42 0x00, 0x00, 0x00, 0x01, |
| 43 0x28, 0xCE, 0x3C, 0x30 |
| 44 }; |
| 45 CMVideoFormatDescriptionRef description = |
| 46 CreateVideoFormatDescription(sps_pps_buffer, arraysize(sps_pps_buffer)); |
| 47 EXPECT_TRUE(description); |
| 48 if (description) { |
| 49 CFRelease(description); |
| 50 description = nullptr; |
| 51 } |
| 52 const uint8_t other_buffer[] = {0x00, 0x00, 0x00, 0x01, 0x28}; |
| 53 EXPECT_FALSE(CreateVideoFormatDescription(other_buffer, |
| 54 arraysize(other_buffer))); |
| 55 } |
| 56 |
24 TEST(AnnexBBufferReaderTest, TestReadEmptyInput) { | 57 TEST(AnnexBBufferReaderTest, TestReadEmptyInput) { |
25 const uint8_t annex_b_test_data[] = {0x00}; | 58 const uint8_t annex_b_test_data[] = {0x00}; |
26 AnnexBBufferReader reader(annex_b_test_data, 0); | 59 AnnexBBufferReader reader(annex_b_test_data, 0); |
27 const uint8_t* nalu = nullptr; | 60 const uint8_t* nalu = nullptr; |
28 size_t nalu_length = 0; | 61 size_t nalu_length = 0; |
29 EXPECT_EQ(0u, reader.BytesRemaining()); | 62 EXPECT_EQ(0u, reader.BytesRemaining()); |
30 EXPECT_FALSE(reader.ReadNalu(&nalu, &nalu_length)); | 63 EXPECT_FALSE(reader.ReadNalu(&nalu, &nalu_length)); |
31 EXPECT_EQ(nullptr, nalu); | 64 EXPECT_EQ(nullptr, nalu); |
32 EXPECT_EQ(0u, nalu_length); | 65 EXPECT_EQ(0u, nalu_length); |
33 } | 66 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 memset(buffer.get(), 0, buffer_size); | 177 memset(buffer.get(), 0, buffer_size); |
145 AvccBufferWriter writer(buffer.get(), buffer_size); | 178 AvccBufferWriter writer(buffer.get(), buffer_size); |
146 EXPECT_EQ(buffer_size, writer.BytesRemaining()); | 179 EXPECT_EQ(buffer_size, writer.BytesRemaining()); |
147 EXPECT_FALSE(writer.WriteNalu(NALU_TEST_DATA_0, arraysize(NALU_TEST_DATA_0))); | 180 EXPECT_FALSE(writer.WriteNalu(NALU_TEST_DATA_0, arraysize(NALU_TEST_DATA_0))); |
148 EXPECT_EQ(buffer_size, writer.BytesRemaining()); | 181 EXPECT_EQ(buffer_size, writer.BytesRemaining()); |
149 EXPECT_EQ(0, | 182 EXPECT_EQ(0, |
150 memcmp(expected_buffer, buffer.get(), arraysize(expected_buffer))); | 183 memcmp(expected_buffer, buffer.get(), arraysize(expected_buffer))); |
151 } | 184 } |
152 | 185 |
153 } // namespace webrtc | 186 } // namespace webrtc |
| 187 |
| 188 #endif // WEBRTC_VIDEO_TOOLBOX_SUPPORTED |
OLD | NEW |