]> git.sesse.net Git - vlc/blob - src/audio_output/aout_internal.h
1e3997fdc8fd5887356b8da629aa448324ca3fc4
[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 #ifndef LIBVLC_AOUT_INTERNAL_H
25 # define LIBVLC_AOUT_INTERNAL_H 1
26
27 /* Max input rate factor (1/4 -> 4) */
28 # define AOUT_MAX_INPUT_RATE (4)
29
30 enum {
31     AOUT_RESAMPLING_NONE=0,
32     AOUT_RESAMPLING_UP,
33     AOUT_RESAMPLING_DOWN
34 };
35
36 typedef struct
37 {
38     struct vout_thread_t  *(*pf_request_vout)( void *, struct vout_thread_t *,
39                                                video_format_t *, bool );
40     void *p_private;
41 } aout_request_vout_t;
42
43 struct filter_owner_sys_t
44 {
45     audio_output_t *p_aout;
46     aout_input_t    *p_input;
47 };
48
49 block_t *aout_FilterBufferNew( filter_t *, int );
50
51 /** an input stream for the audio output */
52 struct aout_input_t
53 {
54     audio_sample_format_t   input;
55     float                   multiplier; /**< Replay gain multiplier */
56
57     /* pre-filters */
58     filter_t *              pp_filters[AOUT_MAX_FILTERS];
59     int                     i_nb_filters;
60
61     filter_t *              p_playback_rate_filter;
62
63     /* resamplers */
64     filter_t *              pp_resamplers[AOUT_MAX_FILTERS];
65     int                     i_nb_resamplers;
66     int                     i_resampling_type;
67     mtime_t                 i_resamp_start_date;
68     int                     i_resamp_start_drift;
69
70     /* Mixer information */
71     audio_replay_gain_t     replay_gain;
72
73     /* If b_restart == 1, the input pipeline will be re-created. */
74     bool              b_restart;
75
76     /* If b_error == 1, there is no input pipeline. */
77     bool              b_error;
78
79     /* last rate from input */
80     int               i_last_input_rate;
81
82     /* */
83     int               i_buffer_lost;
84
85     /* */
86     bool                b_recycle_vout;
87     aout_request_vout_t request_vout;
88
89     /* */
90     date_t                  date;
91 };
92
93 typedef struct
94 {
95     module_t *module; /**< Output plugin (or NULL if inactive) */
96     aout_input_t *input;
97
98     struct
99     {
100         vlc_mutex_t lock;
101         float multiplier; /**< Software volume amplification multiplier */
102         struct audio_mixer *mixer; /**< Software volume plugin */
103     } volume; /**< Volume and gain management (FIXME: input manager?) */
104
105     audio_sample_format_t mixer_format;
106
107     /* Filters between mixer and output */
108     filter_t *filters[AOUT_MAX_FILTERS];
109     int       nb_filters;
110 } aout_owner_t;
111
112 typedef struct
113 {
114     audio_output_t output;
115     aout_owner_t   owner;
116 } aout_instance_t;
117
118 static inline aout_owner_t *aout_owner (audio_output_t *aout)
119 {
120     return &((aout_instance_t *)aout)->owner;
121 }
122
123 /****************************************************************************
124  * Prototypes
125  *****************************************************************************/
126
127 /* From input.c : */
128 int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_request_vout_t * );
129 int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input );
130 block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
131                          block_t *p_buffer, int i_input_rate );
132 void aout_InputCheckAndRestart( audio_output_t * p_aout, aout_input_t * p_input );
133
134 /* From filters.c : */
135 int aout_FiltersCreatePipeline( audio_output_t *, filter_t **, int *,
136     const audio_sample_format_t *, const audio_sample_format_t * );
137 void aout_FiltersDestroyPipeline( filter_t *const *, unsigned );
138 void aout_FiltersPlay( filter_t *const *, unsigned, aout_buffer_t ** );
139
140 /* From mixer.c : */
141 struct audio_mixer *aout_MixerNew(vlc_object_t *, vlc_fourcc_t);
142 #define aout_MixerNew(o, f) aout_MixerNew(VLC_OBJECT(o), f)
143 void aout_MixerDelete(struct audio_mixer *);
144 void aout_MixerRun(struct audio_mixer *, block_t *, float);
145
146 /* From output.c : */
147 int aout_OutputNew( audio_output_t * p_aout,
148                     const audio_sample_format_t * p_format );
149 void aout_OutputPlay( audio_output_t * p_aout, aout_buffer_t * p_buffer );
150 void aout_OutputPause( audio_output_t * p_aout, bool, mtime_t );
151 void aout_OutputFlush( audio_output_t * p_aout, bool );
152 void aout_OutputDelete( audio_output_t * p_aout );
153
154
155 /* From common.c : */
156 /* Release with vlc_object_release() */
157 audio_output_t *aout_New ( vlc_object_t * );
158 #define aout_New(a) aout_New(VLC_OBJECT(a))
159
160 void aout_FifoInit( vlc_object_t *, aout_fifo_t *, uint32_t );
161 #define aout_FifoInit(o, f, r) aout_FifoInit(VLC_OBJECT(o), f, r)
162 //void aout_FifoPush( aout_fifo_t *, aout_buffer_t * );
163 void aout_FifoReset( aout_fifo_t * );
164 void aout_FifoMoveDates( aout_fifo_t *, mtime_t );
165 void aout_FifoDestroy( aout_fifo_t * p_fifo );
166 void aout_FormatsPrint( audio_output_t * p_aout, const char * psz_text, const audio_sample_format_t * p_format1, const audio_sample_format_t * p_format2 );
167 bool aout_ChangeFilterString( vlc_object_t *, audio_output_t *, const char *psz_variable, const char *psz_name, bool b_add );
168
169 /* From dec.c */
170 aout_input_t *aout_DecNew( audio_output_t *, audio_sample_format_t *,
171                    const audio_replay_gain_t *, const aout_request_vout_t * );
172 void aout_DecDelete ( audio_output_t *, aout_input_t * );
173 aout_buffer_t * aout_DecNewBuffer( aout_input_t *, size_t );
174 void aout_DecDeleteBuffer( audio_output_t *, aout_input_t *, aout_buffer_t * );
175 int aout_DecPlay( audio_output_t *, aout_input_t *, aout_buffer_t *, int i_input_rate );
176 int aout_DecGetResetLost( audio_output_t *, aout_input_t * );
177 void aout_DecChangePause( audio_output_t *, aout_input_t *, bool b_paused, mtime_t i_date );
178 void aout_DecFlush( audio_output_t *, aout_input_t * );
179 bool aout_DecIsEmpty( audio_output_t * p_aout, aout_input_t * p_input );
180
181 /* Audio output locking */
182
183 #if !defined (NDEBUG) \
184  && defined __linux__ && (defined (__i386__) || defined (__x86_64__))
185 # define AOUT_DEBUG 1
186 #endif
187
188 #ifdef AOUT_DEBUG
189 enum
190 {
191     OUTPUT_LOCK=1,
192     VOLUME_LOCK=2,
193 };
194
195 void aout_lock_check (unsigned);
196 void aout_unlock_check (unsigned);
197
198 #else
199 # define aout_lock_check( i )   (void)0
200 # define aout_unlock_check( i ) (void)0
201 #endif
202
203 static inline void aout_lock( audio_output_t *p_aout )
204 {
205     aout_lock_check( OUTPUT_LOCK );
206     vlc_mutex_lock( &p_aout->lock );
207 }
208
209 static inline void aout_unlock( audio_output_t *p_aout )
210 {
211     aout_unlock_check( OUTPUT_LOCK );
212     vlc_mutex_unlock( &p_aout->lock );
213 }
214
215 static inline void aout_lock_volume( audio_output_t *p_aout )
216 {
217     aout_lock_check( VOLUME_LOCK );
218     vlc_mutex_lock( &aout_owner(p_aout)->volume.lock );
219 }
220
221 static inline void aout_unlock_volume( audio_output_t *p_aout )
222 {
223     aout_unlock_check( VOLUME_LOCK );
224     vlc_mutex_unlock( &aout_owner(p_aout)->volume.lock );
225 }
226
227 /* Helpers */
228
229 /**
230  * This function will safely mark aout input to be restarted as soon as
231  * possible to take configuration changes into account */
232 static inline void AoutInputsMarkToRestart( audio_output_t *p_aout )
233 {
234     aout_lock( p_aout );
235     if( aout_owner(p_aout)->input != NULL )
236         aout_owner(p_aout)->input->b_restart = true;
237     aout_unlock( p_aout );
238 }
239
240 #endif /* !LIBVLC_AOUT_INTERNAL_H */