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

Side by Side Diff: media/gpu/video_decode_accelerator_unittest.cc

Issue 2753773002: Fix failed to write thumbnail png issue (Closed)
Patch Set: Fix failed to write thumbnail png issue Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // The bulk of this file is support code; sorry about that. Here's an overview 5 // The bulk of this file is support code; sorry about that. Here's an overview
6 // to hopefully help readers of this code: 6 // to hopefully help readers of this code:
7 // - RenderingHelper is charged with interacting with X11/{EGL/GLES2,GLX/GL} or 7 // - RenderingHelper is charged with interacting with X11/{EGL/GLES2,GLX/GL} or
8 // Win/EGL. 8 // Win/EGL.
9 // - ClientState is an enum for the state of the decode client used by the test. 9 // - ClientState is an enum for the state of the decode client used by the test.
10 // - ClientStateNotification is a barrier abstraction that allows the test code 10 // - ClientStateNotification is a barrier abstraction that allows the test code
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 int g_fake_decoder = 0; 136 int g_fake_decoder = 0;
137 137
138 // Test buffer import into VDA, providing buffers allocated by us, instead of 138 // Test buffer import into VDA, providing buffers allocated by us, instead of
139 // requesting the VDA itself to allocate buffers. 139 // requesting the VDA itself to allocate buffers.
140 bool g_test_import = false; 140 bool g_test_import = false;
141 141
142 // This is the location of the test files. If empty, they're in the current 142 // This is the location of the test files. If empty, they're in the current
143 // working directory. 143 // working directory.
144 base::FilePath g_test_file_path; 144 base::FilePath g_test_file_path;
145 145
146 // The location to output bad thumbnail image. If empty or invalid, fallback to
147 // the original location.
148 base::FilePath g_thumbnail_output_dir;
149
146 // Environment to store rendering thread. 150 // Environment to store rendering thread.
147 class VideoDecodeAcceleratorTestEnvironment; 151 class VideoDecodeAcceleratorTestEnvironment;
148 VideoDecodeAcceleratorTestEnvironment* g_env; 152 VideoDecodeAcceleratorTestEnvironment* g_env;
149 153
150 // Magic constants for differentiating the reasons for NotifyResetDone being 154 // Magic constants for differentiating the reasons for NotifyResetDone being
151 // called. 155 // called.
152 enum ResetPoint { 156 enum ResetPoint {
153 // Reset() right after calling Flush() (before getting NotifyFlushDone()). 157 // Reset() right after calling Flush() (before getting NotifyFlushDone()).
154 RESET_BEFORE_NOTIFY_FLUSH_DONE = -5, 158 RESET_BEFORE_NOTIFY_FLUSH_DONE = -5,
155 // Reset() just after calling Decode() with a fragment containing config info. 159 // Reset() just after calling Decode() with a fragment containing config info.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 std::string data_str; 196 std::string data_str;
193 }; 197 };
194 198
195 const gfx::Size kThumbnailsPageSize(1600, 1200); 199 const gfx::Size kThumbnailsPageSize(1600, 1200);
196 const gfx::Size kThumbnailSize(160, 120); 200 const gfx::Size kThumbnailSize(160, 120);
197 const int kMD5StringLength = 32; 201 const int kMD5StringLength = 32;
198 202
199 base::FilePath GetTestDataFile(const base::FilePath& input_file) { 203 base::FilePath GetTestDataFile(const base::FilePath& input_file) {
200 if (input_file.IsAbsolute()) 204 if (input_file.IsAbsolute())
201 return input_file; 205 return input_file;
202 return base::MakeAbsoluteFilePath(g_test_file_path.Append(input_file)); 206 // input_file needs to be existed, otherwise base::MakeAbsoluteFilePath will
207 // return an empty base::FilePath.
208 base::FilePath abs_path =
209 base::MakeAbsoluteFilePath(g_test_file_path.Append(input_file));
210 LOG_IF(FATAL, abs_path.empty())
wuchengli 2017/03/22 08:57:01 s/FATAL/ERROR/. Let's not crash the test. It's bet
211 << g_test_file_path.Append(input_file).value().c_str()
212 << " is not an existing path.";
213 return abs_path;
203 } 214 }
204 215
205 // Read in golden MD5s for the thumbnailed rendering of this video 216 // Read in golden MD5s for the thumbnailed rendering of this video
206 void ReadGoldenThumbnailMD5s(const TestVideoFile* video_file, 217 void ReadGoldenThumbnailMD5s(const TestVideoFile* video_file,
207 std::vector<std::string>* md5_strings) { 218 std::vector<std::string>* md5_strings) {
208 base::FilePath filepath(video_file->file_name); 219 base::FilePath filepath(video_file->file_name);
209 filepath = filepath.AddExtension(FILE_PATH_LITERAL(".md5")); 220 filepath = filepath.AddExtension(FILE_PATH_LITERAL(".md5"));
210 std::string all_md5s; 221 std::string all_md5s;
211 base::ReadFileToString(GetTestDataFile(filepath), &all_md5s); 222 base::ReadFileToString(GetTestDataFile(filepath), &all_md5s);
212 *md5_strings = base::SplitString(all_md5s, "\n", base::TRIM_WHITESPACE, 223 *md5_strings = base::SplitString(all_md5s, "\n", base::TRIM_WHITESPACE,
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 gfx::PNGCodec::FORMAT_RGB, 1544 gfx::PNGCodec::FORMAT_RGB,
1534 kThumbnailsPageSize, 1545 kThumbnailsPageSize,
1535 kThumbnailsPageSize.width() * 3, 1546 kThumbnailsPageSize.width() * 3,
1536 true, 1547 true,
1537 std::vector<gfx::PNGCodec::Comment>(), 1548 std::vector<gfx::PNGCodec::Comment>(),
1538 &png); 1549 &png);
1539 1550
1540 LOG(ERROR) << "Unknown thumbnails MD5: " << md5_string; 1551 LOG(ERROR) << "Unknown thumbnails MD5: " << md5_string;
1541 1552
1542 base::FilePath filepath(test_video_files_[0]->file_name); 1553 base::FilePath filepath(test_video_files_[0]->file_name);
1554 if (!g_thumbnail_output_dir.empty() &&
1555 base::DirectoryExists(g_thumbnail_output_dir))
wuchengli 2017/03/22 08:57:01 This is multiple lines. Please use braces if () {
1556 // Write bad thumbnails image to where --thumbnail_output_dir assigned.
1557 filepath = g_thumbnail_output_dir.Append(filepath.BaseName());
1558 else
1559 // Fallback to write to test data directory.
1560 // Note: test data directory is not writable by vda_unittest while
1561 // running by autotest. It should assign its resultsdir as output
1562 // directory.
1563 filepath = GetTestDataFile(filepath);
1543 filepath = filepath.AddExtension(FILE_PATH_LITERAL(".bad_thumbnails")); 1564 filepath = filepath.AddExtension(FILE_PATH_LITERAL(".bad_thumbnails"));
1544 filepath = filepath.AddExtension(FILE_PATH_LITERAL(".png")); 1565 filepath = filepath.AddExtension(FILE_PATH_LITERAL(".png"));
1545 int num_bytes = 1566 LOG(INFO) << "Write bad thumbnails image to: "
1546 base::WriteFile(GetTestDataFile(filepath), 1567 << filepath.value().c_str();
1547 reinterpret_cast<char*>(&png[0]), png.size()); 1568 int num_bytes = base::WriteFile(
1569 filepath, reinterpret_cast<char*>(&png[0]), png.size());
1548 EXPECT_EQ(num_bytes, static_cast<int>(png.size())); 1570 EXPECT_EQ(num_bytes, static_cast<int>(png.size()));
1549 } 1571 }
1550 EXPECT_NE(match, golden_md5s.end()); 1572 EXPECT_NE(match, golden_md5s.end());
1551 EXPECT_EQ(alpha_solid, true) << "RGBA frame had incorrect alpha"; 1573 EXPECT_EQ(alpha_solid, true) << "RGBA frame had incorrect alpha";
1552 } 1574 }
1553 1575
1554 // Output the frame delivery time to file 1576 // Output the frame delivery time to file
1555 // We can only make performance/correctness assertions if the decoder was 1577 // We can only make performance/correctness assertions if the decoder was
1556 // allowed to finish. 1578 // allowed to finish.
1557 if (g_output_log != NULL && delete_decoder_state >= CS_FLUSHED) { 1579 if (g_output_log != NULL && delete_decoder_state >= CS_FLUSHED) {
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") 1903 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless")
1882 continue; 1904 continue;
1883 if (it->first == "test_import") { 1905 if (it->first == "test_import") {
1884 media::g_test_import = true; 1906 media::g_test_import = true;
1885 continue; 1907 continue;
1886 } 1908 }
1887 if (it->first == "use-test-data-path") { 1909 if (it->first == "use-test-data-path") {
1888 media::g_test_file_path = media::GetTestDataFilePath(""); 1910 media::g_test_file_path = media::GetTestDataFilePath("");
1889 continue; 1911 continue;
1890 } 1912 }
1913 if (it->first == "thumbnail_output_dir") {
1914 media::g_thumbnail_output_dir = base::FilePath(it->second.c_str());
1915 }
1891 } 1916 }
1892 1917
1893 base::ShadowingAtExitManager at_exit_manager; 1918 base::ShadowingAtExitManager at_exit_manager;
1894 1919
1895 return base::LaunchUnitTestsSerially( 1920 return base::LaunchUnitTestsSerially(
1896 argc, argv, 1921 argc, argv,
1897 base::Bind(&media::VDATestSuite::Run, base::Unretained(&test_suite))); 1922 base::Bind(&media::VDATestSuite::Run, base::Unretained(&test_suite)));
1898 } 1923 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698