Skip to content

Commit d62c9fb

Browse files
committed
host: Add eos detection
Add end of stream support to the host. When the pipeline is in the eos state and host runs out of available data, set the sink to the eos state. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent 130ed41 commit d62c9fb

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/audio/host-zephyr.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,30 @@ static int host_get_status(struct comp_dev *dev, struct host_data *hd, struct dm
393393
/* Minimum time between 2 consecutive "no bytes to copy" messages in milliseconds */
394394
#define SOF_MIN_NO_BYTES_INTERVAL_MS 20
395395

396+
static inline bool host_handle_eos(struct host_data *hd, struct comp_dev *dev,
397+
uint32_t avail_samples)
398+
{
399+
struct sof_audio_buffer *buffer = &hd->local_buffer->audio_buffer;
400+
enum sof_audio_buffer_state state = audio_buffer_get_state(buffer);
401+
402+
if (!dev->pipeline->expect_eos)
403+
return false;
404+
405+
if (!avail_samples) {
406+
/* EOS is detected, so we need to set the sink state to STREAM_STATE_EOS. */
407+
if (state != AUDIOBUF_STATE_END_OF_STREAM) {
408+
audio_buffer_set_eos(buffer);
409+
comp_info(dev, "host_handle_eos() - EOS detected");
410+
}
411+
return true;
412+
}
413+
414+
if (state == AUDIOBUF_STATE_END_OF_STREAM)
415+
comp_warn(dev, "Data available after reporting end of stream!");
416+
417+
return false;
418+
}
419+
396420
/**
397421
* Calculates bytes to be copied in normal mode.
398422
* @param dev Host component device.
@@ -440,6 +464,9 @@ static uint32_t host_get_copy_bytes_normal(struct host_data *hd, struct comp_dev
440464
if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
441465
avail_samples = (dma_stat.pending_length - hd->partial_size) / dma_sample_bytes;
442466
free_samples = audio_stream_get_free_samples(&buffer->stream);
467+
468+
if (host_handle_eos(hd, dev, avail_samples))
469+
return 0;
443470
} else {
444471
avail_samples = audio_stream_get_avail_samples(&buffer->stream);
445472
free_samples = (dma_stat.free - hd->partial_size) / dma_sample_bytes;

0 commit comments

Comments
 (0)