1 /*****************************************************************************
2 * quicktime.c: a quicktime decoder that uses the QT library/dll
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: quicktime.c,v 1.16 2003/11/23 03:41:58 fenrir Exp $
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>
35 #include <QuickTime/QuickTimeComponents.h>
36 #include <QuickTime/Movies.h>
37 #include <QuickTime/ImageCodec.h>
40 /* for windows do we require Quicktime compents header? */
43 #include "w32dll/loader/qtx/qtxsdk/components.h"
44 #include "w32dll/loader/wine/windef.h"
45 #include "w32dll/loader/ldt_keeper.h"
47 HMODULE WINAPI LoadLibraryA(LPCSTR);
48 FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR);
49 int WINAPI FreeLibrary(HMODULE);
53 /*****************************************************************************
55 *****************************************************************************/
56 static int Open ( vlc_object_t * );
57 static void Close( vlc_object_t * );
60 set_description( _("QuickTime library decoder") );
61 set_capability( "decoder", 10 );
62 set_callbacks( Open, Close );
65 var_Create( p_module->p_libvlc, "qt_mutex", VLC_VAR_MUTEX );
69 /*****************************************************************************
71 *****************************************************************************/
72 static int OpenAudio( decoder_t * );
73 static int OpenVideo( decoder_t * );
75 static aout_buffer_t *DecodeAudio( decoder_t *, block_t ** );
76 static picture_t *DecodeVideo( decoder_t *, block_t ** );
78 #define FCC( a, b , c, d ) \
79 ((uint32_t)( ((a)<<24)|((b)<<16)|((c)<<8)|(d)))
82 typedef struct OpaqueSoundConverter* SoundConverter;
87 typedef unsigned long UnsignedFixed;
90 typedef struct SoundComponentData {
95 UnsignedFixed sampleRate;
101 #endif /* SYS_DARWIN */
112 OSErr (*InitializeQTML) ( long flags );
113 OSErr (*TerminateQTML) ( void );
114 #endif /* SYS_DARWIN */
117 int (*SoundConverterOpen) ( const SoundComponentData *,
118 const SoundComponentData *,
120 int (*SoundConverterClose) ( SoundConverter );
121 int (*SoundConverterSetInfo) ( SoundConverter , OSType, void * );
122 int (*SoundConverterGetBufferSizes) ( SoundConverter, unsigned long,
123 unsigned long*, unsigned long*,
125 int (*SoundConverterBeginConversion)( SoundConverter );
126 int (*SoundConverterEndConversion) ( SoundConverter, void *,
127 unsigned long *, unsigned long *);
128 int (*SoundConverterConvertBuffer) ( SoundConverter, const void *,
129 unsigned long, void *,
130 unsigned long *, unsigned long * );
131 SoundConverter myConverter;
132 SoundComponentData InputFormatInfo, OutputFormatInfo;
135 unsigned int InFrameSize;
136 unsigned int OutFrameSize;
139 Component (*FindNextComponent)
140 ( Component prev, ComponentDescription* desc );
142 ComponentInstance (*OpenComponent)
145 ComponentResult (*ImageCodecInitialize)
146 ( ComponentInstance ci, ImageSubCodecDecompressCapabilities * cap);
148 ComponentResult (*ImageCodecGetCodecInfo)
149 ( ComponentInstance ci, CodecInfo *info );
151 ComponentResult (*ImageCodecPreDecompress)
152 ( ComponentInstance ci, CodecDecompressParams * params );
154 ComponentResult (*ImageCodecBandDecompress)
155 ( ComponentInstance ci, CodecDecompressParams * params );
157 PixMapHandle (*GetGWorldPixMap)
158 ( GWorldPtr offscreenGWorld );
160 OSErr (*QTNewGWorldFromPtr)
161 ( GWorldPtr *gw, OSType pixelFormat, const Rect *boundsRect,
162 CTabHandle cTable, /*GDHandle*/ void *aGDevice, /*unused*/
163 GWorldFlags flags, void *baseAddr, long rowBytes );
165 OSErr (*NewHandleClear)( Size byteCount );
167 ComponentInstance ci;
168 Rect OutBufferRect; /* the dimensions of our GWorld */
169 GWorldPtr OutBufferGWorld; /* a GWorld is some kind of
170 description for a drawing
172 ImageDescriptionHandle framedescHandle;
174 CodecDecompressParams decpar; /* for ImageCodecPreDecompress()*/
175 CodecCapabilities codeccap; /* for decpar */
178 /* Output properties */
183 int i_late; /* video */
186 unsigned int i_buffer;
187 unsigned int i_buffer_size;
191 uint8_t out_buffer[1000000]; /* FIXME */
196 static int pi_channels_maps[6] =
200 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
201 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER,
202 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT,
203 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
204 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT
207 static int QTAudioInit( decoder_t * );
208 static int QTVideoInit( decoder_t * );
210 /*****************************************************************************
211 * Open: probe the decoder and return score
212 *****************************************************************************
213 * Tries to launch a decoder and return score so that the interface is able
215 *****************************************************************************/
216 static int Open( vlc_object_t *p_this )
218 decoder_t *p_dec = (decoder_t*)p_this;
220 switch( p_dec->fmt_in.i_codec )
222 case VLC_FOURCC('S','V','Q','3'): /* Sorenson v3 */
223 /* case VLC_FOURCC('S','V','Q','1'): Sorenson v1
224 case VLC_FOURCC('Z','y','G','o'):
225 case VLC_FOURCC('V','P','3','1'):
226 case VLC_FOURCC('3','I','V','1'): */
227 case VLC_FOURCC('r','l','e',' '): /* QuickTime animation (RLE) */
228 case VLC_FOURCC('r','p','z','a'): /* QuickTime Apple Video */
229 case VLC_FOURCC('a','z','p','r'): /* QuickTime animation (RLE) */
232 p_dec->pf_decode_video = DecodeVideo;
235 return OpenVideo( p_dec );
238 case VLC_FOURCC('s','a','m','r'): /* 3GPP AMR audio */
239 case VLC_FOURCC('m','p','4','a'): /* MPEG-4 audio */
240 case VLC_FOURCC('Q','D','M','C'): /* QDesign */
241 case VLC_FOURCC('Q','D','M','2'): /* QDesign* 2 */
242 case VLC_FOURCC('Q','c','l','p'): /* Qualcomm Purevoice Codec */
243 case VLC_FOURCC('Q','C','L','P'): /* Qualcomm Purevoice Codec */
244 case VLC_FOURCC('M','A','C','3'): /* MACE3 audio decoder */
245 case VLC_FOURCC('M','A','C','6'): /* MACE6 audio decoder */
246 case VLC_FOURCC('d','v','c','a'): /* DV Audio */
247 case VLC_FOURCC('s','o','w','t'): /* 16-bit Little Endian */
248 case VLC_FOURCC('t','w','o','s'): /* 16-bit Big Endian */
249 case VLC_FOURCC('a','l','a','w'): /* ALaw 2:1 */
250 case VLC_FOURCC('u','l','a','w'): /* mu-Law 2:1 */
251 case VLC_FOURCC('r','a','w',' '): /* 8-bit offset binaries */
252 case VLC_FOURCC('f','l','3','2'): /* 32-bit Floating Point */
253 case VLC_FOURCC('f','l','6','4'): /* 64-bit Floating Point */
254 case VLC_FOURCC('i','n','2','4'): /* 24-bit Interger */
255 case VLC_FOURCC('i','n','3','2'): /* 32-bit Integer */
256 case 0x0011: /* DVI IMA */
257 case 0x6D730002: /* Microsoft ADPCM-ACM */
258 case 0x6D730011: /* DVI Intel IMAADPCM-ACM */
261 p_dec->pf_decode_audio = DecodeAudio;
264 return OpenAudio( p_dec );
272 /*****************************************************************************
274 *****************************************************************************/
275 static void Close( vlc_object_t *p_this )
277 decoder_t *p_dec = (decoder_t*)p_this;
278 decoder_sys_t *p_sys = p_dec->p_sys;
281 /* get lock, avoid segfault */
282 var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
283 vlc_mutex_lock( lockval.p_address );
285 /* on OS X QT is not threadsafe */
286 vlc_mutex_lock( &p_dec->p_vlc->quicktime_lock );
289 if( p_dec->fmt_out.i_cat == AUDIO_ES )
292 unsigned long ConvertedFrames=0;
293 unsigned long ConvertedBytes=0;
295 i_error = p_sys->SoundConverterEndConversion( p_sys->myConverter, NULL,
298 msg_Dbg( p_dec, "SoundConverterEndConversion => %d", i_error );
300 i_error = p_sys->SoundConverterClose( p_sys->myConverter );
301 msg_Dbg( p_dec, "SoundConverterClose => %d", i_error );
303 free( p_sys->p_buffer );
305 else if( p_dec->fmt_out.i_cat == VIDEO_ES )
307 free( p_sys->plane );
311 FreeLibrary( p_sys->qtml );
312 msg_Dbg( p_dec, "FreeLibrary ok." );
322 Restore_LDT_Keeper( p_sys->ldt_fs );
323 msg_Dbg( p_dec, "Restore_LDT_Keeper" );
328 vlc_mutex_unlock( &p_dec->p_vlc->quicktime_lock );
330 vlc_mutex_unlock( lockval.p_address );
335 /*****************************************************************************
337 *****************************************************************************/
338 static int OpenAudio( decoder_t *p_dec )
340 decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );
345 unsigned long WantedBufferSize;
346 unsigned long InputBufferSize = 0;
347 unsigned long OutputBufferSize = 0;
349 memset( p_sys, 0, sizeof( decoder_sys_t ) );
351 p_dec->p_sys = p_sys;
352 p_dec->pf_decode_audio = DecodeAudio;
354 memcpy( fcc, &p_dec->fmt_in.i_codec, 4 );
356 /* get lock, avoid segfault */
357 var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
358 vlc_mutex_lock( lockval.p_address );
360 /* on OS X QT is not threadsafe */
361 vlc_mutex_lock( &p_dec->p_vlc->quicktime_lock );
368 if( QTAudioInit( p_dec ) )
370 msg_Err( p_dec, "cannot initialize QT");
375 if( ( i_error = p_sys->InitializeQTML( 6 + 16 ) ) )
377 msg_Dbg( p_dec, "error while InitializeQTML = %d", i_error );
382 /* input format settings */
383 p_sys->InputFormatInfo.flags = 0;
384 p_sys->InputFormatInfo.sampleCount = 0;
385 p_sys->InputFormatInfo.buffer = NULL;
386 p_sys->InputFormatInfo.reserved = 0;
387 p_sys->InputFormatInfo.numChannels = p_dec->fmt_in.audio.i_channels;
388 p_sys->InputFormatInfo.sampleSize = p_dec->fmt_in.audio.i_bitspersample;
389 p_sys->InputFormatInfo.sampleRate = p_dec->fmt_in.audio.i_rate;
390 p_sys->InputFormatInfo.format = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );
392 /* output format settings */
393 p_sys->OutputFormatInfo.flags = 0;
394 p_sys->OutputFormatInfo.sampleCount = 0;
395 p_sys->OutputFormatInfo.buffer = NULL;
396 p_sys->OutputFormatInfo.reserved = 0;
397 p_sys->OutputFormatInfo.numChannels = p_dec->fmt_in.audio.i_channels;
398 p_sys->OutputFormatInfo.sampleSize = 16;
399 p_sys->OutputFormatInfo.sampleRate = p_dec->fmt_in.audio.i_rate;
400 p_sys->OutputFormatInfo.format = FCC( 'N', 'O', 'N', 'E' );
403 i_error = p_sys->SoundConverterOpen( &p_sys->InputFormatInfo,
404 &p_sys->OutputFormatInfo,
405 &p_sys->myConverter );
408 msg_Err( p_dec, "error while SoundConverterOpen = %d", i_error );
413 /* tell the sound converter we accept VBR formats */
414 i_error = SoundConverterSetInfo( p_dec->myConverter, siClientAcceptsVBR,
418 if( p_dec->fmt_in.i_extra > 36 + 8 )
420 i_error = p_sys->SoundConverterSetInfo( p_sys->myConverter,
421 FCC( 'w', 'a', 'v', 'e' ),
422 ((uint8_t*)p_dec->fmt_in.p_extra) + 36 + 8 );
424 msg_Dbg( p_dec, "error while SoundConverterSetInfo = %d", i_error );
427 WantedBufferSize = p_sys->OutputFormatInfo.numChannels *
428 p_sys->OutputFormatInfo.sampleRate * 2;
429 p_sys->FramesToGet = 0;
431 i_error = p_sys->SoundConverterGetBufferSizes( p_sys->myConverter,
437 msg_Dbg( p_dec, "WantedBufferSize=%li InputBufferSize=%li "
438 "OutputBufferSize=%li FramesToGet=%li",
439 WantedBufferSize, InputBufferSize, OutputBufferSize,
440 p_sys->FramesToGet );
442 p_sys->InFrameSize = (InputBufferSize + p_sys->FramesToGet - 1 ) /
444 p_sys->OutFrameSize = OutputBufferSize / p_sys->FramesToGet;
446 msg_Dbg( p_dec, "frame size %d -> %d",
447 p_sys->InFrameSize, p_sys->OutFrameSize );
449 if( (i_error = p_sys->SoundConverterBeginConversion(p_sys->myConverter)) )
452 "error while SoundConverterBeginConversion = %d", i_error );
457 es_format_Init( &p_dec->fmt_out, AUDIO_ES, AOUT_FMT_S16_NE );
458 p_dec->fmt_out.audio.i_rate = p_sys->OutputFormatInfo.sampleRate;
459 p_dec->fmt_out.audio.i_channels = p_sys->OutputFormatInfo.numChannels;
460 p_dec->fmt_out.audio.i_physical_channels =
461 p_dec->fmt_out.audio.i_original_channels =
462 pi_channels_maps[p_sys->OutputFormatInfo.numChannels];
464 aout_DateInit( &p_sys->date, p_dec->fmt_out.audio.i_rate );
467 p_sys->i_buffer_size = 100*1000;
468 p_sys->p_buffer = malloc( p_sys->i_buffer_size );
471 p_sys->i_out_frames = 0;
474 vlc_mutex_unlock( &p_dec->p_vlc->quicktime_lock );
476 vlc_mutex_unlock( lockval.p_address );
482 Restore_LDT_Keeper( p_sys->ldt_fs );
485 vlc_mutex_unlock( &p_dec->p_vlc->quicktime_lock );
487 vlc_mutex_unlock( lockval.p_address );
491 /*****************************************************************************
493 *****************************************************************************/
494 static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
496 decoder_sys_t *p_sys = p_dec->p_sys;
503 /* We must do open and close in the same thread (unless we do
504 * Setup_LDT_Keeper in the main thread before all others */
507 if( OpenAudio( p_dec ) )
510 p_dec->b_error = VLC_TRUE;
514 p_sys = p_dec->p_sys;
518 if( pp_block == NULL || *pp_block == NULL )
524 if( p_sys->i_out_frames > 0 && p_sys->i_out >= p_sys->i_out_frames )
528 p_sys->i_out_frames = 0;
534 if( p_sys->i_out_frames <= 0 )
536 if( ( p_sys->pts = p_block->i_pts ) < mdate() )
538 block_Release( p_block );
544 if( p_sys->i_buffer_size < p_sys->i_buffer + p_block->i_buffer )
546 p_sys->i_buffer_size = p_sys->i_buffer + p_block->i_buffer + 1024;
547 p_sys->p_buffer = realloc( p_sys->p_buffer, p_sys->i_buffer_size );
549 memcpy( &p_sys->p_buffer[p_sys->i_buffer], p_block->p_buffer,
551 p_sys->i_buffer += p_block->i_buffer;
553 if( p_sys->i_buffer > p_sys->InFrameSize )
555 int i_frames = p_sys->i_buffer / p_sys->InFrameSize;
556 long i_out_frames, i_out_bytes;
558 var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
559 vlc_mutex_lock( lockval.p_address );
560 i_error = p_sys->SoundConverterConvertBuffer( p_sys->myConverter,
566 vlc_mutex_unlock( lockval.p_address );
569 msg_Dbg( p_dec, "decoded %d frames -> %ld frames (error=%d)",
570 i_frames, i_out_frames, i_error );
572 msg_Dbg( p_dec, "decoded %ld frames = %ld bytes",
573 i_out_frames, i_out_bytes );
576 p_sys->i_buffer -= i_frames * p_sys->InFrameSize;
577 if( p_sys->i_buffer > 0 )
579 memmove( &p_sys->p_buffer[0],
580 &p_sys->p_buffer[i_frames * p_sys->InFrameSize],
584 if( p_sys->pts != 0 &&
585 p_sys->pts != aout_DateGet( &p_sys->date ) )
587 aout_DateSet( &p_sys->date, p_sys->pts );
589 else if( !aout_DateGet( &p_sys->date ) )
594 if( !i_error && i_out_frames > 0 )
596 /* we have others samples */
597 p_sys->i_out_frames = i_out_frames;
603 if( p_sys->i_out < p_sys->i_out_frames )
605 aout_buffer_t *p_out;
606 int i_frames = __MIN( p_sys->i_out_frames - p_sys->i_out, 1000 );
608 p_out = p_dec->pf_aout_buffer_new( p_dec, i_frames );
612 p_out->start_date = aout_DateGet( &p_sys->date );
613 p_out->end_date = aout_DateIncrement( &p_sys->date, i_frames );
615 memcpy( p_out->p_buffer,
616 &p_sys->out_buffer[2 * p_sys->i_out * p_dec->fmt_out.audio.i_channels],
619 p_sys->i_out += i_frames;
627 /*****************************************************************************
629 *****************************************************************************/
630 static int OpenVideo( decoder_t *p_dec )
632 decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );
636 ComponentDescription desc;
638 ComponentResult cres;
639 ImageSubCodecDecompressCapabilities icap; /* for ImageCodecInitialize() */
640 CodecInfo cinfo; /* for ImageCodecGetCodecInfo() */
641 ImageDescription *id;
644 int i_vide = p_dec->fmt_in.i_extra;
645 uint8_t *p_vide = p_dec->fmt_in.p_extra;
647 p_dec->p_sys = p_sys;
648 p_dec->pf_decode_video = DecodeVideo;
653 msg_Err( p_dec, "missing extra info" );
658 memcpy( fcc, &p_dec->fmt_in.i_codec, 4 );
659 msg_Dbg( p_dec, "quicktime_video %4.4s %dx%d",
660 fcc, p_dec->fmt_in.video.i_width, p_dec->fmt_in.video.i_height );
662 /* get lock, avoid segfault */
663 var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
664 vlc_mutex_lock( lockval.p_address );
670 if( QTVideoInit( p_dec ) )
672 msg_Err( p_dec, "cannot initialize QT");
677 if( ( i_result = p_sys->InitializeQTML( 6 + 16 ) ) )
679 msg_Dbg( p_dec, "error while InitializeQTML = %d", (int)i_result );
684 /* init ComponentDescription */
685 memset( &desc, 0, sizeof( ComponentDescription ) );
686 desc.componentType = FCC( 'i', 'm', 'd', 'c' );
687 desc.componentSubType = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );
688 desc.componentManufacturer = 0;
689 desc.componentFlags = 0;
690 desc.componentFlagsMask = 0;
692 if( !( prev = p_sys->FindNextComponent( NULL, &desc ) ) )
694 msg_Err( p_dec, "cannot find requested component" );
697 msg_Dbg( p_dec, "component id=0x%p", prev );
699 p_sys->ci = p_sys->OpenComponent( prev );
700 msg_Dbg( p_dec, "component instance p=0x%p", p_sys->ci );
702 memset( &icap, 0, sizeof( ImageSubCodecDecompressCapabilities ) );
703 cres = p_sys->ImageCodecInitialize( p_sys->ci, &icap );
704 /* msg_Dbg( p_dec->p_fifo, "ImageCodecInitialize->%p size=%d (%d)\n",cres,icap.recordSize,icap.decompressRecordSize); */
706 memset( &cinfo, 0, sizeof( CodecInfo ) );
707 cres = p_sys->ImageCodecGetCodecInfo( p_sys->ci, &cinfo );
709 "Flags: compr: 0x%lx decomp: 0x%lx format: 0x%lx\n",
710 cinfo.compressFlags, cinfo.decompressFlags, cinfo.formatFlags );
711 msg_Dbg( p_dec, "quicktime_video: Codec name: %.*s\n",
712 ((unsigned char*)&cinfo.typeName)[0],
713 ((unsigned char*)&cinfo.typeName)+1 );
715 /* make a yuy2 gworld */
716 p_sys->OutBufferRect.top = 0;
717 p_sys->OutBufferRect.left = 0;
718 p_sys->OutBufferRect.right = p_dec->fmt_in.video.i_width;
719 p_sys->OutBufferRect.bottom = p_dec->fmt_in.video.i_height;
722 /* codec data FIXME use codec not SVQ3 */
723 msg_Dbg( p_dec, "vide = %d", i_vide );
724 id = malloc( sizeof( ImageDescription ) + ( i_vide - 70 ) );
725 id->idSize = sizeof( ImageDescription ) + ( i_vide - 70 );
726 id->cType = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );
727 id->version = GetWBE ( p_vide + 0 );
728 id->revisionLevel = GetWBE ( p_vide + 2 );
729 id->vendor = GetDWBE( p_vide + 4 );
730 id->temporalQuality = GetDWBE( p_vide + 8 );
731 id->spatialQuality = GetDWBE( p_vide + 12 );
732 id->width = GetWBE ( p_vide + 16 );
733 id->height = GetWBE ( p_vide + 18 );
734 id->hRes = GetDWBE( p_vide + 20 );
735 id->vRes = GetDWBE( p_vide + 24 );
736 id->dataSize = GetDWBE( p_vide + 28 );
737 id->frameCount = GetWBE ( p_vide + 32 );
738 memcpy( &id->name, p_vide + 34, 32 );
739 id->depth = GetWBE ( p_vide + 66 );
740 id->clutID = GetWBE ( p_vide + 68 );
743 memcpy( ((char*)&id->clutID) + 2, p_vide + 70, i_vide - 70 );
746 msg_Dbg( p_dec, "idSize=%ld ver=%d rev=%d vendor=%ld tempQ=%d "
747 "spaQ=%d w=%d h=%d dpi=%d%d dataSize=%d frameCount=%d clutID=%d",
748 id->idSize, id->version, id->revisionLevel, id->vendor,
749 (int)id->temporalQuality, (int)id->spatialQuality,
750 id->width, id->height,
751 (int)id->hRes, (int)id->vRes,
756 p_sys->framedescHandle =
757 (ImageDescriptionHandle) p_sys->NewHandleClear( id->idSize );
758 memcpy( *p_sys->framedescHandle, id, id->idSize );
760 p_sys->plane = malloc( p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 3 );
762 i_result = p_sys->QTNewGWorldFromPtr( &p_sys->OutBufferGWorld,
763 /*pixel format of new GWorld==YUY2 */
765 /* we should benchmark if yvu9 is
766 * faster for svq3, too */
767 &p_sys->OutBufferRect,
770 p_dec->fmt_in.video.i_width * 2 );
772 msg_Dbg( p_dec, "NewGWorldFromPtr returned:%ld\n",
773 65536 - ( i_result&0xffff ) );
775 memset( &p_sys->decpar, 0, sizeof( CodecDecompressParams ) );
776 p_sys->decpar.imageDescription = p_sys->framedescHandle;
777 p_sys->decpar.startLine = 0;
778 p_sys->decpar.stopLine = ( **p_sys->framedescHandle ).height;
779 p_sys->decpar.frameNumber = 1;
780 p_sys->decpar.matrixFlags = 0;
781 p_sys->decpar.matrixType = 0;
782 p_sys->decpar.matrix = 0;
783 p_sys->decpar.capabilities = &p_sys->codeccap;
784 p_sys->decpar.accuracy = codecNormalQuality;
785 p_sys->decpar.srcRect = p_sys->OutBufferRect;
786 p_sys->decpar.transferMode = srcCopy;
787 p_sys->decpar.dstPixMap = **p_sys->GetGWorldPixMap( p_sys->OutBufferGWorld );/*destPixmap; */
789 cres = p_sys->ImageCodecPreDecompress( p_sys->ci, &p_sys->decpar );
790 msg_Dbg( p_dec, "quicktime_video: ImageCodecPreDecompress cres=0x%X\n",
793 p_dec->fmt_out.i_codec = VLC_FOURCC( 'Y', 'U', 'Y', '2' );
794 p_dec->fmt_out.video.i_width = p_dec->fmt_in.video.i_width;
795 p_dec->fmt_out.video.i_height= p_dec->fmt_in.video.i_height;
796 p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * p_dec->fmt_in.video.i_width / p_dec->fmt_in.video.i_height;
799 vlc_mutex_unlock( lockval.p_address );
804 Restore_LDT_Keeper( p_sys->ldt_fs );
806 vlc_mutex_unlock( lockval.p_address );
810 /*****************************************************************************
812 *****************************************************************************/
813 static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
815 decoder_sys_t *p_sys = p_dec->p_sys;
819 ComponentResult cres;
822 /* We must do open and close in the same thread (unless we do
823 * Setup_LDT_Keeper in the main thread before all others */
826 if( OpenVideo( p_dec ) )
829 p_dec->b_error = VLC_TRUE;
832 p_sys = p_dec->p_sys;
836 if( pp_block == NULL || *pp_block == NULL )
843 if( p_block->i_pts < mdate() )
852 if( p_sys->i_late > 10 )
854 msg_Dbg( p_dec, "too late buffer -> dropped" );
855 block_Release( p_block );
859 if( ( p_pic = p_dec->pf_vout_buffer_new( p_dec ) ) )
863 p_sys->decpar.data = p_block->p_buffer;
864 p_sys->decpar.bufferSize = p_block->i_buffer;
865 (**p_sys->framedescHandle).dataSize = p_block->i_buffer;
867 var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
868 vlc_mutex_lock( lockval.p_address );
869 cres = p_sys->ImageCodecBandDecompress( p_sys->ci, &p_sys->decpar );
870 vlc_mutex_unlock( lockval.p_address );
872 ++p_sys->decpar.frameNumber;
876 msg_Dbg( p_dec, "quicktime_video: ImageCodecBandDecompress"
877 " cres=0x%X (-0x%X) %d :(\n",
878 (int)cres,(int)-cres, (int)cres );
881 memcpy( p_pic->p[0].p_pixels,
883 p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 2 );
884 p_pic->date = p_block->i_pts;
886 block_Release( p_block );
891 /*****************************************************************************
893 *****************************************************************************/
894 static int QTAudioInit( decoder_t *p_dec )
896 decoder_sys_t *p_sys = p_dec->p_sys;
899 p_sys->SoundConverterOpen = (void*)SoundConverterOpen;
900 p_sys->SoundConverterClose = (void*)SoundConverterClose;
901 p_sys->SoundConverterSetInfo = (void*)SoundConverterSetInfo;
902 p_sys->SoundConverterGetBufferSizes = (void*)SoundConverterGetBufferSizes;
903 p_sys->SoundConverterConvertBuffer = (void*)SoundConverterConvertBuffer;
904 p_sys->SoundConverterBeginConversion= (void*)SoundConverterBeginConversion;
905 p_sys->SoundConverterEndConversion = (void*)SoundConverterEndConversion;
909 p_sys->ldt_fs = Setup_LDT_Keeper();
912 p_sys->qtml = LoadLibraryA( "qtmlClient.dll" );
913 if( p_sys->qtml == NULL )
915 msg_Dbg( p_dec, "failed loading qtmlClient.dll" );
919 p_sys->InitializeQTML = (void *)GetProcAddress( p_sys->qtml, "InitializeQTML" );
920 p_sys->TerminateQTML = (void *)GetProcAddress( p_sys->qtml, "TerminateQTML" );
921 p_sys->SoundConverterOpen = (void *)GetProcAddress( p_sys->qtml, "SoundConverterOpen" );
922 p_sys->SoundConverterClose = (void *)GetProcAddress( p_sys->qtml, "SoundConverterClose" );
923 p_sys->SoundConverterSetInfo = (void *)GetProcAddress( p_sys->qtml, "SoundConverterSetInfo" );
924 p_sys->SoundConverterGetBufferSizes = (void *)GetProcAddress( p_sys->qtml, "SoundConverterGetBufferSizes" );
925 p_sys->SoundConverterConvertBuffer = (void *)GetProcAddress( p_sys->qtml, "SoundConverterConvertBuffer" );
926 p_sys->SoundConverterEndConversion = (void *)GetProcAddress( p_sys->qtml, "SoundConverterEndConversion" );
927 p_sys->SoundConverterBeginConversion= (void *)GetProcAddress( p_sys->qtml, "SoundConverterBeginConversion");
929 if( p_sys->InitializeQTML == NULL )
931 msg_Err( p_dec, "failed geting proc address InitializeQTML" );
934 if( p_sys->SoundConverterOpen == NULL ||
935 p_sys->SoundConverterClose == NULL ||
936 p_sys->SoundConverterSetInfo == NULL ||
937 p_sys->SoundConverterGetBufferSizes == NULL ||
938 p_sys->SoundConverterConvertBuffer == NULL ||
939 p_sys->SoundConverterEndConversion == NULL ||
940 p_sys->SoundConverterBeginConversion == NULL )
942 msg_Err( p_dec, "failed geting proc address" );
946 msg_Dbg( p_dec, "Standard init done" );
947 #endif /* else SYS_DARWIN */
953 /*****************************************************************************
955 *****************************************************************************/
956 static int QTVideoInit( decoder_t *p_dec )
958 decoder_sys_t *p_sys = p_dec->p_sys;
961 p_sys->FindNextComponent = (void*)FindNextComponent;
962 p_sys->OpenComponent = (void*)OpenComponent;
963 p_sys->ImageCodecInitialize = (void*)ImageCodecInitialize;
964 p_sys->ImageCodecGetCodecInfo = (void*)ImageCodecGetCodecInfo;
965 p_sys->ImageCodecPreDecompress = (void*)ImageCodecPreDecompress;
966 p_sys->ImageCodecBandDecompress = (void*)ImageCodecBandDecompress;
967 p_sys->GetGWorldPixMap = (void*)GetGWorldPixMap;
968 p_sys->QTNewGWorldFromPtr = (void*)QTNewGWorldFromPtr;
969 p_sys->NewHandleClear = (void*)NewHandleClear;
973 p_sys->ldt_fs = Setup_LDT_Keeper();
975 p_sys->qtml = LoadLibraryA( "qtmlClient.dll" );
976 if( p_sys->qtml == NULL )
978 msg_Dbg( p_dec, "failed loading qtmlClient.dll" );
981 msg_Dbg( p_dec, "qtmlClient.dll loaded" );
983 /* (void*) to shut up gcc */
984 p_sys->InitializeQTML = (void*)GetProcAddress( p_sys->qtml, "InitializeQTML" );
985 p_sys->FindNextComponent = (void*)GetProcAddress( p_sys->qtml, "FindNextComponent" );
986 p_sys->OpenComponent = (void*)GetProcAddress( p_sys->qtml, "OpenComponent" );
987 p_sys->ImageCodecInitialize = (void*)GetProcAddress( p_sys->qtml, "ImageCodecInitialize" );
988 p_sys->ImageCodecGetCodecInfo = (void*)GetProcAddress( p_sys->qtml, "ImageCodecGetCodecInfo" );
989 p_sys->ImageCodecPreDecompress = (void*)GetProcAddress( p_sys->qtml, "ImageCodecPreDecompress" );
990 p_sys->ImageCodecBandDecompress = (void*)GetProcAddress( p_sys->qtml, "ImageCodecBandDecompress" );
991 p_sys->GetGWorldPixMap = (void*)GetProcAddress( p_sys->qtml, "GetGWorldPixMap" );
992 p_sys->QTNewGWorldFromPtr = (void*)GetProcAddress( p_sys->qtml, "QTNewGWorldFromPtr" );
993 p_sys->NewHandleClear = (void*)GetProcAddress( p_sys->qtml, "NewHandleClear" );
995 if( p_sys->InitializeQTML == NULL )
997 msg_Dbg( p_dec, "failed geting proc address InitializeQTML" );
1000 if( p_sys->FindNextComponent == NULL ||
1001 p_sys->OpenComponent == NULL ||
1002 p_sys->ImageCodecInitialize == NULL ||
1003 p_sys->ImageCodecGetCodecInfo == NULL ||
1004 p_sys->ImageCodecPreDecompress == NULL ||
1005 p_sys->ImageCodecBandDecompress == NULL ||
1006 p_sys->GetGWorldPixMap == NULL ||
1007 p_sys->QTNewGWorldFromPtr == NULL ||
1008 p_sys->NewHandleClear == NULL )
1010 msg_Err( p_dec, "failed geting proc address" );
1011 return VLC_EGENERIC;
1013 #endif /* SYS_DARWIN */