]> git.sesse.net Git - vlc/commitdiff
factor the ogg paging code
authorogg.k.ogg.k <ogg.k.ogg.k@googlemail.com>
Thu, 30 Jul 2009 10:12:22 +0000 (11:12 +0100)
committerLaurent Aimar <fenrir@videolan.org>
Fri, 31 Jul 2009 18:24:38 +0000 (20:24 +0200)
Signed-off-by: Laurent Aimar <fenrir@videolan.org>
modules/mux/ogg.c

index 2b1acf29cbfd697927ef770f8840cdf79192c7e1..7528059455567c4199f8dff9a9756edd8ebb8722 100644 (file)
@@ -557,14 +557,16 @@ static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
 /*****************************************************************************
  * Ogg bitstream manipulation routines
  *****************************************************************************/
-static block_t *OggStreamFlush( sout_mux_t *p_mux,
-                                ogg_stream_state *p_os, mtime_t i_pts )
+static block_t *OggStreamGetPage( sout_mux_t *p_mux,
+                                  ogg_stream_state *p_os, mtime_t i_pts,
+                                  bool flush )
 {
     (void)p_mux;
     block_t *p_og, *p_og_first = NULL;
     ogg_page og;
+    int (*pager)( ogg_stream_state*, ogg_page* ) = flush ? ogg_stream_flush : ogg_stream_pageout;
 
-    while( ogg_stream_flush( p_os, &og ) )
+    while( pager( p_os, &og ) )
     {
         /* Flush all data */
         p_og = block_New( p_mux, og.header_len + og.body_len );
@@ -583,30 +585,16 @@ static block_t *OggStreamFlush( sout_mux_t *p_mux,
     return p_og_first;
 }
 
+static block_t *OggStreamFlush( sout_mux_t *p_mux,
+                                ogg_stream_state *p_os, mtime_t i_pts )
+{
+    return OggStreamGetPage( p_mux, p_os, i_pts, true );
+}
+
 static block_t *OggStreamPageOut( sout_mux_t *p_mux,
                                   ogg_stream_state *p_os, mtime_t i_pts )
 {
-    (void)p_mux;
-    block_t *p_og, *p_og_first = NULL;
-    ogg_page og;
-
-    while( ogg_stream_pageout( p_os, &og ) )
-    {
-        /* Flush all data */
-        p_og = block_New( p_mux, og.header_len + og.body_len );
-
-        memcpy( p_og->p_buffer, og.header, og.header_len );
-        memcpy( p_og->p_buffer + og.header_len, og.body, og.body_len );
-        p_og->i_dts     = 0;
-        p_og->i_pts     = i_pts;
-        p_og->i_length  = 0;
-
-        i_pts = 0; // write them only once
-
-        block_ChainAppend( &p_og_first, p_og );
-    }
-
-    return p_og_first;
+    return OggStreamGetPage( p_mux, p_os, i_pts, false );
 }
 
 static block_t *OggCreateHeader( sout_mux_t *p_mux )