Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: content/renderer/pepper/pepper_media_stream_track_host_base.cc

Issue 101463008: [NOT FOR REVIEW][PPAPI] Implement MediaStreamVideoTrack pepper API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Update Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "content/renderer/pepper/pepper_media_stream_track_host_base.h"
6
7 #include "content/public/renderer/render_thread.h"
8 #include "content/public/renderer/renderer_ppapi_host.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/host/dispatch_host_message.h"
11 #include "ppapi/host/host_message_context.h"
12 #include "ppapi/host/ppapi_host.h"
13 #include "ppapi/proxy/ppapi_messages.h"
14 #include "ppapi/shared_impl/media_stream_frame.h"
15
16 using ppapi::host::HostMessageContext;
17 using ppapi::proxy::SerializedHandle;
18
19 namespace content {
20
21 PepperMediaStreamTrackHostBase::PepperMediaStreamTrackHostBase(
22 RendererPpapiHost* host,
23 PP_Instance instance,
24 PP_Resource resource)
25 : ResourceHost(host->GetPpapiHost(), instance, resource),
26 host_(host) {
27 }
28
29 PepperMediaStreamTrackHostBase::~PepperMediaStreamTrackHostBase() {
30 }
31
32 int32_t PepperMediaStreamTrackHostBase::OnResourceMessageReceived(
33 const IPC::Message& msg,
34 HostMessageContext* context) {
35 IPC_BEGIN_MESSAGE_MAP(PepperMediaStreamTrackHostBase, msg)
36 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
37 PpapiHostMsg_MediaStreamTrack_EnqueueFrame, OnHostMsgEnqueueFrame)
38 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
39 PpapiHostMsg_MediaStreamTrack_Close, OnHostMsgClose)
40 IPC_END_MESSAGE_MAP()
41 return ppapi::host::ResourceHost::OnResourceMessageReceived(msg, context);
42 }
43
44 bool PepperMediaStreamTrackHostBase::InitFrames(int32_t number_of_frames,
45 int32_t frame_size) {
46 DCHECK_GT(number_of_frames, 0);
47 DCHECK_GT(frame_size,
48 static_cast<int32_t>(sizeof(ppapi::MediaStreamFrame::Header)));
49 // Make each frame 4 byte aligned.
50 frame_size = (frame_size + 3) & ~0x3;
51
52 int32_t size = number_of_frames * frame_size;
53 content::RenderThread* render_thread = content::RenderThread::Get();
54 scoped_ptr<base::SharedMemory> shm(
55 render_thread->HostAllocateSharedMemoryBuffer(size).Pass());
56 if (!shm)
57 return false;
58
59 base::SharedMemoryHandle shm_handle = shm->handle();
60 if (!SetFrames(number_of_frames, frame_size, shm.Pass()))
61 return false;
62
63 base::PlatformFile platform_file =
64 #if defined(OS_WIN)
65 reinterpret_cast<HANDLE>(static_cast<intptr_t>(shm_handle));
66 #elif defined(OS_POSIX)
67 shm_handle.fd;
68 #else
69 #error Not implemented.
70 #endif
71 SerializedHandle handle(
72 host_->ShareHandleWithRemote(platform_file, false), size);
73 host()->SendUnsolicitedReplyWithHandles(pp_resource(),
74 PpapiPluginMsg_MediaStreamTrack_InitFrames(number_of_frames, frame_size),
75 std::vector<SerializedHandle>(1, handle));
76 return true;
77 }
78
79 void PepperMediaStreamTrackHostBase::PluginEnqueueFrame(int32_t index) {
80 DCHECK_GE(index, 0);
81 DCHECK_LT(index, number_of_frames());
82 host()->SendUnsolicitedReply(pp_resource(),
83 PpapiPluginMsg_MediaStreamTrack_EnqueueFrame(index));
84 }
85
86 int32_t PepperMediaStreamTrackHostBase::OnHostMsgEnqueueFrame(
87 HostMessageContext* context,
88 int32_t index) {
89 EnqueueFrame(index);
90 return PP_OK;
91 }
92
93 int32_t PepperMediaStreamTrackHostBase::OnHostMsgClose(
94 HostMessageContext* context) {
95 OnClose();
96 return PP_OK;
97 }
98
99 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698