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 #include "media/gpu/avda_codec_allocator.h" | 5 #include "media/gpu/avda_codec_allocator.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
133 // Return the task runner for tasks of type |type|. | 133 // Return the task runner for tasks of type |type|. |
134 scoped_refptr<base::SingleThreadTaskRunner> AVDACodecAllocator::TaskRunnerFor( | 134 scoped_refptr<base::SingleThreadTaskRunner> AVDACodecAllocator::TaskRunnerFor( |
135 TaskType task_type) { | 135 TaskType task_type) { |
136 DCHECK(thread_checker_.CalledOnValidThread()); | 136 DCHECK(thread_checker_.CalledOnValidThread()); |
137 return threads_[task_type]->thread.task_runner(); | 137 return threads_[task_type]->thread.task_runner(); |
138 } | 138 } |
139 | 139 |
140 bool AVDACodecAllocator::AllocateSurface(AVDACodecAllocatorClient* client, | 140 bool AVDACodecAllocator::AllocateSurface(AVDASurfaceAllocatorClient* client, |
141 int surface_id) { | 141 int surface_id) { |
142 DVLOG(1) << __func__ << ": " << surface_id; | 142 DVLOG(1) << __func__ << ": " << surface_id; |
143 DCHECK(thread_checker_.CalledOnValidThread()); | 143 DCHECK(thread_checker_.CalledOnValidThread()); |
144 | 144 |
145 if (surface_id == SurfaceManager::kNoSurfaceID) | 145 if (surface_id == SurfaceManager::kNoSurfaceID) |
146 return true; | 146 return true; |
147 | 147 |
148 // If it's not owned or being released, |client| now owns it. | 148 // If it's not owned or being released, |client| now owns it. |
149 if (!surface_owners_.count(surface_id) && | 149 if (!surface_owners_.count(surface_id) && |
150 !pending_codec_releases_.count(surface_id)) { | 150 !pending_codec_releases_.count(surface_id)) { |
151 surface_owners_[surface_id].owner = client; | 151 surface_owners_[surface_id].owner = client; |
152 return true; | 152 return true; |
153 } | 153 } |
154 | 154 |
155 // Otherwise |client| replaces the previous waiter (if any). | 155 // Otherwise |client| replaces the previous waiter (if any). |
156 OwnerRecord& record = surface_owners_[surface_id]; | 156 OwnerRecord& record = surface_owners_[surface_id]; |
157 if (record.waiter) | 157 if (record.waiter) |
158 record.waiter->OnSurfaceAvailable(false); | 158 record.waiter->OnSurfaceAvailable(false); |
159 record.waiter = client; | 159 record.waiter = client; |
160 return false; | 160 return false; |
161 } | 161 } |
162 | 162 |
163 void AVDACodecAllocator::DeallocateSurface(AVDACodecAllocatorClient* client, | 163 void AVDACodecAllocator::DeallocateSurface(AVDASurfaceAllocatorClient* client, |
164 int surface_id) { | 164 int surface_id) { |
165 DCHECK(thread_checker_.CalledOnValidThread()); | 165 DCHECK(thread_checker_.CalledOnValidThread()); |
166 if (surface_id == SurfaceManager::kNoSurfaceID || | 166 if (surface_id == SurfaceManager::kNoSurfaceID || |
167 !surface_owners_.count(surface_id)) { | 167 !surface_owners_.count(surface_id)) { |
168 return; | 168 return; |
169 } | 169 } |
170 | 170 |
171 OwnerRecord& record = surface_owners_[surface_id]; | 171 OwnerRecord& record = surface_owners_[surface_id]; |
172 if (record.owner == client) | 172 if (record.owner == client) |
173 record.owner = nullptr; | 173 record.owner = nullptr; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 jobject media_crypto = | 241 jobject media_crypto = |
242 codec_config->media_crypto ? codec_config->media_crypto->obj() : nullptr; | 242 codec_config->media_crypto ? codec_config->media_crypto->obj() : nullptr; |
243 | 243 |
244 // |needs_protected_surface| implies encrypted stream. | 244 // |needs_protected_surface| implies encrypted stream. |
245 DCHECK(!codec_config->needs_protected_surface || media_crypto); | 245 DCHECK(!codec_config->needs_protected_surface || media_crypto); |
246 | 246 |
247 const bool require_software_codec = codec_config->task_type == SW_CODEC; | 247 const bool require_software_codec = codec_config->task_type == SW_CODEC; |
248 std::unique_ptr<VideoCodecBridge> codec(VideoCodecBridge::CreateDecoder( | 248 std::unique_ptr<VideoCodecBridge> codec(VideoCodecBridge::CreateDecoder( |
249 codec_config->codec, codec_config->needs_protected_surface, | 249 codec_config->codec, codec_config->needs_protected_surface, |
250 codec_config->initial_expected_coded_size, | 250 codec_config->initial_expected_coded_size, |
251 codec_config->surface.j_surface().obj(), media_crypto, codec_config->csd0, | 251 codec_config->j_surface().obj(), media_crypto, codec_config->csd0, |
252 codec_config->csd1, true, require_software_codec)); | 252 codec_config->csd1, true, require_software_codec)); |
253 | 253 |
254 return codec; | 254 return codec; |
255 } | 255 } |
256 | 256 |
257 void AVDACodecAllocator::CreateMediaCodecAsync( | 257 void AVDACodecAllocator::CreateMediaCodecAsync( |
258 base::WeakPtr<AVDACodecAllocatorClient> client, | 258 base::WeakPtr<AVDACodecAllocatorClient> client, |
259 scoped_refptr<CodecConfig> codec_config) { | 259 scoped_refptr<CodecConfig> codec_config) { |
| 260 // We pass |codec_config| back to OnCodecConfigured in case it's the last |
| 261 // reference to it. It might have an overlay that must be dropped on the |
| 262 // right thread. |
260 base::PostTaskAndReplyWithResult( | 263 base::PostTaskAndReplyWithResult( |
261 TaskRunnerFor(codec_config->task_type).get(), FROM_HERE, | 264 TaskRunnerFor(codec_config->task_type).get(), FROM_HERE, |
262 base::Bind(&AVDACodecAllocator::CreateMediaCodecSync, | 265 base::Bind(&AVDACodecAllocator::CreateMediaCodecSync, |
263 base::Unretained(this), codec_config), | 266 base::Unretained(this), codec_config), |
264 base::Bind(&AVDACodecAllocatorClient::OnCodecConfigured, client)); | 267 base::Bind(&AVDACodecAllocatorClient::OnCodecConfigured, client, |
| 268 codec_config)); |
265 } | 269 } |
266 | 270 |
267 void AVDACodecAllocator::ReleaseMediaCodec( | 271 void AVDACodecAllocator::ReleaseMediaCodec( |
268 std::unique_ptr<VideoCodecBridge> media_codec, | 272 std::unique_ptr<VideoCodecBridge> media_codec, |
269 TaskType task_type, | 273 TaskType task_type, |
270 int surface_id) { | 274 int surface_id) { |
271 DCHECK(thread_checker_.CalledOnValidThread()); | 275 DCHECK(thread_checker_.CalledOnValidThread()); |
272 DCHECK(media_codec); | 276 DCHECK(media_codec); |
273 | 277 |
274 // No need to track the release if it's a SurfaceTexture. | 278 // No need to track the release if it's a SurfaceTexture. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 void AVDACodecAllocator::StopThreadTask(size_t index) { | 362 void AVDACodecAllocator::StopThreadTask(size_t index) { |
359 threads_[index]->thread.Stop(); | 363 threads_[index]->thread.Stop(); |
360 // Signal the stop event after both threads are stopped. | 364 // Signal the stop event after both threads are stopped. |
361 if (stop_event_for_testing_ && !threads_[AUTO_CODEC]->thread.IsRunning() && | 365 if (stop_event_for_testing_ && !threads_[AUTO_CODEC]->thread.IsRunning() && |
362 !threads_[SW_CODEC]->thread.IsRunning()) { | 366 !threads_[SW_CODEC]->thread.IsRunning()) { |
363 stop_event_for_testing_->Signal(); | 367 stop_event_for_testing_->Signal(); |
364 } | 368 } |
365 } | 369 } |
366 | 370 |
367 } // namespace media | 371 } // namespace media |
OLD | NEW |