]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/atmo/atmo.cpp
String removal
[vlc] / modules / video_filter / atmo / atmo.cpp
index e780e9579de117bcca4462e9d24af2823f7aa5d0..27e0f867bd495f51d4529aacbcd70069dffc9c96 100644 (file)
@@ -1,25 +1,25 @@
 /*****************************************************************************
-* atmo.cpp : "Atmo Light" video filter
-*****************************************************************************
-* Copyright (C) 2000-2006 the VideoLAN team
-* $Id$
-*
-* Authors: AndrĂ© Weber (WeberAndre@gmx.de)
-*
-* 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
-* (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.
-*
-* 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.
-*****************************************************************************/
+ * atmo.cpp : "Atmo Light" video filter
+ *****************************************************************************
+ * Copyright (C) 2000-2006 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: AndrĂ© Weber (WeberAndre@gmx.de)
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * 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
 # include "config.h"
@@ -43,6 +43,8 @@
 
 #include <vlc_playlist.h>
 #include <vlc_filter.h>
+#include <vlc_atomic.h>
+#include <vlc_charset.h>
 
 #include "filter_picture.h"
 
@@ -118,7 +120,7 @@ void SaveBitmap(filter_sys_t *p_sys, uint8_t *p_pixels, char *psz_filename);
 strings for settings menus and hints
 */
 #define MODULE_DESCRIPTION N_ ( \
- "This module allows to control an so called AtmoLight device "\
+ "This module allows controlling an so called AtmoLight device "\
  "connected to your computer.\n"\
  "AtmoLight is the homegrown version of what Philips calls AmbiLight.\n"\
  "If you need further information feel free to visit us at\n\n"\
@@ -228,7 +230,7 @@ static const char *const ppsz_device_type_descriptions[] = {
 #define ZONE_BOTTOM_TEXT       N_("Number of zones on bottom")
 #define ZONE_BOTTOM_LONGTEXT   N_("Number of zones on the bottom of the screen")
 #define ZONE_LR_TEXT           N_("Zones on left / right side")
-#define ZONE_LR_LONGTEXT       N_("left and right side having allways the " \
+#define ZONE_LR_LONGTEXT       N_("left and right side having always the " \
                                   "same number of zones")
 #define ZONE_SUMMARY_TEXT      N_("Calculate a average zone")
 #define ZONE_SUMMARY_LONGTEXT  N_("it contains the average of all pixels " \
@@ -255,12 +257,12 @@ static const char *const ppsz_device_type_descriptions[] = {
                                 "On Windows usually something like COM1 or " \
                                 "COM2. On Linux /dev/ttyS01 f.e.")
 
-#define EDGE_TEXT            N_("Edge Weightning")
+#define EDGE_TEXT            N_("Edge weightning")
 #define EDGE_LONGTEXT        N_("Increasing this value will result in color "\
                                 "more depending on the border of the frame.")
 #define BRIGHTNESS_TEXT     N_("Brightness")
 #define BRIGHTNESS_LONGTEXT N_("Overall brightness of your LED stripes")
-#define DARKNESS_TEXT       N_("Darkness Limit")
+#define DARKNESS_TEXT       N_("Darkness limit")
 #define DARKNESS_LONGTEXT   N_("Pixels with a saturation lower than this will "\
                                "be ignored. Should be greater than one for "\
                                "letterboxed videos.")
@@ -275,7 +277,7 @@ static const char *const ppsz_device_type_descriptions[] = {
 #define MEANTHRESHOLD_TEXT     N_("Filter threshold")
 #define MEANTHRESHOLD_LONGTEXT N_("How much a color has to be changed for an "\
                                   "immediate color change.")
-#define MEANPERCENTNEW_TEXT     N_("Filter Smoothness (in %)")
+#define MEANPERCENTNEW_TEXT     N_("Filter smoothness (%)")
 #define MEANPERCENTNEW_LONGTEXT N_("Filter Smoothness")
 
 #define FILTERMODE_TEXT        N_("Output Color filter mode")
