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

📄 quicktime.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 3 页
字号:
    msg_Dbg( p_dec, "FreeLibrary ok." );#else    ExitMovies();#endif#if 0    /* Segfault */#ifdef LOADER    Restore_LDT_Keeper( p_sys->ldt_fs );    msg_Dbg( p_dec, "Restore_LDT_Keeper" );#endif#endif    vlc_mutex_unlock( lock );    free( p_sys );}/***************************************************************************** * OpenAudio: *****************************************************************************/static int OpenAudio( decoder_t *p_dec ){    decoder_sys_t *p_sys;    int             i_error;    char            fcc[4];    unsigned long   WantedBufferSize;    unsigned long   InputBufferSize = 0;    unsigned long   OutputBufferSize = 0;    /* get lock, avoid segfault */    vlc_mutex_t    *lock = var_AcquireMutex( "qt_mutex" );    if( lock == NULL )        return VLC_EGENERIC;    p_sys = calloc( sizeof( decoder_sys_t ), 1 );    p_dec->p_sys = p_sys;    p_dec->pf_decode_audio = DecodeAudio;    memcpy( fcc, &p_dec->fmt_in.i_codec, 4 );#ifdef __APPLE__    EnterMovies();#endif    if( QTAudioInit( p_dec ) )    {        msg_Err( p_dec, "cannot initialize QT");        goto exit_error;    }#ifndef __APPLE__    if( ( i_error = p_sys->InitializeQTML( 6 + 16 ) ) )    {        msg_Dbg( p_dec, "error on InitializeQTML = %d", i_error );        goto exit_error;    }#endif    /* input format settings */    p_sys->InputFormatInfo.flags       = 0;    p_sys->InputFormatInfo.sampleCount = 0;    p_sys->InputFormatInfo.buffer      = NULL;    p_sys->InputFormatInfo.reserved    = 0;    p_sys->InputFormatInfo.numChannels = p_dec->fmt_in.audio.i_channels;    p_sys->InputFormatInfo.sampleSize  = p_dec->fmt_in.audio.i_bitspersample;    p_sys->InputFormatInfo.sampleRate  = p_dec->fmt_in.audio.i_rate;    p_sys->InputFormatInfo.format      = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );    /* output format settings */    p_sys->OutputFormatInfo.flags       = 0;    p_sys->OutputFormatInfo.sampleCount = 0;    p_sys->OutputFormatInfo.buffer      = NULL;    p_sys->OutputFormatInfo.reserved    = 0;    p_sys->OutputFormatInfo.numChannels = p_dec->fmt_in.audio.i_channels;    p_sys->OutputFormatInfo.sampleSize  = 16;    p_sys->OutputFormatInfo.sampleRate  = p_dec->fmt_in.audio.i_rate;    p_sys->OutputFormatInfo.format      = FCC( 'N', 'O', 'N', 'E' );    i_error = p_sys->SoundConverterOpen( &p_sys->InputFormatInfo,                                         &p_sys->OutputFormatInfo,                                         &p_sys->myConverter );    if( i_error )    {        msg_Err( p_dec, "error on SoundConverterOpen = %d", i_error );        goto exit_error;    }#if 0    /* tell the sound converter we accept VBR formats */    i_error = SoundConverterSetInfo( p_dec->myConverter, siClientAcceptsVBR,                                     (void *)true );#endif    if( p_dec->fmt_in.i_extra > 36 + 8 )    {        i_error = p_sys->SoundConverterSetInfo( p_sys->myConverter,                                                FCC( 'w', 'a', 'v', 'e' ),                                                ((uint8_t*)p_dec->fmt_in.p_extra) + 36 + 8 );        msg_Dbg( p_dec, "error on SoundConverterSetInfo = %d", i_error );    }    WantedBufferSize = p_sys->OutputFormatInfo.numChannels *                       p_sys->OutputFormatInfo.sampleRate * 2;    p_sys->FramesToGet = 0;    i_error = p_sys->SoundConverterGetBufferSizes( p_sys->myConverter,                                                   WantedBufferSize,                                                   &p_sys->FramesToGet,                                                   &InputBufferSize,                                                   &OutputBufferSize );    msg_Dbg( p_dec, "WantedBufferSize=%li InputBufferSize=%li "             "OutputBufferSize=%li FramesToGet=%li",             WantedBufferSize, InputBufferSize, OutputBufferSize,             p_sys->FramesToGet );    p_sys->InFrameSize  = (InputBufferSize + p_sys->FramesToGet - 1 ) /                            p_sys->FramesToGet;    p_sys->OutFrameSize = OutputBufferSize / p_sys->FramesToGet;    msg_Dbg( p_dec, "frame size %d -> %d",             p_sys->InFrameSize, p_sys->OutFrameSize );    if( (i_error = p_sys->SoundConverterBeginConversion(p_sys->myConverter)) )    {        msg_Err( p_dec,                 "error on SoundConverterBeginConversion = %d", i_error );        goto exit_error;    }    es_format_Init( &p_dec->fmt_out, AUDIO_ES, AOUT_FMT_S16_NE );    p_dec->fmt_out.audio.i_rate = p_sys->OutputFormatInfo.sampleRate;    p_dec->fmt_out.audio.i_channels = p_sys->OutputFormatInfo.numChannels;    p_dec->fmt_out.audio.i_physical_channels =    p_dec->fmt_out.audio.i_original_channels =        pi_channels_maps[p_sys->OutputFormatInfo.numChannels];    aout_DateInit( &p_sys->date, p_dec->fmt_out.audio.i_rate );    p_sys->i_buffer      = 0;    p_sys->i_buffer_size = 100*1000;    p_sys->p_buffer      = malloc( p_sys->i_buffer_size );    if( !p_sys->p_buffer )        goto exit_error;    p_sys->i_out = 0;    p_sys->i_out_frames = 0;    vlc_mutex_unlock( lock );    return VLC_SUCCESS;exit_error:#ifdef LOADER    Restore_LDT_Keeper( p_sys->ldt_fs );#endif    vlc_mutex_unlock( lock );    free( p_sys );    return VLC_EGENERIC;}/***************************************************************************** * DecodeAudio: *****************************************************************************/static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block ){    decoder_sys_t *p_sys = p_dec->p_sys;    block_t     *p_block;    int         i_error;#ifdef LOADER    /* We must do open and close in the same thread (unless we do     * Setup_LDT_Keeper in the main thread before all others */    if( p_sys == NULL )    {        if( OpenAudio( p_dec ) )        {            /* Fatal */            p_dec->b_error = true;            return NULL;        }        p_sys = p_dec->p_sys;    }#endif    if( pp_block == NULL || *pp_block == NULL )    {        return NULL;    }    p_block = *pp_block;    if( p_sys->i_out_frames > 0 && p_sys->i_out >= p_sys->i_out_frames )    {        /* Ask new data */        p_sys->i_out = 0;        p_sys->i_out_frames = 0;        *pp_block = NULL;        return NULL;    }    if( p_sys->i_out_frames <= 0 )    {        p_sys->pts = p_block->i_pts;        if( decoder_GetDisplayDate( p_dec, p_block->i_pts ) < mdate() )        {            block_Release( p_block );            *pp_block = NULL;            return NULL;        }        /* Append data */        if( p_sys->i_buffer_size < p_sys->i_buffer + p_block->i_buffer )        {            p_sys->i_buffer_size = p_sys->i_buffer + p_block->i_buffer + 1024;            p_sys->p_buffer = realloc( p_sys->p_buffer, p_sys->i_buffer_size );        }        memcpy( &p_sys->p_buffer[p_sys->i_buffer], p_block->p_buffer,                p_block->i_buffer );        p_sys->i_buffer += p_block->i_buffer;        if( p_sys->i_buffer > p_sys->InFrameSize )        {            int i_frames = p_sys->i_buffer / p_sys->InFrameSize;            unsigned long i_out_frames, i_out_bytes;            vlc_mutex_t *lock = var_AcquireMutex( "qt_mutex ");            i_error = p_sys->SoundConverterConvertBuffer( p_sys->myConverter,                                                          p_sys->p_buffer,                                                          i_frames,                                                          p_sys->out_buffer,                                                          &i_out_frames,                                                          &i_out_bytes );            vlc_mutex_unlock( lock );            /*            msg_Dbg( p_dec, "decoded %d frames -> %ld frames (error=%d)",                     i_frames, i_out_frames, i_error );            msg_Dbg( p_dec, "decoded %ld frames = %ld bytes",                     i_out_frames, i_out_bytes );            */            p_sys->i_buffer -= i_frames * p_sys->InFrameSize;            if( p_sys->i_buffer > 0 )            {                memmove( &p_sys->p_buffer[0],                         &p_sys->p_buffer[i_frames * p_sys->InFrameSize],                         p_sys->i_buffer );            }            if( p_sys->pts != 0 &&                p_sys->pts != aout_DateGet( &p_sys->date ) )            {                aout_DateSet( &p_sys->date, p_sys->pts );            }            else if( !aout_DateGet( &p_sys->date ) )            {                return NULL;            }            if( !i_error && i_out_frames > 0 )            {                /* we have others samples */                p_sys->i_out_frames = i_out_frames;                p_sys->i_out = 0;            }        }    }    if( p_sys->i_out < p_sys->i_out_frames )    {        aout_buffer_t *p_out;        int  i_frames = __MIN( p_sys->i_out_frames - p_sys->i_out, 1000 );        p_out = p_dec->pf_aout_buffer_new( p_dec, i_frames );        if( p_out )        {            p_out->start_date = aout_DateGet( &p_sys->date );            p_out->end_date = aout_DateIncrement( &p_sys->date, i_frames );            memcpy( p_out->p_buffer,                    &p_sys->out_buffer[2 * p_sys->i_out * p_dec->fmt_out.audio.i_channels],                    p_out->i_nb_bytes );            p_sys->i_out += i_frames;        }        return p_out;    }    return NULL;}/***************************************************************************** * OpenVideo: *****************************************************************************/static int OpenVideo( decoder_t *p_dec ){    decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );    if( !p_sys )        return VLC_ENOMEM;#ifndef WIN32    vlc_mutex_t                        *lock;    long                                i_result;    ComponentDescription                desc;    Component                           prev;    ComponentResult                     cres;    ImageSubCodecDecompressCapabilities icap;   /* for ImageCodecInitialize() */    CodecInfo                           cinfo;  /* for ImageCodecGetCodecInfo() */    ImageDescription                    *id;    char                fcc[4];    int     i_vide = p_dec->fmt_in.i_extra;    uint8_t *p_vide = p_dec->fmt_in.p_extra;    p_dec->p_sys = p_sys;    p_dec->pf_decode_video = DecodeVideo;    p_sys->i_late = 0;    if( i_vide <= 0 )    {        msg_Err( p_dec, "missing extra info" );        free( p_sys );        return VLC_EGENERIC;    }    memcpy( fcc, &p_dec->fmt_in.i_codec, 4 );    msg_Dbg( p_dec, "quicktime_video %4.4s %dx%d",             fcc, p_dec->fmt_in.video.i_width, p_dec->fmt_in.video.i_height );    /* get lock, avoid segfault */    lock = var_AcquireMutex( "qt_mutex" );#ifdef __APPLE__    EnterMovies();#endif    if( QTVideoInit( p_dec ) )    {        msg_Err( p_dec, "cannot initialize QT");        goto exit_error;    }#ifndef __APPLE__    if( ( i_result = p_sys->InitializeQTML( 6 + 16 ) ) )    {        msg_Dbg( p_dec, "error on InitializeQTML = %d", (int)i_result );        goto exit_error;    }#endif    /* init ComponentDescription */    memset( &desc, 0, sizeof( ComponentDescription ) );    desc.componentType      = FCC( 'i', 'm', 'd', 'c' );

⌨️ 快捷键说明

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