]> git.sesse.net Git - vlc/blobdiff - modules/misc/osd/osd_menu.c
Restore LibVLC/VERSION at the end of the HTTP user agent
[vlc] / modules / misc / osd / osd_menu.c
index bbd1719c4e0575d42d5624fed9c7b2c3a3959d81..57cd24ecab51e5e1a61827c33f42367e216461cd 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * parser.c : OSD import module
  *****************************************************************************
- * Copyright (C) 2007 M2X
- * $Id$
+ * Copyright (C) 2007-2008 M2X
+ * $Id$
  *
  * Authors: Jean-Paul Saman
  *
  * Preamble
  *****************************************************************************/
 
-#include <vlc/vlc.h>
-#include <vlc_vout.h>
-#include <vlc_config.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
-#include <vlc_keys.h>
+#include <vlc_common.h>
 #include <vlc_image.h>
 #include <vlc_osd.h>
-#include <vlc_charset.h>
 
 #include "osd_menu.h"
 
 #undef OSD_MENU_DEBUG
 
+const char * const ppsz_button_states[] = { "unselect", "select", "pressed" };
+
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -50,19 +51,11 @@ osd_menu_t *osd_MenuNew( osd_menu_t *p_menu, const char *psz_path,
 {
     if( !p_menu ) return NULL;
 
-    p_menu->p_state = (osd_menu_state_t *) malloc( sizeof( osd_menu_state_t ) );
+    p_menu->p_state = calloc( 1, sizeof( osd_menu_state_t ) );
     if( !p_menu->p_state )
-    {
-        msg_Err( p_menu, "Memory allocation for OSD Menu state failed" );
         return NULL;
-    }
-
-    memset(p_menu->p_state, 0, sizeof(osd_menu_state_t));
-    if( psz_path != NULL )
-        p_menu->psz_path = strdup( psz_path );
-    else
-        p_menu->psz_path = NULL;
 
+    p_menu->psz_path = psz_path ? strdup( psz_path ) : NULL;
     p_menu->i_x = i_x;
     p_menu->i_y = i_y;
     p_menu->i_style = OSD_MENU_STYLE_SIMPLE;
@@ -78,8 +71,8 @@ void osd_MenuFree( osd_menu_t *p_menu )
     msg_Dbg( p_menu, "freeing menu" );
     osd_ButtonFree( p_menu, p_menu->p_button );
 
-    if( p_menu->psz_path ) free( p_menu->psz_path );
-    if( p_menu->p_state ) free( p_menu->p_state );
+    free( p_menu->psz_path );
+    free( p_menu->p_state );
 
     p_menu->p_button = NULL;
     p_menu->p_last_button = NULL;
@@ -93,11 +86,10 @@ void osd_MenuFree( osd_menu_t *p_menu )
 osd_button_t *osd_ButtonNew( const char *psz_action, int i_x, int i_y )
 {
     osd_button_t *p_button = NULL;
-    p_button = (osd_button_t*) malloc( sizeof(osd_button_t) );
+    p_button = calloc( 1, sizeof(osd_button_t) );
     if( !p_button )
         return NULL;
 
-    memset( p_button, 0, sizeof(osd_button_t) );
     p_button->psz_action = strdup(psz_action);
     p_button->psz_action_down = NULL;
     p_button->p_feedback = NULL;
@@ -116,6 +108,8 @@ void osd_ButtonFree( osd_menu_t *p_menu, osd_button_t *p_button )
     osd_button_t *p_next = NULL;
     osd_button_t *p_prev = NULL;
 
+    if( !p_current ) return;
+
     /* First walk to the end. */
     while( p_current->p_next )
     {
@@ -131,18 +125,15 @@ void osd_ButtonFree( osd_menu_t *p_menu, osd_button_t *p_button )
         p_current = p_prev;
         if( p_current->p_next )
         {
-            if( p_current->p_next->psz_name )
-                free( p_current->p_next->psz_name );
-            if( p_current->p_next->psz_action )
-                free( p_current->p_next->psz_action );
-            if( p_current->p_next->psz_action_down )
-                free( p_current->p_next->psz_action_down );
-            if( p_current->p_feedback && p_current->p_feedback->p_data_orig )
-                free( p_current->p_feedback->p_data_orig );
+            free( p_current->p_next->psz_name );
+            free( p_current->p_next->psz_action );
+            free( p_current->p_next->psz_action_down );
             if( p_current->p_feedback )
+            {
+                free( p_current->p_feedback->p_data_orig );
                 free( p_current->p_feedback );
-
-            p_current->p_feedback = NULL;
+                p_current->p_feedback = NULL;
+            }
 
             /* Free all states first */
             if( p_current->p_next->p_states )
@@ -154,16 +145,14 @@ void osd_ButtonFree( osd_menu_t *p_menu, osd_button_t *p_button )
 
         if( p_current->p_up )
         {
-            if( p_current->p_up->psz_name )
-                free( p_current->p_up->psz_name );
-            if( p_current->p_up->psz_action )
-                free( p_current->p_up->psz_action );
-            if( p_current->p_up->psz_action_down )
-                free( p_current->p_up->psz_action_down );
-            if( p_current->p_feedback && p_current->p_feedback->p_data_orig )
-                free( p_current->p_feedback->p_data_orig );
+            free( p_current->p_up->psz_name );
+            free( p_current->p_up->psz_action );
+            free( p_current->p_up->psz_action_down );
             if( p_current->p_feedback )
+            {
+                free( p_current->p_feedback->p_data_orig );
                 free( p_current->p_feedback );
+            }
 
             p_current->p_feedback = NULL;
 
@@ -179,20 +168,20 @@ void osd_ButtonFree( osd_menu_t *p_menu, osd_button_t *p_button )
     {
         msg_Dbg( p_menu, "+ freeing button %s [%p]",
                  p_button->psz_action, p_button );
-        if( p_button->psz_name ) free( p_button->psz_name );
-        if( p_button->psz_action ) free( p_button->psz_action );
-        if( p_button->psz_action_down ) free( p_button->psz_action_down );
-        if( p_current->p_feedback && p_current->p_feedback->p_data_orig )
-            free( p_current->p_feedback->p_data_orig );
+        free( p_button->psz_name );
+        free( p_button->psz_action );
+        free( p_button->psz_action_down );
         if( p_current->p_feedback )
+        {
+            free( p_current->p_feedback->p_data_orig );
             free( p_current->p_feedback );
-        p_current->p_feedback = NULL;
+            p_current->p_feedback = NULL;
+        }
 
         if( p_button->p_states )
             osd_StatesFree( p_menu, p_button->p_states );
 
         free( p_button );
-        p_button = NULL;
     }
 }
 
@@ -205,22 +194,23 @@ osd_state_t *osd_StateNew( osd_menu_t *p_menu, const char *psz_file,
     osd_state_t *p_state = NULL;
     video_format_t fmt_in, fmt_out;
 
-    p_state = (osd_state_t*) malloc( sizeof(osd_state_t) );
+    p_state = calloc( 1, sizeof(osd_state_t) );
     if( !p_state )
         return NULL;
 
-    memset( p_state, 0, sizeof(osd_state_t) );
     memset( &fmt_in, 0, sizeof(video_format_t) );
     memset( &fmt_out, 0, sizeof(video_format_t) );
 
-    fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
+    fmt_out.i_chroma = VLC_CODEC_YUVA;
     if( p_menu->p_image )
     {
         p_state->p_pic = image_ReadUrl( p_menu->p_image, psz_file,
                                         &fmt_in, &fmt_out );
-
-        p_state->i_width  = p_state->p_pic->p[Y_PLANE].i_visible_pitch;
-        p_state->i_height = p_state->p_pic->p[Y_PLANE].i_visible_lines;
+        if( p_state->p_pic )
+        {
+            p_state->i_width  = p_state->p_pic->p[Y_PLANE].i_visible_pitch;
+            p_state->i_height = p_state->p_pic->p[Y_PLANE].i_visible_lines;
+        }
     }
 
     if( psz_state )
@@ -248,6 +238,8 @@ void osd_StatesFree( osd_menu_t *p_menu, osd_state_t *p_states )
     osd_state_t *p_next = NULL;
     osd_state_t *p_prev = NULL;
 
+    if( !p_state ) return;
+
     while( p_state->p_next )
     {
         p_next = p_state->p_next;
@@ -264,12 +256,10 @@ void osd_StatesFree( osd_menu_t *p_menu, osd_state_t *p_states )
         {
             if( p_state->p_next->p_pic )
             {
-                if( p_state->p_next->p_pic->p_data_orig )
-                    free( p_state->p_next->p_pic->p_data_orig );
+                free( p_state->p_next->p_pic->p_data_orig );
                 free( p_state->p_next->p_pic );
             }
-            if( p_state->p_next->psz_state )
-                free( p_state->p_next->psz_state );
+            free( p_state->p_next->psz_state );
             free( p_state->p_next );
             p_state->p_next = NULL;
         }
@@ -281,12 +271,11 @@ void osd_StatesFree( osd_menu_t *p_menu, osd_state_t *p_states )
                  p_state->psz_state, p_states );
         if( p_states->p_pic )
         {
-            if( p_states->p_pic->p_data_orig )
-                free( p_states->p_pic->p_data_orig );
+            free( p_states->p_pic->p_data_orig );
             free( p_states->p_pic );
         }
-        if( p_state->psz_state ) free( p_state->psz_state );
+        free( p_state->psz_state );
         free( p_states );
-        p_states = NULL;
     }
 }
+