1 /*****************************************************************************
2 * quicktime.c: a quicktime decoder that uses the QT library/dll
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir at via.ecp.fr>
8 * Derk-Jan Hartman <thedj at users.sf.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc/decoder.h>
34 #if !defined (SYS_DARWIN) && !defined(WIN32)
39 #include <QuickTime/QuickTimeComponents.h>
40 #include <QuickTime/Movies.h>
41 #include <QuickTime/ImageCodec.h>
44 /* for windows do we require Quicktime compents header? */
46 #include "qtx/qtxsdk/components.h"
47 #include "wine/windef.h"
48 #include "ldt_keeper.h"
50 HMODULE WINAPI LoadLibraryA(LPCSTR);
51 FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR);
52 int WINAPI FreeLibrary(HMODULE);
56 /*****************************************************************************
58 *****************************************************************************/
59 static int Open ( vlc_object_t * );
60 static void Close( vlc_object_t * );
63 set_description( _("QuickTime library decoder") );
64 set_capability( "decoder", 10 );
65 set_category( CAT_INPUT );
66 set_subcategory( SUBCAT_INPUT_VCODEC );
67 set_callbacks( Open, Close );
70 var_Create( p_module->p_libvlc, "qt_mutex", VLC_VAR_MUTEX );
74 /*****************************************************************************
76 *****************************************************************************/
77 static int OpenAudio( decoder_t * );
78 static int OpenVideo( decoder_t * );
80 static aout_buffer_t *DecodeAudio( decoder_t *, block_t ** );
81 static picture_t *DecodeVideo( decoder_t *, block_t ** );
83 #define FCC( a, b , c, d ) \
84 ((uint32_t)( ((a)<<24)|((b)<<16)|((c)<<8)|(d)))
87 typedef struct OpaqueSoundConverter* SoundConverter;
92 typedef unsigned long UnsignedFixed;
95 typedef struct SoundComponentData {
100 UnsignedFixed sampleRate;
104 } SoundComponentData;
106 #endif /* SYS_DARWIN */
117 OSErr (*InitializeQTML) ( long flags );
118 OSErr (*TerminateQTML) ( void );
119 #endif /* SYS_DARWIN */
122 int (*SoundConverterOpen) ( const SoundComponentData *,
123 const SoundComponentData *,
125 int (*SoundConverterClose) ( SoundConverter );
126 int (*SoundConverterSetInfo) ( SoundConverter , OSType, void * );
127 int (*SoundConverterGetBufferSizes) ( SoundConverter, unsigned long,
128 unsigned long*, unsigned long*,
130 int (*SoundConverterBeginConversion)( SoundConverter );
131 int (*SoundConverterEndConversion) ( SoundConverter, void *,
132 unsigned long *, unsigned long *);
133 int (*SoundConverterConvertBuffer) ( SoundConverter, const void *,
134 unsigned long, void *,
135 unsigned long *, unsigned long * );
136 SoundConverter myConverter;
137 SoundComponentData InputFormatInfo, OutputFormatInfo;
140 unsigned int InFrameSize;
141 unsigned int OutFrameSize;
145 Component (*FindNextComponent)
146 ( Component prev, ComponentDescription* desc );
148 ComponentInstance (*OpenComponent)
151 ComponentResult (*ImageCodecInitialize)
152 ( ComponentInstance ci, ImageSubCodecDecompressCapabilities * cap);
154 ComponentResult (*ImageCodecGetCodecInfo)
155 ( ComponentInstance ci, CodecInfo *info );
157 ComponentResult (*ImageCodecPreDecompress)
158 ( ComponentInstance ci, CodecDecompressParams * params );
160 ComponentResult (*ImageCodecBandDecompress)
161 ( ComponentInstance ci, CodecDecompressParams * params );
163 PixMapHandle (*GetGWorldPixMap)
164 ( GWorldPtr offscreenGWorld );
166 OSErr (*QTNewGWorldFromPtr)
167 ( GWorldPtr *gw, OSType pixelFormat, const Rect *boundsRect,
168 CTabHandle cTable, /*GDHandle*/ void *aGDevice, /*unused*/
169 GWorldFlags flags, void *baseAddr, long rowBytes );
171 OSErr (*NewHandleClear)( Size byteCount );
173 ComponentInstance ci;
174 Rect OutBufferRect; /* the dimensions of our GWorld */
175 GWorldPtr OutBufferGWorld; /* a GWorld is some kind of
176 description for a drawing
178 ImageDescriptionHandle framedescHandle;
180 CodecDecompressParams decpar; /* for ImageCodecPreDecompress()*/
181 CodecCapabilities codeccap; /* for decpar */
184 /* Output properties */
189 int i_late; /* video */
192 unsigned int i_buffer;
193 unsigned int i_buffer_size;
197 uint8_t out_buffer[1000000]; /* FIXME */
202 static int pi_channels_maps[6] =
206 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
207 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER,
208 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT,
209 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
210 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT
213 static int QTAudioInit( decoder_t * );
214 static int QTVideoInit( decoder_t * );
216 /*****************************************************************************
217 * Open: probe the decoder and return score
218 *****************************************************************************
219 * Tries to launch a decoder and return score so that the interface is able
221 *****************************************************************************/
222 static int Open( vlc_object_t *p_this )
224 decoder_t *p_dec = (decoder_t*)p_this;
226 switch( p_dec->fmt_in.i_codec )
228 case VLC_FOURCC('S','V','Q','3'): /* Sorenson v3 */
229 /* case VLC_FOURCC('S','V','Q','1'): Sorenson v1
230 case VLC_FOURCC('Z','y','G','o'):
231 case VLC_FOURCC('V','P','3','1'):
232 case VLC_FOURCC('3','I','V','1'): */
233 case VLC_FOURCC('r','l','e',' '): /* QuickTime animation (RLE) */
234 case VLC_FOURCC('r','p','z','a'): /* QuickTime Apple Video */
235 case VLC_FOURCC('a','z','p','r'): /* QuickTime animation (RLE) */
238 p_dec->pf_decode_video = DecodeVideo;
241 return OpenVideo( p_dec );
244 case VLC_FOURCC('s','a','m','r'): /* 3GPP AMR audio */
245 case VLC_FOURCC('m','p','4','a'): /* MPEG-4 audio */
246 case VLC_FOURCC('Q','D','M','C'): /* QDesign */
247 case VLC_FOURCC('Q','D','M','2'): /* QDesign* 2 */
248 case VLC_FOURCC('Q','c','l','p'): /* Qualcomm Purevoice Codec */
249 case VLC_FOURCC('Q','C','L','P'): /* Qualcomm Purevoice Codec */
250 case VLC_FOURCC('M','A','C','3'): /* MACE3 audio decoder */
251 case VLC_FOURCC('M','A','C','6'): /* MACE6 audio decoder */
252 case VLC_FOURCC('d','v','c','a'): /* DV Audio */
253 case VLC_FOURCC('s','o','w','t'): /* 16-bit Little Endian */
254 case VLC_FOURCC('t','w','o','s'): /* 16-bit Big Endian */
255 case VLC_FOURCC('a','l','a','w'): /* ALaw 2:1 */
256 case VLC_FOURCC('u','l','a','w'): /* mu-Law 2:1 */
257 case VLC_FOURCC('r','a','w',' '): /* 8-bit offset binaries */
258 case VLC_FOURCC('f','l','3','2'): /* 32-bit Floating Point */
259 case VLC_FOURCC('f','l','6','4'): /* 64-bit Floating Point */
260 case VLC_FOURCC('i','n','2','4'): /* 24-bit Interger */
261 case VLC_FOURCC('i','n','3','2'): /* 32-bit Integer */
262 case 0x0011: /* DVI IMA */
263 case 0x6D730002: /* Microsoft ADPCM-ACM */
264 case 0x6D730011: /* DVI Intel IMAADPCM-ACM */
267 p_dec->pf_decode_audio = DecodeAudio;
270 return OpenAudio( p_dec );
278 /*****************************************************************************
280 *****************************************************************************/
281 static void Close( vlc_object_t *p_this )
283 decoder_t *p_dec = (decoder_t*)p_this;
284 decoder_sys_t *p_sys = p_dec->p_sys;
287 /* get lock, avoid segfault */
288 var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
289 vlc_mutex_lock( lockval.p_address );
291 /* on OS X QT is not threadsafe */
292 vlc_mutex_lock( &p_dec->p_vlc->quicktime_lock );
295 if( p_dec->fmt_out.i_cat == AUDIO_ES )
298 unsigned long ConvertedFrames=0;
299 unsigned long ConvertedBytes=0;
301 i_error = p_sys->SoundConverterEndConversion( p_sys->myConverter, NULL,
304 msg_Dbg( p_dec, "SoundConverterEndConversion => %d", i_error );
306 i_error = p_sys->SoundConverterClose( p_sys->myConverter );
307 msg_Dbg( p_dec, "SoundConverterClose => %d", i_error );
309 free( p_sys->p_buffer );
311 else if( p_dec->fmt_out.i_cat == VIDEO_ES )
313 free( p_sys->plane );
317 FreeLibrary( p_sys->qtml );
318 msg_Dbg( p_dec, "FreeLibrary ok." );
328 Restore_LDT_Keeper( p_sys->ldt_fs );
329 msg_Dbg( p_dec, "Restore_LDT_Keeper" );
334 vlc_mutex_unlock( &p_dec->p_vlc->quicktime_lock );
336 vlc_mutex_unlock( lockval.p_address );
341 /*****************************************************************************
343 *****************************************************************************/
344 static int OpenAudio( decoder_t *p_dec )
346 decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );
351 unsigned long WantedBufferSize;
352 unsigned long InputBufferSize = 0;
353 unsigned long OutputBufferSize = 0;
355 memset( p_sys, 0, sizeof( decoder_sys_t ) );
357 p_dec->p_sys = p_sys;
358 p_dec->pf_decode_audio = DecodeAudio;
360 memcpy( fcc, &p_dec->fmt_in.i_codec, 4 );
362 /* get lock, avoid segfault */
363 var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
364 vlc_mutex_lock( lockval.p_address );
366 /* on OS X QT is not threadsafe */
367 vlc_mutex_lock( &p_dec->p_vlc->quicktime_lock );
374 if( QTAudioInit( p_dec ) )
376 msg_Err( p_dec, "cannot initialize QT");
381 if( ( i_error = p_sys->InitializeQTML( 6 + 16 ) ) )
383 msg_Dbg( p_dec, "error on InitializeQTML = %d", i_error );
388 /* input format settings */
389 p_sys->InputFormatInfo.flags = 0;
390 p_sys->InputFormatInfo.sampleCount = 0;
391 p_sys->InputFormatInfo.buffer = NULL;
392 p_sys->InputFormatInfo.reserved = 0;
393 p_sys->InputFormatInfo.numChannels = p_dec->fmt_in.audio.i_channels;
394 p_sys->InputFormatInfo.sampleSize = p_dec->fmt_in.audio.i_bitspersample;
395 p_sys->InputFormatInfo.sampleRate = p_dec->fmt_in.audio.i_rate;
396 p_sys->InputFormatInfo.format = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );
398 /* output format settings */
399 p_sys->OutputFormatInfo.flags = 0;
400 p_sys->OutputFormatInfo.sampleCount = 0;
401 p_sys->OutputFormatInfo.buffer = NULL;
402 p_sys->OutputFormatInfo.reserved = 0;
403 p_sys->OutputFormatInfo.numChannels = p_dec->fmt_in.audio.i_channels;
404 p_sys->OutputFormatInfo.sampleSize = 16;
405 p_sys->OutputFormatInfo.sampleRate = p_dec->fmt_in.audio.i_rate;
406 p_sys->OutputFormatInfo.format = FCC( 'N', 'O', 'N', 'E' );
409 i_error = p_sys->SoundConverterOpen( &p_sys->InputFormatInfo,
410 &p_sys->OutputFormatInfo,
411 &p_sys->myConverter );
414 msg_Err( p_dec, "error on SoundConverterOpen = %d", i_error );
419 /* tell the sound converter we accept VBR formats */
420 i_error = SoundConverterSetInfo( p_dec->myConverter, siClientAcceptsVBR,
424 if( p_dec->fmt_in.i_extra > 36 + 8 )
426 i_error = p_sys->SoundConverterSetInfo( p_sys->myConverter,
427 FCC( 'w', 'a', 'v', 'e' ),
428 ((uint8_t*)p_dec->fmt_in.p_extra) + 36 + 8 );
430 msg_Dbg( p_dec, "error on SoundConverterSetInfo = %d", i_error );
433 WantedBufferSize = p_sys->OutputFormatInfo.numChannels *
434 p_sys->OutputFormatInfo.sampleRate * 2;
435 p_sys->FramesToGet = 0;
437 i_error = p_sys->SoundConverterGetBufferSizes( p_sys->myConverter,
443 msg_Dbg( p_dec, "WantedBufferSize=%li InputBufferSize=%li "
444 "OutputBufferSize=%li FramesToGet=%li",
445 WantedBufferSize, InputBufferSize, OutputBufferSize,
446 p_sys->FramesToGet );
448 p_sys->InFrameSize = (InputBufferSize + p_sys->FramesToGet - 1 ) /
450 p_sys->OutFrameSize = OutputBufferSize / p_sys->FramesToGet;
452 msg_Dbg( p_dec, "frame size %d -> %d",
453 p_sys->InFrameSize, p_sys->OutFrameSize );
455 if( (i_error = p_sys->SoundConverterBeginConversion(p_sys->myConverter)) )
458 "error on SoundConverterBeginConversion = %d", i_error );
463 es_format_Init( &p_dec->fmt_out, AUDIO_ES, AOUT_FMT_S16_NE );
464 p_dec->fmt_out.audio.i_rate = p_sys->OutputFormatInfo.sampleRate;
465 p_dec->fmt_out.audio.i_channels = p_sys->OutputFormatInfo.numChannels;
466 p_dec->fmt_out.audio.i_physical_channels =
467 p_dec->fmt_out.audio.i_original_channels =
468 pi_channels_maps[p_sys->OutputFormatInfo.numChannels];
470 aout_DateInit( &p_sys->date, p_dec->fmt_out.audio.i_rate );
473 p_sys->i_buffer_size = 100*1000;
474 p_sys->p_buffer = malloc( p_sys->i_buffer_size );
477 p_sys->i_out_frames = 0;
480 vlc_mutex_unlock( &p_dec->p_vlc->quicktime_lock );
482 vlc_mutex_unlock( lockval.p_address );
488 Restore_LDT_Keeper( p_sys->ldt_fs );
491 vlc_mutex_unlock( &p_dec->p_vlc->quicktime_lock );
493 vlc_mutex_unlock( lockval.p_address );
499 /*****************************************************************************
501 *****************************************************************************/
502 static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
504 decoder_sys_t *p_sys = p_dec->p_sys;
511 /* We must do open and close in the same thread (unless we do
512 * Setup_LDT_Keeper in the main thread before all others */
515 if( OpenAudio( p_dec ) )
518 p_dec->b_error = VLC_TRUE;
522 p_sys = p_dec->p_sys;
526 if( pp_block == NULL || *pp_block == NULL )
532 if( p_sys->i_out_frames > 0 && p_sys->i_out >= p_sys->i_out_frames )
536 p_sys->i_out_frames = 0;
542 if( p_sys->i_out_frames <= 0 )
544 if( ( p_sys->pts = p_block->i_pts ) < mdate() )
546 block_Release( p_block );
552 if( p_sys->i_buffer_size < p_sys->i_buffer + p_block->i_buffer )
554 p_sys->i_buffer_size = p_sys->i_buffer + p_block->i_buffer + 1024;
555 p_sys->p_buffer = realloc( p_sys->p_buffer, p_sys->i_buffer_size );
557 memcpy( &p_sys->p_buffer[p_sys->i_buffer], p_block->p_buffer,
559 p_sys->i_buffer += p_block->i_buffer;
561 if( p_sys->i_buffer > p_sys->InFrameSize )
563 int i_frames = p_sys->i_buffer / p_sys->InFrameSize;
564 long i_out_frames, i_out_bytes;
566 var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
567 vlc_mutex_lock( lockval.p_address );
568 i_error = p_sys->SoundConverterConvertBuffer( p_sys->myConverter,
574 vlc_mutex_unlock( lockval.p_address );
577 msg_Dbg( p_dec, "decoded %d frames -> %ld frames (error=%d)",
578 i_frames, i_out_frames, i_error );
580 msg_Dbg( p_dec, "decoded %ld frames = %ld bytes",
581 i_out_frames, i_out_bytes );
584 p_sys->i_buffer -= i_frames * p_sys->InFrameSize;
585 if( p_sys->i_buffer > 0 )
587 memmove( &p_sys->p_buffer[0],
588 &p_sys->p_buffer[i_frames * p_sys->InFrameSize],
592 if( p_sys->pts != 0 &&
593 p_sys->pts != aout_DateGet( &p_sys->date ) )
595 aout_DateSet( &p_sys->date, p_sys->pts );
597 else if( !aout_DateGet( &p_sys->date ) )
602 if( !i_error && i_out_frames > 0 )
604 /* we have others samples */
605 p_sys->i_out_frames = i_out_frames;
611 if( p_sys->i_out < p_sys->i_out_frames )
613 aout_buffer_t *p_out;
614 int i_frames = __MIN( p_sys->i_out_frames - p_sys->i_out, 1000 );
616 p_out = p_dec->pf_aout_buffer_new( p_dec, i_frames );
620 p_out->start_date = aout_DateGet( &p_sys->date );
621 p_out->end_date = aout_DateIncrement( &p_sys->date, i_frames );
623 memcpy( p_out->p_buffer,
624 &p_sys->out_buffer[2 * p_sys->i_out * p_dec->fmt_out.audio.i_channels],
627 p_sys->i_out += i_frames;
635 /*****************************************************************************
637 *****************************************************************************/
638 static int OpenVideo( decoder_t *p_dec )
640 decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );
645 ComponentDescription desc;
647 ComponentResult cres;
648 ImageSubCodecDecompressCapabilities icap; /* for ImageCodecInitialize() */
649 CodecInfo cinfo; /* for ImageCodecGetCodecInfo() */
650 ImageDescription *id;
653 int i_vide = p_dec->fmt_in.i_extra;
654 uint8_t *p_vide = p_dec->fmt_in.p_extra;
656 p_dec->p_sys = p_sys;
657 p_dec->pf_decode_video = DecodeVideo;
662 msg_Err( p_dec, "missing extra info" );
667 memcpy( fcc, &p_dec->fmt_in.i_codec, 4 );
668 msg_Dbg( p_dec, "quicktime_video %4.4s %dx%d",
669 fcc, p_dec->fmt_in.video.i_width, p_dec->fmt_in.video.i_height );
671 /* get lock, avoid segfault */
672 var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
673 vlc_mutex_lock( lockval.p_address );
679 if( QTVideoInit( p_dec ) )
681 msg_Err( p_dec, "cannot initialize QT");
686 if( ( i_result = p_sys->InitializeQTML( 6 + 16 ) ) )
688 msg_Dbg( p_dec, "error on InitializeQTML = %d", (int)i_result );
693 /* init ComponentDescription */
694 memset( &desc, 0, sizeof( ComponentDescription ) );
695 desc.componentType = FCC( 'i', 'm', 'd', 'c' );
696 desc.componentSubType = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );
697 desc.componentManufacturer = 0;
698 desc.componentFlags = 0;
699 desc.componentFlagsMask = 0;
701 if( !( prev = p_sys->FindNextComponent( NULL, &desc ) ) )
703 msg_Err( p_dec, "cannot find requested component" );
706 msg_Dbg( p_dec, "component id=0x%p", prev );
708 p_sys->ci = p_sys->OpenComponent( prev );
709 msg_Dbg( p_dec, "component instance p=0x%p", p_sys->ci );
711 memset( &icap, 0, sizeof( ImageSubCodecDecompressCapabilities ) );
712 cres = p_sys->ImageCodecInitialize( p_sys->ci, &icap );
713 /* msg_Dbg( p_dec->p_fifo, "ImageCodecInitialize->%p size=%d (%d)\n",cres,icap.recordSize,icap.decompressRecordSize); */
715 memset( &cinfo, 0, sizeof( CodecInfo ) );
716 cres = p_sys->ImageCodecGetCodecInfo( p_sys->ci, &cinfo );
718 "Flags: compr: 0x%lx decomp: 0x%lx format: 0x%lx\n",
719 cinfo.compressFlags, cinfo.decompressFlags, cinfo.formatFlags );
720 msg_Dbg( p_dec, "quicktime_video: Codec name: %.*s\n",
721 ((unsigned char*)&cinfo.typeName)[0],
722 ((unsigned char*)&cinfo.typeName)+1 );
724 /* make a yuy2 gworld */
725 p_sys->OutBufferRect.top = 0;
726 p_sys->OutBufferRect.left = 0;
727 p_sys->OutBufferRect.right = p_dec->fmt_in.video.i_width;
728 p_sys->OutBufferRect.bottom = p_dec->fmt_in.video.i_height;
731 /* codec data FIXME use codec not SVQ3 */
732 msg_Dbg( p_dec, "vide = %d", i_vide );
733 id = malloc( sizeof( ImageDescription ) + ( i_vide - 70 ) );
734 id->idSize = sizeof( ImageDescription ) + ( i_vide - 70 );
735 id->cType = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );
736 id->version = GetWBE ( p_vide + 0 );
737 id->revisionLevel = GetWBE ( p_vide + 2 );
738 id->vendor = GetDWBE( p_vide + 4 );
739 id->temporalQuality = GetDWBE( p_vide + 8 );
740 id->spatialQuality = GetDWBE( p_vide + 12 );
741 id->width = GetWBE ( p_vide + 16 );
742 id->height = GetWBE ( p_vide + 18 );
743 id->hRes = GetDWBE( p_vide + 20 );
744 id->vRes = GetDWBE( p_vide + 24 );
745 id->dataSize = GetDWBE( p_vide + 28 );
746 id->frameCount = GetWBE ( p_vide + 32 );
747 memcpy( &id->name, p_vide + 34, 32 );
748 id->depth = GetWBE ( p_vide + 66 );
749 id->clutID = GetWBE ( p_vide + 68 );
752 memcpy( ((char*)&id->clutID) + 2, p_vide + 70, i_vide - 70 );
755 msg_Dbg( p_dec, "idSize=%ld ver=%d rev=%d vendor=%ld tempQ=%d "
756 "spaQ=%d w=%d h=%d dpi=%d%d dataSize=%d frameCount=%d clutID=%d",
757 id->idSize, id->version, id->revisionLevel, id->vendor,
758 (int)id->temporalQuality, (int)id->spatialQuality,
759 id->width, id->height,
760 (int)id->hRes, (int)id->vRes,
765 p_sys->framedescHandle =
766 (ImageDescriptionHandle) p_sys->NewHandleClear( id->idSize );
767 memcpy( *p_sys->framedescHandle, id, id->idSize );
769 p_sys->plane = malloc( p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 3 );
771 i_result = p_sys->QTNewGWorldFromPtr( &p_sys->OutBufferGWorld,
772 /*pixel format of new GWorld==YUY2 */
774 /* we should benchmark if yvu9 is
775 * faster for svq3, too */
776 &p_sys->OutBufferRect,
779 p_dec->fmt_in.video.i_width * 2 );
781 msg_Dbg( p_dec, "NewGWorldFromPtr returned:%ld\n",
782 65536 - ( i_result&0xffff ) );
784 memset( &p_sys->decpar, 0, sizeof( CodecDecompressParams ) );
785 p_sys->decpar.imageDescription = p_sys->framedescHandle;
786 p_sys->decpar.startLine = 0;
787 p_sys->decpar.stopLine = ( **p_sys->framedescHandle ).height;
788 p_sys->decpar.frameNumber = 1;
789 p_sys->decpar.matrixFlags = 0;
790 p_sys->decpar.matrixType = 0;
791 p_sys->decpar.matrix = 0;
792 p_sys->decpar.capabilities = &p_sys->codeccap;
793 p_sys->decpar.accuracy = codecNormalQuality;
794 p_sys->decpar.srcRect = p_sys->OutBufferRect;
795 p_sys->decpar.transferMode = srcCopy;
796 p_sys->decpar.dstPixMap = **p_sys->GetGWorldPixMap( p_sys->OutBufferGWorld );/*destPixmap; */
798 cres = p_sys->ImageCodecPreDecompress( p_sys->ci, &p_sys->decpar );
799 msg_Dbg( p_dec, "quicktime_video: ImageCodecPreDecompress cres=0x%X\n",
802 p_dec->fmt_out.i_codec = VLC_FOURCC( 'Y', 'U', 'Y', '2' );
803 p_dec->fmt_out.video.i_width = p_dec->fmt_in.video.i_width;
804 p_dec->fmt_out.video.i_height= p_dec->fmt_in.video.i_height;
805 p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * p_dec->fmt_in.video.i_width / p_dec->fmt_in.video.i_height;
808 vlc_mutex_unlock( lockval.p_address );
813 Restore_LDT_Keeper( p_sys->ldt_fs );
815 vlc_mutex_unlock( lockval.p_address );
823 /*****************************************************************************
825 *****************************************************************************/
826 static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
828 decoder_sys_t *p_sys = p_dec->p_sys;
833 ComponentResult cres;
836 /* We must do open and close in the same thread (unless we do
837 * Setup_LDT_Keeper in the main thread before all others */
840 if( OpenVideo( p_dec ) )
843 p_dec->b_error = VLC_TRUE;
846 p_sys = p_dec->p_sys;
850 if( pp_block == NULL || *pp_block == NULL )
857 i_pts = p_block->i_pts ? p_block->i_pts : p_block->i_dts;
859 if( i_pts < mdate() )
868 if( p_sys->i_late > 10 )
870 msg_Dbg( p_dec, "too late buffer -> dropped" );
871 block_Release( p_block );
875 if( ( p_pic = p_dec->pf_vout_buffer_new( p_dec ) ) )
879 p_sys->decpar.data = p_block->p_buffer;
880 p_sys->decpar.bufferSize = p_block->i_buffer;
881 (**p_sys->framedescHandle).dataSize = p_block->i_buffer;
883 var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
884 vlc_mutex_lock( lockval.p_address );
885 cres = p_sys->ImageCodecBandDecompress( p_sys->ci, &p_sys->decpar );
886 vlc_mutex_unlock( lockval.p_address );
888 ++p_sys->decpar.frameNumber;
892 msg_Dbg( p_dec, "quicktime_video: ImageCodecBandDecompress"
893 " cres=0x%X (-0x%X) %d :(\n",
894 (int)cres,(int)-cres, (int)cres );
897 memcpy( p_pic->p[0].p_pixels, p_sys->plane,
898 p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 2 );
901 block_Release( p_block );
907 /*****************************************************************************
909 *****************************************************************************/
910 static int QTAudioInit( decoder_t *p_dec )
912 decoder_sys_t *p_sys = p_dec->p_sys;
915 p_sys->SoundConverterOpen = (void*)SoundConverterOpen;
916 p_sys->SoundConverterClose = (void*)SoundConverterClose;
917 p_sys->SoundConverterSetInfo = (void*)SoundConverterSetInfo;
918 p_sys->SoundConverterGetBufferSizes = (void*)SoundConverterGetBufferSizes;
919 p_sys->SoundConverterConvertBuffer = (void*)SoundConverterConvertBuffer;
920 p_sys->SoundConverterBeginConversion= (void*)SoundConverterBeginConversion;
921 p_sys->SoundConverterEndConversion = (void*)SoundConverterEndConversion;
925 p_sys->ldt_fs = Setup_LDT_Keeper();
928 p_sys->qtml = LoadLibraryA( "qtmlClient.dll" );
929 if( p_sys->qtml == NULL )
931 msg_Dbg( p_dec, "failed loading qtmlClient.dll" );
935 p_sys->InitializeQTML = (void *)GetProcAddress( p_sys->qtml, "InitializeQTML" );
936 p_sys->TerminateQTML = (void *)GetProcAddress( p_sys->qtml, "TerminateQTML" );
937 p_sys->SoundConverterOpen = (void *)GetProcAddress( p_sys->qtml, "SoundConverterOpen" );
938 p_sys->SoundConverterClose = (void *)GetProcAddress( p_sys->qtml, "SoundConverterClose" );
939 p_sys->SoundConverterSetInfo = (void *)GetProcAddress( p_sys->qtml, "SoundConverterSetInfo" );
940 p_sys->SoundConverterGetBufferSizes = (void *)GetProcAddress( p_sys->qtml, "SoundConverterGetBufferSizes" );
941 p_sys->SoundConverterConvertBuffer = (void *)GetProcAddress( p_sys->qtml, "SoundConverterConvertBuffer" );
942 p_sys->SoundConverterEndConversion = (void *)GetProcAddress( p_sys->qtml, "SoundConverterEndConversion" );
943 p_sys->SoundConverterBeginConversion= (void *)GetProcAddress( p_sys->qtml, "SoundConverterBeginConversion");
945 if( p_sys->InitializeQTML == NULL )
947 msg_Err( p_dec, "failed getting proc address InitializeQTML" );
950 if( p_sys->SoundConverterOpen == NULL ||
951 p_sys->SoundConverterClose == NULL ||
952 p_sys->SoundConverterSetInfo == NULL ||
953 p_sys->SoundConverterGetBufferSizes == NULL ||
954 p_sys->SoundConverterConvertBuffer == NULL ||
955 p_sys->SoundConverterEndConversion == NULL ||
956 p_sys->SoundConverterBeginConversion == NULL )
958 msg_Err( p_dec, "failed getting proc address" );
962 msg_Dbg( p_dec, "Standard init done" );
963 #endif /* else SYS_DARWIN */
969 /*****************************************************************************
971 *****************************************************************************/
972 static int QTVideoInit( decoder_t *p_dec )
974 decoder_sys_t *p_sys = p_dec->p_sys;
977 p_sys->FindNextComponent = (void*)FindNextComponent;
978 p_sys->OpenComponent = (void*)OpenComponent;
979 p_sys->ImageCodecInitialize = (void*)ImageCodecInitialize;
980 p_sys->ImageCodecGetCodecInfo = (void*)ImageCodecGetCodecInfo;
981 p_sys->ImageCodecPreDecompress = (void*)ImageCodecPreDecompress;
982 p_sys->ImageCodecBandDecompress = (void*)ImageCodecBandDecompress;
983 p_sys->GetGWorldPixMap = (void*)GetGWorldPixMap;
984 p_sys->QTNewGWorldFromPtr = (void*)QTNewGWorldFromPtr;
985 p_sys->NewHandleClear = (void*)NewHandleClear;
989 p_sys->ldt_fs = Setup_LDT_Keeper();
991 p_sys->qtml = LoadLibraryA( "qtmlClient.dll" );
992 if( p_sys->qtml == NULL )
994 msg_Dbg( p_dec, "failed loading qtmlClient.dll" );
997 msg_Dbg( p_dec, "qtmlClient.dll loaded" );
999 /* (void*) to shut up gcc */
1000 p_sys->InitializeQTML = (void*)GetProcAddress( p_sys->qtml, "InitializeQTML" );
1001 p_sys->FindNextComponent = (void*)GetProcAddress( p_sys->qtml, "FindNextComponent" );
1002 p_sys->OpenComponent = (void*)GetProcAddress( p_sys->qtml, "OpenComponent" );
1003 p_sys->ImageCodecInitialize = (void*)GetProcAddress( p_sys->qtml, "ImageCodecInitialize" );
1004 p_sys->ImageCodecGetCodecInfo = (void*)GetProcAddress( p_sys->qtml, "ImageCodecGetCodecInfo" );
1005 p_sys->ImageCodecPreDecompress = (void*)GetProcAddress( p_sys->qtml, "ImageCodecPreDecompress" );
1006 p_sys->ImageCodecBandDecompress = (void*)GetProcAddress( p_sys->qtml, "ImageCodecBandDecompress" );
1007 p_sys->GetGWorldPixMap = (void*)GetProcAddress( p_sys->qtml, "GetGWorldPixMap" );
1008 p_sys->QTNewGWorldFromPtr = (void*)GetProcAddress( p_sys->qtml, "QTNewGWorldFromPtr" );
1009 p_sys->NewHandleClear = (void*)GetProcAddress( p_sys->qtml, "NewHandleClear" );
1011 if( p_sys->InitializeQTML == NULL )
1013 msg_Dbg( p_dec, "failed getting proc address InitializeQTML" );
1014 return VLC_EGENERIC;
1016 if( p_sys->FindNextComponent == NULL ||
1017 p_sys->OpenComponent == NULL ||
1018 p_sys->ImageCodecInitialize == NULL ||
1019 p_sys->ImageCodecGetCodecInfo == NULL ||
1020 p_sys->ImageCodecPreDecompress == NULL ||
1021 p_sys->ImageCodecBandDecompress == NULL ||
1022 p_sys->GetGWorldPixMap == NULL ||
1023 p_sys->QTNewGWorldFromPtr == NULL ||
1024 p_sys->NewHandleClear == NULL )
1026 msg_Err( p_dec, "failed getting proc address" );
1027 return VLC_EGENERIC;
1029 #endif /* SYS_DARWIN */