OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_encode_accelerator.h" | 5 #include "content/common/gpu/media/android_video_encode_accelerator.h" |
6 | 6 |
7 #include <set> | |
8 | |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
11 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
12 #include "content/common/gpu/gpu_channel.h" | 14 #include "content/common/gpu/gpu_channel.h" |
13 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.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/android/media_codec_bridge.h" | 17 #include "media/base/android/media_codec_bridge.h" |
16 #include "media/base/bitstream_buffer.h" | 18 #include "media/base/bitstream_buffer.h" |
17 #include "media/base/limits.h" | 19 #include "media/base/limits.h" |
18 #include "media/video/picture.h" | 20 #include "media/video/picture.h" |
19 #include "third_party/libyuv/include/libyuv/convert_from.h" | 21 #include "third_party/libyuv/include/libyuv/convert_from.h" |
20 #include "ui/gl/android/scoped_java_surface.h" | 22 #include "ui/gl/android/scoped_java_surface.h" |
21 #include "ui/gl/gl_bindings.h" | 23 #include "ui/gl/gl_bindings.h" |
22 | 24 |
23 using media::MediaCodecBridge; | 25 using media::MediaCodecBridge; |
24 using media::VideoCodecBridge; | 26 using media::VideoCodecBridge; |
25 using media::VideoFrame; | 27 using media::VideoFrame; |
26 | 28 |
27 namespace content { | 29 namespace content { |
28 | 30 |
29 enum { | 31 enum PixelFormat { |
30 // Subset of MediaCodecInfo.CodecCapabilities. | 32 // Subset of MediaCodecInfo.CodecCapabilities. |
33 COLOR_FORMAT_YUV420_PLANAR = 19, | |
31 COLOR_FORMAT_YUV420_SEMIPLANAR = 21, | 34 COLOR_FORMAT_YUV420_SEMIPLANAR = 21, |
35 COLOR_FORMAT_UNKNOWN, | |
xhwang
2014/10/15 04:15:45
This is confusing because value "22" is a valid on
changbin
2014/10/15 07:00:37
Done.
| |
32 }; | 36 }; |
33 | 37 |
34 // Helper macros for dealing with failure. If |result| evaluates false, emit | 38 // Helper macros for dealing with failure. If |result| evaluates false, emit |
35 // |log| to DLOG(ERROR), register |error| with the client, and return. | 39 // |log| to DLOG(ERROR), register |error| with the client, and return. |
36 #define RETURN_ON_FAILURE(result, log, error) \ | 40 #define RETURN_ON_FAILURE(result, log, error) \ |
37 do { \ | 41 do { \ |
38 if (!(result)) { \ | 42 if (!(result)) { \ |
39 DLOG(ERROR) << log; \ | 43 DLOG(ERROR) << log; \ |
40 if (client_ptr_factory_->GetWeakPtr()) { \ | 44 if (client_ptr_factory_->GetWeakPtr()) { \ |
41 client_ptr_factory_->GetWeakPtr()->NotifyError(error); \ | 45 client_ptr_factory_->GetWeakPtr()->NotifyError(error); \ |
(...skipping 18 matching lines...) Expand all Loading... | |
60 // pictures have been fed to saturate any internal buffering). This is | 64 // pictures have been fed to saturate any internal buffering). This is |
61 // speculative and it's unclear that this would be a win (nor that there's a | 65 // speculative and it's unclear that this would be a win (nor that there's a |
62 // reasonably device-agnostic way to fill in the "believes" above). | 66 // reasonably device-agnostic way to fill in the "believes" above). |
63 return base::TimeDelta::FromMilliseconds(10); | 67 return base::TimeDelta::FromMilliseconds(10); |
64 } | 68 } |
65 | 69 |
66 static inline const base::TimeDelta NoWaitTimeOut() { | 70 static inline const base::TimeDelta NoWaitTimeOut() { |
67 return base::TimeDelta::FromMicroseconds(0); | 71 return base::TimeDelta::FromMicroseconds(0); |
68 } | 72 } |
69 | 73 |
74 static PixelFormat GetSupportedColorFormatForMime(const std::string& mime) { | |
75 std::set<int> formats = MediaCodecBridge::GetEncoderColorFormats(mime); | |
76 if (formats.find(COLOR_FORMAT_YUV420_SEMIPLANAR) != formats.end()) | |
77 return COLOR_FORMAT_YUV420_SEMIPLANAR; | |
78 if (formats.find(COLOR_FORMAT_YUV420_PLANAR) != formats.end()) | |
79 return COLOR_FORMAT_YUV420_PLANAR; | |
80 return COLOR_FORMAT_UNKNOWN; | |
81 } | |
82 | |
70 AndroidVideoEncodeAccelerator::AndroidVideoEncodeAccelerator() | 83 AndroidVideoEncodeAccelerator::AndroidVideoEncodeAccelerator() |
71 : num_buffers_at_codec_(0), | 84 : num_buffers_at_codec_(0), |
72 num_output_buffers_(-1), | 85 num_output_buffers_(-1), |
73 output_buffers_capacity_(0), | 86 output_buffers_capacity_(0), |
74 last_set_bitrate_(0) {} | 87 last_set_bitrate_(0) {} |
75 | 88 |
76 AndroidVideoEncodeAccelerator::~AndroidVideoEncodeAccelerator() { | 89 AndroidVideoEncodeAccelerator::~AndroidVideoEncodeAccelerator() { |
77 DCHECK(thread_checker_.CalledOnValidThread()); | 90 DCHECK(thread_checker_.CalledOnValidThread()); |
78 } | 91 } |
79 | 92 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 | 148 |
136 last_set_bitrate_ = initial_bitrate; | 149 last_set_bitrate_ = initial_bitrate; |
137 | 150 |
138 // Only consider using MediaCodec if it's likely backed by hardware. | 151 // Only consider using MediaCodec if it's likely backed by hardware. |
139 if (media::VideoCodecBridge::IsKnownUnaccelerated( | 152 if (media::VideoCodecBridge::IsKnownUnaccelerated( |
140 media::kCodecVP8, media::MEDIA_CODEC_ENCODER)) { | 153 media::kCodecVP8, media::MEDIA_CODEC_ENCODER)) { |
141 DLOG(ERROR) << "No HW support"; | 154 DLOG(ERROR) << "No HW support"; |
142 return false; | 155 return false; |
143 } | 156 } |
144 | 157 |
145 // TODO(fischman): when there is more HW out there with different color-space | 158 PixelFormat pixel_format = |
146 // support, this should turn into a negotiation with the codec for supported | 159 GetSupportedColorFormatForMime("video/x-vnd.on2.vp8"); |
147 // formats. For now we use the only format supported by the only available | 160 if (pixel_format == COLOR_FORMAT_UNKNOWN) |
148 // HW. | 161 return false; |
149 media_codec_.reset( | 162 media_codec_.reset(media::VideoCodecBridge::CreateEncoder(media::kCodecVP8, |
150 media::VideoCodecBridge::CreateEncoder(media::kCodecVP8, | 163 input_visible_size, |
151 input_visible_size, | 164 initial_bitrate, |
152 initial_bitrate, | 165 INITIAL_FRAMERATE, |
153 INITIAL_FRAMERATE, | 166 IFRAME_INTERVAL, |
154 IFRAME_INTERVAL, | 167 pixel_format)); |
155 COLOR_FORMAT_YUV420_SEMIPLANAR)); | |
156 | 168 |
157 if (!media_codec_) { | 169 if (!media_codec_) { |
158 DLOG(ERROR) << "Failed to create/start the codec: " | 170 DLOG(ERROR) << "Failed to create/start the codec: " |
159 << input_visible_size.ToString(); | 171 << input_visible_size.ToString(); |
160 return false; | 172 return false; |
161 } | 173 } |
162 | 174 |
163 num_output_buffers_ = media_codec_->GetOutputBuffersCount(); | 175 num_output_buffers_ = media_codec_->GetOutputBuffersCount(); |
164 output_buffers_capacity_ = media_codec_->GetOutputBuffersCapacity(); | 176 output_buffers_capacity_ = media_codec_->GetOutputBuffersCapacity(); |
165 base::MessageLoop::current()->PostTask( | 177 base::MessageLoop::current()->PostTask( |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 base::MessageLoop::current()->PostTask( | 415 base::MessageLoop::current()->PostTask( |
404 FROM_HERE, | 416 FROM_HERE, |
405 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, | 417 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, |
406 client_ptr_factory_->GetWeakPtr(), | 418 client_ptr_factory_->GetWeakPtr(), |
407 bitstream_buffer.id(), | 419 bitstream_buffer.id(), |
408 size, | 420 size, |
409 key_frame)); | 421 key_frame)); |
410 } | 422 } |
411 | 423 |
412 } // namespace content | 424 } // namespace content |
OLD | NEW |