Skip to content

Commit 2427f43

Browse files
committed
Audio: Modify audio_stream_avail_frames_aligned() to align for source
This change fixes an issue that is caused by the logic in the function that calculates the aligned frames counts separately for source and sink and then returns the smaller number of them. The fixed logic checks the maximum number of frames that could be processed from source to sink and adjusts the the number down with source align constraints. It prevents an issue where a downstream module in pipeline modifies align constraint for it's source that is previous module's sink. A more relaxed constraint could then break source align criteria if the number of frames to process is limited by sink. The proposed logic for align follows only source align criteria to avoid conflicting constraints. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 20c06c4 commit 2427f43

1 file changed

Lines changed: 19 additions & 22 deletions

File tree

src/include/sof/audio/audio_stream.h

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -590,28 +590,6 @@ audio_stream_avail_frames(const struct audio_stream *source,
590590
return MIN(src_frames, sink_frames);
591591
}
592592

593-
/**
594-
* Computes maximum number of frames aligned that can be copied from
595-
* source buffer to sink buffer, verifying number of available source
596-
* frames vs. free space available in sink.
597-
* @param source Buffer of source.
598-
* @param sink Buffer of sink.
599-
* @return Number of frames.
600-
*/
601-
static inline uint32_t
602-
audio_stream_avail_frames_aligned(const struct audio_stream *source,
603-
const struct audio_stream *sink)
604-
{
605-
uint32_t src_frames = (audio_stream_get_avail_bytes(source) >>
606-
source->runtime_stream_params.align_shift_idx) *
607-
source->runtime_stream_params.align_frame_cnt;
608-
uint32_t sink_frames = (audio_stream_get_free_bytes(sink) >>
609-
sink->runtime_stream_params.align_shift_idx) *
610-
sink->runtime_stream_params.align_frame_cnt;
611-
612-
return MIN(src_frames, sink_frames);
613-
}
614-
615593
/**
616594
* Rounds down a frame count to meet the alignment constraint of the stream.
617595
* @param stream Audio stream with alignment requirements set.
@@ -658,6 +636,25 @@ static inline uint32_t audio_stream_align_frames_round_nearest(const struct audi
658636
return ROUND_DOWN(frames + (align >> 1), align);
659637
}
660638

639+
/**
640+
* Computes maximum number of frames aligned with source align criteria
641+
* that can be copied from source buffer to sink buffer, verifying number
642+
* of available source frames vs. free space available in sink.
643+
* @param source Buffer of source.
644+
* @param sink Buffer of sink.
645+
* @return Number of frames.
646+
*/
647+
static inline uint32_t
648+
audio_stream_avail_frames_aligned(const struct audio_stream *source,
649+
const struct audio_stream *sink)
650+
{
651+
uint32_t src_frames = audio_stream_get_avail_frames(source);
652+
uint32_t sink_frames = audio_stream_get_free_frames(sink);
653+
uint32_t n = MIN(src_frames, sink_frames);
654+
655+
return audio_stream_align_frames_round_down(source, n);
656+
}
657+
661658
/**
662659
* Updates the buffer state after writing to the buffer.
663660
* @param buffer Buffer to update.

0 commit comments

Comments
 (0)