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 23 matching lines...) Expand all Loading... |
34 ACTION_P(RunClosure, closure) { | 34 ACTION_P(RunClosure, closure) { |
35 closure.Run(); | 35 closure.Run(); |
36 } | 36 } |
37 | 37 |
38 static const std::string kTestStreamUrl = "stream_url"; | 38 static const std::string kTestStreamUrl = "stream_url"; |
39 static const std::string kTestVideoTrackId = "video_track_id"; | 39 static const std::string kTestVideoTrackId = "video_track_id"; |
40 static const std::string kTestAudioTrackId = "audio_track_id"; | 40 static const std::string kTestAudioTrackId = "audio_track_id"; |
41 static const int kTestAudioChannels = 2; | 41 static const int kTestAudioChannels = 2; |
42 static const int kTestAudioBitsPerSample = 16; | 42 static const int kTestAudioBitsPerSample = 16; |
43 static const int kTestAudioSampleRate = 48000; | 43 static const int kTestAudioSampleRate = 48000; |
44 static const int kTestAudioBufferDurationMS = 60; | 44 // MediaStream Audio Tack always provides chunks 10 ms of audio data. |
| 45 static const int kMediaStreamAudioTrackBufferDurationMs = 10; |
45 | 46 |
46 struct MediaRecorderTestParams { | 47 struct MediaRecorderTestParams { |
47 const bool has_video; | 48 const bool has_video; |
48 const bool has_audio; | 49 const bool has_audio; |
49 const char* const mime_type; | 50 const char* const mime_type; |
50 const char* const codecs; | 51 const char* const codecs; |
51 const size_t first_encoded_video_frame_size; | 52 const size_t first_encoded_video_frame_size; |
52 const size_t second_encoded_video_frame_size; | 53 const size_t second_encoded_video_frame_size; |
53 const size_t first_encoded_audio_frame_size; | 54 const size_t first_encoded_audio_frame_size; |
54 const size_t second_encoded_audio_frame_size; | 55 const size_t second_encoded_audio_frame_size; |
55 }; | 56 }; |
56 | 57 |
57 // Array of valid combinations of video/audio/codecs and expected collected | 58 // Array of valid combinations of video/audio/codecs and expected collected |
58 // encoded sizes to use for parameterizing MediaRecorderHandlerTest. | 59 // encoded sizes to use for parameterizing MediaRecorderHandlerTest. |
59 static const MediaRecorderTestParams kMediaRecorderTestParams[] = { | 60 static const MediaRecorderTestParams kMediaRecorderTestParams[] = { |
60 {true, false, "video/webm", "vp8", 52, 32, 0, 0}, | 61 {true, false, "video/webm", "vp8", 52, 32, 0, 0}, |
61 {true, false, "video/webm", "vp9", 33, 18, 0, 0}, | 62 {true, false, "video/webm", "vp9", 33, 18, 0, 0}, |
62 {false, true, "video/webm", "vp8", 0, 0, 990, 706}}; | 63 {false, true, "video/webm", "vp8", 0, 0, 248, 125}}; |
63 | 64 |
64 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>, | 65 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>, |
65 public blink::WebMediaRecorderHandlerClient { | 66 public blink::WebMediaRecorderHandlerClient { |
66 public: | 67 public: |
67 MediaRecorderHandlerTest() | 68 MediaRecorderHandlerTest() |
68 : media_recorder_handler_(new MediaRecorderHandler()), | 69 : media_recorder_handler_(new MediaRecorderHandler()), |
69 audio_source_(kTestAudioChannels, | 70 audio_source_(kTestAudioChannels, |
70 440 /* freq */, | 71 440 /* freq */, |
71 kTestAudioSampleRate) { | 72 kTestAudioSampleRate) { |
72 EXPECT_FALSE(media_recorder_handler_->recording_); | 73 EXPECT_FALSE(media_recorder_handler_->recording_); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // Avoid issues with non-parameterized tests by calling this outside of ctr. | 107 // Avoid issues with non-parameterized tests by calling this outside of ctr. |
107 if (GetParam().has_video) | 108 if (GetParam().has_video) |
108 registry_.AddVideoTrack(kTestVideoTrackId); | 109 registry_.AddVideoTrack(kTestVideoTrackId); |
109 if (GetParam().has_audio) | 110 if (GetParam().has_audio) |
110 registry_.AddAudioTrack(kTestAudioTrackId); | 111 registry_.AddAudioTrack(kTestAudioTrackId); |
111 } | 112 } |
112 | 113 |
113 scoped_ptr<media::AudioBus> NextAudioBus() { | 114 scoped_ptr<media::AudioBus> NextAudioBus() { |
114 scoped_ptr<media::AudioBus> bus(media::AudioBus::Create( | 115 scoped_ptr<media::AudioBus> bus(media::AudioBus::Create( |
115 kTestAudioChannels, | 116 kTestAudioChannels, |
116 kTestAudioSampleRate * kTestAudioBufferDurationMS / 1000)); | 117 kTestAudioSampleRate * kMediaStreamAudioTrackBufferDurationMs / 1000)); |
117 audio_source_.OnMoreData(bus.get(), 0, 0); | 118 audio_source_.OnMoreData(bus.get(), 0, 0); |
118 return bus; | 119 return bus; |
119 } | 120 } |
120 | 121 |
121 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks | 122 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks |
122 // and Sources in |registry_| into believing they are on the right threads. | 123 // and Sources in |registry_| into believing they are on the right threads. |
123 const base::MessageLoopForUI message_loop_; | 124 const base::MessageLoopForUI message_loop_; |
124 const ChildProcess child_process_; | 125 const ChildProcess child_process_; |
125 MockMediaStreamRegistry registry_; | 126 MockMediaStreamRegistry registry_; |
126 | 127 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 mime_type, WebString())); | 280 mime_type, WebString())); |
280 EXPECT_TRUE(media_recorder_handler_->start()); | 281 EXPECT_TRUE(media_recorder_handler_->start()); |
281 | 282 |
282 InSequence s; | 283 InSequence s; |
283 const scoped_ptr<media::AudioBus> audio_bus1 = NextAudioBus(); | 284 const scoped_ptr<media::AudioBus> audio_bus1 = NextAudioBus(); |
284 const scoped_ptr<media::AudioBus> audio_bus2 = NextAudioBus(); | 285 const scoped_ptr<media::AudioBus> audio_bus2 = NextAudioBus(); |
285 | 286 |
286 media::AudioParameters params( | 287 media::AudioParameters params( |
287 media::AudioParameters::AUDIO_PCM_LINEAR, media::CHANNEL_LAYOUT_STEREO, | 288 media::AudioParameters::AUDIO_PCM_LINEAR, media::CHANNEL_LAYOUT_STEREO, |
288 kTestAudioSampleRate, kTestAudioBitsPerSample, | 289 kTestAudioSampleRate, kTestAudioBitsPerSample, |
289 kTestAudioSampleRate * kTestAudioBufferDurationMS / 1000); | 290 kTestAudioSampleRate * kMediaStreamAudioTrackBufferDurationMs / 1000); |
290 SetAudioFormatForTesting(params); | 291 SetAudioFormatForTesting(params); |
291 | 292 |
292 { | 293 { |
293 base::RunLoop run_loop; | 294 base::RunLoop run_loop; |
294 base::Closure quit_closure = run_loop.QuitClosure(); | 295 base::Closure quit_closure = run_loop.QuitClosure(); |
295 // writeData() is pinged a number of times as the WebM header is written; | 296 // writeData() is pinged a number of times as the WebM header is written; |
296 // the last time it is called it has the encoded data. | 297 // the last time it is called it has the encoded data. |
297 const size_t kEncodedDataSize = GetParam().first_encoded_audio_frame_size; | 298 const size_t kEncodedDataSize = GetParam().first_encoded_audio_frame_size; |
298 EXPECT_CALL(*this, writeData(_, Lt(kEncodedDataSize), _)).Times(AtLeast(1)); | 299 EXPECT_CALL(*this, writeData(_, Lt(kEncodedDataSize), _)).Times(AtLeast(1)); |
299 EXPECT_CALL(*this, writeData(_, kEncodedDataSize, _)) | 300 EXPECT_CALL(*this, writeData(_, kEncodedDataSize, _)) |
(...skipping 22 matching lines...) Expand all Loading... |
322 } | 323 } |
323 | 324 |
324 media_recorder_handler_->stop(); | 325 media_recorder_handler_->stop(); |
325 | 326 |
326 // Expect a last call on destruction, with size 0 and |lastInSlice| true. | 327 // Expect a last call on destruction, with size 0 and |lastInSlice| true. |
327 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1); | 328 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1); |
328 media_recorder_handler_.reset(); | 329 media_recorder_handler_.reset(); |
329 } | 330 } |
330 | 331 |
331 } // namespace content | 332 } // namespace content |
OLD | NEW |