| 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 "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "content/common/gpu/gpu_channel.h" | 12 #include "content/common/gpu/gpu_channel.h" |
| 13 #include "content/common/gpu/media/android_copying_backing_strategy.h" |
| 14 #include "content/common/gpu/media/android_deferred_rendering_backing_strategy.h
" |
| 13 #include "content/common/gpu/media/avda_return_on_failure.h" | 15 #include "content/common/gpu/media/avda_return_on_failure.h" |
| 14 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 16 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 15 #include "media/base/bitstream_buffer.h" | 17 #include "media/base/bitstream_buffer.h" |
| 16 #include "media/base/limits.h" | 18 #include "media/base/limits.h" |
| 17 #include "media/base/timestamp_constants.h" | 19 #include "media/base/timestamp_constants.h" |
| 18 #include "media/base/video_decoder_config.h" | 20 #include "media/base/video_decoder_config.h" |
| 19 #include "media/video/picture.h" | 21 #include "media/video/picture.h" |
| 20 #include "ui/gl/android/scoped_java_surface.h" | 22 #include "ui/gl/android/scoped_java_surface.h" |
| 21 #include "ui/gl/android/surface_texture.h" | 23 #include "ui/gl/android/surface_texture.h" |
| 22 #include "ui/gl/gl_bindings.h" | 24 #include "ui/gl/gl_bindings.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 43 media::H264PROFILE_EXTENDED, | 45 media::H264PROFILE_EXTENDED, |
| 44 media::H264PROFILE_HIGH, | 46 media::H264PROFILE_HIGH, |
| 45 media::H264PROFILE_HIGH10PROFILE, | 47 media::H264PROFILE_HIGH10PROFILE, |
| 46 media::H264PROFILE_HIGH422PROFILE, | 48 media::H264PROFILE_HIGH422PROFILE, |
| 47 media::H264PROFILE_HIGH444PREDICTIVEPROFILE, | 49 media::H264PROFILE_HIGH444PREDICTIVEPROFILE, |
| 48 media::H264PROFILE_SCALABLEBASELINE, | 50 media::H264PROFILE_SCALABLEBASELINE, |
| 49 media::H264PROFILE_SCALABLEHIGH, | 51 media::H264PROFILE_SCALABLEHIGH, |
| 50 media::H264PROFILE_STEREOHIGH, | 52 media::H264PROFILE_STEREOHIGH, |
| 51 media::H264PROFILE_MULTIVIEWHIGH | 53 media::H264PROFILE_MULTIVIEWHIGH |
| 52 }; | 54 }; |
| 55 |
| 56 #define BACKING_STRATEGY AndroidDeferredRenderingBackingStrategy |
| 57 #else |
| 58 #define BACKING_STRATEGY AndroidCopyingBackingStrategy |
| 53 #endif | 59 #endif |
| 54 | 60 |
| 55 // Because MediaCodec is thread-hostile (must be poked on a single thread) and | 61 // Because MediaCodec is thread-hostile (must be poked on a single thread) and |
| 56 // has no callback mechanism (b/11990118), we must drive it by polling for | 62 // has no callback mechanism (b/11990118), we must drive it by polling for |
| 57 // complete frames (and available input buffers, when the codec is fully | 63 // complete frames (and available input buffers, when the codec is fully |
| 58 // saturated). This function defines the polling delay. The value used is an | 64 // saturated). This function defines the polling delay. The value used is an |
| 59 // arbitrary choice that trades off CPU utilization (spinning) against latency. | 65 // arbitrary choice that trades off CPU utilization (spinning) against latency. |
| 60 // Mirrors android_video_encode_accelerator.cc:EncodePollDelay(). | 66 // Mirrors android_video_encode_accelerator.cc:EncodePollDelay(). |
| 61 static inline const base::TimeDelta DecodePollDelay() { | 67 static inline const base::TimeDelta DecodePollDelay() { |
| 62 // An alternative to this polling scheme could be to dedicate a new thread | 68 // An alternative to this polling scheme could be to dedicate a new thread |
| 63 // (instead of using the ChildThread) to run the MediaCodec, and make that | 69 // (instead of using the ChildThread) to run the MediaCodec, and make that |
| 64 // thread use the timeout-based flavor of MediaCodec's dequeue methods when it | 70 // thread use the timeout-based flavor of MediaCodec's dequeue methods when it |
| 65 // believes the codec should complete "soon" (e.g. waiting for an input | 71 // believes the codec should complete "soon" (e.g. waiting for an input |
| 66 // buffer, or waiting for a picture when it knows enough complete input | 72 // buffer, or waiting for a picture when it knows enough complete input |
| 67 // pictures have been fed to saturate any internal buffering). This is | 73 // pictures have been fed to saturate any internal buffering). This is |
| 68 // speculative and it's unclear that this would be a win (nor that there's a | 74 // speculative and it's unclear that this would be a win (nor that there's a |
| 69 // reasonably device-agnostic way to fill in the "believes" above). | 75 // reasonably device-agnostic way to fill in the "believes" above). |
| 70 return base::TimeDelta::FromMilliseconds(10); | 76 return base::TimeDelta::FromMilliseconds(10); |
| 71 } | 77 } |
| 72 | 78 |
| 73 static inline const base::TimeDelta NoWaitTimeOut() { | 79 static inline const base::TimeDelta NoWaitTimeOut() { |
| 74 return base::TimeDelta::FromMicroseconds(0); | 80 return base::TimeDelta::FromMicroseconds(0); |
| 75 } | 81 } |
| 76 | 82 |
| 77 AndroidVideoDecodeAccelerator::AndroidVideoDecodeAccelerator( | 83 AndroidVideoDecodeAccelerator::AndroidVideoDecodeAccelerator( |
| 78 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, | 84 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, |
| 79 const base::Callback<bool(void)>& make_context_current, | 85 const base::Callback<bool(void)>& make_context_current) |
| 80 scoped_ptr<BackingStrategy> strategy) | |
| 81 : client_(NULL), | 86 : client_(NULL), |
| 82 make_context_current_(make_context_current), | 87 make_context_current_(make_context_current), |
| 83 codec_(media::kCodecH264), | 88 codec_(media::kCodecH264), |
| 84 state_(NO_ERROR), | 89 state_(NO_ERROR), |
| 85 picturebuffers_requested_(false), | 90 picturebuffers_requested_(false), |
| 86 gl_decoder_(decoder), | 91 gl_decoder_(decoder), |
| 87 strategy_(strategy.Pass()), | 92 strategy_(new BACKING_STRATEGY()), |
| 88 weak_this_factory_(this) {} | 93 weak_this_factory_(this) {} |
| 89 | 94 |
| 90 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { | 95 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { |
| 91 DCHECK(thread_checker_.CalledOnValidThread()); | 96 DCHECK(thread_checker_.CalledOnValidThread()); |
| 92 } | 97 } |
| 93 | 98 |
| 94 bool AndroidVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, | 99 bool AndroidVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, |
| 95 Client* client) { | 100 Client* client) { |
| 96 DCHECK(!media_codec_); | 101 DCHECK(!media_codec_); |
| 97 DCHECK(thread_checker_.CalledOnValidThread()); | 102 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 void AndroidVideoDecodeAccelerator::NotifyResetDone() { | 627 void AndroidVideoDecodeAccelerator::NotifyResetDone() { |
| 623 client_->NotifyResetDone(); | 628 client_->NotifyResetDone(); |
| 624 } | 629 } |
| 625 | 630 |
| 626 void AndroidVideoDecodeAccelerator::NotifyError( | 631 void AndroidVideoDecodeAccelerator::NotifyError( |
| 627 media::VideoDecodeAccelerator::Error error) { | 632 media::VideoDecodeAccelerator::Error error) { |
| 628 client_->NotifyError(error); | 633 client_->NotifyError(error); |
| 629 } | 634 } |
| 630 | 635 |
| 631 // static | 636 // static |
| 632 media::VideoDecodeAccelerator::SupportedProfiles | 637 media::VideoDecodeAccelerator::Capabilities |
| 633 AndroidVideoDecodeAccelerator::GetSupportedProfiles() { | 638 AndroidVideoDecodeAccelerator::GetCapabilities() { |
| 634 SupportedProfiles profiles; | 639 Capabilities capabilities; |
| 640 SupportedProfiles& profiles = capabilities.supported_profiles; |
| 635 | 641 |
| 636 if (!media::VideoCodecBridge::IsKnownUnaccelerated( | 642 if (!media::VideoCodecBridge::IsKnownUnaccelerated( |
| 637 media::kCodecVP8, media::MEDIA_CODEC_DECODER)) { | 643 media::kCodecVP8, media::MEDIA_CODEC_DECODER)) { |
| 638 SupportedProfile profile; | 644 SupportedProfile profile; |
| 639 profile.profile = media::VP8PROFILE_ANY; | 645 profile.profile = media::VP8PROFILE_ANY; |
| 640 profile.min_resolution.SetSize(0, 0); | 646 profile.min_resolution.SetSize(0, 0); |
| 641 profile.max_resolution.SetSize(1920, 1088); | 647 profile.max_resolution.SetSize(1920, 1088); |
| 642 profiles.push_back(profile); | 648 profiles.push_back(profile); |
| 643 } | 649 } |
| 644 | 650 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 657 profile.profile = supported_profile; | 663 profile.profile = supported_profile; |
| 658 profile.min_resolution.SetSize(0, 0); | 664 profile.min_resolution.SetSize(0, 0); |
| 659 // Advertise support for 4k and let the MediaCodec fail when decoding if it | 665 // Advertise support for 4k and let the MediaCodec fail when decoding if it |
| 660 // doesn't support the resolution. It's assumed that consumers won't have | 666 // doesn't support the resolution. It's assumed that consumers won't have |
| 661 // software fallback for H264 on Android anyway. | 667 // software fallback for H264 on Android anyway. |
| 662 profile.max_resolution.SetSize(3840, 2160); | 668 profile.max_resolution.SetSize(3840, 2160); |
| 663 profiles.push_back(profile); | 669 profiles.push_back(profile); |
| 664 } | 670 } |
| 665 #endif | 671 #endif |
| 666 | 672 |
| 667 return profiles; | 673 capabilities.flags = BACKING_STRATEGY::GetCapabilitiesFlags(); |
| 674 |
| 675 return capabilities; |
| 668 } | 676 } |
| 669 | 677 |
| 670 } // namespace content | 678 } // namespace content |
| OLD | NEW |