| OLD | NEW |
| 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 Loading... |
| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_.width(), |
| 244 natural_size_.height(), | 240 natural_size_.height(), |
| 241 natural_size_, |
| 245 buf->timestamp - start_time_); | 242 buf->timestamp - start_time_); |
| 246 | 243 |
| 247 last_frame_timestamp_ = buf->timestamp; | 244 last_frame_timestamp_ = buf->timestamp; |
| 248 uint8* buffer = buf->memory_pointer; | 245 uint8* buffer = buf->memory_pointer; |
| 249 | 246 |
| 250 // Assume YV12 format. Note that camera gives YUV and media pipeline video | 247 // Assume YV12 format. Note that camera gives YUV and media pipeline video |
| 251 // renderer asks for YVU. The following code did the conversion. | 248 // renderer asks for YVU. The following code did the conversion. |
| 252 DCHECK_EQ(capability_.color, media::VideoCaptureCapability::kI420); | 249 DCHECK_EQ(capability_.color, media::VideoCaptureCapability::kI420); |
| 253 int y_width = buf->width; | 250 int y_width = buf->width; |
| 254 int y_height = buf->height; | 251 int y_height = buf->height; |
| 255 int uv_width = buf->width / 2; | 252 int uv_width = buf->width / 2; |
| 256 int uv_height = buf->height / 2; // YV12 format. | 253 int uv_height = buf->height / 2; // YV12 format. |
| 257 CopyYPlane(buffer, y_width, y_height, video_frame); | 254 CopyYPlane(buffer, y_width, y_height, video_frame); |
| 258 buffer += y_width * y_height; | 255 buffer += y_width * y_height; |
| 259 CopyUPlane(buffer, uv_width, uv_height, video_frame); | 256 CopyUPlane(buffer, uv_width, uv_height, video_frame); |
| 260 buffer += uv_width * uv_height; | 257 buffer += uv_width * uv_height; |
| 261 CopyVPlane(buffer, uv_width, uv_height, video_frame); | 258 CopyVPlane(buffer, uv_width, uv_height, video_frame); |
| 262 | 259 |
| 263 DeliverFrame(video_frame); | 260 DeliverFrame(video_frame); |
| 264 capture->FeedBuffer(buf); | 261 capture->FeedBuffer(buf); |
| 265 } | 262 } |
| 266 | 263 |
| 267 void CaptureVideoDecoder::DeliverFrame( | 264 void CaptureVideoDecoder::DeliverFrame( |
| 268 const scoped_refptr<media::VideoFrame>& video_frame) { | 265 const scoped_refptr<media::VideoFrame>& video_frame) { |
| 269 // Reset the callback before running to protect against reentrancy. | 266 // Reset the callback before running to protect against reentrancy. |
| 270 base::ResetAndReturn(&read_cb_).Run(kOk, video_frame); | 267 base::ResetAndReturn(&read_cb_).Run(kOk, video_frame); |
| 271 } | 268 } |
| OLD | NEW |