mirror of
https://github.com/librempeg/librempeg
synced 2024-11-23 03:28:27 +00:00
Merge commit '3627ce2f1dab1d33b7f99d78907a3e4d86b7d847'
* commit '3627ce2f1dab1d33b7f99d78907a3e4d86b7d847': aviobuf: Add functions for null buffers Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
commit
2ad8056c5e
@ -130,4 +130,22 @@ int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size);
|
||||
*/
|
||||
int ffio_fdopen(AVIOContext **s, URLContext *h);
|
||||
|
||||
/**
|
||||
* Open a write-only fake memory stream. The written data is not stored
|
||||
* anywhere - this is only used for measuring the amount of data
|
||||
* written.
|
||||
*
|
||||
* @param s new IO context
|
||||
* @return zero if no error.
|
||||
*/
|
||||
int ffio_open_null_buf(AVIOContext **s);
|
||||
|
||||
/**
|
||||
* Close a null buffer.
|
||||
*
|
||||
* @param s an IO context opened by ffio_open_null_buf
|
||||
* @return the number of bytes written to the null buffer
|
||||
*/
|
||||
int ffio_close_null_buf(AVIOContext *s);
|
||||
|
||||
#endif /* AVFORMAT_AVIO_INTERNAL_H */
|
||||
|
@ -1045,3 +1045,36 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
|
||||
av_free(s);
|
||||
return size - padding;
|
||||
}
|
||||
|
||||
static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
|
||||
{
|
||||
DynBuffer *d = opaque;
|
||||
|
||||
d->pos += buf_size;
|
||||
if (d->pos > d->size)
|
||||
d->size = d->pos;
|
||||
return buf_size;
|
||||
}
|
||||
|
||||
int ffio_open_null_buf(AVIOContext **s)
|
||||
{
|
||||
int ret = url_open_dyn_buf_internal(s, 0);
|
||||
if (ret >= 0) {
|
||||
AVIOContext *pb = *s;
|
||||
pb->write_packet = null_buf_write;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ffio_close_null_buf(AVIOContext *s)
|
||||
{
|
||||
DynBuffer *d = s->opaque;
|
||||
int size;
|
||||
|
||||
avio_flush(s);
|
||||
|
||||
size = d->size;
|
||||
av_free(d);
|
||||
av_free(s);
|
||||
return size;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user