Show
Ignore:
Timestamp:
16/05/08 00:10:27 (5 months ago)
Author:
Jean-Baptiste Kempf <jb@videolan.org>
git-committer:
Jean-Baptiste Kempf <jb@videolan.org> 1210889427 -0700
git-parent:

[82abb3013a56507f3431eab49480d53376e5965f]

git-author:
Jean-Baptiste Kempf <jb@videolan.org> 1210889001 -0700
Message:

Support for RealText? Subtitles.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/demux/subtitle.c

    r99c7892 r39aae2a  
    109109    SUB_TYPE_MPSUB, 
    110110    SUB_TYPE_JACOSUB, 
    111     SUB_TYPE_PSB 
     111    SUB_TYPE_PSB, 
     112    SUB_TYPE_RT 
    112113}; 
    113114 
     
    161162static int  ParseJSS        ( demux_t *, subtitle_t *, int ); 
    162163static int  ParsePSB        ( demux_t *, subtitle_t *, int ); 
     164static int  ParseRealText   ( demux_t *, subtitle_t *, int ); 
    163165 
    164166static struct 
     
    185187    { "jacosub",    SUB_TYPE_JACOSUB,     "JacoSub",     ParseJSS }, 
    186188    { "psb",        SUB_TYPE_PSB,         "PowerDivx",   ParsePSB }, 
     189    { "realtext",   SUB_TYPE_RT,          "RealText",    ParseRealText }, 
    187190    { NULL,         SUB_TYPE_UNKNOWN,     "Unknown",     NULL } 
    188191}; 
     
    190193/* Missing Detect 
    191194    SubViewer 1 
    192     JSS 
    193     RealText 
    194195    Subrip09 
    195196   */ 
     
    375376                p_sys->i_type = SUB_TYPE_PSB; 
    376377            } 
     378            else if( strcasestr( s, "<time" ) ) 
     379            { 
     380                p_sys->i_type = SUB_TYPE_RT; 
     381            } 
    377382 
    378383            free( s ); 
     
    389394        } 
    390395    } 
     396 
     397    /* Quit on unknown subtitles */ 
    391398    if( p_sys->i_type == SUB_TYPE_UNKNOWN ) 
    392399    { 
     
    17421749} 
    17431750 
    1744  
     1751static int64_t ParseRealTime( char *psz, int *h, int *m, int *s, int *f ) 
     1752
     1753    if( strlen( psz ) == 0 ) return 0; 
     1754    if( sscanf( psz, "%d:%d:%d.%d", h, m, s, f ) == 4 || 
     1755            sscanf( psz, "%d:%d.%d", m, s, f ) == 3 || 
     1756            sscanf( psz, "%d.%d", s, f ) == 2 || 
     1757            sscanf( psz, "%d:%d", m, s ) == 2 || 
     1758            sscanf( psz, "%d", s ) == 1 ) 
     1759    { 
     1760        return (int64_t)((( *h * 60 + *m ) * 60 ) + *s ) * 1000 * 1000 
     1761               + (int64_t)*f * 10 * 1000; 
     1762    } 
     1763    else return VLC_EGENERIC; 
     1764
     1765 
     1766static int ParseRealText( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) 
     1767
     1768    VLC_UNUSED( i_idx ); 
     1769    demux_sys_t *p_sys = p_demux->p_sys; 
     1770    text_t      *txt = &p_sys->txt; 
     1771    char *psz_text; 
     1772    char psz_end[12]= "", psz_begin[12] = ""; 
     1773 
     1774    for( ;; ) 
     1775    { 
     1776        int h1 = 0, m1 = 0, s1 = 0, f1 = 0; 
     1777        int h2 = 0, m2 = 0, s2 = 0, f2 = 0; 
     1778        const char *s = TextGetLine( txt ); 
     1779 
     1780        if( !s ) 
     1781            return VLC_EGENERIC; 
     1782 
     1783        psz_text = malloc( strlen( s ) + 1 ); 
     1784        if( !psz_text ) 
     1785            return VLC_ENOMEM; 
     1786 
     1787        /* Find the good begining. This removes extra spaces at the beginning 
     1788           of the line.*/ 
     1789        char *psz_temp = strcasestr( s, "<time"); 
     1790        if( psz_temp != NULL ) 
     1791        { 
     1792            /* Line has begin and end */ 
     1793            if( ( sscanf( psz_temp, 
     1794                            "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\" %*[e|E]nd=\"%[^\"]%*[^>]%[^\n\r]", 
     1795                            psz_begin, psz_end, psz_text) != 3 ) && 
     1796                    /* Line has begin and no end */ 
     1797                    ( sscanf( psz_temp, 
     1798                              "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\"%*[^>]%[^\n\r]", 
     1799                              psz_begin, psz_text ) != 2) ) 
     1800                /* Line is not recognized */ 
     1801            { 
     1802                free( psz_text ); 
     1803                continue; 
     1804            } 
     1805 
     1806 
     1807            /* Get the times */ 
     1808            int64_t i_time = ParseRealTime( psz_begin, &h1, &m1, &s1, &f1 ); 
     1809            if( i_time >= 0) 
     1810            { 
     1811                p_subtitle->i_start = i_time; 
     1812            } 
     1813 
     1814            i_time = ParseRealTime( psz_end, &h2, &m2, &s2, &f2 ); 
     1815            if( i_time >= 0 ) 
     1816            { 
     1817                p_subtitle->i_stop = i_time; 
     1818            } 
     1819            break; 
     1820        } 
     1821        /* Line is not recognized */ 
     1822        else continue; 
     1823        free( psz_text ); 
     1824    } 
     1825 
     1826    /* Get the following Lines */ 
     1827    for( ;; ) 
     1828    { 
     1829        const char *s = TextGetLine( txt ); 
     1830 
     1831        if( !s ) 
     1832            return VLC_EGENERIC; 
     1833 
     1834        int i_len = strlen( s ); 
     1835        if( i_len == 0 ) break; 
     1836 
     1837        if( strcasestr( s, "<time" ) || 
     1838            strcasestr( s, "<clear/") ) 
     1839        { 
     1840            txt->i_line--; 
     1841            break; 
     1842        } 
     1843 
     1844        int i_old = strlen( psz_text ); 
     1845 
     1846        psz_text = realloc( psz_text, i_old + i_len + 1 + 1 ); 
     1847        if( !psz_text ) 
     1848            return VLC_ENOMEM; 
     1849 
     1850        strcat( psz_text, s ); 
     1851        strcat( psz_text, "\n" ); 
     1852    } 
     1853 
     1854    /* Remove the starting ">" that remained after the sscanf */ 
     1855    memmove( &psz_text[0], &psz_text[1], strlen( psz_text ) ); 
     1856 
     1857    p_subtitle->psz_text = psz_text; 
     1858 
     1859    return VLC_SUCCESS; 
     1860
     1861