]> git.sesse.net Git - vlc/blobdiff - modules/access/dc1394.c
Used a sar for picture_New/Setup.
[vlc] / modules / access / dc1394.c
index ec3ea6affdb2d420424ce16cfc28a199681b2d67..9575d8adf82d91aa112454581ca84a01b8d06c1e 100644 (file)
@@ -62,7 +62,7 @@
  *****************************************************************************/
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
-static void OpenAudioDev( demux_t *p_demux );
+static int OpenAudioDev( demux_t *p_demux );
 static inline void CloseAudioDev( demux_t *p_demux );
 
 vlc_module_begin()
@@ -122,21 +122,20 @@ static int process_options( demux_t *p_demux);
 static int FindCamera( demux_sys_t *sys, demux_t *p_demux )
 {
     dc1394camera_list_t *list;
+    int i_ret = VLC_EGENERIC;
 
     msg_Dbg( p_demux, "Scanning for ieee1394 ports ..." );
 
     if( dc1394_camera_enumerate (sys->p_dccontext, &list) != DC1394_SUCCESS )
     {
         msg_Err(p_demux, "Can not ennumerate cameras");
-        dc1394_camera_free_list (list);
-        return VLC_EGENERIC;
+        goto end;
     }
 
     if( list->num == 0 )
     {
         msg_Err(p_demux, "Can not find cameras");
-        dc1394_camera_free_list (list);
-        return VLC_EGENERIC;
+        goto end;
     }
 
     sys->num_cameras = list->num;
@@ -159,16 +158,14 @@ static int FindCamera( demux_sys_t *sys, demux_t *p_demux )
         {
             msg_Err( p_demux, "Can't find camera with uid : 0x%llx.",
                      sys->selected_uid );
-            dc1394_camera_free_list (list);
-            return VLC_EGENERIC;
+            goto end;
         }
     }
     else if( sys->selected_camera >= (int)list->num )
     {
         msg_Err( p_demux, "There are not this many cameras. (%d/%d)",
                  sys->selected_camera, sys->num_cameras );
-        dc1394_camera_free_list (list);
-        return VLC_EGENERIC;
+        goto end;
     }
     else if( sys->selected_camera >= 0 )
     {
@@ -181,8 +178,11 @@ static int FindCamera( demux_sys_t *sys, demux_t *p_demux )
                                           list->ids[0].guid);
     }
 
+    i_ret = VLC_SUCCESS;
+
+end:
     dc1394_camera_free_list (list);
-    return VLC_SUCCESS;
+    return i_ret;
 }
 
 /*****************************************************************************
@@ -318,7 +318,8 @@ static int Open( vlc_object_t *p_this )
             msg_Err( p_demux, "Unable to set initial focus to %u",
                      p_sys->focus );
         }
-        msg_Dbg( p_demux, "Initial focus set to %u", p_sys->focus );
+        else
+            msg_Dbg( p_demux, "Initial focus set to %u", p_sys->focus );
     }
 
     if( dc1394_feature_set_value( p_sys->camera,
@@ -328,7 +329,8 @@ static int Open( vlc_object_t *p_this )
         msg_Err( p_demux, "Unable to set initial brightness to %u",
                  p_sys->brightness );
     }
-    msg_Dbg( p_demux, "Initial brightness set to %u", p_sys->brightness );
+    else
+        msg_Dbg( p_demux, "Initial brightness set to %u", p_sys->brightness );
 
     if( dc1394_video_set_framerate( p_sys->camera,
                     p_sys->frame_rate ) != DC1394_SUCCESS )
@@ -380,8 +382,7 @@ static int Open( vlc_object_t *p_this )
     i_height = p_sys->height;
 
     if( picture_Setup( &p_sys->pic, VLC_CODEC_UYVY,
-                       i_width, i_height,
-                       i_width * VOUT_ASPECT_FACTOR / i_height ) )
+                       i_width, i_height, 1, 1 ) )
     {
         msg_Err( p_demux ,"unknown chroma" );
         Close( p_this );
@@ -400,8 +401,7 @@ static int Open( vlc_object_t *p_this )
 
     if( p_sys->audio_device )
     {
-        OpenAudioDev( p_demux );
-        if( p_sys->fd_audio >= 0 )
+        if( OpenAudioDev( p_demux ) == VLC_SUCCESS )
         {
             es_format_t fmt;
             es_format_Init( &fmt, AUDIO_ES, VLC_CODEC_S16L ); /* FIXME: hmm, ?? */
