]> git.sesse.net Git - vlc/commitdiff
* ./modules/codec/spudec/parse.c: fixed bad initialization of the alpha
authorSam Hocevar <sam@videolan.org>
Thu, 17 Oct 2002 08:24:12 +0000 (08:24 +0000)
committerSam Hocevar <sam@videolan.org>
Thu, 17 Oct 2002 08:24:12 +0000 (08:24 +0000)
    palette, implemented the "force display" command as forever-living
    subtitles, and reworked some code.
  * ./src/video_output/video_output.c: we increment the image date even if
    we are repeating the previous image, so that subtitles have a chance to
    get displayed.
  * ./src/video_output/vout_subpictures.c: ephemer subpictures don't timeout.

modules/codec/spudec/parse.c
src/video_output/video_output.c
src/video_output/vout_subpictures.c

index 0401ad8fcd35d5c7669a9e0023435c200b3d95cd..0b6c2320aba00834793764b13edcd078591cba02 100644 (file)
@@ -2,7 +2,7 @@
  * parse.c: SPU parser
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: parse.c,v 1.1 2002/08/16 03:07:56 sam Exp $
+ * $Id: parse.c,v 1.2 2002/10/17 08:24:12 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -84,12 +84,12 @@ int E_(SyncPacket)( spudec_thread_t *p_spudec )
     if( !p_spudec->i_spu_size
          || ( p_spudec->i_rle_size >= p_spudec->i_spu_size ) )
     {
-        return( 1 );
+        return VLC_EGENERIC;
     }
 
     RemoveBits( &p_spudec->bit_stream, 16 );
 
-    return( 0 );
+    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
@@ -131,7 +131,12 @@ void E_(ParsePacket)( spudec_thread_t *p_spudec )
     /* Fill the p_spu structure */
     p_spu->pf_render = E_(RenderSPU);
     p_spu->p_sys->p_data = (u8*)p_spu->p_sys + sizeof( subpicture_sys_t );
-    p_spu->p_sys->b_palette = 0;
+    p_spu->p_sys->b_palette = VLC_FALSE;
+
+    p_spu->p_sys->pi_alpha[0] = 0x00;
+    p_spu->p_sys->pi_alpha[1] = 0x0f;
+    p_spu->p_sys->pi_alpha[2] = 0x0f;
+    p_spu->p_sys->pi_alpha[3] = 0x0f;
 
     /* Get display time now. If we do it later, we may miss the PTS. */
     p_spu->p_sys->i_pts = p_spudec->p_fifo->p_first->i_pts;
