forked from mirrors/gstreamer-rs
audio: Add AudioInfo::is_valid() and guard against finfo being NULL when retrieving the audio format
This commit is contained in:
parent
cf33e0acd0
commit
be00953ec6
1 changed files with 8 additions and 0 deletions
|
@ -151,6 +151,10 @@ impl AudioInfo {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_valid(&self) -> bool {
|
||||
!self.0.finfo.is_null() && self.0.channels > 0 && self.0.rate > 0 && self.0.bpf > 0
|
||||
}
|
||||
|
||||
pub fn from_caps(caps: &gst::CapsRef) -> Result<AudioInfo, glib::error::BoolError> {
|
||||
skip_assert_initialized!();
|
||||
|
||||
|
@ -230,6 +234,10 @@ impl AudioInfo {
|
|||
}
|
||||
|
||||
pub fn format(&self) -> ::AudioFormat {
|
||||
if self.0.finfo.is_null() {
|
||||
return ::AudioFormat::Unknown;
|
||||
}
|
||||
|
||||
unsafe { from_glib((*self.0.finfo).format) }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue