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 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" | 5 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" |
6 | 6 |
7 #import <QTKit/QTKit.h> | 7 #import <QTKit/QTKit.h> |
8 | 8 |
9 #include "base/debug/crash_logging.h" | 9 #include "base/debug/crash_logging.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 [captureDecompressedOutput setPixelBufferAttributes:captureDictionary]; | 137 [captureDecompressedOutput setPixelBufferAttributes:captureDictionary]; |
138 | 138 |
139 return YES; | 139 return YES; |
140 } else { | 140 } else { |
141 // Remove the previously set capture device. | 141 // Remove the previously set capture device. |
142 if (!captureDeviceInput_) { | 142 if (!captureDeviceInput_) { |
143 [self sendErrorString:[NSString | 143 [self sendErrorString:[NSString |
144 stringWithUTF8String:"No video capture device set, on removal."]]; | 144 stringWithUTF8String:"No video capture device set, on removal."]]; |
145 return YES; | 145 return YES; |
146 } | 146 } |
147 if ([[captureSession_ inputs] count] > 0) { | 147 [self stopCapture]; |
148 // The device is still running. | |
149 [self stopCapture]; | |
150 } | |
151 if ([[captureSession_ outputs] count] > 0) { | 148 if ([[captureSession_ outputs] count] > 0) { |
152 // Only one output is set for |captureSession_|. | 149 // Only one output is set for |captureSession_|. |
153 DCHECK_EQ([[captureSession_ outputs] count], 1u); | 150 DCHECK_EQ([[captureSession_ outputs] count], 1u); |
154 id output = [[captureSession_ outputs] objectAtIndex:0]; | 151 id output = [[captureSession_ outputs] objectAtIndex:0]; |
155 [output setDelegate:nil]; | 152 [output setDelegate:nil]; |
156 | 153 |
157 // TODO(shess): QTKit achieves thread safety by posting messages to the | 154 // TODO(shess): QTKit achieves thread safety by posting messages to the |
158 // main thread. As part of -addOutput:, it posts a message to the main | 155 // main thread. As part of -addOutput:, it posts a message to the main |
159 // thread which in turn posts a notification which will run in a future | 156 // thread which in turn posts a notification which will run in a future |
160 // spin after the original method returns. -removeOutput: can post a | 157 // spin after the original method returns. -removeOutput: can post a |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 [NSNotificationCenter defaultCenter]; | 229 [NSNotificationCenter defaultCenter]; |
233 [notificationCenter addObserver:self | 230 [notificationCenter addObserver:self |
234 selector:@selector(handleNotification:) | 231 selector:@selector(handleNotification:) |
235 name:QTCaptureSessionRuntimeErrorNotification | 232 name:QTCaptureSessionRuntimeErrorNotification |
236 object:captureSession_]; | 233 object:captureSession_]; |
237 [captureSession_ startRunning]; | 234 [captureSession_ startRunning]; |
238 } | 235 } |
239 return YES; | 236 return YES; |
240 } | 237 } |
241 | 238 |
242 - (void)stopCapture { | 239 - (void)stopCapture { |
Scott Hess - ex-Googler
2014/08/15 23:38:15
Since you've removed the other user of -stopCaptur
mcasas
2014/08/18 11:29:43
-stopCapture is part of the device interface [1] t
| |
240 // Similar to the comments about -removeOutput: in -setCaptureDevice:, | |
241 // -removeInput: can post a call to main thread while holding a lock, | |
242 // causing a deadlock, see http://crbug.com/399792. | |
243 [self performSelectorOnMainThread:@selector(stopCaptureOnUIThread:) | |
244 withObject:captureSession_ | |
245 waitUntilDone:YES]; | |
246 [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
247 } | |
248 | |
249 - (void)stopCaptureOnUIThread:(QTCaptureSession*)captureSession { | |
243 if ([[captureSession_ inputs] count] == 1) { | 250 if ([[captureSession_ inputs] count] == 1) { |
Scott Hess - ex-Googler
2014/08/15 23:38:15
This test should definitely not be here. If the c
mcasas
2014/08/18 11:29:43
This test is actually a bug, since there is just o
| |
244 [captureSession_ removeInput:captureDeviceInput_]; | 251 [captureSession_ removeInput:captureDeviceInput_]; |
245 [captureSession_ stopRunning]; | 252 [captureSession_ stopRunning]; |
246 } | 253 } |
247 | |
248 [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
249 } | 254 } |
250 | 255 |
251 // |captureOutput| is called by the capture device to deliver a new frame. | 256 // |captureOutput| is called by the capture device to deliver a new frame. |
252 - (void)captureOutput:(QTCaptureOutput*)captureOutput | 257 - (void)captureOutput:(QTCaptureOutput*)captureOutput |
253 didOutputVideoFrame:(CVImageBufferRef)videoFrame | 258 didOutputVideoFrame:(CVImageBufferRef)videoFrame |
254 withSampleBuffer:(QTSampleBuffer*)sampleBuffer | 259 withSampleBuffer:(QTSampleBuffer*)sampleBuffer |
255 fromConnection:(QTCaptureConnection*)connection { | 260 fromConnection:(QTCaptureConnection*)connection { |
256 [lock_ lock]; | 261 [lock_ lock]; |
257 if(!frameReceiver_) { | 262 if(!frameReceiver_) { |
258 [lock_ unlock]; | 263 [lock_ unlock]; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 | 344 |
340 - (void)sendErrorString:(NSString*)error { | 345 - (void)sendErrorString:(NSString*)error { |
341 DLOG(ERROR) << [error UTF8String]; | 346 DLOG(ERROR) << [error UTF8String]; |
342 [lock_ lock]; | 347 [lock_ lock]; |
343 if (frameReceiver_) | 348 if (frameReceiver_) |
344 frameReceiver_->ReceiveError([error UTF8String]); | 349 frameReceiver_->ReceiveError([error UTF8String]); |
345 [lock_ unlock]; | 350 [lock_ unlock]; |
346 } | 351 } |
347 | 352 |
348 @end | 353 @end |
OLD | NEW |