1# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import glob, os
6from autotest_lib.client.cros.video import device_capability
7
8def find_cameras():
9    """
10    Find V4L camera devices
11
12    @return [device list]. If no camera is found, returns empty list.
13    """
14    cameras = [os.path.basename(camera) for camera in
15               glob.glob('/sys/bus/usb/drivers/uvcvideo/*/video4linux/video*')]
16    if not cameras:
17        return []
18    return cameras
19
20
21def has_builtin_usb_camera():
22    """Check if there is a built-in USB camera by capability."""
23    return device_capability.DeviceCapability().have_capability('builtin_usb_camera')
24
25
26def has_builtin_or_vivid_camera():
27    """Check if there is a built-in USB camera or MIPI camera by capability."""
28    return device_capability.DeviceCapability().have_capability(
29            'builtin_or_vivid_camera')
30
31
32def get_camera_hal_paths():
33    """Return the paths of all camera HALs on device."""
34    return glob.glob('/usr/lib*/camera_hal/*.so')
35
36
37def get_camera_hal_paths_for_test():
38    """Return the paths of all camera HALs on device for test."""
39    paths = []
40    for path in get_camera_hal_paths():
41        name = os.path.basename(path)
42        # usb.so might be there for external cameras, skip it if there is no
43        # built-in USB camera.
44        if name == 'usb.so' and not has_builtin_usb_camera():
45            continue
46        paths.append(path)
47    return paths
48