Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: content/common/gpu/media/android_video_encode_accelerator.cc

Issue 648613003: Add support for color formats negotiation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update per mcasas's comments. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm>
8 #include <vector>
9
7 #include "base/bind.h" 10 #include "base/bind.h"
8 #include "base/command_line.h" 11 #include "base/command_line.h"
9 #include "base/logging.h" 12 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
11 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
12 #include "content/common/gpu/gpu_channel.h" 15 #include "content/common/gpu/gpu_channel.h"
13 #include "content/public/common/content_switches.h" 16 #include "content/public/common/content_switches.h"
14 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 17 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
15 #include "media/base/android/media_codec_bridge.h" 18 #include "media/base/android/media_codec_bridge.h"
16 #include "media/base/bitstream_buffer.h" 19 #include "media/base/bitstream_buffer.h"
17 #include "media/base/limits.h" 20 #include "media/base/limits.h"
18 #include "media/video/picture.h" 21 #include "media/video/picture.h"
19 #include "third_party/libyuv/include/libyuv/convert_from.h" 22 #include "third_party/libyuv/include/libyuv/convert_from.h"
20 #include "ui/gl/android/scoped_java_surface.h" 23 #include "ui/gl/android/scoped_java_surface.h"
21 #include "ui/gl/gl_bindings.h" 24 #include "ui/gl/gl_bindings.h"
22 25
23 using media::MediaCodecBridge; 26 using media::MediaCodecBridge;
24 using media::VideoCodecBridge; 27 using media::VideoCodecBridge;
25 using media::VideoFrame; 28 using media::VideoFrame;
26 29
27 namespace content { 30 namespace content {
28 31
29 enum { 32 enum PixelFormat {
30 // Subset of MediaCodecInfo.CodecCapabilities. 33 // Subset of MediaCodecInfo.CodecCapabilities.
34 COLOR_FORMAT_YUV420_PLANAR = 19,
31 COLOR_FORMAT_YUV420_SEMIPLANAR = 21, 35 COLOR_FORMAT_YUV420_SEMIPLANAR = 21,
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()) { \
(...skipping 19 matching lines...) Expand all
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::vector<int> formats = MediaCodecBridge::GetEncoderColorFormats(mime);
76 if (std::find(formats.begin(), formats.end(), COLOR_FORMAT_YUV420_PLANAR) !=
77 formats.end())
xhwang 2014/10/13 17:37:35 nit: Seems like GetEncoderColorFormats() should re
changbin 2014/10/15 02:17:10 Done.
78 return COLOR_FORMAT_YUV420_PLANAR;
79 return COLOR_FORMAT_YUV420_SEMIPLANAR;
xhwang 2014/10/13 17:37:35 Is COLOR_FORMAT_YUV420_SEMIPLANAR always supported
changbin 2014/10/15 02:17:10 Thanks for pointing this out:) I think COLOR_FORMA
80 }
81
70 AndroidVideoEncodeAccelerator::AndroidVideoEncodeAccelerator() 82 AndroidVideoEncodeAccelerator::AndroidVideoEncodeAccelerator()
71 : num_buffers_at_codec_(0), 83 : num_buffers_at_codec_(0),
72 num_output_buffers_(-1), 84 num_output_buffers_(-1),
73 output_buffers_capacity_(0), 85 output_buffers_capacity_(0),
74 last_set_bitrate_(0) {} 86 last_set_bitrate_(0) {}
75 87
76 AndroidVideoEncodeAccelerator::~AndroidVideoEncodeAccelerator() { 88 AndroidVideoEncodeAccelerator::~AndroidVideoEncodeAccelerator() {
77 DCHECK(thread_checker_.CalledOnValidThread()); 89 DCHECK(thread_checker_.CalledOnValidThread());
78 } 90 }
79 91
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 147
136 last_set_bitrate_ = initial_bitrate; 148 last_set_bitrate_ = initial_bitrate;
137 149
138 // Only consider using MediaCodec if it's likely backed by hardware. 150 // Only consider using MediaCodec if it's likely backed by hardware.
139 if (media::VideoCodecBridge::IsKnownUnaccelerated( 151 if (media::VideoCodecBridge::IsKnownUnaccelerated(
140 media::kCodecVP8, media::MEDIA_CODEC_ENCODER)) { 152 media::kCodecVP8, media::MEDIA_CODEC_ENCODER)) {
141 DLOG(ERROR) << "No HW support"; 153 DLOG(ERROR) << "No HW support";
142 return false; 154 return false;
143 } 155 }
144 156
145 // TODO(fischman): when there is more HW out there with different color-space 157 media_codec_.reset(media::VideoCodecBridge::CreateEncoder(
146 // support, this should turn into a negotiation with the codec for supported 158 media::kCodecVP8,
147 // formats. For now we use the only format supported by the only available 159 input_visible_size,
148 // HW. 160 initial_bitrate,
149 media_codec_.reset( 161 INITIAL_FRAMERATE,
150 media::VideoCodecBridge::CreateEncoder(media::kCodecVP8, 162 IFRAME_INTERVAL,
151 input_visible_size, 163 GetSupportedColorFormatForMime("video/x-vnd.on2.vp8")));
152 initial_bitrate,
153 INITIAL_FRAMERATE,
154 IFRAME_INTERVAL,
155 COLOR_FORMAT_YUV420_SEMIPLANAR));
156 164
157 if (!media_codec_) { 165 if (!media_codec_) {
158 DLOG(ERROR) << "Failed to create/start the codec: " 166 DLOG(ERROR) << "Failed to create/start the codec: "
159 << input_visible_size.ToString(); 167 << input_visible_size.ToString();
160 return false; 168 return false;
161 } 169 }
162 170
163 num_output_buffers_ = media_codec_->GetOutputBuffersCount(); 171 num_output_buffers_ = media_codec_->GetOutputBuffersCount();
164 output_buffers_capacity_ = media_codec_->GetOutputBuffersCapacity(); 172 output_buffers_capacity_ = media_codec_->GetOutputBuffersCapacity();
165 base::MessageLoop::current()->PostTask( 173 base::MessageLoop::current()->PostTask(
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 base::MessageLoop::current()->PostTask( 411 base::MessageLoop::current()->PostTask(
404 FROM_HERE, 412 FROM_HERE,
405 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, 413 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady,
406 client_ptr_factory_->GetWeakPtr(), 414 client_ptr_factory_->GetWeakPtr(),
407 bitstream_buffer.id(), 415 bitstream_buffer.id(),
408 size, 416 size,
409 key_frame)); 417 key_frame));
410 } 418 }
411 419
412 } // namespace content 420 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698