Index: content/renderer/media/rtc_video_render.cc |
=================================================================== |
--- content/renderer/media/rtc_video_render.cc (revision 0) |
+++ content/renderer/media/rtc_video_render.cc (revision 0) |
@@ -0,0 +1,105 @@ |
+// Copyright (c) 2012 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/rtc_video_render.h" |
+ |
+#include "base/bind.h" |
+#include "base/location.h" |
+#include "base/logging.h" |
+#include "base/message_loop_proxy.h" |
+#include "media/base/video_frame.h" |
+#include "media/base/video_util.h" |
+#include "third_party/libjingle/source/talk/base/timeutils.h" |
+#include "third_party/libjingle/source/talk/media/base/videoframe.h" |
+ |
+using media::CopyYPlane; |
+using media::CopyUPlane; |
+using media::CopyVPlane; |
+ |
+RTCVideoRender::RTCVideoRender( |
+ webrtc::VideoTrackInterface* video_track, |
+ const base::Closure& error_cb, |
+ const webkit_media::RepaintCB& repaint_cb) |
+ : error_cb_(error_cb), |
+ repaint_cb_(repaint_cb), |
+ message_loop_proxy_(base::MessageLoopProxy::current()), |
+ state_(kStopped), |
+ video_track_(video_track) { |
+} |
+ |
+RTCVideoRender::~RTCVideoRender() { |
+} |
+ |
+void RTCVideoRender::Start() { |
+ DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
+ DCHECK_EQ(state_, kStopped); |
+ |
+ if (video_track_) |
+ video_track_->AddRenderer(this); |
+ state_ = kStarted; |
+} |
+ |
+void RTCVideoRender::Stop() { |
+ DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
+ if (video_track_) { |
+ state_ = kStopped; |
+ video_track_->RemoveRenderer(this); |
+ video_track_ = NULL; |
+ } |
+} |
+ |
+void RTCVideoRender::Play() { |
+ DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
+ if (video_track_ && state_ == kPaused) { |
+ state_ = kStarted; |
+ } |
+} |
+ |
+void RTCVideoRender::Pause() { |
+ DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
+ if (video_track_ && state_ == kStarted) { |
+ state_ = kPaused; |
+ } |
+} |
+ |
+void RTCVideoRender::SetSize(int width, int height) { |
scherkus (not reviewing)
2012/09/07 11:44:03
we don't need to implement this?
can it be remove
wjia(left Chromium)
2012/09/13 01:22:07
Right, since the frame in RenderFrame() has the si
|
+} |
+ |
+void RTCVideoRender::RenderFrame(const cricket::VideoFrame* frame) { |
+ DCHECK(frame); |
scherkus (not reviewing)
2012/09/07 11:44:03
dcheck not needed (you'll crash on subsequent line
wjia(left Chromium)
2012/09/13 01:22:07
Done.
|
+ |
+ base::TimeDelta timestamp = base::TimeDelta::FromMilliseconds( |
+ frame->GetTimeStamp() / talk_base::kNumNanosecsPerMillisec); |
+ gfx::Size size(frame->GetWidth(), frame->GetHeight()); |
+ scoped_refptr<media::VideoFrame> video_frame = |
+ media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
+ size, |
+ size, |
+ timestamp); |
+ |
+ // Aspect ratio unsupported; DCHECK when there are non-square pixels. |
+ DCHECK_EQ(frame->GetPixelWidth(), 1u); |
scherkus (not reviewing)
2012/09/07 11:44:03
what happens in release mode?
wjia(left Chromium)
2012/09/13 01:22:07
It should be ok. According to http://code.google.c
|
+ 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); |
+ CopyUPlane(frame->GetUPlane(), frame->GetUPitch(), uv_rows, video_frame); |
+ CopyVPlane(frame->GetVPlane(), frame->GetVPitch(), uv_rows, video_frame); |
+ |
+ message_loop_proxy_->PostTask( |
+ FROM_HERE, base::Bind(&RTCVideoRender::DoRenderFrameOnMainThread, |
+ this, video_frame)); |
+} |
+ |
+void RTCVideoRender::DoRenderFrameOnMainThread( |
+ scoped_refptr<media::VideoFrame> video_frame) { |
+ DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
+ |
+ if (state_ != kStarted) { |
+ return; |
+ } |
+ |
+ repaint_cb_.Run(video_frame); |
+} |
Property changes on: content/renderer/media/rtc_video_render.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |