Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: media/gpu/avda_codec_allocator.h

Issue 2629223003: media: Ensure MediaCodecs are released before attached SurfaceTextures (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 #include "base/time/tick_clock.h" 21 #include "base/time/tick_clock.h"
22 #include "base/trace_event/trace_event.h" 22 #include "base/trace_event/trace_event.h"
23 #include "media/base/android/media_drm_bridge_cdm_context.h" 23 #include "media/base/android/media_drm_bridge_cdm_context.h"
24 #include "media/base/android/sdk_media_codec_bridge.h" 24 #include "media/base/android/sdk_media_codec_bridge.h"
25 #include "media/base/media.h" 25 #include "media/base/media.h"
26 #include "media/base/surface_manager.h" 26 #include "media/base/surface_manager.h"
27 #include "media/base/video_codecs.h" 27 #include "media/base/video_codecs.h"
28 #include "media/gpu/media_gpu_export.h" 28 #include "media/gpu/media_gpu_export.h"
29 #include "ui/gfx/geometry/size.h" 29 #include "ui/gfx/geometry/size.h"
30 #include "ui/gl/android/scoped_java_surface.h" 30 #include "ui/gl/android/scoped_java_surface.h"
31 #include "ui/gl/android/surface_texture.h"
31 32
32 namespace media { 33 namespace media {
33 34
34 // For TaskRunnerFor. These are used as vector indices, so please update 35 // For TaskRunnerFor. These are used as vector indices, so please update
35 // AVDACodecAllocator's constructor if you add / change them. 36 // AVDACodecAllocator's constructor if you add / change them.
36 enum TaskType { 37 enum TaskType {
37 // Task for an autodetected MediaCodec instance. 38 // Task for an autodetected MediaCodec instance.
38 AUTO_CODEC = 0, 39 AUTO_CODEC = 0,
39 40
40 // Task for a software-codec-required MediaCodec. 41 // Task for a software-codec-required MediaCodec.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 134
134 // Create and configure a MediaCodec synchronously. 135 // Create and configure a MediaCodec synchronously.
135 std::unique_ptr<VideoCodecBridge> CreateMediaCodecSync( 136 std::unique_ptr<VideoCodecBridge> CreateMediaCodecSync(
136 scoped_refptr<CodecConfig> codec_config); 137 scoped_refptr<CodecConfig> codec_config);
137 138
138 // Create and configure a MediaCodec asynchronously. The result is delivered 139 // Create and configure a MediaCodec asynchronously. The result is delivered
139 // via OnCodecConfigured(). 140 // via OnCodecConfigured().
140 void CreateMediaCodecAsync(base::WeakPtr<AVDACodecAllocatorClient> client, 141 void CreateMediaCodecAsync(base::WeakPtr<AVDACodecAllocatorClient> client,
141 scoped_refptr<CodecConfig> codec_config); 142 scoped_refptr<CodecConfig> codec_config);
142 143
143 // Asynchronously release |media_codec| with the attached surface. 144 // Asynchronously release |media_codec| with the attached surface. If a
145 // SurfaceView is attached to the codec, the release is tracked so that
146 // OnSurfaceDestroyed() can wait on it to complete. If a SurfaceTexture
147 // is attached to the codec, the release is tracked so that
148 // ReleaseSurfaceTexture() can arrange for the SurfaceTexture to be released
149 // after the codec.
liberato (no reviews please) 2017/01/13 17:22:04 that it's a raw ptr is a little subtle. might des
144 // TODO(watk): Bundle the MediaCodec and surface together so you can't get 150 // TODO(watk): Bundle the MediaCodec and surface together so you can't get
145 // this pairing wrong. 151 // this pairing wrong.
146 void ReleaseMediaCodec(std::unique_ptr<VideoCodecBridge> media_codec, 152 void ReleaseMediaCodec(std::unique_ptr<VideoCodecBridge> media_codec,
147 TaskType task_type, 153 TaskType task_type,
148 int surface_id); 154 int surface_id,
155 gl::SurfaceTexture* surface_texture);
156
157 // Call |surface_texture|->ReleaseSurfaceTexture() after the MediaCodec it's
158 // attached to is released. This should always be called after
159 // ReleaseMediaCodec().
160 void ReleaseSurfaceTexture(scoped_refptr<gl::SurfaceTexture> surface_texture);
149 161
150 // Returns a hint about whether the construction thread has hung for 162 // Returns a hint about whether the construction thread has hung for
151 // |task_type|. Note that if a thread isn't started, then we'll just return 163 // |task_type|. Note that if a thread isn't started, then we'll just return
152 // "not hung", since it'll run on the current thread anyway. The hang 164 // "not hung", since it'll run on the current thread anyway. The hang
153 // detector will see no pending jobs in that case, so it's automatic. 165 // detector will see no pending jobs in that case, so it's automatic.
154 bool IsThreadLikelyHung(TaskType task_type); 166 bool IsThreadLikelyHung(TaskType task_type);
155 167
156 // Return true if and only if there is any AVDA registered. 168 // Return true if and only if there is any AVDA registered.
157 bool IsAnyRegisteredAVDA(); 169 bool IsAnyRegisteredAVDA();
158 170
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 }; 211 };
200 212
201 // |tick_clock| and |stop_event| are for tests only. 213 // |tick_clock| and |stop_event| are for tests only.
202 AVDACodecAllocator(base::TickClock* tick_clock = nullptr, 214 AVDACodecAllocator(base::TickClock* tick_clock = nullptr,
203 base::WaitableEvent* stop_event = nullptr); 215 base::WaitableEvent* stop_event = nullptr);
204 ~AVDACodecAllocator(); 216 ~AVDACodecAllocator();
205 217
206 // Return the task runner for tasks of type |type|. 218 // Return the task runner for tasks of type |type|.
207 scoped_refptr<base::SingleThreadTaskRunner> TaskRunnerFor(TaskType task_type); 219 scoped_refptr<base::SingleThreadTaskRunner> TaskRunnerFor(TaskType task_type);
208 220
209 void OnMediaCodecAndSurfaceReleased(int surface_id); 221 void OnMediaCodecReleased(int surface_id,
222 gl::SurfaceTexture* surface_texture);
210 223
211 // Stop the thread indicated by |index|. This signals stop_event_for_testing_ 224 // Stop the thread indicated by |index|. This signals stop_event_for_testing_
212 // after both threads are stopped. 225 // after both threads are stopped.
213 void StopThreadTask(size_t index); 226 void StopThreadTask(size_t index);
214 227
215 // All registered AVDAs. 228 // All registered AVDAs.
216 std::set<AVDACodecAllocatorClient*> clients_; 229 std::set<AVDACodecAllocatorClient*> clients_;
217 230
218 // Indexed by surface id. 231 // Indexed by surface id.
219 std::map<int32_t, OwnerRecord> surface_owners_; 232 std::map<int32_t, OwnerRecord> surface_owners_;
220 233
221 // Waitable events for ongoing release tasks indexed by surface id so we can 234 // Waitable events for ongoing releases of codecs with attached SurfaceViews,
222 // wait on the codec release if the surface attached to it is being destroyed. 235 // indexed by surface id. For waiting on the codec release if the surface is
223 std::map<int32_t, base::WaitableEvent> pending_codec_releases_; 236 // being destroyed.
237 std::map<int32_t, base::WaitableEvent> surface_view_codec_releases_;
238
239 // TaskTypes of ongoing releases of codecs with attached SurfaceTextures, For
240 // deferring SurfaceTexture release until after the codec release.
241 std::map<gl::SurfaceTexture*, TaskType> surface_texture_codec_releases_;
224 242
225 // Threads for each of TaskType. They are started / stopped as avda instances 243 // Threads for each of TaskType. They are started / stopped as avda instances
226 // show and and request them. The vector indicies must match TaskType. 244 // show and and request them. The vector indicies must match TaskType.
227 std::vector<ThreadAndHangDetector*> threads_; 245 std::vector<ThreadAndHangDetector*> threads_;
228 246
229 base::ThreadChecker thread_checker_; 247 base::ThreadChecker thread_checker_;
230 248
231 base::WaitableEvent* stop_event_for_testing_; 249 base::WaitableEvent* stop_event_for_testing_;
232 250
233 // For canceling pending StopThreadTask()s. 251 // For canceling pending StopThreadTask()s.
234 base::WeakPtrFactory<AVDACodecAllocator> weak_this_factory_; 252 base::WeakPtrFactory<AVDACodecAllocator> weak_this_factory_;
235 253
236 DISALLOW_COPY_AND_ASSIGN(AVDACodecAllocator); 254 DISALLOW_COPY_AND_ASSIGN(AVDACodecAllocator);
237 }; 255 };
238 256
239 } // namespace media 257 } // namespace media
240 258
241 #endif // MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_ 259 #endif // MEDIA_GPU_AVDA_CODEC_ALLOCATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698