@@ -69,25 +69,23 @@ def _resolve_stable_path(self, device: str | int) -> str:
6969 CameraOpenError: If camera cannot be resolved
7070 """
7171 if isinstance (device , str ) and device .startswith ("/dev/v4l/by-id" ):
72- # Already a stable link
73- return device
72+ # Already a stable link, resolve video device
73+ device_path = os . path . realpath ( device )
7474 elif isinstance (device , str ) and device .startswith ("/dev/v4l/by-path" ):
75- # A stable link, but not the one we want, resolve to by-id
75+ # A stable link, but not the one we want, resolve video device
7676 if not os .path .exists (device ):
7777 raise CameraOpenError (f"Device path { device } does not exist" )
78- resolved_path = os .path .realpath (device )
79- video_path = resolved_path
78+ device_path = os .path .realpath (device )
8079 elif isinstance (device , int ) or (isinstance (device , str ) and device .isdigit ()):
81- # Treat as /dev/video<device>
82- dev_num = int (device )
83- video_path = f"/dev/video{ dev_num } "
80+ # Resolve video device as /dev/video<device>
81+ device_path = f"/dev/video{ int (device )} "
8482 elif isinstance (device , str ) and device .startswith ("/dev/video" ):
85- # A device node path
86- video_path = device
83+ # Already a video device
84+ device_path = device
8785 else :
8886 raise CameraOpenError (f"Unrecognized device identifier: { device } " )
8987
90- # Now map /dev/videoX to a stable link in /dev/v4l/by-id
88+ # Now map /dev/videoX to a stable link under /dev/v4l/by-id
9189 by_id_dir = "/dev/v4l/by-id/"
9290 if not os .path .exists (by_id_dir ):
9391 raise CameraOpenError (f"Directory '{ by_id_dir } ' not found." )
@@ -97,12 +95,12 @@ def _resolve_stable_path(self, device: str | int) -> str:
9795 full_path = os .path .join (by_id_dir , entry )
9896 if os .path .islink (full_path ):
9997 target = os .path .realpath (full_path )
100- if target == video_path :
98+ if target == device_path :
10199 return full_path
102100 except Exception as e :
103101 raise CameraOpenError (f"Error resolving stable link: { e } " )
104102
105- raise CameraOpenError (f"No stable link found for device { device } (resolved as { video_path } )" )
103+ raise CameraOpenError (f"No stable link found for device { device } (resolved as { device_path } )" )
106104
107105 def _resolve_name (self , stable_path : str ) -> str :
108106 """
0 commit comments