Skip to content

Commit 54c752f

Browse files
committed
Fix nginx parsing frame_rate and audio codec
1 parent 7026674 commit 54c752f

File tree

1 file changed

+81
-3
lines changed

1 file changed

+81
-3
lines changed

src/stream_servers/nginx.rs

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct Meta {
4343
pub struct Video {
4444
width: u32,
4545
height: u32,
46-
frame_rate: u32,
46+
frame_rate: f64,
4747
codec: String,
4848
profile: Option<String>,
4949
compat: Option<u32>,
@@ -52,7 +52,7 @@ pub struct Video {
5252

5353
#[derive(Deserialize, Debug)]
5454
pub struct Audio {
55-
codec: String,
55+
codec: Option<String>,
5656
profile: Option<String>,
5757
channels: Option<u32>,
5858
sample_rate: Option<u32>,
@@ -186,7 +186,7 @@ impl StreamServersCommands for Nginx {
186186

187187
let a_info = format!(
188188
"{} {} {}Hz, {} channels",
189-
audio.codec,
189+
audio.codec.unwrap_or_default(),
190190
audio.profile.unwrap_or_default(),
191191
audio.sample_rate.unwrap_or_default(),
192192
audio.channels.unwrap_or_default(),
@@ -210,3 +210,81 @@ impl Bsl for Nginx {}
210210
// }
211211
// }
212212
// }
213+
//
214+
215+
#[cfg(test)]
216+
mod tests {
217+
use super::*;
218+
219+
#[test]
220+
fn invalid_digit() {
221+
let text = r#"
222+
<?xml version="1.0" encoding="utf-8" ?>
223+
<?xml-stylesheet type="text/xsl" href="/stat.xsl" ?>
224+
<rtmp>
225+
<nginx_version>1.17.6</nginx_version>
226+
<nginx_rtmp_version>1.1.7.11-dev</nginx_rtmp_version>
227+
<compiler>gcc 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) </compiler>
228+
<built>Feb 15 2021 01:06:01</built>
229+
<pid>944</pid>
230+
<uptime>1781693</uptime>
231+
<naccepted>262</naccepted>
232+
<bw_in>0</bw_in>
233+
<bytes_in>1185796040</bytes_in>
234+
<bw_out>0</bw_out>
235+
<bytes_out>646442932</bytes_out>
236+
<server>
237+
<application>
238+
<name>publish</name>
239+
<live>
240+
<stream>
241+
<name>test</name>
242+
<time>1832</time>
243+
<bw_in>0</bw_in>
244+
<bytes_in>766897</bytes_in>
245+
<bw_out>0</bw_out>
246+
<bytes_out>0</bytes_out>
247+
<bw_audio>0</bw_audio>
248+
<bw_video>0</bw_video>
249+
<bw_data>0</bw_data>
250+
<client>
251+
<id>3192</id>
252+
<address>123.123.123.123</address>
253+
<port>59796</port>
254+
<time>2008</time>
255+
<flashver>FMLE/3.0 (compatible; Larix/nul</flashver>
256+
<bytes_in>768181</bytes_in>
257+
<bytes_out>409</bytes_out>
258+
<dropped>0</dropped>
259+
<avsync></avsync>
260+
<timestamp>3361</timestamp>
261+
<publishing/>
262+
<active/>
263+
</client>
264+
<meta>
265+
<video>
266+
<width>1280</width>
267+
<height>720</height>
268+
<frame_rate>0.000</frame_rate>
269+
<codec>H264</codec>
270+
<profile>Baseline</profile>
271+
<compat>192</compat>
272+
<level>3.1</level>
273+
</video>
274+
<audio></audio>
275+
</meta>
276+
<nclients>1</nclients>
277+
<publishing/>
278+
<active/>
279+
</stream>
280+
<nclients>1</nclients>
281+
</live>
282+
</application>
283+
</server>
284+
</rtmp>
285+
"#;
286+
287+
let parsed: NginxRtmpStats = quick_xml::de::from_str(&text).unwrap();
288+
println!("{:#?}", parsed);
289+
}
290+
}

0 commit comments

Comments
 (0)