| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // libudev is used for monitoring device changes. | 5 // libudev is used for monitoring device changes. |
| 6 | 6 |
| 7 #include "media/capture/device_monitor_udev.h" | 7 #include "device/capture/device_monitor_udev.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/system_monitor/system_monitor.h" | 14 #include "base/system_monitor/system_monitor.h" |
| 15 #include "device/udev_linux/udev.h" | 15 #include "device/udev_linux/udev.h" |
| 16 #include "device/udev_linux/udev_linux.h" | 16 #include "device/udev_linux/udev_linux.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 struct SubsystemMap { | 20 struct SubsystemMap { |
| 21 base::SystemMonitor::DeviceType device_type; | 21 base::SystemMonitor::DeviceType device_type; |
| 22 const char* subsystem; | 22 const char* subsystem; |
| 23 const char* devtype; | 23 const char* devtype; |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 const char kAudioSubsystem[] = "sound"; | 26 const char kAudioSubsystem[] = "sound"; |
| 27 const char kVideoSubsystem[] = "video4linux"; | 27 const char kVideoSubsystem[] = "video4linux"; |
| 28 | 28 |
| 29 // Add more subsystems here for monitoring. | 29 // Add more subsystems here for monitoring. |
| 30 const SubsystemMap kSubsystemMap[] = { | 30 const SubsystemMap kSubsystemMap[] = { |
| 31 {base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE, kAudioSubsystem, NULL}, | 31 {base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE, kAudioSubsystem, NULL}, |
| 32 {base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE, kVideoSubsystem, NULL}, | 32 {base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE, kVideoSubsystem, NULL}, |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 namespace media { | 37 namespace device { |
| 38 | 38 |
| 39 DeviceMonitorLinux::DeviceMonitorLinux( | 39 DeviceMonitorUdev::DeviceMonitorUdev( |
| 40 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | 40 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
| 41 : io_task_runner_(io_task_runner) { | 41 : io_task_runner_(io_task_runner) { |
| 42 io_task_runner_->PostTask( | 42 io_task_runner_->PostTask( |
| 43 FROM_HERE, | 43 FROM_HERE, |
| 44 base::Bind(&DeviceMonitorLinux::Initialize, base::Unretained(this))); | 44 base::Bind(&DeviceMonitorUdev::Initialize, base::Unretained(this))); |
| 45 } | 45 } |
| 46 | 46 |
| 47 DeviceMonitorLinux::~DeviceMonitorLinux() {} | 47 DeviceMonitorUdev::~DeviceMonitorUdev() {} |
| 48 | 48 |
| 49 void DeviceMonitorLinux::Initialize() { | 49 void DeviceMonitorUdev::Initialize() { |
| 50 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 50 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 51 | 51 |
| 52 // We want to be notified of IO message loop destruction to delete |udev_|. | 52 // We want to be notified of IO message loop destruction to delete |udev_|. |
| 53 base::MessageLoop::current()->AddDestructionObserver(this); | 53 base::MessageLoop::current()->AddDestructionObserver(this); |
| 54 | 54 |
| 55 std::vector<device::UdevLinux::UdevMonitorFilter> filters; | 55 std::vector<device::UdevLinux::UdevMonitorFilter> filters; |
| 56 for (const SubsystemMap& entry : kSubsystemMap) { | 56 for (const SubsystemMap& entry : kSubsystemMap) { |
| 57 filters.push_back( | 57 filters.push_back( |
| 58 device::UdevLinux::UdevMonitorFilter(entry.subsystem, entry.devtype)); | 58 device::UdevLinux::UdevMonitorFilter(entry.subsystem, entry.devtype)); |
| 59 } | 59 } |
| 60 udev_.reset(new device::UdevLinux( | 60 udev_.reset(new device::UdevLinux( |
| 61 filters, base::Bind(&DeviceMonitorLinux::OnDevicesChanged, | 61 filters, base::Bind(&DeviceMonitorUdev::OnDevicesChanged, |
| 62 base::Unretained(this)))); | 62 base::Unretained(this)))); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void DeviceMonitorLinux::WillDestroyCurrentMessageLoop() { | 65 void DeviceMonitorUdev::WillDestroyCurrentMessageLoop() { |
| 66 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 66 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 67 udev_.reset(); | 67 udev_.reset(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void DeviceMonitorLinux::OnDevicesChanged(udev_device* device) { | 70 void DeviceMonitorUdev::OnDevicesChanged(udev_device* device) { |
| 71 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 71 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 72 DCHECK(device); | 72 DCHECK(device); |
| 73 | 73 |
| 74 base::SystemMonitor::DeviceType device_type = | 74 base::SystemMonitor::DeviceType device_type = |
| 75 base::SystemMonitor::DEVTYPE_UNKNOWN; | 75 base::SystemMonitor::DEVTYPE_UNKNOWN; |
| 76 const std::string subsystem(device::udev_device_get_subsystem(device)); | 76 const std::string subsystem(device::udev_device_get_subsystem(device)); |
| 77 for (const SubsystemMap& entry : kSubsystemMap) { | 77 for (const SubsystemMap& entry : kSubsystemMap) { |
| 78 if (subsystem == entry.subsystem) { | 78 if (subsystem == entry.subsystem) { |
| 79 device_type = entry.device_type; | 79 device_type = entry.device_type; |
| 80 break; | 80 break; |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 DCHECK_NE(device_type, base::SystemMonitor::DEVTYPE_UNKNOWN); | 83 DCHECK_NE(device_type, base::SystemMonitor::DEVTYPE_UNKNOWN); |
| 84 | 84 |
| 85 base::SystemMonitor::Get()->ProcessDevicesChanged(device_type); | 85 base::SystemMonitor::Get()->ProcessDevicesChanged(device_type); |
| 86 } | 86 } |
| 87 | 87 |
| 88 } // namespace media | 88 } // namespace device |
| OLD | NEW |