Commit 62a36de1 authored by Shik Chen's avatar Shik Chen Committed by Commit Bot

Pepper: support GpuMemoryBuffer-based frame in MediaStream Video

GpuMemoryBuffer-based video capture is enabled on selected Chrome OS
boards to reduce memory copies.  This CL allows the Pepper media stream
video track host to convert the GpuMemoryBuffer-based VideoFrames to the
I420 buffer PPAPI MediaStream Video [1] supports.

[1] https://source.chromium.org/chromium/chromium/src/+/master:ppapi/examples/media_stream_video/

Bug: 1039514
Test: Check the camera frames from the PPAPI media_stream_video example
Change-Id: I02a41ef3a458cbe2df3740b4bd6b380ea6d57ab5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2109510Reviewed-by: default avatarRicky Liang <jcliang@chromium.org>
Reviewed-by: default avatarBill Budge <bbudge@chromium.org>
Commit-Queue: Shik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751878}
parent 9f930d1e
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "ppapi/host/host_message_context.h" #include "ppapi/host/host_message_context.h"
#include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/shared_impl/media_stream_buffer.h" #include "ppapi/shared_impl/media_stream_buffer.h"
#include "ui/gfx/gpu_memory_buffer.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_source.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_video_source.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_track.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_video_track.h"
#include "third_party/libyuv/include/libyuv.h" #include "third_party/libyuv/include/libyuv.h"
...@@ -355,6 +356,36 @@ void PepperMediaStreamVideoTrackHost::OnVideoFrame( ...@@ -355,6 +356,36 @@ void PepperMediaStreamVideoTrackHost::OnVideoFrame(
if (frame->format() == media::PIXEL_FORMAT_I420A) if (frame->format() == media::PIXEL_FORMAT_I420A)
frame = media::WrapAsI420VideoFrame(std::move(video_frame)); frame = media::WrapAsI420VideoFrame(std::move(video_frame));
PP_VideoFrame_Format ppformat = ToPpapiFormat(frame->format()); PP_VideoFrame_Format ppformat = ToPpapiFormat(frame->format());
if (frame->storage_type() == media::VideoFrame::STORAGE_GPU_MEMORY_BUFFER) {
// NV12 is the only supported GMB pixel format at the moment, and there is
// no corresponding PP_VideoFrame_Format. Convert the video frame to I420.
DCHECK_EQ(frame->format(), media::PIXEL_FORMAT_NV12);
ppformat = PP_VIDEOFRAME_FORMAT_I420;
auto* gmb = video_frame->GetGpuMemoryBuffer();
if (!gmb->Map()) {
DLOG(WARNING) << "Failed to map GpuMemoryBuffer";
return;
}
frame = media::VideoFrame::CreateFrame(
media::PIXEL_FORMAT_I420, video_frame->coded_size(),
video_frame->visible_rect(), video_frame->natural_size(),
video_frame->timestamp());
int ret = libyuv::NV12ToI420(
static_cast<const uint8_t*>(gmb->memory(0)), gmb->stride(0),
static_cast<const uint8_t*>(gmb->memory(1)), gmb->stride(1),
frame->data(media::VideoFrame::kYPlane),
frame->stride(media::VideoFrame::kYPlane),
frame->data(media::VideoFrame::kUPlane),
frame->stride(media::VideoFrame::kUPlane),
frame->data(media::VideoFrame::kVPlane),
frame->stride(media::VideoFrame::kVPlane),
video_frame->coded_size().width(), video_frame->coded_size().height());
gmb->Unmap();
if (ret != 0) {
DLOG(WARNING) << "Failed to convert NV12 to I420";
return;
}
}
if (ppformat == PP_VIDEOFRAME_FORMAT_UNKNOWN) if (ppformat == PP_VIDEOFRAME_FORMAT_UNKNOWN)
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment