]> git.sesse.net Git - vlc/blobdiff - modules/codec/csri.c
Fix memleak in lua module.
[vlc] / modules / codec / csri.c
index 963e7d86475dfb20df99cf7e9879932dcc5ad079..8e43d178fb4ace1685225c7d217673df422ce340 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
+
+#ifdef HAVE_CONFIG_H
+#   include "config.h"
+#endif
+
 #include <string.h>
+#include <math.h>
 
-#include "config.h"
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_vout.h>
 #include <vlc_codec.h>
 #include <vlc_osd.h>
-#include <vlc_block.h>
-#include <vlc_filter.h>
-#include <vlc_stream.h>
-#include <vlc_xml.h>
-
-#include <math.h>
-
-#ifdef HAVE_ERRNO_H
-#   include <errno.h>
-#endif
+#include <vlc_input.h>
 
 #include <csri/csri.h>
 #include <csri/stream.h>
@@ -67,9 +62,9 @@ vlc_module_end();
  *****************************************************************************/
 static subpicture_t *DecodeBlock( decoder_t *, block_t ** );
 static void DestroySubpicture( subpicture_t * );
-static void PreRender( video_format_t *, spu_t *, subpicture_t *, mtime_t );
-static subpicture_region_t *UpdateRegions( video_format_t *, spu_t *,
-                                           subpicture_t *, mtime_t );
+static void PreRender( video_format_t *, spu_t *, subpicture_t * );
+static void UpdateRegions( video_format_t *, spu_t *,
+                           subpicture_t *, mtime_t );
 
 /*****************************************************************************
  * decoder_sys_t: decoder data
@@ -170,6 +165,8 @@ static subpicture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         return NULL;
 
     p_block = *pp_block;
+    if( p_block->i_rate != 0 )
+        p_block->i_length = p_block->i_length * p_block->i_rate / INPUT_RATE_DEFAULT;
     *pp_block = NULL;
 
     if( p_block->i_buffer == 0 || p_block->p_buffer[0] == '\0' )
@@ -238,14 +235,14 @@ static void DestroySubpicture( subpicture_t *p_subpic )
 }
 
 static void PreRender( video_format_t *p_fmt, spu_t *p_spu,
-                       subpicture_t *p_subpic, mtime_t ts )
+                       subpicture_t *p_subpic )
 {
     decoder_t *p_dec = p_subpic->p_sys->p_dec;
     p_dec->p_sys->p_spu_final = p_subpic;
 }
 
-static subpicture_region_t *UpdateRegions( video_format_t *p_fmt, spu_t *p_spu,
-                                           subpicture_t *p_subpic, mtime_t ts )
+static void UpdateRegions( video_format_t *p_fmt, spu_t *p_spu,
+                           subpicture_t *p_subpic, mtime_t ts )
 {
     decoder_t *p_dec = p_subpic->p_sys->p_dec;
     decoder_sys_t *p_sys = p_dec->p_sys;
@@ -253,8 +250,18 @@ static subpicture_region_t *UpdateRegions( video_format_t *p_fmt, spu_t *p_spu,
     subpicture_region_t *p_spu_region;
     video_format_t fmt;
 
+    /* TODO maybe checking if we really need redrawing */
+    while( p_subpic->p_region )
+    {
+        subpicture_region_t *p_region = p_subpic->p_region;
+        p_subpic->p_region = p_region->p_next;
+        spu_DestroyRegion( p_spu, p_region );
+    }
+    p_subpic->p_region = NULL;
+
+    /* FIXME check why this is needed */
     if( p_subpic != p_sys->p_spu_final )
-        return NULL;
+        return;
 
 #if 0
     msg_Warn( p_dec, "---- fmt: %dx%d %dx%d chroma=%4.4s",
@@ -262,7 +269,8 @@ static subpicture_region_t *UpdateRegions( video_format_t *p_fmt, spu_t *p_spu,
             p_fmt->i_visible_width, p_fmt->i_visible_height,
             (const char*)&p_fmt->i_chroma );
 #endif
-
+    /* XXX On x86 at least our RGBA is mapped to their BGRA
+     * TODO confirm that is the same on big endian cpu */
     fmt = *p_fmt;
     fmt.i_chroma = VLC_FOURCC('R','G','B','A');
     fmt.i_width = fmt.i_visible_width;
@@ -278,7 +286,7 @@ static subpicture_region_t *UpdateRegions( video_format_t *p_fmt, spu_t *p_spu,
 
         struct csri_fmt csri_fmt;
         memset(&csri_fmt, 0, sizeof(csri_fmt));
-        csri_fmt.pixfmt = CSRI_F_RGBA;
+        csri_fmt.pixfmt = CSRI_F_BGRA;
         csri_fmt.width = fmt.i_width;
         csri_fmt.height = fmt.i_height;
         if( csri_request_fmt( p_sys->p_instance, &csri_fmt ) )
@@ -290,7 +298,7 @@ static subpicture_region_t *UpdateRegions( video_format_t *p_fmt, spu_t *p_spu,
     p_subpic->i_original_picture_height = fmt.i_height;
     p_subpic->i_original_picture_width = fmt.i_width;
 
-    p_spu_region = p_subpic->pf_create_region( VLC_OBJECT(p_dec), &fmt );
+    p_spu_region = p_subpic->p_region = p_subpic->pf_create_region( VLC_OBJECT(p_dec), &fmt );
 
     if( p_spu_region )
     {
@@ -303,11 +311,10 @@ static subpicture_region_t *UpdateRegions( video_format_t *p_fmt, spu_t *p_spu,
         /* */
         //msg_Dbg( p_dec, "TS %lf", ts * 0.000001 );
         memset( &csri_frame, 0, sizeof(csri_frame) );
-        csri_frame.pixfmt = CSRI_F_RGBA;
+        csri_frame.pixfmt = CSRI_F_BGRA;
         csri_frame.planes[0] = (unsigned char*)p_spu_region->picture.Y_PIXELS;
         csri_frame.strides[0] = p_spu_region->picture.Y_PITCH;
         csri_render( p_sys->p_instance, &csri_frame, ts * 0.000001 );
     }
-    return p_spu_region;
 }