1 /*****************************************************************************
2 * libvlc_audio.c: New libvlc audio control API
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Filippo Carone <filippo@carone.org>
8 * Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "libvlc_internal.h"
26 #include <vlc/libvlc.h>
28 #include <vlc_input.h>
32 * Remember to release the returned input_thread_t since it is locked at
33 * the end of this function.
35 static input_thread_t *GetInput( libvlc_input_t *p_input,
36 libvlc_exception_t *p_exception )
38 input_thread_t *p_input_thread = NULL;
42 libvlc_exception_raise( p_exception, "Input is NULL" );
46 p_input_thread = (input_thread_t*)vlc_object_get(
47 p_input->p_instance->p_libvlc_int,
48 p_input->i_input_id );
51 libvlc_exception_raise( p_exception, "Input does not exist" );
55 return p_input_thread;
59 * Remember to release the returned aout_instance_t since it is locked at
60 * the end of this function.
62 static aout_instance_t *GetAOut( libvlc_instance_t *p_instance,
63 libvlc_exception_t *p_exception )
65 aout_instance_t * p_aout = NULL;
67 p_aout = vlc_object_find( p_instance->p_libvlc_int, VLC_OBJECT_AOUT, FIND_CHILD );
70 libvlc_exception_raise( p_exception, "No active audio output" );
78 /*****************************************************************************
79 * libvlc_audio_get_mute : Get the volume state, true if muted
80 *****************************************************************************/
81 void libvlc_audio_toggle_mute( libvlc_instance_t *p_instance,
82 libvlc_exception_t *p_e )
84 aout_VolumeMute( p_instance->p_libvlc_int, NULL );
87 vlc_bool_t libvlc_audio_get_mute( libvlc_instance_t *p_instance,
88 libvlc_exception_t *p_e )
91 * If the volume level is 0, then the channel is muted
93 audio_volume_t i_volume;
95 i_volume = libvlc_audio_get_volume(p_instance, p_e);
101 void libvlc_audio_set_mute( libvlc_instance_t *p_instance, vlc_bool_t mute,
102 libvlc_exception_t *p_e )
104 if ( mute ^ libvlc_audio_get_mute( p_instance, p_e ) )
106 aout_VolumeMute( p_instance->p_libvlc_int, NULL );
110 /*****************************************************************************
111 * libvlc_audio_get_volume : Get the current volume (range 0-200 %)
112 *****************************************************************************/
113 int libvlc_audio_get_volume( libvlc_instance_t *p_instance,
114 libvlc_exception_t *p_e )
116 audio_volume_t i_volume;
118 aout_VolumeGet( p_instance->p_libvlc_int, &i_volume );
120 return (i_volume*200+AOUT_VOLUME_MAX/2)/AOUT_VOLUME_MAX;
124 /*****************************************************************************
125 * libvlc_audio_set_volume : Set the current volume
126 *****************************************************************************/
127 void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume,
128 libvlc_exception_t *p_e )
130 if( i_volume >= 0 && i_volume <= 200 )
132 i_volume = (i_volume * AOUT_VOLUME_MAX + 100) / 200;
134 aout_VolumeSet( p_instance->p_libvlc_int, i_volume );
138 libvlc_exception_raise( p_e, "Volume out of range" );
142 /*****************************************************************************
143 * libvlc_audio_get_track : Get the current audio track
144 *****************************************************************************/
145 int libvlc_audio_get_track( libvlc_input_t *p_input,
146 libvlc_exception_t *p_e )
148 input_thread_t *p_input_thread = GetInput( p_input, p_e );
149 vlc_value_t val_list;
155 if( !p_input_thread )
158 i_ret = var_Get( p_input_thread, "audio-es", &val );
161 libvlc_exception_raise( p_e, "Getting Audio track information failed" );
162 vlc_object_release( p_input_thread );
166 var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL );
167 for( i = 0; i < val_list.p_list->i_count; i++ )
169 vlc_value_t track_val = val_list.p_list->p_values[i];
170 if( track_val.i_int == val.i_int )
176 vlc_object_release( p_input_thread );
180 /*****************************************************************************
181 * libvlc_audio_set_track : Set the current audio track
182 *****************************************************************************/
183 void libvlc_audio_set_track( libvlc_input_t *p_input, int i_track,
184 libvlc_exception_t *p_e )
186 input_thread_t *p_input_thread = GetInput( p_input, p_e );
187 vlc_value_t val_list;
191 if( !p_input_thread )
194 var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL );
195 for( i = 0; i < val_list.p_list->i_count; i++ )
197 vlc_value_t val = val_list.p_list->p_values[i];
200 i_ret = var_Set( p_input_thread, "audio-es", val );
203 libvlc_exception_raise( p_e, "Setting audio track failed" );
205 vlc_object_release( p_input_thread );
209 libvlc_exception_raise( p_e, "Audio track out of range" );
210 vlc_object_release( p_input_thread );
213 /*****************************************************************************
214 * libvlc_audio_get_channel : Get the current audio channel
215 *****************************************************************************/
216 int libvlc_audio_get_channel( libvlc_instance_t *p_instance,
217 libvlc_exception_t *p_e )
219 aout_instance_t *p_aout = GetAOut( p_instance, p_e );
224 var_Get( p_aout, "audio-channels", &val );
225 vlc_object_release( p_aout );
231 /*****************************************************************************
232 * libvlc_audio_set_channel : Set the current audio channel
233 *****************************************************************************/
234 void libvlc_audio_set_channel( libvlc_instance_t *p_instance, int i_channel,
235 libvlc_exception_t *p_e )
237 aout_instance_t *p_aout = GetAOut( p_instance, p_e );
243 val.i_int = i_channel;
246 case AOUT_VAR_CHAN_RSTEREO:
247 case AOUT_VAR_CHAN_STEREO:
248 case AOUT_VAR_CHAN_LEFT:
249 case AOUT_VAR_CHAN_RIGHT:
250 case AOUT_VAR_CHAN_DOLBYS:
251 i_ret = var_Set( p_aout, "audio-channels", val );
254 libvlc_exception_raise( p_e, "Failed setting audio channel" );
255 vlc_object_release( p_aout );
258 vlc_object_release( p_aout );
261 libvlc_exception_raise( p_e, "Audio channel out of range" );
264 vlc_object_release( p_aout );