[vlc-commits] stream_fifo: use separater poitenrs for read and write sides
Rémi Denis-Courmont
git at videolan.org
Fri Mar 15 02:28:21 CET 2019
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Mar 15 03:13:15 2019 +0200| [e8e9bda4de883cba69ff1d44f653217215b96e4b] | committer: Rémi Denis-Courmont
stream_fifo: use separater poitenrs for read and write sides
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e8e9bda4de883cba69ff1d44f653217215b96e4b
---
include/vlc_stream.h | 3 +-
src/input/demux_chained.c | 19 +++--
src/input/stream_fifo.c | 3 +-
test/src/input/stream_fifo.c | 191 ++++++++++++++++++++++---------------------
4 files changed, 110 insertions(+), 106 deletions(-)
diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index ef204b27dd..3fecf5decc 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -449,9 +449,10 @@ VLC_USED;
* vlc_stream_fifo_Close() respectively.
*
* \param parent parent VLC object for the stream
+ * \param reader location to store read side stream pointer [OUT]
* \return a stream object or NULL on memory error.
*/
-VLC_API stream_t *vlc_stream_fifo_New(vlc_object_t *parent);
+VLC_API stream_t *vlc_stream_fifo_New(vlc_object_t *parent, stream_t **reader);
/**
* Writes a block to a FIFO stream.
diff --git a/src/input/demux_chained.c b/src/input/demux_chained.c
index 30fb6fd935..784e0e292a 100644
--- a/src/input/demux_chained.c
+++ b/src/input/demux_chained.c
@@ -34,7 +34,8 @@
struct vlc_demux_chained_t
{
- stream_t *fifo;
+ stream_t *writer;
+ stream_t *reader;
vlc_thread_t thread;
vlc_mutex_t lock;
@@ -53,11 +54,11 @@ struct vlc_demux_chained_t
static void *vlc_demux_chained_Thread(void *data)
{
vlc_demux_chained_t *dc = data;
- demux_t *demux = demux_New(VLC_OBJECT(dc->fifo), dc->name, dc->fifo,
+ demux_t *demux = demux_New(VLC_OBJECT(dc->reader), dc->name, dc->reader,
dc->out);
if (demux == NULL)
{
- vlc_stream_Delete(dc->fifo);
+ vlc_stream_Delete(dc->reader);
return NULL;
}
@@ -103,8 +104,8 @@ vlc_demux_chained_t *vlc_demux_chained_New(vlc_object_t *parent,
if (unlikely(dc == NULL))
return NULL;
- dc->fifo = vlc_stream_fifo_New(parent);
- if (dc->fifo == NULL)
+ dc->writer = vlc_stream_fifo_New(parent, &dc->reader);
+ if (dc->writer == NULL)
{
free(dc);
return NULL;
@@ -121,8 +122,8 @@ vlc_demux_chained_t *vlc_demux_chained_New(vlc_object_t *parent,
if (vlc_clone(&dc->thread, vlc_demux_chained_Thread, dc,
VLC_THREAD_PRIORITY_INPUT))
{
- vlc_stream_Delete(dc->fifo);
- vlc_stream_fifo_Close(dc->fifo);
+ vlc_stream_Delete(dc->reader);
+ vlc_stream_fifo_Close(dc->writer);
vlc_mutex_destroy(&dc->lock);
free(dc);
dc = NULL;
@@ -132,7 +133,7 @@ vlc_demux_chained_t *vlc_demux_chained_New(vlc_object_t *parent,
void vlc_demux_chained_Send(vlc_demux_chained_t *dc, block_t *block)
{
- vlc_stream_fifo_Queue(dc->fifo, block);
+ vlc_stream_fifo_Queue(dc->writer, block);
}
int vlc_demux_chained_ControlVa(vlc_demux_chained_t *dc, int query, va_list ap)
@@ -162,7 +163,7 @@ int vlc_demux_chained_ControlVa(vlc_demux_chained_t *dc, int query, va_list ap)
void vlc_demux_chained_Delete(vlc_demux_chained_t *dc)
{
- vlc_stream_fifo_Close(dc->fifo);
+ vlc_stream_fifo_Close(dc->writer);
vlc_join(dc->thread, NULL);
vlc_mutex_destroy(&dc->lock);
free(dc);
diff --git a/src/input/stream_fifo.c b/src/input/stream_fifo.c
index 8a5b4269db..9bc4d81a2b 100644
--- a/src/input/stream_fifo.c
+++ b/src/input/stream_fifo.c
@@ -103,7 +103,7 @@ static int vlc_stream_fifo_Control(stream_t *s, int query, va_list ap)
return VLC_SUCCESS;
}
-stream_t *vlc_stream_fifo_New(vlc_object_t *parent)
+stream_t *vlc_stream_fifo_New(vlc_object_t *parent, stream_t **reader)
{
vlc_fifo_t *fifo = block_FifoNew();
if (unlikely(fifo == NULL))
@@ -124,6 +124,7 @@ stream_t *vlc_stream_fifo_New(vlc_object_t *parent)
s->pf_block = vlc_stream_fifo_Block;
s->pf_seek = NULL;
s->pf_control = vlc_stream_fifo_Control;
+ *reader = s;
return vlc_object_hold(s);
}
diff --git a/test/src/input/stream_fifo.c b/test/src/input/stream_fifo.c
index 2bc3227cbe..950565eb10 100644
--- a/test/src/input/stream_fifo.c
+++ b/test/src/input/stream_fifo.c
@@ -37,7 +37,8 @@
static libvlc_instance_t *vlc;
static vlc_object_t *parent;
-static stream_t *s;
+static stream_t *writer;
+static stream_t *reader;
int main(void)
{
@@ -53,191 +54,191 @@ int main(void)
assert(vlc != NULL);
parent = VLC_OBJECT(vlc->p_libvlc_int);
- s = vlc_stream_fifo_New(parent);
- assert(s != NULL);
- val = vlc_stream_Control(s, STREAM_CAN_SEEK, &b);
+ writer = vlc_stream_fifo_New(parent, &reader);
+ assert(writer != NULL);
+ val = vlc_stream_Control(reader, STREAM_CAN_SEEK, &b);
assert(val == VLC_SUCCESS && !b);
- val = vlc_stream_GetSize(s, &(uint64_t){ 0 });
+ val = vlc_stream_GetSize(reader, &(uint64_t){ 0 });
assert(val < 0);
- val = vlc_stream_Control(s, STREAM_GET_PTS_DELAY, &(vlc_tick_t){ 0 });
+ val = vlc_stream_Control(reader, STREAM_GET_PTS_DELAY, &(vlc_tick_t){ 0 });
assert(val == VLC_SUCCESS);
- vlc_stream_Delete(s);
- vlc_stream_fifo_Close(s);
+ vlc_stream_Delete(reader);
+ vlc_stream_fifo_Close(writer);
- s = vlc_stream_fifo_New(parent);
- assert(s != NULL);
- assert(vlc_stream_Tell(s) == 0);
- assert(!vlc_stream_Eof(s));
- val = vlc_stream_fifo_Write(s, "123", 3);
- vlc_stream_fifo_Close(s);
+ writer = vlc_stream_fifo_New(parent, &reader);
+ assert(writer != NULL);
+ assert(vlc_stream_Tell(reader) == 0);
+ assert(!vlc_stream_Eof(reader));
+ val = vlc_stream_fifo_Write(writer, "123", 3);
+ vlc_stream_fifo_Close(writer);
- val = vlc_stream_Read(s, buf, 0);
+ val = vlc_stream_Read(reader, buf, 0);
assert(val == 0);
- assert(vlc_stream_Tell(s) == 0);
- assert(!vlc_stream_Eof(s));
+ assert(vlc_stream_Tell(reader) == 0);
+ assert(!vlc_stream_Eof(reader));
- val = vlc_stream_Read(s, buf, sizeof (buf));
+ val = vlc_stream_Read(reader, buf, sizeof (buf));
assert(val == 3);
- assert(vlc_stream_Tell(s) == 3);
+ assert(vlc_stream_Tell(reader) == 3);
assert(memcmp(buf, "123", 3) == 0);
- val = vlc_stream_Read(s, buf, sizeof (buf));
+ val = vlc_stream_Read(reader, buf, sizeof (buf));
assert(val == 0);
- assert(vlc_stream_Tell(s) == 3);
- assert(vlc_stream_Eof(s));
- vlc_stream_Delete(s);
+ assert(vlc_stream_Tell(reader) == 3);
+ assert(vlc_stream_Eof(reader));
+ vlc_stream_Delete(reader);
- s = vlc_stream_fifo_New(parent);
- assert(s != NULL);
- val = vlc_stream_fifo_Write(s, "Hello ", 6);
+ writer = vlc_stream_fifo_New(parent, &reader);
+ assert(writer != NULL);
+ val = vlc_stream_fifo_Write(writer, "Hello ", 6);
assert(val == 6);
- val = vlc_stream_fifo_Write(s, "world!\n", 7);
+ val = vlc_stream_fifo_Write(writer, "world!\n", 7);
assert(val == 7);
- val = vlc_stream_fifo_Write(s, "blahblah", 8);
+ val = vlc_stream_fifo_Write(writer, "blahblah", 8);
assert(val == 8);
- val = vlc_stream_Read(s, buf, 13);
+ val = vlc_stream_Read(reader, buf, 13);
assert(val == 13);
assert(memcmp(buf, "Hello world!\n", 13) == 0);
- vlc_stream_Delete(s);
+ vlc_stream_Delete(reader);
- val = vlc_stream_fifo_Write(s, "cough cough", 11);
+ val = vlc_stream_fifo_Write(writer, "cough cough", 11);
assert(val == -1 && errno == EPIPE);
- vlc_stream_fifo_Close(s);
+ vlc_stream_fifo_Close(writer);
- s = vlc_stream_fifo_New(parent);
- assert(s != NULL);
- val = vlc_stream_Peek(s, &peek, 0);
+ writer = vlc_stream_fifo_New(parent, &reader);
+ assert(writer != NULL);
+ val = vlc_stream_Peek(reader, &peek, 0);
assert(val == 0);
- val = vlc_stream_fifo_Write(s, "1st block\n", 10);
+ val = vlc_stream_fifo_Write(writer, "1st block\n", 10);
assert(val == 10);
- val = vlc_stream_fifo_Write(s, "2nd block\n", 10);
+ val = vlc_stream_fifo_Write(writer, "2nd block\n", 10);
assert(val == 10);
- val = vlc_stream_fifo_Write(s, "3rd block\n", 10);
+ val = vlc_stream_fifo_Write(writer, "3rd block\n", 10);
assert(val == 10);
- val = vlc_stream_Peek(s, &peek, 5);
+ val = vlc_stream_Peek(reader, &peek, 5);
assert(val == 5);
- assert(vlc_stream_Tell(s) == 0);
- assert(!vlc_stream_Eof(s));
+ assert(vlc_stream_Tell(reader) == 0);
+ assert(!vlc_stream_Eof(reader));
assert(memcmp(peek, "1st b", 5) == 0);
- val = vlc_stream_Peek(s, &peek, 0);
+ val = vlc_stream_Peek(reader, &peek, 0);
assert(val == 0);
- assert(vlc_stream_Tell(s) == 0);
- assert(!vlc_stream_Eof(s));
+ assert(vlc_stream_Tell(reader) == 0);
+ assert(!vlc_stream_Eof(reader));
- val = vlc_stream_Peek(s, &peek, 15);
+ val = vlc_stream_Peek(reader, &peek, 15);
assert(val == 15);
- assert(vlc_stream_Tell(s) == 0);
- assert(!vlc_stream_Eof(s));
+ assert(vlc_stream_Tell(reader) == 0);
+ assert(!vlc_stream_Eof(reader));
assert(memcmp(peek, "1st block\n2nd b", 15) == 0);
- vlc_stream_fifo_Close(s);
- val = vlc_stream_Peek(s, &peek, 40);
+ vlc_stream_fifo_Close(writer);
+ val = vlc_stream_Peek(reader, &peek, 40);
assert(val == 30);
- assert(vlc_stream_Tell(s) == 0);
- assert(!vlc_stream_Eof(s));
+ assert(vlc_stream_Tell(reader) == 0);
+ assert(!vlc_stream_Eof(reader));
assert(memcmp(peek, "1st block\n2nd block\n3rd block\n", 30) == 0);
- val = vlc_stream_Peek(s, &peek, 25);
+ val = vlc_stream_Peek(reader, &peek, 25);
assert(val == 25);
- assert(vlc_stream_Tell(s) == 0);
- assert(!vlc_stream_Eof(s));
+ assert(vlc_stream_Tell(reader) == 0);
+ assert(!vlc_stream_Eof(reader));
assert(memcmp(peek, "1st block\n2nd block\n3rd b", 25) == 0);
- block = vlc_stream_ReadBlock(s);
+ block = vlc_stream_ReadBlock(reader);
assert(block != NULL);
- assert(vlc_stream_Tell(s) == block->i_buffer);
+ assert(vlc_stream_Tell(reader) == block->i_buffer);
assert(block->i_buffer <= 30);
assert(memcmp(block->p_buffer, "1st block\n2nd block\n3rd block\n",
block->i_buffer) == 0);
block_Release(block);
- block = vlc_stream_ReadBlock(s);
+ block = vlc_stream_ReadBlock(reader);
assert(block == NULL);
- assert(vlc_stream_Eof(s));
- vlc_stream_Delete(s);
+ assert(vlc_stream_Eof(reader));
+ vlc_stream_Delete(reader);
- s = vlc_stream_fifo_New(parent);
- assert(s != NULL);
- val = vlc_stream_fifo_Write(s, "1st block\n", 10);
+ writer = vlc_stream_fifo_New(parent, &reader);
+ assert(writer != NULL);
+ val = vlc_stream_fifo_Write(writer, "1st block\n", 10);
assert(val == 10);
- val = vlc_stream_fifo_Write(s, "2nd block\n", 10);
+ val = vlc_stream_fifo_Write(writer, "2nd block\n", 10);
assert(val == 10);
- val = vlc_stream_fifo_Write(s, "3rd block\n", 10);
+ val = vlc_stream_fifo_Write(writer, "3rd block\n", 10);
assert(val == 10);
- val = vlc_stream_fifo_Write(s, "4th block\n", 10);
+ val = vlc_stream_fifo_Write(writer, "4th block\n", 10);
assert(val == 10);
- val = vlc_stream_fifo_Write(s, "5th block\n", 10);
+ val = vlc_stream_fifo_Write(writer, "5th block\n", 10);
assert(val == 10);
- vlc_stream_fifo_Close(s);
+ vlc_stream_fifo_Close(writer);
- block = vlc_stream_ReadBlock(s);
+ block = vlc_stream_ReadBlock(reader);
assert(block != NULL);
- assert(vlc_stream_Tell(s) == 10);
+ assert(vlc_stream_Tell(reader) == 10);
assert(block->i_buffer == 10);
assert(memcmp(block->p_buffer, "1st block\n", 10) == 0);
block_Release(block);
- val = vlc_stream_Read(s, buf, 5);
+ val = vlc_stream_Read(reader, buf, 5);
assert(val == 5);
- assert(vlc_stream_Tell(s) == 15);
+ assert(vlc_stream_Tell(reader) == 15);
assert(memcmp(buf, "2nd b", 5) == 0);
- val = vlc_stream_Read(s, buf, 7);
+ val = vlc_stream_Read(reader, buf, 7);
assert(val == 7);
- assert(vlc_stream_Tell(s) == 22);
+ assert(vlc_stream_Tell(reader) == 22);
assert(memcmp(buf, "lock\n3r", 7) == 0);
- val = vlc_stream_Peek(s, &peek, 2);
+ val = vlc_stream_Peek(reader, &peek, 2);
assert(val == 2);
- assert(vlc_stream_Tell(s) == 22);
- assert(!vlc_stream_Eof(s));
+ assert(vlc_stream_Tell(reader) == 22);
+ assert(!vlc_stream_Eof(reader));
assert(memcmp(peek, "d ", 2) == 0);
/* seeking within peek buffer has to work... */
- val = vlc_stream_Seek(s, 23);
+ val = vlc_stream_Seek(reader, 23);
assert(val == VLC_SUCCESS);
- assert(vlc_stream_Tell(s) == 23);
- assert(!vlc_stream_Eof(s));
+ assert(vlc_stream_Tell(reader) == 23);
+ assert(!vlc_stream_Eof(reader));
- val = vlc_stream_Seek(s, 24);
+ val = vlc_stream_Seek(reader, 24);
assert(val == VLC_SUCCESS);
- assert(vlc_stream_Tell(s) == 24);
- assert(!vlc_stream_Eof(s));
+ assert(vlc_stream_Tell(reader) == 24);
+ assert(!vlc_stream_Eof(reader));
- val = vlc_stream_Peek(s, &peek, 2);
+ val = vlc_stream_Peek(reader, &peek, 2);
assert(val == 2);
- assert(vlc_stream_Tell(s) == 24);
- assert(!vlc_stream_Eof(s));
+ assert(vlc_stream_Tell(reader) == 24);
+ assert(!vlc_stream_Eof(reader));
assert(memcmp(peek, "bl", 2) == 0);
- block = vlc_stream_Block(s, 3);
+ block = vlc_stream_Block(reader, 3);
assert(block != NULL);
assert(block->i_buffer == 3);
- assert(vlc_stream_Tell(s) == 27);
+ assert(vlc_stream_Tell(reader) == 27);
assert(memcmp(block->p_buffer, "blo", 3) == 0);
block_Release(block);
- block = vlc_stream_ReadBlock(s);
+ block = vlc_stream_ReadBlock(reader);
assert(block != NULL);
assert(block->i_buffer == 3);
- assert(vlc_stream_Tell(s) == 30);
+ assert(vlc_stream_Tell(reader) == 30);
assert(memcmp(block->p_buffer, "ck\n", 3) == 0);
block_Release(block);
- val = vlc_stream_Read(s, buf, 5);
+ val = vlc_stream_Read(reader, buf, 5);
assert(val == 5);
- assert(vlc_stream_Tell(s) == 35);
- assert(!vlc_stream_Eof(s));
+ assert(vlc_stream_Tell(reader) == 35);
+ assert(!vlc_stream_Eof(reader));
assert(memcmp(buf, "4th b", 5) == 0);
- block = vlc_stream_ReadBlock(s);
+ block = vlc_stream_ReadBlock(reader);
assert(block != NULL);
assert(block->i_buffer == 5);
- assert(vlc_stream_Tell(s) == 40);
+ assert(vlc_stream_Tell(reader) == 40);
assert(memcmp(block->p_buffer, "lock\n", 5) == 0);
- vlc_stream_Delete(s);
+ vlc_stream_Delete(reader);
block_Release(block);
libvlc_release(vlc);
More information about the vlc-commits
mailing list