⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subtitle_asa.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
    {        es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','u','b','t' ) );    }    p_sys->es = es_out_Add( p_demux->out, &fmt );    return VLC_SUCCESS;}/***************************************************************************** * ProcessLine: Callback for asa_import, fed one line * (note: return values are not kept. nonzero signals abort to asa_import) *****************************************************************************/static int ProcessLine( demux_t *p_demux, void *p_arg,                         int64_t i_start, int64_t i_stop,                         const char *p_buffer, size_t i_buffer_length ){    demux_sys_t *p_sys = p_demux->p_sys;    subtitle_t *p_subtitle;    char *psz_text;    VLC_UNUSED(p_arg);    if( p_sys->i_subtitles >= p_sys->i_subs_alloc )    {        p_sys->i_subs_alloc += 500;        if( !( p_sys->subtitle = realloc( p_sys->subtitle, sizeof(subtitle_t)                                          * p_sys->i_subs_alloc ) ) )        {            return VLC_ENOMEM;        }    }    p_subtitle = &p_sys->subtitle[p_sys->i_subtitles];    psz_text = malloc( i_buffer_length + 1 );    if( !psz_text )        return VLC_ENOMEM;    memcpy( psz_text, p_buffer, i_buffer_length );    psz_text[i_buffer_length] = '\0';    p_subtitle->i_start = i_start;    p_subtitle->i_stop  = i_stop;    p_subtitle->psz_text = psz_text;    p_sys->i_subtitles++;    return VLC_SUCCESS;}/***************************************************************************** * Close: Close subtitle demux *****************************************************************************/static void Close( vlc_object_t *p_this ){    demux_t *p_demux = (demux_t*)p_this;    demux_sys_t *p_sys = p_demux->p_sys;    int i;    for( i = 0; i < p_sys->i_subtitles; i++ )        free( p_sys->subtitle[i].psz_text );    free( p_sys->subtitle );    free( p_sys );}/***************************************************************************** * Control: *****************************************************************************/static int Control( demux_t *p_demux, int i_query, va_list args ){    demux_sys_t *p_sys = p_demux->p_sys;    int64_t *pi64, i64;    double *pf, f;    switch( i_query )    {        case DEMUX_GET_LENGTH:            pi64 = (int64_t*)va_arg( args, int64_t * );            *pi64 = p_sys->i_length;            return VLC_SUCCESS;        case DEMUX_GET_TIME:            pi64 = (int64_t*)va_arg( args, int64_t * );            if( p_sys->i_subtitle < p_sys->i_subtitles )            {                *pi64 = p_sys->subtitle[p_sys->i_subtitle].i_start;                return VLC_SUCCESS;            }            return VLC_EGENERIC;        case DEMUX_SET_TIME:            i64 = (int64_t)va_arg( args, int64_t );            p_sys->i_subtitle = 0;            while( p_sys->i_subtitle < p_sys->i_subtitles &&                   p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )            {                p_sys->i_subtitle++;            }            if( p_sys->i_subtitle >= p_sys->i_subtitles )                return VLC_EGENERIC;            return VLC_SUCCESS;        case DEMUX_GET_POSITION:            pf = (double*)va_arg( args, double * );            if( p_sys->i_subtitle >= p_sys->i_subtitles )            {                *pf = 1.0;            }            else if( p_sys->i_subtitles > 0 )            {                *pf = (double)p_sys->subtitle[p_sys->i_subtitle].i_start /                      (double)p_sys->i_length;            }            else            {                *pf = 0.0;            }            return VLC_SUCCESS;        case DEMUX_SET_POSITION:            f = (double)va_arg( args, double );            i64 = f * p_sys->i_length;            p_sys->i_subtitle = 0;            while( p_sys->i_subtitle < p_sys->i_subtitles &&                   p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )            {                p_sys->i_subtitle++;            }            if( p_sys->i_subtitle >= p_sys->i_subtitles )                return VLC_EGENERIC;            return VLC_SUCCESS;        case DEMUX_SET_NEXT_DEMUX_TIME:            p_sys->i_next_demux_date = (int64_t)va_arg( args, int64_t );            return VLC_SUCCESS;        case DEMUX_GET_FPS:        case DEMUX_GET_META:        case DEMUX_GET_ATTACHMENTS:        case DEMUX_GET_TITLE_INFO:            return VLC_EGENERIC;        default:            msg_Err( p_demux, "unknown query in subtitle control" );            return VLC_EGENERIC;    }}/***************************************************************************** * Demux: Send subtitle to decoder *****************************************************************************/static int Demux( demux_t *p_demux ){    demux_sys_t *p_sys = p_demux->p_sys;    int64_t i_maxdate;    if( p_sys->i_subtitle >= p_sys->i_subtitles )        return 0;    i_maxdate = p_sys->i_next_demux_date - var_GetTime( p_demux->p_parent, "spu-delay" );;    if( i_maxdate <= 0 && p_sys->i_subtitle < p_sys->i_subtitles )    {        /* Should not happen */        i_maxdate = p_sys->subtitle[p_sys->i_subtitle].i_start + 1;    }    while( p_sys->i_subtitle < p_sys->i_subtitles &&           p_sys->subtitle[p_sys->i_subtitle].i_start < i_maxdate )    {        block_t *p_block;        int i_len = strlen( p_sys->subtitle[p_sys->i_subtitle].psz_text ) + 1;        if( i_len <= 1 )        {            /* empty subtitle */            p_sys->i_subtitle++;            continue;        }        if( ( p_block = block_New( p_demux, i_len ) ) == NULL )        {            p_sys->i_subtitle++;            continue;        }        if( p_sys->subtitle[p_sys->i_subtitle].i_start < 0 )        {            p_sys->i_subtitle++;            continue;        }        p_block->i_pts = p_sys->subtitle[p_sys->i_subtitle].i_start;        p_block->i_dts = p_block->i_pts;        if( p_sys->subtitle[p_sys->i_subtitle].i_stop > 0 )        {            p_block->i_length =                p_sys->subtitle[p_sys->i_subtitle].i_stop - p_block->i_pts;        }        memcpy( p_block->p_buffer,                p_sys->subtitle[p_sys->i_subtitle].psz_text, i_len );        if( p_block->i_pts > 0 )        {            es_out_Send( p_demux->out, p_sys->es, p_block );        }        else        {            block_Release( p_block );        }        p_sys->i_subtitle++;    }    /* */    p_sys->i_next_demux_date = 0;    return 1;}/***************************************************************************** * Fix: fix time stamp and order of subtitle *****************************************************************************/static void Fix( demux_t *p_demux ){    demux_sys_t *p_sys = p_demux->p_sys;    bool b_done;    int     i_index;    /* *** fix order (to be sure...) *** */    /* We suppose that there are near in order and this durty bubble sort     * wont take too much time     */    do    {        b_done = true;        for( i_index = 1; i_index < p_sys->i_subtitles; i_index++ )        {            if( p_sys->subtitle[i_index].i_start <                    p_sys->subtitle[i_index - 1].i_start )            {                subtitle_t sub_xch;                memcpy( &sub_xch,                        p_sys->subtitle + i_index - 1,                        sizeof( subtitle_t ) );                memcpy( p_sys->subtitle + i_index - 1,                        p_sys->subtitle + i_index,                        sizeof( subtitle_t ) );                memcpy( p_sys->subtitle + i_index,                        &sub_xch,                        sizeof( subtitle_t ) );                b_done = false;            }        }    } while( !b_done );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -