aout_internal.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * aout_internal.h : internal defines for audio output
00003  *****************************************************************************
00004  * Copyright (C) 2002 VLC authors and VideoLAN
00005  * $Id: e94c0c80bc1950f03fff58812a4435ba0bc0ce94 $
00006  *
00007  * Authors: Christophe Massiot <massiot@via.ecp.fr>
00008  *
00009  * This program is free software; you can redistribute it and/or modify it
00010  * under the terms of the GNU Lesser General Public License as published by
00011  * the Free Software Foundation; either version 2.1 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017  * GNU Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with this program; if not, write to the Free Software Foundation,
00021  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00022  *****************************************************************************/
00023 
00024 #ifndef LIBVLC_AOUT_INTERNAL_H
00025 # define LIBVLC_AOUT_INTERNAL_H 1
00026 
00027 /* Max input rate factor (1/4 -> 4) */
00028 # define AOUT_MAX_INPUT_RATE (4)
00029 
00030 enum {
00031     AOUT_RESAMPLING_NONE=0,
00032     AOUT_RESAMPLING_UP,
00033     AOUT_RESAMPLING_DOWN
00034 };
00035 
00036 typedef struct
00037 {
00038     struct vout_thread_t  *(*pf_request_vout)( void *, struct vout_thread_t *,
00039                                                video_format_t *, bool );
00040     void *p_private;
00041 } aout_request_vout_t;
00042 
00043 struct filter_owner_sys_t
00044 {
00045     audio_output_t *p_aout;
00046     aout_input_t    *p_input;
00047 };
00048 
00049 /** an input stream for the audio output */
00050 struct aout_input_t
00051 {
00052     unsigned            samplerate; /**< Input sample rate */
00053 
00054     /* pre-filters */
00055     filter_t *              pp_filters[AOUT_MAX_FILTERS];
00056     int                     i_nb_filters;
00057 
00058     filter_t *              p_playback_rate_filter;
00059 
00060     /* resamplers */
00061     filter_t *              pp_resamplers[AOUT_MAX_FILTERS];
00062     int                     i_nb_resamplers;
00063     int                     i_resampling_type;
00064     mtime_t                 i_resamp_start_date;
00065     int                     i_resamp_start_drift;
00066 
00067     /* last rate from input */
00068     int               i_last_input_rate;
00069 
00070     /* */
00071     int               i_buffer_lost;
00072 
00073     /* */
00074     bool                b_recycle_vout;
00075     aout_request_vout_t request_vout;
00076 };
00077 
00078 typedef struct
00079 {
00080     vlc_mutex_t lock;
00081     module_t *module; /**< Output plugin (or NULL if inactive) */
00082     aout_input_t *input;
00083 
00084     struct
00085     {
00086         date_t date;
00087     } sync;
00088 
00089     struct
00090     {
00091         vlc_mutex_t lock;
00092         float multiplier; /**< Software volume amplification multiplier */
00093         struct audio_mixer *mixer; /**< Software volume plugin */
00094     } volume;
00095 
00096     struct
00097     {
00098         vlc_atomic_t multiplier;
00099         audio_replay_gain_t data;
00100     } gain;
00101 
00102     audio_sample_format_t mixer_format;
00103     audio_sample_format_t input_format;
00104 
00105     /* Filters between mixer and output */
00106     filter_t *filters[AOUT_MAX_FILTERS];
00107     int       nb_filters;
00108 
00109     vlc_atomic_t restart;
00110 } aout_owner_t;
00111 
00112 typedef struct
00113 {
00114     audio_output_t output;
00115     aout_owner_t   owner;
00116 } aout_instance_t;
00117 
00118 static inline aout_owner_t *aout_owner (audio_output_t *aout)
00119 {
00120     return &((aout_instance_t *)aout)->owner;
00121 }
00122 
00123 /****************************************************************************
00124  * Prototypes
00125  *****************************************************************************/
00126 
00127 /* From input.c : */
00128 aout_input_t *aout_InputNew(audio_output_t *, const audio_sample_format_t *,
00129                             const audio_sample_format_t *,
00130                             const aout_request_vout_t *);
00131 int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input );
00132 block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
00133                          block_t *p_buffer, int i_input_rate, date_t * );
00134 
00135 /* From filters.c : */
00136 int aout_FiltersCreatePipeline( vlc_object_t *, filter_t **, int *,
00137     const audio_sample_format_t *, const audio_sample_format_t * );
00138 #define aout_FiltersCreatePipeline(o, pv, pc, inf, outf) \
00139         aout_FiltersCreatePipeline(VLC_OBJECT(o), pv, pc, inf, outf)
00140 void aout_FiltersDestroyPipeline( filter_t *const *, unsigned );
00141 void aout_FiltersPlay( filter_t *const *, unsigned, aout_buffer_t ** );
00142 
00143 /* From mixer.c : */
00144 #define aout_MixerNew(o, f) aout_MixerNew(VLC_OBJECT(o), f)
00145 
00146 float aout_ReplayGainSelect(vlc_object_t *, const char *,
00147                             const audio_replay_gain_t *);
00148 #define aout_ReplayGainSelect(o, s, g) \
00149         aout_ReplayGainSelect(VLC_OBJECT(o), s, g)
00150 
00151 static inline void aout_ReplayGainInit(audio_replay_gain_t *restrict d,
00152                                        const audio_replay_gain_t *restrict s)
00153 {
00154     if (s != NULL)
00155         *d = *s;
00156     else
00157         memset (d, 0, sizeof (*d));
00158 }
00159 
00160 
00161 /* From output.c : */
00162 int aout_OutputNew( audio_output_t * p_aout,
00163                     const audio_sample_format_t * p_format );
00164 void aout_OutputPlay( audio_output_t * p_aout, aout_buffer_t * p_buffer );
00165 void aout_OutputPause( audio_output_t * p_aout, bool, mtime_t );
00166 void aout_OutputFlush( audio_output_t * p_aout, bool );
00167 void aout_OutputDelete( audio_output_t * p_aout );
00168 
00169 
00170 /* From common.c : */
00171 audio_output_t *aout_New (vlc_object_t *);
00172 #define aout_New(a) aout_New(VLC_OBJECT(a))
00173 void aout_Destroy (audio_output_t *);
00174 
00175 void aout_FormatsPrint(vlc_object_t *, const char *,
00176                        const audio_sample_format_t *,
00177                        const audio_sample_format_t *);
00178 #define aout_FormatsPrint(o, t, a, b) \
00179         aout_FormatsPrint(VLC_OBJECT(o), t, a, b)
00180 bool aout_ChangeFilterString( vlc_object_t *manager, vlc_object_t *aout,
00181                               const char *var, const char *name, bool b_add );
00182 
00183 /* From dec.c */
00184 int aout_DecNew(audio_output_t *, const audio_sample_format_t *,
00185                 const audio_replay_gain_t *, const aout_request_vout_t *);
00186 void aout_DecDelete(audio_output_t *);
00187 block_t *aout_DecNewBuffer(audio_output_t *, size_t);
00188 void aout_DecDeleteBuffer(audio_output_t *, block_t *);
00189 int aout_DecPlay(audio_output_t *, block_t *, int i_input_rate);
00190 int aout_DecGetResetLost(audio_output_t *);
00191 void aout_DecChangePause(audio_output_t *, bool b_paused, mtime_t i_date);
00192 void aout_DecFlush(audio_output_t *);
00193 bool aout_DecIsEmpty(audio_output_t *);
00194 
00195 void aout_InputRequestRestart(audio_output_t *);
00196 void aout_RequestRestart(audio_output_t *);
00197 void aout_Shutdown (audio_output_t *);
00198 
00199 /* Audio output locking */
00200 
00201 #if !defined (NDEBUG) \
00202  && defined __linux__ && (defined (__i386__) || defined (__x86_64__))
00203 # define AOUT_DEBUG 1
00204 #endif
00205 
00206 #ifdef AOUT_DEBUG
00207 enum
00208 {
00209     OUTPUT_LOCK=1,
00210     VOLUME_LOCK=2,
00211 };
00212 
00213 void aout_lock_check (unsigned);
00214 void aout_unlock_check (unsigned);
00215 
00216 #else
00217 # define aout_lock_check( i )   (void)0
00218 # define aout_unlock_check( i ) (void)0
00219 #endif
00220 
00221 static inline void aout_lock( audio_output_t *p_aout )
00222 {
00223     aout_lock_check( OUTPUT_LOCK );
00224     vlc_mutex_lock( &aout_owner(p_aout)->lock );
00225 }
00226 
00227 static inline void aout_unlock( audio_output_t *p_aout )
00228 {
00229     aout_unlock_check( OUTPUT_LOCK );
00230     vlc_mutex_unlock( &aout_owner(p_aout)->lock );
00231 }
00232 
00233 static inline void aout_lock_volume( audio_output_t *p_aout )
00234 {
00235     aout_lock_check( VOLUME_LOCK );
00236     vlc_mutex_lock( &aout_owner(p_aout)->volume.lock );
00237 }
00238 
00239 static inline void aout_unlock_volume( audio_output_t *p_aout )
00240 {
00241     aout_unlock_check( VOLUME_LOCK );
00242     vlc_mutex_unlock( &aout_owner(p_aout)->volume.lock );
00243 }
00244 
00245 #define aout_assert_locked( aout ) \
00246         vlc_assert_locked( &aout_owner(aout)->lock )
00247 
00248 #endif /* !LIBVLC_AOUT_INTERNAL_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines