forge
Explore
Log in

Don't you dare go Hollow

pw_utils: change early return to match in modifier negotiation

Browse files at this commit

3644e03d2fb229994b324e3a248d2359a2ccdde6wrvsrxParent: aa1f64c
This commit is preparation for supporting shared memory sharing
src/screencasting/pw_utils.rsmodified+218 -202
@@ -448,150 +448,53 @@ impl PipeWire {
448448 );
449449 inner.min_time_between_frames = min_frame_time;
450450
451+ // We have following cases when param_changed:
452+ //
453+ // 1. Modifier exists and its flags contain DONT_FIXATE
454+ //
455+ // Do test allocation, set CastState to ConfirmationPending and send param
456+ // again.
457+ //
458+ // 2. Modifier exists and it doesn't need fixation
459+ //
460+ // Do test allocation to ensure the modifier work, then set CastState to
461+ // Ready. Then set buffer to DMA.
462+ //
463+ // 3. Modifier doesn't exist
464+ //
465+ // TODO: set CastState to Ready and set buffer to SHM.
466+
451467 let object = pod.as_object().unwrap();
452- let Some(prop_modifier) =
453- object.find_prop(spa::utils::Id(FormatProperties::VideoModifier.0))
454- else {
455- warn!("modifier prop missing");
456- stop_cast();
457- return;
458- };
468+ let maybe_prop_modifier = object.find_prop(spa::utils::Id(FormatProperties::VideoModifier.0));
459469
460- if prop_modifier.flags().contains(PodPropFlags::DONT_FIXATE) {
461- debug!("fixating the modifier");
470+ match maybe_prop_modifier {
471+ Some(prop_modifier) if prop_modifier.flags().contains(PodPropFlags::DONT_FIXATE) => {
472+ debug!("fixating the modifier");
462473
463- let pod_modifier = prop_modifier.value();
464- let Ok((_, modifiers)) = PodDeserializer::deserialize_from::<Choice<i64>>(
465- pod_modifier.as_bytes(),
466- ) else {
467- warn!("wrong modifier property type");
468- stop_cast();
469- return;
470- };
471-
472- let ChoiceEnum::Enum { alternatives, .. } = modifiers.1 else {
473- warn!("wrong modifier choice type");
474- stop_cast();
475- return;
476- };
477-
478- let (modifier, plane_count) = match find_preferred_modifier(
479- &gbm,
480- format_size,
481- fourcc,
482- alternatives,
483- ) {
484- Ok(x) => x,
485- Err(err) => {
486- warn!("couldn't find preferred modifier: {err:?}");
474+ let pod_modifier = prop_modifier.value();
475+ let Ok((_, modifiers)) = PodDeserializer::deserialize_from::<Choice<i64>>(
476+ pod_modifier.as_bytes(),
477+ ) else {
478+ warn!("wrong modifier property type");
487479 stop_cast();
488480 return;
489- }
490- };
491-
492- debug!(
493- "allocation successful \
494- (modifier={modifier:?}, plane_count={plane_count}), \
495- moving to confirmation pending"
496- );
497-
498- *state = CastState::ConfirmationPending {
499- size: format_size,
500- alpha: format_has_alpha,
501- dma_negotiation: DmaNegotiation {
502- modifier,
503- plane_count: plane_count as i32,
504- },
505- };
506-
507- let fixated_format = FormatSet::from_iter([Format {
508- code: fourcc,
509- modifier,
510- }]);
511-
512- let mut b1 = Vec::new();
513- let mut b2 = Vec::new();
514-
515- let o1 = make_video_params(
516- &fixated_format,
517- format_size,
518- inner.refresh,
519- format_has_alpha,
520- );
521- let pod1 = make_pod(&mut b1, o1);
522-
523- let o2 = make_video_params(
524- &formats,
525- format_size,
526- inner.refresh,
527- format_has_alpha,
528- );
529- let mut params = [pod1, make_pod(&mut b2, o2)];
530-
531- if let Err(err) = stream.update_params(&mut params) {
532- warn!("error updating stream params: {err:?}");
533- stop_cast();
534- }
535-
536- return;
537- }
481+ };
538482
539- // Verify that alpha and modifier didn't change.
540- let plane_count = match &*state {
541- CastState::ConfirmationPending {
542- size,
543- alpha,
544- dma_negotiation,
545- }
546- | CastState::Ready {
547- size,
548- alpha,
549- dma_negotiation,
550- ..
551- } if *alpha == format_has_alpha
552- && dma_negotiation.modifier == Modifier::from(format.modifier()) =>
553- {
554- let size = *size;
555- let alpha = *alpha;
556- let dma_negotiation = *dma_negotiation;
557-
558- let (damage_tracker, cursor_damage_tracker) =
559- if let CastState::Ready {
560- damage_tracker,
561- cursor_damage_tracker,
562- ..
563- } = &mut *state
564- {
565- (damage_tracker.take(), cursor_damage_tracker.take())
566- } else {
567- (None, None)
568- };
569-
570- debug!("moving to ready state");
571-
572- *state = CastState::Ready {
573- size,
574- alpha,
575- dma_negotiation,
576- damage_tracker,
577- cursor_damage_tracker,
578- last_cursor_location: None,
483+ let ChoiceEnum::Enum { alternatives, .. } = modifiers.1 else {
484+ warn!("wrong modifier choice type");
485+ stop_cast();
486+ return;
579487 };
580488
581- dma_negotiation.plane_count
582- }
583- _ => {
584- // We're negotiating a single modifier, or alpha or modifier changed,
585- // so we need to do a test allocation.
586489 let (modifier, plane_count) = match find_preferred_modifier(
587490 &gbm,
588491 format_size,
589492 fourcc,
590- vec![format.modifier() as i64],
493+ alternatives,
591494 ) {
592495 Ok(x) => x,
593496 Err(err) => {
594- warn!("test allocation failed: {err:?}");
497+ warn!("couldn't find preferred modifier: {err:?}");
595498 stop_cast();
596499 return;
597500 }
@@ -600,93 +503,206 @@ impl PipeWire {
600503 debug!(
601504 "allocation successful \
602505 (modifier={modifier:?}, plane_count={plane_count}), \
603- moving to ready"
506+ moving to confirmation pending"
604507 );
605508
606- *state = CastState::Ready {
509+ *state = CastState::ConfirmationPending {
607510 size: format_size,
608511 alpha: format_has_alpha,
609512 dma_negotiation: DmaNegotiation {
610513 modifier,
611514 plane_count: plane_count as i32,
612515 },
613- damage_tracker: None,
614- cursor_damage_tracker: None,
615- last_cursor_location: None,
616516 };
617517
618- plane_count as i32
619- }
620- };
518+ let fixated_format = FormatSet::from_iter([Format {
519+ code: fourcc,
520+ modifier,
521+ }]);
522+
523+ let mut b1 = Vec::new();
524+ let mut b2 = Vec::new();
525+
526+ let o1 = make_video_params(
527+ &fixated_format,
528+ format_size,
529+ inner.refresh,
530+ format_has_alpha,
531+ );
532+ let pod1 = make_pod(&mut b1, o1);
533+
534+ let o2 = make_video_params(
535+ &formats,
536+ format_size,
537+ inner.refresh,
538+ format_has_alpha,
539+ );
540+ let mut params = [pod1, make_pod(&mut b2, o2)];
621541
622- // const BPP: u32 = 4;
623- // let stride = format.size().width * BPP;
624- // let size = stride * format.size().height;
625-
626- let o1 = pod::object!(
627- SpaTypes::ObjectParamBuffers,
628- ParamType::Buffers,
629- Property::new(
630- SPA_PARAM_BUFFERS_buffers,
631- pod::Value::Choice(ChoiceValue::Int(Choice(
632- ChoiceFlags::empty(),
633- ChoiceEnum::Range {
634- default: 8,
635- min: 2,
636- max: 16
542+ if let Err(err) = stream.update_params(&mut params) {
543+ warn!("error updating stream params: {err:?}");
544+ stop_cast();
545+ }
546+ }
547+ Some(_) => {
548+ // Verify that alpha and modifier didn't change.
549+ let plane_count = match &*state {
550+ CastState::ConfirmationPending {
551+ size,
552+ alpha,
553+ dma_negotiation,
637554 }
638- ))),
639- ),
640- Property::new(SPA_PARAM_BUFFERS_blocks, pod::Value::Int(plane_count)),
641- Property::new(
642- SPA_PARAM_BUFFERS_dataType,
643- pod::Value::Choice(ChoiceValue::Int(Choice(
644- ChoiceFlags::empty(),
645- ChoiceEnum::Flags {
646- default: 1 << DataType::DmaBuf.as_raw(),
647- flags: vec![1 << DataType::DmaBuf.as_raw()],
648- },
649- ))),
650- ),
651- );
555+ | CastState::Ready {
556+ size,
557+ alpha,
558+ dma_negotiation,
559+ ..
560+ } if *alpha == format_has_alpha
561+ && dma_negotiation.modifier
562+ == Modifier::from(format.modifier()) =>
563+ {
564+ let size = *size;
565+ let alpha = *alpha;
566+ let dma_negotiation = *dma_negotiation;
567+
568+ let (damage_tracker, cursor_damage_tracker) =
569+ if let CastState::Ready {
570+ damage_tracker,
571+ cursor_damage_tracker,
572+ ..
573+ } = &mut *state
574+ {
575+ (damage_tracker.take(), cursor_damage_tracker.take())
576+ } else {
577+ (None, None)
578+ };
579+
580+ debug!("moving to ready state");
581+
582+ *state = CastState::Ready {
583+ size,
584+ alpha,
585+ dma_negotiation,
586+ damage_tracker,
587+ cursor_damage_tracker,
588+ last_cursor_location: None,
589+ };
590+
591+ dma_negotiation.plane_count
592+ }
593+ _ => {
594+ // We're negotiating a single modifier, or alpha or modifier changed,
595+ // so we need to do a test allocation.
596+ let (modifier, plane_count) = match find_preferred_modifier(
597+ &gbm,
598+ format_size,
599+ fourcc,
600+ vec![format.modifier() as i64],
601+ ) {
602+ Ok(x) => x,
603+ Err(err) => {
604+ warn!("test allocation failed: {err:?}");
605+ stop_cast();
606+ return;
607+ }
608+ };
609+
610+ debug!(
611+ "allocation successful \
612+ (modifier={modifier:?}, plane_count={plane_count}), \
613+ moving to ready"
614+ );
615+
616+ *state = CastState::Ready {
617+ size: format_size,
618+ alpha: format_has_alpha,
619+ dma_negotiation: DmaNegotiation {
620+ modifier,
621+ plane_count: plane_count as i32,
622+ },
623+ damage_tracker: None,
624+ cursor_damage_tracker: None,
625+ last_cursor_location: None,
626+ };
627+
628+ plane_count as i32
629+ }
630+ };
652631
653- let o2 = pod::object!(
654- SpaTypes::ObjectParamMeta,
655- ParamType::Meta,
656- Property::new(
657- SPA_PARAM_META_type,
658- pod::Value::Id(spa::utils::Id(SPA_META_Header))
659- ),
660- Property::new(
661- SPA_PARAM_META_size,
662- pod::Value::Int(size_of::<spa_meta_header>() as i32)
663- ),
664- );
665- let mut b1 = vec![];
666- let mut b2 = vec![];
667- let mut params = vec![make_pod(&mut b1, o1), make_pod(&mut b2, o2)];
668-
669- let mut b_cursor = vec![];
670- if cursor_mode == CursorMode::Metadata {
671- let o_cursor = pod::object!(
672- SpaTypes::ObjectParamMeta,
673- ParamType::Meta,
674- Property::new(
675- SPA_PARAM_META_type,
676- pod::Value::Id(spa::utils::Id(SPA_META_Cursor))
677- ),
678- Property::new(
679- SPA_PARAM_META_size,
680- pod::Value::Int(CURSOR_META_SIZE as i32)
681- ),
682- );
683- params.push(make_pod(&mut b_cursor, o_cursor));
684- }
632+ // const BPP: u32 = 4;
633+ // let stride = format.size().width * BPP;
634+ // let size = stride * format.size().height;
635+
636+ let o1 = pod::object!(
637+ SpaTypes::ObjectParamBuffers,
638+ ParamType::Buffers,
639+ Property::new(
640+ SPA_PARAM_BUFFERS_buffers,
641+ pod::Value::Choice(ChoiceValue::Int(Choice(
642+ ChoiceFlags::empty(),
643+ ChoiceEnum::Range {
644+ default: 8,
645+ min: 2,
646+ max: 16
647+ }
648+ ))),
649+ ),
650+ Property::new(SPA_PARAM_BUFFERS_blocks, pod::Value::Int(plane_count)),
651+ Property::new(
652+ SPA_PARAM_BUFFERS_dataType,
653+ pod::Value::Choice(ChoiceValue::Int(Choice(
654+ ChoiceFlags::empty(),
655+ ChoiceEnum::Flags {
656+ default: 1 << DataType::DmaBuf.as_raw(),
657+ flags: vec![1 << DataType::DmaBuf.as_raw()],
658+ },
659+ ))),
660+ ),
661+ );
685662
686- if let Err(err) = stream.update_params(&mut params) {
687- warn!("error updating stream params: {err:?}");
688- stop_cast();
689- }
663+ let o2 = pod::object!(
664+ SpaTypes::ObjectParamMeta,
665+ ParamType::Meta,
666+ Property::new(
667+ SPA_PARAM_META_type,
668+ pod::Value::Id(spa::utils::Id(SPA_META_Header))
669+ ),
670+ Property::new(
671+ SPA_PARAM_META_size,
672+ pod::Value::Int(size_of::<spa_meta_header>() as i32)
673+ ),
674+ );
675+ let mut b1 = vec![];
676+ let mut b2 = vec![];
677+ let mut params = vec![make_pod(&mut b1, o1), make_pod(&mut b2, o2)];
678+
679+ let mut b_cursor = vec![];
680+ if cursor_mode == CursorMode::Metadata {
681+ let o_cursor = pod::object!(
682+ SpaTypes::ObjectParamMeta,
683+ ParamType::Meta,
684+ Property::new(
685+ SPA_PARAM_META_type,
686+ pod::Value::Id(spa::utils::Id(SPA_META_Cursor))
687+ ),
688+ Property::new(
689+ SPA_PARAM_META_size,
690+ pod::Value::Int(CURSOR_META_SIZE as i32)
691+ ),
692+ );
693+ params.push(make_pod(&mut b_cursor, o_cursor));
694+ }
695+
696+ if let Err(err) = stream.update_params(&mut params) {
697+ warn!("error updating stream params: {err:?}");
698+ stop_cast();
699+ }
700+ }
701+ None => {
702+ warn!("pw stream: modifier prop missing and we don't support shared memory sharing currently");
703+ stop_cast();
704+ }
705+ };
690706 }
691707 })
692708 .add_buffer({