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

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: Remove COLOR_FORMAT_UNKNOWN. 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
« no previous file with comments | « no previous file | media/base/android/java/src/org/chromium/media/MediaCodecBridge.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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,
32 }; 35 };
33 36
34 // Helper macros for dealing with failure. If |result| evaluates false, emit 37 // Helper macros for dealing with failure. If |result| evaluates false, emit
35 // |log| to DLOG(ERROR), register |error| with the client, and return. 38 // |log| to DLOG(ERROR), register |error| with the client, and return.
36 #define RETURN_ON_FAILURE(result, log, error) \ 39 #define RETURN_ON_FAILURE(result, log, error) \
37 do { \ 40 do { \
38 if (!(result)) { \ 41 if (!(result)) { \
39 DLOG(ERROR) << log; \ 42 DLOG(ERROR) << log; \
40 if (client_ptr_factory_->GetWeakPtr()) { \ 43 if (client_ptr_factory_->GetWeakPtr()) { \
(...skipping 19 matching lines...) Expand all
60 // pictures have been fed to saturate any internal buffering). This is 63 // 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 64 // 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). 65 // reasonably device-agnostic way to fill in the "believes" above).
63 return base::TimeDelta::FromMilliseconds(10); 66 return base::TimeDelta::FromMilliseconds(10);
64 } 67 }
65 68
66 static inline const base::TimeDelta NoWaitTimeOut() { 69 static inline const base::TimeDelta NoWaitTimeOut() {
67 return base::TimeDelta::FromMicroseconds(0); 70 return base::TimeDelta::FromMicroseconds(0);
68 } 71 }
69 72
73 static bool GetSupportedColorFormatForMime(const std::string& mime,
74 PixelFormat* pixel_format) {
75 std::set<int> formats = MediaCodecBridge::GetEncoderColorFormats(mime);
76 if (formats.find(COLOR_FORMAT_YUV420_SEMIPLANAR) == formats.end() &&
77 formats.find(COLOR_FORMAT_YUV420_PLANAR) == formats.end())
78 return false;
79
80 *pixel_format = formats.find(COLOR_FORMAT_YUV420_SEMIPLANAR) != formats.end()
81 ? COLOR_FORMAT_YUV420_SEMIPLANAR
82 : COLOR_FORMAT_YUV420_PLANAR;
Pawel Osciak 2014/10/20 08:10:24 Perhaps: if (formats.count(COLOR_FORMAT_YUV420_SE
changbin 2014/10/20 14:45:47 Done.
83 return true;
84 }
85
70 AndroidVideoEncodeAccelerator::AndroidVideoEncodeAccelerator() 86 AndroidVideoEncodeAccelerator::AndroidVideoEncodeAccelerator()
71 : num_buffers_at_codec_(0), 87 : num_buffers_at_codec_(0),
72 num_output_buffers_(-1), 88 num_output_buffers_(-1),
73 output_buffers_capacity_(0), 89 output_buffers_capacity_(0),
74 last_set_bitrate_(0) {} 90 last_set_bitrate_(0) {}
75 91
76 AndroidVideoEncodeAccelerator::~AndroidVideoEncodeAccelerator() { 92 AndroidVideoEncodeAccelerator::~AndroidVideoEncodeAccelerator() {
77 DCHECK(thread_checker_.CalledOnValidThread()); 93 DCHECK(thread_checker_.CalledOnValidThread());
78 } 94 }
79 95
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 151
136 last_set_bitrate_ = initial_bitrate; 152 last_set_bitrate_ = initial_bitrate;
137 153
138 // Only consider using MediaCodec if it's likely backed by hardware. 154 // Only consider using MediaCodec if it's likely backed by hardware.
139 if (media::VideoCodecBridge::IsKnownUnaccelerated( 155 if (media::VideoCodecBridge::IsKnownUnaccelerated(
140 media::kCodecVP8, media::MEDIA_CODEC_ENCODER)) { 156 media::kCodecVP8, media::MEDIA_CODEC_ENCODER)) {
141 DLOG(ERROR) << "No HW support"; 157 DLOG(ERROR) << "No HW support";
142 return false; 158 return false;
143 } 159 }
144 160
145 // TODO(fischman): when there is more HW out there with different color-space 161 PixelFormat pixel_format = COLOR_FORMAT_YUV420_SEMIPLANAR;
146 // support, this should turn into a negotiation with the codec for supported 162 if (!GetSupportedColorFormatForMime("video/x-vnd.on2.vp8", &pixel_format)) {
147 // formats. For now we use the only format supported by the only available 163 DLOG(ERROR) << "No color format support.";
148 // HW. 164 return false;
149 media_codec_.reset( 165 }
150 media::VideoCodecBridge::CreateEncoder(media::kCodecVP8, 166 media_codec_.reset(media::VideoCodecBridge::CreateEncoder(media::kCodecVP8,
151 input_visible_size, 167 input_visible_size,
152 initial_bitrate, 168 initial_bitrate,
153 INITIAL_FRAMERATE, 169 INITIAL_FRAMERATE,
154 IFRAME_INTERVAL, 170 IFRAME_INTERVAL,
155 COLOR_FORMAT_YUV420_SEMIPLANAR)); 171 pixel_format));
156 172
157 if (!media_codec_) { 173 if (!media_codec_) {
158 DLOG(ERROR) << "Failed to create/start the codec: " 174 DLOG(ERROR) << "Failed to create/start the codec: "
159 << input_visible_size.ToString(); 175 << input_visible_size.ToString();
160 return false; 176 return false;
161 } 177 }
162 178
163 num_output_buffers_ = media_codec_->GetOutputBuffersCount(); 179 num_output_buffers_ = media_codec_->GetOutputBuffersCount();
164 output_buffers_capacity_ = media_codec_->GetOutputBuffersCapacity(); 180 output_buffers_capacity_ = media_codec_->GetOutputBuffersCapacity();
165 base::MessageLoop::current()->PostTask( 181 base::MessageLoop::current()->PostTask(
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 base::MessageLoop::current()->PostTask( 419 base::MessageLoop::current()->PostTask(
404 FROM_HERE, 420 FROM_HERE,
405 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, 421 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady,
406 client_ptr_factory_->GetWeakPtr(), 422 client_ptr_factory_->GetWeakPtr(),
407 bitstream_buffer.id(), 423 bitstream_buffer.id(),
408 size, 424 size,
409 key_frame)); 425 key_frame));
410 } 426 }
411 427
412 } // namespace content 428 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | media/base/android/java/src/org/chromium/media/MediaCodecBridge.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698