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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 // Called when the allocated surface is being destroyed. This must either | 93 // Called when the allocated surface is being destroyed. This must either |
94 // replace the surface with MediaCodec#setSurface, or release the MediaCodec | 94 // replace the surface with MediaCodec#setSurface, or release the MediaCodec |
95 // it's attached to. The client no longer owns the surface and doesn't | 95 // it's attached to. The client no longer owns the surface and doesn't |
96 // need to call DeallocateSurface(); | 96 // need to call DeallocateSurface(); |
97 virtual void OnSurfaceDestroyed() = 0; | 97 virtual void OnSurfaceDestroyed() = 0; |
98 | 98 |
99 // Called on the main thread when a new MediaCodec is configured. | 99 // Called on the main thread when a new MediaCodec is configured. |
100 // |media_codec| will be null if configuration failed. | 100 // |media_codec| will be null if configuration failed. |
101 virtual void OnCodecConfigured( | 101 virtual void OnCodecConfigured( |
102 std::unique_ptr<VideoCodecBridge> media_codec) = 0; | 102 std::unique_ptr<MediaCodecBridge> media_codec) = 0; |
103 | 103 |
104 protected: | 104 protected: |
105 ~AVDACodecAllocatorClient() {} | 105 ~AVDACodecAllocatorClient() {} |
106 }; | 106 }; |
107 | 107 |
108 // AVDACodecAllocator manages threads for allocating and releasing MediaCodec | 108 // AVDACodecAllocator manages threads for allocating and releasing MediaCodec |
109 // instances. These activities can hang, depending on android version, due | 109 // instances. These activities can hang, depending on android version, due |
110 // to mediaserver bugs. AVDACodecAllocator detects these cases, and reports | 110 // to mediaserver bugs. AVDACodecAllocator detects these cases, and reports |
111 // on them to allow software fallback if the HW path is hung up. | 111 // on them to allow software fallback if the HW path is hung up. |
112 class MEDIA_GPU_EXPORT AVDACodecAllocator { | 112 class MEDIA_GPU_EXPORT AVDACodecAllocator { |
(...skipping 15 matching lines...) Expand all Loading... |
128 // via OnSurfaceAvailable(). | 128 // via OnSurfaceAvailable(). |
129 bool AllocateSurface(AVDACodecAllocatorClient* client, int surface_id); | 129 bool AllocateSurface(AVDACodecAllocatorClient* client, int surface_id); |
130 | 130 |
131 // Relinquish ownership of the surface or stop waiting for it to be available. | 131 // Relinquish ownership of the surface or stop waiting for it to be available. |
132 // The caller must guarantee that when calling this the surface is either no | 132 // The caller must guarantee that when calling this the surface is either no |
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<MediaCodecBridge> 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 virtual void CreateMediaCodecAsync( | 143 virtual void CreateMediaCodecAsync( |
144 base::WeakPtr<AVDACodecAllocatorClient> client, | 144 base::WeakPtr<AVDACodecAllocatorClient> client, |
145 scoped_refptr<CodecConfig> codec_config); | 145 scoped_refptr<CodecConfig> codec_config); |
146 | 146 |
147 // Asynchronously release |media_codec| with the attached surface. | 147 // Asynchronously release |media_codec| with the attached surface. |
148 // 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 |
149 // this pairing wrong. | 149 // this pairing wrong. |
150 void ReleaseMediaCodec(std::unique_ptr<VideoCodecBridge> media_codec, | 150 void ReleaseMediaCodec(std::unique_ptr<MediaCodecBridge> media_codec, |
151 TaskType task_type, | 151 TaskType task_type, |
152 int surface_id); | 152 int surface_id); |
153 | 153 |
154 // Returns a hint about whether the construction thread has hung for | 154 // Returns a hint about whether the construction thread has hung for |
155 // |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 |
156 // "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 |
157 // 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. |
158 bool IsThreadLikelyHung(TaskType task_type); | 158 bool IsThreadLikelyHung(TaskType task_type); |
159 | 159 |
160 // Return true if and only if there is any AVDA registered. | 160 // Return true if and only if there is any AVDA registered. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 236 |
237 // For canceling pending StopThreadTask()s. | 237 // For canceling pending StopThreadTask()s. |
238 base::WeakPtrFactory<AVDACodecAllocator> weak_this_factory_; | 238 base::WeakPtrFactory<AVDACodecAllocator> weak_this_factory_; |
239 | 239 |
240 DISALLOW_COPY_AND_ASSIGN(AVDACodecAllocator); | 240 DISALLOW_COPY_AND_ASSIGN(AVDACodecAllocator); |
241 }; | 241 }; |
242 | 242 |
243 } // namespace media | 243 } // namespace media |
244 | 244 |
245 #endif // MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_ | 245 #endif // MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_ |
OLD | NEW |