| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/pepper/pepper_media_stream_track_host_base.h" | 5 #include "content/renderer/pepper/pepper_media_stream_track_host_base.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/public/renderer/render_thread.h" | 8 #include "content/public/renderer/render_thread.h" |
| 9 #include "content/public/renderer/renderer_ppapi_host.h" | 9 #include "content/public/renderer/renderer_ppapi_host.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| 11 #include "ppapi/host/dispatch_host_message.h" | 11 #include "ppapi/host/dispatch_host_message.h" |
| 12 #include "ppapi/host/host_message_context.h" | 12 #include "ppapi/host/host_message_context.h" |
| 13 #include "ppapi/host/ppapi_host.h" | 13 #include "ppapi/host/ppapi_host.h" |
| 14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
| 15 #include "ppapi/shared_impl/media_stream_frame.h" | 15 #include "ppapi/shared_impl/media_stream_buffer.h" |
| 16 | 16 |
| 17 using ppapi::host::HostMessageContext; | 17 using ppapi::host::HostMessageContext; |
| 18 using ppapi::proxy::SerializedHandle; | 18 using ppapi::proxy::SerializedHandle; |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 PepperMediaStreamTrackHostBase::PepperMediaStreamTrackHostBase( | 22 PepperMediaStreamTrackHostBase::PepperMediaStreamTrackHostBase( |
| 23 RendererPpapiHost* host, | 23 RendererPpapiHost* host, |
| 24 PP_Instance instance, | 24 PP_Instance instance, |
| 25 PP_Resource resource) | 25 PP_Resource resource) |
| 26 : ResourceHost(host->GetPpapiHost(), instance, resource), | 26 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 27 host_(host), | 27 host_(host), |
| 28 frame_buffer_(this) { | 28 buffer_manager_(this) { |
| 29 } | 29 } |
| 30 | 30 |
| 31 PepperMediaStreamTrackHostBase::~PepperMediaStreamTrackHostBase() { | 31 PepperMediaStreamTrackHostBase::~PepperMediaStreamTrackHostBase() { |
| 32 } | 32 } |
| 33 | 33 |
| 34 bool PepperMediaStreamTrackHostBase::InitFrames(int32_t number_of_frames, | 34 bool PepperMediaStreamTrackHostBase::InitBuffers(int32_t number_of_buffers, |
| 35 int32_t frame_size) { | 35 int32_t buffer_size) { |
| 36 DCHECK_GT(number_of_frames, 0); | 36 DCHECK_GT(number_of_buffers, 0); |
| 37 DCHECK_GT(frame_size, | 37 DCHECK_GT(buffer_size, |
| 38 static_cast<int32_t>(sizeof(ppapi::MediaStreamFrame::Header))); | 38 static_cast<int32_t>(sizeof(ppapi::MediaStreamBuffer::Header))); |
| 39 // Make each frame 4 byte aligned. | 39 // Make each buffer 4 byte aligned. |
| 40 frame_size = (frame_size + 3) & ~0x3; | 40 buffer_size = (buffer_size + 3) & ~0x3; |
| 41 | 41 |
| 42 // TODO(penghuang): |HostAllocateSharedMemoryBuffer| uses sync IPC. We should | 42 // TODO(penghuang): |HostAllocateSharedMemoryBuffer| uses sync IPC. We should |
| 43 // avoid it. | 43 // avoid it. |
| 44 int32_t size = number_of_frames * frame_size; | 44 int32_t size = number_of_buffers * buffer_size; |
| 45 content::RenderThread* render_thread = content::RenderThread::Get(); | 45 content::RenderThread* render_thread = content::RenderThread::Get(); |
| 46 scoped_ptr<base::SharedMemory> shm( | 46 scoped_ptr<base::SharedMemory> shm( |
| 47 render_thread->HostAllocateSharedMemoryBuffer(size).Pass()); | 47 render_thread->HostAllocateSharedMemoryBuffer(size).Pass()); |
| 48 if (!shm) | 48 if (!shm) |
| 49 return false; | 49 return false; |
| 50 | 50 |
| 51 base::SharedMemoryHandle shm_handle = shm->handle(); | 51 base::SharedMemoryHandle shm_handle = shm->handle(); |
| 52 if (!frame_buffer_.SetFrames(number_of_frames, frame_size, shm.Pass(), true)) | 52 if (!buffer_manager_.SetBuffers( |
| 53 number_of_buffers, buffer_size, shm.Pass(), true)) { |
| 53 return false; | 54 return false; |
| 55 } |
| 54 | 56 |
| 55 base::PlatformFile platform_file = | 57 base::PlatformFile platform_file = |
| 56 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
| 57 shm_handle; | 59 shm_handle; |
| 58 #elif defined(OS_POSIX) | 60 #elif defined(OS_POSIX) |
| 59 shm_handle.fd; | 61 shm_handle.fd; |
| 60 #else | 62 #else |
| 61 #error Not implemented. | 63 #error Not implemented. |
| 62 #endif | 64 #endif |
| 63 SerializedHandle handle( | 65 SerializedHandle handle( |
| 64 host_->ShareHandleWithRemote(platform_file, false), size); | 66 host_->ShareHandleWithRemote(platform_file, false), size); |
| 65 host()->SendUnsolicitedReplyWithHandles(pp_resource(), | 67 host()->SendUnsolicitedReplyWithHandles(pp_resource(), |
| 66 PpapiPluginMsg_MediaStreamTrack_InitFrames(number_of_frames, frame_size), | 68 PpapiPluginMsg_MediaStreamTrack_InitBuffers(number_of_buffers, |
| 69 buffer_size), |
| 67 std::vector<SerializedHandle>(1, handle)); | 70 std::vector<SerializedHandle>(1, handle)); |
| 68 return true; | 71 return true; |
| 69 } | 72 } |
| 70 | 73 |
| 71 void PepperMediaStreamTrackHostBase::SendEnqueueFrameMessageToPlugin( | 74 void PepperMediaStreamTrackHostBase::SendEnqueueBufferMessageToPlugin( |
| 72 int32_t index) { | 75 int32_t index) { |
| 73 DCHECK_GE(index, 0); | 76 DCHECK_GE(index, 0); |
| 74 DCHECK_LT(index, frame_buffer_.number_of_frames()); | 77 DCHECK_LT(index, buffer_manager_.number_of_buffers()); |
| 75 host()->SendUnsolicitedReply(pp_resource(), | 78 host()->SendUnsolicitedReply(pp_resource(), |
| 76 PpapiPluginMsg_MediaStreamTrack_EnqueueFrame(index)); | 79 PpapiPluginMsg_MediaStreamTrack_EnqueueBuffer(index)); |
| 77 } | 80 } |
| 78 | 81 |
| 79 int32_t PepperMediaStreamTrackHostBase::OnResourceMessageReceived( | 82 int32_t PepperMediaStreamTrackHostBase::OnResourceMessageReceived( |
| 80 const IPC::Message& msg, | 83 const IPC::Message& msg, |
| 81 HostMessageContext* context) { | 84 HostMessageContext* context) { |
| 82 IPC_BEGIN_MESSAGE_MAP(PepperMediaStreamTrackHostBase, msg) | 85 IPC_BEGIN_MESSAGE_MAP(PepperMediaStreamTrackHostBase, msg) |
| 83 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | 86 PPAPI_DISPATCH_HOST_RESOURCE_CALL( |
| 84 PpapiHostMsg_MediaStreamTrack_EnqueueFrame, OnHostMsgEnqueueFrame) | 87 PpapiHostMsg_MediaStreamTrack_EnqueueBuffer, OnHostMsgEnqueueBuffer) |
| 85 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( | 88 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( |
| 86 PpapiHostMsg_MediaStreamTrack_Close, OnHostMsgClose) | 89 PpapiHostMsg_MediaStreamTrack_Close, OnHostMsgClose) |
| 87 IPC_END_MESSAGE_MAP() | 90 IPC_END_MESSAGE_MAP() |
| 88 return ppapi::host::ResourceHost::OnResourceMessageReceived(msg, context); | 91 return ppapi::host::ResourceHost::OnResourceMessageReceived(msg, context); |
| 89 } | 92 } |
| 90 | 93 |
| 91 int32_t PepperMediaStreamTrackHostBase::OnHostMsgEnqueueFrame( | 94 int32_t PepperMediaStreamTrackHostBase::OnHostMsgEnqueueBuffer( |
| 92 HostMessageContext* context, | 95 HostMessageContext* context, |
| 93 int32_t index) { | 96 int32_t index) { |
| 94 frame_buffer_.EnqueueFrame(index); | 97 buffer_manager_.EnqueueBuffer(index); |
| 95 return PP_OK; | 98 return PP_OK; |
| 96 } | 99 } |
| 97 | 100 |
| 98 int32_t PepperMediaStreamTrackHostBase::OnHostMsgClose( | 101 int32_t PepperMediaStreamTrackHostBase::OnHostMsgClose( |
| 99 HostMessageContext* context) { | 102 HostMessageContext* context) { |
| 100 OnClose(); | 103 OnClose(); |
| 101 return PP_OK; | 104 return PP_OK; |
| 102 } | 105 } |
| 103 | 106 |
| 104 } // namespace content | 107 } // namespace content |
| OLD | NEW |