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_
15 #include "base/compiler_specific.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/weak_ptr.h"
18 #include "media/video/capture/video_capture_device.h"
19 #include "media/video/capture/video_capture_types.h"
21 @protocol PlatformVideoCapturingMac
;
24 class SingleThreadTaskRunner
;
29 // Called by VideoCaptureManager to open, close and start, stop Mac video
31 class VideoCaptureDeviceMac
: public VideoCaptureDevice
{
33 explicit VideoCaptureDeviceMac(const Name
& device_name
);
34 virtual ~VideoCaptureDeviceMac();
36 // VideoCaptureDevice implementation.
37 virtual void AllocateAndStart(
38 const VideoCaptureParams
& params
,
39 scoped_ptr
<VideoCaptureDevice::Client
> client
) OVERRIDE
;
40 virtual void StopAndDeAllocate() OVERRIDE
;
42 bool Init(VideoCaptureDevice::Name::CaptureApiType capture_api_type
);
44 // Called to deliver captured video frames.
45 void ReceiveFrame(const uint8
* video_frame
,
46 int video_frame_length
,
47 const VideoCaptureFormat
& frame_format
,
49 int aspect_denominator
);
51 void ReceiveError(const std::string
& reason
);
54 void SetErrorState(const std::string
& reason
);
55 void LogMessage(const std::string
& message
);
56 bool UpdateCaptureResolution();
58 // Flag indicating the internal state.
67 scoped_ptr
<VideoCaptureDevice::Client
> client_
;
69 VideoCaptureFormat capture_format_
;
70 // These variables control the two-step configure-start process for QTKit HD:
71 // the device is first started with no configuration and the captured frames
72 // are inspected to check if the camera really supports HD. AVFoundation does
73 // not need this process so |final_resolution_selected_| is false then.
74 bool final_resolution_selected_
;
75 bool tried_to_square_pixels_
;
77 // Only read and write state_ from inside this loop.
78 const scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
81 id
<PlatformVideoCapturingMac
> capture_device_
;
83 // Used with Bind and PostTask to ensure that methods aren't called after the
84 // VideoCaptureDeviceMac is destroyed.
85 // NOTE: Weak pointers must be invalidated before all other member variables.
86 base::WeakPtrFactory
<VideoCaptureDeviceMac
> weak_factory_
;
88 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceMac
);
93 #endif // MEDIA_VIDEO_CAPTURE_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_