1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup MultiMedia_FrameConfig 18 * @{ 19 * 20 * @brief Defines the <b>FrameConfig</b> class for operations related to frame 21 * configurations. 22 * 23 * @since 1.0 24 * @version 1.0 25 */ 26 27 /** 28 * @file frame_config.h 29 * 30 * @brief Declares APIs of the <b>FrameConfig</b> class. 31 * 32 * 33 * @since 1.0 34 * @version 1.0 35 */ 36 37 #ifndef OHOS_FRAME_CONFIG_H 38 #define OHOS_FRAME_CONFIG_H 39 40 #include "meta_data.h" 41 #include "surface.h" 42 #include <list> 43 #include <map> 44 45 namespace OHOS { 46 namespace Media { 47 constexpr int32_t FRAME_CONFIG_PREVIEW = 0; 48 constexpr int32_t FRAME_CONFIG_RECORD = 1; 49 constexpr int32_t FRAME_CONFIG_CAPTURE = 2; 50 constexpr int32_t FRAME_CONFIG_CALLBACK = 3; 51 constexpr int32_t PRIVATE_TAG_LEN = 32; 52 53 /** 54 * @brief Provides functions to configure frames. 55 * 56 * 57 * @since 1.0 58 * @version 1.0 59 */ 60 class FrameConfig { 61 public: 62 /** 63 * @brief A constructor used to create a <b>FrameConfig</b> instance. 64 * 65 */ 66 FrameConfig() = delete; 67 /** 68 * @brief A constructor used to create a <b>FrameConfig</b> instance based on the configuration mode. 69 * 70 * @param type Indicates the frame configuration mode, which can be <b>FRAME_CONFIG_PREVIEW</b>, 71 * @<b>FRAME_CONFIG_RECORD</b>, or <b>FRAME_CONFIG_CAPTURE</b>. 72 */ 73 explicit FrameConfig(int32_t type); 74 75 /** 76 * @brief A destructor used to delete the <b>FrameConfig</b> instance. 77 * 78 */ ~FrameConfig()79 ~FrameConfig() {} 80 81 /** 82 * @brief Obtains the frame configuration type. 83 * 84 * @return Returns the frame configuration type if obtained; returns <b>-1</b> 85 * otherwise. 86 */ 87 int32_t GetFrameConfigType(); 88 89 /** 90 * @brief Obtains a list of shared memories (surface objects). 91 * 92 * @return Returns the list of shared memories if obtained; returns 93 * <b>NULL</b> otherwise. 94 * 95 */ 96 std::list<Surface *> GetSurfaces(); 97 98 /** 99 * @brief Adds a surface (an object of shared memory). 100 * 101 * @param surface Indicates the surface to add. 102 */ 103 void AddSurface(Surface &surface); 104 105 /** 106 * @brief Removes a surface (an object of shared memory). 107 * You can call this function to release the surface when your 108 * application does not need to obtain data. 109 * 110 * @param surface Indicates the surface to remove. 111 */ 112 void RemoveSurface(Surface &surface); 113 114 /** 115 * @brief Sets the common parameter. 116 * @param key Indicates the common parameter key to set. 117 * @param value Indicates the common parameter value to set. 118 */ SetParameter(uint32_t key,const T value)119 template<typename T> void SetParameter(uint32_t key, const T value) 120 { 121 SetValue(key, static_cast<const void *>(&value)); 122 } 123 124 /** 125 * @brief Obtains the value of a common parameter based on its key. For 126 * details, see {@link CAMERA_FUC_KEY}. 127 * @param key Indicates the common parameter key. 128 */ GetParameter(uint32_t key,T & value)129 template<typename T> void GetParameter(uint32_t key, T &value) 130 { 131 T *pvalue = static_cast<T *>(GetValue(key)); 132 if (pvalue != nullptr) { 133 value = *pvalue; 134 } 135 } 136 137 /** 138 * @brief set the private config value 139 * @param value Indicates the private config value. 140 * @param len Indicates the length of the private config value; 141 */ 142 void SetVendorParameter(uint8_t *value, uint32_t len); 143 144 /** 145 * @brief get the private config value 146 * @param value Indicates the private config value. 147 * @param len Indicates the length of the private config value; 148 */ 149 void GetVendorParameter(uint8_t *value, uint32_t len); 150 151 private: 152 int32_t type_; 153 std::list<Surface *> surfaceList_; 154 std::map<uint32_t, int32_t> keyMap_; 155 CameraRect crop; 156 uint8_t privateTag_[PRIVATE_TAG_LEN]; 157 void *GetValue(uint32_t key); 158 void SetValue(uint32_t key, const void *value); 159 }; 160 } // namespace Media 161 } // namespace OHOS 162 #endif // OHOS_FRAME_CONFIG_H