| 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 "content/common/gpu/media/android_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/android_video_decode_accelerator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "content/common/gpu/gpu_channel.h" | 11 #include "content/common/gpu/gpu_channel.h" |
| 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 13 #include "media/base/bitstream_buffer.h" | 13 #include "media/base/bitstream_buffer.h" |
| 14 #include "media/base/limits.h" | 14 #include "media/base/limits.h" |
| 15 #include "media/base/video_decoder_config.h" |
| 15 #include "media/video/picture.h" | 16 #include "media/video/picture.h" |
| 16 #include "ui/gl/android/scoped_java_surface.h" | 17 #include "ui/gl/android/scoped_java_surface.h" |
| 17 #include "ui/gl/android/surface_texture.h" | 18 #include "ui/gl/android/surface_texture.h" |
| 18 #include "ui/gl/gl_bindings.h" | 19 #include "ui/gl/gl_bindings.h" |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 // Helper macros for dealing with failure. If |result| evaluates false, emit | 23 // Helper macros for dealing with failure. If |result| evaluates false, emit |
| 23 // |log| to ERROR, register |error| with the decoder, and return. | 24 // |log| to ERROR, register |error| with the decoder, and return. |
| 24 #define RETURN_ON_FAILURE(result, log, error) \ | 25 #define RETURN_ON_FAILURE(result, log, error) \ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 37 | 38 |
| 38 // TODO(dwkang): We only need kMaxVideoFrames to pass media stack's prerolling | 39 // TODO(dwkang): We only need kMaxVideoFrames to pass media stack's prerolling |
| 39 // phase, but 1 is added due to crbug.com/176036. This should be tuned when we | 40 // phase, but 1 is added due to crbug.com/176036. This should be tuned when we |
| 40 // have actual use case. | 41 // have actual use case. |
| 41 enum { kNumPictureBuffers = media::limits::kMaxVideoFrames + 1 }; | 42 enum { kNumPictureBuffers = media::limits::kMaxVideoFrames + 1 }; |
| 42 | 43 |
| 43 // Max number of bitstreams notified to the client with | 44 // Max number of bitstreams notified to the client with |
| 44 // NotifyEndOfBitstreamBuffer() before getting output from the bitstream. | 45 // NotifyEndOfBitstreamBuffer() before getting output from the bitstream. |
| 45 enum { kMaxBitstreamsNotifiedInAdvance = 32 }; | 46 enum { kMaxBitstreamsNotifiedInAdvance = 32 }; |
| 46 | 47 |
| 48 #if defined(ENABLE_MEDIA_PIPELINE_ON_ANDROID) |
| 49 // MediaCodec is only guaranteed to support baseline, but some devices may |
| 50 // support others. Advertise support for all H264 profiles and let the |
| 51 // MediaCodec fail when decoding if it's not actually supported. It's assumed |
| 52 // that consumers won't have software fallback for H264 on Android anyway. |
| 53 static const media::VideoCodecProfile kSupportedH264Profiles[] = { |
| 54 media::H264PROFILE_BASELINE, |
| 55 media::H264PROFILE_MAIN, |
| 56 media::H264PROFILE_EXTENDED, |
| 57 media::H264PROFILE_HIGH, |
| 58 media::H264PROFILE_HIGH10PROFILE, |
| 59 media::H264PROFILE_HIGH422PROFILE, |
| 60 media::H264PROFILE_HIGH444PREDICTIVEPROFILE, |
| 61 media::H264PROFILE_SCALABLEBASELINE, |
| 62 media::H264PROFILE_SCALABLEHIGH, |
| 63 media::H264PROFILE_STEREOHIGH, |
| 64 media::H264PROFILE_MULTIVIEWHIGH |
| 65 }; |
| 66 #endif |
| 67 |
| 47 // Because MediaCodec is thread-hostile (must be poked on a single thread) and | 68 // Because MediaCodec is thread-hostile (must be poked on a single thread) and |
| 48 // has no callback mechanism (b/11990118), we must drive it by polling for | 69 // has no callback mechanism (b/11990118), we must drive it by polling for |
| 49 // complete frames (and available input buffers, when the codec is fully | 70 // complete frames (and available input buffers, when the codec is fully |
| 50 // saturated). This function defines the polling delay. The value used is an | 71 // saturated). This function defines the polling delay. The value used is an |
| 51 // arbitrary choice that trades off CPU utilization (spinning) against latency. | 72 // arbitrary choice that trades off CPU utilization (spinning) against latency. |
| 52 // Mirrors android_video_encode_accelerator.cc:EncodePollDelay(). | 73 // Mirrors android_video_encode_accelerator.cc:EncodePollDelay(). |
| 53 static inline const base::TimeDelta DecodePollDelay() { | 74 static inline const base::TimeDelta DecodePollDelay() { |
| 54 // An alternative to this polling scheme could be to dedicate a new thread | 75 // An alternative to this polling scheme could be to dedicate a new thread |
| 55 // (instead of using the ChildThread) to run the MediaCodec, and make that | 76 // (instead of using the ChildThread) to run the MediaCodec, and make that |
| 56 // thread use the timeout-based flavor of MediaCodec's dequeue methods when it | 77 // thread use the timeout-based flavor of MediaCodec's dequeue methods when it |
| (...skipping 24 matching lines...) Expand all Loading... |
| 81 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { | 102 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { |
| 82 DCHECK(thread_checker_.CalledOnValidThread()); | 103 DCHECK(thread_checker_.CalledOnValidThread()); |
| 83 } | 104 } |
| 84 | 105 |
| 85 bool AndroidVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, | 106 bool AndroidVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, |
| 86 Client* client) { | 107 Client* client) { |
| 87 DCHECK(!media_codec_); | 108 DCHECK(!media_codec_); |
| 88 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
| 89 | 110 |
| 90 client_ = client; | 111 client_ = client; |
| 112 codec_ = VideoCodecProfileToVideoCodec(profile); |
| 91 | 113 |
| 92 if (profile == media::VP8PROFILE_ANY) { | 114 bool profile_supported = codec_ == media::kCodecVP8; |
| 93 codec_ = media::kCodecVP8; | 115 #if defined(ENABLE_MEDIA_PIPELINE_ON_ANDROID) |
| 94 } else { | 116 profile_supported |= |
| 95 // TODO(dwkang): enable H264 once b/8125974 is fixed. | 117 (codec_ == media::kCodecVP9 || codec_ == media::kCodecH264); |
| 118 #endif |
| 119 |
| 120 if (!profile_supported) { |
| 96 LOG(ERROR) << "Unsupported profile: " << profile; | 121 LOG(ERROR) << "Unsupported profile: " << profile; |
| 97 return false; | 122 return false; |
| 98 } | 123 } |
| 99 | 124 |
| 100 // Only consider using MediaCodec if it's likely backed by hardware. | 125 // Only use MediaCodec for VP8/9 if it's likely backed by hardware. |
| 101 if (media::VideoCodecBridge::IsKnownUnaccelerated( | 126 if ((codec_ == media::kCodecVP8 || codec_ == media::kCodecVP9) && |
| 127 media::VideoCodecBridge::IsKnownUnaccelerated( |
| 102 codec_, media::MEDIA_CODEC_DECODER)) { | 128 codec_, media::MEDIA_CODEC_DECODER)) { |
| 129 DVLOG(1) << "Initialization failed: " |
| 130 << (codec_ == media::kCodecVP8 ? "vp8" : "vp9") |
| 131 << " is not hardware accelerated"; |
| 103 return false; | 132 return false; |
| 104 } | 133 } |
| 105 | 134 |
| 106 if (!make_context_current_.Run()) { | 135 if (!make_context_current_.Run()) { |
| 107 LOG(ERROR) << "Failed to make this decoder's GL context current."; | 136 LOG(ERROR) << "Failed to make this decoder's GL context current."; |
| 108 return false; | 137 return false; |
| 109 } | 138 } |
| 110 | 139 |
| 111 if (!gl_decoder_) { | 140 if (!gl_decoder_) { |
| 112 LOG(ERROR) << "Failed to get gles2 decoder instance."; | 141 LOG(ERROR) << "Failed to get gles2 decoder instance."; |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 580 |
| 552 void AndroidVideoDecodeAccelerator::NotifyError( | 581 void AndroidVideoDecodeAccelerator::NotifyError( |
| 553 media::VideoDecodeAccelerator::Error error) { | 582 media::VideoDecodeAccelerator::Error error) { |
| 554 client_->NotifyError(error); | 583 client_->NotifyError(error); |
| 555 } | 584 } |
| 556 | 585 |
| 557 // static | 586 // static |
| 558 media::VideoDecodeAccelerator::SupportedProfiles | 587 media::VideoDecodeAccelerator::SupportedProfiles |
| 559 AndroidVideoDecodeAccelerator::GetSupportedProfiles() { | 588 AndroidVideoDecodeAccelerator::GetSupportedProfiles() { |
| 560 SupportedProfiles profiles; | 589 SupportedProfiles profiles; |
| 561 if (media::VideoCodecBridge::IsKnownUnaccelerated( | 590 |
| 591 if (!media::VideoCodecBridge::IsKnownUnaccelerated( |
| 562 media::kCodecVP8, media::MEDIA_CODEC_DECODER)) { | 592 media::kCodecVP8, media::MEDIA_CODEC_DECODER)) { |
| 563 return profiles; | 593 SupportedProfile profile; |
| 594 profile.profile = media::VP8PROFILE_ANY; |
| 595 profile.min_resolution.SetSize(0, 0); |
| 596 profile.max_resolution.SetSize(1920, 1088); |
| 597 profiles.push_back(profile); |
| 564 } | 598 } |
| 565 SupportedProfile profile; | 599 |
| 566 profile.profile = media::VP8PROFILE_ANY; | 600 #if defined(ENABLE_MEDIA_PIPELINE_ON_ANDROID) |
| 567 profile.min_resolution.SetSize(16, 16); | 601 if (!media::VideoCodecBridge::IsKnownUnaccelerated( |
| 568 profile.max_resolution.SetSize(1920, 1088); | 602 media::kCodecVP9, media::MEDIA_CODEC_DECODER)) { |
| 569 profiles.push_back(profile); | 603 SupportedProfile profile; |
| 604 profile.profile = media::VP9PROFILE_ANY; |
| 605 profile.min_resolution.SetSize(0, 0); |
| 606 profile.max_resolution.SetSize(1920, 1088); |
| 607 profiles.push_back(profile); |
| 608 } |
| 609 |
| 610 for (const auto& supported_profile : kSupportedH264Profiles) { |
| 611 SupportedProfile profile; |
| 612 profile.profile = supported_profile; |
| 613 profile.min_resolution.SetSize(0, 0); |
| 614 // Advertise support for 4k and let the MediaCodec fail when decoding if it |
| 615 // doesn't support the resolution. It's assumed that consumers won't have |
| 616 // software fallback for H264 on Android anyway. |
| 617 profile.max_resolution.SetSize(3840, 2160); |
| 618 profiles.push_back(profile); |
| 619 } |
| 620 #endif |
| 621 |
| 570 return profiles; | 622 return profiles; |
| 571 } | 623 } |
| 572 | 624 |
| 573 } // namespace content | 625 } // namespace content |
| OLD | NEW |