Skip to content

Commit cf1ab40

Browse files
committed
google_rtc_audio_processing: Cache frame size from source/sink
Don't query the frame size every time it's used, cache it in the component struct to save a few cycles. This also permits a workaround: on MTL the mic stream lies about its format, claiming s26_le when it's really s32_le. We can leave the existing format error in place and just use our own configuration for now. Signed-off-by: Andy Ross <andyross@google.com>
1 parent d92d9a6 commit cf1ab40

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/audio/google/google_rtc_audio_processing.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ struct google_rtc_audio_processing_comp_data {
9191
int aec_reference_source;
9292
int raw_microphone_source;
9393
struct comp_buffer *ref_comp_buffer;
94+
int ref_frame_bytes;
95+
int out_frame_bytes;
9496
};
9597

9698
#if CONFIG_GOOGLE_RTC_AUDIO_PROCESSING_MIC_BITS == 16
@@ -607,14 +609,24 @@ static int google_rtc_audio_processing_prepare(struct processing_module *mod,
607609
if (mic_fmt != bits_fmt(CONFIG_GOOGLE_RTC_AUDIO_PROCESSING_MIC_BITS)) {
608610
comp_err(dev, "Mic stream must be %d bit samples\n",
609611
CONFIG_GOOGLE_RTC_AUDIO_PROCESSING_MIC_BITS);
610-
ret = -EINVAL;
612+
613+
// FIXME: squash for now, the streams lie. See below.
614+
//ret = -EINVAL;
611615
}
612616

613617
if (mic_fmt != out_fmt) {
614618
comp_err(dev, "Mismatched in/out frame format");
615619
ret = -EINVAL;
616620
}
617621

622+
// FIXME: the streams have a bad format on MTL, so we can't
623+
// use this API. Compute by hand.
624+
//
625+
//cd->ref_frame_bytes = source_get_frame_bytes(sources[cd->aec_reference_source]);
626+
//cd->out_frame_bytes = sink_get_frame_bytes(sinks[0]);
627+
cd->ref_frame_bytes = sizeof(mic_sample_t) * source_get_channels(sources[cd->aec_reference_source]);
628+
cd->out_frame_bytes = cd->ref_frame_bytes;
629+
618630
/* Blobs sent during COMP_STATE_READY is assigned to blob_handler->data
619631
* directly, so comp_is_new_data_blob_available always returns false.
620632
*/
@@ -777,7 +789,7 @@ static int mod_process(struct processing_module *mod, struct sof_source **source
777789
* samples so AEC compares the most recent values.
778790
*/
779791
if (ref_ok && fref > fmic)
780-
source_release_data(ref, (fref - fmic) * source_get_frame_bytes(ref));
792+
source_release_data(ref, (fref - fmic) * cd->ref_frame_bytes);
781793

782794
for (frames_rem = frames; frames_rem; frames_rem -= n) {
783795
n = MIN(frames_rem, cd->num_frames - cd->buffered_frames);
@@ -814,7 +826,7 @@ static bool mod_is_ready_to_process(struct processing_module *mod,
814826
* Currently the topology sets IBS incorrectly
815827
*/
816828
if (ref_ok && (source_get_data_available(ref)
817-
< cd->num_frames * source_get_frame_bytes(ref)))
829+
< cd->num_frames * cd->ref_frame_bytes))
818830
return false;
819831

820832
if (source_get_data_available(mic) < source_get_min_available(mic))
@@ -823,7 +835,7 @@ static bool mod_is_ready_to_process(struct processing_module *mod,
823835
/* Output comes out all at once, the output sink much have
824836
* space for the full block
825837
*/
826-
if (sink_get_free_size(out) < cd->num_frames * sink_get_frame_bytes(out))
838+
if (sink_get_free_size(out) < cd->num_frames * cd->out_frame_bytes)
827839
return false;
828840

829841
return true;

0 commit comments

Comments
 (0)