Chromium Code Reviews| 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 #include "media/capture/video/linux/video_capture_device_linux.h" | 5 #include "media/capture/video/linux/video_capture_device_linux.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 if (!capture_impl_) { | 62 if (!capture_impl_) { |
| 63 client->OnError(FROM_HERE, "Failed to create VideoCaptureDelegate"); | 63 client->OnError(FROM_HERE, "Failed to create VideoCaptureDelegate"); |
| 64 return; | 64 return; |
| 65 } | 65 } |
| 66 v4l2_thread_.task_runner()->PostTask( | 66 v4l2_thread_.task_runner()->PostTask( |
| 67 FROM_HERE, | 67 FROM_HERE, |
| 68 base::Bind(&V4L2CaptureDelegate::AllocateAndStart, capture_impl_, | 68 base::Bind(&V4L2CaptureDelegate::AllocateAndStart, capture_impl_, |
| 69 params.requested_format.frame_size.width(), | 69 params.requested_format.frame_size.width(), |
| 70 params.requested_format.frame_size.height(), | 70 params.requested_format.frame_size.height(), |
| 71 params.requested_format.frame_rate, base::Passed(&client))); | 71 params.requested_format.frame_rate, base::Passed(&client))); |
| 72 | |
| 73 for (const auto& request : photo_requests_queue_) | |
| 74 v4l2_thread_.task_runner()->PostTask(FROM_HERE, request); | |
| 75 photo_requests_queue_.clear(); | |
| 72 } | 76 } |
| 73 | 77 |
| 74 void VideoCaptureDeviceLinux::StopAndDeAllocate() { | 78 void VideoCaptureDeviceLinux::StopAndDeAllocate() { |
| 75 if (!v4l2_thread_.IsRunning()) | 79 if (!v4l2_thread_.IsRunning()) |
| 76 return; // Wrong state. | 80 return; // Wrong state. |
| 77 v4l2_thread_.task_runner()->PostTask( | 81 v4l2_thread_.task_runner()->PostTask( |
| 78 FROM_HERE, | 82 FROM_HERE, |
| 79 base::Bind(&V4L2CaptureDelegate::StopAndDeAllocate, capture_impl_)); | 83 base::Bind(&V4L2CaptureDelegate::StopAndDeAllocate, capture_impl_)); |
| 80 v4l2_thread_.Stop(); | 84 v4l2_thread_.Stop(); |
| 81 | 85 |
| 82 capture_impl_ = nullptr; | 86 capture_impl_ = nullptr; |
| 83 } | 87 } |
| 84 | 88 |
| 85 void VideoCaptureDeviceLinux::TakePhoto(TakePhotoCallback callback) { | 89 void VideoCaptureDeviceLinux::TakePhoto(TakePhotoCallback callback) { |
| 86 DCHECK(capture_impl_); | 90 DCHECK(capture_impl_); |
| 87 if (!v4l2_thread_.IsRunning()) | 91 auto functor = base::Bind(&V4L2CaptureDelegate::TakePhoto, capture_impl_, |
|
xianglu
2016/12/06 18:18:03
s/functor/callback/ ?
mcasas
2016/12/06 19:21:03
Yeah, but |callback| is a parameter... couldn't co
| |
| 92 base::Passed(&callback)); | |
| 93 if (!v4l2_thread_.IsRunning()) { | |
| 94 // We have to wait until we get the device AllocateAndStart()ed. | |
| 95 photo_requests_queue_.push_back(std::move(functor)); | |
| 88 return; | 96 return; |
| 89 v4l2_thread_.task_runner()->PostTask( | 97 } |
| 90 FROM_HERE, base::Bind(&V4L2CaptureDelegate::TakePhoto, capture_impl_, | 98 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor)); |
| 91 base::Passed(&callback))); | |
| 92 } | 99 } |
| 93 | 100 |
| 94 void VideoCaptureDeviceLinux::GetPhotoCapabilities( | 101 void VideoCaptureDeviceLinux::GetPhotoCapabilities( |
| 95 GetPhotoCapabilitiesCallback callback) { | 102 GetPhotoCapabilitiesCallback callback) { |
| 96 if (!v4l2_thread_.IsRunning()) | 103 auto functor = base::Bind(&V4L2CaptureDelegate::GetPhotoCapabilities, |
| 97 return; // Wrong state. | 104 capture_impl_, base::Passed(&callback)); |
| 98 v4l2_thread_.task_runner()->PostTask( | 105 if (!v4l2_thread_.IsRunning()) { |
| 99 FROM_HERE, base::Bind(&V4L2CaptureDelegate::GetPhotoCapabilities, | 106 // We have to wait until we get the device AllocateAndStart()ed. |
| 100 capture_impl_, base::Passed(&callback))); | 107 photo_requests_queue_.push_back(std::move(functor)); |
| 108 return; | |
| 109 } | |
| 110 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor)); | |
| 101 } | 111 } |
| 102 | 112 |
| 103 void VideoCaptureDeviceLinux::SetPhotoOptions( | 113 void VideoCaptureDeviceLinux::SetPhotoOptions( |
| 104 mojom::PhotoSettingsPtr settings, | 114 mojom::PhotoSettingsPtr settings, |
| 105 SetPhotoOptionsCallback callback) { | 115 SetPhotoOptionsCallback callback) { |
| 106 if (!v4l2_thread_.IsRunning()) | 116 auto functor = |
| 107 return; // Wrong state. | |
| 108 v4l2_thread_.task_runner()->PostTask( | |
| 109 FROM_HERE, | |
| 110 base::Bind(&V4L2CaptureDelegate::SetPhotoOptions, capture_impl_, | 117 base::Bind(&V4L2CaptureDelegate::SetPhotoOptions, capture_impl_, |
| 111 base::Passed(&settings), base::Passed(&callback))); | 118 base::Passed(&settings), base::Passed(&callback)); |
| 119 if (!v4l2_thread_.IsRunning()) { | |
| 120 // We have to wait until we get the device AllocateAndStart()ed. | |
| 121 photo_requests_queue_.push_back(std::move(functor)); | |
| 122 return; | |
| 123 } | |
| 124 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor)); | |
| 112 } | 125 } |
| 113 | 126 |
| 114 void VideoCaptureDeviceLinux::SetRotation(int rotation) { | 127 void VideoCaptureDeviceLinux::SetRotation(int rotation) { |
| 115 if (v4l2_thread_.IsRunning()) { | 128 if (v4l2_thread_.IsRunning()) { |
| 116 v4l2_thread_.task_runner()->PostTask( | 129 v4l2_thread_.task_runner()->PostTask( |
| 117 FROM_HERE, | 130 FROM_HERE, |
| 118 base::Bind(&V4L2CaptureDelegate::SetRotation, capture_impl_, rotation)); | 131 base::Bind(&V4L2CaptureDelegate::SetRotation, capture_impl_, rotation)); |
| 119 } | 132 } |
| 120 } | 133 } |
| 121 | 134 |
| 122 // static | 135 // static |
| 123 int VideoCaptureDeviceLinux::TranslatePowerLineFrequencyToV4L2( | 136 int VideoCaptureDeviceLinux::TranslatePowerLineFrequencyToV4L2( |
| 124 PowerLineFrequency frequency) { | 137 PowerLineFrequency frequency) { |
| 125 switch (frequency) { | 138 switch (frequency) { |
| 126 case media::PowerLineFrequency::FREQUENCY_50HZ: | 139 case media::PowerLineFrequency::FREQUENCY_50HZ: |
| 127 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ; | 140 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ; |
| 128 case media::PowerLineFrequency::FREQUENCY_60HZ: | 141 case media::PowerLineFrequency::FREQUENCY_60HZ: |
| 129 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ; | 142 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ; |
| 130 default: | 143 default: |
| 131 // If we have no idea of the frequency, at least try and set it to AUTO. | 144 // If we have no idea of the frequency, at least try and set it to AUTO. |
| 132 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO; | 145 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO; |
| 133 } | 146 } |
| 134 } | 147 } |
| 135 | 148 |
| 136 } // namespace media | 149 } // namespace media |
| OLD | NEW |