Skip to content

Commit ec577bc

Browse files
mrajwalgirdwood
authored andcommitted
kpb: check if draining speed should be controlled
This patch checks if draining should be controlled in terms of speed. Such condition may be necessary if host buffer is smaller than KPB's history buffer. Signed-off-by: Marcin Rajwa <marcin.rajwa@linux.intel.com>
1 parent a1c498e commit ec577bc

2 files changed

Lines changed: 25 additions & 14 deletions

File tree

src/audio/kpb.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -995,18 +995,26 @@ static void kpb_init_draining(struct comp_dev *dev, struct kpb_client *cli)
995995

996996
} while (buff != first_buff);
997997

998-
/* Calculate time in clock ticks each draining event shall
999-
* take place. This time will be used to synchronize us with
1000-
* an end application interrupts.
998+
/* Should we drain in synchronized mode (sync_draining_mode)?
999+
* Note! We have already verified host params during
1000+
* kpb_prepare().
10011001
*/
1002-
1003-
drain_interval = (host_period_size / bytes_per_ms) *
1004-
ticks_per_ms;
1005-
/* In draining intervals we will fill only two periods
1006-
* and give host time to read it.
1007-
* This way we are safe to not overflow host buffer.
1008-
*/
1009-
period_bytes_limit = host_period_size * 2;
1002+
if (kpb->hb_buffer_size > host_buffer_size) {
1003+
/* Calculate time in clock ticks each draining event
1004+
* shall take place. This time will be used to
1005+
* synchronize us with application interrupts.
1006+
*/
1007+
drain_interval = (host_period_size / bytes_per_ms) *
1008+
ticks_per_ms;
1009+
period_bytes_limit = host_period_size;
1010+
trace_kpb_with_ids(dev, "kpb_init_draining(): sync_draining_mode selected with interval %d [uS].",
1011+
drain_interval * 1000 / ticks_per_ms);
1012+
} else {
1013+
/* Unlimited draining */
1014+
drain_interval = 0;
1015+
period_bytes_limit = 0;
1016+
trace_kpb_with_ids(dev, "kpb_init_draining: unlimited draining speed selected.");
1017+
}
10101018

10111019
trace_kpb_with_ids(dev, "kpb_init_draining(), "
10121020
"schedule draining task");
@@ -1019,6 +1027,7 @@ static void kpb_init_draining(struct comp_dev *dev, struct kpb_client *cli)
10191027
kpb->draining_task_data.drain_interval = drain_interval;
10201028
kpb->draining_task_data.pb_limit = period_bytes_limit;
10211029
kpb->draining_task_data.dev = dev;
1030+
kpb->draining_task_data.sync_mode_on = kpb->sync_draining_mode;
10221031

10231032
/* Set host-sink copy mode to blocking */
10241033
comp_set_attribute(kpb->host_sink->sink, COMP_ATTR_COPY_TYPE,
@@ -1063,6 +1072,7 @@ static enum task_state kpb_draining_task(void *arg)
10631072
size_t time_taken = 0;
10641073
size_t *rt_stream_update = &draining_data->buffered_while_draining;
10651074
struct comp_data *kpb = comp_get_drvdata(draining_data->dev);
1075+
bool sync_mode_on = &draining_data->sync_mode_on;
10661076

10671077
trace_kpb("kpb_draining_task(), start.");
10681078

@@ -1081,7 +1091,8 @@ static enum task_state kpb_draining_task(void *arg)
10811091
/* Are we ready to drain further or host still need some time
10821092
* to read the data already provided?
10831093
*/
1084-
if (next_copy_time > platform_timer_get(platform_timer)) {
1094+
if (sync_mode_on &&
1095+
next_copy_time > platform_timer_get(platform_timer)) {
10851096
period_bytes = 0;
10861097
period_copy_start = platform_timer_get(platform_timer);
10871098
continue;
@@ -1090,7 +1101,6 @@ static enum task_state kpb_draining_task(void *arg)
10901101
}
10911102

10921103
size_to_read = (uint32_t)buff->end_addr - (uint32_t)buff->r_ptr;
1093-
10941104
if (size_to_read > sink->free) {
10951105
if (sink->free >= history_depth)
10961106
size_to_copy = history_depth;
@@ -1124,7 +1134,7 @@ static enum task_state kpb_draining_task(void *arg)
11241134
comp_copy(sink->sink);
11251135
}
11261136

1127-
if (period_bytes >= period_bytes_limit) {
1137+
if (sync_mode_on && period_bytes >= period_bytes_limit) {
11281138
current_time = platform_timer_get(platform_timer);
11291139
time_taken = current_time - period_copy_start;
11301140
next_copy_time = current_time + drain_interval -

src/include/sof/audio/kpb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ struct dd {
121121
size_t drain_interval;
122122
size_t pb_limit; /**< Period bytes limit */
123123
struct comp_dev *dev;
124+
bool sync_mode_on;
124125
};
125126

126127
#ifdef UNIT_TEST

0 commit comments

Comments
 (0)