mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
output: Add snd_output_buffer_steal() function
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
4870358b2f
commit
3e0140088c
2 changed files with 26 additions and 1 deletions
|
|
@ -65,6 +65,7 @@ int snd_output_stdio_open(snd_output_t **outputp, const char *file, const char *
|
||||||
int snd_output_stdio_attach(snd_output_t **outputp, FILE *fp, int _close);
|
int snd_output_stdio_attach(snd_output_t **outputp, FILE *fp, int _close);
|
||||||
int snd_output_buffer_open(snd_output_t **outputp);
|
int snd_output_buffer_open(snd_output_t **outputp);
|
||||||
size_t snd_output_buffer_string(snd_output_t *output, char **buf);
|
size_t snd_output_buffer_string(snd_output_t *output, char **buf);
|
||||||
|
size_t snd_output_buffer_steal(snd_output_t *output, char **buf);
|
||||||
int snd_output_close(snd_output_t *output);
|
int snd_output_close(snd_output_t *output);
|
||||||
int snd_output_printf(snd_output_t *output, const char *format, ...)
|
int snd_output_printf(snd_output_t *output, const char *format, ...)
|
||||||
#ifndef DOC_HIDDEN
|
#ifndef DOC_HIDDEN
|
||||||
|
|
|
||||||
26
src/output.c
26
src/output.c
|
|
@ -252,6 +252,9 @@ static int snd_output_buffer_need(snd_output_t *output, size_t size)
|
||||||
size_t alloc;
|
size_t alloc;
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
|
|
||||||
|
/* use 'size++' to allow to add the '\0' string terminator */
|
||||||
|
/* without reallocation */
|
||||||
|
size++;
|
||||||
if (_free >= size)
|
if (_free >= size)
|
||||||
return _free;
|
return _free;
|
||||||
if (buffer->alloc == 0)
|
if (buffer->alloc == 0)
|
||||||
|
|
@ -349,6 +352,28 @@ size_t snd_output_buffer_string(snd_output_t *output, char **buf)
|
||||||
return buffer->size;
|
return buffer->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Returns the address of the buffer of a #SND_OUTPUT_BUFFER output handle.
|
||||||
|
* \param output The output handle.
|
||||||
|
* \param buf The functions puts the current address of the buffer at the
|
||||||
|
* address specified by \p buf.
|
||||||
|
* \return The current size of valid data in the buffer.
|
||||||
|
*
|
||||||
|
* The internal buffer is empty after this call. The caller has the responsibility
|
||||||
|
* to clean the buffer using the free() call.
|
||||||
|
*/
|
||||||
|
size_t snd_output_buffer_steal(snd_output_t *output, char **buf)
|
||||||
|
{
|
||||||
|
snd_output_buffer_t *buffer = output->private_data;
|
||||||
|
size_t size;
|
||||||
|
*buf = (char *)buffer->buf;
|
||||||
|
size = buffer->size;
|
||||||
|
buffer->buf = NULL;
|
||||||
|
buffer->alloc = 0;
|
||||||
|
buffer->size = 0;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Creates a new output object with an auto-extending memory buffer.
|
* \brief Creates a new output object with an auto-extending memory buffer.
|
||||||
* \param outputp The function puts the pointer to the new output object
|
* \param outputp The function puts the pointer to the new output object
|
||||||
|
|
@ -377,4 +402,3 @@ int snd_output_buffer_open(snd_output_t **outputp)
|
||||||
*outputp = output;
|
*outputp = output;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue