]> git.sesse.net Git - vlc/blobdiff - modules/codec/quicktime.c
We also want to activate AMR-WB. More to come within the next few days.
[vlc] / modules / codec / quicktime.c
index 9cb4137a955fcd367bfb73b77b50dba5ee8deed9..7c6025a65565865697a1dfdcb8629998b8224e89 100644 (file)
  * Preamble
  *****************************************************************************/
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_aout.h>
 #include <vlc_vout.h>
 #include <vlc_codec.h>
@@ -60,8 +65,8 @@ static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
 vlc_module_begin();
-    set_description( _("QuickTime library decoder") );
-    set_capability( "decoder", 10 );
+    set_description( N_("QuickTime library decoder") );
+    set_capability( "decoder", 100 );
     set_category( CAT_INPUT );
     set_subcategory( SUBCAT_INPUT_VCODEC );
     set_callbacks( Open, Close );
@@ -222,13 +227,18 @@ static int Open( vlc_object_t *p_this )
 {
     decoder_t *p_dec = (decoder_t*)p_this;
 
-    /* create a mutex */
-    var_Create( p_this->p_libvlc_global, "qt_mutex", VLC_VAR_MUTEX );
+#ifdef __APPLE__
+    OSErr err;
+    SInt32 qtVersion;
     
+    err = Gestalt(gestaltQuickTimeVersion, &qtVersion);
+#endif
+
     switch( p_dec->fmt_in.i_codec )
     {
+        case VLC_FOURCC('h','2','6','4'): /* H.264 */
         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'): */
@@ -243,7 +253,16 @@ static int Open( vlc_object_t *p_this )
             return OpenVideo( p_dec );
 #endif
 
+#ifdef __APPLE__
+        case VLC_FOURCC('I','L','B','C'): /* iLBC */
+            if ((err == noErr) || (qtVersion < 0x07500000)) 
+                return VLC_EGENERIC;
+        case VLC_FOURCC('i','l','b','c'): /* iLBC */
+            if ((err == noErr) || (qtVersion < 0x07500000)) 
+                return VLC_EGENERIC;
+#endif
         case VLC_FOURCC('s','a','m','r'): /* 3GPP AMR audio */
+        case VLC_FOURCC('s','a','m','b'): /* 3GPP AMR-WB audio */
         case VLC_FOURCC('m','p','4','a'): /* MPEG-4 audio */
         case VLC_FOURCC('Q','D','M','C'): /* QDesign */
         case VLC_FOURCC('Q','D','M','2'): /* QDesign* 2 */
@@ -284,11 +303,10 @@ 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_global, "qt_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+    lock = var_AcquireMutex( "qt_mutex" );
 
     if( p_dec->fmt_out.i_cat == AUDIO_ES )
     {
@@ -304,11 +322,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__
@@ -327,10 +345,9 @@ static void Close( vlc_object_t *p_this )
 #endif
 #endif
 
-    vlc_mutex_unlock( lockval.p_address );
-    var_Destroy( p_dec->p_libvlc_global, "qt_mutex" );
+    vlc_mutex_unlock( lock );
 
-    if( p_sys ) free( p_sys );
+    free( p_sys );
 }
 
 /*****************************************************************************
@@ -338,26 +355,25 @@ 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_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 ) );
+    /* get lock, avoid segfault */
+    vlc_mutex_t    *lock = var_AcquireMutex( "qt_mutex" );
+    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_global, "qt_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-
 #ifdef __APPLE__
     EnterMovies();
 #endif
@@ -463,11 +479,13 @@ static int OpenAudio( decoder_t *p_dec )
     p_sys->i_buffer      = 0;
     p_sys->i_buffer_size = 100*1000;
     p_sys->p_buffer      = malloc( p_sys->i_buffer_size );
+    if( !p_sys->p_buffer )
+        goto exit_error;
 
     p_sys->i_out = 0;
     p_sys->i_out_frames = 0;
 
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
     return VLC_SUCCESS;
 
 exit_error:
@@ -475,7 +493,7 @@ exit_error:
 #ifdef LOADER
     Restore_LDT_Keeper( p_sys->ldt_fs );
 #endif
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
 
     free( p_sys );
     return VLC_EGENERIC;
@@ -488,7 +506,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;
 
@@ -500,7 +517,7 @@ static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
         if( OpenAudio( p_dec ) )
         {
             /* Fatal */
-            p_dec->b_error = VLC_TRUE;
+            p_dec->b_error = true;
             return NULL;
         }
 
@@ -526,7 +543,8 @@ static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
 
     if( p_sys->i_out_frames <= 0 )
     {
-        if( ( p_sys->pts = p_block->i_pts ) < mdate() )
+        p_sys->pts = p_block->i_pts;
+        if( decoder_GetDisplayDate( p_dec, p_block->i_pts ) < mdate() )
         {
             block_Release( p_block );
             *pp_block = NULL;
@@ -547,16 +565,15 @@ 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_AcquireMutex( "qt_mutex ");
 
-            var_Get( p_dec->p_libvlc_global, "qt_mutex", &lockval );
-            vlc_mutex_lock( lockval.p_address );
             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)",
@@ -623,9 +640,11 @@ static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
 static int OpenVideo( decoder_t *p_dec )
 {
     decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );
+    if( !p_sys )
+        return VLC_ENOMEM;
 
 #ifndef WIN32
-    vlc_value_t                         lockval;
+    vlc_mutex_t                        *lock;
     long                                i_result;
     ComponentDescription                desc;
     Component                           prev;
@@ -654,8 +673,7 @@ 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_global, "qt_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+    lock = var_AcquireMutex( "qt_mutex" );
 
 #ifdef __APPLE__
     EnterMovies();
@@ -719,6 +737,8 @@ static int OpenVideo( decoder_t *p_dec )
     /* codec data FIXME use codec not SVQ3 */
     msg_Dbg( p_dec, "vide = %d", i_vide  );
     id = malloc( sizeof( ImageDescription ) + ( i_vide - 70 ) );
+    if( !id )
+        goto exit_error;
     id->idSize          = sizeof( ImageDescription ) + ( i_vide - 70 );
     id->cType           = FCC( fcc[0], fcc[1], fcc[2], fcc[3] );
     id->version         = GetWBE ( p_vide +  0 );
@@ -755,6 +775,8 @@ static int OpenVideo( decoder_t *p_dec )
     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 );
+    if( !p_sys->plane )
+        goto exit_error;
 
     i_result = p_sys->QTNewGWorldFromPtr( &p_sys->OutBufferGWorld,
                                           /*pixel format of new GWorld==YUY2 */
@@ -791,15 +813,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 */
 
@@ -813,7 +835,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;
@@ -828,7 +850,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
         if( OpenVideo( p_dec ) )
         {
             /* Fatal */
-            p_dec->b_error = VLC_TRUE;
+            p_dec->b_error = true;
             return NULL;
         }
         p_sys = p_dec->p_sys;
@@ -841,10 +863,10 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
     }
     p_block = *pp_block;
     *pp_block = NULL;
-    
     i_pts = p_block->i_pts ? p_block->i_pts : p_block->i_dts;
 
-    if( i_pts < mdate() )
+    if( decoder_GetDisplayDate( p_dec, i_pts ) < mdate() )
     {
         p_sys->i_late++;
     }
@@ -860,9 +882,8 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
         block_Release( p_block );
         return NULL;
     }
-    
-    var_Get( p_dec->p_libvlc_global, "qt_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+    lock = var_AcquireMutex( "qt_mutex" );
 
     if( ( p_pic = p_dec->pf_vout_buffer_new( p_dec ) ) )
     {
@@ -885,8 +906,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;
     }
-    
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
 
     block_Release( p_block );
     return p_pic;