]> git.sesse.net Git - vlc/blob - modules/codec/quicktime.c
* modules/codec/quicktime.c, configure.ac: ported the audio part of the quicktime...
[vlc] / modules / codec / quicktime.c
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.9 2003/07/21 17:48:31 gbazin Exp $
6  *
7  * Authors: Laurent Aimar <fenrir at via.ecp.fr>
8  *          Derk-Jan Hartman <thedj at users.sf.net>
9  *
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.
14  * 
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.
19  *
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  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <vlc/vlc.h>
29 #include <vlc/aout.h>
30 #include <vlc/vout.h>
31 #include <vlc/decoder.h>
32 #include <vlc/input.h>
33
34 #include <stdlib.h>                                      /* malloc(), free() */
35 #include <string.h>                                              /* strdup() */
36 #include "codecs.h"
37
38 #ifdef SYS_DARWIN
39 #include <QuickTime/QuickTimeComponents.h>
40 #include <QuickTime/Movies.h>
41 #include <QuickTime/ImageCodec.h>
42 #endif
43
44 /* for windows do we require Quicktime compents header? */
45
46 #ifdef LOADER
47 #include "w32dll/loader/qtx/qtxsdk/components.h"
48 #include "w32dll/loader/wine/windef.h"
49 #include "w32dll/loader/ldt_keeper.h"
50
51 HMODULE   WINAPI LoadLibraryA(LPCSTR);
52 FARPROC   WINAPI GetProcAddress(HMODULE,LPCSTR);
53 int       WINAPI FreeLibrary(HMODULE);
54
55 #endif
56
57 /*****************************************************************************
58  * Local prototypes
59  *****************************************************************************/
60 static int  OpenDecoder    ( vlc_object_t * );
61
62 static int  RunDecoderAudio( decoder_fifo_t * );
63 static int  RunDecoderVideo( decoder_fifo_t * );
64
65 /*****************************************************************************
66  * Module descriptor
67  *****************************************************************************/
68
69 vlc_module_begin();
70     set_description( _("QuickTime library decoder") );
71     set_capability( "decoder", 10 );
72     set_callbacks( OpenDecoder, NULL );
73
74     /* create a mutex */
75     var_Create( p_module->p_libvlc, "qt_mutex", VLC_VAR_MUTEX );
76 vlc_module_end();
77
78 #define FCC( a, b , c, d ) \
79     ((uint32_t)( ((a)<<24)|((b)<<16)|((c)<<8)|(d)))
80
81 #ifndef SYS_DARWIN
82 typedef struct OpaqueSoundConverter*    SoundConverter;
83 typedef long                            OSType;
84 typedef int                             OSErr;
85 typedef unsigned long                   UnsignedFixed;
86 typedef uint8_t                         Byte;
87
88 typedef struct SoundComponentData {
89     long                            flags;
90     OSType                          format;
91     short                           numChannels;
92     short                           sampleSize;
93     UnsignedFixed                   sampleRate;
94     long                            sampleCount;
95     Byte *                          buffer;
96     long                            reserved;
97 } SoundComponentData;
98
99 #endif /* SYS_DARWIN */
100
101 typedef struct
102 {
103     /* Input properties */
104     decoder_fifo_t *p_fifo;
105
106     /* library */
107 #ifndef SYS_DARWIN
108 #ifdef LOADER
109     ldt_fs_t    *ldt_fs;
110
111 #endif /* LOADER */
112     HMODULE qtml;
113     OSErr (*InitializeQTML)             ( long flags );
114     OSErr (*TerminateQTML)              ( void );
115 #endif /* SYS_DARWIN */
116
117     int (*SoundConverterOpen)           ( const SoundComponentData *,
118                                           const SoundComponentData *,
119                                           SoundConverter* );
120     int (*SoundConverterClose)          ( SoundConverter );
121     int (*SoundConverterSetInfo)        ( SoundConverter , OSType, void * );
122     int (*SoundConverterGetBufferSizes) ( SoundConverter, unsigned long,
123                                           unsigned long*, unsigned long*,
124                                           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;
133
134     long            FramesToGet;
135     unsigned int    InFrameSize;
136     unsigned int    OutFrameSize;
137
138     /* Output properties */
139     aout_instance_t *   p_aout;       /* opaque */
140     aout_input_t *      p_aout_input; /* opaque */
141     audio_sample_format_t output_format;
142
143     audio_date_t        date;
144     mtime_t             pts;
145
146     /* buffer */
147     unsigned int        i_buffer;
148     unsigned int        i_buffer_size;
149     uint8_t             *p_buffer;
150
151     uint8_t             buffer_out[1000000];    /* FIXME */
152
153 } adec_thread_t;
154
155 #ifndef WIN32
156 typedef struct
157 {
158     /* Input properties */
159     decoder_fifo_t *p_fifo;
160
161     /* library */
162 #ifndef SYS_DARWIN
163 #ifdef LOADER
164     ldt_fs_t          *ldt_fs;
165 #endif /* LOADER */
166     HMODULE           qtml;
167     OSErr             (*InitializeQTML)         ( long flags );
168
169 #endif /* SYS_DARWIN */
170     Component         (*FindNextComponent)
171         ( Component prev, ComponentDescription* desc );
172
173     ComponentInstance (*OpenComponent)
174         ( Component c );
175
176     ComponentResult   (*ImageCodecInitialize)
177         ( ComponentInstance ci, ImageSubCodecDecompressCapabilities * cap);
178
179     ComponentResult   (*ImageCodecGetCodecInfo)
180         ( ComponentInstance ci, CodecInfo *info );
181
182     ComponentResult   (*ImageCodecPreDecompress)
183         ( ComponentInstance ci, CodecDecompressParams * params );
184
185     ComponentResult   (*ImageCodecBandDecompress)
186         ( ComponentInstance ci, CodecDecompressParams * params );
187
188     PixMapHandle      (*GetGWorldPixMap)
189         ( GWorldPtr offscreenGWorld );
190
191     OSErr             (*QTNewGWorldFromPtr)
192         ( GWorldPtr *gw, OSType pixelFormat, const Rect *boundsRect,
193           CTabHandle cTable, /*GDHandle*/ void *aGDevice, /*unused*/
194           GWorldFlags flags, void *baseAddr, long rowBytes );
195
196     OSErr             (*NewHandleClear)
197         ( Size byteCount );
198
199     ComponentInstance       ci;
200     Rect                    OutBufferRect;   /* the dimensions of our GWorld */
201     GWorldPtr               OutBufferGWorld; /* a GWorld is some kind of
202                                                 description for a drawing
203                                                 environment */
204     ImageDescriptionHandle  framedescHandle;
205
206     CodecDecompressParams   decpar;          /* for ImageCodecPreDecompress()*/
207     CodecCapabilities       codeccap;        /* for decpar */
208
209
210     /* Output properties */
211     vout_thread_t *     p_vout;
212     uint8_t *           plane;
213     mtime_t             pts;
214
215     /* buffer */
216     unsigned int        i_buffer;
217     uint8_t             *p_buffer;
218
219 } vdec_thread_t;
220 #endif
221
222 static int pi_channels_maps[6] =
223 {
224     0,
225     AOUT_CHAN_CENTER,
226     AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
227     AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER,
228     AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT,
229     AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
230      | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT
231 };
232
233
234 static uint16_t GetWBE( uint8_t *p_buff )
235 {
236     return( (p_buff[0]<<8) + p_buff[1] );
237 }
238
239 static uint32_t GetDWBE( uint8_t *p_buff )
240 {
241     return( (p_buff[0] << 24) + ( p_buff[1] <<16 ) +
242             ( p_buff[2] <<8 ) + p_buff[3] );
243 }
244
245
246 static int GetPESData( uint8_t *p_buf, int i_max, pes_packet_t *p_pes )
247 {
248     int i_copy;
249     int i_count;
250
251     data_packet_t   *p_data;
252
253     i_count = 0;
254     p_data = p_pes->p_first;
255     while( p_data != NULL && i_count < i_max )
256     {
257
258         i_copy = __MIN( p_data->p_payload_end - p_data->p_payload_start,
259                         i_max - i_count );
260
261         if( i_copy > 0 )
262         {
263             memcpy( p_buf,
264                     p_data->p_payload_start,
265                     i_copy );
266         }
267
268         p_data = p_data->p_next;
269         i_count += i_copy;
270         p_buf   += i_copy;
271     }
272
273     if( i_count < i_max )
274     {
275         memset( p_buf, 0, i_max - i_count );
276     }
277     return( i_count );
278 }
279
280 /*****************************************************************************
281  * OpenDecoder: probe the decoder and return score
282  *****************************************************************************
283  * Tries to launch a decoder and return score so that the interface is able
284  * to choose.
285  *****************************************************************************/
286 static int OpenDecoder( vlc_object_t *p_this )
287 {
288     decoder_fifo_t *p_fifo = (decoder_fifo_t*) p_this;
289
290     switch( p_fifo->i_fourcc )
291     {
292         case VLC_FOURCC('S','V','Q','3'): /* Sorenson v3 */
293     /*    case VLC_FOURCC('S','V','Q','1'):  Sorenson v1 
294         case VLC_FOURCC('Z','y','G','o'):
295         case VLC_FOURCC('V','P','3','1'):
296         case VLC_FOURCC('3','I','V','1'): */
297         case VLC_FOURCC('r','l','e',' '): /* QuickTime animation (RLE) */
298         case VLC_FOURCC('r','p','z','a'): /* QuickTime Apple Video */
299         case VLC_FOURCC('a','z','p','r'): /* QuickTime animation (RLE) */
300             p_fifo->pf_run = RunDecoderVideo;
301             return VLC_SUCCESS;
302
303         case VLC_FOURCC('m','p','4','a'): /* MPEG-4 audio */
304         case VLC_FOURCC('Q','D','M','C'): /* QDesign */
305         case VLC_FOURCC('Q','D','M','2'): /* QDesign* 2 */
306         case VLC_FOURCC('Q','c','l','p'): /* Qualcomm Purevoice Codec */
307         case VLC_FOURCC('Q','C','L','P'): /* Qualcomm Purevoice Codec */
308         case VLC_FOURCC('M','A','C','3'): /* MACE3 audio decoder */
309         case VLC_FOURCC('M','A','C','6'): /* MACE6 audio decoder */
310         case VLC_FOURCC('d','v','c','a'): /* DV Audio */
311         case VLC_FOURCC('s','o','w','t'): /* 16-bit Little Endian */
312         case VLC_FOURCC('t','w','o','s'): /* 16-bit Big Endian */
313         case VLC_FOURCC('a','l','a','w'): /* ALaw 2:1 */
314         case VLC_FOURCC('u','l','a','w'): /* mu-Law 2:1 */
315         case VLC_FOURCC('r','a','w',' '): /* 8-bit offset binaries */
316         case VLC_FOURCC('f','l','3','2'): /* 32-bit Floating Point */
317         case VLC_FOURCC('f','l','6','4'): /* 64-bit Floating Point */
318         case VLC_FOURCC('i','n','2','4'): /* 24-bit Interger */
319         case VLC_FOURCC('i','n','3','2'): /* 32-bit Integer */
320         case 0x0011:                            /* DVI IMA */
321         case 0x6D730002:                        /* Microsoft ADPCM-ACM */
322         case 0x6D730011:                        /* DVI Intel IMAADPCM-ACM */
323
324             p_fifo->pf_run = RunDecoderAudio;
325             return VLC_SUCCESS;
326         default:
327             return VLC_EGENERIC;
328     }
329 }
330
331 /****************************************************************************
332  ****************************************************************************
333  **
334  **     audio part
335  **
336  **************************************************************************** 
337  ****************************************************************************/
338 static int  InitThreadAudio     ( adec_thread_t * );
339 static void DecodeThreadAudio   ( adec_thread_t * );
340 static void EndThreadAudio      ( adec_thread_t * );
341 static int  QTAudioInit         ( adec_thread_t * );
342
343 static int RunDecoderAudio( decoder_fifo_t *p_fifo )
344 {
345     adec_thread_t *p_dec;
346     vlc_bool_t    b_error;
347
348     p_dec = malloc( sizeof( adec_thread_t ) );
349     if( !p_dec )
350     {
351         msg_Err( p_fifo, "out of memory" );
352         DecoderError( p_fifo );
353         return VLC_EGENERIC;
354     }
355     p_dec->p_fifo = p_fifo;
356
357     if( InitThreadAudio( p_dec ) != 0 )
358     {
359         DecoderError( p_fifo );
360         return VLC_EGENERIC;
361     }
362
363     while( !p_dec->p_fifo->b_die && !p_dec->p_fifo->b_error )
364     {
365         DecodeThreadAudio( p_dec );
366     }
367
368
369     if( ( b_error = p_dec->p_fifo->b_error ) )
370     {
371         DecoderError( p_dec->p_fifo );
372     }
373
374     EndThreadAudio( p_dec );
375     if( b_error )
376     {
377         return VLC_EGENERIC;
378     }
379
380     return VLC_SUCCESS;
381 }
382
383 static int InitThreadAudio( adec_thread_t *p_dec )
384 {
385     vlc_value_t     lockval;
386     int             i_error;
387     char            fcc[4];
388     unsigned long   WantedBufferSize;
389     unsigned long   InputBufferSize = 0;
390     unsigned long   OutputBufferSize = 0;
391
392     WAVEFORMATEX    *p_wf;
393
394     if( !( p_wf = (WAVEFORMATEX*)p_dec->p_fifo->p_waveformatex ) )
395     {
396         msg_Err( p_dec->p_fifo, "missing WAVEFORMATEX");
397         return VLC_EGENERIC;
398     }
399     memcpy( fcc, &p_dec->p_fifo->i_fourcc, 4 );
400
401     /* get lock, avoid segfault */
402     var_Get( p_dec->p_fifo->p_libvlc, "qt_mutex", &lockval );
403     vlc_mutex_lock( lockval.p_address );
404
405 #ifdef SYS_DARWIN
406     EnterMovies();
407 #endif
408
409     if( QTAudioInit( p_dec ) != VLC_SUCCESS )
410     {
411         msg_Err( p_dec->p_fifo, "cannot initialize QT");
412         goto exit_error;
413     }
414
415 #ifndef SYS_DARWIN
416     if( ( i_error = p_dec->InitializeQTML( 6 + 16 ) ) )
417     {
418         msg_Dbg( p_dec->p_fifo, "error while InitializeQTML = %d", i_error );
419         goto exit_error;
420     }
421 #endif
422
423     /* input format settings */
424     p_dec->InputFormatInfo.flags       = 0;
425     p_dec->InputFormatInfo.sampleCount = 0;
426     p_dec->InputFormatInfo.buffer      = NULL;
427     p_dec->InputFormatInfo.reserved    = 0;
428     p_dec->InputFormatInfo.numChannels = p_wf->nChannels;
429     p_dec->InputFormatInfo.sampleSize  = p_wf->wBitsPerSample;
430     p_dec->InputFormatInfo.sampleRate  = p_wf->nSamplesPerSec;
431     p_dec->InputFormatInfo.format      = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );
432
433     /* output format settings */
434     p_dec->OutputFormatInfo.flags       = 0;
435     p_dec->OutputFormatInfo.sampleCount = 0;
436     p_dec->OutputFormatInfo.buffer      = NULL;
437     p_dec->OutputFormatInfo.reserved    = 0;
438     p_dec->OutputFormatInfo.numChannels = p_wf->nChannels;
439     p_dec->OutputFormatInfo.sampleSize  = 16;
440     p_dec->OutputFormatInfo.sampleRate  = p_wf->nSamplesPerSec;
441     p_dec->OutputFormatInfo.format      = FCC( 'N', 'O', 'N', 'E' );
442
443 #ifdef SYS_DARWIN
444 /* on OS X QT is not threadsafe */
445     vlc_mutex_lock( &p_dec->p_fifo->p_vlc->quicktime_lock );
446 #endif
447
448     i_error = p_dec->SoundConverterOpen( &p_dec->InputFormatInfo,
449                                          &p_dec->OutputFormatInfo,
450                                          &p_dec->myConverter );
451     if( i_error )
452     {
453         msg_Err( p_dec->p_fifo,
454                  "error while SoundConverterOpen = %d", i_error );
455         goto exit_error;
456     }
457
458 #if 0
459     /* tell the sound converter we accept VBR formats */
460     i_error = SoundConverterSetInfo( p_dec->myConverter, siClientAcceptsVBR,
461                                      (void *)true );
462 #endif
463
464     if( p_wf->cbSize > 36 + 8 )
465     {
466         i_error =
467             p_dec->SoundConverterSetInfo( p_dec->myConverter,
468                                           FCC( 'w', 'a', 'v', 'e' ),
469                                           ((uint8_t*)&p_wf[1]) + 36 + 8 );
470         msg_Dbg( p_dec->p_fifo,
471                  "error while SoundConverterSetInfo = %d", i_error );
472     }
473
474     WantedBufferSize = p_dec->OutputFormatInfo.numChannels *
475                          p_dec->OutputFormatInfo.sampleRate * 2;
476     p_dec->FramesToGet = 0;
477
478     i_error = p_dec->SoundConverterGetBufferSizes( p_dec->myConverter,
479                   WantedBufferSize, &p_dec->FramesToGet,
480                   &InputBufferSize, &OutputBufferSize );
481
482     msg_Dbg( p_dec->p_fifo, "WantedBufferSize=%li InputBufferSize=%li "
483              "OutputBufferSize=%li FramesToGet=%li", WantedBufferSize,
484              InputBufferSize, OutputBufferSize, p_dec->FramesToGet );
485
486     p_dec->InFrameSize  = (InputBufferSize + p_dec->FramesToGet - 1 ) /
487                             p_dec->FramesToGet;
488     p_dec->OutFrameSize = OutputBufferSize / p_dec->FramesToGet;
489
490     msg_Dbg( p_dec->p_fifo, "frame size %d -> %d",
491              p_dec->InFrameSize, p_dec->OutFrameSize );
492
493     i_error = p_dec->SoundConverterBeginConversion( p_dec->myConverter );
494     if( i_error )
495     {
496         msg_Err( p_dec->p_fifo,
497                  "error while SoundConverterBeginConversion = %d", i_error );
498         goto exit_error;
499     }
500
501 #ifdef SYS_DARWIN
502     vlc_mutex_unlock( &p_dec->p_fifo->p_vlc->quicktime_lock );
503 #endif
504
505     p_dec->output_format.i_format   = AOUT_FMT_S16_NE;
506     p_dec->output_format.i_rate     = p_wf->nSamplesPerSec;
507     p_dec->output_format.i_physical_channels =
508         p_dec->output_format.i_original_channels =
509             pi_channels_maps[p_wf->nChannels];
510     aout_DateInit( &p_dec->date, p_dec->output_format.i_rate );
511     p_dec->p_aout_input = aout_DecNew( p_dec->p_fifo,
512                                        &p_dec->p_aout,
513                                        &p_dec->output_format );
514     if( !p_dec->p_aout_input )
515     {
516         msg_Err( p_dec->p_fifo, "cannot create aout" );
517         goto exit_error;
518     }
519
520     p_dec->i_buffer      = 0;
521     p_dec->i_buffer_size = 100*1000;
522     p_dec->p_buffer      = malloc( p_dec->i_buffer_size );
523
524     p_dec->pts = -1;
525
526     vlc_mutex_unlock( lockval.p_address );
527     return VLC_SUCCESS;
528
529 exit_error:
530 #ifdef LOADER
531     Restore_LDT_Keeper( p_dec->ldt_fs );
532 #endif
533     vlc_mutex_unlock( lockval.p_address );
534     return VLC_EGENERIC;
535 }
536
537 static void DecodeThreadAudio( adec_thread_t *p_dec )
538 {
539     pes_packet_t    *p_pes;
540     vlc_value_t     lockval;
541     int             i_error;
542
543     var_Get( p_dec->p_fifo->p_libvlc, "qt_mutex", &lockval );
544
545     input_ExtractPES( p_dec->p_fifo, &p_pes );
546     if( !p_pes )
547     {
548         msg_Err( p_dec->p_fifo, "cannot get PES" );
549         p_dec->p_fifo->b_error = 1;
550         return;
551     }
552     /*if( p_dec->pts <= 0 )*/
553     {
554         p_dec->pts = p_pes->i_pts;
555     }
556
557     if( p_pes->i_pes_size > 0 && p_pes->i_pts > mdate() )
558     {
559
560         if( p_dec->i_buffer_size < p_dec->i_buffer + p_pes->i_pes_size )
561         {
562             p_dec->i_buffer_size = p_dec->i_buffer + p_pes->i_pes_size + 1024;
563             p_dec->p_buffer = realloc( p_dec->p_buffer,
564                                        p_dec->i_buffer_size );
565         }
566
567         GetPESData( &p_dec->p_buffer[p_dec->i_buffer],
568                     p_dec->i_buffer_size - p_dec->i_buffer, p_pes );
569         p_dec->i_buffer += p_pes->i_pes_size;
570
571         if( p_dec->i_buffer > p_dec->InFrameSize )
572         {
573             int i_frames = p_dec->i_buffer / p_dec->InFrameSize;
574             long i_out_frames, i_out_bytes;
575             /* enough data */
576
577             vlc_mutex_lock( lockval.p_address );
578             i_error = p_dec->SoundConverterConvertBuffer( p_dec->myConverter,
579                                                           p_dec->p_buffer,
580                                                           i_frames,
581                                                           p_dec->buffer_out,
582                                                           &i_out_frames,
583                                                           &i_out_bytes );
584             vlc_mutex_unlock( lockval.p_address );
585
586             /*
587             msg_Dbg( p_dec->p_fifo,
588                      "decoded %d frames -> %ld frames (error=%d)",
589                      i_frames, i_out_frames, i_error );
590
591             msg_Dbg( p_dec->p_fifo, "decoded %ld frames = %ld bytes",
592                      i_out_frames, i_out_bytes );
593             */
594
595             p_dec->i_buffer -= i_frames * p_dec->InFrameSize;
596             if( p_dec->i_buffer > 0 )
597             {
598                 memmove( &p_dec->p_buffer[0],
599                          &p_dec->p_buffer[i_frames * p_dec->InFrameSize],
600                          p_dec->i_buffer );
601             }
602
603             if( !i_error && i_out_frames > 0 )
604             {
605                 aout_buffer_t   *p_aout_buffer;
606                 uint8_t         *p_buff = p_dec->buffer_out;
607
608                 /*msg_Dbg( p_dec->p_fifo, "pts=%lld date=%lld dateget=%lld",
609                          p_dec->pts, mdate(), aout_DateGet( &p_dec->date ) );*/
610
611                 if( p_dec->pts != 0 &&
612                     p_dec->pts != aout_DateGet( &p_dec->date ) )
613                 {
614                     aout_DateSet( &p_dec->date, p_dec->pts );
615                 }
616                 else if( !aout_DateGet( &p_dec->date ) )
617                 {
618                     input_DeletePES( p_dec->p_fifo->p_packets_mgt, p_pes );
619                     return;
620                 }
621
622                 while( i_out_frames > 0 )
623                 {
624                     int i_frames;
625
626                     i_frames = __MIN( i_out_frames, 1000 );
627                     p_aout_buffer = aout_DecNewBuffer( p_dec->p_aout,
628                                                        p_dec->p_aout_input,
629                                                        i_frames );
630                     if( !p_aout_buffer )
631                     {
632                         msg_Err( p_dec->p_fifo, "cannot get aout buffer" );
633                         p_dec->p_fifo->b_error = 1;
634                         return;
635                     }
636                     p_aout_buffer->start_date = aout_DateGet( &p_dec->date );
637                     p_aout_buffer->end_date = aout_DateIncrement( &p_dec->date,
638                                                                   i_frames );
639
640                     memcpy( p_aout_buffer->p_buffer,
641                             p_buff,
642                             p_aout_buffer->i_nb_bytes );
643
644                     /*
645                     msg_Dbg( p_dec->p_fifo,
646                              "==> start=%lld end=%lld date=%lld",
647                              p_aout_buffer->start_date,
648                              p_aout_buffer->end_date, mdate() );
649                     */
650
651                     aout_DecPlay( p_dec->p_aout, p_dec->p_aout_input,
652                                   p_aout_buffer );
653
654                     /*
655                     msg_Dbg( p_dec->p_fifo, "s1=%d s2=%d", i_framesperchannels,
656                              p_aout_buffer->i_nb_samples );
657
658                     msg_Dbg( p_dec->p_fifo, "i_nb_bytes=%d i_nb_samples*4=%d",
659                              p_aout_buffer->i_nb_bytes,
660                              p_aout_buffer->i_nb_samples * 4 );
661                     */
662
663                     p_buff += i_frames * 4;
664                     i_out_frames -= i_frames;
665                 }
666
667                 p_dec->pts = -1;
668             }
669         }
670     }
671
672     input_DeletePES( p_dec->p_fifo->p_packets_mgt, p_pes );
673 }
674
675 static void EndThreadAudio( adec_thread_t *p_dec )
676 {
677     vlc_value_t             lockval;
678     int i_error;
679     unsigned long ConvertedFrames=0;
680     unsigned long ConvertedBytes=0;
681
682     /* get lock, avoid segfault */
683     var_Get( p_dec->p_fifo->p_libvlc, "qt_mutex", &lockval );
684     vlc_mutex_lock( lockval.p_address );
685
686     i_error = p_dec->SoundConverterEndConversion( p_dec->myConverter, NULL,
687                                                   &ConvertedFrames,
688                                                   &ConvertedBytes );
689     msg_Dbg( p_dec->p_fifo, "SoundConverterEndConversion => %d", i_error );
690
691     i_error = p_dec->SoundConverterClose( p_dec->myConverter );
692     msg_Dbg( p_dec->p_fifo, "SoundConverterClose => %d", i_error );
693
694 #ifndef SYS_DARWIN
695     FreeLibrary( p_dec->qtml );
696     msg_Dbg( p_dec->p_fifo, "FreeLibrary ok." );
697 #endif
698     vlc_mutex_unlock( lockval.p_address );
699
700 #ifdef LOADER
701     Restore_LDT_Keeper( p_dec->ldt_fs );
702     msg_Dbg( p_dec->p_fifo, "Restore_LDT_Keeper" );
703 #endif
704 #ifdef SYS_DARWIN
705     ExitMovies();
706 #endif
707     aout_DecDelete( p_dec->p_aout, p_dec->p_aout_input );
708 }
709
710 static int QTAudioInit( adec_thread_t *p_dec )
711 {
712
713 #ifdef SYS_DARWIN
714     p_dec->SoundConverterOpen       = (void*)SoundConverterOpen;
715     p_dec->SoundConverterClose      = (void*)SoundConverterClose;
716     p_dec->SoundConverterSetInfo    = (void*)SoundConverterSetInfo;
717     p_dec->SoundConverterGetBufferSizes = (void*)SoundConverterGetBufferSizes;
718     p_dec->SoundConverterConvertBuffer  = (void*)SoundConverterConvertBuffer;
719     p_dec->SoundConverterBeginConversion= (void*)SoundConverterBeginConversion;
720     p_dec->SoundConverterEndConversion  = (void*)SoundConverterEndConversion;
721 #else
722
723 #ifdef LOADER
724     p_dec->ldt_fs = Setup_LDT_Keeper();
725 #endif /* LOADER */
726
727     p_dec->qtml = LoadLibraryA( "qtmlClient.dll" );
728     if( p_dec->qtml == NULL )
729     {
730         msg_Dbg( p_dec->p_fifo, "failed loading qtmlClient.dll" );
731         return VLC_EGENERIC;
732     }
733
734     p_dec->InitializeQTML =
735         (void *)GetProcAddress( p_dec->qtml, "InitializeQTML" );
736     if( p_dec->InitializeQTML == NULL )
737     {
738         msg_Dbg( p_dec->p_fifo, "failed geting proc address InitializeQTML" );
739         return VLC_EGENERIC;
740     }
741
742     p_dec->SoundConverterOpen =
743         (void *)GetProcAddress( p_dec->qtml, "SoundConverterOpen" );
744     if( p_dec->SoundConverterOpen == NULL )
745     {
746         msg_Dbg( p_dec->p_fifo,
747                  "failed getting proc address SoundConverterOpen");
748         return VLC_EGENERIC;
749     }
750
751     p_dec->SoundConverterClose =
752         (void *)GetProcAddress( p_dec->qtml, "SoundConverterClose" );
753     if( p_dec->SoundConverterClose == NULL )
754     {
755         msg_Dbg( p_dec->p_fifo,
756                  "failed getting proc address SoundConverterClose");
757         return VLC_EGENERIC;
758     }
759
760     p_dec->TerminateQTML =
761         (void *)GetProcAddress( p_dec->qtml, "TerminateQTML" );
762     if( p_dec->TerminateQTML == NULL )
763     {
764         msg_Dbg( p_dec->p_fifo, "failed getting proc address TerminateQTML");
765         return VLC_EGENERIC;
766     }
767
768     p_dec->SoundConverterSetInfo =
769         (void *)GetProcAddress( p_dec->qtml, "SoundConverterSetInfo" );
770     if( p_dec->SoundConverterSetInfo == NULL )
771     {
772         msg_Dbg( p_dec->p_fifo,
773                  "failed getting proc address SoundConverterSetInfo");
774         return VLC_EGENERIC;
775     }
776
777     p_dec->SoundConverterGetBufferSizes =
778         (void *)GetProcAddress( p_dec->qtml, "SoundConverterGetBufferSizes" );
779     if( p_dec->SoundConverterGetBufferSizes == NULL )
780     {
781         msg_Dbg( p_dec->p_fifo,
782                  "failed getting proc address SoundConverterGetBufferSizes");
783         return VLC_EGENERIC;
784     }
785
786     p_dec->SoundConverterConvertBuffer =
787         (void *)GetProcAddress( p_dec->qtml, "SoundConverterConvertBuffer" );
788     if( p_dec->SoundConverterConvertBuffer == NULL )
789     {
790         msg_Dbg( p_dec->p_fifo,
791                  "failed getting proc address SoundConverterConvertBuffer" );
792         return VLC_EGENERIC;
793     }
794
795     p_dec->SoundConverterEndConversion =
796         (void *)GetProcAddress( p_dec->qtml, "SoundConverterEndConversion" );
797     if( p_dec->SoundConverterEndConversion == NULL )
798     {
799         msg_Dbg( p_dec->p_fifo,
800                  "failed getting proc address SoundConverterEndConversion" );
801         return VLC_EGENERIC;
802     }
803
804     p_dec->SoundConverterBeginConversion =
805         (void *)GetProcAddress( p_dec->qtml, "SoundConverterBeginConversion");
806     if( p_dec->SoundConverterBeginConversion == NULL )
807     {
808         msg_Dbg( p_dec->p_fifo,
809                  "failed getting proc address SoundConverterBeginConversion" );
810         return VLC_EGENERIC;
811     }
812
813     msg_Dbg( p_dec->p_fifo,
814              "Standard init done you may now call supported functions" );
815 #endif /* else SYS_DARWIN */
816
817     return VLC_SUCCESS;
818 }
819
820 /****************************************************************************
821  ****************************************************************************
822  **
823  **     video part
824  **
825  **************************************************************************** 
826  ****************************************************************************/
827
828 #ifdef WIN32
829 static int  RunDecoderVideo( decoder_fifo_t *p_fifo ){ return VLC_EGENERIC; }
830
831 #else
832 static int  InitThreadVideo     ( vdec_thread_t * );
833 static void DecodeThreadVideo   ( vdec_thread_t * );
834 static void EndThreadVideo      ( vdec_thread_t * );
835
836 static int  RunDecoderVideo( decoder_fifo_t *p_fifo )
837 {
838     vdec_thread_t *p_dec;
839     vlc_bool_t    b_error;
840
841     p_dec = malloc( sizeof( vdec_thread_t ) );
842     if( !p_dec )
843     {
844         msg_Err( p_fifo, "out of memory" );
845         DecoderError( p_fifo );
846         return VLC_EGENERIC;
847     }
848     p_dec->p_fifo = p_fifo;
849
850     if( InitThreadVideo( p_dec ) != 0 )
851     {
852         DecoderError( p_fifo );
853         return VLC_EGENERIC;
854     }
855
856     while( !p_dec->p_fifo->b_die && !p_dec->p_fifo->b_error )
857     {
858         DecodeThreadVideo( p_dec );
859     }
860
861
862     if( ( b_error = p_dec->p_fifo->b_error ) )
863     {
864         DecoderError( p_dec->p_fifo );
865     }
866
867     EndThreadVideo( p_dec );
868     if( b_error )
869     {
870         return VLC_EGENERIC;
871     }
872
873     return VLC_SUCCESS;
874 }
875
876 /*
877  * InitThreadVideo: load and init library
878  *
879  */
880 static int InitThreadVideo( vdec_thread_t *p_dec )
881 {
882     vlc_value_t                         lockval;
883     long                                i_result;
884     ComponentDescription                desc;
885     Component                           prev;
886     ComponentResult                     cres;
887     ImageSubCodecDecompressCapabilities icap;   /* for ImageCodecInitialize() */
888     CodecInfo                           cinfo;  /* for ImageCodecGetCodecInfo() */
889     ImageDescription                    *id;
890
891     BITMAPINFOHEADER    *p_bih;
892     int                 i_vide;
893     uint8_t             *p_vide;
894     char                fcc[4];
895
896     if( !( p_bih  = (BITMAPINFOHEADER*)p_dec->p_fifo->p_bitmapinfoheader ) )
897     {
898         msg_Err( p_dec->p_fifo, "missing BITMAPINFOHEADER !!" );
899         return VLC_EGENERIC;
900     }
901     i_vide = p_bih->biSize - sizeof( BITMAPINFOHEADER );
902     p_vide = (uint8_t*)&p_bih[1];
903     if( i_vide <= 0 || p_vide == NULL )
904     {
905         msg_Err( p_dec->p_fifo, "invalid BITMAPINFOHEADER !!" );
906         return VLC_EGENERIC;
907     }
908     memcpy( fcc, &p_dec->p_fifo->i_fourcc, 4 );
909     msg_Dbg( p_dec->p_fifo, "quicktime_video %4.4s %dx%d", fcc,
910              p_bih->biWidth, p_bih->biHeight );
911
912     /* get lock, avoid segfault */
913     var_Get( p_dec->p_fifo->p_libvlc, "qt_mutex", &lockval );
914     vlc_mutex_lock( lockval.p_address );
915 #ifdef SYS_DARWIN
916     EnterMovies();
917 #else
918 #ifdef LOADER
919     p_dec->ldt_fs = Setup_LDT_Keeper();
920 #endif /* LOADER */
921     msg_Dbg( p_dec->p_fifo, "trying to load `qtmlClient.dll'" );
922     if( !( p_dec->qtml = LoadLibraryA("qtmlClient.dll") ) )
923     {
924         msg_Err( p_dec->p_fifo, "cannot load qtmlClient.dll");
925         goto exit_error;
926     }
927
928     msg_Dbg( p_dec->p_fifo, "qtmlClient.dll loaded" );
929
930     /* (void*) to shut up gcc */
931     p_dec->InitializeQTML           = (void*)InitializeQTML;
932 #endif /* SYS_DARWIN */
933     p_dec->FindNextComponent        = (void*)FindNextComponent;
934     p_dec->OpenComponent            = (void*)OpenComponent;
935     p_dec->ImageCodecInitialize     = (void*)ImageCodecInitialize;
936     p_dec->ImageCodecGetCodecInfo   = (void*)ImageCodecGetCodecInfo;
937     p_dec->ImageCodecPreDecompress  = (void*)ImageCodecPreDecompress;
938     p_dec->ImageCodecBandDecompress = (void*)ImageCodecBandDecompress;
939     p_dec->GetGWorldPixMap          = (void*)GetGWorldPixMap;
940     p_dec->QTNewGWorldFromPtr       = (void*)QTNewGWorldFromPtr;
941     p_dec->NewHandleClear           = (void*)NewHandleClear;
942
943 #ifndef SYS_DARWIN
944     /* some sanity check */
945     if( !p_dec->InitializeQTML ||
946         !p_dec->FindNextComponent ||
947         !p_dec->OpenComponent ||
948         !p_dec->ImageCodecBandDecompress )
949     {
950         msg_Err( p_dec->p_fifo, "error getting qtmlClient.dll symbols");
951         goto exit_error;
952     }
953
954     if( ( i_result = p_dec->InitializeQTML( 6 + 16 ) ) )
955     {
956         msg_Dbg( p_dec->p_fifo, "error while InitializeQTML = %d", i_result );
957         goto exit_error;
958     }
959 #endif
960
961     /* init ComponentDescription */
962     memset( &desc, 0, sizeof( ComponentDescription ) );
963     desc.componentType      = FCC( 'i', 'm', 'd', 'c' );
964     desc.componentSubType   = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );
965     desc.componentManufacturer = 0;
966     desc.componentFlags        = 0;
967     desc.componentFlagsMask    = 0;
968
969     if( !( prev = p_dec->FindNextComponent( NULL, &desc ) ) )
970     {
971         msg_Err( p_dec->p_fifo, "cannot find requested component" );
972         goto exit_error;
973     }
974     msg_Dbg( p_dec->p_fifo, "component id=0x%p", prev );
975
976     p_dec->ci =  p_dec->OpenComponent( prev );
977     msg_Dbg( p_dec->p_fifo, "component instance p=0x%p", p_dec->ci );
978
979     memset( &icap, 0, sizeof( ImageSubCodecDecompressCapabilities ) );
980     cres =  p_dec->ImageCodecInitialize( p_dec->ci, &icap );
981 /*    msg_Dbg( p_dec->p_fifo, "ImageCodecInitialize->%p  size=%d (%d)\n",cres,icap.recordSize,icap.decompressRecordSize); */
982
983
984     memset( &cinfo, 0, sizeof( CodecInfo ) );
985     cres =  p_dec->ImageCodecGetCodecInfo( p_dec->ci, &cinfo );
986     msg_Dbg( p_dec->p_fifo,
987              "Flags: compr: 0x%lx  decomp: 0x%lx format: 0x%lx\n",
988              cinfo.compressFlags, cinfo.decompressFlags, cinfo.formatFlags );
989     msg_Dbg( p_dec->p_fifo, "quicktime_video: Codec name: %.*s\n",
990              ((unsigned char*)&cinfo.typeName)[0],
991              ((unsigned char*)&cinfo.typeName)+1 );
992
993     /* make a yuy2 gworld */
994     p_dec->OutBufferRect.top    = 0;
995     p_dec->OutBufferRect.left   = 0;
996     p_dec->OutBufferRect.right  = p_bih->biWidth;
997     p_dec->OutBufferRect.bottom = p_bih->biHeight;
998
999
1000     /* codec data FIXME use codec not SVQ3 */
1001     msg_Dbg( p_dec->p_fifo, "vide = %d", i_vide );
1002     id = malloc( sizeof( ImageDescription ) + ( i_vide - 70 ) );
1003     id->idSize          = sizeof( ImageDescription ) + ( i_vide - 70 );
1004     id->cType           = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );
1005     id->version         = GetWBE ( p_vide +  0 );
1006     id->revisionLevel   = GetWBE ( p_vide +  2 );
1007     id->vendor          = GetDWBE( p_vide +  4 );
1008     id->temporalQuality = GetDWBE( p_vide +  8 );
1009     id->spatialQuality  = GetDWBE( p_vide + 12 );
1010     id->width           = GetWBE ( p_vide + 16 );
1011     id->height          = GetWBE ( p_vide + 18 );
1012     id->hRes            = GetDWBE( p_vide + 20 );
1013     id->vRes            = GetDWBE( p_vide + 24 );
1014     id->dataSize        = GetDWBE( p_vide + 28 );
1015     id->frameCount      = GetWBE ( p_vide + 32 );
1016     memcpy( &id->name, p_vide + 34, 32 );
1017     id->depth           = GetWBE ( p_vide + 66 );
1018     id->clutID          = GetWBE ( p_vide + 68 );
1019     if( i_vide > 70 )
1020     {
1021         memcpy( ((char*)&id->clutID) + 2, p_vide + 70, i_vide - 70 );
1022     }
1023
1024     msg_Dbg( p_dec->p_fifo, "idSize=%ld ver=%d rev=%d vendor=%ld tempQ=%d "
1025              "spaQ=%d w=%d h=%d dpi=%d%d dataSize=%d frameCount=%d clutID=%d",
1026              id->idSize, id->version, id->revisionLevel, id->vendor,
1027              (int)id->temporalQuality, (int)id->spatialQuality,
1028              id->width, id->height,
1029              (int)id->hRes, (int)id->vRes,
1030              (int)id->dataSize,
1031              id->frameCount,
1032              id->clutID );
1033
1034     p_dec->framedescHandle =
1035         (ImageDescriptionHandle) p_dec->NewHandleClear( id->idSize );
1036     memcpy( *p_dec->framedescHandle, id, id->idSize );
1037
1038     p_dec->plane = malloc( p_bih->biWidth * p_bih->biHeight * 3 );
1039
1040     i_result = p_dec->QTNewGWorldFromPtr( &p_dec->OutBufferGWorld,
1041                                           /*pixel format of new GWorld==YUY2 */
1042                                           kYUVSPixelFormat,
1043                                           /* we should benchmark if yvu9 is
1044                                            * faster for svq3, too */
1045                                           &p_dec->OutBufferRect,
1046                                           0, 0, 0,
1047                                           p_dec->plane,
1048                                           p_bih->biWidth * 2 );
1049
1050     msg_Dbg( p_dec->p_fifo, "NewGWorldFromPtr returned:%ld\n",
1051              65536 - ( i_result&0xffff ) );
1052
1053     memset( &p_dec->decpar, 0, sizeof( CodecDecompressParams ) );
1054     p_dec->decpar.imageDescription = p_dec->framedescHandle;
1055     p_dec->decpar.startLine        = 0;
1056     p_dec->decpar.stopLine         = ( **p_dec->framedescHandle ).height;
1057     p_dec->decpar.frameNumber      = 1;
1058     p_dec->decpar.matrixFlags      = 0;
1059     p_dec->decpar.matrixType       = 0;
1060     p_dec->decpar.matrix           = 0;
1061     p_dec->decpar.capabilities     = &p_dec->codeccap;
1062     p_dec->decpar.accuracy         = codecNormalQuality;
1063     p_dec->decpar.srcRect          = p_dec->OutBufferRect;
1064     p_dec->decpar.transferMode     = srcCopy;
1065     p_dec->decpar.dstPixMap        = **p_dec->GetGWorldPixMap( p_dec->OutBufferGWorld );/*destPixmap;  */
1066
1067     cres =  p_dec->ImageCodecPreDecompress( p_dec->ci, &p_dec->decpar );
1068     msg_Dbg( p_dec->p_fifo,
1069              "quicktime_video: ImageCodecPreDecompress cres=0x%X\n",
1070              (int)cres );
1071
1072     p_dec->p_vout = vout_Request( p_dec->p_fifo, NULL,
1073                                   p_bih->biWidth, p_bih->biHeight,
1074                                   VLC_FOURCC( 'Y', 'U', 'Y', '2' ),
1075                                   VOUT_ASPECT_FACTOR * p_bih->biWidth /
1076                                   p_bih->biHeight );
1077
1078     if( !p_dec->p_vout )
1079     {
1080         msg_Err( p_dec->p_fifo, "cannot get a vout" );
1081         goto exit_error;
1082     }
1083
1084     p_dec->i_buffer = 1000*1000;
1085     p_dec->p_buffer = malloc( p_dec->i_buffer );
1086
1087     vlc_mutex_unlock( lockval.p_address );
1088     return VLC_SUCCESS;
1089
1090 exit_error:
1091 #ifdef LOADER
1092     Restore_LDT_Keeper( p_dec->ldt_fs );
1093 #endif
1094     vlc_mutex_unlock( lockval.p_address );
1095     return VLC_EGENERIC;
1096
1097 }
1098
1099 static void DecodeThreadVideo( vdec_thread_t *p_dec )
1100 {
1101     BITMAPINFOHEADER *p_bih =
1102         (BITMAPINFOHEADER*)p_dec->p_fifo->p_bitmapinfoheader;
1103
1104     pes_packet_t    *p_pes;
1105     vlc_value_t     lockval;
1106     picture_t       *p_pic;
1107     ComponentResult cres;
1108
1109     var_Get( p_dec->p_fifo->p_libvlc, "qt_mutex", &lockval );
1110
1111     input_ExtractPES( p_dec->p_fifo, &p_pes );
1112     if( !p_pes )
1113     {
1114         msg_Err( p_dec->p_fifo, "cannot get PES" );
1115         p_dec->p_fifo->b_error = 1;
1116         return;
1117     }
1118
1119     if( p_pes->i_pes_size > p_dec->i_buffer )
1120     {
1121         p_dec->i_buffer = 3 * p_pes->i_pes_size / 2;
1122         free( p_dec->p_buffer );
1123         p_dec->p_buffer = malloc( p_dec->i_buffer );
1124     }
1125
1126     if( p_pes->i_pes_size > 0 && p_pes->i_pts > mdate() )
1127     {
1128         GetPESData( p_dec->p_buffer, p_dec->i_buffer, p_pes );
1129
1130         while( !(p_pic = vout_CreatePicture( p_dec->p_vout, 0, 0, 0 ) ) )
1131         {
1132             if( p_dec->p_fifo->b_die || p_dec->p_fifo->b_error )
1133             {
1134                 break;
1135             }
1136             msleep( VOUT_OUTMEM_SLEEP );
1137         }
1138
1139         p_dec->decpar.data                  = p_dec->p_buffer;
1140         p_dec->decpar.bufferSize            = p_pes->i_pes_size;
1141         (**p_dec->framedescHandle).dataSize = p_pes->i_pes_size;
1142
1143         vlc_mutex_lock( lockval.p_address );
1144         cres = p_dec->ImageCodecBandDecompress( p_dec->ci, &p_dec->decpar );
1145         vlc_mutex_unlock( lockval.p_address );
1146
1147         ++p_dec->decpar.frameNumber;
1148
1149         if( cres &0xFFFF )
1150         {
1151             msg_Dbg( p_dec->p_fifo, "quicktime_video: ImageCodecBandDecompress"
1152                      " cres=0x%X (-0x%X) %d :(\n",
1153                      (int)cres,(int)-cres, (int)cres );
1154         }
1155
1156         memcpy( p_pic->p[0].p_pixels,
1157                 p_dec->plane,
1158                 p_bih->biWidth * p_bih->biHeight * 2 );
1159
1160         vout_DatePicture( p_dec->p_vout, p_pic, p_pes->i_pts );
1161         vout_DisplayPicture( p_dec->p_vout, p_pic );
1162     }
1163
1164     input_DeletePES( p_dec->p_fifo->p_packets_mgt, p_pes );
1165 }
1166
1167 static void EndThreadVideo( vdec_thread_t *p_dec )
1168 {
1169     msg_Dbg( p_dec->p_fifo, "QuickTime library video decoder closing" );
1170     free( p_dec->plane );
1171     vout_Request( p_dec->p_fifo, p_dec->p_vout, 0, 0, 0, 0 );
1172
1173 #ifndef SYS_DARWIN
1174     FreeLibrary( p_dec->qtml );
1175     msg_Dbg( p_dec->p_fifo, "FreeLibrary ok." );
1176 #endif
1177
1178 #ifdef LOADER
1179     Restore_LDT_Keeper( p_dec->ldt_fs );
1180     msg_Dbg( p_dec->p_fifo, "Restore_LDT_Keeper" );
1181 #endif
1182 #ifdef SYS_DARWIN
1183     ExitMovies();
1184 #endif
1185 }
1186 #endif