]> git.sesse.net Git - vlc/blobdiff - lib/video.c
UNPACK_DIR should only strip .tar as 2nd suffix
[vlc] / lib / video.c
index ff0697956c79c1c426de424b9e035ba5f55a8490..43471b9e21b5e0cda1d57d00a4fe8bae8393c27e 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * video.c: libvlc new API video functions
  *****************************************************************************
- * Copyright (C) 2005-2010 the VideoLAN team
+ * Copyright (C) 2005-2010 VLC authors and VideoLAN
  *
  * $Id$
  *
  *          Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
  *          Damien Fouilleul <damienf a_t videolan dot org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -147,11 +147,17 @@ libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, unsigned num,
     if (p_vout == NULL)
         return -1;
 
-    /* FIXME: This is not atomic. Someone else could change the values,
-     * at least in theory. */
+    /* FIXME: This is not atomic. All parameters should be passed at once
+     * (obviously _not_ with var_*()). Also, the libvlc object should not be
+     * used for the callbacks: that breaks badly if there are concurrent
+     * media players in the instance. */
+    var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER );
     var_SetInteger( p_vout, "snapshot-width", i_width);
+    var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER );
     var_SetInteger( p_vout, "snapshot-height", i_height );
+    var_Create( p_vout, "snapshot-path", VLC_VAR_STRING );
     var_SetString( p_vout, "snapshot-path", psz_filepath );
+    var_Create( p_vout, "snapshot-format", VLC_VAR_STRING );
     var_SetString( p_vout, "snapshot-format", "png" );
     var_TriggerCallback( p_vout, "video-snapshot" );
     vlc_object_release( p_vout );
@@ -161,34 +167,40 @@ libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, unsigned num,
 int libvlc_video_get_size( libvlc_media_player_t *p_mi, unsigned num,
                            unsigned *restrict px, unsigned *restrict py )
 {
-#if 0
-    vout_thread_t *p_vout = GetVout (p_mi, num);
-    if (p_vout == NULL)
-        return -1;
+    libvlc_media_track_info_t *info;
+    int ret = -1;
+    if (!p_mi->p_md)
+        return ret;
+    int infos = libvlc_media_get_tracks_info(p_mi->p_md, &info);
+    if (infos <= 0)
+        return ret;
+
+    for (int i = 0; i < infos; i++)
+        if (info[i].i_type == libvlc_track_video && num-- == 0) {
+            *px = info[i].u.video.i_width;
+            *py = info[i].u.video.i_height;
+            ret = 0;
+            break;
+        }
 
-    *px = p_vout->i_window_height;
-    *py = p_vout->i_window_width;
-    vlc_object_release (p_vout);
-    return 0;
-#else
-    return -1;
-#endif
+    free(info);
+    return ret;
 }
 
 int libvlc_video_get_height( libvlc_media_player_t *p_mi )
 {
-    unsigned height, width;
+    unsigned width, height;
 
-    if (libvlc_video_get_size (p_mi, 0, &height, &width))
+    if (libvlc_video_get_size (p_mi, 0, &width, &height))
         return 0;
     return height;
 }
 
 int libvlc_video_get_width( libvlc_media_player_t *p_mi )
 {
-    unsigned height, width;
+    unsigned width, height;
 
-    if (libvlc_video_get_size (p_mi, 0, &height, &width))
+    if (libvlc_video_get_size (p_mi, 0, &width, &height))
         return 0;
     return width;
 }
@@ -271,11 +283,6 @@ void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
 int libvlc_video_get_spu( libvlc_media_player_t *p_mi )
 {
     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
-    vlc_value_t val_list;
-    vlc_value_t val;
-    int i_spu = -1;
-    int i_ret = -1;
-    int i;
 
     if( !p_input_thread )
     {
@@ -283,24 +290,7 @@ int libvlc_video_get_spu( libvlc_media_player_t *p_mi )
         return -1;
     }
 
-    i_ret = var_Get( p_input_thread, "spu-es", &val );
-    if( i_ret < 0 )
-    {
-        vlc_object_release( p_input_thread );
-        libvlc_printerr( "Subtitle information not found" );
-        return -1;
-    }
-
-    var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
-    for( i = 0; i < val_list.p_list->i_count; i++ )
-    {
-        if( val.i_int == val_list.p_list->p_values[i].i_int )
-        {
-            i_spu = i;
-            break;
-        }
-    }
-    var_FreeList( &val_list, NULL );
+    int i_spu = var_GetInteger( p_input_thread, "spu-es" );
     vlc_object_release( p_input_thread );
     return i_spu;
 }
