]> git.sesse.net Git - vlc/blobdiff - modules/video_output/opengl.c
misc/objects.c: Don't rely on vlc_object_destroy() to destroy objects, but expects...
[vlc] / modules / video_output / opengl.c
index fa2c122e67fdb60dd78bd16bf4f919d92a679889..a8835a9ce4a999a180cd9d0762da7bb0fb58b233 100644 (file)
  * Preamble
  *****************************************************************************/
 #include <errno.h>                                                 /* ENOMEM */
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
 #include <vlc_vout.h>
     static const char *ppsz_effects[] = {
             "none", "cube", "transparent-cube", "cylinder", "torus", "sphere","SQUAREXY","SQUARER", "ASINXY", "ASINR", "SINEXY", "SINER" };
     static const char *ppsz_effects_text[] = {
-            N_("None"), N_("Cube"), N_("Transparent Cube"), 
+            N_("None"), N_("Cube"), N_("Transparent Cube"),
             N_("Cylinder"), N_("Torus"), N_("Sphere"), N_("SQUAREXY"),N_("SQUARER"), N_("ASINXY"), N_("ASINR"), N_("SINEXY"), N_("SINER") };
 #endif
 
@@ -141,9 +143,9 @@ static int InitTextures  ( vout_thread_t * );
 static int SendEvents    ( vlc_object_t *, char const *,
                            vlc_value_t, vlc_value_t, void * );
 
-#ifdef OPENGL_MORE_EFFECT                       
+#ifdef OPENGL_MORE_EFFECT
 static float Z_Compute   ( float, int, float, float );
-static void Transform    ( float, int, float, float, int, int, int, int, double *, double * );
+static void Transform    ( int, float, float, int, int, int, int, double *, double * );
 
 /*****************************************************************************
  * Module descriptor
@@ -162,6 +164,8 @@ static void Transform    ( float, int, float, float, int, int, int, int, double
 #define POV_Z_LONGTEXT N_("Point of view (Z coordinate) of the cube/cylinder "\
                            "effect, if enabled.")
 #endif
+#define PROVIDER_TEXT N_("OpenGL Provider")
+#define PROVIDER_LONGTEXT N_("Allows you to modify what OpenGL provider should be used")
 #define SPEED_TEXT N_( "OpenGL cube rotation speed" )
 #define SPEED_LONGTEXT N_( "Rotation speed of the OpenGL cube effect, if " \
         "enabled." )
@@ -202,6 +206,9 @@ vlc_module_begin();
                     RADIUS_LONGTEXT, VLC_TRUE );
 
 #endif
+    /* Allow opengl provider plugin selection */
+    add_string( "opengl-provider", "default", NULL, PROVIDER_TEXT, 
+                    PROVIDER_LONGTEXT, VLC_TRUE );
     set_callbacks( CreateVout, DestroyVout );
     add_string( "opengl-effect", "none", NULL, EFFECT_TEXT,
                  EFFECT_LONGTEXT, VLC_FALSE );
@@ -237,6 +244,7 @@ static int CreateVout( vlc_object_t *p_this )
 {
     vout_thread_t *p_vout = (vout_thread_t *)p_this;
     vout_sys_t *p_sys;
+    char * psz;
 
     /* Allocate structure */
     p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) );
@@ -282,13 +290,19 @@ static int CreateVout( vlc_object_t *p_this )
     p_sys->p_vout->b_scale = p_vout->b_scale;
     p_sys->p_vout->i_alignment = p_vout->i_alignment;
 
+    psz = config_GetPsz( p_vout, "opengl-provider" );
+
+    msg_Dbg( p_vout, "requesting \"%s\" opengl provider",
+                      psz ? psz : "default" );
+
     p_sys->p_vout->p_module =
-        module_Need( p_sys->p_vout, "opengl provider", NULL, 0 );
+        module_Need( p_sys->p_vout, "opengl provider", psz, 0 );
+    free( psz );
     if( p_sys->p_vout->p_module == NULL )
     {
         msg_Warn( p_vout, "No OpenGL provider found" );
         vlc_object_detach( p_sys->p_vout );
-        vlc_object_destroy( p_sys->p_vout );
+        vlc_object_release( p_sys->p_vout );
         return VLC_ENOOBJ;
     }
 
@@ -467,7 +481,7 @@ static int Init( vout_thread_t *p_vout )
         {
             p_sys->i_effect ++;
         }
-        if (pow(2,p_sys->i_effect) < INIFILE) 
+        if (pow(2,p_sys->i_effect) < INIFILE)
             p_sys->i_effect = pow(2,p_sys->i_effect);
         else if ( strcmp( val.psz_string, ppsz_effects[p_sys->i_effect]))
         {
@@ -495,7 +509,7 @@ static int Init( vout_thread_t *p_vout )
         glTranslatef( 0.0, 0.0, - 5.0 );
     }
 #ifdef OPENGL_MORE_EFFECT
