|
7 | 7 | # in the file PATENTS. All contributing project authors may
|
8 | 8 | # be found in the AUTHORS file in the root of the source tree.
|
9 | 9 |
|
| 10 | +import glob |
10 | 11 | import optparse
|
11 | 12 | import os
|
| 13 | +import shutil |
12 | 14 | import subprocess
|
13 | 15 | import sys
|
14 | 16 | import time
|
15 |
| -import glob |
16 |
| -import re |
17 |
| -import shutil |
| 17 | + |
18 | 18 |
|
19 | 19 | # Used to time-stamp output files and directories
|
20 | 20 | CURRENT_TIME = time.strftime("%d_%m_%Y-%H:%M:%S")
|
@@ -158,47 +158,67 @@ def CreateRecordingDirs(options):
|
158 | 158 | return record_paths
|
159 | 159 |
|
160 | 160 |
|
161 |
| -def RestartMagewellDevices(ref_video_device, test_video_device): |
162 |
| - """Reset the USB ports where Magewell capture devices are connected to. |
| 161 | +def FindUsbPortForV4lDevices(ref_video_device, test_video_device): |
| 162 | + """Tries to find the usb port for ref_video_device and test_video_device. |
163 | 163 |
|
164 | 164 | Tries to find the provided ref_video_device and test_video_device devices
|
165 | 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. Tested |
| 178 | + # on Ubuntu 14.04. |
| 179 | + v4l_device_path = '/sys/bus/usb/devices/usb1/1-1/driver/**/**/video4linux/' |
| 180 | + v4l_ref_device = glob.glob('%s%s' % (v4l_device_path, ref_video_device)) |
| 181 | + v4l_test_device = glob.glob('%s%s' % (v4l_device_path, test_video_device)) |
| 182 | + usb_ports = [] |
| 183 | + paths = [] |
| 184 | + |
| 185 | + # Split on the driver folder first since we are only interested in the |
| 186 | + # folders thereafter. |
| 187 | + ref_path = str(v4l_ref_device).split('driver')[1].split('/') |
| 188 | + test_path = str(v4l_test_device).split('driver')[1].split('/') |
| 189 | + paths.append(ref_path) |
| 190 | + paths.append(test_path) |
| 191 | + |
| 192 | + for path in paths: |
| 193 | + for usb_id in path: |
| 194 | + # Look for : separator and then use the first element in the list. |
| 195 | + # E.g 3-3.1:1.0 split on : and [0] becomes 3-3.1 which can be used |
| 196 | + # for bind/unbind. |
| 197 | + if ':' in usb_id: |
| 198 | + usb_ports.append(usb_id.split(':')[0]) |
| 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 | 206 | This is due to Magewell capture devices have proven to be unstable after the
|
167 | 207 | first recording attempt.
|
168 | 208 |
|
169 |
| - Args : |
170 |
| - ref_video_device(string): reference recording device path. |
171 |
| - test_video_device(string): test recording device path |
| 209 | + Args: |
| 210 | + ref_video_device_path(string): reference recording device path. |
| 211 | + test_video_device_path(string): test recording device path |
172 | 212 |
|
173 | 213 | Raises:
|
174 | 214 | MagewellError: If no magewell devices are found.
|
175 | 215 | """
|
176 | 216 |
|
177 | 217 | # Get the dev/videoN device name from the command line arguments.
|
178 |
| - ref_magewell = ref_video_device.split('/')[2] |
179 |
| - test_magewell = test_video_device.split('/')[2] |
180 |
| - |
181 |
| - # Find the device location including USB and USB Bus ID's. |
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) |
| 218 | + ref_magewell_path = ref_video_device_path.split('/')[2] |
| 219 | + test_magewell_path = test_video_device_path.split('/')[2] |
| 220 | + magewell_usb_ports = FindUsbPortForV4lDevices(ref_magewell_path, |
| 221 | + test_magewell_path) |
202 | 222 |
|
203 | 223 | # Abort early if no devices are found.
|
204 | 224 | if len(magewell_usb_ports) == 0:
|
@@ -413,7 +433,6 @@ def CompareVideos(options, cropped_ref_file, cropped_test_file):
|
413 | 433 | crop_height = param.split(':')[1]
|
414 | 434 |
|
415 | 435 | compare_cmd = [
|
416 |
| - sys.executable, |
417 | 436 | compare_videos_script,
|
418 | 437 | '--ref_video', cropped_ref_file,
|
419 | 438 | '--test_video', cropped_test_file,
|
|
0 commit comments