From: Gildas Bazin Date: Thu, 1 Jul 2004 10:06:42 +0000 (+0000) Subject: * modules/codec/dmo: "DirectX Media Object" decoder plugin (win32 only). X-Git-Tag: 0.8.0~1010 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=40a4073e30d3b6bdb243e1e378aacc5ce7752138;p=vlc * modules/codec/dmo: "DirectX Media Object" decoder plugin (win32 only). This plugin allows using DMO filters to decode some media types (eg. WMV3). --- diff --git a/configure.ac b/configure.ac index b5ca20b541..9c56a7c2a7 100644 --- a/configure.ac +++ b/configure.ac @@ -889,7 +889,7 @@ dnl dnl default modules dnl VLC_ADD_PLUGINS([dummy rc telnet logger gestures memcpy hotkeys netsync]) -VLC_ADD_PLUGINS([mpgv mpga m4v h264 ps pva avi asf aac mp4 rawdv nsv real aiff mjpeg]) +VLC_ADD_PLUGINS([mpgv mpga m4v h264 ps pva avi asf aac mp4 rawdv nsv real aiff mjpeg demuxdump]) VLC_ADD_PLUGINS([cvdsub svcdsub spudec dvbsub mpeg_audio lpcm a52 dts cinepak]) VLC_ADD_PLUGINS([deinterlace invert adjust wall transform distort clone crop motionblur]) VLC_ADD_PLUGINS([float32tos16 float32tos8 float32tou16 float32tou8 a52tospdif dtstospdif fixed32tofloat32 fixed32tos16 s16tofixed32 s16tofloat32 s16tofloat32swab s8tofloat32 u8tofixed32 u8tofloat32]) @@ -921,6 +921,8 @@ if test "${SYS}" != "mingw32"; then VLC_ADD_PLUGINS([screensaver]) else VLC_ADD_PLUGINS([ntservice]) + VLC_ADD_PLUGINS([dmo]) + VLC_ADD_LDFLAGS([dmo],[-lole32]) fi dnl @@ -1270,6 +1272,12 @@ then AC_MSG_ERROR([cannot find ${with_dvdread}/include/dvdread/dvd_reader.h]) fi fi + + dnl Temporary hack (yeah, sure ;) + if test "${SYS}" = "mingw32" || test "${SYS}" = "darwin"; then + VLC_ADD_LDFLAGS([dvdread],[-ldvdcss]) + fi + fi dnl @@ -3782,6 +3790,7 @@ AC_CONFIG_FILES([ modules/audio_output/Makefile modules/codec/Makefile modules/codec/cmml/Makefile + modules/codec/dmo/Makefile modules/codec/ffmpeg/Makefile modules/codec/ffmpeg/postprocessing/Makefile modules/codec/ogt/Makefile diff --git a/include/codecs.h b/include/codecs.h index 2e3361d4c2..a144765533 100644 --- a/include/codecs.h +++ b/include/codecs.h @@ -4,7 +4,7 @@ * Copyright (C) 1999-2001 VideoLAN * $Id$ * - * Author: Gildas Bazin + * Author: Gildas Bazin * * 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 @@ -120,11 +120,29 @@ typedef struct { } BITMAPINFO, *LPBITMAPINFO; #endif -/* dvb_spuinfo_t exports the id of the selected track to the decoder */ typedef struct +#ifdef HAVE_ATTRIBUTE_PACKED + __attribute__((__packed__)) +#endif +{ + int left, top, right, bottom; +} RECT32; + +typedef int64_t REFERENCE_TIME; + +typedef struct +#ifdef HAVE_ATTRIBUTE_PACKED + __attribute__((__packed__)) +#endif { - unsigned int i_id; -} dvb_spuinfo_t; + RECT32 rcSource; + RECT32 rcTarget; + uint32_t dwBitRate; + uint32_t dwBitErrorRate; + REFERENCE_TIME AvgTimePerFrame; + BITMAPINFOHEADER bmiHeader; + //int reserved[3]; +} VIDEOINFOHEADER; /* WAVE format wFormatTag IDs */ #define WAVE_FORMAT_UNKNOWN 0x0000 /* Microsoft Corporation */ @@ -207,25 +225,26 @@ wave_format_tag_to_fourcc[] = { WAVE_FORMAT_UNKNOWN, VLC_FOURCC( 'u', 'n', 'd', 'f' ), "Unknown" } }; -static inline void wf_tag_to_fourcc( uint16_t i_tag, - vlc_fourcc_t *fcc, char **ppsz_name ) +static inline void wf_tag_to_fourcc( uint16_t i_tag, vlc_fourcc_t *fcc, + char **ppsz_name ) { int i; for( i = 0; wave_format_tag_to_fourcc[i].i_tag != 0; i++ ) { - if( wave_format_tag_to_fourcc[i].i_tag == i_tag ) - { - break; - } - } - if( fcc ) - { - *fcc = wave_format_tag_to_fourcc[i].i_fourcc; + if( wave_format_tag_to_fourcc[i].i_tag == i_tag ) break; } - if( ppsz_name ) + if( fcc ) *fcc = wave_format_tag_to_fourcc[i].i_fourcc; + if( ppsz_name ) *ppsz_name = wave_format_tag_to_fourcc[i].psz_name; +} + +static inline void fourcc_to_wf_tag( vlc_fourcc_t fcc, uint16_t *pi_tag ) +{ + int i; + for( i = 0; wave_format_tag_to_fourcc[i].i_tag != 0; i++ ) { - *ppsz_name = wave_format_tag_to_fourcc[i].psz_name; + if( wave_format_tag_to_fourcc[i].i_fourcc == fcc ) break; } + if( pi_tag ) *pi_tag = wave_format_tag_to_fourcc[i].i_tag; } /** @@ -252,6 +271,7 @@ typedef struct es_sys_t vlc_bool_t b_forced_subs; unsigned int palette[16]; unsigned int colors[4]; + } subtitle_data_t; #endif /* "codecs.h" */ diff --git a/modules/codec/dmo/Modules.am b/modules/codec/dmo/Modules.am new file mode 100644 index 0000000000..148aea346f --- /dev/null +++ b/modules/codec/dmo/Modules.am @@ -0,0 +1 @@ +SOURCES_dmo = dmo.c dmo.h buffer.c diff --git a/modules/codec/dmo/buffer.c b/modules/codec/dmo/buffer.c new file mode 100644 index 0000000000..8cf3f8cada --- /dev/null +++ b/modules/codec/dmo/buffer.c @@ -0,0 +1,132 @@ +/***************************************************************************** + * buffer.c : DirectMedia Object decoder module for vlc + ***************************************************************************** + * Copyright (C) 2002, 2003 VideoLAN + * $Id$ + * + * Author: Gildas Bazin + * + * 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 +#include +#include + +#include +#include +#include + +#include +#include "codecs.h" +#include "dmo.h" + +static long STDCALL QueryInterface( IUnknown *This, + const GUID *riid, void **ppv ) +{ + CMediaBuffer *p_mb = (CMediaBuffer *)This; + if( !memcmp( riid, &IID_IUnknown, sizeof(GUID) ) || + !memcmp( riid, &IID_IMediaBuffer, sizeof(GUID) ) ) + { + p_mb->i_ref++; + *ppv = (void *)This; + return NOERROR; + } + else + { + *ppv = NULL; + return E_NOINTERFACE; + } +} + +static long STDCALL AddRef( IUnknown *This ) +{ + CMediaBuffer *p_mb = (CMediaBuffer *)This; + return p_mb->i_ref++; +} + +static long STDCALL Release( IUnknown *This ) +{ + CMediaBuffer *p_mb = (CMediaBuffer *)This; + p_mb->i_ref--; + + if( p_mb->i_ref == 0 ) + { + if( p_mb->b_own ) block_Release( p_mb->p_block ); + free( p_mb->vt ); + free( p_mb ); + } + + return 0; +} + +static long STDCALL SetLength( IMediaBuffer *This, uint32_t cbLength ) +{ + CMediaBuffer *p_mb = (CMediaBuffer *)This; + if( cbLength > p_mb->i_max_size ) return E_INVALIDARG; + p_mb->p_block->i_buffer = cbLength; + return S_OK; +} + +static long STDCALL GetMaxLength( IMediaBuffer *This, uint32_t *pcbMaxLength ) +{ + CMediaBuffer *p_mb = (CMediaBuffer *)This; + if( !pcbMaxLength ) return E_POINTER; + *pcbMaxLength = p_mb->i_max_size; + return S_OK; +} + +static long STDCALL GetBufferAndLength( IMediaBuffer *This, + char **ppBuffer, uint32_t *pcbLength ) +{ + CMediaBuffer *p_mb = (CMediaBuffer *)This; + + if( !ppBuffer && !pcbLength ) return E_POINTER; + if( ppBuffer ) *ppBuffer = p_mb->p_block->p_buffer; + if( pcbLength ) *pcbLength = p_mb->p_block->i_buffer; + return S_OK; +} + +CMediaBuffer *CMediaBufferCreate( block_t *p_block, int i_max_size, + vlc_bool_t b_own ) +{ + CMediaBuffer *p_mb = (CMediaBuffer *)malloc( sizeof(CMediaBuffer) ); + if( !p_mb ) return NULL; + + p_mb->vt = (IMediaBuffer_vt *)malloc( sizeof(IMediaBuffer_vt) ); + if( !p_mb->vt ) + { + free( p_mb ); + return NULL; + } + + p_mb->i_ref = 1; + p_mb->p_block = p_block; + p_mb->i_max_size = i_max_size; + p_mb->b_own = b_own; + + p_mb->vt->QueryInterface = QueryInterface; + p_mb->vt->AddRef = AddRef; + p_mb->vt->Release = Release; + + p_mb->vt->SetLength = SetLength; + p_mb->vt->GetMaxLength = GetMaxLength; + p_mb->vt->GetBufferAndLength = GetBufferAndLength; + + return p_mb; +} diff --git a/modules/codec/dmo/dmo.c b/modules/codec/dmo/dmo.c new file mode 100644 index 0000000000..75d410e9a4 --- /dev/null +++ b/modules/codec/dmo/dmo.c @@ -0,0 +1,631 @@ +/***************************************************************************** + * dmo.c : DirectMedia Object decoder module for vlc + ***************************************************************************** + * Copyright (C) 2002, 2003 VideoLAN + * $Id$ + * + * Author: Gildas Bazin + * + * 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 +#include +#include + +#include +#include +#include + +#include +#include "codecs.h" +#include "dmo.h" + +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 void DecoderClose ( vlc_object_t * ); +static void *DecodeBlock ( decoder_t *, block_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 ); +vlc_module_end(); + +/***************************************************************************** + * Local prototypes + *****************************************************************************/ + +/**************************************************************************** + * Decoder descriptor declaration + ****************************************************************************/ +struct decoder_sys_t +{ + HINSTANCE hmsdmo_dll; + IMediaObject *p_dmo; + + int i_min_output; + + audio_date_t end_date; +}; + +/***************************************************************************** + * DecoderOpen: open dmo codec + *****************************************************************************/ +static int DecoderOpen( vlc_object_t *p_this ) +{ + decoder_t *p_dec = (decoder_t*)p_this; + decoder_sys_t *p_sys = NULL; + + DMO_PARTIAL_MEDIATYPE dmo_partial_type; + DMO_MEDIA_TYPE dmo_input_type, dmo_output_type; + IEnumDMO *p_enum_dmo = NULL; + IMediaObject *p_dmo = NULL; + WCHAR *psz_dmo_name; + GUID clsid_dmo; + + VIDEOINFOHEADER *p_vih = NULL; + WAVEFORMATEX *p_wf = NULL; + + HRESULT (STDCALL *OurDMOEnum)( const GUID *, uint32_t, uint32_t, + const DMO_PARTIAL_MEDIATYPE *, + uint32_t, const DMO_PARTIAL_MEDIATYPE *, + IEnumDMO ** ); + + /* Load msdmo DLL */ + HINSTANCE hmsdmo_dll = LoadLibrary( "msdmo.dll" ); + if( hmsdmo_dll == NULL ) + { + msg_Dbg( p_dec, "failed loading msdmo.dll" ); + return VLC_EGENERIC; + } + OurDMOEnum = (void *)GetProcAddress( hmsdmo_dll, "DMOEnum" ); + if( OurDMOEnum == NULL ) + { + msg_Dbg( p_dec, "GetProcAddress failed to find DMOEnum()" ); + FreeLibrary( hmsdmo_dll ); + return VLC_EGENERIC; + } + + /* Look for a DMO which can handle the requested codec */ + if( p_dec->fmt_in.i_cat == AUDIO_ES ) + { + uint16_t i_tag; + dmo_partial_type.type = MEDIATYPE_Audio; + dmo_partial_type.subtype = dmo_partial_type.type; + dmo_partial_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_partial_type.subtype.Data1 = i_tag; + } + else + { + dmo_partial_type.type = MEDIATYPE_Video; + dmo_partial_type.subtype = dmo_partial_type.type; + dmo_partial_type.subtype.Data1 = p_dec->fmt_in.i_codec; + } + + /* Initialize OLE/COM */ + CoInitialize( 0 ); + + if( OurDMOEnum( &GUID_NULL, 1 /*DMO_ENUMF_INCLUDE_KEYED*/, + 1, &dmo_partial_type, 0, NULL, &p_enum_dmo ) ) + { + goto error; + } + + /* Pickup the first available codec */ + if( p_enum_dmo->vt->Next( p_enum_dmo, 1, &clsid_dmo, + &psz_dmo_name, NULL ) ) + { + goto error; + } + p_enum_dmo->vt->Release( (IUnknown *)p_enum_dmo ); + +#if 1 + { + char psz_temp[MAX_PATH]; + wcstombs( psz_temp, psz_dmo_name, MAX_PATH ); + msg_Dbg( p_dec, "found DMO: %s", psz_temp ); + } +#endif + + CoTaskMemFree( psz_dmo_name ); + + /* Create DMO */ + if( CoCreateInstance( &clsid_dmo, NULL, CLSCTX_INPROC, + &IID_IMediaObject, (void **)&p_dmo ) ) + { + msg_Err( p_dec, "can't create DMO" ); + goto error; + } + + /* Setup input format */ + memset( &dmo_input_type, 0, sizeof(dmo_input_type) ); + dmo_input_type.majortype = dmo_partial_type.type; + dmo_input_type.subtype = dmo_partial_type.subtype; + dmo_input_type.pUnk = 0; + + if( p_dec->fmt_in.i_cat == AUDIO_ES ) + { + 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 ); + + p_wf->wFormatTag = dmo_partial_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 = i_size; + + dmo_input_type.formattype = FORMAT_WaveFormatEx; + dmo_input_type.cbFormat = i_size; + dmo_input_type.pbFormat = (char *)p_wf; + dmo_input_type.pUnk = NULL; + 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 = dmo_partial_type.subtype.Data1; + 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.formattype = MEDIASUBTYPE_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.majortype = dmo_partial_type.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 = + p_dec->fmt_in.audio.i_bitspersample; + 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 = sizeof(WAVEFORMATEX); + + 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; + dmo_output_type.pUnk = NULL; + } + else + { + BITMAPINFOHEADER *p_bih; + + p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0'); + p_dec->fmt_out.video.i_width = p_dec->fmt_in.video.i_width; + p_dec->fmt_out.video.i_height = p_dec->fmt_in.video.i_height; + p_dec->fmt_out.video.i_bits_per_pixel = 12; + p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * + p_dec->fmt_out.video.i_width / p_dec->fmt_out.video.i_height; + + dmo_output_type.formattype = MEDIASUBTYPE_VideoInfo; + dmo_output_type.subtype = MEDIASUBTYPE_YV12; + + p_bih = &p_vih->bmiHeader; + p_bih->biCompression = dmo_partial_type.subtype.Data1; + p_bih->biHeight *= -1; + p_bih->biBitCount = p_dec->fmt_out.video.i_bits_per_pixel; + p_bih->biSizeImage = p_dec->fmt_in.video.i_width * + p_dec->fmt_in.video.i_height * + (p_dec->fmt_in.video.i_bits_per_pixel + 7) / 8; + + //p_bih->biPlanes = 1; + p_bih->biSize = sizeof(BITMAPINFOHEADER); + + dmo_output_type.bFixedSizeSamples = VLC_TRUE; + dmo_output_type.bTemporalCompression = 0; + dmo_output_type.lSampleSize = p_bih->biSizeImage; + dmo_output_type.cbFormat = sizeof(VIDEOINFOHEADER); + dmo_output_type.pbFormat = (char *)p_vih; + } + + /* Enumerate output types */ + if( p_dec->fmt_in.i_cat == VIDEO_ES ) + { + int i = 0; + DMO_MEDIA_TYPE mt; + + while( !p_dmo->vt->GetOutputType( p_dmo, 0, i++, &mt ) ) + { + msg_Dbg( p_dec, "available output chroma: %4.4s", + (char *)&mt.subtype.Data1 ); + } + } + + /* Choose an output type. + * FIXME, get rid of the dmo_output_type code above. */ + if( p_dec->fmt_in.i_cat == VIDEO_ES ) + { + int i = 0; + DMO_MEDIA_TYPE mt; + + while( !p_dmo->vt->GetOutputType( p_dmo, 0, i++, &mt ) ) + { + if( dmo_output_type.subtype.Data1 == mt.subtype.Data1 ) + { + *p_vih = *(VIDEOINFOHEADER *)mt.pbFormat; + break; + } + } + } + + if( p_dmo->vt->SetOutputType( p_dmo, 0, &dmo_output_type, 0 ) ) + { + msg_Err( p_dec, "can't set DMO output type" ); + goto error; + } + msg_Dbg( p_dec, "DMO output type set" ); + + /* Allocate the memory needed to store the decoder's structure */ + if( ( p_dec->p_sys = p_sys = + (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL ) + { + msg_Err( p_dec, "out of memory" ); + goto error; + } + + p_sys->hmsdmo_dll = hmsdmo_dll; + p_sys->p_dmo = p_dmo; + + /* Find out some properties of the output */ + { + uint32_t i_size, i_align; + + p_sys->i_min_output = 0; + if( p_dmo->vt->GetOutputSizeInfo( p_dmo, 0, &i_size, &i_align ) ) + { + msg_Err( p_dec, "GetOutputSizeInfo() failed" ); + goto error; + } + else + { + msg_Dbg( p_dec, "GetOutputSizeInfo(): bytes %i, align %i", + i_size, i_align ); + p_sys->i_min_output = i_size; + } + } + + /* Set output properties */ + p_dec->fmt_out.i_cat = p_dec->fmt_in.i_cat; + if( p_dec->fmt_out.i_cat == AUDIO_ES ) + aout_DateInit( &p_sys->end_date, p_dec->fmt_in.audio.i_rate ); + else + aout_DateInit( &p_sys->end_date, 25 /* FIXME */ ); + aout_DateSet( &p_sys->end_date, 0 ); + + /* 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; + + if( p_vih ) free( p_vih ); + if( p_wf ) free( p_wf ); + + return VLC_SUCCESS; + + error: + /* Uninitialize OLE/COM */ + CoUninitialize(); + FreeLibrary( hmsdmo_dll ); + + if( p_vih ) free( p_vih ); + if( p_wf ) free( p_wf ); + if( p_sys ) free( p_sys ); + + return VLC_EGENERIC; +} + +/***************************************************************************** + * DecoderClose: close codec + *****************************************************************************/ +void DecoderClose( vlc_object_t *p_this ) +{ + decoder_t *p_dec = (decoder_t*)p_this; + decoder_sys_t *p_sys = p_dec->p_sys; + + /* Uninitialize OLE/COM */ + CoUninitialize(); + + FreeLibrary( p_sys->hmsdmo_dll ); + + free( p_sys ); +} + +/**************************************************************************** + * DecodeBlock: the whole thing + **************************************************************************** + * This function must be fed with ogg packets. + ****************************************************************************/ +static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) +{ + decoder_sys_t *p_sys = p_dec->p_sys; + block_t *p_block; + int i_result; + + DMO_OUTPUT_DATA_BUFFER db; + CMediaBuffer *p_out; + block_t block_out; + uint32_t i_status, i_buffer_out; + uint8_t *p_buffer_out; + + if( !pp_block ) return NULL; + + p_block = *pp_block; + + /* Won't work with streams with B-frames, but do we have any ? */ + if( p_block && p_block->i_pts <= 0 ) p_block->i_pts = p_block->i_dts; + + /* Date management */ + if( p_block && 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 0 /* Breaks the video decoding */ + 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; + } +#endif + + /* Feed input to the DMO */ + if( p_block && p_block->i_buffer ) + { + CMediaBuffer *p_in; + + p_in = CMediaBufferCreate( p_block, p_block->i_buffer, VLC_TRUE ); + + i_result = p_sys->p_dmo->vt->ProcessInput( p_sys->p_dmo, 0, + (IMediaBuffer *)p_in, DMO_INPUT_DATA_BUFFER_SYNCPOINT, + 0, 0 ); + + p_in->vt->Release( (IUnknown *)p_in ); + + if( i_result == S_FALSE ) + { + /* No output generated */ +#ifdef DMO_DEBUG + msg_Dbg( p_dec, "ProcessInput(): no output generated" ); +#endif + return NULL; + } + else if( i_result == DMO_E_NOTACCEPTING ) + { + /* Need to call ProcessOutput */ + msg_Dbg( p_dec, "ProcessInput(): not accepting" ); + } + else if( i_result != S_OK ) + { + msg_Dbg( p_dec, "ProcessInput(): failed" ); + return NULL; + } + else + { + //msg_Dbg( p_dec, "ProcessInput(): successful" ); + *pp_block = 0; + } + } + else if( p_block && !p_block->i_buffer ) + { + block_Release( p_block ); + *pp_block = 0; + } + + /* Get output from the DMO */ + block_out.p_buffer = malloc( p_sys->i_min_output ); + block_out.i_buffer = 0; + + p_out = CMediaBufferCreate( &block_out, p_sys->i_min_output, VLC_FALSE ); + db.rtTimestamp = 0; + db.rtTimelength = 0; + db.dwStatus = 0; + db.pBuffer = (IMediaBuffer *)p_out; + + i_result = p_sys->p_dmo->vt->ProcessOutput( p_sys->p_dmo, + DMO_PROCESS_OUTPUT_DISCARD_WHEN_NO_BUFFER, + 1, &db, &i_status ); + + if( i_result != S_OK ) + { + if( i_result != S_FALSE ) + msg_Dbg( p_dec, "ProcessOutput(): failed" ); +#if DMO_DEBUG + else + msg_Dbg( p_dec, "ProcessOutput(): no output" ); +#endif + + p_out->vt->Release( (IUnknown *)p_out ); + free( block_out.p_buffer ); + return NULL; + } + +#if DMO_DEBUG + msg_Dbg( p_dec, "ProcessOutput(): success" ); +#endif + + i_result = p_out->vt->GetBufferAndLength( (IMediaBuffer *)p_out, + &p_buffer_out, &i_buffer_out ); + if( i_result != S_OK ) + { + msg_Dbg( p_dec, "GetBufferAndLength(): failed" ); + p_out->vt->Release( (IUnknown *)p_out ); + free( block_out.p_buffer ); + return NULL; + } + + if( !i_buffer_out ) + { +#if DMO_DEBUG + msg_Dbg( p_dec, "ProcessOutput(): no output (i_buffer_out == 0)" ); +#endif + p_out->vt->Release( (IUnknown *)p_out ); + free( block_out.p_buffer ); + return NULL; + } + + if( p_dec->fmt_out.i_cat == VIDEO_ES ) + { + /* Get a new picture */ + picture_t *p_pic = p_dec->pf_vout_buffer_new( p_dec ); + if( !p_pic ) return NULL; + + CopyPicture( p_dec, p_pic, block_out.p_buffer ); + + /* Date management */ + p_pic->date = aout_DateGet( &p_sys->end_date ); + aout_DateIncrement( &p_sys->end_date, 1 ); + + p_out->vt->Release( (IUnknown *)p_out ); + free( block_out.p_buffer ); + + return p_pic; + } + else + { + aout_buffer_t *p_aout_buffer; + int i_samples = i_buffer_out / + ( p_dec->fmt_in.audio.i_bitspersample * + p_dec->fmt_in.audio.i_channels / 8 ); + + p_aout_buffer = p_dec->pf_aout_buffer_new( p_dec, i_samples ); + memcpy( p_aout_buffer->p_buffer, p_buffer_out, i_buffer_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 ); + + p_out->vt->Release( (IUnknown *)p_out ); + free( block_out.p_buffer ); + + return p_aout_buffer; + } + + return NULL; +} + +static void CopyPicture( decoder_t *p_dec, picture_t *p_pic, uint8_t *p_in ) +{ + int i_plane, i_line, i_width, i_dst_stride; + uint8_t *p_dst, *p_src = p_in; + + p_dst = p_pic->p[1].p_pixels; + p_pic->p[1].p_pixels = p_pic->p[2].p_pixels; + p_pic->p[2].p_pixels = p_dst; + + for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ ) + { + p_dst = p_pic->p[i_plane].p_pixels; + i_width = p_pic->p[i_plane].i_visible_pitch; + i_dst_stride = p_pic->p[i_plane].i_pitch; + + p_src += i_width; + + for( i_line = 0; i_line < p_pic->p[i_plane].i_lines; i_line++ ) + { + p_dec->p_vlc->pf_memcpy( p_dst, p_src, i_width ); + p_src += i_width; + p_dst += i_dst_stride; + } + } + + p_dst = p_pic->p[1].p_pixels; + p_pic->p[1].p_pixels = p_pic->p[2].p_pixels; + p_pic->p[2].p_pixels = p_dst; +} diff --git a/modules/codec/dmo/dmo.h b/modules/codec/dmo/dmo.h new file mode 100644 index 0000000000..35c5080df1 --- /dev/null +++ b/modules/codec/dmo/dmo.h @@ -0,0 +1,244 @@ +/***************************************************************************** + * dmo.h : DirectMedia Object codec module for vlc + ***************************************************************************** + * Copyright (C) 2002, 2003 VideoLAN + * $Id$ + * + * Author: Gildas Bazin + * + * 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. + *****************************************************************************/ + +static const GUID IID_IUnknown = {0x00000000, 0x0000, 0x0000, {0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46}}; +static const GUID IID_IMediaObject = {0xd8ad0f58, 0x5494, 0x4102, {0x97, 0xc5, 0xec, 0x79, 0x8e, 0x59, 0xbc, 0xf4}}; +static const GUID IID_IMediaBuffer = {0x59eff8b9, 0x938c, 0x4a26, {0x82, 0xf2, 0x95, 0xcb, 0x84, 0xcd, 0xc8, 0x37}}; +static const GUID MEDIATYPE_Video = {0x73646976, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}; +static const GUID MEDIATYPE_Audio = {0x73647561, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}; +static const GUID MEDIASUBTYPE_PCM = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}; +static const GUID MEDIASUBTYPE_VideoInfo = {0x05589f80, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}}; +static const GUID FORMAT_WaveFormatEx = {0x05589f81, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}}; +static const GUID GUID_NULL = {0x0000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +static const GUID MEDIASUBTYPE_I420 = {0x30323449, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}; +static const GUID MEDIASUBTYPE_YV12 = {0x32315659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}; + +#ifdef WIN32 +# define IUnknown IUnknownHack +#endif +typedef struct _IUnknown IUnknown; +typedef struct _IEnumDMO IEnumDMO; +typedef struct _IMediaBuffer IMediaBuffer; +typedef struct _IMediaObject IMediaObject; +#ifndef STDCALL +#define STDCALL __stdcall +#endif + +#define DMO_INPUT_DATA_BUFFER_SYNCPOINT 1 +#define DMO_PROCESS_OUTPUT_DISCARD_WHEN_NO_BUFFER 1 +#define DMO_E_NOTACCEPTING 0x80040204 + +/* + * DMO types definition + */ +typedef struct +#ifdef HAVE_ATTRIBUTE_PACKED + __attribute__((__packed__)) +#endif + _DMO_PARTIAL_MEDIATYPE +{ + GUID type; + GUID subtype; + +} DMO_PARTIAL_MEDIATYPE; + +typedef struct +#ifdef HAVE_ATTRIBUTE_PACKED + __attribute__((__packed__)) +#endif + _DMO_OUTPUT_DATA_BUFFER +{ + IMediaBuffer *pBuffer; + uint32_t dwStatus; + REFERENCE_TIME rtTimestamp; + REFERENCE_TIME rtTimelength; + +} DMO_OUTPUT_DATA_BUFFER; + +typedef struct +#ifdef HAVE_ATTRIBUTE_PACKED + __attribute__((__packed__)) +#endif + _DMOMediaType +{ + GUID majortype; + GUID subtype; + int bFixedSizeSamples; + int bTemporalCompression; + uint32_t lSampleSize; + GUID formattype; + IUnknown *pUnk; + uint32_t cbFormat; + char *pbFormat; + +} DMO_MEDIA_TYPE; + +/* + * IUnknown interface + */ +typedef struct IUnknown_vt +{ + /* IUnknown methods */ + long (STDCALL *QueryInterface)(IUnknown *This, const GUID *riid, + void **ppvObject); + long (STDCALL *AddRef)(IUnknown *This); + long (STDCALL *Release)(IUnknown *This); + +} IUnknown_vt; +struct _IUnknown { IUnknown_vt* vt; }; + +/* + * IEnumDMO interface + */ +typedef struct IEnumDMO_vt +{ + /* IUnknown methods */ + long (STDCALL *QueryInterface)(IUnknown *This, const GUID *riid, + void **ppvObject); + long (STDCALL *AddRef)(IUnknown *This); + long (STDCALL *Release)(IUnknown *This); + + /* IEnumDMO methods */ + long (STDCALL *Next)(IEnumDMO *This, uint32_t cItemsToFetch, + const GUID *pCLSID, WCHAR **Names, + uint32_t *pcItemsFetched); + long (STDCALL *Skip)(IEnumDMO *This, uint32_t cItemsToSkip); + long (STDCALL *Reset)(IEnumDMO *This); + long (STDCALL *Clone)(IEnumDMO *This, IEnumDMO **ppEnum); + +} IEnumDMO_vt; +struct _IEnumDMO { IEnumDMO_vt* vt; }; + +/* + * IMediaBuffer interface + */ +typedef struct IMediaBuffer_vt +{ + /* IUnknown methods */ + long (STDCALL *QueryInterface)(IUnknown *This, const GUID *riid, + void **ppvObject); + long (STDCALL *AddRef)(IUnknown *This); + long (STDCALL *Release)(IUnknown *This); + + long (STDCALL *SetLength)(IMediaBuffer* This, uint32_t cbLength); + long (STDCALL *GetMaxLength)(IMediaBuffer* This, uint32_t *pcbMaxLength); + long (STDCALL *GetBufferAndLength)(IMediaBuffer* This, + char** ppBuffer, uint32_t* pcbLength); + +} IMediaBuffer_vt; +struct _IMediaBuffer { IMediaBuffer_vt* vt; }; + +/* + * IMediaObject interface + */ +typedef struct IMediaObject_vt +{ + /* IUnknown methods */ + long (STDCALL *QueryInterface)(IUnknown *This, const GUID *riid, + void **ppvObject); + long (STDCALL *AddRef)(IUnknown *This); + long (STDCALL *Release)(IUnknown *This); + + /* IEnumDMO methods */ + long (STDCALL *GetStreamCount)(IMediaObject *This, + uint32_t *pcInputStreams, + uint32_t *pcOutputStreams); + long (STDCALL *GetInputStreamInfo)(IMediaObject *This, + uint32_t dwInputStreamIndex, + uint32_t *pdwFlags); + long (STDCALL *GetOutputStreamInfo)(IMediaObject *This, + uint32_t dwOutputStreamIndex, + uint32_t *pdwFlags); + long (STDCALL *GetInputType)(IMediaObject *This, + uint32_t dwInputStreamIndex, + uint32_t dwTypeIndex, + DMO_MEDIA_TYPE *pmt); + long (STDCALL *GetOutputType)(IMediaObject *This, + uint32_t dwOutputStreamIndex, + uint32_t dwTypeIndex, + DMO_MEDIA_TYPE *pmt); + long (STDCALL *SetInputType)(IMediaObject *This, + uint32_t dwInputStreamIndex, + const DMO_MEDIA_TYPE *pmt, + uint32_t dwFlags); + long (STDCALL *SetOutputType)(IMediaObject *This, + uint32_t dwOutputStreamIndex, + const DMO_MEDIA_TYPE *pmt, + uint32_t dwFlags); + long (STDCALL *GetInputCurrentType)(IMediaObject *This, + uint32_t dwInputStreamIndex, + DMO_MEDIA_TYPE *pmt); + long (STDCALL *GetOutputCurrentType)(IMediaObject *This, + uint32_t dwOutputStreamIndex, + DMO_MEDIA_TYPE *pmt); + long (STDCALL *GetInputSizeInfo)(IMediaObject *This, + uint32_t dwInputStreamIndex, + uint32_t *pcbSize, + uint32_t *pcbMaxLookahead, + uint32_t *pcbAlignment); + long (STDCALL *GetOutputSizeInfo)(IMediaObject *This, + uint32_t dwOutputStreamIndex, + uint32_t *pcbSize, + uint32_t *pcbAlignment); + long (STDCALL *GetInputMaxLatency)(IMediaObject *This, + uint32_t dwInputStreamIndex, + REFERENCE_TIME *prtMaxLatency); + long (STDCALL *SetInputMaxLatency)(IMediaObject *This, + uint32_t dwInputStreamIndex, + REFERENCE_TIME rtMaxLatency); + long (STDCALL *Flush)(IMediaObject * This); + long (STDCALL *Discontinuity)(IMediaObject *This, + uint32_t dwInputStreamIndex); + long (STDCALL *AllocateStreamingResources)(IMediaObject * This); + long (STDCALL *FreeStreamingResources)(IMediaObject * This); + long (STDCALL *GetInputStatus)(IMediaObject *This, + uint32_t dwInputStreamIndex, + uint32_t *dwFlags); + long (STDCALL *ProcessInput)(IMediaObject *This, + uint32_t dwInputStreamIndex, + IMediaBuffer *pBuffer, + uint32_t dwFlags, + REFERENCE_TIME rtTimestamp, + REFERENCE_TIME rtTimelength); + long (STDCALL *ProcessOutput)(IMediaObject *This, + uint32_t dwFlags, + uint32_t cOutputBufferCount, + DMO_OUTPUT_DATA_BUFFER *pOutputBuffers, + uint32_t *pdwStatus); + long (STDCALL *Lock)(IMediaObject *This, long bLock); + +} IMediaObject_vt; +struct _IMediaObject { IMediaObject_vt* vt; }; + +/* Implementation of IMediaBuffer */ +typedef struct _CMediaBuffer +{ + IMediaBuffer_vt *vt; + int i_ref; + block_t *p_block; + int i_max_size; + vlc_bool_t b_own; + +} CMediaBuffer; + +CMediaBuffer *CMediaBufferCreate( block_t *, int, vlc_bool_t );