1 /*****************************************************************************
2 * quicktime.c: a quicktime decoder that uses the QT library/dll
3 *****************************************************************************
4 * Copyright (C) 2003, 2008 - 2009 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir at via.ecp.fr>
8 * Derk-Jan Hartman <hartman at videolan.org>>
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 *****************************************************************************/
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
37 #include <vlc_codec.h>
39 #if !defined (__APPLE__) && !defined(WIN32)
44 #include <QuickTime/QuickTimeComponents.h>
45 #include <QuickTime/Movies.h>
46 #include <QuickTime/ImageCodec.h>
49 /* for windows do we require Quicktime compents header? */
51 #include "qtx/qtxsdk/components.h"
52 #include "wine/windef.h"
53 #include "ldt_keeper.h"
55 HMODULE WINAPI LoadLibraryA(LPCSTR);
56 FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR);
57 int WINAPI FreeLibrary(HMODULE);
61 /*****************************************************************************
63 *****************************************************************************/
64 static int Open ( vlc_object_t * );
65 static void Close( vlc_object_t * );
68 set_description( N_("QuickTime library decoder") )
69 set_capability( "decoder", 0 )
70 set_category( CAT_INPUT )
71 set_subcategory( SUBCAT_INPUT_VCODEC )
72 set_callbacks( Open, Close )
77 /*****************************************************************************
79 *****************************************************************************/
80 static int OpenAudio( decoder_t * );
81 static int OpenVideo( decoder_t * );
83 static aout_buffer_t *DecodeAudio( decoder_t *, block_t ** );
84 static picture_t *DecodeVideo( decoder_t *, block_t ** );
86 #define FCC( a, b , c, d ) \
87 ((uint32_t)( ((a)<<24)|((b)<<16)|((c)<<8)|(d)))
90 typedef struct OpaqueSoundConverter* SoundConverter;
95 typedef unsigned long UnsignedFixed;
98 typedef struct SoundComponentData {
103 UnsignedFixed sampleRate;
107 } SoundComponentData;
109 #endif /* __APPLE__ */
121 OSErr (*InitializeQTML) ( long flags );
122 OSErr (*TerminateQTML) ( void );
123 #endif /* __APPLE__ */
126 int (*SoundConverterOpen) ( const SoundComponentData *,
127 const SoundComponentData *,
129 int (*SoundConverterClose) ( SoundConverter );
130 int (*SoundConverterSetInfo) ( SoundConverter , OSType, void * );
131 int (*SoundConverterGetBufferSizes) ( SoundConverter, unsigned long,
132 unsigned long*, unsigned long*,
134 int (*SoundConverterBeginConversion)( SoundConverter );
135 int (*SoundConverterEndConversion) ( SoundConverter, void *,
136 unsigned long *, unsigned long *);
137 int (*SoundConverterConvertBuffer) ( SoundConverter, const void *,
138 unsigned long, void *,
139 unsigned long *, unsigned long * );
140 SoundConverter myConverter;
141 SoundComponentData InputFormatInfo, OutputFormatInfo;
143 unsigned long FramesToGet;
144 unsigned int InFrameSize;
145 unsigned int OutFrameSize;
149 Component (*FindNextComponent)
150 ( Component prev, ComponentDescription* desc );
152 ComponentInstance (*OpenComponent)
155 ComponentResult (*ImageCodecInitialize)
156 ( ComponentInstance ci, ImageSubCodecDecompressCapabilities * cap);
158 ComponentResult (*ImageCodecGetCodecInfo)
159 ( ComponentInstance ci, CodecInfo *info );
161 ComponentResult (*ImageCodecPreDecompress)
162 ( ComponentInstance ci, CodecDecompressParams * params );
164 ComponentResult (*ImageCodecBandDecompress)
165 ( ComponentInstance ci, CodecDecompressParams * params );
167 PixMapHandle (*GetGWorldPixMap)
168 ( GWorldPtr offscreenGWorld );
170 OSErr (*QTNewGWorldFromPtr)
171 ( GWorldPtr *gw, OSType pixelFormat, const Rect *boundsRect,
172 CTabHandle cTable, /*GDHandle*/ void *aGDevice, /*unused*/
173 GWorldFlags flags, void *baseAddr, long rowBytes );
175 OSErr (*NewHandleClear)( Size byteCount );
177 ComponentInstance ci;
178 Rect OutBufferRect; /* the dimensions of our GWorld */
179 GWorldPtr OutBufferGWorld; /* a GWorld is some kind of
180 description for a drawing
182 ImageDescriptionHandle framedescHandle;
184 CodecDecompressParams decpar; /* for ImageCodecPreDecompress()*/
185 CodecCapabilities codeccap; /* for decpar */
188 /* Output properties */
193 int i_late; /* video */
196 unsigned int i_buffer;
197 unsigned int i_buffer_size;
201 uint8_t out_buffer[1000000]; /* FIXME */
206 static const int pi_channels_maps[6] =
210 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
211 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER,
212 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT,
213 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
214 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT
217 static int QTAudioInit( decoder_t * );
218 static int QTVideoInit( decoder_t * );
220 /*****************************************************************************
221 * Open: probe the decoder and return score
222 *****************************************************************************
223 * Tries to launch a decoder and return score so that the interface is able
225 *****************************************************************************/
226 static int Open( vlc_object_t *p_this )
228 decoder_t *p_dec = (decoder_t*)p_this;
232 SInt32 qtVersion, macosversion;
234 err = Gestalt(gestaltQuickTimeVersion, &qtVersion);
235 err = Gestalt(gestaltSystemVersion, &macosversion);
237 msg_Dbg( p_this, "Mac OS version is %#lx", macosversion );
238 msg_Dbg( p_this, "Quicktime version is %#lx", qtVersion );
241 /* bail out. This plugin is soo Carbon, that it can't be used on 10.5 at all */
242 msg_Info( p_dec, "Your Mac OS version is to new to use this plugin for anything." );
246 switch( p_dec->fmt_in.i_codec )
249 case VLC_CODEC_CINEPAK:
250 case VLC_FOURCC('I','V','4','1'): /* Indeo Video IV */
251 case VLC_FOURCC('i','v','4','1'): /* dto. */
253 case VLC_FOURCC('p','x','l','t'): /* Pixlet */
256 case VLC_CODEC_SVQ3: /* Sorenson v3 */
257 /* case VLC_CODEC_SVQ1: Sorenson v1
258 case VLC_FOURCC('Z','y','G','o'):
259 case VLC_FOURCC('V','P','3','1'):
260 case VLC_FOURCC('3','I','V','1'): */
261 case VLC_CODEC_QTRLE:
265 p_dec->pf_decode_video = DecodeVideo;
266 p_dec->fmt_out.i_cat = VIDEO_ES;
269 return OpenVideo( p_dec );
273 case VLC_FOURCC('I','L','B','C'): /* iLBC */
274 if ((err != noErr) || (qtVersion < 0x07500000))
276 case VLC_FOURCC('i','l','b','c'): /* iLBC */
277 if ((err != noErr) || (qtVersion < 0x07500000))
280 case VLC_CODEC_AMR_NB: /* 3GPP AMR audio */
281 case VLC_FOURCC('s','a','m','b'): /* 3GPP AMR-WB audio */
282 case VLC_CODEC_MP4A: /* MPEG-4 audio */
283 case VLC_FOURCC('Q','D','M','C'): /* QDesign */
284 case VLC_CODEC_QDM2: /* QDesign* 2 */
285 case VLC_CODEC_QCELP: /* Qualcomm Purevoice Codec */
286 case VLC_FOURCC('Q','C','L','P'): /* Qualcomm Purevoice Codec */
287 case VLC_CODEC_MACE3: /* MACE3 audio decoder */
288 case VLC_CODEC_MACE6: /* MACE6 audio decoder */
289 case VLC_FOURCC('d','v','c','a'): /* DV Audio */
290 case VLC_FOURCC('s','o','w','t'): /* 16-bit Little Endian */
291 case VLC_FOURCC('t','w','o','s'): /* 16-bit Big Endian */
292 case VLC_CODEC_ALAW: /* ALaw 2:1 */
293 case VLC_FOURCC('u','l','a','w'): /* mu-Law 2:1 */
294 case VLC_FOURCC('r','a','w',' '): /* 8-bit offset binaries */
295 case VLC_CODEC_FL32: /* 32-bit Floating Point */
296 case VLC_CODEC_FL64: /* 64-bit Floating Point */
297 case VLC_FOURCC('i','n','2','4'): /* 24-bit Interger */
298 case VLC_FOURCC('i','n','3','2'): /* 32-bit Integer */
299 case 0x0011: /* DVI IMA */
300 case 0x6D730002: /* Microsoft ADPCM-ACM */
301 case 0x6D730011: /* DVI Intel IMAADPCM-ACM */
304 p_dec->pf_decode_audio = DecodeAudio;
305 p_dec->fmt_out.i_cat = AUDIO_ES;
308 return OpenAudio( p_dec );
316 static vlc_mutex_t qt_mutex = VLC_STATIC_MUTEX;
318 /*****************************************************************************
320 *****************************************************************************/
321 static void Close( vlc_object_t *p_this )
323 decoder_t *p_dec = (decoder_t*)p_this;
324 decoder_sys_t *p_sys = p_dec->p_sys;
326 /* get lock, avoid segfault */
327 vlc_mutex_lock( &qt_mutex );
329 if( p_dec->fmt_out.i_cat == AUDIO_ES )
332 unsigned long ConvertedFrames=0;
333 unsigned long ConvertedBytes=0;
335 i_error = p_sys->SoundConverterEndConversion( p_sys->myConverter, NULL,
338 msg_Dbg( p_dec, "SoundConverterEndConversion => %d", i_error );
340 i_error = p_sys->SoundConverterClose( p_sys->myConverter );
341 msg_Dbg( p_dec, "SoundConverterClose => %d", i_error );
343 free( p_sys->p_buffer );
345 else if( p_dec->fmt_out.i_cat == VIDEO_ES )
347 free( p_sys->plane );
351 FreeLibrary( p_sys->qtml );
352 FreeLibrary( p_sys->qts );
353 msg_Dbg( p_dec, "FreeLibrary ok." );
361 Restore_LDT_Keeper( p_sys->ldt_fs );
362 msg_Dbg( p_dec, "Restore_LDT_Keeper" );
366 vlc_mutex_unlock( &qt_mutex );
371 /*****************************************************************************
373 *****************************************************************************/
374 static int OpenAudio( decoder_t *p_dec )
376 decoder_sys_t *p_sys;
380 unsigned long WantedBufferSize;
381 unsigned long InputBufferSize = 0;
382 unsigned long OutputBufferSize = 0;
384 /* get lock, avoid segfault */
385 vlc_mutex_lock( &qt_mutex );
387 p_sys = calloc( 1, sizeof( decoder_sys_t ) );
388 p_dec->p_sys = p_sys;
389 p_dec->pf_decode_audio = DecodeAudio;
391 if( p_dec->fmt_in.i_original_fourcc )
392 memcpy( fcc, &p_dec->fmt_in.i_original_fourcc, 4 );
394 memcpy( fcc, &p_dec->fmt_in.i_codec, 4 );
400 if( QTAudioInit( p_dec ) )
402 msg_Err( p_dec, "cannot initialize QT");
407 if( ( i_error = p_sys->InitializeQTML( 6 + 16 ) ) )
409 msg_Dbg( p_dec, "error on InitializeQTML = %d", i_error );
414 /* input format settings */
415 p_sys->InputFormatInfo.flags = 0;
416 p_sys->InputFormatInfo.sampleCount = 0;
417 p_sys->InputFormatInfo.buffer = NULL;
418 p_sys->InputFormatInfo.reserved = 0;
419 p_sys->InputFormatInfo.numChannels = p_dec->fmt_in.audio.i_channels;
420 p_sys->InputFormatInfo.sampleSize = p_dec->fmt_in.audio.i_bitspersample;
421 p_sys->InputFormatInfo.sampleRate = p_dec->fmt_in.audio.i_rate;
422 p_sys->InputFormatInfo.format = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );
424 /* output format settings */
425 p_sys->OutputFormatInfo.flags = 0;
426 p_sys->OutputFormatInfo.sampleCount = 0;
427 p_sys->OutputFormatInfo.buffer = NULL;
428 p_sys->OutputFormatInfo.reserved = 0;
429 p_sys->OutputFormatInfo.numChannels = p_dec->fmt_in.audio.i_channels;
430 p_sys->OutputFormatInfo.sampleSize = 16;
431 p_sys->OutputFormatInfo.sampleRate = p_dec->fmt_in.audio.i_rate;
432 p_sys->OutputFormatInfo.format = FCC( 'N', 'O', 'N', 'E' );
435 i_error = p_sys->SoundConverterOpen( &p_sys->InputFormatInfo,
436 &p_sys->OutputFormatInfo,
437 &p_sys->myConverter );
440 msg_Err( p_dec, "error on SoundConverterOpen = %d", i_error );
445 /* tell the sound converter we accept VBR formats */
446 i_error = SoundConverterSetInfo( p_dec->myConverter, siClientAcceptsVBR,
450 if( p_dec->fmt_in.i_extra > 36 + 8 )
452 i_error = p_sys->SoundConverterSetInfo( p_sys->myConverter,
453 FCC( 'w', 'a', 'v', 'e' ),
454 ((uint8_t*)p_dec->fmt_in.p_extra) + 36 + 8 );
456 msg_Dbg( p_dec, "error on SoundConverterSetInfo = %d", i_error );
459 WantedBufferSize = p_sys->OutputFormatInfo.numChannels *
460 p_sys->OutputFormatInfo.sampleRate * 2;
461 p_sys->FramesToGet = 0;
463 i_error = p_sys->SoundConverterGetBufferSizes( p_sys->myConverter,
469 msg_Dbg( p_dec, "WantedBufferSize=%li InputBufferSize=%li "
470 "OutputBufferSize=%li FramesToGet=%li",
471 WantedBufferSize, InputBufferSize, OutputBufferSize,
472 p_sys->FramesToGet );
474 p_sys->InFrameSize = (InputBufferSize + p_sys->FramesToGet - 1 ) /
476 p_sys->OutFrameSize = OutputBufferSize / p_sys->FramesToGet;
478 msg_Dbg( p_dec, "frame size %d -> %d",
479 p_sys->InFrameSize, p_sys->OutFrameSize );
481 if( (i_error = p_sys->SoundConverterBeginConversion(p_sys->myConverter)) )
484 "error on SoundConverterBeginConversion = %d", i_error );
489 es_format_Init( &p_dec->fmt_out, AUDIO_ES, VLC_CODEC_S16N );
490 p_dec->fmt_out.audio.i_rate = p_sys->OutputFormatInfo.sampleRate;
491 p_dec->fmt_out.audio.i_channels = p_sys->OutputFormatInfo.numChannels;
492 p_dec->fmt_out.audio.i_physical_channels =
493 p_dec->fmt_out.audio.i_original_channels =
494 pi_channels_maps[p_sys->OutputFormatInfo.numChannels];
496 aout_DateInit( &p_sys->date, p_dec->fmt_out.audio.i_rate );
499 p_sys->i_buffer_size = 100*1000;
500 p_sys->p_buffer = malloc( p_sys->i_buffer_size );
501 if( !p_sys->p_buffer )
505 p_sys->i_out_frames = 0;
507 vlc_mutex_unlock( &qt_mutex );
513 Restore_LDT_Keeper( p_sys->ldt_fs );
515 vlc_mutex_unlock( &qt_mutex );
521 /*****************************************************************************
523 *****************************************************************************/
524 static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
526 decoder_sys_t *p_sys = p_dec->p_sys;
532 /* We must do open and close in the same thread (unless we do
533 * Setup_LDT_Keeper in the main thread before all others */
536 if( OpenAudio( p_dec ) )
539 p_dec->b_error = true;
543 p_sys = p_dec->p_sys;
547 if( pp_block == NULL || *pp_block == NULL )
553 if( p_sys->i_out_frames > 0 && p_sys->i_out >= p_sys->i_out_frames )
557 p_sys->i_out_frames = 0;
563 if( p_sys->i_out_frames <= 0 )
565 p_sys->pts = p_block->i_pts;
567 mtime_t i_display_date = 0;
568 if( !(p_block->i_flags & BLOCK_FLAG_PREROLL) )
569 i_display_date = decoder_GetDisplayDate( p_dec, p_block->i_pts );
571 if( i_display_date > 0 && i_display_date < mdate() )
573 block_Release( p_block );
579 if( p_sys->i_buffer_size < p_sys->i_buffer + p_block->i_buffer )
581 p_sys->i_buffer_size = p_sys->i_buffer + p_block->i_buffer + 1024;
582 p_sys->p_buffer = realloc( p_sys->p_buffer, p_sys->i_buffer_size );
584 memcpy( &p_sys->p_buffer[p_sys->i_buffer], p_block->p_buffer,
586 p_sys->i_buffer += p_block->i_buffer;
588 if( p_sys->i_buffer > p_sys->InFrameSize )
590 int i_frames = p_sys->i_buffer / p_sys->InFrameSize;
591 unsigned long i_out_frames, i_out_bytes;
592 vlc_mutex_lock( &qt_mutex );
594 i_error = p_sys->SoundConverterConvertBuffer( p_sys->myConverter,
600 vlc_mutex_unlock( &qt_mutex );
603 msg_Dbg( p_dec, "decoded %d frames -> %ld frames (error=%d)",
604 i_frames, i_out_frames, i_error );
606 msg_Dbg( p_dec, "decoded %ld frames = %ld bytes",
607 i_out_frames, i_out_bytes );
610 p_sys->i_buffer -= i_frames * p_sys->InFrameSize;
611 if( p_sys->i_buffer > 0 )
613 memmove( &p_sys->p_buffer[0],
614 &p_sys->p_buffer[i_frames * p_sys->InFrameSize],
618 if( p_sys->pts != 0 &&
619 p_sys->pts != aout_DateGet( &p_sys->date ) )
621 aout_DateSet( &p_sys->date, p_sys->pts );
623 else if( !aout_DateGet( &p_sys->date ) )
628 if( !i_error && i_out_frames > 0 )
630 /* we have others samples */
631 p_sys->i_out_frames = i_out_frames;
637 if( p_sys->i_out < p_sys->i_out_frames )
639 aout_buffer_t *p_out;
640 int i_frames = __MIN( p_sys->i_out_frames - p_sys->i_out, 1000 );
642 p_out = decoder_NewAudioBuffer( p_dec, i_frames );
646 p_out->start_date = aout_DateGet( &p_sys->date );
647 p_out->end_date = aout_DateIncrement( &p_sys->date, i_frames );
649 memcpy( p_out->p_buffer,
650 &p_sys->out_buffer[2 * p_sys->i_out * p_dec->fmt_out.audio.i_channels],
653 p_sys->i_out += i_frames;
661 /*****************************************************************************
663 *****************************************************************************/
664 static int OpenVideo( decoder_t *p_dec )
667 decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );
672 ComponentDescription desc;
674 ComponentResult cres;
675 ImageSubCodecDecompressCapabilities icap; /* for ImageCodecInitialize() */
676 CodecInfo cinfo; /* for ImageCodecGetCodecInfo() */
677 ImageDescription *id;
680 int i_vide = p_dec->fmt_in.i_extra;
681 uint8_t *p_vide = p_dec->fmt_in.p_extra;
683 p_dec->p_sys = p_sys;
684 p_dec->pf_decode_video = DecodeVideo;
689 msg_Err( p_dec, "missing extra info" );
694 if( p_dec->fmt_in.i_original_fourcc )
695 memcpy( fcc, &p_dec->fmt_in.i_original_fourcc, 4 );
697 memcpy( fcc, &p_dec->fmt_in.i_codec, 4 );
699 msg_Dbg( p_dec, "quicktime_video %4.4s %dx%d",
700 fcc, p_dec->fmt_in.video.i_width, p_dec->fmt_in.video.i_height );
702 /* get lock, avoid segfault */
703 vlc_mutex_lock( &qt_mutex );
709 if( QTVideoInit( p_dec ) )
711 msg_Err( p_dec, "cannot initialize QT");
716 if( ( i_result = p_sys->InitializeQTML( 6 + 16 ) ) )
718 msg_Dbg( p_dec, "error on InitializeQTML = %d", (int)i_result );
723 /* init ComponentDescription */
724 memset( &desc, 0, sizeof( ComponentDescription ) );
725 desc.componentType = FCC( 'i', 'm', 'd', 'c' );
726 desc.componentSubType = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );
727 desc.componentManufacturer = 0;
728 desc.componentFlags = 0;
729 desc.componentFlagsMask = 0;
731 if( !( prev = p_sys->FindNextComponent( NULL, &desc ) ) )
733 msg_Err( p_dec, "cannot find requested component" );
736 msg_Dbg( p_dec, "component id=0x%p", prev );
738 p_sys->ci = p_sys->OpenComponent( prev );
739 msg_Dbg( p_dec, "component instance p=0x%p", p_sys->ci );
741 memset( &icap, 0, sizeof( ImageSubCodecDecompressCapabilities ) );
742 cres = p_sys->ImageCodecInitialize( p_sys->ci, &icap );
743 msg_Dbg( p_dec, "ImageCodecInitialize->0x%X size=%d (%d)",
744 (int)cres, (int)icap.recordSize, (int)icap.decompressRecordSize);
746 memset( &cinfo, 0, sizeof( CodecInfo ) );
747 cres = p_sys->ImageCodecGetCodecInfo( p_sys->ci, &cinfo );
749 "Flags: compr: 0x%x decomp: 0x%x format: 0x%x",
750 (unsigned int)cinfo.compressFlags,
751 (unsigned int)cinfo.decompressFlags,
752 (unsigned int)cinfo.formatFlags );
753 msg_Dbg( p_dec, "quicktime_video: Codec name: %.*s",
754 ((unsigned char*)&cinfo.typeName)[0],
755 ((unsigned char*)&cinfo.typeName)+1 );
757 /* make a yuy2 gworld */
758 p_sys->OutBufferRect.top = 0;
759 p_sys->OutBufferRect.left = 0;
760 p_sys->OutBufferRect.right = p_dec->fmt_in.video.i_width;
761 p_sys->OutBufferRect.bottom = p_dec->fmt_in.video.i_height;
764 /* codec data FIXME use codec not SVQ3 */
765 msg_Dbg( p_dec, "vide = %d", i_vide );
766 id = malloc( sizeof( ImageDescription ) + ( i_vide - 70 ) );
769 id->idSize = sizeof( ImageDescription ) + ( i_vide - 70 );
770 id->cType = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );
771 id->version = GetWBE ( p_vide + 0 );
772 id->revisionLevel = GetWBE ( p_vide + 2 );
773 id->vendor = GetDWBE( p_vide + 4 );
774 id->temporalQuality = GetDWBE( p_vide + 8 );
775 id->spatialQuality = GetDWBE( p_vide + 12 );
776 id->width = GetWBE ( p_vide + 16 );
777 id->height = GetWBE ( p_vide + 18 );
778 id->hRes = GetDWBE( p_vide + 20 );
779 id->vRes = GetDWBE( p_vide + 24 );
780 id->dataSize = GetDWBE( p_vide + 28 );
781 id->frameCount = GetWBE ( p_vide + 32 );
782 memcpy( &id->name, p_vide + 34, 32 );
783 id->depth = GetWBE ( p_vide + 66 );
784 id->clutID = GetWBE ( p_vide + 68 );
787 memcpy( ((char*)&id->clutID) + 2, p_vide + 70, i_vide - 70 );
790 msg_Dbg( p_dec, "idSize=%d ver=%d rev=%d vendor=%d tempQ=%d "
791 "spaQ=%d w=%d h=%d dpi=%d%d dataSize=%d depth=%d frameCount=%d clutID=%d",
792 (int)id->idSize, id->version, id->revisionLevel, (int)id->vendor,
793 (int)id->temporalQuality, (int)id->spatialQuality,
794 (int)id->width, (int)id->height,
795 (int)id->hRes, (int)id->vRes,
801 p_sys->framedescHandle = (ImageDescriptionHandle) NewHandleClear( id->idSize );
802 memcpy( *p_sys->framedescHandle, id, id->idSize );
804 if( p_dec->fmt_in.video.i_width != 0 && p_dec->fmt_in.video.i_height != 0)
805 p_sys->plane = malloc( p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 3 );
809 i_result = p_sys->QTNewGWorldFromPtr( &p_sys->OutBufferGWorld,
810 /*pixel format of new GWorld==YUY2 */
812 /* we should benchmark if yvu9 is
813 * faster for svq3, too */
814 &p_sys->OutBufferRect,
817 p_dec->fmt_in.video.i_width * 2 );
819 msg_Dbg( p_dec, "NewGWorldFromPtr returned:%ld",
820 65536 - ( i_result&0xffff ) );
822 memset( &p_sys->decpar, 0, sizeof( CodecDecompressParams ) );
823 p_sys->decpar.imageDescription = p_sys->framedescHandle;
824 p_sys->decpar.startLine = 0;
825 p_sys->decpar.stopLine = ( **p_sys->framedescHandle ).height;
826 p_sys->decpar.frameNumber = 1;
827 p_sys->decpar.matrixFlags = 0;
828 p_sys->decpar.matrixType = 0;
829 p_sys->decpar.matrix = 0;
830 p_sys->decpar.capabilities = &p_sys->codeccap;
831 p_sys->decpar.accuracy = codecNormalQuality;
832 p_sys->decpar.srcRect = p_sys->OutBufferRect;
833 p_sys->decpar.transferMode = srcCopy;
834 p_sys->decpar.dstPixMap = **p_sys->GetGWorldPixMap( p_sys->OutBufferGWorld );/*destPixmap; */
836 cres = p_sys->ImageCodecPreDecompress( p_sys->ci, &p_sys->decpar );
837 msg_Dbg( p_dec, "quicktime_video: ImageCodecPreDecompress cres=0x%X",
840 es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_CODEC_YUYV);
841 p_dec->fmt_out.video.i_width = p_dec->fmt_in.video.i_width;
842 p_dec->fmt_out.video.i_height= p_dec->fmt_in.video.i_height;
843 p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * p_dec->fmt_in.video.i_width / p_dec->fmt_in.video.i_height;
845 vlc_mutex_unlock( &qt_mutex );
850 Restore_LDT_Keeper( p_sys->ldt_fs );
852 vlc_mutex_unlock( &qt_mutex );
860 /*****************************************************************************
862 *****************************************************************************/
863 static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
865 decoder_sys_t *p_sys = p_dec->p_sys;
870 ComponentResult cres;
873 /* We must do open and close in the same thread (unless we do
874 * Setup_LDT_Keeper in the main thread before all others */
877 if( OpenVideo( p_dec ) )
880 p_dec->b_error = true;
883 p_sys = p_dec->p_sys;
887 if( pp_block == NULL || *pp_block == NULL )
894 i_pts = p_block->i_pts ? p_block->i_pts : p_block->i_dts;
896 mtime_t i_display_date = 0;
897 if( !(p_block->i_flags & BLOCK_FLAG_PREROLL) )
898 i_display_date = decoder_GetDisplayDate( p_dec, i_pts );
900 if( i_display_date > 0 && i_display_date < mdate() )
909 msg_Dbg( p_dec, "bufsize: %d", (int)p_block->i_buffer);
912 if( p_sys->i_late > 10 )
914 msg_Dbg( p_dec, "late buffer dropped (%"PRId64")", i_pts );
915 block_Release( p_block );
919 vlc_mutex_lock( &qt_mutex );
921 if( ( p_pic = decoder_NewPicture( p_dec ) ) )
923 p_sys->decpar.data = (Ptr)p_block->p_buffer;
924 p_sys->decpar.bufferSize = p_block->i_buffer;
925 (**p_sys->framedescHandle).dataSize = p_block->i_buffer;
927 cres = p_sys->ImageCodecBandDecompress( p_sys->ci, &p_sys->decpar );
929 ++p_sys->decpar.frameNumber;
933 msg_Dbg( p_dec, "quicktime_video: ImageCodecBandDecompress"
934 " cres=0x%X (-0x%X) %d :(",
935 (int)cres,(int)-cres, (int)cres );
938 memcpy( p_pic->p[0].p_pixels, p_sys->plane,
939 p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 2 );
943 vlc_mutex_unlock( &qt_mutex );
945 block_Release( p_block );
950 /*****************************************************************************
952 *****************************************************************************/
953 static int QTAudioInit( decoder_t *p_dec )
955 decoder_sys_t *p_sys = p_dec->p_sys;
958 p_sys->SoundConverterOpen = (void*)SoundConverterOpen;
959 p_sys->SoundConverterClose = (void*)SoundConverterClose;
960 p_sys->SoundConverterSetInfo = (void*)SoundConverterSetInfo;
961 p_sys->SoundConverterGetBufferSizes = (void*)SoundConverterGetBufferSizes;
962 p_sys->SoundConverterConvertBuffer = (void*)SoundConverterConvertBuffer;
963 p_sys->SoundConverterBeginConversion= (void*)SoundConverterBeginConversion;
964 p_sys->SoundConverterEndConversion = (void*)SoundConverterEndConversion;
968 p_sys->ldt_fs = Setup_LDT_Keeper();
971 p_sys->qts = LoadLibraryA( "QuickTime.qts" );
972 if( p_sys->qts == NULL )
974 msg_Dbg( p_dec, "failed loading QuickTime.qts" );
977 p_sys->qtml = LoadLibraryA( "qtmlClient.dll" );
978 if( p_sys->qtml == NULL )
980 msg_Dbg( p_dec, "failed loading qtmlClient.dll" );
984 p_sys->InitializeQTML = (void *)GetProcAddress( p_sys->qtml, "InitializeQTML" );
985 p_sys->TerminateQTML = (void *)GetProcAddress( p_sys->qtml, "TerminateQTML" );
986 p_sys->SoundConverterOpen = (void *)GetProcAddress( p_sys->qtml, "SoundConverterOpen" );
987 p_sys->SoundConverterClose = (void *)GetProcAddress( p_sys->qtml, "SoundConverterClose" );
988 p_sys->SoundConverterSetInfo = (void *)GetProcAddress( p_sys->qtml, "SoundConverterSetInfo" );
989 p_sys->SoundConverterGetBufferSizes = (void *)GetProcAddress( p_sys->qtml, "SoundConverterGetBufferSizes" );
990 p_sys->SoundConverterConvertBuffer = (void *)GetProcAddress( p_sys->qtml, "SoundConverterConvertBuffer" );
991 p_sys->SoundConverterEndConversion = (void *)GetProcAddress( p_sys->qtml, "SoundConverterEndConversion" );
992 p_sys->SoundConverterBeginConversion= (void *)GetProcAddress( p_sys->qtml, "SoundConverterBeginConversion");
994 if( p_sys->InitializeQTML == NULL )
996 msg_Err( p_dec, "failed getting proc address InitializeQTML" );
999 if( p_sys->SoundConverterOpen == NULL ||
1000 p_sys->SoundConverterClose == NULL ||
1001 p_sys->SoundConverterSetInfo == NULL ||
1002 p_sys->SoundConverterGetBufferSizes == NULL ||
1003 p_sys->SoundConverterConvertBuffer == NULL ||
1004 p_sys->SoundConverterEndConversion == NULL ||
1005 p_sys->SoundConverterBeginConversion == NULL )
1007 msg_Err( p_dec, "failed getting proc address" );
1008 return VLC_EGENERIC;
1011 msg_Dbg( p_dec, "standard init done" );
1012 #endif /* else __APPLE__ */
1018 /*****************************************************************************
1020 *****************************************************************************/
1021 static int QTVideoInit( decoder_t *p_dec )
1023 decoder_sys_t *p_sys = p_dec->p_sys;
1026 p_sys->FindNextComponent = (void*)FindNextComponent;
1027 p_sys->OpenComponent = (void*)OpenComponent;
1028 p_sys->ImageCodecInitialize = (void*)ImageCodecInitialize;
1029 p_sys->ImageCodecGetCodecInfo = (void*)ImageCodecGetCodecInfo;
1030 p_sys->ImageCodecPreDecompress = (void*)ImageCodecPreDecompress;
1031 p_sys->ImageCodecBandDecompress = (void*)ImageCodecBandDecompress;
1032 p_sys->GetGWorldPixMap = (void*)GetGWorldPixMap;
1033 p_sys->QTNewGWorldFromPtr = (void*)QTNewGWorldFromPtr;
1034 p_sys->NewHandleClear = (void*)NewHandleClear;
1038 p_sys->ldt_fs = Setup_LDT_Keeper();
1040 p_sys->qts = LoadLibraryA( "QuickTime.qts" );
1041 if( p_sys->qts == NULL )
1043 msg_Dbg( p_dec, "failed loading QuickTime.qts" );
1044 return VLC_EGENERIC;
1046 msg_Dbg( p_dec, "QuickTime.qts loaded" );
1047 p_sys->qtml = LoadLibraryA( "qtmlClient.dll" );
1048 if( p_sys->qtml == NULL )
1050 msg_Dbg( p_dec, "failed loading qtmlClient.dll" );
1051 return VLC_EGENERIC;
1053 msg_Dbg( p_dec, "qtmlClient.dll loaded" );
1055 /* (void*) to shut up gcc */
1056 p_sys->InitializeQTML = (void*)GetProcAddress( p_sys->qtml, "InitializeQTML" );
1057 p_sys->FindNextComponent = (void*)GetProcAddress( p_sys->qtml, "FindNextComponent" );
1058 p_sys->OpenComponent = (void*)GetProcAddress( p_sys->qtml, "OpenComponent" );
1059 p_sys->ImageCodecInitialize = (void*)GetProcAddress( p_sys->qtml, "ImageCodecInitialize" );
1060 p_sys->ImageCodecGetCodecInfo = (void*)GetProcAddress( p_sys->qtml, "ImageCodecGetCodecInfo" );
1061 p_sys->ImageCodecPreDecompress = (void*)GetProcAddress( p_sys->qtml, "ImageCodecPreDecompress" );
1062 p_sys->ImageCodecBandDecompress = (void*)GetProcAddress( p_sys->qtml, "ImageCodecBandDecompress" );
1063 p_sys->GetGWorldPixMap = (void*)GetProcAddress( p_sys->qtml, "GetGWorldPixMap" );
1064 p_sys->QTNewGWorldFromPtr = (void*)GetProcAddress( p_sys->qtml, "QTNewGWorldFromPtr" );
1065 p_sys->NewHandleClear = (void*)GetProcAddress( p_sys->qtml, "NewHandleClear" );
1067 if( p_sys->InitializeQTML == NULL )
1069 msg_Dbg( p_dec, "failed getting proc address InitializeQTML" );
1070 return VLC_EGENERIC;
1072 if( p_sys->FindNextComponent == NULL ||
1073 p_sys->OpenComponent == NULL ||
1074 p_sys->ImageCodecInitialize == NULL ||
1075 p_sys->ImageCodecGetCodecInfo == NULL ||
1076 p_sys->ImageCodecPreDecompress == NULL ||
1077 p_sys->ImageCodecBandDecompress == NULL ||
1078 p_sys->GetGWorldPixMap == NULL ||
1079 p_sys->QTNewGWorldFromPtr == NULL ||
1080 p_sys->NewHandleClear == NULL )
1082 msg_Err( p_dec, "failed getting proc address" );
1083 return VLC_EGENERIC;
1085 #endif /* __APPLE__ */