]> git.sesse.net Git - vlc/blobdiff - modules/codec/quicktime.c
Removes trailing spaces. Removes tabs.
[vlc] / modules / codec / quicktime.c
index 7d682fbd54bbb879a7f64ef208955b58508f595e..1afe697d1f3d019d23bd043d1fc14a894bfcd1a3 100644 (file)
@@ -27,9 +27,9 @@
  *****************************************************************************/
 
 #include <vlc/vlc.h>
-#include <vlc/aout.h>
-#include <vlc/vout.h>
-#include <vlc/decoder.h>
+#include <vlc_aout.h>
+#include <vlc_vout.h>
+#include <vlc_codec.h>
 
 #if !defined (__APPLE__) && !defined(WIN32)
 # define LOADER 1
@@ -66,8 +66,6 @@ vlc_module_begin();
     set_subcategory( SUBCAT_INPUT_VCODEC );
     set_callbacks( Open, Close );
 
-    /* create a mutex */
-    var_Create( p_module->p_libvlc, "qt_mutex", VLC_VAR_MUTEX );
 vlc_module_end();
 
 
@@ -223,11 +221,14 @@ static int QTVideoInit( decoder_t * );
 static int Open( vlc_object_t *p_this )
 {
     decoder_t *p_dec = (decoder_t*)p_this;
+    if( var_GetGlobalMutex( "qt_mutex" ) == NULL )
+        return VLC_EGENERIC;
 
+    /* create a mutex */
     switch( p_dec->fmt_in.i_codec )
     {
         case VLC_FOURCC('S','V','Q','3'): /* Sorenson v3 */
-    /*    case VLC_FOURCC('S','V','Q','1'):  Sorenson v1 
+    /*    case VLC_FOURCC('S','V','Q','1'):  Sorenson v1
         case VLC_FOURCC('Z','y','G','o'):
         case VLC_FOURCC('V','P','3','1'):
         case VLC_FOURCC('3','I','V','1'): */
@@ -283,15 +284,11 @@ static void Close( vlc_object_t *p_this )
 {
     decoder_t     *p_dec = (decoder_t*)p_this;
     decoder_sys_t *p_sys = p_dec->p_sys;
-    vlc_value_t   lockval;
+    vlc_mutex_t   *lock;
 
     /* get lock, avoid segfault */
-    var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-#ifdef __APPLE__
-    /* on OS X QT is not threadsafe */
-    vlc_mutex_lock( &p_dec->p_vlc->quicktime_lock );
-#endif
+    lock = var_GetGlobalMutex( "qt_mutex" );
+    vlc_mutex_lock( lock );
 
     if( p_dec->fmt_out.i_cat == AUDIO_ES )
     {
@@ -307,11 +304,11 @@ static void Close( vlc_object_t *p_this )
         i_error = p_sys->SoundConverterClose( p_sys->myConverter );
         msg_Dbg( p_dec, "SoundConverterClose => %d", i_error );
 
-        if( p_sys->p_buffer ) free( p_sys->p_buffer );
+        free( p_sys->p_buffer );
     }
     else if( p_dec->fmt_out.i_cat == VIDEO_ES )
     {
-        if( p_sys->plane)  free( p_sys->plane );
+        free( p_sys->plane );
     }
 
 #ifndef __APPLE__
@@ -330,12 +327,9 @@ static void Close( vlc_object_t *p_this )
 #endif
 #endif
 
-#ifdef __APPLE__
-    vlc_mutex_unlock( &p_dec->p_vlc->quicktime_lock );
-#endif
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
 
-    free( p_sys );
+    if( p_sys ) free( p_sys );
 }
 
 /*****************************************************************************
@@ -343,29 +337,26 @@ static void Close( vlc_object_t *p_this )
  *****************************************************************************/
 static int OpenAudio( decoder_t *p_dec )
 {
-    decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );
+    decoder_sys_t *p_sys;
+    vlc_mutex_t    *lock = var_GetGlobalMutex( "qt_mutex" );
 
-    vlc_value_t     lockval;
     int             i_error;
     char            fcc[4];
     unsigned long   WantedBufferSize;
     unsigned long   InputBufferSize = 0;
     unsigned long   OutputBufferSize = 0;
 
-    memset( p_sys, 0, sizeof( decoder_sys_t ) );
+    if( lock == NULL )
+        return VLC_EGENERIC;
 
+    p_sys = calloc( sizeof( decoder_sys_t ), 1 );
     p_dec->p_sys = p_sys;
     p_dec->pf_decode_audio = DecodeAudio;
 
     memcpy( fcc, &p_dec->fmt_in.i_codec, 4 );
 
     /* get lock, avoid segfault */
-    var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-#ifdef __APPLE__
-    /* on OS X QT is not threadsafe */
-    vlc_mutex_lock( &p_dec->p_vlc->quicktime_lock );
-#endif
+    vlc_mutex_lock( lock );
 
 #ifdef __APPLE__
     EnterMovies();
@@ -476,10 +467,7 @@ static int OpenAudio( decoder_t *p_dec )
     p_sys->i_out = 0;
     p_sys->i_out_frames = 0;
 
-#ifdef __APPLE__
-    vlc_mutex_unlock( &p_dec->p_vlc->quicktime_lock );
-#endif
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
     return VLC_SUCCESS;
 
 exit_error:
@@ -487,10 +475,7 @@ exit_error:
 #ifdef LOADER
     Restore_LDT_Keeper( p_sys->ldt_fs );
 #endif
-#ifdef __APPLE__
-    vlc_mutex_unlock( &p_dec->p_vlc->quicktime_lock );
-#endif
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
 
     free( p_sys );
     return VLC_EGENERIC;
@@ -503,7 +488,6 @@ static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
 
-    vlc_value_t lockval;
     block_t     *p_block;
     int         i_error;
 
@@ -562,16 +546,16 @@ static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
         {
             int i_frames = p_sys->i_buffer / p_sys->InFrameSize;
             unsigned long i_out_frames, i_out_bytes;
+            vlc_mutex_t *lock = var_GetGlobalMutex( "qt_mutex ");
 
-            var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
-            vlc_mutex_lock( lockval.p_address );
+            vlc_mutex_lock( lock );
             i_error = p_sys->SoundConverterConvertBuffer( p_sys->myConverter,
                                                           p_sys->p_buffer,
                                                           i_frames,
                                                           p_sys->out_buffer,
                                                           &i_out_frames,
                                                           &i_out_bytes );
-            vlc_mutex_unlock( lockval.p_address );
+            vlc_mutex_unlock( lock );
 
             /*
             msg_Dbg( p_dec, "decoded %d frames -> %ld frames (error=%d)",
@@ -640,7 +624,7 @@ static int OpenVideo( decoder_t *p_dec )
     decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );
 
 #ifndef WIN32
-    vlc_value_t                         lockval;
+    vlc_mutex_t                        *lock;
     long                                i_result;
     ComponentDescription                desc;
     Component                           prev;
@@ -669,8 +653,8 @@ static int OpenVideo( decoder_t *p_dec )
              fcc, p_dec->fmt_in.video.i_width, p_dec->fmt_in.video.i_height );
 
     /* get lock, avoid segfault */
-    var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+    lock = var_GetGlobalMutex( "qt_mutex" );
+    vlc_mutex_lock( lock );
 
 #ifdef __APPLE__
     EnterMovies();
@@ -711,14 +695,15 @@ static int OpenVideo( decoder_t *p_dec )
     memset( &icap, 0, sizeof( ImageSubCodecDecompressCapabilities ) );
     cres =  p_sys->ImageCodecInitialize( p_sys->ci, &icap );
     msg_Dbg( p_dec, "ImageCodecInitialize->0x%X size=%d (%d)\n",
-             (int)cres, icap.recordSize, icap.decompressRecordSize);
+             (int)cres, (int)icap.recordSize, (int)icap.decompressRecordSize);
 
     memset( &cinfo, 0, sizeof( CodecInfo ) );
     cres =  p_sys->ImageCodecGetCodecInfo( p_sys->ci, &cinfo );
     msg_Dbg( p_dec,
-             "Flags: compr: 0x%x  decomp: 0x%x format: 0x%x\n",
-             cinfo.compressFlags,
-             cinfo.decompressFlags, cinfo.formatFlags );
+             "Flags: compr: 0x%x decomp: 0x%x format: 0x%x\n",
+             (unsigned int)cinfo.compressFlags,
+             (unsigned int)cinfo.decompressFlags,
+             (unsigned int)cinfo.formatFlags );
     msg_Dbg( p_dec, "quicktime_video: Codec name: %.*s\n",
              ((unsigned char*)&cinfo.typeName)[0],
              ((unsigned char*)&cinfo.typeName)+1 );
@@ -756,17 +741,16 @@ static int OpenVideo( decoder_t *p_dec )
 
     msg_Dbg( p_dec, "idSize=%d ver=%d rev=%d vendor=%d tempQ=%d "
              "spaQ=%d w=%d h=%d dpi=%d%d dataSize=%d depth=%d frameCount=%d clutID=%d",
-             id->idSize, id->version, id->revisionLevel, id->vendor,
+             (int)id->idSize, id->version, id->revisionLevel, (int)id->vendor,
              (int)id->temporalQuality, (int)id->spatialQuality,
-             id->width, id->height,
+             (int)id->width, (int)id->height,
              (int)id->hRes, (int)id->vRes,
              (int)id->dataSize,
              id->depth,
              id->frameCount,
              id->clutID );
 
-    p_sys->framedescHandle =
-        (ImageDescriptionHandle) p_sys->NewHandleClear( id->idSize );
+    p_sys->framedescHandle = (ImageDescriptionHandle) NewHandleClear( id->idSize );
     memcpy( *p_sys->framedescHandle, id, id->idSize );
 
     p_sys->plane = malloc( p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 3 );
@@ -779,7 +763,7 @@ static int OpenVideo( decoder_t *p_dec )
                                           &p_sys->OutBufferRect,
                                           0, 0, 0,
                                           p_sys->plane,
-                                          (long)p_dec->fmt_in.video.i_width * 2 );
+                                          p_dec->fmt_in.video.i_width * 2 );
 
     msg_Dbg( p_dec, "NewGWorldFromPtr returned:%ld\n",
              65536 - ( i_result&0xffff ) );
