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

Side by Side Diff: media/filters/vpx_video_decoder.cc

Issue 2668813002: Remove LazyInstance usage from media/ (Closed)
Patch Set: Fix presubmit comments. Created 3 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
« no previous file with comments | « media/filters/ffmpeg_glue.cc ('k') | media/gpu/android_video_decode_accelerator.cc » ('j') | 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 #include "media/filters/vpx_video_decoder.h" 5 #include "media/filters/vpx_video_decoder.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/callback_helpers.h" 16 #include "base/callback_helpers.h"
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/lazy_instance.h"
19 #include "base/location.h" 18 #include "base/location.h"
20 #include "base/logging.h" 19 #include "base/logging.h"
21 #include "base/macros.h" 20 #include "base/macros.h"
22 #include "base/memory/ptr_util.h" 21 #include "base/memory/ptr_util.h"
23 #include "base/metrics/histogram_macros.h" 22 #include "base/metrics/histogram_macros.h"
24 #include "base/single_thread_task_runner.h" 23 #include "base/single_thread_task_runner.h"
25 #include "base/strings/string_number_conversions.h" 24 #include "base/strings/string_number_conversions.h"
26 #include "base/sys_byteorder.h" 25 #include "base/sys_byteorder.h"
27 #include "base/sys_info.h" 26 #include "base/sys_info.h"
28 #include "base/threading/thread.h" 27 #include "base/threading/thread.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 offload_thread_.Stop(); 103 offload_thread_.Stop();
105 } 104 }
106 105
107 int offload_thread_users_ = 0; 106 int offload_thread_users_ = 0;
108 base::Thread offload_thread_; 107 base::Thread offload_thread_;
109 base::ThreadChecker thread_checker_; 108 base::ThreadChecker thread_checker_;
110 109
111 DISALLOW_COPY_AND_ASSIGN(VpxOffloadThread); 110 DISALLOW_COPY_AND_ASSIGN(VpxOffloadThread);
112 }; 111 };
113 112
114 static base::LazyInstance<VpxOffloadThread>::Leaky g_vpx_offload_thread = 113 static VpxOffloadThread* GetOffloadThread() {
115 LAZY_INSTANCE_INITIALIZER; 114 static VpxOffloadThread* thread = new VpxOffloadThread();
115 return thread;
116 }
116 117
117 // Always try to use three threads for video decoding. There is little reason 118 // Always try to use three threads for video decoding. There is little reason
118 // not to since current day CPUs tend to be multi-core and we measured 119 // not to since current day CPUs tend to be multi-core and we measured
119 // performance benefits on older machines such as P4s with hyperthreading. 120 // performance benefits on older machines such as P4s with hyperthreading.
120 static const int kDecodeThreads = 2; 121 static const int kDecodeThreads = 2;
121 static const int kMaxDecodeThreads = 16; 122 static const int kMaxDecodeThreads = 16;
122 123
123 // Returns the number of threads. 124 // Returns the number of threads.
124 static int GetThreadCount(const VideoDecoderConfig& config) { 125 static int GetThreadCount(const VideoDecoderConfig& config) {
125 // Refer to http://crbug.com/93932 for tsan suppressions on decoding. 126 // Refer to http://crbug.com/93932 for tsan suppressions on decoding.
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 FROM_HERE, base::Bind(&VpxVideoDecoder::DecodeBuffer, 436 FROM_HERE, base::Bind(&VpxVideoDecoder::DecodeBuffer,
436 base::Unretained(this), buffer, bound_decode_cb)); 437 base::Unretained(this), buffer, bound_decode_cb));
437 } else { 438 } else {
438 DecodeBuffer(buffer, bound_decode_cb); 439 DecodeBuffer(buffer, bound_decode_cb);
439 } 440 }
440 } 441 }
441 442
442 void VpxVideoDecoder::Reset(const base::Closure& closure) { 443 void VpxVideoDecoder::Reset(const base::Closure& closure) {
443 DCHECK(thread_checker_.CalledOnValidThread()); 444 DCHECK(thread_checker_.CalledOnValidThread());
444 if (offload_task_runner_) 445 if (offload_task_runner_)
445 g_vpx_offload_thread.Pointer()->WaitForOutstandingTasks(); 446 GetOffloadThread()->WaitForOutstandingTasks();
446 447
447 state_ = kNormal; 448 state_ = kNormal;
448 // PostTask() to avoid calling |closure| inmediately. 449 // PostTask() to avoid calling |closure| inmediately.
449 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); 450 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure);
450 } 451 }
451 452
452 bool VpxVideoDecoder::ConfigureDecoder(const VideoDecoderConfig& config) { 453 bool VpxVideoDecoder::ConfigureDecoder(const VideoDecoderConfig& config) {
453 if (config.codec() != kCodecVP8 && config.codec() != kCodecVP9) 454 if (config.codec() != kCodecVP8 && config.codec() != kCodecVP9)
454 return false; 455 return false;
455 456
(...skipping 21 matching lines...) Expand all
477 // Configure VP9 to decode on our buffers to skip a data copy on 478 // Configure VP9 to decode on our buffers to skip a data copy on
478 // decoding. For YV12A-VP9, we use our buffers for the Y, U and V planes and 479 // decoding. For YV12A-VP9, we use our buffers for the Y, U and V planes and
479 // copy the A plane. 480 // copy the A plane.
480 if (config.codec() == kCodecVP9) { 481 if (config.codec() == kCodecVP9) {
481 DCHECK(vpx_codec_get_caps(vpx_codec_->iface) & 482 DCHECK(vpx_codec_get_caps(vpx_codec_->iface) &
482 VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER); 483 VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER);
483 484
484 // Move high resolution vp9 decodes off of the main media thread (otherwise 485 // Move high resolution vp9 decodes off of the main media thread (otherwise
485 // decode may block audio decoding, demuxing, and other control activities). 486 // decode may block audio decoding, demuxing, and other control activities).
486 if (config.coded_size().width() >= 1024) { 487 if (config.coded_size().width() >= 1024) {
487 offload_task_runner_ = 488 offload_task_runner_ = GetOffloadThread()->RequestOffloadThread();
488 g_vpx_offload_thread.Pointer()->RequestOffloadThread();
489 } 489 }
490 490
491 DCHECK(!memory_pool_); 491 DCHECK(!memory_pool_);
492 memory_pool_ = new MemoryPool(); 492 memory_pool_ = new MemoryPool();
493 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 493 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
494 memory_pool_.get(), "VpxVideoDecoder", 494 memory_pool_.get(), "VpxVideoDecoder",
495 base::ThreadTaskRunnerHandle::Get()); 495 base::ThreadTaskRunnerHandle::Get());
496 496
497 if (vpx_codec_set_frame_buffer_functions(vpx_codec_, 497 if (vpx_codec_set_frame_buffer_functions(vpx_codec_,
498 &MemoryPool::GetVP9FrameBuffer, 498 &MemoryPool::GetVP9FrameBuffer,
499 &MemoryPool::ReleaseVP9FrameBuffer, 499 &MemoryPool::ReleaseVP9FrameBuffer,
500 memory_pool_.get())) { 500 memory_pool_.get())) {
501 DLOG(ERROR) << "Failed to configure external buffers. " 501 DLOG(ERROR) << "Failed to configure external buffers. "
502 << vpx_codec_error(vpx_codec_); 502 << vpx_codec_error(vpx_codec_);
503 return false; 503 return false;
504 } 504 }
505 } 505 }
506 506
507 if (config.format() != PIXEL_FORMAT_YV12A) 507 if (config.format() != PIXEL_FORMAT_YV12A)
508 return true; 508 return true;
509 509
510 vpx_codec_alpha_ = InitializeVpxContext(vpx_codec_alpha_, config); 510 vpx_codec_alpha_ = InitializeVpxContext(vpx_codec_alpha_, config);
511 return !!vpx_codec_alpha_; 511 return !!vpx_codec_alpha_;
512 } 512 }
513 513
514 void VpxVideoDecoder::CloseDecoder() { 514 void VpxVideoDecoder::CloseDecoder() {
515 if (offload_task_runner_) { 515 if (offload_task_runner_) {
516 g_vpx_offload_thread.Pointer() 516 GetOffloadThread()->WaitForOutstandingTasksAndReleaseOffloadThread();
517 ->WaitForOutstandingTasksAndReleaseOffloadThread();
518 offload_task_runner_ = nullptr; 517 offload_task_runner_ = nullptr;
519 } 518 }
520 519
521 if (vpx_codec_) { 520 if (vpx_codec_) {
522 vpx_codec_destroy(vpx_codec_); 521 vpx_codec_destroy(vpx_codec_);
523 delete vpx_codec_; 522 delete vpx_codec_;
524 vpx_codec_ = nullptr; 523 vpx_codec_ = nullptr;
525 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 524 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
526 memory_pool_.get()); 525 memory_pool_.get());
527 memory_pool_ = nullptr; 526 memory_pool_ = nullptr;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 (*video_frame)->visible_data(VideoFrame::kUPlane), 846 (*video_frame)->visible_data(VideoFrame::kUPlane),
848 (*video_frame)->stride(VideoFrame::kUPlane), 847 (*video_frame)->stride(VideoFrame::kUPlane),
849 (*video_frame)->visible_data(VideoFrame::kVPlane), 848 (*video_frame)->visible_data(VideoFrame::kVPlane),
850 (*video_frame)->stride(VideoFrame::kVPlane), coded_size.width(), 849 (*video_frame)->stride(VideoFrame::kVPlane), coded_size.width(),
851 coded_size.height()); 850 coded_size.height());
852 851
853 return true; 852 return true;
854 } 853 }
855 854
856 } // namespace media 855 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_glue.cc ('k') | media/gpu/android_video_decode_accelerator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698