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

Side by Side Diff: ppapi/proxy/video_source_resource.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 | « ppapi/proxy/video_source_resource.h ('k') | ppapi/shared_impl/resource.h » ('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 "ppapi/proxy/video_source_resource.h"
6
7 #include "base/bind.h"
8 #include "ipc/ipc_message.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/private/pp_video_frame_private.h"
11 #include "ppapi/proxy/ppapi_messages.h"
12 #include "ppapi/shared_impl/ppapi_globals.h"
13 #include "ppapi/shared_impl/resource_tracker.h"
14 #include "ppapi/shared_impl/var.h"
15 #include "ppapi/thunk/enter.h"
16
17 using ppapi::thunk::EnterResourceNoLock;
18 using ppapi::thunk::PPB_VideoSource_Private_API;
19
20 namespace ppapi {
21 namespace proxy {
22
23 VideoSourceResource::VideoSourceResource(
24 Connection connection,
25 PP_Instance instance)
26 : PluginResource(connection, instance),
27 is_open_(false) {
28 SendCreate(RENDERER, PpapiHostMsg_VideoSource_Create());
29 }
30
31 VideoSourceResource::~VideoSourceResource() {
32 }
33
34 PPB_VideoSource_Private_API*
35 VideoSourceResource::AsPPB_VideoSource_Private_API() {
36 return this;
37 }
38
39 int32_t VideoSourceResource::Open(
40 const PP_Var& stream_url,
41 scoped_refptr<TrackedCallback> callback) {
42 if (TrackedCallback::IsPending(open_callback_))
43 return PP_ERROR_INPROGRESS;
44
45 open_callback_ = callback;
46
47 scoped_refptr<StringVar> stream_url_var = StringVar::FromPPVar(stream_url);
48 const uint32_t kMaxStreamIdSizeInBytes = 16384;
49 if (!stream_url_var ||
50 stream_url_var->value().size() > kMaxStreamIdSizeInBytes)
51 return PP_ERROR_BADARGUMENT;
52 Call<PpapiPluginMsg_VideoSource_OpenReply>(RENDERER,
53 PpapiHostMsg_VideoSource_Open(stream_url_var->value()),
54 base::Bind(&VideoSourceResource::OnPluginMsgOpenComplete, this));
55 return PP_OK_COMPLETIONPENDING;
56 }
57
58 int32_t VideoSourceResource::GetFrame(
59 PP_VideoFrame_Private* frame,
60 scoped_refptr<TrackedCallback> callback) {
61 if (!is_open_)
62 return PP_ERROR_FAILED;
63
64 if (TrackedCallback::IsPending(get_frame_callback_))
65 return PP_ERROR_INPROGRESS;
66
67 get_frame_callback_ = callback;
68
69 Call<PpapiPluginMsg_VideoSource_GetFrameReply>(RENDERER,
70 PpapiHostMsg_VideoSource_GetFrame(),
71 base::Bind(&VideoSourceResource::OnPluginMsgGetFrameComplete, this,
72 frame));
73 return PP_OK_COMPLETIONPENDING;
74 }
75
76 void VideoSourceResource::Close() {
77 Post(RENDERER, PpapiHostMsg_VideoSource_Close());
78
79 if (TrackedCallback::IsPending(open_callback_))
80 open_callback_->PostAbort();
81 if (TrackedCallback::IsPending(get_frame_callback_))
82 get_frame_callback_->PostAbort();
83 }
84
85 void VideoSourceResource::OnPluginMsgOpenComplete(
86 const ResourceMessageReplyParams& params) {
87 if (TrackedCallback::IsPending(open_callback_)) {
88 int32_t result = params.result();
89 if (result == PP_OK)
90 is_open_ = true;
91 open_callback_->Run(result);
92 }
93 }
94
95 void VideoSourceResource::OnPluginMsgGetFrameComplete(
96 PP_VideoFrame_Private* frame,
97 const ResourceMessageReplyParams& params,
98 const HostResource& image_data,
99 PP_TimeTicks timestamp) {
100 // The callback may have been aborted by Close().
101 if (TrackedCallback::IsPending(get_frame_callback_)) {
102 int32_t result = params.result();
103 if (result == PP_OK) {
104 frame->timestamp = timestamp;
105 frame->image_data = image_data.host_resource();
106 }
107 get_frame_callback_->Run(result);
108 }
109 }
110
111 } // namespace proxy
112 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/video_source_resource.h ('k') | ppapi/shared_impl/resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698