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

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

Issue 13771020: Add Pepper VideoReader and VideoWriter plumbing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, clean up some headers. Created 7 years, 7 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
« no previous file with comments | « content/renderer/pepper/pepper_video_source_host.h ('k') | ppapi/ppapi_proxy.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_(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 IPC_BEGIN_MESSAGE_MAP(PepperVideoSourceHost, msg)
43 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_VideoSource_Open,
44 OnHostMsgOpen)
45 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoSource_GetFrame,
46 OnHostMsgGetFrame)
47 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoSource_Close,
48 OnHostMsgClose)
49 IPC_END_MESSAGE_MAP()
50 return PP_ERROR_FAILED;
51 }
52
53 int32_t PepperVideoSourceHost::OnHostMsgOpen(HostMessageContext* context,
54 const std::string& stream_url) {
55 GURL gurl(stream_url);
56 if (!gurl.is_valid())
57 return PP_ERROR_BADARGUMENT;
58 // TODO(ronghuawu) Check that gurl is a valid MediaStream video track URL.
59 // TODO(ronghuawu) Open a MediaStream video track.
60 ReplyMessageContext reply_context = context->MakeReplyMessageContext();
61 reply_context.params.set_result(PP_OK);
62 host()->SendReply(reply_context, PpapiPluginMsg_VideoSource_OpenReply());
63 return PP_OK_COMPLETIONPENDING;
64 }
65
66 int32_t PepperVideoSourceHost::OnHostMsgGetFrame(
67 HostMessageContext* context) {
68 ReplyMessageContext reply_context = context->MakeReplyMessageContext();
69 // TODO(ronghuawu) Wait until a frame with timestamp > last_timestamp_ is
70 // available.
71 // Create an image data resource to hold the frame pixels.
72 PP_ImageDataDesc desc;
73 IPC::PlatformFileForTransit image_handle;
74 uint32_t byte_count;
75 ppapi::ScopedPPResource resource(
76 ppapi::ScopedPPResource::PassRef(),
77 ppapi::proxy::PPB_ImageData_Proxy::CreateImageData(
78 pp_instance(),
79 webkit::ppapi::PPB_ImageData_Impl::GetNativeImageDataFormat(),
80 PP_MakeSize(0, 0),
81 false /* init_to_zero */,
82 false /* is_nacl_plugin */,
83 &desc, &image_handle, &byte_count));
84 if (!resource.get())
85 return PP_ERROR_FAILED;
86
87 ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_ImageData_API>
88 enter_resource(resource, false);
89 if (enter_resource.failed())
90 return PP_ERROR_FAILED;
91
92 webkit::ppapi::PPB_ImageData_Impl* image_data =
93 static_cast<webkit::ppapi::PPB_ImageData_Impl*>(enter_resource.object());
94 webkit::ppapi::ImageDataAutoMapper mapper(image_data);
95 if (!mapper.is_valid())
96 return PP_ERROR_FAILED;
97
98 // TODO(ronghuawu) Copy frame pixels to canvas.
99
100 ppapi::HostResource image_data_resource;
101 image_data_resource.SetHostResource(pp_instance(), resource.get());
102 double timestamp = 0;
103 reply_context.params.set_result(PP_OK);
104 host()->SendReply(
105 reply_context,
106 PpapiPluginMsg_VideoSource_GetFrameReply(image_data_resource, timestamp));
107 last_timestamp_ = timestamp;
108 return PP_OK_COMPLETIONPENDING;
109 }
110
111 int32_t PepperVideoSourceHost::OnHostMsgClose(HostMessageContext* context) {
112 // TODO(ronghuawu) Close the video stream.
113 return PP_OK;
114 }
115
116 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_video_source_host.h ('k') | ppapi/ppapi_proxy.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698