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

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

Issue 826663002: Support multiple video decoders and encoders (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nits Created 5 years, 12 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/gpu_video_encode_accelerator.h" 5 #include "content/common/gpu/media/gpu_video_encode_accelerator.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
11 #include "base/message_loop/message_loop_proxy.h" 11 #include "base/message_loop/message_loop_proxy.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "content/common/gpu/gpu_channel.h" 13 #include "content/common/gpu/gpu_channel.h"
14 #include "content/common/gpu/gpu_messages.h" 14 #include "content/common/gpu/gpu_messages.h"
15 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
16 #include "ipc/ipc_message_macros.h" 16 #include "ipc/ipc_message_macros.h"
17 #include "media/base/limits.h" 17 #include "media/base/limits.h"
18 #include "media/base/video_frame.h" 18 #include "media/base/video_frame.h"
19 19
20 #if defined(OS_CHROMEOS) && defined(USE_X11) 20 #if defined(OS_CHROMEOS) && defined(USE_X11)
21 21
22 #if defined(ARCH_CPU_ARMEL) 22 #if defined(ARCH_CPU_ARMEL)
23 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" 23 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h"
24 #elif defined(ARCH_CPU_X86_FAMILY) 24 #elif defined(ARCH_CPU_X86_FAMILY)
25 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h"
25 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" 26 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h"
26 #include "ui/gfx/x/x11_types.h" 27 #include "ui/gfx/x/x11_types.h"
27 #endif 28 #endif
28 29
29 #elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC) 30 #elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
30 #include "content/common/gpu/media/android_video_encode_accelerator.h" 31 #include "content/common/gpu/media/android_video_encode_accelerator.h"
31 #endif 32 #endif
32 33
33 namespace content { 34 namespace content {
34 35
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 if (input_visible_size.width() > media::limits::kMaxDimension || 89 if (input_visible_size.width() > media::limits::kMaxDimension ||
89 input_visible_size.height() > media::limits::kMaxDimension || 90 input_visible_size.height() > media::limits::kMaxDimension ||
90 input_visible_size.GetArea() > media::limits::kMaxCanvas) { 91 input_visible_size.GetArea() > media::limits::kMaxCanvas) {
91 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Initialize(): " 92 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Initialize(): "
92 "input_visible_size " << input_visible_size.ToString() 93 "input_visible_size " << input_visible_size.ToString()
93 << " too large"; 94 << " too large";
94 SendCreateEncoderReply(init_done_msg, false); 95 SendCreateEncoderReply(init_done_msg, false);
95 return; 96 return;
96 } 97 }
97 98
98 encoder_ = CreateEncoder(); 99 encoder_list_ = CreateEncoder();
99 if (!encoder_) { 100 if (!encoder_list_.size()) {
Pawel Osciak 2014/12/26 01:11:35 if (encoder_list_.empty())
henryhsu 2014/12/26 08:40:40 Done.
100 DLOG(ERROR) 101 DLOG(ERROR)
101 << "GpuVideoEncodeAccelerator::Initialize(): VEA creation failed"; 102 << "GpuVideoEncodeAccelerator::Initialize(): VEA creation failed";
102 SendCreateEncoderReply(init_done_msg, false); 103 SendCreateEncoderReply(init_done_msg, false);
103 return; 104 return;
104 } 105 }
105 if (!encoder_->Initialize(input_format, 106 for (size_t i = 0; i < encoder_list_.size(); ++i) {
106 input_visible_size, 107 if (encoder_list_[i]->Initialize(input_format,
107 output_profile, 108 input_visible_size,
Pawel Osciak 2014/12/26 01:11:36 Indent.
henryhsu 2014/12/26 08:40:40 Done.
108 initial_bitrate, 109 output_profile,
109 this)) { 110 initial_bitrate,
110 DLOG(ERROR) 111 this)) {
111 << "GpuVideoEncodeAccelerator::Initialize(): VEA initialization failed"; 112 encoder_ = encoder_list_[i];
Pawel Osciak 2014/12/26 01:11:36 Do we need to keep all the encoders, if we only us
henryhsu 2014/12/26 08:40:40 Done.
112 SendCreateEncoderReply(init_done_msg, false); 113 input_format_ = input_format;
113 return; 114 input_visible_size_ = input_visible_size;
115 SendCreateEncoderReply(init_done_msg, true);
116 return;
117 }
114 } 118 }
115 input_format_ = input_format; 119 encoder_ = NULL;
116 input_visible_size_ = input_visible_size; 120 DLOG(ERROR)
117 SendCreateEncoderReply(init_done_msg, true); 121 << "GpuVideoEncodeAccelerator::Initialize(): VEA initialization failed";
122 SendCreateEncoderReply(init_done_msg, false);
118 } 123 }
119 124
120 bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) { 125 bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) {
121 bool handled = true; 126 bool handled = true;
122 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAccelerator, message) 127 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAccelerator, message)
123 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode, OnEncode) 128 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode, OnEncode)
124 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer, 129 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer,
125 OnUseOutputBitstreamBuffer) 130 OnUseOutputBitstreamBuffer)
126 IPC_MESSAGE_HANDLER( 131 IPC_MESSAGE_HANDLER(
127 AcceleratedVideoEncoderMsg_RequestEncodingParametersChange, 132 AcceleratedVideoEncoderMsg_RequestEncodingParametersChange,
(...skipping 23 matching lines...) Expand all
151 156
152 void GpuVideoEncodeAccelerator::NotifyError( 157 void GpuVideoEncodeAccelerator::NotifyError(
153 media::VideoEncodeAccelerator::Error error) { 158 media::VideoEncodeAccelerator::Error error) {
154 Send(new AcceleratedVideoEncoderHostMsg_NotifyError(host_route_id_, error)); 159 Send(new AcceleratedVideoEncoderHostMsg_NotifyError(host_route_id_, error));
155 } 160 }
156 161
157 void GpuVideoEncodeAccelerator::OnWillDestroyStub() { 162 void GpuVideoEncodeAccelerator::OnWillDestroyStub() {
158 DCHECK(stub_); 163 DCHECK(stub_);
159 stub_->channel()->RemoveRoute(host_route_id_); 164 stub_->channel()->RemoveRoute(host_route_id_);
160 stub_->RemoveDestructionObserver(this); 165 stub_->RemoveDestructionObserver(this);
161 encoder_.reset(); 166 encoder_list_.clear();
162 delete this; 167 delete this;
163 } 168 }
164 169
165 // static 170 // static
166 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> 171 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile>
167 GpuVideoEncodeAccelerator::GetSupportedProfiles() { 172 GpuVideoEncodeAccelerator::GetSupportedProfiles() {
168 scoped_ptr<media::VideoEncodeAccelerator> encoder = CreateEncoder(); 173 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles;
169 if (!encoder) 174 ScopedVector<media::VideoEncodeAccelerator>
Pawel Osciak 2014/12/26 01:11:36 Is the newline needed?
henryhsu 2014/12/26 08:40:40 Done.
175 encoder_list = CreateEncoder();
176 if (!encoder_list.size())
Pawel Osciak 2014/12/26 01:11:36 if empty()
henryhsu 2014/12/26 08:40:40 Done.
170 return std::vector<gpu::VideoEncodeAcceleratorSupportedProfile>(); 177 return std::vector<gpu::VideoEncodeAcceleratorSupportedProfile>();
171 return ConvertMediaToGpuProfiles(encoder->GetSupportedProfiles()); 178 for (size_t i = 0; i < encoder_list.size(); ++i) {
179 std::vector<media::VideoEncodeAccelerator::SupportedProfile>
180 vea_profiles = encoder_list[i]->GetSupportedProfiles();
181 profiles.insert(profiles.end(), vea_profiles.begin(), vea_profiles.end());
Pawel Osciak 2014/12/26 01:11:36 This may result in profiles containing duplicates,
henryhsu 2014/12/26 08:40:40 How to decide which profile should be used when Vi
182 }
183 return ConvertMediaToGpuProfiles(profiles);
172 } 184 }
173 185
186 // static
174 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> 187 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile>
175 GpuVideoEncodeAccelerator::ConvertMediaToGpuProfiles(const std::vector< 188 GpuVideoEncodeAccelerator::ConvertMediaToGpuProfiles(const std::vector<
176 media::VideoEncodeAccelerator::SupportedProfile>& media_profiles) { 189 media::VideoEncodeAccelerator::SupportedProfile>& media_profiles) {
177 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> profiles; 190 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> profiles;
178 for (size_t i = 0; i < media_profiles.size(); i++) { 191 for (size_t i = 0; i < media_profiles.size(); i++) {
179 gpu::VideoEncodeAcceleratorSupportedProfile profile; 192 gpu::VideoEncodeAcceleratorSupportedProfile profile;
180 profile.profile = 193 profile.profile =
181 static_cast<gpu::VideoCodecProfile>(media_profiles[i].profile); 194 static_cast<gpu::VideoCodecProfile>(media_profiles[i].profile);
182 profile.max_resolution = media_profiles[i].max_resolution; 195 profile.max_resolution = media_profiles[i].max_resolution;
183 profile.max_framerate_numerator = media_profiles[i].max_framerate_numerator; 196 profile.max_framerate_numerator = media_profiles[i].max_framerate_numerator;
184 profile.max_framerate_denominator = 197 profile.max_framerate_denominator =
185 media_profiles[i].max_framerate_denominator; 198 media_profiles[i].max_framerate_denominator;
186 profiles.push_back(profile); 199 profiles.push_back(profile);
187 } 200 }
188 return profiles; 201 return profiles;
189 } 202 }
190 203
191 scoped_ptr<media::VideoEncodeAccelerator> 204 // static
205 ScopedVector<media::VideoEncodeAccelerator>
192 GpuVideoEncodeAccelerator::CreateEncoder() { 206 GpuVideoEncodeAccelerator::CreateEncoder() {
193 scoped_ptr<media::VideoEncodeAccelerator> encoder; 207 ScopedVector<media::VideoEncodeAccelerator> encoder_list;
194 #if defined(OS_CHROMEOS) && defined(USE_X11) 208 #if defined(OS_CHROMEOS) && defined(USE_X11)
195 #if defined(ARCH_CPU_ARMEL)
196 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); 209 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder);
197 if (device) 210 if (device)
198 encoder.reset(new V4L2VideoEncodeAccelerator(device.Pass())); 211 encoder_list.push_back(new V4L2VideoEncodeAccelerator(device.Pass()));
199 #elif defined(ARCH_CPU_X86_FAMILY) 212 #if defined(ARCH_CPU_X86_FAMILY)
200 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 213 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
201 if (!cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode)) 214 if (!cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode))
202 encoder.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); 215 encoder_list.push_back(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay()));
203 #endif 216 #endif
204 #elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC) 217 #elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
205 encoder.reset(new AndroidVideoEncodeAccelerator()); 218 encoder_list.push_back(new AndroidVideoEncodeAccelerator());
206 #endif 219 #endif
207 return encoder.Pass(); 220 return encoder_list.Pass();
208 } 221 }
209 222
210 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, 223 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id,
211 base::SharedMemoryHandle buffer_handle, 224 base::SharedMemoryHandle buffer_handle,
212 uint32 buffer_size, 225 uint32 buffer_size,
213 bool force_keyframe) { 226 bool force_keyframe) {
214 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id 227 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id
215 << ", buffer_size=" << buffer_size 228 << ", buffer_size=" << buffer_size
216 << ", force_keyframe=" << force_keyframe; 229 << ", force_keyframe=" << force_keyframe;
217 if (!encoder_) 230 if (!encoder_)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 stub_->channel()->Send(message); 328 stub_->channel()->Send(message);
316 } 329 }
317 330
318 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message, 331 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message,
319 bool succeeded) { 332 bool succeeded) {
320 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded); 333 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded);
321 Send(message); 334 Send(message);
322 } 335 }
323 336
324 } // namespace content 337 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698