• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 EMULATOR_STREAM_CONFIGURATION_MAP_H_
18 #define EMULATOR_STREAM_CONFIGURATION_MAP_H_
19 
20 #include <set>
21 #include <unordered_map>
22 
23 #include "hwl_types.h"
24 #include "system/camera_metadata.h"
25 #include "utils/Timers.h"
26 
27 namespace android {
28 
29 using google_camera_hal::HalCameraMetadata;
30 
31 typedef std::pair<uint32_t, uint32_t> StreamSize;
32 typedef std::pair<android_pixel_format_t, StreamSize> StreamConfig;
33 
34 inline bool operator==(const StreamConfig& lhs, const StreamConfig& rhs) {
35   return (std::get<0>(lhs) == std::get<0>(rhs)) &&
36          (std::get<1>(lhs).first == std::get<1>(rhs).first) &&
37          (std::get<1>(lhs).second == std::get<1>(rhs).second);
38 }
39 
40 struct StreamConfigurationHash {
operatorStreamConfigurationHash41   inline std::size_t operator()(const StreamConfig& entry) const {
42     size_t result = 1;
43     size_t hashValue = 31;
44     result = hashValue * result +
45              std::hash<android_pixel_format_t>{}(std::get<0>(entry));
46     result =
47         hashValue * result + std::hash<uint32_t>{}(std::get<1>(entry).first);
48     result =
49         hashValue * result + std::hash<uint32_t>{}(std::get<1>(entry).second);
50     return result;
51   }
52 };
53 
54 class StreamConfigurationMap {
55  public:
56   StreamConfigurationMap(const HalCameraMetadata& chars);
57 
GetOutputFormats()58   const std::set<android_pixel_format_t>& GetOutputFormats() const {
59     return stream_output_formats_;
60   }
61 
GetOutputSizes(android_pixel_format_t format)62   const std::set<StreamSize>& GetOutputSizes(android_pixel_format_t format) {
63     return stream_output_size_map_[format];
64   }
65 
GetOutputMinFrameDuration(StreamConfig configuration)66   nsecs_t GetOutputMinFrameDuration(StreamConfig configuration) const {
67     auto ret = stream_min_duration_map_.find(configuration);
68     return (ret == stream_min_duration_map_.end()) ? 0 : ret->second;
69   }
70 
GetOutputStallDuration(StreamConfig configuration)71   nsecs_t GetOutputStallDuration(StreamConfig configuration) const {
72     auto ret = stream_stall_map_.find(configuration);
73     return (ret == stream_stall_map_.end()) ? 0 : ret->second;
74   }
75 
SupportsReprocessing()76   bool SupportsReprocessing() const {
77     return !stream_input_output_map_.empty();
78   }
79 
GetValidOutputFormatsForInput(android_pixel_format_t format)80   const std::set<android_pixel_format_t>& GetValidOutputFormatsForInput(
81       android_pixel_format_t format) {
82     return stream_input_output_map_[format];
83   }
84 
GetInputFormats()85   const std::set<android_pixel_format_t>& GetInputFormats() {
86     return stream_input_formats_;
87   }
88 
89  private:
90   void AppendAvailableStreamConfigurations(const camera_metadata_ro_entry& entry);
91   void AppendAvailableStreamMinDurations(const camera_metadata_ro_entry_t& entry);
92   void AppendAvailableStreamStallDurations(const camera_metadata_ro_entry& entry);
93 
94   const size_t kStreamFormatOffset = 0;
95   const size_t kStreamWidthOffset = 1;
96   const size_t kStreamHeightOffset = 2;
97   const size_t kStreamIsInputOffset = 3;
98   const size_t kStreamMinDurationOffset = 3;
99   const size_t kStreamStallDurationOffset = 3;
100   const size_t kStreamConfigurationSize = 4;
101 
102   std::set<android_pixel_format_t> stream_output_formats_;
103   std::unordered_map<android_pixel_format_t, std::set<StreamSize>>
104       stream_output_size_map_;
105   std::unordered_map<StreamConfig, nsecs_t, StreamConfigurationHash>
106       stream_stall_map_;
107   std::unordered_map<StreamConfig, nsecs_t, StreamConfigurationHash>
108       stream_min_duration_map_;
109   std::set<android_pixel_format_t> stream_input_formats_;
110   std::unordered_map<android_pixel_format_t, std::set<android_pixel_format_t>>
111       stream_input_output_map_;
112 };
113 
114 }  // namespace android
115 
116 #endif  // EMULATOR_STREAM_CONFIGURATION_MAP_H_
117