@@ -806,15 +790,15 @@ static int OpenVideo( decoder_t *p_dec )
     p_dec->fmt_out.video.i_width = p_dec->fmt_in.video.i_width;
     p_dec->fmt_out.video.i_height= p_dec->fmt_in.video.i_height;
     p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * p_dec->fmt_in.video.i_width / p_dec->fmt_in.video.i_height;
-    
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
     return VLC_SUCCESS;
 
 exit_error:
 #ifdef LOADER
     Restore_LDT_Keeper( p_sys->ldt_fs );
 #endif
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
 
 #endif /* !WIN32 */
 
@@ -828,7 +812,7 @@ exit_error:
 static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
-    vlc_value_t   lockval;
+    vlc_mutex_t   *lock;
     block_t       *p_block;
     picture_t     *p_pic;
     mtime_t       i_pts;
@@ -855,13 +839,8 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     }
     p_block = *pp_block;
-
-    if( !p_block->i_buffer )
-    {
-        block_Release( p_block );
-        return NULL;
-    }
-    
+    *pp_block = NULL;
     i_pts = p_block->i_pts ? p_block->i_pts : p_block->i_dts;
 
     if( i_pts < mdate() )
@@ -872,7 +851,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
     {
         p_sys->i_late = 0;
     }
-    msg_Dbg( p_dec, "bufsize: %d",p_block->i_buffer);
+    msg_Dbg( p_dec, "bufsize: %d", p_block->i_buffer);
 
     if( p_sys->i_late > 10 )
     {
@@ -880,9 +859,9 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
         block_Release( p_block );
         return NULL;
     }
-    
-    var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+    lock = var_GetGlobalMutex( "qt_mutex" );
+    vlc_mutex_lock( lock );
 
     if( ( p_pic = p_dec->pf_vout_buffer_new( p_dec ) ) )
     {
@@ -905,9 +884,8 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
                 p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 2 );
         p_pic->date = i_pts;
     }
-    else 
-    
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
 
     block_Release( p_block );
     return p_pic;
@@ -975,7 +953,7 @@ static int QTAudioInit( decoder_t *p_dec )
         return VLC_EGENERIC;
     }
 
-    msg_Dbg( p_dec, "Standard init done" );
+    msg_Dbg( p_dec, "standard init done" );
 #endif /* else __APPLE__ */
 
     return VLC_SUCCESS;