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

Side by Side Diff: media/video/capture/mac/video_capture_device_mac.mm

Issue 66183002: Replace MessageLoopProxy with SingleThreadTaskRunner for the rest of media/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win and audio tests Created 6 years, 11 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 "media/video/capture/mac/video_capture_device_mac.h" 5 #include "media/video/capture/mac/video_capture_device_mac.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #import "media/video/capture/mac/avfoundation_glue.h" 12 #import "media/video/capture/mac/avfoundation_glue.h"
12 #import "media/video/capture/mac/platform_video_capturing_mac.h" 13 #import "media/video/capture/mac/platform_video_capturing_mac.h"
13 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h" 14 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h"
14 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" 15 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h"
15 16
16 namespace media { 17 namespace media {
17 18
18 const int kMinFrameRate = 1; 19 const int kMinFrameRate = 1;
19 const int kMaxFrameRate = 30; 20 const int kMaxFrameRate = 30;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 delete capture_device; 111 delete capture_device;
111 capture_device = NULL; 112 capture_device = NULL;
112 } 113 }
113 return capture_device; 114 return capture_device;
114 } 115 }
115 116
116 VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name) 117 VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name)
117 : device_name_(device_name), 118 : device_name_(device_name),
118 sent_frame_info_(false), 119 sent_frame_info_(false),
119 tried_to_square_pixels_(false), 120 tried_to_square_pixels_(false),
120 loop_proxy_(base::MessageLoopProxy::current()), 121 task_runner_(base::MessageLoopProxy::current()),
121 state_(kNotInitialized), 122 state_(kNotInitialized),
122 weak_factory_(this), 123 weak_factory_(this),
123 weak_this_(weak_factory_.GetWeakPtr()), 124 weak_this_(weak_factory_.GetWeakPtr()),
124 capture_device_(nil) { 125 capture_device_(nil) {
125 } 126 }
126 127
127 VideoCaptureDeviceMac::~VideoCaptureDeviceMac() { 128 VideoCaptureDeviceMac::~VideoCaptureDeviceMac() {
128 DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current()); 129 DCHECK(task_runner_->BelongsToCurrentThread());
129 [capture_device_ release]; 130 [capture_device_ release];
130 } 131 }
131 132
132 void VideoCaptureDeviceMac::AllocateAndStart( 133 void VideoCaptureDeviceMac::AllocateAndStart(
133 const VideoCaptureParams& params, 134 const VideoCaptureParams& params,
134 scoped_ptr<VideoCaptureDevice::Client> client) { 135 scoped_ptr<VideoCaptureDevice::Client> client) {
135 DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current()); 136 DCHECK(task_runner_->BelongsToCurrentThread());
136 if (state_ != kIdle) { 137 if (state_ != kIdle) {
137 return; 138 return;
138 } 139 }
139 int width = params.requested_format.frame_size.width(); 140 int width = params.requested_format.frame_size.width();
140 int height = params.requested_format.frame_size.height(); 141 int height = params.requested_format.frame_size.height();
141 int frame_rate = params.requested_format.frame_rate; 142 int frame_rate = params.requested_format.frame_rate;
142 143
143 // The OS API can scale captured frame to any size requested, which would lead 144 // The OS API can scale captured frame to any size requested, which would lead
144 // to undesired aspect ratio change. Try to open the camera with a natively 145 // to undesired aspect ratio change. Try to open the camera with a natively
145 // supported format and let the client crop/pad the captured frames. 146 // supported format and let the client crop/pad the captured frames.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 182
182 if (![capture_device_ startCapture]) { 183 if (![capture_device_ startCapture]) {
183 SetErrorState("Could not start capture device."); 184 SetErrorState("Could not start capture device.");
184 return; 185 return;
185 } 186 }
186 187
187 state_ = kCapturing; 188 state_ = kCapturing;
188 } 189 }
189 190
190 void VideoCaptureDeviceMac::StopAndDeAllocate() { 191 void VideoCaptureDeviceMac::StopAndDeAllocate() {
191 DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current()); 192 DCHECK(task_runner_->BelongsToCurrentThread());
192 DCHECK(state_ == kCapturing || state_ == kError) << state_; 193 DCHECK(state_ == kCapturing || state_ == kError) << state_;
193 [capture_device_ stopCapture]; 194 [capture_device_ stopCapture];
194 195
195 [capture_device_ setCaptureDevice:nil]; 196 [capture_device_ setCaptureDevice:nil];
196 [capture_device_ setFrameReceiver:nil]; 197 [capture_device_ setFrameReceiver:nil];
197 client_.reset(); 198 client_.reset();
198 state_ = kIdle; 199 state_ = kIdle;
199 tried_to_square_pixels_ = false; 200 tried_to_square_pixels_ = false;
200 } 201 }
201 202
202 bool VideoCaptureDeviceMac::Init() { 203 bool VideoCaptureDeviceMac::Init() {
203 DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current()); 204 DCHECK(task_runner_->BelongsToCurrentThread());
204 DCHECK_EQ(state_, kNotInitialized); 205 DCHECK_EQ(state_, kNotInitialized);
205 206
206 // TODO(mcasas): The following check might not be necessary; if the device has 207 // TODO(mcasas): The following check might not be necessary; if the device has
207 // disappeared after enumeration and before coming here, opening would just 208 // disappeared after enumeration and before coming here, opening would just
208 // fail but not necessarily produce a crash. 209 // fail but not necessarily produce a crash.
209 Names device_names; 210 Names device_names;
210 GetDeviceNames(&device_names); 211 GetDeviceNames(&device_names);
211 Names::iterator it = device_names.begin(); 212 Names::iterator it = device_names.begin();
212 for (; it != device_names.end(); ++it) { 213 for (; it != device_names.end(); ++it) {
213 if (it->id() == device_name_.id()) 214 if (it->id() == device_name_.id())
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 frame_format.frame_size.height()); 306 frame_format.frame_size.height());
306 307
307 client_->OnIncomingCapturedFrame(video_frame, 308 client_->OnIncomingCapturedFrame(video_frame,
308 video_frame_length, 309 video_frame_length,
309 base::Time::Now(), 310 base::Time::Now(),
310 0, 311 0,
311 capture_format_); 312 capture_format_);
312 } 313 }
313 314
314 void VideoCaptureDeviceMac::ReceiveError(const std::string& reason) { 315 void VideoCaptureDeviceMac::ReceiveError(const std::string& reason) {
315 loop_proxy_->PostTask(FROM_HERE, 316 task_runner_->PostTask(FROM_HERE,
316 base::Bind(&VideoCaptureDeviceMac::SetErrorState, weak_this_, 317 base::Bind(&VideoCaptureDeviceMac::SetErrorState, weak_this_,
317 reason)); 318 reason));
318 } 319 }
319 320
320 void VideoCaptureDeviceMac::SetErrorState(const std::string& reason) { 321 void VideoCaptureDeviceMac::SetErrorState(const std::string& reason) {
321 DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current()); 322 DCHECK(task_runner_->BelongsToCurrentThread());
322 DLOG(ERROR) << reason; 323 DLOG(ERROR) << reason;
323 state_ = kError; 324 state_ = kError;
324 client_->OnError(); 325 client_->OnError();
325 } 326 }
326 327
327 bool VideoCaptureDeviceMac::UpdateCaptureResolution() { 328 bool VideoCaptureDeviceMac::UpdateCaptureResolution() {
328 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height() 329 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height()
329 width:capture_format_.frame_size.width() 330 width:capture_format_.frame_size.width()
330 frameRate:capture_format_.frame_rate]) { 331 frameRate:capture_format_.frame_rate]) {
331 ReceiveError("Could not configure capture device."); 332 ReceiveError("Could not configure capture device.");
332 return false; 333 return false;
333 } 334 }
334 return true; 335 return true;
335 } 336 }
336 337
337 } // namespace media 338 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/mac/video_capture_device_mac.h ('k') | media/video/capture/video_capture_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698