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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 class VideoCaptureDeviceMac : public VideoCaptureDevice { | 55 class VideoCaptureDeviceMac : public VideoCaptureDevice { |
56 public: | 56 public: |
57 explicit VideoCaptureDeviceMac(const Name& device_name); | 57 explicit VideoCaptureDeviceMac(const Name& device_name); |
58 ~VideoCaptureDeviceMac() override; | 58 ~VideoCaptureDeviceMac() override; |
59 | 59 |
60 // VideoCaptureDevice implementation. | 60 // VideoCaptureDevice implementation. |
61 void AllocateAndStart( | 61 void AllocateAndStart( |
62 const VideoCaptureParams& params, | 62 const VideoCaptureParams& params, |
63 std::unique_ptr<VideoCaptureDevice::Client> client) override; | 63 std::unique_ptr<VideoCaptureDevice::Client> client) override; |
64 void StopAndDeAllocate() override; | 64 void StopAndDeAllocate() override; |
| 65 void TakePhoto(TakePhotoCallback callback) override; |
65 | 66 |
66 bool Init(VideoCaptureDevice::Name::CaptureApiType capture_api_type); | 67 bool Init(VideoCaptureDevice::Name::CaptureApiType capture_api_type); |
67 | 68 |
68 // Called to deliver captured video frames. | 69 // Called to deliver captured video frames. It's safe to call this method |
| 70 // from any thread, including those controlled by AVFoundation. |
69 void ReceiveFrame(const uint8_t* video_frame, | 71 void ReceiveFrame(const uint8_t* video_frame, |
70 int video_frame_length, | 72 int video_frame_length, |
71 const VideoCaptureFormat& frame_format, | 73 const VideoCaptureFormat& frame_format, |
72 int aspect_numerator, | 74 int aspect_numerator, |
73 int aspect_denominator, | 75 int aspect_denominator, |
74 base::TimeDelta timestamp); | 76 base::TimeDelta timestamp); |
75 | 77 |
| 78 // 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 void OnPhotoTaken(const uint8_t* image_data, |
| 81 size_t image_length, |
| 82 const std::string& mime_type); |
| 83 void OnPhotoError(); |
| 84 |
76 // Forwarder to VideoCaptureDevice::Client::OnError(). | 85 // Forwarder to VideoCaptureDevice::Client::OnError(). |
77 void ReceiveError(const tracked_objects::Location& from_here, | 86 void ReceiveError(const tracked_objects::Location& from_here, |
78 const std::string& reason); | 87 const std::string& reason); |
79 | 88 |
80 // Forwarder to VideoCaptureDevice::Client::OnLog(). | 89 // Forwarder to VideoCaptureDevice::Client::OnLog(). |
81 void LogMessage(const std::string& message); | 90 void LogMessage(const std::string& message); |
82 | 91 |
83 private: | 92 private: |
84 void SetErrorState(const tracked_objects::Location& from_here, | 93 void SetErrorState(const tracked_objects::Location& from_here, |
85 const std::string& reason); | 94 const std::string& reason); |
86 bool UpdateCaptureResolution(); | 95 bool UpdateCaptureResolution(); |
87 | 96 |
88 // Flag indicating the internal state. | 97 // Flag indicating the internal state. |
89 enum InternalState { kNotInitialized, kIdle, kCapturing, kError }; | 98 enum InternalState { kNotInitialized, kIdle, kCapturing, kError }; |
90 | 99 |
91 Name device_name_; | 100 Name device_name_; |
92 std::unique_ptr<VideoCaptureDevice::Client> client_; | 101 std::unique_ptr<VideoCaptureDevice::Client> client_; |
93 | 102 |
94 VideoCaptureFormat capture_format_; | 103 VideoCaptureFormat capture_format_; |
95 | 104 |
96 // Only read and write state_ from inside this loop. | 105 // Only read and write state_ from inside this loop. |
97 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 106 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
98 InternalState state_; | 107 InternalState state_; |
99 | 108 |
100 base::scoped_nsobject<VideoCaptureDeviceAVFoundation> capture_device_; | 109 base::scoped_nsobject<VideoCaptureDeviceAVFoundation> capture_device_; |
101 | 110 |
| 111 // To hold on to the TakePhotoCallback while the picture is being taken. |
| 112 std::unique_ptr<TakePhotoCallback> photo_callback_; |
| 113 |
102 // Used with Bind and PostTask to ensure that methods aren't called after the | 114 // Used with Bind and PostTask to ensure that methods aren't called after the |
103 // VideoCaptureDeviceMac is destroyed. | 115 // VideoCaptureDeviceMac is destroyed. |
104 // NOTE: Weak pointers must be invalidated before all other member variables. | 116 // NOTE: Weak pointers must be invalidated before all other member variables. |
105 base::WeakPtrFactory<VideoCaptureDeviceMac> weak_factory_; | 117 base::WeakPtrFactory<VideoCaptureDeviceMac> weak_factory_; |
106 | 118 |
107 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceMac); | 119 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceMac); |
108 }; | 120 }; |
109 | 121 |
110 } // namespace media | 122 } // namespace media |
111 | 123 |
112 #endif // MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_ | 124 #endif // MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_ |
OLD | NEW |