aboutsummaryrefslogtreecommitdiff
path: root/apps/CameraITS/tests/scene1/test_ae_precapture_trigger.py
blob: 59b7db10245fc0eb10edeeefbdfb23a446d80cae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Copyright 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import its.device
import its.caps
import its.objects
import its.target

def main():
    """Test the AE state machine when using the precapture trigger.
    """

    INACTIVE = 0
    SEARCHING = 1
    CONVERGED = 2
    LOCKED = 3
    FLASHREQUIRED = 4
    PRECAPTURE = 5

    with its.device.ItsSession() as cam:
        props = cam.get_camera_properties()
        if not its.caps.compute_target_exposure(props):
            print "Test skipped"
            return

        _,fmt = its.objects.get_fastest_manual_capture_settings(props)

        # Capture 5 manual requests, with AE disabled, and the last request
        # has an AE precapture trigger (which should be ignored since AE is
        # disabled).
        manual_reqs = []
        e, s = its.target.get_target_exposure_combos(cam)["midExposureTime"]
        manual_req = its.objects.manual_capture_request(s,e)
        manual_req['android.control.aeMode'] = 0 # Off
        manual_reqs += [manual_req]*4
        precap_req = its.objects.manual_capture_request(s,e)
        precap_req['android.control.aeMode'] = 0 # Off
        precap_req['android.control.aePrecaptureTrigger'] = 1 # Start
        manual_reqs.append(precap_req)
        caps = cam.do_capture(manual_reqs, fmt)
        for cap in caps:
            assert(cap['metadata']['android.control.aeState'] == INACTIVE)

        # Capture an auto request and verify the AE state; no trigger.
        auto_req = its.objects.auto_capture_request()
        auto_req['android.control.aeMode'] = 1  # On
        cap = cam.do_capture(auto_req, fmt)
        state = cap['metadata']['android.control.aeState']
        print "AE state after auto request:", state
        assert(state in [SEARCHING, CONVERGED])

        # Capture with auto request with a precapture trigger.
        auto_req['android.control.aePrecaptureTrigger'] = 1  # Start
        cap = cam.do_capture(auto_req, fmt)
        state = cap['metadata']['android.control.aeState']
        print "AE state after auto request with precapture trigger:", state
        assert(state in [SEARCHING, CONVERGED, PRECAPTURE])

        # Capture some more auto requests, and AE should converge.
        auto_req['android.control.aePrecaptureTrigger'] = 0
        caps = cam.do_capture([auto_req]*5, fmt)
        state = caps[-1]['metadata']['android.control.aeState']
        print "AE state after auto request:", state
        assert(state == CONVERGED)

if __name__ == '__main__':
    main()