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