]> git.sesse.net Git - vlc/blob - src/audio_output/aout_internal.h
aout: partly rewrite and move filters initialization code
[vlc] / src / audio_output / aout_internal.h
1 /*****************************************************************************
2  * aout_internal.h : internal defines for audio output
3  *****************************************************************************
4  * Copyright (C) 2002 VLC authors and VideoLAN
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 it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * 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 # include <vlc_atomic.h>
28
29 /* Max input rate factor (1/4 -> 4) */
30 # define AOUT_MAX_INPUT_RATE (4)
31
32 # define AOUT_MAX_FILTERS 10
33
34 enum {
35     AOUT_RESAMPLING_NONE=0,
36     AOUT_RESAMPLING_UP,
37     AOUT_RESAMPLING_DOWN
38 };
39
40 typedef struct
41 {
42     struct vout_thread_t  *(*pf_request_vout)( void *, struct vout_thread_t *,
43                                                video_format_t *, bool );
44     void *p_private;
45 } aout_request_vout_t;
46
47 typedef struct aout_volume aout_volume_t;
48
49 /** an input stream for the audio output */
50 struct aout_input_t
51 {
52     unsigned            samplerate; /**< Input sample rate */
53
54     int                     i_resampling_type;
55     mtime_t                 i_resamp_start_date;
56     int                     i_resamp_start_drift;
57
58     /* last rate from input */
59     int               i_last_input_rate;
60
61     /* */
62     int               i_buffer_lost;
63 };
64
65 typedef struct
66 {
67     vlc_mutex_t lock;
68     module_t *module; /**< Output plugin (or NULL if inactive) */
69     aout_input_t *input;
70     aout_volume_t *volume;
71
72     struct
73     {
74         date_t date;
75     } sync;
76
77     audio_sample_format_t input_format;
78     audio_sample_format_t mixer_format;
79
80     filter_t *rate_filter; /**< The filter adjusting samples count
81         (either the scaletempo filter or a resampler) */
82     filter_t *resampler; /**< The resampler */
83     filter_t *filters[AOUT_MAX_FILTERS]; /**< Configured user filters
84         (e.g. equalization) and their conversions */
85     unsigned nb_filters;
86     unsigned nb_converters;
87     filter_t *converters[5]; /**< Converters to the output */
88
89     aout_request_vout_t request_vout;
90     bool recycle_vout;
91
92     vlc_atomic_t restart;
93 } aout_owner_t;
94
95 typedef struct
96 {
97     audio_output_t output;
98     aout_owner_t   owner;
99 } aout_instance_t;
100
101 static inline aout_owner_t *aout_owner (audio_output_t *aout)
102 {
103     return &((aout_instance_t *)aout)->owner;
104 }
105
106 /****************************************************************************
107  * Prototypes
108  *****************************************************************************/
109
110 /* From input.c : */
111 aout_input_t *aout_InputNew(audio_output_t *, const audio_sample_format_t *,
112                             const audio_sample_format_t *,
113                             const aout_request_vout_t *);
114 int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input );
115 block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
116                          block_t *p_buffer, int i_input_rate, date_t * );
117
118 /* From filters.c : */
119 int aout_FiltersCreatePipeline( vlc_object_t *, filter_t **, unsigned *,
120     unsigned, const audio_sample_format_t *, const audio_sample_format_t * );
121 #define aout_FiltersCreatePipeline(o, pv, pc, max, inf, outf) \
122         aout_FiltersCreatePipeline(VLC_OBJECT(o), pv, pc, max, inf, outf)
123 void aout_FiltersDestroyPipeline( filter_t *const *, unsigned );
124 void aout_FiltersPlay( filter_t *const *, unsigned, block_t ** );
125
126 int aout_FiltersNew(audio_output_t *, const audio_sample_format_t *,
127                    const audio_sample_format_t *, const aout_request_vout_t *);
128 void aout_FiltersDestroy(audio_output_t *);
129
130 /* From mixer.c : */
131 aout_volume_t *aout_volume_New(vlc_object_t *, const audio_replay_gain_t *);
132 #define aout_volume_New(o, g) aout_volume_New(VLC_OBJECT(o), g)
133 int aout_volume_SetFormat(aout_volume_t *, vlc_fourcc_t);
134 void aout_volume_SetVolume(aout_volume_t *, float);
135 int aout_volume_Amplify(aout_volume_t *, block_t *);
136 void aout_volume_Delete(aout_volume_t *);
137
138
139 /* From output.c : */
140 audio_output_t *aout_New (vlc_object_t *);
141 #define aout_New(a) aout_New(VLC_OBJECT(a))
142 void aout_Destroy (audio_output_t *);
143
144 int aout_OutputNew( audio_output_t * p_aout,
145                     const audio_sample_format_t * p_format );
146 void aout_OutputPlay( audio_output_t * p_aout, block_t * p_buffer );
147 void aout_OutputPause( audio_output_t * p_aout, bool, mtime_t );
148 void aout_OutputFlush( audio_output_t * p_aout, bool );
149 void aout_OutputDelete( audio_output_t * p_aout );
150
151
152 /* From common.c : */
153 void aout_FormatsPrint(vlc_object_t *, const char *,
154                        const audio_sample_format_t *,
155                        const audio_sample_format_t *);
156 #define aout_FormatsPrint(o, t, a, b) \
157         aout_FormatsPrint(VLC_OBJECT(o), t, a, b)
158 bool aout_ChangeFilterString( vlc_object_t *manager, vlc_object_t *aout,
159                               const char *var, const char *name, bool b_add );
160
161 /* From dec.c */
162 int aout_DecNew(audio_output_t *, const audio_sample_format_t *,
163                 const audio_replay_gain_t *, const aout_request_vout_t *);
164 void aout_DecDelete(audio_output_t *);
165 block_t *aout_DecNewBuffer(audio_output_t *, size_t);
166 void aout_DecDeleteBuffer(audio_output_t *, block_t *);
167 int aout_DecPlay(audio_output_t *, block_t *, int i_input_rate);
168 int aout_DecGetResetLost(audio_output_t *);
169 void aout_DecChangePause(audio_output_t *, bool b_paused, mtime_t i_date);
170 void aout_DecFlush(audio_output_t *);
171 bool aout_DecIsEmpty(audio_output_t *);
172
173 void aout_InputRequestRestart(audio_output_t *);
174
175 /* Audio output locking */
176 static inline void aout_lock( audio_output_t *p_aout )
177 {
178     vlc_mutex_lock( &aout_owner(p_aout)->lock );
179 }
180
181 static inline void aout_unlock( audio_output_t *p_aout )
182 {
183     vlc_mutex_unlock( &aout_owner(p_aout)->lock );
184 }
185
186 #define aout_assert_locked( aout ) \
187         vlc_assert_locked( &aout_owner(aout)->lock )
188
189 #endif /* !LIBVLC_AOUT_INTERNAL_H */