Skip to content

[DNM (for v1.8-rc2) ] CA: cadence: update stream params during config apply - #4008

Closed
mrajwa wants to merge 2 commits into
thesofproject:mainfrom
mrajwa:dev
Closed

mrajwa wants to merge 2 commits into
thesofproject:mainfrom
mrajwa:dev

Conversation

@mrajwa

@mrajwa mrajwa commented Apr 7, 2021

Copy link
Copy Markdown
Contributor

This patch updates configuration parameters read from the topology
or during runtime with the stream parameters. Hence settings like
sampling rate or sample width are aligned with stream parameters.
The mismatch in those parameters may result in audio glitches or
stream stalls, just to name a few potential issues.

Signed-off-by: Marcin Rajwa marcin.rajwa@linux.intel.com

Comment thread src/audio/codec_adapter/codec/cadence.c Outdated
Comment thread src/audio/codec_adapter/codec/cadence.c Outdated

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need some comments to help guide other developers through the Cadence differences.

Comment thread src/audio/codec_adapter/codec/cadence.c Outdated
Comment thread src/audio/codec_adapter/codec/cadence.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also have a big comment here explaining which Cadence codecs this applies to and state other may differ.

@mrajwa
mrajwa force-pushed the dev branch 2 times, most recently from f75d28f to f7742a4 Compare April 8, 2021 21:25
Comment thread src/audio/codec_adapter/codec/cadence.c Outdated
Comment thread src/audio/codec_adapter/codec/cadence.c Outdated
Comment thread src/audio/codec_adapter/codec/cadence.c Outdated
@lgirdwood

Copy link
Copy Markdown
Member

@dbaluta I'm aligned if you need to take over whilst @mrajwa is busy.

@dbaluta

dbaluta commented Apr 12, 2021

Copy link
Copy Markdown
Collaborator

@lgirdwood thanks will take over this as it also overlaps with some patches I need to send for somehow similar issue.

@mrajwa

mrajwa commented Apr 13, 2021

Copy link
Copy Markdown
Contributor Author

@lgirdwood thanks will take over this as it also overlaps with some patches I need to send for somehow similar issue.

Hmm I'll update this PR later today, please don't close

mrajwa added 2 commits April 27, 2021 12:34
This patch assigns IDs of each stream parameter that
needs to be updated in runtime. This is because each
codec uses different params and we need a consistent
method of update.

Signed-off-by: Marcin Rajwa <marcin.rajwa@linux.intel.com>
This patch takes care of the update of stream
parameters during runtime. It is important to
start stream base on its runtime params and not
those read from the topology which may not mach
those of stream.

Signed-off-by: Marcin Rajwa <marcin.rajwa@linux.intel.com>
@mrajwa
mrajwa force-pushed the dev branch 3 times, most recently from 549d261 to b8ba597 Compare April 27, 2021 10:47
@mrajwa

mrajwa commented Apr 27, 2021

Copy link
Copy Markdown
Contributor Author

@dbaluta I have finally updated. I would appreciate if you could review :)

Comment thread src/audio/codec_adapter/codec/cadence.c Outdated
@mrajwa

mrajwa commented Apr 29, 2021

Copy link
Copy Markdown
Contributor Author

@lgirdwood @paulstelian97 @dbaluta updated. Are we good to merge?

@paulstelian97 paulstelian97 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the fact that we are using comp_err for something that's not an error this looks good now.

@zrombel

zrombel commented Apr 29, 2021

Copy link
Copy Markdown

CI is all green so PR is good to merge for me :)

@dbaluta

dbaluta commented May 4, 2021

Copy link
Copy Markdown
Collaborator

@lgirdwood Yes, I figured out the problem. update_params() tries to do invalid set parameters configuration for MP3 for example and prepare fails.

E.g setting sample rate for MP3 is an invalid operation! sample rate can only be read with a call to Cadence API.

cadence_codec_prepare()
   => update_stream_params
       =>        API_CALL(cd, XA_API_CMD_SET_CONFIG_PARAM, cd->sample_rate_id, &sample_rate, ret)
                 if (LIB_IS_FATAL_ERROR(ret)) {
                      comp_err(dev, "update_stream_params(): failed to set sample rate."); <===== API fails here!
                      goto err;
                  }

@lgirdwood

Copy link
Copy Markdown
Member

@dbaluta ok, does this mean this is good to merge or can it wait for rc2 ? (it also need a conflict fixed)

@dbaluta

dbaluta commented May 4, 2021 •

Copy link
Copy Markdown
Collaborator

@lgirdwood it's no good to merge. lets wait for rc2

@mrajwa

mrajwa commented May 5, 2021

Copy link
Copy Markdown
Contributor Author

@dbaluta are you going to fix that mp3 issue or you want me to do this? Although I don't have that codec on my disposal.. ;/

@dbaluta

dbaluta commented May 5, 2021

Copy link
Copy Markdown
Collaborator

@mrajwa let me send you my version of this patch.

@lgirdwood lgirdwood changed the title CA: cadence: update stream params during config apply [DNM (for v1.8-rc2) ] CA: cadence: update stream params during config apply May 5, 2021
@dbaluta

dbaluta commented May 5, 2021

Copy link
Copy Markdown
Collaborator

@mrajwa what do you think about this? #4139

@mrajwa

mrajwa commented May 7, 2021 •

Copy link
Copy Markdown
Contributor Author

@dbaluta #4139 seems to be just a copy and rework of this patch. Could you please tell why the update of sample rate fails for MP3 codec? Maybe we can make a define which keep record of updates that need to be performed? I am thinking about some sort of a mask like 0x03 -> first n bits can define parameters to be updated.

