--- /dev/null
+/*****************************************************************************\r
+ * dmo.c : DirectMedia Object decoder module for vlc\r
+ *****************************************************************************\r
+ * Copyright (C) 2002, 2003 VideoLAN\r
+ * $Id$\r
+ *\r
+ * Author: Gildas Bazin <gbazin@videolan.org>\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.\r
+ *****************************************************************************/\r
+\r
+/*****************************************************************************\r
+ * Preamble\r
+ *****************************************************************************/\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+#include <vlc/vlc.h>\r
+#include <vlc/decoder.h>\r
+#include <vlc/vout.h>\r
+\r
+#include <objbase.h>\r
+#include "codecs.h"\r
+#include "dmo.h"\r
+\r
+static int pi_channels_maps[7] =\r
+{\r
+ 0,\r
+ AOUT_CHAN_CENTER,\r
+ AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,\r
+ AOUT_CHAN_CENTER | AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,\r
+ AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT\r
+ | AOUT_CHAN_REARRIGHT,\r
+ AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER\r
+ | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT,\r
+ AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER\r
+ | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE\r
+};\r
+\r
+/*****************************************************************************\r
+ * Module descriptor\r
+ *****************************************************************************/\r
+static int DecoderOpen ( vlc_object_t * );\r
+static void DecoderClose ( vlc_object_t * );\r
+static void *DecodeBlock ( decoder_t *, block_t ** );\r
+\r
+static void CopyPicture( decoder_t *, picture_t *, uint8_t * );\r
+\r
+vlc_module_begin();\r
+ set_description( _("DirectMedia Object decoder") );\r
+ add_shortcut( "dmo" );\r
+ set_capability( "decoder", 1 );\r
+ set_callbacks( DecoderOpen, DecoderClose );\r
+vlc_module_end();\r
+\r
+/*****************************************************************************\r
+ * Local prototypes\r
+ *****************************************************************************/\r
+\r
+/****************************************************************************\r
+ * Decoder descriptor declaration\r
+ ****************************************************************************/\r
+struct decoder_sys_t\r
+{\r
+ HINSTANCE hmsdmo_dll;\r
+ IMediaObject *p_dmo;\r
+\r
+ int i_min_output;\r
+\r
+ audio_date_t end_date;\r
+};\r
+\r
+/*****************************************************************************\r
+ * DecoderOpen: open dmo codec\r
+ *****************************************************************************/\r
+static int DecoderOpen( vlc_object_t *p_this )\r
+{\r
+ decoder_t *p_dec = (decoder_t*)p_this;\r
+ decoder_sys_t *p_sys = NULL;\r
+\r
+ DMO_PARTIAL_MEDIATYPE dmo_partial_type;\r
+ DMO_MEDIA_TYPE dmo_input_type, dmo_output_type;\r
+ IEnumDMO *p_enum_dmo = NULL; \r
+ IMediaObject *p_dmo = NULL;\r
+ WCHAR *psz_dmo_name;\r
+ GUID clsid_dmo;\r
+\r
+ VIDEOINFOHEADER *p_vih = NULL;\r
+ WAVEFORMATEX *p_wf = NULL;\r
+\r
+ HRESULT (STDCALL *OurDMOEnum)( const GUID *, uint32_t, uint32_t,\r
+ const DMO_PARTIAL_MEDIATYPE *,\r
+ uint32_t, const DMO_PARTIAL_MEDIATYPE *,\r
+ IEnumDMO ** );\r
+\r
+ /* Load msdmo DLL */\r
+ HINSTANCE hmsdmo_dll = LoadLibrary( "msdmo.dll" );\r
+ if( hmsdmo_dll == NULL )\r
+ {\r
+ msg_Dbg( p_dec, "failed loading msdmo.dll" );\r
+ return VLC_EGENERIC;\r
+ }\r
+ OurDMOEnum = (void *)GetProcAddress( hmsdmo_dll, "DMOEnum" );\r
+ if( OurDMOEnum == NULL )\r
+ {\r
+ msg_Dbg( p_dec, "GetProcAddress failed to find DMOEnum()" );\r
+ FreeLibrary( hmsdmo_dll );\r
+ return VLC_EGENERIC;\r
+ }\r
+\r
+ /* Look for a DMO which can handle the requested codec */\r
+ if( p_dec->fmt_in.i_cat == AUDIO_ES )\r
+ {\r
+ uint16_t i_tag;\r
+ dmo_partial_type.type = MEDIATYPE_Audio;\r
+ dmo_partial_type.subtype = dmo_partial_type.type;\r
+ dmo_partial_type.subtype.Data1 = p_dec->fmt_in.i_codec;\r
+ fourcc_to_wf_tag( p_dec->fmt_in.i_codec, &i_tag );\r
+ if( i_tag ) dmo_partial_type.subtype.Data1 = i_tag;\r
+ }\r
+ else\r
+ {\r
+ dmo_partial_type.type = MEDIATYPE_Video;\r
+ dmo_partial_type.subtype = dmo_partial_type.type;\r
+ dmo_partial_type.subtype.Data1 = p_dec->fmt_in.i_codec;\r
+ }\r
+\r
+ /* Initialize OLE/COM */\r
+ CoInitialize( 0 );\r
+\r
+ if( OurDMOEnum( &GUID_NULL, 1 /*DMO_ENUMF_INCLUDE_KEYED*/,\r
+ 1, &dmo_partial_type, 0, NULL, &p_enum_dmo ) )\r
+ {\r
+ goto error;\r
+ }\r
+\r
+ /* Pickup the first available codec */\r
+ if( p_enum_dmo->vt->Next( p_enum_dmo, 1, &clsid_dmo,\r
+ &psz_dmo_name, NULL ) )\r
+ {\r
+ goto error;\r
+ }\r
+ p_enum_dmo->vt->Release( (IUnknown *)p_enum_dmo );\r
+\r
+#if 1\r
+ {\r
+ char psz_temp[MAX_PATH];\r
+ wcstombs( psz_temp, psz_dmo_name, MAX_PATH );\r
+ msg_Dbg( p_dec, "found DMO: %s", psz_temp );\r
+ }\r
+#endif\r
+\r
+ CoTaskMemFree( psz_dmo_name );\r
+\r
+ /* Create DMO */\r
+ if( CoCreateInstance( &clsid_dmo, NULL, CLSCTX_INPROC,\r
+ &IID_IMediaObject, (void **)&p_dmo ) )\r
+ {\r
+ msg_Err( p_dec, "can't create DMO" );\r
+ goto error;\r
+ }\r
+\r
+ /* Setup input format */\r
+ memset( &dmo_input_type, 0, sizeof(dmo_input_type) );\r
+ dmo_input_type.majortype = dmo_partial_type.type;\r
+ dmo_input_type.subtype = dmo_partial_type.subtype;\r
+ dmo_input_type.pUnk = 0;\r
+\r
+ if( p_dec->fmt_in.i_cat == AUDIO_ES )\r
+ {\r
+ int i_size = sizeof(WAVEFORMATEX) + p_dec->fmt_in.i_extra;\r
+ p_wf = malloc( i_size );\r
+\r
+ memset( p_wf, 0, sizeof(WAVEFORMATEX) );\r
+ if( p_dec->fmt_in.i_extra )\r
+ memcpy( &p_wf[1], p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra );\r
+\r
+ p_wf->wFormatTag = dmo_partial_type.subtype.Data1;\r
+ p_wf->nSamplesPerSec = p_dec->fmt_in.audio.i_rate;\r
+ p_wf->nChannels = p_dec->fmt_in.audio.i_channels;\r
+ p_wf->wBitsPerSample = p_dec->fmt_in.audio.i_bitspersample;\r
+ p_wf->nBlockAlign = p_dec->fmt_in.audio.i_blockalign;\r
+ p_wf->nAvgBytesPerSec = p_dec->fmt_in.i_bitrate / 8;\r
+ p_wf->cbSize = i_size;\r
+\r
+ dmo_input_type.formattype = FORMAT_WaveFormatEx;\r
+ dmo_input_type.cbFormat = i_size;\r
+ dmo_input_type.pbFormat = (char *)p_wf;\r
+ dmo_input_type.pUnk = NULL;\r
+ dmo_input_type.bFixedSizeSamples = 1;\r
+ dmo_input_type.bTemporalCompression = 0;\r
+ dmo_input_type.lSampleSize = p_wf->nBlockAlign;\r
+ }\r
+ else\r
+ {\r
+ BITMAPINFOHEADER *p_bih;\r
+\r
+ int i_size = sizeof(VIDEOINFOHEADER) + p_dec->fmt_in.i_extra;\r
+ p_vih = malloc( i_size );\r
+\r
+ memset( p_vih, 0, sizeof(VIDEOINFOHEADER) );\r
+ if( p_dec->fmt_in.i_extra )\r
+ memcpy( &p_vih[1], p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra );\r
+\r
+ p_bih = &p_vih->bmiHeader;\r
+ p_bih->biCompression = dmo_partial_type.subtype.Data1;\r
+ p_bih->biWidth = p_dec->fmt_in.video.i_width;\r
+ p_bih->biHeight = p_dec->fmt_in.video.i_height;\r
+ p_bih->biBitCount = p_dec->fmt_in.video.i_bits_per_pixel;\r
+ p_bih->biPlanes = 1;\r
+ p_bih->biSize = i_size - sizeof(VIDEOINFOHEADER) +\r
+ sizeof(BITMAPINFOHEADER);\r
+\r
+ p_vih->rcSource.left = p_vih->rcSource.top = 0;\r
+ p_vih->rcSource.right = p_dec->fmt_in.video.i_width;\r
+ p_vih->rcSource.bottom = p_dec->fmt_in.video.i_height;\r
+ p_vih->rcTarget = p_vih->rcSource;\r
+\r
+ dmo_input_type.formattype = MEDIASUBTYPE_VideoInfo;\r
+ dmo_input_type.bFixedSizeSamples = 0;\r
+ dmo_input_type.bTemporalCompression = 1;\r
+ dmo_input_type.cbFormat = i_size;\r
+ dmo_input_type.pbFormat = (char *)p_vih;\r
+ }\r
+\r
+ if( p_dmo->vt->SetInputType( p_dmo, 0, &dmo_input_type, 0 ) )\r
+ {\r
+ msg_Err( p_dec, "can't set DMO input type" );\r
+ goto error;\r
+ }\r
+ msg_Dbg( p_dec, "DMO input type set" );\r
+\r
+ /* Setup output format */\r
+ memset( &dmo_output_type, 0, sizeof(dmo_output_type) );\r
+ dmo_output_type.majortype = dmo_partial_type.type;\r
+ dmo_output_type.pUnk = 0;\r
+\r
+ if( p_dec->fmt_in.i_cat == AUDIO_ES )\r
+ {\r
+ /* Setup the format */\r
+ p_dec->fmt_out.i_codec = AOUT_FMT_S16_NE;\r
+ p_dec->fmt_out.audio.i_rate = p_dec->fmt_in.audio.i_rate;\r
+ p_dec->fmt_out.audio.i_channels = p_dec->fmt_in.audio.i_channels;\r
+ p_dec->fmt_out.audio.i_bitspersample =\r
+ p_dec->fmt_in.audio.i_bitspersample;\r
+ p_dec->fmt_out.audio.i_physical_channels =\r
+ p_dec->fmt_out.audio.i_original_channels =\r
+ pi_channels_maps[p_dec->fmt_out.audio.i_channels];\r
+\r
+ p_wf->wFormatTag = WAVE_FORMAT_PCM;\r
+ p_wf->nSamplesPerSec = p_dec->fmt_out.audio.i_rate;\r
+ p_wf->nChannels = p_dec->fmt_out.audio.i_channels;\r
+ p_wf->wBitsPerSample = p_dec->fmt_out.audio.i_bitspersample;\r
+ p_wf->nBlockAlign =\r
+ p_wf->wBitsPerSample / 8 * p_wf->nChannels;\r
+ p_wf->nAvgBytesPerSec =\r
+ p_wf->nSamplesPerSec * p_wf->nBlockAlign;\r
+ p_wf->cbSize = sizeof(WAVEFORMATEX);\r
+\r
+ dmo_output_type.formattype = FORMAT_WaveFormatEx;\r
+ dmo_output_type.subtype = MEDIASUBTYPE_PCM;\r
+ dmo_output_type.cbFormat = sizeof(WAVEFORMATEX);\r
+ dmo_output_type.pbFormat = (char *)p_wf;\r
+ dmo_output_type.bFixedSizeSamples = 1;\r
+ dmo_output_type.bTemporalCompression = 0;\r
+ dmo_output_type.lSampleSize = p_wf->nBlockAlign;\r
+ dmo_output_type.pUnk = NULL;\r
+ }\r
+ else\r
+ {\r
+ BITMAPINFOHEADER *p_bih;\r
+\r
+ p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0');\r
+ p_dec->fmt_out.video.i_width = p_dec->fmt_in.video.i_width;\r
+ p_dec->fmt_out.video.i_height = p_dec->fmt_in.video.i_height;\r
+ p_dec->fmt_out.video.i_bits_per_pixel = 12;\r
+ p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR *\r
+ p_dec->fmt_out.video.i_width / p_dec->fmt_out.video.i_height;\r
+\r
+ dmo_output_type.formattype = MEDIASUBTYPE_VideoInfo;\r
+ dmo_output_type.subtype = MEDIASUBTYPE_YV12;\r
+\r
+ p_bih = &p_vih->bmiHeader;\r
+ p_bih->biCompression = dmo_partial_type.subtype.Data1;\r
+ p_bih->biHeight *= -1;\r
+ p_bih->biBitCount = p_dec->fmt_out.video.i_bits_per_pixel;\r
+ p_bih->biSizeImage = p_dec->fmt_in.video.i_width *\r
+ p_dec->fmt_in.video.i_height *\r
+ (p_dec->fmt_in.video.i_bits_per_pixel + 7) / 8;\r
+\r
+ //p_bih->biPlanes = 1;\r
+ p_bih->biSize = sizeof(BITMAPINFOHEADER);\r
+\r
+ dmo_output_type.bFixedSizeSamples = VLC_TRUE;\r
+ dmo_output_type.bTemporalCompression = 0;\r
+ dmo_output_type.lSampleSize = p_bih->biSizeImage;\r
+ dmo_output_type.cbFormat = sizeof(VIDEOINFOHEADER);\r
+ dmo_output_type.pbFormat = (char *)p_vih;\r
+ }\r
+\r
+ /* Enumerate output types */\r
+ if( p_dec->fmt_in.i_cat == VIDEO_ES )\r
+ {\r
+ int i = 0;\r
+ DMO_MEDIA_TYPE mt;\r
+\r
+ while( !p_dmo->vt->GetOutputType( p_dmo, 0, i++, &mt ) )\r
+ {\r
+ msg_Dbg( p_dec, "available output chroma: %4.4s",\r
+ (char *)&mt.subtype.Data1 );\r
+ }\r
+ }\r
+\r
+ /* Choose an output type.\r
+ * FIXME, get rid of the dmo_output_type code above. */\r
+ if( p_dec->fmt_in.i_cat == VIDEO_ES )\r
+ {\r
+ int i = 0;\r
+ DMO_MEDIA_TYPE mt;\r
+\r
+ while( !p_dmo->vt->GetOutputType( p_dmo, 0, i++, &mt ) )\r
+ {\r
+ if( dmo_output_type.subtype.Data1 == mt.subtype.Data1 )\r
+ {\r
+ *p_vih = *(VIDEOINFOHEADER *)mt.pbFormat;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ if( p_dmo->vt->SetOutputType( p_dmo, 0, &dmo_output_type, 0 ) )\r
+ {\r
+ msg_Err( p_dec, "can't set DMO output type" );\r
+ goto error;\r
+ }\r
+ msg_Dbg( p_dec, "DMO output type set" );\r
+\r
+ /* Allocate the memory needed to store the decoder's structure */\r
+ if( ( p_dec->p_sys = p_sys =\r
+ (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )\r
+ {\r
+ msg_Err( p_dec, "out of memory" );\r
+ goto error;\r
+ }\r
+\r
+ p_sys->hmsdmo_dll = hmsdmo_dll;\r
+ p_sys->p_dmo = p_dmo;\r
+\r
+ /* Find out some properties of the output */\r
+ {\r
+ uint32_t i_size, i_align;\r
+\r
+ p_sys->i_min_output = 0;\r
+ if( p_dmo->vt->GetOutputSizeInfo( p_dmo, 0, &i_size, &i_align ) )\r
+ {\r
+ msg_Err( p_dec, "GetOutputSizeInfo() failed" );\r
+ goto error;\r
+ }\r
+ else\r
+ {\r
+ msg_Dbg( p_dec, "GetOutputSizeInfo(): bytes %i, align %i",\r
+ i_size, i_align );\r
+ p_sys->i_min_output = i_size;\r
+ }\r
+ }\r
+\r
+ /* Set output properties */\r
+ p_dec->fmt_out.i_cat = p_dec->fmt_in.i_cat;\r
+ if( p_dec->fmt_out.i_cat == AUDIO_ES )\r
+ aout_DateInit( &p_sys->end_date, p_dec->fmt_in.audio.i_rate );\r
+ else\r
+ aout_DateInit( &p_sys->end_date, 25 /* FIXME */ );\r
+ aout_DateSet( &p_sys->end_date, 0 );\r
+\r
+ /* Set callbacks */\r
+ p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))\r
+ DecodeBlock;\r
+ p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))\r
+ DecodeBlock;\r
+\r
+ if( p_vih ) free( p_vih );\r
+ if( p_wf ) free( p_wf );\r
+\r
+ return VLC_SUCCESS;\r
+\r
+ error:\r
+ /* Uninitialize OLE/COM */\r
+ CoUninitialize();\r
+ FreeLibrary( hmsdmo_dll );\r
+\r
+ if( p_vih ) free( p_vih );\r
+ if( p_wf ) free( p_wf );\r
+ if( p_sys ) free( p_sys );\r
+\r
+ return VLC_EGENERIC;\r
+}\r
+\r
+/*****************************************************************************\r
+ * DecoderClose: close codec\r
+ *****************************************************************************/\r
+void DecoderClose( vlc_object_t *p_this )\r
+{\r
+ decoder_t *p_dec = (decoder_t*)p_this;\r
+ decoder_sys_t *p_sys = p_dec->p_sys;\r
+\r
+ /* Uninitialize OLE/COM */\r
+ CoUninitialize();\r
+\r
+ FreeLibrary( p_sys->hmsdmo_dll );\r
+\r
+ free( p_sys );\r
+}\r
+\r
+/****************************************************************************\r
+ * DecodeBlock: the whole thing\r
+ ****************************************************************************\r
+ * This function must be fed with ogg packets.\r
+ ****************************************************************************/\r
+static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )\r
+{\r
+ decoder_sys_t *p_sys = p_dec->p_sys;\r
+ block_t *p_block;\r
+ int i_result;\r
+\r
+ DMO_OUTPUT_DATA_BUFFER db;\r
+ CMediaBuffer *p_out;\r
+ block_t block_out;\r
+ uint32_t i_status, i_buffer_out;\r
+ uint8_t *p_buffer_out;\r
+\r
+ if( !pp_block ) return NULL;\r
+\r
+ p_block = *pp_block;\r
+\r
+ /* Won't work with streams with B-frames, but do we have any ? */\r
+ if( p_block && p_block->i_pts <= 0 ) p_block->i_pts = p_block->i_dts;\r
+\r
+ /* Date management */\r
+ if( p_block && p_block->i_pts > 0 &&\r
+ p_block->i_pts != aout_DateGet( &p_sys->end_date ) )\r
+ {\r
+ aout_DateSet( &p_sys->end_date, p_block->i_pts );\r
+ }\r
+\r
+#if 0 /* Breaks the video decoding */\r
+ if( !aout_DateGet( &p_sys->end_date ) )\r
+ {\r
+ /* We've just started the stream, wait for the first PTS. */\r
+ if( p_block ) block_Release( p_block );\r
+ return NULL;\r
+ }\r
+#endif\r
+\r
+ /* Feed input to the DMO */\r
+ if( p_block && p_block->i_buffer )\r
+ {\r
+ CMediaBuffer *p_in;\r
+\r
+ p_in = CMediaBufferCreate( p_block, p_block->i_buffer, VLC_TRUE );\r
+\r
+ i_result = p_sys->p_dmo->vt->ProcessInput( p_sys->p_dmo, 0,\r
+ (IMediaBuffer *)p_in, DMO_INPUT_DATA_BUFFER_SYNCPOINT,\r
+ 0, 0 );\r
+\r
+ p_in->vt->Release( (IUnknown *)p_in );\r
+\r
+ if( i_result == S_FALSE )\r
+ {\r
+ /* No output generated */\r
+#ifdef DMO_DEBUG\r
+ msg_Dbg( p_dec, "ProcessInput(): no output generated" );\r
+#endif\r
+ return NULL;\r
+ }\r
+ else if( i_result == DMO_E_NOTACCEPTING )\r
+ {\r
+ /* Need to call ProcessOutput */\r
+ msg_Dbg( p_dec, "ProcessInput(): not accepting" );\r
+ }\r
+ else if( i_result != S_OK )\r
+ {\r
+ msg_Dbg( p_dec, "ProcessInput(): failed" );\r
+ return NULL;\r
+ }\r
+ else\r
+ {\r
+ //msg_Dbg( p_dec, "ProcessInput(): successful" );\r
+ *pp_block = 0;\r
+ }\r
+ }\r
+ else if( p_block && !p_block->i_buffer )\r
+ {\r
+ block_Release( p_block );\r
+ *pp_block = 0;\r
+ }\r
+\r
+ /* Get output from the DMO */\r
+ block_out.p_buffer = malloc( p_sys->i_min_output );\r
+ block_out.i_buffer = 0;\r
+\r
+ p_out = CMediaBufferCreate( &block_out, p_sys->i_min_output, VLC_FALSE );\r
+ db.rtTimestamp = 0;\r
+ db.rtTimelength = 0;\r
+ db.dwStatus = 0;\r
+ db.pBuffer = (IMediaBuffer *)p_out;\r
+\r
+ i_result = p_sys->p_dmo->vt->ProcessOutput( p_sys->p_dmo,\r
+ DMO_PROCESS_OUTPUT_DISCARD_WHEN_NO_BUFFER,\r
+ 1, &db, &i_status );\r
+\r
+ if( i_result != S_OK )\r
+ {\r
+ if( i_result != S_FALSE )\r
+ msg_Dbg( p_dec, "ProcessOutput(): failed" );\r
+#if DMO_DEBUG\r
+ else\r
+ msg_Dbg( p_dec, "ProcessOutput(): no output" );\r
+#endif\r
+\r
+ p_out->vt->Release( (IUnknown *)p_out );\r
+ free( block_out.p_buffer );\r
+ return NULL;\r
+ }\r
+\r
+#if DMO_DEBUG\r
+ msg_Dbg( p_dec, "ProcessOutput(): success" );\r
+#endif\r
+\r
+ i_result = p_out->vt->GetBufferAndLength( (IMediaBuffer *)p_out,\r
+ &p_buffer_out, &i_buffer_out );\r
+ if( i_result != S_OK )\r
+ {\r
+ msg_Dbg( p_dec, "GetBufferAndLength(): failed" );\r
+ p_out->vt->Release( (IUnknown *)p_out );\r
+ free( block_out.p_buffer );\r
+ return NULL;\r
+ }\r
+\r
+ if( !i_buffer_out )\r
+ {\r
+#if DMO_DEBUG\r
+ msg_Dbg( p_dec, "ProcessOutput(): no output (i_buffer_out == 0)" );\r
+#endif\r
+ p_out->vt->Release( (IUnknown *)p_out );\r
+ free( block_out.p_buffer );\r
+ return NULL;\r
+ }\r
+\r
+ if( p_dec->fmt_out.i_cat == VIDEO_ES )\r
+ {\r
+ /* Get a new picture */\r
+ picture_t *p_pic = p_dec->pf_vout_buffer_new( p_dec );\r
+ if( !p_pic ) return NULL;\r
+\r
+ CopyPicture( p_dec, p_pic, block_out.p_buffer );\r
+\r
+ /* Date management */\r
+ p_pic->date = aout_DateGet( &p_sys->end_date );\r
+ aout_DateIncrement( &p_sys->end_date, 1 );\r
+\r
+ p_out->vt->Release( (IUnknown *)p_out );\r
+ free( block_out.p_buffer );\r
+\r
+ return p_pic;\r
+ }\r
+ else\r
+ {\r
+ aout_buffer_t *p_aout_buffer;\r
+ int i_samples = i_buffer_out /\r
+ ( p_dec->fmt_in.audio.i_bitspersample *\r
+ p_dec->fmt_in.audio.i_channels / 8 );\r
+\r
+ p_aout_buffer = p_dec->pf_aout_buffer_new( p_dec, i_samples );\r
+ memcpy( p_aout_buffer->p_buffer, p_buffer_out, i_buffer_out );\r
+\r
+ /* Date management */\r
+ p_aout_buffer->start_date = aout_DateGet( &p_sys->end_date );\r
+ p_aout_buffer->end_date =\r
+ aout_DateIncrement( &p_sys->end_date, i_samples );\r
+\r
+ p_out->vt->Release( (IUnknown *)p_out );\r
+ free( block_out.p_buffer );\r
+\r
+ return p_aout_buffer;\r
+ }\r
+\r
+ return NULL;\r
+}\r
+\r
+static void CopyPicture( decoder_t *p_dec, picture_t *p_pic, uint8_t *p_in )\r
+{\r
+ int i_plane, i_line, i_width, i_dst_stride;\r
+ uint8_t *p_dst, *p_src = p_in;\r
+\r
+ p_dst = p_pic->p[1].p_pixels;\r
+ p_pic->p[1].p_pixels = p_pic->p[2].p_pixels;\r
+ p_pic->p[2].p_pixels = p_dst;\r
+\r
+ for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )\r
+ {\r
+ p_dst = p_pic->p[i_plane].p_pixels;\r
+ i_width = p_pic->p[i_plane].i_visible_pitch;\r
+ i_dst_stride = p_pic->p[i_plane].i_pitch;\r
+\r
+ p_src += i_width;\r
+\r
+ for( i_line = 0; i_line < p_pic->p[i_plane].i_lines; i_line++ )\r
+ {\r
+ p_dec->p_vlc->pf_memcpy( p_dst, p_src, i_width );\r
+ p_src += i_width;\r
+ p_dst += i_dst_stride;\r
+ }\r
+ }\r
+\r
+ p_dst = p_pic->p[1].p_pixels;\r
+ p_pic->p[1].p_pixels = p_pic->p[2].p_pixels;\r
+ p_pic->p[2].p_pixels = p_dst;\r
+}\r
--- /dev/null
+/*****************************************************************************\r
+ * dmo.h : DirectMedia Object codec module for vlc\r
+ *****************************************************************************\r
+ * Copyright (C) 2002, 2003 VideoLAN\r
+ * $Id$\r
+ *\r
+ * Author: Gildas Bazin <gbazin@videolan.org>\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.\r
+ *****************************************************************************/\r
+\r
+static const GUID IID_IUnknown = {0x00000000, 0x0000, 0x0000, {0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46}};\r
+static const GUID IID_IMediaObject = {0xd8ad0f58, 0x5494, 0x4102, {0x97, 0xc5, 0xec, 0x79, 0x8e, 0x59, 0xbc, 0xf4}};\r
+static const GUID IID_IMediaBuffer = {0x59eff8b9, 0x938c, 0x4a26, {0x82, 0xf2, 0x95, 0xcb, 0x84, 0xcd, 0xc8, 0x37}};\r
+static const GUID MEDIATYPE_Video = {0x73646976, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};\r
+static const GUID MEDIATYPE_Audio = {0x73647561, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};\r
+static const GUID MEDIASUBTYPE_PCM = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};\r
+static const GUID MEDIASUBTYPE_VideoInfo = {0x05589f80, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}};\r
+static const GUID FORMAT_WaveFormatEx = {0x05589f81, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}};\r
+static const GUID GUID_NULL = {0x0000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};\r
+static const GUID MEDIASUBTYPE_I420 = {0x30323449, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};\r
+static const GUID MEDIASUBTYPE_YV12 = {0x32315659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};\r
+\r
+#ifdef WIN32\r
+# define IUnknown IUnknownHack\r
+#endif\r
+typedef struct _IUnknown IUnknown;\r
+typedef struct _IEnumDMO IEnumDMO;\r
+typedef struct _IMediaBuffer IMediaBuffer;\r
+typedef struct _IMediaObject IMediaObject;\r
+#ifndef STDCALL\r
+#define STDCALL __stdcall\r
+#endif\r
+\r
+#define DMO_INPUT_DATA_BUFFER_SYNCPOINT 1\r
+#define DMO_PROCESS_OUTPUT_DISCARD_WHEN_NO_BUFFER 1\r
+#define DMO_E_NOTACCEPTING 0x80040204\r
+\r
+/*\r
+ * DMO types definition\r
+ */\r
+typedef struct\r
+#ifdef HAVE_ATTRIBUTE_PACKED\r
+ __attribute__((__packed__))\r
+#endif\r
+ _DMO_PARTIAL_MEDIATYPE\r
+{\r
+ GUID type;\r
+ GUID subtype;\r
+\r
+} DMO_PARTIAL_MEDIATYPE;\r
+\r
+typedef struct\r
+#ifdef HAVE_ATTRIBUTE_PACKED\r
+ __attribute__((__packed__))\r
+#endif\r
+ _DMO_OUTPUT_DATA_BUFFER\r
+{\r
+ IMediaBuffer *pBuffer;\r
+ uint32_t dwStatus;\r
+ REFERENCE_TIME rtTimestamp;\r
+ REFERENCE_TIME rtTimelength;\r
+\r
+} DMO_OUTPUT_DATA_BUFFER;\r
+\r
+typedef struct\r
+#ifdef HAVE_ATTRIBUTE_PACKED\r
+ __attribute__((__packed__))\r
+#endif\r
+ _DMOMediaType\r
+{\r
+ GUID majortype;\r
+ GUID subtype;\r
+ int bFixedSizeSamples;\r
+ int bTemporalCompression;\r
+ uint32_t lSampleSize;\r
+ GUID formattype;\r
+ IUnknown *pUnk;\r
+ uint32_t cbFormat;\r
+ char *pbFormat;\r
+\r
+} DMO_MEDIA_TYPE;\r
+\r
+/*\r
+ * IUnknown interface\r
+ */\r
+typedef struct IUnknown_vt\r
+{\r
+ /* IUnknown methods */\r
+ long (STDCALL *QueryInterface)(IUnknown *This, const GUID *riid,\r
+ void **ppvObject);\r
+ long (STDCALL *AddRef)(IUnknown *This);\r
+ long (STDCALL *Release)(IUnknown *This);\r
+\r
+} IUnknown_vt;\r
+struct _IUnknown { IUnknown_vt* vt; };\r
+\r
+/*\r
+ * IEnumDMO interface\r
+ */\r
+typedef struct IEnumDMO_vt\r
+{\r
+ /* IUnknown methods */\r
+ long (STDCALL *QueryInterface)(IUnknown *This, const GUID *riid,\r
+ void **ppvObject);\r
+ long (STDCALL *AddRef)(IUnknown *This);\r
+ long (STDCALL *Release)(IUnknown *This);\r
+\r
+ /* IEnumDMO methods */\r
+ long (STDCALL *Next)(IEnumDMO *This, uint32_t cItemsToFetch,\r
+ const GUID *pCLSID, WCHAR **Names,\r
+ uint32_t *pcItemsFetched);\r
+ long (STDCALL *Skip)(IEnumDMO *This, uint32_t cItemsToSkip);\r
+ long (STDCALL *Reset)(IEnumDMO *This);\r
+ long (STDCALL *Clone)(IEnumDMO *This, IEnumDMO **ppEnum);\r
+\r
+} IEnumDMO_vt;\r
+struct _IEnumDMO { IEnumDMO_vt* vt; };\r
+\r
+/*\r
+ * IMediaBuffer interface\r
+ */\r
+typedef struct IMediaBuffer_vt\r
+{\r
+ /* IUnknown methods */\r
+ long (STDCALL *QueryInterface)(IUnknown *This, const GUID *riid,\r
+ void **ppvObject);\r
+ long (STDCALL *AddRef)(IUnknown *This);\r
+ long (STDCALL *Release)(IUnknown *This);\r
+\r
+ long (STDCALL *SetLength)(IMediaBuffer* This, uint32_t cbLength);\r
+ long (STDCALL *GetMaxLength)(IMediaBuffer* This, uint32_t *pcbMaxLength);\r
+ long (STDCALL *GetBufferAndLength)(IMediaBuffer* This,\r
+ char** ppBuffer, uint32_t* pcbLength);\r
+\r
+} IMediaBuffer_vt;\r
+struct _IMediaBuffer { IMediaBuffer_vt* vt; };\r
+\r
+/*\r
+ * IMediaObject interface\r
+ */\r
+typedef struct IMediaObject_vt\r
+{\r
+ /* IUnknown methods */\r
+ long (STDCALL *QueryInterface)(IUnknown *This, const GUID *riid,\r
+ void **ppvObject);\r
+ long (STDCALL *AddRef)(IUnknown *This);\r
+ long (STDCALL *Release)(IUnknown *This);\r
+\r
+ /* IEnumDMO methods */\r
+ long (STDCALL *GetStreamCount)(IMediaObject *This,\r
+ uint32_t *pcInputStreams,\r
+ uint32_t *pcOutputStreams);\r
+ long (STDCALL *GetInputStreamInfo)(IMediaObject *This,\r
+ uint32_t dwInputStreamIndex,\r
+ uint32_t *pdwFlags);\r
+ long (STDCALL *GetOutputStreamInfo)(IMediaObject *This,\r
+ uint32_t dwOutputStreamIndex,\r
+ uint32_t *pdwFlags);\r
+ long (STDCALL *GetInputType)(IMediaObject *This,\r
+ uint32_t dwInputStreamIndex,\r
+ uint32_t dwTypeIndex,\r
+ DMO_MEDIA_TYPE *pmt);\r
+ long (STDCALL *GetOutputType)(IMediaObject *This,\r
+ uint32_t dwOutputStreamIndex,\r
+ uint32_t dwTypeIndex,\r
+ DMO_MEDIA_TYPE *pmt);\r
+ long (STDCALL *SetInputType)(IMediaObject *This,\r
+ uint32_t dwInputStreamIndex,\r
+ const DMO_MEDIA_TYPE *pmt,\r
+ uint32_t dwFlags);\r
+ long (STDCALL *SetOutputType)(IMediaObject *This,\r
+ uint32_t dwOutputStreamIndex,\r
+ const DMO_MEDIA_TYPE *pmt,\r
+ uint32_t dwFlags);\r
+ long (STDCALL *GetInputCurrentType)(IMediaObject *This,\r
+ uint32_t dwInputStreamIndex,\r
+ DMO_MEDIA_TYPE *pmt);\r
+ long (STDCALL *GetOutputCurrentType)(IMediaObject *This,\r
+ uint32_t dwOutputStreamIndex,\r
+ DMO_MEDIA_TYPE *pmt);\r
+ long (STDCALL *GetInputSizeInfo)(IMediaObject *This,\r
+ uint32_t dwInputStreamIndex,\r
+ uint32_t *pcbSize,\r
+ uint32_t *pcbMaxLookahead,\r
+ uint32_t *pcbAlignment);\r
+ long (STDCALL *GetOutputSizeInfo)(IMediaObject *This,\r
+ uint32_t dwOutputStreamIndex,\r
+ uint32_t *pcbSize,\r
+ uint32_t *pcbAlignment);\r
+ long (STDCALL *GetInputMaxLatency)(IMediaObject *This,\r
+ uint32_t dwInputStreamIndex,\r
+ REFERENCE_TIME *prtMaxLatency);\r
+ long (STDCALL *SetInputMaxLatency)(IMediaObject *This,\r
+ uint32_t dwInputStreamIndex,\r
+ REFERENCE_TIME rtMaxLatency);\r
+ long (STDCALL *Flush)(IMediaObject * This);\r
+ long (STDCALL *Discontinuity)(IMediaObject *This,\r
+ uint32_t dwInputStreamIndex);\r
+ long (STDCALL *AllocateStreamingResources)(IMediaObject * This);\r
+ long (STDCALL *FreeStreamingResources)(IMediaObject * This);\r
+ long (STDCALL *GetInputStatus)(IMediaObject *This,\r
+ uint32_t dwInputStreamIndex,\r
+ uint32_t *dwFlags);\r
+ long (STDCALL *ProcessInput)(IMediaObject *This,\r
+ uint32_t dwInputStreamIndex,\r
+ IMediaBuffer *pBuffer,\r
+ uint32_t dwFlags,\r
+ REFERENCE_TIME rtTimestamp,\r
+ REFERENCE_TIME rtTimelength);\r
+ long (STDCALL *ProcessOutput)(IMediaObject *This,\r
+ uint32_t dwFlags,\r
+ uint32_t cOutputBufferCount,\r
+ DMO_OUTPUT_DATA_BUFFER *pOutputBuffers,\r
+ uint32_t *pdwStatus);\r
+ long (STDCALL *Lock)(IMediaObject *This, long bLock);\r
+\r
+} IMediaObject_vt;\r
+struct _IMediaObject { IMediaObject_vt* vt; };\r
+\r
+/* Implementation of IMediaBuffer */\r
+typedef struct _CMediaBuffer\r
+{\r
+ IMediaBuffer_vt *vt;\r
+ int i_ref;\r
+ block_t *p_block;\r
+ int i_max_size;\r
+ vlc_bool_t b_own;\r
+\r
+} CMediaBuffer;\r
+\r
+CMediaBuffer *CMediaBufferCreate( block_t *, int, vlc_bool_t );\r