]> git.sesse.net Git - vlc/blobdiff - modules/codec/schroedinger.c
Less memleaks in Qt interface.
[vlc] / modules / codec / schroedinger.c
index 5886988cefaf9e640600dc3057a5c35c55a1fbd5..3fc1582b8a901c15a6f76bf71b2fc7012ee9c442 100644 (file)
 
 #include <schroedinger/schro.h>
 
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+static int        OpenDecoder  ( vlc_object_t * );
+static void       CloseDecoder ( vlc_object_t * );
+
+vlc_module_begin();
+    set_category( CAT_INPUT );
+    set_subcategory( SUBCAT_INPUT_VCODEC );
+    set_description( N_("Schroedinger video decoder") );
+    set_capability( "decoder", 200 );
+    set_callbacks( OpenDecoder, CloseDecoder );
+    add_shortcut( "schroedinger" );
+vlc_module_end();
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static picture_t *DecodeBlock  ( decoder_t *p_dec, block_t **pp_block );
+
 /*****************************************************************************
  * picture_pts_t : store pts alongside picture number, not carried through
  * decoder
@@ -50,6 +70,12 @@ struct picture_pts_t
    mtime_t i_pts;    //pts for this picture
 };
 
+struct picture_free_t
+{
+   picture_t *p_pic;
+   decoder_t *p_dec;
+};
+
 /*****************************************************************************
  * decoder_sys_t : Schroedinger decoder descriptor
  *****************************************************************************/
@@ -67,25 +93,7 @@ struct decoder_sys_t
     int i_ts_resync_hack;
 };
 
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int        OpenDecoder  ( vlc_object_t * );
-static void       CloseDecoder ( vlc_object_t * );
-static picture_t *DecodeBlock  ( decoder_t *p_dec, block_t **pp_block );
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-
-vlc_module_begin();
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_VCODEC );
-    set_description( N_("Schroedinger video decoder") );
-    set_capability( "decoder", 200 );
-    set_callbacks( OpenDecoder, CloseDecoder );
-    add_shortcut( "schroedinger" );
-vlc_module_end();
+//#define TRACE
 
 /*****************************************************************************
  * ResetPTStlb: Purge all entries in @p_dec@'s PTS-tlb
@@ -245,13 +253,13 @@ static mtime_t GetPicturePTS( decoder_t *p_dec, uint32_t u_pnum )
  *****************************************************************************/
 static void SchroFrameFree( SchroFrame *frame, void *priv)
 {
-    picture_t *p_pic = priv;
+    struct picture_free_t *p_free = priv;
 
-    if( !p_pic )
+    if( !p_free )
         return;
 
-    /* FIXME it is wrong, you should call pf_vout_buffer_del */
-    if( p_pic->pf_release ) p_pic->pf_release( p_pic );
+    p_free->p_dec->pf_vout_buffer_del( p_free->p_dec, p_free->p_pic );
+    free(p_free);
     (void)frame;
 }
 
@@ -263,6 +271,7 @@ static SchroFrame *CreateSchroFrameFromPic( decoder_t *p_dec )
     decoder_sys_t *p_sys = p_dec->p_sys;
     SchroFrame *p_schroframe = schro_frame_new();
     picture_t *p_pic = NULL;
+    struct picture_free_t *p_free;
 
     if( !p_schroframe )
         return NULL;
@@ -284,7 +293,11 @@ static SchroFrame *CreateSchroFrameFromPic( decoder_t *p_dec )
 
     p_schroframe->width = p_sys->p_format->width;
     p_schroframe->height = p_sys->p_format->height;
