]> git.sesse.net Git - vlc/blobdiff - src/input/control.c
Fix a memory leak.
[vlc] / src / input / control.c
index 4b3cec6e839464e703df728e62e1bdbf5258c770..061d8ccf88a1998543cee2f85ec77c223d75949e 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * control.c
  *****************************************************************************
- * Copyright (C) 1999-2004 VideoLAN
+ * Copyright (C) 1999-2004 the VideoLAN team
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+
+#include <stdio.h>
 #include <stdlib.h>
-#include <vlc/vlc.h>
-#include <vlc/input.h>
 
 #include "input_internal.h"
-#include "vlc_playlist.h"
 
 
 static void UpdateBookmarksOption( input_thread_t * );
-static void NotifyPlaylist( input_thread_t * );
 
 /****************************************************************************
  * input_Control
@@ -129,7 +132,7 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
 
         case INPUT_ADD_INFO:
         {
-            /* FIXME : Impossible to use vlc_input_item_AddInfo because of
+            /* FIXME : Impossible to use input_ItemAddInfo because of
              * the ... problem ? */
             char *psz_cat = (char *)va_arg( args, char * );
             char *psz_name = (char *)va_arg( args, char * );
@@ -139,30 +142,30 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             info_t *p_info;
             int i;
 
-            vlc_mutex_lock( &p_input->input.p_item->lock );
-            for( i = 0; i < p_input->input.p_item->i_categories; i++ )
+            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            for( i = 0; i < p_input->p->input.p_item->i_categories; i++ )
             {
-                if( !strcmp( p_input->input.p_item->pp_categories[i]->psz_name,
+                if( !strcmp( p_input->p->input.p_item->pp_categories[i]->psz_name,
                              psz_cat ) ) break;
             }
 
-            if( i == p_input->input.p_item->i_categories )
+            if( i == p_input->p->input.p_item->i_categories )
             {
                 p_cat = malloc( sizeof( info_category_t ) );
                 if( !p_cat )
                 {
-                    vlc_mutex_lock( &p_input->input.p_item->lock );
+                    vlc_mutex_unlock( &p_input->p->input.p_item->lock );
                     return VLC_EGENERIC;
                 }
                 p_cat->psz_name = strdup( psz_cat );
                 p_cat->i_infos = 0;
                 p_cat->pp_infos = NULL;
-                INSERT_ELEM( p_input->input.p_item->pp_categories,
-                             p_input->input.p_item->i_categories,
-                             p_input->input.p_item->i_categories, p_cat );
+                INSERT_ELEM( p_input->p->input.p_item->pp_categories,
+                             p_input->p->input.p_item->i_categories,
+                             p_input->p->input.p_item->i_categories, p_cat );
             }
 
-            p_cat = p_input->input.p_item->pp_categories[i];
+            p_cat = p_input->p->input.p_item->pp_categories[i];
 
             for( i = 0; i < p_cat->i_infos; i++ )
             {
@@ -179,7 +182,7 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
                 p_info = malloc( sizeof( info_t ) );
                 if( !p_info )
                 {
-                    vlc_mutex_lock( &p_input->input.p_item->lock );
+                    vlc_mutex_unlock( &p_input->p->input.p_item->lock );
                     return VLC_EGENERIC;
                 }
 
@@ -189,24 +192,101 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             }
 
             p_info = p_cat->pp_infos[i];
-            vasprintf( &p_info->psz_value, psz_format, args );
+            if( vasprintf( &p_info->psz_value, psz_format, args ) == -1 )
+                p_info->psz_value = NULL;
 
-            vlc_mutex_unlock( &p_input->input.p_item->lock );
+            vlc_mutex_unlock( &p_input->p->input.p_item->lock );
 
-            NotifyPlaylist( p_input );
+            if( !p_input->b_preparsing )
+            {
+                vlc_event_t event;
+                event.type = vlc_InputItemInfoChanged;
+                vlc_event_send( &p_input->p->input.p_item->event_manager, &event );
+            }
         }
         return VLC_SUCCESS;
 
+        case INPUT_DEL_INFO:
+        {
+            char *psz_cat = (char *)va_arg( args, char * );
+            char *psz_name = (char *)va_arg( args, char * );
+
+            info_category_t *p_cat = NULL;
+            int i_cat;
+            int i;
+
+            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            for( i_cat = 0; i_cat < p_input->p->input.p_item->i_categories; i_cat++ )
+            {
+                if( !strcmp( p_input->p->input.p_item->pp_categories[i_cat]->psz_name,
+                             psz_cat ) )
+                {
+                    p_cat = p_input->p->input.p_item->pp_categories[i_cat];
+                    break;
+                }
+            }
+            if( p_cat == NULL )
+            {
+                vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+                return VLC_EGENERIC;
+            }
+
+            if( psz_name )
+            {
+                /* Remove a specific info */
+                for( i = 0; i < p_cat->i_infos; i++ )
+                {
+                    if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
+                    {
+                        free( p_cat->pp_infos[i]->psz_name );
+                        if( p_cat->pp_infos[i]->psz_value )
+                            free( p_cat->pp_infos[i]->psz_value );
+                        free( p_cat->pp_infos[i] );
+                        REMOVE_ELEM( p_cat->pp_infos, p_cat->i_infos, i );
+                        break;
+                    }
+                }
+                if( i >= p_cat->i_infos )
+                {
+                    vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+                    return VLC_EGENERIC;
+                }
+            }
+            else
+            {
+                /* Remove the complete categorie */
+                for( i = 0; i < p_cat->i_infos; i++ )
+                {
+                    free( p_cat->pp_infos[i]->psz_name );
+                    if( p_cat->pp_infos[i]->psz_value )
+                        free( p_cat->pp_infos[i]->psz_value );
+                    free( p_cat->pp_infos[i] );
+                }
+                if( p_cat->pp_infos )
+                    free( p_cat->pp_infos );
+                REMOVE_ELEM( p_input->p->input.p_item->pp_categories, p_input->p->input.p_item->i_categories, i_cat );
+            }
+            vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+
+            if( !p_input->b_preparsing )
+            {
+                vlc_event_t event;
+                event.type = vlc_InputItemInfoChanged;
+                vlc_event_send( &p_input->p->input.p_item->event_manager, &event );
+            }
+            return VLC_SUCCESS;
+        }
+
+
         case INPUT_GET_INFO:
         {
             char *psz_cat = (char *)va_arg( args, char * );
             char *psz_name = (char *)va_arg( args, char * );
             char **ppsz_value = (char **)va_arg( args, char ** );
             int i_ret = VLC_EGENERIC;
-            int i;
             *ppsz_value = NULL;
 
-            *ppsz_value = vlc_input_item_GetInfo( p_input->input.p_item,
+            *ppsz_value = input_ItemGetInfo( p_input->p->input.p_item,
                                                   psz_cat, psz_name );
             return i_ret;
         }
@@ -217,14 +297,19 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
 
             if( !psz_name ) return VLC_EGENERIC;
 
-            vlc_mutex_lock( &p_input->input.p_item->lock );
-            if( p_input->input.p_item->psz_name )
-                free( p_input->input.p_item->psz_name );
-            p_input->input.p_item->psz_name = strdup( psz_name );
-            vlc_mutex_unlock( &p_input->input.p_item->lock );
-
-            NotifyPlaylist( p_input );
+            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            if( p_input->p->input.p_item->psz_name )
+                free( p_input->p->input.p_item->psz_name );
+            p_input->p->input.p_item->psz_name = strdup( psz_name );
+            vlc_mutex_unlock( &p_input->p->input.p_item->lock );
 
+            if( !p_input->b_preparsing )
+            {
+                vlc_event_t event;
+                event.type = vlc_InputItemNameChanged;
+                event.u.input_item_name_changed.new_name = psz_name;
+                vlc_event_send( &p_input->p->input.p_item->event_manager, &event );
+            }
             return VLC_SUCCESS;
         }
 
@@ -232,14 +317,15 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             p_bkmk = (seekpoint_t *)va_arg( args, seekpoint_t * );
             p_bkmk = vlc_seekpoint_Duplicate( p_bkmk );
 
-            vlc_mutex_lock( &p_input->input.p_item->lock );
+            vlc_mutex_lock( &p_input->p->input.p_item->lock );
             if( !p_bkmk->psz_name )
             {
-                 asprintf( &p_bkmk->psz_name, _("Bookmark %i"),
-                           p_input->i_bookmark );
+                 if( asprintf( &p_bkmk->psz_name, _("Bookmark %i"),
+                               p_input->p->i_bookmark ) == -1 )
+                     p_bkmk->psz_name = NULL;
             }
 
-            TAB_APPEND( p_input->i_bookmark, p_input->bookmark, p_bkmk );
+            TAB_APPEND( p_input->p->i_bookmark, p_input->p->bookmark, p_bkmk );
 
             /* Reflect the changes on the object var */
             var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
@@ -247,15 +333,15 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
                 vlc_value_t val, text;
                 int i;
 
-                for( i = 0; i < p_input->i_bookmark; i++ )
+                for( i = 0; i < p_input->p->i_bookmark; i++ )
                 {
                     val.i_int = i;
-                    text.psz_string = p_input->bookmark[i]->psz_name;
+                    text.psz_string = p_input->p->bookmark[i]->psz_name;
                     var_Change( p_input, "bookmark", VLC_VAR_ADDCHOICE,
                                 &val, &text );
                 }
             }
-            vlc_mutex_unlock( &p_input->input.p_item->lock );
+            vlc_mutex_unlock( &p_input->p->input.p_item->lock );
 
             UpdateBookmarksOption( p_input );
 
@@ -265,25 +351,25 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             p_bkmk = (seekpoint_t *)va_arg( args, seekpoint_t * );
             i_bkmk = (int)va_arg( args, int );
 
-            vlc_mutex_lock( &p_input->input.p_item->lock );
-            if( i_bkmk < p_input->i_bookmark )
+            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            if( i_bkmk < p_input->p->i_bookmark )
             {
                 vlc_value_t val, text;
                 int i;
 
-                p_input->bookmark[i_bkmk] = p_bkmk;
+                p_input->p->bookmark[i_bkmk] = p_bkmk;
 
                 /* Reflect the changes on the object var */
                 var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
-                for( i = 0; i < p_input->i_bookmark; i++ )
+                for( i = 0; i < p_input->p->i_bookmark; i++ )
                 {
                     val.i_int = i;
-                    text.psz_string = p_input->bookmark[i]->psz_name;
+                    text.psz_string = p_input->p->bookmark[i]->psz_name;
                     var_Change( p_input, "bookmark", VLC_VAR_ADDCHOICE,
                                 &val, &text );
                 }
             }
-            vlc_mutex_unlock( &p_input->input.p_item->lock );
+            vlc_mutex_unlock( &p_input->p->input.p_item->lock );
 
             UpdateBookmarksOption( p_input );
 
@@ -292,33 +378,33 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
         case INPUT_DEL_BOOKMARK:
             i_bkmk = (int)va_arg( args, int );
 
-            vlc_mutex_lock( &p_input->input.p_item->lock );
-            if( i_bkmk < p_input->i_bookmark )
+            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            if( i_bkmk < p_input->p->i_bookmark )
             {
                 vlc_value_t val, text;
                 int i;
 
-                p_bkmk = p_input->bookmark[i_bkmk];
-                TAB_REMOVE( p_input->i_bookmark, p_input->bookmark,
+                p_bkmk = p_input->p->bookmark[i_bkmk];
+                TAB_REMOVE( p_input->p->i_bookmark, p_input->p->bookmark,
                             p_bkmk );
                 vlc_seekpoint_Delete( p_bkmk );
 
                 /* Reflect the changes on the object var */
                 var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
-                for( i = 0; i < p_input->i_bookmark; i++ )
+                for( i = 0; i < p_input->p->i_bookmark; i++ )
                 {
                     val.i_int = i;
-                    text.psz_string = p_input->bookmark[i]->psz_name;
+                    text.psz_string = p_input->p->bookmark[i]->psz_name;
                     var_Change( p_input, "bookmark", VLC_VAR_ADDCHOICE,
                                 &val, &text );
                 }
-                vlc_mutex_unlock( &p_input->input.p_item->lock );
+                vlc_mutex_unlock( &p_input->p->input.p_item->lock );
 
                 UpdateBookmarksOption( p_input );
 
                 return VLC_SUCCESS;
             }
-            vlc_mutex_unlock( &p_input->input.p_item->lock );
+            vlc_mutex_unlock( &p_input->p->input.p_item->lock );
 
             return VLC_EGENERIC;
 
@@ -326,21 +412,21 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             ppp_bkmk = (seekpoint_t ***)va_arg( args, seekpoint_t *** );
             pi_bkmk = (int *)va_arg( args, int * );
 
-            vlc_mutex_lock( &p_input->input.p_item->lock );
-            if( p_input->i_bookmark )
+            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            if( p_input->p->i_bookmark )
             {
                 int i;
 
-                *pi_bkmk = p_input->i_bookmark;
+                *pi_bkmk = p_input->p->i_bookmark;
                 *ppp_bkmk = malloc( sizeof(seekpoint_t *) *
-                                    p_input->i_bookmark );
-                for( i = 0; i < p_input->i_bookmark; i++ )
+                                    p_input->p->i_bookmark );
+                for( i = 0; i < p_input->p->i_bookmark; i++ )
                 {
                     (*ppp_bkmk)[i] =
-                        vlc_seekpoint_Duplicate(p_input->bookmark[i]);
+                        vlc_seekpoint_Duplicate(p_input->p->bookmark[i]);
                 }
 
-                vlc_mutex_unlock( &p_input->input.p_item->lock );
+                vlc_mutex_unlock( &p_input->p->input.p_item->lock );
                 return VLC_SUCCESS;
             }
             else
