@@ -511,6 +511,12 @@ static int audio_test_cleanup(FAR struct audio_state_s *state, int direction)
511
511
512
512
ioctl (fd , AUDIOIOC_UNREGISTERMQ , (unsigned long )state -> mq );
513
513
514
+ #ifdef CONFIG_AUDIO_MULTI_SESSION
515
+ ioctl (fd , AUDIOIOC_RELEASE , (unsigned long )state -> session );
516
+ #else
517
+ ioctl (fd , AUDIOIOC_RELEASE , 0 );
518
+ #endif
519
+
514
520
if (state -> out_fd >= 0 )
515
521
{
516
522
close (state -> out_fd );
@@ -535,6 +541,7 @@ static void audio_test_case(void **audio_state)
535
541
};
536
542
537
543
struct mq_attr attr ;
544
+ int unconsumed = 0 ;
538
545
unsigned int prio ;
539
546
bool streaming ;
540
547
bool running ;
@@ -596,6 +603,8 @@ static void audio_test_case(void **audio_state)
596
603
printf ("Start %s. \n" , direct == AUDIO_TYPE_OUTPUT ?
597
604
"Playback" : "Capture" );
598
605
606
+ unconsumed = buf_info .nbuffers ;
607
+
599
608
while (running )
600
609
{
601
610
ret = mq_receive (state -> mq , (FAR char * )& msg , sizeof (msg ), & prio );
@@ -607,6 +616,7 @@ static void audio_test_case(void **audio_state)
607
616
switch (msg .msg_id )
608
617
{
609
618
case AUDIO_MSG_DEQUEUE :
619
+ unconsumed -- ;
610
620
if (streaming )
611
621
{
612
622
if (direct == AUDIO_TYPE_INPUT )
@@ -627,11 +637,15 @@ static void audio_test_case(void **audio_state)
627
637
ret = audio_test_enqueuebuffer (state ,
628
638
msg .u .ptr , direct );
629
639
if (ret != OK )
630
- {
631
- close (state -> out_fd );
632
- state -> out_fd = -1 ;
633
- streaming = false;
634
- }
640
+ {
641
+ close (state -> out_fd );
642
+ state -> out_fd = -1 ;
643
+ streaming = false;
644
+ }
645
+ else
646
+ {
647
+ unconsumed ++ ;
648
+ }
635
649
}
636
650
}
637
651
break ;
@@ -659,12 +673,16 @@ static void audio_test_case(void **audio_state)
659
673
ret = mq_getattr (state -> mq , & attr );
660
674
assert_false (ret < 0 );
661
675
662
- if (attr .mq_curmsgs == 0 )
663
- {
664
- break ;
665
- }
676
+ if (attr .mq_curmsgs == 0 && unconsumed <= 0 )
677
+ {
678
+ break ;
679
+ }
666
680
667
681
mq_receive (state -> mq , (FAR char * )& msg , sizeof (msg ), & prio );
682
+ if (msg .msg_id == AUDIO_MSG_DEQUEUE )
683
+ {
684
+ unconsumed -- ;
685
+ }
668
686
}
669
687
while (ret >= 0 );
670
688
0 commit comments