mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-23 02:26:35 +00:00
Slightly improve code making use of element factories retrieved from an element
We can use `is_some_and(...)` instead of `map_or(false, ...)`. Also in a few places the factory was retrieved multiple times, one time with unwrapping and another time with handling the `None` case correctly. Instead of unwrapping, move code to handle the `None` case. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1630>
This commit is contained in:
parent
8f96509f03
commit
23d998a1db
4 changed files with 27 additions and 27 deletions
|
@ -740,7 +740,11 @@ impl ObjectImpl for S3HlsSink {
|
||||||
|
|
||||||
// The signature on delete-fragment signal is different for
|
// The signature on delete-fragment signal is different for
|
||||||
// hlssink2 and hlssink3.
|
// hlssink2 and hlssink3.
|
||||||
if self_.hlssink.factory().unwrap().name().contains("hlssink3") {
|
if self_
|
||||||
|
.hlssink
|
||||||
|
.factory()
|
||||||
|
.is_some_and(|factory| factory.name() == "hlssink3")
|
||||||
|
{
|
||||||
if res.is_ok() {
|
if res.is_ok() {
|
||||||
Some(true.to_value())
|
Some(true.to_value())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -40,11 +40,12 @@ fn main() -> Result<(), Error> {
|
||||||
pipeline.connect("deep-element-added", false, |values| {
|
pipeline.connect("deep-element-added", false, |values| {
|
||||||
let element = values[2].get::<gst::Element>().unwrap();
|
let element = values[2].get::<gst::Element>().unwrap();
|
||||||
|
|
||||||
if let Some(factory) = element.factory() {
|
if element
|
||||||
if factory.name().as_str() == "videoscale" {
|
.factory()
|
||||||
println!("Tuning videoscale");
|
.is_some_and(|factory| factory.name() == "videoscale")
|
||||||
element.set_property_from_str("method", "lanczos");
|
{
|
||||||
}
|
println!("Tuning videoscale");
|
||||||
|
element.set_property_from_str("method", "lanczos");
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
|
@ -61,9 +62,9 @@ fn main() -> Result<(), Error> {
|
||||||
webrtcsink.connect("encoder-setup", true, |values| {
|
webrtcsink.connect("encoder-setup", true, |values| {
|
||||||
let encoder = values[3].get::<gst::Element>().unwrap();
|
let encoder = values[3].get::<gst::Element>().unwrap();
|
||||||
|
|
||||||
println!("Encoder: {}", encoder.factory().unwrap().name());
|
|
||||||
|
|
||||||
if let Some(factory) = encoder.factory() {
|
if let Some(factory) = encoder.factory() {
|
||||||
|
println!("Encoder: {}", factory.name());
|
||||||
|
|
||||||
match factory.name().as_str() {
|
match factory.name().as_str() {
|
||||||
"x264enc" => {
|
"x264enc" => {
|
||||||
println!("Applying extra configuration to x264enc");
|
println!("Applying extra configuration to x264enc");
|
||||||
|
|
|
@ -137,9 +137,8 @@ async fn run(args: Args) -> Result<(), Error> {
|
||||||
ws.connect("encoder-setup", false, |values| {
|
ws.connect("encoder-setup", false, |values| {
|
||||||
let encoder = values[3].get::<gst::Element>().unwrap();
|
let encoder = values[3].get::<gst::Element>().unwrap();
|
||||||
|
|
||||||
info!("Encoder: {}", encoder.factory().unwrap().name());
|
|
||||||
|
|
||||||
let configured = if let Some(factory) = encoder.factory() {
|
let configured = if let Some(factory) = encoder.factory() {
|
||||||
|
info!("Encoder: {}", factory.name());
|
||||||
matches!(factory.name().as_str(), "does-not-exist")
|
matches!(factory.name().as_str(), "does-not-exist")
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
|
@ -559,7 +559,7 @@ fn make_converter_for_video_caps(caps: &gst::Caps, codec: &Codec) -> Result<gst:
|
||||||
// corresponding converter
|
// corresponding converter
|
||||||
|| codec
|
|| codec
|
||||||
.encoder_factory()
|
.encoder_factory()
|
||||||
.map_or(false, |factory| factory.name().starts_with("nvv4l2"))
|
.is_some_and(|factory| factory.name().starts_with("nvv4l2"))
|
||||||
{
|
{
|
||||||
let queue = make_element("queue", None)?;
|
let queue = make_element("queue", None)?;
|
||||||
let nvconvert = if let Ok(nvconvert) = make_element("nvvideoconvert", None) {
|
let nvconvert = if let Ok(nvconvert) = make_element("nvvideoconvert", None) {
|
||||||
|
@ -788,15 +788,17 @@ fn configure_encoder(enc: &gst::Element, start_bitrate: u32) {
|
||||||
fn configure_payloader(pay: &gst::Element) {
|
fn configure_payloader(pay: &gst::Element) {
|
||||||
pay.set_property("mtu", 1200_u32);
|
pay.set_property("mtu", 1200_u32);
|
||||||
|
|
||||||
match pay.factory().unwrap().name().as_str() {
|
if let Some(factory) = pay.factory() {
|
||||||
"rtpvp8pay" | "rtpvp9pay" => {
|
match factory.name().as_str() {
|
||||||
pay.set_property_from_str("picture-id-mode", "15-bit");
|
"rtpvp8pay" | "rtpvp9pay" => {
|
||||||
|
pay.set_property_from_str("picture-id-mode", "15-bit");
|
||||||
|
}
|
||||||
|
"rtph264pay" | "rtph265pay" => {
|
||||||
|
pay.set_property_from_str("aggregate-mode", "zero-latency");
|
||||||
|
pay.set_property("config-interval", -1i32);
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
"rtph264pay" | "rtph265pay" => {
|
|
||||||
pay.set_property_from_str("aggregate-mode", "zero-latency");
|
|
||||||
pay.set_property("config-interval", -1i32);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -950,13 +952,7 @@ impl VideoEncoder {
|
||||||
) -> Option<Self> {
|
) -> Option<Self> {
|
||||||
let halved_framerate = video_info.fps().mul(gst::Fraction::new(1, 2));
|
let halved_framerate = video_info.fps().mul(gst::Fraction::new(1, 2));
|
||||||
Some(Self {
|
Some(Self {
|
||||||
factory_name: encoding_elements
|
factory_name: encoding_elements.encoder.as_ref()?.factory()?.name().into(),
|
||||||
.encoder
|
|
||||||
.as_ref()?
|
|
||||||
.factory()
|
|
||||||
.unwrap()
|
|
||||||
.name()
|
|
||||||
.into(),
|
|
||||||
codec_name: codec_name.to_string(),
|
codec_name: codec_name.to_string(),
|
||||||
element: encoding_elements.encoder.as_ref()?.clone(),
|
element: encoding_elements.encoder.as_ref()?.clone(),
|
||||||
filter: encoding_elements.raw_filter.as_ref()?.clone(),
|
filter: encoding_elements.raw_filter.as_ref()?.clone(),
|
||||||
|
@ -2634,7 +2630,7 @@ impl BaseWebRTCSink {
|
||||||
glib::closure!(@watch element, @strong session_id
|
glib::closure!(@watch element, @strong session_id
|
||||||
=> move |_webrtcbin: gst::Element, _bin: gst::Bin, e: gst::Element| {
|
=> move |_webrtcbin: gst::Element, _bin: gst::Bin, e: gst::Element| {
|
||||||
|
|
||||||
if e.factory().map_or(false, |f| f.name() == "rtprtxsend") {
|
if e.factory().is_some_and(|f| f.name() == "rtprtxsend") {
|
||||||
if e.has_property("stuffing-kbps", Some(i32::static_type())) {
|
if e.has_property("stuffing-kbps", Some(i32::static_type())) {
|
||||||
element.imp().set_rtptrxsend(element, &session_id, e);
|
element.imp().set_rtptrxsend(element, &session_id, e);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue