| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // longer attached to a MediaCodec, or the MediaCodec it was attached to is | 133 // longer attached to a MediaCodec, or the MediaCodec it was attached to is |
| 134 // was released with ReleaseMediaCodec(). | 134 // was released with ReleaseMediaCodec(). |
| 135 void DeallocateSurface(AVDACodecAllocatorClient* client, int surface_id); | 135 void DeallocateSurface(AVDACodecAllocatorClient* client, int surface_id); |
| 136 | 136 |
| 137 // Create and configure a MediaCodec synchronously. | 137 // Create and configure a MediaCodec synchronously. |
| 138 std::unique_ptr<VideoCodecBridge> CreateMediaCodecSync( | 138 std::unique_ptr<VideoCodecBridge> CreateMediaCodecSync( |
| 139 scoped_refptr<CodecConfig> codec_config); | 139 scoped_refptr<CodecConfig> codec_config); |
| 140 | 140 |
| 141 // Create and configure a MediaCodec asynchronously. The result is delivered | 141 // Create and configure a MediaCodec asynchronously. The result is delivered |
| 142 // via OnCodecConfigured(). | 142 // via OnCodecConfigured(). |
| 143 void CreateMediaCodecAsync(base::WeakPtr<AVDACodecAllocatorClient> client, | 143 virtual void CreateMediaCodecAsync( |
| 144 scoped_refptr<CodecConfig> codec_config); | 144 base::WeakPtr<AVDACodecAllocatorClient> client, |
| 145 scoped_refptr<CodecConfig> codec_config); |
| 145 | 146 |
| 146 // Asynchronously release |media_codec| with the attached surface. | 147 // Asynchronously release |media_codec| with the attached surface. |
| 147 // TODO(watk): Bundle the MediaCodec and surface together so you can't get | 148 // TODO(watk): Bundle the MediaCodec and surface together so you can't get |
| 148 // this pairing wrong. | 149 // this pairing wrong. |
| 149 void ReleaseMediaCodec(std::unique_ptr<VideoCodecBridge> media_codec, | 150 void ReleaseMediaCodec(std::unique_ptr<VideoCodecBridge> media_codec, |
| 150 TaskType task_type, | 151 TaskType task_type, |
| 151 int surface_id); | 152 int surface_id); |
| 152 | 153 |
| 153 // Returns a hint about whether the construction thread has hung for | 154 // Returns a hint about whether the construction thread has hung for |
| 154 // |task_type|. Note that if a thread isn't started, then we'll just return | 155 // |task_type|. Note that if a thread isn't started, then we'll just return |
| 155 // "not hung", since it'll run on the current thread anyway. The hang | 156 // "not hung", since it'll run on the current thread anyway. The hang |
| 156 // detector will see no pending jobs in that case, so it's automatic. | 157 // detector will see no pending jobs in that case, so it's automatic. |
| 157 bool IsThreadLikelyHung(TaskType task_type); | 158 bool IsThreadLikelyHung(TaskType task_type); |
| 158 | 159 |
| 159 // Return true if and only if there is any AVDA registered. | 160 // Return true if and only if there is any AVDA registered. |
| 160 bool IsAnyRegisteredAVDA(); | 161 bool IsAnyRegisteredAVDA(); |
| 161 | 162 |
| 162 // Return the task type to use for a new codec allocation, or nullopt if | 163 // Return the task type to use for a new codec allocation, or nullopt if |
| 163 // both threads are hung. | 164 // both threads are hung. |
| 164 base::Optional<TaskType> TaskTypeForAllocation(); | 165 base::Optional<TaskType> TaskTypeForAllocation(); |
| 165 | 166 |
| 166 // Return the task runner for tasks of type |type|. | 167 // Return the task runner for tasks of type |type|. |
| 167 scoped_refptr<base::SingleThreadTaskRunner> TaskRunnerFor(TaskType task_type); | 168 scoped_refptr<base::SingleThreadTaskRunner> TaskRunnerFor(TaskType task_type); |
| 168 | 169 |
| 169 // Return a reference to the thread for unit tests. | 170 // Return a reference to the thread for unit tests. |
| 170 base::Thread& GetThreadForTesting(TaskType task_type); | 171 base::Thread& GetThreadForTesting(TaskType task_type); |
| 171 | 172 |
| 173 protected: |
| 174 // |tick_clock| and |stop_event| are for tests only. |
| 175 AVDACodecAllocator(base::TickClock* tick_clock = nullptr, |
| 176 base::WaitableEvent* stop_event = nullptr); |
| 177 virtual ~AVDACodecAllocator(); |
| 178 |
| 172 private: | 179 private: |
| 173 friend class AVDACodecAllocatorTest; | 180 friend class AVDACodecAllocatorTest; |
| 174 | 181 |
| 175 struct OwnerRecord { | 182 struct OwnerRecord { |
| 176 AVDACodecAllocatorClient* owner = nullptr; | 183 AVDACodecAllocatorClient* owner = nullptr; |
| 177 AVDACodecAllocatorClient* waiter = nullptr; | 184 AVDACodecAllocatorClient* waiter = nullptr; |
| 178 }; | 185 }; |
| 179 | 186 |
| 180 class HangDetector : public base::MessageLoop::TaskObserver { | 187 class HangDetector : public base::MessageLoop::TaskObserver { |
| 181 public: | 188 public: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 196 }; | 203 }; |
| 197 | 204 |
| 198 // Handy combination of a thread and hang detector for it. | 205 // Handy combination of a thread and hang detector for it. |
| 199 struct ThreadAndHangDetector { | 206 struct ThreadAndHangDetector { |
| 200 ThreadAndHangDetector(const std::string& name, base::TickClock* tick_clock) | 207 ThreadAndHangDetector(const std::string& name, base::TickClock* tick_clock) |
| 201 : thread(name), hang_detector(tick_clock) {} | 208 : thread(name), hang_detector(tick_clock) {} |
| 202 base::Thread thread; | 209 base::Thread thread; |
| 203 HangDetector hang_detector; | 210 HangDetector hang_detector; |
| 204 }; | 211 }; |
| 205 | 212 |
| 206 // |tick_clock| and |stop_event| are for tests only. | |
| 207 AVDACodecAllocator(base::TickClock* tick_clock = nullptr, | |
| 208 base::WaitableEvent* stop_event = nullptr); | |
| 209 ~AVDACodecAllocator(); | |
| 210 | |
| 211 void OnMediaCodecAndSurfaceReleased(int surface_id); | 213 void OnMediaCodecAndSurfaceReleased(int surface_id); |
| 212 | 214 |
| 213 // Stop the thread indicated by |index|. This signals stop_event_for_testing_ | 215 // Stop the thread indicated by |index|. This signals stop_event_for_testing_ |
| 214 // after both threads are stopped. | 216 // after both threads are stopped. |
| 215 void StopThreadTask(size_t index); | 217 void StopThreadTask(size_t index); |
| 216 | 218 |
| 217 // All registered AVDAs. | 219 // All registered AVDAs. |
| 218 std::set<AVDACodecAllocatorClient*> clients_; | 220 std::set<AVDACodecAllocatorClient*> clients_; |
| 219 | 221 |
| 220 // Indexed by surface id. | 222 // Indexed by surface id. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 234 | 236 |
| 235 // For canceling pending StopThreadTask()s. | 237 // For canceling pending StopThreadTask()s. |
| 236 base::WeakPtrFactory<AVDACodecAllocator> weak_this_factory_; | 238 base::WeakPtrFactory<AVDACodecAllocator> weak_this_factory_; |
| 237 | 239 |
| 238 DISALLOW_COPY_AND_ASSIGN(AVDACodecAllocator); | 240 DISALLOW_COPY_AND_ASSIGN(AVDACodecAllocator); |
| 239 }; | 241 }; |
| 240 | 242 |
| 241 } // namespace media | 243 } // namespace media |
| 242 | 244 |
| 243 #endif // MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_ | 245 #endif // MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_ |
| OLD | NEW |