1# Copyright 2014 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import its.image 16import its.device 17import its.objects 18import its.target 19import its.caps 20 21def main(): 22 """Test the validity of some metadata entries. 23 24 Looks at capture results and at the camera characteristics objects. 25 """ 26 global md, props, failed 27 28 with its.device.ItsSession() as cam: 29 # Arbitrary capture request exposure values; image content is not 30 # important for this test, only the metadata. 31 props = cam.get_camera_properties() 32 auto_req = its.objects.auto_capture_request() 33 cap = cam.do_capture(auto_req) 34 md = cap["metadata"] 35 36 print "Hardware level" 37 print " Legacy:", its.caps.legacy(props) 38 print " Limited:", its.caps.limited(props) 39 print " Full:", its.caps.full(props) 40 print "Capabilities" 41 print " Manual sensor:", its.caps.manual_sensor(props) 42 print " Manual post-proc:", its.caps.manual_post_proc(props) 43 print " Raw:", its.caps.raw(props) 44 print " Sensor fusion:", its.caps.sensor_fusion(props) 45 46 # Test: hardware level should be a valid value. 47 check('props.has_key("android.info.supportedHardwareLevel")') 48 check('props["android.info.supportedHardwareLevel"] is not None') 49 check('props["android.info.supportedHardwareLevel"] in [0,1,2]') 50 full = getval('props["android.info.supportedHardwareLevel"]') == 1 51 52 # Test: rollingShutterSkew, and frameDuration tags must all be present, 53 # and rollingShutterSkew must be greater than zero and smaller than all 54 # of the possible frame durations. 55 check('md.has_key("android.sensor.frameDuration")') 56 check('md["android.sensor.frameDuration"] is not None') 57 check('md.has_key("android.sensor.rollingShutterSkew")') 58 check('md["android.sensor.rollingShutterSkew"] is not None') 59 check('md["android.sensor.frameDuration"] > ' 60 'md["android.sensor.rollingShutterSkew"] > 0') 61 62 # Test: timestampSource must be a valid value. 63 check('props.has_key("android.sensor.info.timestampSource")') 64 check('props["android.sensor.info.timestampSource"] is not None') 65 check('props["android.sensor.info.timestampSource"] in [0,1]') 66 67 # Test: croppingType must be a valid value, and for full devices, it 68 # must be FREEFORM=1. 69 check('props.has_key("android.scaler.croppingType")') 70 check('props["android.scaler.croppingType"] is not None') 71 check('props["android.scaler.croppingType"] in [0,1]') 72 if full: 73 check('props["android.scaler.croppingType"] == 1') 74 75 assert(not failed) 76 77def getval(expr, default=None): 78 try: 79 return eval(expr) 80 except: 81 return default 82 83failed = False 84def check(expr): 85 global md, props, failed 86 try: 87 if eval(expr): 88 print "Passed>", expr 89 else: 90 print "Failed>>", expr 91 failed = True 92 except: 93 print "Failed>>", expr 94 failed = True 95 96if __name__ == '__main__': 97 main() 98 99