Chromium Code Reviews| Index: ppapi/proxy/video_destination_resource.cc |
| diff --git a/ppapi/proxy/video_destination_resource.cc b/ppapi/proxy/video_destination_resource.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c4ecc5731338733b3544ace4434c9dce937ce8d3 |
| --- /dev/null |
| +++ b/ppapi/proxy/video_destination_resource.cc |
| @@ -0,0 +1,94 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ppapi/proxy/video_destination_resource.h" |
| + |
| +#include "base/bind.h" |
| +#include "ipc/ipc_message.h" |
| +#include "ppapi/c/pp_errors.h" |
| +#include "ppapi/c/private/pp_video_frame_private.h" |
| +#include "ppapi/proxy/ppapi_messages.h" |
| +#include "ppapi/shared_impl/array_writer.h" |
|
yzshen1
2013/05/01 23:18:33
you probably don't need this.
bbudge
2013/05/02 21:39:06
Done.
|
| +#include "ppapi/shared_impl/ppapi_globals.h" |
| +#include "ppapi/shared_impl/resource_tracker.h" |
| +#include "ppapi/shared_impl/var.h" |
|
yzshen1
2013/05/01 23:18:33
this has been included in the .h file.
bbudge
2013/05/02 21:39:06
Done.
|
| +#include "ppapi/thunk/enter.h" |
| +#include "ppapi/thunk/ppb_image_data_api.h" |
| + |
| +using ppapi::thunk::EnterResourceNoLock; |
| +using ppapi::thunk::PPB_VideoDestination_Private_API; |
| + |
| +namespace { |
|
yzshen1
2013/05/01 23:18:33
this is not needed.
bbudge
2013/05/02 21:39:06
Done.
|
| + |
| +} // namespace |
| + |
| +namespace ppapi { |
| +namespace proxy { |
| + |
| +VideoDestinationResource::VideoDestinationResource( |
| + Connection connection, |
| + PP_Instance instance) |
| + : PluginResource(connection, instance) { |
| + SendCreate(RENDERER, PpapiHostMsg_VideoDestination_Create()); |
| +} |
| + |
| +VideoDestinationResource::~VideoDestinationResource() { |
| +} |
| + |
| +PPB_VideoDestination_Private_API* |
| + VideoDestinationResource::AsPPB_VideoDestination_Private_API() { |
| + return this; |
| +} |
| + |
| +int32_t VideoDestinationResource::Open( |
| + PP_Var stream_url, |
| + scoped_refptr<TrackedCallback> callback) { |
| + scoped_refptr<StringVar> stream_url_var = StringVar::FromPPVar(stream_url); |
| + const uint32_t kMaxStreamIdSizeInBytes = 16384; |
| + if (!stream_url_var || |
| + stream_url_var->value().size() > kMaxStreamIdSizeInBytes) |
| + return PP_ERROR_BADARGUMENT; |
| + Call<PpapiPluginMsg_VideoDestination_OpenReply>(RENDERER, |
| + PpapiHostMsg_VideoDestination_Open(stream_url_var->value()), |
| + base::Bind(&VideoDestinationResource::OnPluginMsgOpenComplete, |
| + this, |
| + callback)); |
| + return PP_OK_COMPLETIONPENDING; |
| +} |
| + |
| +int32_t VideoDestinationResource::PutFrame( |
| + const PP_VideoFrame_Private& frame) { |
| + thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_image( |
| + frame.image_data, true); |
| + if (enter_image.failed()) |
| + return PP_ERROR_BADRESOURCE; |
| + |
| + // Check that the PP_Instance matches. |
| + Resource* image_object = |
| + PpapiGlobals::Get()->GetResourceTracker()->GetResource(frame.image_data); |
| + if (!image_object || pp_instance() != image_object->pp_instance()) { |
| + Log(PP_LOGLEVEL_ERROR, |
| + "VideoDestinationPrivateResource.PutFrame: Bad image resource."); |
| + return PP_ERROR_BADRESOURCE; |
| + } |
| + |
| + Post(RENDERER, |
| + PpapiHostMsg_VideoDestination_PutFrame(image_object->host_resource(), |
| + frame.timestamp)); |
| + return PP_OK; |
| +} |
| + |
| +void VideoDestinationResource::Close() { |
| + Post(RENDERER, PpapiHostMsg_VideoDestination_Close()); |
| +} |
| + |
| +void VideoDestinationResource::OnPluginMsgOpenComplete( |
| + scoped_refptr<TrackedCallback> callback, |
| + const ResourceMessageReplyParams& params) { |
| + int32_t result = params.result(); |
| + callback->Run(result); |
| +} |
| + |
| +} // namespace proxy |
| +} // namespace ppapi |