@@ -214,189 +219,164 @@ static int ParseControlSequences( spudec_thread_t *p_spudec,
     int i_index = p_spudec->i_rle_size + 4;
 
     /* The next start-of-control-sequence index and the previous one */
-    int i_next_seq, i_cur_seq;
+    int i_next_seq = 0, i_cur_seq = 0;
 
-    /* Command time and date */
-    u8  i_command;
-    int i_date;
+    /* Command and date */
+    u8 i_command = SPU_CMD_END;
+    mtime_t date = 0;
 
     int i, pi_alpha[4];
 
-    /* XXX: temporary variables */
-    vlc_bool_t b_force_display = 0;
-
     /* Initialize the structure */
     p_spu->i_start = p_spu->i_stop = 0;
-    p_spu->b_ephemer = 0;
+    p_spu->b_ephemer = VLC_FALSE;
 
     do
     {
-        /* Get the control sequence date */
-        i_date = GetBits( &p_spudec->bit_stream, 16 );
-        /* Next offset */
-        i_cur_seq = i_index;
-        i_next_seq = GetBits( &p_spudec->bit_stream, 16 );
-        /* Skip what we just read */
-        i_index += 4;
-        do
+        /* If we just read a command sequence, read the next one;
+         * otherwise, go on with the commands of the current sequence. */
+        if( i_command == SPU_CMD_END )
         {
-            i_command = GetBits( &p_spudec->bit_stream, 8 );
-            i_index++;
-            switch( i_command )
-            {
-                case SPU_CMD_FORCE_DISPLAY:
-
-                    /* 00 (force displaying) */
-                    p_spu->i_start = p_spu->p_sys->i_pts + ( i_date * 11000 );
-                    b_force_display = 1;
-                    break;
-                /* Convert the dates in seconds to PTS values */
-                case SPU_CMD_START_DISPLAY:
+            /* Get the control sequence date */
+            date = GetBits( &p_spudec->bit_stream, 16 );
  
-                    /* 01 (start displaying) */
-                    p_spu->i_start = p_spu->p_sys->i_pts + ( i_date * 11000 );
+            /* Next offset */
+            i_cur_seq = i_index;
+            i_next_seq = GetBits( &p_spudec->bit_stream, 16 );
  
-                    break;
-                case SPU_CMD_STOP_DISPLAY:
-                    /* 02 (stop displaying) */
-                    p_spu->i_stop = p_spu->p_sys->i_pts + ( i_date * 11000 );
-                    break;
+            /* Skip what we just read */
+            i_index += 4;
+        }
  
-                case SPU_CMD_SET_PALETTE:
+        i_command = GetBits( &p_spudec->bit_stream, 8 );
+        i_index++;
  
-                    /* 03xxxx (palette) */
-                    if( p_spudec->p_fifo->p_demux_data &&
-                         *(int*)p_spudec->p_fifo->p_demux_data == 0xBeeF )
-                    {
-                        u32 i_color;
+        switch( i_command )
+        {
+        case SPU_CMD_FORCE_DISPLAY: /* 00 (force displaying) */
+            p_spu->i_start = p_spu->p_sys->i_pts + ( date * 11000 );
+            p_spu->b_ephemer = VLC_TRUE;
+            break;
 
-                        p_spu->p_sys->b_palette = 1;
-                        for( i = 0; i < 4 ; i++ )
-                        {
-                            i_color = ((u32*)((char*)p_spudec->p_fifo->
-                                        p_demux_data + sizeof(int)))[
-                                          GetBits(&p_spudec->bit_stream, 4) ];
+        /* Convert the dates in seconds to PTS values */
+        case SPU_CMD_START_DISPLAY: /* 01 (start displaying) */
+            p_spu->i_start = p_spu->p_sys->i_pts + ( date * 11000 );
+            break;
+
+        case SPU_CMD_STOP_DISPLAY: /* 02 (stop displaying) */
+            p_spu->i_stop = p_spu->p_sys->i_pts + ( date * 11000 );
+            break;
 
-                            /* FIXME: this job should be done sooner */
+        case SPU_CMD_SET_PALETTE:
+
+            /* 03xxxx (palette) */
+            if( p_spudec->p_fifo->p_demux_data
+                 && *(int*)p_spudec->p_fifo->p_demux_data == 0xBeeF )
+            {
+                u32 i_color;
+
+                p_spu->p_sys->b_palette = VLC_TRUE;
+                for( i = 0; i < 4 ; i++ )
+                {
+                    i_color = ((u32*)((char*)p_spudec->p_fifo->
+                                p_demux_data + sizeof(int)))[
+                                  GetBits(&p_spudec->bit_stream, 4) ];
+
+                    /* FIXME: this job should be done sooner */
 #ifndef WORDS_BIGENDIAN
-                            p_spu->p_sys->pi_yuv[3-i][0] = (i_color>>16) & 0xff;
-                            p_spu->p_sys->pi_yuv[3-i][1] = (i_color>>0) & 0xff;
-                            p_spu->p_sys->pi_yuv[3-i][2] = (i_color>>8) & 0xff;
+                    p_spu->p_sys->pi_yuv[3-i][0] = (i_color>>16) & 0xff;
+                    p_spu->p_sys->pi_yuv[3-i][1] = (i_color>>0) & 0xff;
+                    p_spu->p_sys->pi_yuv[3-i][2] = (i_color>>8) & 0xff;
 #else
-                            p_spu->p_sys->pi_yuv[3-i][0] = (i_color>>8) & 0xff;
-                            p_spu->p_sys->pi_yuv[3-i][1] = (i_color>>24) & 0xff;
-                            p_spu->p_sys->pi_yuv[3-i][2] = (i_color>>16) & 0xff;
+                    p_spu->p_sys->pi_yuv[3-i][0] = (i_color>>8) & 0xff;
+                    p_spu->p_sys->pi_yuv[3-i][1] = (i_color>>24) & 0xff;
+                    p_spu->p_sys->pi_yuv[3-i][2] = (i_color>>16) & 0xff;
 #endif
-                        }
-                    }
-                    else
-                    {
-                        RemoveBits( &p_spudec->bit_stream, 16 );
-                    }
-                    i_index += 2;
-                    break;
-                case SPU_CMD_SET_ALPHACHANNEL:
-                    /* 04xxxx (alpha channel) */
-                    pi_alpha[3] = GetBits( &p_spudec->bit_stream, 4 );
-                    pi_alpha[2] = GetBits( &p_spudec->bit_stream, 4 );
-                    pi_alpha[1] = GetBits( &p_spudec->bit_stream, 4 );
-                    pi_alpha[0] = GetBits( &p_spudec->bit_stream, 4 );
-
-                    /* Ignore blank alpha palette. Sometimes spurious blank
-                     * alpha palettes are present - dunno why. */
-                    if( pi_alpha[0] | pi_alpha[1] | pi_alpha[2] | pi_alpha[3] )
-                    {
-                        p_spu->p_sys->pi_alpha[0] = pi_alpha[0];
-                        p_spu->p_sys->pi_alpha[1] = pi_alpha[1];
-                        p_spu->p_sys->pi_alpha[2] = pi_alpha[2];
-                        p_spu->p_sys->pi_alpha[3] = pi_alpha[3];
-                    }
-                    else
-                    {
-                        msg_Warn( p_spudec->p_fifo,
-                                  "ignoring blank alpha palette" );
-                    }
-
-                    i_index += 2;
-                    break;
-                case SPU_CMD_SET_COORDINATES:
-                    /* 05xxxyyyxxxyyy (coordinates) */
-                    p_spu->i_x = GetBits( &p_spudec->bit_stream, 12 );
-                    p_spu->i_width = GetBits( &p_spudec->bit_stream, 12 )
-                                      - p_spu->i_x + 1;
-                    p_spu->i_y = GetBits( &p_spudec->bit_stream, 12 );
-                    p_spu->i_height = GetBits( &p_spudec->bit_stream, 12 )
-                                       - p_spu->i_y + 1;
-                    i_index += 6;
-                    break;
-                case SPU_CMD_SET_OFFSETS:
-                    /* 06xxxxyyyy (byte offsets) */
-                    p_spu->p_sys->pi_offset[0] =
-                        GetBits( &p_spudec->bit_stream, 16 ) - 4;
-                    p_spu->p_sys->pi_offset[1] =
-                        GetBits( &p_spudec->bit_stream, 16 ) - 4;
-                    i_index += 4;
-                    break;
-                case SPU_CMD_END:
-                    /* ff (end) */
-                    break;
-                default:
-                    /* xx (unknown command) */
-                    msg_Err( p_spudec->p_fifo, "unknown command 0x%.2x",
-                                               i_command );
-                    return( 1 );
+                }
+            }
+            else
+            {
+                RemoveBits( &p_spudec->bit_stream, 16 );
             }
+            i_index += 2;
+
+            break;
 
-            /* We need to check for quit commands here */
-            if( p_spudec->p_fifo->b_die )
+        case SPU_CMD_SET_ALPHACHANNEL: /* 04xxxx (alpha channel) */
+            pi_alpha[3] = GetBits( &p_spudec->bit_stream, 4 );
+            pi_alpha[2] = GetBits( &p_spudec->bit_stream, 4 );
+            pi_alpha[1] = GetBits( &p_spudec->bit_stream, 4 );
+            pi_alpha[0] = GetBits( &p_spudec->bit_stream, 4 );
+
+            /* Ignore blank alpha palette. Sometimes spurious blank
+             * alpha palettes are present - dunno why. */
+            if( pi_alpha[0] | pi_alpha[1] | pi_alpha[2] | pi_alpha[3] )
             {
-                return( 1 );
+                p_spu->p_sys->pi_alpha[0] = pi_alpha[0];
+                p_spu->p_sys->pi_alpha[1] = pi_alpha[1];
+                p_spu->p_sys->pi_alpha[2] = pi_alpha[2];
+                p_spu->p_sys->pi_alpha[3] = pi_alpha[3];
+            }
+            else
+            {
+                msg_Warn( p_spudec->p_fifo, "ignoring blank alpha palette" );
             }
 
-        } while( i_command != SPU_CMD_END );
+            i_index += 2;
+            break;
 
-    } while( i_index == i_next_seq );
+        case SPU_CMD_SET_COORDINATES: /* 05xxxyyyxxxyyy (coordinates) */
+            p_spu->i_x = GetBits( &p_spudec->bit_stream, 12 );
+            p_spu->i_width = GetBits( &p_spudec->bit_stream, 12 )
+                              - p_spu->i_x + 1;
+
+            p_spu->i_y = GetBits( &p_spudec->bit_stream, 12 );
+            p_spu->i_height = GetBits( &p_spudec->bit_stream, 12 )
+                               - p_spu->i_y + 1;
+
+            i_index += 6;
+            break;
+
+        case SPU_CMD_SET_OFFSETS: /* 06xxxxyyyy (byte offsets) */
+            p_spu->p_sys->pi_offset[0] =
+                GetBits( &p_spudec->bit_stream, 16 ) - 4;
+
+            p_spu->p_sys->pi_offset[1] =
+                GetBits( &p_spudec->bit_stream, 16 ) - 4;
+
+            i_index += 4;
+            break;
+
+        case SPU_CMD_END: /* ff (end) */
+            break;
+
+        default: /* xx (unknown command) */
+            msg_Err( p_spudec->p_fifo, "unknown command 0x%.2x",
+                                       i_command );
+            return VLC_EGENERIC;
+        }
+
+        /* We need to check for quit commands here */
+        if( p_spudec->p_fifo->b_die )
+        {
+            return VLC_EGENERIC;
+        }
+
+    } while( i_command != SPU_CMD_END || i_index == i_next_seq );
 
     /* Check that the next sequence index matches the current one */
     if( i_next_seq != i_cur_seq )
     {
         msg_Err( p_spudec->p_fifo, "index mismatch (0x%.4x != 0x%.4x)",
                                    i_next_seq, i_cur_seq );
-        return( 1 );
+        return VLC_EGENERIC;
     }
 
     if( i_index > p_spudec->i_spu_size )
     {
         msg_Err( p_spudec->p_fifo, "uh-oh, we went too far (0x%.4x > 0x%.4x)",
                                    i_index, p_spudec->i_spu_size );
-        return( 1 );
+        return VLC_EGENERIC;
     }
 
     if( !p_spu->i_start )
