@@ -683,7 +683,7 @@ static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd,
683683    INIT_QUEUE_HEAD (& q );
684684
685685    /* Collect the descriptors */ 
686-     int  i  =  0 ;
686+     int  cnt  =  0 ;
687687    while  (true) {
688688        /* The size of the `struct virtq_desc` is 4 words */ 
689689        const  uint32_t  * desc  =  & vsnd -> ram [queue -> QueueDesc  +  desc_idx  *  4 ];
@@ -701,12 +701,12 @@ static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd,
701701        queue_push (& node -> q , & q );
702702        desc_idx  =  desc [3 ] >> 16 ; /* vq_desc[desc_cnt].next */ 
703703
704-         i ++ ;
704+         cnt ++ ;
705705        sleep (1 );
706706
707707        /* Leave the loop if next-flag is not set */ 
708708        if  (!(desc [3 ] &  VIRTIO_DESC_F_NEXT )) {
709-             fprintf (stderr , "index %"  PRIu32  " no next flag\n" , i );
709+             fprintf (stderr , "index %"  PRIu32  " no next flag\n" , cnt );
710710            break ;
711711        }
712712    }
@@ -733,11 +733,27 @@ static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd,
733733    * plen  =  vq_desc [1 ].len  +  sizeof (* response );
734734#endif 
735735    int  idx  =  0 ;
736+     uint32_t  stream_id ;
737+     uintptr_t  base  =  vsnd -> ram ;
736738    queue_for_each_entry (node , & q , q )
737739    {
738740        uint32_t  addr  =  node -> vq_desc .addr ;
739741        uint32_t  len  =  node -> vq_desc .len ;
740-         printf ("node %d addr %"  PRIu32  " len %"  PRIu32  "\n" , idx , addr , len );
742+         fprintf (stderr , "idx %d addr %"  PRIu32  " len %"  PRIu32  "\n" , idx , addr , len );
743+         if  (idx  ==  0 ) {  // the first descriptor 
744+             const  virtio_snd_pcm_xfer_t  * request  =  (virtio_snd_pcm_xfer_t  * )(base  +  addr );
745+             stream_id  =  request -> stream_id ;
746+             fprintf (stderr , "stream_id %"  PRIu32  "\n" , stream_id );
747+         } else  if  (idx  ==  cnt  -  1 ) {  // the last descriptor 
748+             virtio_snd_pcm_status_t  * response  =  (virtio_snd_pcm_status_t  * )(base  +  addr );
749+             response -> status  =  VIRTIO_SND_S_OK ;
750+             response -> latency_bytes  = 
751+                 0 ;                     /* TODO: show the actual latency bytes */ 
752+             * plen  =  sizeof (* response ); /* TODO: set the read length of buffer of 
753+                                           PCM frames */ 
754+             fprintf (stderr , "TX response\n" );
755+         }
756+ 
741757        idx ++ ;
742758    }
743759
0 commit comments