| 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 codec_config_->codec_ = VideoCodecProfileToVideoCodec(config.profile); | 373 codec_config_->codec_ = VideoCodecProfileToVideoCodec(config.profile); |
| 374 codec_config_->initial_expected_coded_size_ = | 374 codec_config_->initial_expected_coded_size_ = |
| 375 config.initial_expected_coded_size; | 375 config.initial_expected_coded_size; |
| 376 | 376 |
| 377 if (codec_config_->codec_ != kCodecVP8 && | 377 if (codec_config_->codec_ != kCodecVP8 && |
| 378 codec_config_->codec_ != kCodecVP9 && | 378 codec_config_->codec_ != kCodecVP9 && |
| 379 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 379 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 380 codec_config_->codec_ != kCodecHEVC && | 380 codec_config_->codec_ != kCodecHEVC && |
| 381 #endif | 381 #endif |
| 382 codec_config_->codec_ != kCodecH264) { | 382 codec_config_->codec_ != kCodecH264) { |
| 383 LOG(ERROR) << "Unsupported profile: " << config.profile; | 383 DLOG(ERROR) << "Unsupported profile: " << config.profile; |
| 384 return false; | 384 return false; |
| 385 } | 385 } |
| 386 | 386 |
| 387 if (codec_config_->codec_ == kCodecH264) { |
| 388 codec_config_->csd0_ = config.sps; |
| 389 codec_config_->csd1_ = config.pps; |
| 390 } |
| 391 |
| 387 // Only use MediaCodec for VP8/9 if it's likely backed by hardware | 392 // Only use MediaCodec for VP8/9 if it's likely backed by hardware |
| 388 // or if the stream is encrypted. | 393 // or if the stream is encrypted. |
| 389 if (IsMediaCodecSoftwareDecodingForbidden() && | 394 if (IsMediaCodecSoftwareDecodingForbidden() && |
| 390 VideoCodecBridge::IsKnownUnaccelerated(codec_config_->codec_, | 395 VideoCodecBridge::IsKnownUnaccelerated(codec_config_->codec_, |
| 391 MEDIA_CODEC_DECODER)) { | 396 MEDIA_CODEC_DECODER)) { |
| 392 DVLOG(1) << "Initialization failed: " | 397 DVLOG(1) << "Initialization failed: " |
| 393 << (codec_config_->codec_ == kCodecVP8 ? "vp8" : "vp9") | 398 << (codec_config_->codec_ == kCodecVP8 ? "vp8" : "vp9") |
| 394 << " is not hardware accelerated"; | 399 << " is not hardware accelerated"; |
| 395 return false; | 400 return false; |
| 396 } | 401 } |
| 397 | 402 |
| 398 auto gles_decoder = get_gles2_decoder_cb_.Run(); | 403 auto gles_decoder = get_gles2_decoder_cb_.Run(); |
| 399 if (!gles_decoder) { | 404 if (!gles_decoder) { |
| 400 LOG(ERROR) << "Failed to get gles2 decoder instance."; | 405 DLOG(ERROR) << "Failed to get gles2 decoder instance."; |
| 401 return false; | 406 return false; |
| 402 } | 407 } |
| 403 | 408 |
| 404 // If we're low on resources, we may decide to defer creation of the surface | 409 // If we're low on resources, we may decide to defer creation of the surface |
| 405 // until the codec is actually used. | 410 // until the codec is actually used. |
| 406 if (g_avda_manager.Get().ShouldDeferSurfaceCreation(config_.surface_id, | 411 if (g_avda_manager.Get().ShouldDeferSurfaceCreation(config_.surface_id, |
| 407 codec_config_->codec_)) { | 412 codec_config_->codec_)) { |
| 408 DCHECK(!deferred_initialization_pending_); | 413 DCHECK(!deferred_initialization_pending_); |
| 409 | 414 |
| 410 // We should never be here if a SurfaceView is required. | 415 // We should never be here if a SurfaceView is required. |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 | 1041 |
| 1037 // |needs_protected_surface_| implies encrypted stream. | 1042 // |needs_protected_surface_| implies encrypted stream. |
| 1038 DCHECK(!codec_config->needs_protected_surface_ || media_crypto); | 1043 DCHECK(!codec_config->needs_protected_surface_ || media_crypto); |
| 1039 | 1044 |
| 1040 const bool require_software_codec = | 1045 const bool require_software_codec = |
| 1041 codec_config->task_type_ == AVDACodecAllocator::TaskType::SW_CODEC; | 1046 codec_config->task_type_ == AVDACodecAllocator::TaskType::SW_CODEC; |
| 1042 | 1047 |
| 1043 std::unique_ptr<VideoCodecBridge> codec(VideoCodecBridge::CreateDecoder( | 1048 std::unique_ptr<VideoCodecBridge> codec(VideoCodecBridge::CreateDecoder( |
| 1044 codec_config->codec_, codec_config->needs_protected_surface_, | 1049 codec_config->codec_, codec_config->needs_protected_surface_, |
| 1045 codec_config->initial_expected_coded_size_, | 1050 codec_config->initial_expected_coded_size_, |
| 1046 codec_config->surface_.j_surface().obj(), media_crypto, true, | 1051 codec_config->surface_.j_surface().obj(), media_crypto, |
| 1047 require_software_codec)); | 1052 codec_config->csd0_, codec_config->csd1_, true, require_software_codec)); |
| 1048 | 1053 |
| 1049 return codec; | 1054 return codec; |
| 1050 } | 1055 } |
| 1051 | 1056 |
| 1052 void AndroidVideoDecodeAccelerator::OnCodecConfigured( | 1057 void AndroidVideoDecodeAccelerator::OnCodecConfigured( |
| 1053 std::unique_ptr<VideoCodecBridge> media_codec) { | 1058 std::unique_ptr<VideoCodecBridge> media_codec) { |
| 1054 DCHECK(thread_checker_.CalledOnValidThread()); | 1059 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1055 DCHECK(state_ == WAITING_FOR_CODEC || state_ == SURFACE_DESTROYED); | 1060 DCHECK(state_ == WAITING_FOR_CODEC || state_ == SURFACE_DESTROYED); |
| 1056 | 1061 |
| 1057 // Record one instance of the codec being initialized. | 1062 // Record one instance of the codec being initialized. |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 | 1593 |
| 1589 bool AndroidVideoDecodeAccelerator::IsMediaCodecSoftwareDecodingForbidden() | 1594 bool AndroidVideoDecodeAccelerator::IsMediaCodecSoftwareDecodingForbidden() |
| 1590 const { | 1595 const { |
| 1591 // Prevent MediaCodec from using its internal software decoders when we have | 1596 // Prevent MediaCodec from using its internal software decoders when we have |
| 1592 // more secure and up to date versions in the renderer process. | 1597 // more secure and up to date versions in the renderer process. |
| 1593 return !config_.is_encrypted && (codec_config_->codec_ == kCodecVP8 || | 1598 return !config_.is_encrypted && (codec_config_->codec_ == kCodecVP8 || |
| 1594 codec_config_->codec_ == kCodecVP9); | 1599 codec_config_->codec_ == kCodecVP9); |
| 1595 } | 1600 } |
| 1596 | 1601 |
| 1597 } // namespace media | 1602 } // namespace media |
| OLD | NEW |