@@ -404,11 +384,11 @@ static int ParseControlSequences( spudec_thread_t *p_spudec,
         msg_Err( p_spudec->p_fifo, "no `start display' command" );
     }
 
-    if( !p_spu->i_stop )
+    if( !p_spu->i_stop && !p_spu->b_ephemer )
     {
         /* This subtitle will live for 5 seconds or until the next subtitle */
         p_spu->i_stop = p_spu->i_start + 500 * 11000;
-        p_spu->b_ephemer = 1;
+        p_spu->b_ephemer = VLC_TRUE;
     }
 
     /* Get rid of padding bytes */
@@ -437,15 +417,8 @@ static int ParseControlSequences( spudec_thread_t *p_spudec,
             break;
     }
 
-    if( b_force_display )
-    {
-        msg_Err( p_spudec->p_fifo, "\"force display\" command" );
-        msg_Err( p_spudec->p_fifo, "send mail to <sam@zoy.org> if you "
-                                   "want to help debugging this" );
-    }
-
     /* Successfully parsed ! */
-    return( 0 );
+    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
@@ -471,8 +444,8 @@ static int ParseRLE( spudec_thread_t *p_spudec,
     unsigned int  pi_table[ 2 ];
     unsigned int *pi_offset;
 
-    vlc_bool_t b_empty_top = 1,
-               b_empty_bottom = 0;
+    vlc_bool_t b_empty_top = VLC_TRUE,
+               b_empty_bottom = VLC_FALSE;
     unsigned int i_skipped_top = 0,
                  i_skipped_bottom = 0;
 
@@ -516,7 +489,7 @@ static int ParseRLE( spudec_thread_t *p_spudec,
                                 /* We have a boo boo ! */
                                 msg_Err( p_spudec->p_fifo, "unknown RLE code "
                                          "0x%.4x", i_code );
-                                return( 1 );
+                                return VLC_EGENERIC;
                             }
                         }
                     }
