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

📄 dmo.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 4 页
字号:
/***************************************************************************** * dmo.c : DirectMedia Object decoder module for vlc ***************************************************************************** * Copyright (C) 2002, 2003 the VideoLAN team * $Id$ * * Author: Gildas Bazin <gbazin@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 *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_codec.h>#include <vlc_vout.h>#include <vlc_aout.h>#ifndef WIN32#    define LOADER#else#   include <objbase.h>#endif#ifdef LOADER/* Need the w32dll loader from mplayer */#   include <wine/winerror.h>#   include <ldt_keeper.h>#   include <wine/windef.h>#endif#include <vlc_codecs.h>#include "dmo.h"//#define DMO_DEBUG 1#ifdef LOADER/* Not Needed */long CoInitialize( void *pvReserved ) { VLC_UNUSED(pvReserved); return -1; }void CoUninitialize( void ) { }/* A few prototypes */HMODULE WINAPI LoadLibraryA(LPCSTR);#define LoadLibrary LoadLibraryAFARPROC WINAPI GetProcAddress(HMODULE,LPCSTR);int     WINAPI FreeLibrary(HMODULE);#endif /* LOADER */typedef long (STDCALL *GETCLASS) ( const GUID*, const GUID*, void** );static const int pi_channels_maps[7] ={    0,    AOUT_CHAN_CENTER,    AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,    AOUT_CHAN_CENTER | AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,    AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT     | AOUT_CHAN_REARRIGHT,    AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER     | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT,    AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER     | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE};/***************************************************************************** * Module descriptor *****************************************************************************/static int  DecoderOpen  ( vlc_object_t * );static int  DecOpen      ( vlc_object_t * );static void DecoderClose ( vlc_object_t * );static void *DecodeBlock ( decoder_t *, block_t ** );static int  EncoderOpen  ( vlc_object_t * );static int  EncOpen      ( vlc_object_t * );static void EncoderClose ( vlc_object_t * );static block_t *EncodeBlock( encoder_t *, void * );static int LoadDMO( vlc_object_t *, HINSTANCE *, IMediaObject **,                    es_format_t *, bool );static void CopyPicture( decoder_t *, picture_t *, uint8_t * );vlc_module_begin();    set_description( N_("DirectMedia Object decoder") );    add_shortcut( "dmo" );    set_capability( "decoder", 1 );    set_callbacks( DecoderOpen, DecoderClose );    set_category( CAT_INPUT );    set_subcategory( SUBCAT_INPUT_SCODEC );#   define ENC_CFG_PREFIX "sout-dmo-"    add_submodule();    set_description( N_("DirectMedia Object encoder") );    set_capability( "encoder", 10 );    set_callbacks( EncoderOpen, EncoderClose );vlc_module_end();/***************************************************************************** * Local prototypes *****************************************************************************//**************************************************************************** * Decoder descriptor declaration ****************************************************************************/struct decoder_sys_t{    HINSTANCE hmsdmo_dll;    IMediaObject *p_dmo;    int i_min_output;    uint8_t *p_buffer;    date_t end_date;#ifdef LOADER    ldt_fs_t    *ldt_fs;#endif};const GUID IID_IWMCodecPrivateData = {0x73f0be8e, 0x57f7, 0x4f01, {0xaa, 0x66, 0x9f, 0x57, 0x34, 0xc, 0xfe, 0xe}};const GUID IID_IMediaObject = {0xd8ad0f58, 0x5494, 0x4102, {0x97, 0xc5, 0xec, 0x79, 0x8e, 0x59, 0xbc, 0xf4}};const GUID IID_IMediaBuffer = {0x59eff8b9, 0x938c, 0x4a26, {0x82, 0xf2, 0x95, 0xcb, 0x84, 0xcd, 0xc8, 0x37}};const GUID MEDIATYPE_Video = {0x73646976, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};const GUID MEDIATYPE_Audio = {0x73647561, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};const GUID MEDIASUBTYPE_PCM = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};const GUID FORMAT_VideoInfo = {0x05589f80, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}};const GUID FORMAT_WaveFormatEx = {0x05589f81, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}};const GUID GUID_NULL = {0x0000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};const GUID MEDIASUBTYPE_I420 = {0x30323449, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};const GUID MEDIASUBTYPE_YV12 = {0x32315659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};const GUID MEDIASUBTYPE_RGB24 = {0xe436eb7d, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};const GUID MEDIASUBTYPE_RGB565 = {0xe436eb7b, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};static const GUID guid_wvc1 = { 0xc9bfbccf, 0xe60e, 0x4588, { 0xa3, 0xdf, 0x5a, 0x03, 0xb1, 0xfd, 0x95, 0x85 } };static const GUID guid_wmv9 = { 0x724bb6a4, 0xe526, 0x450f, { 0xaf, 0xfa, 0xab, 0x9b, 0x45, 0x12, 0x91, 0x11 } };static const GUID guid_wmv = { 0x82d353df, 0x90bd, 0x4382, { 0x8b, 0xc2, 0x3f, 0x61, 0x92, 0xb7, 0x6e, 0x34 } };static const GUID guid_wms = { 0x7bafb3b1, 0xd8f4, 0x4279, { 0x92, 0x53, 0x27, 0xda, 0x42, 0x31, 0x08, 0xde } };static const GUID guid_wmva ={ 0x03be3ac4, 0x84b7, 0x4e0e, { 0xa7, 0x8d, 0xd3, 0x52, 0x4e, 0x60, 0x39, 0x5a } };static const GUID guid_wma = { 0x874131cb, 0x4ecc, 0x443b, { 0x89, 0x48, 0x74, 0x6b, 0x89, 0x59, 0x5d, 0x20 } };static const GUID guid_wma9 = { 0x27ca0808, 0x01f5, 0x4e7a, { 0x8b, 0x05, 0x87, 0xf8, 0x07, 0xa2, 0x33, 0xd1 } };static const GUID guid_wmv_enc = { 0x3181343b, 0x94a2, 0x4feb, { 0xad, 0xef, 0x30, 0xa1, 0xdd, 0xe6, 0x17, 0xb4 } };static const GUID guid_wmv_enc2 = { 0x96b57cdd, 0x8966, 0x410c,{ 0xbb, 0x1f, 0xc9, 0x7e, 0xea, 0x76, 0x5c, 0x04 } };static const GUID guid_wma_enc = { 0x70f598e9, 0xf4ab, 0x495a, { 0x99, 0xe2, 0xa7, 0xc4, 0xd3, 0xd8, 0x9a, 0xbf } };typedef struct{    vlc_fourcc_t i_fourcc;    const char   *psz_dll;    const GUID   *p_guid;} codec_dll;static const codec_dll decoders_table[] ={    /* WVC1 */    { VLC_FOURCC('W','V','C','1'), "wvc1dmod.dll", &guid_wvc1 },    { VLC_FOURCC('w','v','c','1'), "wvc1dmod.dll", &guid_wvc1 },    /* WMV3 */    { VLC_FOURCC('W','M','V','3'), "wmv9dmod.dll", &guid_wmv9 },    { VLC_FOURCC('w','m','v','3'), "wmv9dmod.dll", &guid_wmv9 },    { VLC_FOURCC('W','M','V','P'), "wmv9dmod.dll", &guid_wmv9 },    { VLC_FOURCC('w','m','v','p'), "wmv9dmod.dll", &guid_wmv9 },    /* WMV2 */    { VLC_FOURCC('W','M','V','2'), "wmvdmod.dll", &guid_wmv },    { VLC_FOURCC('w','m','v','2'), "wmvdmod.dll", &guid_wmv },    /* WMV1 */    { VLC_FOURCC('W','M','V','1'), "wmvdmod.dll", &guid_wmv },    { VLC_FOURCC('w','m','v','1'), "wmvdmod.dll", &guid_wmv },    /* Screen codecs */    { VLC_FOURCC('M','S','S','2'), "wmsdmod.dll", &guid_wms },    { VLC_FOURCC('m','s','s','2'), "wmsdmod.dll", &guid_wms },    { VLC_FOURCC('M','S','S','1'), "wmsdmod.dll", &guid_wms },    { VLC_FOURCC('m','s','s','1'), "wmsdmod.dll", &guid_wms },    /* Windows Media Video Adv */    { VLC_FOURCC('W','M','V','A'), "wmvadvd.dll", &guid_wmva },    { VLC_FOURCC('w','m','v','a'), "wmvadvd.dll", &guid_wmva },    { VLC_FOURCC('W','V','P','2'), "wmvadvd.dll", &guid_wmva },    { VLC_FOURCC('w','v','p','2'), "wmvadvd.dll", &guid_wmva },    /* WMA 3 */    { VLC_FOURCC('W','M','A','3'), "wma9dmod.dll", &guid_wma9 },    { VLC_FOURCC('w','m','a','3'), "wma9dmod.dll", &guid_wma9 },    { VLC_FOURCC('W','M','A','P'), "wma9dmod.dll", &guid_wma9 },    { VLC_FOURCC('w','m','a','p'), "wma9dmod.dll", &guid_wma9 },    /* WMA 2 */    { VLC_FOURCC('W','M','A','2'), "wma9dmod.dll", &guid_wma9 },    { VLC_FOURCC('w','m','a','2'), "wma9dmod.dll", &guid_wma9 },    /* WMA Speech */    { VLC_FOURCC('W','M','A','S'), "wmspdmod.dll", &guid_wma },    { VLC_FOURCC('w','m','a','s'), "wmspdmod.dll", &guid_wma },    /* */    { 0, NULL, NULL }};static const codec_dll encoders_table[] ={    /* WMV3 */    { VLC_FOURCC('W','M','V','3'), "wmvdmoe2.dll", &guid_wmv_enc2 },    { VLC_FOURCC('w','m','v','3'), "wmvdmoe2.dll", &guid_wmv_enc2 },    /* WMV2 */    { VLC_FOURCC('W','M','V','2'), "wmvdmoe2.dll", &guid_wmv_enc2 },    { VLC_FOURCC('w','m','v','2'), "wmvdmoe2.dll", &guid_wmv_enc2 },    /* WMV1 */    { VLC_FOURCC('W','M','V','1'), "wmvdmoe2.dll", &guid_wmv_enc2 },    { VLC_FOURCC('w','m','v','1'), "wmvdmoe2.dll", &guid_wmv_enc2 },    /* WMA 3 */    { VLC_FOURCC('W','M','A','3'), "wmadmoe.dll", &guid_wma_enc },    { VLC_FOURCC('w','m','a','3'), "wmadmoe.dll", &guid_wma_enc },    /* WMA 2 */    { VLC_FOURCC('W','M','A','2'), "wmadmoe.dll", &guid_wma_enc },    { VLC_FOURCC('w','m','a','2'), "wmadmoe.dll", &guid_wma_enc },    /* */    { 0, NULL, NULL }};static void WINAPI DMOFreeMediaType( DMO_MEDIA_TYPE *mt ){    if( mt->cbFormat != 0 ) CoTaskMemFree( (PVOID)mt->pbFormat );    if( mt->pUnk != NULL ) mt->pUnk->vt->Release( (IUnknown *)mt->pUnk );    mt->cbFormat = 0;    mt->pbFormat = NULL;    mt->pUnk = NULL;}/***************************************************************************** * DecoderOpen: open dmo codec *****************************************************************************/static int DecoderOpen( vlc_object_t *p_this ){    decoder_t *p_dec = (decoder_t*)p_this;#ifndef LOADER    int i_ret = DecOpen( p_this );    if( i_ret != VLC_SUCCESS ) return i_ret;#else    /* We can't open it now, because of ldt_keeper or something     * Open/Decode/Close has to be done in the same thread */    int i;    p_dec->p_sys = NULL;    /* Probe if we support it */    for( i = 0; decoders_table[i].i_fourcc != 0; i++ )    {        if( decoders_table[i].i_fourcc == p_dec->fmt_in.i_codec )        {            msg_Dbg( p_dec, "DMO codec for %4.4s may work with dll=%s",                     (char*)&p_dec->fmt_in.i_codec,                     decoders_table[i].psz_dll );            break;        }    }    p_dec->p_sys = NULL;    if( !decoders_table[i].i_fourcc ) return VLC_EGENERIC;#endif /* LOADER */    /* Set callbacks */    p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))        DecodeBlock;    p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))        DecodeBlock;    return VLC_SUCCESS;}/***************************************************************************** * DecOpen: open dmo codec *****************************************************************************/static int DecOpen( vlc_object_t *p_this ){    decoder_t *p_dec = (decoder_t*)p_this;    decoder_sys_t *p_sys = NULL;    DMO_MEDIA_TYPE dmo_input_type, dmo_output_type;    IMediaObject *p_dmo = NULL;    HINSTANCE hmsdmo_dll = NULL;    VIDEOINFOHEADER *p_vih = NULL;    WAVEFORMATEX *p_wf = NULL;#ifdef LOADER    ldt_fs_t *ldt_fs = Setup_LDT_Keeper();#else    /* Initialize OLE/COM */    CoInitialize( 0 );#endif /* LOADER */    if( LoadDMO( p_this, &hmsdmo_dll, &p_dmo, &p_dec->fmt_in, false )        != VLC_SUCCESS )    {        hmsdmo_dll = 0;        p_dmo = 0;        goto error;    }    /* Setup input format */    memset( &dmo_input_type, 0, sizeof(dmo_input_type) );    dmo_input_type.pUnk = 0;    if( p_dec->fmt_in.i_cat == AUDIO_ES )    {        uint16_t i_tag;        int i_size = sizeof(WAVEFORMATEX) + p_dec->fmt_in.i_extra;        p_wf = malloc( i_size );        memset( p_wf, 0, sizeof(WAVEFORMATEX) );        if( p_dec->fmt_in.i_extra )            memcpy( &p_wf[1], p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra );        dmo_input_type.majortype  = MEDIATYPE_Audio;        dmo_input_type.subtype    = dmo_input_type.majortype;        dmo_input_type.subtype.Data1 = p_dec->fmt_in.i_codec;        fourcc_to_wf_tag( p_dec->fmt_in.i_codec, &i_tag );        if( i_tag ) dmo_input_type.subtype.Data1 = i_tag;        p_wf->wFormatTag = dmo_input_type.subtype.Data1;        p_wf->nSamplesPerSec = p_dec->fmt_in.audio.i_rate;        p_wf->nChannels = p_dec->fmt_in.audio.i_channels;        p_wf->wBitsPerSample = p_dec->fmt_in.audio.i_bitspersample;        p_wf->nBlockAlign = p_dec->fmt_in.audio.i_blockalign;        p_wf->nAvgBytesPerSec = p_dec->fmt_in.i_bitrate / 8;        p_wf->cbSize = p_dec->fmt_in.i_extra;        dmo_input_type.formattype = FORMAT_WaveFormatEx;        dmo_input_type.cbFormat   = i_size;        dmo_input_type.pbFormat   = (char *)p_wf;        dmo_input_type.bFixedSizeSamples = 1;        dmo_input_type.bTemporalCompression = 0;        dmo_input_type.lSampleSize = p_wf->nBlockAlign;    }    else    {        BITMAPINFOHEADER *p_bih;        int i_size = sizeof(VIDEOINFOHEADER) + p_dec->fmt_in.i_extra;        p_vih = malloc( i_size );        memset( p_vih, 0, sizeof(VIDEOINFOHEADER) );        if( p_dec->fmt_in.i_extra )            memcpy( &p_vih[1], p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra );        p_bih = &p_vih->bmiHeader;        p_bih->biCompression = p_dec->fmt_in.i_codec;        p_bih->biWidth = p_dec->fmt_in.video.i_width;        p_bih->biHeight = p_dec->fmt_in.video.i_height;        p_bih->biBitCount = p_dec->fmt_in.video.i_bits_per_pixel;        p_bih->biPlanes = 1;        p_bih->biSize = i_size - sizeof(VIDEOINFOHEADER) +            sizeof(BITMAPINFOHEADER);        p_vih->rcSource.left = p_vih->rcSource.top = 0;        p_vih->rcSource.right = p_dec->fmt_in.video.i_width;        p_vih->rcSource.bottom = p_dec->fmt_in.video.i_height;        p_vih->rcTarget = p_vih->rcSource;        dmo_input_type.majortype  = MEDIATYPE_Video;        dmo_input_type.subtype    = dmo_input_type.majortype;        dmo_input_type.subtype.Data1 = p_dec->fmt_in.i_codec;        dmo_input_type.formattype = FORMAT_VideoInfo;        dmo_input_type.bFixedSizeSamples = 0;        dmo_input_type.bTemporalCompression = 1;        dmo_input_type.cbFormat = i_size;        dmo_input_type.pbFormat = (char *)p_vih;    }    if( p_dmo->vt->SetInputType( p_dmo, 0, &dmo_input_type, 0 ) )    {

⌨️ 快捷键说明

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