• 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 V4L2_CAMERA_HAL_METADATA_DEFAULT_OPTION_DELEGATE_H_
18 #define V4L2_CAMERA_HAL_METADATA_DEFAULT_OPTION_DELEGATE_H_
19 
20 #include <errno.h>
21 
22 #include <map>
23 
24 #include <hardware/camera3.h>
25 
26 namespace v4l2_camera_hal {
27 
28 // A constant that can be used to identify an overall default.
29 static constexpr int OTHER_TEMPLATES = CAMERA3_TEMPLATE_COUNT;
30 
31 // DefaultingOptionDelegate provides an interface to get default options from.
32 template <typename T>
33 class DefaultOptionDelegate {
34  public:
35   // |defaults| maps template types to default values
DefaultOptionDelegate(std::map<int,T> defaults)36   DefaultOptionDelegate(std::map<int, T> defaults)
37       : defaults_(std::move(defaults)){};
~DefaultOptionDelegate()38   virtual ~DefaultOptionDelegate(){};
39 
40   // Get a default value for a template type. Returns false if no default
41   // provided.
DefaultValueForTemplate(int template_type,T * default_value)42   virtual bool DefaultValueForTemplate(int template_type, T* default_value) {
43     if (defaults_.count(template_type) > 0) {
44       // Best option is template-specific.
45       *default_value = defaults_[template_type];
46       return true;
47     } else if (defaults_.count(OTHER_TEMPLATES)) {
48       // Fall back to a general default.
49       *default_value = defaults_[OTHER_TEMPLATES];
50       return true;
51     }
52 
53     return false;
54   };
55 
56  private:
57   std::map<int, T> defaults_;
58 };
59 
60 }  // namespace v4l2_camera_hal
61 
62 #endif  // V4L2_CAMERA_HAL_METADATA_DEFAULT_OPTION_DELEGATE_H_
63