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 p_bkmk = (seekpoint_t *)va_arg( args, seekpoint_t * );
89 if( p_input->i_bookmarks )
92 for( i = 0; i < p_input->i_bookmarks; i++ )
94 if( ( p_bkmk->i_byte_offset &&
95 p_input->pp_bookmarks[i]->i_byte_offset ==
96 p_bkmk->i_byte_offset ) ||
97 ( p_bkmk->i_time_offset &&
98 p_input->pp_bookmarks[i]->i_time_offset ==
99 p_bkmk->i_time_offset ) ||
100 ( !p_bkmk->i_byte_offset && !p_bkmk->i_time_offset &&
101 p_input->pp_bookmarks[i]->i_byte_offset ==
102 p_bkmk->i_byte_offset ) )
104 p_bkmk = p_input->pp_bookmarks[i];
108 if( i < p_input->i_bookmarks )
110 TAB_REMOVE( p_input->i_bookmarks, p_input->pp_bookmarks,
112 vlc_seekpoint_Delete( p_bkmk );
114 /* Reflect the changes on the object var */
115 var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES,
117 for( i = 0; i < p_input->i_bookmarks; i++ )
120 text.psz_string = p_input->pp_bookmarks[i]->psz_name;
121 var_Change( p_input, "bookmark", VLC_VAR_ADDCHOICE,
129 case INPUT_GET_BOOKMARKS:
130 ppp_bkmk = (seekpoint_t ***)va_arg( args, seekpoint_t *** );
131 pi_bkmk = (int *)va_arg( args, int * );
132 if( p_input->i_bookmarks )
136 *pi_bkmk = p_input->i_bookmarks;
137 *ppp_bkmk = malloc( sizeof(seekpoint_t *) *
138 p_input->i_bookmarks );
139 for( i = 0; i < p_input->i_bookmarks; i++ )
142 vlc_seekpoint_Duplicate(p_input->pp_bookmarks[i]);
150 i_ret = VLC_EGENERIC;
154 case INPUT_CLEAR_BOOKMARKS:
155 if( p_input->i_bookmarks )
159 for( i = p_input->i_bookmarks - 1; i >= 0; i-- )
161 p_bkmk = p_input->pp_bookmarks[i];
162 TAB_REMOVE( p_input->i_bookmarks, p_input->pp_bookmarks,
164 vlc_seekpoint_Delete( p_bkmk );
170 case INPUT_SET_BOOKMARK:
171 i_bkmk = (int)va_arg( args, int );
172 if( i_bkmk >= 0 && i_bkmk < p_input->i_bookmarks )
175 vlc_mutex_unlock( &p_input->stream.stream_lock );
176 if( p_input->pp_bookmarks[i_bkmk]->i_byte_offset ||
177 ( !p_input->pp_bookmarks[i_bkmk]->i_byte_offset &&
178 !p_input->pp_bookmarks[i_bkmk]->i_time_offset ) )
180 pos.f_float = p_input->pp_bookmarks[i_bkmk]->i_byte_offset/
181 (double)p_input->stream.p_selected_area->i_size;
182 i_ret = var_Set( p_input, "position", pos );
184 else if( p_input->pp_bookmarks[i_bkmk]->i_time_offset )
186 pos.i_time = p_input->pp_bookmarks[i_bkmk]->i_time_offset;
187 i_ret = var_Set( p_input, "time", pos );
189 vlc_mutex_lock( &p_input->stream.stream_lock );
193 i_ret = VLC_EGENERIC;
198 msg_Err( p_input, "unknown query in input_vaControl" );
199 i_ret = VLC_EGENERIC;
202 vlc_mutex_unlock( &p_input->stream.stream_lock );