]> www.vanbest.org Git - motioneye-debian/commitdiff
use persistent video device paths rather than generic /dev/video* ones
authorCalin Crisan <ccrisan@gmail.com>
Sun, 12 Apr 2015 14:49:24 +0000 (17:49 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 12 Apr 2015 14:49:24 +0000 (17:49 +0300)
src/v4l2ctl.py

index e760efb9f250c304be4c26f86bf5af1b8ba58409..8c17bd9e4ed584071285dc4ccae64185abefcbc4 100644 (file)
@@ -17,7 +17,7 @@
 
 import fcntl
 import logging
-import os
+import os.path
 import re
 import stat
 import subprocess
@@ -28,6 +28,8 @@ _resolutions_cache = {}
 _ctrls_cache = {}
 _ctrl_values_cache = {}
 
+_DEV_V4L_BY_ID = '/dev/v4l/by-id/'
+
 
 def find_v4l2_ctl():
     try:
@@ -87,6 +89,7 @@ def list_devices():
     for line in output.split('\n'):
         if line.startswith('\t'):
             device = line.strip()
+            device = find_persistent_device(device)
             devices.append((device, name))
         
             logging.debug('found device %(name)s: %(device)s' % {
@@ -201,6 +204,21 @@ def device_present(device):
 
     except:
         return False
+    
+
+def find_persistent_device(device):
+    try:
+        devs_by_id = os.listdir(_DEV_V4L_BY_ID)
+
+    except OSError:
+        return device
+    
+    for p in devs_by_id:
+        p = os.path.join(_DEV_V4L_BY_ID, p)
+        if os.path.realpath(p) == device:
+            return p
+    
+    return device
 
 
 def get_brightness(device):