]> git.sesse.net Git - vlc/blobdiff - lib/video.c
mediacodec: don't loop in GetOutput
[vlc] / lib / video.c
index 163bca306e2245bd4d15a4aa4cf3be2f6365ad20..4abe36e4311fd54682a41339eaa9e87e9e47ed35 100644 (file)
@@ -38,6 +38,7 @@
 #include <vlc_vout.h>
 
 #include "media_player_internal.h"
+#include <math.h>
 #include <assert.h>
 
 /*
@@ -147,11 +148,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,18 +168,24 @@ 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 )
@@ -217,17 +230,17 @@ unsigned libvlc_media_player_has_vout( libvlc_media_player_t *p_mi )
 
 float libvlc_video_get_scale( libvlc_media_player_t *mp )
 {
-    float f_scale = var_GetFloat (mp, "scale");
+    float f_scale = var_GetFloat (mp, "zoom");
     if (var_GetBool (mp, "autoscale"))
-        f_scale = 0.;
+        f_scale = 0.f;
     return f_scale;
 }
 
 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale )
 {
-    if (f_scale != 0.)
-        var_SetFloat (p_mp, "scale", f_scale);
-    var_SetBool (p_mp, "autoscale", f_scale == 0.);
+    if (isfinite(f_scale) && f_scale != 0.f)
+        var_SetFloat (p_mp, "zoom", f_scale);
+    var_SetBool (p_mp, "autoscale", f_scale == 0.f);
 
     /* Apply to current video outputs (if any) */
     size_t n;
@@ -236,9 +249,9 @@ void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale )
     {
         vout_thread_t *p_vout = pp_vouts[i];
 
-        if (f_scale != 0.)
-            var_SetFloat (p_vout, "scale", f_scale);
-        var_SetBool (p_vout, "autoscale", f_scale == 0.);
+        if (isfinite(f_scale) && f_scale != 0.f)
+            var_SetFloat (p_vout, "zoom", f_scale);
+        var_SetBool (p_vout, "autoscale", f_scale == 0.f);
         vlc_object_release (p_vout);
     }
     free (pp_vouts);
@@ -271,11 +284,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 +291,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 +315,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);
@@ -503,7 +495,7 @@ void libvlc_toggle_teletext( libvlc_media_player_t *p_mi )
     else
     {
         vlc_value_t list;
-        if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
+        if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETCHOICES, &list, NULL ) )
         {
             if( list.p_list->i_count > 0 )
                 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
@@ -537,32 +529,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 )
@@ -585,7 +558,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 );
@@ -638,66 +611,63 @@ void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi,
 /* module helpers */
 /* ************** */
 
-
-static vlc_object_t *get_object( libvlc_media_player_t * p_mi,
-                                 const char *name )
+static bool find_sub_source_by_name( libvlc_media_player_t *p_mi, const char *restrict name )
 {
-    vlc_object_t *object;
     vout_thread_t *vout = GetVout( p_mi, 0 );
+    if (!vout)
+        return false;
 
-    if( vout )
+    char *psz_sources = var_GetString( vout, "sub-source" );
+    if( !psz_sources )
     {
-        object = vlc_object_find_name( vout, name );
-        vlc_object_release(vout);
+        libvlc_printerr( "%s not enabled", name );
+        vlc_object_release( vout );
+        return false;
     }
-    else
-        object = NULL;
 
-    if( !object )
-        libvlc_printerr( "%s not enabled", name );
-    return object;
+    /* Find 'name'  */
+    char *p = strstr( psz_sources, name );
+    free( psz_sources );
+    vlc_object_release( vout );
+    return (p != NULL);
 }
 
-
 typedef const struct {
     const char name[20];
     unsigned type;
 } opt_t;
 
-
 static void
 set_int( libvlc_media_player_t *p_mi, const char *restrict name,
          const opt_t *restrict opt, int value )
 {
     if( !opt ) return;
 
-    if( !opt->type ) /* the enabler */
+    switch( opt->type )
     {
-        vout_thread_t *vout = GetVout( p_mi, 0 );
-        if (vout)
+        case 0: /* the enabler */
         {
-            vout_EnableFilter( vout, opt->name, value, false );
-            vlc_object_release( vout );
+            vout_thread_t *vout = GetVout( p_mi, 0 );
+            if (vout != NULL)
+            {   /* Fill sub-source */
+                vout_EnableFilter( vout, opt->name, value, false );
+                var_TriggerCallback( vout, "sub-source" );
+                vlc_object_release( vout );
+            }
+            break;
         }
-        return;
-    }
-
-    if( opt->type != VLC_VAR_INTEGER )
-    {
-        libvlc_printerr( "Invalid argument to %s in %s", name, "set int" );
-        return;
-    }
-
-    var_SetInteger(p_mi, opt->name, value);
-    vlc_object_t *object = get_object( p_mi, name );
-    if( object )
-    {
-        var_SetInteger(object, opt->name, value);
-        vlc_object_release( object );
+        case VLC_VAR_INTEGER:
+            var_SetInteger( p_mi, opt->name, value );
+            break;
+        case VLC_VAR_FLOAT:
+            var_SetFloat( p_mi, opt->name, value );
+            break;
+        default:
+            libvlc_printerr( "Invalid argument to %s in %s", name, "set int" );
+            return;
     }
 }
 
