From 5acd4ee978d9fa1da9476c0338190e08c53ea2aa Mon Sep 17 00:00:00 2001 From: Woody Chow Date: Tue, 12 Oct 2021 13:42:38 +0900 Subject: [PATCH] snd: Add debug prints and comments to virtio-snd (cras) BUG=None TEST=cargo test Change-Id: Id4d0795f9001215dea07b8ff4edeee723782d7c0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3217344 Reviewed-by: Chirantan Ekbote Reviewed-by: Chih-Yang Hsia Tested-by: kokoro Commit-Queue: Woody Chow --- devices/src/virtio/snd/common.rs | 8 ++++++++ .../virtio/snd/cras_backend/async_funcs.rs | 13 +++++++++++- devices/src/virtio/snd/cras_backend/mod.rs | 20 +++++++++++++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/devices/src/virtio/snd/common.rs b/devices/src/virtio/snd/common.rs index c7f06b6c43..0f734e9c20 100644 --- a/devices/src/virtio/snd/common.rs +++ b/devices/src/virtio/snd/common.rs @@ -102,3 +102,11 @@ pub fn get_virtio_snd_r_pcm_cmd_name(cmd_code: u32) -> &'static str { _ => unreachable!(), } } + +pub fn get_virtio_direction_name(dir: u8) -> &'static str { + match dir { + VIRTIO_SND_D_OUTPUT => "VIRTIO_SND_D_OUTPUT", + VIRTIO_SND_D_INPUT => "VIRTIO_SND_D_INPUT", + _ => unreachable!(), + } +} diff --git a/devices/src/virtio/snd/cras_backend/async_funcs.rs b/devices/src/virtio/snd/cras_backend/async_funcs.rs index a5fd6b7573..d67a230728 100644 --- a/devices/src/virtio/snd/cras_backend/async_funcs.rs +++ b/devices/src/virtio/snd/cras_backend/async_funcs.rs @@ -6,7 +6,7 @@ use futures::{channel::mpsc, SinkExt, StreamExt}; use std::io::{self, Write}; use std::rc::Rc; -use base::error; +use base::{debug, error}; use cros_async::{sync::Condvar, sync::Mutex as AsyncMutex, EventAsync, Executor}; use data_model::{DataInit, Le32}; use vm_memory::GuestMemory; @@ -48,6 +48,12 @@ async fn process_pcm_ctrl( } }; + debug!( + "{} for stream id={}", + get_virtio_snd_r_pcm_cmd_name(cmd_code), + stream_id + ); + let result = match cmd_code { VIRTIO_SND_R_PCM_PREPARE => { stream @@ -548,6 +554,11 @@ pub async fn handle_ctrl_queue( stream_info.direction = dir; stream_info.state = VIRTIO_SND_R_PCM_SET_PARAMS; + debug!( + "VIRTIO_SND_R_PCM_SET_PARAMS for stream id={}. Stream info: {:#?}", + stream_id, *stream_info + ); + writer .write_obj(VIRTIO_SND_S_OK) .map_err(Error::WriteResponse) diff --git a/devices/src/virtio/snd/cras_backend/mod.rs b/devices/src/virtio/snd/cras_backend/mod.rs index 5d2cf4c237..d870ce7358 100644 --- a/devices/src/virtio/snd/cras_backend/mod.rs +++ b/devices/src/virtio/snd/cras_backend/mod.rs @@ -4,6 +4,7 @@ // virtio-sound spec: https://github.com/oasis-tcs/virtio-spec/blob/master/virtio-sound.tex +use std::fmt; use std::io; use std::rc::Rc; use std::str::{FromStr, ParseBoolError}; @@ -160,6 +161,7 @@ pub enum WorkerStatus { Running = 1, Quit = 2, } + pub struct StreamInfo<'a> { client: Option>, channels: u8, @@ -167,8 +169,8 @@ pub struct StreamInfo<'a> { frame_rate: u32, buffer_bytes: usize, period_bytes: usize, - direction: u8, - state: u32, // VIRTIO_SND_R_PCM_SET_PARAMS -> VIRTIO_SND_R_PCM_STOP, or 0 (uninitialized) + direction: u8, // VIRTIO_SND_D_* + state: u32, // VIRTIO_SND_R_PCM_SET_PARAMS -> VIRTIO_SND_R_PCM_STOP, or 0 (uninitialized) // Worker related status_mutex: Rc>, @@ -177,6 +179,20 @@ pub struct StreamInfo<'a> { worker_future: Option> + Unpin>>, } +impl fmt::Debug for StreamInfo<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("StreamInfo") + .field("channels", &self.channels) + .field("format", &self.format) + .field("frame_rate", &self.frame_rate) + .field("buffer_bytes", &self.buffer_bytes) + .field("period_bytes", &self.period_bytes) + .field("direction", &get_virtio_direction_name(self.direction)) + .field("state", &get_virtio_snd_r_pcm_cmd_name(self.state)) + .finish() + } +} + impl Default for StreamInfo<'_> { fn default() -> Self { StreamInfo {