]> git.sesse.net Git - vlc/commitdiff
* all: now mux and access_out can request to reserve some memory in front
authorLaurent Aimar <fenrir@videolan.org>
Mon, 13 Jan 2003 02:33:13 +0000 (02:33 +0000)
committerLaurent Aimar <fenrir@videolan.org>
Mon, 13 Jan 2003 02:33:13 +0000 (02:33 +0000)
of each sout buffer (will prevent some unnecessary memcpy :). Not yet
really used.

include/stream_output.h
modules/mux/avi.c
modules/mux/mpeg/ps.c
modules/mux/mpeg/ts.c
modules/packetizer/mpegvideo.c
src/stream_output/stream_output.c

index b44a74aa8dcbce90e0c75a609a9fd095fa52becd..c28db613891ce89f4d8e7d62428e8a12eda629a3 100644 (file)
@@ -2,7 +2,7 @@
  * stream_output.h : stream output module
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: stream_output.h,v 1.3 2003/01/08 10:38:32 fenrir Exp $
+ * $Id: stream_output.h,v 1.4 2003/01/13 02:33:13 fenrir Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Laurent Aimar <fenrir@via.ecp.fr>
  * sout_instance_t: stream output thread descriptor
  *****************************************************************************/
 
+/*
+ * i_allocated_size: size of allocated buffer
+ * p_allocated_buffer: where data has been allocated
+ *
+ * i_buffer_size: sizeof buffer from p_buffer
+ * p_buffer: where data begins
+ * i_size: size of valid data
+ *
+ */
 struct sout_buffer_t
 {
     size_t                  i_allocated_size;
+    byte_t                  *p_allocated_buffer;
+
+    size_t                  i_buffer_size;
     byte_t                  *p_buffer;
 
     size_t                  i_size;
-//    mtime_t                 i_date;
     mtime_t                 i_length;
 
     mtime_t                 i_dts;
@@ -91,11 +102,13 @@ struct sout_instance_t
     module_t                *p_access;
     int                     i_method;
     void                    *p_access_data;
+    int                     i_access_preheader;
     int                     (* pf_write )( sout_instance_t *, sout_buffer_t * );
     int                     (* pf_seek  )( sout_instance_t *, off_t );
 
     module_t                *p_mux;
     void                    *p_mux_data;
+    int                     i_mux_preheader;
     int                     (* pf_mux_addstream )( sout_instance_t *,
                                                    sout_input_t * );
     int                     (* pf_mux_delstream )( sout_instance_t *,
@@ -135,6 +148,7 @@ VLC_EXPORT( int,            sout_InputSendBuffer,  ( sout_input_t *, sout_buffer
 
 VLC_EXPORT( sout_buffer_t*, sout_BufferNew,    ( sout_instance_t *, size_t ) );
 VLC_EXPORT( int,            sout_BufferRealloc,( sout_instance_t *, sout_buffer_t*, size_t ) );
+VLC_EXPORT( int,            sout_BufferReallocFromPreHeader,( sout_instance_t *, sout_buffer_t*, size_t ) );
 VLC_EXPORT( int,            sout_BufferDelete, ( sout_instance_t *, sout_buffer_t* ) );
 VLC_EXPORT( sout_buffer_t*, sout_BufferDuplicate,(sout_instance_t *, sout_buffer_t * ) );
 VLC_EXPORT( void,           sout_BufferChain,  ( sout_buffer_t **, sout_buffer_t * ) );
index fb72e822d749c76e4a562b6cea1229db8baa1ecd..3c7c99ff8618b1d07cac869fb601634969d5da59 100644 (file)
@@ -2,7 +2,7 @@
  * avi.c
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: avi.c,v 1.1 2003/01/12 04:30:14 fenrir Exp $
+ * $Id: avi.c,v 1.2 2003/01/13 02:33:13 fenrir Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -140,8 +140,8 @@ static int Open( vlc_object_t *p_this )
     p_sout->pf_mux_addstream = AddStream;
     p_sout->pf_mux_delstream = DelStream;
     p_sout->pf_mux           = Mux;
-
     p_sout->p_mux_data = (void*)p_mux;
+    p_sout->i_mux_preheader  = 8; // (fourcc,length) header
 
     /* room to add header at the end */
     p_hdr = sout_BufferNew( p_sout, HDR_SIZE );
@@ -303,7 +303,6 @@ static int Mux      ( sout_instance_t *p_sout )
         while( i_count > 0 )
         {
             sout_buffer_t *p_data;
-            sout_buffer_t *p_hdr;
 
             p_data = sout_FifoGet( p_fifo );
 
@@ -311,9 +310,24 @@ static int Mux      ( sout_instance_t *p_sout )
             p_stream->i_duration  += p_data->i_length;
             p_stream->i_totalsize += p_data->i_size;
 
-            p_hdr = sout_BufferNew( p_sout, 8 );
-            SetFCC( p_hdr->p_buffer, p_stream->fcc );
-            SetDWLE( p_hdr->p_buffer + 4, p_data->i_size );
+            if( sout_BufferReallocFromPreHeader( p_sout, p_data, 8 ) )
+            {
+                /* there isn't enough data in preheader */
+                sout_buffer_t *p_hdr;
+
+                p_hdr = sout_BufferNew( p_sout, 8 );
+                SetFCC( p_hdr->p_buffer, p_stream->fcc );
+                SetDWLE( p_hdr->p_buffer + 4, p_data->i_size );
+
+                p_sout->pf_write( p_sout, p_hdr );
+                p_mux->i_movi_size += p_hdr->i_size;
+
+            }
+            else
+            {
+                SetFCC( p_data->p_buffer, p_stream->fcc );
+                SetDWLE( p_data->p_buffer + 4, p_data->i_size - 8 );
+            }
 
             if( p_data->i_size & 0x01 )
             {
@@ -321,8 +335,6 @@ static int Mux      ( sout_instance_t *p_sout )
                 p_data->i_size += 1;
             }
 
-            p_sout->pf_write( p_sout, p_hdr );
-            p_mux->i_movi_size += p_hdr->i_size;
             p_sout->pf_write( p_sout, p_data );
             p_mux->i_movi_size += p_data->i_size;
 
index 50c640409d727f2529846286bf5f548891825de8..dfb18528aacab5f1efdccb7d707376ad4cea000a 100644 (file)
@@ -2,7 +2,7 @@
  * ps.c
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: ps.c,v 1.4 2003/01/08 10:34:58 fenrir Exp $
+ * $Id: ps.c,v 1.5 2003/01/13 02:33:13 fenrir Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Eric Petit <titer@videolan.org>
@@ -120,6 +120,7 @@ static int Open( vlc_object_t *p_this )
     p_sout->pf_mux_delstream = DelStream;
     p_sout->pf_mux           = Mux;
     p_sout->p_mux_data       = (void*)p_mux;
+    p_sout->i_mux_preheader  = 30; // really enough for a pes header
 
     p_mux->i_stream_id_mpga = 0xc0;
     p_mux->i_stream_id_a52  = 0x80;
index 8566611d04d4c031b8ab37d83a7f5d02eb25d194..531ce3b3fe060193ac48a759bb7fddd56d1da97f 100644 (file)
@@ -2,7 +2,7 @@
  * ts.c
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: ts.c,v 1.6 2003/01/11 17:23:13 ipkiss Exp $
+ * $Id: ts.c,v 1.7 2003/01/13 02:33:13 fenrir Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Eric Petit <titer@videolan.org>
@@ -158,6 +158,7 @@ static int Open( vlc_object_t *p_this )
     p_sout->pf_mux_delstream = DelStream;
     p_sout->pf_mux           = Mux;
     p_sout->p_mux_data       = (void*)p_mux;
+    p_sout->i_mux_preheader  = 30; // really enough for a pes header
 
     srand( (uint32_t)mdate() );
 
index aa490d05f9222096e62eea257be3604e4b9768ef..bf7a2a7d085d09cfb0eb6dbdf851bb71c88c3547 100644 (file)
@@ -2,7 +2,7 @@
  * mpegvideo.c
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: mpegvideo.c,v 1.2 2003/01/08 10:26:49 fenrir Exp $
+ * $Id: mpegvideo.c,v 1.3 2003/01/13 02:33:13 fenrir Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Eric Petit <titer@videolan.org>
@@ -188,11 +188,11 @@ static int CopyUntilNextStartCode( packetizer_t   *p_pack,
                 GetBits( &p_pack->bit_stream, 8 );
         i_copy++;
 
-        if( *pi_pos + 2048 > p_sout_buffer->i_allocated_size )
+        if( *pi_pos + 2048 > p_sout_buffer->i_buffer_size )
         {
             sout_BufferRealloc( p_pack->p_sout_input->p_sout,
                                 p_sout_buffer,
-                                p_sout_buffer->i_allocated_size + 50 * 1024);
+                                p_sout_buffer->i_buffer_size + 50 * 1024);
         }
 
     } while( ShowBits( &p_pack->bit_stream, 24 ) != 0x01 &&
index e91dec78267e24d828603d3ba414d31d2680ddbf..42d497c26e7fe0bbfab28edd64c7fdbb46e2df9a 100644 (file)
@@ -2,7 +2,7 @@
  * stream_output.c : stream output module
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: stream_output.c,v 1.8 2003/01/08 14:59:23 sam Exp $
+ * $Id: stream_output.c,v 1.9 2003/01/13 02:33:13 fenrir Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Laurent Aimar <fenrir@via.ecp.fr>
@@ -82,6 +82,8 @@ static int InitInstance( sout_instance_t * p_sout )
     p_sout->psz_name = "";
     p_sout->p_access = NULL;
     p_sout->p_mux = NULL;
+    p_sout->i_access_preheader = 0;
+    p_sout->i_mux_preheader = 0;
     p_sout->i_nb_inputs = 0;
     p_sout->pp_inputs = NULL;
     vlc_mutex_init( p_sout, &p_sout->lock );
@@ -478,55 +480,91 @@ sout_buffer_t *sout_FifoShow( sout_fifo_t *p_fifo )
 sout_buffer_t *sout_BufferNew( sout_instance_t *p_sout, size_t i_size )
 {
     sout_buffer_t *p_buffer;
+    size_t        i_prehader;
 
 #ifdef DEBUG_BUFFER
     msg_Dbg( p_sout, "allocating an new buffer, size:%d", (uint32_t)i_size );
 #endif
 
     p_buffer = malloc( sizeof( sout_buffer_t ) );
+    i_prehader = p_sout->i_access_preheader + p_sout->i_mux_preheader;
+
     if( i_size > 0 )
     {
-        p_buffer->p_buffer = malloc( i_size );
+        p_buffer->p_allocated_buffer = malloc( i_size + i_prehader );
+        p_buffer->p_buffer = p_buffer->p_allocated_buffer + i_prehader;
     }
     else
     {
+        p_buffer->p_allocated_buffer = NULL;
         p_buffer->p_buffer = NULL;
     }
-    p_buffer->i_allocated_size = i_size;
+    p_buffer->i_allocated_size = i_size + i_prehader;
+    p_buffer->i_buffer_size = i_size;
+
     p_buffer->i_size = i_size;
+    p_buffer->i_length = 0;
+    p_buffer->i_dts = 0;
+    p_buffer->i_pts = 0;
+    p_buffer->i_bitrate = 0;
     p_buffer->p_next = NULL;
 
     return( p_buffer );
 }
 int sout_BufferRealloc( sout_instance_t *p_sout, sout_buffer_t *p_buffer, size_t i_size )
 {
+    size_t          i_prehader;
+
 #ifdef DEBUG_BUFFER
     msg_Dbg( p_sout,
              "realloc buffer old size:%d new size:%d",
              (uint32_t)p_buffer->i_allocated_size,
              (uint32_t)i_size );
 #endif
-    if( !( p_buffer->p_buffer = realloc( p_buffer->p_buffer, i_size ) ) )
+
+    i_prehader = p_buffer->p_buffer - p_buffer->p_allocated_buffer;
+
+    if( !( p_buffer->p_allocated_buffer = realloc( p_buffer->p_allocated_buffer, i_size + i_prehader ) ) )
     {
         msg_Err( p_sout, "realloc failed" );
         p_buffer->i_allocated_size = 0;
+        p_buffer->i_buffer_size = 0;
         p_buffer->i_size = 0;
-
+        p_buffer->p_buffer = NULL;
         return( -1 );
     }
+    p_buffer->p_buffer = p_buffer->p_allocated_buffer + i_prehader;
+
+    p_buffer->i_allocated_size = i_size + i_prehader;
+    p_buffer->i_buffer_size = i_size;
 
-    p_buffer->i_allocated_size = i_size;
     return( 0 );
 }
 
+int sout_BufferReallocFromPreHeader( sout_instance_t *p_sout, sout_buffer_t *p_buffer, size_t i_size )
+{
+    size_t  i_preheader;
+
+    i_preheader = p_buffer->p_buffer - p_buffer->p_allocated_buffer;
+
+    if( i_preheader < i_size )
+    {
+        return( -1 );
+    }
+
+    p_buffer->p_buffer -= i_size;
+    p_buffer->i_size += i_size;
+    p_buffer->i_buffer_size += i_size;
+}
+
 int sout_BufferDelete( sout_instance_t *p_sout, sout_buffer_t *p_buffer )
 {
 #ifdef DEBUG_BUFFER
     msg_Dbg( p_sout, "freeing buffer, size:%d", p_buffer->i_size );
 #endif
-    if( p_buffer->p_buffer )
+    if( p_buffer->p_allocated_buffer )
     {
-        free( p_buffer->p_buffer );
+        free( p_buffer->p_allocated_buffer );
     }
     free( p_buffer );
     return( 0 );