mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-01-09 02:35:29 +00:00
Structure/Caps API improvements
This commit is contained in:
parent
757d7532c1
commit
df51424631
3 changed files with 52 additions and 36 deletions
|
@ -149,7 +149,7 @@ impl AudioFormat {
|
||||||
flavors::SoundFormat::MP3 |
|
flavors::SoundFormat::MP3 |
|
||||||
flavors::SoundFormat::MP3_8KHZ => {
|
flavors::SoundFormat::MP3_8KHZ => {
|
||||||
Some(Caps::new_simple("audio/mpeg",
|
Some(Caps::new_simple("audio/mpeg",
|
||||||
&[("mpegversion", &1.into()), ("layer", &3.into())]))
|
&[("mpegversion", 1i32.into()), ("layer", 3i32.into())]))
|
||||||
}
|
}
|
||||||
flavors::SoundFormat::PCM_NE |
|
flavors::SoundFormat::PCM_NE |
|
||||||
flavors::SoundFormat::PCM_LE => {
|
flavors::SoundFormat::PCM_LE => {
|
||||||
|
@ -157,19 +157,19 @@ impl AudioFormat {
|
||||||
// Assume little-endian for "PCM_NE", it's probably more common and we have no
|
// Assume little-endian for "PCM_NE", it's probably more common and we have no
|
||||||
// way to know what the endianness of the system creating the stream was
|
// way to know what the endianness of the system creating the stream was
|
||||||
Some(Caps::new_simple("audio/x-raw",
|
Some(Caps::new_simple("audio/x-raw",
|
||||||
&[("layout", &"interleaved".into()),
|
&[("layout", "interleaved".into()),
|
||||||
("format",
|
("format",
|
||||||
&if self.width == 8 {
|
if self.width == 8 {
|
||||||
"U8".into()
|
"U8".into()
|
||||||
} else {
|
} else {
|
||||||
"S16LE".into()
|
"S16LE".into()
|
||||||
})]))
|
})]))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flavors::SoundFormat::ADPCM => {
|
flavors::SoundFormat::ADPCM => {
|
||||||
Some(Caps::new_simple("audio/x-adpcm", &[("layout", &"swf".into())]))
|
Some(Caps::new_simple("audio/x-adpcm", &[("layout", "swf".into())]))
|
||||||
}
|
}
|
||||||
flavors::SoundFormat::NELLYMOSER_16KHZ_MONO |
|
flavors::SoundFormat::NELLYMOSER_16KHZ_MONO |
|
||||||
flavors::SoundFormat::NELLYMOSER_8KHZ_MONO |
|
flavors::SoundFormat::NELLYMOSER_8KHZ_MONO |
|
||||||
|
@ -181,10 +181,10 @@ impl AudioFormat {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|header| {
|
.map(|header| {
|
||||||
Caps::new_simple("audio/mpeg",
|
Caps::new_simple("audio/mpeg",
|
||||||
&[("mpegversion", &4.into()),
|
&[("mpegversion", 4i32.into()),
|
||||||
("framed", &true.into()),
|
("framed", true.into()),
|
||||||
("stream-format", &"raw".into()),
|
("stream-format", "raw".into()),
|
||||||
("codec_data", &header.as_ref().into())])
|
("codec_data", header.as_ref().into())])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
flavors::SoundFormat::SPEEX => {
|
flavors::SoundFormat::SPEEX => {
|
||||||
|
@ -211,7 +211,7 @@ impl AudioFormat {
|
||||||
|
|
||||||
data.into_inner()
|
data.into_inner()
|
||||||
};
|
};
|
||||||
let header = Buffer::new_from_vec(header).unwrap();
|
let header = Buffer::from_vec(header).unwrap();
|
||||||
|
|
||||||
let comment = {
|
let comment = {
|
||||||
let comment_size = 4 + 7 /* nothing */ + 4 + 1;
|
let comment_size = 4 + 7 /* nothing */ + 4 + 1;
|
||||||
|
@ -225,11 +225,11 @@ impl AudioFormat {
|
||||||
|
|
||||||
data.into_inner()
|
data.into_inner()
|
||||||
};
|
};
|
||||||
let comment = Buffer::new_from_vec(comment).unwrap();
|
let comment = Buffer::from_vec(comment).unwrap();
|
||||||
|
|
||||||
Some(Caps::new_simple("audio/x-speex",
|
Some(Caps::new_simple("audio/x-speex",
|
||||||
&[("streamheader",
|
&[("streamheader",
|
||||||
&vec![header.into(), comment.into()].into())]))
|
vec![header.into(), comment.into()].into())]))
|
||||||
}
|
}
|
||||||
flavors::SoundFormat::DEVICE_SPECIFIC => {
|
flavors::SoundFormat::DEVICE_SPECIFIC => {
|
||||||
// Nobody knows
|
// Nobody knows
|
||||||
|
@ -242,7 +242,7 @@ impl AudioFormat {
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
c.get_mut()
|
c.get_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_simple(&[("rate", &(self.rate as i32).into())])
|
.set_simple(&[("rate", (self.rate as i32).into())])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if self.channels != 0 {
|
if self.channels != 0 {
|
||||||
|
@ -250,7 +250,7 @@ impl AudioFormat {
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
c.get_mut()
|
c.get_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_simple(&[("channels", &(self.channels as i32).into())])
|
.set_simple(&[("channels", (self.channels as i32).into())])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,7 +325,7 @@ impl VideoFormat {
|
||||||
fn to_caps(&self) -> Option<GstRc<Caps>> {
|
fn to_caps(&self) -> Option<GstRc<Caps>> {
|
||||||
let mut caps = match self.format {
|
let mut caps = match self.format {
|
||||||
flavors::CodecId::SORENSON_H263 => {
|
flavors::CodecId::SORENSON_H263 => {
|
||||||
Some(Caps::new_simple("video/x-flash-video", &[("flvversion", &1.into())]))
|
Some(Caps::new_simple("video/x-flash-video", &[("flvversion", 1i32.into())]))
|
||||||
}
|
}
|
||||||
flavors::CodecId::SCREEN => Some(Caps::new_simple("video/x-flash-screen", &[])),
|
flavors::CodecId::SCREEN => Some(Caps::new_simple("video/x-flash-screen", &[])),
|
||||||
flavors::CodecId::VP6 => Some(Caps::new_simple("video/x-vp6-flash", &[])),
|
flavors::CodecId::VP6 => Some(Caps::new_simple("video/x-vp6-flash", &[])),
|
||||||
|
@ -336,15 +336,15 @@ impl VideoFormat {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|header| {
|
.map(|header| {
|
||||||
Caps::new_simple("video/x-h264",
|
Caps::new_simple("video/x-h264",
|
||||||
&[("stream-format", &"avc".into()),
|
&[("stream-format", "avc".into()),
|
||||||
("codec_data", &header.as_ref().into())])
|
("codec_data", header.as_ref().into())])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
flavors::CodecId::H263 => Some(Caps::new_simple("video/x-h263", &[])),
|
flavors::CodecId::H263 => Some(Caps::new_simple("video/x-h263", &[])),
|
||||||
flavors::CodecId::MPEG4Part2 => {
|
flavors::CodecId::MPEG4Part2 => {
|
||||||
Some(Caps::new_simple("video/x-h263",
|
Some(Caps::new_simple("video/x-h263",
|
||||||
&[("mpegversion", &4.into()),
|
&[("mpegversion", 4i32.into()),
|
||||||
("systemstream", &false.into())]))
|
("systemstream", false.into())]))
|
||||||
}
|
}
|
||||||
flavors::CodecId::JPEG => {
|
flavors::CodecId::JPEG => {
|
||||||
// Unused according to spec
|
// Unused according to spec
|
||||||
|
@ -357,8 +357,8 @@ impl VideoFormat {
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
c.get_mut()
|
c.get_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_simple(&[("width", &(width as i32).into()),
|
.set_simple(&[("width", (width as i32).into()),
|
||||||
("height", &(height as i32).into())])
|
("height", (height as i32).into())])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +368,7 @@ impl VideoFormat {
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
c.get_mut()
|
c.get_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_simple(&[("pixel-aspect-ratio", &par.into())])
|
.set_simple(&[("pixel-aspect-ratio", par.into())])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,7 @@ impl VideoFormat {
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
c.get_mut()
|
c.get_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_simple(&[("framerate", &fps.into())])
|
.set_simple(&[("framerate", fps.into())])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ impl Caps {
|
||||||
unsafe { GstRc::from_owned_ptr(gst::gst_caps_new_any()) }
|
unsafe { GstRc::from_owned_ptr(gst::gst_caps_new_any()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_simple(name: &str, values: &[(&str, &Value)]) -> GstRc<Self> {
|
pub fn new_simple(name: &str, values: &[(&str, Value)]) -> GstRc<Self> {
|
||||||
let mut caps = Caps::new_empty();
|
let mut caps = Caps::new_empty();
|
||||||
|
|
||||||
let name_cstr = CString::new(name).unwrap();
|
let name_cstr = CString::new(name).unwrap();
|
||||||
|
@ -72,7 +72,7 @@ impl Caps {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_simple(&mut self, values: &[(&str, &Value)]) {
|
pub fn set_simple(&mut self, values: &[(&str, Value)]) {
|
||||||
for value in values {
|
for value in values {
|
||||||
let name_cstr = CString::new(value.0).unwrap();
|
let name_cstr = CString::new(value.0).unwrap();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -124,11 +124,11 @@ mod tests {
|
||||||
init();
|
init();
|
||||||
|
|
||||||
let caps = Caps::new_simple("foo/bar",
|
let caps = Caps::new_simple("foo/bar",
|
||||||
&[("int", &12.into()),
|
&[("int", 12.into()),
|
||||||
("bool", &true.into()),
|
("bool", true.into()),
|
||||||
("string", &"bla".into()),
|
("string", "bla".into()),
|
||||||
("fraction", &(1, 2).into()),
|
("fraction", (1, 2).into()),
|
||||||
("array", &vec![1.into(), 2.into()].into())]);
|
("array", vec![1.into(), 2.into()].into())]);
|
||||||
assert_eq!(caps.to_string(),
|
assert_eq!(caps.to_string(),
|
||||||
"foo/bar, int=(int)12, bool=(boolean)true, string=(string)bla, \
|
"foo/bar, int=(int)12, bool=(boolean)true, string=(string)bla, \
|
||||||
fraction=(fraction)1/2, array=(int)< 1, 2 >");
|
fraction=(fraction)1/2, array=(int)< 1, 2 >");
|
||||||
|
|
|
@ -20,11 +20,21 @@ use gst;
|
||||||
pub struct Structure(*mut gst::GstStructure);
|
pub struct Structure(*mut gst::GstStructure);
|
||||||
|
|
||||||
impl Structure {
|
impl Structure {
|
||||||
pub fn new(name: &str) -> Structure {
|
pub fn new_empty(name: &str) -> Structure {
|
||||||
let name_cstr = CString::new(name).unwrap();
|
let name_cstr = CString::new(name).unwrap();
|
||||||
Structure(unsafe { gst::gst_structure_new_empty(name_cstr.as_ptr()) })
|
Structure(unsafe { gst::gst_structure_new_empty(name_cstr.as_ptr()) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new(name: &str, values: &[(&str, Value)]) -> Structure {
|
||||||
|
let mut structure = Structure::new_empty(name);
|
||||||
|
|
||||||
|
for &(ref f, ref v) in values {
|
||||||
|
structure.set(f, v.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
structure
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from_string(s: &str) -> Option<Structure> {
|
pub fn from_string(s: &str) -> Option<Structure> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let cstr = CString::new(s).unwrap();
|
let cstr = CString::new(s).unwrap();
|
||||||
|
@ -262,10 +272,10 @@ mod tests {
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn set_get() {
|
fn new_set_get() {
|
||||||
unsafe { gst::gst_init(ptr::null_mut(), ptr::null_mut()) };
|
unsafe { gst::gst_init(ptr::null_mut(), ptr::null_mut()) };
|
||||||
|
|
||||||
let mut s = Structure::new("test");
|
let mut s = Structure::new_empty("test");
|
||||||
assert_eq!(s.get_name(), "test");
|
assert_eq!(s.get_name(), "test");
|
||||||
|
|
||||||
s.set("f1", "abc");
|
s.set("f1", "abc");
|
||||||
|
@ -282,5 +292,11 @@ mod tests {
|
||||||
vec![("f1", Value::new("abc")),
|
vec![("f1", Value::new("abc")),
|
||||||
("f2", Value::new("bcd")),
|
("f2", Value::new("bcd")),
|
||||||
("f3", Value::new(123i32))]);
|
("f3", Value::new(123i32))]);
|
||||||
|
|
||||||
|
let s2 = Structure::new("test",
|
||||||
|
&[("f1", "abc".into()),
|
||||||
|
("f2", "bcd".into()),
|
||||||
|
("f3", 123i32.into())]);
|
||||||
|
assert_eq!(s, s2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue