| 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 #ifndef MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_ |    5 #ifndef MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_ | 
|    6 #define MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_ |    6 #define MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_ | 
|    7  |    7  | 
|    8 #include <stddef.h> |    8 #include <stddef.h> | 
|    9  |    9  | 
|   10 #include <memory> |   10 #include <memory> | 
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  170   // there is no thread that can support it. |  170   // there is no thread that can support it. | 
|  171   TaskType TaskTypeForAllocation(); |  171   TaskType TaskTypeForAllocation(); | 
|  172  |  172  | 
|  173   // Return a reference to the thread for unit tests. |  173   // Return a reference to the thread for unit tests. | 
|  174   base::Thread& GetThreadForTesting(TaskType task_type); |  174   base::Thread& GetThreadForTesting(TaskType task_type); | 
|  175  |  175  | 
|  176  private: |  176  private: | 
|  177   friend struct base::DefaultLazyInstanceTraits<AVDACodecAllocator>; |  177   friend struct base::DefaultLazyInstanceTraits<AVDACodecAllocator>; | 
|  178   friend class AVDACodecAllocatorTest; |  178   friend class AVDACodecAllocatorTest; | 
|  179  |  179  | 
|  180   // Things that our unit test needs.  We guarantee that we'll access none of |  | 
|  181   // it, from any thread, after we are destructed. |  | 
|  182   struct TestInformation { |  | 
|  183     TestInformation(); |  | 
|  184     ~TestInformation(); |  | 
|  185     // Optional clock source. |  | 
|  186     std::unique_ptr<base::TickClock> tick_clock_; |  | 
|  187  |  | 
|  188     // Optional event that we'll signal when stopping the AUTO_CODEC thread. |  | 
|  189     std::unique_ptr<base::WaitableEvent> stop_event_; |  | 
|  190   }; |  | 
|  191  |  | 
|  192   struct OwnerRecord { |  180   struct OwnerRecord { | 
|  193     AVDACodecAllocatorClient* owner = nullptr; |  181     AVDACodecAllocatorClient* owner = nullptr; | 
|  194     AVDACodecAllocatorClient* waiter = nullptr; |  182     AVDACodecAllocatorClient* waiter = nullptr; | 
|  195   }; |  183   }; | 
|  196  |  184  | 
|  197   class HangDetector : public base::MessageLoop::TaskObserver { |  185   class HangDetector : public base::MessageLoop::TaskObserver { | 
|  198    public: |  186    public: | 
|  199     HangDetector(base::TickClock* tick_clock); |  187     HangDetector(base::TickClock* tick_clock); | 
|  200     void WillProcessTask(const base::PendingTask& pending_task) override; |  188     void WillProcessTask(const base::PendingTask& pending_task) override; | 
|  201     void DidProcessTask(const base::PendingTask& pending_task) override; |  189     void DidProcessTask(const base::PendingTask& pending_task) override; | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|  213   }; |  201   }; | 
|  214  |  202  | 
|  215   // Handy combination of a thread and hang detector for it. |  203   // Handy combination of a thread and hang detector for it. | 
|  216   struct ThreadAndHangDetector { |  204   struct ThreadAndHangDetector { | 
|  217     ThreadAndHangDetector(const std::string& name, base::TickClock* tick_clock) |  205     ThreadAndHangDetector(const std::string& name, base::TickClock* tick_clock) | 
|  218         : thread(name), hang_detector(tick_clock) {} |  206         : thread(name), hang_detector(tick_clock) {} | 
|  219     base::Thread thread; |  207     base::Thread thread; | 
|  220     HangDetector hang_detector; |  208     HangDetector hang_detector; | 
|  221   }; |  209   }; | 
|  222  |  210  | 
|  223   // |test_info| is owned by the unit test. |  211   // |tick_clock| and |stop_event| are for tests only. | 
|  224   AVDACodecAllocator(TestInformation* test_info = nullptr); |  212   AVDACodecAllocator(base::TickClock* tick_clock = nullptr, | 
 |  213                      base::WaitableEvent* stop_event = nullptr); | 
|  225   ~AVDACodecAllocator(); |  214   ~AVDACodecAllocator(); | 
|  226  |  215  | 
|  227   void OnMediaCodecAndSurfaceReleased(int surface_id); |  216   void OnMediaCodecAndSurfaceReleased(int surface_id); | 
|  228  |  217  | 
|  229   // Stop the thread indicated by |index|, then signal |event| if provided. |  218   // Stop the thread indicated by |index|, then signal |event| if provided. | 
|  230   void StopThreadTask(size_t index, base::WaitableEvent* event = nullptr); |  219   void StopThreadTask(size_t index, base::WaitableEvent* event = nullptr); | 
|  231  |  220  | 
|  232   // All registered AVDAs. |  221   // All registered AVDAs. | 
|  233   std::set<AVDACodecAllocatorClient*> clients_; |  222   std::set<AVDACodecAllocatorClient*> clients_; | 
|  234  |  223  | 
|  235   // Indexed by surface id. |  224   // Indexed by surface id. | 
|  236   std::map<int32_t, OwnerRecord> surface_owners_; |  225   std::map<int32_t, OwnerRecord> surface_owners_; | 
|  237  |  226  | 
|  238   // Waitable events for ongoing release tasks indexed by surface id so we can |  227   // Waitable events for ongoing release tasks indexed by surface id so we can | 
|  239   // wait on the codec release if the surface attached to it is being destroyed. |  228   // wait on the codec release if the surface attached to it is being destroyed. | 
|  240   std::map<int32_t, base::WaitableEvent> pending_codec_releases_; |  229   std::map<int32_t, base::WaitableEvent> pending_codec_releases_; | 
|  241  |  230  | 
|  242   // Threads for each of TaskType.  They are started / stopped as avda instances |  231   // Threads for each of TaskType.  They are started / stopped as avda instances | 
|  243   // show and and request them.  The vector indicies must match TaskType. |  232   // show and and request them.  The vector indicies must match TaskType. | 
|  244   std::vector<ThreadAndHangDetector*> threads_; |  233   std::vector<ThreadAndHangDetector*> threads_; | 
|  245  |  234  | 
|  246   base::ThreadChecker thread_checker_; |  235   base::ThreadChecker thread_checker_; | 
|  247  |  236  | 
|  248   // Optional, used for unit testing.  We do not own this. |  237   base::WaitableEvent* stop_event_for_testing_; | 
|  249   TestInformation* test_info_; |  | 
|  250  |  238  | 
|  251   // For canceling pending StopThreadTask()s. |  239   // For canceling pending StopThreadTask()s. | 
|  252   base::WeakPtrFactory<AVDACodecAllocator> weak_this_factory_; |  240   base::WeakPtrFactory<AVDACodecAllocator> weak_this_factory_; | 
|  253  |  241  | 
|  254   DISALLOW_COPY_AND_ASSIGN(AVDACodecAllocator); |  242   DISALLOW_COPY_AND_ASSIGN(AVDACodecAllocator); | 
|  255 }; |  243 }; | 
|  256  |  244  | 
|  257 }  // namespace media |  245 }  // namespace media | 
|  258  |  246  | 
|  259 #endif  // MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_ |  247 #endif  // MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_ | 
| OLD | NEW |