Skip to content

Commit f2008f3

Browse files
committed
host: Add eos detection
Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent 1d76a18 commit f2008f3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/audio/host-zephyr.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,28 @@ static int host_get_status(struct comp_dev *dev, struct host_data *hd, struct dm
389389
/* Minimum time between 2 consecutive "no bytes to copy" messages in milliseconds */
390390
#define SOF_MIN_NO_BYTES_INTERVAL_MS 20
391391

392+
static inline bool host_handle_eos(struct host_data *hd, struct comp_dev *dev, uint32_t avail_samples)
393+
{
394+
struct sof_audio_buffer *buffer = &hd->local_buffer->audio_buffer;
395+
enum sof_audio_stream_state state = audio_buffer_get_state(buffer);
396+
397+
if (!dev->pipeline->expect_eos)
398+
return false;
399+
400+
if (!avail_samples) {
401+
/* EOS is detected, so we need to set the sink state to STREAM_STATE_EOS. */
402+
if (state != STREAM_STATE_END_OF_STREAM) {
403+
audio_buffer_set_eos(buffer);
404+
comp_info(dev, "host_handle_eos() - EOS detected");
405+
}
406+
return true;
407+
} else {
408+
if (state == STREAM_STATE_END_OF_STREAM)
409+
comp_warn(dev, "Data available after reporting end of stream!");
410+
}
411+
return false;
412+
}
413+
392414
/**
393415
* Calculates bytes to be copied in normal mode.
394416
* @param dev Host component device.
@@ -419,6 +441,9 @@ static uint32_t host_get_copy_bytes_normal(struct host_data *hd, struct comp_dev
419441
if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
420442
avail_samples = (dma_stat.pending_length - hd->partial_size) / dma_sample_bytes;
421443
free_samples = audio_stream_get_free_samples(&buffer->stream);
444+
445+
if (host_handle_eos(hd, dev, avail_samples))
446+
return 0;
422447
} else {
423448
avail_samples = audio_stream_get_avail_samples(&buffer->stream);
424449
free_samples = (dma_stat.free - hd->partial_size) / dma_sample_bytes;

0 commit comments

Comments
 (0)