| 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 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 } | 334 } |
| 335 | 335 |
| 336 base::Thread& AVDACodecAllocator::GetThreadForTesting(TaskType task_type) { | 336 base::Thread& AVDACodecAllocator::GetThreadForTesting(TaskType task_type) { |
| 337 return threads_[task_type]->thread; | 337 return threads_[task_type]->thread; |
| 338 } | 338 } |
| 339 | 339 |
| 340 AVDACodecAllocator::AVDACodecAllocator(base::TickClock* tick_clock, | 340 AVDACodecAllocator::AVDACodecAllocator(base::TickClock* tick_clock, |
| 341 base::WaitableEvent* stop_event) | 341 base::WaitableEvent* stop_event) |
| 342 : stop_event_for_testing_(stop_event), weak_this_factory_(this) { | 342 : stop_event_for_testing_(stop_event), weak_this_factory_(this) { |
| 343 // We leak the clock we create, but that's okay because we're a singleton. | 343 // We leak the clock we create, but that's okay because we're a singleton. |
| 344 auto clock = tick_clock ? tick_clock : new base::DefaultTickClock(); | 344 auto* clock = tick_clock ? tick_clock : new base::DefaultTickClock(); |
| 345 | 345 |
| 346 // Create threads with names and indices that match up with TaskType. | 346 // Create threads with names and indices that match up with TaskType. |
| 347 threads_.push_back(new ThreadAndHangDetector("AVDAAutoThread", clock)); | 347 threads_.push_back(new ThreadAndHangDetector("AVDAAutoThread", clock)); |
| 348 threads_.push_back(new ThreadAndHangDetector("AVDASWThread", clock)); | 348 threads_.push_back(new ThreadAndHangDetector("AVDASWThread", clock)); |
| 349 static_assert(AUTO_CODEC == 0 && SW_CODEC == 1, | 349 static_assert(AUTO_CODEC == 0 && SW_CODEC == 1, |
| 350 "TaskType values are not ordered correctly."); | 350 "TaskType values are not ordered correctly."); |
| 351 } | 351 } |
| 352 | 352 |
| 353 AVDACodecAllocator::~AVDACodecAllocator() { | 353 AVDACodecAllocator::~AVDACodecAllocator() { |
| 354 // Only tests should reach here. Shut down threads so that we guarantee that | 354 // Only tests should reach here. Shut down threads so that we guarantee that |
| 355 // nothing will use the threads. | 355 // nothing will use the threads. |
| 356 for (auto* thread : threads_) | 356 for (auto* thread : threads_) |
| 357 thread->thread.Stop(); | 357 thread->thread.Stop(); |
| 358 } | 358 } |
| 359 | 359 |
| 360 void AVDACodecAllocator::StopThreadTask(size_t index) { | 360 void AVDACodecAllocator::StopThreadTask(size_t index) { |
| 361 threads_[index]->thread.Stop(); | 361 threads_[index]->thread.Stop(); |
| 362 // Signal the stop event after both threads are stopped. | 362 // Signal the stop event after both threads are stopped. |
| 363 if (stop_event_for_testing_ && !threads_[AUTO_CODEC]->thread.IsRunning() && | 363 if (stop_event_for_testing_ && !threads_[AUTO_CODEC]->thread.IsRunning() && |
| 364 !threads_[SW_CODEC]->thread.IsRunning()) { | 364 !threads_[SW_CODEC]->thread.IsRunning()) { |
| 365 stop_event_for_testing_->Signal(); | 365 stop_event_for_testing_->Signal(); |
| 366 } | 366 } |
| 367 } | 367 } |
| 368 | 368 |
| 369 } // namespace media | 369 } // namespace media |
| OLD | NEW |