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

📄 realaudio.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        /* Old format */        asprintf( &psz_dll, "%s\\%4.4s3260.dll", ppsz_path[i],                  (char *)&p_dec->fmt_in.i_codec );        i_result = OpenWin32Dll( p_dec, ppsz_path[i], psz_dll );        free( psz_dll );        if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;    }    return VLC_EGENERIC;}static int OpenNativeDll( decoder_t *p_dec, char *psz_path, char *psz_dll ){#if defined(HAVE_DL_DLOPEN)    decoder_sys_t *p_sys = p_dec->p_sys;    void *handle = 0, *context = 0;    unsigned int i_result;    void *p_prop;    int i_prop;    ra_init_t init_data =    {        p_dec->fmt_in.audio.i_rate,        p_dec->fmt_in.audio.i_bitspersample,        p_dec->fmt_in.audio.i_channels,        100, /* quality */        p_dec->fmt_in.audio.i_blockalign, /* subpacket size */        p_dec->fmt_in.audio.i_blockalign, /* coded frame size */        p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra    };    msg_Dbg( p_dec, "opening library '%s'", psz_dll );    if( !(handle = dlopen( psz_dll, RTLD_LAZY )) )    {        msg_Dbg( p_dec, "couldn't load library '%s' (%s)",                 psz_dll, dlerror() );        return VLC_EGENERIC;    }    p_sys->raCloseCodec = dlsym( handle, "RACloseCodec" );    p_sys->raDecode = dlsym( handle, "RADecode" );    p_sys->raFlush = dlsym( handle, "RAFlush" );    p_sys->raFreeDecoder = dlsym( handle, "RAFreeDecoder" );    p_sys->raGetFlavorProperty = dlsym( handle, "RAGetFlavorProperty" );    p_sys->raOpenCodec = dlsym( handle, "RAOpenCodec" );    p_sys->raOpenCodec2 = dlsym( handle, "RAOpenCodec2" );    p_sys->raInitDecoder = dlsym( handle, "RAInitDecoder" );    p_sys->raSetFlavor = dlsym( handle, "RASetFlavor" );    p_sys->raSetDLLAccessPath = dlsym( handle, "SetDLLAccessPath" );    p_sys->raSetPwd = dlsym( handle, "RASetPwd" ); // optional, used by SIPR    if( !(p_sys->raOpenCodec || p_sys->raOpenCodec2) ||        !p_sys->raCloseCodec || !p_sys->raInitDecoder ||        !p_sys->raDecode || !p_sys->raFreeDecoder ||        !p_sys->raGetFlavorProperty || !p_sys->raSetFlavor        /* || !p_sys->raFlush || !p_sys->raSetDLLAccessPath */ )    {        goto error_native;    }    if( p_sys->raOpenCodec2 )        i_result = p_sys->raOpenCodec2( &context, psz_path );    else        i_result = p_sys->raOpenCodec( &context );    if( i_result )    {        msg_Err( p_dec, "decoder open failed, error code: 0x%x", i_result );        goto error_native;    }    i_result = p_sys->raInitDecoder( context, &init_data );    if( i_result )    {        msg_Err( p_dec, "decoder init failed, error code: 0x%x", i_result );        goto error_native;    }    if( p_sys->i_codec_flavor >= 0 )    {        i_result = p_sys->raSetFlavor( context, p_sys->i_codec_flavor );        if( i_result )        {            msg_Err( p_dec, "decoder flavor setup failed, error code: 0x%x",                     i_result );            goto error_native;        }        p_prop = p_sys->raGetFlavorProperty( context, p_sys->i_codec_flavor,                                             0, &i_prop );        msg_Dbg( p_dec, "audio codec: [%d] %s",                 p_sys->i_codec_flavor, (char *)p_prop );        p_prop = p_sys->raGetFlavorProperty( context, p_sys->i_codec_flavor,                                             1, &i_prop );        if( p_prop )        {            int i_bps = ((*((int*)p_prop))+4)/8;            msg_Dbg( p_dec, "audio bitrate: %5.3f kbit/s (%d bps)",                     (*((int*)p_prop))*0.001f, i_bps );        }    }    p_sys->context = context;    p_sys->dll = handle;    return VLC_SUCCESS; error_native:    if( context ) p_sys->raFreeDecoder( context );    if( context ) p_sys->raCloseCodec( context );    dlclose( handle );#endif    return VLC_EGENERIC;}static int OpenWin32Dll( decoder_t *p_dec, char *psz_path, char *psz_dll ){#if defined(LOADER) || defined(WIN32)    decoder_sys_t *p_sys = p_dec->p_sys;    void *handle = 0, *context = 0;    unsigned int i_result;    void *p_prop;    int i_prop;    wra_init_t init_data =    {        p_dec->fmt_in.audio.i_rate,        p_dec->fmt_in.audio.i_bitspersample,        p_dec->fmt_in.audio.i_channels,        100, /* quality */        p_dec->fmt_in.audio.i_blockalign, /* subpacket size */        p_dec->fmt_in.audio.i_blockalign, /* coded frame size */        p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra    };    msg_Dbg( p_dec, "opening win32 dll '%s'", psz_dll );#ifdef LOADER    Setup_LDT_Keeper();#endif    if( !(handle = LoadLibraryA( psz_dll )) )    {        msg_Dbg( p_dec, "couldn't load dll '%s'", psz_dll );        return VLC_EGENERIC;    }    p_sys->wraCloseCodec = GetProcAddress( handle, "RACloseCodec" );    p_sys->wraDecode = GetProcAddress( handle, "RADecode" );    p_sys->wraFlush = GetProcAddress( handle, "RAFlush" );    p_sys->wraFreeDecoder = GetProcAddress( handle, "RAFreeDecoder" );    p_sys->wraGetFlavorProperty =        GetProcAddress( handle, "RAGetFlavorProperty" );    p_sys->wraOpenCodec = GetProcAddress( handle, "RAOpenCodec" );    p_sys->wraOpenCodec2 = GetProcAddress( handle, "RAOpenCodec2" );    p_sys->wraInitDecoder = GetProcAddress( handle, "RAInitDecoder" );    p_sys->wraSetFlavor = GetProcAddress( handle, "RASetFlavor" );    p_sys->wraSetDLLAccessPath = GetProcAddress( handle, "SetDLLAccessPath" );    p_sys->wraSetPwd =        GetProcAddress( handle, "RASetPwd" ); // optional, used by SIPR    if( !(p_sys->wraOpenCodec || p_sys->wraOpenCodec2) ||        !p_sys->wraCloseCodec || !p_sys->wraInitDecoder ||        !p_sys->wraDecode || !p_sys->wraFreeDecoder ||        !p_sys->wraGetFlavorProperty || !p_sys->wraSetFlavor        /* || !p_sys->wraFlush || !p_sys->wraSetDLLAccessPath */ )    {        FreeLibrary( handle );        return VLC_EGENERIC;    }    if( p_sys->wraOpenCodec2 )        i_result = p_sys->wraOpenCodec2( &context, psz_path );    else        i_result = p_sys->wraOpenCodec( &context );    if( i_result )    {        msg_Err( p_dec, "decoder open failed, error code: 0x%x", i_result );        goto error_win32;    }    i_result = p_sys->wraInitDecoder( context, &init_data );    if( i_result )    {        msg_Err( p_dec, "decoder init failed, error code: 0x%x", i_result );        goto error_win32;    }    if( p_sys->i_codec_flavor >= 0 )    {        i_result = p_sys->wraSetFlavor( context, p_sys->i_codec_flavor );        if( i_result )        {            msg_Err( p_dec, "decoder flavor setup failed, error code: 0x%x",                     i_result );            goto error_win32;        }        p_prop = p_sys->wraGetFlavorProperty( context, p_sys->i_codec_flavor,                                              0, &i_prop );        msg_Dbg( p_dec, "audio codec: [%d] %s",                 p_sys->i_codec_flavor, (char *)p_prop );        p_prop = p_sys->wraGetFlavorProperty( context, p_sys->i_codec_flavor,                                              1, &i_prop );        if( p_prop )        {            int i_bps = ((*((int*)p_prop))+4)/8;            msg_Dbg( p_dec, "audio bitrate: %5.3f kbit/s (%d bps)",                     (*((int*)p_prop))*0.001f, i_bps );        }    }    p_sys->context = context;    p_sys->win32_dll = handle;    return VLC_SUCCESS; error_win32:    if( context ) p_sys->wraFreeDecoder( context );    if( context ) p_sys->wraCloseCodec( context );    FreeLibrary( handle );#endif    return VLC_EGENERIC;}/***************************************************************************** * CloseDll: *****************************************************************************/static void CloseDll( decoder_t *p_dec ){    decoder_sys_t *p_sys = p_dec->p_sys;    if( p_sys->context && p_sys->dll )    {        p_sys->raFreeDecoder( p_sys->context );        p_sys->raCloseCodec( p_sys->context );    }    if( p_sys->context && p_sys->win32_dll )    {        p_sys->wraFreeDecoder( p_sys->context );        p_sys->wraCloseCodec( p_sys->context );    }#if defined(HAVE_DL_DLOPEN)    if( p_sys->dll ) dlclose( p_sys->dll );#endif#if defined(LOADER) || defined(WIN32)    if( p_sys->win32_dll ) FreeLibrary( p_sys->win32_dll );#if 0 //def LOADER /* Segfaults */    Restore_LDT_Keeper( p_sys->ldt_fs );    msg_Dbg( p_dec, "Restore_LDT_Keeper" );#endif#endif    p_sys->dll = 0;    p_sys->win32_dll = 0;    p_sys->context = 0;}/***************************************************************************** * DecodeAudio: *****************************************************************************/static aout_buffer_t *Decode( decoder_t *p_dec, block_t **pp_block ){    decoder_sys_t *p_sys = p_dec->p_sys;    aout_buffer_t *p_aout_buffer = 0;    unsigned int i_result;    int i_samples;    block_t *p_block;#ifdef LOADER    if( !p_sys->win32_dll && !p_sys->dll )    {        /* We must do open and close in the same thread (unless we do         * Setup_LDT_Keeper in the main thread before all others */        if( OpenDll( p_dec ) != VLC_SUCCESS )        {            /* Fatal */            p_dec->b_error = VLC_TRUE;            return NULL;        }    }#endif    if( pp_block == NULL || *pp_block == NULL ) return NULL;    p_block = *pp_block;    if( p_sys->dll )        i_result = p_sys->raDecode( p_sys->context, (char *)p_block->p_buffer,                                    (unsigned long)p_block->i_buffer,                                    p_sys->p_out, &p_sys->i_out, -1 );    else        i_result = p_sys->wraDecode( p_sys->context, (char *)p_block->p_buffer,                                     (unsigned long)p_block->i_buffer,                                     p_sys->p_out, &p_sys->i_out, -1 );#if 0    msg_Err( p_dec, "decoded: %i samples (%i)",             p_sys->i_out * 8 / p_dec->fmt_out.audio.i_bitspersample /             p_dec->fmt_out.audio.i_channels, i_result );#endif    /* Date management */    if( p_block->i_pts > 0 &&        p_block->i_pts != aout_DateGet( &p_sys->end_date ) )    {        aout_DateSet( &p_sys->end_date, p_block->i_pts );    }    if( !aout_DateGet( &p_sys->end_date ) )    {        /* We've just started the stream, wait for the first PTS. */        if( p_block ) block_Release( p_block );        return NULL;    }    i_samples = p_sys->i_out * 8 /        p_dec->fmt_out.audio.i_bitspersample /p_dec->fmt_out.audio.i_channels;    p_aout_buffer =        p_dec->pf_aout_buffer_new( p_dec, i_samples );    if( p_aout_buffer )    {        memcpy( p_aout_buffer->p_buffer, p_sys->p_out, p_sys->i_out );        /* Date management */        p_aout_buffer->start_date = aout_DateGet( &p_sys->end_date );        p_aout_buffer->end_date =            aout_DateIncrement( &p_sys->end_date, i_samples );    }    block_Release( p_block );    *pp_block = 0;    return p_aout_buffer;}

⌨️ 快捷键说明

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