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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc/decoder.h>
34 #if !defined (__APPLE__) && !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 /* __APPLE__ */
118 OSErr (*InitializeQTML) ( long flags );
119 OSErr (*TerminateQTML) ( void );
120 #endif /* __APPLE__ */
123 int (*SoundConverterOpen) ( const SoundComponentData *,
124 const SoundComponentData *,
126 int (*SoundConverterClose) ( SoundConverter );
127 int (*SoundConverterSetInfo) ( SoundConverter , OSType, void * );
128 int (*SoundConverterGetBufferSizes) ( SoundConverter, unsigned long,
129 unsigned long*, unsigned long*,
131 int (*SoundConverterBeginConversion)( SoundConverter );
132 int (*SoundConverterEndConversion) ( SoundConverter, void *,
133 unsigned long *, unsigned long *);
134 int (*SoundConverterConvertBuffer) ( SoundConverter, const void *,
135 unsigned long, void *,
136 unsigned long *, unsigned long * );
137 SoundConverter myConverter;
138 SoundComponentData InputFormatInfo, OutputFormatInfo;
140 unsigned long FramesToGet;
141 unsigned int InFrameSize;
142 unsigned int OutFrameSize;
146 Component (*FindNextComponent)
147 ( Component prev, ComponentDescription* desc );
149 ComponentInstance (*OpenComponent)
152 ComponentResult (*ImageCodecInitialize)
153 ( ComponentInstance ci, ImageSubCodecDecompressCapabilities * cap);
155 ComponentResult (*ImageCodecGetCodecInfo)
156 ( ComponentInstance ci, CodecInfo *info );
158 ComponentResult (*ImageCodecPreDecompress)
159 ( ComponentInstance ci, CodecDecompressParams * params );
161 ComponentResult (*ImageCodecBandDecompress)
162 ( ComponentInstance ci, CodecDecompressParams * params );
164 PixMapHandle (*GetGWorldPixMap)
165 ( GWorldPtr offscreenGWorld );
167 OSErr (*QTNewGWorldFromPtr)
168 ( GWorldPtr *gw, OSType pixelFormat, const Rect *boundsRect,
169 CTabHandle cTable, /*GDHandle*/ void *aGDevice, /*unused*/
170 GWorldFlags flags, void *baseAddr, long rowBytes );
172 OSErr (*NewHandleClear)( Size byteCount );
174 ComponentInstance ci;
175 Rect OutBufferRect; /* the dimensions of our GWorld */
176 GWorldPtr OutBufferGWorld; /* a GWorld is some kind of
177 description for a drawing
179 ImageDescriptionHandle framedescHandle;
181 CodecDecompressParams decpar; /* for ImageCodecPreDecompress()*/
182 CodecCapabilities codeccap; /* for decpar */
185 /* Output properties */
190 int i_late; /* video */
193 unsigned int i_buffer;
194 unsigned int i_buffer_size;
198 uint8_t out_buffer[1000000]; /* FIXME */
203 static int pi_channels_maps[6] =
207 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
208 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER,
209 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT,
210 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
211 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT
214 static int QTAudioInit( decoder_t * );
215 static int QTVideoInit( decoder_t * );
217 /*****************************************************************************
218 * Open: probe the decoder and return score
219 *****************************************************************************
220 * Tries to launch a decoder and return score so that the interface is able
222 *****************************************************************************/
223 static int Open( vlc_object_t *p_this )
225 decoder_t *p_dec = (decoder_t*)p_this;
227 switch( p_dec->fmt_in.i_codec )
229 case VLC_FOURCC('S','V','Q','3'): /* Sorenson v3 */
230 /* case VLC_FOURCC('S','V','Q','1'): Sorenson v1
231 case VLC_FOURCC('Z','y','G','o'):
232 case VLC_FOURCC('V','P','3','1'):
233 case VLC_FOURCC('3','I','V','1'): */
234 case VLC_FOURCC('r','l','e',' '): /* QuickTime animation (RLE) */
235 case VLC_FOURCC('r','p','z','a'): /* QuickTime Apple Video */
236 case VLC_FOURCC('a','z','p','r'): /* QuickTime animation (RLE) */
239 p_dec->pf_decode_video = DecodeVideo;
242 return OpenVideo( p_dec );
245 case VLC_FOURCC('s','a','m','r'): /* 3GPP AMR audio */
246 case VLC_FOURCC('m','p','4','a'): /* MPEG-4 audio */
247 case VLC_FOURCC('Q','D','M','C'): /* QDesign */
248 case VLC_FOURCC('Q','D','M','2'): /* QDesign* 2 */
249 case VLC_FOURCC('Q','c','l','p'): /* Qualcomm Purevoice Codec */
250 case VLC_FOURCC('Q','C','L','P'): /* Qualcomm Purevoice Codec */
251 case VLC_FOURCC('M','A','C','3'): /* MACE3 audio decoder */
252 case VLC_FOURCC('M','A','C','6'): /* MACE6 audio decoder */
253 case VLC_FOURCC('d','v','c','a'): /* DV Audio */
254 case VLC_FOURCC('s','o','w','t'): /* 16-bit Little Endian */
255 case VLC_FOURCC('t','w','o','s'): /* 16-bit Big Endian */
256 case VLC_FOURCC('a','l','a','w'): /* ALaw 2:1 */
257 case VLC_FOURCC('u','l','a','w'): /* mu-Law 2:1 */
258 case VLC_FOURCC('r','a','w',' '): /* 8-bit offset binaries */
259 case VLC_FOURCC('f','l','3','2'): /* 32-bit Floating Point */
260 case VLC_FOURCC('f','l','6','4'): /* 64-bit Floating Point */
261 case VLC_FOURCC('i','n','2','4'): /* 24-bit Interger */
262 case VLC_FOURCC('i','n','3','2'): /* 32-bit Integer */
263 case 0x0011: /* DVI IMA */
264 case 0x6D730002: /* Microsoft ADPCM-ACM */
265 case 0x6D730011: /* DVI Intel IMAADPCM-ACM */
268 p_dec->pf_decode_audio = DecodeAudio;
271 return OpenAudio( p_dec );
279 /*****************************************************************************
281 *****************************************************************************/
282 static void Close( vlc_object_t *p_this )
284 decoder_t *p_dec = (decoder_t*)p_this;
285 decoder_sys_t *p_sys = p_dec->p_sys;
288 /* get lock, avoid segfault */
289 var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
290 vlc_mutex_lock( lockval.p_address );
292 /* on OS X QT is not threadsafe */
293 vlc_mutex_lock( &p_dec->p_vlc->quicktime_lock );
296 if( p_dec->fmt_out.i_cat == AUDIO_ES )
299 unsigned long ConvertedFrames=0;
300 unsigned long ConvertedBytes=0;
302 i_error = p_sys->SoundConverterEndConversion( p_sys->myConverter, NULL,
305 msg_Dbg( p_dec, "SoundConverterEndConversion => %d", i_error );
307 i_error = p_sys->SoundConverterClose( p_sys->myConverter );
308 msg_Dbg( p_dec, "SoundConverterClose => %d", i_error );
310 if( p_sys->p_buffer ) free( p_sys->p_buffer );
312 else if( p_dec->fmt_out.i_cat == VIDEO_ES )
314 if( p_sys->plane) free( p_sys->plane );
318 FreeLibrary( p_sys->qtml );
319 FreeLibrary( p_sys->qts );
320 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 unsigned 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, "ImageCodecInitialize->0x%X size=%ld (%ld)\n",(int)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 depth=%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,
766 p_sys->framedescHandle =
767 (ImageDescriptionHandle) p_sys->NewHandleClear( id->idSize );
768 memcpy( *p_sys->framedescHandle, id, id->idSize );
770 p_sys->plane = malloc( p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 3 );
772 i_result = p_sys->QTNewGWorldFromPtr( &p_sys->OutBufferGWorld,
773 /*pixel format of new GWorld==YUY2 */
775 /* we should benchmark if yvu9 is
776 * faster for svq3, too */
777 &p_sys->OutBufferRect,
780 (long)p_dec->fmt_in.video.i_width * 2 );
782 msg_Dbg( p_dec, "NewGWorldFromPtr returned:%ld\n",
783 65536 - ( i_result&0xffff ) );
785 memset( &p_sys->decpar, 0, sizeof( CodecDecompressParams ) );
786 p_sys->decpar.imageDescription = p_sys->framedescHandle;
787 p_sys->decpar.startLine = 0;
788 p_sys->decpar.stopLine = ( **p_sys->framedescHandle ).height;
789 p_sys->decpar.frameNumber = 1;
790 p_sys->decpar.matrixFlags = 0;
791 p_sys->decpar.matrixType = 0;
792 p_sys->decpar.matrix = 0;
793 p_sys->decpar.capabilities = &p_sys->codeccap;
794 p_sys->decpar.accuracy = codecNormalQuality;
795 p_sys->decpar.srcRect = p_sys->OutBufferRect;
796 p_sys->decpar.transferMode = srcCopy;
797 p_sys->decpar.dstPixMap = **p_sys->GetGWorldPixMap( p_sys->OutBufferGWorld );/*destPixmap; */
799 cres = p_sys->ImageCodecPreDecompress( p_sys->ci, &p_sys->decpar );
800 msg_Dbg( p_dec, "quicktime_video: ImageCodecPreDecompress cres=0x%X\n",
803 es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_FOURCC( 'Y', 'U', 'Y', '2' ));
804 p_dec->fmt_out.video.i_width = p_dec->fmt_in.video.i_width;
805 p_dec->fmt_out.video.i_height= p_dec->fmt_in.video.i_height;
806 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;
834 ComponentResult cres;
837 /* We must do open and close in the same thread (unless we do
838 * Setup_LDT_Keeper in the main thread before all others */
841 if( OpenVideo( p_dec ) )
844 p_dec->b_error = VLC_TRUE;
847 p_sys = p_dec->p_sys;
851 if( pp_block == NULL || *pp_block == NULL )
857 if( !p_block->i_buffer )
859 block_Release( p_block );
863 i_pts = p_block->i_pts ? p_block->i_pts : p_block->i_dts;
865 if( i_pts < mdate() )
873 msg_Dbg( p_dec, "bufsize: %d",p_block->i_buffer);
875 if( p_sys->i_late > 10 )
877 msg_Dbg( p_dec, "too late buffer -> dropped" );
878 block_Release( p_block );
882 var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
883 vlc_mutex_lock( lockval.p_address );
885 if( ( p_pic = p_dec->pf_vout_buffer_new( p_dec ) ) )
887 p_sys->decpar.data = (Ptr)p_block->p_buffer;
888 p_sys->decpar.bufferSize = p_block->i_buffer;
889 (**p_sys->framedescHandle).dataSize = p_block->i_buffer;
891 cres = p_sys->ImageCodecBandDecompress( p_sys->ci, &p_sys->decpar );
893 ++p_sys->decpar.frameNumber;
897 msg_Dbg( p_dec, "quicktime_video: ImageCodecBandDecompress"
898 " cres=0x%X (-0x%X) %d :(\n",
899 (int)cres,(int)-cres, (int)cres );
902 memcpy( p_pic->p[0].p_pixels, p_sys->plane,
903 p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 2 );
908 vlc_mutex_unlock( lockval.p_address );
910 block_Release( p_block );
915 /*****************************************************************************
917 *****************************************************************************/
918 static int QTAudioInit( decoder_t *p_dec )
920 decoder_sys_t *p_sys = p_dec->p_sys;
923 p_sys->SoundConverterOpen = (void*)SoundConverterOpen;
924 p_sys->SoundConverterClose = (void*)SoundConverterClose;
925 p_sys->SoundConverterSetInfo = (void*)SoundConverterSetInfo;
926 p_sys->SoundConverterGetBufferSizes = (void*)SoundConverterGetBufferSizes;
927 p_sys->SoundConverterConvertBuffer = (void*)SoundConverterConvertBuffer;
928 p_sys->SoundConverterBeginConversion= (void*)SoundConverterBeginConversion;
929 p_sys->SoundConverterEndConversion = (void*)SoundConverterEndConversion;
933 p_sys->ldt_fs = Setup_LDT_Keeper();
936 p_sys->qts = LoadLibraryA( "QuickTime.qts" );
937 if( p_sys->qts == NULL )
939 msg_Dbg( p_dec, "failed loading QuickTime.qts" );
942 p_sys->qtml = LoadLibraryA( "qtmlClient.dll" );
943 if( p_sys->qtml == NULL )
945 msg_Dbg( p_dec, "failed loading qtmlClient.dll" );
949 p_sys->InitializeQTML = (void *)GetProcAddress( p_sys->qtml, "InitializeQTML" );
950 p_sys->TerminateQTML = (void *)GetProcAddress( p_sys->qtml, "TerminateQTML" );
951 p_sys->SoundConverterOpen = (void *)GetProcAddress( p_sys->qtml, "SoundConverterOpen" );
952 p_sys->SoundConverterClose = (void *)GetProcAddress( p_sys->qtml, "SoundConverterClose" );
953 p_sys->SoundConverterSetInfo = (void *)GetProcAddress( p_sys->qtml, "SoundConverterSetInfo" );
954 p_sys->SoundConverterGetBufferSizes = (void *)GetProcAddress( p_sys->qtml, "SoundConverterGetBufferSizes" );
955 p_sys->SoundConverterConvertBuffer = (void *)GetProcAddress( p_sys->qtml, "SoundConverterConvertBuffer" );
956 p_sys->SoundConverterEndConversion = (void *)GetProcAddress( p_sys->qtml, "SoundConverterEndConversion" );
957 p_sys->SoundConverterBeginConversion= (void *)GetProcAddress( p_sys->qtml, "SoundConverterBeginConversion");
959 if( p_sys->InitializeQTML == NULL )
961 msg_Err( p_dec, "failed getting proc address InitializeQTML" );
964 if( p_sys->SoundConverterOpen == NULL ||
965 p_sys->SoundConverterClose == NULL ||
966 p_sys->SoundConverterSetInfo == NULL ||
967 p_sys->SoundConverterGetBufferSizes == NULL ||
968 p_sys->SoundConverterConvertBuffer == NULL ||
969 p_sys->SoundConverterEndConversion == NULL ||
970 p_sys->SoundConverterBeginConversion == NULL )
972 msg_Err( p_dec, "failed getting proc address" );
976 msg_Dbg( p_dec, "Standard init done" );
977 #endif /* else __APPLE__ */
983 /*****************************************************************************
985 *****************************************************************************/
986 static int QTVideoInit( decoder_t *p_dec )
988 decoder_sys_t *p_sys = p_dec->p_sys;
991 p_sys->FindNextComponent = (void*)FindNextComponent;
992 p_sys->OpenComponent = (void*)OpenComponent;
993 p_sys->ImageCodecInitialize = (void*)ImageCodecInitialize;
994 p_sys->ImageCodecGetCodecInfo = (void*)ImageCodecGetCodecInfo;
995 p_sys->ImageCodecPreDecompress = (void*)ImageCodecPreDecompress;
996 p_sys->ImageCodecBandDecompress = (void*)ImageCodecBandDecompress;
997 p_sys->GetGWorldPixMap = (void*)GetGWorldPixMap;
998 p_sys->QTNewGWorldFromPtr = (void*)QTNewGWorldFromPtr;
999 p_sys->NewHandleClear = (void*)NewHandleClear;
1003 p_sys->ldt_fs = Setup_LDT_Keeper();
1005 p_sys->qts = LoadLibraryA( "QuickTime.qts" );
1006 if( p_sys->qts == NULL )
1008 msg_Dbg( p_dec, "failed loading QuickTime.qts" );
1009 return VLC_EGENERIC;
1011 msg_Dbg( p_dec, "QuickTime.qts loaded" );
1012 p_sys->qtml = LoadLibraryA( "qtmlClient.dll" );
1013 if( p_sys->qtml == NULL )
1015 msg_Dbg( p_dec, "failed loading qtmlClient.dll" );
1016 return VLC_EGENERIC;
1018 msg_Dbg( p_dec, "qtmlClient.dll loaded" );
1020 /* (void*) to shut up gcc */
1021 p_sys->InitializeQTML = (void*)GetProcAddress( p_sys->qtml, "InitializeQTML" );
1022 p_sys->FindNextComponent = (void*)GetProcAddress( p_sys->qtml, "FindNextComponent" );
1023 p_sys->OpenComponent = (void*)GetProcAddress( p_sys->qtml, "OpenComponent" );
1024 p_sys->ImageCodecInitialize = (void*)GetProcAddress( p_sys->qtml, "ImageCodecInitialize" );
1025 p_sys->ImageCodecGetCodecInfo = (void*)GetProcAddress( p_sys->qtml, "ImageCodecGetCodecInfo" );
1026 p_sys->ImageCodecPreDecompress = (void*)GetProcAddress( p_sys->qtml, "ImageCodecPreDecompress" );
1027 p_sys->ImageCodecBandDecompress = (void*)GetProcAddress( p_sys->qtml, "ImageCodecBandDecompress" );
1028 p_sys->GetGWorldPixMap = (void*)GetProcAddress( p_sys->qtml, "GetGWorldPixMap" );
1029 p_sys->QTNewGWorldFromPtr = (void*)GetProcAddress( p_sys->qtml, "QTNewGWorldFromPtr" );
1030 p_sys->NewHandleClear = (void*)GetProcAddress( p_sys->qtml, "NewHandleClear" );
1032 if( p_sys->InitializeQTML == NULL )
1034 msg_Dbg( p_dec, "failed getting proc address InitializeQTML" );
1035 return VLC_EGENERIC;
1037 if( p_sys->FindNextComponent == NULL ||
1038 p_sys->OpenComponent == NULL ||
1039 p_sys->ImageCodecInitialize == NULL ||
1040 p_sys->ImageCodecGetCodecInfo == NULL ||
1041 p_sys->ImageCodecPreDecompress == NULL ||
1042 p_sys->ImageCodecBandDecompress == NULL ||
1043 p_sys->GetGWorldPixMap == NULL ||
1044 p_sys->QTNewGWorldFromPtr == NULL ||
1045 p_sys->NewHandleClear == NULL )
1047 msg_Err( p_dec, "failed getting proc address" );
1048 return VLC_EGENERIC;
1050 #endif /* __APPLE__ */