| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/android_video_decode_accelerator.h" | 5 #include "media/gpu/android_video_decode_accelerator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "media/base/bind_to_current_loop.h" | 31 #include "media/base/bind_to_current_loop.h" |
| 32 #include "media/base/bitstream_buffer.h" | 32 #include "media/base/bitstream_buffer.h" |
| 33 #include "media/base/limits.h" | 33 #include "media/base/limits.h" |
| 34 #include "media/base/media.h" | 34 #include "media/base/media.h" |
| 35 #include "media/base/timestamp_constants.h" | 35 #include "media/base/timestamp_constants.h" |
| 36 #include "media/base/video_decoder_config.h" | 36 #include "media/base/video_decoder_config.h" |
| 37 #include "media/gpu/android_video_surface_chooser_impl.h" | 37 #include "media/gpu/android_video_surface_chooser_impl.h" |
| 38 #include "media/gpu/avda_picture_buffer_manager.h" | 38 #include "media/gpu/avda_picture_buffer_manager.h" |
| 39 #include "media/gpu/content_video_view_overlay.h" | 39 #include "media/gpu/content_video_view_overlay.h" |
| 40 #include "media/gpu/shared_memory_region.h" | 40 #include "media/gpu/shared_memory_region.h" |
| 41 #include "media/mojo/features.h" |
| 41 #include "media/video/picture.h" | 42 #include "media/video/picture.h" |
| 42 #include "ui/gl/android/scoped_java_surface.h" | 43 #include "ui/gl/android/scoped_java_surface.h" |
| 43 #include "ui/gl/android/surface_texture.h" | 44 #include "ui/gl/android/surface_texture.h" |
| 44 #include "ui/gl/gl_bindings.h" | 45 #include "ui/gl/gl_bindings.h" |
| 45 | 46 |
| 46 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 47 #if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 47 #include "media/cdm/cdm_manager.h" // nogncheck | 48 #include "media/cdm/cdm_manager.h" // nogncheck |
| 48 #endif | 49 #endif |
| 49 | 50 |
| 50 #define NOTIFY_ERROR(error_code, error_message) \ | 51 #define NOTIFY_ERROR(error_code, error_message) \ |
| 51 do { \ | 52 do { \ |
| 52 DLOG(ERROR) << error_message; \ | 53 DLOG(ERROR) << error_message; \ |
| 53 NotifyError(VideoDecodeAccelerator::error_code); \ | 54 NotifyError(VideoDecodeAccelerator::error_code); \ |
| 54 } while (0) | 55 } while (0) |
| 55 | 56 |
| 56 namespace media { | 57 namespace media { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 surface_chooser_(std::move(surface_chooser)), | 269 surface_chooser_(std::move(surface_chooser)), |
| 269 platform_config_(platform_config), | 270 platform_config_(platform_config), |
| 270 overlay_factory_cb_(overlay_factory_cb), | 271 overlay_factory_cb_(overlay_factory_cb), |
| 271 weak_this_factory_(this) {} | 272 weak_this_factory_(this) {} |
| 272 | 273 |
| 273 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { | 274 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { |
| 274 DCHECK(thread_checker_.CalledOnValidThread()); | 275 DCHECK(thread_checker_.CalledOnValidThread()); |
| 275 GetManager()->StopTimer(this); | 276 GetManager()->StopTimer(this); |
| 276 codec_allocator_->StopThread(this); | 277 codec_allocator_->StopThread(this); |
| 277 | 278 |
| 278 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 279 #if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 279 if (!media_drm_bridge_cdm_context_) | 280 if (!media_drm_bridge_cdm_context_) |
| 280 return; | 281 return; |
| 281 | 282 |
| 282 DCHECK(cdm_registration_id_); | 283 DCHECK(cdm_registration_id_); |
| 283 | 284 |
| 284 // Cancel previously registered callback (if any). | 285 // Cancel previously registered callback (if any). |
| 285 media_drm_bridge_cdm_context_->SetMediaCryptoReadyCB( | 286 media_drm_bridge_cdm_context_->SetMediaCryptoReadyCB( |
| 286 MediaDrmBridgeCdmContext::MediaCryptoReadyCB()); | 287 MediaDrmBridgeCdmContext::MediaCryptoReadyCB()); |
| 287 | 288 |
| 288 media_drm_bridge_cdm_context_->UnregisterPlayer(cdm_registration_id_); | 289 media_drm_bridge_cdm_context_->UnregisterPlayer(cdm_registration_id_); |
| 289 #endif // defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 290 #endif // BUILDFLAG(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 290 } | 291 } |
| 291 | 292 |
| 292 bool AndroidVideoDecodeAccelerator::Initialize(const Config& config, | 293 bool AndroidVideoDecodeAccelerator::Initialize(const Config& config, |
| 293 Client* client) { | 294 Client* client) { |
| 294 DVLOG(1) << __func__ << ": " << config.AsHumanReadableString(); | 295 DVLOG(1) << __func__ << ": " << config.AsHumanReadableString(); |
| 295 TRACE_EVENT0("media", "AVDA::Initialize"); | 296 TRACE_EVENT0("media", "AVDA::Initialize"); |
| 296 DCHECK(!media_codec_); | 297 DCHECK(!media_codec_); |
| 297 DCHECK(thread_checker_.CalledOnValidThread()); | 298 DCHECK(thread_checker_.CalledOnValidThread()); |
| 298 base::AutoReset<bool> scoper(&during_initialize_, true); | 299 base::AutoReset<bool> scoper(&during_initialize_, true); |
| 299 | 300 |
| (...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1398 | 1399 |
| 1399 // If we're draining, signal completion now because the drain can no longer | 1400 // If we're draining, signal completion now because the drain can no longer |
| 1400 // proceed. | 1401 // proceed. |
| 1401 if (drain_type_) | 1402 if (drain_type_) |
| 1402 OnDrainCompleted(); | 1403 OnDrainCompleted(); |
| 1403 } | 1404 } |
| 1404 | 1405 |
| 1405 void AndroidVideoDecodeAccelerator::InitializeCdm() { | 1406 void AndroidVideoDecodeAccelerator::InitializeCdm() { |
| 1406 DVLOG(2) << __func__ << ": " << config_.cdm_id; | 1407 DVLOG(2) << __func__ << ": " << config_.cdm_id; |
| 1407 | 1408 |
| 1408 #if !defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 1409 #if !BUILDFLAG(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 1409 NOTIMPLEMENTED(); | 1410 NOTIMPLEMENTED(); |
| 1410 NOTIFY_ERROR(PLATFORM_FAILURE, "Cdm support needs mojo in the gpu process"); | 1411 NOTIFY_ERROR(PLATFORM_FAILURE, "Cdm support needs mojo in the gpu process"); |
| 1411 #else | 1412 #else |
| 1412 // Store the CDM to hold a reference to it. | 1413 // Store the CDM to hold a reference to it. |
| 1413 cdm_for_reference_holding_only_ = | 1414 cdm_for_reference_holding_only_ = |
| 1414 CdmManager::GetInstance()->GetCdm(config_.cdm_id); | 1415 CdmManager::GetInstance()->GetCdm(config_.cdm_id); |
| 1415 DCHECK(cdm_for_reference_holding_only_); | 1416 DCHECK(cdm_for_reference_holding_only_); |
| 1416 | 1417 |
| 1417 // On Android platform the CdmContext must be a MediaDrmBridgeCdmContext. | 1418 // On Android platform the CdmContext must be a MediaDrmBridgeCdmContext. |
| 1418 media_drm_bridge_cdm_context_ = static_cast<MediaDrmBridgeCdmContext*>( | 1419 media_drm_bridge_cdm_context_ = static_cast<MediaDrmBridgeCdmContext*>( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1429 // TODO(xhwang): Remove |cdm_unset_cb| after it's not used on all platforms. | 1430 // TODO(xhwang): Remove |cdm_unset_cb| after it's not used on all platforms. |
| 1430 cdm_registration_id_ = media_drm_bridge_cdm_context_->RegisterPlayer( | 1431 cdm_registration_id_ = media_drm_bridge_cdm_context_->RegisterPlayer( |
| 1431 BindToCurrentLoop(base::Bind(&AndroidVideoDecodeAccelerator::OnKeyAdded, | 1432 BindToCurrentLoop(base::Bind(&AndroidVideoDecodeAccelerator::OnKeyAdded, |
| 1432 weak_this_factory_.GetWeakPtr())), | 1433 weak_this_factory_.GetWeakPtr())), |
| 1433 base::Bind(&base::DoNothing)); | 1434 base::Bind(&base::DoNothing)); |
| 1434 | 1435 |
| 1435 // Deferred initialization will continue in OnMediaCryptoReady(). | 1436 // Deferred initialization will continue in OnMediaCryptoReady(). |
| 1436 media_drm_bridge_cdm_context_->SetMediaCryptoReadyCB(BindToCurrentLoop( | 1437 media_drm_bridge_cdm_context_->SetMediaCryptoReadyCB(BindToCurrentLoop( |
| 1437 base::Bind(&AndroidVideoDecodeAccelerator::OnMediaCryptoReady, | 1438 base::Bind(&AndroidVideoDecodeAccelerator::OnMediaCryptoReady, |
| 1438 weak_this_factory_.GetWeakPtr()))); | 1439 weak_this_factory_.GetWeakPtr()))); |
| 1439 #endif // !defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 1440 #endif // !BUILDFLAG(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 1440 } | 1441 } |
| 1441 | 1442 |
| 1442 void AndroidVideoDecodeAccelerator::OnMediaCryptoReady( | 1443 void AndroidVideoDecodeAccelerator::OnMediaCryptoReady( |
| 1443 MediaDrmBridgeCdmContext::JavaObjectPtr media_crypto, | 1444 MediaDrmBridgeCdmContext::JavaObjectPtr media_crypto, |
| 1444 bool needs_protected_surface) { | 1445 bool needs_protected_surface) { |
| 1445 DVLOG(1) << __func__; | 1446 DVLOG(1) << __func__; |
| 1446 | 1447 |
| 1447 if (!media_crypto) { | 1448 if (!media_crypto) { |
| 1448 LOG(ERROR) << "MediaCrypto is not available, can't play encrypted stream."; | 1449 LOG(ERROR) << "MediaCrypto is not available, can't play encrypted stream."; |
| 1449 cdm_for_reference_holding_only_ = nullptr; | 1450 cdm_for_reference_holding_only_ = nullptr; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1692 codec_allocator_->ReleaseMediaCodec(std::move(media_codec_), | 1693 codec_allocator_->ReleaseMediaCodec(std::move(media_codec_), |
| 1693 codec_config_->surface_bundle); | 1694 codec_config_->surface_bundle); |
| 1694 } | 1695 } |
| 1695 | 1696 |
| 1696 void AndroidVideoDecodeAccelerator::ReleaseCodecAndBundle() { | 1697 void AndroidVideoDecodeAccelerator::ReleaseCodecAndBundle() { |
| 1697 ReleaseCodec(); | 1698 ReleaseCodec(); |
| 1698 codec_config_->surface_bundle = nullptr; | 1699 codec_config_->surface_bundle = nullptr; |
| 1699 } | 1700 } |
| 1700 | 1701 |
| 1701 } // namespace media | 1702 } // namespace media |
| OLD | NEW |