]> git.sesse.net Git - vlc/blobdiff - modules/mux/ogg.c
ogg: Fix a divide by zero.
[vlc] / modules / mux / ogg.c
index bcdc13103cb3c85ab46d751ec7efd0ebf2f1839a..bc420a24bf3774e6cb343dde602a6e0ecac5d81a 100644 (file)
@@ -34,7 +34,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_sout.h>
 #include <vlc_block.h>
 #include <vlc_codecs.h>
@@ -48,7 +49,7 @@ static int  Open   ( vlc_object_t * );
 static void Close  ( vlc_object_t * );
 
 vlc_module_begin();
-    set_description( _("Ogg/OGM muxer") );
+    set_description( N_("Ogg/OGM muxer") );
     set_capability( "sout mux", 10 );
     set_category( CAT_SOUT );
     set_subcategory( SUBCAT_SOUT_MUX );
@@ -217,6 +218,8 @@ static int Open( vlc_object_t *p_this )
     msg_Info( p_mux, "Open" );
 
     p_sys                 = malloc( sizeof( sout_mux_sys_t ) );
+    if( !p_sys )
+        return VLC_ENOMEM;
     p_sys->i_streams      = 0;
     p_sys->i_add_streams  = 0;
     p_sys->i_del_streams  = 0;
@@ -318,6 +321,8 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
     msg_Dbg( p_mux, "adding input" );
 
     p_input->p_sys = p_stream = malloc( sizeof( ogg_stream_t ) );
+    if( !p_stream )
+        return VLC_ENOMEM;
 
     p_stream->i_cat       = p_input->p_fmt->i_cat;
     p_stream->i_fourcc    = p_input->p_fmt->i_codec;
@@ -349,6 +354,11 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
         case VLC_FOURCC( 'S', 'N', 'O', 'W' ):
         case VLC_FOURCC( 'd', 'r', 'a', 'c' ):
             p_stream->p_oggds_header = malloc( sizeof(oggds_header_t) );
+            if( !p_stream->p_oggds_header )
+            {
+                free( p_stream );
+                return VLC_ENOMEM;
+            }
             memset( p_stream->p_oggds_header, 0, sizeof(oggds_header_t) );
             p_stream->p_oggds_header->i_packet_type = PACKET_TYPE_HEADER;
 
@@ -417,6 +427,11 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
 
             p_stream->p_oggds_header =
                 malloc( sizeof(oggds_header_t) + p_input->p_fmt->i_extra );
+            if( !p_stream->p_oggds_header )
+            {
+                free( p_stream );
+                return VLC_ENOMEM;
+            }
             memset( p_stream->p_oggds_header, 0, sizeof(oggds_header_t) );
             p_stream->p_oggds_header->i_packet_type = PACKET_TYPE_HEADER;
 
@@ -457,6 +472,11 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
         {
         case VLC_FOURCC( 's', 'u','b', 't' ):
             p_stream->p_oggds_header = malloc( sizeof(oggds_header_t) );
+            if( !p_stream->p_oggds_header )
+            {
+                free( p_stream );
+                return VLC_ENOMEM;
+            }
             memset( p_stream->p_oggds_header, 0, sizeof(oggds_header_t) );
             p_stream->p_oggds_header->i_packet_type = PACKET_TYPE_HEADER;
 
@@ -536,6 +556,7 @@ static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
 static block_t *OggStreamFlush( 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;
 
@@ -561,6 +582,7 @@ static block_t *OggStreamFlush( sout_mux_t *p_mux,
 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;
 
@@ -850,6 +872,9 @@ static void OggSetDate( block_t *p_og, mtime_t i_dts, mtime_t i_length )
     {
         i_count++;
     }
+
+    if( i_count == 0 ) return; /* ignore. */
+
     i_delta = i_length / i_count;
 
     for( p_tmp = p_og; p_tmp != NULL; p_tmp = p_tmp->p_next )
@@ -977,7 +1002,7 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
     }
     else if( p_stream->i_cat == SPU_ES )
     {
-        /* granulepos is in milisec */
+        /* granulepos is in millisec */
         op.granulepos = ( p_data->i_dts - p_sys->i_start_dts ) / 1000;
     }