mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-22 09:31:06 +00:00
Move more code to caps/structure builders
Instead of the new() functions requiring slices. The code reads cleaner.
This commit is contained in:
parent
8cc018c164
commit
b4a3738b82
12 changed files with 88 additions and 95 deletions
|
@ -56,15 +56,14 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
|||
// provide the format we request.
|
||||
// This can be set after linking the two objects, because format negotiation between
|
||||
// both elements will happen during pre-rolling of the pipeline.
|
||||
appsink.set_caps(Some(&gst::Caps::new_simple(
|
||||
"audio/x-raw",
|
||||
&[
|
||||
("format", &gst_audio::AUDIO_FORMAT_S16.to_str()),
|
||||
("layout", &"interleaved"),
|
||||
("channels", &(1i32)),
|
||||
("rate", &gst::IntRange::<i32>::new(1, i32::MAX)),
|
||||
],
|
||||
)));
|
||||
appsink.set_caps(Some(
|
||||
&gst::Caps::builder("audio/x-raw")
|
||||
.field("format", gst_audio::AUDIO_FORMAT_S16.to_str())
|
||||
.field("layout", "interleaved")
|
||||
.field("channels", (1i32))
|
||||
.field("rate", gst::IntRange::<i32>::new(1, i32::MAX))
|
||||
.build(),
|
||||
));
|
||||
|
||||
// Getting data out of the appsink is done by setting callbacks on it.
|
||||
// The appsink will then call those handlers, as soon as data is available.
|
||||
|
|
|
@ -158,25 +158,19 @@ fn example_main() -> Result<(), Error> {
|
|||
.expect("rtpbin \"new-storage\" signal values[2]");
|
||||
match pt {
|
||||
100 => Some(
|
||||
gst::Caps::new_simple(
|
||||
"application/x-rtp",
|
||||
&[
|
||||
("media", &"video"),
|
||||
("clock-rate", &90000i32),
|
||||
("is-fec", &true),
|
||||
],
|
||||
)
|
||||
gst::Caps::builder("application/x-rtp")
|
||||
.field("media", "video")
|
||||
.field("clock-rate", 90000i32)
|
||||
.field("is-fec", true)
|
||||
.build()
|
||||
.to_value(),
|
||||
),
|
||||
96 => Some(
|
||||
gst::Caps::new_simple(
|
||||
"application/x-rtp",
|
||||
&[
|
||||
("media", &"video"),
|
||||
("clock-rate", &90000i32),
|
||||
("encoding-name", &"VP8"),
|
||||
],
|
||||
)
|
||||
gst::Caps::builder("application/x-rtp")
|
||||
.field("media", "video")
|
||||
.field("clock-rate", 90000i32)
|
||||
.field("encoding-name", "VP8")
|
||||
.build()
|
||||
.to_value(),
|
||||
),
|
||||
_ => None,
|
||||
|
@ -229,10 +223,14 @@ fn example_main() -> Result<(), Error> {
|
|||
}
|
||||
});
|
||||
|
||||
let rtp_caps = gst::Caps::new_simple("application/x-rtp", &[("clock-rate", &90000i32)]);
|
||||
let rtp_caps = gst::Caps::builder("application/x-rtp")
|
||||
.field("clock-rate", 90000i32)
|
||||
.build();
|
||||
|
||||
let video_caps =
|
||||
gst::Caps::new_simple("video/x-raw", &[("width", &1920i32), ("height", &1080i32)]);
|
||||
let video_caps = gst::Caps::builder("video/x-raw")
|
||||
.field("width", 1920i32)
|
||||
.field("height", 1080i32)
|
||||
.build();
|
||||
|
||||
src.set_property("address", &"127.0.0.1")?;
|
||||
src.set_property("caps", &rtp_caps)?;
|
||||
|
|
|
@ -149,7 +149,7 @@ fn example_main() -> Result<(), Error> {
|
|||
},
|
||||
);
|
||||
|
||||
let video_caps = gst::Caps::new_simple("video/x-raw", &[]);
|
||||
let video_caps = gst::Caps::builder("video/x-raw").build();
|
||||
|
||||
src.set_property_from_str("pattern", "ball")?;
|
||||
sink.set_property("host", &"127.0.0.1")?;
|
||||
|
|
|
@ -88,15 +88,12 @@ mod fir_filter {
|
|||
// GStreamer about all possible pads that could exist for this type.
|
||||
|
||||
// On both of pads we can only handle F32 mono at any sample rate.
|
||||
let caps = gst::Caps::new_simple(
|
||||
"audio/x-raw",
|
||||
&[
|
||||
("format", &gst_audio::AUDIO_FORMAT_F32.to_str()),
|
||||
("rate", &gst::IntRange::<i32>::new(1, i32::MAX)),
|
||||
("channels", &1i32),
|
||||
("layout", &"interleaved"),
|
||||
],
|
||||
);
|
||||
let caps = gst::Caps::builder("audio/x-raw")
|
||||
.field("format", gst_audio::AUDIO_FORMAT_F32.to_str())
|
||||
.field("rate", gst::IntRange::<i32>::new(1, i32::MAX))
|
||||
.field("channels", 1i32)
|
||||
.field("layout", "interleaved")
|
||||
.build();
|
||||
|
||||
vec![
|
||||
// The src pad template must be named "src" for basetransform
|
||||
|
|
|
@ -470,16 +470,13 @@ mod tests {
|
|||
fn test_from_to_caps() {
|
||||
gst::init().unwrap();
|
||||
|
||||
let caps = gst::Caps::new_simple(
|
||||
"audio/x-raw",
|
||||
&[
|
||||
("format", &"S16LE"),
|
||||
("rate", &48000),
|
||||
("channels", &2),
|
||||
("layout", &"interleaved"),
|
||||
("channel-mask", &gst::Bitmask::new(0x3)),
|
||||
],
|
||||
);
|
||||
let caps = gst::Caps::builder("audio/x-raw")
|
||||
.field("format", "S16LE")
|
||||
.field("rate", 48000)
|
||||
.field("channels", 2)
|
||||
.field("layout", "interleaved")
|
||||
.field("channel-mask", gst::Bitmask::new(0x3))
|
||||
.build();
|
||||
let info = AudioInfo::from_caps(&caps).unwrap();
|
||||
assert_eq!(info.format(), crate::AudioFormat::S16le);
|
||||
assert_eq!(info.rate(), 48000);
|
||||
|
|
|
@ -538,9 +538,11 @@ mod tests {
|
|||
fn test_encoding_audio_profile_builder() {
|
||||
gst::init().unwrap();
|
||||
|
||||
let caps = gst::Caps::new_simple("audio/x-raw", &[]);
|
||||
let caps = gst::Caps::builder("audio/x-raw").build();
|
||||
|
||||
let restriction = gst::Caps::new_simple("audio/x-raw", &[("format", &"S32LE")]);
|
||||
let restriction = gst::Caps::builder("audio/x-raw")
|
||||
.field("format", "S32LE")
|
||||
.build();
|
||||
|
||||
let audio_profile = EncodingAudioProfile::builder(&caps)
|
||||
.name(AUDIO_PROFILE_NAME)
|
||||
|
@ -566,7 +568,9 @@ mod tests {
|
|||
assert_eq!(audio_profile.allows_dynamic_output(), ALLOW_DYNAMIC_OUTPUT);
|
||||
assert_eq!(audio_profile.is_enabled(), ENABLED);
|
||||
|
||||
let restriction = gst::Caps::new_simple("audio/x-raw", &[("format", &"S32BE")]);
|
||||
let restriction = gst::Caps::builder("audio/x-raw")
|
||||
.field("format", "S32BE")
|
||||
.build();
|
||||
audio_profile.set_restriction(Some(&restriction));
|
||||
assert_eq!(audio_profile.restriction().unwrap(), restriction);
|
||||
}
|
||||
|
@ -575,9 +579,11 @@ mod tests {
|
|||
fn test_encoding_video_profile_builder() {
|
||||
gst::init().unwrap();
|
||||
|
||||
let caps = gst::Caps::new_simple("video/x-raw", &[]);
|
||||
let caps = gst::Caps::builder("video/x-raw").build();
|
||||
|
||||
let restriction = gst::Caps::new_simple("video/x-raw", &[("format", &"RGBA")]);
|
||||
let restriction = gst::Caps::builder("video/x-raw")
|
||||
.field("format", "RGBA")
|
||||
.build();
|
||||
|
||||
let video_profile = EncodingVideoProfile::builder(&caps)
|
||||
.name(VIDEO_PROFILE_NAME)
|
||||
|
@ -610,7 +616,9 @@ mod tests {
|
|||
assert_eq!(video_profile.is_variableframerate(), VARIABLE_FRAMERATE);
|
||||
assert_eq!(video_profile.pass(), PASS);
|
||||
|
||||
let restriction = gst::Caps::new_simple("video/x-raw", &[("format", &"NV12")]);
|
||||
let restriction = gst::Caps::builder("video/x-raw")
|
||||
.field("format", "NV12")
|
||||
.build();
|
||||
video_profile.set_restriction(Some(&restriction));
|
||||
assert_eq!(video_profile.restriction().unwrap(), restriction);
|
||||
}
|
||||
|
@ -619,9 +627,9 @@ mod tests {
|
|||
fn test_encoding_container_profile_builder() {
|
||||
gst::init().unwrap();
|
||||
|
||||
let container_caps = gst::Caps::new_simple("container/x-caps", &[]);
|
||||
let video_caps = gst::Caps::new_simple("video/x-raw", &[]);
|
||||
let audio_caps = gst::Caps::new_simple("audio/x-raw", &[]);
|
||||
let container_caps = gst::Caps::builder("container/x-caps").build();
|
||||
let video_caps = gst::Caps::builder("video/x-raw").build();
|
||||
let audio_caps = gst::Caps::builder("audio/x-raw").build();
|
||||
|
||||
let video_profile = EncodingVideoProfile::builder(&video_caps)
|
||||
.name(VIDEO_PROFILE_NAME)
|
||||
|
|
|
@ -1058,19 +1058,16 @@ mod tests {
|
|||
fn test_from_to_caps() {
|
||||
gst::init().unwrap();
|
||||
|
||||
let caps = gst::Caps::new_simple(
|
||||
"video/x-raw",
|
||||
&[
|
||||
("format", &"I420"),
|
||||
("width", &320),
|
||||
("height", &240),
|
||||
("framerate", &gst::Fraction::new(30, 1)),
|
||||
("pixel-aspect-ratio", &gst::Fraction::new(1, 1)),
|
||||
("interlace-mode", &"progressive"),
|
||||
("chroma-site", &"mpeg2"),
|
||||
("colorimetry", &"bt709"),
|
||||
],
|
||||
);
|
||||
let caps = gst::Caps::builder("video/x-raw")
|
||||
.field("format", "I420")
|
||||
.field("width", 320)
|
||||
.field("height", 240)
|
||||
.field("framerate", gst::Fraction::new(30, 1))
|
||||
.field("pixel-aspect-ratio", gst::Fraction::new(1, 1))
|
||||
.field("interlace-mode", "progressive")
|
||||
.field("chroma-site", "mpeg2")
|
||||
.field("colorimetry", "bt709")
|
||||
.build();
|
||||
let info = VideoInfo::from_caps(&caps).unwrap();
|
||||
assert_eq!(info.format(), crate::VideoFormat::I420);
|
||||
assert_eq!(info.width(), 320);
|
||||
|
|
|
@ -373,7 +373,7 @@ mod tests {
|
|||
|
||||
let pool = crate::BufferPool::new();
|
||||
let mut config = pool.config();
|
||||
config.set_params(Some(&crate::Caps::new_simple("foo/bar", &[])), 1024, 0, 2);
|
||||
config.set_params(Some(&crate::Caps::builder("foo/bar").build()), 1024, 0, 2);
|
||||
pool.set_config(config).unwrap();
|
||||
|
||||
pool.set_active(true).unwrap();
|
||||
|
|
|
@ -901,7 +901,7 @@ mod tests {
|
|||
fn test_display() {
|
||||
crate::init().unwrap();
|
||||
|
||||
let caps = Caps::new_simple("foo/bar", &[]);
|
||||
let caps = Caps::builder("foo/bar").build();
|
||||
format!("{}", caps);
|
||||
}
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ mod tests {
|
|||
});
|
||||
|
||||
thread::spawn(move || {
|
||||
promise.reply(Some(crate::Structure::new("foo/bar", &[])));
|
||||
promise.reply(Some(crate::Structure::new_empty("foo/bar")));
|
||||
});
|
||||
|
||||
let res = receiver.recv().unwrap();
|
||||
|
|
|
@ -231,21 +231,18 @@ mod tests {
|
|||
let s: Structure = ron::de::from_str(s_ron).unwrap();
|
||||
assert_eq!(
|
||||
s.as_ref(),
|
||||
Structure::new(
|
||||
"test",
|
||||
&[
|
||||
("f1", &"abc"),
|
||||
("f2", &"bcd"),
|
||||
("f3", &123),
|
||||
("date", &Date::new_dmy(19, DateMonth::August, 2019).unwrap()),
|
||||
(
|
||||
Structure::builder("test")
|
||||
.field("f1", "abc")
|
||||
.field("f2", "bcd")
|
||||
.field("f3", 123)
|
||||
.field("date", Date::new_dmy(19, DateMonth::August, 2019).unwrap())
|
||||
.field(
|
||||
"date_time",
|
||||
&DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64).unwrap()
|
||||
),
|
||||
("fraction", &Fraction::new(1, 2)),
|
||||
("array", &Array::new(&[&1, &2])),
|
||||
],
|
||||
DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64).unwrap()
|
||||
)
|
||||
.field("fraction", Fraction::new(1, 2))
|
||||
.field("array", Array::new(&[&1, &2]))
|
||||
.build()
|
||||
.as_ref()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ mod tests {
|
|||
|
||||
assert_eq!(
|
||||
typefind.caps,
|
||||
Some(Caps::new_simple("application/xml", &[]))
|
||||
Some(Caps::builder("application/xml").build())
|
||||
);
|
||||
assert_eq!(typefind.probability, Some(TypeFindProbability::Minimum));
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ mod tests {
|
|||
"test_typefind",
|
||||
crate::Rank::Primary,
|
||||
None,
|
||||
Some(&Caps::new_simple("test/test", &[])),
|
||||
Some(&Caps::builder("test/test").build()),
|
||||
|typefind| {
|
||||
assert_eq!(typefind.length(), Some(8));
|
||||
let mut found = false;
|
||||
|
@ -295,7 +295,7 @@ mod tests {
|
|||
if found {
|
||||
typefind.suggest(
|
||||
TypeFindProbability::Likely,
|
||||
&Caps::new_simple("test/test", &[]),
|
||||
&Caps::builder("test/test").build(),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
@ -306,7 +306,7 @@ mod tests {
|
|||
let data = &data[..];
|
||||
let (probability, caps) = SliceTypeFind::type_find(&data);
|
||||
|
||||
assert_eq!(caps, Some(Caps::new_simple("test/test", &[])));
|
||||
assert_eq!(caps, Some(Caps::builder("test/test").build()));
|
||||
assert_eq!(probability, TypeFindProbability::Likely);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue