Delete unused downloads page asset.
[chromium-blink-merge.git] / ppapi / proxy / video_destination_resource.cc
blob5175705160e69b83d902279c43d94fa899ad5901
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.
5 #include "ppapi/proxy/video_destination_resource.h"
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 #include "ppapi/thunk/ppb_image_data_api.h"
18 using ppapi::thunk::EnterResourceNoLock;
19 using ppapi::thunk::PPB_VideoDestination_Private_API;
21 namespace ppapi {
22 namespace proxy {
24 VideoDestinationResource::VideoDestinationResource(
25 Connection connection,
26 PP_Instance instance)
27 : PluginResource(connection, instance),
28 is_open_(false) {
29 SendCreate(RENDERER, PpapiHostMsg_VideoDestination_Create());
32 VideoDestinationResource::~VideoDestinationResource() {
35 PPB_VideoDestination_Private_API*
36 VideoDestinationResource::AsPPB_VideoDestination_Private_API() {
37 return this;
40 int32_t VideoDestinationResource::Open(
41 const PP_Var& stream_url,
42 scoped_refptr<TrackedCallback> callback) {
43 if (TrackedCallback::IsPending(open_callback_))
44 return PP_ERROR_INPROGRESS;
46 open_callback_ = callback;
48 scoped_refptr<StringVar> stream_url_var = StringVar::FromPPVar(stream_url);
49 const uint32_t kMaxStreamIdSizeInBytes = 16384;
50 if (!stream_url_var.get() ||
51 stream_url_var->value().size() > kMaxStreamIdSizeInBytes)
52 return PP_ERROR_BADARGUMENT;
53 Call<PpapiPluginMsg_VideoDestination_OpenReply>(RENDERER,
54 PpapiHostMsg_VideoDestination_Open(stream_url_var->value()),
55 base::Bind(&VideoDestinationResource::OnPluginMsgOpenComplete, this));
56 return PP_OK_COMPLETIONPENDING;
59 int32_t VideoDestinationResource::PutFrame(
60 const PP_VideoFrame_Private& frame) {
61 if (!is_open_)
62 return PP_ERROR_FAILED;
64 thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_image(
65 frame.image_data, true);
66 if (enter_image.failed())
67 return PP_ERROR_BADRESOURCE;
69 // Check that the PP_Instance matches.
70 Resource* image_object =
71 PpapiGlobals::Get()->GetResourceTracker()->GetResource(frame.image_data);
72 if (!image_object || pp_instance() != image_object->pp_instance()) {
73 Log(PP_LOGLEVEL_ERROR,
74 "VideoDestinationPrivateResource.PutFrame: Bad image resource.");
75 return PP_ERROR_BADRESOURCE;
78 Post(RENDERER,
79 PpapiHostMsg_VideoDestination_PutFrame(image_object->host_resource(),
80 frame.timestamp));
81 return PP_OK;
84 void VideoDestinationResource::Close() {
85 Post(RENDERER, PpapiHostMsg_VideoDestination_Close());
87 if (TrackedCallback::IsPending(open_callback_))
88 open_callback_->PostAbort();
91 void VideoDestinationResource::OnPluginMsgOpenComplete(
92 const ResourceMessageReplyParams& params) {
93 if (TrackedCallback::IsPending(open_callback_)) {
94 int32_t result = params.result();
95 if (result == PP_OK)
96 is_open_ = true;
97 open_callback_->Run(result);
101 } // namespace proxy
102 } // namespace ppapi