| 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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "content/child/child_process.h" | 7 #include "content/child/child_process.h" |
| 8 #include "content/renderer/media/media_recorder_handler.h" | 8 #include "content/renderer/media/media_recorder_handler.h" |
| 9 #include "content/renderer/media/mock_media_stream_registry.h" | 9 #include "content/renderer/media/mock_media_stream_registry.h" |
| 10 #include "media/audio/simple_sources.h" | 10 #include "media/audio/simple_sources.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 static const std::string kTestAudioTrackId = "audio_track_id"; | 37 static const std::string kTestAudioTrackId = "audio_track_id"; |
| 38 static const int kTestAudioChannels = 2; | 38 static const int kTestAudioChannels = 2; |
| 39 static const int kTestAudioBitsPerSample = 16; | 39 static const int kTestAudioBitsPerSample = 16; |
| 40 static const int kTestAudioSampleRate = 48000; | 40 static const int kTestAudioSampleRate = 48000; |
| 41 static const int kTestAudioBufferDurationMS = 60; | 41 static const int kTestAudioBufferDurationMS = 60; |
| 42 | 42 |
| 43 struct MediaRecorderTestParams { | 43 struct MediaRecorderTestParams { |
| 44 const bool has_video; | 44 const bool has_video; |
| 45 const bool has_audio; | 45 const bool has_audio; |
| 46 const char* const mime_type; | 46 const char* const mime_type; |
| 47 const char* const codecs; |
| 47 const size_t first_encoded_video_frame_size; | 48 const size_t first_encoded_video_frame_size; |
| 48 const size_t second_encoded_video_frame_size; | 49 const size_t second_encoded_video_frame_size; |
| 49 const size_t first_encoded_audio_frame_size; | 50 const size_t first_encoded_audio_frame_size; |
| 50 const size_t second_encoded_audio_frame_size; | 51 const size_t second_encoded_audio_frame_size; |
| 51 }; | 52 }; |
| 52 | 53 |
| 54 // Array of valid combinations of video/audio/codecs and expected collected |
| 55 // encoded sizes to use for parameterizing MediaRecorderHandlerTest. |
| 53 static const MediaRecorderTestParams kMediaRecorderTestParams[] = { | 56 static const MediaRecorderTestParams kMediaRecorderTestParams[] = { |
| 54 {true, false, "video/vp8", 52, 32, 0, 0}, | 57 {true, false, "video/webm", "vp8", 52, 32, 0, 0}, |
| 55 {true, false, "video/vp9", 33, 18, 0, 0}, | 58 {true, false, "video/webm", "vp9", 33, 18, 0, 0}, |
| 56 {false, true, "video/vp8", 0, 0, 990, 706}}; | 59 {false, true, "video/webm", "vp8", 0, 0, 990, 706}}; |
| 57 | 60 |
| 58 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>, | 61 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>, |
| 59 public blink::WebMediaRecorderHandlerClient { | 62 public blink::WebMediaRecorderHandlerClient { |
| 60 public: | 63 public: |
| 61 MediaRecorderHandlerTest() | 64 MediaRecorderHandlerTest() |
| 62 : media_recorder_handler_(new MediaRecorderHandler()), | 65 : media_recorder_handler_(new MediaRecorderHandler()), |
| 63 audio_source_(kTestAudioChannels, | 66 audio_source_(kTestAudioChannels, |
| 64 440 /* freq */, | 67 440 /* freq */, |
| 65 kTestAudioSampleRate) { | 68 kTestAudioSampleRate) { |
| 66 EXPECT_FALSE(media_recorder_handler_->recording_); | 69 EXPECT_FALSE(media_recorder_handler_->recording_); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // The Class under test. Needs to be scoped_ptr to force its destruction. | 126 // The Class under test. Needs to be scoped_ptr to force its destruction. |
| 124 scoped_ptr<MediaRecorderHandler> media_recorder_handler_; | 127 scoped_ptr<MediaRecorderHandler> media_recorder_handler_; |
| 125 | 128 |
| 126 // For generating test AudioBuses | 129 // For generating test AudioBuses |
| 127 media::SineWaveAudioSource audio_source_; | 130 media::SineWaveAudioSource audio_source_; |
| 128 | 131 |
| 129 private: | 132 private: |
| 130 DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandlerTest); | 133 DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandlerTest); |
| 131 }; | 134 }; |
| 132 | 135 |
| 133 // Checks that canSupportMimeType() works as expected. | 136 // Checks that canSupportMimeType() works as expected, by sending supported |
| 134 // TODO(mcasas): revisit this when canSupportMimeType() is fully implemented. | 137 // combinations and unsupported ones. |
| 135 TEST_F(MediaRecorderHandlerTest, CanSupportMimeType) { | 138 TEST_F(MediaRecorderHandlerTest, CanSupportMimeType) { |
| 136 const WebString good_mime_type_vp8(base::UTF8ToUTF16("video/vp8")); | 139 const WebString unsupported_mime_type(base::UTF8ToUTF16("video/mpeg")); |
| 137 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(good_mime_type_vp8)); | 140 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( |
| 141 unsupported_mime_type, WebString())); |
| 138 | 142 |
| 139 const WebString good_mime_type_vp9(base::UTF8ToUTF16("video/vp9")); | 143 const WebString mime_type_video(base::UTF8ToUTF16("video/webm")); |
| 140 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(good_mime_type_vp9)); | 144 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 145 mime_type_video, WebString())); |
| 146 const WebString mime_type_video_uppercase(base::UTF8ToUTF16("video/WEBM")); |
| 147 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 148 mime_type_video_uppercase, WebString())); |
| 149 const WebString example_good_codecs_1(base::UTF8ToUTF16("vp8")); |
| 150 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 151 mime_type_video, example_good_codecs_1)); |
| 152 const WebString example_good_codecs_2(base::UTF8ToUTF16("vp9,opus")); |
| 153 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 154 mime_type_video, example_good_codecs_2)); |
| 155 const WebString example_good_codecs_3(base::UTF8ToUTF16("VP9,opus")); |
| 156 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 157 mime_type_video, example_good_codecs_3)); |
| 141 | 158 |
| 142 const WebString audio_mime_type(base::UTF8ToUTF16("audio/opus")); | 159 const WebString example_unsupported_codecs_1(base::UTF8ToUTF16("daala")); |
| 143 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(audio_mime_type)); | 160 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( |
| 161 mime_type_video, example_unsupported_codecs_1)); |
| 144 | 162 |
| 145 const WebString combo_mime_type(base::UTF8ToUTF16("video/vp8, audio/opus")); | 163 const WebString mime_type_audio(base::UTF8ToUTF16("audio/webm")); |
| 146 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(combo_mime_type)); | 164 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 165 mime_type_audio, WebString())); |
| 166 const WebString example_good_codecs_4(base::UTF8ToUTF16("opus")); |
| 167 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 168 mime_type_audio, example_good_codecs_4)); |
| 169 const WebString example_good_codecs_5(base::UTF8ToUTF16("OpUs")); |
| 170 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 171 mime_type_audio, example_good_codecs_5)); |
| 147 | 172 |
| 148 const WebString bad_combo(base::UTF8ToUTF16("video/vp8, audio/unsupported")); | 173 const WebString example_unsupported_codecs_2(base::UTF8ToUTF16("vorbis")); |
| 149 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType(bad_combo)); | 174 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( |
| 150 | 175 mime_type_audio, example_unsupported_codecs_2)); |
| 151 const WebString bad_mime_type(base::UTF8ToUTF16("video/unsupportedcodec")); | |
| 152 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType(bad_mime_type)); | |
| 153 | |
| 154 const WebString empty_mime_type(base::UTF8ToUTF16("")); | |
| 155 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(empty_mime_type)); | |
| 156 } | 176 } |
| 157 | 177 |
| 158 // Checks that the initialization-destruction sequence works fine. | 178 // Checks that the initialization-destruction sequence works fine. |
| 159 TEST_P(MediaRecorderHandlerTest, InitializeStartStop) { | 179 TEST_P(MediaRecorderHandlerTest, InitializeStartStop) { |
| 160 AddTracks(); | 180 AddTracks(); |
| 161 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); | 181 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); |
| 182 const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); |
| 162 EXPECT_TRUE(media_recorder_handler_->initialize(this, | 183 EXPECT_TRUE(media_recorder_handler_->initialize(this, |
| 163 registry_.test_stream(), | 184 registry_.test_stream(), |
| 164 mime_type)); | 185 mime_type, |
| 186 codecs)); |
| 165 EXPECT_FALSE(recording()); | 187 EXPECT_FALSE(recording()); |
| 166 EXPECT_FALSE(hasVideoRecorders()); | 188 EXPECT_FALSE(hasVideoRecorders()); |
| 167 EXPECT_FALSE(hasAudioRecorders()); | 189 EXPECT_FALSE(hasAudioRecorders()); |
| 168 | 190 |
| 169 EXPECT_TRUE(media_recorder_handler_->start()); | 191 EXPECT_TRUE(media_recorder_handler_->start()); |
| 170 EXPECT_TRUE(recording()); | 192 EXPECT_TRUE(recording()); |
| 171 | 193 |
| 172 EXPECT_TRUE(hasVideoRecorders() || !GetParam().has_video); | 194 EXPECT_TRUE(hasVideoRecorders() || !GetParam().has_video); |
| 173 EXPECT_TRUE(hasAudioRecorders() || !GetParam().has_audio); | 195 EXPECT_TRUE(hasAudioRecorders() || !GetParam().has_audio); |
| 174 | 196 |
| 175 media_recorder_handler_->stop(); | 197 media_recorder_handler_->stop(); |
| 176 EXPECT_FALSE(recording()); | 198 EXPECT_FALSE(recording()); |
| 177 EXPECT_FALSE(hasVideoRecorders()); | 199 EXPECT_FALSE(hasVideoRecorders()); |
| 178 EXPECT_FALSE(hasAudioRecorders()); | 200 EXPECT_FALSE(hasAudioRecorders()); |
| 179 | 201 |
| 180 // Expect a last call on destruction. | 202 // Expect a last call on destruction. |
| 181 EXPECT_CALL(*this, writeData(_, _, true)).Times(1); | 203 EXPECT_CALL(*this, writeData(_, _, true)).Times(1); |
| 182 media_recorder_handler_.reset(); | 204 media_recorder_handler_.reset(); |
| 183 } | 205 } |
| 184 | 206 |
| 185 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). | 207 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). |
| 186 TEST_P(MediaRecorderHandlerTest, EncodeVideoFrames) { | 208 TEST_P(MediaRecorderHandlerTest, EncodeVideoFrames) { |
| 187 // Video-only test. | 209 // Video-only test. |
| 188 if (GetParam().has_audio) | 210 if (GetParam().has_audio) |
| 189 return; | 211 return; |
| 190 | 212 |
| 191 AddTracks(); | 213 AddTracks(); |
| 192 | 214 |
| 193 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); | 215 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); |
| 216 const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); |
| 194 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), | 217 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), |
| 195 mime_type)); | 218 mime_type, codecs)); |
| 196 EXPECT_TRUE(media_recorder_handler_->start()); | 219 EXPECT_TRUE(media_recorder_handler_->start()); |
| 197 | 220 |
| 198 InSequence s; | 221 InSequence s; |
| 199 const scoped_refptr<media::VideoFrame> video_frame = | 222 const scoped_refptr<media::VideoFrame> video_frame = |
| 200 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); | 223 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); |
| 201 | 224 |
| 202 { | 225 { |
| 203 base::RunLoop run_loop; | 226 base::RunLoop run_loop; |
| 204 base::Closure quit_closure = run_loop.QuitClosure(); | 227 base::Closure quit_closure = run_loop.QuitClosure(); |
| 205 // writeData() is pinged a number of times as the WebM header is written; | 228 // writeData() is pinged a number of times as the WebM header is written; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 ValuesIn(kMediaRecorderTestParams)); | 266 ValuesIn(kMediaRecorderTestParams)); |
| 244 | 267 |
| 245 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). | 268 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). |
| 246 TEST_P(MediaRecorderHandlerTest, EncodeAudioFrames) { | 269 TEST_P(MediaRecorderHandlerTest, EncodeAudioFrames) { |
| 247 // Audio-only test. | 270 // Audio-only test. |
| 248 if (GetParam().has_video) | 271 if (GetParam().has_video) |
| 249 return; | 272 return; |
| 250 | 273 |
| 251 AddTracks(); | 274 AddTracks(); |
| 252 | 275 |
| 253 const WebString mime_type(base::UTF8ToUTF16("audio/opus")); | 276 const WebString mime_type(base::UTF8ToUTF16("audio/webm")); |
| 254 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), | 277 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), |
| 255 mime_type)); | 278 mime_type, WebString())); |
| 256 EXPECT_TRUE(media_recorder_handler_->start()); | 279 EXPECT_TRUE(media_recorder_handler_->start()); |
| 257 | 280 |
| 258 InSequence s; | 281 InSequence s; |
| 259 const scoped_ptr<media::AudioBus> audio_bus1 = NextAudioBus(); | 282 const scoped_ptr<media::AudioBus> audio_bus1 = NextAudioBus(); |
| 260 const scoped_ptr<media::AudioBus> audio_bus2 = NextAudioBus(); | 283 const scoped_ptr<media::AudioBus> audio_bus2 = NextAudioBus(); |
| 261 | 284 |
| 262 media::AudioParameters params( | 285 media::AudioParameters params( |
| 263 media::AudioParameters::AUDIO_PCM_LINEAR, media::CHANNEL_LAYOUT_STEREO, | 286 media::AudioParameters::AUDIO_PCM_LINEAR, media::CHANNEL_LAYOUT_STEREO, |
| 264 kTestAudioSampleRate, kTestAudioBitsPerSample, | 287 kTestAudioSampleRate, kTestAudioBitsPerSample, |
| 265 kTestAudioSampleRate * kTestAudioBufferDurationMS / 1000); | 288 kTestAudioSampleRate * kTestAudioBufferDurationMS / 1000); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 } | 321 } |
| 299 | 322 |
| 300 media_recorder_handler_->stop(); | 323 media_recorder_handler_->stop(); |
| 301 | 324 |
| 302 // Expect a last call on destruction, with size 0 and |lastInSlice| true. | 325 // Expect a last call on destruction, with size 0 and |lastInSlice| true. |
| 303 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1); | 326 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1); |
| 304 media_recorder_handler_.reset(); | 327 media_recorder_handler_.reset(); |
| 305 } | 328 } |
| 306 | 329 |
| 307 } // namespace content | 330 } // namespace content |
| OLD | NEW |