blob: 25c8205798246a1887e7cb214ebe263d0b6ea257 [file] [log] [blame]
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef DEFAULT_CAMERA_HAL_STATIC_PROPERTIES_H_
18#define DEFAULT_CAMERA_HAL_STATIC_PROPERTIES_H_
19
20#include <memory>
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -070021#include <set>
22
23#include <hardware/camera3.h>
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -070024
25#include "common.h"
26#include "metadata/metadata_reader.h"
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -070027#include "metadata/types.h"
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -070028
29namespace default_camera_hal {
30
31// StaticProperties provides a wrapper around useful static metadata entries.
32class StaticProperties {
33 public:
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -070034 // Helpful types for interpreting some static properties.
35 struct StreamCapabilities {
36 int64_t stall_duration;
37 int32_t input_supported;
38 int32_t output_supported;
39 // Default constructor ensures no support
40 // and an invalid stall duration.
41 StreamCapabilities()
42 : stall_duration(-1), input_supported(0), output_supported(0) {}
43 };
44 // Map stream spec (format, size) to their
45 // capabilities (input, output, stall).
46 typedef std::map<StreamSpec, StreamCapabilities, StreamSpec::Compare>
47 CapabilitiesMap;
48
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -070049 // Use this method to create StaticProperties objects.
50 // Functionally equivalent to "new StaticProperties",
51 // except that it may return nullptr in case of failure (missing entries).
52 static StaticProperties* NewStaticProperties(
53 std::unique_ptr<const MetadataReader> metadata_reader);
Ari Hausman-Cohene31e1f32016-11-16 15:02:07 -080054 static StaticProperties* NewStaticProperties(
55 std::unique_ptr<android::CameraMetadata> metadata) {
56 return NewStaticProperties(
57 std::make_unique<MetadataReader>(std::move(metadata)));
58 }
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -070059 virtual ~StaticProperties(){};
60
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -070061 // Simple accessors.
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -070062 int facing() const { return facing_; };
63 int orientation() const { return orientation_; };
64 // Carrying on the promise of the underlying reader,
65 // the returned pointer is valid only as long as this object is alive.
66 const camera_metadata_t* raw_metadata() const {
67 return metadata_reader_->raw_metadata();
68 };
69
Ari Hausman-Cohene31e1f32016-11-16 15:02:07 -080070 // Check if a given template type is supported.
71 bool TemplateSupported(int type);
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -070072 // Validators (check that values are consistent with the capabilities
73 // this object represents/base requirements of the camera HAL).
74 bool StreamConfigurationSupported(
75 const camera3_stream_configuration_t* stream_config);
76 // Check that the inputs and outputs for a request don't conflict.
77 bool ReprocessingSupported(
78 const camera3_stream_t* input_stream,
79 const std::set<const camera3_stream_t*>& output_streams);
80
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -070081 private:
82 // Constructor private to allow failing on bad input.
83 // Use NewStaticProperties instead.
84 StaticProperties(std::unique_ptr<const MetadataReader> metadata_reader,
85 int facing,
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -070086 int orientation,
87 int32_t max_input_streams,
88 int32_t max_raw_output_streams,
89 int32_t max_non_stalling_output_streams,
90 int32_t max_stalling_output_streams,
Ari Hausman-Cohene31e1f32016-11-16 15:02:07 -080091 std::set<uint8_t> request_capabilities,
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -070092 CapabilitiesMap stream_capabilities,
93 ReprocessFormatMap supported_reprocess_outputs);
94
95 // Helper functions for StreamConfigurationSupported.
96 bool SanityCheckStreamConfiguration(
97 const camera3_stream_configuration_t* stream_config);
98 bool InputStreamsSupported(
99 const camera3_stream_configuration_t* stream_config);
100 bool OutputStreamsSupported(
101 const camera3_stream_configuration_t* stream_config);
102 bool OperationModeSupported(
103 const camera3_stream_configuration_t* stream_config);
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -0700104
105 const std::unique_ptr<const MetadataReader> metadata_reader_;
106 const int facing_;
107 const int orientation_;
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -0700108 const int32_t max_input_streams_;
109 const int32_t max_raw_output_streams_;
110 const int32_t max_non_stalling_output_streams_;
111 const int32_t max_stalling_output_streams_;
Ari Hausman-Cohene31e1f32016-11-16 15:02:07 -0800112 const std::set<uint8_t> request_capabilities_;
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -0700113 const CapabilitiesMap stream_capabilities_;
114 const ReprocessFormatMap supported_reprocess_outputs_;
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -0700115
116 DISALLOW_COPY_AND_ASSIGN(StaticProperties);
117};
118
119} // namespace default_camera_hal
120
121#endif // DEFAULT_CAMERA_HAL_STATIC_PROPERTIES_H_