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/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 Loading... | |
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 std::vector<media::VideoEncodeAccelerator*> encoders = CreateEncoders(); |
99 if (!encoder_) { | 100 if (encoders.empty()) { |
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 < encoders.size(); ++i) { |
106 input_visible_size, | 107 if (encoders[i]->Initialize(input_format, |
107 output_profile, | 108 input_visible_size, |
108 initial_bitrate, | 109 output_profile, |
109 this)) { | 110 initial_bitrate, |
111 this)) { | |
112 encoder_.reset(encoders[i]); | |
113 input_format_ = input_format; | |
114 input_visible_size_ = input_visible_size; | |
115 SendCreateEncoderReply(init_done_msg, true); | |
wuchengli
2014/12/26 09:26:25
You need to stop initializing and destroy other en
henryhsu
2014/12/26 09:52:11
Done.
| |
116 } else { | |
117 encoders[i]->Destroy(); | |
118 } | |
119 } | |
120 if (!encoder_.get()) { | |
110 DLOG(ERROR) | 121 DLOG(ERROR) |
111 << "GpuVideoEncodeAccelerator::Initialize(): VEA initialization failed"; | 122 << "GpuVideoEncodeAccelerator::Initialize(): VEA initialization failed"; |
112 SendCreateEncoderReply(init_done_msg, false); | 123 SendCreateEncoderReply(init_done_msg, false); |
113 return; | |
114 } | 124 } |
115 input_format_ = input_format; | |
116 input_visible_size_ = input_visible_size; | |
117 SendCreateEncoderReply(init_done_msg, true); | |
118 } | 125 } |
119 | 126 |
120 bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) { | 127 bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) { |
121 bool handled = true; | 128 bool handled = true; |
122 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAccelerator, message) | 129 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAccelerator, message) |
123 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode, OnEncode) | 130 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode, OnEncode) |
124 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer, | 131 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer, |
125 OnUseOutputBitstreamBuffer) | 132 OnUseOutputBitstreamBuffer) |
126 IPC_MESSAGE_HANDLER( | 133 IPC_MESSAGE_HANDLER( |
127 AcceleratedVideoEncoderMsg_RequestEncodingParametersChange, | 134 AcceleratedVideoEncoderMsg_RequestEncodingParametersChange, |
(...skipping 30 matching lines...) Expand all Loading... | |
158 DCHECK(stub_); | 165 DCHECK(stub_); |
159 stub_->channel()->RemoveRoute(host_route_id_); | 166 stub_->channel()->RemoveRoute(host_route_id_); |
160 stub_->RemoveDestructionObserver(this); | 167 stub_->RemoveDestructionObserver(this); |
161 encoder_.reset(); | 168 encoder_.reset(); |
162 delete this; | 169 delete this; |
163 } | 170 } |
164 | 171 |
165 // static | 172 // static |
166 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> | 173 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> |
167 GpuVideoEncodeAccelerator::GetSupportedProfiles() { | 174 GpuVideoEncodeAccelerator::GetSupportedProfiles() { |
168 scoped_ptr<media::VideoEncodeAccelerator> encoder = CreateEncoder(); | 175 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles; |
169 if (!encoder) | 176 std::vector<media::VideoEncodeAccelerator*> encoders = CreateEncoders(); |
177 if (encoders.empty()) | |
170 return std::vector<gpu::VideoEncodeAcceleratorSupportedProfile>(); | 178 return std::vector<gpu::VideoEncodeAcceleratorSupportedProfile>(); |
171 return ConvertMediaToGpuProfiles(encoder->GetSupportedProfiles()); | 179 |
180 std::set<media::VideoEncodeAccelerator::SupportedProfile> profile_set; | |
181 for (size_t i = 0; i < encoders.size(); ++i) { | |
182 std::vector<media::VideoEncodeAccelerator::SupportedProfile> | |
183 vea_profiles = encoders[i]->GetSupportedProfiles(); | |
184 for (size_t j = 0; j < vea_profiles.size(); ++j) | |
185 profile_set.insert(vea_profiles[j]); | |
186 encoders[i]->Destroy(); | |
187 } | |
188 profiles.assign(profile_set.begin(), profile_set.end()); | |
189 return ConvertMediaToGpuProfiles(profiles); | |
172 } | 190 } |
173 | 191 |
192 // static | |
174 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> | 193 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> |
175 GpuVideoEncodeAccelerator::ConvertMediaToGpuProfiles(const std::vector< | 194 GpuVideoEncodeAccelerator::ConvertMediaToGpuProfiles(const std::vector< |
176 media::VideoEncodeAccelerator::SupportedProfile>& media_profiles) { | 195 media::VideoEncodeAccelerator::SupportedProfile>& media_profiles) { |
177 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> profiles; | 196 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> profiles; |
178 for (size_t i = 0; i < media_profiles.size(); i++) { | 197 for (size_t i = 0; i < media_profiles.size(); i++) { |
179 gpu::VideoEncodeAcceleratorSupportedProfile profile; | 198 gpu::VideoEncodeAcceleratorSupportedProfile profile; |
180 profile.profile = | 199 profile.profile = |
181 static_cast<gpu::VideoCodecProfile>(media_profiles[i].profile); | 200 static_cast<gpu::VideoCodecProfile>(media_profiles[i].profile); |
182 profile.max_resolution = media_profiles[i].max_resolution; | 201 profile.max_resolution = media_profiles[i].max_resolution; |
183 profile.max_framerate_numerator = media_profiles[i].max_framerate_numerator; | 202 profile.max_framerate_numerator = media_profiles[i].max_framerate_numerator; |
184 profile.max_framerate_denominator = | 203 profile.max_framerate_denominator = |
185 media_profiles[i].max_framerate_denominator; | 204 media_profiles[i].max_framerate_denominator; |
186 profiles.push_back(profile); | 205 profiles.push_back(profile); |
187 } | 206 } |
188 return profiles; | 207 return profiles; |
189 } | 208 } |
190 | 209 |
191 scoped_ptr<media::VideoEncodeAccelerator> | 210 // static |
192 GpuVideoEncodeAccelerator::CreateEncoder() { | 211 std::vector<media::VideoEncodeAccelerator*> |
193 scoped_ptr<media::VideoEncodeAccelerator> encoder; | 212 GpuVideoEncodeAccelerator::CreateEncoders() { |
213 std::vector<media::VideoEncodeAccelerator*> encoders; | |
194 #if defined(OS_CHROMEOS) && defined(USE_X11) | 214 #if defined(OS_CHROMEOS) && defined(USE_X11) |
195 #if defined(ARCH_CPU_ARMEL) | |
196 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); | 215 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); |
197 if (device) | 216 if (device) |
198 encoder.reset(new V4L2VideoEncodeAccelerator(device.Pass())); | 217 encoders.push_back(new V4L2VideoEncodeAccelerator(device.Pass())); |
199 #elif defined(ARCH_CPU_X86_FAMILY) | 218 #if defined(ARCH_CPU_X86_FAMILY) |
200 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 219 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
201 if (!cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode)) | 220 if (!cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode)) |
202 encoder.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); | 221 encoders.push_back(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); |
203 #endif | 222 #endif |
204 #elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | 223 #elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
205 encoder.reset(new AndroidVideoEncodeAccelerator()); | 224 encoders.push_back(new AndroidVideoEncodeAccelerator()); |
206 #endif | 225 #endif |
207 return encoder.Pass(); | 226 return encoders; |
208 } | 227 } |
209 | 228 |
210 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, | 229 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, |
211 base::SharedMemoryHandle buffer_handle, | 230 base::SharedMemoryHandle buffer_handle, |
212 uint32 buffer_size, | 231 uint32 buffer_size, |
213 bool force_keyframe) { | 232 bool force_keyframe) { |
214 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id | 233 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id |
215 << ", buffer_size=" << buffer_size | 234 << ", buffer_size=" << buffer_size |
216 << ", force_keyframe=" << force_keyframe; | 235 << ", force_keyframe=" << force_keyframe; |
217 if (!encoder_) | 236 if (!encoder_) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 stub_->channel()->Send(message); | 334 stub_->channel()->Send(message); |
316 } | 335 } |
317 | 336 |
318 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message, | 337 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message, |
319 bool succeeded) { | 338 bool succeeded) { |
320 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded); | 339 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded); |
321 Send(message); | 340 Send(message); |
322 } | 341 } |
323 | 342 |
324 } // namespace content | 343 } // namespace content |
OLD | NEW |