| 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 #include "webrtc/modules/rtp_rtcp/source/h264_sps_parser.h" | 11 #include "webrtc/modules/rtp_rtcp/source/h264_sps_parser.h" |
| 12 | 12 |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 #include "webrtc/base/arraysize.h" |
| 15 #include "webrtc/base/bitbuffer.h" | 16 #include "webrtc/base/bitbuffer.h" |
| 16 | 17 |
| 17 namespace webrtc { | 18 namespace webrtc { |
| 18 | 19 |
| 19 // Example SPS can be generated with ffmpeg. Here's an example set of commands, | 20 // Example SPS can be generated with ffmpeg. Here's an example set of commands, |
| 20 // runnable on OS X: | 21 // runnable on OS X: |
| 21 // 1) Generate a video, from the camera: | 22 // 1) Generate a video, from the camera: |
| 22 // ffmpeg -f avfoundation -i "0" -video_size 640x360 camera.mov | 23 // ffmpeg -f avfoundation -i "0" -video_size 640x360 camera.mov |
| 23 // | 24 // |
| 24 // 2) Scale the video to the desired size: | 25 // 2) Scale the video to the desired size: |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 115 } |
| 115 } | 116 } |
| 116 } | 117 } |
| 117 | 118 |
| 118 TEST(H264SpsParserTest, TestSampleSPSHdLandscape) { | 119 TEST(H264SpsParserTest, TestSampleSPSHdLandscape) { |
| 119 // SPS for a 1280x720 camera capture from ffmpeg on osx. Contains | 120 // SPS for a 1280x720 camera capture from ffmpeg on osx. Contains |
| 120 // emulation bytes but no cropping. | 121 // emulation bytes but no cropping. |
| 121 const uint8_t buffer[] = {0x7A, 0x00, 0x1F, 0xBC, 0xD9, 0x40, 0x50, 0x05, | 122 const uint8_t buffer[] = {0x7A, 0x00, 0x1F, 0xBC, 0xD9, 0x40, 0x50, 0x05, |
| 122 0xBA, 0x10, 0x00, 0x00, 0x03, 0x00, 0xC0, 0x00, | 123 0xBA, 0x10, 0x00, 0x00, 0x03, 0x00, 0xC0, 0x00, |
| 123 0x00, 0x2A, 0xE0, 0xF1, 0x83, 0x19, 0x60}; | 124 0x00, 0x2A, 0xE0, 0xF1, 0x83, 0x19, 0x60}; |
| 124 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer)); | 125 H264SpsParser parser = H264SpsParser(buffer, arraysize(buffer)); |
| 125 EXPECT_TRUE(parser.Parse()); | 126 EXPECT_TRUE(parser.Parse()); |
| 126 EXPECT_EQ(1280u, parser.width()); | 127 EXPECT_EQ(1280u, parser.width()); |
| 127 EXPECT_EQ(720u, parser.height()); | 128 EXPECT_EQ(720u, parser.height()); |
| 128 } | 129 } |
| 129 | 130 |
| 130 TEST(H264SpsParserTest, TestSampleSPSVgaLandscape) { | 131 TEST(H264SpsParserTest, TestSampleSPSVgaLandscape) { |
| 131 // SPS for a 640x360 camera capture from ffmpeg on osx. Contains emulation | 132 // SPS for a 640x360 camera capture from ffmpeg on osx. Contains emulation |
| 132 // bytes and cropping (360 isn't divisible by 16). | 133 // bytes and cropping (360 isn't divisible by 16). |
| 133 const uint8_t buffer[] = {0x7A, 0x00, 0x1E, 0xBC, 0xD9, 0x40, 0xA0, 0x2F, | 134 const uint8_t buffer[] = {0x7A, 0x00, 0x1E, 0xBC, 0xD9, 0x40, 0xA0, 0x2F, |
| 134 0xF8, 0x98, 0x40, 0x00, 0x00, 0x03, 0x01, 0x80, | 135 0xF8, 0x98, 0x40, 0x00, 0x00, 0x03, 0x01, 0x80, |
| 135 0x00, 0x00, 0x56, 0x83, 0xC5, 0x8B, 0x65, 0x80}; | 136 0x00, 0x00, 0x56, 0x83, 0xC5, 0x8B, 0x65, 0x80}; |
| 136 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer)); | 137 H264SpsParser parser = H264SpsParser(buffer, arraysize(buffer)); |
| 137 EXPECT_TRUE(parser.Parse()); | 138 EXPECT_TRUE(parser.Parse()); |
| 138 EXPECT_EQ(640u, parser.width()); | 139 EXPECT_EQ(640u, parser.width()); |
| 139 EXPECT_EQ(360u, parser.height()); | 140 EXPECT_EQ(360u, parser.height()); |
| 140 } | 141 } |
| 141 | 142 |
| 142 TEST(H264SpsParserTest, TestSampleSPSWeirdResolution) { | 143 TEST(H264SpsParserTest, TestSampleSPSWeirdResolution) { |
| 143 // SPS for a 200x400 camera capture from ffmpeg on osx. Horizontal and | 144 // SPS for a 200x400 camera capture from ffmpeg on osx. Horizontal and |
| 144 // veritcal crop (neither dimension is divisible by 16). | 145 // veritcal crop (neither dimension is divisible by 16). |
| 145 const uint8_t buffer[] = {0x7A, 0x00, 0x0D, 0xBC, 0xD9, 0x43, 0x43, 0x3E, | 146 const uint8_t buffer[] = {0x7A, 0x00, 0x0D, 0xBC, 0xD9, 0x43, 0x43, 0x3E, |
| 146 0x5E, 0x10, 0x00, 0x00, 0x03, 0x00, 0x60, 0x00, | 147 0x5E, 0x10, 0x00, 0x00, 0x03, 0x00, 0x60, 0x00, |
| 147 0x00, 0x15, 0xA0, 0xF1, 0x42, 0x99, 0x60}; | 148 0x00, 0x15, 0xA0, 0xF1, 0x42, 0x99, 0x60}; |
| 148 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer)); | 149 H264SpsParser parser = H264SpsParser(buffer, arraysize(buffer)); |
| 149 EXPECT_TRUE(parser.Parse()); | 150 EXPECT_TRUE(parser.Parse()); |
| 150 EXPECT_EQ(200u, parser.width()); | 151 EXPECT_EQ(200u, parser.width()); |
| 151 EXPECT_EQ(400u, parser.height()); | 152 EXPECT_EQ(400u, parser.height()); |
| 152 } | 153 } |
| 153 | 154 |
| 154 TEST(H264SpsParserTest, TestSyntheticSPSQvgaLandscape) { | 155 TEST(H264SpsParserTest, TestSyntheticSPSQvgaLandscape) { |
| 155 uint8_t buffer[kSpsBufferMaxSize] = {0}; | 156 uint8_t buffer[kSpsBufferMaxSize] = {0}; |
| 156 GenerateFakeSps(320u, 180u, buffer); | 157 GenerateFakeSps(320u, 180u, buffer); |
| 157 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer)); | 158 H264SpsParser parser = H264SpsParser(buffer, arraysize(buffer)); |
| 158 EXPECT_TRUE(parser.Parse()); | 159 EXPECT_TRUE(parser.Parse()); |
| 159 EXPECT_EQ(320u, parser.width()); | 160 EXPECT_EQ(320u, parser.width()); |
| 160 EXPECT_EQ(180u, parser.height()); | 161 EXPECT_EQ(180u, parser.height()); |
| 161 } | 162 } |
| 162 | 163 |
| 163 TEST(H264SpsParserTest, TestSyntheticSPSWeirdResolution) { | 164 TEST(H264SpsParserTest, TestSyntheticSPSWeirdResolution) { |
| 164 uint8_t buffer[kSpsBufferMaxSize] = {0}; | 165 uint8_t buffer[kSpsBufferMaxSize] = {0}; |
| 165 GenerateFakeSps(156u, 122u, buffer); | 166 GenerateFakeSps(156u, 122u, buffer); |
| 166 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer)); | 167 H264SpsParser parser = H264SpsParser(buffer, arraysize(buffer)); |
| 167 EXPECT_TRUE(parser.Parse()); | 168 EXPECT_TRUE(parser.Parse()); |
| 168 EXPECT_EQ(156u, parser.width()); | 169 EXPECT_EQ(156u, parser.width()); |
| 169 EXPECT_EQ(122u, parser.height()); | 170 EXPECT_EQ(122u, parser.height()); |
| 170 } | 171 } |
| 171 | 172 |
| 172 } // namespace webrtc | 173 } // namespace webrtc |
| OLD | NEW |