| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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/media_stream_video_track_resource.h" |
| 6 |
| 7 #include "ppapi/proxy/io_stream_resource.h" |
| 8 #include "ppapi/proxy/ppapi_messages.h" |
| 9 #include "ppapi/proxy/video_frame_resource.h" |
| 10 #include "ppapi/shared_impl/var.h" |
| 11 #include "ppapi/shared_impl/video_frame.h" |
| 12 #include "ppapi/thunk/enter.h" |
| 13 |
| 14 namespace ppapi { |
| 15 namespace proxy { |
| 16 |
| 17 MediaStreamVideoTrackResource::MediaStreamVideoTrackResource( |
| 18 Connection connection, |
| 19 PP_Instance instance, |
| 20 int pending_renderer_id, |
| 21 const std::string& id) |
| 22 : IOStreamResource(connection, instance, pending_renderer_id, true), |
| 23 id_(id), |
| 24 current_frame_(NULL), |
| 25 get_frame_output_(NULL) { |
| 26 } |
| 27 |
| 28 MediaStreamVideoTrackResource::~MediaStreamVideoTrackResource() { |
| 29 ppapi::ProxyLock::AssertAcquiredDebugOnly(); |
| 30 } |
| 31 |
| 32 thunk::PPB_MediaStreamVideoTrack_API* |
| 33 MediaStreamVideoTrackResource::AsPPB_MediaStreamVideoTrack_API() { |
| 34 return this; |
| 35 } |
| 36 |
| 37 PP_Var MediaStreamVideoTrackResource::GetId() { |
| 38 return StringVar::StringToPPVar(id_); |
| 39 } |
| 40 |
| 41 PP_Bool MediaStreamVideoTrackResource::HasEnded() { |
| 42 return PP_FALSE; |
| 43 } |
| 44 |
| 45 int32_t MediaStreamVideoTrackResource::Configure(uint32_t max_buffered_frames) { |
| 46 return PP_OK; |
| 47 } |
| 48 |
| 49 int32_t MediaStreamVideoTrackResource::GetFrame( |
| 50 PP_Resource* frame, |
| 51 const scoped_refptr<ppapi::TrackedCallback>& callback) { |
| 52 if (TrackedCallback::IsPending(get_frame_callback_)) |
| 53 return PP_ERROR_INPROGRESS; |
| 54 int32_t result = CreateCurrentFrame(); |
| 55 if (result == PP_OK) { |
| 56 *frame = current_frame_->GetReference(); |
| 57 } else if (result == PP_OK_COMPLETIONPENDING) { |
| 58 get_frame_output_ = frame; |
| 59 get_frame_callback_ = callback; |
| 60 } |
| 61 return result; |
| 62 } |
| 63 |
| 64 int32_t MediaStreamVideoTrackResource::RecycleFrame(PP_Resource frame) { |
| 65 if (!frame) |
| 66 return PP_ERROR_BADRESOURCE; |
| 67 if (!current_frame_) |
| 68 return PP_ERROR_FAILED; |
| 69 if (current_frame_->pp_resource() != frame) |
| 70 return PP_ERROR_BADARGUMENT; |
| 71 |
| 72 Unlock(current_frame_->video_frame()); |
| 73 current_frame_->set_video_frame(NULL); |
| 74 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource( |
| 75 current_frame_->pp_resource()); |
| 76 current_frame_ = NULL; |
| 77 return PP_OK; |
| 78 } |
| 79 |
| 80 int32_t MediaStreamVideoTrackResource::Close() { |
| 81 return PP_OK; |
| 82 } |
| 83 |
| 84 void MediaStreamVideoTrackResource::OnReplyReceived( |
| 85 const proxy::ResourceMessageReplyParams& params, const IPC::Message& msg) { |
| 86 IPC_BEGIN_MESSAGE_MAP(MediaStreamVideoTrackResource, msg) |
| 87 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( |
| 88 IOStreamResource::OnReplyReceived(params, msg)) |
| 89 IPC_END_MESSAGE_MAP() |
| 90 } |
| 91 |
| 92 void MediaStreamVideoTrackResource::OnMoreBufferAvailable() { |
| 93 int32_t result = PP_ERROR_FAILED; |
| 94 if (TrackedCallback::IsPending(get_frame_callback_)) |
| 95 result = CreateCurrentFrame(); |
| 96 if (result == PP_OK) { |
| 97 *get_frame_output_ = current_frame_->GetReference(); |
| 98 get_frame_callback_->PostRun(PP_OK); |
| 99 get_frame_output_ = 0; |
| 100 get_frame_callback_ = NULL; |
| 101 } |
| 102 } |
| 103 |
| 104 int32_t MediaStreamVideoTrackResource::CreateCurrentFrame() { |
| 105 if (current_frame_) |
| 106 return PP_ERROR_INPROGRESS; |
| 107 if (!remaining()) |
| 108 return PP_OK_COMPLETIONPENDING; |
| 109 VideoFrame* frame = NULL; |
| 110 CHECK(Lock(reinterpret_cast<void **>(&frame), sizeof(VideoFrame)) == PP_OK); |
| 111 CHECK(Relock(frame, sizeof(VideoFrame) + frame->data_size) == PP_OK); |
| 112 current_frame_ = new VideoFrameResource(pp_instance(), frame); |
| 113 current_frame_->GetReference(); |
| 114 return PP_OK; |
| 115 } |
| 116 |
| 117 } // namespace proxy |
| 118 } // namespace ppapi |
| OLD | NEW |