@@ -528,7 +501,7 @@ static int ParseRLE( spudec_thread_t *p_spudec,
                 msg_Err( p_spudec->p_fifo,
                          "out of bounds, %i at (%i,%i) is out of %ix%i",
                          i_code >> 2, i_x, i_y, i_width, i_height );
-                return( 1 );
+                return VLC_EGENERIC;
             }
 
             /* Try to find the border color */
@@ -552,7 +525,7 @@ static int ParseRLE( spudec_thread_t *p_spudec,
                      * so we store the code just in case. */
                     *p_dest++ = i_code;
 
-                    b_empty_bottom = 1;
+                    b_empty_bottom = VLC_TRUE;
                     i_skipped_bottom++;
                 }
             }
@@ -562,8 +535,8 @@ static int ParseRLE( spudec_thread_t *p_spudec,
                 *p_dest++ = i_code;
 
                 /* Valid code means no blank line */
-                b_empty_top = 0;
-                b_empty_bottom = 0;
+                b_empty_top = VLC_FALSE;
+                b_empty_bottom = VLC_FALSE;
                 i_skipped_bottom = 0;
             }
         }
@@ -573,7 +546,7 @@ static int ParseRLE( spudec_thread_t *p_spudec,
         {
             msg_Err( p_spudec->p_fifo, "i_x overflowed, %i > %i",
                                        i_x, i_width );
-            return( 1 );
+            return VLC_EGENERIC;
         }
 
         /* Byte-align the stream */
@@ -600,7 +573,7 @@ static int ParseRLE( spudec_thread_t *p_spudec,
             i_y++;
         }
 
-        return( 1 );
+        return VLC_EGENERIC;
     }
 
     msg_Dbg( p_spudec->p_fifo, "valid subtitle, size: %ix%i, position: %i,%i",
@@ -673,6 +646,6 @@ static int ParseRLE( spudec_thread_t *p_spudec,
                  i_border, i_inner, i_shade );
     }
 
