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