@@ -496,7 +496,9 @@ mod tests {
496
496
use super :: * ;
497
497
498
498
#[ derive( Debug , Clone ) ]
499
- struct TestNode { }
499
+ struct TestNode {
500
+ tail_time : bool ,
501
+ }
500
502
501
503
impl AudioProcessor for TestNode {
502
504
fn process (
@@ -506,7 +508,7 @@ mod tests {
506
508
_params : AudioParamValues < ' _ > ,
507
509
_scope : & RenderScope ,
508
510
) -> bool {
509
- false
511
+ self . tail_time
510
512
}
511
513
}
512
514
@@ -529,11 +531,15 @@ mod tests {
529
531
graph. add_edge ( ( AudioNodeId ( from) , 0 ) , ( AudioNodeId ( to) , 0 ) ) ;
530
532
}
531
533
534
+ fn add_audioparam ( graph : & mut Graph , from : u64 , to : u64 ) {
535
+ graph. add_edge ( ( AudioNodeId ( from) , 0 ) , ( AudioNodeId ( to) , usize:: MAX ) ) ;
536
+ }
537
+
532
538
#[ test]
533
539
fn test_add_remove ( ) {
534
540
let mut graph = Graph :: new ( llq:: Queue :: new ( ) . split ( ) . 0 ) ;
535
541
536
- let node = Box :: new ( TestNode { } ) ;
542
+ let node = Box :: new ( TestNode { tail_time : false } ) ;
537
543
add_node ( & mut graph, 0 , node. clone ( ) ) ;
538
544
add_node ( & mut graph, 1 , node. clone ( ) ) ;
539
545
add_node ( & mut graph, 2 , node. clone ( ) ) ;
@@ -584,7 +590,7 @@ mod tests {
584
590
fn test_remove_all ( ) {
585
591
let mut graph = Graph :: new ( llq:: Queue :: new ( ) . split ( ) . 0 ) ;
586
592
587
- let node = Box :: new ( TestNode { } ) ;
593
+ let node = Box :: new ( TestNode { tail_time : false } ) ;
588
594
add_node ( & mut graph, 0 , node. clone ( ) ) ;
589
595
add_node ( & mut graph, 1 , node. clone ( ) ) ;
590
596
add_node ( & mut graph, 2 , node) ;
@@ -623,7 +629,7 @@ mod tests {
623
629
fn test_cycle ( ) {
624
630
let mut graph = Graph :: new ( llq:: Queue :: new ( ) . split ( ) . 0 ) ;
625
631
626
- let node = Box :: new ( TestNode { } ) ;
632
+ let node = Box :: new ( TestNode { tail_time : false } ) ;
627
633
add_node ( & mut graph, 0 , node. clone ( ) ) ;
628
634
add_node ( & mut graph, 1 , node. clone ( ) ) ;
629
635
add_node ( & mut graph, 2 , node. clone ( ) ) ;
@@ -659,7 +665,7 @@ mod tests {
659
665
let ( node_id_producer, mut node_id_consumer) = llq:: Queue :: new ( ) . split ( ) ;
660
666
let mut graph = Graph :: new ( node_id_producer) ;
661
667
662
- let node = Box :: new ( TestNode { } ) ;
668
+ let node = Box :: new ( TestNode { tail_time : false } ) ;
663
669
664
670
// Destination Node is always node id 0, and should never drop
665
671
add_node ( & mut graph, 0 , node. clone ( ) ) ;
@@ -691,5 +697,55 @@ mod tests {
691
697
. pop ( )
692
698
. expect ( "should have decommisioned node" ) ;
693
699
assert_eq ! ( reclaimed. 0 , 2 ) ;
700
+
701
+ // No other dropped nodes
702
+ assert ! ( node_id_consumer. pop( ) . is_none( ) ) ;
703
+ }
704
+
705
+ #[ test]
706
+ fn test_audio_param_lifecycle ( ) {
707
+ let ( node_id_producer, mut node_id_consumer) = llq:: Queue :: new ( ) . split ( ) ;
708
+ let mut graph = Graph :: new ( node_id_producer) ;
709
+
710
+ let node = Box :: new ( TestNode { tail_time : false } ) ;
711
+
712
+ // Destination Node is always node id 0, and should never drop
713
+ add_node ( & mut graph, 0 , node. clone ( ) ) ;
714
+
715
+ // AudioListener Node is always node id 1, and should never drop
716
+ add_node ( & mut graph, 1 , node. clone ( ) ) ;
717
+
718
+ // Add a regular node at id 3, it has tail time false so after rendering it should be
719
+ // dropped and the AudioNodeId(3) should be reclaimed
720
+ add_node ( & mut graph, 2 , node. clone ( ) ) ;
721
+ // Mark the node as 'detached from the control thread', so it is allowed to drop
722
+ graph. nodes [ 2 ] . get_mut ( ) . free_when_finished = true ;
723
+
724
+ // Connect the regular node to the AudioDestinationNode
725
+ add_edge ( & mut graph, 2 , 0 ) ;
726
+
727
+ // Add an AudioParam at id 4, it should be dropped alongside the regular node
728
+ let param = Box :: new ( TestNode { tail_time : true } ) ; // audio params have tail time true
729
+ add_node ( & mut graph, 3 , param) ;
730
+
731
+ // Connect the audioparam to the regular node
732
+ add_audioparam ( & mut graph, 3 , 2 ) ;
733
+
734
+ // Render a single quantum
735
+ let scope = RenderScope {
736
+ current_frame : 0 ,
737
+ current_time : 0. ,
738
+ sample_rate : 48000. ,
739
+ node_id : std:: cell:: Cell :: new ( AudioNodeId ( 0 ) ) ,
740
+ event_sender : None ,
741
+ } ;
742
+ graph. render ( & scope) ;
743
+
744
+ // First the regular node should be dropped, then the audioparam
745
+ assert_eq ! ( node_id_consumer. pop( ) . unwrap( ) . 0 , 2 ) ;
746
+ assert_eq ! ( node_id_consumer. pop( ) . unwrap( ) . 0 , 3 ) ;
747
+
748
+ // No other dropped nodes
749
+ assert ! ( node_id_consumer. pop( ) . is_none( ) ) ;
694
750
}
695
751
}
0 commit comments