vlc | branch: master | Thomas Guillem <[email protected]> | Fri Jul 20 16:26:49 2018 +0200| [02ec20713089d52f2565e6752c7498d6d52d90a0] | committer: Thomas Guillem
stream: add vlc_stream_AttachmentNew Like vlc_stream_MemoryNew but with an attachment, that is released on stream destroy. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=02ec20713089d52f2565e6752c7498d6d52d90a0 --- src/input/stream.h | 3 +++ src/input/stream_memory.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/input/stream.h b/src/input/stream.h index 025d7e1795..60f0b0bd1b 100644 --- a/src/input/stream.h +++ b/src/input/stream.h @@ -36,6 +36,9 @@ void *vlc_stream_Private(stream_t *stream); /* */ void stream_CommonDelete( stream_t *s ); +stream_t *vlc_stream_AttachmentNew(vlc_object_t *p_this, + input_attachment_t *attachement); + /** * This function creates a raw stream_t from an URL. */ diff --git a/src/input/stream_memory.c b/src/input/stream_memory.c index f9a3df117c..e1b23531e3 100644 --- a/src/input/stream_memory.c +++ b/src/input/stream_memory.c @@ -25,6 +25,7 @@ # include "config.h" #endif +#include <vlc_input.h> #include "stream.h" struct vlc_stream_memory_private @@ -34,6 +35,12 @@ struct vlc_stream_memory_private uint8_t *p_buffer; }; +struct vlc_stream_attachment_private +{ + struct vlc_stream_memory_private memory; + input_attachment_t *attachment; +}; + static ssize_t Read( stream_t *, void *p_read, size_t i_read ); static int Seek( stream_t *, uint64_t ); static int Control( stream_t *, int i_query, va_list ); @@ -50,6 +57,14 @@ static void stream_MemoryDelete(stream_t *s) free(sys->p_buffer); } +static void stream_AttachmentDelete(stream_t *s) +{ + struct vlc_stream_attachment_private *sys = vlc_stream_Private(s); + + vlc_input_attachment_Delete(sys->attachment); + free(s->psz_name); +} + stream_t *(vlc_stream_MemoryNew)(vlc_object_t *p_this, uint8_t *p_buffer, size_t i_size, bool preserve) { @@ -73,6 +88,35 @@ stream_t *(vlc_stream_MemoryNew)(vlc_object_t *p_this, uint8_t *p_buffer, return s; } +stream_t *vlc_stream_AttachmentNew(vlc_object_t *p_this, + input_attachment_t *attachment) +{ + struct vlc_stream_attachment_private *p_sys; + stream_t *s = vlc_stream_CustomNew(p_this, stream_AttachmentDelete, + sizeof (*p_sys), "stream"); + if (unlikely(s == NULL)) + return NULL; + + s->psz_name = strdup("attachment"); + if (unlikely(s->psz_name == NULL)) + { + stream_CommonDelete(s); + return NULL; + } + + p_sys = vlc_stream_Private(s); + p_sys->memory.i_pos = 0; + p_sys->memory.i_size = attachment->i_data; + p_sys->memory.p_buffer = attachment->p_data; + p_sys->attachment = attachment; + + s->pf_read = Read; + s->pf_seek = Seek; + s->pf_control = Control; + + return s; +} + /**************************************************************************** * AStreamControl: ****************************************************************************/ _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
