@@ -276,6 +276,7 @@ typedef struct {
276276typedef struct {
277277 int32_t guest_playing ;
278278 uint32_t stream_id ;
279+ int8_t is_done ;
279280 pthread_mutex_t ctrl_mutex ;
280281 pthread_cond_t ctrl_cond ;
281282} vsnd_stream_sel_t ;
@@ -494,6 +495,7 @@ static void virtio_snd_read_pcm_prepare(const virtio_snd_pcm_hdr_t *query,
494495 props -> pp .hdr .hdr .code = VIRTIO_SND_R_PCM_PREPARE ;
495496 props -> v .guest_playing = 0 ;
496497 props -> v .stream_id = stream_id ;
498+ props -> v .is_done = 0 ;
497499
498500 uint32_t channels = props -> pp .channels ;
499501 uint32_t rate = pcm_rate_tbl [props -> pp .rate ];
@@ -626,15 +628,16 @@ static void virtio_snd_read_pcm_release(const virtio_snd_pcm_hdr_t *query,
626628 }
627629 }
628630
631+ props -> v .is_done = 1 ;
632+ fprintf (stderr , "pcm_release tear down CNFA\n" );
633+ CNFAClose (props -> audio_host );
634+
629635 /* Tear down stream related locking attributes. */
630636 pthread_cond_broadcast (& props -> v .ctrl_cond );
631637 pthread_mutex_unlock (& props -> v .ctrl_mutex );
632638 pthread_mutex_destroy (& props -> v .ctrl_mutex );
633639 pthread_cond_destroy (& props -> v .ctrl_cond );
634640
635- fprintf (stderr , "pcm_release tear down CNFA\n" );
636- CNFAClose (props -> audio_host );
637-
638641 * plen = 0 ;
639642 fprintf (stderr , "pcm_release stop\n" );
640643}
@@ -685,6 +688,12 @@ static void virtio_snd_cb(struct CNFADriver *dev,
685688 uint32_t out_buf_sz = framesp * channels ;
686689
687690 pthread_mutex_lock (& v_ptr -> ctrl_mutex );
691+ if (v_ptr -> is_done == 1 ) {
692+ fprintf (stderr , "start tear down\n" );
693+ memset (out , 0 , sizeof (* out ) * out_buf_sz );
694+ goto finally ;
695+ }
696+
688697 while (v_ptr -> guest_playing == 0 ) {
689698 fprintf (stderr , "wait ctrl_cond\n" );
690699 memset (out , 0 , sizeof (* out ) * out_buf_sz );
@@ -696,6 +705,7 @@ static void virtio_snd_cb(struct CNFADriver *dev,
696705
697706 __virtio_snd_frame_dequeue (out , out_buf_bytes , id );
698707
708+ finally :
699709 pthread_mutex_unlock (& v_ptr -> ctrl_mutex );
700710}
701711
0 commit comments