]> git.sesse.net Git - vlc/blobdiff - modules/codec/theora.c
Clean up L20 decoding
[vlc] / modules / codec / theora.c
index 57d90d5e6abb7e0406c6cc6a707f0df4821c8f17..6493f35027c012ee4612cf2b04de22d90ca02a88 100644 (file)
@@ -120,7 +120,7 @@ vlc_module_begin ()
     add_shortcut( "theora" )
 
 #   define ENC_CFG_PREFIX "sout-theora-"
-    add_integer( ENC_CFG_PREFIX "quality", 2, NULL, ENC_QUALITY_TEXT,
+    add_integer( ENC_CFG_PREFIX "quality", 2, ENC_QUALITY_TEXT,
                  ENC_QUALITY_LONGTEXT, false )
 vlc_module_end ()
 
@@ -250,6 +250,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     }
 
     /* Set output properties */
+    if( !p_sys->b_packetizer )
     switch( p_sys->ti.pixelformat )
     {
       case OC_PF_420:
@@ -550,9 +551,7 @@ static int OpenEncoder( vlc_object_t *p_this )
 {
     encoder_t *p_enc = (encoder_t *)p_this;
     encoder_sys_t *p_sys;
-    ogg_packet header;
-    uint8_t *p_extra;
-    int i_quality, i;
+    int i_quality;
 
     if( p_enc->fmt_out.i_codec != VLC_CODEC_THEORA &&
         !p_enc->b_force )
@@ -644,25 +643,24 @@ static int OpenEncoder( vlc_object_t *p_this )
     theora_comment_init( &p_sys->tc );
 
     /* Create and store headers */
-    p_enc->fmt_out.i_extra = 3 * 2;
-    for( i = 0; i < 3; i++ )
+    for( int i = 0; i < 3; i++ )
     {
-        if( i == 0 ) theora_encode_header( &p_sys->td, &header );
-        else if( i == 1 ) theora_encode_comment( &p_sys->tc, &header );
-        else if( i == 2 ) theora_encode_tables( &p_sys->td, &header );
-
-        p_enc->fmt_out.p_extra = xrealloc( p_enc->fmt_out.p_extra,
-                                      p_enc->fmt_out.i_extra + header.bytes );
-        p_extra = p_enc->fmt_out.p_extra;
-        p_extra += p_enc->fmt_out.i_extra + (i-3)*2;
-        p_enc->fmt_out.i_extra += header.bytes;
+        ogg_packet header;
 
-        *(p_extra++) = header.bytes >> 8;
-        *(p_extra++) = header.bytes & 0xFF;
+        if( i == 0 )
+            theora_encode_header( &p_sys->td, &header );
+        else if( i == 1 )
+            theora_encode_comment( &p_sys->tc, &header );
+        else
+            theora_encode_tables( &p_sys->td, &header );
 
-        memcpy( p_extra, header.packet, header.bytes );
+        if( xiph_AppendHeaders( &p_enc->fmt_out.i_extra, &p_enc->fmt_out.p_extra,
+                                header.bytes, header.packet ) )
+        {
+            p_enc->fmt_out.i_extra = 0;
+            p_enc->fmt_out.p_extra = NULL;
+        }
     }
-
     return VLC_SUCCESS;
 }
 
@@ -679,6 +677,7 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
     yuv_buffer yuv;
     int i;
 
+    if( !p_pict ) return NULL;
     /* Sanity check */
     if( p_pict->p[0].i_pitch < (int)p_sys->i_width ||
         p_pict->p[0].i_lines < (int)p_sys->i_height )