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 <chirantan@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Woody Chow <woodychow@google.com>
This commit is contained in:
Woody Chow 2021-10-12 13:42:38 +09:00 committed by Commit Bot
parent e2947e0f12
commit 5acd4ee978
3 changed files with 38 additions and 3 deletions

View file

@ -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!(),
}
}

View file

@ -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)

View file

@ -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<CrasClient<'a>>,
channels: u8,
@ -167,7 +169,7 @@ pub struct StreamInfo<'a> {
frame_rate: u32,
buffer_bytes: usize,
period_bytes: usize,
direction: u8,
direction: u8, // VIRTIO_SND_D_*
state: u32, // VIRTIO_SND_R_PCM_SET_PARAMS -> VIRTIO_SND_R_PCM_STOP, or 0 (uninitialized)
// Worker related
@ -177,6 +179,20 @@ pub struct StreamInfo<'a> {
worker_future: Option<Box<dyn Future<Output = Result<(), Error>> + 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 {