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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/single_thread_task_runner.h" |
12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
13 #include "media/capture/video/linux/v4l2_capture_delegate.h" | 14 #include "media/capture/video/linux/v4l2_capture_delegate.h" |
14 | 15 |
15 #if defined(OS_OPENBSD) | 16 #if defined(OS_OPENBSD) |
16 #include <sys/videoio.h> | 17 #include <sys/videoio.h> |
17 #else | 18 #else |
18 #include <linux/videodev2.h> | 19 #include <linux/videodev2.h> |
19 #endif | 20 #endif |
20 | 21 |
21 namespace media { | 22 namespace media { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 v4l2_thread_.Start(); | 56 v4l2_thread_.Start(); |
56 | 57 |
57 const int line_frequency = | 58 const int line_frequency = |
58 TranslatePowerLineFrequencyToV4L2(GetPowerLineFrequency(params)); | 59 TranslatePowerLineFrequencyToV4L2(GetPowerLineFrequency(params)); |
59 capture_impl_ = new V4L2CaptureDelegate( | 60 capture_impl_ = new V4L2CaptureDelegate( |
60 device_descriptor_, v4l2_thread_.task_runner(), line_frequency); | 61 device_descriptor_, v4l2_thread_.task_runner(), line_frequency); |
61 if (!capture_impl_) { | 62 if (!capture_impl_) { |
62 client->OnError(FROM_HERE, "Failed to create VideoCaptureDelegate"); | 63 client->OnError(FROM_HERE, "Failed to create VideoCaptureDelegate"); |
63 return; | 64 return; |
64 } | 65 } |
65 v4l2_thread_.message_loop()->PostTask( | 66 v4l2_thread_.task_runner()->PostTask( |
66 FROM_HERE, | 67 FROM_HERE, |
67 base::Bind(&V4L2CaptureDelegate::AllocateAndStart, capture_impl_, | 68 base::Bind(&V4L2CaptureDelegate::AllocateAndStart, capture_impl_, |
68 params.requested_format.frame_size.width(), | 69 params.requested_format.frame_size.width(), |
69 params.requested_format.frame_size.height(), | 70 params.requested_format.frame_size.height(), |
70 params.requested_format.frame_rate, base::Passed(&client))); | 71 params.requested_format.frame_rate, base::Passed(&client))); |
71 } | 72 } |
72 | 73 |
73 void VideoCaptureDeviceLinux::StopAndDeAllocate() { | 74 void VideoCaptureDeviceLinux::StopAndDeAllocate() { |
74 if (!v4l2_thread_.IsRunning()) | 75 if (!v4l2_thread_.IsRunning()) |
75 return; // Wrong state. | 76 return; // Wrong state. |
76 v4l2_thread_.message_loop()->PostTask( | 77 v4l2_thread_.task_runner()->PostTask( |
77 FROM_HERE, | 78 FROM_HERE, |
78 base::Bind(&V4L2CaptureDelegate::StopAndDeAllocate, capture_impl_)); | 79 base::Bind(&V4L2CaptureDelegate::StopAndDeAllocate, capture_impl_)); |
79 v4l2_thread_.Stop(); | 80 v4l2_thread_.Stop(); |
80 | 81 |
81 capture_impl_ = NULL; | 82 capture_impl_ = NULL; |
82 } | 83 } |
83 | 84 |
84 void VideoCaptureDeviceLinux::SetRotation(int rotation) { | 85 void VideoCaptureDeviceLinux::SetRotation(int rotation) { |
85 if (v4l2_thread_.IsRunning()) { | 86 if (v4l2_thread_.IsRunning()) { |
86 v4l2_thread_.message_loop()->PostTask( | 87 v4l2_thread_.task_runner()->PostTask( |
87 FROM_HERE, | 88 FROM_HERE, |
88 base::Bind(&V4L2CaptureDelegate::SetRotation, capture_impl_, rotation)); | 89 base::Bind(&V4L2CaptureDelegate::SetRotation, capture_impl_, rotation)); |
89 } | 90 } |
90 } | 91 } |
91 | 92 |
92 // static | 93 // static |
93 int VideoCaptureDeviceLinux::TranslatePowerLineFrequencyToV4L2( | 94 int VideoCaptureDeviceLinux::TranslatePowerLineFrequencyToV4L2( |
94 PowerLineFrequency frequency) { | 95 PowerLineFrequency frequency) { |
95 switch (frequency) { | 96 switch (frequency) { |
96 case media::PowerLineFrequency::FREQUENCY_50HZ: | 97 case media::PowerLineFrequency::FREQUENCY_50HZ: |
97 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ; | 98 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ; |
98 case media::PowerLineFrequency::FREQUENCY_60HZ: | 99 case media::PowerLineFrequency::FREQUENCY_60HZ: |
99 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ; | 100 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ; |
100 default: | 101 default: |
101 // If we have no idea of the frequency, at least try and set it to AUTO. | 102 // If we have no idea of the frequency, at least try and set it to AUTO. |
102 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO; | 103 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO; |
103 } | 104 } |
104 } | 105 } |
105 | 106 |
106 } // namespace media | 107 } // namespace media |
OLD | NEW |