mirror of
https://github.com/rust-vmm/vhost-device.git
synced 2026-01-07 11:37:40 +00:00
sound: add NullBackend skeleton
This commit is contained in:
parent
5e8fd650e9
commit
82660840ca
@ -9,6 +9,10 @@ keywords = ["vhost", "sound", "virtio-sound"]
|
||||
license = "Apache-2.0 OR BSD-3-Clause"
|
||||
edition = "2018"
|
||||
|
||||
[features]
|
||||
default = ["null-backend"]
|
||||
null-backend = []
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.1", features = ["derive"] }
|
||||
env_logger = "0.10"
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
|
||||
|
||||
#[cfg(feature = "null-backend")]
|
||||
mod null;
|
||||
|
||||
#[cfg(feature = "null-backend")]
|
||||
use self::null::NullBackend;
|
||||
use crate::{Error, Result, SoundRequest};
|
||||
|
||||
pub trait AudioBackend {
|
||||
@ -10,6 +15,8 @@ pub trait AudioBackend {
|
||||
|
||||
pub fn allocate_audio_backend(name: String) -> Result<Box<dyn AudioBackend + Send + Sync>> {
|
||||
match name.as_str() {
|
||||
#[cfg(feature = "null-backend")]
|
||||
"null" => Ok(Box::new(NullBackend::new())),
|
||||
_ => Err(Error::AudioBackendNotSupported),
|
||||
}
|
||||
}
|
||||
|
||||
27
crates/sound/src/audio_backends/null.rs
Normal file
27
crates/sound/src/audio_backends/null.rs
Normal file
@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
|
||||
|
||||
use super::AudioBackend;
|
||||
use crate::{Error, Result, SoundRequest};
|
||||
|
||||
pub struct NullBackend {}
|
||||
|
||||
impl NullBackend {
|
||||
pub fn new() -> Self {
|
||||
NullBackend {}
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioBackend for NullBackend {
|
||||
fn write(&self, _req: &SoundRequest) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn read(&self, req: &mut SoundRequest) -> Result<()> {
|
||||
let buf = req.data_slice().ok_or(Error::SoundReqMissingData)?;
|
||||
let zero_mem = vec![0u8; buf.len()];
|
||||
|
||||
buf.copy_from(&zero_mem);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user