OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 # | 3 # |
4 # Use of this source code is governed by a BSD-style license | 4 # Use of this source code is governed by a BSD-style license |
5 # that can be found in the LICENSE file in the root of the source | 5 # that can be found in the LICENSE file in the root of the source |
6 # tree. An additional intellectual property rights grant can be found | 6 # tree. An additional intellectual property rights grant can be found |
7 # in the file PATENTS. All contributing project authors may | 7 # in the file PATENTS. All contributing project authors may |
8 # be found in the AUTHORS file in the root of the source tree. | 8 # be found in the AUTHORS file in the root of the source tree. |
9 | 9 |
10 import optparse | 10 import optparse |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 os.makedirs(test_rec_dir) | 151 os.makedirs(test_rec_dir) |
152 | 152 |
153 record_paths = { | 153 record_paths = { |
154 'ref_rec_location' : os.path.abspath(ref_rec_dir), | 154 'ref_rec_location' : os.path.abspath(ref_rec_dir), |
155 'test_rec_location' : os.path.abspath(test_rec_dir) | 155 'test_rec_location' : os.path.abspath(test_rec_dir) |
156 } | 156 } |
157 | 157 |
158 return record_paths | 158 return record_paths |
159 | 159 |
160 | 160 |
161 def RestartMagewellDevices(ref_video_device, test_video_device): | 161 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.
| |
162 """Reset the USB ports where Magewell capture devices are connected to. | 162 """Tries to find the usb port for ref_video_device and test_video_device. |
163 | 163 |
164 Tries to find the provided ref_video_device and test_video_device devices | 164 Tries to find the provided ref_video_device and test_video_device devices |
165 which use video4linux and then do a soft reset by using USB unbind and bind. | 165 which use video4linux and then do a soft reset by using USB unbind and bind. |
166 | |
167 Args: | |
168 ref_device(string): reference recording device path. | |
169 test_device(string): test recording device path | |
170 | |
171 Returns: | |
172 usb_ports(list): USB ports(string) for the devices found. | |
173 """ | |
174 | |
175 # Find the device location including USB and USB Bus ID's. Use the usb1 | |
176 # in the path since the driver folder is a symlink which contains all the | |
177 # 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.
| |
178 v4l_device_path = '/sys/bus/usb/devices/usb1/1-1/driver/**/**/video4linux/' | |
179 v4l_ref_device = glob.glob('%s%s' % (v4l_device_path, ref_video_device)) | |
180 v4l_test_device = glob.glob('%s%s' % (v4l_device_path, test_video_device)) | |
181 usb_ports = [] | |
182 paths = [] | |
183 | |
184 # Split on the driver folder first since we are only interested in the | |
185 # folders thereafter. | |
186 ref_path = str(v4l_ref_device).split('driver')[1].split('/') | |
187 test_path = str(v4l_test_device).split('driver')[1].split('/') | |
188 paths.append(ref_path) | |
189 paths.append(test_path) | |
190 | |
191 for path in paths: | |
192 for usb_id in path: | |
193 # Some motherboards have an additional USB controller/hub and hence why | |
194 # we need to look for two different strings. | |
195 # E.g "4-4.4" and "4-4". | |
196 if re.match(r'^\d-\d$', usb_id) or re.match(r'^\d-\d\.\d$', usb_id): | |
197 usb_ports.append(usb_id) | |
198 | |
199 return usb_ports | |
200 | |
201 | |
202 def RestartMagewellDevices(ref_video_device_path, test_video_device_path): | |
203 """Reset the USB ports where Magewell capture devices are connected to. | |
204 | |
205 Performs a soft reset by using USB unbind and bind. | |
166 This is due to Magewell capture devices have proven to be unstable after the | 206 This is due to Magewell capture devices have proven to be unstable after the |
167 first recording attempt. | 207 first recording attempt. |
168 | 208 |
169 Args : | 209 Args: |
170 ref_video_device(string): reference recording device path. | 210 ref_video_device_path(string): reference recording device path. |
171 test_video_device(string): test recording device path | 211 test_video_device_path(string): test recording device path |
172 | 212 |
173 Raises: | 213 Raises: |
174 MagewellError: If no magewell devices are found. | 214 MagewellError: If no magewell devices are found. |
175 """ | 215 """ |
176 | 216 |
177 # Get the dev/videoN device name from the command line arguments. | 217 # Get the dev/videoN device name from the command line arguments. |
178 ref_magewell = ref_video_device.split('/')[2] | 218 ref_magewell_path = ref_video_device_path.split('/')[2] |
179 test_magewell = test_video_device.split('/')[2] | 219 test_magewell_path = test_video_device_path.split('/')[2] |
180 | 220 magewell_usb_ports = FindUsbPortForV4lDevices(ref_magewell_path, |
181 # Find the device location including USB and USB Bus ID's. | 221 test_magewell_path) |
182 device_string = '/sys/bus/usb/devices/usb*/**/**/video4linux/' | |
183 ref_magewell_device = glob.glob('%s%s' % (device_string, ref_magewell)) | |
184 test_magewell_device = glob.glob('%s%s' % (device_string, test_magewell)) | |
185 | |
186 magewell_usb_ports = [] | |
187 | |
188 # Figure out the USB bus and port ID for each device. | |
189 ref_magewell_path = str(ref_magewell_device).split('/') | |
190 for directory in ref_magewell_path: | |
191 # Find the folder with pattern "N-N", e.g. "4-3" or \ | |
192 # "[USB bus ID]-[USB port]" | |
193 if re.match(r'^\d-\d$', directory): | |
194 magewell_usb_ports.append(directory) | |
195 | |
196 test_magewell_path = str(test_magewell_device).split('/') | |
197 for directory in test_magewell_path: | |
198 # Find the folder with pattern "N-N", e.g. "4-3" or \ | |
199 # "[USB bus ID]-[USB port]" | |
200 if re.match(r'^\d-\d$', directory): | |
201 magewell_usb_ports.append(directory) | |
202 | 222 |
203 # Abort early if no devices are found. | 223 # Abort early if no devices are found. |
204 if len(magewell_usb_ports) == 0: | 224 if len(magewell_usb_ports) == 0: |
205 raise MagewellError('No magewell devices found.') | 225 raise MagewellError('No magewell devices found.') |
206 else: | 226 else: |
207 print '\nResetting USB ports where magewell devices are connected...' | 227 print '\nResetting USB ports where magewell devices are connected...' |
208 # Use the USB bus and port ID (e.g. 4-3) to unbind and bind the USB devices | 228 # Use the USB bus and port ID (e.g. 4-3) to unbind and bind the USB devices |
209 # (i.e. soft eject and insert). | 229 # (i.e. soft eject and insert). |
210 for usb_port in magewell_usb_ports: | 230 for usb_port in magewell_usb_ports: |
211 echo_cmd = ['echo', usb_port] | 231 echo_cmd = ['echo', usb_port] |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 if options.compare_videos_script: | 495 if options.compare_videos_script: |
476 CompareVideos(options, recording_result['cropped_ref_file'], | 496 CompareVideos(options, recording_result['cropped_ref_file'], |
477 recording_result['cropped_test_file']) | 497 recording_result['cropped_test_file']) |
478 else: | 498 else: |
479 print ('Skipping compare videos step due to compare_videos flag were not ' | 499 print ('Skipping compare videos step due to compare_videos flag were not ' |
480 'passed.') | 500 'passed.') |
481 | 501 |
482 | 502 |
483 if __name__ == '__main__': | 503 if __name__ == '__main__': |
484 sys.exit(main()) | 504 sys.exit(main()) |
OLD | NEW |