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

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

Issue 128683003: [PPAPI] Implement media stream video track API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@video_track_impl_cl
Patch Set: Fix review issue 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 frame_buffer_(this) {
28 }
29
30 PepperMediaStreamTrackHostBase::~PepperMediaStreamTrackHostBase() {
31 }
32
33 bool PepperMediaStreamTrackHostBase::InitFrames(int32_t number_of_frames,
34 int32_t frame_size) {
35 DCHECK_GT(number_of_frames, 0);
36 DCHECK_GT(frame_size,
37 static_cast<int32_t>(sizeof(ppapi::MediaStreamFrame::Header)));
38 // Make each frame 4 byte aligned.
39 frame_size = (frame_size + 3) & ~0x3;
40
41 int32_t size = number_of_frames * frame_size;
42 content::RenderThread* render_thread = content::RenderThread::Get();
43 scoped_ptr<base::SharedMemory> shm(
44 render_thread->HostAllocateSharedMemoryBuffer(size).Pass());
45 if (!shm)
46 return false;
47
48 base::SharedMemoryHandle shm_handle = shm->handle();
49 if (!frame_buffer_.SetFrames(number_of_frames, frame_size, shm.Pass(), true))
50 return false;
51
52 base::PlatformFile platform_file =
53 #if defined(OS_WIN)
54 reinterpret_cast<HANDLE>(static_cast<intptr_t>(shm_handle));
55 #elif defined(OS_POSIX)
56 shm_handle.fd;
57 #else
58 #error Not implemented.
59 #endif
60 SerializedHandle handle(
61 host_->ShareHandleWithRemote(platform_file, false), size);
62 host()->SendUnsolicitedReplyWithHandles(pp_resource(),
63 PpapiPluginMsg_MediaStreamTrack_InitFrames(number_of_frames, frame_size),
64 std::vector<SerializedHandle>(1, handle));
65 return true;
66 }
67
68 void PepperMediaStreamTrackHostBase::PluginEnqueueFrame(int32_t index) {
69 DCHECK_GE(index, 0);
70 DCHECK_LT(index, frame_buffer_.number_of_frames());
71 host()->SendUnsolicitedReply(pp_resource(),
72 PpapiPluginMsg_MediaStreamTrack_EnqueueFrame(index));
73 }
74
75 int32_t PepperMediaStreamTrackHostBase::OnResourceMessageReceived(
76 const IPC::Message& msg,
77 HostMessageContext* context) {
78 IPC_BEGIN_MESSAGE_MAP(PepperMediaStreamTrackHostBase, msg)
79 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
80 PpapiHostMsg_MediaStreamTrack_EnqueueFrame, OnHostMsgEnqueueFrame)
81 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
82 PpapiHostMsg_MediaStreamTrack_Close, OnHostMsgClose)
83 IPC_END_MESSAGE_MAP()
84 return ppapi::host::ResourceHost::OnResourceMessageReceived(msg, context);
85 }
86
87 int32_t PepperMediaStreamTrackHostBase::OnHostMsgEnqueueFrame(
88 HostMessageContext* context,
89 int32_t index) {
90 frame_buffer_.EnqueueFrame(index);
91 return PP_OK;
92 }
93
94 int32_t PepperMediaStreamTrackHostBase::OnHostMsgClose(
95 HostMessageContext* context) {
96 OnClose();
97 return PP_OK;
98 }
99
100 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698