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 // MacOSX implementation of generic VideoCaptureDevice, using AVFoundation as | 5 // MacOSX implementation of generic VideoCaptureDevice, using AVFoundation as |
6 // native capture API. AVFoundation is available in versions 10.7 (Lion) and | 6 // native capture API. AVFoundation is available in versions 10.7 (Lion) and |
7 // later. | 7 // later. |
8 | 8 |
9 #ifndef MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_ | 9 #ifndef MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_ |
10 #define MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_ | 10 #define MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_ |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 - (NSString*)deviceName; | 47 - (NSString*)deviceName; |
48 - (int32_t)transportType; | 48 - (int32_t)transportType; |
49 @end | 49 @end |
50 | 50 |
51 namespace media { | 51 namespace media { |
52 | 52 |
53 // Called by VideoCaptureManager to open, close and start, stop Mac video | 53 // Called by VideoCaptureManager to open, close and start, stop Mac video |
54 // capture devices. | 54 // capture devices. |
55 class VideoCaptureDeviceMac : public VideoCaptureDevice { | 55 class VideoCaptureDeviceMac : public VideoCaptureDevice { |
56 public: | 56 public: |
57 explicit VideoCaptureDeviceMac(const Name& device_name); | 57 explicit VideoCaptureDeviceMac( |
| 58 const VideoCaptureDeviceDescriptor& device_descriptor); |
58 ~VideoCaptureDeviceMac() override; | 59 ~VideoCaptureDeviceMac() override; |
59 | 60 |
60 // VideoCaptureDevice implementation. | 61 // VideoCaptureDevice implementation. |
61 void AllocateAndStart( | 62 void AllocateAndStart( |
62 const VideoCaptureParams& params, | 63 const VideoCaptureParams& params, |
63 std::unique_ptr<VideoCaptureDevice::Client> client) override; | 64 std::unique_ptr<VideoCaptureDevice::Client> client) override; |
64 void StopAndDeAllocate() override; | 65 void StopAndDeAllocate() override; |
65 void TakePhoto(TakePhotoCallback callback) override; | 66 void TakePhoto(TakePhotoCallback callback) override; |
66 | 67 |
67 bool Init(VideoCaptureDevice::Name::CaptureApiType capture_api_type); | 68 bool Init(VideoCaptureApi capture_api_type); |
68 | 69 |
69 // Called to deliver captured video frames. It's safe to call this method | 70 // Called to deliver captured video frames. It's safe to call this method |
70 // from any thread, including those controlled by AVFoundation. | 71 // from any thread, including those controlled by AVFoundation. |
71 void ReceiveFrame(const uint8_t* video_frame, | 72 void ReceiveFrame(const uint8_t* video_frame, |
72 int video_frame_length, | 73 int video_frame_length, |
73 const VideoCaptureFormat& frame_format, | 74 const VideoCaptureFormat& frame_format, |
74 int aspect_numerator, | 75 int aspect_numerator, |
75 int aspect_denominator, | 76 int aspect_denominator, |
76 base::TimeDelta timestamp); | 77 base::TimeDelta timestamp); |
77 | 78 |
78 // Callbacks with the result of a still image capture, or in case of error, | 79 // Callbacks with the result of a still image capture, or in case of error, |
79 // respectively. It's safe to call these methods from any thread. | 80 // respectively. It's safe to call these methods from any thread. |
80 void OnPhotoTaken(const uint8_t* image_data, | 81 void OnPhotoTaken(const uint8_t* image_data, |
81 size_t image_length, | 82 size_t image_length, |
82 const std::string& mime_type); | 83 const std::string& mime_type); |
83 void OnPhotoError(); | 84 void OnPhotoError(); |
84 | 85 |
85 // Forwarder to VideoCaptureDevice::Client::OnError(). | 86 // Forwarder to VideoCaptureDevice::Client::OnError(). |
86 void ReceiveError(const tracked_objects::Location& from_here, | 87 void ReceiveError(const tracked_objects::Location& from_here, |
87 const std::string& reason); | 88 const std::string& reason); |
88 | 89 |
89 // Forwarder to VideoCaptureDevice::Client::OnLog(). | 90 // Forwarder to VideoCaptureDevice::Client::OnLog(). |
90 void LogMessage(const std::string& message); | 91 void LogMessage(const std::string& message); |
91 | 92 |
| 93 static std::string GetDeviceModelId(const std::string& device_id, |
| 94 VideoCaptureApi capture_api, |
| 95 VideoCaptureTransportType transport_type); |
| 96 |
92 private: | 97 private: |
93 void SetErrorState(const tracked_objects::Location& from_here, | 98 void SetErrorState(const tracked_objects::Location& from_here, |
94 const std::string& reason); | 99 const std::string& reason); |
95 bool UpdateCaptureResolution(); | 100 bool UpdateCaptureResolution(); |
96 | 101 |
97 // Flag indicating the internal state. | 102 // Flag indicating the internal state. |
98 enum InternalState { kNotInitialized, kIdle, kCapturing, kError }; | 103 enum InternalState { kNotInitialized, kIdle, kCapturing, kError }; |
99 | 104 |
100 Name device_name_; | 105 VideoCaptureDeviceDescriptor device_descriptor_; |
101 std::unique_ptr<VideoCaptureDevice::Client> client_; | 106 std::unique_ptr<VideoCaptureDevice::Client> client_; |
102 | 107 |
103 VideoCaptureFormat capture_format_; | 108 VideoCaptureFormat capture_format_; |
104 | 109 |
105 // Only read and write state_ from inside this loop. | 110 // Only read and write state_ from inside this loop. |
106 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 111 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
107 InternalState state_; | 112 InternalState state_; |
108 | 113 |
109 base::scoped_nsobject<VideoCaptureDeviceAVFoundation> capture_device_; | 114 base::scoped_nsobject<VideoCaptureDeviceAVFoundation> capture_device_; |
110 | 115 |
111 // To hold on to the TakePhotoCallback while the picture is being taken. | 116 // To hold on to the TakePhotoCallback while the picture is being taken. |
112 std::unique_ptr<TakePhotoCallback> photo_callback_; | 117 std::unique_ptr<TakePhotoCallback> photo_callback_; |
113 | 118 |
114 // Used with Bind and PostTask to ensure that methods aren't called after the | 119 // Used with Bind and PostTask to ensure that methods aren't called after the |
115 // VideoCaptureDeviceMac is destroyed. | 120 // VideoCaptureDeviceMac is destroyed. |
116 // NOTE: Weak pointers must be invalidated before all other member variables. | 121 // NOTE: Weak pointers must be invalidated before all other member variables. |
117 base::WeakPtrFactory<VideoCaptureDeviceMac> weak_factory_; | 122 base::WeakPtrFactory<VideoCaptureDeviceMac> weak_factory_; |
118 | 123 |
119 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceMac); | 124 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceMac); |
120 }; | 125 }; |
121 | 126 |
122 } // namespace media | 127 } // namespace media |
123 | 128 |
124 #endif // MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_ | 129 #endif // MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_ |
OLD | NEW |