| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_AVFOUNDATION_MAC_H_ | |
| 6 #define MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_AVFOUNDATION_MAC_H_ | |
| 7 | |
| 8 #import <Foundation/Foundation.h> | |
| 9 | |
| 10 #import "base/mac/scoped_nsobject.h" | |
| 11 #include "base/synchronization/lock.h" | |
| 12 #include "base/threading/thread_checker.h" | |
| 13 #import "media/base/mac/avfoundation_glue.h" | |
| 14 #include "media/base/video_capture_types.h" | |
| 15 #include "media/capture/video/video_capture_device.h" | |
| 16 | |
| 17 namespace media { | |
| 18 class VideoCaptureDeviceMac; | |
| 19 } | |
| 20 | |
| 21 @class CrAVCaptureDevice; | |
| 22 @class CrAVCaptureSession; | |
| 23 @class CrAVCaptureVideoDataOutput; | |
| 24 @class CrAVCaptureStillImageOutput; | |
| 25 | |
| 26 // Class used by VideoCaptureDeviceMac (VCDM) for video and image capture using | |
| 27 // AVFoundation API. This class lives inside the thread created by its owner | |
| 28 // VCDM. | |
| 29 // | |
| 30 // * Clients (VCDM) should call +deviceNames to fetch the list of devices | |
| 31 // available in the system; this method returns the list of device names that | |
| 32 // have to be used with -setCaptureDevice:. | |
| 33 // * Previous to any use, clients (VCDM) must call -initWithFrameReceiver: to | |
| 34 // initialise an object of this class and register a |frameReceiver_|. | |
| 35 // * Frame receiver registration or removal can also happen via explicit call | |
| 36 // to -setFrameReceiver:. Re-registrations are safe and allowed, even during | |
| 37 // capture using this method. | |
| 38 // * Method -setCaptureDevice: must be called at least once with a device | |
| 39 // identifier from +deviceNames. Creates all the necessary AVFoundation | |
| 40 // objects on first call; it connects them ready for capture every time. | |
| 41 // This method should not be called during capture (i.e. between | |
| 42 // -startCapture and -stopCapture). | |
| 43 // * -setCaptureWidth:height:frameRate: is called if a resolution or frame rate | |
| 44 // different than the by default one set by -setCaptureDevice: is needed. | |
| 45 // This method should not be called during capture. This method must be | |
| 46 // called after -setCaptureDevice:. | |
| 47 // * -startCapture registers the notification listeners and starts the | |
| 48 // capture. The capture can be stop using -stopCapture. The capture can be | |
| 49 // restarted and restoped multiple times, reconfiguring or not the device in | |
| 50 // between. | |
| 51 // * -setCaptureDevice can be called with a |nil| value, case in which it stops | |
| 52 // the capture and disconnects the library objects. This step is not | |
| 53 // necessary. | |
| 54 // * Deallocation of the library objects happens gracefully on destruction of | |
| 55 // the VideoCaptureDeviceAVFoundation object. | |
| 56 // | |
| 57 // | |
| 58 @interface VideoCaptureDeviceAVFoundation | |
| 59 : NSObject<CrAVCaptureVideoDataOutputSampleBufferDelegate> { | |
| 60 @private | |
| 61 // The following attributes are set via -setCaptureHeight:width:frameRate:. | |
| 62 int frameWidth_; | |
| 63 int frameHeight_; | |
| 64 float frameRate_; | |
| 65 | |
| 66 base::Lock lock_; // Protects concurrent setting and using |frameReceiver_|. | |
| 67 media::VideoCaptureDeviceMac* frameReceiver_; // weak. | |
| 68 | |
| 69 base::scoped_nsobject<CrAVCaptureSession> captureSession_; | |
| 70 | |
| 71 // |captureDevice_| is an object coming from AVFoundation, used only to be | |
| 72 // plugged in |captureDeviceInput_| and to query for session preset support. | |
| 73 CrAVCaptureDevice* captureDevice_; | |
| 74 // |captureDeviceInput_| is owned by |captureSession_|. | |
| 75 CrAVCaptureDeviceInput* captureDeviceInput_; | |
| 76 base::scoped_nsobject<CrAVCaptureVideoDataOutput> captureVideoDataOutput_; | |
| 77 | |
| 78 // An AVDataOutput specialized for taking pictures out of |captureSession_|. | |
| 79 base::scoped_nsobject<CrAVCaptureStillImageOutput> stillImageOutput_; | |
| 80 | |
| 81 base::ThreadChecker main_thread_checker_; | |
| 82 } | |
| 83 | |
| 84 // Returns a dictionary of capture devices with friendly name and unique id. | |
| 85 + (NSDictionary*)deviceNames; | |
| 86 | |
| 87 // Retrieve the capture supported formats for a given device |name|. | |
| 88 + (void)getDevice:(const media::VideoCaptureDevice::Name&)name | |
| 89 supportedFormats:(media::VideoCaptureFormats*)formats; | |
| 90 | |
| 91 // Initializes the instance and the underlying capture session and registers the | |
| 92 // frame receiver. | |
| 93 - (id)initWithFrameReceiver:(media::VideoCaptureDeviceMac*)frameReceiver; | |
| 94 | |
| 95 // Sets the frame receiver. | |
| 96 - (void)setFrameReceiver:(media::VideoCaptureDeviceMac*)frameReceiver; | |
| 97 | |
| 98 // Sets which capture device to use by name, retrieved via |deviceNames|. Once | |
| 99 // the deviceId is known, the library objects are created if needed and | |
| 100 // connected for the capture, and a by default resolution is set. If deviceId is | |
| 101 // nil, then the eventual capture is stopped and library objects are | |
| 102 // disconnected. Returns YES on success, NO otherwise. This method should not be | |
| 103 // called during capture. | |
| 104 - (BOOL)setCaptureDevice:(NSString*)deviceId; | |
| 105 | |
| 106 // Configures the capture properties for the capture session and the video data | |
| 107 // output; this means it MUST be called after setCaptureDevice:. Return YES on | |
| 108 // success, else NO. | |
| 109 - (BOOL)setCaptureHeight:(int)height | |
| 110 width:(int)width | |
| 111 frameRate:(float)frameRate; | |
| 112 | |
| 113 // Starts video capturing and register the notification listeners. Must be | |
| 114 // called after setCaptureDevice:, and, eventually, also after | |
| 115 // setCaptureHeight:width:frameRate:. Returns YES on success, NO otherwise. | |
| 116 - (BOOL)startCapture; | |
| 117 | |
| 118 // Stops video capturing and stops listening to notifications. | |
| 119 - (void)stopCapture; | |
| 120 | |
| 121 // Takes a photo. This method should only be called between -startCapture and | |
| 122 // -stopCapture. | |
| 123 - (void)takePhoto; | |
| 124 | |
| 125 @end | |
| 126 | |
| 127 #endif // MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_AVFOUNDATION_MAC_H_ | |
| OLD | NEW |