1 /*
2 * Copyright (C) 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 #include "avcodec_xml_parser.h"
16 #include "media_errors.h"
17 #include "media_log.h"
18 #include "string_ex.h"
19
20 namespace {
21 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVCodecXmlParser"};
22 constexpr int32_t PAIR_LENGTH = 2;
23 }
24
25 namespace OHOS {
26 namespace Media {
27 const std::unordered_map<std::string, int> VIDEO_PROFILE_MAP = {
28 // H263
29 {"H263BackwardCompatible", H263_PROFILE_BACKWARD_COMPATIBLE},
30 {"H263Baseline", H263_PROFILE_BASELINE},
31 {"H263H320Coding", H263_PROFILE_H320_CODING},
32 {"H263HighCompression", H263_PROFILE_HIGH_COMPRESSION},
33 {"H263HighLatency", H263_PROFILE_HIGH_LATENCY},
34 {"H263ISWV2", H263_PROFILE_ISW_V2},
35 {"H263ISWV3", H263_PROFILE_ISW_V3},
36 {"H263Interlace", H263_PROFILE_INTERLACE},
37 {"H263Internet", H263_PROFILE_INTERNET},
38 // H264
39 {"AVCBaseline", AVC_PROFILE_BASELINE},
40 {"AVCHighCompression", AVC_PROFILE_CONSTRAINED_BASELINE},
41 {"AVCConstrainedHigh", AVC_PROFILE_CONSTRAINED_HIGH},
42 {"AVCExtended", AVC_PROFILE_EXTENDED},
43 {"AVCHigh", AVC_PROFILE_HIGH},
44 {"AVCHigh10", AVC_PROFILE_HIGH_10},
45 {"AVCHigh422", AVC_PROFILE_HIGH_422},
46 {"AVCHigh444", AVC_PROFILE_HIGH_444},
47 {"AVCMain", AVC_PROFILE_MAIN},
48 // H265
49 {"HEVCMain", HEVC_PROFILE_MAIN},
50 {"HEVCMain10", HEVC_PROFILE_MAIN_10},
51 {"HEVCMainStill", HEVC_PROFILE_MAIN_STILL},
52 // MPEG2
53 {"MPEG2_422", MPEG2_PROFILE_422},
54 {"MPEG2High", MPEG2_PROFILE_HIGH},
55 {"MPEG2Main", MPEG2_PROFILE_MAIN},
56 {"MPEG2SNR", MPEG2_PROFILE_SNR},
57 {"MPEG2Simple", MPEG2_PROFILE_SIMPLE},
58 {"MPEG2Spatial", MPEG2_PROFILE_SPATIAL},
59 // MPEG4
60 {"MPEG4AdvancedCoding", MPEG4_PROFILE_ADVANCED_CODING},
61 {"MPEG4AdvancedCore", MPEG4_PROFILE_ADVANCED_CORE},
62 {"MPEG4AdvancedRealTime", MPEG4_PROFILE_ADVANCED_REAL_TIME},
63 {"MPEG4AdvancedScalable", MPEG4_PROFILE_ADVANCED_SCALABLE},
64 {"MPEG4AdvancedSimple", MPEG4_PROFILE_ADVANCED_SIMPLE},
65 {"MPEG4BasicAnimated", MPEG4_PROFILE_BASIC_ANIMATED},
66 {"MPEG4Core", MPEG4_PROFILE_CORE},
67 {"MPEG4CoreScalable", MPEG4_PROFILE_CORE_SCALABLE},
68 {"MPEG4Hybrid", MPEG4_PROFILE_HYBRID},
69 {"MPEG4Main", MPEG4_PROFILE_MAIN},
70 {"MPEG4Nbit", MPEG4_PROFILE_NBIT},
71 {"MPEG4ScalableTexture", MPEG4_PROFILE_SCALABLE_TEXTURE},
72 {"MPEG4Simple", MPEG4_PROFILE_SIMPLE},
73 {"MPEG4SimpleFBA", MPEG4_PROFILE_SIMPLE_FBA},
74 {"MPEG4SimpleFace", MPEG4_PROFILE_SIMPLE_FACE},
75 {"MPEG4SimpleScalable", MPEG4_PROFILE_SIMPLE_SCALABLE},
76 // VP8
77 {"VP8Main", VP8_PROFILE_MAIN},
78 };
79
80 const std::unordered_map<std::string, int> AUDIO_PROFILE_MAP = {
81 {"AAC_LC", AAC_PROFILE_LC},
82 {"AAC_ELD", AAC_PROFILE_ELD},
83 {"AAC_ERLC", AAC_PROFILE_ERLC},
84 {"AAC_HE", AAC_PROFILE_HE},
85 {"AAC_HE_V2", AAC_PROFILE_HE_V2},
86 {"AAC_LD", AAC_PROFILE_LD},
87 {"AAC_Main", AAC_PROFILE_MAIN},
88 };
89
90 const std::unordered_map<std::string, int> VIDEO_FORMAT_MAP = {
91 {"YUVI420", YUVI420},
92 {"NV12", NV12},
93 {"NV21", NV21},
94 };
95
96 const std::unordered_map<std::string, int> AUDIO_FORMAT_MAP = {
97 {"U8", AudioStandard::SAMPLE_U8},
98 {"S16LE", AudioStandard::SAMPLE_S16LE},
99 {"S24LE", AudioStandard::SAMPLE_S24LE},
100 {"S32LE", AudioStandard::SAMPLE_S32LE},
101 };
102
103 const std::unordered_map<std::string, int> BITRATE_MODE_MAP = {
104 {"CBR", CBR},
105 {"VBR", VBR},
106 {"CQ", CQ},
107 };
108
109 const std::unordered_map<std::string, AVCodecType> CODEC_TYPE_MAP = {
110 {"VIDEO_ENCODER", AVCODEC_TYPE_VIDEO_ENCODER},
111 {"VIDEO_DECODER", AVCODEC_TYPE_VIDEO_DECODER},
112 {"AUDIO_ENCODER", AVCODEC_TYPE_AUDIO_ENCODER},
113 {"AUDIO_DECODER", AVCODEC_TYPE_AUDIO_DECODER},
114 };
115
AVCodecXmlParser()116 AVCodecXmlParser::AVCodecXmlParser()
117 {
118 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
119 }
120
~AVCodecXmlParser()121 AVCodecXmlParser::~AVCodecXmlParser()
122 {
123 Destroy();
124 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
125 }
126
LoadConfiguration()127 bool AVCodecXmlParser::LoadConfiguration()
128 {
129 mDoc_ = xmlReadFile(AVCODEC_CONFIG_FILE, NULL, 0);
130 if (mDoc_ == NULL) {
131 MEDIA_LOGE("AVCodec xmlReadFile failed");
132 return false;
133 }
134 return true;
135 }
136
Parse()137 bool AVCodecXmlParser::Parse()
138 {
139 xmlNode *root = xmlDocGetRootElement(mDoc_);
140 if (root == NULL) {
141 MEDIA_LOGE("AVCodec xmlDocGetRootElement failed");
142 return false;
143 }
144 if (!ParseInternal(root)) {
145 return false;
146 }
147 return true;
148 }
149
150
Destroy()151 void AVCodecXmlParser::Destroy()
152 {
153 if (mDoc_ != NULL) {
154 xmlFreeDoc(mDoc_);
155 }
156 return;
157 }
158
ParseInternal(xmlNode * node)159 bool AVCodecXmlParser::ParseInternal(xmlNode *node)
160 {
161 xmlNode *currNode = node;
162 for (; currNode; currNode = currNode->next) {
163 if (XML_ELEMENT_NODE == currNode->type) {
164 switch (GetNodeNameAsInt(currNode)) {
165 case AUDIO_DECODER:
166 case AUDIO_ENCODER:
167 case VIDEO_DECODER:
168 case VIDEO_ENCODER: {
169 ParseData(currNode);
170 break;
171 }
172 default:
173 ParseInternal(currNode->children);
174 break;
175 }
176 }
177 }
178 return true;
179 }
180
TransStrAsRange(const std::string & str,Range & range)181 bool AVCodecXmlParser::TransStrAsRange(const std::string &str, Range &range)
182 {
183 if (str == "null" || str == "") {
184 MEDIA_LOGD("str is null");
185 return false;
186 }
187 size_t pos = str.find("-");
188 if (pos != str.npos) {
189 std::string head = str.substr(0, pos);
190 std::string tail = str.substr(pos + 1);
191 if (!StrToInt(head, range.minVal)) {
192 MEDIA_LOGE("call StrToInt func false, input str is: %{public}s", head.c_str());
193 return false;
194 }
195 if (!StrToInt(tail, range.maxVal)) {
196 MEDIA_LOGE("call StrToInt func false, input str is: %{public}s", tail.c_str());
197 return false;
198 }
199 } else {
200 MEDIA_LOGD("Can not find the delimiter of \"-\" in : %{public}s", str.c_str());
201 return false;
202 }
203 return true;
204 }
205
TransStrAsSize(const std::string & str,ImgSize & size)206 bool AVCodecXmlParser::TransStrAsSize(const std::string &str, ImgSize &size)
207 {
208 if (str == "null" || str == "") {
209 MEDIA_LOGD("str is null");
210 return false;
211 }
212 size_t pos = str.find("x");
213 if (pos != str.npos) {
214 std::string head = str.substr(0, pos);
215 std::string tail = str.substr(pos + 1);
216 if (!StrToInt(head, size.width)) {
217 MEDIA_LOGE("call StrToInt func false, input str is: %{public}s", head.c_str());
218 return false;
219 }
220 if (!StrToInt(tail, size.height)) {
221 MEDIA_LOGE("call StrToInt func false, input str is: %{public}s", tail.c_str());
222 return false;
223 }
224 } else {
225 MEDIA_LOGD("Can not find the delimiter of \"x\" in : %{public}s", str.c_str());
226 return false;
227 }
228 return true;
229 }
230
TransStrAsIntegerArray(std::vector<std::string> & spilt)231 std::vector<int32_t> AVCodecXmlParser::TransStrAsIntegerArray(std::vector<std::string> &spilt)
232 {
233 std::vector<int32_t> array;
234 for (auto iter = spilt.begin(); iter != spilt.end(); iter++) {
235 int32_t num = -1;
236 if (!StrToInt(*iter, num)) {
237 MEDIA_LOGE("call StrToInt func false, input str is: %{public}s", iter->c_str());
238 return array;
239 }
240 array.push_back(num);
241 }
242 return array;
243 }
244
TransMapAsIntegerArray(const std::unordered_map<std::string,int> & capabilityMap,std::vector<std::string> & spilt)245 std::vector<int32_t> AVCodecXmlParser::TransMapAsIntegerArray(
246 const std::unordered_map<std::string, int> &capabilityMap,
247 std::vector<std::string> &spilt)
248 {
249 std::vector<int32_t> res;
250 for (auto iter = spilt.begin(); iter != spilt.end(); iter++) {
251 if (capabilityMap.find(*iter) != capabilityMap.end()) {
252 res.push_back(capabilityMap.at(*iter));
253 } else {
254 MEDIA_LOGD("can not find %{public}s in capabilityMap", iter->c_str());
255 }
256 }
257 return res;
258 }
259
SpiltKeyList(const std::string & str,const std::string & delim,std::vector<std::string> & spilt)260 bool AVCodecXmlParser::SpiltKeyList(const std::string &str, const std::string &delim, std::vector<std::string> &spilt)
261 {
262 if (str == "") {
263 return false;
264 }
265 std::string strAddDelim = str;
266 if (str.back() != delim.back()) {
267 strAddDelim = str + delim;
268 }
269 size_t pos = 0;
270 size_t size = strAddDelim.size();
271 for (size_t i = 0; i < size; ++i) {
272 pos = strAddDelim.find(delim, i);
273 if (pos != strAddDelim.npos) {
274 std::string s = strAddDelim.substr(i, pos - i);
275 spilt.push_back(s);
276 i = pos + delim.size() - 1;
277 }
278 }
279 return true;
280 }
281
SetCapabilityStringData(std::unordered_map<std::string,std::string &> dataMap,const std::string & capabilityKey,const std::string & capabilityValue)282 bool AVCodecXmlParser::SetCapabilityStringData(std::unordered_map<std::string, std::string&> dataMap,
283 const std::string &capabilityKey, const std::string &capabilityValue)
284 {
285 dataMap.at(capabilityKey) = capabilityValue;
286 return true;
287 }
288
SetCapabilityIntData(std::unordered_map<std::string,int32_t &> dataMap,const std::string & capabilityKey,const std::string & capabilityValue)289 bool AVCodecXmlParser::SetCapabilityIntData(std::unordered_map<std::string, int32_t&> dataMap,
290 const std::string &capabilityKey, const std::string &capabilityValue)
291 {
292 if (CODEC_TYPE_MAP.find(capabilityValue) != CODEC_TYPE_MAP.end()) {
293 dataMap.at(capabilityKey) = CODEC_TYPE_MAP.at(capabilityValue);
294 } else {
295 MEDIA_LOGD("The value of %{public}s in the configuration file is incorrect.", capabilityValue.c_str());
296 return false;
297 }
298 return true;
299 }
300
SetCapabilityBoolData(std::unordered_map<std::string,bool &> dataMap,const std::string & capabilityKey,const std::string & capabilityValue)301 bool AVCodecXmlParser::SetCapabilityBoolData(std::unordered_map<std::string, bool&> dataMap,
302 const std::string &capabilityKey, const std::string &capabilityValue)
303 {
304 if (capabilityValue == "true") {
305 dataMap.at(capabilityKey) = true;
306 } else if (capabilityValue == "false") {
307 dataMap.at(capabilityKey) = false;
308 } else {
309 MEDIA_LOGD("The value of %{public}s in the configuration file is incorrect.", capabilityValue.c_str());
310 return false;
311 }
312 return true;
313 }
314
SetCapabilityRangeData(std::unordered_map<std::string,Range &> dataMap,const std::string & capabilityKey,const std::string & capabilityValue)315 bool AVCodecXmlParser::SetCapabilityRangeData(std::unordered_map<std::string, Range&> dataMap,
316 const std::string &capabilityKey, const std::string &capabilityValue)
317 {
318 Range range;
319 bool ret = TransStrAsRange(capabilityValue, range);
320 CHECK_AND_RETURN_RET_LOG(ret != false, false, "failed:can not trans %{public}s", capabilityValue.c_str());
321 dataMap.at(capabilityKey) = range;
322 return true;
323 }
324
SetCapabilitySizeData(std::unordered_map<std::string,ImgSize &> dataMap,const std::string & capabilityKey,const std::string & capabilityValue)325 bool AVCodecXmlParser::SetCapabilitySizeData(std::unordered_map<std::string, ImgSize&> dataMap,
326 const std::string &capabilityKey, const std::string &capabilityValue)
327 {
328 ImgSize size;
329 bool ret = TransStrAsSize(capabilityValue, size);
330 CHECK_AND_RETURN_RET_LOG(ret != false, false, "failed:can not trans %{public}s", capabilityValue.c_str());
331 dataMap.at(capabilityKey) = size;
332 return true;
333 }
334
SetCapabilityHashRangeData(std::unordered_map<std::string,std::map<ImgSize,Range> &> dataMap,const std::string & capabilityKey,const std::string & capabilityValue)335 bool AVCodecXmlParser::SetCapabilityHashRangeData(std::unordered_map<std::string, std::map<ImgSize, Range>&> dataMap,
336 const std::string &capabilityKey, const std::string &capabilityValue)
337 {
338 std::map<ImgSize, Range> resolutionFrameRateMap;
339 std::vector<std::string> spilt;
340 bool ret = SpiltKeyList(capabilityValue, ",", spilt);
341 CHECK_AND_RETURN_RET_LOG(ret != false, false, "failed:can not split %{public}s", capabilityValue.c_str());
342 for (auto iter = spilt.begin(); iter != spilt.end(); iter++) {
343 std::vector<std::string> resolutionFrameRateVector;
344 ImgSize resolution;
345 Range frameRate;
346 ret = SpiltKeyList(*iter, "@", resolutionFrameRateVector);
347 CHECK_AND_RETURN_RET_LOG(ret != false && resolutionFrameRateVector.size() == PAIR_LENGTH, false,
348 "failed:can not trans %{public}s", iter->c_str());
349 if (!(TransStrAsSize(resolutionFrameRateVector[0], resolution) &&
350 TransStrAsRange(resolutionFrameRateVector[1], frameRate))) {
351 MEDIA_LOGD("failed:can not trans %{public}s for resolution or frame rate", iter->c_str());
352 return false;
353 }
354 resolutionFrameRateMap.insert(std::make_pair(resolution, frameRate));
355 }
356 dataMap.at(capabilityKey) = resolutionFrameRateMap;
357 return true;
358 }
359
IsNumberArray(const std::vector<std::string> & strArray)360 bool AVCodecXmlParser::IsNumberArray(const std::vector<std::string> &strArray)
361 {
362 for (auto iter = strArray.begin(); iter != strArray.end(); iter++) {
363 for (char const &c : *iter) {
364 if (std::isdigit(c) == 0) {
365 return false;
366 }
367 }
368 }
369 return true;
370 }
371
SetCapabilityVectorData(std::unordered_map<std::string,std::vector<int32_t> &> dataMap,const std::string & capabilityKey,const std::string & capabilityValue)372 bool AVCodecXmlParser::SetCapabilityVectorData(std::unordered_map<std::string, std::vector<int32_t>&> dataMap,
373 const std::string &capabilityKey, const std::string &capabilityValue)
374 {
375 std::vector<std::string> spilt;
376 std::vector<int32_t> array;
377 bool ret = SpiltKeyList(capabilityValue, ",", spilt);
378 CHECK_AND_RETURN_RET_LOG(ret != false, false, "failed:can not split %{public}s", capabilityValue.c_str());
379 if (spilt.size() > 0) {
380 std::string probe = spilt[0];
381 if (VIDEO_PROFILE_MAP.find(probe) != VIDEO_PROFILE_MAP.end()) {
382 array = TransMapAsIntegerArray(VIDEO_PROFILE_MAP, spilt);
383 } else if (AUDIO_PROFILE_MAP.find(probe) != AUDIO_PROFILE_MAP.end()) {
384 array = TransMapAsIntegerArray(AUDIO_PROFILE_MAP, spilt);
385 } else if (VIDEO_FORMAT_MAP.find(probe) != VIDEO_FORMAT_MAP.end()) {
386 array = TransMapAsIntegerArray(VIDEO_FORMAT_MAP, spilt);
387 } else if (AUDIO_FORMAT_MAP.find(probe) != AUDIO_FORMAT_MAP.end()) {
388 array = TransMapAsIntegerArray(AUDIO_FORMAT_MAP, spilt);
389 } else if (BITRATE_MODE_MAP.find(probe) != BITRATE_MODE_MAP.end()) {
390 array = TransMapAsIntegerArray(BITRATE_MODE_MAP, spilt);
391 } else if (IsNumberArray(spilt)) {
392 array = TransStrAsIntegerArray(spilt);
393 } else {
394 MEDIA_LOGD("The value of %{public}s in the configuration file is incorrect.", capabilityValue.c_str());
395 return false;
396 }
397 dataMap.at(capabilityKey) = array;
398 }
399 return true;
400 }
401
SetCapabilityData(CapabilityData & data,const std::string & capabilityKey,const std::string & capabilityValue)402 bool AVCodecXmlParser::SetCapabilityData(CapabilityData &data, const std::string &capabilityKey,
403 const std::string &capabilityValue)
404 {
405 std::unordered_map<std::string, std::string&> capabilityStringMap = {
406 {"codecName", data.codecName}, {"mimeType", data.mimeType}};
407
408 std::unordered_map<std::string, int32_t&> capabilityIntMap = {{"codecType", data.codecType}};
409
410 std::unordered_map<std::string, bool&> capabilityBoolMap = {{"isVendor", data.isVendor}};
411
412 std::unordered_map<std::string, ImgSize&> capabilitySizeMap = {{"blockSize", data.blockSize}};
413
414 std::unordered_map<std::string, std::map<ImgSize, Range>&> capabilityHashRangeMap = {
415 {"measuredFrameRate", data.measuredFrameRate}};
416
417 std::unordered_map<std::string, Range&> capabilityRangeMap = {
418 {"bitrate", data.bitrate}, {"channels", data.channels}, {"complexity", data.complexity},
419 {"alignment", data.alignment}, {"width", data.width}, {"height", data.height}, {"frameRate", data.frameRate},
420 {"encodeQuality", data.encodeQuality}, {"quality", data.quality}, {"blockPerFrame", data.blockPerFrame},
421 {"blockPerSecond", data.blockPerSecond}};
422
423 std::unordered_map<std::string, std::vector<int32_t>&> capabilityVectorMap = {
424 {"sampleRate", data.sampleRate}, {"format", data.format}, {"profiles", data.profiles},
425 {"bitrateMode", data.bitrateMode}, {"levels", data.levels}};
426
427 bool ret = false;
428 if (capabilityStringMap.find(capabilityKey) != capabilityStringMap.end()) {
429 ret = SetCapabilityStringData(capabilityStringMap, capabilityKey, capabilityValue);
430 CHECK_AND_RETURN_RET_LOG(ret != false, false, "SetCapabilityStringData failed");
431 } else if (capabilityIntMap.find(capabilityKey) != capabilityIntMap.end()) {
432 ret = SetCapabilityIntData(capabilityIntMap, capabilityKey, capabilityValue);
433 CHECK_AND_RETURN_RET_LOG(ret != false, false, "SetCapabilityIntData failed");
434 } else if (capabilityBoolMap.find(capabilityKey) != capabilityBoolMap.end()) {
435 ret = SetCapabilityBoolData(capabilityBoolMap, capabilityKey, capabilityValue);
436 CHECK_AND_RETURN_RET_LOG(ret != false, false, "SetCapabilityBoolData failed");
437 } else if (capabilitySizeMap.find(capabilityKey) != capabilitySizeMap.end()) {
438 ret = SetCapabilitySizeData(capabilitySizeMap, capabilityKey, capabilityValue);
439 CHECK_AND_RETURN_RET_LOG(ret != false, false, "SetCapabilitySizeData failed");
440 } else if (capabilityHashRangeMap.find(capabilityKey) != capabilityHashRangeMap.end()) {
441 ret = SetCapabilityHashRangeData(capabilityHashRangeMap, capabilityKey, capabilityValue);
442 CHECK_AND_RETURN_RET_LOG(ret != false, false, "SetCapabilityHashRangeData failed");
443 } else if (capabilityRangeMap.find(capabilityKey) != capabilityRangeMap.end()) {
444 ret = SetCapabilityRangeData(capabilityRangeMap, capabilityKey, capabilityValue);
445 CHECK_AND_RETURN_RET_LOG(ret != false, false, "SetCapabilityRangeData failed");
446 } else if (capabilityVectorMap.find(capabilityKey) != capabilityVectorMap.end()) {
447 ret = SetCapabilityVectorData(capabilityVectorMap, capabilityKey, capabilityValue);
448 CHECK_AND_RETURN_RET_LOG(ret != false, false, "SetCapabilityVectorData failed");
449 } else {
450 CHECK_AND_RETURN_RET_LOG(ret != false, false, "can not find capabilityKey: %{public}s", capabilityKey.c_str());
451 }
452 return true;
453 }
454
ParseData(xmlNode * node)455 bool AVCodecXmlParser::ParseData(xmlNode *node)
456 {
457 xmlNode *child = node->xmlChildrenNode;
458 std::string capabilityValue;
459 CapabilityData capabilityData;
460 for (; child; child = child->next) {
461 if (xmlStrcmp(child->name, reinterpret_cast<const xmlChar*>("Item"))) {
462 continue;
463 }
464 for (auto it = capabilityKeys_.begin(); it != capabilityKeys_.end(); it++) {
465 std::string capabilityKey = *it;
466
467 if (xmlHasProp(child, reinterpret_cast<xmlChar*>(const_cast<char*>(capabilityKey.c_str())))) {
468 capabilityValue = std::string(reinterpret_cast<char*>(xmlGetProp(child,
469 reinterpret_cast<xmlChar*>(const_cast<char*>(capabilityKey.c_str())))));
470 bool ret = SetCapabilityData(capabilityData, capabilityKey, capabilityValue);
471 CHECK_AND_RETURN_RET_LOG(ret != false, false, "SetCapabilityData failed");
472 break;
473 }
474 }
475 }
476 capabilityDataArray_.push_back(capabilityData);
477 return true;
478 }
479
GetNodeNameAsInt(xmlNode * node)480 NodeName AVCodecXmlParser::GetNodeNameAsInt(xmlNode *node)
481 {
482 if (!xmlStrcmp(node->name, reinterpret_cast<const xmlChar*>("Codecs"))) {
483 return CODECS;
484 } else if (!xmlStrcmp(node->name, reinterpret_cast<const xmlChar*>("AudioCodecs"))) {
485 return AUDIO_CODECS;
486 } else if (!xmlStrcmp(node->name, reinterpret_cast<const xmlChar*>("VideoCodecs"))) {
487 return VIDEO_CODECS;
488 } else if (!xmlStrcmp(node->name, reinterpret_cast<const xmlChar*>("AudioDecoder"))) {
489 return AUDIO_DECODER;
490 } else if (!xmlStrcmp(node->name, reinterpret_cast<const xmlChar*>("AudioEncoder"))) {
491 return AUDIO_ENCODER;
492 } else if (!xmlStrcmp(node->name, reinterpret_cast<const xmlChar*>("VideoDecoder"))) {
493 return VIDEO_DECODER;
494 } else if (!xmlStrcmp(node->name, reinterpret_cast<const xmlChar*>("VideoEncoder"))) {
495 return VIDEO_ENCODER;
496 } else {
497 return UNKNOWN;
498 }
499 }
500
GetCapabilityDataArray()501 std::vector<CapabilityData> AVCodecXmlParser::GetCapabilityDataArray()
502 {
503 return this->capabilityDataArray_;
504 }
505 } // namespace Media
506 } // namespace OHOS