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

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

Issue 8528045: corresponding change in CaptureVideoDecoder and RTCVideoDecoder due to pull model used in medi... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: code review Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/rtc_video_decoder.h" 5 #include "content/renderer/media/rtc_video_decoder.h"
6 6
7 #include <deque>
8
9 #include "base/bind.h" 7 #include "base/bind.h"
10 #include "base/callback.h" 8 #include "base/callback.h"
11 #include "base/message_loop.h" 9 #include "base/message_loop.h"
12 #include "base/task.h" 10 #include "base/task.h"
13 #include "media/base/demuxer.h" 11 #include "media/base/demuxer.h"
14 #include "media/base/filter_host.h" 12 #include "media/base/filter_host.h"
15 #include "media/base/filters.h" 13 #include "media/base/filters.h"
16 #include "media/base/limits.h" 14 #include "media/base/limits.h"
17 #include "media/base/video_frame.h" 15 #include "media/base/video_frame.h"
18 #include "media/base/video_util.h" 16 #include "media/base/video_util.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return; 78 return;
81 } 79 }
82 80
83 DCHECK_EQ(MessageLoop::current(), message_loop_); 81 DCHECK_EQ(MessageLoop::current(), message_loop_);
84 82
85 state_ = kPaused; 83 state_ = kPaused;
86 84
87 VideoDecoder::Pause(callback); 85 VideoDecoder::Pause(callback);
88 } 86 }
89 87
88 void RTCVideoDecoder::Flush(const base::Closure& callback) {
89 if (MessageLoop::current() != message_loop_) {
90 message_loop_->PostTask(FROM_HERE,
91 base::Bind(&RTCVideoDecoder::Flush,
92 this, callback));
93 return;
94 }
95
96 DCHECK_EQ(MessageLoop::current(), message_loop_);
97
98 ReadCB read_cb;
99 {
100 base::AutoLock auto_lock(lock_);
101 if (!read_cb_.is_null()) {
102 std::swap(read_cb, read_cb_);
103 }
104 }
105
106 if (!read_cb.is_null()) {
107 scoped_refptr<media::VideoFrame> video_frame =
108 media::VideoFrame::CreateBlackFrame(visible_size_.width(),
109 visible_size_.height());
110 read_cb.Run(video_frame);
111 }
112
113 VideoDecoder::Flush(callback);
114 }
115
90 void RTCVideoDecoder::Stop(const base::Closure& callback) { 116 void RTCVideoDecoder::Stop(const base::Closure& callback) {
91 if (MessageLoop::current() != message_loop_) { 117 if (MessageLoop::current() != message_loop_) {
92 message_loop_->PostTask(FROM_HERE, 118 message_loop_->PostTask(FROM_HERE,
93 base::Bind(&RTCVideoDecoder::Stop, 119 base::Bind(&RTCVideoDecoder::Stop,
94 this, callback)); 120 this, callback));
95 return; 121 return;
96 } 122 }
97 123
98 DCHECK_EQ(MessageLoop::current(), message_loop_); 124 DCHECK_EQ(MessageLoop::current(), message_loop_);
99 125
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 160 }
135 161
136 bool RTCVideoDecoder::SetSize(int width, int height, int reserved) { 162 bool RTCVideoDecoder::SetSize(int width, int height, int reserved) {
137 visible_size_.SetSize(width, height); 163 visible_size_.SetSize(width, height);
138 164
139 // TODO(vrk): Provide natural size when aspect ratio support is implemented. 165 // TODO(vrk): Provide natural size when aspect ratio support is implemented.
140 host()->SetNaturalVideoSize(visible_size_); 166 host()->SetNaturalVideoSize(visible_size_);
141 return true; 167 return true;
142 } 168 }
143 169
170 // TODO(wjia): this function can be split into two parts so that the |lock_|
171 // can be removed.
172 // First creates media::VideoFrame, then post a task onto |message_loop_|
173 // to deliver that frame.
144 bool RTCVideoDecoder::RenderFrame(const cricket::VideoFrame* frame) { 174 bool RTCVideoDecoder::RenderFrame(const cricket::VideoFrame* frame) {
145 // Called from libjingle thread. 175 // Called from libjingle thread.
146 DCHECK(frame); 176 DCHECK(frame);
147 177
148 if (state_ != kNormal) 178 if (state_ != kNormal)
149 return true; 179 return true;
150 180
151 ReadCB read_cb; 181 ReadCB read_cb;
152 { 182 {
153 base::AutoLock auto_lock(lock_); 183 base::AutoLock auto_lock(lock_);
(...skipping 19 matching lines...) Expand all
173 203
174 int y_rows = frame->GetHeight(); 204 int y_rows = frame->GetHeight();
175 int uv_rows = frame->GetHeight() / 2; // YV12 format. 205 int uv_rows = frame->GetHeight() / 2; // YV12 format.
176 CopyYPlane(frame->GetYPlane(), frame->GetYPitch(), y_rows, video_frame); 206 CopyYPlane(frame->GetYPlane(), frame->GetYPitch(), y_rows, video_frame);
177 CopyUPlane(frame->GetUPlane(), frame->GetUPitch(), uv_rows, video_frame); 207 CopyUPlane(frame->GetUPlane(), frame->GetUPitch(), uv_rows, video_frame);
178 CopyVPlane(frame->GetVPlane(), frame->GetVPitch(), uv_rows, video_frame); 208 CopyVPlane(frame->GetVPlane(), frame->GetVPitch(), uv_rows, video_frame);
179 209
180 read_cb.Run(video_frame); 210 read_cb.Run(video_frame);
181 return true; 211 return true;
182 } 212 }
OLDNEW
« no previous file with comments | « content/renderer/media/rtc_video_decoder.h ('k') | content/renderer/media/rtc_video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698