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

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: 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 "base/logging.h"
8 #include "content/public/renderer/render_thread.h"
9 #include "content/public/renderer/renderer_ppapi_host.h"
10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/host/dispatch_host_message.h"
12 #include "ppapi/host/host_message_context.h"
13 #include "ppapi/host/ppapi_host.h"
14 #include "ppapi/proxy/ppapi_messages.h"
15 #include "ppapi/shared_impl/media_stream_frame.h"
16
17 using ppapi::host::HostMessageContext;
18 using ppapi::proxy::SerializedHandle;
19
20 namespace content {
21
22 PepperMediaStreamTrackHostBase::PepperMediaStreamTrackHostBase(
23 RendererPpapiHost* host,
24 PP_Instance instance,
25 PP_Resource resource)
26 : ResourceHost(host->GetPpapiHost(), instance, resource),
27 host_(host),
28 frame_buffer_(this) {
29 }
30
31 PepperMediaStreamTrackHostBase::~PepperMediaStreamTrackHostBase() {
32 }
33
34 bool PepperMediaStreamTrackHostBase::InitFrames(int32_t number_of_frames,
35 int32_t frame_size) {
36 DCHECK_GT(number_of_frames, 0);
37 DCHECK_GT(frame_size,
38 static_cast<int32_t>(sizeof(ppapi::MediaStreamFrame::Header)));
39 // Make each frame 4 byte aligned.
40 frame_size = (frame_size + 3) & ~0x3;
41
42 int32_t size = number_of_frames * frame_size;
43 content::RenderThread* render_thread = content::RenderThread::Get();
44 scoped_ptr<base::SharedMemory> shm(
45 render_thread->HostAllocateSharedMemoryBuffer(size).Pass());
46 if (!shm)
47 return false;
48
49 base::SharedMemoryHandle shm_handle = shm->handle();
50 if (!frame_buffer_.SetFrames(number_of_frames, frame_size, shm.Pass(), true))
51 return false;
52
53 base::PlatformFile platform_file =
54 #if defined(OS_WIN)
55 shm_handle;
56 #elif defined(OS_POSIX)
57 shm_handle.fd;
58 #else
59 #error Not implemented.
60 #endif
61 SerializedHandle handle(
62 host_->ShareHandleWithRemote(platform_file, false), size);
63 host()->SendUnsolicitedReplyWithHandles(pp_resource(),
64 PpapiPluginMsg_MediaStreamTrack_InitFrames(number_of_frames, frame_size),
65 std::vector<SerializedHandle>(1, handle));
66 return true;
67 }
68
69 void PepperMediaStreamTrackHostBase::SendEnqueueFrameMessageToPlugin(
70 int32_t index) {
71 DCHECK_GE(index, 0);
72 DCHECK_LT(index, frame_buffer_.number_of_frames());
73 host()->SendUnsolicitedReply(pp_resource(),
74 PpapiPluginMsg_MediaStreamTrack_EnqueueFrame(index));
75 }
76
77 int32_t PepperMediaStreamTrackHostBase::OnResourceMessageReceived(
78 const IPC::Message& msg,
79 HostMessageContext* context) {
80 IPC_BEGIN_MESSAGE_MAP(PepperMediaStreamTrackHostBase, msg)
81 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
82 PpapiHostMsg_MediaStreamTrack_EnqueueFrame, OnHostMsgEnqueueFrame)
83 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
84 PpapiHostMsg_MediaStreamTrack_Close, OnHostMsgClose)
85 IPC_END_MESSAGE_MAP()
86 return ppapi::host::ResourceHost::OnResourceMessageReceived(msg, context);
87 }
88
89 int32_t PepperMediaStreamTrackHostBase::OnHostMsgEnqueueFrame(
90 HostMessageContext* context,
91 int32_t index) {
92 frame_buffer_.EnqueueFrame(index);
93 return PP_OK;
94 }
95
96 int32_t PepperMediaStreamTrackHostBase::OnHostMsgClose(
97 HostMessageContext* context) {
98 OnClose();
99 return PP_OK;
100 }
101
102 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698