]> git.sesse.net Git - vlc/blob - src/control/audio.c
Add support to the activex, mozilla, firefox, safari plugin for changing audio track...
[vlc] / src / control / audio.c
1 /*****************************************************************************
2  * libvlc_audio.c: New libvlc audio control API
3  *****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Filippo Carone <filippo@carone.org>
8  *          Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #include "libvlc_internal.h"
26 #include <vlc/libvlc.h>
27
28 #include <vlc_aout.h>
29
30 /*****************************************************************************
31  * libvlc_audio_get_mute : Get the volume state, true if muted
32  *****************************************************************************/
33 void libvlc_audio_toggle_mute( libvlc_instance_t *p_instance,
34                                libvlc_exception_t *p_e )
35 {
36     aout_VolumeMute( p_instance->p_libvlc_int, NULL );
37 }
38
39 vlc_bool_t libvlc_audio_get_mute( libvlc_instance_t *p_instance,
40                                   libvlc_exception_t *p_e )
41 {
42     /*
43      * If the volume level is 0, then the channel is muted
44      */
45     audio_volume_t i_volume;
46
47     i_volume = libvlc_audio_get_volume(p_instance, p_e);
48     if ( i_volume == 0 )
49         return VLC_TRUE;
50     return VLC_FALSE;
51 }
52
53 void libvlc_audio_set_mute( libvlc_instance_t *p_instance, vlc_bool_t mute,
54                             libvlc_exception_t *p_e )
55 {
56     if ( mute ^ libvlc_audio_get_mute( p_instance, p_e ) )
57     {
58         aout_VolumeMute( p_instance->p_libvlc_int, NULL );
59     }
60 }
61
62 /*****************************************************************************
63  * libvlc_audio_get_volume : Get the current volume (range 0-200 %)
64  *****************************************************************************/
65 int libvlc_audio_get_volume( libvlc_instance_t *p_instance,
66                              libvlc_exception_t *p_e )
67 {
68     audio_volume_t i_volume;
69
70     aout_VolumeGet( p_instance->p_libvlc_int, &i_volume );
71
72     return (i_volume*200+AOUT_VOLUME_MAX/2)/AOUT_VOLUME_MAX;
73 }
74
75
76 /*****************************************************************************
77  * libvlc_audio_set_volume : Set the current volume
78  *****************************************************************************/
79 void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume,
80                               libvlc_exception_t *p_e )
81 {
82     if( i_volume >= 0 && i_volume <= 200 )
83     {
84         i_volume = (i_volume * AOUT_VOLUME_MAX + 100) / 200;
85
86         aout_VolumeSet( p_instance->p_libvlc_int, i_volume );
87     }
88     else
89     {
90         libvlc_exception_raise( p_e, "Volume out of range" );
91     }
92 }
93
94 /*****************************************************************************
95  * libvlc_audio_get_track : Get the current audio track
96  *****************************************************************************/
97 int libvlc_audio_get_track( libvlc_instance_t *p_instance,
98                             libvlc_exception_t *p_e )
99 {
100     int i_track = 0;
101
102     i_track = var_GetInteger( p_instance->p_libvlc_int, "audio-track" );
103
104     return i_track;
105 }
106
107 /*****************************************************************************
108  * libvlc_audio_set_track : Set the current audio track
109  *****************************************************************************/
110 void libvlc_audio_set_track( libvlc_instance_t *p_instance, int i_track,
111                              libvlc_exception_t *p_e )
112 {
113     int i_ret = -1;
114
115     i_ret = var_SetInteger( p_instance->p_libvlc_int, "audio-track", i_track );
116
117     if( i_ret < 0 )
118     {
119         libvlc_exception_raise( p_e, "Audio track out of range" );
120     }
121 }
122
123 /*****************************************************************************
124  * libvlc_audio_get_channel : Get the current audio channel
125  *****************************************************************************/
126 char *libvlc_audio_get_channel( libvlc_instance_t *p_instance,
127                                 libvlc_exception_t *p_e )
128 {
129     char *psz_channel = NULL;
130     int i_channel = 0;
131
132     i_channel = var_GetInteger( p_instance->p_libvlc_int, "audio-channel" );
133     switch( i_channel )
134     {
135         case AOUT_VAR_CHAN_RSTEREO:
136             psz_channel = strdup("reverse");
137             break;
138         case AOUT_VAR_CHAN_STEREO:
139             psz_channel = strdup("stereo");
140             break;
141         case AOUT_VAR_CHAN_LEFT:
142             psz_channel = strdup("left");
143             break;
144         case AOUT_VAR_CHAN_RIGHT:
145             psz_channel = strdup("right");
146             break;
147         case AOUT_VAR_CHAN_DOLBYS:
148             psz_channel = strdup("dolby");
149             break;
150         default:
151             psz_channel = strdup("disabled");
152             break;
153     }
154     return psz_channel;
155 }
156
157 /*****************************************************************************
158  * libvlc_audio_set_channel : Set the current audio channel
159  *****************************************************************************/
160 void libvlc_audio_set_channel( libvlc_instance_t *p_instance, char *psz_channel,
161                                libvlc_exception_t *p_e )
162 {
163     int i_ret = -1;
164     int i_channel = 0;
165
166     if( !psz_channel )
167     {
168         libvlc_exception_raise( p_e, "Audio track out of range" );
169     }
170     else
171     {
172         if( strncmp( psz_channel, "reverse", 7 ) == 0 )
173             i_channel = AOUT_VAR_CHAN_RSTEREO;
174         else if( strncmp( psz_channel, "stereo", 6 ) == 0 )
175             i_channel = AOUT_VAR_CHAN_STEREO;
176         else if( strncmp( psz_channel, "left", 4 ) == 0 )
177             i_channel = AOUT_VAR_CHAN_LEFT;
178         else if( strncmp( psz_channel, "right", 5 ) == 0 )
179             i_channel = AOUT_VAR_CHAN_RIGHT;
180         else if( strncmp( psz_channel, "dolby", 5 ) == 0 )
181             i_channel = AOUT_VAR_CHAN_DOLBYS;
182
183         i_ret = var_SetInteger( p_instance->p_libvlc_int, "audio-channel", i_channel );
184         if( i_ret < 0 )
185         {
186             libvlc_exception_raise( p_e, "Audio track out of range" );
187         }
188     }
189 }