• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8
9def find_camera():
10    """
11    Find a V4L camera device.
12
13    @return (device_name, device_index). If no camera is found, (None, None).
14    """
15    cameras = [os.path.basename(camera) for camera in
16               glob.glob('/sys/bus/usb/drivers/uvcvideo/*/video4linux/video*')]
17    if not cameras:
18        return None, None
19    camera = cameras[0]
20    return camera, int(camera[5:])
21
22
23def has_builtin_usb_camera():
24    """Check if there is a built-in USB camera by capability."""
25    return device_capability.DeviceCapability().have_capability('usb_camera')
26
27
28def get_camera_hal_paths():
29    """Return the paths of all camera HALs on device."""
30    return glob.glob('/usr/lib*/camera_hal/*.so')
31
32
33def get_camera_hal_paths_for_test():
34    """Return the paths of all camera HALs on device for test."""
35    paths = []
36    for path in get_camera_hal_paths():
37        name = os.path.basename(path)
38        # usb.so might be there for external cameras, skip it if there is no
39        # built-in USB camera.
40        if name == 'usb.so' and not has_builtin_usb_camera():
41            continue
42        paths.append(path)
43    return paths
44