1 // Copyright 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.
5 #include "ppapi/proxy/media_stream_track_resource_base.h"
7 #include "base/logging.h"
8 #include "ppapi/proxy/ppapi_messages.h"
13 MediaStreamTrackResourceBase::MediaStreamTrackResourceBase(
14 Connection connection
,
16 int pending_renderer_id
,
17 const std::string
& id
)
18 : PluginResource(connection
, instance
),
19 buffer_manager_(this),
22 AttachToPendingHost(RENDERER
, pending_renderer_id
);
25 MediaStreamTrackResourceBase::MediaStreamTrackResourceBase(
26 Connection connection
,
28 : PluginResource(connection
, instance
),
29 buffer_manager_(this),
33 MediaStreamTrackResourceBase::~MediaStreamTrackResourceBase() {
36 void MediaStreamTrackResourceBase::SendEnqueueBufferMessageToHost(
39 DCHECK_LT(index
, buffer_manager()->number_of_buffers());
40 Post(RENDERER
, PpapiHostMsg_MediaStreamTrack_EnqueueBuffer(index
));
43 void MediaStreamTrackResourceBase::OnReplyReceived(
44 const ResourceMessageReplyParams
& params
,
45 const IPC::Message
& msg
) {
46 PPAPI_BEGIN_MESSAGE_MAP(MediaStreamTrackResourceBase
, msg
)
47 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
48 PpapiPluginMsg_MediaStreamTrack_InitBuffers
, OnPluginMsgInitBuffers
)
49 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
50 PpapiPluginMsg_MediaStreamTrack_EnqueueBuffer
, OnPluginMsgEnqueueBuffer
)
51 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
52 PpapiPluginMsg_MediaStreamTrack_EnqueueBuffers
,
53 OnPluginMsgEnqueueBuffers
)
54 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(
55 PluginResource::OnReplyReceived(params
, msg
))
56 PPAPI_END_MESSAGE_MAP()
59 void MediaStreamTrackResourceBase::CloseInternal() {
61 Post(RENDERER
, PpapiHostMsg_MediaStreamTrack_Close());
66 void MediaStreamTrackResourceBase::OnPluginMsgInitBuffers(
67 const ResourceMessageReplyParams
& params
,
68 int32_t number_of_buffers
,
71 base::SharedMemoryHandle shm_handle
= base::SharedMemory::NULLHandle();
72 params
.TakeSharedMemoryHandleAtIndex(0, &shm_handle
);
73 buffer_manager_
.SetBuffers(number_of_buffers
, buffer_size
,
74 scoped_ptr
<base::SharedMemory
>(new base::SharedMemory(shm_handle
,
79 void MediaStreamTrackResourceBase::OnPluginMsgEnqueueBuffer(
80 const ResourceMessageReplyParams
& params
,
82 buffer_manager_
.EnqueueBuffer(index
);
85 void MediaStreamTrackResourceBase::OnPluginMsgEnqueueBuffers(
86 const ResourceMessageReplyParams
& params
,
87 const std::vector
<int32_t>& indices
) {
88 for (size_t i
= 0; i
< indices
.size(); ++i
)
89 buffer_manager_
.EnqueueBuffer(indices
[i
]);