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

Unified Diff: content/renderer/pepper/pepper_video_source_host.cc

Issue 14968002: Glue code to connect PPAPI proxy to MediaStream sources and destinations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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_video_source_host.cc
diff --git a/content/renderer/pepper/pepper_video_source_host.cc b/content/renderer/pepper/pepper_video_source_host.cc
index 1015ea069c1a484eae06e6787cdb29269efc8767..858870493137de96121ea387784a02ba600962ab 100644
--- a/content/renderer/pepper/pepper_video_source_host.cc
+++ b/content/renderer/pepper/pepper_video_source_host.cc
@@ -6,16 +6,18 @@
#include "base/bind.h"
#include "content/public/renderer/renderer_ppapi_host.h"
+#include "content/renderer/render_thread_impl.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/proxy/ppb_image_data_proxy.h"
#include "ppapi/shared_impl/scoped_pp_resource.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_image_data_api.h"
-#include "skia/ext/platform_canvas.h"
+#include "third_party/libjingle/source/talk/media/base/videocommon.h"
+#include "third_party/libjingle/source/talk/media/base/videoframe.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
using ppapi::host::HostMessageContext;
@@ -30,7 +32,8 @@ PepperVideoSourceHost::PepperVideoSourceHost(
: ResourceHost(host->GetPpapiHost(), instance, resource),
renderer_ppapi_host_(host),
weak_factory_(this),
- last_timestamp_(0) {
+ source_handler_(new content::VideoSourceHandler(NULL)),
+ get_frame_pending_(false) {
}
PepperVideoSourceHost::~PepperVideoSourceHost() {
@@ -50,24 +53,26 @@ int32_t PepperVideoSourceHost::OnResourceMessageReceived(
return PP_ERROR_FAILED;
}
-int32_t PepperVideoSourceHost::OnHostMsgOpen(HostMessageContext* context,
- const std::string& stream_url) {
- GURL gurl(stream_url);
- if (!gurl.is_valid())
- return PP_ERROR_BADARGUMENT;
- // TODO(ronghuawu) Check that gurl is a valid MediaStream video track URL.
- // TODO(ronghuawu) Open a MediaStream video track.
- ReplyMessageContext reply_context = context->MakeReplyMessageContext();
- reply_context.params.set_result(PP_OK);
- host()->SendReply(reply_context, PpapiPluginMsg_VideoSource_OpenReply());
- return PP_OK_COMPLETIONPENDING;
+bool PepperVideoSourceHost::GotFrame(cricket::VideoFrame* frame) {
+ // Take ownership of the new frame, and possibly delete any unsent one.
+ last_frame_.reset(frame);
Ronghua Wu (Left Chromium) 2013/05/05 15:39:35 This callback will be called from the libjingle wo
bbudge 2013/05/06 04:02:15 Done. I added a lock. It wasn't clear from comment
Ronghua Wu (Left Chromium) 2013/05/06 04:42:07 Thanks. My bad.
+
+ if (get_frame_pending_) {
+ ppapi::HostResource image_data_resource;
+ PP_TimeTicks timestamp = 0;
+ int32_t result = ConvertFrame(&image_data_resource, &timestamp);
+ SendFrame(image_data_resource, timestamp, result);
+ }
+
+ return true;
}
-int32_t PepperVideoSourceHost::OnHostMsgGetFrame(
- HostMessageContext* context) {
- ReplyMessageContext reply_context = context->MakeReplyMessageContext();
- // TODO(ronghuawu) Wait until a frame with timestamp > last_timestamp_ is
- // available.
+int32_t PepperVideoSourceHost::ConvertFrame(
+ ppapi::HostResource* image_data_resource,
+ PP_TimeTicks* timestamp) {
+ scoped_ptr<cricket::VideoFrame> frame(last_frame_.release());
+ int32_t width = static_cast<int32_t>(frame->GetWidth());
+ int32_t height = static_cast<int32_t>(frame->GetHeight());
// Create an image data resource to hold the frame pixels.
PP_ImageDataDesc desc;
IPC::PlatformFileForTransit image_handle;
@@ -76,8 +81,8 @@ int32_t PepperVideoSourceHost::OnHostMsgGetFrame(
ppapi::ScopedPPResource::PassRef(),
ppapi::proxy::PPB_ImageData_Proxy::CreateImageData(
pp_instance(),
- webkit::ppapi::PPB_ImageData_Impl::GetNativeImageDataFormat(),
- PP_MakeSize(0, 0),
+ PP_IMAGEDATAFORMAT_BGRA_PREMUL,
+ PP_MakeSize(width, height),
false /* init_to_zero */,
false /* is_nacl_plugin */,
&desc, &image_handle, &byte_count));
@@ -95,21 +100,80 @@ int32_t PepperVideoSourceHost::OnHostMsgGetFrame(
if (!mapper.is_valid())
return PP_ERROR_FAILED;
- // TODO(ronghuawu) Copy frame pixels to canvas.
+ const SkBitmap* bitmap = image_data->GetMappedBitmap();
+ if (!bitmap)
+ return PP_ERROR_FAILED;
+ uint8_t* bitmap_pixels = static_cast<uint8_t*>(bitmap->getPixels());
+ if (!bitmap_pixels)
+ return PP_ERROR_FAILED;
- ppapi::HostResource image_data_resource;
- image_data_resource.SetHostResource(pp_instance(), resource.get());
- double timestamp = 0;
- reply_context.params.set_result(PP_OK);
+ size_t bitmap_size = bitmap->getSize();
+ frame->ConvertToRgbBuffer(cricket::FOURCC_BGRA,
+ bitmap_pixels,
+ bitmap_size,
+ bitmap->rowBytes());
+
+ image_data_resource->SetHostResource(pp_instance(), resource.get());
+ *timestamp = static_cast<PP_TimeTicks>(frame->GetTimeStamp()) /
+ talk_base::kNumNanosecsPerSec;
+ return PP_OK;
+}
+
+void PepperVideoSourceHost::SendFrame(
+ const ppapi::HostResource& image_data_resource,
+ PP_TimeTicks timestamp,
+ int32_t result) {
+ reply_context_.params.set_result(result);
host()->SendReply(
- reply_context,
+ reply_context_,
PpapiPluginMsg_VideoSource_GetFrameReply(image_data_resource, timestamp));
- last_timestamp_ = timestamp;
+
+ reply_context_ = ppapi::host::ReplyMessageContext();
+ get_frame_pending_ = false;
+}
+
+int32_t PepperVideoSourceHost::OnHostMsgOpen(HostMessageContext* context,
+ const std::string& stream_url) {
+ GURL gurl(stream_url);
+ if (!gurl.is_valid())
+ return PP_ERROR_BADARGUMENT;
+
+ stream_url_ = gurl.spec();
+ if (!source_handler_->Open(stream_url_, this))
+ return PP_ERROR_BADARGUMENT;
+
+ ReplyMessageContext reply_context = context->MakeReplyMessageContext();
+ reply_context.params.set_result(PP_OK);
+ host()->SendReply(reply_context, PpapiPluginMsg_VideoSource_OpenReply());
+ return PP_OK_COMPLETIONPENDING;
+}
+
+int32_t PepperVideoSourceHost::OnHostMsgGetFrame(
+ HostMessageContext* context) {
+ if (get_frame_pending_)
+ return PP_ERROR_INPROGRESS;
+
+ reply_context_ = context->MakeReplyMessageContext();
+ get_frame_pending_ = true;
+
+ // If a frame is ready, try to convert it and reply.
+ if (last_frame_.get()) {
+ ppapi::HostResource image_data_resource;
+ PP_TimeTicks timestamp = 0;
+ int32_t result = ConvertFrame(&image_data_resource, &timestamp);
+ if (result == PP_OK) {
+ SendFrame(image_data_resource, timestamp, result);
+ } else {
+ reply_context_ = ppapi::host::ReplyMessageContext();
+ return result;
+ }
+ }
+
return PP_OK_COMPLETIONPENDING;
}
int32_t PepperVideoSourceHost::OnHostMsgClose(HostMessageContext* context) {
- // TODO(ronghuawu) Close the video stream.
+ source_handler_->Close(stream_url_, this);
return PP_OK;
}

Powered by Google App Engine
This is Rietveld 408576698