Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/pepper/pepper_video_source_host.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "content/public/renderer/renderer_ppapi_host.h" | |
| 9 #include "ppapi/c/pp_errors.h" | |
| 10 #include "ppapi/host/dispatch_host_message.h" | |
| 11 #include "ppapi/host/host_message_context.h" | |
| 12 #include "ppapi/host/ppapi_host.h" | |
| 13 #include "ppapi/proxy/ppapi_messages.h" | |
| 14 #include "ppapi/proxy/ppb_image_data_proxy.h" | |
| 15 #include "ppapi/shared_impl/scoped_pp_resource.h" | |
| 16 #include "ppapi/thunk/enter.h" | |
| 17 #include "ppapi/thunk/ppb_image_data_api.h" | |
| 18 #include "skia/ext/platform_canvas.h" | |
| 19 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | |
| 20 | |
| 21 using ppapi::host::HostMessageContext; | |
| 22 using ppapi::host::ReplyMessageContext; | |
| 23 | |
| 24 namespace content { | |
| 25 | |
| 26 PepperVideoSourceHost::PepperVideoSourceHost( | |
| 27 RendererPpapiHost* host, | |
| 28 PP_Instance instance, | |
| 29 PP_Resource resource) | |
| 30 : ResourceHost(host->GetPpapiHost(), instance, resource), | |
| 31 renderer_ppapi_host_(host), | |
| 32 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | |
| 33 last_timestamp_(0) { | |
| 34 } | |
| 35 | |
| 36 PepperVideoSourceHost::~PepperVideoSourceHost() { | |
| 37 } | |
| 38 | |
| 39 int32_t PepperVideoSourceHost::OnResourceMessageReceived( | |
| 40 const IPC::Message& msg, | |
| 41 HostMessageContext* context) { | |
| 42 if (!host()->permissions().HasPermission(ppapi::PERMISSION_PRIVATE)) | |
|
yzshen1
2013/05/01 23:18:33
We won't create this instance from the begining if
bbudge
2013/05/02 21:39:06
Done.
| |
| 43 return PP_ERROR_FAILED; | |
| 44 | |
| 45 IPC_BEGIN_MESSAGE_MAP(PepperVideoSourceHost, msg) | |
| 46 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_VideoSource_Open, | |
| 47 OnHostMsgOpen) | |
| 48 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoSource_GetFrame, | |
| 49 OnHostMsgGetFrame) | |
| 50 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoSource_Close, | |
| 51 OnHostMsgClose) | |
| 52 IPC_END_MESSAGE_MAP() | |
| 53 return PP_ERROR_FAILED; | |
| 54 } | |
| 55 | |
| 56 int32_t PepperVideoSourceHost::OnHostMsgOpen(HostMessageContext* context, | |
| 57 const std::string& stream_id) { | |
| 58 ReplyMessageContext reply_context = context->MakeReplyMessageContext(); | |
| 59 // TODO() Create the video stream here and return error / result code. | |
| 60 reply_context.params.set_result(PP_ERROR_FAILED); | |
| 61 host()->SendReply(reply_context, PpapiPluginMsg_VideoSource_OpenReply()); | |
| 62 return PP_OK_COMPLETIONPENDING; | |
| 63 } | |
| 64 | |
| 65 int32_t PepperVideoSourceHost::OnHostMsgGetFrame( | |
| 66 HostMessageContext* context) { | |
| 67 ReplyMessageContext reply_context = context->MakeReplyMessageContext(); | |
| 68 // TODO() Check next available frame's timestamp. Wait until it changes. | |
|
yzshen1
2013/05/01 23:18:33
Please add a name for the TODO.
bbudge
2013/05/02 21:39:06
Done.
| |
| 69 // Create an image data resource to hold the frame pixels. | |
| 70 PP_ImageDataDesc desc; | |
| 71 IPC::PlatformFileForTransit image_handle; | |
| 72 uint32_t byte_count; | |
| 73 ppapi::ScopedPPResource resource( | |
| 74 ppapi::ScopedPPResource::PassRef(), | |
| 75 ppapi::proxy::PPB_ImageData_Proxy::CreateImageData( | |
| 76 pp_instance(), | |
| 77 webkit::ppapi::PPB_ImageData_Impl::GetNativeImageDataFormat(), | |
| 78 PP_MakeSize(0, 0), | |
| 79 false /* init_to_zero */, | |
| 80 false /* is_nacl_plugin */, | |
| 81 &desc, &image_handle, &byte_count)); | |
| 82 if (!resource.get()) | |
| 83 return PP_ERROR_FAILED; | |
| 84 | |
| 85 ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_ImageData_API> | |
| 86 enter_resource(resource, false); | |
| 87 if (enter_resource.failed()) | |
| 88 return PP_ERROR_FAILED; | |
| 89 | |
| 90 webkit::ppapi::PPB_ImageData_Impl* image_data = | |
| 91 static_cast<webkit::ppapi::PPB_ImageData_Impl*>(enter_resource.object()); | |
| 92 webkit::ppapi::ImageDataAutoMapper mapper(image_data); | |
| 93 if (!mapper.is_valid()) | |
| 94 return PP_ERROR_FAILED; | |
| 95 | |
| 96 // TODO() Copy frame pixels to canvas. | |
| 97 //skia::PlatformCanvas* canvas = image_data->GetPlatformCanvas(); | |
| 98 | |
| 99 ppapi::HostResource image_data_resource; | |
| 100 image_data_resource.SetHostResource(pp_instance(), resource.get()); | |
| 101 double timestamp = 0; | |
| 102 reply_context.params.set_result(PP_ERROR_FAILED); | |
| 103 host()->SendReply( | |
| 104 reply_context, | |
| 105 PpapiPluginMsg_VideoSource_GetFrameReply(image_data_resource, timestamp)); | |
| 106 last_timestamp_ = timestamp; | |
| 107 return PP_OK_COMPLETIONPENDING; | |
| 108 } | |
| 109 | |
| 110 int32_t PepperVideoSourceHost::OnHostMsgClose(HostMessageContext* context) { | |
| 111 // TODO() Close the video stream. | |
| 112 return PP_OK; | |
| 113 } | |
| 114 | |
| 115 } // namespace content | |
| OLD | NEW |