-    return( 0 );
+    return VLC_SUCCESS;
 }
 
index f2fb320576478b288524e9391672843dee0ed9c0..ad727c3b6f5eb715b27c4f5a55f491c82fba1270 100644 (file)
@@ -5,7 +5,7 @@
  * thread, and destroy a previously oppened video output thread.
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: video_output.c,v 1.191 2002/08/29 23:53:22 massiot Exp $
+ * $Id: video_output.c,v 1.192 2002/10/17 08:24:12 sam Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *
@@ -29,8 +29,6 @@
  *****************************************************************************/
 #include <errno.h>                                                 /* ENOMEM */
 #include <stdlib.h>                                                /* free() */
-#include <stdio.h>                                              /* sprintf() */
-#include <string.h>                                            /* strerror() */
 
 #include <vlc/vlc.h>
 
@@ -78,7 +76,7 @@ vout_thread_t * __vout_CreateThread ( vlc_object_t *p_parent,
     if( p_vout == NULL )
     {
         msg_Err( p_parent, "out of memory" );
-        return( NULL );
+        return NULL;
     }
 
     /* If the parent is not a VOUT object, that means we are at the start of
@@ -192,7 +190,7 @@ vout_thread_t * __vout_CreateThread ( vlc_object_t *p_parent,
     {
         msg_Err( p_vout, "no suitable vout module" );
         vlc_object_destroy( p_vout );
-        return( NULL );
+        return NULL;
     }
 
     /* Create thread and set locks */
@@ -205,7 +203,7 @@ vout_thread_t * __vout_CreateThread ( vlc_object_t *p_parent,
     if( vlc_thread_create( p_vout, "video output", RunThread,
                            VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
     {
-        msg_Err( p_vout, "%s", strerror(ENOMEM) );
+        msg_Err( p_vout, "out of memory" );
         module_Unneed( p_vout, p_vout->p_module );
         vlc_object_destroy( p_vout );
         return NULL;
@@ -253,7 +251,7 @@ static int InitThread( vout_thread_t *p_vout )
     if( p_vout->pf_init( p_vout ) )
     {
         vlc_mutex_unlock( &p_vout->change_lock );
-        return( 1 );
+        return VLC_EGENERIC;
     }
 
     if( !I_OUTPUTPICTURES )
@@ -262,7 +260,7 @@ static int InitThread( vout_thread_t *p_vout )
                          "one direct buffer" );
         p_vout->pf_end( p_vout );
         vlc_mutex_unlock( &p_vout->change_lock );
-        return( 1 );
+        return VLC_EGENERIC;
     }
 
     msg_Dbg( p_vout, "got %i direct buffer(s)", I_OUTPUTPICTURES );
@@ -328,7 +326,7 @@ static int InitThread( vout_thread_t *p_vout )
                      &p_vout->render.i_chroma, &p_vout->output.i_chroma );
             p_vout->pf_end( p_vout );
             vlc_mutex_unlock( &p_vout->change_lock );
-            return( 1 );
+            return VLC_EGENERIC;
         }
 
         if( I_OUTPUTPICTURES < 2 * VOUT_MAX_PICTURES )
@@ -366,7 +364,7 @@ static int InitThread( vout_thread_t *p_vout )
     }
 
 /* XXX XXX mark thread ready */
