Skip to content

Commit

Permalink
Debug pcm_release state
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuda-Chen committed Dec 2, 2024
1 parent 6dc7670 commit 0dd17ee
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions virtio-snd.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ static void virtio_snd_read_jack_info_handler(
uint32_t *plen)
{
uint32_t cnt = query->count;
printf("jack info handler count %d\n", cnt);
for (uint32_t i = 0; i < cnt; i++) {
info[i].hdr.hda_fn_nid = 0;
info[i].features = 0;
Expand All @@ -359,7 +358,6 @@ static void virtio_snd_read_pcm_info_handler(
uint32_t *plen)
{
uint32_t cnt = query->count;
printf("snd info handler count %d\n", cnt);
for (uint32_t i = 0; i < cnt; i++) {
info[i].hdr.hda_fn_nid = 0;
info[i].features = 0;
Expand Down Expand Up @@ -388,7 +386,6 @@ static void virtio_snd_read_chmap_info_handler(
uint32_t *plen)
{
uint32_t cnt = query->count;
printf("chmap info handler count %d\n", cnt);
for (uint32_t i = 0; i < cnt; i++) {
info[i].hdr.hda_fn_nid = 0;
info[i].direction = VIRTIO_SND_D_OUTPUT;
Expand Down Expand Up @@ -516,6 +513,7 @@ static void virtio_snd_read_pcm_stop(const virtio_snd_pcm_hdr_t *query,
static void virtio_snd_read_pcm_release(const virtio_snd_pcm_hdr_t *query,
uint32_t *plen)
{
fprintf(stderr, "virtio_snd_read_pcm_release start\n");
const virtio_snd_pcm_hdr_t *request = query;
uint32_t stream_id = request->stream_id;
uint32_t code = vsnd_props[stream_id].pp.hdr.hdr.code;
Expand All @@ -528,21 +526,28 @@ static void virtio_snd_read_pcm_release(const virtio_snd_pcm_hdr_t *query,
}
/* Control the callback to stop playing */
/* TODO: add lock to avoid race condition */
fprintf(stderr, "start guest_playing\n");
v.guest_playing = 0;
pthread_cond_signal(&virtio_snd_ctrl_cond);
fprintf(stderr, "pass guest_playing\n");

vsnd_props[stream_id].pp.hdr.hdr.code = VIRTIO_SND_R_PCM_RELEASE;
CNFAClose(vsnd_props[stream_id].audio_host);
fprintf(stderr, "pass CNFAclose\n");

/* Tear down the PCM frames. */
virtio_snd_pcm_frame_t *t = NULL;
struct queue_head *frame_q = &(vsnd_props[stream_id].pcm_frames_q);
virtio_snd_pcm_frame_t *frame = vsnd_props[stream_id].pcm_frames;
int idx = 0;
queue_for_each_entry_safe(frame, t, frame_q, q)
{
free(frame->buf);
queue_del(&frame->q);
free(frame);

fprintf(stderr, "tear down frame %d\n", idx);
idx++;
}
assert(queue_empty(frame_q));

Expand Down Expand Up @@ -579,8 +584,10 @@ static void virtio_snd_cb(struct CNFADriver *dev,

pthread_mutex_lock(&virtio_snd_ctrl_mutex);

while (v_ptr->guest_playing <= 0)
while (v_ptr->guest_playing <= 0) {
fprintf(stderr, "wait ctrl cond\n");
pthread_cond_wait(&virtio_snd_ctrl_cond, &virtio_snd_ctrl_mutex);
}

v_ptr->guest_playing--;

Expand Down

0 comments on commit 0dd17ee

Please sign in to comment.