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

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

Issue 337683002: Revert of Implement software fallback for PPB_VideoDecoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 "content/renderer/pepper/pepper_video_decoder_host.h" 5 #include "content/renderer/pepper/pepper_video_decoder_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "content/common/gpu/client/gpu_channel_host.h" 9 #include "content/common/gpu/client/gpu_channel_host.h"
10 #include "content/public/renderer/render_thread.h" 10 #include "content/public/renderer/render_thread.h"
11 #include "content/public/renderer/renderer_ppapi_host.h" 11 #include "content/public/renderer/renderer_ppapi_host.h"
12 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" 12 #include "content/renderer/pepper/ppb_graphics_3d_impl.h"
13 #include "content/renderer/pepper/video_decoder_shim.h" 13 #include "content/renderer/render_thread_impl.h"
14 #include "content/renderer/render_view_impl.h"
15 #include "media/video/picture.h"
14 #include "media/video/video_decode_accelerator.h" 16 #include "media/video/video_decode_accelerator.h"
15 #include "ppapi/c/pp_completion_callback.h" 17 #include "ppapi/c/pp_completion_callback.h"
16 #include "ppapi/c/pp_errors.h" 18 #include "ppapi/c/pp_errors.h"
17 #include "ppapi/host/dispatch_host_message.h" 19 #include "ppapi/host/dispatch_host_message.h"
18 #include "ppapi/host/ppapi_host.h" 20 #include "ppapi/host/ppapi_host.h"
19 #include "ppapi/proxy/ppapi_messages.h" 21 #include "ppapi/proxy/ppapi_messages.h"
20 #include "ppapi/proxy/video_decoder_constants.h" 22 #include "ppapi/proxy/video_decoder_constants.h"
21 #include "ppapi/thunk/enter.h" 23 #include "ppapi/thunk/enter.h"
22 #include "ppapi/thunk/ppb_graphics_3d_api.h" 24 #include "ppapi/thunk/ppb_graphics_3d_api.h"
23 25
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const ppapi::HostResource& graphics_context, 112 const ppapi::HostResource& graphics_context,
111 PP_VideoProfile profile, 113 PP_VideoProfile profile,
112 bool allow_software_fallback) { 114 bool allow_software_fallback) {
113 if (initialized_) 115 if (initialized_)
114 return PP_ERROR_FAILED; 116 return PP_ERROR_FAILED;
115 117
116 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics( 118 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics(
117 graphics_context.host_resource(), true); 119 graphics_context.host_resource(), true);
118 if (enter_graphics.failed()) 120 if (enter_graphics.failed())
119 return PP_ERROR_FAILED; 121 return PP_ERROR_FAILED;
120 PPB_Graphics3D_Impl* graphics3d = 122 graphics3d_ = static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object());
121 static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object());
122 123
123 int command_buffer_route_id = graphics3d->GetCommandBufferRouteId(); 124 int command_buffer_route_id = graphics3d_->GetCommandBufferRouteId();
124 if (!command_buffer_route_id) 125 if (!command_buffer_route_id)
125 return PP_ERROR_FAILED; 126 return PP_ERROR_FAILED;
126 127
127 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile); 128 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile);
128 129
129 // This is not synchronous, but subsequent IPC messages will be buffered, so 130 // This is not synchronous, but subsequent IPC messages will be buffered, so
130 // it is okay to immediately send IPC messages through the returned channel. 131 // it is okay to immediately send IPC messages through the returned channel.
131 GpuChannelHost* channel = graphics3d->channel(); 132 GpuChannelHost* channel = graphics3d_->channel();
132 DCHECK(channel); 133 DCHECK(channel);
133 decoder_ = channel->CreateVideoDecoder(command_buffer_route_id); 134 decoder_ = channel->CreateVideoDecoder(command_buffer_route_id);
134 if (decoder_ && decoder_->Initialize(media_profile, this)) { 135 if (decoder_ && decoder_->Initialize(media_profile, this)) {
135 initialized_ = true; 136 initialized_ = true;
136 return PP_OK; 137 return PP_OK;
137 } 138 }
138 decoder_.reset(); 139 decoder_.reset();
139 140
140 if (!allow_software_fallback) 141 // TODO(bbudge) Implement software fallback.
141 return PP_ERROR_NOTSUPPORTED; 142 return PP_ERROR_NOTSUPPORTED;
142
143 decoder_.reset(new VideoDecoderShim(this));
144 initialize_reply_context_ = context->MakeReplyMessageContext();
145 decoder_->Initialize(media_profile, this);
146
147 return PP_OK_COMPLETIONPENDING;
148 } 143 }
149 144
150 int32_t PepperVideoDecoderHost::OnHostMsgGetShm( 145 int32_t PepperVideoDecoderHost::OnHostMsgGetShm(
151 ppapi::host::HostMessageContext* context, 146 ppapi::host::HostMessageContext* context,
152 uint32_t shm_id, 147 uint32_t shm_id,
153 uint32_t shm_size) { 148 uint32_t shm_size) {
154 if (!initialized_) 149 if (!initialized_)
155 return PP_ERROR_FAILED; 150 return PP_ERROR_FAILED;
156 151
157 // Make the buffers larger since we hope to reuse them. 152 // Make the buffers larger since we hope to reuse them.
(...skipping 16 matching lines...) Expand all
174 scoped_ptr<base::SharedMemory> shm( 169 scoped_ptr<base::SharedMemory> shm(
175 render_thread->HostAllocateSharedMemoryBuffer(shm_size).Pass()); 170 render_thread->HostAllocateSharedMemoryBuffer(shm_size).Pass());
176 if (!shm || !shm->Map(shm_size)) 171 if (!shm || !shm->Map(shm_size))
177 return PP_ERROR_FAILED; 172 return PP_ERROR_FAILED;
178 173
179 base::SharedMemoryHandle shm_handle = shm->handle(); 174 base::SharedMemoryHandle shm_handle = shm->handle();
180 if (shm_id == shm_buffers_.size()) { 175 if (shm_id == shm_buffers_.size()) {
181 shm_buffers_.push_back(shm.release()); 176 shm_buffers_.push_back(shm.release());
182 shm_buffer_busy_.push_back(false); 177 shm_buffer_busy_.push_back(false);
183 } else { 178 } else {
184 // Remove the old buffer. Delete manually since ScopedVector won't delete 179 // Fill in the new resized buffer. Delete it manually since ScopedVector
185 // the existing element if we just assign over it. 180 // won't delete the existing element if we just assign it.
186 delete shm_buffers_[shm_id]; 181 delete shm_buffers_[shm_id];
187 shm_buffers_[shm_id] = shm.release(); 182 shm_buffers_[shm_id] = shm.release();
188 } 183 }
189 184
190 #if defined(OS_WIN) 185 #if defined(OS_WIN)
191 base::PlatformFile platform_file = shm_handle; 186 base::PlatformFile platform_file = shm_handle;
192 #elif defined(OS_POSIX) 187 #elif defined(OS_POSIX)
193 base::PlatformFile platform_file = shm_handle.fd; 188 base::PlatformFile platform_file = shm_handle.fd;
194 #else 189 #else
195 #error Not implemented. 190 #error Not implemented.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 int32_t PepperVideoDecoderHost::OnHostMsgRecyclePicture( 255 int32_t PepperVideoDecoderHost::OnHostMsgRecyclePicture(
261 ppapi::host::HostMessageContext* context, 256 ppapi::host::HostMessageContext* context,
262 uint32_t texture_id) { 257 uint32_t texture_id) {
263 if (!initialized_) 258 if (!initialized_)
264 return PP_ERROR_FAILED; 259 return PP_ERROR_FAILED;
265 DCHECK(decoder_); 260 DCHECK(decoder_);
266 if (reset_reply_context_.is_valid()) 261 if (reset_reply_context_.is_valid())
267 return PP_ERROR_FAILED; 262 return PP_ERROR_FAILED;
268 263
269 decoder_->ReusePictureBuffer(texture_id); 264 decoder_->ReusePictureBuffer(texture_id);
265
270 return PP_OK; 266 return PP_OK;
271 } 267 }
272 268
273 int32_t PepperVideoDecoderHost::OnHostMsgFlush( 269 int32_t PepperVideoDecoderHost::OnHostMsgFlush(
274 ppapi::host::HostMessageContext* context) { 270 ppapi::host::HostMessageContext* context) {
275 if (!initialized_) 271 if (!initialized_)
276 return PP_ERROR_FAILED; 272 return PP_ERROR_FAILED;
277 DCHECK(decoder_); 273 DCHECK(decoder_);
278 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid()) 274 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid())
279 return PP_ERROR_FAILED; 275 return PP_ERROR_FAILED;
(...skipping 15 matching lines...) Expand all
295 reset_reply_context_ = context->MakeReplyMessageContext(); 291 reset_reply_context_ = context->MakeReplyMessageContext();
296 decoder_->Reset(); 292 decoder_->Reset();
297 293
298 return PP_OK_COMPLETIONPENDING; 294 return PP_OK_COMPLETIONPENDING;
299 } 295 }
300 296
301 void PepperVideoDecoderHost::ProvidePictureBuffers( 297 void PepperVideoDecoderHost::ProvidePictureBuffers(
302 uint32 requested_num_of_buffers, 298 uint32 requested_num_of_buffers,
303 const gfx::Size& dimensions, 299 const gfx::Size& dimensions,
304 uint32 texture_target) { 300 uint32 texture_target) {
305 RequestTextures(requested_num_of_buffers, 301 DCHECK(RenderThreadImpl::current());
306 dimensions, 302 host()->SendUnsolicitedReply(
307 texture_target, 303 pp_resource(),
308 std::vector<gpu::Mailbox>()); 304 PpapiPluginMsg_VideoDecoder_RequestTextures(
305 requested_num_of_buffers,
306 PP_MakeSize(dimensions.width(), dimensions.height()),
307 texture_target));
309 } 308 }
310 309
311 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) { 310 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) {
311 DCHECK(RenderThreadImpl::current());
312 host()->SendUnsolicitedReply( 312 host()->SendUnsolicitedReply(
313 pp_resource(), 313 pp_resource(),
314 PpapiPluginMsg_VideoDecoder_PictureReady(picture.bitstream_buffer_id(), 314 PpapiPluginMsg_VideoDecoder_PictureReady(picture.bitstream_buffer_id(),
315 picture.picture_buffer_id())); 315 picture.picture_buffer_id()));
316 } 316 }
317 317
318 void PepperVideoDecoderHost::DismissPictureBuffer(int32 picture_buffer_id) { 318 void PepperVideoDecoderHost::DismissPictureBuffer(int32 picture_buffer_id) {
319 DCHECK(RenderThreadImpl::current());
319 host()->SendUnsolicitedReply( 320 host()->SendUnsolicitedReply(
320 pp_resource(), 321 pp_resource(),
321 PpapiPluginMsg_VideoDecoder_DismissPicture(picture_buffer_id)); 322 PpapiPluginMsg_VideoDecoder_DismissPicture(picture_buffer_id));
322 } 323 }
323 324
324 void PepperVideoDecoderHost::NotifyEndOfBitstreamBuffer(
325 int32 bitstream_buffer_id) {
326 PendingDecodeMap::iterator it = pending_decodes_.find(bitstream_buffer_id);
327 if (it == pending_decodes_.end()) {
328 NOTREACHED();
329 return;
330 }
331 const PendingDecode& pending_decode = it->second;
332 host()->SendReply(
333 pending_decode.reply_context,
334 PpapiPluginMsg_VideoDecoder_DecodeReply(pending_decode.shm_id));
335 shm_buffer_busy_[pending_decode.shm_id] = false;
336 pending_decodes_.erase(it);
337 }
338
339 void PepperVideoDecoderHost::NotifyFlushDone() {
340 host()->SendReply(flush_reply_context_,
341 PpapiPluginMsg_VideoDecoder_FlushReply());
342 flush_reply_context_ = ppapi::host::ReplyMessageContext();
343 }
344
345 void PepperVideoDecoderHost::NotifyResetDone() {
346 host()->SendReply(reset_reply_context_,
347 PpapiPluginMsg_VideoDecoder_ResetReply());
348 reset_reply_context_ = ppapi::host::ReplyMessageContext();
349 }
350
351 void PepperVideoDecoderHost::NotifyError( 325 void PepperVideoDecoderHost::NotifyError(
352 media::VideoDecodeAccelerator::Error error) { 326 media::VideoDecodeAccelerator::Error error) {
327 DCHECK(RenderThreadImpl::current());
353 int32_t pp_error = PP_ERROR_FAILED; 328 int32_t pp_error = PP_ERROR_FAILED;
354 switch (error) { 329 switch (error) {
355 case media::VideoDecodeAccelerator::UNREADABLE_INPUT: 330 case media::VideoDecodeAccelerator::UNREADABLE_INPUT:
356 pp_error = PP_ERROR_MALFORMED_INPUT; 331 pp_error = PP_ERROR_MALFORMED_INPUT;
357 break; 332 break;
358 case media::VideoDecodeAccelerator::ILLEGAL_STATE: 333 case media::VideoDecodeAccelerator::ILLEGAL_STATE:
359 case media::VideoDecodeAccelerator::INVALID_ARGUMENT: 334 case media::VideoDecodeAccelerator::INVALID_ARGUMENT:
360 case media::VideoDecodeAccelerator::PLATFORM_FAILURE: 335 case media::VideoDecodeAccelerator::PLATFORM_FAILURE:
361 case media::VideoDecodeAccelerator::LARGEST_ERROR_ENUM: 336 case media::VideoDecodeAccelerator::LARGEST_ERROR_ENUM:
362 pp_error = PP_ERROR_RESOURCE_FAILED; 337 pp_error = PP_ERROR_RESOURCE_FAILED;
363 break; 338 break;
364 // No default case, to catch unhandled enum values. 339 // No default case, to catch unhandled enum values.
365 } 340 }
366 host()->SendUnsolicitedReply( 341 host()->SendUnsolicitedReply(
367 pp_resource(), PpapiPluginMsg_VideoDecoder_NotifyError(pp_error)); 342 pp_resource(), PpapiPluginMsg_VideoDecoder_NotifyError(pp_error));
368 } 343 }
369 344
370 void PepperVideoDecoderHost::OnInitializeComplete(int32_t result) { 345 void PepperVideoDecoderHost::NotifyResetDone() {
371 if (!initialized_) { 346 DCHECK(RenderThreadImpl::current());
372 if (result == PP_OK) 347 host()->SendReply(reset_reply_context_,
373 initialized_ = true; 348 PpapiPluginMsg_VideoDecoder_ResetReply());
374 initialize_reply_context_.params.set_result(result); 349 reset_reply_context_ = ppapi::host::ReplyMessageContext();
375 host()->SendReply(initialize_reply_context_,
376 PpapiPluginMsg_VideoDecoder_InitializeReply());
377 }
378 } 350 }
379 351
380 const uint8_t* PepperVideoDecoderHost::DecodeIdToAddress(uint32_t decode_id) { 352 void PepperVideoDecoderHost::NotifyEndOfBitstreamBuffer(
381 PendingDecodeMap::const_iterator it = pending_decodes_.find(decode_id); 353 int32 bitstream_buffer_id) {
382 DCHECK(it != pending_decodes_.end()); 354 DCHECK(RenderThreadImpl::current());
383 uint32_t shm_id = it->second.shm_id; 355 PendingDecodeMap::iterator it = pending_decodes_.find(bitstream_buffer_id);
384 return static_cast<uint8_t*>(shm_buffers_[shm_id]->memory()); 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);
385 } 366 }
386 367
387 void PepperVideoDecoderHost::RequestTextures( 368 void PepperVideoDecoderHost::NotifyFlushDone() {
388 uint32 requested_num_of_buffers, 369 DCHECK(RenderThreadImpl::current());
389 const gfx::Size& dimensions, 370 host()->SendReply(flush_reply_context_,
390 uint32 texture_target, 371 PpapiPluginMsg_VideoDecoder_FlushReply());
391 const std::vector<gpu::Mailbox>& mailboxes) { 372 flush_reply_context_ = ppapi::host::ReplyMessageContext();
392 host()->SendUnsolicitedReply(
393 pp_resource(),
394 PpapiPluginMsg_VideoDecoder_RequestTextures(
395 requested_num_of_buffers,
396 PP_MakeSize(dimensions.width(), dimensions.height()),
397 texture_target,
398 mailboxes));
399 } 373 }
400 374
401 } // namespace content 375 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_video_decoder_host.h ('k') | content/renderer/pepper/video_decoder_shim.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698