@dbaluta

dbaluta commented May 10, 2021

Copy link
Copy Markdown
Collaborator

@mrajwa I will provide you a detailed answer to this on Tuesday. As I said above Cadence algorithms for MP3 (for example) will result in a fatal error when one tries to set sample rate or number of channels.

The Cadence algorithm will figure out by itself these parameters by parsing the mp3 header.

@mrajwa
mrajwa force-pushed the dev branch 3 times, most recently from 11da945 to 27afe5d Compare July 27, 2021 18:25

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update @mrajwa !
@dbaluta I guess you can test this with your Cadence library too ?

@dbaluta

dbaluta commented Jul 28, 2021

Copy link
Copy Markdown
Collaborator

@lgirdwood will test this today.


static int update_stream_params(struct comp_dev *dev)
{
int ret = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC API_CALL() was ret = ... in which case this initialisation is superfluous

@dbaluta

dbaluta commented Jul 28, 2021

Copy link
Copy Markdown
Collaborator

@lgirdwood @mrajwa what branch should I test this on? It looks like it cannot be cleanly applied on main / or v1.8 branch.

@dbaluta

dbaluta commented Jul 28, 2021

Copy link
Copy Markdown
Collaborator

@lgirdwood @mrajwa this patch fails for AAC and MP3 because some parameters are not supported for these codecs and the error is fatal.

For example:

  • setting sample rate for MP3 codec returns XA_API_FATAL_INVALID_CMD_TYPE.

We can merge this patch with the following compromise. Do not return an error if setting a parameter fails:

e.g

        /* sample rate */
        API_CALL(cd, XA_API_CMD_SET_CONFIG_PARAM, cd->sample_rate_id,
                 &sample_rate, ret);
-       if (LIB_IS_FATAL_ERROR(ret)) {
-               comp_err(dev, "update_stream_params(): failed to set sample rate.");
-               goto err;
-       }
+       if (LIB_IS_FATAL_ERROR(ret))
+               comp_err(dev, "update_stream_params(): failed to set sample rate, err = %x", ret);
+

there are few other comments which i will add inline.

CADENCE_SAMPLE_WIDTH_ID = 0x02,
CADENCE_CHANNELS_COUNT_ID = 0x04
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we need a semicolon:

        CADENCE_SAMPLE_WIDTH_ID = 0x02,
        CADENCE_CHANNELS_COUNT_ID = 0x04
-}
+};




/*****************************************************************************/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the new lines from here. Also, add the following changes:

--- a/src/audio/codec_adapter/CMakeLists.txt
+++ b/src/audio/codec_adapter/CMakeLists.txt
@@ -4,6 +4,7 @@ add_local_sources(sof codec_adapter.c codec/generic.c)
 
 if(CONFIG_CADENCE_CODEC)
 add_local_sources(sof codec/cadence.c)
+target_include_directories(sof PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../../include/sof/audio/cadence)
--- a/src/include/sof/audio/codec_adapter/codec/cadence.h
+++ b/src/include/sof/audio/codec_adapter/codec/cadence.h
@@ -13,6 +13,9 @@
#include <sof/audio/cadence/xa_error_standards.h>
#include <sof/audio/cadence/xa_memory_standards.h>

+#include <sof/audio/cadence/mp3_dec/xa_mp3_dec_api.h>
+#include <sof/audio/cadence/aac_dec/xa_aac_dec_api.h>

I will add a PR with these changes later if you want.

if (LIB_IS_FATAL_ERROR(ret)) {
comp_err(dev, "update_stream_params(): failed to set sample width.");
goto err;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here only print a warning if there is an error but do not return err from this function.

@lgirdwood

lgirdwood commented Sep 20, 2021 •

Copy link
Copy Markdown
Member

@mrajwa @dbaluta any updates here ? Do we need this or does the latest Cadence code have a fix ?

@mrajwa

mrajwa commented Sep 20, 2021

Copy link
Copy Markdown
Contributor Author

@dbaluta do you happen to know if Cadence fixed the reset bug in their library? If no let's resurrect our workaround for this here.

@iuliana-prodan
iuliana-prodan self-requested a review September 20, 2021 13:44
@dbaluta

dbaluta commented Sep 20, 2021 •

Copy link
Copy Markdown
Collaborator

@dbaluta do you happen to know if Cadence fixed the reset bug in their library? If no let's resurrect our workaround for this here.

No news from Cadence. Also, @mrajwa can you remind me what was the reset bug? Instead of current PR I remember I prepared this PR #4139 which should be similar for Intel uses cases but doesn't break IMX usecases.

@mrajwa

mrajwa commented Sep 22, 2021

Copy link
Copy Markdown
Contributor Author

@daniel, ohh sorry I confused, this is not about the reset this is about the update of stream params, we really need this patch. Unfortunately I no longer have my test board, can you retest it on your side?

@dbaluta

dbaluta commented Sep 22, 2021

Copy link
Copy Markdown
Collaborator

@mrajwa OK, will retest it until EOW. But I will retest the equivalent #4139 which should be equivalent with your PR but without breaking IMX usecases.

Unfortunately, I cannot test your DAP algorithm. Could we assign someone from Intel to do it?

@mrajwa

mrajwa commented Sep 22, 2021

Copy link
Copy Markdown
Contributor Author

Ok I will update this patch as it is unmergable now and ask our internal validation to test it.

CC: @wszypelt

@kv2019i

kv2019i commented Apr 20, 2022

Copy link
Copy Markdown
Collaborator

No activity in almost half a year, should we close? @mrajwa @dbaluta @lgirdwood

@lgirdwood lgirdwood closed this Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants