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

Unified 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: Rebase it 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/pepper/pepper_media_stream_track_host_base.cc
diff --git a/content/renderer/pepper/pepper_media_stream_track_host_base.cc b/content/renderer/pepper/pepper_media_stream_track_host_base.cc
new file mode 100644
index 0000000000000000000000000000000000000000..49dd94913ba5f1b1d80dd33b086df76ad2738af3
--- /dev/null
+++ b/content/renderer/pepper/pepper_media_stream_track_host_base.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/pepper/pepper_media_stream_track_host_base.h"
+
+#include "content/public/renderer/render_thread.h"
+#include "content/public/renderer/renderer_ppapi_host.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/host/dispatch_host_message.h"
+#include "ppapi/host/host_message_context.h"
+#include "ppapi/host/ppapi_host.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/shared_impl/media_stream_frame.h"
+
+using ppapi::host::HostMessageContext;
+using ppapi::proxy::SerializedHandle;
+
+namespace content {
+
+PepperMediaStreamTrackHostBase::PepperMediaStreamTrackHostBase(
+ RendererPpapiHost* host,
+ PP_Instance instance,
+ PP_Resource resource)
+ : ResourceHost(host->GetPpapiHost(), instance, resource),
+ host_(host),
+ frame_buffer_(this) {
+}
+
+PepperMediaStreamTrackHostBase::~PepperMediaStreamTrackHostBase() {
+}
+
+int32_t PepperMediaStreamTrackHostBase::OnResourceMessageReceived(
+ const IPC::Message& msg,
+ HostMessageContext* context) {
+ IPC_BEGIN_MESSAGE_MAP(PepperMediaStreamTrackHostBase, msg)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL(
+ PpapiHostMsg_MediaStreamTrack_EnqueueFrame, OnHostMsgEnqueueFrame)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
+ PpapiHostMsg_MediaStreamTrack_Close, OnHostMsgClose)
+ IPC_END_MESSAGE_MAP()
+ return ppapi::host::ResourceHost::OnResourceMessageReceived(msg, context);
+}
+
+bool PepperMediaStreamTrackHostBase::InitFrames(int32_t number_of_frames,
+ int32_t frame_size) {
+ DCHECK_GT(number_of_frames, 0);
+ DCHECK_GT(frame_size,
+ static_cast<int32_t>(sizeof(ppapi::MediaStreamFrame::Header)));
+ // Make each frame 4 byte aligned.
+ frame_size = (frame_size + 3) & ~0x3;
+
+ int32_t size = number_of_frames * frame_size;
+ content::RenderThread* render_thread = content::RenderThread::Get();
+ scoped_ptr<base::SharedMemory> shm(
+ render_thread->HostAllocateSharedMemoryBuffer(size).Pass());
+ if (!shm)
+ return false;
+
+ base::SharedMemoryHandle shm_handle = shm->handle();
+ if (!frame_buffer_.SetFrames(number_of_frames, frame_size, shm.Pass(), true))
+ return false;
+
+ base::PlatformFile platform_file =
+#if defined(OS_WIN)
+ reinterpret_cast<HANDLE>(static_cast<intptr_t>(shm_handle));
+#elif defined(OS_POSIX)
+ shm_handle.fd;
+#else
+#error Not implemented.
+#endif
+ SerializedHandle handle(
+ host_->ShareHandleWithRemote(platform_file, false), size);
+ host()->SendUnsolicitedReplyWithHandles(pp_resource(),
+ PpapiPluginMsg_MediaStreamTrack_InitFrames(number_of_frames, frame_size),
+ std::vector<SerializedHandle>(1, handle));
+ return true;
+}
+
+void PepperMediaStreamTrackHostBase::PluginEnqueueFrame(int32_t index) {
+ DCHECK_GE(index, 0);
+ DCHECK_LT(index, frame_buffer_.number_of_frames());
+ host()->SendUnsolicitedReply(pp_resource(),
+ PpapiPluginMsg_MediaStreamTrack_EnqueueFrame(index));
+}
+
+int32_t PepperMediaStreamTrackHostBase::OnHostMsgEnqueueFrame(
+ HostMessageContext* context,
+ int32_t index) {
+ frame_buffer_.EnqueueFrame(index);
+ return PP_OK;
+}
+
+int32_t PepperMediaStreamTrackHostBase::OnHostMsgClose(
+ HostMessageContext* context) {
+ OnClose();
+ return PP_OK;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698