Ari Hausman-Cohen | f45f8d4 | 2016-09-07 15:35:53 -0700 | [diff] [blame] | 1 | /* |
| 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-Cohen | ffb9b72 | 2016-09-09 12:06:26 -0700 | [diff] [blame] | 21 | #include <set> |
| 22 | |
| 23 | #include <hardware/camera3.h> |
Ari Hausman-Cohen | f45f8d4 | 2016-09-07 15:35:53 -0700 | [diff] [blame] | 24 | |
| 25 | #include "common.h" |
| 26 | #include "metadata/metadata_reader.h" |
Ari Hausman-Cohen | ffb9b72 | 2016-09-09 12:06:26 -0700 | [diff] [blame] | 27 | #include "metadata/types.h" |
Ari Hausman-Cohen | f45f8d4 | 2016-09-07 15:35:53 -0700 | [diff] [blame] | 28 | |
| 29 | namespace default_camera_hal { |
| 30 | |
| 31 | // StaticProperties provides a wrapper around useful static metadata entries. |
| 32 | class StaticProperties { |
| 33 | public: |
Ari Hausman-Cohen | ffb9b72 | 2016-09-09 12:06:26 -0700 | [diff] [blame] | 34 | // 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-Cohen | f45f8d4 | 2016-09-07 15:35:53 -0700 | [diff] [blame] | 49 | // 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-Cohen | e31e1f3 | 2016-11-16 15:02:07 -0800 | [diff] [blame] | 54 | static StaticProperties* NewStaticProperties( |
| 55 | std::unique_ptr<android::CameraMetadata> metadata) { |
| 56 | return NewStaticProperties( |
| 57 | std::make_unique<MetadataReader>(std::move(metadata))); |
| 58 | } |
Ari Hausman-Cohen | f45f8d4 | 2016-09-07 15:35:53 -0700 | [diff] [blame] | 59 | virtual ~StaticProperties(){}; |
| 60 | |
Ari Hausman-Cohen | ffb9b72 | 2016-09-09 12:06:26 -0700 | [diff] [blame] | 61 | // Simple accessors. |
Ari Hausman-Cohen | f45f8d4 | 2016-09-07 15:35:53 -0700 | [diff] [blame] | 62 | 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-Cohen | e31e1f3 | 2016-11-16 15:02:07 -0800 | [diff] [blame] | 70 | // Check if a given template type is supported. |
| 71 | bool TemplateSupported(int type); |
Ari Hausman-Cohen | ffb9b72 | 2016-09-09 12:06:26 -0700 | [diff] [blame] | 72 | // 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-Cohen | f45f8d4 | 2016-09-07 15:35:53 -0700 | [diff] [blame] | 81 | 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-Cohen | ffb9b72 | 2016-09-09 12:06:26 -0700 | [diff] [blame] | 86 | 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-Cohen | e31e1f3 | 2016-11-16 15:02:07 -0800 | [diff] [blame] | 91 | std::set<uint8_t> request_capabilities, |
Ari Hausman-Cohen | ffb9b72 | 2016-09-09 12:06:26 -0700 | [diff] [blame] | 92 | 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-Cohen | f45f8d4 | 2016-09-07 15:35:53 -0700 | [diff] [blame] | 104 | |
| 105 | const std::unique_ptr<const MetadataReader> metadata_reader_; |
| 106 | const int facing_; |
| 107 | const int orientation_; |
Ari Hausman-Cohen | ffb9b72 | 2016-09-09 12:06:26 -0700 | [diff] [blame] | 108 | 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-Cohen | e31e1f3 | 2016-11-16 15:02:07 -0800 | [diff] [blame] | 112 | const std::set<uint8_t> request_capabilities_; |
Ari Hausman-Cohen | ffb9b72 | 2016-09-09 12:06:26 -0700 | [diff] [blame] | 113 | const CapabilitiesMap stream_capabilities_; |
| 114 | const ReprocessFormatMap supported_reprocess_outputs_; |
Ari Hausman-Cohen | f45f8d4 | 2016-09-07 15:35:53 -0700 | [diff] [blame] | 115 | |
| 116 | DISALLOW_COPY_AND_ASSIGN(StaticProperties); |
| 117 | }; |
| 118 | |
| 119 | } // namespace default_camera_hal |
| 120 | |
| 121 | #endif // DEFAULT_CAMERA_HAL_STATIC_PROPERTIES_H_ |