mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-01-03 15:58:42 +00:00
onvifmetadataparse: Pass through other XML as is with the UTC times based on the buffer PTSs
This commit is contained in:
parent
420f36251a
commit
cb339c1bf8
1 changed files with 50 additions and 8 deletions
|
@ -36,8 +36,8 @@ struct State {
|
||||||
pre_queued_buffers: Vec<gst::Buffer>,
|
pre_queued_buffers: Vec<gst::Buffer>,
|
||||||
// Mapping of UTC time to PTS
|
// Mapping of UTC time to PTS
|
||||||
utc_time_pts_mapping: Option<(gst::ClockTime, gst::ClockTime)>,
|
utc_time_pts_mapping: Option<(gst::ClockTime, gst::ClockTime)>,
|
||||||
// UTC time -> XML
|
// UTC time -> (VideoAnalytics XML with Frames, other XML nodes)
|
||||||
queued_frames: BTreeMap<gst::ClockTime, Element>,
|
queued_frames: BTreeMap<gst::ClockTime, (Element, Vec<Element>)>,
|
||||||
// Configured latency
|
// Configured latency
|
||||||
configured_latency: gst::ClockTime,
|
configured_latency: gst::ClockTime,
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ impl OnvifMetadataParse {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.queue(element, &mut state, buffer)?;
|
self.queue(element, &mut state, buffer, pts)?;
|
||||||
let buffers = self.drain(element, &mut state, Some(pts))?;
|
let buffers = self.drain(element, &mut state, Some(pts))?;
|
||||||
|
|
||||||
if let Some(buffers) = buffers {
|
if let Some(buffers) = buffers {
|
||||||
|
@ -136,13 +136,17 @@ impl OnvifMetadataParse {
|
||||||
element: &super::OnvifMetadataParse,
|
element: &super::OnvifMetadataParse,
|
||||||
state: &mut State,
|
state: &mut State,
|
||||||
buffer: gst::Buffer,
|
buffer: gst::Buffer,
|
||||||
|
pts: gst::ClockTime,
|
||||||
) -> Result<(), gst::FlowError> {
|
) -> Result<(), gst::FlowError> {
|
||||||
let State {
|
let State {
|
||||||
ref mut pre_queued_buffers,
|
ref mut pre_queued_buffers,
|
||||||
ref mut queued_frames,
|
ref mut queued_frames,
|
||||||
|
ref utc_time_pts_mapping,
|
||||||
..
|
..
|
||||||
} = &mut *state;
|
} = &mut *state;
|
||||||
|
|
||||||
|
let utc_time_pts_mapping = utc_time_pts_mapping.unwrap();
|
||||||
|
|
||||||
for buffer in pre_queued_buffers.drain(..).chain(std::iter::once(buffer)) {
|
for buffer in pre_queued_buffers.drain(..).chain(std::iter::once(buffer)) {
|
||||||
let root = crate::xml_from_buffer(&buffer).map_err(|err| {
|
let root = crate::xml_from_buffer(&buffer).map_err(|err| {
|
||||||
element.post_error_message(err);
|
element.post_error_message(err);
|
||||||
|
@ -167,12 +171,44 @@ impl OnvifMetadataParse {
|
||||||
dt_unix_ns
|
dt_unix_ns
|
||||||
);
|
);
|
||||||
|
|
||||||
let xml = queued_frames.entry(dt_unix_ns).or_insert_with(|| {
|
let (xml, _) = queued_frames.entry(dt_unix_ns).or_insert_with(|| {
|
||||||
Element::bare("VideoAnalytics", "http://www.onvif.org/ver10/schema")
|
(
|
||||||
|
Element::bare("VideoAnalytics", "http://www.onvif.org/ver10/schema"),
|
||||||
|
Vec::new(),
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
xml.append_child(el.clone());
|
xml.append_child(el.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pts_diff = pts.saturating_sub(utc_time_pts_mapping.1);
|
||||||
|
let utc_time = utc_time_pts_mapping.0 + pts_diff;
|
||||||
|
|
||||||
|
for child in root.children() {
|
||||||
|
let (_, xmls) = queued_frames.entry(utc_time).or_insert_with(|| {
|
||||||
|
(
|
||||||
|
Element::bare("VideoAnalytics", "http://www.onvif.org/ver10/schema"),
|
||||||
|
Vec::new(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
if child.is("VideoAnalytics", "http://www.onvif.org/ver10/schema") {
|
||||||
|
let mut element =
|
||||||
|
Element::bare("VideoAnalytics", "http://www.onvif.org/ver10/schema");
|
||||||
|
|
||||||
|
for subchild in child.children() {
|
||||||
|
if subchild.is("Frame", "http://www.onvif.org/ver10/schema") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
element.append_child(subchild.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
xmls.push(element);
|
||||||
|
} else {
|
||||||
|
xmls.push(child.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -225,7 +261,7 @@ impl OnvifMetadataParse {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let frame = queued_frames.remove(&utc_time).unwrap();
|
let (frames, xmls) = queued_frames.remove(&utc_time).unwrap();
|
||||||
|
|
||||||
gst::trace!(
|
gst::trace!(
|
||||||
CAT,
|
CAT,
|
||||||
|
@ -235,12 +271,18 @@ impl OnvifMetadataParse {
|
||||||
frame_pts
|
frame_pts
|
||||||
);
|
);
|
||||||
|
|
||||||
let xml = Element::builder("MetadataStream", "http://www.onvif.org/ver10/schema")
|
let mut xml = Element::builder("MetadataStream", "http://www.onvif.org/ver10/schema")
|
||||||
.prefix(Some("tt".into()), "http://www.onvif.org/ver10/schema")
|
.prefix(Some("tt".into()), "http://www.onvif.org/ver10/schema")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.append(frame)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
if frames.children().next().is_some() {
|
||||||
|
xml.append_child(frames);
|
||||||
|
}
|
||||||
|
for child in xmls {
|
||||||
|
xml.append_child(child);
|
||||||
|
}
|
||||||
|
|
||||||
let mut vec = Vec::new();
|
let mut vec = Vec::new();
|
||||||
if let Err(err) = xml.write_to_decl(&mut vec) {
|
if let Err(err) = xml.write_to_decl(&mut vec) {
|
||||||
gst::error!(CAT, obj: element, "Can't serialize XML element: {}", err);
|
gst::error!(CAT, obj: element, "Can't serialize XML element: {}", err);
|
||||||
|
|
Loading…
Reference in a new issue