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
3 // found in the LICENSE file.
5 // MacOSX implementation of generic VideoCaptureDevice, using either QTKit or
6 // AVFoundation as native capture API. QTKit is available in all OSX versions,
7 // although namely deprecated in 10.9, and AVFoundation is available in versions
8 // 10.7 (Lion) and later.
10 #ifndef MEDIA_VIDEO_CAPTURE_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_
11 #define MEDIA_VIDEO_CAPTURE_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_
13 #import <Foundation/Foundation.h>
17 #include "base/compiler_specific.h"
18 #include "base/mac/scoped_nsobject.h"
19 #include "base/memory/ref_counted.h"
20 #include "base/memory/weak_ptr.h"
21 #include "media/video/capture/video_capture_device.h"
22 #include "media/video/capture/video_capture_types.h"
24 @protocol PlatformVideoCapturingMac;
27 class SingleThreadTaskRunner;
30 // Small class to bundle device name and connection type into a dictionary.
32 @interface DeviceNameAndTransportType : NSObject {
34 base::scoped_nsobject<NSString> deviceName_;
35 // The transport type of the device (USB, PCI, etc), values are defined in
36 // <IOKit/audio/IOAudioTypes.h> as kIOAudioDeviceTransportType*.
37 int32_t transportType_;
40 - (id)initWithName:(NSString*)name transportType:(int32_t)transportType;
42 - (NSString*)deviceName;
43 - (int32_t)transportType;
49 // Unknown transport type, addition to the kIOAudioDeviceTransportType*
50 // family for QTKit devices where this attribute isn't published.
51 kIOAudioDeviceTransportTypeUnknown = 'unkn'
54 // Called by VideoCaptureManager to open, close and start, stop Mac video
56 class VideoCaptureDeviceMac : public VideoCaptureDevice {
58 explicit VideoCaptureDeviceMac(const Name& device_name);
59 virtual ~VideoCaptureDeviceMac();
61 // VideoCaptureDevice implementation.
62 virtual void AllocateAndStart(
63 const VideoCaptureParams& params,
64 scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE;
65 virtual void StopAndDeAllocate() OVERRIDE;
67 bool Init(VideoCaptureDevice::Name::CaptureApiType capture_api_type);
69 // Called to deliver captured video frames.
70 void ReceiveFrame(const uint8* video_frame,
71 int video_frame_length,
72 const VideoCaptureFormat& frame_format,
74 int aspect_denominator);
76 void ReceiveError(const std::string& reason);
79 void SetErrorState(const std::string& reason);
80 void LogMessage(const std::string& message);
81 bool UpdateCaptureResolution();
83 // Flag indicating the internal state.
92 scoped_ptr<VideoCaptureDevice::Client> client_;
94 VideoCaptureFormat capture_format_;
95 // These variables control the two-step configure-start process for QTKit HD:
96 // the device is first started with no configuration and the captured frames
97 // are inspected to check if the camera really supports HD. AVFoundation does
98 // not need this process so |final_resolution_selected_| is false then.
99 bool final_resolution_selected_;
100 bool tried_to_square_pixels_;
102 // Only read and write state_ from inside this loop.
103 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
104 InternalState state_;
106 id<PlatformVideoCapturingMac> capture_device_;
108 // Used with Bind and PostTask to ensure that methods aren't called after the
109 // VideoCaptureDeviceMac is destroyed.
110 // NOTE: Weak pointers must be invalidated before all other member variables.
111 base::WeakPtrFactory<VideoCaptureDeviceMac> weak_factory_;
113 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceMac);
118 #endif // MEDIA_VIDEO_CAPTURE_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_