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> 21 #include <set> 22 23 #include <hardware/camera3.h> 24 #include "common.h" 25 #include "metadata/metadata_reader.h" 26 #include "metadata/types.h" 27 28 namespace default_camera_hal { 29 30 // StaticProperties provides a wrapper around useful static metadata entries. 31 class StaticProperties { 32 public: 33 // 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. StreamCapabilitiesStreamCapabilities40 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 48 // 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); NewStaticProperties(std::unique_ptr<android::CameraMetadata> metadata)53 static StaticProperties* NewStaticProperties( 54 std::unique_ptr<android::CameraMetadata> metadata) { 55 return NewStaticProperties( 56 std::make_unique<MetadataReader>(std::move(metadata))); 57 } ~StaticProperties()58 virtual ~StaticProperties(){}; 59 60 // Simple accessors. facing()61 int facing() const { return facing_; }; orientation()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. raw_metadata()65 const camera_metadata_t* raw_metadata() const { 66 return metadata_reader_->raw_metadata(); 67 }; 68 69 // Check if a given template type is supported. 70 bool TemplateSupported(int type); 71 // 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 80 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, 85 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, 90 std::set<uint8_t> request_capabilities, 91 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); 103 104 const std::unique_ptr<const MetadataReader> metadata_reader_; 105 const int facing_; 106 const int orientation_; 107 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_; 111 const std::set<uint8_t> request_capabilities_; 112 const CapabilitiesMap stream_capabilities_; 113 const ReprocessFormatMap supported_reprocess_outputs_; 114 115 DISALLOW_COPY_AND_ASSIGN(StaticProperties); 116 }; 117 118 } // namespace default_camera_hal 119 120 #endif // DEFAULT_CAMERA_HAL_STATIC_PROPERTIES_H_ 121