-    return( 0 );
+    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
@@ -407,6 +405,7 @@ static void RunThread( vout_thread_t *p_vout)
     while( (!p_vout->b_die) && (!p_vout->b_error) )
     {
         /* Initialize loop variables */
+        p_picture = NULL;
         display_date = 0;
         current_date = mdate();
 
@@ -420,11 +419,9 @@ static void RunThread( vout_thread_t *p_vout)
 #endif
 
         /*
-         * Find the picture to display - this operation does not need lock,
-         * since only READY_PICTUREs are handled
-         */
-        p_picture = NULL;
-
+         * Find the picture to display (the one with the earliest date).
+         * This operation does not need lock, since only READY_PICTUREs
+         * are handled. */
         for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
         {
             if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
@@ -436,7 +433,7 @@ static void RunThread( vout_thread_t *p_vout)
             }
         }
 
-        if( p_picture != NULL )
+        if( p_picture )
         {
             /* If we met the last picture, parse again to see whether there is
              * a more appropriate one. */
@@ -546,7 +543,9 @@ static void RunThread( vout_thread_t *p_vout)
                 }
                 else
                 {
-                    /*intf_WarnMsg( 6, "vout info: duplicating picture" );*/
+                    /* We set the display date to something high, otherwise
+                     * we'll have lots of problems with late pictures */
+                    display_date = current_date + p_vout->render_time;
                 }
             }
         }
@@ -580,7 +579,7 @@ static void RunThread( vout_thread_t *p_vout)
          */
         if( display_date != 0 )
         {
-            /* Store render time using Bresenham algorithm */
+            /* Store render time using a sliding mean */
             p_vout->render_time += mdate() - current_date;
             p_vout->render_time >>= 1;
         }
@@ -659,7 +658,6 @@ static void RunThread( vout_thread_t *p_vout)
             p_vout->chroma.p_module->pf_deactivate( VLC_OBJECT(p_vout) );
             p_vout->chroma.p_module->pf_activate( VLC_OBJECT(p_vout) );
         }
-
     }
 
     /*
@@ -816,7 +814,7 @@ static int BinaryLog(u32 i)
     if( i & 0xcccccccc ) i_log += 2;
     if( i & 0xaaaaaaaa ) i_log += 1;
 
-    return( i_log );
+    return i_log;
 }
 
 /*****************************************************************************
index 45e76bc9c7ce555abcc27156a2c952052ea6d505..d7affb8dfce55cf47d85877fd96b1598c8eacfd3 100644 (file)
@@ -2,7 +2,7 @@
  * vout_subpictures.c : subpicture management functions
  *****************************************************************************
  * Copyright (C) 2000 VideoLAN
- * $Id: vout_subpictures.c,v 1.14 2002/06/01 12:32:02 sam Exp $
+ * $Id: vout_subpictures.c,v 1.15 2002/10/17 08:24:12 sam Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -104,7 +104,7 @@ subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
                  * to be done */
                 p_vout->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
                 vlc_mutex_unlock( &p_vout->subpicture_lock );
-                return( &p_vout->p_subpicture[i_subpic] );
+                return &p_vout->p_subpicture[i_subpic];
             }
             else if( p_destroyed_subpic == NULL )
             {
@@ -135,7 +135,7 @@ subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
     {
         msg_Err( p_vout, "subpicture heap is full" );
         vlc_mutex_unlock( &p_vout->subpicture_lock );
-        return( NULL );
+        return NULL;
     }
 
     p_free_subpic->p_sys =
@@ -163,7 +163,7 @@ subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
 
     vlc_mutex_unlock( &p_vout->subpicture_lock );
 
-    return( p_free_subpic );
+    return p_free_subpic;
 }
 
 /*****************************************************************************
@@ -230,7 +230,8 @@ subpicture_t *vout_SortSubPictures( vout_thread_t *p_vout,
             /* If it is a DVD subpicture, check its date */
             if( p_vout->p_subpicture[i_index].i_type == MEMORY_SUBPICTURE )
             {
-                if( display_date > p_vout->p_subpicture[i_index].i_stop )
+                if( !p_vout->p_subpicture[i_index].b_ephemer
+                     && display_date > p_vout->p_subpicture[i_index].i_stop )
                 {
                     /* Too late, destroy the subpic */
                     vout_DestroySubPicture( p_vout,
@@ -238,7 +239,8 @@ subpicture_t *vout_SortSubPictures( vout_thread_t *p_vout,
                     continue;
                 }
 
-                if( display_date < p_vout->p_subpicture[i_index].i_start )
+                if( display_date
+                     && display_date < p_vout->p_subpicture[i_index].i_start )
                 {
                     /* Too early, come back next monday */
                     continue;