Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/renderer_host/media/video_capture_device_impl.h" | 5 #include "content/browser/renderer_host/media/video_capture_device_impl.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 capture_machine->Stop(); | 37 capture_machine->Stop(); |
| 38 capture_machine.reset(); | 38 capture_machine.reset(); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 ThreadSafeCaptureOracle::ThreadSafeCaptureOracle( | 44 ThreadSafeCaptureOracle::ThreadSafeCaptureOracle( |
| 45 scoped_ptr<media::VideoCaptureDevice::Client> client, | 45 scoped_ptr<media::VideoCaptureDevice::Client> client, |
| 46 scoped_ptr<VideoCaptureOracle> oracle, | 46 scoped_ptr<VideoCaptureOracle> oracle, |
| 47 const gfx::Size& capture_size, | 47 const media::VideoCaptureParams& params) |
| 48 int frame_rate) | |
| 49 : client_(client.Pass()), | 48 : client_(client.Pass()), |
| 50 oracle_(oracle.Pass()), | 49 oracle_(oracle.Pass()), |
| 51 capture_size_(capture_size), | 50 params_(params), |
| 52 frame_rate_(frame_rate) {} | 51 capture_size_updated_(false) { |
| 52 // Frame dimensions must each be an even integer since the client wants (or | |
| 53 // will convert to) YUV420. | |
| 54 capture_size_ = gfx::Size( | |
| 55 MakeEven(params.requested_format.frame_size.width()), | |
| 56 MakeEven(params.requested_format.frame_size.height())); | |
| 57 frame_rate_ = params.requested_format.frame_rate; | |
| 58 } | |
| 53 | 59 |
| 54 ThreadSafeCaptureOracle::~ThreadSafeCaptureOracle() {} | 60 ThreadSafeCaptureOracle::~ThreadSafeCaptureOracle() {} |
| 55 | 61 |
| 56 bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture( | 62 bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture( |
| 57 VideoCaptureOracle::Event event, | 63 VideoCaptureOracle::Event event, |
| 58 base::Time event_time, | 64 base::Time event_time, |
| 59 scoped_refptr<media::VideoFrame>* storage, | 65 scoped_refptr<media::VideoFrame>* storage, |
| 60 CaptureFrameCallback* callback) { | 66 CaptureFrameCallback* callback) { |
| 61 base::AutoLock guard(lock_); | 67 base::AutoLock guard(lock_); |
| 62 | 68 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 gfx::Rect(capture_size_), | 121 gfx::Rect(capture_size_), |
| 116 capture_size_, | 122 capture_size_, |
| 117 static_cast<uint8*>(output_buffer->data()), | 123 static_cast<uint8*>(output_buffer->data()), |
| 118 output_buffer->size(), | 124 output_buffer->size(), |
| 119 base::SharedMemory::NULLHandle(), | 125 base::SharedMemory::NULLHandle(), |
| 120 base::TimeDelta(), | 126 base::TimeDelta(), |
| 121 base::Closure()); | 127 base::Closure()); |
| 122 return true; | 128 return true; |
| 123 } | 129 } |
| 124 | 130 |
| 131 void ThreadSafeCaptureOracle::UpdateCaptureSize(const gfx::Size& source_size) { | |
| 132 base::AutoLock guard(lock_); | |
| 133 | |
| 134 // If this is the first call to UpdateCaptureSize(), or the receiver supports | |
| 135 // variable resolution, then determine the capture size by treating the | |
| 136 // requested width and height as maxima. | |
| 137 if (!capture_size_updated_ || params_.allow_resolution_change) { | |
| 138 // The capture resolution should not exceed the source frame size. | |
| 139 // In other words it should downscale the image but not upscale it. | |
| 140 gfx::Size capture_size = params_.requested_format.frame_size; | |
| 141 capture_size.SetToMin(source_size); | |
|
Sergey Ulanov
2013/12/03 02:14:23
SetToMin() doesn't preserve aspect ratio. I think
hshi1
2013/12/03 02:19:36
Done.
| |
| 142 capture_size_ = gfx::Size(MakeEven(capture_size.width()), | |
| 143 MakeEven(capture_size.height())); | |
| 144 capture_size_updated_ = true; | |
| 145 } | |
| 146 } | |
| 147 | |
| 125 void ThreadSafeCaptureOracle::Stop() { | 148 void ThreadSafeCaptureOracle::Stop() { |
| 126 base::AutoLock guard(lock_); | 149 base::AutoLock guard(lock_); |
| 127 client_.reset(); | 150 client_.reset(); |
| 128 } | 151 } |
| 129 | 152 |
| 130 void ThreadSafeCaptureOracle::ReportError() { | 153 void ThreadSafeCaptureOracle::ReportError() { |
| 131 base::AutoLock guard(lock_); | 154 base::AutoLock guard(lock_); |
| 132 if (client_) | 155 if (client_) |
| 133 client_->OnError(); | 156 client_->OnError(); |
| 134 } | 157 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 DVLOG(1) << "Allocate() invoked when not in state Idle."; | 189 DVLOG(1) << "Allocate() invoked when not in state Idle."; |
| 167 return; | 190 return; |
| 168 } | 191 } |
| 169 | 192 |
| 170 if (params.requested_format.frame_rate <= 0) { | 193 if (params.requested_format.frame_rate <= 0) { |
| 171 DVLOG(1) << "invalid frame_rate: " << params.requested_format.frame_rate; | 194 DVLOG(1) << "invalid frame_rate: " << params.requested_format.frame_rate; |
| 172 client->OnError(); | 195 client->OnError(); |
| 173 return; | 196 return; |
| 174 } | 197 } |
| 175 | 198 |
| 176 // Frame dimensions must each be a positive, even integer, since the client | 199 if (params.requested_format.frame_size.width() < kMinFrameWidth || |
| 177 // wants (or will convert to) YUV420. | 200 params.requested_format.frame_size.height() < kMinFrameHeight) { |
| 178 gfx::Size frame_size(MakeEven(params.requested_format.frame_size.width()), | 201 DVLOG(1) << "invalid frame size: " |
| 179 MakeEven(params.requested_format.frame_size.height())); | 202 << params.requested_format.frame_size.ToString(); |
| 180 if (frame_size.width() < kMinFrameWidth || | |
| 181 frame_size.height() < kMinFrameHeight) { | |
| 182 DVLOG(1) << "invalid frame size: " << frame_size.ToString(); | |
| 183 client->OnError(); | 203 client->OnError(); |
| 184 return; | 204 return; |
| 185 } | 205 } |
| 186 | 206 |
| 187 base::TimeDelta capture_period = base::TimeDelta::FromMicroseconds( | 207 base::TimeDelta capture_period = base::TimeDelta::FromMicroseconds( |
| 188 1000000.0 / params.requested_format.frame_rate + 0.5); | 208 1000000.0 / params.requested_format.frame_rate + 0.5); |
| 189 | 209 |
| 190 scoped_ptr<VideoCaptureOracle> oracle( | 210 scoped_ptr<VideoCaptureOracle> oracle( |
| 191 new VideoCaptureOracle(capture_period, | 211 new VideoCaptureOracle(capture_period, |
| 192 kAcceleratedSubscriberIsSupported)); | 212 kAcceleratedSubscriberIsSupported)); |
| 193 oracle_proxy_ = | 213 oracle_proxy_ = |
| 194 new ThreadSafeCaptureOracle(client.Pass(), | 214 new ThreadSafeCaptureOracle(client.Pass(), |
| 195 oracle.Pass(), | 215 oracle.Pass(), |
| 196 frame_size, | 216 params); |
| 197 params.requested_format.frame_rate); | |
| 198 | 217 |
| 199 // Starts the capture machine asynchronously. | 218 // Starts the capture machine asynchronously. |
| 200 BrowserThread::PostTaskAndReplyWithResult( | 219 BrowserThread::PostTaskAndReplyWithResult( |
| 201 BrowserThread::UI, FROM_HERE, | 220 BrowserThread::UI, FROM_HERE, |
| 202 base::Bind(&VideoCaptureMachine::Start, | 221 base::Bind(&VideoCaptureMachine::Start, |
| 203 base::Unretained(capture_machine_.get()), | 222 base::Unretained(capture_machine_.get()), |
| 204 oracle_proxy_), | 223 oracle_proxy_), |
| 205 base::Bind(&VideoCaptureDeviceImpl::CaptureStarted, | 224 base::Bind(&VideoCaptureDeviceImpl::CaptureStarted, |
| 206 AsWeakPtr())); | 225 AsWeakPtr())); |
| 207 | 226 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 return; | 290 return; |
| 272 | 291 |
| 273 if (oracle_proxy_) | 292 if (oracle_proxy_) |
| 274 oracle_proxy_->ReportError(); | 293 oracle_proxy_->ReportError(); |
| 275 | 294 |
| 276 StopAndDeAllocate(); | 295 StopAndDeAllocate(); |
| 277 TransitionStateTo(kError); | 296 TransitionStateTo(kError); |
| 278 } | 297 } |
| 279 | 298 |
| 280 } // namespace content | 299 } // namespace content |
| OLD | NEW |