@@ -348,28 +434,28 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
                 *ppp_bkmk = NULL;
                 *pi_bkmk = 0;
 
-                vlc_mutex_unlock( &p_input->input.p_item->lock );
+                vlc_mutex_unlock( &p_input->p->input.p_item->lock );
                 return VLC_EGENERIC;
             }
             break;
 
         case INPUT_CLEAR_BOOKMARKS:
 
-            vlc_mutex_lock( &p_input->input.p_item->lock );
-            if( p_input->i_bookmark )
+            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            if( p_input->p->i_bookmark )
             {
                 int i;
 
-                for( i = p_input->i_bookmark - 1; i >= 0; i-- )
+                for( i = p_input->p->i_bookmark - 1; i >= 0; i-- )
                 {
-                    p_bkmk = p_input->bookmark[i];
-                    TAB_REMOVE( p_input->i_bookmark, p_input->bookmark,
+                    p_bkmk = p_input->p->bookmark[i];
+                    TAB_REMOVE( p_input->p->i_bookmark, p_input->p->bookmark,
                                 p_bkmk );
                     vlc_seekpoint_Delete( p_bkmk );
                 }
                 var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
             }
-            vlc_mutex_unlock( &p_input->input.p_item->lock );
+            vlc_mutex_unlock( &p_input->p->input.p_item->lock );
 
             UpdateBookmarksOption( p_input );
 
@@ -378,22 +464,28 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
         case INPUT_SET_BOOKMARK:
             i_bkmk = (int)va_arg( args, int );
 
-            vlc_mutex_lock( &p_input->input.p_item->lock );
-            if( i_bkmk >= 0 && i_bkmk < p_input->i_bookmark )
+            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            if( i_bkmk >= 0 && i_bkmk < p_input->p->i_bookmark )
             {
                 vlc_value_t pos;
                 int i_ret;
 
-                if( p_input->bookmark[i_bkmk]->i_time_offset )
+                if( p_input->p->bookmark[i_bkmk]->i_time_offset != -1 )
                 {
-                    pos.i_time = p_input->bookmark[i_bkmk]->i_time_offset;
+                    pos.i_time = p_input->p->bookmark[i_bkmk]->i_time_offset;
                     i_ret = var_Set( p_input, "time", pos );
                 }
-                else if( p_input->bookmark[i_bkmk]->i_byte_offset )
+                else if( p_input->p->bookmark[i_bkmk]->i_byte_offset != -1 )
                 {
-                    pos.f_float = !p_input->input.p_stream ? 0 :
-                        p_input->bookmark[i_bkmk]->i_byte_offset /
-                        stream_Size( p_input->input.p_stream );
+                    // don't crash on bookmarks in live streams
+                    if( stream_Size( p_input->p->input.p_stream ) == 0 )
+                    {
+                        vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+                        return VLC_EGENERIC;
+                    }
+                    pos.f_float = !p_input->p->input.p_stream ? 0 :
+                        p_input->p->bookmark[i_bkmk]->i_byte_offset /
+                        stream_Size( p_input->p->input.p_stream );
                     i_ret = var_Set( p_input, "position", pos );
                 }
                 else
@@ -402,12 +494,12 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
                     i_ret = var_Set( p_input, "position", pos );
                 }
 
-                vlc_mutex_unlock( &p_input->input.p_item->lock );
+                vlc_mutex_unlock( &p_input->p->input.p_item->lock );
                 return i_ret;
             }
             else
             {
-                vlc_mutex_unlock( &p_input->input.p_item->lock );
+                vlc_mutex_unlock( &p_input->p->input.p_item->lock );
                 return VLC_EGENERIC;
             }
 
