-
Notifications
You must be signed in to change notification settings - Fork 350
ASRC: SRC: Fail params() when DAI does not provide sink stream format information #2642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ASRC: SRC: Fail params() when DAI does not provide sink stream format information #2642
Conversation
|
PR #2539 kind of add can avoid the issue for HDA. In addition the stream rate need to be set. |
lgirdwood
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth while to validate this against supported rates ?
src/audio/asrc/asrc.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we check anywhere else for supported source /sink rates ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's check in prepare() where the rate conversion filters are set up for copy(). But this same fail would happen in prepare() if I moved this code there. I think it's better to fail early when we know things won't later work.
There used to be in params() where this error happens a stream params rewrite for topology new() provided rate for sink or source but it was removed when pipeline walk was enhanced to be bi-directional.
The topology provided 48k value for the fixed side buffer is still available (ignored now) and I could revert that pipeline upstream walk impact for sink_rate == 0 or source_rate == 0 cases. In addition I should copy the PCM format from the known buffer. But I don't know if such is appropriate thing to do.
(edited to make my description better understandable for both playback and capture directions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@singalsu for my education, why would the sink_rate be 0 for HDA or ALH? Is it because they are not using the timer-based pipeline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because in hda.c (and alh.c).
static int hda_get_hw_params(struct dai *dai,
struct sof_ipc_stream_params *params, int dir)
{
/* 0 means variable */
params->rate = 0;
params->channels = 0;
params->buffer_fmt = 0;
params->frame_fmt = 0;
return 0;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@singalsu thanks but I was wondering conceptually why it is so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@singalsu it's best to check as early as possible and base the check on the supported kconfig ASRC settings and topology settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initialization is split to new(), params(), and prepare(). We've had a lot of changes in streaming start and done fixes by moving parts of initialization between these functions. As result (make small easy to review patches) it might not be the most logical any more.
But this issue is not related to Kconfig (where reject for non-supported rate happens now in prepare()).
This is related to topology such way the with the bi-directional pipeline walk the capability of SRC and ASRC to alter downstream parameters via topology provided rate was removed. We get now that information from SSP and DMIC DAI types. But not from HDA and ALH.
I could ugly fix this by implemeting to SRC components a pipeline parameters override when the stream parameter appear as zero but didn't do it because pipeline should take care of such, not individual components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@singalsu this makes sense but with thesofproject/linux#1943 this problem shouldnt be seen no? But nevertheless, a check is a good thing to have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, similar PR is needed for HDA kernel and for both the FW counterpart. Wrong parameters can and will happen in future too so it's useful to have check in component for sane parameters, especially when a crash happens.
src/audio/src/src.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like in a more fuzzy way described above I think this is the best way to handle streaming abort to prevent firmware crash.
When the rate converter filter is initialized in prepare() there's need to know the max frame size. Getting the output rate 0 Hz to fail similarly as request to initialize for 48000 Hz to 45678 Hz is not less code than this.
src/audio/asrc/asrc.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!cd->sink_rate)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I'll change.
Off topic I wonder what's the rationale for this Linux kernel rule. The compiler can issue the same compare to zero operation when == 0 seen plus it's more readable in my opinion. Is it to avoid accidental if (variable = 0) {} ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about the rationale but seems like the universally accepted pattern. @lyakh any insights?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The just pushed version fixes this.
This patch prevents a firmware crash due to divide by zero. It can happen with DAI types those do not return actual values in pipeline walk with e.g. hda_get_hw_params(). Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This patch prevents a firmware crash due to divide by zero. It can happen with DAI types those do not return actual values in pipeline walk with e.g. hda_get_hw_params(). Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
e96cdac to
94ed761
Compare
|
SOFCI TEST |
This can happen with HDA and ALH and avoids a firmware crash.