Index: webrtc/tools/run_video_analysis.py |
diff --git a/webrtc/tools/run_video_analysis.py b/webrtc/tools/run_video_analysis.py |
index 29682aa02917779742ececaca52b0662a6d80546..a60d035f70b0374fcb464357a48b47bf22f171f7 100755 |
--- a/webrtc/tools/run_video_analysis.py |
+++ b/webrtc/tools/run_video_analysis.py |
@@ -158,47 +158,67 @@ def CreateRecordingDirs(options): |
return record_paths |
-def RestartMagewellDevices(ref_video_device, test_video_device): |
- """Reset the USB ports where Magewell capture devices are connected to. |
+def FindUsbPortForV4lDevices(ref_video_device, test_video_device): |
kjellander_webrtc
2017/03/30 15:52:42
FindUsbPortForV4lDevices is a great candidate for
janssonWebRTC
2017/03/31 11:55:39
Done.
|
+ """Tries to find the usb port for ref_video_device and test_video_device. |
Tries to find the provided ref_video_device and test_video_device devices |
which use video4linux and then do a soft reset by using USB unbind and bind. |
+ |
+ Args: |
+ ref_device(string): reference recording device path. |
+ test_device(string): test recording device path |
+ |
+ Returns: |
+ usb_ports(list): USB ports(string) for the devices found. |
+ """ |
+ |
+ # Find the device location including USB and USB Bus ID's. Use the usb1 |
+ # in the path since the driver folder is a symlink which contains all the |
+ # usb device port mappings and it's the same in all usbN folders. |
kjellander_webrtc
2017/03/30 15:52:42
Maybe mention something about (at least on Ubuntu
janssonWebRTC
2017/03/31 11:55:39
Done.
|
+ v4l_device_path = '/sys/bus/usb/devices/usb1/1-1/driver/**/**/video4linux/' |
+ v4l_ref_device = glob.glob('%s%s' % (v4l_device_path, ref_video_device)) |
+ v4l_test_device = glob.glob('%s%s' % (v4l_device_path, test_video_device)) |
+ usb_ports = [] |
+ paths = [] |
+ |
+ # Split on the driver folder first since we are only interested in the |
+ # folders thereafter. |
+ ref_path = str(v4l_ref_device).split('driver')[1].split('/') |
+ test_path = str(v4l_test_device).split('driver')[1].split('/') |
+ paths.append(ref_path) |
+ paths.append(test_path) |
+ |
+ for path in paths: |
+ for usb_id in path: |
+ # Some motherboards have an additional USB controller/hub and hence why |
+ # we need to look for two different strings. |
+ # E.g "4-4.4" and "4-4". |
+ if re.match(r'^\d-\d$', usb_id) or re.match(r'^\d-\d\.\d$', usb_id): |
+ usb_ports.append(usb_id) |
+ |
+ return usb_ports |
+ |
+ |
+def RestartMagewellDevices(ref_video_device_path, test_video_device_path): |
+ """Reset the USB ports where Magewell capture devices are connected to. |
+ |
+ Performs a soft reset by using USB unbind and bind. |
This is due to Magewell capture devices have proven to be unstable after the |
first recording attempt. |
- Args : |
- ref_video_device(string): reference recording device path. |
- test_video_device(string): test recording device path |
+ Args: |
+ ref_video_device_path(string): reference recording device path. |
+ test_video_device_path(string): test recording device path |
Raises: |
MagewellError: If no magewell devices are found. |
""" |
# Get the dev/videoN device name from the command line arguments. |
- ref_magewell = ref_video_device.split('/')[2] |
- test_magewell = test_video_device.split('/')[2] |
- |
- # Find the device location including USB and USB Bus ID's. |
- device_string = '/sys/bus/usb/devices/usb*/**/**/video4linux/' |
- ref_magewell_device = glob.glob('%s%s' % (device_string, ref_magewell)) |
- test_magewell_device = glob.glob('%s%s' % (device_string, test_magewell)) |
- |
- magewell_usb_ports = [] |
- |
- # Figure out the USB bus and port ID for each device. |
- ref_magewell_path = str(ref_magewell_device).split('/') |
- for directory in ref_magewell_path: |
- # Find the folder with pattern "N-N", e.g. "4-3" or \ |
- # "[USB bus ID]-[USB port]" |
- if re.match(r'^\d-\d$', directory): |
- magewell_usb_ports.append(directory) |
- |
- test_magewell_path = str(test_magewell_device).split('/') |
- for directory in test_magewell_path: |
- # Find the folder with pattern "N-N", e.g. "4-3" or \ |
- # "[USB bus ID]-[USB port]" |
- if re.match(r'^\d-\d$', directory): |
- magewell_usb_ports.append(directory) |
+ ref_magewell_path = ref_video_device_path.split('/')[2] |
+ test_magewell_path = test_video_device_path.split('/')[2] |
+ magewell_usb_ports = FindUsbPortForV4lDevices(ref_magewell_path, |
+ test_magewell_path) |
# Abort early if no devices are found. |
if len(magewell_usb_ports) == 0: |