@@ -415,51 +507,44 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
 
         case INPUT_ADD_OPTION:
         {
-            char *psz_option = (char *)va_arg( args, char * );
-            char *psz_value = (char *)va_arg( args, char * );
+            const char *psz_option = va_arg( args, const char * );
+            const char *psz_value = va_arg( args, const char * );
+            char *str;
             int i;
 
-            vlc_mutex_lock( &p_input->input.p_item->lock );
-            /* Check if option already exists */
-            for( i = 0; i < p_input->input.p_item->i_options; i++ )
-            {
-                if( !strncmp( p_input->input.p_item->ppsz_options[i],
-                              psz_option, strlen( psz_option ) ) &&
-                    p_input->input.p_item->ppsz_options[i][strlen(psz_option)]
-                      == '=' )
-                {
-                    free( p_input->input.p_item->ppsz_options[i] );
-                    break;
-                }
-            }
-            if( i == p_input->input.p_item->i_options )
-            {
-                p_input->input.p_item->i_options++;
-                p_input->input.p_item->ppsz_options =
-                    realloc( p_input->input.p_item->ppsz_options,
-                             p_input->input.p_item->i_options *
-                             sizeof(char **) );
-            }
-
-            asprintf( &p_input->input.p_item->ppsz_options[i],
-                      "%s=%s", psz_option, psz_value ) ;
-            vlc_mutex_unlock( &p_input->input.p_item->lock );
+            if( asprintf( &str, "%s=%s", psz_option, psz_value ) == -1 )
+                return VLC_ENOMEM;
 
-            return VLC_SUCCESS;
+            i = input_ItemAddOpt( p_input->p->input.p_item, str,
+                                  VLC_INPUT_OPTION_UNIQUE );
+            free( str );
+            return i;
         }
 
         case INPUT_GET_BYTE_POSITION:
             pi_64 = (int64_t*)va_arg( args, int64_t * );
-            *pi_64 = !p_input->input.p_stream ? 0 :
-                stream_Tell( p_input->input.p_stream );
+            *pi_64 = !p_input->p->input.p_stream ? 0 :
+                stream_Tell( p_input->p->input.p_stream );
             return VLC_SUCCESS;
 
         case INPUT_SET_BYTE_SIZE:
             pi_64 = (int64_t*)va_arg( args, int64_t * );
-            *pi_64 = !p_input->input.p_stream ? 0 :
-                stream_Size( p_input->input.p_stream );
+            *pi_64 = !p_input->p->input.p_stream ? 0 :
+                stream_Size( p_input->p->input.p_stream );
             return VLC_SUCCESS;
 
+        case INPUT_GET_VIDEO_FPS:
+        {
+            int i;
+            pf = (double*)va_arg( args, double * );
+            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            *pf = p_input->p->input.f_fps;
+            for( i = 0; i < p_input->p->i_slave && *pf <= 0.001; i++ )
+                *pf = p_input->p->slave[i]->f_fps;
+            vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+            return VLC_SUCCESS;
+        }
+
         case INPUT_ADD_SLAVE:
             psz = (char*)va_arg( args, char * );
             if( psz && *psz )
@@ -469,56 +554,90 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             }
             return VLC_SUCCESS;
 