@@ -435,7 +435,7 @@ static int Open( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
-static void OpenAudioDev( demux_t *p_demux )
+static int OpenAudioDev( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     char *psz_device = p_sys->audio_device;
@@ -446,7 +446,7 @@ static void OpenAudioDev( demux_t *p_demux )
     if( p_sys->fd_audio  < 0 )
     {
         msg_Err( p_demux, "Cannot open audio device (%s)", psz_device );
-        CloseAudioDev( p_demux );
+        return VLC_EGENERIC;
     }
 
     if( !p_sys->i_sample_rate )
@@ -457,7 +457,7 @@ static void OpenAudioDev( demux_t *p_demux )
     {
         msg_Err( p_demux, "Cannot set audio format (16b little endian) "
                           "(%d)", i_format );
-        CloseAudioDev( p_demux );
+        goto error;
     }
 
     result = ioctl( p_sys->fd_audio, SNDCTL_DSP_CHANNELS, &p_sys->channels );
@@ -465,7 +465,7 @@ static void OpenAudioDev( demux_t *p_demux )
     {
         msg_Err( p_demux, "Cannot set audio channels count (%d)",
                  p_sys->channels );
-        CloseAudioDev( p_demux );
+        goto error;
     }
 
     result = ioctl( p_sys->fd_audio, SNDCTL_DSP_SPEED, &p_sys->i_sample_rate );
@@ -473,7 +473,7 @@ static void OpenAudioDev( demux_t *p_demux )
     {
         msg_Err( p_demux, "Cannot set audio sample rate (%d)",
          p_sys->i_sample_rate );
-        CloseAudioDev( p_demux );
+        goto error;
     }
 
     msg_Dbg( p_demux, "Opened adev=`%s' %s %dHz",
@@ -482,6 +482,13 @@ static void OpenAudioDev( demux_t *p_demux )
              p_sys->i_sample_rate );
 
     p_sys->i_audio_max_frame_size = 32 * 1024;
+
+    return VLC_SUCCESS;
+
+error:
+    CloseAudioDev( p_demux );
+    p_sys->fd_audio = -1;
+    return VLC_EGENERIC;
 }
 
 static inline void CloseAudioDev( demux_t *p_demux )
@@ -513,6 +520,7 @@ static void Close( vlc_object_t *p_this )
     dc1394_camera_free(p_sys->camera);
     dc1394_free(p_sys->p_dccontext);
 
+    free( p_sys->video_device );
     free( p_sys->audio_device );
     free( p_sys );
 }
@@ -610,7 +618,10 @@ static block_t *GrabAudio( demux_t *p_demux )
                    p_sys->i_audio_max_frame_size );
 
     if( i_read <= 0 )
+    {
+        block_Release( p_block );
         return NULL;
+    }
 
     p_block->i_buffer = i_read;
 
@@ -633,7 +644,7 @@ static int Demux( demux_t *p_demux )
     block_t *p_blockv = NULL;
 
     /* Try grabbing audio frames first */
-    if( p_sys->fd_audio > 0 )
+    if( p_sys->fd_audio >= 0 )
         p_blocka = GrabAudio( p_demux );
 
     /* Try grabbing video frame */
@@ -958,5 +969,7 @@ static int process_options( demux_t *p_demux )
         else // YUV422 default
             p_sys->video_mode = DC1394_VIDEO_MODE_640x480_YUV422;
     }
+
+    free( psz_dup );
     return VLC_SUCCESS;
 }