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

📄 voc.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * voc.c : Creative Voice File (.VOC) demux module for vlc ***************************************************************************** * Copyright (C) 2005 Rémi Denis-Courmont * $Id: voc.c 16434 2006-08-30 15:18:13Z hartman $ * * Authors: Rémi Denis-Courmont <rem # videolan.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h>                                      /* malloc(), free() */#include <vlc/vlc.h>#include <vlc/input.h>#include <vlc/aout.h>#include <codecs.h>/***************************************************************************** * Module descriptor *****************************************************************************/static int  Open ( vlc_object_t * );static void Close( vlc_object_t * );vlc_module_begin();    set_description( _("VOC demuxer") );    set_category( CAT_INPUT );    set_subcategory( SUBCAT_INPUT_DEMUX );    set_capability( "demux2", 10 );    set_callbacks( Open, Close );vlc_module_end();/***************************************************************************** * Local prototypes *****************************************************************************/static int Demux  ( demux_t * );static int Control( demux_t *, int i_query, va_list args );struct demux_sys_t{    es_format_t     fmt;    es_out_id_t     *p_es;    int64_t         i_block_start;    int64_t         i_block_end;    int64_t         i_loop_offset;    unsigned        i_loop_count;    unsigned        i_silence_countdown;    date_t          pts;};static const char ct_header[] = "Creative Voice File\x1a";/***************************************************************************** * Open: check file and initializes structures *****************************************************************************/static int Open( vlc_object_t * p_this ){    demux_t     *p_demux = (demux_t*)p_this;    demux_sys_t *p_sys;    uint8_t     *p_buf;    uint16_t    i_data_offset, i_version;    if( stream_Peek( p_demux->s, &p_buf, 26 ) < 26 )        return VLC_EGENERIC;    if( memcmp( p_buf, ct_header, 20 ) )        return VLC_EGENERIC;    p_buf += 20;    i_data_offset = GetWLE( p_buf );    if ( i_data_offset < 26 /* not enough room for full VOC header */ )        return VLC_EGENERIC;    p_buf += 2;    i_version = GetWLE( p_buf );    if( ( i_version != 0x10A ) && ( i_version != 0x114 ) )        return VLC_EGENERIC; /* unknown VOC version */    p_buf += 2;    if( GetWLE( p_buf ) != (uint16_t)(0x1234 + ~i_version) )        return VLC_EGENERIC;    /* We have a valid VOC header */    msg_Dbg( p_demux, "CT Voice file v%d.%d", i_version >> 8,             i_version & 0xff );    /* skip VOC header */    if( stream_Read( p_demux->s, NULL, i_data_offset ) < i_data_offset )        return VLC_EGENERIC;    p_demux->pf_demux   = Demux;    p_demux->pf_control = Control;    p_demux->p_sys      = p_sys = malloc( sizeof( demux_sys_t ) );    if( p_sys == NULL )        return VLC_ENOMEM;    p_sys->i_silence_countdown = p_sys->i_block_start = p_sys->i_block_end =    p_sys->i_loop_count = 0;    p_sys->p_es = NULL;    date_Init( &p_sys->pts, 1, 1 );    date_Set( &p_sys->pts, 1 );    es_format_Init( &p_sys->fmt, AUDIO_ES, 0 );    return VLC_SUCCESS;}static int fmtcmp( es_format_t *ofmt, es_format_t *nfmt ){    return (ofmt->audio.i_bitspersample != nfmt->audio.i_bitspersample)        || (ofmt->audio.i_rate != nfmt->audio.i_rate)        || (ofmt->audio.i_channels != nfmt->audio.i_channels);}/* * Converts old-style VOC sample rates to commonly used ones * so as not to confuse sound card drivers. * (I assume 16k, 24k and 32k are never found in .VOC files) */static unsigned int fix_voc_sr( unsigned int sr ){    switch( sr )    {        /*case 8000:            return 8000;*/        case 11111:            return 11025;        case 22222:            return 22050;        case 44444:            return 44100;    }    return sr;}static int ReadBlockHeader( demux_t *p_demux ){    es_format_t     new_fmt;    uint8_t buf[8];    int32_t i_block_size;    demux_sys_t *p_sys = p_demux->p_sys;    if( stream_Read( p_demux->s, buf, 4 ) < 4 )        return VLC_EGENERIC; /* EOF */    i_block_size = GetDWLE( buf ) >> 8;    msg_Dbg( p_demux, "new block: type: %u, size: %u",             (unsigned)*buf, i_block_size );    es_format_Init( &new_fmt, AUDIO_ES, 0 );    switch( *buf )    {        case 0: /* not possible : caught with earlier stream_Read */            goto corrupt;        case 1:            if( i_block_size < 2 )                goto corrupt;            i_block_size -= 2;            if( stream_Read( p_demux->s, buf, 2 ) < 2 )                goto corrupt;            if( buf[1] )            {                msg_Err( p_demux, "unsupported compression" );                return VLC_EGENERIC;            }            new_fmt.i_codec = VLC_FOURCC('u','8',' ',' ');            new_fmt.audio.i_rate = fix_voc_sr( 1000000L / (256L - buf[0]) );            new_fmt.audio.i_bytes_per_frame = 1;            new_fmt.audio.i_frame_length = 1;            new_fmt.audio.i_channels = 1;            new_fmt.audio.i_blockalign = 1;            new_fmt.audio.i_bitspersample = 8;            new_fmt.i_bitrate = new_fmt.audio.i_rate * 8;            break;        case 2: /* data block with same format as the previous one */            if( p_sys->p_es == NULL )                goto corrupt; /* no previous block! */            memcpy( &new_fmt, &p_sys->fmt, sizeof( new_fmt ) );            break;        case 3: /* silence block */            if( ( i_block_size != 3 )             || ( stream_Read( p_demux->s, buf, 3 ) < 3 ) )                goto corrupt;            i_block_size = 0;            p_sys->i_silence_countdown = GetWLE( buf );            new_fmt.i_codec = VLC_FOURCC('u','8',' ',' ');            new_fmt.audio.i_rate = fix_voc_sr( 1000000L / (256L - buf[0]) );            new_fmt.audio.i_bytes_per_frame = 1;            new_fmt.audio.i_frame_length = 1;            new_fmt.audio.i_channels = 1;            new_fmt.audio.i_blockalign = 1;            new_fmt.audio.i_bitspersample = 8;            new_fmt.i_bitrate = new_fmt.audio.i_rate * 8;            break;        case 6: /* repeat block */            if( ( i_block_size != 2 )             || ( stream_Read( p_demux->s, buf, 2 ) < 2 ) )                goto corrupt;            i_block_size = 0;            p_sys->i_loop_count = GetWLE( buf );            p_sys->i_loop_offset = stream_Tell( p_demux->s );            break;        case 7: /* repeat end block */            if( i_block_size != 0 )                goto corrupt;            if( p_sys->i_loop_count > 0 )            {                if( stream_Seek( p_demux->s, p_sys->i_loop_offset ) )                    msg_Warn( p_demux, "cannot loop: seek failed" );

⌨️ 快捷键说明

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