X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Fquicktime.c;h=1afe697d1f3d019d23bd043d1fc14a894bfcd1a3;hb=6ee1e193fd896ab9a4729fde14f009d9ce629815;hp=177ce446b1964be2c534405c4dc1747d2fefbc2e;hpb=20da59b56469323dc7493860eab104f3c5fb7280;p=vlc diff --git a/modules/codec/quicktime.c b/modules/codec/quicktime.c index 177ce446b1..1afe697d1f 100644 --- a/modules/codec/quicktime.c +++ b/modules/codec/quicktime.c @@ -1,8 +1,8 @@ /***************************************************************************** * quicktime.c: a quicktime decoder that uses the QT library/dll ***************************************************************************** - * Copyright (C) 2003 VideoLAN - * $Id: quicktime.c,v 1.19 2003/11/23 22:18:08 hartman Exp $ + * Copyright (C) 2003 the VideoLAN team + * $Id$ * * Authors: Laurent Aimar * Derk-Jan Hartman @@ -19,7 +19,7 @@ * * 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. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -27,11 +27,15 @@ *****************************************************************************/ #include -#include -#include -#include +#include +#include +#include -#ifdef SYS_DARWIN +#if !defined (__APPLE__) && !defined(WIN32) +# define LOADER 1 +#endif + +#ifdef __APPLE__ #include #include #include @@ -39,9 +43,9 @@ /* for windows do we require Quicktime compents header? */ #ifdef LOADER -#include "w32dll/loader/qtx/qtxsdk/components.h" -#include "w32dll/loader/wine/windef.h" -#include "w32dll/loader/ldt_keeper.h" +#include "qtx/qtxsdk/components.h" +#include "wine/windef.h" +#include "ldt_keeper.h" HMODULE WINAPI LoadLibraryA(LPCSTR); FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR); @@ -58,10 +62,10 @@ static void Close( vlc_object_t * ); vlc_module_begin(); set_description( _("QuickTime library decoder") ); set_capability( "decoder", 10 ); + set_category( CAT_INPUT ); + set_subcategory( SUBCAT_INPUT_VCODEC ); set_callbacks( Open, Close ); - /* create a mutex */ - var_Create( p_module->p_libvlc, "qt_mutex", VLC_VAR_MUTEX ); vlc_module_end(); @@ -77,7 +81,7 @@ static picture_t *DecodeVideo( decoder_t *, block_t ** ); #define FCC( a, b , c, d ) \ ((uint32_t)( ((a)<<24)|((b)<<16)|((c)<<8)|(d))) -#ifndef SYS_DARWIN +#ifndef __APPLE__ typedef struct OpaqueSoundConverter* SoundConverter; #ifndef LOADER typedef long OSType; @@ -97,20 +101,21 @@ typedef struct SoundComponentData { long reserved; } SoundComponentData; -#endif /* SYS_DARWIN */ +#endif /* __APPLE__ */ struct decoder_sys_t { /* library */ -#ifndef SYS_DARWIN +#ifndef __APPLE__ #ifdef LOADER ldt_fs_t *ldt_fs; - #endif /* LOADER */ + HMODULE qtml; + HINSTANCE qts; OSErr (*InitializeQTML) ( long flags ); OSErr (*TerminateQTML) ( void ); -#endif /* SYS_DARWIN */ +#endif /* __APPLE__ */ /* Audio */ int (*SoundConverterOpen) ( const SoundComponentData *, @@ -130,10 +135,11 @@ struct decoder_sys_t SoundConverter myConverter; SoundComponentData InputFormatInfo, OutputFormatInfo; - long FramesToGet; + unsigned long FramesToGet; unsigned int InFrameSize; unsigned int OutFrameSize; +#ifndef WIN32 /* Video */ Component (*FindNextComponent) ( Component prev, ComponentDescription* desc ); @@ -172,7 +178,7 @@ struct decoder_sys_t CodecDecompressParams decpar; /* for ImageCodecPreDecompress()*/ CodecCapabilities codeccap; /* for decpar */ - +#endif /* Output properties */ uint8_t * plane; @@ -215,11 +221,14 @@ static int QTVideoInit( decoder_t * ); static int Open( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; + if( var_GetGlobalMutex( "qt_mutex" ) == NULL ) + return VLC_EGENERIC; + /* create a mutex */ switch( p_dec->fmt_in.i_codec ) { case VLC_FOURCC('S','V','Q','3'): /* Sorenson v3 */ - /* case VLC_FOURCC('S','V','Q','1'): Sorenson v1 + /* case VLC_FOURCC('S','V','Q','1'): Sorenson v1 case VLC_FOURCC('Z','y','G','o'): case VLC_FOURCC('V','P','3','1'): case VLC_FOURCC('3','I','V','1'): */ @@ -275,15 +284,11 @@ static void Close( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys = p_dec->p_sys; - vlc_value_t lockval; + vlc_mutex_t *lock; /* get lock, avoid segfault */ - var_Get( p_dec->p_libvlc, "qt_mutex", &lockval ); - vlc_mutex_lock( lockval.p_address ); -#ifdef SYS_DARWIN - /* on OS X QT is not threadsafe */ - vlc_mutex_lock( &p_dec->p_vlc->quicktime_lock ); -#endif + lock = var_GetGlobalMutex( "qt_mutex" ); + vlc_mutex_lock( lock ); if( p_dec->fmt_out.i_cat == AUDIO_ES ) { @@ -306,12 +311,11 @@ static void Close( vlc_object_t *p_this ) free( p_sys->plane ); } -#ifndef SYS_DARWIN +#ifndef __APPLE__ FreeLibrary( p_sys->qtml ); + FreeLibrary( p_sys->qts ); msg_Dbg( p_dec, "FreeLibrary ok." ); -#endif - -#ifdef SYS_DARWIN +#else ExitMovies(); #endif @@ -323,12 +327,9 @@ static void Close( vlc_object_t *p_this ) #endif #endif -#ifdef SYS_DARWIN - vlc_mutex_unlock( &p_dec->p_vlc->quicktime_lock ); -#endif - vlc_mutex_unlock( lockval.p_address ); + vlc_mutex_unlock( lock ); - free( p_sys ); + if( p_sys ) free( p_sys ); } /***************************************************************************** @@ -336,31 +337,28 @@ static void Close( vlc_object_t *p_this ) *****************************************************************************/ static int OpenAudio( decoder_t *p_dec ) { - decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) ); + decoder_sys_t *p_sys; + vlc_mutex_t *lock = var_GetGlobalMutex( "qt_mutex" ); - vlc_value_t lockval; int i_error; char fcc[4]; unsigned long WantedBufferSize; unsigned long InputBufferSize = 0; unsigned long OutputBufferSize = 0; - memset( p_sys, 0, sizeof( decoder_sys_t ) ); + 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 ); /* get lock, avoid segfault */ - var_Get( p_dec->p_libvlc, "qt_mutex", &lockval ); - vlc_mutex_lock( lockval.p_address ); -#ifdef SYS_DARWIN - /* on OS X QT is not threadsafe */ - vlc_mutex_lock( &p_dec->p_vlc->quicktime_lock ); -#endif + vlc_mutex_lock( lock ); -#ifdef SYS_DARWIN +#ifdef __APPLE__ EnterMovies(); #endif @@ -370,10 +368,10 @@ static int OpenAudio( decoder_t *p_dec ) goto exit_error; } -#ifndef SYS_DARWIN +#ifndef __APPLE__ if( ( i_error = p_sys->InitializeQTML( 6 + 16 ) ) ) { - msg_Dbg( p_dec, "error while InitializeQTML = %d", i_error ); + msg_Dbg( p_dec, "error on InitializeQTML = %d", i_error ); goto exit_error; } #endif @@ -404,7 +402,7 @@ static int OpenAudio( decoder_t *p_dec ) &p_sys->myConverter ); if( i_error ) { - msg_Err( p_dec, "error while SoundConverterOpen = %d", i_error ); + msg_Err( p_dec, "error on SoundConverterOpen = %d", i_error ); goto exit_error; } @@ -420,7 +418,7 @@ static int OpenAudio( decoder_t *p_dec ) FCC( 'w', 'a', 'v', 'e' ), ((uint8_t*)p_dec->fmt_in.p_extra) + 36 + 8 ); - msg_Dbg( p_dec, "error while SoundConverterSetInfo = %d", i_error ); + msg_Dbg( p_dec, "error on SoundConverterSetInfo = %d", i_error ); } WantedBufferSize = p_sys->OutputFormatInfo.numChannels * @@ -448,7 +446,7 @@ static int OpenAudio( decoder_t *p_dec ) if( (i_error = p_sys->SoundConverterBeginConversion(p_sys->myConverter)) ) { msg_Err( p_dec, - "error while SoundConverterBeginConversion = %d", i_error ); + "error on SoundConverterBeginConversion = %d", i_error ); goto exit_error; } @@ -469,10 +467,7 @@ static int OpenAudio( decoder_t *p_dec ) p_sys->i_out = 0; p_sys->i_out_frames = 0; -#ifdef SYS_DARWIN - vlc_mutex_unlock( &p_dec->p_vlc->quicktime_lock ); -#endif - vlc_mutex_unlock( lockval.p_address ); + vlc_mutex_unlock( lock ); return VLC_SUCCESS; exit_error: @@ -480,10 +475,9 @@ exit_error: #ifdef LOADER Restore_LDT_Keeper( p_sys->ldt_fs ); #endif -#ifdef SYS_DARWIN - vlc_mutex_unlock( &p_dec->p_vlc->quicktime_lock ); -#endif - vlc_mutex_unlock( lockval.p_address ); + vlc_mutex_unlock( lock ); + + free( p_sys ); return VLC_EGENERIC; } @@ -494,7 +488,6 @@ static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block ) { decoder_sys_t *p_sys = p_dec->p_sys; - vlc_value_t lockval; block_t *p_block; int i_error; @@ -552,17 +545,17 @@ static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block ) if( p_sys->i_buffer > p_sys->InFrameSize ) { int i_frames = p_sys->i_buffer / p_sys->InFrameSize; - long i_out_frames, i_out_bytes; + unsigned long i_out_frames, i_out_bytes; + vlc_mutex_t *lock = var_GetGlobalMutex( "qt_mutex "); - var_Get( p_dec->p_libvlc, "qt_mutex", &lockval ); - vlc_mutex_lock( lockval.p_address ); + vlc_mutex_lock( lock ); 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( lockval.p_address ); + vlc_mutex_unlock( lock ); /* msg_Dbg( p_dec, "decoded %d frames -> %ld frames (error=%d)", @@ -630,7 +623,8 @@ static int OpenVideo( decoder_t *p_dec ) { decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) ); - vlc_value_t lockval; +#ifndef WIN32 + vlc_mutex_t *lock; long i_result; ComponentDescription desc; Component prev; @@ -659,10 +653,10 @@ static int OpenVideo( decoder_t *p_dec ) fcc, p_dec->fmt_in.video.i_width, p_dec->fmt_in.video.i_height ); /* get lock, avoid segfault */ - var_Get( p_dec->p_libvlc, "qt_mutex", &lockval ); - vlc_mutex_lock( lockval.p_address ); + lock = var_GetGlobalMutex( "qt_mutex" ); + vlc_mutex_lock( lock ); -#ifdef SYS_DARWIN +#ifdef __APPLE__ EnterMovies(); #endif @@ -672,10 +666,10 @@ static int OpenVideo( decoder_t *p_dec ) goto exit_error; } -#ifndef SYS_DARWIN +#ifndef __APPLE__ if( ( i_result = p_sys->InitializeQTML( 6 + 16 ) ) ) { - msg_Dbg( p_dec, "error while InitializeQTML = %d", (int)i_result ); + msg_Dbg( p_dec, "error on InitializeQTML = %d", (int)i_result ); goto exit_error; } #endif @@ -700,13 +694,16 @@ static int OpenVideo( decoder_t *p_dec ) memset( &icap, 0, sizeof( ImageSubCodecDecompressCapabilities ) ); cres = p_sys->ImageCodecInitialize( p_sys->ci, &icap ); -/* msg_Dbg( p_dec->p_fifo, "ImageCodecInitialize->%p size=%d (%d)\n",cres,icap.recordSize,icap.decompressRecordSize); */ + msg_Dbg( p_dec, "ImageCodecInitialize->0x%X size=%d (%d)\n", + (int)cres, (int)icap.recordSize, (int)icap.decompressRecordSize); memset( &cinfo, 0, sizeof( CodecInfo ) ); cres = p_sys->ImageCodecGetCodecInfo( p_sys->ci, &cinfo ); msg_Dbg( p_dec, - "Flags: compr: 0x%lx decomp: 0x%lx format: 0x%lx\n", - cinfo.compressFlags, cinfo.decompressFlags, cinfo.formatFlags ); + "Flags: compr: 0x%x decomp: 0x%x format: 0x%x\n", + (unsigned int)cinfo.compressFlags, + (unsigned int)cinfo.decompressFlags, + (unsigned int)cinfo.formatFlags ); msg_Dbg( p_dec, "quicktime_video: Codec name: %.*s\n", ((unsigned char*)&cinfo.typeName)[0], ((unsigned char*)&cinfo.typeName)+1 ); @@ -742,18 +739,18 @@ static int OpenVideo( decoder_t *p_dec ) memcpy( ((char*)&id->clutID) + 2, p_vide + 70, i_vide - 70 ); } - msg_Dbg( p_dec, "idSize=%ld ver=%d rev=%d vendor=%ld tempQ=%d " - "spaQ=%d w=%d h=%d dpi=%d%d dataSize=%d frameCount=%d clutID=%d", - id->idSize, id->version, id->revisionLevel, id->vendor, + msg_Dbg( p_dec, "idSize=%d ver=%d rev=%d vendor=%d tempQ=%d " + "spaQ=%d w=%d h=%d dpi=%d%d dataSize=%d depth=%d frameCount=%d clutID=%d", + (int)id->idSize, id->version, id->revisionLevel, (int)id->vendor, (int)id->temporalQuality, (int)id->spatialQuality, - id->width, id->height, + (int)id->width, (int)id->height, (int)id->hRes, (int)id->vRes, (int)id->dataSize, + id->depth, id->frameCount, id->clutID ); - p_sys->framedescHandle = - (ImageDescriptionHandle) p_sys->NewHandleClear( id->idSize ); + p_sys->framedescHandle = (ImageDescriptionHandle) NewHandleClear( id->idSize ); memcpy( *p_sys->framedescHandle, id, id->idSize ); p_sys->plane = malloc( p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 3 ); @@ -789,29 +786,33 @@ static int OpenVideo( decoder_t *p_dec ) msg_Dbg( p_dec, "quicktime_video: ImageCodecPreDecompress cres=0x%X\n", (int)cres ); - p_dec->fmt_out.i_codec = VLC_FOURCC( 'Y', 'U', 'Y', '2' ); + es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_FOURCC( 'Y', 'U', 'Y', '2' )); 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_aspect = VOUT_ASPECT_FACTOR * p_dec->fmt_in.video.i_width / p_dec->fmt_in.video.i_height; - - - vlc_mutex_unlock( lockval.p_address ); + + vlc_mutex_unlock( lock ); return VLC_SUCCESS; exit_error: #ifdef LOADER Restore_LDT_Keeper( p_sys->ldt_fs ); #endif - vlc_mutex_unlock( lockval.p_address ); + vlc_mutex_unlock( lock ); + +#endif /* !WIN32 */ + return VLC_EGENERIC; } +#ifndef WIN32 /***************************************************************************** * DecodeVideo: *****************************************************************************/ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) { decoder_sys_t *p_sys = p_dec->p_sys; + vlc_mutex_t *lock; block_t *p_block; picture_t *p_pic; mtime_t i_pts; @@ -839,7 +840,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) } p_block = *pp_block; *pp_block = NULL; - + i_pts = p_block->i_pts ? p_block->i_pts : p_block->i_dts; if( i_pts < mdate() ) @@ -850,6 +851,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) { p_sys->i_late = 0; } + msg_Dbg( p_dec, "bufsize: %d", p_block->i_buffer); if( p_sys->i_late > 10 ) { @@ -857,19 +859,17 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) block_Release( p_block ); return NULL; } + + lock = var_GetGlobalMutex( "qt_mutex" ); + vlc_mutex_lock( lock ); if( ( p_pic = p_dec->pf_vout_buffer_new( p_dec ) ) ) { - vlc_value_t lockval; - - p_sys->decpar.data = p_block->p_buffer; + p_sys->decpar.data = (Ptr)p_block->p_buffer; p_sys->decpar.bufferSize = p_block->i_buffer; (**p_sys->framedescHandle).dataSize = p_block->i_buffer; - var_Get( p_dec->p_libvlc, "qt_mutex", &lockval ); - vlc_mutex_lock( lockval.p_address ); cres = p_sys->ImageCodecBandDecompress( p_sys->ci, &p_sys->decpar ); - vlc_mutex_unlock( lockval.p_address ); ++p_sys->decpar.frameNumber; @@ -884,10 +884,13 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 2 ); p_pic->date = i_pts; } - block_Release( p_block ); + + vlc_mutex_unlock( lock ); + block_Release( p_block ); return p_pic; } +#endif /* !WIN32 */ /***************************************************************************** * QTAudioInit: @@ -896,7 +899,7 @@ static int QTAudioInit( decoder_t *p_dec ) { decoder_sys_t *p_sys = p_dec->p_sys; -#ifdef SYS_DARWIN +#ifdef __APPLE__ p_sys->SoundConverterOpen = (void*)SoundConverterOpen; p_sys->SoundConverterClose = (void*)SoundConverterClose; p_sys->SoundConverterSetInfo = (void*)SoundConverterSetInfo; @@ -910,6 +913,12 @@ static int QTAudioInit( decoder_t *p_dec ) p_sys->ldt_fs = Setup_LDT_Keeper(); #endif /* LOADER */ + p_sys->qts = LoadLibraryA( "QuickTime.qts" ); + if( p_sys->qts == NULL ) + { + msg_Dbg( p_dec, "failed loading QuickTime.qts" ); + return VLC_EGENERIC; + } p_sys->qtml = LoadLibraryA( "qtmlClient.dll" ); if( p_sys->qtml == NULL ) { @@ -929,7 +938,7 @@ static int QTAudioInit( decoder_t *p_dec ) if( p_sys->InitializeQTML == NULL ) { - msg_Err( p_dec, "failed geting proc address InitializeQTML" ); + msg_Err( p_dec, "failed getting proc address InitializeQTML" ); return VLC_EGENERIC; } if( p_sys->SoundConverterOpen == NULL || @@ -940,17 +949,17 @@ static int QTAudioInit( decoder_t *p_dec ) p_sys->SoundConverterEndConversion == NULL || p_sys->SoundConverterBeginConversion == NULL ) { - msg_Err( p_dec, "failed geting proc address" ); + msg_Err( p_dec, "failed getting proc address" ); return VLC_EGENERIC; } - msg_Dbg( p_dec, "Standard init done" ); -#endif /* else SYS_DARWIN */ + msg_Dbg( p_dec, "standard init done" ); +#endif /* else __APPLE__ */ return VLC_SUCCESS; } - +#ifndef WIN32 /***************************************************************************** * QTVideoInit: *****************************************************************************/ @@ -958,7 +967,7 @@ static int QTVideoInit( decoder_t *p_dec ) { decoder_sys_t *p_sys = p_dec->p_sys; -#ifdef SYS_DARWIN +#ifdef __APPLE__ p_sys->FindNextComponent = (void*)FindNextComponent; p_sys->OpenComponent = (void*)OpenComponent; p_sys->ImageCodecInitialize = (void*)ImageCodecInitialize; @@ -973,6 +982,13 @@ static int QTVideoInit( decoder_t *p_dec ) #ifdef LOADER p_sys->ldt_fs = Setup_LDT_Keeper(); #endif /* LOADER */ + p_sys->qts = LoadLibraryA( "QuickTime.qts" ); + if( p_sys->qts == NULL ) + { + msg_Dbg( p_dec, "failed loading QuickTime.qts" ); + return VLC_EGENERIC; + } + msg_Dbg( p_dec, "QuickTime.qts loaded" ); p_sys->qtml = LoadLibraryA( "qtmlClient.dll" ); if( p_sys->qtml == NULL ) { @@ -995,7 +1011,7 @@ static int QTVideoInit( decoder_t *p_dec ) if( p_sys->InitializeQTML == NULL ) { - msg_Dbg( p_dec, "failed geting proc address InitializeQTML" ); + msg_Dbg( p_dec, "failed getting proc address InitializeQTML" ); return VLC_EGENERIC; } if( p_sys->FindNextComponent == NULL || @@ -1008,12 +1024,11 @@ static int QTVideoInit( decoder_t *p_dec ) p_sys->QTNewGWorldFromPtr == NULL || p_sys->NewHandleClear == NULL ) { - msg_Err( p_dec, "failed geting proc address" ); + msg_Err( p_dec, "failed getting proc address" ); return VLC_EGENERIC; } -#endif /* SYS_DARWIN */ +#endif /* __APPLE__ */ return VLC_SUCCESS; } - - +#endif /* !WIN32 */