@@ -536,6 +536,61 @@ def test_pipewire_router_reapplies_controls_when_processing_link_becomes_active(
536536 assert applied == ["apply" , "apply" ]
537537
538538
539+ def test_pipewire_router_reroutes_tracked_stream_when_relinked_away (
540+ monkeypatch : pytest .MonkeyPatch ,
541+ ) -> None :
542+ spotify = make_node (1 , pw_backend .STREAM_OUTPUT_AUDIO , "spotify" , "Spotify" )
543+ speakers = make_node (22 , pw_backend .AUDIO_SINK , "speakers" )
544+ backend = FakePipeWireBackend ([spotify ], sinks = [speakers ])
545+ router = pw_router .PipeWireStreamRouter ("mini_eq_sink" , "mini_eq_sink_output" , lambda _message : None , backend )
546+ scheduled_callbacks : list [object ] = []
547+
548+ monkeypatch .setattr (
549+ pw_router .GLib ,
550+ "idle_add" ,
551+ lambda callback : scheduled_callbacks .append (callback ) or 321 ,
552+ )
553+
554+ router .enabled = True
555+ router .accept_stream_events = True
556+ router .routed_stream_ids = {spotify .bound_id }
557+ router .handle_object_added (None , make_link (92 , output_node_id = spotify .bound_id , input_node_id = speakers .bound_id ))
558+
559+ assert len (scheduled_callbacks ) == 1
560+ scheduled_callbacks [0 ]()
561+
562+ assert backend .moves == [(spotify .bound_id , "mini_eq_sink" )]
563+
564+
565+ def test_pipewire_router_reroutes_tracked_stream_when_current_link_disappears (
566+ monkeypatch : pytest .MonkeyPatch ,
567+ ) -> None :
568+ spotify = make_node (1 , pw_backend .STREAM_OUTPUT_AUDIO , "spotify" , "Spotify" )
569+ virtual_sink = make_node (11 , pw_backend .AUDIO_SINK , "mini_eq_sink" )
570+ backend = FakePipeWireBackend ([spotify ], sinks = [virtual_sink ])
571+ router = pw_router .PipeWireStreamRouter ("mini_eq_sink" , "mini_eq_sink_output" , lambda _message : None , backend )
572+ scheduled_callbacks : list [object ] = []
573+
574+ monkeypatch .setattr (
575+ pw_router .GLib ,
576+ "idle_add" ,
577+ lambda callback : scheduled_callbacks .append (callback ) or 321 ,
578+ )
579+
580+ router .enabled = True
581+ router .accept_stream_events = True
582+ router .routed_stream_ids = {spotify .bound_id }
583+ router .handle_object_removed (
584+ None ,
585+ make_link (92 , output_node_id = spotify .bound_id , input_node_id = virtual_sink .bound_id ),
586+ )
587+
588+ assert len (scheduled_callbacks ) == 1
589+ scheduled_callbacks [0 ]()
590+
591+ assert backend .moves == [(spotify .bound_id , "mini_eq_sink" )]
592+
593+
539594def test_pipewire_router_tracks_internal_output_links (monkeypatch : pytest .MonkeyPatch ) -> None :
540595 internal_output = make_node (90 , pw_backend .STREAM_OUTPUT_AUDIO , "mini_eq_sink_output" )
541596 backend = FakePipeWireBackend ([internal_output ], sinks = [make_node (22 , pw_backend .AUDIO_SINK , "speakers" )])
0 commit comments