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