]> git.sesse.net Git - vlc/blobdiff - src/input/mem_stream.c
Removes trailing spaces. Removes tabs.
[vlc] / src / input / mem_stream.c
index 5778fb62d73713d168a2afc93794d446e1569433..775d80f36813568d678a072d6a8d98719f833f62 100644 (file)
@@ -1,10 +1,10 @@
 /*****************************************************************************
  * mem_stream.c: stream_t wrapper around memory buffer
  *****************************************************************************
- * Copyright (C) 1999-2004 VideoLAN
- * $Id: stream.c 9390 2004-11-22 09:56:48Z fenrir $
+ * Copyright (C) 1999-2004 the VideoLAN team
+ * $Id$
  *
- * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
+ * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include <stdlib.h>
 #include <vlc/vlc.h>
-#include <vlc/input.h>
 
 #include "input_internal.h"
 
 struct stream_sys_t
 {
+    vlc_bool_t  i_preserve_memory;
     int64_t     i_pos;      /* Current reading offset */
     int64_t     i_size;
     uint8_t    *p_buffer;
 
 };
 
-static int AStreamReadMem( stream_t *, void *p_read, int i_read );
-static int AStreamPeekMem( stream_t *, uint8_t **pp_peek, int i_read );
-static int AStreamControl( stream_t *, int i_query, va_list );
+static int  Read   ( stream_t *, void *p_read, int i_read );
+static int  Peek   ( stream_t *, const uint8_t **pp_peek, int i_read );
+static int  Control( stream_t *, int i_query, va_list );
+static void Delete ( stream_t * );
 
-/****************************************************************************
- * stream_MemoryNew: create a stream from a buffer
- ****************************************************************************/
+/**
+ * Create a stream from a memory buffer
+ *
+ * \param p_this the calling vlc_object
+ * \param p_buffer the memory buffer for the stream
+ * \param i_buffer the size of the buffer
+ * \param i_preserve_memory if this is set to VLC_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 )
+                              int64_t i_size, vlc_bool_t i_preserve_memory )
 {
-    stream_t *s = vlc_object_create( p_this, VLC_OBJECT_STREAM );
+    stream_t *s = vlc_stream_create( p_this );
     stream_sys_t *p_sys;
 
     if( !s ) return NULL;
@@ -54,19 +60,23 @@ stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer,
     p_sys->i_pos = 0;
     p_sys->i_size = i_size;
     p_sys->p_buffer = p_buffer;
+    p_sys->i_preserve_memory = i_preserve_memory;
+
+    s->pf_read    = Read;
+    s->pf_peek    = Peek;
+    s->pf_control = Control;
+    s->pf_destroy = Delete;
 
-    s->pf_block   = NULL;
-    s->pf_read    = AStreamReadMem;    /* Set up later */
-    s->pf_peek    = AStreamPeekMem;
-    s->pf_control = AStreamControl;
+    s->i_char_width = 1;
+    s->b_little_endian = VLC_FALSE;
     vlc_object_attach( s, p_this );
 
     return s;
 }
 
-void stream_MemoryDelete( stream_t *s, vlc_bool_t b_free_buffer )
+static void Delete( stream_t *s )
 {
-    if( b_free_buffer ) free( s->p_sys->p_buffer );
+    if( !s->p_sys->i_preserve_memory ) free( s->p_sys->p_buffer );
     free( s->p_sys );
     vlc_object_detach( s );
     vlc_object_destroy( s );
@@ -75,7 +85,7 @@ void stream_MemoryDelete( stream_t *s, vlc_bool_t b_free_buffer )
 /****************************************************************************
  * AStreamControl:
  ****************************************************************************/
-static int AStreamControl( stream_t *s, int i_query, va_list args )
+static int Control( stream_t *s, int i_query, va_list args )
 {
     stream_sys_t *p_sys = s->p_sys;
 
@@ -108,7 +118,7 @@ static int AStreamControl( stream_t *s, int i_query, va_list args )
         case STREAM_SET_POSITION:
             i_64 = (int64_t)va_arg( args, int64_t );
             i_64 = __MAX( i_64, 0 );
-            i_64 = __MIN( i_64, s->p_sys->i_size ); 
+            i_64 = __MIN( i_64, s->p_sys->i_size );
             p_sys->i_pos = i_64;
             break;
 
@@ -128,7 +138,7 @@ static int AStreamControl( stream_t *s, int i_query, va_list args )
     return VLC_SUCCESS;
 }
 
-static int AStreamReadMem( stream_t *s, void *p_read, int i_read )
+static int Read( stream_t *s, void *p_read, int i_read )
 {
     stream_sys_t *p_sys = s->p_sys;
     int i_res = __MIN( i_read, p_sys->i_size - p_sys->i_pos );
@@ -137,7 +147,7 @@ static int AStreamReadMem( stream_t *s, void *p_read, int i_read )
     return i_res;
 }
 
-static int AStreamPeekMem( stream_t *s, uint8_t **pp_peek, int i_read )
+static int Peek( stream_t *s, const uint8_t **pp_peek, int i_read )
 {
     stream_sys_t *p_sys = s->p_sys;
     int i_res = __MIN( i_read, p_sys->i_size - p_sys->i_pos );