X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Finput%2Fstream_memory.c;h=d73d846cdf17bb2c2bb59788eb9729988ef4f578;hb=e2eccee759772d903d7fb1fed398fb354d45b676;hp=341f5f6083ff9915c2c29485f043094df02d4a82;hpb=ea83a25e84bca24d045c34713ce7008ea5ce4e8a;p=vlc diff --git a/src/input/stream_memory.c b/src/input/stream_memory.c index 341f5f6083..d73d846cdf 100644 --- a/src/input/stream_memory.c +++ b/src/input/stream_memory.c @@ -30,8 +30,8 @@ struct stream_sys_t { bool i_preserve_memory; - int64_t i_pos; /* Current reading offset */ - int64_t i_size; + uint64_t i_pos; /* Current reading offset */ + uint64_t i_size; uint8_t *p_buffer; }; @@ -41,6 +41,7 @@ static int Peek ( stream_t *, const uint8_t **pp_peek, unsigned int i_read ); static int Control( stream_t *, int i_query, va_list ); static void Delete ( stream_t * ); +#undef stream_MemoryNew /** * Create a stream from a memory buffer * @@ -50,15 +51,22 @@ static void Delete ( stream_t * ); * \param i_preserve_memory if this is set to false the memory buffer * pointed to by p_buffer is freed on stream_Destroy */ -stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer, - int64_t i_size, bool i_preserve_memory ) +stream_t *stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer, + uint64_t i_size, bool i_preserve_memory ) { - stream_t *s = vlc_stream_create( p_this ); + stream_t *s = stream_CommonNew( p_this ); stream_sys_t *p_sys; - if( !s ) return NULL; + if( !s ) + return NULL; + s->psz_path = strdup( "" ); /* N/A */ s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) ); + if( !s->psz_path || !s->p_sys ) + { + stream_CommonDelete( s ); + return NULL; + } p_sys->i_pos = 0; p_sys->i_size = i_size; p_sys->p_buffer = p_buffer; @@ -69,10 +77,14 @@ stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer, s->pf_control = Control; s->pf_destroy = Delete; - s->i_char_width = 1; - s->b_little_endian = false; vlc_object_attach( s, p_this ); + /* Get a weak link to the parent input */ + /* FIXME: The usage of vlc_object_find has to be removed. */ + s->p_input = (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT ); + if(s->p_input) + vlc_object_release((vlc_object_t*)s->p_input); + return s; } @@ -80,8 +92,7 @@ static void Delete( stream_t *s ) { if( !s->p_sys->i_preserve_memory ) free( s->p_sys->p_buffer ); free( s->p_sys ); - vlc_object_detach( s ); - vlc_object_release( s ); + stream_CommonDelete( s ); } /**************************************************************************** @@ -92,13 +103,13 @@ static int Control( stream_t *s, int i_query, va_list args ) stream_sys_t *p_sys = s->p_sys; bool *p_bool; - int64_t *pi_64, i_64; + uint64_t *pi_64, i_64; int i_int; switch( i_query ) { case STREAM_GET_SIZE: - pi_64 = (int64_t*)va_arg( args, int64_t * ); + pi_64 = va_arg( args, uint64_t * ); *pi_64 = p_sys->i_size; break; @@ -113,18 +124,16 @@ static int Control( stream_t *s, int i_query, va_list args ) break; case STREAM_GET_POSITION: - pi_64 = (int64_t*)va_arg( args, int64_t * ); + pi_64 = va_arg( args, uint64_t * ); *pi_64 = p_sys->i_pos; break; case STREAM_SET_POSITION: - i_64 = (int64_t)va_arg( args, int64_t ); - i_64 = __MAX( i_64, 0 ); + i_64 = va_arg( args, uint64_t ); i_64 = __MIN( i_64, s->p_sys->i_size ); p_sys->i_pos = i_64; break; - case STREAM_GET_MTU: case STREAM_GET_CONTENT_TYPE: return VLC_EGENERIC;