-
 static int
 get_int( libvlc_media_player_t *p_mi, const char *restrict name,
          const opt_t *restrict opt )
@@ -708,19 +678,19 @@ get_int( libvlc_media_player_t *p_mi, const char *restrict name,
     {
         case 0: /* the enabler */
         {
-            vlc_object_t *object = get_object( p_mi, name );
-            vlc_object_release( object );
-            return object != NULL;
+            bool b_enabled = find_sub_source_by_name( p_mi, name );
+            return b_enabled ? 1 : 0;
         }
     case VLC_VAR_INTEGER:
         return var_GetInteger(p_mi, opt->name);
+    case VLC_VAR_FLOAT:
+        return lroundf(var_GetFloat(p_mi, opt->name));
     default:
         libvlc_printerr( "Invalid argument to %s in %s", name, "get int" );
         return 0;
     }
 }
 
-
 static void
 set_float( libvlc_media_player_t *p_mi, const char *restrict name,
             const opt_t *restrict opt, float value )
@@ -734,23 +704,14 @@ set_float( libvlc_media_player_t *p_mi, const char *restrict name,
     }
 
     var_SetFloat( p_mi, opt->name, value );
-
-    vlc_object_t *object = get_object( p_mi, name );
-    if( object )
-    {
-        var_SetFloat(object, opt->name, value );
-        vlc_object_release( object );
-    }
 }
 
-
 static float
 get_float( libvlc_media_player_t *p_mi, const char *restrict name,
             const opt_t *restrict opt )
 {
     if( !opt ) return 0.0;
 
-
     if( opt->type != VLC_VAR_FLOAT )
     {
         libvlc_printerr( "Invalid argument to %s in %s", name, "get float" );
@@ -760,7 +721,6 @@ get_float( libvlc_media_player_t *p_mi, const char *restrict name,
     return var_GetFloat( p_mi, opt->name );
 }
 
-
 static void
 set_string( libvlc_media_player_t *p_mi, const char *restrict name,
             const opt_t *restrict opt, const char *restrict psz_value )
@@ -774,16 +734,8 @@ set_string( libvlc_media_player_t *p_mi, const char *restrict name,
     }
 
     var_SetString( p_mi, opt->name, psz_value );
-
-    vlc_object_t *object = get_object( p_mi, name );
-    if( object )
-    {
-        var_SetString(object, opt->name, psz_value );
-        vlc_object_release( object );
-    }
 }
 
-
 static char *
 get_string( libvlc_media_player_t *p_mi, const char *restrict name,
             const opt_t *restrict opt )
@@ -799,7 +751,6 @@ get_string( libvlc_media_player_t *p_mi, const char *restrict name,
     return var_GetString( p_mi, opt->name );
 }
 
-
 static const opt_t *
 marq_option_bynumber(unsigned option)
 {
@@ -824,8 +775,6 @@ marq_option_bynumber(unsigned option)
     return r;
 }
 
-static vlc_object_t *get_object( libvlc_media_player_t *, const char *);
-
 /*****************************************************************************
  * libvlc_video_get_marquee_int : get a marq option value
  *****************************************************************************/
@@ -865,7 +814,6 @@ void libvlc_video_set_marquee_string( libvlc_media_player_t *p_mi,
 
 /* logo module support */
 
-
 static const opt_t *
 logo_option_bynumber( unsigned option )
 {
@@ -889,11 +837,10 @@ logo_option_bynumber( unsigned option )
     return r;
 }
 
-
 void libvlc_video_set_logo_string( libvlc_media_player_t *p_mi,
                                    unsigned option, const char *psz_value )
 {
-    set_string( p_mi,"logo",logo_option_bynumber(option),psz_value );
+    set_string( p_mi,"logo",logo_option_bynumber(option), psz_value );
 }
 
 
@@ -919,12 +866,12 @@ adjust_option_bynumber( unsigned option )
 {
     static const opt_t optlist[] =
     {
-        { "adjust",               0 },
-        { "contrast",             VLC_VAR_FLOAT },
-        { "brightness",           VLC_VAR_FLOAT },
-        { "hue",                  VLC_VAR_INTEGER },
-        { "saturation",           VLC_VAR_FLOAT },
-        { "gamma",                VLC_VAR_FLOAT },
+        { "adjust",     0 },
+        { "contrast",   VLC_VAR_FLOAT },
+        { "brightness", VLC_VAR_FLOAT },
+        { "hue",        VLC_VAR_FLOAT },
+        { "saturation", VLC_VAR_FLOAT },
+        { "gamma",      VLC_VAR_FLOAT },
     };
     enum { num_opts = sizeof(optlist) / sizeof(*optlist) };