@@ -699,8 +701,10 @@ static const char *const ppsz_filter_options[] = {
 */
 typedef struct
 {
-    VLC_COMMON_MEMBERS
-        filter_t *p_filter;
+    filter_t *p_filter;
+    vlc_thread_t thread;
+    vlc_atomic_t abort;
+
     /* tell the thread which color should be the target of fading */
     uint8_t ui_red;
     uint8_t ui_green;
@@ -710,7 +714,7 @@ typedef struct
 
 } fadethread_t;
 
-static void *FadeToColorThread(vlc_object_t *);
+static void *FadeToColorThread(void *);
 
 
 /*****************************************************************************
@@ -732,6 +736,8 @@ struct filter_sys_t
     bool b_show_dots;
     int32_t i_device_type;
 
+    bool b_swap_uv;
+
     int32_t i_atmo_width;
     int32_t i_atmo_height;
     /* used to disable fadeout if less than 50 frames are processed
@@ -769,7 +775,7 @@ struct filter_sys_t
     /* storage for temporal settings "volatile" */
     CAtmoDynData *p_atmo_dyndata;
     /* initialized for buildin driver with AtmoCreateTransferBuffers */
-    BITMAPINFOHEADER mini_image_format;
+    VLC_BITMAPINFOHEADER mini_image_format;
     /* is only use buildin driver! */
     uint8_t *p_atmo_transfer_buffer;
     /* end buildin driver */
@@ -986,9 +992,9 @@ static void AtmoCreateTransferBuffers(filter_t *p_filter,
         p_sys->p_atmo_transfer_buffer = (uint8_t *)malloc(bytePerPixel *
                                                           width *  height);
 
-        memset(&p_sys->mini_image_format,0,sizeof(BITMAPINFOHEADER));
+        memset(&p_sys->mini_image_format,0,sizeof(VLC_BITMAPINFOHEADER));
 
-        p_sys->mini_image_format.biSize = sizeof(BITMAPINFOHEADER);
+        p_sys->mini_image_format.biSize = sizeof(VLC_BITMAPINFOHEADER);
         p_sys->mini_image_format.biWidth = width;
         p_sys->mini_image_format.biHeight = height;
         p_sys->mini_image_format.biBitCount = bytePerPixel*8;
@@ -1105,9 +1111,7 @@ static void Atmo_Shutdown(filter_t *p_filter)
         p_sys->b_pause_live = true;
 
 
-        p_sys->p_fadethread = (fadethread_t *)vlc_object_create( p_filter,
-                                                    sizeof(fadethread_t) );
-
+        p_sys->p_fadethread = (fadethread_t *)calloc( 1, sizeof(fadethread_t) );
         p_sys->p_fadethread->p_filter = p_filter;
         p_sys->p_fadethread->ui_red   = p_sys->ui_endcolor_red;
         p_sys->p_fadethread->ui_green = p_sys->ui_endcolor_green;
@@ -1116,13 +1120,15 @@ static void Atmo_Shutdown(filter_t *p_filter)
           p_sys->p_fadethread->i_steps  = 1;
         else
           p_sys->p_fadethread->i_steps  = p_sys->i_endfadesteps;
+        vlc_atomic_set(&p_sys->p_fadethread->abort, 0);
 
-        if( vlc_thread_create( p_sys->p_fadethread,
-            FadeToColorThread,
-            VLC_THREAD_PRIORITY_LOW ) )
+        if( vlc_clone( &p_sys->p_fadethread->thread,
+                       FadeToColorThread,
+                       p_sys->p_fadethread,
+                       VLC_THREAD_PRIORITY_LOW ) )
         {
             msg_Err( p_filter, "cannot create FadeToColorThread" );
-            vlc_object_release( p_sys->p_fadethread );
+            free( p_sys->p_fadethread );
             p_sys->p_fadethread = NULL;
             vlc_mutex_unlock( &p_sys->filter_lock );
 
@@ -1131,9 +1137,9 @@ static void Atmo_Shutdown(filter_t *p_filter)
             vlc_mutex_unlock( &p_sys->filter_lock );
 
             /* wait for the thread... */
-            vlc_thread_join(p_sys->p_fadethread);
+            vlc_join(p_sys->p_fadethread->thread, NULL);
 
-            vlc_object_release(p_sys->p_fadethread);
+            free(p_sys->p_fadethread);
 
             p_sys->p_fadethread = NULL;
         }
@@ -1558,7 +1564,6 @@ if this fails fallback to the buildin software
 */
 static void Atmo_SetupParameters(filter_t *p_filter)
 {
-    char *psz_path;
     filter_sys_t *p_sys =  p_filter->p_sys;
 
 
@@ -1594,7 +1599,7 @@ static void Atmo_SetupParameters(filter_t *p_filter)
         if(p_sys->h_AtmoCtrl == NULL)
         {
             /*
-              be clever if the location of atmowina.exe is set
+              be clever if the location of atmowin.exe is set
               try to load the dll from the same folder :-)
             */
             char *psz_path = var_CreateGetStringCommand( p_filter,
@@ -1613,7 +1618,9 @@ static void Atmo_SetupParameters(filter_t *p_filter)
                     if( psz_dllname )
                     {
                         msg_Dbg( p_filter, "Try Loading '%s'", psz_dllname );
-                        p_sys->h_AtmoCtrl = LoadLibraryA( psz_dllname );
+                        TCHAR* ptsz_dllname = ToT(psz_dllname);
+                        p_sys->h_AtmoCtrl = LoadLibrary( ptsz_dllname );
+                        free(ptsz_dllname);
                     }
                     free( psz_dllname );
                 }
@@ -1734,8 +1741,12 @@ static void Atmo_SetupParameters(filter_t *p_filter)
     switch( p_filter->fmt_in.video.i_chroma )
     {
     case VLC_CODEC_I420:
+        p_sys->pf_extract_mini_image = ExtractMiniImage_YUV;
+        p_sys->b_swap_uv = false;
+        break;
     case VLC_CODEC_YV12:
         p_sys->pf_extract_mini_image = ExtractMiniImage_YUV;
+        p_sys->b_swap_uv = true;
         break;
     default:
         msg_Warn( p_filter, "InitFilter-unsupported chroma: %4.4s",
@@ -1839,18 +1850,19 @@ static void Atmo_SetupParameters(filter_t *p_filter)
           COM Server for AtmoLight not running ?
           if the exe path is configured try to start the "userspace" driver
         */
-        psz_path = var_CreateGetStringCommand( p_filter,
+        char *psz_path = var_CreateGetStringCommand( p_filter,
                                                CFG_PREFIX "atmowinexe" );
+        LPTSTR ptsz_path = ToT(psz_path);
         if(psz_path != NULL)
         {
             STARTUPINFO startupinfo;
             PROCESS_INFORMATION pinfo;
             memset(&startupinfo, 0, sizeof(STARTUPINFO));
             startupinfo.cb = sizeof(STARTUPINFO);
-            if(CreateProcess(psz_path, NULL, NULL, NULL,
+            if(CreateProcess(ptsz_path, NULL, NULL, NULL,
                 FALSE, 0, NULL, NULL, &startupinfo, &pinfo) == TRUE)
             {
-                msg_Dbg(p_filter,"launched AtmoWin from %s",psz_path);
+                msg_Dbg(p_filter,"launched AtmoWin from %s", psz_path);
                 WaitForInputIdle(pinfo.hProcess, 5000);
                 /*
                   retry to initialize the library COM ... functionality
@@ -1861,6 +1873,7 @@ static void Atmo_SetupParameters(filter_t *p_filter)
                 msg_Err(p_filter,"failed to launch AtmoWin from %s", psz_path);
             }
             free(psz_path);
+            free(ptsz_path);
         }
     }
 #endif
@@ -2054,7 +2067,7 @@ static void ExtractMiniImage_YUV(filter_sys_t *p_sys,
 
     /*  these two ugly loops extract the small image - goes it faster? how?
     the loops are so designed that there is a small border around the extracted
-    image so we wont get column and row - zero from the frame, and not the most
+    image so we won't get column and row - zero from the frame, and not the most
     right and bottom pixels --- which may be clipped on computers useing TV out
     - through overscan!
 
@@ -2103,6 +2116,16 @@ static void ExtractMiniImage_YUV(filter_sys_t *p_sys,
         p_src_v = p_inpic->p[V_PLANE].p_pixels +
             p_inpic->p[V_PLANE].i_pitch * i_v_row;
 
+        if(p_sys->b_swap_uv)
+        {
+          /*
+           swap u and v plane for YV12 images
+          */
+          uint8_t *p_temp_plane = p_src_u;
+          p_src_u = p_src_v;
+          p_src_v = p_temp_plane;
+        }
+
         for(i_col = 1; i_col < i_col_count; i_col++)
         {
             i_pixel_col = (i_col * p_sys->i_crop_width) / i_col_count +
@@ -2174,12 +2197,12 @@ static void ExtractMiniImage_YUV(filter_sys_t *p_sys,
 void SaveBitmap(filter_sys_t *p_sys, uint8_t *p_pixels, char *psz_filename)
 {
     /* for debug out only used*/
-    BITMAPINFO bmp_info;
+    VLC_BITMAPINFO bmp_info;
     BITMAPFILEHEADER  bmp_fileheader;
     FILE *fp_bitmap;
 
-    memset(&bmp_info, 0, sizeof(BITMAPINFO));
-    bmp_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+    memset(&bmp_info, 0, sizeof(VLC_BITMAPINFO));
+    bmp_info.bmiHeader.biSize = sizeof(VLC_BITMAPINFOHEADER);
     bmp_info.bmiHeader.biSizeImage   = p_sys->i_atmo_height *
                                        p_sys->i_atmo_width * 4;
     bmp_info.bmiHeader.biCompression = BI_RGB;
@@ -2191,17 +2214,17 @@ void SaveBitmap(filter_sys_t *p_sys, uint8_t *p_pixels, char *psz_filename)
     bmp_fileheader.bfReserved1 = 0;
     bmp_fileheader.bfReserved2 = 0;
     bmp_fileheader.bfSize = sizeof(BITMAPFILEHEADER) +
-                            sizeof(BITMAPINFOHEADER) +
+                            sizeof(VLC_BITMAPINFOHEADER) +
                             bmp_info.bmiHeader.biSizeImage;
     bmp_fileheader.bfType = VLC_TWOCC('B','M');
     bmp_fileheader.bfOffBits = sizeof(BITMAPFILEHEADER) +
-                               sizeof(BITMAPINFOHEADER);
+                               sizeof(VLC_BITMAPINFOHEADER);
 
     fp_bitmap = fopen(psz_filename,"wb");
     if( fp_bitmap != NULL)
     {
         fwrite(&bmp_fileheader, sizeof(BITMAPFILEHEADER), 1, fp_bitmap);
-        fwrite(&bmp_info.bmiHeader, sizeof(BITMAPINFOHEADER), 1, fp_bitmap);
+        fwrite(&bmp_info.bmiHeader, sizeof(VLC_BITMAPINFOHEADER), 1, fp_bitmap);
         fwrite(p_pixels, bmp_info.bmiHeader.biSizeImage, 1, fp_bitmap);
         fclose(fp_bitmap);
     }
@@ -2290,7 +2313,7 @@ static picture_t * Filter( filter_t *p_filter, picture_t *p_pic )
 {
     filter_sys_t *p_sys = p_filter->p_sys;
     if( !p_pic ) return NULL;
-    
+
     picture_t *p_outpic = filter_NewPicture( p_filter );
     if( !p_outpic )
     {
@@ -2298,7 +2321,7 @@ static picture_t * Filter( filter_t *p_filter, picture_t *p_pic )
         return NULL;
     }
     picture_CopyPixels( p_outpic, p_pic );
-    
+
     vlc_mutex_lock( &p_sys->filter_lock );
 
     if(p_sys->b_enabled && p_sys->pf_extract_mini_image &&
@@ -2324,7 +2347,7 @@ static picture_t * Filter( filter_t *p_filter, picture_t *p_pic )
 * to a target color defined in p_fadethread struct
 * use for: Fade to Pause Color,  and Fade to End Color
 *****************************************************************************/
-static void *FadeToColorThread(vlc_object_t *obj)
+static void *FadeToColorThread(void *obj)
 {
     fadethread_t *p_fadethread = (fadethread_t *)obj;
     filter_sys_t *p_sys = (filter_sys_t *)p_fadethread->p_filter->p_sys;
@@ -2367,7 +2390,7 @@ static void *FadeToColorThread(vlc_object_t *obj)
             /* send the same pixel data again... to unlock the buffer! */
             AtmoSendPixelData( p_fadethread->p_filter );
 
-            while( (vlc_object_alive (p_fadethread)) &&
+            while( (!vlc_atomic_get (&p_fadethread->abort)) &&
                 (i_steps_done < p_fadethread->i_steps))
             {
                 p_transfer = AtmoLockTransferBuffer( p_fadethread->p_filter );
@@ -2380,7 +2403,7 @@ static void *FadeToColorThread(vlc_object_t *obj)
                 thread improvements wellcome!
                 */
                 for(i_index = 0;
-                    (i_index < i_size) && (vlc_object_alive (p_fadethread));
+                    (i_index < i_size) && (!vlc_atomic_get (&p_fadethread->abort));
                     i_index+=4)
                 {
                     i_src_blue  = p_source[i_index+0];
@@ -2436,11 +2459,10 @@ static void CheckAndStopFadeThread(filter_t *p_filter)
     {
         msg_Dbg(p_filter, "kill still running fadeing thread...");
 
-        p_sys->p_fadethread->b_die = true;
+        vlc_atomic_set(&p_sys->p_fadethread->abort, 1);
 
-        vlc_thread_join(p_sys->p_fadethread);
-
-        vlc_object_release(p_sys->p_fadethread);
+        vlc_join(p_sys->p_fadethread->thread, NULL);
+        free(p_sys->p_fadethread);
         p_sys->p_fadethread = NULL;
     }
     vlc_mutex_unlock( &p_sys->filter_lock );
@@ -2450,7 +2472,7 @@ static void CheckAndStopFadeThread(filter_t *p_filter)
 * StateCallback: Callback for the inputs variable "State" to get notified
 * about Pause and Continue Playback events.
 *****************************************************************************/
-static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
+static int StateCallback( vlc_object_t *, char const *,
                          vlc_value_t oldval, vlc_value_t newval,
                          void *p_data )
 {
@@ -2479,22 +2501,21 @@ static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
             */
             if(p_sys->p_fadethread == NULL)
             {
-                p_sys->p_fadethread = (fadethread_t *)vlc_object_create(
-                     p_filter,
-                     sizeof(fadethread_t) );
-
+                p_sys->p_fadethread = (fadethread_t *)calloc( 1, sizeof(fadethread_t) );
                 p_sys->p_fadethread->p_filter = p_filter;
                 p_sys->p_fadethread->ui_red   = p_sys->ui_pausecolor_red;
                 p_sys->p_fadethread->ui_green = p_sys->ui_pausecolor_green;
                 p_sys->p_fadethread->ui_blue  = p_sys->ui_pausecolor_blue;
                 p_sys->p_fadethread->i_steps  = p_sys->i_fadesteps;
+                vlc_atomic_set(&p_sys->p_fadethread->abort, 0);
 
-                if( vlc_thread_create( p_sys->p_fadethread,
-                    FadeToColorThread,
-                    VLC_THREAD_PRIORITY_LOW ) )
+                if( vlc_clone( &p_sys->p_fadethread->thread,
+                               FadeToColorThread,
+                               p_sys->p_fadethread,
+                               VLC_THREAD_PRIORITY_LOW ) )
                 {
                     msg_Err( p_filter, "cannot create FadeToColorThread" );
-                    vlc_object_release( p_sys->p_fadethread );
+                    free( p_sys->p_fadethread );
                     p_sys->p_fadethread = NULL;
                 }
             }
@@ -2551,7 +2572,7 @@ static void DelStateVariableCallback( filter_t *p_filter )
 * StateCallback: Callback for the inputs variable "State" to get notified
 * about Pause and Continue Playback events.
 *****************************************************************************/
-static int AtmoSettingsCallback( vlc_object_t *p_this, char const *psz_var,
+static int AtmoSettingsCallback( vlc_object_t *, char const *psz_var,
                                  vlc_value_t oldval, vlc_value_t newval,
                                  void *p_data )
 {