2004-06-08 23:54:24 +00:00
|
|
|
#ifndef foomemblockqhfoo
|
|
|
|
|
#define foomemblockqhfoo
|
|
|
|
|
|
2004-07-16 19:56:36 +00:00
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2004-2006 Lennart Poettering
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-21 21:31:28 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as
|
2009-03-03 20:23:02 +00:00
|
|
|
published by the Free Software Foundation; either version 2.1 of the
|
2004-11-21 21:31:28 +00:00
|
|
|
License, or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-07-16 19:56:36 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2006-06-19 21:53:48 +00:00
|
|
|
License along with PulseAudio; if not, write to the Free Software
|
2004-07-16 19:56:36 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
#include <sys/types.h>
|
2006-02-20 04:05:16 +00:00
|
|
|
#include <inttypes.h>
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/memblock.h>
|
|
|
|
|
#include <pulsecore/memchunk.h>
|
|
|
|
|
#include <pulse/def.h>
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
/* A memblockq is a queue of pa_memchunks (yepp, the name is not
|
|
|
|
|
* perfect). It is similar to the ring buffers used by most other
|
|
|
|
|
* audio software. In contrast to a ring buffer this memblockq data
|
|
|
|
|
* type doesn't need to copy any data around, it just maintains
|
|
|
|
|
* references to reference counted memory blocks. */
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
typedef struct pa_memblockq pa_memblockq;
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2006-02-20 04:05:16 +00:00
|
|
|
|
2004-07-07 00:22:46 +00:00
|
|
|
/* Parameters:
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-02-20 04:05:16 +00:00
|
|
|
- idx: start value for both read and write index
|
|
|
|
|
|
|
|
|
|
- maxlength: maximum length of queue. If more data is pushed into
|
|
|
|
|
the queue, the operation will fail. Must not be 0.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-02-20 04:05:16 +00:00
|
|
|
- tlength: the target length of the queue. Pass 0 for the default.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-02-20 04:05:16 +00:00
|
|
|
- base: a base value for all metrics. Only multiples of this value
|
|
|
|
|
are popped from the queue or should be pushed into
|
|
|
|
|
it. Must not be 0.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-02-20 04:05:16 +00:00
|
|
|
- prebuf: If the queue runs empty wait until this many bytes are in
|
|
|
|
|
queue again before passing the first byte out. If set
|
|
|
|
|
to 0 pa_memblockq_pop() will return a silence memblock
|
|
|
|
|
if no data is in the queue and will never fail. Pass
|
|
|
|
|
(size_t) -1 for the default.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-02-20 04:05:16 +00:00
|
|
|
- minreq: pa_memblockq_missing() will only return values greater
|
|
|
|
|
than this value. Pass 0 for the default.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
- maxrewind: how many bytes of history to keep in the queue
|
|
|
|
|
|
|
|
|
|
- silence: return this memchunk when reading unitialized data
|
2004-07-07 00:22:46 +00:00
|
|
|
*/
|
2006-02-20 04:05:16 +00:00
|
|
|
pa_memblockq* pa_memblockq_new(
|
|
|
|
|
int64_t idx,
|
|
|
|
|
size_t maxlength,
|
|
|
|
|
size_t tlength,
|
|
|
|
|
size_t base,
|
2007-01-04 13:43:45 +00:00
|
|
|
size_t prebuf,
|
2006-02-20 04:05:16 +00:00
|
|
|
size_t minreq,
|
2008-05-15 23:34:41 +00:00
|
|
|
size_t maxrewind,
|
|
|
|
|
pa_memchunk *silence);
|
2006-02-20 04:05:16 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_memblockq_free(pa_memblockq*bq);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2006-02-20 04:05:16 +00:00
|
|
|
/* Push a new memory chunk into the queue. */
|
|
|
|
|
int pa_memblockq_push(pa_memblockq* bq, const pa_memchunk *chunk);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2006-02-20 04:05:16 +00:00
|
|
|
/* Push a new memory chunk into the queue, but filter it through a
|
|
|
|
|
* pa_mcalign object. Don't mix this with pa_memblockq_seek() unless
|
|
|
|
|
* you know what you do. */
|
|
|
|
|
int pa_memblockq_push_align(pa_memblockq* bq, const pa_memchunk *chunk);
|
2004-07-03 00:19:17 +00:00
|
|
|
|
2008-06-26 00:39:31 +02:00
|
|
|
/* Manipulate the write pointer */
|
2009-04-01 23:05:09 +02:00
|
|
|
void pa_memblockq_seek(pa_memblockq *bq, int64_t offset, pa_seek_mode_t seek, pa_bool_t account);
|
2008-06-26 00:39:31 +02:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
/* Return a copy of the next memory chunk in the queue. It is not
|
|
|
|
|
* removed from the queue. There are two reasons this function might
|
|
|
|
|
* fail: 1. prebuffering is active, 2. queue is empty and no silence
|
|
|
|
|
* memblock was passed at initialization. If the queue is not empty,
|
|
|
|
|
* but we're currently at a hole in the queue and no silence memblock
|
|
|
|
|
* was passed we return the length of the hole in chunk->length. */
|
2006-01-11 01:17:39 +00:00
|
|
|
int pa_memblockq_peek(pa_memblockq* bq, pa_memchunk *chunk);
|
2004-07-03 00:19:17 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
/* Drop the specified bytes from the queue. */
|
|
|
|
|
void pa_memblockq_drop(pa_memblockq *bq, size_t length);
|
2004-08-22 21:13:58 +00:00
|
|
|
|
2008-06-26 00:39:31 +02:00
|
|
|
/* Rewind the read index. If the history is shorter than the specified length we'll point to silence afterwards. */
|
|
|
|
|
void pa_memblockq_rewind(pa_memblockq *bq, size_t length);
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
/* Test if the pa_memblockq is currently readable, that is, more data than base */
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_bool_t pa_memblockq_is_readable(pa_memblockq *bq);
|
2004-07-03 00:19:17 +00:00
|
|
|
|
|
|
|
|
/* Return the length of the queue in bytes */
|
2006-02-20 04:05:16 +00:00
|
|
|
size_t pa_memblockq_get_length(pa_memblockq *bq);
|
2004-06-15 15:18:33 +00:00
|
|
|
|
2004-07-03 00:19:17 +00:00
|
|
|
/* Return how many bytes are missing in queue to the specified fill amount */
|
2006-02-20 04:05:16 +00:00
|
|
|
size_t pa_memblockq_missing(pa_memblockq *bq);
|
2004-07-07 00:22:46 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
/* Return the number of bytes that are missing since the last call to
|
|
|
|
|
* this function, reset the internal counter to 0. */
|
|
|
|
|
size_t pa_memblockq_pop_missing(pa_memblockq *bq);
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* Directly moves the data from the source memblockq into bq */
|
|
|
|
|
int pa_memblockq_splice(pa_memblockq *bq, pa_memblockq *source);
|
|
|
|
|
|
2006-02-20 04:05:16 +00:00
|
|
|
/* Set the queue to silence, set write index to read index */
|
2008-06-26 00:39:31 +02:00
|
|
|
void pa_memblockq_flush_write(pa_memblockq *bq);
|
2006-02-20 04:05:16 +00:00
|
|
|
|
2008-06-26 00:39:31 +02:00
|
|
|
/* Set the queue to silence, set write read index to write index*/
|
|
|
|
|
void pa_memblockq_flush_read(pa_memblockq *bq);
|
2006-02-20 04:05:16 +00:00
|
|
|
|
|
|
|
|
/* Ignore prebuf for now */
|
|
|
|
|
void pa_memblockq_prebuf_disable(pa_memblockq *bq);
|
|
|
|
|
|
|
|
|
|
/* Force prebuf */
|
|
|
|
|
void pa_memblockq_prebuf_force(pa_memblockq *bq);
|
|
|
|
|
|
2006-05-25 23:20:28 +00:00
|
|
|
/* Return the maximum length of the queue in bytes */
|
|
|
|
|
size_t pa_memblockq_get_maxlength(pa_memblockq *bq);
|
|
|
|
|
|
2008-06-26 00:39:31 +02:00
|
|
|
/* Get Target length */
|
|
|
|
|
size_t pa_memblockq_get_tlength(pa_memblockq *bq);
|
|
|
|
|
|
2006-05-25 23:20:28 +00:00
|
|
|
/* Return the prebuffer length in bytes */
|
|
|
|
|
size_t pa_memblockq_get_prebuf(pa_memblockq *bq);
|
|
|
|
|
|
2008-06-26 00:39:31 +02:00
|
|
|
/* Returns the minimal request value */
|
|
|
|
|
size_t pa_memblockq_get_minreq(pa_memblockq *bq);
|
|
|
|
|
|
|
|
|
|
/* Return the base unit in bytes */
|
|
|
|
|
size_t pa_memblockq_get_base(pa_memblockq *bq);
|
|
|
|
|
|
|
|
|
|
/* Return the current read index */
|
|
|
|
|
int64_t pa_memblockq_get_read_index(pa_memblockq *bq);
|
|
|
|
|
|
|
|
|
|
/* Return the current write index */
|
|
|
|
|
int64_t pa_memblockq_get_write_index(pa_memblockq *bq);
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* Change metrics. Always call in order. */
|
|
|
|
|
void pa_memblockq_set_maxlength(pa_memblockq *memblockq, size_t maxlength); /* might modify tlength, prebuf, minreq too */
|
|
|
|
|
void pa_memblockq_set_tlength(pa_memblockq *memblockq, size_t tlength); /* might modify minreq, too */
|
|
|
|
|
void pa_memblockq_set_prebuf(pa_memblockq *memblockq, size_t prebuf); /* might modify minreq, too */
|
2007-11-21 01:19:28 +00:00
|
|
|
void pa_memblockq_set_minreq(pa_memblockq *memblockq, size_t minreq);
|
2008-08-29 23:53:55 +02:00
|
|
|
void pa_memblockq_set_maxrewind(pa_memblockq *memblockq, size_t maxrewind); /* Set the maximum history size */
|
2008-05-15 23:34:41 +00:00
|
|
|
void pa_memblockq_set_silence(pa_memblockq *memblockq, pa_memchunk *silence);
|
|
|
|
|
|
2009-03-30 18:27:07 +02:00
|
|
|
/* Apply the data from pa_buffer_attr */
|
|
|
|
|
void pa_memblockq_apply_attr(pa_memblockq *memblockq, const pa_buffer_attr *a);
|
|
|
|
|
void pa_memblockq_get_attr(pa_memblockq *bq, pa_buffer_attr *a);
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* Call pa_memchunk_willneed() for every chunk in the queue from the current read pointer to the end */
|
|
|
|
|
void pa_memblockq_willneed(pa_memblockq *bq);
|
|
|
|
|
|
|
|
|
|
/* Check whether the memblockq is completely empty, i.e. no data
|
|
|
|
|
* neither left nor right of the read pointer, and hence no buffered
|
|
|
|
|
* data for the future nor data in the backlog. */
|
|
|
|
|
pa_bool_t pa_memblockq_is_empty(pa_memblockq *bq);
|
|
|
|
|
|
2008-06-26 00:36:05 +02:00
|
|
|
/* Drop everything in the queue, but don't modify the indexes */
|
2008-05-15 23:34:41 +00:00
|
|
|
void pa_memblockq_silence(pa_memblockq *bq);
|
|
|
|
|
|
|
|
|
|
/* Check whether we currently are in prebuf state */
|
|
|
|
|
pa_bool_t pa_memblockq_prebuf_active(pa_memblockq *bq);
|
|
|
|
|
|
2008-06-26 00:36:05 +02:00
|
|
|
/* Return how many items are currently stored in the queue */
|
2008-05-15 23:34:41 +00:00
|
|
|
unsigned pa_memblockq_get_nblocks(pa_memblockq *bq);
|
2007-11-21 01:19:28 +00:00
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
#endif
|