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> |
11 | 11 |
12 #include "base/android/build_info.h" | 12 #include "base/android/build_info.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/optional.h" | 15 #include "base/optional.h" |
16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
17 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
19 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
20 #include "base/time/tick_clock.h" | 20 #include "base/time/tick_clock.h" |
21 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
| 22 #include "media/base/android/android_overlay.h" |
22 #include "media/base/android/media_codec_bridge_impl.h" | 23 #include "media/base/android/media_codec_bridge_impl.h" |
23 #include "media/base/android/media_drm_bridge_cdm_context.h" | 24 #include "media/base/android/media_drm_bridge_cdm_context.h" |
24 #include "media/base/media.h" | 25 #include "media/base/media.h" |
25 #include "media/base/surface_manager.h" | 26 #include "media/base/surface_manager.h" |
26 #include "media/base/video_codecs.h" | 27 #include "media/base/video_codecs.h" |
27 #include "media/gpu/avda_surface_bundle.h" | 28 #include "media/gpu/avda_surface_bundle.h" |
28 #include "media/gpu/media_gpu_export.h" | 29 #include "media/gpu/media_gpu_export.h" |
29 #include "ui/gfx/geometry/size.h" | 30 #include "ui/gfx/geometry/size.h" |
30 #include "ui/gl/android/scoped_java_surface.h" | 31 #include "ui/gl/android/scoped_java_surface.h" |
31 | 32 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 std::vector<uint8_t> csd1; | 74 std::vector<uint8_t> csd1; |
74 | 75 |
75 protected: | 76 protected: |
76 friend class base::RefCountedThreadSafe<CodecConfig>; | 77 friend class base::RefCountedThreadSafe<CodecConfig>; |
77 virtual ~CodecConfig(); | 78 virtual ~CodecConfig(); |
78 | 79 |
79 private: | 80 private: |
80 DISALLOW_COPY_AND_ASSIGN(CodecConfig); | 81 DISALLOW_COPY_AND_ASSIGN(CodecConfig); |
81 }; | 82 }; |
82 | 83 |
83 class AVDACodecAllocatorClient { | 84 class AVDASurfaceAllocatorClient { |
84 public: | 85 public: |
85 // Called when the requested SurfaceView becomes available after a call to | 86 // Called when the requested SurfaceView becomes available after a call to |
86 // AllocateSurface() | 87 // AllocateSurface() |
87 virtual void OnSurfaceAvailable(bool success) = 0; | 88 virtual void OnSurfaceAvailable(bool success) = 0; |
88 | 89 |
89 // Called when the allocated surface is being destroyed. This must either | 90 // Called when the allocated surface is being destroyed. This must either |
90 // replace the surface with MediaCodec#setSurface, or release the MediaCodec | 91 // replace the surface with MediaCodec#setSurface, or release the MediaCodec |
91 // it's attached to. The client no longer owns the surface and doesn't | 92 // it's attached to. The client no longer owns the surface and doesn't |
92 // need to call DeallocateSurface(); | 93 // need to call DeallocateSurface(); |
93 virtual void OnSurfaceDestroyed() = 0; | 94 virtual void OnSurfaceDestroyed() = 0; |
94 | 95 |
| 96 protected: |
| 97 ~AVDASurfaceAllocatorClient() {} |
| 98 }; |
| 99 |
| 100 class AVDACodecAllocatorClient { |
| 101 public: |
95 // Called on the main thread when a new MediaCodec is configured. | 102 // Called on the main thread when a new MediaCodec is configured. |
96 // |media_codec| will be null if configuration failed. | 103 // |media_codec| will be null if configuration failed. |
97 virtual void OnCodecConfigured( | 104 virtual void OnCodecConfigured( |
98 std::unique_ptr<MediaCodecBridge> media_codec) = 0; | 105 std::unique_ptr<MediaCodecBridge> media_codec) = 0; |
99 | 106 |
100 protected: | 107 protected: |
101 ~AVDACodecAllocatorClient() {} | 108 ~AVDACodecAllocatorClient() {} |
102 }; | 109 }; |
103 | 110 |
104 // AVDACodecAllocator manages threads for allocating and releasing MediaCodec | 111 // AVDACodecAllocator manages threads for allocating and releasing MediaCodec |
(...skipping 10 matching lines...) Expand all Loading... |
115 | 122 |
116 // Make sure the construction threads are started for |client|. Returns true | 123 // Make sure the construction threads are started for |client|. Returns true |
117 // on success. | 124 // on success. |
118 bool StartThread(AVDACodecAllocatorClient* client); | 125 bool StartThread(AVDACodecAllocatorClient* client); |
119 | 126 |
120 void StopThread(AVDACodecAllocatorClient* client); | 127 void StopThread(AVDACodecAllocatorClient* client); |
121 | 128 |
122 // Returns true if the caller now owns the surface, or false if someone else | 129 // Returns true if the caller now owns the surface, or false if someone else |
123 // owns the surface. |client| will be notified when the surface is available | 130 // owns the surface. |client| will be notified when the surface is available |
124 // via OnSurfaceAvailable(). | 131 // via OnSurfaceAvailable(). |
125 bool AllocateSurface(AVDACodecAllocatorClient* client, int surface_id); | 132 bool AllocateSurface(AVDASurfaceAllocatorClient* client, int surface_id); |
126 | 133 |
127 // Relinquish ownership of the surface or stop waiting for it to be available. | 134 // Relinquish ownership of the surface or stop waiting for it to be available. |
128 // The caller must guarantee that when calling this the surface is either no | 135 // The caller must guarantee that when calling this the surface is either no |
129 // longer attached to a MediaCodec, or the MediaCodec it was attached to is | 136 // longer attached to a MediaCodec, or the MediaCodec it was attached to is |
130 // was released with ReleaseMediaCodec(). | 137 // was released with ReleaseMediaCodec(). |
131 void DeallocateSurface(AVDACodecAllocatorClient* client, int surface_id); | 138 void DeallocateSurface(AVDASurfaceAllocatorClient* client, int surface_id); |
132 | 139 |
133 // Create and configure a MediaCodec synchronously. | 140 // Create and configure a MediaCodec synchronously. |
134 std::unique_ptr<MediaCodecBridge> CreateMediaCodecSync( | 141 std::unique_ptr<MediaCodecBridge> CreateMediaCodecSync( |
135 scoped_refptr<CodecConfig> codec_config); | 142 scoped_refptr<CodecConfig> codec_config); |
136 | 143 |
137 // Create and configure a MediaCodec asynchronously. The result is delivered | 144 // Create and configure a MediaCodec asynchronously. The result is delivered |
138 // via OnCodecConfigured(). | 145 // via OnCodecConfigured(). |
139 virtual void CreateMediaCodecAsync( | 146 virtual void CreateMediaCodecAsync( |
140 base::WeakPtr<AVDACodecAllocatorClient> client, | 147 base::WeakPtr<AVDACodecAllocatorClient> client, |
141 scoped_refptr<CodecConfig> codec_config); | 148 scoped_refptr<CodecConfig> codec_config); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // then drop our ref to |surface_bundle|. | 190 // then drop our ref to |surface_bundle|. |
184 void ForwardOrDropCodec(base::WeakPtr<AVDACodecAllocatorClient> client, | 191 void ForwardOrDropCodec(base::WeakPtr<AVDACodecAllocatorClient> client, |
185 TaskType task_type, | 192 TaskType task_type, |
186 scoped_refptr<AVDASurfaceBundle> surface_bundle, | 193 scoped_refptr<AVDASurfaceBundle> surface_bundle, |
187 std::unique_ptr<MediaCodecBridge> media_codec); | 194 std::unique_ptr<MediaCodecBridge> media_codec); |
188 | 195 |
189 private: | 196 private: |
190 friend class AVDACodecAllocatorTest; | 197 friend class AVDACodecAllocatorTest; |
191 | 198 |
192 struct OwnerRecord { | 199 struct OwnerRecord { |
193 AVDACodecAllocatorClient* owner = nullptr; | 200 AVDASurfaceAllocatorClient* owner = nullptr; |
194 AVDACodecAllocatorClient* waiter = nullptr; | 201 AVDASurfaceAllocatorClient* waiter = nullptr; |
195 }; | 202 }; |
196 | 203 |
197 class HangDetector : public base::MessageLoop::TaskObserver { | 204 class HangDetector : public base::MessageLoop::TaskObserver { |
198 public: | 205 public: |
199 HangDetector(base::TickClock* tick_clock); | 206 HangDetector(base::TickClock* tick_clock); |
200 void WillProcessTask(const base::PendingTask& pending_task) override; | 207 void WillProcessTask(const base::PendingTask& pending_task) override; |
201 void DidProcessTask(const base::PendingTask& pending_task) override; | 208 void DidProcessTask(const base::PendingTask& pending_task) override; |
202 bool IsThreadLikelyHung(); | 209 bool IsThreadLikelyHung(); |
203 | 210 |
204 private: | 211 private: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 255 |
249 // For canceling pending StopThreadTask()s. | 256 // For canceling pending StopThreadTask()s. |
250 base::WeakPtrFactory<AVDACodecAllocator> weak_this_factory_; | 257 base::WeakPtrFactory<AVDACodecAllocator> weak_this_factory_; |
251 | 258 |
252 DISALLOW_COPY_AND_ASSIGN(AVDACodecAllocator); | 259 DISALLOW_COPY_AND_ASSIGN(AVDACodecAllocator); |
253 }; | 260 }; |
254 | 261 |
255 } // namespace media | 262 } // namespace media |
256 | 263 |
257 #endif // MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_ | 264 #endif // MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_ |
OLD | NEW |