1# Copyright 2021 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"""Verify jpeg capture latency for both front and back primary cameras.
15"""
16
17import logging
18
19from mobly import test_runner
20
21import camera_properties_utils
22import its_base_test
23import its_session_utils
24
25JPEG_CAPTURE_S_PERFORMANCE_CLASS_THRESHOLD = 1000  # ms
26
27
28class JpegCaptureSPerfClassTest(its_base_test.ItsBaseTest):
29  """Test jpeg capture latency for S performance class as specified in CDD.
30
31  [7.5/H-1-6] MUST have camera2 JPEG capture latency < 1000ms for 1080p
32  resolution as measured by the CTS camera PerformanceTest under ITS lighting
33  conditions (3000K) for both primary cameras.
34  """
35
36  def test_jpeg_capture(self):
37    # Open camera with "with" semantics to check skip condition and load chart
38    #
39    with its_session_utils.ItsSession(
40        device_id=self.dut.serial,
41        camera_id=self.camera_id) as cam:
42
43      camera_properties_utils.skip_unless(
44          cam.is_performance_class_primary_camera())
45
46      # Load chart for scene.
47      props = cam.get_camera_properties()
48      its_session_utils.load_scene(
49          cam, props, self.scene, self.tablet, self.chart_distance)
50
51    # Create an Its session without opening the camera to test camera jpeg
52    # capture latency because the test opens camera internally
53    cam = its_session_utils.ItsSession(
54        device_id=self.dut.serial,
55        camera_id=self.camera_id)
56
57    jpeg_capture_ms = cam.measure_camera_1080p_jpeg_capture_ms()
58    if jpeg_capture_ms >= JPEG_CAPTURE_S_PERFORMANCE_CLASS_THRESHOLD:
59      raise AssertionError(f'1080p jpeg capture time: {jpeg_capture_ms} ms, '
60                           f'THRESH: '
61                           f'{JPEG_CAPTURE_S_PERFORMANCE_CLASS_THRESHOLD} ms')
62    else:
63      logging.debug('1080p jpeg capture time: %.1f ms', jpeg_capture_ms)
64
65if __name__ == '__main__':
66  test_runner.main()
67