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

Side by Side Diff: ppapi/proxy/video_destination_resource.cc

Issue 13771020: Add Pepper VideoReader and VideoWriter plumbing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address first round of comments. 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
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_destination_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/thunk/enter.h"
15 #include "ppapi/thunk/ppb_image_data_api.h"
16
17 using ppapi::thunk::EnterResourceNoLock;
18 using ppapi::thunk::PPB_VideoDestination_Private_API;
19
20 namespace ppapi {
21 namespace proxy {
22
23 VideoDestinationResource::VideoDestinationResource(
24 Connection connection,
25 PP_Instance instance)
26 : PluginResource(connection, instance),
27 is_open_(false) {
28 SendCreate(RENDERER, PpapiHostMsg_VideoDestination_Create());
29 }
30
31 VideoDestinationResource::~VideoDestinationResource() {
32 }
33
34 PPB_VideoDestination_Private_API*
35 VideoDestinationResource::AsPPB_VideoDestination_Private_API() {
36 return this;
37 }
38
39 int32_t VideoDestinationResource::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_VideoDestination_OpenReply>(RENDERER,
53 PpapiHostMsg_VideoDestination_Open(stream_url_var->value()),
54 base::Bind(&VideoDestinationResource::OnPluginMsgOpenComplete, this));
55 return PP_OK_COMPLETIONPENDING;
56 }
57
58 int32_t VideoDestinationResource::PutFrame(
59 const PP_VideoFrame_Private& frame) {
60 if (!is_open_)
61 return PP_ERROR_FAILED;
62
63 thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_image(
64 frame.image_data, true);
65 if (enter_image.failed())
66 return PP_ERROR_BADRESOURCE;
67
68 // Check that the PP_Instance matches.
69 Resource* image_object =
70 PpapiGlobals::Get()->GetResourceTracker()->GetResource(frame.image_data);
71 if (!image_object || pp_instance() != image_object->pp_instance()) {
72 Log(PP_LOGLEVEL_ERROR,
73 "VideoDestinationPrivateResource.PutFrame: Bad image resource.");
74 return PP_ERROR_BADRESOURCE;
75 }
76
77 Post(RENDERER,
78 PpapiHostMsg_VideoDestination_PutFrame(image_object->host_resource(),
79 frame.timestamp));
80 return PP_OK;
81 }
82
83 void VideoDestinationResource::Close() {
84 Post(RENDERER, PpapiHostMsg_VideoDestination_Close());
85
86 if (TrackedCallback::IsPending(open_callback_))
87 open_callback_->PostAbort();
88 }
89
90 void VideoDestinationResource::OnPluginMsgOpenComplete(
91 const ResourceMessageReplyParams& params) {
92 is_open_ = true;
yzshen1 2013/05/02 22:03:05 Maybe we set is_open_ to true only if open is succ
bbudge 2013/05/02 23:12:19 Done.
93 if (TrackedCallback::IsPending(open_callback_))
94 open_callback_->Run(params.result());
95 }
96
97 } // namespace proxy
98 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698