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

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

Issue 10824141: Remove VideoDecoder::natural_size() & added VideoFrame::natural_size(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix copyright year. Created 8 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/capture_video_decoder.h" 5 #include "content/renderer/media/capture_video_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "content/renderer/media/video_capture_impl_manager.h" 9 #include "content/renderer/media/video_capture_impl_manager.h"
10 #include "media/base/demuxer_stream.h" 10 #include "media/base/demuxer_stream.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 FROM_HERE, 54 FROM_HERE,
55 base::Bind(&CaptureVideoDecoder::ResetOnDecoderThread, this, closure)); 55 base::Bind(&CaptureVideoDecoder::ResetOnDecoderThread, this, closure));
56 } 56 }
57 57
58 void CaptureVideoDecoder::Stop(const base::Closure& closure) { 58 void CaptureVideoDecoder::Stop(const base::Closure& closure) {
59 message_loop_proxy_->PostTask( 59 message_loop_proxy_->PostTask(
60 FROM_HERE, 60 FROM_HERE,
61 base::Bind(&CaptureVideoDecoder::StopOnDecoderThread, this, closure)); 61 base::Bind(&CaptureVideoDecoder::StopOnDecoderThread, this, closure));
62 } 62 }
63 63
64 const gfx::Size& CaptureVideoDecoder::natural_size() {
65 return natural_size_;
66 }
67
68 void CaptureVideoDecoder::PrepareForShutdownHack() { 64 void CaptureVideoDecoder::PrepareForShutdownHack() {
69 message_loop_proxy_->PostTask( 65 message_loop_proxy_->PostTask(
70 FROM_HERE, 66 FROM_HERE,
71 base::Bind(&CaptureVideoDecoder::PrepareForShutdownHackOnDecoderThread, 67 base::Bind(&CaptureVideoDecoder::PrepareForShutdownHackOnDecoderThread,
72 this)); 68 this));
73 } 69 }
74 70
75 void CaptureVideoDecoder::OnStarted(media::VideoCapture* capture) { 71 void CaptureVideoDecoder::OnStarted(media::VideoCapture* capture) {
76 NOTIMPLEMENTED(); 72 NOTIMPLEMENTED();
77 } 73 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 128
133 capture_engine_ = vc_manager_->AddDevice(video_stream_id_, this); 129 capture_engine_ = vc_manager_->AddDevice(video_stream_id_, this);
134 130
135 statistics_cb_ = statistics_cb; 131 statistics_cb_ = statistics_cb;
136 status_cb.Run(media::PIPELINE_OK); 132 status_cb.Run(media::PIPELINE_OK);
137 state_ = kNormal; 133 state_ = kNormal;
138 capture_engine_->StartCapture(this, capability_); 134 capture_engine_->StartCapture(this, capability_);
139 } 135 }
140 136
141 void CaptureVideoDecoder::ReadOnDecoderThread(const ReadCB& read_cb) { 137 void CaptureVideoDecoder::ReadOnDecoderThread(const ReadCB& read_cb) {
138 DCHECK_NE(state_, kUnInitialized);
142 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); 139 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
143 CHECK(read_cb_.is_null()); 140 CHECK(read_cb_.is_null());
144 read_cb_ = read_cb; 141 read_cb_ = read_cb;
145 if (state_ == kPaused || shutting_down_) { 142 if (state_ == kPaused || shutting_down_) {
146 DeliverFrame(media::VideoFrame::CreateEmptyFrame()); 143 DeliverFrame(media::VideoFrame::CreateEmptyFrame());
147 } 144 }
148 } 145 }
149 146
150 void CaptureVideoDecoder::ResetOnDecoderThread(const base::Closure& closure) { 147 void CaptureVideoDecoder::ResetOnDecoderThread(const base::Closure& closure) {
151 DVLOG(1) << "ResetOnDecoderThread"; 148 DVLOG(1) << "ResetOnDecoderThread";
152 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); 149 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
153 if (!read_cb_.is_null()) { 150 if (!read_cb_.is_null()) {
154 scoped_refptr<media::VideoFrame> video_frame = 151 scoped_refptr<media::VideoFrame> video_frame =
155 media::VideoFrame::CreateBlackFrame(natural_size_.width(), 152 media::VideoFrame::CreateBlackFrame(natural_size_);
156 natural_size_.height());
157 DeliverFrame(video_frame); 153 DeliverFrame(video_frame);
158 } 154 }
159 closure.Run(); 155 closure.Run();
160 } 156 }
161 157
162 void CaptureVideoDecoder::StopOnDecoderThread(const base::Closure& closure) { 158 void CaptureVideoDecoder::StopOnDecoderThread(const base::Closure& closure) {
163 DVLOG(1) << "StopOnDecoderThread"; 159 DVLOG(1) << "StopOnDecoderThread";
164 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); 160 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
165 pending_stop_cb_ = closure; 161 pending_stop_cb_ = closure;
166 state_ = kStopped; 162 state_ = kStopped;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 if (!got_first_frame_) { 229 if (!got_first_frame_) {
234 start_time_ = buf->timestamp; 230 start_time_ = buf->timestamp;
235 got_first_frame_ = true; 231 got_first_frame_ = true;
236 } 232 }
237 233
238 // Always allocate a new frame. 234 // Always allocate a new frame.
239 // 235 //
240 // TODO(scherkus): migrate this to proper buffer recycling. 236 // TODO(scherkus): migrate this to proper buffer recycling.
241 scoped_refptr<media::VideoFrame> video_frame = 237 scoped_refptr<media::VideoFrame> video_frame =
242 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, 238 media::VideoFrame::CreateFrame(media::VideoFrame::YV12,
243 natural_size_.width(), 239 natural_size_, natural_size_,
244 natural_size_.height(),
245 buf->timestamp - start_time_); 240 buf->timestamp - start_time_);
246 241
247 last_frame_timestamp_ = buf->timestamp; 242 last_frame_timestamp_ = buf->timestamp;
248 uint8* buffer = buf->memory_pointer; 243 uint8* buffer = buf->memory_pointer;
249 244
250 // Assume YV12 format. Note that camera gives YUV and media pipeline video 245 // Assume YV12 format. Note that camera gives YUV and media pipeline video
251 // renderer asks for YVU. The following code did the conversion. 246 // renderer asks for YVU. The following code did the conversion.
252 DCHECK_EQ(capability_.color, media::VideoCaptureCapability::kI420); 247 DCHECK_EQ(capability_.color, media::VideoCaptureCapability::kI420);
253 int y_width = buf->width; 248 int y_width = buf->width;
254 int y_height = buf->height; 249 int y_height = buf->height;
255 int uv_width = buf->width / 2; 250 int uv_width = buf->width / 2;
256 int uv_height = buf->height / 2; // YV12 format. 251 int uv_height = buf->height / 2; // YV12 format.
257 CopyYPlane(buffer, y_width, y_height, video_frame); 252 CopyYPlane(buffer, y_width, y_height, video_frame);
258 buffer += y_width * y_height; 253 buffer += y_width * y_height;
259 CopyUPlane(buffer, uv_width, uv_height, video_frame); 254 CopyUPlane(buffer, uv_width, uv_height, video_frame);
260 buffer += uv_width * uv_height; 255 buffer += uv_width * uv_height;
261 CopyVPlane(buffer, uv_width, uv_height, video_frame); 256 CopyVPlane(buffer, uv_width, uv_height, video_frame);
262 257
263 DeliverFrame(video_frame); 258 DeliverFrame(video_frame);
264 capture->FeedBuffer(buf); 259 capture->FeedBuffer(buf);
265 } 260 }
266 261
267 void CaptureVideoDecoder::DeliverFrame( 262 void CaptureVideoDecoder::DeliverFrame(
268 const scoped_refptr<media::VideoFrame>& video_frame) { 263 const scoped_refptr<media::VideoFrame>& video_frame) {
269 // Reset the callback before running to protect against reentrancy. 264 // Reset the callback before running to protect against reentrancy.
270 base::ResetAndReturn(&read_cb_).Run(kOk, video_frame); 265 base::ResetAndReturn(&read_cb_).Run(kOk, video_frame);
271 } 266 }
OLDNEW
« no previous file with comments | « content/renderer/media/capture_video_decoder.h ('k') | content/renderer/media/capture_video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698