• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Shenzhen Kaihong DID 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 #include "codec_component_config.h"
16 #include <cinttypes>
17 #include <osal_mem.h>
18 #include "codec_log_wrapper.h"
19 #include "codec_hcb_util.h"
20 
21 #define CODEC_CONFIG_NAME "media_codec_capabilities"
22 
23 namespace {
24     constexpr int32_t MASK_NUM_LIMIT = 32;
25     constexpr char NODE_VIDEO_HARDWARE_ENCODERS[] = "VideoHwEncoders";
26     constexpr char NODE_VIDEO_HARDWARE_DECODERS[] = "VideoHwDecoders";
27     constexpr char NODE_VIDEO_SOFTWARE_ENCODERS[] = "VideoSwEncoders";
28     constexpr char NODE_VIDEO_SOFTWARE_DECODERS[] = "VideoSwDecoders";
29     constexpr char NODE_AUDIO_HARDWARE_ENCODERS[] = "AudioHwEncoders";
30     constexpr char NODE_AUDIO_HARDWARE_DECODERS[] = "AudioHwDecoders";
31     constexpr char NODE_AUDIO_SOFTWARE_ENCODERS[] = "AudioSwEncoders";
32     constexpr char NODE_AUDIO_SOFTWARE_DECODERS[] = "AudioSwDecoders";
33 
34     constexpr char CODEC_CONFIG_KEY_ROLE[] = "role";
35     constexpr char CODEC_CONFIG_KEY_TYPE[] = "type";
36     constexpr char CODEC_CONFIG_KEY_NAME[] = "name";
37     constexpr char CODEC_CONFIG_KEY_SUPPORT_PROFILES[] = "supportProfiles";
38     constexpr char CODEC_CONFIG_KEY_MAX_INST[] = "maxInst";
39     constexpr char CODEC_CONFIG_KEY_IS_SOFTWARE_CODEC[] = "isSoftwareCodec";
40     constexpr char CODEC_CONFIG_KEY_PROCESS_MODE_MASK[] = "processModeMask";
41     constexpr char CODEC_CONFIG_KEY_CAPS_MASK[] = "capsMask";
42     constexpr char CODEC_CONFIG_KEY_MIN_BITRATE[] = "minBitRate";
43     constexpr char CODEC_CONFIG_KEY_MAX_BITRATE[] = "maxBitRate";
44 
45     constexpr char CODEC_CONFIG_KEY_MIN_WIDTH[] = "minWidth";
46     constexpr char CODEC_CONFIG_KEY_MIN_HEIGHT[] = "minHeight";
47     constexpr char CODEC_CONFIG_KEY_MAX_WIDTH[] = "maxWidth";
48     constexpr char CODEC_CONFIG_KEY_MAX_HEIGHT[] = "maxHeight";
49     constexpr char CODEC_CONFIG_KEY_WIDTH_ALIGNMENT[] = "widthAlignment";
50     constexpr char CODEC_CONFIG_KEY_HEIGHT_ALIGNMENT[] = "heightAlignment";
51     constexpr char CODEC_CONFIG_KEY_MIN_BLOCK_COUNT[] = "minBlockCount";
52     constexpr char CODEC_CONFIG_KEY_MAX_BLOCK_COUNT[] = "maxBlockCount";
53     constexpr char CODEC_CONFIG_KEY_MIN_BLOCKS_PER_SECOND[] = "minBlocksPerSecond";
54     constexpr char CODEC_CONFIG_KEY_MAX_BLOCKS_PER_SECOND[] = "maxBlocksPerSecond";
55     constexpr char CODEC_CONFIG_KEY_SUPPORT_PIXEL_FMTS[] = "supportPixelFmts";
56     constexpr char CODEC_CONFIG_KEY_BLOCK_SIZE_WIDTH[] = "blockSizeWidth";
57     constexpr char CODEC_CONFIG_KEY_BLOCK_SIZE_HEIGHT[] = "blockSizeHeight";
58     constexpr char CODEC_CONFIG_KEY_MIN_FRAME_RATE[] = "minFrameRate";
59     constexpr char CODEC_CONFIG_KEY_MAX_FRAME_RATE[] = "maxFrameRate";
60     constexpr char CODEC_CONFIG_KEY_BITE_RATE_MODE[] = "bitRateMode";
61     constexpr char CODEC_CONFIG_KEY_MESURED_FRAME_RATE[] = "measuredFrameRate";
62     constexpr char CODEC_CONFIG_KEY_CAN_SWAP_WIDTH_HEIGHT[] = "canSwapWidthHeight";
63 
64     constexpr char CODEC_CONFIG_KEY_IS_SUPPORT_PASSTHROUGH[] = "isSupportPassthrough";
65     constexpr char CODEC_CONFIG_KEY_IS_SUPPORT_LOW_LATENCY[] = "isSupportLowLatency";
66     constexpr char CODEC_CONFIG_KEY_IS_SUPPORT_TSVC[] = "isSupportTSVC";
67     constexpr char CODEC_CONFIG_KEY_IS_SUPPORT_LTR[] = "isSupportLTR";
68     constexpr char CODEC_CONFIG_KEY_MAX_LTR_FRAME_NUM[] = "maxLTRFrameNum";
69     constexpr char CODEC_CONFIG_KEY_IS_SUPPORT_WATERMARK[] = "isSupportWaterMark";
70     constexpr char CODEC_CONFIG_KEY_IS_SUPPORT_SEEK_WITHOUT_FLUSH[] = "isSupportSeekWithoutFlush";
71 
72     constexpr char CODEC_CONFIG_KEY_SAMPLE_FORMATS[] = "sampleFormats";
73     constexpr char CODEC_CONFIG_KEY_SAMPLE_RATE[] = "sampleRate";
74     constexpr char CODEC_CONFIG_KEY_CHANNEL_LAYOUTS[] = "channelLayouts";
75     constexpr char CODEC_CONFIG_KEY_CHANNEL_COUNT[] = "channelCount";
76 }
77 
78 using namespace OHOS::HDI::Codec::V3_0;
79 namespace OHOS {
80 namespace Codec {
81 namespace Omx {
82 CodecComponentConfig CodecComponentConfig::config_;
CodecComponentConfig()83 CodecComponentConfig::CodecComponentConfig()
84 {
85     node_.name = nullptr;
86     node_.hashValue = 0;
87     node_.attrData = nullptr;
88     node_.parent = nullptr;
89     node_.child = nullptr;
90     node_.sibling = nullptr;
91 }
92 
Init(const DeviceResourceNode & node)93 void CodecComponentConfig::Init(const DeviceResourceNode &node)
94 {
95     node_ = node;
96     const std::string codecGroupsNodeName[] = { NODE_VIDEO_HARDWARE_ENCODERS, NODE_VIDEO_HARDWARE_DECODERS,
97                                                 NODE_VIDEO_SOFTWARE_ENCODERS, NODE_VIDEO_SOFTWARE_DECODERS,
98                                                 NODE_AUDIO_HARDWARE_ENCODERS, NODE_AUDIO_HARDWARE_DECODERS,
99                                                 NODE_AUDIO_SOFTWARE_ENCODERS, NODE_AUDIO_SOFTWARE_DECODERS };
100     int count = sizeof(codecGroupsNodeName) / sizeof(std::string);
101     for (int index = 0; index < count; index++) {
102         GetGroupCapabilities(codecGroupsNodeName[index]);
103     }
104     CODEC_LOGD("Init Run....capList_.size=%{public}zu", capList_.size());
105 }
106 
CodecCompCapabilityInit()107 int32_t CodecComponentConfig::CodecCompCapabilityInit()
108 {
109     const struct DeviceResourceNode *rootNode = HdfGetHcsRootNode();
110     if (rootNode == nullptr) {
111         CODEC_LOGE("GetRootNode failed");
112         return HDF_FAILURE;
113     }
114     const struct DeviceResourceNode *codecNode = HcsGetNodeByMatchAttr(rootNode, CODEC_CONFIG_NAME);
115     if (codecNode == nullptr) {
116         CODEC_LOGE("codecNode is nullptr");
117         return HDF_FAILURE;
118     }
119     OHOS::Codec::Omx::CodecComponentConfig::GetInstance()->Init(*codecNode);
120     return HDF_SUCCESS;
121 }
122 
GetInstance()123 CodecComponentConfig *CodecComponentConfig::GetInstance()
124 {
125     return &config_;
126 }
127 
GetComponentNum(int32_t & count)128 int32_t CodecComponentConfig::GetComponentNum(int32_t &count)
129 {
130     count = static_cast<int32_t>(capList_.size());
131     CODEC_LOGD("enter, count = %{public}d", count);
132     return HDF_SUCCESS;
133 }
134 
GetComponentCapabilityList(std::vector<CodecCompCapability> & capList,int32_t count)135 int32_t CodecComponentConfig::GetComponentCapabilityList(std::vector<CodecCompCapability> &capList, int32_t count)
136 {
137     CODEC_LOGD("count[%{public}d], size[%{public}zu]", count, capList_.size());
138     if (count <= 0) {
139         CODEC_LOGE("count[%{public}d] is invalid", count);
140         return HDF_FAILURE;
141     }
142     if (count > static_cast<int32_t>(capList_.size())) {
143         CODEC_LOGW("count[%{public}d] is too large", count);
144         count = static_cast<int32_t>(capList_.size());
145     }
146     auto first = capList_.begin();
147     auto last = capList_.begin() + count;
148     capList.assign(first, last);
149     return HDF_SUCCESS;
150 }
151 
GetGroupCapabilities(const std::string & nodeName)152 int32_t CodecComponentConfig::GetGroupCapabilities(const std::string &nodeName)
153 {
154     bool isVideoGroup = true;
155     const struct DeviceResourceNode *codecGroupNode = nullptr;
156     struct DeviceResourceNode *childNode = nullptr;
157     struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
158     if ((iface == nullptr) || (iface->GetUint32 == nullptr) ||
159         (iface->GetBool == nullptr) || (iface->GetString == nullptr)) {
160         CODEC_LOGE(" failed, iface or its GetUint32 or GetBool or GetString is nullptr!");
161         return HDF_ERR_INVALID_PARAM;
162     }
163 
164     codecGroupNode = iface->GetChildNode(&node_, nodeName.c_str());
165     if (codecGroupNode == nullptr) {
166         CODEC_LOGE("failed to get child node: %{public}s!", nodeName.c_str());
167         return HDF_FAILURE;
168     }
169 
170     if (nodeName.find("Video") == std::string::npos) {
171         isVideoGroup = false;
172     }
173 
174     DEV_RES_NODE_FOR_EACH_CHILD_NODE(codecGroupNode, childNode)
175     {
176         CodecCompCapability cap;
177         if (GetOneCapability(*iface, *childNode, cap, isVideoGroup) != HDF_SUCCESS) {
178             CODEC_LOGE("GetOneCapability failed, role is %{public}d!", cap.role);
179         }
180         capList_.push_back(cap);
181     }
182 
183     return HDF_SUCCESS;
184 }
185 
GetOneCapability(const struct DeviceResourceIface & iface,const struct DeviceResourceNode & childNode,CodecCompCapability & cap,bool isVideoGroup)186 int32_t CodecComponentConfig::GetOneCapability(const struct DeviceResourceIface &iface,
187                                                const struct DeviceResourceNode &childNode,
188                                                CodecCompCapability &cap, bool isVideoGroup)
189 {
190     if (iface.GetUint32(&childNode, CODEC_CONFIG_KEY_ROLE, reinterpret_cast<uint32_t *>(&cap.role),
191                         MEDIA_ROLETYPE_INVALID) != HDF_SUCCESS) {
192         cap.role = MEDIA_ROLETYPE_INVALID;
193         CODEC_LOGE("failed to get mime for: %{public}s! Discarded", childNode.name);
194         return HDF_FAILURE;
195     }
196     if (iface.GetUint32(&childNode, CODEC_CONFIG_KEY_TYPE, reinterpret_cast<uint32_t *>(&cap.type), INVALID_TYPE) !=
197         HDF_SUCCESS) {
198         cap.role = MEDIA_ROLETYPE_INVALID;
199         cap.type = INVALID_TYPE;
200         CODEC_LOGE("failed to get type for: %{public}s! Discarded", childNode.name);
201         return HDF_FAILURE;
202     }
203 
204     const char *compName = nullptr;
205     if (iface.GetString(&childNode, CODEC_CONFIG_KEY_NAME, &compName, "") != HDF_SUCCESS) {
206         cap.role = MEDIA_ROLETYPE_INVALID;
207         CODEC_LOGE("get attr %{public}s err!", CODEC_CONFIG_KEY_NAME);
208         return HDF_FAILURE;
209     }
210     if (compName == nullptr || strlen(compName) == 0) {
211         cap.role = MEDIA_ROLETYPE_INVALID;
212         CODEC_LOGE("compName is nullptr or empty!");
213         return HDF_FAILURE;
214     }
215     cap.compName = compName;
216 
217     cap.isSoftwareCodec = iface.GetBool(&childNode, CODEC_CONFIG_KEY_IS_SOFTWARE_CODEC);
218     cap.canSwapWidthHeight = iface.GetBool(&childNode, CODEC_CONFIG_KEY_CAN_SWAP_WIDTH_HEIGHT);
219 
220     if (GetMiscOfCapability(iface, childNode, cap) != HDF_SUCCESS) {
221         cap.role = MEDIA_ROLETYPE_INVALID;
222         CODEC_LOGE("get misc cap  err!");
223         return HDF_FAILURE;
224     }
225     if (isVideoGroup) {
226         if (GetVideoPortCapability(iface, childNode, cap) != HDF_SUCCESS) {
227             cap.role = MEDIA_ROLETYPE_INVALID;
228             CODEC_LOGE("get video port cap  err!");
229             return HDF_FAILURE;
230         }
231     } else {
232         if (GetAudioPortCapability(iface, childNode, cap) != HDF_SUCCESS) {
233             cap.role = MEDIA_ROLETYPE_INVALID;
234             CODEC_LOGE("get audio port cap  err!");
235             return HDF_FAILURE;
236         }
237     }
238 
239     return HDF_SUCCESS;
240 }
241 
GetMiscOfCapability(const struct DeviceResourceIface & iface,const struct DeviceResourceNode & childNode,CodecCompCapability & cap)242 int32_t CodecComponentConfig::GetMiscOfCapability(const struct DeviceResourceIface &iface,
243                                                   const struct DeviceResourceNode &childNode, CodecCompCapability &cap)
244 {
245     ConfigUintArrayNodeAttr attr = {CODEC_CONFIG_KEY_SUPPORT_PROFILES, cap.supportProfiles};
246     if (GetUintTableConfig(iface, childNode, attr) != HDF_SUCCESS) {
247         CODEC_LOGE("get uint table config [%{public}s] err!", attr.attrName.c_str());
248         return HDF_FAILURE;
249     }
250 
251     if (iface.GetUint32(&childNode, CODEC_CONFIG_KEY_MAX_INST, reinterpret_cast<uint32_t *>(&cap.maxInst), 0) !=
252         HDF_SUCCESS) {
253         CODEC_LOGE("get uint32 config [%{public}s] err!", attr.attrName.c_str());
254         return HDF_FAILURE;
255     }
256     if (GetMaskedConfig(iface, childNode, CODEC_CONFIG_KEY_PROCESS_MODE_MASK,
257                         reinterpret_cast<uint32_t &>(cap.processModeMask)) != HDF_SUCCESS) {
258         CODEC_LOGE("get masked config [%{public}s] err!", attr.attrName.c_str());
259         return HDF_FAILURE;
260     }
261     if (GetMaskedConfig(iface, childNode, CODEC_CONFIG_KEY_CAPS_MASK, static_cast<uint32_t &>(cap.capsMask)) !=
262         HDF_SUCCESS) {
263         CODEC_LOGE("get masked config [%{public}s] err!", attr.attrName.c_str());
264         return HDF_FAILURE;
265     }
266     if (iface.GetUint32(&childNode, CODEC_CONFIG_KEY_MIN_BITRATE, reinterpret_cast<uint32_t *>(&cap.bitRate.min), 0) !=
267         HDF_SUCCESS) {
268         CODEC_LOGE("get uin32 config [%{public}s] err!", attr.attrName.c_str());
269         return HDF_FAILURE;
270     }
271     if (iface.GetUint32(&childNode, CODEC_CONFIG_KEY_MAX_BITRATE, reinterpret_cast<uint32_t *>(&cap.bitRate.max), 0) !=
272         HDF_SUCCESS) {
273         CODEC_LOGE("get uin32 config [%{public}s] err!", attr.attrName.c_str());
274         return HDF_FAILURE;
275     }
276 
277     return HDF_SUCCESS;
278 }
279 
GetUintTableConfig(const struct DeviceResourceIface & iface,const struct DeviceResourceNode & node,ConfigUintArrayNodeAttr & attr)280 int32_t CodecComponentConfig::GetUintTableConfig(const struct DeviceResourceIface &iface,
281                                                  const struct DeviceResourceNode &node, ConfigUintArrayNodeAttr &attr)
282 {
283     if (attr.attrName.empty()) {
284         CODEC_LOGE("failed, invalid attr!");
285         return HDF_ERR_INVALID_PARAM;
286     }
287 
288     int32_t count = iface.GetElemNum(&node, attr.attrName.c_str());
289     if (count < 0) {
290         CODEC_LOGE("%{public}s table size: count[%{public}d] < 0!", attr.attrName.c_str(), count);
291         return HDF_FAILURE;
292     }
293     if (count > 0) {
294         std::unique_ptr<int32_t[]> array = std::make_unique<int32_t[]>(count);
295         iface.GetUint32Array(&node, attr.attrName.c_str(), reinterpret_cast<uint32_t *>(array.get()), count, 0);
296         attr.vec.assign(array.get(), array.get() + count);
297     }
298     return HDF_SUCCESS;
299 }
300 
GetMaskedConfig(const struct DeviceResourceIface & iface,const struct DeviceResourceNode & node,const std::string & attrName,uint32_t & mask)301 int32_t CodecComponentConfig::GetMaskedConfig(const struct DeviceResourceIface &iface,
302                                               const struct DeviceResourceNode &node, const std::string &attrName,
303                                               uint32_t &mask)
304 {
305     int32_t count = iface.GetElemNum(&node, attrName.c_str());
306 
307     mask = 0;
308     if (count < 0 || count > MASK_NUM_LIMIT) {
309         CODEC_LOGE("failed, count %{public}d incorrect!", count);
310         return HDF_FAILURE;
311     }
312 
313     if (count > 0) {
314         std::unique_ptr<uint32_t[]> values = std::make_unique<uint32_t[]>(count);
315         iface.GetUint32Array(&node, attrName.c_str(), values.get(), count, 0);
316         for (int32_t index = 0; index < count; index++) {
317             mask |= values[index];
318         }
319     }
320 
321     return HDF_SUCCESS;
322 }
323 
GetVideoPortCapability(const struct DeviceResourceIface & iface,const struct DeviceResourceNode & childNode,CodecCompCapability & cap)324 int32_t CodecComponentConfig::GetVideoPortCapability(const struct DeviceResourceIface &iface,
325                                                      const struct DeviceResourceNode &childNode,
326                                                      CodecCompCapability &cap)
327 {
328     ConfigUintNodeAttr nodeAttrs[] = {
329         {CODEC_CONFIG_KEY_MIN_WIDTH, cap.port.video.minSize.width, 0},
330         {CODEC_CONFIG_KEY_MIN_HEIGHT, cap.port.video.minSize.height, 0},
331         {CODEC_CONFIG_KEY_MAX_WIDTH, cap.port.video.maxSize.width, 0},
332         {CODEC_CONFIG_KEY_MAX_HEIGHT, cap.port.video.maxSize.height, 0},
333         {CODEC_CONFIG_KEY_WIDTH_ALIGNMENT, cap.port.video.whAlignment.widthAlignment, 0},
334         {CODEC_CONFIG_KEY_HEIGHT_ALIGNMENT, cap.port.video.whAlignment.heightAlignment, 0},
335         {CODEC_CONFIG_KEY_MIN_BLOCK_COUNT, cap.port.video.blockCount.min, 0},
336         {CODEC_CONFIG_KEY_MAX_BLOCK_COUNT, cap.port.video.blockCount.max, 0},
337         {CODEC_CONFIG_KEY_MIN_BLOCKS_PER_SECOND, cap.port.video.blocksPerSecond.min, 0},
338         {CODEC_CONFIG_KEY_MAX_BLOCKS_PER_SECOND, cap.port.video.blocksPerSecond.max, 0},
339         {CODEC_CONFIG_KEY_BLOCK_SIZE_WIDTH, cap.port.video.blockSize.width, 0},
340         {CODEC_CONFIG_KEY_BLOCK_SIZE_HEIGHT, cap.port.video.blockSize.height, 0},
341         {CODEC_CONFIG_KEY_MIN_FRAME_RATE, cap.port.video.frameRate.min, 0},
342         {CODEC_CONFIG_KEY_MAX_FRAME_RATE, cap.port.video.frameRate.max, 0}};
343 
344     int32_t count = sizeof(nodeAttrs) / sizeof(ConfigUintNodeAttr);
345     for (int32_t i = 0; i < count; i++) {
346         if (iface.GetUint32(&childNode, nodeAttrs[i].attrName.c_str(),
347                             reinterpret_cast<uint32_t *>(&nodeAttrs[i].value),
348                             nodeAttrs[i].defaultValue) != HDF_SUCCESS) {
349             CODEC_LOGE("failed to get %{public}s.%{public}s!", childNode.name, nodeAttrs[i].attrName.c_str());
350             return HDF_FAILURE;
351         }
352     }
353     ConfigUintArrayNodeAttr arrayAttrs[] = {
354         {CODEC_CONFIG_KEY_SUPPORT_PIXEL_FMTS, cap.port.video.supportPixFmts},
355         {CODEC_CONFIG_KEY_BITE_RATE_MODE, reinterpret_cast<std::vector<int32_t> &>(cap.port.video.bitRatemode)},
356         {CODEC_CONFIG_KEY_MESURED_FRAME_RATE, cap.port.video.measuredFrameRate}};
357 
358     count = sizeof(arrayAttrs) / sizeof(ConfigUintArrayNodeAttr);
359     for (int32_t i = 0; i < count; i++) {
360         if (GetUintTableConfig(iface, childNode, arrayAttrs[i]) != HDF_SUCCESS) {
361             CODEC_LOGE("failed to get %{public}s.%{public}s!", childNode.name, nodeAttrs[i].attrName.c_str());
362             return HDF_FAILURE;
363         }
364     }
365 
366     GetVideoPortFeature(iface, childNode, cap);
367     return HDF_SUCCESS;
368 }
369 
GetVideoPortFeature(const struct DeviceResourceIface & iface,const struct DeviceResourceNode & childNode,CodecCompCapability & cap)370 void CodecComponentConfig::GetVideoPortFeature(const struct DeviceResourceIface &iface,
371                                                const struct DeviceResourceNode &childNode,
372                                                CodecCompCapability &cap)
373 {
374     cap.port.video.isSupportPassthrough = iface.GetBool(&childNode, CODEC_CONFIG_KEY_IS_SUPPORT_PASSTHROUGH);
375     cap.port.video.isSupportLowLatency = iface.GetBool(&childNode, CODEC_CONFIG_KEY_IS_SUPPORT_LOW_LATENCY);
376     cap.port.video.isSupportTSVC = iface.GetBool(&childNode, CODEC_CONFIG_KEY_IS_SUPPORT_TSVC);
377     cap.port.video.isSupportLTR = iface.GetBool(&childNode, CODEC_CONFIG_KEY_IS_SUPPORT_LTR);
378     if (cap.port.video.isSupportLTR) {
379         if (iface.GetUint32(&childNode, CODEC_CONFIG_KEY_MAX_LTR_FRAME_NUM,
380                             reinterpret_cast<uint32_t *>(&cap.port.video.maxLTRFrameNum), 0) != HDF_SUCCESS) {
381             CODEC_LOGE("failed to get %{public}s maxLTRFrameNum!", childNode.name);
382         }
383     }
384     cap.port.video.isSupportWaterMark = iface.GetBool(&childNode, CODEC_CONFIG_KEY_IS_SUPPORT_WATERMARK);
385     cap.port.video.isSupportSeekWithoutFlush = iface.GetBool(&childNode,
386         CODEC_CONFIG_KEY_IS_SUPPORT_SEEK_WITHOUT_FLUSH);
387 }
388 
GetAudioPortCapability(const struct DeviceResourceIface & iface,const struct DeviceResourceNode & childNode,CodecCompCapability & cap)389 int32_t CodecComponentConfig::GetAudioPortCapability(const struct DeviceResourceIface &iface,
390                                                      const struct DeviceResourceNode &childNode,
391                                                      CodecCompCapability &cap)
392 {
393     ConfigUintArrayNodeAttr arrayAttrs[] = {{CODEC_CONFIG_KEY_SAMPLE_FORMATS, cap.port.audio.sampleFormats},
394                                             {CODEC_CONFIG_KEY_SAMPLE_RATE, cap.port.audio.sampleRate},
395                                             {CODEC_CONFIG_KEY_CHANNEL_LAYOUTS, cap.port.audio.channelLayouts},
396                                             {CODEC_CONFIG_KEY_CHANNEL_COUNT, cap.port.audio.channelCount}};
397 
398     int32_t count = sizeof(arrayAttrs) / sizeof(ConfigUintArrayNodeAttr);
399     for (int32_t i = 0; i < count; i++) {
400         if (GetUintTableConfig(iface, childNode, arrayAttrs[i]) != HDF_SUCCESS) {
401             CODEC_LOGE("failed to get %{public}s.%{public}s!", childNode.name, arrayAttrs[i].attrName.c_str());
402             return HDF_FAILURE;
403         }
404     }
405 
406     return HDF_SUCCESS;
407 }
408 }  // namespace Omx
409 }  // namespace Codec
410 }  // namespace OHOS
411