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 <vlc/libvlc.h>
27 #include <vlc_input.h>
30 #include "libvlc_internal.h"
34 * Remember to release the returned aout_instance_t since it is locked at
35 * the end of this function.
37 static aout_instance_t *GetAOut( libvlc_instance_t *p_instance,
38 libvlc_exception_t *p_exception )
40 aout_instance_t * p_aout = NULL;
42 p_aout = vlc_object_find( p_instance->p_libvlc_int, VLC_OBJECT_AOUT, FIND_CHILD );
45 libvlc_exception_raise( p_exception, "No active audio output" );
53 /*****************************************************************************
54 * libvlc_audio_get_mute : Get the volume state, true if muted
55 *****************************************************************************/
56 void libvlc_audio_toggle_mute( libvlc_instance_t *p_instance,
57 libvlc_exception_t *p_e )
59 aout_VolumeMute( p_instance->p_libvlc_int, NULL );
62 vlc_bool_t libvlc_audio_get_mute( libvlc_instance_t *p_instance,
63 libvlc_exception_t *p_e )
66 * If the volume level is 0, then the channel is muted
68 audio_volume_t i_volume;
70 i_volume = libvlc_audio_get_volume(p_instance, p_e);
76 void libvlc_audio_set_mute( libvlc_instance_t *p_instance, vlc_bool_t mute,
77 libvlc_exception_t *p_e )
79 if ( mute ^ libvlc_audio_get_mute( p_instance, p_e ) )
81 aout_VolumeMute( p_instance->p_libvlc_int, NULL );
85 /*****************************************************************************
86 * libvlc_audio_get_volume : Get the current volume (range 0-200 %)
87 *****************************************************************************/
88 int libvlc_audio_get_volume( libvlc_instance_t *p_instance,
89 libvlc_exception_t *p_e )
91 audio_volume_t i_volume;
93 aout_VolumeGet( p_instance->p_libvlc_int, &i_volume );
95 return (i_volume*200+AOUT_VOLUME_MAX/2)/AOUT_VOLUME_MAX;
99 /*****************************************************************************
100 * libvlc_audio_set_volume : Set the current volume
101 *****************************************************************************/
102 void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume,
103 libvlc_exception_t *p_e )
105 if( i_volume >= 0 && i_volume <= 200 )
107 i_volume = (i_volume * AOUT_VOLUME_MAX + 100) / 200;
109 aout_VolumeSet( p_instance->p_libvlc_int, i_volume );
113 libvlc_exception_raise( p_e, "Volume out of range" );
117 /*****************************************************************************
118 * libvlc_audio_get_track_count : Get the number of available audio tracks
119 *****************************************************************************/
120 int libvlc_audio_get_track_count( libvlc_media_instance_t *p_mi,
121 libvlc_exception_t *p_e )
123 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
124 vlc_value_t val_list;
126 if( !p_input_thread )
129 var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL );
130 vlc_object_release( p_input_thread );
131 return val_list.p_list->i_count;
134 /*****************************************************************************
135 * libvlc_audio_get_track : Get the current audio track
136 *****************************************************************************/
137 int libvlc_audio_get_track( libvlc_media_instance_t *p_mi,
138 libvlc_exception_t *p_e )
140 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
141 vlc_value_t val_list;
147 if( !p_input_thread )
150 i_ret = var_Get( p_input_thread, "audio-es", &val );
153 libvlc_exception_raise( p_e, "Getting Audio track information failed" );
154 vlc_object_release( p_input_thread );
158 var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL );
159 for( i = 0; i < val_list.p_list->i_count; i++ )
161 vlc_value_t track_val = val_list.p_list->p_values[i];
162 if( track_val.i_int == val.i_int )
168 vlc_object_release( p_input_thread );
173 /*****************************************************************************
174 * libvlc_audio_set_track : Set the current audio track
175 *****************************************************************************/
176 void libvlc_audio_set_track( libvlc_media_instance_t *p_mi, int i_track,
177 libvlc_exception_t *p_e )
179 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
180 vlc_value_t val_list;
184 if( !p_input_thread )
187 var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL );
188 for( i = 0; i < val_list.p_list->i_count; i++ )
190 vlc_value_t val = val_list.p_list->p_values[i];
193 i_ret = var_Set( p_input_thread, "audio-es", val );
196 libvlc_exception_raise( p_e, "Setting audio track failed" );
198 vlc_object_release( p_input_thread );
202 libvlc_exception_raise( p_e, "Audio track out of range" );
203 vlc_object_release( p_input_thread );
206 /*****************************************************************************
207 * libvlc_audio_get_channel : Get the current audio channel
208 *****************************************************************************/
209 int libvlc_audio_get_channel( libvlc_instance_t *p_instance,
210 libvlc_exception_t *p_e )
212 aout_instance_t *p_aout = GetAOut( p_instance, p_e );
217 var_Get( p_aout, "audio-channels", &val );
218 vlc_object_release( p_aout );
224 /*****************************************************************************
225 * libvlc_audio_set_channel : Set the current audio channel
226 *****************************************************************************/
227 void libvlc_audio_set_channel( libvlc_instance_t *p_instance, int i_channel,
228 libvlc_exception_t *p_e )
230 aout_instance_t *p_aout = GetAOut( p_instance, p_e );
236 val.i_int = i_channel;
239 case AOUT_VAR_CHAN_RSTEREO:
240 case AOUT_VAR_CHAN_STEREO:
241 case AOUT_VAR_CHAN_LEFT:
242 case AOUT_VAR_CHAN_RIGHT:
243 case AOUT_VAR_CHAN_DOLBYS:
244 i_ret = var_Set( p_aout, "audio-channels", val );
247 libvlc_exception_raise( p_e, "Failed setting audio channel" );
248 vlc_object_release( p_aout );
251 vlc_object_release( p_aout );
254 libvlc_exception_raise( p_e, "Audio channel out of range" );
257 vlc_object_release( p_aout );