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

Side by Side Diff: content/renderer/media/rtc_video_render.cc

Issue 10918052: create a separate WebMediaPlayer for URL derived from media stream (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix win build Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/renderer/media/rtc_video_render.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/logging.h"
10 #include "base/message_loop_proxy.h"
11 #include "media/base/video_frame.h"
12 #include "media/base/video_util.h"
13 #include "third_party/libjingle/source/talk/base/timeutils.h"
14 #include "third_party/libjingle/source/talk/media/base/videoframe.h"
15
16 using media::CopyYPlane;
17 using media::CopyUPlane;
18 using media::CopyVPlane;
19
20 RTCVideoRender::RTCVideoRender(
21 webrtc::VideoTrackInterface* video_track,
22 const base::Closure& error_cb,
23 const webkit_media::RepaintCB& repaint_cb)
24 : error_cb_(error_cb),
25 repaint_cb_(repaint_cb),
26 message_loop_proxy_(base::MessageLoopProxy::current()),
27 state_(kStopped),
28 video_track_(video_track) {
29 }
30
31 RTCVideoRender::~RTCVideoRender() {
32 }
33
34 void RTCVideoRender::Start() {
35 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
36 DCHECK_EQ(state_, kStopped);
37
38 if (video_track_)
39 video_track_->AddRenderer(this);
40 state_ = kStarted;
41 }
42
43 void RTCVideoRender::Stop() {
44 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
45 if (video_track_) {
46 state_ = kStopped;
47 video_track_->RemoveRenderer(this);
48 video_track_ = NULL;
49 }
50 }
51
52 void RTCVideoRender::Play() {
53 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
54 if (video_track_ && state_ == kPaused) {
55 state_ = kStarted;
56 }
57 }
58
59 void RTCVideoRender::Pause() {
60 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
61 if (video_track_ && state_ == kStarted) {
62 state_ = kPaused;
63 }
64 }
65
66 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
67 }
68
69 void RTCVideoRender::RenderFrame(const cricket::VideoFrame* frame) {
70 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.
71
72 base::TimeDelta timestamp = base::TimeDelta::FromMilliseconds(
73 frame->GetTimeStamp() / talk_base::kNumNanosecsPerMillisec);
74 gfx::Size size(frame->GetWidth(), frame->GetHeight());
75 scoped_refptr<media::VideoFrame> video_frame =
76 media::VideoFrame::CreateFrame(media::VideoFrame::YV12,
77 size,
78 size,
79 timestamp);
80
81 // Aspect ratio unsupported; DCHECK when there are non-square pixels.
82 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
83 DCHECK_EQ(frame->GetPixelHeight(), 1u);
84
85 int y_rows = frame->GetHeight();
86 int uv_rows = frame->GetHeight() / 2; // YV12 format.
87 CopyYPlane(frame->GetYPlane(), frame->GetYPitch(), y_rows, video_frame);
88 CopyUPlane(frame->GetUPlane(), frame->GetUPitch(), uv_rows, video_frame);
89 CopyVPlane(frame->GetVPlane(), frame->GetVPitch(), uv_rows, video_frame);
90
91 message_loop_proxy_->PostTask(
92 FROM_HERE, base::Bind(&RTCVideoRender::DoRenderFrameOnMainThread,
93 this, video_frame));
94 }
95
96 void RTCVideoRender::DoRenderFrameOnMainThread(
97 scoped_refptr<media::VideoFrame> video_frame) {
98 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
99
100 if (state_ != kStarted) {
101 return;
102 }
103
104 repaint_cb_.Run(video_frame);
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698