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 16 matching lines...) Expand all Loading... |
27 namespace { | 27 namespace { |
28 | 28 |
29 // Give tasks 800ms before considering them hung. MediaCodec.configure() calls | 29 // Give tasks 800ms before considering them hung. MediaCodec.configure() calls |
30 // typically take 100-200ms on a N5, so 800ms is expected to very rarely result | 30 // typically take 100-200ms on a N5, so 800ms is expected to very rarely result |
31 // in false positives. Also, false positives have low impact because we resume | 31 // in false positives. Also, false positives have low impact because we resume |
32 // using the thread when the task completes. | 32 // using the thread when the task completes. |
33 constexpr base::TimeDelta kHungTaskDetectionTimeout = | 33 constexpr base::TimeDelta kHungTaskDetectionTimeout = |
34 base::TimeDelta::FromMilliseconds(800); | 34 base::TimeDelta::FromMilliseconds(800); |
35 | 35 |
36 // Delete |codec| and signal |done_event| if it's not null. | 36 // Delete |codec| and signal |done_event| if it's not null. |
37 void DeleteMediaCodecAndSignal(std::unique_ptr<VideoCodecBridge> codec, | 37 void DeleteMediaCodecAndSignal(std::unique_ptr<MediaCodecBridge> codec, |
38 base::WaitableEvent* done_event) { | 38 base::WaitableEvent* done_event) { |
39 codec.reset(); | 39 codec.reset(); |
40 if (done_event) | 40 if (done_event) |
41 done_event->Signal(); | 41 done_event->Signal(); |
42 } | 42 } |
43 | 43 |
44 } // namespace | 44 } // namespace |
45 | 45 |
46 CodecConfig::CodecConfig() {} | 46 CodecConfig::CodecConfig() {} |
47 CodecConfig::~CodecConfig() {} | 47 CodecConfig::~CodecConfig() {} |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // And in that case we don't want to hang the browser UI thread. Android ANRs | 227 // And in that case we don't want to hang the browser UI thread. Android ANRs |
228 // occur when the UI thread is blocked for 5 seconds, so waiting for 2 seconds | 228 // occur when the UI thread is blocked for 5 seconds, so waiting for 2 seconds |
229 // gives us leeway to avoid an ANR. Verified no ANR on a Nexus 7. | 229 // gives us leeway to avoid an ANR. Verified no ANR on a Nexus 7. |
230 base::WaitableEvent& released = | 230 base::WaitableEvent& released = |
231 pending_codec_releases_.find(surface_id)->second; | 231 pending_codec_releases_.find(surface_id)->second; |
232 released.TimedWait(base::TimeDelta::FromSeconds(2)); | 232 released.TimedWait(base::TimeDelta::FromSeconds(2)); |
233 if (!released.IsSignaled()) | 233 if (!released.IsSignaled()) |
234 DLOG(WARNING) << __func__ << ": timed out waiting for MediaCodec#release()"; | 234 DLOG(WARNING) << __func__ << ": timed out waiting for MediaCodec#release()"; |
235 } | 235 } |
236 | 236 |
237 std::unique_ptr<VideoCodecBridge> AVDACodecAllocator::CreateMediaCodecSync( | 237 std::unique_ptr<MediaCodecBridge> AVDACodecAllocator::CreateMediaCodecSync( |
238 scoped_refptr<CodecConfig> codec_config) { | 238 scoped_refptr<CodecConfig> codec_config) { |
239 TRACE_EVENT0("media", "AVDA::CreateMediaCodecSync"); | 239 TRACE_EVENT0("media", "AVDA::CreateMediaCodecSync"); |
240 | 240 |
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<MediaCodecBridge> codec( |
249 codec_config->codec, codec_config->needs_protected_surface, | 249 MediaCodecBridgeImpl::CreateVideoDecoder( |
250 codec_config->initial_expected_coded_size, | 250 codec_config->codec, codec_config->needs_protected_surface, |
251 codec_config->surface.j_surface().obj(), media_crypto, codec_config->csd0, | 251 codec_config->initial_expected_coded_size, |
252 codec_config->csd1, true, require_software_codec)); | 252 codec_config->surface.j_surface().obj(), media_crypto, |
| 253 codec_config->csd0, codec_config->csd1, true, |
| 254 require_software_codec)); |
253 | 255 |
254 return codec; | 256 return codec; |
255 } | 257 } |
256 | 258 |
257 void AVDACodecAllocator::CreateMediaCodecAsync( | 259 void AVDACodecAllocator::CreateMediaCodecAsync( |
258 base::WeakPtr<AVDACodecAllocatorClient> client, | 260 base::WeakPtr<AVDACodecAllocatorClient> client, |
259 scoped_refptr<CodecConfig> codec_config) { | 261 scoped_refptr<CodecConfig> codec_config) { |
260 base::PostTaskAndReplyWithResult( | 262 base::PostTaskAndReplyWithResult( |
261 TaskRunnerFor(codec_config->task_type).get(), FROM_HERE, | 263 TaskRunnerFor(codec_config->task_type).get(), FROM_HERE, |
262 base::Bind(&AVDACodecAllocator::CreateMediaCodecSync, | 264 base::Bind(&AVDACodecAllocator::CreateMediaCodecSync, |
263 base::Unretained(this), codec_config), | 265 base::Unretained(this), codec_config), |
264 base::Bind(&AVDACodecAllocatorClient::OnCodecConfigured, client)); | 266 base::Bind(&AVDACodecAllocatorClient::OnCodecConfigured, client)); |
265 } | 267 } |
266 | 268 |
267 void AVDACodecAllocator::ReleaseMediaCodec( | 269 void AVDACodecAllocator::ReleaseMediaCodec( |
268 std::unique_ptr<VideoCodecBridge> media_codec, | 270 std::unique_ptr<MediaCodecBridge> media_codec, |
269 TaskType task_type, | 271 TaskType task_type, |
270 int surface_id) { | 272 int surface_id) { |
271 DCHECK(thread_checker_.CalledOnValidThread()); | 273 DCHECK(thread_checker_.CalledOnValidThread()); |
272 DCHECK(media_codec); | 274 DCHECK(media_codec); |
273 | 275 |
274 // No need to track the release if it's a SurfaceTexture. | 276 // No need to track the release if it's a SurfaceTexture. |
275 if (surface_id == SurfaceManager::kNoSurfaceID) { | 277 if (surface_id == SurfaceManager::kNoSurfaceID) { |
276 TaskRunnerFor(task_type)->PostTask( | 278 TaskRunnerFor(task_type)->PostTask( |
277 FROM_HERE, base::Bind(&DeleteMediaCodecAndSignal, | 279 FROM_HERE, base::Bind(&DeleteMediaCodecAndSignal, |
278 base::Passed(std::move(media_codec)), nullptr)); | 280 base::Passed(std::move(media_codec)), nullptr)); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 void AVDACodecAllocator::StopThreadTask(size_t index) { | 360 void AVDACodecAllocator::StopThreadTask(size_t index) { |
359 threads_[index]->thread.Stop(); | 361 threads_[index]->thread.Stop(); |
360 // Signal the stop event after both threads are stopped. | 362 // Signal the stop event after both threads are stopped. |
361 if (stop_event_for_testing_ && !threads_[AUTO_CODEC]->thread.IsRunning() && | 363 if (stop_event_for_testing_ && !threads_[AUTO_CODEC]->thread.IsRunning() && |
362 !threads_[SW_CODEC]->thread.IsRunning()) { | 364 !threads_[SW_CODEC]->thread.IsRunning()) { |
363 stop_event_for_testing_->Signal(); | 365 stop_event_for_testing_->Signal(); |
364 } | 366 } |
365 } | 367 } |
366 | 368 |
367 } // namespace media | 369 } // namespace media |
OLD | NEW |