Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sdroege/gst-plugin-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorJan Alexander Steffens (heftig) <jan.steffens@ltnglobal.com>2023-02-08 18:41:53 +0300
committerJan Alexander Steffens (heftig) <jan.steffens@ltnglobal.com>2023-02-09 15:07:32 +0300
commitf03ee95bf0726a4bf00559b8658b8ac6162ec84e (patch)
tree28d907a180b26e3c632c664806aba91e05cfa1ef /utils
parentc971c4d1d595a4c2358843c1e30f856256cb2d52 (diff)
livesync: Extract audio_info_from_caps
And adjust it slightly so it never panics. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1083>
Diffstat (limited to 'utils')
-rw-r--r--utils/livesync/src/livesync/imp.rs23
1 files changed, 11 insertions, 12 deletions
diff --git a/utils/livesync/src/livesync/imp.rs b/utils/livesync/src/livesync/imp.rs
index f21decba..9fc22257 100644
--- a/utils/livesync/src/livesync/imp.rs
+++ b/utils/livesync/src/livesync/imp.rs
@@ -27,6 +27,15 @@ static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
)
});
+fn audio_info_from_caps(
+ caps: &gst::CapsRef,
+) -> Result<Option<gst_audio::AudioInfo>, glib::BoolError> {
+ caps.structure(0)
+ .map_or(false, |s| s.has_name("audio/x-raw"))
+ .then(|| gst_audio::AudioInfo::from_caps(caps))
+ .transpose()
+}
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum BufferLateness {
OnTime,
@@ -631,13 +640,7 @@ impl LiveSync {
gst::EventView::Caps(c) => {
let caps = c.caps_owned();
- let audio_info = match caps
- .structure(0)
- .unwrap()
- .has_name("audio/x-raw")
- .then(|| gst_audio::AudioInfo::from_caps(&caps))
- .transpose()
- {
+ let audio_info = match audio_info_from_caps(&caps) {
Ok(ai) => ai,
Err(e) => {
gst::error!(CAT, imp: self, "Failed to parse audio caps: {}", e);
@@ -1092,11 +1095,7 @@ impl LiveSync {
MutexGuard::unlocked(&mut state, || self.srcpad.push_event(event));
state.srcresult?;
- state.out_audio_info = caps
- .structure(0)
- .unwrap()
- .has_name("audio/x-raw")
- .then(|| gst_audio::AudioInfo::from_caps(&caps).unwrap());
+ state.out_audio_info = audio_info_from_caps(&caps).unwrap();
}
if let Some(segment) = segment {