Skip to content

Commit e24231d

Browse files
committed
mixin: Add eos notification
Add sending notification when end of stream is detected. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent 8da9ef7 commit e24231d

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

src/audio/mixin_mixout/mixin_mixout.c

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ struct mixin_data {
7979
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
8080
uint32_t last_reported_underrun;
8181
uint32_t underrun_notification_period;
82+
uint32_t eos_delay_periods;
83+
bool eos_delay_configured;
8284
#endif
8385
};
8486

@@ -248,23 +250,40 @@ static void silence(struct cir_buf_ptr *stream, uint32_t start_offset,
248250

249251
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
250252
static void mixin_check_notify_underrun(struct comp_dev *dev, struct mixin_data *mixin_data,
253+
enum sof_audio_buffer_state state,
251254
size_t source_avail, size_t sinks_free)
252255
{
256+
const bool eos_detected = state == AUDIOBUF_STATE_END_OF_STREAM_FLUSH ||
257+
state == AUDIOBUF_STATE_END_OF_STREAM;
258+
253259
struct ipc_msg *notify;
254260

255261
mixin_data->last_reported_underrun++;
256262

257-
if (!source_avail && mixin_data->last_reported_underrun >=
258-
mixin_data->underrun_notification_period) {
259-
mixin_data->last_reported_underrun = 0;
263+
if (!source_avail || eos_detected) {
264+
if (eos_detected) {
265+
if (mixin_data->eos_delay_configured) {
266+
mixin_data->eos_delay_periods--;
267+
} else {
268+
pipeline_get_dai_comp_latency(dev->pipeline->pipeline_id,
269+
&mixin_data->eos_delay_periods);
270+
mixin_data->eos_delay_configured = true;
271+
}
272+
}
273+
274+
if ((!eos_detected && mixin_data->last_reported_underrun >=
275+
mixin_data->underrun_notification_period) ||
276+
(eos_detected && mixin_data->eos_delay_periods == 0)) {
277+
mixin_data->last_reported_underrun = 0;
260278

261-
notify = ipc_notification_pool_get(IPC4_RESOURCE_EVENT_SIZE);
262-
if (!notify)
263-
return;
279+
notify = ipc_notification_pool_get(IPC4_RESOURCE_EVENT_SIZE);
280+
if (!notify)
281+
return;
264282

265-
mixer_underrun_notif_msg_init(notify, dev->ipc_config.id, false,
266-
source_avail, sinks_free);
267-
ipc_msg_send(notify, notify->tx_data, false);
283+
mixer_underrun_notif_msg_init(notify, dev->ipc_config.id, eos_detected,
284+
source_avail, sinks_free);
285+
ipc_msg_send(notify, notify->tx_data, false);
286+
}
268287
}
269288
}
270289
#endif
@@ -294,9 +313,10 @@ static int mixin_process(struct processing_module *mod,
294313
uint32_t source_avail_frames, sinks_free_frames;
295314
struct processing_module *active_mixouts[MIXIN_MAX_SINKS];
296315
uint16_t sinks_ids[MIXIN_MAX_SINKS];
316+
struct pending_frames *pending_frames;
297317
uint32_t bytes_to_consume = 0;
298318
uint32_t frames_to_copy;
299-
struct pending_frames *pending_frames;
319+
size_t frame_bytes;
300320
int i, ret;
301321
struct cir_buf_ptr source_ptr;
302322

@@ -389,10 +409,10 @@ static int mixin_process(struct processing_module *mod,
389409
return 0;
390410

391411
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
392-
size_t frame_bytes = source_get_frame_bytes(sources[0]);
393-
size_t min_frames = MIN(dev->frames, sinks_free_frames);
412+
frame_bytes = source_get_frame_bytes(sources[0]);
413+
const size_t min_frames = MIN(dev->frames, sinks_free_frames);
394414

395-
mixin_check_notify_underrun(dev, mixin_data,
415+
mixin_check_notify_underrun(dev, mixin_data, source_get_state(sources[0]),
396416
source_avail_frames * frame_bytes,
397417
min_frames * frame_bytes);
398418
#endif
@@ -461,7 +481,7 @@ static int mixin_process(struct processing_module *mod,
461481
* silence instead of that source data
462482
*/
463483
if (source_avail_frames == 0) {
464-
uint32_t frame_bytes = sink_get_frame_bytes(mixout_mod->sinks[0]);
484+
frame_bytes = sink_get_frame_bytes(mixout_mod->sinks[0]);
465485

466486
/* generate silence */
467487
silence(&mixout_data->acquired_buf, start_frame * frame_bytes,
@@ -698,6 +718,7 @@ static int mixin_prepare(struct processing_module *mod,
698718
int ret;
699719

700720
comp_info(dev, "mixin_prepare()");
721+
md->eos_delay_configured = false;
701722

702723
ret = mixin_params(mod);
703724
if (ret < 0)

src/audio/pipeline/pipeline-graph.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,4 +551,6 @@ struct comp_dev *pipeline_get_dai_comp_latency(uint32_t pipeline_id, uint32_t *l
551551

552552
return NULL;
553553
}
554+
EXPORT_SYMBOL(pipeline_get_dai_comp_latency);
555+
554556
#endif

0 commit comments

Comments
 (0)