-    schro_frame_set_free_callback( p_schroframe, SchroFrameFree, p_pic );
+
+    p_free = malloc( sizeof( *p_free ) );
+    p_free->p_pic = p_pic;
+    p_free->p_dec = p_dec;
+    schro_frame_set_free_callback( p_schroframe, SchroFrameFree, p_free );
 
     for( int i=0; i<3; i++ )
     {
@@ -384,7 +397,9 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         /* reset the decoder when seeking as the decode in progress is invalid */
         /* discard the block as it is just a null magic block */
         if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) {
+#ifdef TRACE
             msg_Dbg( p_dec, "SCHRO_DECODER_RESET" );
+#endif
             schro_decoder_reset( p_sys->p_schro );
 
             ResetPTStlb( p_dec );
@@ -420,6 +435,10 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
             size_t i_pulen = GetDWBE( p_block->p_buffer + i_bufused + 5 );
             uint8_t *p_pu = p_block->p_buffer + i_bufused;
 
+            if( 0 == i_pulen ) {
+                i_pulen = 13;
+            }
+
             /* blocks that do not start with the parse info prefix are invalid */
             if( p_pu[0] != 'B' || p_pu[1] != 'B' ||
                 p_pu[2] != 'C' || p_pu[3] != 'D')
@@ -450,8 +469,10 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 b_bail = 1;
             }
 
+#ifdef TRACE
             msg_Dbg( p_dec, "Inserting bytes into decoder len=%zu of %zu pts=%"PRId64,
                      i_pulen, p_block->i_buffer, p_block->i_pts);
+#endif
             /* this stops the same block being fed back into this function if
              * we were on the next iteration of this loop to output a picture */
             *pp_block = NULL;
@@ -462,9 +483,16 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
             i_bufused += i_pulen;
 
             if( state == SCHRO_DECODER_FIRST_ACCESS_UNIT ) {
+#ifdef TRACE
                 msg_Dbg( p_dec, "SCHRO_DECODER_FIRST_ACCESS_UNIT");
+#endif
                 SetVideoFormat( p_dec );
                 ResetPTStlb( p_dec );
+
+                p_schroframe = CreateSchroFrameFromPic( p_dec );
+                if( p_schroframe ) {
+                    schro_decoder_add_output_picture( p_sys->p_schro, p_schroframe);
+                }
             }
 
             if( b_bail )
@@ -479,11 +507,15 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         switch( state )
         {
         case SCHRO_DECODER_NEED_BITS:
+#ifdef TRACE
             msg_Dbg( p_dec, "SCHRO_DECODER_NEED_BITS" );
+#endif
             return NULL;
 
         case SCHRO_DECODER_NEED_FRAME:
+#ifdef TRACE
             msg_Dbg( p_dec, "SCHRO_DECODER_NEED_FRAME" );
+#endif
             p_schroframe = CreateSchroFrameFromPic( p_dec );
 
             if( !p_schroframe )
@@ -498,7 +530,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         case SCHRO_DECODER_OK:
             u_pnum = schro_decoder_get_picture_number( p_sys->p_schro );
             p_schroframe = schro_decoder_pull( p_sys->p_schro );
-            p_pic = p_schroframe->priv;
+            p_pic = ((struct picture_free_t*) p_schroframe->priv)->p_pic;
             p_schroframe->priv = NULL;
             schro_frame_unref( p_schroframe );
 
@@ -512,24 +544,27 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 p_pic->date = p_sys->i_lastpts + p_sys->i_frame_pts_delta;
             p_sys->i_lastpts = p_pic->date;
 
+#ifdef TRACE
             msg_Dbg( p_dec, "SCHRO_DECODER_OK num=%u date=%"PRId64,
                      u_pnum, p_pic->date);
-
+#endif
             return p_pic;
 
         case SCHRO_DECODER_EOS:
+#ifdef TRACE
             msg_Dbg( p_dec, "SCHRO_DECODER_EOS");
+#endif
             /* reset the decoder -- schro doesn't do this itself automatically */
             /* there are no more pictures in the output buffer at this point */
             schro_decoder_reset( p_sys->p_schro );
             break;
 
         case SCHRO_DECODER_ERROR:
+#ifdef TRACE
             msg_Dbg( p_dec, "SCHRO_DECODER_ERROR");
+#endif
             return NULL;
         }
     }
-
-    /* Never reached */
-    return NULL;
 }
+