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 glob | 10 import glob |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 # usb device port mappings and it's the same in all usbN folders. Tested | 177 # usb device port mappings and it's the same in all usbN folders. Tested |
178 # on Ubuntu 14.04. | 178 # on Ubuntu 14.04. |
179 v4l_device_path = '/sys/bus/usb/devices/usb1/1-1/driver/**/**/video4linux/' | 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)) | 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)) | 181 v4l_test_device = glob.glob('%s%s' % (v4l_device_path, test_video_device)) |
182 usb_ports = [] | 182 usb_ports = [] |
183 paths = [] | 183 paths = [] |
184 | 184 |
185 # Split on the driver folder first since we are only interested in the | 185 # Split on the driver folder first since we are only interested in the |
186 # folders thereafter. | 186 # folders thereafter. |
187 ref_path = str(v4l_ref_device).split('driver')[1].split('/') | 187 try: |
188 test_path = str(v4l_test_device).split('driver')[1].split('/') | 188 ref_path = str(v4l_ref_device).split('driver')[1].split('/') |
189 paths.append(ref_path) | 189 test_path = str(v4l_test_device).split('driver')[1].split('/') |
190 paths.append(test_path) | 190 except IndexError: |
| 191 print 'Could not find one or both of the specified recording devices.' |
| 192 else: |
| 193 paths.append(ref_path) |
| 194 paths.append(test_path) |
191 | 195 |
192 for path in paths: | 196 for path in paths: |
193 for usb_id in path: | 197 for usb_id in path: |
194 # Look for : separator and then use the first element in the list. | 198 # 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 | 199 # E.g 3-3.1:1.0 split on : and [0] becomes 3-3.1 which can be used |
196 # for bind/unbind. | 200 # for bind/unbind. |
197 if ':' in usb_id: | 201 if ':' in usb_id: |
198 usb_ports.append(usb_id.split(':')[0]) | 202 usb_ports.append(usb_id.split(':')[0]) |
| 203 |
199 return usb_ports | 204 return usb_ports |
200 | 205 |
201 | 206 |
202 def RestartMagewellDevices(ref_video_device_path, test_video_device_path): | 207 def RestartMagewellDevices(ref_video_device_path, test_video_device_path): |
203 """Reset the USB ports where Magewell capture devices are connected to. | 208 """Reset the USB ports where Magewell capture devices are connected to. |
204 | 209 |
205 Performs a soft reset by using USB unbind and bind. | 210 Performs a soft reset by using USB unbind and bind. |
206 This is due to Magewell capture devices have proven to be unstable after the | 211 This is due to Magewell capture devices have proven to be unstable after the |
207 first recording attempt. | 212 first recording attempt. |
208 | 213 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 '--ffmpeg_path', options.ffmpeg, | 446 '--ffmpeg_path', options.ffmpeg, |
442 '--stats_file_ref', os.path.join(os.path.dirname(cropped_ref_file), | 447 '--stats_file_ref', os.path.join(os.path.dirname(cropped_ref_file), |
443 cropped_ref_file + '_stats.txt'), | 448 cropped_ref_file + '_stats.txt'), |
444 '--stats_file_test', os.path.join(os.path.dirname(cropped_test_file), | 449 '--stats_file_test', os.path.join(os.path.dirname(cropped_test_file), |
445 cropped_test_file + '_stats.txt'), | 450 cropped_test_file + '_stats.txt'), |
446 '--yuv_frame_height', crop_height, | 451 '--yuv_frame_height', crop_height, |
447 '--yuv_frame_width', crop_width | 452 '--yuv_frame_width', crop_width |
448 ] | 453 ] |
449 | 454 |
450 with open(result_file_name, 'w') as f: | 455 with open(result_file_name, 'w') as f: |
451 compare_video_recordings = subprocess.Popen(compare_cmd, stdout=f) | 456 try: |
452 compare_video_recordings.wait() | 457 compare_video_recordings = subprocess.check_output(compare_cmd) |
453 if compare_video_recordings.returncode != 0: | 458 f.write(compare_video_recordings) |
454 raise CompareVideosError('Failed to perform comparison.') | 459 except subprocess.CalledProcessError as error: |
455 else: | 460 raise CompareVideosError('Failed to perform comparison: %s' % error) |
456 print 'Result recorded to: ' + os.path.abspath(result_file_name) | 461 else: |
457 print 'Comparison done!' | 462 print 'Result recorded to: %s' % os.path.abspath(result_file_name) |
| 463 print 'Comparison done!' |
| 464 return compare_video_recordings |
458 | 465 |
459 | 466 |
460 def main(): | 467 def main(): |
461 """The main function. | 468 """The main function. |
462 | 469 |
463 A simple invocation is: | 470 A simple invocation is: |
464 ./run_video_analysis.py \ | 471 ./run_video_analysis.py \ |
465 --app_name AppRTCMobile \ | 472 --app_name AppRTCMobile \ |
466 --ffmpeg ./ffmpeg --ref_video_device=/dev/video0 \ | 473 --ffmpeg ./ffmpeg --ref_video_device=/dev/video0 \ |
467 --test_video_device=/dev/video1 \ | 474 --test_video_device=/dev/video1 \ |
(...skipping 26 matching lines...) Expand all Loading... |
494 if options.compare_videos_script: | 501 if options.compare_videos_script: |
495 CompareVideos(options, recording_result['cropped_ref_file'], | 502 CompareVideos(options, recording_result['cropped_ref_file'], |
496 recording_result['cropped_test_file']) | 503 recording_result['cropped_test_file']) |
497 else: | 504 else: |
498 print ('Skipping compare videos step due to compare_videos flag were not ' | 505 print ('Skipping compare videos step due to compare_videos flag were not ' |
499 'passed.') | 506 'passed.') |
500 | 507 |
501 | 508 |
502 if __name__ == '__main__': | 509 if __name__ == '__main__': |
503 sys.exit(main()) | 510 sys.exit(main()) |
OLD | NEW |