| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014 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_track_resource_base.h" |
| 6 |
| 7 #include "ppapi/proxy/ppapi_messages.h" |
| 8 #include "ppapi/shared_impl/var.h" |
| 9 |
| 10 namespace ppapi { |
| 11 namespace proxy { |
| 12 |
| 13 MediaStreamTrackResourceBase::MediaStreamTrackResourceBase( |
| 14 Connection connection, |
| 15 PP_Instance instance, |
| 16 int pending_renderer_id, |
| 17 const std::string& id) |
| 18 : PluginResource(connection, instance), |
| 19 id_(id), |
| 20 has_ended_(false) { |
| 21 AttachToPendingHost(RENDERER, pending_renderer_id); |
| 22 } |
| 23 |
| 24 MediaStreamTrackResourceBase::~MediaStreamTrackResourceBase() { |
| 25 } |
| 26 |
| 27 void MediaStreamTrackResourceBase::HostEnqueueFrame(int32_t index) { |
| 28 DCHECK_GE(index, 0); |
| 29 DCHECK_LT(index, number_of_frames()); |
| 30 Post(RENDERER, PpapiHostMsg_MediaStreamTrack_EnqueueFrame(index)); |
| 31 } |
| 32 |
| 33 thunk::PPB_MediaStreamTrack_API* |
| 34 MediaStreamTrackResourceBase::AsPPB_MediaStreamTrack_API() { |
| 35 return this; |
| 36 } |
| 37 |
| 38 PP_Var MediaStreamTrackResourceBase::GetId() { |
| 39 return StringVar::StringToPPVar(id_); |
| 40 } |
| 41 |
| 42 PP_Bool MediaStreamTrackResourceBase::HasEnded() { |
| 43 return PP_FromBool(has_ended_); |
| 44 } |
| 45 |
| 46 void MediaStreamTrackResourceBase::Close() { |
| 47 if (!has_ended_) { |
| 48 Post(RENDERER, PpapiHostMsg_MediaStreamTrack_Close()); |
| 49 has_ended_ = true; |
| 50 } |
| 51 } |
| 52 |
| 53 void MediaStreamTrackResourceBase::OnReplyReceived( |
| 54 const ResourceMessageReplyParams& params, |
| 55 const IPC::Message& msg) { |
| 56 IPC_BEGIN_MESSAGE_MAP(MediaStreamTrackResourceBase, msg) |
| 57 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( |
| 58 PpapiPluginMsg_MediaStreamTrack_InitFrames, OnPluginMsgInitFrames) |
| 59 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( |
| 60 PpapiPluginMsg_MediaStreamTrack_EnqueueFrame, OnPluginMsgEnqueueFrame) |
| 61 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( |
| 62 PluginResource::OnReplyReceived(params, msg)) |
| 63 IPC_END_MESSAGE_MAP() |
| 64 } |
| 65 |
| 66 void MediaStreamTrackResourceBase::OnPluginMsgInitFrames( |
| 67 const ResourceMessageReplyParams& params, |
| 68 int32_t number_of_frames, |
| 69 int32_t frame_size) { |
| 70 base::SharedMemoryHandle shm_handle = base::SharedMemory::NULLHandle(); |
| 71 params.TakeSharedMemoryHandleAtIndex(0, &shm_handle); |
| 72 SetFrames(number_of_frames, frame_size, |
| 73 scoped_ptr<base::SharedMemory>(new base::SharedMemory(shm_handle, true))); |
| 74 } |
| 75 |
| 76 void MediaStreamTrackResourceBase::OnPluginMsgEnqueueFrame( |
| 77 const ResourceMessageReplyParams& params, |
| 78 int32_t index) { |
| 79 EnqueueFrame(index); |
| 80 } |
| 81 |
| 82 } // namespace proxy |
| 83 } // namespace ppapi |
| OLD | NEW |