Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: content/renderer/media/media_recorder_handler_unittest.cc

Issue 1579693006: MediaRecorder: support sampling rate adaption in AudioTrackRecorder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: miu@s second round of comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 Track always provides audio in chunks of 10 ms.
miu 2016/01/29 02:37:15 This is not a global assumption. The current Chro
mcasas 2016/01/29 20:37:34 Removed the comment. For these tests is fine to us
45 static const int kMediaStreamAudioTrackBufferDurationMs = 10;
46 // Opus works with 60ms buffers, so 6 MediaStreamAudioTrack Buffers are needed
47 // to encode one output buffer.
48 static const int kRatioOpusToMediaStreamTrackBuffers = 6;
45 49
46 struct MediaRecorderTestParams { 50 struct MediaRecorderTestParams {
47 const bool has_video; 51 const bool has_video;
48 const bool has_audio; 52 const bool has_audio;
49 const char* const mime_type; 53 const char* const mime_type;
50 const char* const codecs; 54 const char* const codecs;
51 const size_t first_encoded_video_frame_size; 55 const size_t first_encoded_video_frame_size;
52 const size_t second_encoded_video_frame_size; 56 const size_t second_encoded_video_frame_size;
53 const size_t first_encoded_audio_frame_size; 57 const size_t first_encoded_audio_frame_size;
54 const size_t second_encoded_audio_frame_size; 58 const size_t second_encoded_audio_frame_size;
55 }; 59 };
56 60
57 // Array of valid combinations of video/audio/codecs and expected collected 61 // Array of valid combinations of video/audio/codecs and expected collected
58 // encoded sizes to use for parameterizing MediaRecorderHandlerTest. 62 // encoded sizes to use for parameterizing MediaRecorderHandlerTest.
59 static const MediaRecorderTestParams kMediaRecorderTestParams[] = { 63 static const MediaRecorderTestParams kMediaRecorderTestParams[] = {
60 {true, false, "video/webm", "vp8", 52, 32, 0, 0}, 64 {true, false, "video/webm", "vp8", 52, 32, 0, 0},
61 {true, false, "video/webm", "vp9", 33, 18, 0, 0}, 65 {true, false, "video/webm", "vp9", 33, 18, 0, 0},
62 {false, true, "video/webm", "vp8", 0, 0, 990, 706}}; 66 {false, true, "video/webm", "vp8", 0, 0, 996, 746}};
miu 2016/01/29 02:37:15 It's a bit brittle to require the tests pass based
mcasas 2016/01/29 20:37:34 My opinion is that a potential libvpx roller shoul
63 67
64 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>, 68 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>,
65 public blink::WebMediaRecorderHandlerClient { 69 public blink::WebMediaRecorderHandlerClient {
66 public: 70 public:
67 MediaRecorderHandlerTest() 71 MediaRecorderHandlerTest()
68 : media_recorder_handler_(new MediaRecorderHandler()), 72 : media_recorder_handler_(new MediaRecorderHandler()),
69 audio_source_(kTestAudioChannels, 73 audio_source_(kTestAudioChannels,
70 440 /* freq */, 74 440 /* freq */,
71 kTestAudioSampleRate) { 75 kTestAudioSampleRate) {
72 EXPECT_FALSE(media_recorder_handler_->recording_); 76 EXPECT_FALSE(media_recorder_handler_->recording_);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // Avoid issues with non-parameterized tests by calling this outside of ctr. 110 // Avoid issues with non-parameterized tests by calling this outside of ctr.
107 if (GetParam().has_video) 111 if (GetParam().has_video)
108 registry_.AddVideoTrack(kTestVideoTrackId); 112 registry_.AddVideoTrack(kTestVideoTrackId);
109 if (GetParam().has_audio) 113 if (GetParam().has_audio)
110 registry_.AddAudioTrack(kTestAudioTrackId); 114 registry_.AddAudioTrack(kTestAudioTrackId);
111 } 115 }
112 116
113 scoped_ptr<media::AudioBus> NextAudioBus() { 117 scoped_ptr<media::AudioBus> NextAudioBus() {
114 scoped_ptr<media::AudioBus> bus(media::AudioBus::Create( 118 scoped_ptr<media::AudioBus> bus(media::AudioBus::Create(
115 kTestAudioChannels, 119 kTestAudioChannels,
116 kTestAudioSampleRate * kTestAudioBufferDurationMS / 1000)); 120 kTestAudioSampleRate * kMediaStreamAudioTrackBufferDurationMs / 1000));
117 audio_source_.OnMoreData(bus.get(), 0, 0); 121 audio_source_.OnMoreData(bus.get(), 0, 0);
118 return bus; 122 return bus;
119 } 123 }
120 124
121 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks 125 // 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. 126 // and Sources in |registry_| into believing they are on the right threads.
123 const base::MessageLoopForUI message_loop_; 127 const base::MessageLoopForUI message_loop_;
124 const ChildProcess child_process_; 128 const ChildProcess child_process_;
125 MockMediaStreamRegistry registry_; 129 MockMediaStreamRegistry registry_;
126 130
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 this, registry_.test_stream(), mime_type, WebString(), 0, 0)); 281 this, registry_.test_stream(), mime_type, WebString(), 0, 0));
278 EXPECT_TRUE(media_recorder_handler_->start()); 282 EXPECT_TRUE(media_recorder_handler_->start());
279 283
280 InSequence s; 284 InSequence s;
281 const scoped_ptr<media::AudioBus> audio_bus1 = NextAudioBus(); 285 const scoped_ptr<media::AudioBus> audio_bus1 = NextAudioBus();
282 const scoped_ptr<media::AudioBus> audio_bus2 = NextAudioBus(); 286 const scoped_ptr<media::AudioBus> audio_bus2 = NextAudioBus();
283 287
284 media::AudioParameters params( 288 media::AudioParameters params(
285 media::AudioParameters::AUDIO_PCM_LINEAR, media::CHANNEL_LAYOUT_STEREO, 289 media::AudioParameters::AUDIO_PCM_LINEAR, media::CHANNEL_LAYOUT_STEREO,
286 kTestAudioSampleRate, kTestAudioBitsPerSample, 290 kTestAudioSampleRate, kTestAudioBitsPerSample,
287 kTestAudioSampleRate * kTestAudioBufferDurationMS / 1000); 291 kTestAudioSampleRate * kMediaStreamAudioTrackBufferDurationMs / 1000);
288 SetAudioFormatForTesting(params); 292 SetAudioFormatForTesting(params);
289 293
290 { 294 {
291 base::RunLoop run_loop; 295 base::RunLoop run_loop;
292 base::Closure quit_closure = run_loop.QuitClosure(); 296 base::Closure quit_closure = run_loop.QuitClosure();
293 // writeData() is pinged a number of times as the WebM header is written; 297 // writeData() is pinged a number of times as the WebM header is written;
294 // the last time it is called it has the encoded data. 298 // the last time it is called it has the encoded data.
295 const size_t kEncodedDataSize = GetParam().first_encoded_audio_frame_size; 299 const size_t kEncodedDataSize = GetParam().first_encoded_audio_frame_size;
296 EXPECT_CALL(*this, writeData(_, Lt(kEncodedDataSize), _)).Times(AtLeast(1)); 300 EXPECT_CALL(*this, writeData(_, Lt(kEncodedDataSize), _)).Times(AtLeast(1));
297 EXPECT_CALL(*this, writeData(_, kEncodedDataSize, _)) 301 EXPECT_CALL(*this, writeData(_, kEncodedDataSize, _))
298 .Times(1) 302 .Times(1)
299 .WillOnce(RunClosure(quit_closure)); 303 .WillOnce(RunClosure(quit_closure));
300 304
301 OnAudioBusForTesting(*audio_bus1); 305 for (int i = 0; i < kRatioOpusToMediaStreamTrackBuffers; ++i)
306 OnAudioBusForTesting(*audio_bus1);
302 run_loop.Run(); 307 run_loop.Run();
303 } 308 }
304 309
305 { 310 {
306 base::RunLoop run_loop; 311 base::RunLoop run_loop;
307 base::Closure quit_closure = run_loop.QuitClosure(); 312 base::Closure quit_closure = run_loop.QuitClosure();
308 // The second time around writeData() is called a number of times to write 313 // The second time around writeData() is called a number of times to write
309 // the WebM frame header, and then is pinged with the encoded data. 314 // the WebM frame header, and then is pinged with the encoded data.
310 const size_t kSecondEncodedDataSize = 315 const size_t kSecondEncodedDataSize =
311 GetParam().second_encoded_audio_frame_size; 316 GetParam().second_encoded_audio_frame_size;
312 EXPECT_CALL(*this, writeData(_, Lt(kSecondEncodedDataSize), _)) 317 EXPECT_CALL(*this, writeData(_, Lt(kSecondEncodedDataSize), _))
313 .Times(AtLeast(1)); 318 .Times(AtLeast(1));
314 EXPECT_CALL(*this, writeData(_, kSecondEncodedDataSize, _)) 319 EXPECT_CALL(*this, writeData(_, kSecondEncodedDataSize, _))
315 .Times(1) 320 .Times(1)
316 .WillOnce(RunClosure(quit_closure)); 321 .WillOnce(RunClosure(quit_closure));
317 322
318 OnAudioBusForTesting(*audio_bus2); 323 for (int i = 0; i < kRatioOpusToMediaStreamTrackBuffers; ++i)
324 OnAudioBusForTesting(*audio_bus2);
319 run_loop.Run(); 325 run_loop.Run();
320 } 326 }
321 327
322 media_recorder_handler_->stop(); 328 media_recorder_handler_->stop();
323 329
324 // Expect a last call on destruction, with size 0 and |lastInSlice| true. 330 // Expect a last call on destruction, with size 0 and |lastInSlice| true.
325 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1); 331 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1);
326 media_recorder_handler_.reset(); 332 media_recorder_handler_.reset();
327 } 333 }
328 334
329 } // namespace content 335 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698