buffer: add EMPTY chunk flag

Add an EMPTY chunk flag to mark a piece of memory as 'empty'. For audio
this means silence.
Use the empty flag to avoid mixing 0 samples.
Set the empty flag in output buffers on audioconvert.
This commit is contained in:
Wim Taymans 2022-06-24 11:09:01 +02:00
parent 71f3c759f4
commit f2dee23085
4 changed files with 18 additions and 5 deletions

View file

@ -63,6 +63,9 @@ struct spa_chunk {
int32_t stride; /**< stride of valid data */
#define SPA_CHUNK_FLAG_NONE 0
#define SPA_CHUNK_FLAG_CORRUPTED (1u<<0) /**< chunk data is corrupted in some way */
#define SPA_CHUNK_FLAG_EMPTY (1u<<1) /**< chunk data is empty with media specific
* neutral data such as silence or black. This
* could be used to optimize processing. */
int32_t flags; /**< chunk flags */
};

View file

@ -2160,7 +2160,7 @@ static int impl_node_process(void *object)
struct dir *dir;
int tmp = 0, res = 0;
bool in_passthrough, mix_passthrough, resample_passthrough, out_passthrough, end_passthrough;
bool in_avail = false, flush_in = false, flush_out = false, draining = false;
bool in_avail = false, flush_in = false, flush_out = false, draining = false, in_empty = true;
struct spa_io_buffers *io, *ctrlio = NULL;
const struct spa_pod_sequence *ctrl = NULL;
@ -2219,6 +2219,8 @@ static int impl_node_process(void *object)
offs = SPA_MIN(bd->chunk->offset, bd->maxsize);
size = SPA_MIN(bd->maxsize - offs, bd->chunk->size);
if (!SPA_FLAG_IS_SET(bd->chunk->flags, SPA_CHUNK_FLAG_EMPTY))
in_empty = false;
if (port->is_control) {
spa_log_trace_fp(this->log, "%p: control %d", this,
@ -2487,6 +2489,7 @@ static int impl_node_process(void *object)
for (j = 0; j < port->blocks; j++) {
bd = &buf->buf->datas[j];
bd->chunk->size = this->out_offset * port->stride;
SPA_FLAG_UPDATE(bd->chunk->flags, SPA_CHUNK_FLAG_EMPTY, in_empty);
spa_log_trace_fp(this->log, "out: %d %d %d", this->out_offset,
port->stride, bd->chunk->size);
}

View file

@ -782,8 +782,10 @@ static int impl_node_process(void *object)
i, inio, outio, inio->status, inio->buffer_id,
offs, size);
datas[n_buffers] = SPA_PTROFF(bd->data, offs, void);
buffers[n_buffers++] = inb;
if (!SPA_FLAG_IS_SET(bd->chunk->flags, SPA_CHUNK_FLAG_EMPTY)) {
datas[n_buffers] = SPA_PTROFF(bd->data, offs, void);
buffers[n_buffers++] = inb;
}
inio->status = SPA_STATUS_NEED_DATA;
}
@ -805,6 +807,7 @@ static int impl_node_process(void *object)
d[0].chunk->offset = 0;
d[0].chunk->size = maxsize;
d[0].chunk->stride = this->stride;
SPA_FLAG_UPDATE(d[0].chunk->flags, SPA_CHUNK_FLAG_EMPTY, n_buffers == 0);
mix_ops_process(&this->ops, d[0].data,
datas, n_buffers, maxsize / this->stride);

View file

@ -744,8 +744,10 @@ static int impl_node_process(void *object)
i, inio, outio, inio->status, inio->buffer_id,
offs, size);
datas[n_buffers] = SPA_PTROFF(bd->data, offs, void);
buffers[n_buffers++] = inb;
if (!SPA_FLAG_IS_SET(bd->chunk->flags, SPA_CHUNK_FLAG_EMPTY)) {
datas[n_buffers] = SPA_PTROFF(bd->data, offs, void);
buffers[n_buffers++] = inb;
}
inio->status = SPA_STATUS_NEED_DATA;
}
@ -759,6 +761,7 @@ static int impl_node_process(void *object)
*outb->buffer = *buffers[0]->buffer;
} else {
struct spa_data *d = outb->buf.datas;
*outb->buffer = outb->buf;
maxsize = SPA_MIN(maxsize, d[0].maxsize);
@ -766,6 +769,7 @@ static int impl_node_process(void *object)
d[0].chunk->offset = 0;
d[0].chunk->size = maxsize;
d[0].chunk->stride = sizeof(float);
SPA_FLAG_UPDATE(d[0].chunk->flags, SPA_CHUNK_FLAG_EMPTY, n_buffers == 0);
spa_log_trace_fp(this->log, "%p: %d mix %d", this, n_buffers, maxsize);