Repository navigation
codec_adapter: cadence: fix reset procedure + improve prepare - #4263
Conversation
This patch fixes wrong comment in generic processing function. Signed-off-by: Marcin Rajwa <marcin.rajwa@linux.intel.com>
After the reset codec should not need to be prepared again. We want reset procedure to just set all the parameters to their default values. Signed-off-by: Marcin Rajwa <marcin.rajwa@linux.intel.com>
There was a problem hiding this comment.
I don't think this will work.
cadence_codec_init_prcess will call API_CALL(cd, XA_API_CMD_INIT, XA_CMD_TYPE_INIT_PROCESS, NULL, ret);
This will fail because at cadence_codec_prepare() time there is no data in the input buffer. Does this work for Intel DAP codec?
There was a problem hiding this comment.
@dbaluta but do you think XA_CMD_TYPE_INIT_PROCESS requires data in the input buffer?
There was a problem hiding this comment.
@mrajwa yes. Here is what DAP VLLDP Programmers Guide says:
Same for mp3, aac or any other cadence codec. That's why i added the cadence_codec_init_process() call inside the copy() function
There was a problem hiding this comment.
We need to clarify this with cadence, namely what is the correct way of performing the reset - this is nowhere defined. I noticed INIT_PROCESS does reset the parameters by DAP lib code inspection.
Does this work for Intel DAP codec?
Yes it works for DAP
There was a problem hiding this comment.
Ok, i see. It doesn't work for mp3 for example. It needs to have some input data in the buffers. Care to start a thread with Cadence support?
I will be on vacation starting tomorrow returning on June, 9 but will still check my emails.
There was a problem hiding this comment.
Can you, for the testing purposes call the codec API with XA_CMD_TYPE_DO_RUNTIME_INIT command before the update of init_done at the end of the prepare() function? I have a feeling this may update the flag for compress streams.
There was a problem hiding this comment.
@mrajwa Ack. Will get back to you when get some time for testing.
There was a problem hiding this comment.
@mrajwa I checked with your suggestion. But no luck. The init_done is still set at 1.
API_CALL(cd, XA_API_CMD_EXECUTE, XA_CMD_TYPE_DO_RUNTIME_INIT, NULL, ret);
API_CALL(cd, XA_API_CMD_INIT, XA_CMD_TYPE_INIT_DONE_QUERY, &codec->cpd.init_done, ret);
I checked with Cadence support team and they confirm that this happens and might be a library bug. They will forward the problem to engineering.
Anyhow, what is exactly our problem to fix with this reset procedure. I'm sorry I'm still after vacation and is hard for me to navigate through the sea of emails. Can you provide a simple description of the problem we are trying to solve.
On another note, I'm having a problem with second cplay run. It's always get stuck. Anyhow, if I leave enough time between 1st run and 2nd run of cplay everything works (system runtime suspend/resume get into action).
Cc: @paulstelian97
There was a problem hiding this comment.
On another note, I'm having a problem with second cplay run. It's always get stuck. Anyhow, if I leave enough time between 1st run and 2nd run of cplay everything works (system runtime suspend/resume get into action).
Sounds like kernel runtime PM is rebooting FW and reseting the state ?
This patch simplifies reset procedure of cadence codecs by only calling the init_process() function in which XA_CMD_TYPE_INIT_PROCESS is the API call responsible for the actual reset of codec parameters. Signed-off-by: Marcin Rajwa <marcin.rajwa@linux.intel.com>
e091652 to
2e1fe1d
Compare
|
@lgirdwood yes I am ok with that. The bug only affects compress streams. |
|
@lgirdwood please don't merge this. This breaks existing working usecases. Actually, only the last commit ( codec_adapter: cadence: get init_done status on prepare ) is problematic. This breaks compress streams. Later edit: @mrajwa can you please confirm that the problem we are trying to fix is that running aplay/cplay multiple time fails at the second run? e.g @paulstelian97 I now you also looked at this. Do you have any insight? |
dbaluta
left a comment
There was a problem hiding this comment.
@lgirdwood @mrajwa leave us time until Wednesday to fix it.
Yes that's about it, plus keep in mind real time parameters like i.e post gain shall be reset to their default values as well. Current implementation allows for consecutive play but it doesn't reset parameters as it should.
Well, it's not us who should come up with a fix but Cadence... What did they tell you, are they working to fix that? |
|
@mrajwa they forwarded the problem to engineering and they are working for a fix. Will send them another mail to ask for status. |
|
@dbaluta okay, I would propose them dedicated API for parameters reset - the fact that we need to free all codec memory and allocate again shows the API is defective in the first place. |
|
@mrajwa I agree. Can you continue the discussion with Cadence on email via thread stared by me? |
|
@dbaluta sure but I didn't receive any thread, could you please forward? |
|
Ok, lets delay this until Cadence provide us with guidance. We can make this a hotfix when we are all aligned with each other and Cadence. |
This patch adds init_done status check at the very end of cadence_codec_prepare() function. This is needed to know if codec is fully prepared for the processing or not. Note we don't do anything with the value read at prepare, we postpone final verification until copy/process time since some codec variants require input in order to finish its initialization. Signed-off-by: Marcin Rajwa <marcin.rajwa@linux.intel.com>
2e1fe1d to
9c9642a
Compare
|
@dbaluta I have just updated with temporary solution for the init done bit. Is that OK for you? |
| * in codec_adapter_copy(). | ||
| */ | ||
| API_CALL(cd, XA_API_CMD_INIT, XA_CMD_TYPE_INIT_DONE_QUERY, | ||
| &codec->cpd.init_done, ret); |
There was a problem hiding this comment.
side note unrelated to this PR: I think it would be good to switch API_CALL() to
#define API_CALL(cd, cmd, sub_cmd, value) \
(cd)->api((cd)->self, cmd, sub_cmd, value)
and then do explicitly
ret = API_CALL(cd, cmd, sub_cmd, value);
There was a problem hiding this comment.
@lyakh not a bad idea, but I don't see a draw back from the current implementation either. It is just a mater of taste. We all know that API_CALL is a macro.
Remember spin_lock_irqsave in the Linux kernel?

This patch set:
Cadence documentation doesn't document reset procedure at all so for a long time we were just freeing all the memory codec allocated and start over. However this is very inefficient way of performing simple reset of parameters. Hence this patch https://github.com/thesofproject/sof/pull/4162/files tried to simplify it and while it does reset parameters it also breaks the flow since XA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS is only allowed during INIT phase. After code inspection of the codec library XA_CMD_TYPE_INIT_PROCESS seems to do what we need to perform the reset and hence this patch relies on that API call.