New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 645051 link

Starred by 1 user

Issue metadata

Status: Verified
Owner:
Closed: Sep 2016
Cc:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 1
Type: Feature

Blocking:
issue 646037



Sign in to add a comment

CRAS: Support left/right swapping using DSP

Project Member Reported by cychiang@chromium.org, Sep 8 2016

Issue description

We need to support left/right channel swapping for boards that do not have proper mixer control for speaker exposed by codec to do that.

We can implement this in DSP by attaching an extra instance
swap_left_right into original DSP pipeline.

We can do
1. Set left right swapping support in UCM.
2. Add a pipeline for purpose="playback-swap" into dsp.ini. This pipeline use swap_left_right instance.

When client requests to swap left right, we can do
1. Check if left/right swapping is supported by mixer control or by DSP.

If swapping is supported by DSP, do the following:

2. Disable speaker so streams go to fallback device.
3. Change the dsp pipeline that speaker is using from purpose="playback" to purpose="playback-swap". Here we can just mark a flag.
4. Enable speaker again. Here cras_iodev_alloc_dsp will handle the reload with respect to the flag set in 2.

Hi Dylan, do you think this is reasonable ?
Thanks!
 
Chihchung just pointed out that we don't need extra built-in module to do that.
We will fix the output_source and output_sink, add two extra section just controlling the switching.
Then we disable/enable one of the extra section with variable (not using purpose).
I will take a close look on how this works.


I think we want to provide a non-stopping listening experience so the steps involving enable/disable devices will not work.  We want something that could be toggled or applied on-the-fly, so approach in #1 sounds promising.
Hi Chinyue, after taking a look again in the code, I agree it should be fine to do this dsp reload without enable/disable devices.

Following what cras_iodev_update_dsp does, we enable the left-right-swap variable to change the dsp pipeline. Since the pipeline is protected by a mutex. We don't need to worry it might mess up audio thread. In audio thread, when it runs apply_dsp, it will acquire the mutex first, so after the quick switch in cmd_load_pipeline

        /* This locking is short to avoild blocking audio thread. */
        pthread_mutex_lock(&ctx->mutex);
        old_pipeline = ctx->pipeline;
        ctx->pipeline = pipeline;
        pthread_mutex_unlock(&ctx->mutex);

audio thread can acquire the mutex and get the new dsp pipeline.
It should happen without user noticing it.

Thanks for the suggestion!
Blocking: 646037
Status: Started (was: Assigned)
Project Member

Comment 7 by bugdroid1@chromium.org, Sep 26 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/adhd/+/9e6d58368b2f2d1a3a9d9281433470a6319e9847

commit 9e6d58368b2f2d1a3a9d9281433470a6319e9847
Author: Cheng-Yi Chiang <cychiang@chromium.org>
Date: Sat Sep 17 19:01:53 2016

CRAS: dps_mod_builtin - Add a swap_lr built-in module

This module swaps data on left and right channels.

BUG= chromium:645051 
TEST=Insert one swap_lr section in dsp.ini and check left and right
channels are swapped.
    [swap_lr]
    library=builtin
    label=swap_lr
    input_0={swap_lr:0}
    input_1={swap_lr:1}
    output_2={dst:1}
    output_3={dst:0}

Change-Id: I687e69bcc13375436f9535db97514b3a60580376
Reviewed-on: https://chromium-review.googlesource.com/386701
Commit-Ready: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>

[modify] https://crrev.com/9e6d58368b2f2d1a3a9d9281433470a6319e9847/cras/src/server/cras_dsp_mod_builtin.c

Project Member

Comment 8 by bugdroid1@chromium.org, Sep 26 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/adhd/+/4f86aad321250a527075476dac94241c24817521

commit 4f86aad321250a527075476dac94241c24817521
Author: Cheng-Yi Chiang <cychiang@chromium.org>
Date: Mon Sep 19 16:37:26 2016

CRAS: dsp - Add function to set a boolean variable

Rename cras_dsp_set_variable to cras_dsp_set_variable_string.
Add cras_dsp_set_variable_boolean to set a boolean variable.
Remove unused cras_dsp_sync declaration.

BUG= chromium:645051 
TEST=make check

Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
Change-Id: I6ef667629b5c170bb7cd854fc89c31aa2064aa03
Reviewed-on: https://chromium-review.googlesource.com/386702
Reviewed-by: Dylan Reid <dgreid@chromium.org>

