1 /*
2  * Copyright 2009-2017 Alibaba Cloud All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <alibabacloud/oss/model/GetLiveChannelStatResult.h>
19 #include <alibabacloud/oss/model/Owner.h>
20 #include <external/tinyxml2/tinyxml2.h>
21 #include <sstream>
22 #include "utils/Utils.h"
23 using namespace AlibabaCloud::OSS;
24 using namespace tinyxml2;
25 
GetLiveChannelStatResult()26 GetLiveChannelStatResult::GetLiveChannelStatResult() :
27     OssResult(),
28     width_(0),
29     height_(0),
30     frameRate_(0),
31     videoBandWidth_(0),
32     sampleRate_(0),
33     audioBandWidth_(0)
34 {
35 
36 }
37 
GetLiveChannelStatResult(const std::string & result)38 GetLiveChannelStatResult::GetLiveChannelStatResult(const std::string& result):
39     GetLiveChannelStatResult()
40 {
41     *this = result;
42 }
43 
GetLiveChannelStatResult(const std::shared_ptr<std::iostream> & result)44 GetLiveChannelStatResult::GetLiveChannelStatResult(const std::shared_ptr<std::iostream>& result):
45     GetLiveChannelStatResult()
46 {
47     std::istreambuf_iterator<char> isb(*result.get()), end;
48     std::string str(isb, end);
49     *this = str;
50 }
51 
operator =(const std::string & result)52 GetLiveChannelStatResult& GetLiveChannelStatResult::operator =(const std::string& result)
53 {
54     XMLDocument doc;
55     XMLError xml_err;
56     if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) {
57         XMLElement* root =doc.RootElement();
58         if (root && !std::strncmp("LiveChannelStat", root->Name(), 15)) {
59             XMLElement *node;
60 
61             node  = root->FirstChildElement("Status");
62             if(node && node->GetText())
63             {
64                 status_ = ToLiveChannelStatusType(node->GetText());
65             }
66 
67             node = root->FirstChildElement("ConnectedTime");
68             if(node && node->GetText())
69             {
70                 connectedTime_ = node->GetText();
71             }
72 
73             node = root->FirstChildElement("RemoteAddr");
74             if(node && node->GetText())
75             {
76                 remoteAddr_ = node->GetText();
77             }
78             XMLElement *videoRoot = root->FirstChildElement("Video");
79             if(videoRoot)
80             {
81                 node = videoRoot->FirstChildElement("Width");
82                 if(node && node->GetText())
83                 {
84                     width_ = std::strtoul(node->GetText(), nullptr, 10);
85                 }
86                 node = videoRoot->FirstChildElement("Height");
87                 if(node && node->GetText())
88                 {
89                     height_ = std::strtoul(node->GetText(), nullptr, 10);
90                 }
91                 node = videoRoot->FirstChildElement("FrameRate");
92                 if(node && node->GetText())
93                 {
94                     frameRate_ = std::strtoull(node->GetText(), nullptr, 10);
95                 }
96                 node = videoRoot->FirstChildElement("Bandwidth");
97                 if(node && node->GetText())
98                 {
99                     videoBandWidth_ = std::strtoull(node->GetText(), nullptr, 10);
100                 }
101                 node = videoRoot->FirstChildElement("Codec");
102                 if(node && node->GetText())
103                 {
104                     videoCodec_ = node->GetText();
105                 }
106             }
107             XMLElement *audioRoot = root->FirstChildElement("Audio");
108             if(audioRoot)
109             {
110                 node = audioRoot->FirstChildElement("Bandwidth");
111                 if(node && node->GetText())
112                 {
113                     audioBandWidth_ = std::strtoull(node->GetText(), nullptr, 10);
114                 }
115                 node = audioRoot->FirstChildElement("SampleRate");
116                 if(node && node->GetText())
117                 {
118                     sampleRate_ = std::strtoull(node->GetText(), nullptr, 10);
119                 }
120                 node = audioRoot->FirstChildElement("Codec");
121                 if(node && node->GetText())
122                 {
123                     audioCodec_ = node->GetText();
124                 }
125             }
126             parseDone_ = true;
127         }
128     }
129     return *this;
130 }
131 
Status() const132 LiveChannelStatus GetLiveChannelStatResult::Status() const
133 {
134     return status_;
135 }
136 
ConnectedTime() const137 const std::string& GetLiveChannelStatResult::ConnectedTime() const
138 {
139     return connectedTime_;
140 }
141 
RemoteAddr() const142 const std::string& GetLiveChannelStatResult::RemoteAddr() const
143 {
144     return remoteAddr_;
145 }
146 
Width() const147 uint32_t GetLiveChannelStatResult::Width() const
148 {
149     return width_;
150 }
151 
Height() const152 uint32_t GetLiveChannelStatResult::Height() const
153 {
154     return height_;
155 }
156 
FrameRate() const157 uint64_t GetLiveChannelStatResult::FrameRate() const
158 {
159     return frameRate_;
160 }
161 
VideoBandWidth() const162 uint64_t GetLiveChannelStatResult::VideoBandWidth() const
163 {
164     return videoBandWidth_;
165 }
166 
VideoCodec() const167 const std::string& GetLiveChannelStatResult::VideoCodec() const
168 {
169     return videoCodec_;
170 }
171 
SampleRate() const172 uint64_t GetLiveChannelStatResult::SampleRate() const
173 {
174     return sampleRate_;
175 }
176 
AudioBandWidth() const177 uint64_t GetLiveChannelStatResult::AudioBandWidth() const
178 {
179     return audioBandWidth_;
180 }
181 
AudioCodec() const182 const std::string& GetLiveChannelStatResult::AudioCodec() const
183 {
184     return audioCodec_;
185 }
186 
187