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