@@ -1721,9 +1721,8 @@ static enum task_state kpb_draining_task(void *arg)
17211721 struct history_buffer * buff = draining_data -> hb ;
17221722 size_t drain_req = draining_data -> drain_req ;
17231723 size_t sample_width = draining_data -> sample_width ;
1724- size_t size_to_read ;
1724+ size_t avail ;
17251725 size_t size_to_copy ;
1726- bool move_buffer = false;
17271726 uint32_t drained = 0 ;
17281727 uint64_t draining_time_start ;
17291728 uint64_t draining_time_end ;
@@ -1791,21 +1790,9 @@ static enum task_state kpb_draining_task(void *arg)
17911790 period_copy_start = sof_cycle_get_64 ();
17921791 }
17931792
1794- size_to_read = (uintptr_t )buff -> end_addr - (uintptr_t )buff -> r_ptr ;
1795-
1796- if (size_to_read > audio_stream_get_free_bytes (& sink -> stream )) {
1797- if (audio_stream_get_free_bytes (& sink -> stream ) >= drain_req )
1798- size_to_copy = drain_req ;
1799- else
1800- size_to_copy = audio_stream_get_free_bytes (& sink -> stream );
1801- } else {
1802- if (size_to_read > drain_req ) {
1803- size_to_copy = drain_req ;
1804- } else {
1805- size_to_copy = size_to_read ;
1806- move_buffer = true;
1807- }
1808- }
1793+ avail = (uintptr_t )buff -> end_addr - (uintptr_t )buff -> r_ptr ;
1794+ size_to_copy = MIN (avail ,
1795+ MIN (drain_req , audio_stream_get_free_bytes (& sink -> stream )));
18091796
18101797 kpb_drain_samples (buff -> r_ptr , & sink -> stream , size_to_copy ,
18111798 sample_width );
@@ -1817,10 +1804,10 @@ static enum task_state kpb_draining_task(void *arg)
18171804 kpb -> hd .free += MIN (kpb -> hd .buffer_size -
18181805 kpb -> hd .free , size_to_copy );
18191806
1820- if (move_buffer ) {
1807+ /* no data left in the current buffer -- switch to the next buffer */
1808+ if (size_to_copy == avail ) {
18211809 buff -> r_ptr = buff -> start_addr ;
18221810 buff = buff -> next ;
1823- move_buffer = false;
18241811 }
18251812
18261813 if (size_to_copy ) {
0 commit comments