]> git.sesse.net Git - vlc/blob - src/audio_output/aout_internal.h
Use <vlc_cpu.h>
[vlc] / src / audio_output / aout_internal.h
1 /*****************************************************************************
2  * aout_internal.h : internal defines for audio output
3  *****************************************************************************
4  * Copyright (C) 2002 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #if defined(__PLUGIN__) || defined(__BUILTIN__) || !defined(__LIBVLC__)
25 # error This header file can only be included from LibVLC.
26 #endif
27
28 #ifndef __LIBVLC_AOUT_INTERNAL_H
29 # define __LIBVLC_AOUT_INTERNAL_H 1
30
31 aout_buffer_t *aout_BufferAlloc(aout_alloc_t *allocation, mtime_t microseconds,
32         aout_buffer_t *old_buffer);
33
34 struct aout_filter_owner_sys_t
35 {
36     aout_instance_t *p_aout;
37     aout_input_t    *p_input;
38 };
39
40 /** an input stream for the audio output */
41 struct aout_input_t
42 {
43     /* When this lock is taken, the pipeline cannot be changed by a
44      * third-party. */
45     vlc_mutex_t             lock;
46
47     audio_sample_format_t   input;
48     aout_alloc_t            input_alloc;
49
50     /* pre-filters */
51     aout_filter_t *         pp_filters[AOUT_MAX_FILTERS];
52     int                     i_nb_filters;
53
54     aout_filter_t *         p_playback_rate_filter;
55
56     /* resamplers */
57     aout_filter_t *         pp_resamplers[AOUT_MAX_FILTERS];
58     int                     i_nb_resamplers;
59     int                     i_resampling_type;
60     mtime_t                 i_resamp_start_date;
61     int                     i_resamp_start_drift;
62
63     /* Mixer information */
64     audio_replay_gain_t     replay_gain;
65
66     /* If b_restart == 1, the input pipeline will be re-created. */
67     bool              b_restart;
68
69     /* If b_error == 1, there is no input pipeline. */
70     bool              b_error;
71
72     /* Did we just change the output format? (expect buffer inconsistencies) */
73     bool              b_changed;
74
75     /* last rate from input */
76     int               i_last_input_rate;
77
78     /* */
79     int               i_buffer_lost;
80
81     /* */
82     bool              b_paused;
83     mtime_t           i_pause_date;
84
85     /* */
86     bool                b_recycle_vout;
87     aout_request_vout_t request_vout;
88
89     /* */
90     aout_mixer_input_t mixer;
91  };
92
93 /****************************************************************************
94  * Prototypes
95  *****************************************************************************/
96
97 /* From input.c : */
98 int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_request_vout_t * );
99 int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input );
100 int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
101                     aout_buffer_t * p_buffer, int i_input_rate );
102
103 /* From filters.c : */
104 int aout_FiltersCreatePipeline ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int * pi_nb_filters, const audio_sample_format_t * p_input_format, const audio_sample_format_t * p_output_format );
105 void aout_FiltersDestroyPipeline ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters );
106 void  aout_FiltersPlay ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_buffer_t ** pp_input_buffer );
107 void aout_FiltersHintBuffers( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_alloc_t * p_first_alloc );
108
109 /* From mixer.c : */
110 int aout_MixerNew( aout_instance_t * p_aout );
111 void aout_MixerDelete( aout_instance_t * p_aout );
112 void aout_MixerRun( aout_instance_t * p_aout );
113 int aout_MixerMultiplierSet( aout_instance_t * p_aout, float f_multiplier );
114 int aout_MixerMultiplierGet( aout_instance_t * p_aout, float * pf_multiplier );
115
116 /* From output.c : */
117 int aout_OutputNew( aout_instance_t * p_aout,
118                     audio_sample_format_t * p_format );
119 void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer );
120 void aout_OutputDelete( aout_instance_t * p_aout );
121
122
123 /* From common.c : */
124 #define aout_New(a) __aout_New(VLC_OBJECT(a))
125 /* Release with vlc_object_release() */
126 aout_instance_t * __aout_New ( vlc_object_t * );
127
128 void aout_FifoInit( aout_instance_t *, aout_fifo_t *, uint32_t );
129 mtime_t aout_FifoNextStart( aout_instance_t *, aout_fifo_t * );
130 void aout_FifoPush( aout_instance_t *, aout_fifo_t *, aout_buffer_t * );
131 void aout_FifoSet( aout_instance_t *, aout_fifo_t *, mtime_t );
132 void aout_FifoMoveDates( aout_instance_t *, aout_fifo_t *, mtime_t );
133 void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo );
134 void aout_FormatsPrint( aout_instance_t * p_aout, const char * psz_text, const audio_sample_format_t * p_format1, const audio_sample_format_t * p_format2 );
135
136
137 /* From intf.c :*/
138 int aout_VolumeSoftGet( aout_instance_t *, audio_volume_t * );
139 int aout_VolumeSoftSet( aout_instance_t *, audio_volume_t );
140 int aout_VolumeSoftInfos( aout_instance_t *, audio_volume_t * );
141 int aout_VolumeNoneGet( aout_instance_t *, audio_volume_t * );
142 int aout_VolumeNoneSet( aout_instance_t *, audio_volume_t );
143 int aout_VolumeNoneInfos( aout_instance_t *, audio_volume_t * );
144
145 /* From dec.c */
146 #define aout_DecNew(a, b, c, d, e) __aout_DecNew(VLC_OBJECT(a), b, c, d, e)
147 aout_input_t * __aout_DecNew( vlc_object_t *, aout_instance_t **,
148                               audio_sample_format_t *, const audio_replay_gain_t *,
149                               const aout_request_vout_t * );
150 int aout_DecDelete ( aout_instance_t *, aout_input_t * );
151 aout_buffer_t * aout_DecNewBuffer( aout_input_t *, size_t );
152 void aout_DecDeleteBuffer( aout_instance_t *, aout_input_t *, aout_buffer_t * );
153 int aout_DecPlay( aout_instance_t *, aout_input_t *, aout_buffer_t *, int i_input_rate );
154 int aout_DecGetResetLost( aout_instance_t *, aout_input_t * );
155 void aout_DecChangePause( aout_instance_t *, aout_input_t *, bool b_paused, mtime_t i_date );
156 void aout_DecFlush( aout_instance_t *, aout_input_t * );
157
158 /* Helpers */
159
160 static inline void aout_lock_mixer( aout_instance_t *p_aout )
161 {
162     vlc_mutex_lock( &p_aout->mixer_lock );
163 }
164
165 static inline void aout_unlock_mixer( aout_instance_t *p_aout )
166 {
167     vlc_mutex_unlock( &p_aout->mixer_lock );
168 }
169
170 static inline void aout_lock_input_fifos( aout_instance_t *p_aout )
171 {
172     vlc_mutex_lock( &p_aout->input_fifos_lock );
173 }
174
175 static inline void aout_unlock_input_fifos( aout_instance_t *p_aout )
176 {
177     vlc_mutex_unlock( &p_aout->input_fifos_lock );
178 }
179
180 static inline void aout_lock_output_fifo( aout_instance_t *p_aout )
181 {
182     vlc_mutex_lock( &p_aout->output_fifo_lock );
183 }
184
185 static inline void aout_unlock_output_fifo( aout_instance_t *p_aout )
186 {
187     vlc_mutex_unlock( &p_aout->output_fifo_lock );
188 }
189
190 static inline void aout_lock_input( aout_instance_t *p_aout, aout_input_t * p_input )
191 {
192     (void)p_aout;
193     vlc_mutex_lock( &p_input->lock );
194 }
195
196 static inline void aout_unlock_input( aout_instance_t *p_aout, aout_input_t * p_input )
197 {
198     (void)p_aout;
199     vlc_mutex_unlock( &p_input->lock );
200 }
201
202
203 /**
204  * This function will safely mark aout input to be restarted as soon as
205  * possible to take configuration changes into account */
206 static inline void AoutInputsMarkToRestart( aout_instance_t *p_aout )
207 {
208     int i;
209     aout_lock_mixer( p_aout );
210     for( i = 0; i < p_aout->i_nb_inputs; i++ )
211         p_aout->pp_inputs[i]->b_restart = true;
212     aout_unlock_mixer( p_aout );
213 }
214
215 /* This function will add or remove a a module from a string list (comma
216  * separated). It will return true if there is a modification
217  * In case p_aout is NULL, we will use configuration instead of variable */
218 static inline bool AoutChangeFilterString( vlc_object_t *p_obj, aout_instance_t * p_aout,
219                                            const char* psz_variable,
220                                            const char *psz_name, bool b_add )
221 {
222     char *psz_val;
223     char *psz_parser;
224
225     if( *psz_name == '\0' )
226         return false;
227
228     if( p_aout )
229         psz_val = var_GetString( p_aout, psz_variable );
230     else
231         psz_val = config_GetPsz( p_obj, "audio-filter" );
232
233     if( !psz_val )
234         psz_val = strdup( "" );
235
236     psz_parser = strstr( psz_val, psz_name );
237
238     if( ( b_add && psz_parser ) || ( !b_add && !psz_parser ) )
239     {
240         /* Nothing to do */
241         free( psz_val );
242         return false;
243     }
244
245     if( b_add )
246     {
247         char *psz_old = psz_val;
248         if( *psz_old )
249         {
250             if( asprintf( &psz_val, "%s:%s", psz_old, psz_name ) == -1 )
251                 psz_val = NULL;
252         }
253         else
254             psz_val = strdup( psz_name );
255         free( psz_old );
256     }
257     else
258     {
259         const int i_name = strlen( psz_name );
260         const char *psz_next;
261
262         psz_next = &psz_parser[i_name];
263         if( *psz_next == ':' )
264             psz_next++;
265
266         memmove( psz_parser, psz_next, strlen(psz_next)+1 );
267     }
268
269     if( p_aout )
270         var_SetString( p_aout, psz_variable, psz_val );
271     else
272         config_PutPsz( p_obj, psz_variable, psz_val );
273     free( psz_val );
274     return true;
275 }
276
277 #endif /* !__LIBVLC_AOUT_INTERNAL_H */