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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { | 82 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { |
82 DCHECK(thread_checker_.CalledOnValidThread()); | 83 DCHECK(thread_checker_.CalledOnValidThread()); |
83 } | 84 } |
84 | 85 |
85 bool AndroidVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, | 86 bool AndroidVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, |
86 Client* client) { | 87 Client* client) { |
87 DCHECK(!media_codec_); | 88 DCHECK(!media_codec_); |
88 DCHECK(thread_checker_.CalledOnValidThread()); | 89 DCHECK(thread_checker_.CalledOnValidThread()); |
89 | 90 |
90 client_ = client; | 91 client_ = client; |
92 codec_ = VideoCodecProfileToVideoCodec(profile); | |
93 if (codec_ != media::kCodecVP8 && codec_ != media::kCodecVP9 && | |
94 codec_ != media::kCodecH264) { | |
95 DVLOG(1) << "Unsupported profile: " << profile; | |
sandersd (OOO until July 31)
2015/08/08 00:17:44
return false;
| |
96 } | |
91 | 97 |
92 if (profile == media::VP8PROFILE_ANY) { | 98 // Only use MediaCodec for VP8/9 if it's likely backed by hardware. |
93 codec_ = media::kCodecVP8; | 99 if ((codec_ == media::kCodecVP8 || codec_ == media::kCodecVP9) && |
94 } else { | 100 media::VideoCodecBridge::IsKnownUnaccelerated( |
95 // TODO(dwkang): enable H264 once b/8125974 is fixed. | 101 codec_, media::MEDIA_CODEC_DECODER)) { |
96 LOG(ERROR) << "Unsupported profile: " << profile; | 102 DVLOG(1) << "Initialization failed because the " |
103 << (codec_ == media::kCodecVP8 ? "vp8" : "vp9") | |
104 << " decoder is not hardware accelerated"; | |
97 return false; | 105 return false; |
98 } | 106 } |
99 | 107 |
100 // Only consider using MediaCodec if it's likely backed by hardware. | |
101 if (media::VideoCodecBridge::IsKnownUnaccelerated( | |
102 codec_, media::MEDIA_CODEC_DECODER)) { | |
103 return false; | |
104 } | |
105 | |
106 if (!make_context_current_.Run()) { | 108 if (!make_context_current_.Run()) { |
107 LOG(ERROR) << "Failed to make this decoder's GL context current."; | 109 LOG(ERROR) << "Failed to make this decoder's GL context current."; |
108 return false; | 110 return false; |
109 } | 111 } |
110 | 112 |
111 if (!gl_decoder_) { | 113 if (!gl_decoder_) { |
112 LOG(ERROR) << "Failed to get gles2 decoder instance."; | 114 LOG(ERROR) << "Failed to get gles2 decoder instance."; |
113 return false; | 115 return false; |
114 } | 116 } |
115 glGenTextures(1, &surface_texture_id_); | 117 glGenTextures(1, &surface_texture_id_); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 | 553 |
552 void AndroidVideoDecodeAccelerator::NotifyError( | 554 void AndroidVideoDecodeAccelerator::NotifyError( |
553 media::VideoDecodeAccelerator::Error error) { | 555 media::VideoDecodeAccelerator::Error error) { |
554 client_->NotifyError(error); | 556 client_->NotifyError(error); |
555 } | 557 } |
556 | 558 |
557 // static | 559 // static |
558 media::VideoDecodeAccelerator::SupportedProfiles | 560 media::VideoDecodeAccelerator::SupportedProfiles |
559 AndroidVideoDecodeAccelerator::GetSupportedProfiles() { | 561 AndroidVideoDecodeAccelerator::GetSupportedProfiles() { |
560 SupportedProfiles profiles; | 562 SupportedProfiles profiles; |
561 if (media::VideoCodecBridge::IsKnownUnaccelerated( | 563 |
564 if (!media::VideoCodecBridge::IsKnownUnaccelerated( | |
562 media::kCodecVP8, media::MEDIA_CODEC_DECODER)) { | 565 media::kCodecVP8, media::MEDIA_CODEC_DECODER)) { |
563 return profiles; | 566 SupportedProfile profile; |
567 profile.profile = media::VP8PROFILE_ANY; | |
568 profile.min_resolution.SetSize(0, 0); | |
569 profile.max_resolution.SetSize(3840, 2160); | |
570 profiles.push_back(profile); | |
564 } | 571 } |
572 | |
573 if (!media::VideoCodecBridge::IsKnownUnaccelerated( | |
574 media::kCodecVP9, media::MEDIA_CODEC_DECODER)) { | |
575 SupportedProfile profile; | |
576 profile.profile = media::VP9PROFILE_ANY; | |
577 profile.min_resolution.SetSize(0, 0); | |
578 profile.max_resolution.SetSize(3840, 2160); | |
579 profiles.push_back(profile); | |
580 } | |
581 | |
565 SupportedProfile profile; | 582 SupportedProfile profile; |
566 profile.profile = media::VP8PROFILE_ANY; | 583 // MediaCodec is only guaranteed to support the baseline profile. |
567 profile.min_resolution.SetSize(16, 16); | 584 profile.profile = media::H264PROFILE_BASELINE; |
568 profile.max_resolution.SetSize(1920, 1088); | 585 profile.min_resolution.SetSize(0, 0); |
586 profile.max_resolution.SetSize(3840, 2160); | |
569 profiles.push_back(profile); | 587 profiles.push_back(profile); |
588 | |
570 return profiles; | 589 return profiles; |
571 } | 590 } |
572 | 591 |
573 } // namespace content | 592 } // namespace content |
OLD | NEW |