-    else 
+    else
     {
         /* Set the perpective */
         glMatrixMode( GL_PROJECTION );
@@ -560,7 +574,7 @@ static void DestroyVout( vlc_object_t *p_this )
 
     module_Unneed( p_sys->p_vout, p_sys->p_vout->p_module );
     vlc_object_detach( p_sys->p_vout );
-    vlc_object_destroy( p_sys->p_vout );
+    vlc_object_release( p_sys->p_vout );
 
     free( p_sys );
 }
@@ -625,7 +639,7 @@ static int Manage( vout_thread_t *p_vout )
             case ASINR:
             case SINEXY:
             case SINER:
-#endif            
+#endif
                 glEnable( GL_CULL_FACE );
                 break;
 
@@ -648,7 +662,7 @@ static int Manage( vout_thread_t *p_vout )
             glTranslatef( 0.0, 0.0, - 5.0 );
         }
 #ifdef OPENGL_MORE_EFFECT
-        else 
+        else
         {
             glMatrixMode( GL_PROJECTION );
             glLoadIdentity();
@@ -656,14 +670,14 @@ static int Manage( vout_thread_t *p_vout )
             glMatrixMode( GL_MODELVIEW );
             glLoadIdentity();
             glTranslatef( 0.0, 0.0, -3.0 );
-    
             float f_pov_x, f_pov_y, f_pov_z;
             f_pov_x = var_CreateGetFloat( p_vout, "opengl-pov-x");
             f_pov_y = var_CreateGetFloat( p_vout, "opengl-pov-y");
             f_pov_z = var_CreateGetFloat( p_vout, "opengl-pov-z");
             gluLookAt(0, 0, 0, f_pov_x, f_pov_y, f_pov_z, 0, 1, 0);
         }
-#endif        
+#endif
     }
 
     if( p_sys->p_vout->pf_unlock )
@@ -672,12 +686,11 @@ static int Manage( vout_thread_t *p_vout )
     }
 #endif
 // to align in real time in OPENGL
-       if (p_sys->p_vout->i_alignment != p_vout->i_alignment)
-       {
-               p_vout->i_changes = VOUT_CROP_CHANGE;           //to force change
-       p_sys->p_vout->i_alignment = p_vout->i_alignment;       
-       }
-       
+    if (p_sys->p_vout->i_alignment != p_vout->i_alignment)
+    {
+        p_vout->i_changes = VOUT_CROP_CHANGE;        //to force change
+        p_sys->p_vout->i_alignment = p_vout->i_alignment;    
+    }
     return i_ret;
 }
 
@@ -686,6 +699,7 @@ static int Manage( vout_thread_t *p_vout )
  *****************************************************************************/
 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
 {
+    VLC_UNUSED(p_pic);
     vout_sys_t *p_sys = p_vout->p_sys;
 
     /* On Win32/GLX, we do this the usual way:
@@ -750,7 +764,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
 /*****************************************************************************
  *   Transform: Calculate the distorted grid coordinates
  *****************************************************************************/
-static void Transform(float p, int distortion, float width, float height,int i, int j, int i_visible_width, int i_visible_height, double *ix,double *iy)
+static void Transform( int distortion, float width, float height,int i, int j, int i_visible_width, int i_visible_height, double *ix, double *iy )
 {
     double x,y,xnew,ynew;
     double r,theta,rnew,thetanew;
@@ -765,7 +779,7 @@ static void Transform(float p, int distortion, float width, float height,int i,
     r = sqrt(x*x+y*y);
     theta = atan2(y,x);
 
-    switch (distortion) 
+    switch (distortion)
     {
 /* GRID2D TRANSFORMATION */
         case SINEXY:
@@ -816,23 +830,23 @@ static float Z_Compute(float p, int distortion, float x, float y)
     float f_z = 0.0;
     double d_p = p / 100.0;
 
-    switch (distortion) 
+    switch (distortion)
     {
 /* 3D MODEL */
         case CYLINDER:
-            if (d_p > 0) 
+            if (d_p > 0)
                 f_z = (1 - d_p * d_p) / (2 * d_p) - sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - x * x));
             else
                 f_z = (1 - d_p * d_p) / (2 * d_p) + d_p + sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - x * x));
             break;
         case TORUS:
-            if (d_p > 0) 
+            if (d_p > 0)
                 f_z =  (1 - d_p * d_p) / (d_p) - sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - x * x)) - sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - y * y));
             else
                 f_z =  (1 - d_p * d_p) / (d_p) + 2 * d_p + sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - x * x)) + sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - y * y));
             break;
         case SPHERE:
