22#include <pthread.h>
33#include <stdio.h>
44#include <string.h>
5+ #include <inttypes.h>
56
67#define CNFA_IMPLEMENTATION
78#include "CNFA_sf.h"
@@ -679,19 +680,27 @@ static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd,
679680 struct virtq_desc vq_desc [VSND_DESC_CNT ];
680681
681682 /* Collect the descriptors */
682- for (int i = 0 ; i < VSND_DESC_CNT ; i ++ ) {
683+ int i = 0 ;
684+ while (true) {
683685 /* The size of the `struct virtq_desc` is 4 words */
684686 const uint32_t * desc = & vsnd -> ram [queue -> QueueDesc + desc_idx * 4 ];
685687
686688 /* Retrieve the fields of current descriptor */
689+ if (i < VSND_DESC_CNT ) {
687690 vq_desc [i ].addr = desc [0 ];
688691 vq_desc [i ].len = desc [2 ];
689692 vq_desc [i ].flags = desc [3 ];
693+ }
690694 desc_idx = desc [3 ] >> 16 ; /* vq_desc[desc_cnt].next */
691695
696+ i ++ ;
697+ sleep (1 );
698+
692699 /* Leave the loop if next-flag is not set */
693- if (!(vq_desc [i ].flags & VIRTIO_DESC_F_NEXT ))
700+ if (!(desc [3 ] & VIRTIO_DESC_F_NEXT )) {
701+ fprintf (stderr , "index %" PRIu32 " no next flag\n" , i );
694702 break ;
703+ }
695704 }
696705
697706 fprintf (stderr , "TX process header\n" );
@@ -701,18 +710,18 @@ static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd,
701710 uint32_t stream_id = request -> stream_id ;
702711 void * payload = (void * ) ((uintptr_t ) vsnd -> ram + vq_desc [1 ].addr );
703712 virtio_snd_pcm_status_t * response =
704- (virtio_snd_pcm_status_t * ) (uintptr_t ) vsnd -> ram + vq_desc [2 ].addr ;
713+ (virtio_snd_pcm_status_t * ) (( uintptr_t ) vsnd -> ram + vq_desc [2 ].addr ) ;
705714
706715 /* Process the data */
707716 fprintf (stderr , "TX process header\n" );
708- size_t sz = vsnd_props [stream_id ].pp .buffer_bytes ;
717+ uint32_t sz = vsnd_props [stream_id ].pp .buffer_bytes ;
709718 memcpy (vsnd_props [stream_id ].buf , payload , sz );
710719
711720 /* Return the device status */
712721 fprintf (stderr , "TX return device status\n" );
713722 response -> status = VIRTIO_SND_S_OK ;
714723 response -> latency_bytes = 0 ; /* TODO: show the actual latency bytes */
715- * plen = sz ;
724+ * plen = vq_desc [ 1 ]. len + sizeof ( * response ) ;
716725
717726 return 0 ;
718727}
@@ -896,8 +905,8 @@ static bool virtio_snd_reg_write(virtio_snd_state_t *vsnd,
896905 break ;
897906 case VSND_QUEUE_TX :
898907 fprintf (stderr , "TX start\n" );
899- /* virtio_queue_notify_handler(vsnd, value,
900- virtio_snd_tx_desc_handler);*/
908+ virtio_queue_notify_handler (vsnd , value ,
909+ virtio_snd_tx_desc_handler );
901910 fprintf (stderr , "TX end\n" );
902911 break ;
903912 case VSND_QUEUE_EVT :
0 commit comments