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

Side by Side Diff: content/renderer/pepper/pepper_video_decoder_host.cc

Issue 311853005: Implement software fallback for PPB_VideoDecoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move SoftwareDecoder to its own file, split into Proxy/Delegate classes, State enum. Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 <GLES2/gl2.h>
6 #include <GLES2/gl2ext.h>
7 #include <GLES2/gl2extchromium.h>
bbudge 2014/06/04 14:31:41 unnecessary.
8
5 #include "content/renderer/pepper/pepper_video_decoder_host.h" 9 #include "content/renderer/pepper/pepper_video_decoder_host.h"
6 10
7 #include "base/bind.h" 11 #include "base/bind.h"
8 #include "base/memory/shared_memory.h" 12 #include "base/memory/shared_memory.h"
9 #include "content/common/gpu/client/gpu_channel_host.h" 13 #include "content/common/gpu/client/gpu_channel_host.h"
10 #include "content/public/renderer/render_thread.h" 14 #include "content/public/renderer/render_thread.h"
11 #include "content/public/renderer/renderer_ppapi_host.h" 15 #include "content/public/renderer/renderer_ppapi_host.h"
12 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" 16 #include "content/renderer/pepper/ppb_graphics_3d_impl.h"
13 #include "content/renderer/render_thread_impl.h" 17 #include "media/filters/ffmpeg_video_decoder.h"
14 #include "content/renderer/render_view_impl.h"
15 #include "media/video/picture.h"
16 #include "media/video/video_decode_accelerator.h" 18 #include "media/video/video_decode_accelerator.h"
17 #include "ppapi/c/pp_completion_callback.h" 19 #include "ppapi/c/pp_completion_callback.h"
18 #include "ppapi/c/pp_errors.h" 20 #include "ppapi/c/pp_errors.h"
19 #include "ppapi/host/dispatch_host_message.h" 21 #include "ppapi/host/dispatch_host_message.h"
20 #include "ppapi/host/ppapi_host.h" 22 #include "ppapi/host/ppapi_host.h"
21 #include "ppapi/proxy/ppapi_messages.h" 23 #include "ppapi/proxy/ppapi_messages.h"
22 #include "ppapi/proxy/video_decoder_constants.h" 24 #include "ppapi/proxy/video_decoder_constants.h"
23 #include "ppapi/thunk/enter.h" 25 #include "ppapi/thunk/enter.h"
24 #include "ppapi/thunk/ppb_graphics_3d_api.h" 26 #include "ppapi/thunk/ppb_graphics_3d_api.h"
25 27
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 const ppapi::HostResource& graphics_context, 114 const ppapi::HostResource& graphics_context,
113 PP_VideoProfile profile, 115 PP_VideoProfile profile,
114 bool allow_software_fallback) { 116 bool allow_software_fallback) {
115 if (initialized_) 117 if (initialized_)
116 return PP_ERROR_FAILED; 118 return PP_ERROR_FAILED;
117 119
118 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics( 120 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics(
119 graphics_context.host_resource(), true); 121 graphics_context.host_resource(), true);
120 if (enter_graphics.failed()) 122 if (enter_graphics.failed())
121 return PP_ERROR_FAILED; 123 return PP_ERROR_FAILED;
122 graphics3d_ = static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object()); 124 PPB_Graphics3D_Impl* graphics3d =
125 static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object());
123 126
124 int command_buffer_route_id = graphics3d_->GetCommandBufferRouteId(); 127 int command_buffer_route_id = graphics3d->GetCommandBufferRouteId();
125 if (!command_buffer_route_id) 128 if (!command_buffer_route_id)
126 return PP_ERROR_FAILED; 129 return PP_ERROR_FAILED;
127 130
128 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile); 131 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile);
129 132
130 // This is not synchronous, but subsequent IPC messages will be buffered, so 133 // This is not synchronous, but subsequent IPC messages will be buffered, so
131 // it is okay to immediately send IPC messages through the returned channel. 134 // it is okay to immediately send IPC messages through the returned channel.
132 GpuChannelHost* channel = graphics3d_->channel(); 135 GpuChannelHost* channel = graphics3d->channel();
133 DCHECK(channel); 136 DCHECK(channel);
134 decoder_ = channel->CreateVideoDecoder(command_buffer_route_id); 137 decoder_ = channel->CreateVideoDecoder(command_buffer_route_id);
135 if (decoder_ && decoder_->Initialize(media_profile, this)) { 138 if (decoder_ && decoder_->Initialize(media_profile, this)) {
136 initialized_ = true; 139 initialized_ = true;
137 return PP_OK; 140 return PP_OK;
138 } 141 }
139 decoder_.reset(); 142 decoder_.reset();
140 143
141 // TODO(bbudge) Implement software fallback. 144 if (!allow_software_fallback)
142 return PP_ERROR_NOTSUPPORTED; 145 return PP_ERROR_NOTSUPPORTED;
146
147 software_decoder_.reset(new VideoDecoderProxy(this));
148 initialize_reply_context_ = context->MakeReplyMessageContext();
149 software_decoder_->Initialize(media_profile);
150
151 return PP_OK_COMPLETIONPENDING;
143 } 152 }
144 153
145 int32_t PepperVideoDecoderHost::OnHostMsgGetShm( 154 int32_t PepperVideoDecoderHost::OnHostMsgGetShm(
146 ppapi::host::HostMessageContext* context, 155 ppapi::host::HostMessageContext* context,
147 uint32_t shm_id, 156 uint32_t shm_id,
148 uint32_t shm_size) { 157 uint32_t shm_size) {
149 if (!initialized_) 158 if (!initialized_)
150 return PP_ERROR_FAILED; 159 return PP_ERROR_FAILED;
151 160
152 // Make the buffers larger since we hope to reuse them. 161 // Make the buffers larger since we hope to reuse them.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 return PP_OK_COMPLETIONPENDING; 210 return PP_OK_COMPLETIONPENDING;
202 } 211 }
203 212
204 int32_t PepperVideoDecoderHost::OnHostMsgDecode( 213 int32_t PepperVideoDecoderHost::OnHostMsgDecode(
205 ppapi::host::HostMessageContext* context, 214 ppapi::host::HostMessageContext* context,
206 uint32_t shm_id, 215 uint32_t shm_id,
207 uint32_t size, 216 uint32_t size,
208 int32_t decode_id) { 217 int32_t decode_id) {
209 if (!initialized_) 218 if (!initialized_)
210 return PP_ERROR_FAILED; 219 return PP_ERROR_FAILED;
211 DCHECK(decoder_); 220 DCHECK(decoder_ || software_decoder_);
212 // |shm_id| is just an index into shm_buffers_. Make sure it's in range. 221 // |shm_id| is just an index into shm_buffers_. Make sure it's in range.
213 if (static_cast<size_t>(shm_id) >= shm_buffers_.size()) 222 if (static_cast<size_t>(shm_id) >= shm_buffers_.size())
214 return PP_ERROR_FAILED; 223 return PP_ERROR_FAILED;
215 // Reject an attempt to pass a busy buffer to the decoder again. 224 // Reject an attempt to pass a busy buffer to the decoder again.
216 if (shm_buffer_busy_[shm_id]) 225 if (shm_buffer_busy_[shm_id])
217 return PP_ERROR_FAILED; 226 return PP_ERROR_FAILED;
218 // Reject non-unique decode_id values. 227 // Reject non-unique decode_id values.
219 if (pending_decodes_.find(decode_id) != pending_decodes_.end()) 228 if (pending_decodes_.find(decode_id) != pending_decodes_.end())
220 return PP_ERROR_FAILED; 229 return PP_ERROR_FAILED;
221 230
222 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid()) 231 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid())
223 return PP_ERROR_FAILED; 232 return PP_ERROR_FAILED;
224 233
225 pending_decodes_.insert(std::make_pair( 234 pending_decodes_.insert(std::make_pair(
226 decode_id, PendingDecode(shm_id, context->MakeReplyMessageContext()))); 235 decode_id, PendingDecode(shm_id, context->MakeReplyMessageContext())));
227 236
228 shm_buffer_busy_[shm_id] = true; 237 shm_buffer_busy_[shm_id] = true;
229 decoder_->Decode( 238 base::SharedMemory* shm = shm_buffers_[shm_id];
230 media::BitstreamBuffer(decode_id, shm_buffers_[shm_id]->handle(), size)); 239 if (decoder_) {
240 decoder_->Decode(media::BitstreamBuffer(decode_id, shm->handle(), size));
241 } else {
242 software_decoder_->Decode(
243 decode_id, static_cast<uint8_t*>(shm->memory()), size);
244 }
231 245
232 return PP_OK_COMPLETIONPENDING; 246 return PP_OK_COMPLETIONPENDING;
233 } 247 }
234 248
235 int32_t PepperVideoDecoderHost::OnHostMsgAssignTextures( 249 int32_t PepperVideoDecoderHost::OnHostMsgAssignTextures(
236 ppapi::host::HostMessageContext* context, 250 ppapi::host::HostMessageContext* context,
237 const PP_Size& size, 251 const PP_Size& size,
238 const std::vector<uint32_t>& texture_ids) { 252 const std::vector<uint32_t>& texture_ids) {
239 if (!initialized_) 253 if (!initialized_)
240 return PP_ERROR_FAILED; 254 return PP_ERROR_FAILED;
241 DCHECK(decoder_); 255 DCHECK(decoder_ || software_decoder_);
242 256
243 std::vector<media::PictureBuffer> picture_buffers; 257 if (decoder_) {
244 for (uint32 i = 0; i < texture_ids.size(); i++) { 258 std::vector<media::PictureBuffer> picture_buffers;
245 media::PictureBuffer buffer( 259 for (uint32 i = 0; i < texture_ids.size(); i++) {
246 texture_ids[i], // Use the texture_id to identify the buffer. 260 media::PictureBuffer buffer(
247 gfx::Size(size.width, size.height), 261 texture_ids[i], // Use the texture_id to identify the buffer.
248 texture_ids[i]); 262 gfx::Size(size.width, size.height),
249 picture_buffers.push_back(buffer); 263 texture_ids[i]);
264 picture_buffers.push_back(buffer);
265 }
266 decoder_->AssignPictureBuffers(picture_buffers);
267 } else {
268 software_decoder_->AssignTextures(texture_ids);
250 } 269 }
251 decoder_->AssignPictureBuffers(picture_buffers);
252 return PP_OK; 270 return PP_OK;
253 } 271 }
254 272
255 int32_t PepperVideoDecoderHost::OnHostMsgRecyclePicture( 273 int32_t PepperVideoDecoderHost::OnHostMsgRecyclePicture(
256 ppapi::host::HostMessageContext* context, 274 ppapi::host::HostMessageContext* context,
257 uint32_t texture_id) { 275 uint32_t texture_id) {
258 if (!initialized_) 276 if (!initialized_)
259 return PP_ERROR_FAILED; 277 return PP_ERROR_FAILED;
260 DCHECK(decoder_); 278 DCHECK(decoder_ || software_decoder_);
261 if (reset_reply_context_.is_valid()) 279 if (reset_reply_context_.is_valid())
262 return PP_ERROR_FAILED; 280 return PP_ERROR_FAILED;
263 281 if (decoder_) {
264 decoder_->ReusePictureBuffer(texture_id); 282 decoder_->ReusePictureBuffer(texture_id);
283 } else {
284 software_decoder_->RecycleTexture(texture_id);
285 }
265 286
266 return PP_OK; 287 return PP_OK;
267 } 288 }
268 289
269 int32_t PepperVideoDecoderHost::OnHostMsgFlush( 290 int32_t PepperVideoDecoderHost::OnHostMsgFlush(
270 ppapi::host::HostMessageContext* context) { 291 ppapi::host::HostMessageContext* context) {
271 if (!initialized_) 292 if (!initialized_)
272 return PP_ERROR_FAILED; 293 return PP_ERROR_FAILED;
273 DCHECK(decoder_); 294 DCHECK(decoder_ || software_decoder_);
274 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid()) 295 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid())
275 return PP_ERROR_FAILED; 296 return PP_ERROR_FAILED;
276 297
277 flush_reply_context_ = context->MakeReplyMessageContext(); 298 flush_reply_context_ = context->MakeReplyMessageContext();
278 decoder_->Flush(); 299 if (decoder_)
300 decoder_->Flush();
301 else
302 software_decoder_->Flush();
279 303
280 return PP_OK_COMPLETIONPENDING; 304 return PP_OK_COMPLETIONPENDING;
281 } 305 }
282 306
283 int32_t PepperVideoDecoderHost::OnHostMsgReset( 307 int32_t PepperVideoDecoderHost::OnHostMsgReset(
284 ppapi::host::HostMessageContext* context) { 308 ppapi::host::HostMessageContext* context) {
285 if (!initialized_) 309 if (!initialized_)
286 return PP_ERROR_FAILED; 310 return PP_ERROR_FAILED;
287 DCHECK(decoder_); 311 DCHECK(decoder_ || software_decoder_);
288 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid()) 312 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid())
289 return PP_ERROR_FAILED; 313 return PP_ERROR_FAILED;
290 314
291 reset_reply_context_ = context->MakeReplyMessageContext(); 315 reset_reply_context_ = context->MakeReplyMessageContext();
292 decoder_->Reset(); 316 if (decoder_)
317 decoder_->Reset();
318 else
319 software_decoder_->Reset();
293 320
294 return PP_OK_COMPLETIONPENDING; 321 return PP_OK_COMPLETIONPENDING;
295 } 322 }
296 323
297 void PepperVideoDecoderHost::ProvidePictureBuffers( 324 void PepperVideoDecoderHost::ProvidePictureBuffers(
298 uint32 requested_num_of_buffers, 325 uint32 requested_num_of_buffers,
299 const gfx::Size& dimensions, 326 const gfx::Size& dimensions,
300 uint32 texture_target) { 327 uint32 texture_target) {
301 DCHECK(RenderThreadImpl::current()); 328 RequestTextures(requested_num_of_buffers,
302 host()->SendUnsolicitedReply( 329 dimensions,
303 pp_resource(), 330 texture_target,
304 PpapiPluginMsg_VideoDecoder_RequestTextures( 331 std::vector<gpu::Mailbox>());
305 requested_num_of_buffers,
306 PP_MakeSize(dimensions.width(), dimensions.height()),
307 texture_target));
308 } 332 }
309 333
310 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) { 334 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) {
311 DCHECK(RenderThreadImpl::current());
312 host()->SendUnsolicitedReply( 335 host()->SendUnsolicitedReply(
313 pp_resource(), 336 pp_resource(),
314 PpapiPluginMsg_VideoDecoder_PictureReady(picture.bitstream_buffer_id(), 337 PpapiPluginMsg_VideoDecoder_PictureReady(picture.bitstream_buffer_id(),
315 picture.picture_buffer_id())); 338 picture.picture_buffer_id()));
316 } 339 }
317 340
318 void PepperVideoDecoderHost::DismissPictureBuffer(int32 picture_buffer_id) { 341 void PepperVideoDecoderHost::DismissPictureBuffer(int32 picture_buffer_id) {
319 DCHECK(RenderThreadImpl::current());
320 host()->SendUnsolicitedReply( 342 host()->SendUnsolicitedReply(
321 pp_resource(), 343 pp_resource(),
322 PpapiPluginMsg_VideoDecoder_DismissPicture(picture_buffer_id)); 344 PpapiPluginMsg_VideoDecoder_DismissPicture(picture_buffer_id));
323 } 345 }
324 346
347 void PepperVideoDecoderHost::NotifyEndOfBitstreamBuffer(
348 int32 bitstream_buffer_id) {
349 PendingDecodeMap::iterator it = pending_decodes_.find(bitstream_buffer_id);
350 if (it == pending_decodes_.end()) {
351 NOTREACHED();
352 return;
353 }
354 const PendingDecode& pending_decode = it->second;
355 host()->SendReply(
356 pending_decode.reply_context,
357 PpapiPluginMsg_VideoDecoder_DecodeReply(pending_decode.shm_id));
358 shm_buffer_busy_[pending_decode.shm_id] = false;
359 pending_decodes_.erase(it);
360 }
361
362 void PepperVideoDecoderHost::NotifyFlushDone() {
363 host()->SendReply(flush_reply_context_,
364 PpapiPluginMsg_VideoDecoder_FlushReply());
365 flush_reply_context_ = ppapi::host::ReplyMessageContext();
366 }
367
368 void PepperVideoDecoderHost::NotifyResetDone() {
369 host()->SendReply(reset_reply_context_,
370 PpapiPluginMsg_VideoDecoder_ResetReply());
371 reset_reply_context_ = ppapi::host::ReplyMessageContext();
372 }
373
325 void PepperVideoDecoderHost::NotifyError( 374 void PepperVideoDecoderHost::NotifyError(
326 media::VideoDecodeAccelerator::Error error) { 375 media::VideoDecodeAccelerator::Error error) {
327 DCHECK(RenderThreadImpl::current());
328 int32_t pp_error = PP_ERROR_FAILED; 376 int32_t pp_error = PP_ERROR_FAILED;
329 switch (error) { 377 switch (error) {
330 case media::VideoDecodeAccelerator::UNREADABLE_INPUT: 378 case media::VideoDecodeAccelerator::UNREADABLE_INPUT:
331 pp_error = PP_ERROR_MALFORMED_INPUT; 379 pp_error = PP_ERROR_MALFORMED_INPUT;
332 break; 380 break;
333 case media::VideoDecodeAccelerator::ILLEGAL_STATE: 381 case media::VideoDecodeAccelerator::ILLEGAL_STATE:
334 case media::VideoDecodeAccelerator::INVALID_ARGUMENT: 382 case media::VideoDecodeAccelerator::INVALID_ARGUMENT:
335 case media::VideoDecodeAccelerator::PLATFORM_FAILURE: 383 case media::VideoDecodeAccelerator::PLATFORM_FAILURE:
336 case media::VideoDecodeAccelerator::LARGEST_ERROR_ENUM: 384 case media::VideoDecodeAccelerator::LARGEST_ERROR_ENUM:
337 pp_error = PP_ERROR_RESOURCE_FAILED; 385 pp_error = PP_ERROR_RESOURCE_FAILED;
338 break; 386 break;
339 // No default case, to catch unhandled enum values. 387 // No default case, to catch unhandled enum values.
340 } 388 }
389 NotifyError(pp_error);
390 }
391
392 void PepperVideoDecoderHost::OnInitializeComplete(int32_t result) {
393 if (!initialized_) {
394 initialized_ = true;
395 initialize_reply_context_.params.set_result(result);
396 host()->SendReply(initialize_reply_context_,
397 PpapiPluginMsg_VideoDecoder_InitializeReply());
398 }
399 }
400
401 void PepperVideoDecoderHost::RequestTextures(
402 uint32 requested_num_of_buffers,
403 const gfx::Size& dimensions,
404 uint32 texture_target,
405 const std::vector<gpu::Mailbox>& mailboxes) {
406 host()->SendUnsolicitedReply(
407 pp_resource(),
408 PpapiPluginMsg_VideoDecoder_RequestTextures(
409 requested_num_of_buffers,
410 PP_MakeSize(dimensions.width(), dimensions.height()),
411 texture_target,
412 mailboxes));
413 }
414
415 void PepperVideoDecoderHost::NotifyError(int32_t pp_error) {
341 host()->SendUnsolicitedReply( 416 host()->SendUnsolicitedReply(
342 pp_resource(), PpapiPluginMsg_VideoDecoder_NotifyError(pp_error)); 417 pp_resource(), PpapiPluginMsg_VideoDecoder_NotifyError(pp_error));
343 } 418 }
344 419
345 void PepperVideoDecoderHost::NotifyResetDone() {
346 DCHECK(RenderThreadImpl::current());
347 host()->SendReply(reset_reply_context_,
348 PpapiPluginMsg_VideoDecoder_ResetReply());
349 reset_reply_context_ = ppapi::host::ReplyMessageContext();
350 }
351
352 void PepperVideoDecoderHost::NotifyEndOfBitstreamBuffer(
353 int32 bitstream_buffer_id) {
354 DCHECK(RenderThreadImpl::current());
355 PendingDecodeMap::iterator it = pending_decodes_.find(bitstream_buffer_id);
356 if (it == pending_decodes_.end()) {
357 NOTREACHED();
358 return;
359 }
360 const PendingDecode& pending_decode = it->second;
361 host()->SendReply(
362 pending_decode.reply_context,
363 PpapiPluginMsg_VideoDecoder_DecodeReply(pending_decode.shm_id));
364 shm_buffer_busy_[pending_decode.shm_id] = false;
365 pending_decodes_.erase(it);
366 }
367
368 void PepperVideoDecoderHost::NotifyFlushDone() {
369 DCHECK(RenderThreadImpl::current());
370 host()->SendReply(flush_reply_context_,
371 PpapiPluginMsg_VideoDecoder_FlushReply());
372 flush_reply_context_ = ppapi::host::ReplyMessageContext();
373 }
374
375 } // namespace content 420 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_video_decoder_host.h ('k') | content/renderer/pepper/video_decoder_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698