From 85e4b7d7eafc3a06a725085f7845aa616926455b Mon Sep 17 00:00:00 2001 From: Keyon Jie Date: Tue, 14 May 2019 18:53:28 +0800 Subject: [PATCH] kpb: stop pipeline copy at draining Add a state KPB_STATE_REALTIME for the realtime copy, and stop propagate copying while at draining. Signed-off-by: Keyon Jie --- src/audio/kpb.c | 24 +++++++++--------------- src/include/sof/audio/kpb.h | 1 + 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/audio/kpb.c b/src/audio/kpb.c index 8a912a307a65..9c29c10b96de 100644 --- a/src/audio/kpb.c +++ b/src/audio/kpb.c @@ -350,7 +350,6 @@ static int kpb_prepare(struct comp_dev *dev) /* Init private data */ cd->kpb_no_of_clients = 0; cd->buffered_data = 0; - cd->state = KPB_STATE_BUFFERING; /* Init history buffer */ kpb_clear_history_buffer(cd->history_buffer); @@ -437,16 +436,12 @@ static int kpb_reset(struct comp_dev *dev) /* Reset history buffer */ kpb->is_internal_buffer_full = false; kpb_clear_history_buffer(kpb->history_buffer); - /* Reset amount of buffered data */ kpb->buffered_data = 0; /* Unregister KPB for async notification */ notifier_unregister(&kpb->kpb_events); - /* Reset KPB state to initial buffering state */ - kpb->state = KPB_STATE_BUFFERING; - return comp_set_state(dev, COMP_TRIGGER_RESET); } @@ -474,17 +469,15 @@ static int kpb_copy(struct comp_dev *dev) /* Get source and sink buffers */ source = list_first_item(&dev->bsource_list, struct comp_buffer, sink_list); - sink = (kpb->state == KPB_STATE_BUFFERING) ? kpb->rt_sink - : kpb->cli_sink; - /* Pause selector copy during draining and/or draining on demand. - * We keep selector in this "paused" state as long as draining - * is going and later during direct copy to client's/host sink, - * in so called "draining on demand" state. In order to rearm - * detection algorithm kpb_reset is needed. - */ - if (kpb->state != KPB_STATE_BUFFERING) + /* Stop copying downstream if in draining */ + if (kpb->state == KPB_STATE_DRAINING_ON_DEMAND) { + comp_update_buffer_consume(source, source->avail); return PPL_STATUS_PATH_STOP; + } + + sink = (kpb->state == KPB_STATE_BUFFERING) ? kpb->rt_sink + : kpb->cli_sink; /* Process source data */ /* Check if there are valid pointers */ @@ -795,6 +788,7 @@ static void kpb_init_draining(struct comp_data *kpb, struct kpb_client *cli) comp_set_attribute(kpb->cli_sink->sink, COMP_ATTR_COPY_BLOCKING, 1); + kpb->state = KPB_STATE_DRAINING_ON_DEMAND; /* Schedule draining task */ schedule_task(&kpb->draining_task, 0, 0, SOF_SCHEDULE_FLAG_IDLE); @@ -855,7 +849,7 @@ static uint64_t kpb_draining_task(void *arg) /* Draining is done. Now switch KPB to copy real time stream * to client's sink */ - *draining_data->state = KPB_STATE_DRAINING_ON_DEMAND; + *draining_data->state = KPB_STATE_REALTIME; /* Reset host-sink copy mode back to unblocking */ comp_set_attribute(sink->sink, COMP_ATTR_COPY_BLOCKING, 0); diff --git a/src/include/sof/audio/kpb.h b/src/include/sof/audio/kpb.h index 382a1ed919b6..938b2a354d79 100644 --- a/src/include/sof/audio/kpb.h +++ b/src/include/sof/audio/kpb.h @@ -60,6 +60,7 @@ enum kpb_state { KPB_STATE_BUFFERING = 0, KPB_STATE_DRAINING_ON_DEMAND, + KPB_STATE_REALTIME, }; enum kpb_event {