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

Unified Diff: content/renderer/media/rtc_video_encoder.cc

Issue 1128213005: Passing Native Texture backed Video Frame from Renderer to GPU process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: posciak@ and magjed@ comments. Created 5 years, 7 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/media/rtc_video_encoder.cc
diff --git a/content/renderer/media/rtc_video_encoder.cc b/content/renderer/media/rtc_video_encoder.cc
index cdadae55cd560cc65a60864302399a9afb21df07..fcc1063ee722deb8712d4f416d2064a73071916c 100644
--- a/content/renderer/media/rtc_video_encoder.cc
+++ b/content/renderer/media/rtc_video_encoder.cc
@@ -13,6 +13,7 @@
#include "base/single_thread_task_runner.h"
#include "base/synchronization/waitable_event.h"
#include "base/thread_task_runner_handle.h"
+#include "media/base/bind_to_current_loop.h"
#include "media/base/bitstream_buffer.h"
#include "media/base/video_frame.h"
#include "media/base/video_util.h"
@@ -491,49 +492,53 @@ void RTCVideoEncoder::Impl::EncodeOneFrame() {
}
const int index = input_buffers_free_.back();
- base::SharedMemory* input_buffer = input_buffers_[index];
- scoped_refptr<media::VideoFrame> frame =
- media::VideoFrame::WrapExternalSharedMemory(
- media::VideoFrame::I420,
- input_frame_coded_size_,
- gfx::Rect(input_visible_size_),
- input_visible_size_,
- reinterpret_cast<uint8*>(input_buffer->memory()),
- input_buffer->mapped_size(),
- input_buffer->handle(),
- 0,
- base::TimeDelta());
- frame->AddDestructionObserver(
- base::Bind(&RTCVideoEncoder::Impl::EncodeFrameFinished, this, index));
- if (!frame.get()) {
- DLOG(ERROR) << "Impl::EncodeOneFrame(): failed to create frame";
- NOTIFY_ERROR(media::VideoEncodeAccelerator::kPlatformFailureError);
- return;
- }
- // Do a strided copy of the input frame to match the input requirements for
- // the encoder.
- // TODO(sheu): support zero-copy from WebRTC. http://crbug.com/269312
- if (libyuv::I420Copy(next_frame->buffer(webrtc::kYPlane),
- next_frame->stride(webrtc::kYPlane),
- next_frame->buffer(webrtc::kUPlane),
- next_frame->stride(webrtc::kUPlane),
- next_frame->buffer(webrtc::kVPlane),
- next_frame->stride(webrtc::kVPlane),
- 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),
- next_frame->width(),
- next_frame->height())) {
- DLOG(ERROR) << "Failed to copy buffer";
- NOTIFY_ERROR(media::VideoEncodeAccelerator::kPlatformFailureError);
- return;
+ if (next_frame->native_handle()) {
+ scoped_refptr<media::VideoFrame> frame(
+ static_cast<media::VideoFrame*>(next_frame->native_handle()));
+ frame->AddDestructionObserver(media::BindToCurrentLoop(
+ base::Bind(&RTCVideoEncoder::Impl::EncodeFrameFinished, this, index)));
+ video_encoder_->Encode(frame, next_frame_keyframe);
+ } else {
+ base::SharedMemory* input_buffer = input_buffers_[index];
+ scoped_refptr<media::VideoFrame> frame =
+ media::VideoFrame::WrapExternalSharedMemory(
+ media::VideoFrame::I420, input_frame_coded_size_,
+ gfx::Rect(input_visible_size_), input_visible_size_,
+ reinterpret_cast<uint8*>(input_buffer->memory()),
+ input_buffer->mapped_size(), input_buffer->handle(), 0,
+ base::TimeDelta());
+ frame->AddDestructionObserver(
mcasas 2015/06/04 15:20:56 Could we move the frame->AddDestructionObserver()
+ base::Bind(&RTCVideoEncoder::Impl::EncodeFrameFinished, this, index));
+ if (!frame.get()) {
+ DLOG(ERROR) << "Impl::EncodeOneFrame(): failed to create frame";
+ NOTIFY_ERROR(media::VideoEncodeAccelerator::kPlatformFailureError);
+ return;
+ }
+
+ // Do a strided copy of the input frame to match the input requirements for
+ // the encoder.
+ // TODO(sheu): support zero-copy from WebRTC. http://crbug.com/269312
+ if (libyuv::I420Copy(next_frame->buffer(webrtc::kYPlane),
+ next_frame->stride(webrtc::kYPlane),
+ next_frame->buffer(webrtc::kUPlane),
+ next_frame->stride(webrtc::kUPlane),
+ next_frame->buffer(webrtc::kVPlane),
+ next_frame->stride(webrtc::kVPlane),
+ 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),
+ next_frame->width(), next_frame->height())) {
+ DLOG(ERROR) << "Failed to copy buffer";
+ NOTIFY_ERROR(media::VideoEncodeAccelerator::kPlatformFailureError);
+ return;
+ }
+ video_encoder_->Encode(frame, next_frame_keyframe);
}
- video_encoder_->Encode(frame, next_frame_keyframe);
input_buffers_free_.pop_back();
SignalAsyncWaiter(WEBRTC_VIDEO_CODEC_OK);
}

Powered by Google App Engine
This is Rietveld 408576698