* 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>
*
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;
}
/*****************************************************************************
/* 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;
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 )
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 */
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;
}
/*****************************************************************************
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;
/* We have a boo boo ! */
msg_Err( p_spudec->p_fifo, "unknown RLE code "
"0x%.4x", i_code );
- return( 1 );
+ return VLC_EGENERIC;
}
}
}
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 */
* so we store the code just in case. */
*p_dest++ = i_code;
- b_empty_bottom = 1;
+ b_empty_bottom = VLC_TRUE;
i_skipped_bottom++;
}
}
*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;
}
}
{
msg_Err( p_spudec->p_fifo, "i_x overflowed, %i > %i",
i_x, i_width );
- return( 1 );
+ return VLC_EGENERIC;
}
/* Byte-align the stream */
i_y++;
}
- return( 1 );
+ return VLC_EGENERIC;
}
msg_Dbg( p_spudec->p_fifo, "valid subtitle, size: %ix%i, position: %i,%i",
i_border, i_inner, i_shade );
}
- return( 0 );
+ return VLC_SUCCESS;
}
* 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>
*
*****************************************************************************/
#include <errno.h> /* ENOMEM */
#include <stdlib.h> /* free() */
-#include <stdio.h> /* sprintf() */
-#include <string.h> /* strerror() */
#include <vlc/vlc.h>
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
{
msg_Err( p_vout, "no suitable vout module" );
vlc_object_destroy( p_vout );
- return( NULL );
+ return NULL;
}
/* Create thread and set locks */
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;
if( p_vout->pf_init( p_vout ) )
{
vlc_mutex_unlock( &p_vout->change_lock );
- return( 1 );
+ return VLC_EGENERIC;
}
if( !I_OUTPUTPICTURES )
"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 );
&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 )
}
/* XXX XXX mark thread ready */
- return( 0 );
+ return VLC_SUCCESS;
}
/*****************************************************************************
while( (!p_vout->b_die) && (!p_vout->b_error) )
{
/* Initialize loop variables */
+ p_picture = NULL;
display_date = 0;
current_date = mdate();
#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)
}
}
- if( p_picture != NULL )
+ if( p_picture )
{
/* If we met the last picture, parse again to see whether there is
* a more appropriate one. */
}
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;
}
}
}
*/
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;
}
p_vout->chroma.p_module->pf_deactivate( VLC_OBJECT(p_vout) );
p_vout->chroma.p_module->pf_activate( VLC_OBJECT(p_vout) );
}
-
}
/*
if( i & 0xcccccccc ) i_log += 2;
if( i & 0xaaaaaaaa ) i_log += 1;
- return( i_log );
+ return i_log;
}
/*****************************************************************************