]> git.sesse.net Git - vlc/blob - modules/codec/spudec/text.c
* ALL: i18n updates and fixes.
[vlc] / modules / codec / spudec / text.c
1 /*****************************************************************************
2  * text.c: text subtitles parser
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: text.c,v 1.4 2003/01/30 16:36:04 gbazin Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>                                    /* memcpy(), memset() */
29
30 #include <vlc/vlc.h>
31 #include <vlc/vout.h>
32 #include <vlc/decoder.h>
33
34 #include "spudec.h"
35
36 /*****************************************************************************
37  * Local prototypes.
38  *****************************************************************************/
39
40 /*****************************************************************************
41  * ParseText: parse an text subtitle packet and send it to the video output
42  *****************************************************************************/
43 void E_(ParseText)( spudec_thread_t *p_spudec, subtitler_font_t *p_font )
44 {
45     char         * psz_subtitle;
46     mtime_t        i_pts, i_dts;
47
48     /* We cannot display a subpicture with no date */
49     i_pts = p_spudec->bit_stream.p_pes->i_pts;
50     i_dts = p_spudec->bit_stream.p_pes->i_dts;
51     if( i_pts == 0 )
52     {
53         /* Dump the packet */
54         NextDataPacket( p_spudec->p_fifo, &p_spudec->bit_stream );
55         msg_Warn( p_spudec->p_fifo, "subtitle without a date" );
56         return;
57     }
58
59     /* Check validity of packet data */
60     if( (p_spudec->bit_stream.p_data->p_payload_end
61           - p_spudec->bit_stream.p_data->p_payload_start) <= 0
62         || (strlen(p_spudec->bit_stream.p_data->p_payload_start)
63             > (size_t)(p_spudec->bit_stream.p_data->p_payload_end
64                         - p_spudec->bit_stream.p_data->p_payload_start)) )
65     {
66         /* Dump the packet */
67         NextDataPacket( p_spudec->p_fifo, &p_spudec->bit_stream );
68         msg_Warn( p_spudec->p_fifo, "invalid subtitle" );
69         return;
70     }
71     psz_subtitle = p_spudec->bit_stream.p_data->p_payload_start;
72
73     if( psz_subtitle[0] != '\0' )
74     {
75         subtitler_PlotSubtitle( p_spudec->p_vout,
76                                 psz_subtitle, p_font,
77                                 i_pts,
78                                 i_dts );
79     }
80
81     /* Prepare for next time. No need to check that
82      * p_spudec->bit_stream->p_data is valid since we check later on
83      * for b_die and b_error */
84     NextDataPacket( p_spudec->p_fifo, &p_spudec->bit_stream );
85 }