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