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> |
| 13 |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 | 15 |
14 #include "webrtc/base/arraysize.h" | 16 #include "webrtc/base/arraysize.h" |
15 #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" |
16 | 18 |
17 namespace webrtc { | 19 namespace webrtc { |
18 | 20 |
19 static const uint8_t NALU_TEST_DATA_0[] = {0xAA, 0xBB, 0xCC}; | 21 static const uint8_t NALU_TEST_DATA_0[] = {0xAA, 0xBB, 0xCC}; |
20 static const uint8_t NALU_TEST_DATA_1[] = {0xDE, 0xAD, 0xBE, 0xEF}; | 22 static const uint8_t NALU_TEST_DATA_1[] = {0xDE, 0xAD, 0xBE, 0xEF}; |
21 | 23 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 EXPECT_EQ(2u, nalu_length); | 85 EXPECT_EQ(2u, nalu_length); |
84 EXPECT_EQ(0u, reader.BytesRemaining()); | 86 EXPECT_EQ(0u, reader.BytesRemaining()); |
85 EXPECT_FALSE(reader.ReadNalu(&nalu, &nalu_length)); | 87 EXPECT_FALSE(reader.ReadNalu(&nalu, &nalu_length)); |
86 EXPECT_EQ(nullptr, nalu); | 88 EXPECT_EQ(nullptr, nalu); |
87 EXPECT_EQ(0u, nalu_length); | 89 EXPECT_EQ(0u, nalu_length); |
88 } | 90 } |
89 | 91 |
90 TEST(AvccBufferWriterTest, TestEmptyOutputBuffer) { | 92 TEST(AvccBufferWriterTest, TestEmptyOutputBuffer) { |
91 const uint8_t expected_buffer[] = {0x00}; | 93 const uint8_t expected_buffer[] = {0x00}; |
92 const size_t buffer_size = 1; | 94 const size_t buffer_size = 1; |
93 rtc::scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); | 95 std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); |
94 memset(buffer.get(), 0, buffer_size); | 96 memset(buffer.get(), 0, buffer_size); |
95 AvccBufferWriter writer(buffer.get(), 0); | 97 AvccBufferWriter writer(buffer.get(), 0); |
96 EXPECT_EQ(0u, writer.BytesRemaining()); | 98 EXPECT_EQ(0u, writer.BytesRemaining()); |
97 EXPECT_FALSE(writer.WriteNalu(NALU_TEST_DATA_0, arraysize(NALU_TEST_DATA_0))); | 99 EXPECT_FALSE(writer.WriteNalu(NALU_TEST_DATA_0, arraysize(NALU_TEST_DATA_0))); |
98 EXPECT_EQ(0, | 100 EXPECT_EQ(0, |
99 memcmp(expected_buffer, buffer.get(), arraysize(expected_buffer))); | 101 memcmp(expected_buffer, buffer.get(), arraysize(expected_buffer))); |
100 } | 102 } |
101 | 103 |
102 TEST(AvccBufferWriterTest, TestWriteSingleNalu) { | 104 TEST(AvccBufferWriterTest, TestWriteSingleNalu) { |
103 const uint8_t expected_buffer[] = { | 105 const uint8_t expected_buffer[] = { |
104 0x00, 0x00, 0x00, 0x03, 0xAA, 0xBB, 0xCC, | 106 0x00, 0x00, 0x00, 0x03, 0xAA, 0xBB, 0xCC, |
105 }; | 107 }; |
106 const size_t buffer_size = arraysize(NALU_TEST_DATA_0) + 4; | 108 const size_t buffer_size = arraysize(NALU_TEST_DATA_0) + 4; |
107 rtc::scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); | 109 std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); |
108 AvccBufferWriter writer(buffer.get(), buffer_size); | 110 AvccBufferWriter writer(buffer.get(), buffer_size); |
109 EXPECT_EQ(buffer_size, writer.BytesRemaining()); | 111 EXPECT_EQ(buffer_size, writer.BytesRemaining()); |
110 EXPECT_TRUE(writer.WriteNalu(NALU_TEST_DATA_0, arraysize(NALU_TEST_DATA_0))); | 112 EXPECT_TRUE(writer.WriteNalu(NALU_TEST_DATA_0, arraysize(NALU_TEST_DATA_0))); |
111 EXPECT_EQ(0u, writer.BytesRemaining()); | 113 EXPECT_EQ(0u, writer.BytesRemaining()); |
112 EXPECT_FALSE(writer.WriteNalu(NALU_TEST_DATA_1, arraysize(NALU_TEST_DATA_1))); | 114 EXPECT_FALSE(writer.WriteNalu(NALU_TEST_DATA_1, arraysize(NALU_TEST_DATA_1))); |
113 EXPECT_EQ(0, | 115 EXPECT_EQ(0, |
114 memcmp(expected_buffer, buffer.get(), arraysize(expected_buffer))); | 116 memcmp(expected_buffer, buffer.get(), arraysize(expected_buffer))); |
115 } | 117 } |
116 | 118 |
117 TEST(AvccBufferWriterTest, TestWriteMultipleNalus) { | 119 TEST(AvccBufferWriterTest, TestWriteMultipleNalus) { |
118 // clang-format off | 120 // clang-format off |
119 const uint8_t expected_buffer[] = { | 121 const uint8_t expected_buffer[] = { |
120 0x00, 0x00, 0x00, 0x03, 0xAA, 0xBB, 0xCC, | 122 0x00, 0x00, 0x00, 0x03, 0xAA, 0xBB, 0xCC, |
121 0x00, 0x00, 0x00, 0x04, 0xDE, 0xAD, 0xBE, 0xEF | 123 0x00, 0x00, 0x00, 0x04, 0xDE, 0xAD, 0xBE, 0xEF |
122 }; | 124 }; |
123 // clang-format on | 125 // clang-format on |
124 const size_t buffer_size = | 126 const size_t buffer_size = |
125 arraysize(NALU_TEST_DATA_0) + arraysize(NALU_TEST_DATA_1) + 8; | 127 arraysize(NALU_TEST_DATA_0) + arraysize(NALU_TEST_DATA_1) + 8; |
126 rtc::scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); | 128 std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); |
127 AvccBufferWriter writer(buffer.get(), buffer_size); | 129 AvccBufferWriter writer(buffer.get(), buffer_size); |
128 EXPECT_EQ(buffer_size, writer.BytesRemaining()); | 130 EXPECT_EQ(buffer_size, writer.BytesRemaining()); |
129 EXPECT_TRUE(writer.WriteNalu(NALU_TEST_DATA_0, arraysize(NALU_TEST_DATA_0))); | 131 EXPECT_TRUE(writer.WriteNalu(NALU_TEST_DATA_0, arraysize(NALU_TEST_DATA_0))); |
130 EXPECT_EQ(buffer_size - (arraysize(NALU_TEST_DATA_0) + 4), | 132 EXPECT_EQ(buffer_size - (arraysize(NALU_TEST_DATA_0) + 4), |
131 writer.BytesRemaining()); | 133 writer.BytesRemaining()); |
132 EXPECT_TRUE(writer.WriteNalu(NALU_TEST_DATA_1, arraysize(NALU_TEST_DATA_1))); | 134 EXPECT_TRUE(writer.WriteNalu(NALU_TEST_DATA_1, arraysize(NALU_TEST_DATA_1))); |
133 EXPECT_EQ(0u, writer.BytesRemaining()); | 135 EXPECT_EQ(0u, writer.BytesRemaining()); |
134 EXPECT_EQ(0, | 136 EXPECT_EQ(0, |
135 memcmp(expected_buffer, buffer.get(), arraysize(expected_buffer))); | 137 memcmp(expected_buffer, buffer.get(), arraysize(expected_buffer))); |
136 } | 138 } |
137 | 139 |
138 TEST(AvccBufferWriterTest, TestOverflow) { | 140 TEST(AvccBufferWriterTest, TestOverflow) { |
139 const uint8_t expected_buffer[] = {0x00, 0x00, 0x00}; | 141 const uint8_t expected_buffer[] = {0x00, 0x00, 0x00}; |
140 const size_t buffer_size = arraysize(NALU_TEST_DATA_0); | 142 const size_t buffer_size = arraysize(NALU_TEST_DATA_0); |
141 rtc::scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); | 143 std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); |
142 memset(buffer.get(), 0, buffer_size); | 144 memset(buffer.get(), 0, buffer_size); |
143 AvccBufferWriter writer(buffer.get(), buffer_size); | 145 AvccBufferWriter writer(buffer.get(), buffer_size); |
144 EXPECT_EQ(buffer_size, writer.BytesRemaining()); | 146 EXPECT_EQ(buffer_size, writer.BytesRemaining()); |
145 EXPECT_FALSE(writer.WriteNalu(NALU_TEST_DATA_0, arraysize(NALU_TEST_DATA_0))); | 147 EXPECT_FALSE(writer.WriteNalu(NALU_TEST_DATA_0, arraysize(NALU_TEST_DATA_0))); |
146 EXPECT_EQ(buffer_size, writer.BytesRemaining()); | 148 EXPECT_EQ(buffer_size, writer.BytesRemaining()); |
147 EXPECT_EQ(0, | 149 EXPECT_EQ(0, |
148 memcmp(expected_buffer, buffer.get(), arraysize(expected_buffer))); | 150 memcmp(expected_buffer, buffer.get(), arraysize(expected_buffer))); |
149 } | 151 } |
150 | 152 |
151 } // namespace webrtc | 153 } // namespace webrtc |
OLD | NEW |