| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/child/child_process.h" | 10 #include "content/child/child_process.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 const bool has_audio; | 52 const bool has_audio; |
| 53 const char* const mime_type; | 53 const char* const mime_type; |
| 54 const char* const codecs; | 54 const char* const codecs; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // Array of valid combinations of video/audio/codecs and expected collected | 57 // Array of valid combinations of video/audio/codecs and expected collected |
| 58 // encoded sizes to use for parameterizing MediaRecorderHandlerTest. | 58 // encoded sizes to use for parameterizing MediaRecorderHandlerTest. |
| 59 static const MediaRecorderTestParams kMediaRecorderTestParams[] = { | 59 static const MediaRecorderTestParams kMediaRecorderTestParams[] = { |
| 60 {true, false, "video/webm", "vp8"}, | 60 {true, false, "video/webm", "vp8"}, |
| 61 {true, false, "video/webm", "vp9"}, | 61 {true, false, "video/webm", "vp9"}, |
| 62 #if BUILDFLAG(RTC_USE_H264) |
| 63 {true, false, "video/webm", "h264"}, |
| 64 #endif |
| 62 {false, true, "video/webm", "vp8"}}; | 65 {false, true, "video/webm", "vp8"}}; |
| 63 | 66 |
| 64 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>, | 67 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>, |
| 65 public blink::WebMediaRecorderHandlerClient { | 68 public blink::WebMediaRecorderHandlerClient { |
| 66 public: | 69 public: |
| 67 MediaRecorderHandlerTest() | 70 MediaRecorderHandlerTest() |
| 68 : media_recorder_handler_(new MediaRecorderHandler()), | 71 : media_recorder_handler_(new MediaRecorderHandler()), |
| 69 audio_source_(kTestAudioChannels, | 72 audio_source_(kTestAudioChannels, |
| 70 440 /* freq */, | 73 440 /* freq */, |
| 71 kTestAudioSampleRate) { | 74 kTestAudioSampleRate) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 mime_type_video_uppercase, WebString())); | 152 mime_type_video_uppercase, WebString())); |
| 150 const WebString example_good_codecs_1(base::UTF8ToUTF16("vp8")); | 153 const WebString example_good_codecs_1(base::UTF8ToUTF16("vp8")); |
| 151 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 154 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 152 mime_type_video, example_good_codecs_1)); | 155 mime_type_video, example_good_codecs_1)); |
| 153 const WebString example_good_codecs_2(base::UTF8ToUTF16("vp9,opus")); | 156 const WebString example_good_codecs_2(base::UTF8ToUTF16("vp9,opus")); |
| 154 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 157 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 155 mime_type_video, example_good_codecs_2)); | 158 mime_type_video, example_good_codecs_2)); |
| 156 const WebString example_good_codecs_3(base::UTF8ToUTF16("VP9,opus")); | 159 const WebString example_good_codecs_3(base::UTF8ToUTF16("VP9,opus")); |
| 157 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 160 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 158 mime_type_video, example_good_codecs_3)); | 161 mime_type_video, example_good_codecs_3)); |
| 162 const WebString example_good_codecs_4(base::UTF8ToUTF16("H264")); |
| 163 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 164 mime_type_video, example_good_codecs_4)); |
| 159 | 165 |
| 160 const WebString example_unsupported_codecs_1(base::UTF8ToUTF16("daala")); | 166 const WebString example_unsupported_codecs_1(base::UTF8ToUTF16("daala")); |
| 161 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( | 167 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( |
| 162 mime_type_video, example_unsupported_codecs_1)); | 168 mime_type_video, example_unsupported_codecs_1)); |
| 163 | 169 |
| 164 const WebString mime_type_audio(base::UTF8ToUTF16("audio/webm")); | 170 const WebString mime_type_audio(base::UTF8ToUTF16("audio/webm")); |
| 165 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 171 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 166 mime_type_audio, WebString())); | 172 mime_type_audio, WebString())); |
| 167 const WebString example_good_codecs_4(base::UTF8ToUTF16("opus")); | 173 const WebString example_good_codecs_5(base::UTF8ToUTF16("opus")); |
| 168 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | |
| 169 mime_type_audio, example_good_codecs_4)); | |
| 170 const WebString example_good_codecs_5(base::UTF8ToUTF16("OpUs")); | |
| 171 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 174 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 172 mime_type_audio, example_good_codecs_5)); | 175 mime_type_audio, example_good_codecs_5)); |
| 176 const WebString example_good_codecs_6(base::UTF8ToUTF16("OpUs")); |
| 177 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 178 mime_type_audio, example_good_codecs_6)); |
| 173 | 179 |
| 174 const WebString example_unsupported_codecs_2(base::UTF8ToUTF16("vorbis")); | 180 const WebString example_unsupported_codecs_2(base::UTF8ToUTF16("vorbis")); |
| 175 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( | 181 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( |
| 176 mime_type_audio, example_unsupported_codecs_2)); | 182 mime_type_audio, example_unsupported_codecs_2)); |
| 177 } | 183 } |
| 178 | 184 |
| 179 // Checks that the initialization-destruction sequence works fine. | 185 // Checks that the initialization-destruction sequence works fine. |
| 180 TEST_P(MediaRecorderHandlerTest, InitializeStartStop) { | 186 TEST_P(MediaRecorderHandlerTest, InitializeStartStop) { |
| 181 AddTracks(); | 187 AddTracks(); |
| 182 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); | 188 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); | 220 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); |
| 215 const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); | 221 const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); |
| 216 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), | 222 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), |
| 217 mime_type, codecs, 0, 0)); | 223 mime_type, codecs, 0, 0)); |
| 218 EXPECT_TRUE(media_recorder_handler_->start()); | 224 EXPECT_TRUE(media_recorder_handler_->start()); |
| 219 | 225 |
| 220 InSequence s; | 226 InSequence s; |
| 221 const scoped_refptr<media::VideoFrame> video_frame = | 227 const scoped_refptr<media::VideoFrame> video_frame = |
| 222 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); | 228 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); |
| 223 | 229 |
| 224 const size_t kEncodedSizeThreshold = 16; | |
| 225 { | 230 { |
| 231 const size_t kEncodedSizeThreshold = 16; |
| 226 base::RunLoop run_loop; | 232 base::RunLoop run_loop; |
| 227 base::Closure quit_closure = run_loop.QuitClosure(); | 233 base::Closure quit_closure = run_loop.QuitClosure(); |
| 228 // writeData() is pinged a number of times as the WebM header is written; | 234 // writeData() is pinged a number of times as the WebM header is written; |
| 229 // the last time it is called it has the encoded data. | 235 // the last time it is called it has the encoded data. |
| 230 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _)) | 236 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _)) |
| 231 .Times(AtLeast(1)); | 237 .Times(AtLeast(1)); |
| 232 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _)) | 238 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _)) |
| 233 .Times(1) | 239 .Times(1) |
| 234 .WillOnce(RunClosure(quit_closure)); | 240 .WillOnce(RunClosure(quit_closure)); |
| 235 | 241 |
| 236 OnVideoFrameForTesting(video_frame); | 242 OnVideoFrameForTesting(video_frame); |
| 237 run_loop.Run(); | 243 run_loop.Run(); |
| 238 } | 244 } |
| 239 Mock::VerifyAndClearExpectations(this); | 245 Mock::VerifyAndClearExpectations(this); |
| 240 | 246 |
| 241 { | 247 { |
| 248 const size_t kEncodedSizeThreshold = 13; |
| 242 base::RunLoop run_loop; | 249 base::RunLoop run_loop; |
| 243 base::Closure quit_closure = run_loop.QuitClosure(); | 250 base::Closure quit_closure = run_loop.QuitClosure(); |
| 244 // The second time around writeData() is called a number of times to write | 251 // The second time around writeData() is called a number of times to write |
| 245 // the WebM frame header, and then is pinged with the encoded data. | 252 // the WebM frame header, and then is pinged with the encoded data. |
| 246 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _)) | 253 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _)) |
| 247 .Times(AtLeast(1)); | 254 .Times(AtLeast(1)); |
| 248 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _)) | 255 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _)) |
| 249 .Times(1) | 256 .Times(1) |
| 250 .WillOnce(RunClosure(quit_closure)); | 257 .WillOnce(RunClosure(quit_closure)); |
| 251 | 258 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 329 } |
| 323 | 330 |
| 324 media_recorder_handler_->stop(); | 331 media_recorder_handler_->stop(); |
| 325 | 332 |
| 326 // Expect a last call on destruction, with size 0 and |lastInSlice| true. | 333 // Expect a last call on destruction, with size 0 and |lastInSlice| true. |
| 327 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1); | 334 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1); |
| 328 media_recorder_handler_.reset(); | 335 media_recorder_handler_.reset(); |
| 329 } | 336 } |
| 330 | 337 |
| 331 } // namespace content | 338 } // namespace content |
| OLD | NEW |