Skip to content

Commit

Permalink
cras_dsp: Use peer processor in echo demo
Browse files Browse the repository at this point in the history
The demo echo processor is updated to use the peer processor.

FIXED=b:383924467
TEST=bazel test //...
TEST=modify dsp.ini and play youtube video

Change-Id: I995ed8d3161aab2bc98042dff69bbed33c3d363c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/6090661
Reviewed-by: Hung-Hsien Chen <[email protected]>
Tested-by: [email protected] <[email protected]>
Commit-Queue: Li-Yu Yu <[email protected]>
  • Loading branch information
afq984 authored and Chromeos LUCI committed Dec 18, 2024
1 parent a2e8821 commit 1b7f4c3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 17 deletions.
16 changes: 14 additions & 2 deletions cras/server/processor/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ enum CrasProcessorWrapMode {
*/
WrapModeDedicatedThread,
/**
* Run the processor pipeline with a ChunkWrapper.
* Run the processor pipeline with a ChunkWrapper with the inner block
* size set to [`CrasProcessorConfig::block_size`].
* In this mode, the caller is allowed to run the pipeline with a block
* size that is different from `CrasProcessorConfig::block_size`
* size that is different from [`CrasProcessorConfig::block_size`].
*/
WrapModeChunk,
/**
* Like `WrapModeChunk` but the pipeline is run inside a peer processor (sandbox).
* [`CrasProcessorConfig::max_block_size`] must be set in this mode.
* WAVE dump is not supported in this mode.
*/
WrapModePeerChunk,
};

struct CrasProcessorCreateResult {
Expand All @@ -53,6 +60,11 @@ struct CrasProcessorConfig {
enum CrasProcessorEffect effect;
enum CrasProcessorWrapMode wrap_mode;
bool wav_dump;
/**
* The max block size when wrap_mode is WrapModePeerChunk.
* Used to determine buffer size to allocate for peer IPC.
*/
size_t max_block_size;
};

/**
Expand Down
50 changes: 37 additions & 13 deletions cras/server/processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ pub enum CrasProcessorWrapMode {
WrapModeNone,
/// Run the processor pipeline in a separate, dedicated thread.
WrapModeDedicatedThread,
/// Run the processor pipeline with a ChunkWrapper.
/// Run the processor pipeline with a ChunkWrapper with the inner block
/// size set to [`CrasProcessorConfig::block_size`].
/// In this mode, the caller is allowed to run the pipeline with a block
/// size that is different from `CrasProcessorConfig::block_size`
/// size that is different from [`CrasProcessorConfig::block_size`].
WrapModeChunk,
/// Like `WrapModeChunk` but the pipeline is run inside a peer processor (sandbox).
/// [`CrasProcessorConfig::max_block_size`] must be set in this mode.
/// WAVE dump is not supported in this mode.
WrapModePeerChunk,
}

#[repr(C)]
Expand All @@ -58,6 +63,10 @@ pub struct CrasProcessorConfig {

// Enable processing dumps as WAVE files.
wav_dump: bool,

/// The max block size when wrap_mode is WrapModePeerChunk.
/// Used to determine buffer size to allocate for peer IPC.
max_block_size: usize,
}

impl CrasProcessorConfig {
Expand Down Expand Up @@ -275,22 +284,37 @@ impl CrasProcessor {
});
}

let pipeline = if matches!(config.wrap_mode, CrasProcessorWrapMode::WrapModeChunk) {
Processor::WrapChunk {
inner: Box::new(Processor::Pipeline { processors: decl }),
let mut pipeline = Processor::Pipeline { processors: decl };
if matches!(
config.wrap_mode,
CrasProcessorWrapMode::WrapModeChunk | CrasProcessorWrapMode::WrapModePeerChunk
) {
pipeline = Processor::WrapChunk {
inner: Box::new(pipeline),
inner_block_size: config.block_size,
disallow_hoisting: true,
};
if matches!(config.wrap_mode, CrasProcessorWrapMode::WrapModePeerChunk) {
pipeline = Processor::Peer {
processor: Box::new(pipeline),
};
}
} else {
Processor::Pipeline { processors: decl }
};
}

let decl_debug = format!("{pipeline:?}");
let pipeline = PipelineBuilder::new(config.format())
// TODO(b/349784210): Use a hardened worker factory.
.with_worker_factory(AudioWorkerSubprocessFactory::default().with_set_thread_priority())
.build(pipeline)
.context("failed to build pipeline")?;
let pipeline = PipelineBuilder::new(Format {
block_size: if matches!(config.wrap_mode, CrasProcessorWrapMode::WrapModePeerChunk) {
assert_ne!(config.max_block_size, 0);
config.max_block_size // Used for allocation.
} else {
config.block_size
},
..config.format()
})
// TODO(b/349784210): Use a hardened worker factory.
.with_worker_factory(AudioWorkerSubprocessFactory::default().with_set_thread_priority())
.build(pipeline)
.context("failed to build pipeline")?;

log::info!("CrasProcessor #{id} created with: {config:?}");
log::info!("CrasProcessor #{id} pipeline: {decl_debug}");
Expand Down
5 changes: 3 additions & 2 deletions cras/src/server/cras_dsp_mod_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,10 +822,11 @@ static int cras_processor_instantiate(struct dsp_module* module,
struct CrasProcessorConfig cfg = {
.channels = data->channels,
.block_size = 256,
.wrap_mode = WrapModeChunk,
.max_block_size = DSP_BUFFER_SIZE,
.wrap_mode = WrapModePeerChunk,
.frame_rate = sample_rate,
.effect = data->effect,
.wav_dump = cras_feature_enabled(CrOSLateBootCrasProcessorWavDump),
.wav_dump = false, // Not supported for WrapModePeerChunk.
};
struct CrasProcessorCreateResult result = cras_processor_create(&cfg, NULL);

Expand Down

0 comments on commit 1b7f4c3

Please sign in to comment.