mirror of https://github.com/thesofproject/sof.git
buffer: add buffer callback
Adds buffer callbacks, which can be called after produce or consume. Signed-off-by: Tomasz Lauda <tomasz.lauda@linux.intel.com>
This commit is contained in:
parent
ad646299af
commit
c694c09824
|
@ -158,6 +158,9 @@ void comp_update_buffer_produce(struct comp_buffer *buffer, uint32_t bytes)
|
|||
/* calculate free bytes */
|
||||
buffer->free = buffer->size - buffer->avail;
|
||||
|
||||
if (buffer->cb && buffer->cb_type & BUFF_CB_TYPE_PRODUCE)
|
||||
buffer->cb(buffer->cb_data, bytes);
|
||||
|
||||
spin_unlock_irq(&buffer->lock, flags);
|
||||
|
||||
tracev_buffer("comp_update_buffer_produce(), ((buffer->avail << 16) | "
|
||||
|
@ -199,6 +202,9 @@ void comp_update_buffer_consume(struct comp_buffer *buffer, uint32_t bytes)
|
|||
!buffer->source->is_dma_connected)
|
||||
dcache_writeback_region(buffer->r_ptr, bytes);
|
||||
|
||||
if (buffer->cb && buffer->cb_type & BUFF_CB_TYPE_CONSUME)
|
||||
buffer->cb(buffer->cb_data, bytes);
|
||||
|
||||
spin_unlock_irq(&buffer->lock, flags);
|
||||
|
||||
tracev_buffer("comp_update_buffer_consume(), %u, %u, %u",
|
||||
|
|
|
@ -48,6 +48,10 @@
|
|||
#define trace_buffer_error(__e, ...) trace_error(TRACE_CLASS_BUFFER, __e, ##__VA_ARGS__)
|
||||
#define tracev_buffer(__e, ...) tracev_event(TRACE_CLASS_BUFFER, __e, ##__VA_ARGS__)
|
||||
|
||||
/* buffer callback types */
|
||||
#define BUFF_CB_TYPE_PRODUCE BIT(0)
|
||||
#define BUFF_CB_TYPE_CONSUME BIT(1)
|
||||
|
||||
/* audio component buffer - connects 2 audio components together in pipeline */
|
||||
struct comp_buffer {
|
||||
|
||||
|
@ -72,6 +76,11 @@ struct comp_buffer {
|
|||
struct list_item source_list; /* list in comp buffers */
|
||||
struct list_item sink_list; /* list in comp buffers */
|
||||
|
||||
/* callbacks */
|
||||
void (*cb)(void *data, uint32_t bytes);
|
||||
void *cb_data;
|
||||
int cb_type;
|
||||
|
||||
spinlock_t lock; /* component buffer spinlock */
|
||||
};
|
||||
|
||||
|
@ -96,6 +105,13 @@ struct comp_buffer {
|
|||
buffer->sink = comp; \
|
||||
} while (0) \
|
||||
|
||||
#define buffer_set_cb(buffer, func, data, type) \
|
||||
do { \
|
||||
buffer->cb = func; \
|
||||
buffer->cb_data = data; \
|
||||
buffer->cb_type = type; \
|
||||
} while (0)
|
||||
|
||||
#define buffer_read_frag(buffer, idx, size) \
|
||||
buffer_get_frag(buffer, buffer->r_ptr, idx, size)
|
||||
|
||||
|
|
|
@ -215,6 +215,9 @@ static struct comp_buffer *mock_comp_buffer(void **state,
|
|||
buffer->end_addr = buffer->w_ptr + buffer->size;
|
||||
break;
|
||||
}
|
||||
|
||||
buffer->cb = NULL;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue