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

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

Issue 1212133002: Passing Texture backed VideoFrame through WebRTC wrappers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mcasas@ comments. Created 5 years, 6 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..995766aaef4e25b2ec6adf8fa439c8605429b9bf 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"
@@ -422,8 +423,9 @@ void RTCVideoEncoder::Impl::BitstreamBufferReady(int32 bitstream_buffer_id,
const int64 capture_time_us = webrtc::TickTime::MicrosecondTimestamp();
// Derive the capture time (in ms) and RTP timestamp (in 90KHz ticks).
- int64 capture_time_ms = capture_time_us / 1000;
- uint32_t rtp_timestamp = static_cast<uint32_t>(capture_time_us * 90 / 1000);
+ const int64 capture_time_ms = capture_time_us / 1000;
+ const uint32_t rtp_timestamp =
+ static_cast<uint32_t>(capture_time_us * 90 / 1000);
scoped_ptr<webrtc::EncodedImage> image(new webrtc::EncodedImage(
reinterpret_cast<uint8_t*>(output_buffer->memory()),
@@ -481,7 +483,7 @@ void RTCVideoEncoder::Impl::EncodeOneFrame() {
// Encode() gets destroyed early. Handle this by resetting our
// input_next_frame_* state before we hand off the VideoFrame to the VEA.
const webrtc::VideoFrame* next_frame = input_next_frame_;
- bool next_frame_keyframe = input_next_frame_keyframe_;
+ const bool next_frame_keyframe = input_next_frame_keyframe_;
input_next_frame_ = NULL;
input_next_frame_keyframe_ = false;
@@ -491,48 +493,49 @@ 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;
+ scoped_refptr<media::VideoFrame> frame;
+ if (next_frame->native_handle()) {
+ frame = static_cast<media::VideoFrame*>(next_frame->native_handle());
+ } else {
+ base::SharedMemory* input_buffer = input_buffers_[index];
+ 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());
+ 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;
+ }
}
-
+ frame->AddDestructionObserver(media::BindToCurrentLoop(
+ base::Bind(&RTCVideoEncoder::Impl::EncodeFrameFinished, this, index)));
video_encoder_->Encode(frame, next_frame_keyframe);
input_buffers_free_.pop_back();
SignalAsyncWaiter(WEBRTC_VIDEO_CODEC_OK);
@@ -601,8 +604,8 @@ int32_t RTCVideoEncoder::InitEncode(const webrtc::VideoCodec* codec_settings,
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!impl_.get());
- media::VideoCodecProfile profile = WebRTCVideoCodecToVideoCodecProfile(
- video_codec_type_, codec_settings);
+ const media::VideoCodecProfile profile =
+ WebRTCVideoCodecToVideoCodecProfile(video_codec_type_, codec_settings);
weak_factory_.InvalidateWeakPtrs();
impl_ = new Impl(weak_factory_.GetWeakPtr(), gpu_factories_);
@@ -634,7 +637,7 @@ int32_t RTCVideoEncoder::Encode(
return impl_status_;
}
- bool want_key_frame = frame_types && frame_types->size() &&
+ const bool want_key_frame = frame_types && frame_types->size() &&
frame_types->front() == webrtc::kKeyFrame;
base::WaitableEvent encode_waiter(true, false);
int32_t encode_retval = WEBRTC_VIDEO_CODEC_UNINITIALIZED;

Powered by Google App Engine
This is Rietveld 408576698