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

Side by Side Diff: chrome/browser/media/webrtc_video_quality_browsertest.cc

Issue 2183873002: Use MediaRecorder to capture video for quality test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/base64.h" 7 #include "base/base64.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/environment.h" 9 #include "base/environment.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 } 46 }
47 } // namespace 47 } // namespace
48 48
49 static const base::FilePath::CharType kFrameAnalyzerExecutable[] = 49 static const base::FilePath::CharType kFrameAnalyzerExecutable[] =
50 #if defined(OS_WIN) 50 #if defined(OS_WIN)
51 FILE_PATH_LITERAL("frame_analyzer.exe"); 51 FILE_PATH_LITERAL("frame_analyzer.exe");
52 #else 52 #else
53 FILE_PATH_LITERAL("frame_analyzer"); 53 FILE_PATH_LITERAL("frame_analyzer");
54 #endif 54 #endif
55 55
56 static const base::FilePath::CharType kArgbToI420ConverterExecutable[] =
57 #if defined(OS_WIN)
58 FILE_PATH_LITERAL("rgba_to_i420_converter.exe");
59 #else
60 FILE_PATH_LITERAL("rgba_to_i420_converter");
61 #endif
62
63 static const base::FilePath::CharType kCapturedYuvFileName[] = 56 static const base::FilePath::CharType kCapturedYuvFileName[] =
64 FILE_PATH_LITERAL("captured_video.yuv"); 57 FILE_PATH_LITERAL("captured_video.yuv");
58 static const base::FilePath::CharType kCapturedWebmFileName[] =
59 FILE_PATH_LITERAL("captured_video.webm");
65 static const base::FilePath::CharType kStatsFileName[] = 60 static const base::FilePath::CharType kStatsFileName[] =
66 FILE_PATH_LITERAL("stats.txt"); 61 FILE_PATH_LITERAL("stats.txt");
67 static const char kMainWebrtcTestHtmlPage[] = 62 static const char kMainWebrtcTestHtmlPage[] =
68 "/webrtc/webrtc_jsep01_test.html"; 63 "/webrtc/webrtc_jsep01_test.html";
69 static const char kCapturingWebrtcHtmlPage[] = 64 static const char kCapturingWebrtcHtmlPage[] =
70 "/webrtc/webrtc_video_quality_test.html"; 65 "/webrtc/webrtc_video_quality_test.html";
71 66
72 static const struct VideoQualityTestConfig { 67 static const struct VideoQualityTestConfig {
73 const char* test_name; 68 const char* test_name;
74 int width; 69 int width;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 .Append(test_config_.reference_video) 120 .Append(test_config_.reference_video)
126 .AddExtension(test::kY4mFileExtension); 121 .AddExtension(test::kY4mFileExtension);
127 command_line->AppendSwitchPath(switches::kUseFileForFakeVideoCapture, 122 command_line->AppendSwitchPath(switches::kUseFileForFakeVideoCapture,
128 webrtc_reference_video_y4m_); 123 webrtc_reference_video_y4m_);
129 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); 124 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
130 125
131 // The video playback will not work without a GPU, so force its use here. 126 // The video playback will not work without a GPU, so force its use here.
132 command_line->AppendSwitch(switches::kUseGpuInTests); 127 command_line->AppendSwitch(switches::kUseGpuInTests);
133 } 128 }
134 129
135 // Writes all frames we've captured so far by grabbing them from the 130 // Writes the captured video to a webm file.
136 // javascript and writing them to the temporary work directory. 131 void WriteCapturedWebmVideo(content::WebContents* capturing_tab,
137 void WriteCapturedFramesToWorkingDir(content::WebContents* capturing_tab) { 132 const base::FilePath& webm_video_filename) {
138 int num_frames = 0; 133 std::string base64_encoded_video =
139 std::string response = 134 ExecuteJavascript("getRecordedVideoAsBase64()", capturing_tab);
140 ExecuteJavascript("getTotalNumberCapturedFrames()", capturing_tab); 135 std::string recorded_video;
141 ASSERT_TRUE(base::StringToInt(response, &num_frames)) << 136 ASSERT_TRUE(base::Base64Decode(base64_encoded_video, &recorded_video));
142 "Failed to retrieve frame count: got " << response; 137 base::File video_file(webm_video_filename,
143 ASSERT_NE(0, num_frames) << "Failed to capture any frames."; 138 base::File::FLAG_CREATE | base::File::FLAG_WRITE);
144 139 size_t written = video_file.Write(0, recorded_video.c_str(),
145 for (int i = 0; i < num_frames; i++) { 140 recorded_video.length());
146 std::string base64_encoded_frame = 141 ASSERT_EQ(recorded_video.length(), written);
147 ExecuteJavascript(base::StringPrintf("getOneCapturedFrame(%d)", i),
148 capturing_tab);
149 std::string decoded_frame;
150 ASSERT_TRUE(base::Base64Decode(base64_encoded_frame, &decoded_frame))
151 << "Failed to decode frame data '" << base64_encoded_frame << "'.";
152
153 std::string file_name = base::StringPrintf("frame_%04d", i);
154 base::File frame_file(GetWorkingDir().AppendASCII(file_name),
155 base::File::FLAG_CREATE | base::File::FLAG_WRITE);
156 size_t written = frame_file.Write(0, decoded_frame.c_str(),
157 decoded_frame.length());
158 ASSERT_EQ(decoded_frame.length(), written);
159 }
160 } 142 }
161 143
162 // Runs the RGBA to I420 converter on the video in |capture_video_filename|, 144 // Runs ffmpeg on the captured webm video and writes it to a yuv video file.
163 // which should contain frames of size |width| x |height|. 145 bool RunWebmToI420Converter(const base::FilePath& webm_video_filename,
164 // 146 const base::FilePath& yuv_video_filename) {
165 // The rgba_to_i420_converter is part of the webrtc_test_tools target which 147 base::FilePath path_to_ffmpeg = test::GetToolForPlatform("ffmpeg");
166 // should be build prior to running this test. The resulting binary should 148 if (!base::PathExists(path_to_ffmpeg)) {
167 // live next to Chrome. 149 LOG(ERROR) << "Missing ffmpeg: should be in " << path_to_ffmpeg.value();
168 bool RunARGBtoI420Converter(int width,
kjellander_chromium 2016/08/01 05:53:34 I'm quite sure this is the only place we use this
169 int height,
170 const base::FilePath& captured_video_filename) {
171 base::FilePath path_to_converter =
172 GetBrowserDir().Append(kArgbToI420ConverterExecutable);
173
174 if (!base::PathExists(path_to_converter)) {
175 LOG(ERROR) << "Missing ARGB->I420 converter: should be in "
176 << path_to_converter.value()
177 << ". Try building the chromium_builder_webrtc target.";
178 return false; 150 return false;
179 } 151 }
180 152
181 base::CommandLine converter_command(path_to_converter); 153 base::CommandLine ffmpeg_command(path_to_ffmpeg);
182 converter_command.AppendSwitchPath("--frames_dir", GetWorkingDir()); 154 ffmpeg_command.AppendArg("-i");
183 converter_command.AppendSwitchPath("--output_file", 155 ffmpeg_command.AppendArgPath(webm_video_filename);
184 captured_video_filename); 156 ffmpeg_command.AppendArgPath(yuv_video_filename);
185 converter_command.AppendSwitchASCII("--width", base::IntToString(width));
186 converter_command.AppendSwitchASCII("--height", base::IntToString(height));
187 converter_command.AppendSwitchASCII("--delete_frames", "true");
188 157
189 // We produce an output file that will later be used as an input to the 158 // We produce an output file that will later be used as an input to the
190 // barcode decoder and frame analyzer tools. 159 // barcode decoder and frame analyzer tools.
191 DVLOG(0) << "Running " << converter_command.GetCommandLineString(); 160 DVLOG(0) << "Running " << ffmpeg_command.GetCommandLineString();
192 std::string result; 161 std::string result;
193 bool ok = base::GetAppOutput(converter_command, &result); 162 bool ok = base::GetAppOutput(ffmpeg_command, &result);
194 DVLOG(0) << "Output was:\n\n" << result; 163 DVLOG(0) << "Output was:\n\n" << result;
195 return ok; 164 return ok;
196 } 165 }
197 166
198 // Compares the |captured_video_filename| with the |reference_video_filename|. 167 // Compares the |captured_video_filename| with the |reference_video_filename|.
199 // 168 //
200 // The barcode decoder decodes the captured video containing barcodes overlaid 169 // The barcode decoder decodes the captured video containing barcodes overlaid
201 // into every frame of the video (produced by rgba_to_i420_converter). It 170 // into every frame of the video (produced by rgba_to_i420_converter). It
202 // produces a set of PNG images and a |stats_file| that maps each captured 171 // produces a set of PNG images and a |stats_file| that maps each captured
203 // frame to a frame in the reference video. The frames should be of size 172 // frame to a frame in the reference video. The frames should be of size
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 271
303 // Poll slower here to avoid flooding the log with messages: capturing and 272 // Poll slower here to avoid flooding the log with messages: capturing and
304 // sending frames take quite a bit of time. 273 // sending frames take quite a bit of time.
305 int polling_interval_msec = 1000; 274 int polling_interval_msec = 1000;
306 275
307 EXPECT_TRUE(test::PollingWaitUntil("doneFrameCapturing()", "done-capturing", 276 EXPECT_TRUE(test::PollingWaitUntil("doneFrameCapturing()", "done-capturing",
308 right_tab, polling_interval_msec)); 277 right_tab, polling_interval_msec));
309 278
310 HangUp(left_tab); 279 HangUp(left_tab);
311 280
312 WriteCapturedFramesToWorkingDir(right_tab); 281 WriteCapturedWebmVideo(
282 right_tab, GetWorkingDir().Append(kCapturedWebmFileName));
313 283
314 // Shut everything down to avoid having the javascript race with the 284 // Shut everything down to avoid having the javascript race with the
315 // analysis tools. For instance, dont have console log printouts interleave 285 // analysis tools. For instance, dont have console log printouts interleave
316 // with the RESULT lines from the analysis tools (crbug.com/323200). 286 // with the RESULT lines from the analysis tools (crbug.com/323200).
317 chrome::CloseWebContents(browser(), left_tab, false); 287 chrome::CloseWebContents(browser(), left_tab, false);
318 chrome::CloseWebContents(browser(), right_tab, false); 288 chrome::CloseWebContents(browser(), right_tab, false);
319 289
320 ASSERT_TRUE( 290 RunWebmToI420Converter(GetWorkingDir().Append(kCapturedWebmFileName),
321 RunARGBtoI420Converter(test_config_.width, test_config_.height, 291 GetWorkingDir().Append(kCapturedYuvFileName));
322 GetWorkingDir().Append(kCapturedYuvFileName)));
323 292
324 ASSERT_TRUE(CompareVideosAndPrintResult( 293 ASSERT_TRUE(CompareVideosAndPrintResult(
325 MakeLabel(test_config_.test_name, video_codec), test_config_.width, 294 MakeLabel(test_config_.test_name, video_codec), test_config_.width,
326 test_config_.height, GetWorkingDir().Append(kCapturedYuvFileName), 295 test_config_.height, GetWorkingDir().Append(kCapturedYuvFileName),
327 test::GetReferenceFilesDir() 296 test::GetReferenceFilesDir()
328 .Append(test_config_.reference_video) 297 .Append(test_config_.reference_video)
329 .AddExtension(test::kYuvFileExtension), 298 .AddExtension(test::kYuvFileExtension),
330 GetWorkingDir().Append(kStatsFileName))); 299 GetWorkingDir().Append(kStatsFileName)));
331 } 300 }
332 301
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 if (!base::FeatureList::IsEnabled(content::kWebRtcH264WithOpenH264FFmpeg)) { 345 if (!base::FeatureList::IsEnabled(content::kWebRtcH264WithOpenH264FFmpeg)) {
377 LOG(WARNING) << "Run-time feature WebRTC-H264WithOpenH264FFmpeg disabled. " 346 LOG(WARNING) << "Run-time feature WebRTC-H264WithOpenH264FFmpeg disabled. "
378 "Skipping WebRtcVideoQualityBrowserTest.MANUAL_TestVideoQualityH264 " 347 "Skipping WebRtcVideoQualityBrowserTest.MANUAL_TestVideoQualityH264 "
379 "(test \"OK\")"; 348 "(test \"OK\")";
380 return; 349 return;
381 } 350 }
382 TestVideoQuality("H264"); 351 TestVideoQuality("H264");
383 } 352 }
384 353
385 #endif // BUILDFLAG(RTC_USE_H264) 354 #endif // BUILDFLAG(RTC_USE_H264)
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/webrtc/video_extraction.js » ('j') | chrome/test/data/webrtc/video_extraction.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698