-            if (d_p > 0) 
+            if (d_p > 0)
                 f_z = (1 - d_p * d_p) / (2 * d_p) - sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - x * x - y * y));
             else
                 f_z = (1 - d_p * d_p) / (2 * d_p) + d_p + sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - x * x - y * y));
@@ -859,6 +873,7 @@ static float Z_Compute(float p, int distortion, float x, float y)
  *****************************************************************************/
 static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
 {
+    VLC_UNUSED(p_pic);
     vout_sys_t *p_sys = p_vout->p_sys;
     float f_width, f_height, f_x, f_y;
 
@@ -905,31 +920,31 @@ static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
     }
     else
 #ifdef OPENGL_MORE_EFFECT
-    if ((p_sys->i_effect > OPENGL_EFFECT_TRANSPARENT_CUBE) || 
+    if ((p_sys->i_effect > OPENGL_EFFECT_TRANSPARENT_CUBE) ||
         ((p_sys->i_effect == OPENGL_EFFECT_NONE)))
     {
        unsigned int i_i, i_j;
        unsigned int i_accuracy  = config_GetInt( p_vout, "opengl-accuracy");
-       unsigned int i_n = pow(2, i_accuracy);    
+       unsigned int i_n = pow(2, i_accuracy);
        unsigned int i_n_x = (p_vout->fmt_out.i_visible_width / (i_n * 2));
        unsigned int i_n_y = (p_vout->fmt_out.i_visible_height / i_n);
        double d_x, d_y;
        int i_distortion = p_sys->i_effect;
-       float f_p = p_sys->f_radius; 
-            
+       float f_p = p_sys->f_radius;
        glEnable( VLCGL_TARGET );
-       glBegin(GL_QUADS);                                   
-       for (i_i = 0; i_i < p_vout->fmt_out.i_visible_width; i_i += i_n_x) 
+       glBegin(GL_QUADS);
+       for (i_i = 0; i_i < p_vout->fmt_out.i_visible_width; i_i += i_n_x)
        {
           if ( i_i == i_n_x * i_n / 2) i_n_x += p_vout->fmt_out.i_visible_width % i_n;
           if ((i_i == (p_vout->fmt_out.i_visible_width / i_n) * i_n / 2 + i_n_x) &&
               (p_vout->fmt_out.i_visible_width / i_n != i_n_x))
-                i_n_x -= p_vout->fmt_out.i_visible_width % i_n; 
+                i_n_x -= p_vout->fmt_out.i_visible_width % i_n;
 
           int i_m;
           int i_index_max = 0;
-                
-          for (i_j = 0; i_j < p_vout->fmt_out.i_visible_height; i_j += i_n_y) 
+          for (i_j = 0; i_j < p_vout->fmt_out.i_visible_height; i_j += i_n_y)
           {
             if ( i_j == i_n_y * i_n / 2) i_n_y += p_vout->fmt_out.i_visible_height % i_n;
             if ((i_j == (p_vout->fmt_out.i_visible_height / i_n) * i_n / 2 + i_n_y) &&
@@ -941,14 +956,14 @@ static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
                 int i_k = ((i_m % 4) == 1) || ((i_m % 4) == 2);
                 int i_l = ((i_m % 4) == 2) || ((i_m % 4) == 3);
 
-                Transform(f_p, i_distortion, f_width, f_height, i_i + i_k * i_n_x, i_j + i_l * i_n_y, p_vout->fmt_out.i_visible_width, p_vout->fmt_out.i_visible_height, &d_x, &d_y);                                
+                Transform( i_distortion, f_width, f_height, i_i + i_k * i_n_x, i_j + i_l * i_n_y, p_vout->fmt_out.i_visible_width, p_vout->fmt_out.i_visible_height, &d_x, &d_y);
                 glTexCoord2f(f_x + d_x, f_y + d_y);
                 d_x =  - 1.0 + 2.0 * ((double)(i_k * i_n_x + i_i) / (double)p_vout->fmt_out.i_visible_width);
                 d_y =    1.0 - 2.0 * (((double)i_l * i_n_y + i_j) / (double)p_vout->fmt_out.i_visible_height);
-                glVertex3f((float)d_x, (float)d_y, Z_Compute(f_p, i_distortion, (float)d_x, (float)d_y));    
+                glVertex3f((float)d_x, (float)d_y, Z_Compute(f_p, i_distortion, (float)d_x, (float)d_y));
             }
           }
-       } 
+       }
        glEnd();
     }
     else
@@ -1093,5 +1108,6 @@ static int InitTextures( vout_thread_t *p_vout )
 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
                        vlc_value_t oldval, vlc_value_t newval, void *_p_vout )
 {
+    VLC_UNUSED(p_this); VLC_UNUSED(oldval);
     return var_Set( (vlc_object_t *)_p_vout, psz_var, newval );
 }