Skip to content

Commit 5772920

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 b924676 commit 5772920

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/audio/host-zephyr.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,32 @@ 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
407+
* state to AUDIOBUF_STATE_END_OF_STREAM.
408+
*/
409+
if (state != AUDIOBUF_STATE_END_OF_STREAM) {
410+
audio_buffer_set_eos(buffer);
411+
comp_info(dev, "host_handle_eos() - EOS detected");
412+
}
413+
return true;
414+
}
415+
416+
if (state == AUDIOBUF_STATE_END_OF_STREAM)
417+
comp_warn(dev, "Data available after reporting end of stream!");
418+
419+
return false;
420+
}
421+
396422
/**
397423
* Calculates bytes to be copied in normal mode.
398424
* @param dev Host component device.
@@ -440,6 +466,9 @@ static uint32_t host_get_copy_bytes_normal(struct host_data *hd, struct comp_dev
440466
if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
441467
avail_samples = (dma_stat.pending_length - hd->partial_size) / dma_sample_bytes;
442468
free_samples = audio_stream_get_free_samples(&buffer->stream);
469+
470+
if (host_handle_eos(hd, dev, avail_samples))
471+
return 0;
443472
} else {
444473
avail_samples = audio_stream_get_avail_samples(&buffer->stream);
445474
free_samples = (dma_stat.free - hd->partial_size) / dma_sample_bytes;

0 commit comments

Comments
 (0)