@@ -324,26 +314,27 @@ libvlc_track_description_t *
     return libvlc_get_track_description( p_mi, "spu-es" );
 }
 
-int libvlc_video_set_spu( libvlc_media_player_t *p_mi, unsigned i_spu )
+int libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu )
 {
     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
     vlc_value_t list;
-    int i_ret = 0;
+    int i_ret = -1;
 
     if( !p_input_thread )
         return -1;
 
     var_Change (p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &list, NULL);
-
-    if (i_spu > (unsigned)list.p_list->i_count)
+    for (int i = 0; i < list.p_list->i_count; i++)
     {
-        libvlc_printerr( "Subtitle number out of range (%u/%u)",
-                         i_spu, list.p_list->i_count );
-        i_ret = -1;
-        goto end;
+        if( i_spu == list.p_list->p_values[i].i_int )
+        {
+            if( var_SetInteger( p_input_thread, "spu-es", i_spu ) < 0 )
+                break;
+            i_ret = 0;
+            goto end;
+        }
     }
-    var_SetInteger (p_input_thread, "spu-es",
-                    list.p_list->p_values[i_spu].i_int);
+    libvlc_printerr( "Track identifier not found" );
 end:
     vlc_object_release (p_input_thread);
     var_FreeList (&list, NULL);
@@ -365,6 +356,44 @@ int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
     return b_ret;
 }
 
+int64_t libvlc_video_get_spu_delay( libvlc_media_player_t *p_mi )
+{
+    input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
+    int64_t val = 0;
+
+    if( p_input_thread )
+    {
+        val = var_GetTime( p_input_thread, "spu-delay" );
+        vlc_object_release( p_input_thread );
+    }
+    else
+    {
+        libvlc_printerr( "No active input" );
+    }
+
+    return val;
+}
+
+int libvlc_video_set_spu_delay( libvlc_media_player_t *p_mi,
+                                int64_t i_delay )
+{
+    input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
+    int ret = -1;
+
+    if( p_input_thread )
+    {
+        var_SetTime( p_input_thread, "spu-delay", i_delay );
+        vlc_object_release( p_input_thread );
+        ret = 0;
+    }
+    else
+    {
+        libvlc_printerr( "No active input" );
+    }
+
+    return ret;
+}
+
 libvlc_track_description_t *
         libvlc_video_get_title_description( libvlc_media_player_t *p_mi )
 {
@@ -499,32 +528,13 @@ libvlc_track_description_t *
 int libvlc_video_get_track( libvlc_media_player_t *p_mi )
 {
     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
-    vlc_value_t val_list;
-    vlc_value_t val;
-    int i_track = -1;
 
     if( !p_input_thread )
         return -1;
 
-    if( var_Get( p_input_thread, "video-es", &val ) < 0 )
-    {
-        libvlc_printerr( "Video track information not found" );
-        vlc_object_release( p_input_thread );
-        return -1;
-    }
-
-    var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
-    for( int i = 0; i < val_list.p_list->i_count; i++ )
-    {
-        if( val_list.p_list->p_values[i].i_int == val.i_int )
-        {
-            i_track = i;
-            break;
-        }
-    }
-    var_FreeList( &val_list, NULL );
+    int id = var_GetInteger( p_input_thread, "video-es" );
     vlc_object_release( p_input_thread );
-    return i_track;
+    return id;
 }
 
 int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
@@ -547,7 +557,7 @@ int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
             goto end;
         }
     }
-    libvlc_printerr( "Video track number out of range" );
+    libvlc_printerr( "Track identifier not found" );
 end:
     var_FreeList( &val_list, NULL );
     vlc_object_release( p_input_thread );