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

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: Created 7 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) 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/time/time.h" 10 #include "base/time/time.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 delete capture_device; 105 delete capture_device;
106 capture_device = NULL; 106 capture_device = NULL;
107 } 107 }
108 return capture_device; 108 return capture_device;
109 } 109 }
110 110
111 VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name) 111 VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name)
112 : device_name_(device_name), 112 : device_name_(device_name),
113 sent_frame_info_(false), 113 sent_frame_info_(false),
114 tried_to_square_pixels_(false), 114 tried_to_square_pixels_(false),
115 loop_proxy_(base::MessageLoopProxy::current()), 115 task_runner_(base::MessageLoopProxy::current()),
116 state_(kNotInitialized), 116 state_(kNotInitialized),
117 weak_factory_(this), 117 weak_factory_(this),
118 weak_this_(weak_factory_.GetWeakPtr()), 118 weak_this_(weak_factory_.GetWeakPtr()),
119 capture_device_(nil) { 119 capture_device_(nil) {
120 } 120 }
121 121
122 VideoCaptureDeviceMac::~VideoCaptureDeviceMac() { 122 VideoCaptureDeviceMac::~VideoCaptureDeviceMac() {
123 DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current()); 123 DCHECK_EQ(task_runner_->BelongsToCurrentThread());
124 [capture_device_ release]; 124 [capture_device_ release];
125 } 125 }
126 126
127 void VideoCaptureDeviceMac::AllocateAndStart( 127 void VideoCaptureDeviceMac::AllocateAndStart(
128 const VideoCaptureCapability& capture_format, 128 const VideoCaptureCapability& capture_format,
129 scoped_ptr<VideoCaptureDevice::Client> client) { 129 scoped_ptr<VideoCaptureDevice::Client> client) {
130 DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current()); 130 DCHECK_EQ(task_runner_->BelongsToCurrentThread());
131 if (state_ != kIdle) { 131 if (state_ != kIdle) {
132 return; 132 return;
133 } 133 }
134 int width = capture_format.width; 134 int width = capture_format.width;
135 int height = capture_format.height; 135 int height = capture_format.height;
136 int frame_rate = capture_format.frame_rate; 136 int frame_rate = capture_format.frame_rate;
137 137
138 // The OS API can scale captured frame to any size requested, which would lead 138 // The OS API can scale captured frame to any size requested, which would lead
139 // to undesired aspect ratio change. Try to open the camera with a natively 139 // to undesired aspect ratio change. Try to open the camera with a natively
140 // supported format and let the client crop/pad the captured frames. 140 // supported format and let the client crop/pad the captured frames.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 if (![capture_device_ startCapture]) { 178 if (![capture_device_ startCapture]) {
179 SetErrorState("Could not start capture device."); 179 SetErrorState("Could not start capture device.");
180 return; 180 return;
181 } 181 }
182 182
183 state_ = kCapturing; 183 state_ = kCapturing;
184 } 184 }
185 185
186 void VideoCaptureDeviceMac::StopAndDeAllocate() { 186 void VideoCaptureDeviceMac::StopAndDeAllocate() {
187 DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current()); 187 DCHECK_EQ(task_runner_->BelongsToCurrentThread());
188 DCHECK(state_ == kCapturing || state_ == kError) << state_; 188 DCHECK(state_ == kCapturing || state_ == kError) << state_;
189 [capture_device_ stopCapture]; 189 [capture_device_ stopCapture];
190 190
191 [capture_device_ setCaptureDevice:nil]; 191 [capture_device_ setCaptureDevice:nil];
192 [capture_device_ setFrameReceiver:nil]; 192 [capture_device_ setFrameReceiver:nil];
193 client_.reset(); 193 client_.reset();
194 state_ = kIdle; 194 state_ = kIdle;
195 tried_to_square_pixels_ = false; 195 tried_to_square_pixels_ = false;
196 } 196 }
197 197
198 bool VideoCaptureDeviceMac::Init() { 198 bool VideoCaptureDeviceMac::Init() {
199 DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current()); 199 DCHECK_EQ(task_runner_->BelongsToCurrentThread());
200 DCHECK_EQ(state_, kNotInitialized); 200 DCHECK_EQ(state_, kNotInitialized);
201 201
202 Names device_names; 202 Names device_names;
203 GetDeviceNames(&device_names); 203 GetDeviceNames(&device_names);
204 Name* found = device_names.FindById(device_name_.id()); 204 Name* found = device_names.FindById(device_name_.id());
205 if (!found) 205 if (!found)
206 return false; 206 return false;
207 207
208 capture_device_ = 208 capture_device_ =
209 [[VideoCaptureDeviceQTKit alloc] initWithFrameReceiver:this]; 209 [[VideoCaptureDeviceQTKit alloc] initWithFrameReceiver:this];
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 287 }
288 288
289 DCHECK(current_settings_.width == frame_info.width && 289 DCHECK(current_settings_.width == frame_info.width &&
290 current_settings_.height == frame_info.height); 290 current_settings_.height == frame_info.height);
291 291
292 client_->OnIncomingCapturedFrame( 292 client_->OnIncomingCapturedFrame(
293 video_frame, video_frame_length, base::Time::Now(), 0, false, false); 293 video_frame, video_frame_length, base::Time::Now(), 0, false, false);
294 } 294 }
295 295
296 void VideoCaptureDeviceMac::ReceiveError(const std::string& reason) { 296 void VideoCaptureDeviceMac::ReceiveError(const std::string& reason) {
297 loop_proxy_->PostTask(FROM_HERE, 297 task_runner_->PostTask(FROM_HERE,
298 base::Bind(&VideoCaptureDeviceMac::SetErrorState, weak_this_, 298 base::Bind(&VideoCaptureDeviceMac::SetErrorState, weak_this_,
299 reason)); 299 reason));
300 } 300 }
301 301
302 void VideoCaptureDeviceMac::SetErrorState(const std::string& reason) { 302 void VideoCaptureDeviceMac::SetErrorState(const std::string& reason) {
303 DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current()); 303 DCHECK_EQ(task_runner_->BelongsToCurrentThread());
304 DLOG(ERROR) << reason; 304 DLOG(ERROR) << reason;
305 state_ = kError; 305 state_ = kError;
306 client_->OnError(); 306 client_->OnError();
307 } 307 }
308 308
309 bool VideoCaptureDeviceMac::UpdateCaptureResolution() { 309 bool VideoCaptureDeviceMac::UpdateCaptureResolution() {
310 if (![capture_device_ setCaptureHeight:current_settings_.height 310 if (![capture_device_ setCaptureHeight:current_settings_.height
311 width:current_settings_.width 311 width:current_settings_.width
312 frameRate:current_settings_.frame_rate]) { 312 frameRate:current_settings_.frame_rate]) {
313 ReceiveError("Could not configure capture device."); 313 ReceiveError("Could not configure capture device.");
314 return false; 314 return false;
315 } 315 }
316 return true; 316 return true;
317 } 317 }
318 318
319 } // namespace media 319 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698