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