[modify] https://crrev.com/4f86aad321250a527075476dac94241c24817521/cras/src/server/cras_dsp.c
[modify] https://crrev.com/4f86aad321250a527075476dac94241c24817521/cras/src/server/cras_dsp.h
[modify] https://crrev.com/4f86aad321250a527075476dac94241c24817521/cras/src/server/cras_iodev.c
[modify] https://crrev.com/4f86aad321250a527075476dac94241c24817521/cras/src/tests/dsp_unittest.cc
[modify] https://crrev.com/4f86aad321250a527075476dac94241c24817521/cras/src/tests/iodev_unittest.cc

Project Member

Comment 9 by bugdroid1@chromium.org, Sep 26 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/adhd/+/c9f56d936f63f56186b6daaa3f0c9abed828531a

commit c9f56d936f63f56186b6daaa3f0c9abed828531a
Author: Cheng-Yi Chiang <cychiang@chromium.org>
Date: Mon Sep 19 16:46:46 2016

CRAS: iodev - Add function to swap left and right channel using dsp

Add cras_iodev_dsp_set_swap_mode_for_node to swap left and right channel
using dsp. It is used as the default implementation of
set_swap_mode_for_node ops on alsa_io device.

To use this function, there must be a swap_lr section in dsp.ini:

  [swap_lr]
  library=builtin
  label=swap_lr
  disable=swap_lr_disabled
  input_0={swap_lr:0}
  input_1={swap_lr:1}
  output_2={dst:1}
  output_3={dst:0}

where {swap_lr:0}, {swap_lr:1} are the output ports of the block which
was before output sink (usually eq2).

cras_iodev_dsp_set_swap_mode_for_node must support two use cases:
- User sets swap mode when device is not playing.
- User sets swap mode when device is playing.

In the first use case, cras_iodev_update_dsp sets swap_lr_disabled
variable based on left_right_swapped on active node.
For the second use case, we need to udpate dsp in
cras_iodev_dsp_set_swap_mode_for_node so the change takes effect right
away. It is fine to do so because pipeline in the context is protected
by a mutex.

BUG= chromium:645051 
TEST=with modified dsp, check left right swap works using
cras_test_client --swap_left_right n:m:1.

Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
Change-Id: I78fa29f3bd9edbe59eda73242cc855aa8781bce0
Reviewed-on: https://chromium-review.googlesource.com/386703
Reviewed-by: Dylan Reid <dgreid@chromium.org>

[modify] https://crrev.com/c9f56d936f63f56186b6daaa3f0c9abed828531a/cras/src/server/cras_dsp.c
[modify] https://crrev.com/c9f56d936f63f56186b6daaa3f0c9abed828531a/cras/src/tests/alsa_io_unittest.cc
[modify] https://crrev.com/c9f56d936f63f56186b6daaa3f0c9abed828531a/cras/src/server/cras_iodev.h
[modify] https://crrev.com/c9f56d936f63f56186b6daaa3f0c9abed828531a/cras/src/tests/iodev_unittest.cc
[modify] https://crrev.com/c9f56d936f63f56186b6daaa3f0c9abed828531a/cras/src/server/cras_iodev.c
[modify] https://crrev.com/c9f56d936f63f56186b6daaa3f0c9abed828531a/cras/src/server/cras_alsa_io.c

Project Member

Comment 10 by bugdroid1@chromium.org, Sep 26 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/adhd/+/91e434c4cb91fdcc90fe893258d3c109ce6069c8

commit 91e434c4cb91fdcc90fe893258d3c109ce6069c8
Author: Cheng-Yi Chiang <cychiang@chromium.org>
Date: Wed Sep 21 10:40:53 2016

CRAS: dsp_ini: Add a swap_lr plugin before sink plugin

Add a swap_lr plugin before sink plugin and handle the port changes.
With this change, user does not need to change dsp.ini for left right
swap function.

BUG= chromium:645051 
TEST=cras_test_client --swap_left_right 8:1:1 on samus and check left
and right channel are swapped. There is no change in dsp ini file.

Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
Change-Id: Ifbb6823218d48bd87487d7d8f8d1b02a16bf9c8f
Reviewed-on: https://chromium-review.googlesource.com/387588

[modify] https://crrev.com/91e434c4cb91fdcc90fe893258d3c109ce6069c8/cras/src/tests/cras_dsp_pipeline_unittest.cc
[modify] https://crrev.com/91e434c4cb91fdcc90fe893258d3c109ce6069c8/cras/src/tests/dsp_ini_unittest.cc
[modify] https://crrev.com/91e434c4cb91fdcc90fe893258d3c109ce6069c8/cras/src/server/cras_dsp_ini.c

Status: Fixed (was: Started)
Status: Verified (was: Fixed)
Verified in ChromeOS ToT Build 8848.0.0 / 55.0.2874.0 on Minnie.

Sign in to add a comment