1 /*
2 * Copyright (c) 2024-2024 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 #include <cstdint>
17 #include "dash_adpt_set_node.h"
18 #include "dash_mpd_util.h"
19
20 namespace OHOS {
21 namespace Media {
22 namespace Plugins {
23 namespace HttpPlugin {
24
DashAdptSetNode()25 DashAdptSetNode::DashAdptSetNode()
26 {
27 for (uint32_t index = 0; index < DASH_ADAPTATION_SET_ATTR_NUM; index++) {
28 adptSetAttr_[index].attr_.assign(adptSetAttrs_[index]);
29 adptSetAttr_[index].val_.assign("");
30 }
31 }
32
~DashAdptSetNode()33 DashAdptSetNode::~DashAdptSetNode() {}
34
ParseNode(std::shared_ptr<XmlParser> xmlParser,std::shared_ptr<XmlElement> rootElement)35 void DashAdptSetNode::ParseNode(std::shared_ptr<XmlParser> xmlParser, std::shared_ptr<XmlElement> rootElement)
36 {
37 if (xmlParser != nullptr) {
38 comAttrsElements_.ParseAttrs(xmlParser, rootElement);
39
40 for (uint32_t index = 0; index < DASH_ADAPTATION_SET_ATTR_NUM; index++) {
41 xmlParser->GetAttribute(rootElement, adptSetAttr_[index].attr_, adptSetAttr_[index].val_);
42 }
43 }
44 }
45
GetAttr(const std::string & attrName,std::string & sAttrVal)46 void DashAdptSetNode::GetAttr(const std::string &attrName, std::string &sAttrVal)
47 {
48 uint32_t index = DashGetAttrIndex(attrName, adptSetAttrs_, DASH_ADAPTATION_SET_ATTR_NUM);
49 if (index < DASH_ADAPTATION_SET_ATTR_NUM) {
50 if (adptSetAttr_[index].val_.length() > 0) {
51 sAttrVal = adptSetAttr_[index].val_;
52 } else {
53 sAttrVal.assign("");
54 }
55 } else {
56 comAttrsElements_.GetAttr(attrName, sAttrVal);
57 }
58 }
59
GetAttr(const std::string & attrName,uint32_t & uiAttrVal)60 void DashAdptSetNode::GetAttr(const std::string &attrName, uint32_t &uiAttrVal)
61 {
62 uint32_t index = DashGetAttrIndex(attrName, adptSetAttrs_, DASH_ADAPTATION_SET_ATTR_NUM);
63 if (index < DASH_ADAPTATION_SET_ATTR_NUM) {
64 if (adptSetAttr_[index].val_.length() > 0) {
65 uiAttrVal = static_cast<uint32_t>(std::atoll(adptSetAttr_[index].val_.c_str()));
66 } else {
67 uiAttrVal = 0;
68 }
69 } else {
70 comAttrsElements_.GetAttr(attrName, uiAttrVal);
71 }
72 }
73
GetAttr(const std::string & attrName,int32_t & iAttrVal)74 void DashAdptSetNode::GetAttr(const std::string &attrName, int32_t &iAttrVal)
75 {
76 uint32_t index = DashGetAttrIndex(attrName, adptSetAttrs_, DASH_ADAPTATION_SET_ATTR_NUM);
77 if (index < DASH_ADAPTATION_SET_ATTR_NUM) {
78 if (adptSetAttr_[index].val_.length() > 0) {
79 iAttrVal = static_cast<int32_t>(std::atoll(adptSetAttr_[index].val_.c_str()));
80 } else {
81 iAttrVal = 0;
82 }
83 } else {
84 comAttrsElements_.GetAttr(attrName, iAttrVal);
85 }
86 }
87
GetAttr(const std::string & attrName,uint64_t & ullAttrVal)88 void DashAdptSetNode::GetAttr(const std::string &attrName, uint64_t &ullAttrVal)
89 {
90 uint32_t index = DashGetAttrIndex(attrName, adptSetAttrs_, DASH_ADAPTATION_SET_ATTR_NUM);
91 if (index < DASH_ADAPTATION_SET_ATTR_NUM) {
92 if (adptSetAttr_[index].val_.length() > 0) {
93 ullAttrVal = static_cast<uint64_t>(std::atoll(adptSetAttr_[index].val_.c_str()));
94 } else {
95 ullAttrVal = 0;
96 }
97 } else {
98 comAttrsElements_.GetAttr(attrName, ullAttrVal);
99 }
100 }
101
GetAttr(const std::string & attrName,double & dAttrVal)102 void DashAdptSetNode::GetAttr(const std::string &attrName, double &dAttrVal)
103 {
104 uint32_t index = DashGetAttrIndex(attrName, adptSetAttrs_, DASH_ADAPTATION_SET_ATTR_NUM);
105 if (index < DASH_ADAPTATION_SET_ATTR_NUM) {
106 if (adptSetAttr_[index].val_.length() > 0) {
107 dAttrVal = atof(adptSetAttr_[index].val_.c_str());
108 } else {
109 dAttrVal = 0.0;
110 }
111 } else {
112 comAttrsElements_.GetAttr(attrName, dAttrVal);
113 }
114 }
115 } // namespace HttpPluginLite
116 } // namespace Plugin
117 } // namespace Media
118 } // namespace OHOS