Commit 5be42805 authored by Markus Handell's avatar Markus Handell Committed by Commit Bot

VideoCaptureDeviceAVFoundationLegacy: revert to legacy state.

This change reverts VideoCaptureDeviceAVFoundationLegacy to the
implementation in video_capture_device_avfoundation at rev 86ee59bf,
permitting further evolution in VideoCaptureDeviceAVFoundation while
retaining the legacy implementation accessible by running with
kAVFoundationCaptureV2 disabled.

Bug: chromium:1126690
Change-Id: I5be7e3dffc4b72d51e69710651fd3a46fb2a9860
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2404166
Commit-Queue: Markus Handell <handellm@google.com>
Reviewed-by: default avatarccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806475}
parent e44e31a4
...@@ -15,6 +15,42 @@ ...@@ -15,6 +15,42 @@
#include "media/capture/video/video_capture_device.h" #include "media/capture/video/video_capture_device.h"
#include "media/capture/video_capture_types.h" #include "media/capture/video_capture_types.h"
namespace media {
class VideoCaptureDeviceMac;
}
// Class used by VideoCaptureDeviceMac (VCDM) for video and image capture using
// AVFoundation API. This class lives inside the thread created by its owner
// VCDM.
//
// * Clients (VCDM) should call +deviceNames to fetch the list of devices
// available in the system; this method returns the list of device names that
// have to be used with -setCaptureDevice:.
// * Previous to any use, clients (VCDM) must call -initWithFrameReceiver: to
// initialise an object of this class and register a |frameReceiver_|.
// * Frame receiver registration or removal can also happen via explicit call
// to -setFrameReceiver:. Re-registrations are safe and allowed, even during
// capture using this method.
// * Method -setCaptureDevice: must be called at least once with a device
// identifier from +deviceNames. Creates all the necessary AVFoundation
// objects on first call; it connects them ready for capture every time.
// This method should not be called during capture (i.e. between
// -startCapture and -stopCapture).
// * -setCaptureWidth:height:frameRate: is called if a resolution or frame rate
// different than the by default one set by -setCaptureDevice: is needed.
// This method should not be called during capture. This method must be
// called after -setCaptureDevice:.
// * -startCapture registers the notification listeners and starts the
// capture. The capture can be stop using -stopCapture. The capture can be
// restarted and restoped multiple times, reconfiguring or not the device in
// between.
// * -setCaptureDevice can be called with a |nil| value, case in which it stops
// the capture and disconnects the library objects. This step is not
// necessary.
// * Deallocation of the library objects happens gracefully on destruction of
// the VideoCaptureDeviceAVFoundation object.
//
//
@interface VideoCaptureDeviceAVFoundationLegacy @interface VideoCaptureDeviceAVFoundationLegacy
: NSObject <AVCaptureVideoDataOutputSampleBufferDelegate, : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate,
VideoCaptureDeviceAVFoundationProtocol> { VideoCaptureDeviceAVFoundationProtocol> {
...@@ -24,9 +60,6 @@ ...@@ -24,9 +60,6 @@
int _frameHeight; int _frameHeight;
float _frameRate; float _frameRate;
// The capture format that best matches the above attributes.
base::scoped_nsobject<AVCaptureDeviceFormat> _bestCaptureFormat;
base::Lock _lock; // Protects concurrent setting and using |frameReceiver_|. base::Lock _lock; // Protects concurrent setting and using |frameReceiver_|.
media::VideoCaptureDeviceAVFoundationFrameReceiver* _frameReceiver; // weak. media::VideoCaptureDeviceAVFoundationFrameReceiver* _frameReceiver; // weak.
...@@ -40,18 +73,55 @@ ...@@ -40,18 +73,55 @@
// An AVDataOutput specialized for taking pictures out of |captureSession_|. // An AVDataOutput specialized for taking pictures out of |captureSession_|.
base::scoped_nsobject<AVCaptureStillImageOutput> _stillImageOutput; base::scoped_nsobject<AVCaptureStillImageOutput> _stillImageOutput;
size_t _takePhotoStartedCount;
size_t _takePhotoPendingCount;
size_t _takePhotoCompletedCount;
bool _stillImageOutputWarmupCompleted;
std::unique_ptr<base::WeakPtrFactory<VideoCaptureDeviceAVFoundationLegacy>>
_weakPtrFactoryForTakePhoto;
// For testing.
base::RepeatingCallback<void()> _onStillImageOutputStopped;
scoped_refptr<base::SingleThreadTaskRunner> _mainThreadTaskRunner; base::ThreadChecker _main_thread_checker;
} }
// Returns a dictionary of capture devices with friendly name and unique id.
+ (NSDictionary*)deviceNames;
// Retrieve the capture supported formats for a given device |descriptor|.
+ (void)getDevice:(const media::VideoCaptureDeviceDescriptor&)descriptor
supportedFormats:(media::VideoCaptureFormats*)formats;
// Initializes the instance and the underlying capture session and registers the
// frame receiver.
- (id)initWithFrameReceiver:
(media::VideoCaptureDeviceAVFoundationFrameReceiver*)frameReceiver;
// Sets the frame receiver.
- (void)setFrameReceiver:
(media::VideoCaptureDeviceAVFoundationFrameReceiver*)frameReceiver;
// Sets which capture device to use by name, retrieved via |deviceNames|. Once
// the deviceId is known, the library objects are created if needed and
// connected for the capture, and a by default resolution is set. If deviceId is
// nil, then the eventual capture is stopped and library objects are
// disconnected. Returns YES on success, NO otherwise. If the return value is
// NO, an error message is assigned to |outMessage|. This method should not be
// called during capture.
- (BOOL)setCaptureDevice:(NSString*)deviceId
errorMessage:(NSString**)outMessage;
// Configures the capture properties for the capture session and the video data
// output; this means it MUST be called after setCaptureDevice:. Return YES on
// success, else NO.
- (BOOL)setCaptureHeight:(int)height
width:(int)width
frameRate:(float)frameRate;
// Starts video capturing and register the notification listeners. Must be
// called after setCaptureDevice:, and, eventually, also after
// setCaptureHeight:width:frameRate:. Returns YES on success, NO otherwise.
- (BOOL)startCapture;
// Stops video capturing and stops listening to notifications.
- (void)stopCapture;
// Takes a photo. This method should only be called between -startCapture and
// -stopCapture.
- (void)takePhoto;
@end @end
#endif // MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_AVFOUNDATION_LEGACY_MAC_H_ #endif // MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_AVFOUNDATION_MAC_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment