1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 1999-2004 VideoLAN
5 * $Id: stream.c 7041 2004-03-11 16:48:27Z gbazin $
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
26 #include <vlc/input.h>
30 /****************************************************************************
32 ****************************************************************************/
34 * Control function for inputs.
35 * \param p_input input handle
36 * \param i_query query type
37 * \return VLC_SUCESS if ok
39 int input_Control( input_thread_t *p_input, int i_query, ... )
44 va_start( args, i_query );
45 i_result = input_vaControl( p_input, i_query, args );
51 int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
54 seekpoint_t *p_bkmk, ***ppp_bkmk;
56 vlc_value_t val, text;
58 vlc_mutex_lock( &p_input->stream.stream_lock );
61 case INPUT_ADD_BOOKMARK:
62 p_bkmk = (seekpoint_t *)va_arg( args, seekpoint_t * );
63 p_bkmk = vlc_seekpoint_Duplicate( p_bkmk );
64 if( !p_bkmk->psz_name )
66 asprintf( &p_bkmk->psz_name, _("Bookmark %i"),
67 p_input->i_bookmarks );
69 TAB_APPEND( p_input->i_bookmarks, p_input->pp_bookmarks, p_bkmk );
71 /* Reflect the changes on the object var */
72 var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
75 for( i = 0; i < p_input->i_bookmarks; i++ )
78 text.psz_string = p_input->pp_bookmarks[i]->psz_name;
79 var_Change( p_input, "bookmark", VLC_VAR_ADDCHOICE,
87 case INPUT_DEL_BOOKMARK:
88 i_bkmk = (int)va_arg( args, int );
89 if( i_bkmk < p_input->i_bookmarks )
92 p_bkmk = p_input->pp_bookmarks[i_bkmk];
93 TAB_REMOVE( p_input->i_bookmarks, p_input->pp_bookmarks,
95 vlc_seekpoint_Delete( p_bkmk );
97 /* Reflect the changes on the object var */
98 var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
99 for( i = 0; i < p_input->i_bookmarks; i++ )
102 text.psz_string = p_input->pp_bookmarks[i]->psz_name;
103 var_Change( p_input, "bookmark", VLC_VAR_ADDCHOICE,
108 else i_ret = VLC_EGENERIC;
111 case INPUT_GET_BOOKMARKS:
112 ppp_bkmk = (seekpoint_t ***)va_arg( args, seekpoint_t *** );
113 pi_bkmk = (int *)va_arg( args, int * );
114 if( p_input->i_bookmarks )
118 *pi_bkmk = p_input->i_bookmarks;
119 *ppp_bkmk = malloc( sizeof(seekpoint_t *) *
120 p_input->i_bookmarks );
121 for( i = 0; i < p_input->i_bookmarks; i++ )
124 vlc_seekpoint_Duplicate(p_input->pp_bookmarks[i]);
132 i_ret = VLC_EGENERIC;
136 case INPUT_CLEAR_BOOKMARKS:
137 if( p_input->i_bookmarks )
141 for( i = p_input->i_bookmarks - 1; i >= 0; i-- )
143 p_bkmk = p_input->pp_bookmarks[i];
144 TAB_REMOVE( p_input->i_bookmarks, p_input->pp_bookmarks,
146 vlc_seekpoint_Delete( p_bkmk );
148 var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
153 case INPUT_SET_BOOKMARK:
154 i_bkmk = (int)va_arg( args, int );
155 if( i_bkmk >= 0 && i_bkmk < p_input->i_bookmarks )
158 vlc_mutex_unlock( &p_input->stream.stream_lock );
159 if( p_input->pp_bookmarks[i_bkmk]->i_byte_offset ||
160 ( !p_input->pp_bookmarks[i_bkmk]->i_byte_offset &&
161 !p_input->pp_bookmarks[i_bkmk]->i_time_offset ) )
163 pos.f_float = p_input->pp_bookmarks[i_bkmk]->i_byte_offset/
164 (double)p_input->stream.p_selected_area->i_size;
165 i_ret = var_Set( p_input, "position", pos );
167 else if( p_input->pp_bookmarks[i_bkmk]->i_time_offset )
169 pos.i_time = p_input->pp_bookmarks[i_bkmk]->i_time_offset;
170 i_ret = var_Set( p_input, "time", pos );
172 vlc_mutex_lock( &p_input->stream.stream_lock );
176 i_ret = VLC_EGENERIC;
181 msg_Err( p_input, "unknown query in input_vaControl" );
182 i_ret = VLC_EGENERIC;
185 vlc_mutex_unlock( &p_input->stream.stream_lock );