+        case INPUT_GET_ATTACHMENTS: /* arg1=input_attachment_t***, arg2=int*  res=can fail */
+        {
+            input_attachment_t ***ppp_attachment = (input_attachment_t***)va_arg( args, input_attachment_t *** );
+            int *pi_attachment = (int*)va_arg( args, int * );
+            int i;
+
+            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            if( p_input->p->i_attachment <= 0 )
+            {
+                vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+                *ppp_attachment = NULL;
+                *pi_attachment = 0;
+                return VLC_EGENERIC;
+            }
+            *pi_attachment = p_input->p->i_attachment;
+            *ppp_attachment = malloc( sizeof(input_attachment_t**) * p_input->p->i_attachment );
+            for( i = 0; i < p_input->p->i_attachment; i++ )
+                (*ppp_attachment)[i] = vlc_input_attachment_Duplicate( p_input->p->attachment[i] );
+
+            vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+            return VLC_SUCCESS;
+        }
+
+        case INPUT_GET_ATTACHMENT:  /* arg1=input_attachment_t**, arg2=char*  res=can fail */
+        {
+            input_attachment_t **pp_attachment = (input_attachment_t**)va_arg( args, input_attachment_t ** );
+            const char *psz_name = (const char*)va_arg( args, const char * );
+            int i;
+
+            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            for( i = 0; i < p_input->p->i_attachment; i++ )
+            {
+                if( !strcmp( p_input->p->attachment[i]->psz_name, psz_name ) )
+                {
+                    *pp_attachment = vlc_input_attachment_Duplicate( p_input->p->attachment[i] );
+                    vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+                    return VLC_SUCCESS;
+                }
+            }
+            *pp_attachment = NULL;
+            vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+            return VLC_EGENERIC;
+        }
+
+
         default:
             msg_Err( p_input, "unknown query in input_vaControl" );
             return VLC_EGENERIC;
     }
 }
 
-static void NotifyPlaylist( input_thread_t *p_input )
-{
-    playlist_t *p_playlist =
-        (playlist_t *)vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
-                                       FIND_PARENT );
-    if( p_playlist )
-    {
-        var_SetInteger( p_playlist, "item-change", p_playlist->i_index );
-        vlc_object_release( p_playlist );
-    }
-}
-
 static void UpdateBookmarksOption( input_thread_t *p_input )
 {
     int i, i_len = 0;
     char *psz_value = NULL, *psz_next = NULL;
 
-    vlc_mutex_lock( &p_input->input.p_item->lock );
-    for( i = 0; i < p_input->i_bookmark; i++ )
+    vlc_mutex_lock( &p_input->p->input.p_item->lock );
+    if( p_input->p->i_bookmark > 0 )
     {
-        asprintf( &psz_value, "{name=%s,bytes="I64Fd",time="I64Fd"}",
-                  p_input->bookmark[i]->psz_name,
-                  p_input->bookmark[i]->i_byte_offset,
-                  p_input->bookmark[i]->i_time_offset/1000000 );
-        i_len += strlen( psz_value );
-        free( psz_value );
-    }
-    for( i = 0; i < p_input->i_bookmark; i++ )
-    {
-        if( !i ) psz_value = psz_next = malloc( i_len + p_input->i_bookmark );
-
-        sprintf( psz_next, "{name=%s,bytes="I64Fd",time="I64Fd"}",
-                 p_input->bookmark[i]->psz_name,
-                 p_input->bookmark[i]->i_byte_offset,
-                 p_input->bookmark[i]->i_time_offset/1000000 );
+        for( i = 0; i < p_input->p->i_bookmark; i++ )
+        {
+            i_len += snprintf( NULL, 0, "{name=%s,bytes=%"PRId64",time=%"PRId64"}",
+                               p_input->p->bookmark[i]->psz_name,
+                               p_input->p->bookmark[i]->i_byte_offset,
+                               p_input->p->bookmark[i]->i_time_offset/1000000 );
+        }
+        psz_value = psz_next = malloc( i_len + p_input->p->i_bookmark );
 
-        psz_next += strlen( psz_next );
-        if( i < p_input->i_bookmark - 1)
+        for( i = 0; i < p_input->p->i_bookmark; i++ )
         {
-            *psz_next = ','; psz_next++;
+            sprintf( psz_next, "{name=%s,bytes=%"PRId64",time=%"PRId64"}",
+                     p_input->p->bookmark[i]->psz_name,
+                     p_input->p->bookmark[i]->i_byte_offset,
+                     p_input->p->bookmark[i]->i_time_offset/1000000 );
+
+            psz_next += strlen( psz_next );
+            if( i < p_input->p->i_bookmark - 1)
+                *psz_next = ','; psz_next++;
         }
     }
-    vlc_mutex_unlock( &p_input->input.p_item->lock );
+    vlc_mutex_unlock( &p_input->p->input.p_item->lock );
 
     input_Control( p_input, INPUT_ADD_OPTION, "bookmarks",
                    psz_value ? psz_value : "" );
+    free( psz_value );
 }
+