diff options
author | wuchengli@chromium.org <wuchengli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-26 12:39:56 +0000 |
---|---|---|
committer | wuchengli@chromium.org <wuchengli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-26 12:39:56 +0000 |
commit | a161042359cdb989141dd41dad7be7753a673b25 (patch) | |
tree | bf74e494215dcc8c325e22b59a003e64feea4839 /content | |
parent | 776d31353d1349c23005e8b8924bbf86441cd68d (diff) | |
download | chromium_src-a161042359cdb989141dd41dad7be7753a673b25.zip chromium_src-a161042359cdb989141dd41dad7be7753a673b25.tar.gz chromium_src-a161042359cdb989141dd41dad7be7753a673b25.tar.bz2 |
Send video frames backed by textures to WebRTC.
The dependent CLs:
webrtc: https://webrtc-codereview.appspot.com/1966004/
libjingle: http://cl/49270949-p10
BUG=170345
TEST=Try http://apprtc.appspot.com/?debug=loopback on Chromebook Daisy. Play hardware-accelerated video.
Review URL: https://chromiumcodereview.appspot.com/19041006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219526 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/content_renderer.gypi | 6 | ||||
-rw-r--r-- | content/renderer/media/native_handle_impl.cc | 16 | ||||
-rw-r--r-- | content/renderer/media/native_handle_impl.h | 32 | ||||
-rw-r--r-- | content/renderer/media/rtc_video_decoder.cc | 11 | ||||
-rw-r--r-- | content/renderer/media/rtc_video_renderer.cc | 44 |
5 files changed, 82 insertions, 27 deletions
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index 53f1219..9b38fb5 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -221,8 +221,6 @@ 'renderer/media/renderer_webaudiodevice_impl.h', 'renderer/media/renderer_webmidiaccessor_impl.cc', 'renderer/media/renderer_webmidiaccessor_impl.h', - 'renderer/media/rtc_video_renderer.cc', - 'renderer/media/rtc_video_renderer.h', 'renderer/media/texttrack_impl.cc', 'renderer/media/texttrack_impl.h', 'renderer/media/video_capture_impl.cc', @@ -587,6 +585,8 @@ 'renderer/media/media_stream_registry_interface.h', 'renderer/media/media_stream_source_observer.cc', 'renderer/media/media_stream_source_observer.h', + 'renderer/media/native_handle_impl.cc', + 'renderer/media/native_handle_impl.h', 'renderer/media/peer_connection_handler_base.cc', 'renderer/media/peer_connection_handler_base.h', 'renderer/media/peer_connection_identity_service.cc', @@ -615,6 +615,8 @@ 'renderer/media/rtc_video_encoder.h', 'renderer/media/rtc_video_encoder_factory.cc', 'renderer/media/rtc_video_encoder_factory.h', + 'renderer/media/rtc_video_renderer.cc', + 'renderer/media/rtc_video_renderer.h', 'renderer/media/video_destination_handler.cc', 'renderer/media/video_destination_handler.h', 'renderer/media/video_source_handler.cc', diff --git a/content/renderer/media/native_handle_impl.cc b/content/renderer/media/native_handle_impl.cc new file mode 100644 index 0000000..3988e39 --- /dev/null +++ b/content/renderer/media/native_handle_impl.cc @@ -0,0 +1,16 @@ +// Copyright 2013 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/media/native_handle_impl.h" + +namespace content { + +NativeHandleImpl::NativeHandleImpl(scoped_refptr<media::VideoFrame> frame) + : frame_(frame) {} + +NativeHandleImpl::~NativeHandleImpl() {} + +void* NativeHandleImpl::GetHandle() { return frame_.get(); } + +} // namespace content diff --git a/content/renderer/media/native_handle_impl.h b/content/renderer/media/native_handle_impl.h new file mode 100644 index 0000000..36c5dab --- /dev/null +++ b/content/renderer/media/native_handle_impl.h @@ -0,0 +1,32 @@ +// Copyright 2013 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. + +#ifndef CONTENT_RENDERER_MEDIA_NATIVE_HANDLE_IMPL_H_ +#define CONTENT_RENDERER_MEDIA_NATIVE_HANDLE_IMPL_H_ + +#include "base/memory/ref_counted.h" +#include "media/base/video_frame.h" +#include "third_party/webrtc/common_video/interface/native_handle.h" + +namespace content { + +class NativeHandleImpl : public webrtc::NativeHandle { + public: + // Wraps a video frame in the handle. + explicit NativeHandleImpl(scoped_refptr<media::VideoFrame> frame); + virtual ~NativeHandleImpl(); + + // Retrieves the video frame in the handle. The frame is still ref-counted by + // the handle. The ref count decreases when NativeHandleImpl is destroyed. + virtual void* GetHandle() OVERRIDE; + + private: + scoped_refptr<media::VideoFrame> frame_; + + DISALLOW_COPY_AND_ASSIGN(NativeHandleImpl); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_MEDIA_NATIVE_HANDLE_IMPL_H_ diff --git a/content/renderer/media/rtc_video_decoder.cc b/content/renderer/media/rtc_video_decoder.cc index c048b6b..adce1f6 100644 --- a/content/renderer/media/rtc_video_decoder.cc +++ b/content/renderer/media/rtc_video_decoder.cc @@ -12,8 +12,10 @@ #include "base/stl_util.h" #include "base/task_runner_util.h" #include "content/child/child_thread.h" +#include "content/renderer/media/native_handle_impl.h" #include "media/base/bind_to_loop.h" #include "media/filters/gpu_video_accelerator_factories.h" +#include "third_party/webrtc/common_video/interface/texture_video_frame.h" #include "third_party/webrtc/system_wrappers/interface/ref_count.h" namespace content { @@ -362,12 +364,9 @@ void RTCVideoDecoder::PictureReady(const media::Picture& picture) { DCHECK(inserted); // Create a WebRTC video frame. - // TODO(wuchengli): make media::VideoFrame an opaque native handle and put it - // into WebRTC frame. - webrtc::I420VideoFrame decoded_image; - decoded_image.CreateEmptyFrame( - width, height, width, (width + 1) / 2, (width + 1) / 2); - decoded_image.set_timestamp(timestamp); + webrtc::RefCountImpl<NativeHandleImpl>* handle = + new webrtc::RefCountImpl<NativeHandleImpl>(frame); + webrtc::TextureVideoFrame decoded_image(handle, width, height, timestamp, 0); // Invoke decode callback. WebRTC expects no callback after Reset or Release. { diff --git a/content/renderer/media/rtc_video_renderer.cc b/content/renderer/media/rtc_video_renderer.cc index 725a778..f64ed02 100644 --- a/content/renderer/media/rtc_video_renderer.cc +++ b/content/renderer/media/rtc_video_renderer.cc @@ -9,6 +9,7 @@ #include "base/location.h" #include "base/logging.h" #include "base/message_loop/message_loop_proxy.h" +#include "content/renderer/media/native_handle_impl.h" #include "media/base/video_frame.h" #include "media/base/video_util.h" #include "third_party/libjingle/source/talk/media/base/videoframe.h" @@ -84,25 +85,30 @@ void RTCVideoRenderer::RenderFrame(const cricket::VideoFrame* frame) { "timestamp_ms", timestamp.InMilliseconds()); - gfx::Size size(frame->GetWidth(), frame->GetHeight()); - scoped_refptr<media::VideoFrame> video_frame = - media::VideoFrame::CreateFrame(media::VideoFrame::YV12, - size, - gfx::Rect(size), - size, - timestamp); - - // Aspect ratio unsupported; DCHECK when there are non-square pixels. - DCHECK_EQ(frame->GetPixelWidth(), 1u); - DCHECK_EQ(frame->GetPixelHeight(), 1u); - - int y_rows = frame->GetHeight(); - int uv_rows = frame->GetHeight() / 2; // YV12 format. - CopyYPlane(frame->GetYPlane(), frame->GetYPitch(), y_rows, video_frame.get()); - CopyUPlane( - frame->GetUPlane(), frame->GetUPitch(), uv_rows, video_frame.get()); - CopyVPlane( - frame->GetVPlane(), frame->GetVPitch(), uv_rows, video_frame.get()); + scoped_refptr<media::VideoFrame> video_frame; + if (frame->GetNativeHandle() != NULL) { + NativeHandleImpl* handle = + static_cast<NativeHandleImpl*>(frame->GetNativeHandle()); + video_frame = static_cast<media::VideoFrame*>(handle->GetHandle()); + video_frame->SetTimestamp(timestamp); + } else { + gfx::Size size(frame->GetWidth(), frame->GetHeight()); + video_frame = media::VideoFrame::CreateFrame( + media::VideoFrame::YV12, size, gfx::Rect(size), size, timestamp); + + // Aspect ratio unsupported; DCHECK when there are non-square pixels. + DCHECK_EQ(frame->GetPixelWidth(), 1u); + DCHECK_EQ(frame->GetPixelHeight(), 1u); + + int y_rows = frame->GetHeight(); + int uv_rows = frame->GetHeight() / 2; // YV12 format. + CopyYPlane( + frame->GetYPlane(), frame->GetYPitch(), y_rows, video_frame.get()); + CopyUPlane( + frame->GetUPlane(), frame->GetUPitch(), uv_rows, video_frame.get()); + CopyVPlane( + frame->GetVPlane(), frame->GetVPitch(), uv_rows, video_frame.get()); + } message_loop_proxy_->PostTask( FROM_HERE, base::Bind(&RTCVideoRenderer::DoRenderFrameOnMainThread, |