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 |
11 import os | 11 import os |
12 import subprocess | 12 import subprocess |
13 import sys | 13 import sys |
14 import time | 14 import time |
15 import glob | 15 import glob |
16 import re | |
17 import shutil | 16 import shutil |
18 | 17 |
19 # Used to time-stamp output files and directories | 18 # Used to time-stamp output files and directories |
20 CURRENT_TIME = time.strftime("%d_%m_%Y-%H:%M:%S") | 19 CURRENT_TIME = time.strftime("%d_%m_%Y-%H:%M:%S") |
21 | 20 |
22 | 21 |
23 class Error(Exception): | 22 class Error(Exception): |
24 pass | 23 pass |
25 | 24 |
26 | 25 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 os.makedirs(test_rec_dir) | 150 os.makedirs(test_rec_dir) |
152 | 151 |
153 record_paths = { | 152 record_paths = { |
154 'ref_rec_location' : os.path.abspath(ref_rec_dir), | 153 'ref_rec_location' : os.path.abspath(ref_rec_dir), |
155 'test_rec_location' : os.path.abspath(test_rec_dir) | 154 'test_rec_location' : os.path.abspath(test_rec_dir) |
156 } | 155 } |
157 | 156 |
158 return record_paths | 157 return record_paths |
159 | 158 |
160 | 159 |
161 def RestartMagewellDevices(ref_video_device, test_video_device): | 160 def FindUsbPortForV4lDevices(ref_video_device, test_video_device): |
162 """Reset the USB ports where Magewell capture devices are connected to. | 161 """Tries to find the usb port for ref_video_device and test_video_device. |
163 | 162 |
164 Tries to find the provided ref_video_device and test_video_device devices | 163 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. | 164 which use video4linux and then do a soft reset by using USB unbind and bind. |
| 165 |
| 166 Args: |
| 167 ref_device(string): reference recording device path. |
| 168 test_device(string): test recording device path |
| 169 |
| 170 Returns: |
| 171 usb_ports(list): USB ports(string) for the devices found. |
| 172 """ |
| 173 |
| 174 # Find the device location including USB and USB Bus ID's. Use the usb1 |
| 175 # in the path since the driver folder is a symlink which contains all the |
| 176 # usb device port mappings and it's the same in all usbN folders. Tested |
| 177 # on Ubuntu 14.04. |
| 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 # Look for : separator and then use the first element in the list. |
| 194 # E.g 3-3.1:1.0 split on : and [0] becomes 3-3.1 which can be used |
| 195 # for bind/unbind. |
| 196 if ':' in usb_id: |
| 197 usb_ports.append(usb_id.split(':')[0]) |
| 198 return usb_ports |
| 199 |
| 200 |
| 201 def RestartMagewellDevices(ref_video_device_path, test_video_device_path): |
| 202 """Reset the USB ports where Magewell capture devices are connected to. |
| 203 |
| 204 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 | 205 This is due to Magewell capture devices have proven to be unstable after the |
167 first recording attempt. | 206 first recording attempt. |
168 | 207 |
169 Args : | 208 Args: |
170 ref_video_device(string): reference recording device path. | 209 ref_video_device_path(string): reference recording device path. |
171 test_video_device(string): test recording device path | 210 test_video_device_path(string): test recording device path |
172 | 211 |
173 Raises: | 212 Raises: |
174 MagewellError: If no magewell devices are found. | 213 MagewellError: If no magewell devices are found. |
175 """ | 214 """ |
176 | 215 |
177 # Get the dev/videoN device name from the command line arguments. | 216 # Get the dev/videoN device name from the command line arguments. |
178 ref_magewell = ref_video_device.split('/')[2] | 217 ref_magewell_path = ref_video_device_path.split('/')[2] |
179 test_magewell = test_video_device.split('/')[2] | 218 test_magewell_path = test_video_device_path.split('/')[2] |
180 | 219 magewell_usb_ports = FindUsbPortForV4lDevices(ref_magewell_path, |
181 # Find the device location including USB and USB Bus ID's. | 220 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 | 221 |
203 # Abort early if no devices are found. | 222 # Abort early if no devices are found. |
204 if len(magewell_usb_ports) == 0: | 223 if len(magewell_usb_ports) == 0: |
205 raise MagewellError('No magewell devices found.') | 224 raise MagewellError('No magewell devices found.') |
206 else: | 225 else: |
207 print '\nResetting USB ports where magewell devices are connected...' | 226 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 | 227 # 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). | 228 # (i.e. soft eject and insert). |
210 for usb_port in magewell_usb_ports: | 229 for usb_port in magewell_usb_ports: |
211 echo_cmd = ['echo', usb_port] | 230 echo_cmd = ['echo', usb_port] |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 if options.compare_videos_script: | 494 if options.compare_videos_script: |
476 CompareVideos(options, recording_result['cropped_ref_file'], | 495 CompareVideos(options, recording_result['cropped_ref_file'], |
477 recording_result['cropped_test_file']) | 496 recording_result['cropped_test_file']) |
478 else: | 497 else: |
479 print ('Skipping compare videos step due to compare_videos flag were not ' | 498 print ('Skipping compare videos step due to compare_videos flag were not ' |
480 'passed.') | 499 'passed.') |
481 | 500 |
482 | 501 |
483 if __name__ == '__main__': | 502 if __name__ == '__main__': |
484 sys.exit(main()) | 503 sys.exit(main()) |
OLD | NEW |