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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 300 } |
301 | 301 |
302 if (codec_config_->codec == kCodecH264) { | 302 if (codec_config_->codec == kCodecH264) { |
303 codec_config_->csd0 = config.sps; | 303 codec_config_->csd0 = config.sps; |
304 codec_config_->csd1 = config.pps; | 304 codec_config_->csd1 = config.pps; |
305 } | 305 } |
306 | 306 |
307 // Only use MediaCodec for VP8/9 if it's likely backed by hardware | 307 // Only use MediaCodec for VP8/9 if it's likely backed by hardware |
308 // or if the stream is encrypted. | 308 // or if the stream is encrypted. |
309 if (IsMediaCodecSoftwareDecodingForbidden() && | 309 if (IsMediaCodecSoftwareDecodingForbidden() && |
310 VideoCodecBridge::IsKnownUnaccelerated(codec_config_->codec, | 310 MediaCodecUtil::IsKnownUnaccelerated(codec_config_->codec, |
311 MEDIA_CODEC_DECODER)) { | 311 MediaCodecDirection::DECODER)) { |
312 DVLOG(1) << "Initialization failed: " | 312 DVLOG(1) << "Initialization failed: " << GetCodecName(codec_config_->codec) |
313 << (codec_config_->codec == kCodecVP8 ? "vp8" : "vp9") | |
314 << " is not hardware accelerated"; | 313 << " is not hardware accelerated"; |
315 return false; | 314 return false; |
316 } | 315 } |
317 | 316 |
318 auto gles_decoder = get_gles2_decoder_cb_.Run(); | 317 auto gles_decoder = get_gles2_decoder_cb_.Run(); |
319 if (!gles_decoder) { | 318 if (!gles_decoder) { |
320 DLOG(ERROR) << "Failed to get gles2 decoder instance."; | 319 DLOG(ERROR) << "Failed to get gles2 decoder instance."; |
321 return false; | 320 return false; |
322 } | 321 } |
323 | 322 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 484 |
486 int input_buf_index = pending_input_buf_index_; | 485 int input_buf_index = pending_input_buf_index_; |
487 | 486 |
488 // Do not dequeue a new input buffer if we failed with MEDIA_CODEC_NO_KEY. | 487 // Do not dequeue a new input buffer if we failed with MEDIA_CODEC_NO_KEY. |
489 // That status does not return this buffer back to the pool of | 488 // That status does not return this buffer back to the pool of |
490 // available input buffers. We have to reuse it in QueueSecureInputBuffer(). | 489 // available input buffers. We have to reuse it in QueueSecureInputBuffer(). |
491 if (input_buf_index == -1) { | 490 if (input_buf_index == -1) { |
492 MediaCodecStatus status = | 491 MediaCodecStatus status = |
493 media_codec_->DequeueInputBuffer(NoWaitTimeOut, &input_buf_index); | 492 media_codec_->DequeueInputBuffer(NoWaitTimeOut, &input_buf_index); |
494 switch (status) { | 493 switch (status) { |
495 case MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER: | 494 case MEDIA_CODEC_TRY_AGAIN_LATER: |
496 return false; | 495 return false; |
497 case MEDIA_CODEC_ERROR: | 496 case MEDIA_CODEC_ERROR: |
498 NOTIFY_ERROR(PLATFORM_FAILURE, "DequeueInputBuffer failed"); | 497 NOTIFY_ERROR(PLATFORM_FAILURE, "DequeueInputBuffer failed"); |
499 return false; | 498 return false; |
500 case MEDIA_CODEC_OK: | 499 case MEDIA_CODEC_OK: |
501 break; | 500 break; |
502 default: | 501 default: |
503 NOTREACHED(); | 502 NOTREACHED(); |
504 return false; | 503 return false; |
505 } | 504 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 // Instead, signal completion of the drain. | 657 // Instead, signal completion of the drain. |
659 if (IsDrainingForResetOrDestroy()) { | 658 if (IsDrainingForResetOrDestroy()) { |
660 DVLOG(1) << __func__ << ": error while draining"; | 659 DVLOG(1) << __func__ << ": error while draining"; |
661 state_ = ERROR; | 660 state_ = ERROR; |
662 OnDrainCompleted(); | 661 OnDrainCompleted(); |
663 } else { | 662 } else { |
664 NOTIFY_ERROR(PLATFORM_FAILURE, "DequeueOutputBuffer failed."); | 663 NOTIFY_ERROR(PLATFORM_FAILURE, "DequeueOutputBuffer failed."); |
665 } | 664 } |
666 return false; | 665 return false; |
667 | 666 |
668 case MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER: | 667 case MEDIA_CODEC_TRY_AGAIN_LATER: |
669 return false; | 668 return false; |
670 | 669 |
671 case MEDIA_CODEC_OUTPUT_FORMAT_CHANGED: { | 670 case MEDIA_CODEC_OUTPUT_FORMAT_CHANGED: { |
672 // An OUTPUT_FORMAT_CHANGED is not reported after flush() if the frame | 671 // An OUTPUT_FORMAT_CHANGED is not reported after flush() if the frame |
673 // size does not change. Therefore we have to keep track on the format | 672 // size does not change. Therefore we have to keep track on the format |
674 // even if draining, unless we are draining for destroy. | 673 // even if draining, unless we are draining for destroy. |
675 if (drain_type_ == DRAIN_FOR_DESTROY) | 674 if (drain_type_ == DRAIN_FOR_DESTROY) |
676 return true; // ignore | 675 return true; // ignore |
677 | 676 |
678 if (media_codec_->GetOutputSize(&size_) != MEDIA_CODEC_OK) { | 677 if (media_codec_->GetOutputSize(&size_) != MEDIA_CODEC_OK) { |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 | 974 |
976 base::Optional<TaskType> task_type = | 975 base::Optional<TaskType> task_type = |
977 codec_allocator_->TaskTypeForAllocation(); | 976 codec_allocator_->TaskTypeForAllocation(); |
978 if (!task_type) { | 977 if (!task_type) { |
979 // If there is no free thread, then just fail. | 978 // If there is no free thread, then just fail. |
980 OnCodecConfigured(nullptr); | 979 OnCodecConfigured(nullptr); |
981 return; | 980 return; |
982 } | 981 } |
983 | 982 |
984 codec_config_->task_type = task_type.value(); | 983 codec_config_->task_type = task_type.value(); |
985 std::unique_ptr<VideoCodecBridge> media_codec = | 984 std::unique_ptr<MediaCodecBridge> media_codec = |
986 codec_allocator_->CreateMediaCodecSync(codec_config_); | 985 AVDACodecAllocator::Instance()->CreateMediaCodecSync(codec_config_); |
987 // Note that |media_codec| might be null, which will NotifyError. | 986 // Note that |media_codec| might be null, which will NotifyError. |
988 OnCodecConfigured(std::move(media_codec)); | 987 OnCodecConfigured(std::move(media_codec)); |
989 } | 988 } |
990 | 989 |
991 void AndroidVideoDecodeAccelerator::OnCodecConfigured( | 990 void AndroidVideoDecodeAccelerator::OnCodecConfigured( |
992 std::unique_ptr<VideoCodecBridge> media_codec) { | 991 std::unique_ptr<MediaCodecBridge> media_codec) { |
993 DCHECK(thread_checker_.CalledOnValidThread()); | 992 DCHECK(thread_checker_.CalledOnValidThread()); |
994 DCHECK(state_ == WAITING_FOR_CODEC || state_ == SURFACE_DESTROYED); | 993 DCHECK(state_ == WAITING_FOR_CODEC || state_ == SURFACE_DESTROYED); |
995 | 994 |
996 // If we are supposed to notify that initialization is complete, then do so | 995 // If we are supposed to notify that initialization is complete, then do so |
997 // before returning. Otherwise, this is a reconfiguration. | 996 // before returning. Otherwise, this is a reconfiguration. |
998 | 997 |
999 // If |state_| changed to SURFACE_DESTROYED while we were configuring a codec, | 998 // If |state_| changed to SURFACE_DESTROYED while we were configuring a codec, |
1000 // then the codec is already invalid so we return early and drop it. | 999 // then the codec is already invalid so we return early and drop it. |
1001 // TODO(liberato): We're going to drop the codec when |media_codec| goes out | 1000 // TODO(liberato): We're going to drop the codec when |media_codec| goes out |
1002 // of scope, on this thread. We really should post it to the proper thread | 1001 // of scope, on this thread. We really should post it to the proper thread |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1453 // support for it. Let libvpx decode it, and save a MediaCodec instance. | 1452 // support for it. Let libvpx decode it, and save a MediaCodec instance. |
1454 // Note that we allow it anyway for encrypted content, since we push a | 1453 // Note that we allow it anyway for encrypted content, since we push a |
1455 // separate profile for that. | 1454 // separate profile for that. |
1456 profile.min_resolution.SetSize(480, 360); | 1455 profile.min_resolution.SetSize(480, 360); |
1457 profile.max_resolution.SetSize(3840, 2160); | 1456 profile.max_resolution.SetSize(3840, 2160); |
1458 // If we know MediaCodec will just create a software codec, prefer our | 1457 // If we know MediaCodec will just create a software codec, prefer our |
1459 // internal software decoder instead. It's more up to date and secured | 1458 // internal software decoder instead. It's more up to date and secured |
1460 // within the renderer sandbox. However if the content is encrypted, we | 1459 // within the renderer sandbox. However if the content is encrypted, we |
1461 // must use MediaCodec anyways since MediaDrm offers no way to decrypt | 1460 // must use MediaCodec anyways since MediaDrm offers no way to decrypt |
1462 // the buffers and let us use our internal software decoders. | 1461 // the buffers and let us use our internal software decoders. |
1463 profile.encrypted_only = | 1462 profile.encrypted_only = MediaCodecUtil::IsKnownUnaccelerated( |
1464 VideoCodecBridge::IsKnownUnaccelerated(kCodecVP8, MEDIA_CODEC_DECODER); | 1463 kCodecVP8, MediaCodecDirection::DECODER); |
1465 profiles.push_back(profile); | 1464 profiles.push_back(profile); |
1466 | 1465 |
1467 // Always allow encrypted content, even at low resolutions. | 1466 // Always allow encrypted content, even at low resolutions. |
1468 profile.min_resolution.SetSize(0, 0); | 1467 profile.min_resolution.SetSize(0, 0); |
1469 profile.encrypted_only = true; | 1468 profile.encrypted_only = true; |
1470 profiles.push_back(profile); | 1469 profiles.push_back(profile); |
1471 } | 1470 } |
1472 | 1471 |
1473 if (MediaCodecUtil::IsVp9DecoderAvailable()) { | 1472 if (MediaCodecUtil::IsVp9DecoderAvailable()) { |
1474 const VideoCodecProfile profile_types[] = { | 1473 const VideoCodecProfile profile_types[] = { |
1475 VP9PROFILE_PROFILE0, VP9PROFILE_PROFILE1, VP9PROFILE_PROFILE2, | 1474 VP9PROFILE_PROFILE0, VP9PROFILE_PROFILE1, VP9PROFILE_PROFILE2, |
1476 VP9PROFILE_PROFILE3, VIDEO_CODEC_PROFILE_UNKNOWN}; | 1475 VP9PROFILE_PROFILE3, VIDEO_CODEC_PROFILE_UNKNOWN}; |
1477 const bool is_known_unaccelerated = | 1476 const bool is_known_unaccelerated = MediaCodecUtil::IsKnownUnaccelerated( |
1478 VideoCodecBridge::IsKnownUnaccelerated(kCodecVP9, MEDIA_CODEC_DECODER); | 1477 kCodecVP9, MediaCodecDirection::DECODER); |
1479 for (int i = 0; profile_types[i] != VIDEO_CODEC_PROFILE_UNKNOWN; i++) { | 1478 for (int i = 0; profile_types[i] != VIDEO_CODEC_PROFILE_UNKNOWN; i++) { |
1480 SupportedProfile profile; | 1479 SupportedProfile profile; |
1481 // Limit to 360p, like we do for vp8. See above. | 1480 // Limit to 360p, like we do for vp8. See above. |
1482 profile.min_resolution.SetSize(480, 360); | 1481 profile.min_resolution.SetSize(480, 360); |
1483 profile.max_resolution.SetSize(3840, 2160); | 1482 profile.max_resolution.SetSize(3840, 2160); |
1484 // If we know MediaCodec will just create a software codec, prefer our | 1483 // If we know MediaCodec will just create a software codec, prefer our |
1485 // internal software decoder instead. It's more up to date and secured | 1484 // internal software decoder instead. It's more up to date and secured |
1486 // within the renderer sandbox. However if the content is encrypted, we | 1485 // within the renderer sandbox. However if the content is encrypted, we |
1487 // must use MediaCodec anyways since MediaDrm offers no way to decrypt | 1486 // must use MediaCodec anyways since MediaDrm offers no way to decrypt |
1488 // the buffers and let us use our internal software decoders. | 1487 // the buffers and let us use our internal software decoders. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1585 if (!media_codec_) | 1584 if (!media_codec_) |
1586 return; | 1585 return; |
1587 | 1586 |
1588 picture_buffer_manager_.CodecChanged(nullptr); | 1587 picture_buffer_manager_.CodecChanged(nullptr); |
1589 codec_allocator_->ReleaseMediaCodec( | 1588 codec_allocator_->ReleaseMediaCodec( |
1590 std::move(media_codec_), codec_config_->task_type, config_.surface_id); | 1589 std::move(media_codec_), codec_config_->task_type, config_.surface_id); |
1591 last_release_task_type_ = codec_config_->task_type; | 1590 last_release_task_type_ = codec_config_->task_type; |
1592 } | 1591 } |
1593 | 1592 |
1594 } // namespace media | 1593 } // namespace media |
OLD | NEW |