diff --git a/src/screencasting/pw_utils.rs b/src/screencasting/pw_utils.rs index d0af82ae..604df8fa 100644 --- a/src/screencasting/pw_utils.rs +++ b/src/screencasting/pw_utils.rs @@ -587,10 +587,10 @@ impl PipeWire { // Set CastState to Ready and set buffer to SHM. let object = pod.as_object().unwrap(); - let maybe_prop_modifier = + let prop_modifier = object.find_prop(spa::utils::Id(FormatProperties::VideoModifier.0)); - match maybe_prop_modifier { + match prop_modifier { Some(prop_modifier) if prop_modifier.flags().contains(PodPropFlags::DONT_FIXATE) => { @@ -664,214 +664,205 @@ impl PipeWire { warn!("error updating stream params: {err:?}"); stop_cast(); } + + return; } - _ => { - let o1 = match maybe_prop_modifier { - Some(_) => { - // Verify that alpha and modifier didn't change. - let plane_count = match &*state { - CastState::ConfirmationPending { - size, - alpha, - dma_negotiation: Some(dma_negotiation), - } - | CastState::Ready { - size, - alpha, - dma_negotiation: Some(dma_negotiation), - .. - } if *alpha == format_has_alpha - && dma_negotiation.modifier - == Modifier::from(format.modifier()) => - { - let size = *size; - let alpha = *alpha; - let dma_negotiation = *dma_negotiation; - - let (damage_tracker, cursor_damage_tracker) = - if let CastState::Ready { - damage_tracker, - cursor_damage_tracker, - .. - } = &mut *state - { - ( - damage_tracker.take(), - cursor_damage_tracker.take(), - ) - } else { - (None, None) - }; - - debug!("moving to ready state"); - - *state = CastState::Ready { - size, - alpha, - dma_negotiation: Some(dma_negotiation), - damage_tracker, - cursor_damage_tracker, - last_cursor_location: None, - }; - - dma_negotiation.plane_count - } - _ => { - // We're negotiating a single modifier, or alpha or - // modifier changed, so we need to do a test - // allocation. - let (modifier, plane_count) = - match find_preferred_modifier( - &gbm, - format_size, - fourcc, - vec![format.modifier() as i64], - ) { - Ok(x) => x, - Err(err) => { - warn!( - "test allocation failed: {err:?}" - ); - stop_cast(); - return; - } - }; - - debug!( - "allocation successful \ - (modifier={modifier:?}, \ - plane_count={plane_count}), \ - moving to ready" - ); - - *state = CastState::Ready { - size: format_size, - alpha: format_has_alpha, - dma_negotiation: Some(DmaNegotiation { - modifier, - plane_count: plane_count as i32, - }), - damage_tracker: None, - cursor_damage_tracker: None, - last_cursor_location: None, - }; - - plane_count as i32 - } - }; + _ => (), + } - pod::object!( - SpaTypes::ObjectParamBuffers, - ParamType::Buffers, - Property::new( - SPA_PARAM_BUFFERS_buffers, - pod::Value::Choice(ChoiceValue::Int(Choice( - ChoiceFlags::empty(), - ChoiceEnum::Range { - default: 8, - min: 2, - max: 16 - } - ))), - ), - Property::new( - SPA_PARAM_BUFFERS_blocks, - pod::Value::Int(plane_count) - ), - Property::new( - SPA_PARAM_BUFFERS_dataType, - pod::Value::Choice(ChoiceValue::Int(Choice( - ChoiceFlags::empty(), - ChoiceEnum::Flags { - default: 1 << DataType::DmaBuf.as_raw(), - flags: vec![1 << DataType::DmaBuf.as_raw()], - }, - ))), - ), - ) - } - None => { - *state = CastState::Ready { - size: format_size, - alpha: format_has_alpha, - dma_negotiation: None, - damage_tracker: None, - cursor_damage_tracker: None, - last_cursor_location: None, + let o1 = if prop_modifier.is_some() { + // Verify that alpha and modifier didn't change. + let plane_count = match &*state { + CastState::ConfirmationPending { + size, + alpha, + dma_negotiation: Some(dma_negotiation), + } + | CastState::Ready { + size, + alpha, + dma_negotiation: Some(dma_negotiation), + .. + } if *alpha == format_has_alpha + && dma_negotiation.modifier + == Modifier::from(format.modifier()) => + { + let size = *size; + let alpha = *alpha; + let dma_negotiation = *dma_negotiation; + + let (damage_tracker, cursor_damage_tracker) = + if let CastState::Ready { + damage_tracker, + cursor_damage_tracker, + .. + } = &mut *state + { + (damage_tracker.take(), cursor_damage_tracker.take()) + } else { + (None, None) }; - pod::object!( - SpaTypes::ObjectParamBuffers, - ParamType::Buffers, - Property::new( - SPA_PARAM_BUFFERS_buffers, - pod::Value::Choice(ChoiceValue::Int(Choice( - ChoiceFlags::empty(), - ChoiceEnum::Range { - default: 8, - min: 2, - max: 16 - } - ))), - ), - Property::new( - SPA_PARAM_BUFFERS_blocks, - pod::Value::Int(SHM_BLOCKS as i32), - ), - Property::new( - SPA_PARAM_BUFFERS_dataType, - pod::Value::Choice(ChoiceValue::Int(Choice( - ChoiceFlags::empty(), - ChoiceEnum::Flags { - default: 1 << DataType::MemFd.as_raw(), - flags: vec![1 << DataType::MemFd.as_raw()], - }, - ))), - ), - ) - } - }; - let o2 = pod::object!( - SpaTypes::ObjectParamMeta, - ParamType::Meta, - Property::new( - SPA_PARAM_META_type, - pod::Value::Id(spa::utils::Id(SPA_META_Header)) - ), - Property::new( - SPA_PARAM_META_size, - pod::Value::Int(size_of::() as i32) - ), - ); + debug!("moving to ready state"); - let mut b1 = vec![]; - let mut b2 = vec![]; - - let mut params = vec![make_pod(&mut b1, o1), make_pod(&mut b2, o2)]; - - let mut b_cursor = vec![]; - if cursor_mode == CursorMode::Metadata { - let o_cursor = pod::object!( - SpaTypes::ObjectParamMeta, - ParamType::Meta, - Property::new( - SPA_PARAM_META_type, - pod::Value::Id(spa::utils::Id(SPA_META_Cursor)) - ), - Property::new( - SPA_PARAM_META_size, - pod::Value::Int(CURSOR_META_SIZE as i32) - ), - ); - params.push(make_pod(&mut b_cursor, o_cursor)); + *state = CastState::Ready { + size, + alpha, + dma_negotiation: Some(dma_negotiation), + damage_tracker, + cursor_damage_tracker, + last_cursor_location: None, + }; + + dma_negotiation.plane_count } + _ => { + // We're negotiating a single modifier, or alpha or modifier + // changed, so we need to do a test allocation. + let (modifier, plane_count) = match find_preferred_modifier( + &gbm, + format_size, + fourcc, + vec![format.modifier() as i64], + ) { + Ok(x) => x, + Err(err) => { + warn!("test allocation failed: {err:?}"); + stop_cast(); + return; + } + }; - if let Err(err) = stream.update_params(&mut params) { - warn!("error updating stream params: {err:?}"); - stop_cast(); + debug!( + "allocation successful \ + (modifier={modifier:?}, plane_count={plane_count}), \ + moving to ready" + ); + + *state = CastState::Ready { + size: format_size, + alpha: format_has_alpha, + dma_negotiation: Some(DmaNegotiation { + modifier, + plane_count: plane_count as i32, + }), + damage_tracker: None, + cursor_damage_tracker: None, + last_cursor_location: None, + }; + + plane_count as i32 } - } + }; + + pod::object!( + SpaTypes::ObjectParamBuffers, + ParamType::Buffers, + Property::new( + SPA_PARAM_BUFFERS_buffers, + pod::Value::Choice(ChoiceValue::Int(Choice( + ChoiceFlags::empty(), + ChoiceEnum::Range { + default: 8, + min: 2, + max: 16 + } + ))), + ), + Property::new( + SPA_PARAM_BUFFERS_blocks, + pod::Value::Int(plane_count) + ), + Property::new( + SPA_PARAM_BUFFERS_dataType, + pod::Value::Choice(ChoiceValue::Int(Choice( + ChoiceFlags::empty(), + ChoiceEnum::Flags { + default: 1 << DataType::DmaBuf.as_raw(), + flags: vec![1 << DataType::DmaBuf.as_raw()], + }, + ))), + ), + ) + } else { + *state = CastState::Ready { + size: format_size, + alpha: format_has_alpha, + dma_negotiation: None, + damage_tracker: None, + cursor_damage_tracker: None, + last_cursor_location: None, + }; + pod::object!( + SpaTypes::ObjectParamBuffers, + ParamType::Buffers, + Property::new( + SPA_PARAM_BUFFERS_buffers, + pod::Value::Choice(ChoiceValue::Int(Choice( + ChoiceFlags::empty(), + ChoiceEnum::Range { + default: 8, + min: 2, + max: 16 + } + ))), + ), + Property::new( + SPA_PARAM_BUFFERS_blocks, + pod::Value::Int(SHM_BLOCKS as i32), + ), + Property::new( + SPA_PARAM_BUFFERS_dataType, + pod::Value::Choice(ChoiceValue::Int(Choice( + ChoiceFlags::empty(), + ChoiceEnum::Flags { + default: 1 << DataType::MemFd.as_raw(), + flags: vec![1 << DataType::MemFd.as_raw()], + }, + ))), + ), + ) }; + + let o2 = pod::object!( + SpaTypes::ObjectParamMeta, + ParamType::Meta, + Property::new( + SPA_PARAM_META_type, + pod::Value::Id(spa::utils::Id(SPA_META_Header)) + ), + Property::new( + SPA_PARAM_META_size, + pod::Value::Int(size_of::() as i32) + ), + ); + + let mut b1 = vec![]; + let mut b2 = vec![]; + + let mut params = vec![make_pod(&mut b1, o1), make_pod(&mut b2, o2)]; + + let mut b_cursor = vec![]; + if cursor_mode == CursorMode::Metadata { + let o_cursor = pod::object!( + SpaTypes::ObjectParamMeta, + ParamType::Meta, + Property::new( + SPA_PARAM_META_type, + pod::Value::Id(spa::utils::Id(SPA_META_Cursor)) + ), + Property::new( + SPA_PARAM_META_size, + pod::Value::Int(CURSOR_META_SIZE as i32) + ), + ); + params.push(make_pod(&mut b_cursor, o_cursor)); + } + + if let Err(err) = stream.update_params(&mut params) { + warn!("error updating stream params: {err:?}"); + stop_cast(); + } } }) .add_buffer({