mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 20:48:55 +00:00
audio_streams: convert to ThisError and sort
BUG=b:197143586 TEST=cargo check Cq-Depend: chromium:3105308 Change-Id: Id48674c3fb0536a72a14a945a9f76bc58649fb46 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105072 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
This commit is contained in:
parent
e8e871b085
commit
b09646303e
5 changed files with 26 additions and 63 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -90,8 +90,10 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"async-trait",
|
||||
"cros_async",
|
||||
"remain",
|
||||
"sync",
|
||||
"sys_util",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -10,5 +10,7 @@ path = "src/audio_streams.rs"
|
|||
[dependencies]
|
||||
async-trait = "0.1.36"
|
||||
cros_async = { path = "../cros_async" } # provided by ebuild
|
||||
remain = "0.2"
|
||||
sync = { path = "../sync" } # provided by ebuild
|
||||
sys_util = { path = "../sys_util" } # provided by ebuild
|
||||
thiserror = "1.0.20"
|
||||
|
|
|
@ -51,6 +51,8 @@ use std::str::FromStr;
|
|||
use std::time::{Duration, Instant};
|
||||
|
||||
use cros_async::{Executor, TimerAsync};
|
||||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum SampleFormat {
|
||||
|
@ -111,21 +113,13 @@ impl Default for StreamEffect {
|
|||
pub type BoxError = Box<dyn error::Error + Send + Sync>;
|
||||
|
||||
/// Errors that are possible from a `StreamEffect`.
|
||||
#[derive(Debug)]
|
||||
#[sorted]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum StreamEffectError {
|
||||
#[error("Must be in [EchoCancellation, aec]")]
|
||||
InvalidEffect,
|
||||
}
|
||||
|
||||
impl error::Error for StreamEffectError {}
|
||||
|
||||
impl Display for StreamEffectError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
StreamEffectError::InvalidEffect => write!(f, "Must be in [EchoCancellation, aec]"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for StreamEffect {
|
||||
type Err = StreamEffectError;
|
||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||
|
@ -136,21 +130,13 @@ impl FromStr for StreamEffect {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[sorted]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("Unimplemented")]
|
||||
Unimplemented,
|
||||
}
|
||||
|
||||
impl error::Error for Error {}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Error::Unimplemented => write!(f, "Unimplemented"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `StreamSource` creates streams for playback or capture of audio.
|
||||
pub trait StreamSource: Send {
|
||||
/// Returns a stream control and buffer generator object. These are separate as the buffer
|
||||
|
@ -329,21 +315,13 @@ pub trait AsyncBufferCommit {
|
|||
}
|
||||
|
||||
/// Errors that are possible from a `PlaybackBuffer`.
|
||||
#[derive(Debug)]
|
||||
#[sorted]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum PlaybackBufferError {
|
||||
#[error("Invalid buffer length")]
|
||||
InvalidLength,
|
||||
}
|
||||
|
||||
impl error::Error for PlaybackBufferError {}
|
||||
|
||||
impl Display for PlaybackBufferError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
PlaybackBufferError::InvalidLength => write!(f, "Invalid buffer length"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `AudioBuffer` is one buffer that holds buffer_size audio frames.
|
||||
/// It is the inner data of `PlaybackBuffer` and `CaptureBuffer`.
|
||||
struct AudioBuffer<'a> {
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
|
||||
use async_trait::async_trait;
|
||||
use std::{
|
||||
error,
|
||||
fmt::{self, Display},
|
||||
io::{self, Read},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
@ -42,6 +40,8 @@ use super::{
|
|||
AsyncBufferCommit, AudioBuffer, BoxError, BufferCommit, NoopBufferCommit, SampleFormat,
|
||||
};
|
||||
use cros_async::{Executor, TimerAsync};
|
||||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
|
||||
/// `CaptureBufferStream` provides `CaptureBuffer`s to read with audio samples from capture.
|
||||
pub trait CaptureBufferStream: Send {
|
||||
|
@ -100,21 +100,13 @@ pub struct AsyncCaptureBuffer<'a> {
|
|||
}
|
||||
|
||||
/// Errors that are possible from a `CaptureBuffer`.
|
||||
#[derive(Debug)]
|
||||
#[sorted]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum CaptureBufferError {
|
||||
#[error("Invalid buffer length")]
|
||||
InvalidLength,
|
||||
}
|
||||
|
||||
impl error::Error for CaptureBufferError {}
|
||||
|
||||
impl Display for CaptureBufferError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
CaptureBufferError::InvalidLength => write!(f, "Invalid buffer length"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> CaptureBuffer<'a> {
|
||||
/// Creates a new `CaptureBuffer` that holds a reference to the backing memory specified in
|
||||
/// `buffer`.
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
// Copyright 2019 The Chromium OS Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
|
||||
use std::os::unix::io::RawFd;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use remain::sorted;
|
||||
use sync::{Condvar, Mutex};
|
||||
use sys_util::SharedMemory;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{BoxError, SampleFormat, StreamDirection, StreamEffect};
|
||||
|
||||
|
@ -29,25 +30,13 @@ pub trait BufferSet {
|
|||
fn ignore(&mut self) -> GenericResult<()>;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[sorted]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("Provided number of frames {0} exceeds requested number of frames {1}")]
|
||||
TooManyFrames(usize, usize),
|
||||
}
|
||||
|
||||
impl error::Error for Error {}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Error::TooManyFrames(provided, requested) => write!(
|
||||
f,
|
||||
"Provided number of frames {} exceeds requested number of frames {}",
|
||||
provided, requested
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `ServerRequest` represents an active request from the server for the client
|
||||
/// to provide a buffer in shared memory to playback from or capture to.
|
||||
pub struct ServerRequest<'a> {
|
||||
|
|
Loading…
Reference in a new issue