📄 dmo.c
字号:
/***************************************************************************** * dmo.c : DirectMedia Object decoder module for vlc ***************************************************************************** * Copyright (C) 2002, 2003 VideoLAN * $Id: dmo.c 10992 2005-05-13 13:11:36Z gbazin $ * * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h>#include <stdio.h>#include <string.h>#include <vlc/vlc.h>#include <vlc/decoder.h>#include <vlc/vout.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 "codecs.h"#include "dmo.h"//#define DMO_DEBUG 1#ifdef LOADER/* Not Needed */long CoInitialize( void *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 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 *, vlc_bool_t );static void CopyPicture( decoder_t *, picture_t *, uint8_t * );vlc_module_begin(); set_description( _("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( _("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};static const GUID guid_wmv9 = { 0x724bb6a4, 0xe526, 0x450f, { 0xaf, 0xfa, 0xab, 0x9b, 0x45, 0x12, 0x91, 0x11 } };static const GUID guid_wma9 = { 0x27ca0808, 0x01f5, 0x4e7a, { 0x8b, 0x05, 0x87, 0xf8, 0x07, 0xa2, 0x33, 0xd1 } };static const GUID guid_wmv = { 0x82d353df, 0x90bd, 0x4382, { 0x8b, 0xc2, 0x3f, 0x61, 0x92, 0xb7, 0x6e, 0x34 } };static const GUID guid_wma = { 0x874131cb, 0x4ecc, 0x443b, { 0x89, 0x48, 0x74, 0x6b, 0x89, 0x59, 0x5d, 0x20 } };static const GUID guid_wmv_enc = { 0x3181343b, 0x94a2, 0x4feb, { 0xad, 0xef, 0x30, 0xa1, 0xdd, 0xe6, 0x17, 0xb4 } };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[] ={ /* WM3 */ { VLC_FOURCC('W','M','V','3'), "wmv9dmod.dll", &guid_wmv9 }, { VLC_FOURCC('w','m','v','3'), "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 }, /* WMA 3 */ { VLC_FOURCC('W','M','A','3'), "wma9dmod.dll", &guid_wma9 }, { VLC_FOURCC('w','m','a','3'), "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 }, /* */ { 0, NULL, NULL }};static const codec_dll encoders_table[] ={ /* WMV2 */ { VLC_FOURCC('W','M','V','2'), "wmvdmoe.dll", &guid_wmv_enc }, { VLC_FOURCC('w','m','v','1'), "wmvdmoe.dll", &guid_wmv_enc }, /* WMV1 */ { VLC_FOURCC('W','M','V','1'), "wmvdmoe.dll", &guid_wmv_enc }, { VLC_FOURCC('w','m','v','1'), "wmvdmoe.dll", &guid_wmv_enc }, /* 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, VLC_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 ) ) { msg_Err( p_dec, "can't set DMO input type" ); goto error; } msg_Dbg( p_dec, "DMO input type set" ); /* Setup output format */ memset( &dmo_output_type, 0, sizeof(dmo_output_type) ); dmo_output_type.pUnk = 0; if( p_dec->fmt_in.i_cat == AUDIO_ES ) { /* Setup the format */ p_dec->fmt_out.i_codec = AOUT_FMT_S16_NE; p_dec->fmt_out.audio.i_rate = p_dec->fmt_in.audio.i_rate; p_dec->fmt_out.audio.i_channels = p_dec->fmt_in.audio.i_channels; p_dec->fmt_out.audio.i_bitspersample = 16;//p_dec->fmt_in.audio.i_bitspersample; We request 16 p_dec->fmt_out.audio.i_physical_channels = p_dec->fmt_out.audio.i_original_channels = pi_channels_maps[p_dec->fmt_out.audio.i_channels]; p_wf->wFormatTag = WAVE_FORMAT_PCM; p_wf->nSamplesPerSec = p_dec->fmt_out.audio.i_rate; p_wf->nChannels = p_dec->fmt_out.audio.i_channels; p_wf->wBitsPerSample = p_dec->fmt_out.audio.i_bitspersample; p_wf->nBlockAlign = p_wf->wBitsPerSample / 8 * p_wf->nChannels; p_wf->nAvgBytesPerSec = p_wf->nSamplesPerSec * p_wf->nBlockAlign; p_wf->cbSize = 0; dmo_output_type.majortype = MEDIATYPE_Audio; dmo_output_type.formattype = FORMAT_WaveFormatEx; dmo_output_type.subtype = MEDIASUBTYPE_PCM; dmo_output_type.cbFormat = sizeof(WAVEFORMATEX); dmo_output_type.pbFormat = (char *)p_wf; dmo_output_type.bFixedSizeSamples = 1; dmo_output_type.bTemporalCompression = 0; dmo_output_type.lSampleSize = p_wf->nBlockAlign; } else { BITMAPINFOHEADER *p_bih;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -