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/arraysize.h" |
16 #include "webrtc/base/bitbuffer.h" | 16 #include "webrtc/base/bitbuffer.h" |
17 #include "webrtc/base/buffer.h" | |
18 #include "webrtc/modules/rtp_rtcp/source/h264/h264_common.h" | |
17 | 19 |
18 namespace webrtc { | 20 namespace webrtc { |
19 | 21 |
20 // Example SPS can be generated with ffmpeg. Here's an example set of commands, | 22 // Example SPS can be generated with ffmpeg. Here's an example set of commands, |
21 // runnable on OS X: | 23 // runnable on OS X: |
22 // 1) Generate a video, from the camera: | 24 // 1) Generate a video, from the camera: |
23 // ffmpeg -f avfoundation -i "0" -video_size 640x360 camera.mov | 25 // ffmpeg -f avfoundation -i "0" -video_size 640x360 camera.mov |
24 // | 26 // |
25 // 2) Scale the video to the desired size: | 27 // 2) Scale the video to the desired size: |
26 // ffmpeg -i camera.mov -vf scale=640x360 scaled.mov | 28 // ffmpeg -i camera.mov -vf scale=640x360 scaled.mov |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 *buffer++ = rbsp[i + 1]; | 111 *buffer++ = rbsp[i + 1]; |
110 *buffer++ = 0x3u; | 112 *buffer++ = 0x3u; |
111 i += 2; | 113 i += 2; |
112 } else { | 114 } else { |
113 *buffer++ = rbsp[i]; | 115 *buffer++ = rbsp[i]; |
114 ++i; | 116 ++i; |
115 } | 117 } |
116 } | 118 } |
117 } | 119 } |
118 | 120 |
119 TEST(H264SpsParserTest, TestSampleSPSHdLandscape) { | 121 class H264SpsParserTest : public ::testing::Test { |
122 public: | |
123 H264SpsParserTest() {} | |
124 virtual ~H264SpsParserTest() {} | |
125 | |
126 protected: | |
127 bool ParseSps(const uint8_t* buffer, int length) { | |
128 sps_ = SpsParser::ParseSps(buffer, length); | |
129 return sps_ ? true : false; | |
stefan-webrtc
2016/05/22 23:11:50
I think you can return sps_().
Wouldn't it be sim
sprang_webrtc
2016/05/25 09:06:03
Nope, "type 'rtc::Optional<SpsParser::SpsState>' d
| |
130 } | |
131 | |
132 rtc::Optional<SpsParser::SpsState> sps_; | |
133 }; | |
134 | |
135 TEST_F(H264SpsParserTest, TestSampleSPSHdLandscape) { | |
120 // SPS for a 1280x720 camera capture from ffmpeg on osx. Contains | 136 // SPS for a 1280x720 camera capture from ffmpeg on osx. Contains |
121 // emulation bytes but no cropping. | 137 // emulation bytes but no cropping. |
122 const uint8_t buffer[] = {0x7A, 0x00, 0x1F, 0xBC, 0xD9, 0x40, 0x50, 0x05, | 138 const uint8_t buffer[] = {0x7A, 0x00, 0x1F, 0xBC, 0xD9, 0x40, 0x50, 0x05, |
123 0xBA, 0x10, 0x00, 0x00, 0x03, 0x00, 0xC0, 0x00, | 139 0xBA, 0x10, 0x00, 0x00, 0x03, 0x00, 0xC0, 0x00, |
124 0x00, 0x2A, 0xE0, 0xF1, 0x83, 0x19, 0x60}; | 140 0x00, 0x2A, 0xE0, 0xF1, 0x83, 0x19, 0x60}; |
125 H264SpsParser parser = H264SpsParser(buffer, arraysize(buffer)); | 141 |
126 EXPECT_TRUE(parser.Parse()); | 142 EXPECT_TRUE(ParseSps(buffer, arraysize(buffer))); |
127 EXPECT_EQ(1280u, parser.width()); | 143 EXPECT_EQ(1280u, sps_->width); |
128 EXPECT_EQ(720u, parser.height()); | 144 EXPECT_EQ(720u, sps_->height); |
129 } | 145 } |
130 | 146 |
131 TEST(H264SpsParserTest, TestSampleSPSVgaLandscape) { | 147 TEST_F(H264SpsParserTest, TestSampleSPSVgaLandscape) { |
132 // SPS for a 640x360 camera capture from ffmpeg on osx. Contains emulation | 148 // SPS for a 640x360 camera capture from ffmpeg on osx. Contains emulation |
133 // bytes and cropping (360 isn't divisible by 16). | 149 // bytes and cropping (360 isn't divisible by 16). |
134 const uint8_t buffer[] = {0x7A, 0x00, 0x1E, 0xBC, 0xD9, 0x40, 0xA0, 0x2F, | 150 const uint8_t buffer[] = {0x7A, 0x00, 0x1E, 0xBC, 0xD9, 0x40, 0xA0, 0x2F, |
135 0xF8, 0x98, 0x40, 0x00, 0x00, 0x03, 0x01, 0x80, | 151 0xF8, 0x98, 0x40, 0x00, 0x00, 0x03, 0x01, 0x80, |
136 0x00, 0x00, 0x56, 0x83, 0xC5, 0x8B, 0x65, 0x80}; | 152 0x00, 0x00, 0x56, 0x83, 0xC5, 0x8B, 0x65, 0x80}; |
137 H264SpsParser parser = H264SpsParser(buffer, arraysize(buffer)); | 153 EXPECT_TRUE(ParseSps(buffer, arraysize(buffer))); |
138 EXPECT_TRUE(parser.Parse()); | 154 EXPECT_EQ(640u, sps_->width); |
139 EXPECT_EQ(640u, parser.width()); | 155 EXPECT_EQ(360u, sps_->height); |
140 EXPECT_EQ(360u, parser.height()); | |
141 } | 156 } |
142 | 157 |
143 TEST(H264SpsParserTest, TestSampleSPSWeirdResolution) { | 158 TEST_F(H264SpsParserTest, TestSampleSPSWeirdResolution) { |
144 // SPS for a 200x400 camera capture from ffmpeg on osx. Horizontal and | 159 // SPS for a 200x400 camera capture from ffmpeg on osx. Horizontal and |
145 // veritcal crop (neither dimension is divisible by 16). | 160 // veritcal crop (neither dimension is divisible by 16). |
146 const uint8_t buffer[] = {0x7A, 0x00, 0x0D, 0xBC, 0xD9, 0x43, 0x43, 0x3E, | 161 const uint8_t buffer[] = {0x7A, 0x00, 0x0D, 0xBC, 0xD9, 0x43, 0x43, 0x3E, |
147 0x5E, 0x10, 0x00, 0x00, 0x03, 0x00, 0x60, 0x00, | 162 0x5E, 0x10, 0x00, 0x00, 0x03, 0x00, 0x60, 0x00, |
148 0x00, 0x15, 0xA0, 0xF1, 0x42, 0x99, 0x60}; | 163 0x00, 0x15, 0xA0, 0xF1, 0x42, 0x99, 0x60}; |
149 H264SpsParser parser = H264SpsParser(buffer, arraysize(buffer)); | 164 EXPECT_TRUE(ParseSps(buffer, arraysize(buffer))); |
150 EXPECT_TRUE(parser.Parse()); | 165 EXPECT_EQ(200u, sps_->width); |
151 EXPECT_EQ(200u, parser.width()); | 166 EXPECT_EQ(400u, sps_->height); |
152 EXPECT_EQ(400u, parser.height()); | |
153 } | 167 } |
154 | 168 |
155 TEST(H264SpsParserTest, TestSyntheticSPSQvgaLandscape) { | 169 TEST_F(H264SpsParserTest, TestSyntheticSPSQvgaLandscape) { |
156 uint8_t buffer[kSpsBufferMaxSize] = {0}; | 170 uint8_t buffer[kSpsBufferMaxSize] = {0}; |
157 GenerateFakeSps(320u, 180u, buffer); | 171 GenerateFakeSps(320u, 180u, buffer); |
158 H264SpsParser parser = H264SpsParser(buffer, arraysize(buffer)); | 172 EXPECT_TRUE(ParseSps(buffer, arraysize(buffer))); |
159 EXPECT_TRUE(parser.Parse()); | 173 EXPECT_EQ(320u, sps_->width); |
160 EXPECT_EQ(320u, parser.width()); | 174 EXPECT_EQ(180u, sps_->height); |
161 EXPECT_EQ(180u, parser.height()); | |
162 } | 175 } |
163 | 176 |
164 TEST(H264SpsParserTest, TestSyntheticSPSWeirdResolution) { | 177 TEST_F(H264SpsParserTest, TestSyntheticSPSWeirdResolution) { |
165 uint8_t buffer[kSpsBufferMaxSize] = {0}; | 178 uint8_t buffer[kSpsBufferMaxSize] = {0}; |
166 GenerateFakeSps(156u, 122u, buffer); | 179 GenerateFakeSps(156u, 122u, buffer); |
167 H264SpsParser parser = H264SpsParser(buffer, arraysize(buffer)); | 180 EXPECT_TRUE(ParseSps(buffer, arraysize(buffer))); |
168 EXPECT_TRUE(parser.Parse()); | 181 EXPECT_EQ(156u, sps_->width); |
169 EXPECT_EQ(156u, parser.width()); | 182 EXPECT_EQ(122u, sps_->height); |
170 EXPECT_EQ(122u, parser.height()); | |
171 } | 183 } |
172 | 184 |
173 } // namespace webrtc | 185 } // namespace webrtc |
OLD | NEW |