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