]> git.sesse.net Git - vlc/blob - src/input/control.c
a1e8d003b4e13bd11a31b734eeec557519590dd7
[vlc] / src / input / control.c
1 /*****************************************************************************
2  * control.c
3  *****************************************************************************
4  * Copyright (C) 1999-2004 VideoLAN
5  * $Id: stream.c 7041 2004-03-11 16:48:27Z gbazin $
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #include <stdlib.h>
25 #include <vlc/vlc.h>
26 #include <vlc/input.h>
27
28 #include "ninput.h"
29
30 /****************************************************************************
31  * input_Control
32  ****************************************************************************/
33 /**
34  * Control function for inputs.
35  * \param p_input input handle
36  * \param i_query query type
37  * \return VLC_SUCESS if ok
38  */
39 int input_Control( input_thread_t *p_input, int i_query, ...  )
40 {
41     va_list args;
42     int     i_result;
43
44     va_start( args, i_query );
45     i_result = input_vaControl( p_input, i_query, args );
46     va_end( args );
47
48     return i_result;
49 }
50
51 int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
52 {
53     int     i_ret;
54     seekpoint_t *p_bkmk, ***ppp_bkmk;
55     int i_bkmk, *pi_bkmk;
56     vlc_value_t val, text;
57
58     vlc_mutex_lock( &p_input->stream.stream_lock );
59     switch( i_query )
60     {
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 )
65             {
66                  asprintf( &p_bkmk->psz_name, _("Bookmark %i"),
67                            p_input->i_bookmarks );
68             }
69             TAB_APPEND( p_input->i_bookmarks, p_input->pp_bookmarks, p_bkmk );
70
71             /* Reflect the changes on the object var */
72             var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
73             {
74                 int i;
75                 for( i = 0; i < p_input->i_bookmarks; i++ )
76                 {
77                     val.i_int = i;
78                     text.psz_string = p_input->pp_bookmarks[i]->psz_name;
79                     var_Change( p_input, "bookmark", VLC_VAR_ADDCHOICE,
80                                 &val, &text );
81                 }
82             }
83
84             i_ret = VLC_SUCCESS;
85             break;
86
87         case INPUT_DEL_BOOKMARK:
88             i_bkmk = (int)va_arg( args, int );
89             if( i_bkmk < p_input->i_bookmarks )
90             {
91                 int i;
92                 p_bkmk = p_input->pp_bookmarks[i_bkmk];
93                 TAB_REMOVE( p_input->i_bookmarks, p_input->pp_bookmarks,
94                             p_bkmk );
95                 vlc_seekpoint_Delete( p_bkmk );
96
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++ )
100                 {
101                     val.i_int = i;
102                     text.psz_string = p_input->pp_bookmarks[i]->psz_name;
103                     var_Change( p_input, "bookmark", VLC_VAR_ADDCHOICE,
104                                 &val, &text );
105                 }
106                 i_ret = VLC_SUCCESS;
107             }
108             else i_ret = VLC_EGENERIC;
109             break;
110
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 )
115             {
116                 int i;
117
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++ )
122                 {
123                     (*ppp_bkmk)[i] =
124                         vlc_seekpoint_Duplicate(p_input->pp_bookmarks[i]);
125                 }
126                 i_ret = VLC_SUCCESS;
127             }
128             else
129             {
130                 *ppp_bkmk = NULL;
131                 *pi_bkmk = 0;
132                 i_ret = VLC_EGENERIC;
133             }
134             break;
135
136         case INPUT_CLEAR_BOOKMARKS:
137             if( p_input->i_bookmarks )
138             {
139                 int i;
140
141                 for( i = p_input->i_bookmarks - 1; i >= 0; i-- )
142                 {
143                     p_bkmk = p_input->pp_bookmarks[i];
144                     TAB_REMOVE( p_input->i_bookmarks, p_input->pp_bookmarks,
145                                 p_bkmk );
146                     vlc_seekpoint_Delete( p_bkmk );
147                 }
148                 var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
149             }
150             i_ret = VLC_SUCCESS;
151             break;
152
153         case INPUT_SET_BOOKMARK:
154             i_bkmk = (int)va_arg( args, int );
155             if( i_bkmk >= 0 && i_bkmk < p_input->i_bookmarks )
156             {
157                 vlc_value_t pos;
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 ) )
162                 {
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 );
166                 }
167                 else if( p_input->pp_bookmarks[i_bkmk]->i_time_offset )
168                 {
169                     pos.i_time = p_input->pp_bookmarks[i_bkmk]->i_time_offset;
170                     i_ret = var_Set( p_input, "time", pos );
171                 }
172                 vlc_mutex_lock( &p_input->stream.stream_lock );
173             }
174             else
175             {
176                 i_ret = VLC_EGENERIC;
177             }
178             break;
179
180         default:
181             msg_Err( p_input, "unknown query in input_vaControl" );
182             i_ret = VLC_EGENERIC;
183             break;
184     }
185     vlc_mutex_unlock( &p_input->stream.stream_lock );
186
187     return i_ret;
188 }