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>
29 #include "../../modules/demux/util/sub.h"
31 struct input_thread_sys_t
35 subtitle_demux_t **sub;
39 /****************************************************************************
41 ****************************************************************************/
43 * Control function for inputs.
44 * \param p_input input handle
45 * \param i_query query type
46 * \return VLC_SUCESS if ok
48 int input_Control( input_thread_t *p_input, int i_query, ... )
53 va_start( args, i_query );
54 i_result = input_vaControl( p_input, i_query, args );
60 int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
63 seekpoint_t *p_bkmk, ***ppp_bkmk;
66 vlc_value_t val, text;
68 vlc_mutex_lock( &p_input->stream.stream_lock );
71 case INPUT_ADD_BOOKMARK:
72 p_bkmk = (seekpoint_t *)va_arg( args, seekpoint_t * );
73 p_bkmk = vlc_seekpoint_Duplicate( p_bkmk );
74 if( !p_bkmk->psz_name )
76 asprintf( &p_bkmk->psz_name, _("Bookmark %i"),
77 p_input->i_bookmarks );
79 TAB_APPEND( p_input->i_bookmarks, p_input->pp_bookmarks, p_bkmk );
81 /* Reflect the changes on the object var */
82 var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
85 for( i = 0; i < p_input->i_bookmarks; i++ )
88 text.psz_string = p_input->pp_bookmarks[i]->psz_name;
89 var_Change( p_input, "bookmark", VLC_VAR_ADDCHOICE,
97 case INPUT_DEL_BOOKMARK:
98 i_bkmk = (int)va_arg( args, int );
99 if( i_bkmk < p_input->i_bookmarks )
102 p_bkmk = p_input->pp_bookmarks[i_bkmk];
103 TAB_REMOVE( p_input->i_bookmarks, p_input->pp_bookmarks,
105 vlc_seekpoint_Delete( p_bkmk );
107 /* Reflect the changes on the object var */
108 var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
109 for( i = 0; i < p_input->i_bookmarks; i++ )
112 text.psz_string = p_input->pp_bookmarks[i]->psz_name;
113 var_Change( p_input, "bookmark", VLC_VAR_ADDCHOICE,
118 else i_ret = VLC_EGENERIC;
121 case INPUT_GET_BOOKMARKS:
122 ppp_bkmk = (seekpoint_t ***)va_arg( args, seekpoint_t *** );
123 pi_bkmk = (int *)va_arg( args, int * );
124 if( p_input->i_bookmarks )
128 *pi_bkmk = p_input->i_bookmarks;
129 *ppp_bkmk = malloc( sizeof(seekpoint_t *) *
130 p_input->i_bookmarks );
131 for( i = 0; i < p_input->i_bookmarks; i++ )
134 vlc_seekpoint_Duplicate(p_input->pp_bookmarks[i]);
142 i_ret = VLC_EGENERIC;
146 case INPUT_CLEAR_BOOKMARKS:
147 if( p_input->i_bookmarks )
151 for( i = p_input->i_bookmarks - 1; i >= 0; i-- )
153 p_bkmk = p_input->pp_bookmarks[i];
154 TAB_REMOVE( p_input->i_bookmarks, p_input->pp_bookmarks,
156 vlc_seekpoint_Delete( p_bkmk );
158 var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
163 case INPUT_SET_BOOKMARK:
164 i_bkmk = (int)va_arg( args, int );
165 if( i_bkmk >= 0 && i_bkmk < p_input->i_bookmarks )
168 vlc_mutex_unlock( &p_input->stream.stream_lock );
169 if( p_input->pp_bookmarks[i_bkmk]->i_byte_offset ||
170 ( !p_input->pp_bookmarks[i_bkmk]->i_byte_offset &&
171 !p_input->pp_bookmarks[i_bkmk]->i_time_offset ) )
173 pos.f_float = p_input->pp_bookmarks[i_bkmk]->i_byte_offset/
174 (double)p_input->stream.p_selected_area->i_size;
175 i_ret = var_Set( p_input, "position", pos );
177 else if( p_input->pp_bookmarks[i_bkmk]->i_time_offset )
179 pos.i_time = p_input->pp_bookmarks[i_bkmk]->i_time_offset;
180 i_ret = var_Set( p_input, "time", pos );
182 vlc_mutex_lock( &p_input->stream.stream_lock );
186 i_ret = VLC_EGENERIC;
190 case INPUT_GET_SUBDELAY:
191 pi = (int*)va_arg( args, int *);
192 /* We work on the first subtitle */
193 if( p_input->p_sys != NULL )
195 if( p_input->p_sys->i_sub > 0 )
197 i_ret = var_Get( (vlc_object_t *)p_input->p_sys->sub[0],
203 msg_Dbg( p_input,"no subtitle track");
204 i_ret = VLC_EGENERIC;
209 i_ret = VLC_EGENERIC;
213 case INPUT_SET_SUBDELAY:
214 i = (int)va_arg( args, int );
215 /* We work on the first subtitle */
218 if( p_input->p_sys->i_sub > 0 )
221 i_ret = var_Set( (vlc_object_t *)p_input->p_sys->sub[0],
226 msg_Dbg( p_input,"no subtitle track");
227 i_ret = VLC_EGENERIC;
232 i_ret = VLC_EGENERIC;
237 msg_Err( p_input, "unknown query in input_vaControl" );
238 i_ret = VLC_EGENERIC;
241 vlc_mutex_unlock( &p_input->stream.stream_lock );