| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/gpu/avda_codec_allocator.h" | 5 #include "media/gpu/avda_codec_allocator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 13 #include "base/task_runner_util.h" | 13 #include "base/task_runner_util.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "base/time/default_tick_clock.h" | 17 #include "base/time/default_tick_clock.h" |
| 18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 19 #include "media/base/android/sdk_media_codec_bridge.h" | 19 #include "media/base/android/sdk_media_codec_bridge.h" |
| 20 #include "media/base/limits.h" | 20 #include "media/base/limits.h" |
| 21 #include "media/base/media.h" | 21 #include "media/base/media.h" |
| 22 #include "media/base/timestamp_constants.h" | 22 #include "media/base/timestamp_constants.h" |
| 23 #include "media/gpu/android_video_decode_accelerator.h" | 23 #include "media/gpu/android_video_decode_accelerator.h" |
| 24 | 24 |
| 25 namespace media { | 25 namespace media { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 base::LazyInstance<AVDACodecAllocator>::Leaky g_avda_codec_allocator = | |
| 30 LAZY_INSTANCE_INITIALIZER; | |
| 31 | |
| 32 // Give tasks 800ms before considering them hung. MediaCodec.configure() calls | 29 // Give tasks 800ms before considering them hung. MediaCodec.configure() calls |
| 33 // typically take 100-200ms on a N5, so 800ms is expected to very rarely result | 30 // typically take 100-200ms on a N5, so 800ms is expected to very rarely result |
| 34 // in false positives. Also, false positives have low impact because we resume | 31 // in false positives. Also, false positives have low impact because we resume |
| 35 // using the thread when the task completes. | 32 // using the thread when the task completes. |
| 36 constexpr base::TimeDelta kHungTaskDetectionTimeout = | 33 constexpr base::TimeDelta kHungTaskDetectionTimeout = |
| 37 base::TimeDelta::FromMilliseconds(800); | 34 base::TimeDelta::FromMilliseconds(800); |
| 38 | 35 |
| 39 // Delete |codec| and signal |done_event| if it's not null. | 36 // Delete |codec| and signal |done_event| if it's not null. |
| 40 void DeleteMediaCodecAndSignal(std::unique_ptr<VideoCodecBridge> codec, | 37 void DeleteMediaCodecAndSignal(std::unique_ptr<VideoCodecBridge> codec, |
| 41 base::WaitableEvent* done_event) { | 38 base::WaitableEvent* done_event) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 68 base::AutoLock l(lock_); | 65 base::AutoLock l(lock_); |
| 69 if (task_start_time_.is_null()) | 66 if (task_start_time_.is_null()) |
| 70 return false; | 67 return false; |
| 71 | 68 |
| 72 return (tick_clock_->NowTicks() - task_start_time_) > | 69 return (tick_clock_->NowTicks() - task_start_time_) > |
| 73 kHungTaskDetectionTimeout; | 70 kHungTaskDetectionTimeout; |
| 74 } | 71 } |
| 75 | 72 |
| 76 // static | 73 // static |
| 77 AVDACodecAllocator* AVDACodecAllocator::Instance() { | 74 AVDACodecAllocator* AVDACodecAllocator::Instance() { |
| 78 return g_avda_codec_allocator.Pointer(); | 75 static AVDACodecAllocator* allocator = new AVDACodecAllocator(); |
| 76 return allocator; |
| 79 } | 77 } |
| 80 | 78 |
| 81 bool AVDACodecAllocator::StartThread(AVDACodecAllocatorClient* client) { | 79 bool AVDACodecAllocator::StartThread(AVDACodecAllocatorClient* client) { |
| 82 DCHECK(thread_checker_.CalledOnValidThread()); | 80 DCHECK(thread_checker_.CalledOnValidThread()); |
| 83 | 81 |
| 84 // Cancel any pending StopThreadTask()s because we need the threads now. | 82 // Cancel any pending StopThreadTask()s because we need the threads now. |
| 85 weak_this_factory_.InvalidateWeakPtrs(); | 83 weak_this_factory_.InvalidateWeakPtrs(); |
| 86 | 84 |
| 87 // Try to start the threads if they haven't been started. | 85 // Try to start the threads if they haven't been started. |
| 88 for (auto* thread : threads_) { | 86 for (auto* thread : threads_) { |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 void AVDACodecAllocator::StopThreadTask(size_t index) { | 358 void AVDACodecAllocator::StopThreadTask(size_t index) { |
| 361 threads_[index]->thread.Stop(); | 359 threads_[index]->thread.Stop(); |
| 362 // Signal the stop event after both threads are stopped. | 360 // Signal the stop event after both threads are stopped. |
| 363 if (stop_event_for_testing_ && !threads_[AUTO_CODEC]->thread.IsRunning() && | 361 if (stop_event_for_testing_ && !threads_[AUTO_CODEC]->thread.IsRunning() && |
| 364 !threads_[SW_CODEC]->thread.IsRunning()) { | 362 !threads_[SW_CODEC]->thread.IsRunning()) { |
| 365 stop_event_for_testing_->Signal(); | 363 stop_event_for_testing_->Signal(); |
| 366 } | 364 } |
| 367 } | 365 } |
| 368 | 366 |
| 369 } // namespace media | 367 } // namespace media |
| OLD | NEW |