blob: 565118d682ad8d25c557bd53cf572a99083507ee [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#include "common.h"
25#include "metadata/metadata_reader.h"
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -070026#include "metadata/types.h"
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -070027
28namespace default_camera_hal {
29
30// StaticProperties provides a wrapper around useful static metadata entries.
31class StaticProperties {
32 public:
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -070033 // Helpful types for interpreting some static properties.
34 struct StreamCapabilities {
35 int64_t stall_duration;
36 int32_t input_supported;
37 int32_t output_supported;
38 // Default constructor ensures no support
39 // and an invalid stall duration.
40 StreamCapabilities()
41 : stall_duration(-1), input_supported(0), output_supported(0) {}
42 };
43 // Map stream spec (format, size) to their
44 // capabilities (input, output, stall).
45 typedef std::map<StreamSpec, StreamCapabilities, StreamSpec::Compare>
46 CapabilitiesMap;
47
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -070048 // Use this method to create StaticProperties objects.
49 // Functionally equivalent to "new StaticProperties",
50 // except that it may return nullptr in case of failure (missing entries).
51 static StaticProperties* NewStaticProperties(
52 std::unique_ptr<const MetadataReader> metadata_reader);
Ari Hausman-Cohene31e1f32016-11-16 15:02:07 -080053 static StaticProperties* NewStaticProperties(
54 std::unique_ptr<android::CameraMetadata> metadata) {
55 return NewStaticProperties(
56 std::make_unique<MetadataReader>(std::move(metadata)));
57 }
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -070058 virtual ~StaticProperties(){};
59
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -070060 // Simple accessors.
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -070061 int facing() const { return facing_; };
62 int orientation() const { return orientation_; };
63 // Carrying on the promise of the underlying reader,
64 // the returned pointer is valid only as long as this object is alive.
65 const camera_metadata_t* raw_metadata() const {
66 return metadata_reader_->raw_metadata();
67 };
68
Ari Hausman-Cohene31e1f32016-11-16 15:02:07 -080069 // Check if a given template type is supported.
70 bool TemplateSupported(int type);
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -070071 // Validators (check that values are consistent with the capabilities
72 // this object represents/base requirements of the camera HAL).
73 bool StreamConfigurationSupported(
74 const camera3_stream_configuration_t* stream_config);
75 // Check that the inputs and outputs for a request don't conflict.
76 bool ReprocessingSupported(
77 const camera3_stream_t* input_stream,
78 const std::set<const camera3_stream_t*>& output_streams);
79
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -070080 private:
81 // Constructor private to allow failing on bad input.
82 // Use NewStaticProperties instead.
83 StaticProperties(std::unique_ptr<const MetadataReader> metadata_reader,
84 int facing,
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -070085 int orientation,
86 int32_t max_input_streams,
87 int32_t max_raw_output_streams,
88 int32_t max_non_stalling_output_streams,
89 int32_t max_stalling_output_streams,
Ari Hausman-Cohene31e1f32016-11-16 15:02:07 -080090 std::set<uint8_t> request_capabilities,
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -070091 CapabilitiesMap stream_capabilities,
92 ReprocessFormatMap supported_reprocess_outputs);
93
94 // Helper functions for StreamConfigurationSupported.
95 bool SanityCheckStreamConfiguration(
96 const camera3_stream_configuration_t* stream_config);
97 bool InputStreamsSupported(
98 const camera3_stream_configuration_t* stream_config);
99 bool OutputStreamsSupported(
100 const camera3_stream_configuration_t* stream_config);
101 bool OperationModeSupported(
102 const camera3_stream_configuration_t* stream_config);
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -0700103
104 const std::unique_ptr<const MetadataReader> metadata_reader_;
105 const int facing_;
106 const int orientation_;
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -0700107 const int32_t max_input_streams_;
108 const int32_t max_raw_output_streams_;
109 const int32_t max_non_stalling_output_streams_;
110 const int32_t max_stalling_output_streams_;
Ari Hausman-Cohene31e1f32016-11-16 15:02:07 -0800111 const std::set<uint8_t> request_capabilities_;
Ari Hausman-Cohenffb9b722016-09-09 12:06:26 -0700112 const CapabilitiesMap stream_capabilities_;
113 const ReprocessFormatMap supported_reprocess_outputs_;
Ari Hausman-Cohenf45f8d42016-09-07 15:35:53 -0700114
115 DISALLOW_COPY_AND_ASSIGN(StaticProperties);
116};
117
118} // namespace default_camera_hal
119
120#endif // DEFAULT_CAMERA_HAL_STATIC_PROPERTIES_H_