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

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

Issue 1882373004: Migrate content/common/gpu/media code to media/gpu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix prefix to content references in content_gpu.gypi Created 4 years, 8 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 // This has to be included first. 5 // This has to be included first.
6 // See http://code.google.com/p/googletest/issues/detail?id=371 6 // See http://code.google.com/p/googletest/issues/detail?id=371
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
11 #include <string.h> 11 #include <string.h>
12 12
13 #include "base/at_exit.h" 13 #include "base/at_exit.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/scoped_vector.h" 19 #include "base/memory/scoped_vector.h"
20 #include "base/path_service.h" 20 #include "base/path_service.h"
21 #include "base/strings/string_piece.h" 21 #include "base/strings/string_piece.h"
22 #include "base/strings/string_split.h" 22 #include "base/strings/string_split.h"
23 #include "base/thread_task_runner_handle.h" 23 #include "base/thread_task_runner_handle.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h"
26 #include "media/base/test_data_util.h" 25 #include "media/base/test_data_util.h"
27 #include "media/filters/jpeg_parser.h" 26 #include "media/filters/jpeg_parser.h"
27 #include "media/gpu/video_accelerator_unittest_helpers.h"
28 #include "media/video/jpeg_decode_accelerator.h" 28 #include "media/video/jpeg_decode_accelerator.h"
29 #include "third_party/libyuv/include/libyuv.h" 29 #include "third_party/libyuv/include/libyuv.h"
30 #include "ui/gfx/codec/jpeg_codec.h" 30 #include "ui/gfx/codec/jpeg_codec.h"
31 31
32 #if defined(OS_CHROMEOS) 32 #if defined(OS_CHROMEOS)
33 #if defined(USE_V4L2_CODEC) 33 #if defined(USE_V4L2_CODEC)
34 #include "content/common/gpu/media/v4l2_device.h" 34 #include "media/gpu/v4l2_device.h"
35 #include "content/common/gpu/media/v4l2_jpeg_decode_accelerator.h" 35 #include "media/gpu/v4l2_jpeg_decode_accelerator.h"
36 #endif 36 #endif
37 #if defined(ARCH_CPU_X86_FAMILY) 37 #if defined(ARCH_CPU_X86_FAMILY)
38 #include "content/common/gpu/media/vaapi_jpeg_decode_accelerator.h" 38 #include "media/gpu/vaapi_jpeg_decode_accelerator.h"
39 #include "content/common/gpu/media/vaapi_wrapper.h" 39 #include "media/gpu/vaapi_wrapper.h"
40 #endif 40 #endif
41 #endif 41 #endif
42 42
43 using media::JpegDecodeAccelerator; 43 using media::JpegDecodeAccelerator;
44 44
45 namespace content { 45 namespace media {
46 namespace { 46 namespace {
47 47
48 // Default test image file. 48 // Default test image file.
49 const base::FilePath::CharType* kDefaultJpegFilename = 49 const base::FilePath::CharType* kDefaultJpegFilename =
50 FILE_PATH_LITERAL("peach_pi-1280x720.jpg"); 50 FILE_PATH_LITERAL("peach_pi-1280x720.jpg");
51 // Decide to save decode results to files or not. Output files will be saved 51 // Decide to save decode results to files or not. Output files will be saved
52 // in the same directory with unittest. File name is like input file but 52 // in the same directory with unittest. File name is like input file but
53 // changing the extension to "yuv". 53 // changing the extension to "yuv".
54 bool g_save_to_file = false; 54 bool g_save_to_file = false;
55 // Threshold for mean absolute difference of hardware and software decode. 55 // Threshold for mean absolute difference of hardware and software decode.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // Mapped memory of output buffer from hardware decoder. 121 // Mapped memory of output buffer from hardware decoder.
122 std::unique_ptr<base::SharedMemory> hw_out_shm_; 122 std::unique_ptr<base::SharedMemory> hw_out_shm_;
123 // Mapped memory of output buffer from software decoder. 123 // Mapped memory of output buffer from software decoder.
124 std::unique_ptr<base::SharedMemory> sw_out_shm_; 124 std::unique_ptr<base::SharedMemory> sw_out_shm_;
125 125
126 DISALLOW_COPY_AND_ASSIGN(JpegClient); 126 DISALLOW_COPY_AND_ASSIGN(JpegClient);
127 }; 127 };
128 128
129 JpegClient::JpegClient(const std::vector<TestImageFile*>& test_image_files, 129 JpegClient::JpegClient(const std::vector<TestImageFile*>& test_image_files,
130 ClientStateNotification<ClientState>* note) 130 ClientStateNotification<ClientState>* note)
131 : test_image_files_(test_image_files), state_(CS_CREATED), note_(note) { 131 : test_image_files_(test_image_files), state_(CS_CREATED), note_(note) {}
132 }
133 132
134 JpegClient::~JpegClient() { 133 JpegClient::~JpegClient() {}
135 }
136 134
137 void JpegClient::CreateJpegDecoder() { 135 void JpegClient::CreateJpegDecoder() {
138 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) 136 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
139 decoder_.reset( 137 decoder_.reset(
140 new VaapiJpegDecodeAccelerator(base::ThreadTaskRunnerHandle::Get())); 138 new VaapiJpegDecodeAccelerator(base::ThreadTaskRunnerHandle::Get()));
141 #elif defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) 139 #elif defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
142 scoped_refptr<V4L2Device> device = 140 scoped_refptr<V4L2Device> device =
143 V4L2Device::Create(V4L2Device::kJpegDecoder); 141 V4L2Device::Create(V4L2Device::kJpegDecoder);
144 if (!device.get()) { 142 if (!device.get()) {
145 LOG(ERROR) << "V4L2Device::Create failed"; 143 LOG(ERROR) << "V4L2Device::Create failed";
(...skipping 24 matching lines...) Expand all
170 } 168 }
171 if (g_save_to_file) { 169 if (g_save_to_file) {
172 SaveToFile(bitstream_buffer_id); 170 SaveToFile(bitstream_buffer_id);
173 } 171 }
174 172
175 double difference = GetMeanAbsoluteDifference(bitstream_buffer_id); 173 double difference = GetMeanAbsoluteDifference(bitstream_buffer_id);
176 if (difference <= kDecodeSimilarityThreshold) { 174 if (difference <= kDecodeSimilarityThreshold) {
177 SetState(CS_DECODE_PASS); 175 SetState(CS_DECODE_PASS);
178 } else { 176 } else {
179 LOG(ERROR) << "The mean absolute difference between software and hardware " 177 LOG(ERROR) << "The mean absolute difference between software and hardware "
180 "decode is " << difference; 178 "decode is "
179 << difference;
181 SetState(CS_ERROR); 180 SetState(CS_ERROR);
182 } 181 }
183 } 182 }
184 183
185 void JpegClient::NotifyError(int32_t bitstream_buffer_id, 184 void JpegClient::NotifyError(int32_t bitstream_buffer_id,
186 JpegDecodeAccelerator::Error error) { 185 JpegDecodeAccelerator::Error error) {
187 LOG(ERROR) << "Notifying of error " << error << " for buffer id " 186 LOG(ERROR) << "Notifying of error " << error << " for buffer id "
188 << bitstream_buffer_id; 187 << bitstream_buffer_id;
189 SetState(CS_ERROR); 188 SetState(CS_ERROR);
190 } 189 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 TestImageFile* image_file = test_image_files_[bitstream_buffer_id]; 246 TestImageFile* image_file = test_image_files_[bitstream_buffer_id];
248 247
249 PrepareMemory(bitstream_buffer_id); 248 PrepareMemory(bitstream_buffer_id);
250 249
251 base::SharedMemoryHandle dup_handle; 250 base::SharedMemoryHandle dup_handle;
252 dup_handle = base::SharedMemory::DuplicateHandle(in_shm_->handle()); 251 dup_handle = base::SharedMemory::DuplicateHandle(in_shm_->handle());
253 media::BitstreamBuffer bitstream_buffer(bitstream_buffer_id, dup_handle, 252 media::BitstreamBuffer bitstream_buffer(bitstream_buffer_id, dup_handle,
254 image_file->data_str.size()); 253 image_file->data_str.size());
255 scoped_refptr<media::VideoFrame> out_frame_ = 254 scoped_refptr<media::VideoFrame> out_frame_ =
256 media::VideoFrame::WrapExternalSharedMemory( 255 media::VideoFrame::WrapExternalSharedMemory(
257 media::PIXEL_FORMAT_I420, 256 media::PIXEL_FORMAT_I420, image_file->visible_size,
258 image_file->visible_size, 257 gfx::Rect(image_file->visible_size), image_file->visible_size,
259 gfx::Rect(image_file->visible_size), 258 static_cast<uint8_t*>(hw_out_shm_->memory()), image_file->output_size,
260 image_file->visible_size, 259 hw_out_shm_->handle(), 0, base::TimeDelta());
261 static_cast<uint8_t*>(hw_out_shm_->memory()),
262 image_file->output_size,
263 hw_out_shm_->handle(),
264 0,
265 base::TimeDelta());
266 LOG_ASSERT(out_frame_.get()); 260 LOG_ASSERT(out_frame_.get());
267 decoder_->Decode(bitstream_buffer, out_frame_); 261 decoder_->Decode(bitstream_buffer, out_frame_);
268 } 262 }
269 263
270 bool JpegClient::GetSoftwareDecodeResult(int32_t bitstream_buffer_id) { 264 bool JpegClient::GetSoftwareDecodeResult(int32_t bitstream_buffer_id) {
271 media::VideoPixelFormat format = media::PIXEL_FORMAT_I420; 265 media::VideoPixelFormat format = media::PIXEL_FORMAT_I420;
272 TestImageFile* image_file = test_image_files_[bitstream_buffer_id]; 266 TestImageFile* image_file = test_image_files_[bitstream_buffer_id];
273 267
274 uint8_t* yplane = static_cast<uint8_t*>(sw_out_shm_->memory()); 268 uint8_t* yplane = static_cast<uint8_t*>(sw_out_shm_->memory());
275 uint8_t* uplane = 269 uint8_t* uplane =
276 yplane + 270 yplane +
277 media::VideoFrame::PlaneSize(format, media::VideoFrame::kYPlane, 271 media::VideoFrame::PlaneSize(format, media::VideoFrame::kYPlane,
278 image_file->visible_size).GetArea(); 272 image_file->visible_size)
273 .GetArea();
279 uint8_t* vplane = 274 uint8_t* vplane =
280 uplane + 275 uplane +
281 media::VideoFrame::PlaneSize(format, media::VideoFrame::kUPlane, 276 media::VideoFrame::PlaneSize(format, media::VideoFrame::kUPlane,
282 image_file->visible_size).GetArea(); 277 image_file->visible_size)
278 .GetArea();
283 int yplane_stride = image_file->visible_size.width(); 279 int yplane_stride = image_file->visible_size.width();
284 int uv_plane_stride = yplane_stride / 2; 280 int uv_plane_stride = yplane_stride / 2;
285 281
286 if (libyuv::ConvertToI420( 282 if (libyuv::ConvertToI420(
287 static_cast<uint8_t*>(in_shm_->memory()), 283 static_cast<uint8_t*>(in_shm_->memory()), image_file->data_str.size(),
288 image_file->data_str.size(), 284 yplane, yplane_stride, uplane, uv_plane_stride, vplane,
289 yplane, 285 uv_plane_stride, 0, 0, image_file->visible_size.width(),
290 yplane_stride, 286 image_file->visible_size.height(), image_file->visible_size.width(),
291 uplane, 287 image_file->visible_size.height(), libyuv::kRotate0,
292 uv_plane_stride,
293 vplane,
294 uv_plane_stride,
295 0,
296 0,
297 image_file->visible_size.width(),
298 image_file->visible_size.height(),
299 image_file->visible_size.width(),
300 image_file->visible_size.height(),
301 libyuv::kRotate0,
302 libyuv::FOURCC_MJPG) != 0) { 288 libyuv::FOURCC_MJPG) != 0) {
303 LOG(ERROR) << "Software decode " << image_file->filename << " failed."; 289 LOG(ERROR) << "Software decode " << image_file->filename << " failed.";
304 return false; 290 return false;
305 } 291 }
306 return true; 292 return true;
307 } 293 }
308 294
309 class JpegDecodeAcceleratorTestEnvironment : public ::testing::Environment { 295 class JpegDecodeAcceleratorTestEnvironment : public ::testing::Environment {
310 public: 296 public:
311 JpegDecodeAcceleratorTestEnvironment( 297 JpegDecodeAcceleratorTestEnvironment(
312 const base::FilePath::CharType* jpeg_filenames) { 298 const base::FilePath::CharType* jpeg_filenames) {
313 user_jpeg_filenames_ = 299 user_jpeg_filenames_ =
314 jpeg_filenames ? jpeg_filenames: kDefaultJpegFilename; 300 jpeg_filenames ? jpeg_filenames : kDefaultJpegFilename;
315 } 301 }
316 void SetUp() override; 302 void SetUp() override;
317 void TearDown() override; 303 void TearDown() override;
318 304
319 // Create all black test image with |width| and |height| size. 305 // Create all black test image with |width| and |height| size.
320 bool CreateTestJpegImage(int width, int height, base::FilePath* filename); 306 bool CreateTestJpegImage(int width, int height, base::FilePath* filename);
321 307
322 // Read image from |filename| to |image_data|. 308 // Read image from |filename| to |image_data|.
323 void ReadTestJpegImage(base::FilePath& filename, TestImageFile* image_data); 309 void ReadTestJpegImage(base::FilePath& filename, TestImageFile* image_data);
324 310
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 return false; 398 return false;
413 } 399 }
414 400
415 LOG_ASSERT(base::CreateTemporaryFile(filename)); 401 LOG_ASSERT(base::CreateTemporaryFile(filename));
416 EXPECT_TRUE(base::AppendToFile( 402 EXPECT_TRUE(base::AppendToFile(
417 *filename, reinterpret_cast<char*>(&encoded[0]), encoded.size())); 403 *filename, reinterpret_cast<char*>(&encoded[0]), encoded.size()));
418 return true; 404 return true;
419 } 405 }
420 406
421 void JpegDecodeAcceleratorTestEnvironment::ReadTestJpegImage( 407 void JpegDecodeAcceleratorTestEnvironment::ReadTestJpegImage(
422 base::FilePath& input_file, TestImageFile* image_data) { 408 base::FilePath& input_file,
409 TestImageFile* image_data) {
423 ASSERT_TRUE(base::ReadFileToString(input_file, &image_data->data_str)); 410 ASSERT_TRUE(base::ReadFileToString(input_file, &image_data->data_str));
424 411
425 ASSERT_TRUE(media::ParseJpegPicture( 412 ASSERT_TRUE(media::ParseJpegPicture(
426 reinterpret_cast<const uint8_t*>(image_data->data_str.data()), 413 reinterpret_cast<const uint8_t*>(image_data->data_str.data()),
427 image_data->data_str.size(), 414 image_data->data_str.size(), &image_data->parse_result));
428 &image_data->parse_result));
429 image_data->visible_size.SetSize( 415 image_data->visible_size.SetSize(
430 image_data->parse_result.frame_header.visible_width, 416 image_data->parse_result.frame_header.visible_width,
431 image_data->parse_result.frame_header.visible_height); 417 image_data->parse_result.frame_header.visible_height);
432 image_data->output_size = media::VideoFrame::AllocationSize( 418 image_data->output_size = media::VideoFrame::AllocationSize(
433 media::PIXEL_FORMAT_I420, image_data->visible_size); 419 media::PIXEL_FORMAT_I420, image_data->visible_size);
434 } 420 }
435 421
436 class JpegDecodeAcceleratorTest : public ::testing::Test { 422 class JpegDecodeAcceleratorTest : public ::testing::Test {
437 protected: 423 protected:
438 JpegDecodeAcceleratorTest() {} 424 JpegDecodeAcceleratorTest() {}
(...skipping 23 matching lines...) Expand all
462 decoder_thread.task_runner()->PostTask( 448 decoder_thread.task_runner()->PostTask(
463 FROM_HERE, base::Bind(&JpegClient::CreateJpegDecoder, 449 FROM_HERE, base::Bind(&JpegClient::CreateJpegDecoder,
464 base::Unretained(clients.back()))); 450 base::Unretained(clients.back())));
465 ASSERT_EQ(notes[i]->Wait(), CS_INITIALIZED); 451 ASSERT_EQ(notes[i]->Wait(), CS_INITIALIZED);
466 } 452 }
467 453
468 for (size_t index = 0; index < test_image_files_.size(); index++) { 454 for (size_t index = 0; index < test_image_files_.size(); index++) {
469 for (size_t i = 0; i < num_concurrent_decoders; i++) { 455 for (size_t i = 0; i < num_concurrent_decoders; i++) {
470 decoder_thread.task_runner()->PostTask( 456 decoder_thread.task_runner()->PostTask(
471 FROM_HERE, base::Bind(&JpegClient::StartDecode, 457 FROM_HERE, base::Bind(&JpegClient::StartDecode,
472 base::Unretained(clients[i]), 458 base::Unretained(clients[i]), index));
473 index));
474 } 459 }
475 for (size_t i = 0; i < num_concurrent_decoders; i++) { 460 for (size_t i = 0; i < num_concurrent_decoders; i++) {
476 ASSERT_EQ(notes[i]->Wait(), expected_status_[index]); 461 ASSERT_EQ(notes[i]->Wait(), expected_status_[index]);
477 } 462 }
478 } 463 }
479 464
480 for (size_t i = 0; i < num_concurrent_decoders; i++) { 465 for (size_t i = 0; i < num_concurrent_decoders; i++) {
481 decoder_thread.task_runner()->PostTask( 466 decoder_thread.task_runner()->PostTask(
482 FROM_HERE, base::Bind(&JpegClient::DestroyJpegDecoder, 467 FROM_HERE, base::Bind(&JpegClient::DestroyJpegDecoder,
483 base::Unretained(clients[i]))); 468 base::Unretained(clients[i])));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 520
536 TEST_F(JpegDecodeAcceleratorTest, KeepDecodeAfterFailure) { 521 TEST_F(JpegDecodeAcceleratorTest, KeepDecodeAfterFailure) {
537 test_image_files_.push_back(g_env->image_data_invalid_.get()); 522 test_image_files_.push_back(g_env->image_data_invalid_.get());
538 test_image_files_.push_back(g_env->image_data_1280x720_default_.get()); 523 test_image_files_.push_back(g_env->image_data_1280x720_default_.get());
539 expected_status_.push_back(CS_ERROR); 524 expected_status_.push_back(CS_ERROR);
540 expected_status_.push_back(CS_DECODE_PASS); 525 expected_status_.push_back(CS_DECODE_PASS);
541 TestDecode(1); 526 TestDecode(1);
542 } 527 }
543 528
544 } // namespace 529 } // namespace
545 } // namespace content 530 } // namespace media
546 531
547 int main(int argc, char** argv) { 532 int main(int argc, char** argv) {
548 testing::InitGoogleTest(&argc, argv); 533 testing::InitGoogleTest(&argc, argv);
549 base::CommandLine::Init(argc, argv); 534 base::CommandLine::Init(argc, argv);
550 base::ShadowingAtExitManager at_exit_manager; 535 base::ShadowingAtExitManager at_exit_manager;
551 536
552 // Needed to enable DVLOG through --vmodule. 537 // Needed to enable DVLOG through --vmodule.
553 logging::LoggingSettings settings; 538 logging::LoggingSettings settings;
554 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 539 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
555 LOG_ASSERT(logging::InitLogging(settings)); 540 LOG_ASSERT(logging::InitLogging(settings));
556 541
557 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 542 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
558 DCHECK(cmd_line); 543 DCHECK(cmd_line);
559 544
560 const base::FilePath::CharType* jpeg_filenames = nullptr; 545 const base::FilePath::CharType* jpeg_filenames = nullptr;
561 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); 546 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches();
562 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); 547 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin();
563 it != switches.end(); ++it) { 548 it != switches.end(); ++it) {
564 // jpeg_filenames can include one or many files and use ';' as delimiter. 549 // jpeg_filenames can include one or many files and use ';' as delimiter.
565 if (it->first == "jpeg_filenames") { 550 if (it->first == "jpeg_filenames") {
566 jpeg_filenames = it->second.c_str(); 551 jpeg_filenames = it->second.c_str();
567 continue; 552 continue;
568 } 553 }
569 if (it->first == "save_to_file") { 554 if (it->first == "save_to_file") {
570 content::g_save_to_file = true; 555 media::g_save_to_file = true;
571 continue; 556 continue;
572 } 557 }
573 if (it->first == "v" || it->first == "vmodule") 558 if (it->first == "v" || it->first == "vmodule")
574 continue; 559 continue;
575 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; 560 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second;
576 } 561 }
577 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) 562 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
578 content::VaapiWrapper::PreSandboxInitialization(); 563 media::VaapiWrapper::PreSandboxInitialization();
579 #endif 564 #endif
580 565
581 content::g_env = 566 media::g_env = reinterpret_cast<media::JpegDecodeAcceleratorTestEnvironment*>(
582 reinterpret_cast<content::JpegDecodeAcceleratorTestEnvironment*>( 567 testing::AddGlobalTestEnvironment(
583 testing::AddGlobalTestEnvironment( 568 new media::JpegDecodeAcceleratorTestEnvironment(jpeg_filenames)));
584 new content::JpegDecodeAcceleratorTestEnvironment(
585 jpeg_filenames)));
586 569
587 return RUN_ALL_TESTS(); 570 return RUN_ALL_TESTS();
588 } 571 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698