]> git.sesse.net Git - vlc/blob - src/audio_output/aout_internal.h
Allow aout to grab vout_Request calls.
[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 #include <assert.h>
32
33 #if defined( __APPLE__ ) || defined( SYS_BSD )
34 #undef HAVE_ALLOCA
35 #endif
36
37 #ifdef HAVE_ALLOCA
38 #   define ALLOCA_TEST( p_alloc, p_new_buffer )                             \
39         if ( (p_alloc)->i_alloc_type == AOUT_ALLOC_STACK )                  \
40         {                                                                   \
41             (p_new_buffer) = alloca( i_alloc_size + sizeof(aout_buffer_t) );\
42             i_alloc_type = AOUT_ALLOC_STACK;                                \
43         }                                                                   \
44         else
45 #else
46 #   define ALLOCA_TEST( p_alloc, p_new_buffer )
47 #endif
48
49 #define aout_BufferAlloc( p_alloc, i_nb_usec, p_previous_buffer,            \
50                           p_new_buffer )                                    \
51     if ( (p_alloc)->i_alloc_type == AOUT_ALLOC_NONE )                       \
52     {                                                                       \
53         (p_new_buffer) = p_previous_buffer;                                 \
54     }                                                                       \
55     else                                                                    \
56     {                                                                       \
57         int i_alloc_size, i_alloc_type;                                     \
58         i_alloc_size = (int)( (uint64_t)(p_alloc)->i_bytes_per_sec          \
59                                             * (i_nb_usec) / 1000000 + 1 );  \
60         ALLOCA_TEST( p_alloc, p_new_buffer )                                \
61         {                                                                   \
62             (p_new_buffer) = malloc( i_alloc_size + sizeof(aout_buffer_t) );\
63             i_alloc_type = AOUT_ALLOC_HEAP;                                 \
64         }                                                                   \
65         if ( p_new_buffer != NULL )                                         \
66         {                                                                   \
67             (p_new_buffer)->i_alloc_type = i_alloc_type;                    \
68             (p_new_buffer)->i_size = i_alloc_size;                          \
69             (p_new_buffer)->p_buffer = (uint8_t *)(p_new_buffer)            \
70                                          + sizeof(aout_buffer_t);           \
71             (p_new_buffer)->b_discontinuity = false;                        \
72             if ( (p_previous_buffer) != NULL )                              \
73             {                                                               \
74                 (p_new_buffer)->start_date =                                \
75                            ((aout_buffer_t *)p_previous_buffer)->start_date;\
76                 (p_new_buffer)->end_date =                                  \
77                            ((aout_buffer_t *)p_previous_buffer)->end_date;  \
78             }                                                               \
79         }                                                                   \
80         /* we'll keep that for a while --Meuuh */                           \
81         /* else printf("%s:%d\n", __FILE__, __LINE__); */                   \
82     }
83
84 struct aout_filter_owner_sys_t
85 {
86     aout_instance_t *p_aout;
87     aout_input_t    *p_input;
88 };
89
90 /****************************************************************************
91  * Prototypes
92  *****************************************************************************/
93 /* From input.c : */
94 int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input );
95 int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input );
96 int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
97                     aout_buffer_t * p_buffer, int i_input_rate );
98
99 /* From filters.c : */
100 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 );
101 void aout_FiltersDestroyPipeline ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters );
102 void  aout_FiltersPlay ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_buffer_t ** pp_input_buffer );
103 void aout_FiltersHintBuffers( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_alloc_t * p_first_alloc );
104
105 /* From mixer.c : */
106 int aout_MixerNew( aout_instance_t * p_aout );
107 void aout_MixerDelete( aout_instance_t * p_aout );
108 void aout_MixerRun( aout_instance_t * p_aout );
109 int aout_MixerMultiplierSet( aout_instance_t * p_aout, float f_multiplier );
110 int aout_MixerMultiplierGet( aout_instance_t * p_aout, float * pf_multiplier );
111
112 /* From output.c : */
113 int aout_OutputNew( aout_instance_t * p_aout,
114                     audio_sample_format_t * p_format );
115 void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer );
116 void aout_OutputDelete( aout_instance_t * p_aout );
117
118
119 /* From common.c : */
120 #define aout_New(a) __aout_New(VLC_OBJECT(a))
121 /* Release with vlc_object_release() */
122 aout_instance_t * __aout_New ( vlc_object_t * );
123
124 void aout_FifoInit( aout_instance_t *, aout_fifo_t *, uint32_t );
125 mtime_t aout_FifoNextStart( aout_instance_t *, aout_fifo_t * );
126 void aout_FifoPush( aout_instance_t *, aout_fifo_t *, aout_buffer_t * );
127 void aout_FifoSet( aout_instance_t *, aout_fifo_t *, mtime_t );
128 void aout_FifoMoveDates( aout_instance_t *, aout_fifo_t *, mtime_t );
129 void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo );
130 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 );
131
132
133 /* From intf.c :*/
134 int aout_VolumeSoftGet( aout_instance_t *, audio_volume_t * );
135 int aout_VolumeSoftSet( aout_instance_t *, audio_volume_t );
136 int aout_VolumeSoftInfos( aout_instance_t *, audio_volume_t * );
137 int aout_VolumeNoneGet( aout_instance_t *, audio_volume_t * );
138 int aout_VolumeNoneSet( aout_instance_t *, audio_volume_t );
139 int aout_VolumeNoneInfos( aout_instance_t *, audio_volume_t * );
140
141 /* From dec.c */
142 #define aout_DecNew(a, b, c, d) __aout_DecNew(VLC_OBJECT(a), b, c, d)
143 aout_input_t * __aout_DecNew( vlc_object_t *, aout_instance_t **, audio_sample_format_t *, audio_replay_gain_t * );
144 int aout_DecDelete ( aout_instance_t *, aout_input_t * );
145 aout_buffer_t * aout_DecNewBuffer( aout_input_t *, size_t );
146 void aout_DecDeleteBuffer( aout_instance_t *, aout_input_t *, aout_buffer_t * );
147 int aout_DecPlay( aout_instance_t *, aout_input_t *, aout_buffer_t *, int i_input_rate );
148 int aout_DecGetResetLost( aout_instance_t *, aout_input_t * );
149 void aout_DecChangePause( aout_instance_t *, aout_input_t *, bool b_paused, mtime_t i_date );
150 void aout_DecFlush( aout_instance_t *, aout_input_t * );
151
152 /* Helpers */
153
154 static inline void aout_lock_mixer( aout_instance_t *p_aout )
155 {
156     vlc_mutex_lock( &p_aout->mixer_lock );
157 }
158
159 static inline void aout_unlock_mixer( aout_instance_t *p_aout )
160 {
161     vlc_mutex_unlock( &p_aout->mixer_lock );
162 }
163
164 static inline void aout_lock_input_fifos( aout_instance_t *p_aout )
165 {
166     vlc_mutex_lock( &p_aout->input_fifos_lock );
167 }
168
169 static inline void aout_unlock_input_fifos( aout_instance_t *p_aout )
170 {
171     vlc_mutex_unlock( &p_aout->input_fifos_lock );
172 }
173
174 static inline void aout_lock_output_fifo( aout_instance_t *p_aout )
175 {
176     vlc_mutex_lock( &p_aout->output_fifo_lock );
177 }
178
179 static inline void aout_unlock_output_fifo( aout_instance_t *p_aout )
180 {
181     vlc_mutex_unlock( &p_aout->output_fifo_lock );
182 }
183
184 static inline void aout_lock_input( aout_instance_t *p_aout, aout_input_t * p_input )
185 {
186     (void)p_aout;
187     vlc_mutex_lock( &p_input->lock );
188 }
189
190 static inline void aout_unlock_input( aout_instance_t *p_aout, aout_input_t * p_input )
191 {
192     (void)p_aout;
193     vlc_mutex_unlock( &p_input->lock );
194 }
195
196
197 /**
198  * This function will safely mark aout input to be restarted as soon as
199  * possible to take configuration changes into account */
200 static inline void AoutInputsMarkToRestart( aout_instance_t *p_aout )
201 {
202     int i;
203     aout_lock_mixer( p_aout );
204     for( i = 0; i < p_aout->i_nb_inputs; i++ )
205         p_aout->pp_inputs[i]->b_restart = true;
206     aout_unlock_mixer( p_aout );
207 }
208
209 /* This function will add or remove a a module from a string list (comma
210  * separated). It will return true if there is a modification
211  * In case p_aout is NULL, we will use configuration instead of variable */
212 static inline bool AoutChangeFilterString( vlc_object_t *p_obj, aout_instance_t * p_aout,
213                                            const char* psz_variable,
214                                            const char *psz_name, bool b_add )
215 {
216     vlc_value_t val;
217     char *psz_parser;
218
219     if( *psz_name == '\0' )
220         return false;
221
222     if( p_aout )
223         var_Get( p_aout, psz_variable, &val );
224     else
225         val.psz_string = config_GetPsz( p_obj, "audio-filter" );
226
227     if( !val.psz_string )
228         val.psz_string = strdup("");
229
230     psz_parser = strstr( val.psz_string, psz_name );
231
232     if( ( b_add && psz_parser ) || ( !b_add && !psz_parser ) )
233     {
234         /* Nothing to do */
235         free( val.psz_string );
236         return false;
237     }
238
239     if( b_add )
240     {
241         char *psz_old = val.psz_string;
242         if( *psz_old )
243         {
244             if( asprintf( &val.psz_string, "%s:%s", psz_old, psz_name ) == -1 )
245                 val.psz_string = NULL;
246         }
247         else
248             val.psz_string = strdup( psz_name );
249         free( psz_old );
250     }
251     else
252     {
253         const int i_name = strlen( psz_name );
254         const char *psz_next;
255
256         psz_next = &psz_parser[i_name];
257         if( *psz_next == ':' )
258             psz_next++;
259
260         memmove( psz_parser, psz_next, strlen(psz_next)+1 );
261     }
262
263     if( p_aout )
264         var_Set( p_aout, psz_variable, val );
265     else
266         config_PutPsz( p_obj, psz_variable, val.psz_string );
267     free( val.psz_string );
268     return true;
269 }
270
271 #endif /* !__LIBVLC_AOUT_INTERNAL_H */