Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

aout_internal.h

00001 /*****************************************************************************
00002  * aout_internal.h : internal defines for audio output
00003  *****************************************************************************
00004  * Copyright (C) 2002 the VideoLAN team
00005  * $Id: aout_internal.h 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Christophe Massiot <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 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 General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * aout_alloc_t : allocation of memory in the audio output
00026  *****************************************************************************/
00027 typedef struct aout_alloc_t
00028 {
00029     int                     i_alloc_type;
00030     int                     i_bytes_per_sec;
00031 } aout_alloc_t;
00032 
00033 #define AOUT_ALLOC_NONE     0
00034 #define AOUT_ALLOC_STACK    1
00035 #define AOUT_ALLOC_HEAP     2
00036 
00037 #ifdef HAVE_ALLOCA
00038 #   define ALLOCA_TEST( p_alloc, p_new_buffer )                             \
00039         if ( (p_alloc)->i_alloc_type == AOUT_ALLOC_STACK )                  \
00040         {                                                                   \
00041             (p_new_buffer) = alloca( i_alloc_size + sizeof(aout_buffer_t) );\
00042             i_alloc_type = AOUT_ALLOC_STACK;                                \
00043         }                                                                   \
00044         else
00045 #else
00046 #   define ALLOCA_TEST( p_alloc, p_new_buffer )
00047 #endif
00048 
00049 #define aout_BufferAlloc( p_alloc, i_nb_usec, p_previous_buffer,            \
00050                           p_new_buffer )                                    \
00051     if ( (p_alloc)->i_alloc_type == AOUT_ALLOC_NONE )                       \
00052     {                                                                       \
00053         (p_new_buffer) = p_previous_buffer;                                 \
00054     }                                                                       \
00055     else                                                                    \
00056     {                                                                       \
00057         int i_alloc_size, i_alloc_type;                                     \
00058         i_alloc_size = (int)( (uint64_t)(p_alloc)->i_bytes_per_sec          \
00059                                             * (i_nb_usec) / 1000000 + 1 );  \
00060         ALLOCA_TEST( p_alloc, p_new_buffer )                                \
00061         {                                                                   \
00062             (p_new_buffer) = malloc( i_alloc_size + sizeof(aout_buffer_t) );\
00063             i_alloc_type = AOUT_ALLOC_HEAP;                                 \
00064         }                                                                   \
00065         if ( p_new_buffer != NULL )                                         \
00066         {                                                                   \
00067             (p_new_buffer)->i_alloc_type = i_alloc_type;                    \
00068             (p_new_buffer)->i_size = i_alloc_size;                          \
00069             (p_new_buffer)->p_buffer = (byte_t *)(p_new_buffer)             \
00070                                          + sizeof(aout_buffer_t);           \
00071             if ( (p_previous_buffer) != NULL )                              \
00072             {                                                               \
00073                 (p_new_buffer)->start_date =                                \
00074                            ((aout_buffer_t *)p_previous_buffer)->start_date;\
00075                 (p_new_buffer)->end_date =                                  \
00076                            ((aout_buffer_t *)p_previous_buffer)->end_date;  \
00077             }                                                               \
00078         }                                                                   \
00079         /* we'll keep that for a while --Meuuh */                           \
00080         /* else printf("%s:%d\n", __FILE__, __LINE__); */                   \
00081     }
00082 
00083 #define aout_BufferFree( p_buffer )                                         \
00084     if ( (p_buffer)->i_alloc_type == AOUT_ALLOC_HEAP )                      \
00085     {                                                                       \
00086         free( p_buffer );                                                   \
00087     }
00088 
00089 /*****************************************************************************
00090  * aout_fifo_t : audio output buffer FIFO
00091  *****************************************************************************/
00092 struct aout_fifo_t
00093 {
00094     aout_buffer_t *         p_first;
00095     aout_buffer_t **        pp_last;
00096     audio_date_t            end_date;
00097 };
00098 
00099 /*****************************************************************************
00100  * aout_filter_t : audio output filter
00101  *****************************************************************************/
00102 struct aout_filter_t
00103 {
00104     VLC_COMMON_MEMBERS
00105 
00106     audio_sample_format_t   input;
00107     audio_sample_format_t   output;
00108     aout_alloc_t            output_alloc;
00109 
00110     module_t *              p_module;
00111     struct aout_filter_sys_t * p_sys;
00112     void                 (* pf_do_work)( struct aout_instance_t *,
00113                                          struct aout_filter_t *,
00114                                          struct aout_buffer_t *,
00115                                          struct aout_buffer_t * );
00116     vlc_bool_t              b_in_place;
00117     vlc_bool_t              b_continuity;
00118 };
00119 
00120 /*****************************************************************************
00121  * aout_mixer_t : audio output mixer
00122  *****************************************************************************/
00123 typedef struct aout_mixer_t
00124 {
00125     audio_sample_format_t   mixer;
00126     aout_alloc_t            output_alloc;
00127 
00128     module_t *              p_module;
00129     struct aout_mixer_sys_t * p_sys;
00130     void                 (* pf_do_work)( struct aout_instance_t *,
00131                                          struct aout_buffer_t * );
00132 
00133     /* If b_error == 1, there is no mixer. */
00134     vlc_bool_t              b_error;
00135     /* Multiplier used to raise or lower the volume of the sound in
00136      * software. Beware, this creates sound distortion and should be avoided
00137      * as much as possible. This isn't available for non-float32 mixer. */
00138     float                   f_multiplier;
00139 } aout_mixer_t;
00140 
00141 /*****************************************************************************
00142  * aout_input_t : input stream for the audio output
00143  *****************************************************************************/
00144 #define AOUT_RESAMPLING_NONE     0
00145 #define AOUT_RESAMPLING_UP       1
00146 #define AOUT_RESAMPLING_DOWN     2
00147 struct aout_input_t
00148 {
00149     /* When this lock is taken, the pipeline cannot be changed by a
00150      * third-party. */
00151     vlc_mutex_t             lock;
00152 
00153     audio_sample_format_t   input;
00154     aout_alloc_t            input_alloc;
00155 
00156     /* pre-filters */
00157     aout_filter_t *         pp_filters[AOUT_MAX_FILTERS];
00158     int                     i_nb_filters;
00159 
00160     /* resamplers */
00161     aout_filter_t *         pp_resamplers[AOUT_MAX_FILTERS];
00162     int                     i_nb_resamplers;
00163     int                     i_resampling_type;
00164     mtime_t                 i_resamp_start_date;
00165     int                     i_resamp_start_drift;
00166 
00167     aout_fifo_t             fifo;
00168 
00169     /* Mixer information */
00170     byte_t *                p_first_byte_to_mix;
00171 
00172     /* If b_restart == 1, the input pipeline will be re-created. */
00173     vlc_bool_t              b_restart;
00174 
00175     /* If b_error == 1, there is no input pipeline. */
00176     vlc_bool_t              b_error;
00177 
00178     /* Did we just change the output format? (expect buffer inconsistencies) */
00179     vlc_bool_t              b_changed;
00180 
00181     /* internal caching delay from input */
00182     int                     i_pts_delay;
00183     /* desynchronisation delay request by the user */
00184     int                     i_desync;
00185 
00186 };
00187 
00188 /*****************************************************************************
00189  * aout_output_t : output stream for the audio output
00190  *****************************************************************************/
00191 typedef struct aout_output_t
00192 {
00193     audio_sample_format_t   output;
00194     /* Indicates whether the audio output is currently starving, to avoid
00195      * printing a 1,000 "output is starving" messages. */
00196     vlc_bool_t              b_starving;
00197 
00198     /* post-filters */
00199     aout_filter_t *         pp_filters[AOUT_MAX_FILTERS];
00200     int                     i_nb_filters;
00201 
00202     aout_fifo_t             fifo;
00203 
00204     struct module_t *       p_module;
00205     struct aout_sys_t *     p_sys;
00206     void                 (* pf_play)( aout_instance_t * );
00207     int                  (* pf_volume_get )( aout_instance_t *, audio_volume_t * );
00208     int                  (* pf_volume_set )( aout_instance_t *, audio_volume_t );
00209     int                  (* pf_volume_infos )( aout_instance_t *, audio_volume_t * );
00210     int                     i_nb_samples;
00211 
00212     /* Current volume for the output - it's just a placeholder, the plug-in
00213      * may or may not use it. */
00214     audio_volume_t          i_volume;
00215 
00216     /* If b_error == 1, there is no audio output pipeline. */
00217     vlc_bool_t              b_error;
00218 } aout_output_t;
00219 
00220 /*****************************************************************************
00221  * aout_instance_t : audio output thread descriptor
00222  *****************************************************************************/
00223 struct aout_instance_t
00224 {
00225     VLC_COMMON_MEMBERS
00226 
00227     /* Locks : please note that if you need several of these locks, it is
00228      * mandatory (to avoid deadlocks) to take them in the following order :
00229      * mixer_lock, p_input->lock, output_fifo_lock, input_fifos_lock.
00230      * --Meuuh */
00231     /* When input_fifos_lock is taken, none of the p_input->fifo structures
00232      * can be read or modified by a third-party thread. */
00233     vlc_mutex_t             input_fifos_lock;
00234     /* When mixer_lock is taken, all decoder threads willing to mix a
00235      * buffer must wait until it is released. The output pipeline cannot
00236      * be modified. No input stream can be added or removed. */
00237     vlc_mutex_t             mixer_lock;
00238     /* When output_fifo_lock is taken, the p_aout->output.fifo structure
00239      * cannot be read or written  by a third-party thread. */
00240     vlc_mutex_t             output_fifo_lock;
00241 
00242     /* Input streams & pre-filters */
00243     aout_input_t *          pp_inputs[AOUT_MAX_INPUTS];
00244     int                     i_nb_inputs;
00245 
00246     /* Mixer */
00247     aout_mixer_t            mixer;
00248 
00249     /* Output plug-in */
00250     aout_output_t           output;
00251 };
00252 
00253 /*****************************************************************************
00254  * Prototypes
00255  *****************************************************************************/
00256 /* From input.c : */
00257 int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input );
00258 int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input );
00259 int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
00260                     aout_buffer_t * p_buffer );
00261 
00262 /* From filters.c : */
00263 VLC_EXPORT( 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 ) );
00264 VLC_EXPORT( void, aout_FiltersDestroyPipeline, ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters ) );
00265 VLC_EXPORT( void, aout_FiltersPlay, ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_buffer_t ** pp_input_buffer ) );
00266 void aout_FiltersHintBuffers( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_alloc_t * p_first_alloc );
00267 
00268 /* From mixer.c : */
00269 int aout_MixerNew( aout_instance_t * p_aout );
00270 void aout_MixerDelete( aout_instance_t * p_aout );
00271 void aout_MixerRun( aout_instance_t * p_aout );
00272 int aout_MixerMultiplierSet( aout_instance_t * p_aout, float f_multiplier );
00273 int aout_MixerMultiplierGet( aout_instance_t * p_aout, float * pf_multiplier );
00274 
00275 /* From output.c : */
00276 int aout_OutputNew( aout_instance_t * p_aout,
00277                     audio_sample_format_t * p_format );
00278 void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer );
00279 void aout_OutputDelete( aout_instance_t * p_aout );
00280 VLC_EXPORT( aout_buffer_t *, aout_OutputNextBuffer, ( aout_instance_t *, mtime_t, vlc_bool_t ) );
00281 
00282 /* From common.c : */
00283 VLC_EXPORT( unsigned int, aout_FormatNbChannels, ( const audio_sample_format_t * p_format ) );
00284 VLC_EXPORT( void, aout_FormatPrepare, ( audio_sample_format_t * p_format ) );
00285 VLC_EXPORT( void, aout_FormatPrint, ( aout_instance_t * p_aout, const char * psz_text, const audio_sample_format_t * p_format ) );
00286 VLC_EXPORT( 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 ) );
00287 VLC_EXPORT( const char *, aout_FormatPrintChannels, ( const audio_sample_format_t * ) );
00288 void aout_FifoInit( aout_instance_t *, aout_fifo_t *, uint32_t );
00289 mtime_t aout_FifoNextStart( aout_instance_t *, aout_fifo_t * );
00290 void aout_FifoPush( aout_instance_t *, aout_fifo_t *, aout_buffer_t * );
00291 void aout_FifoSet( aout_instance_t *, aout_fifo_t *, mtime_t );
00292 void aout_FifoMoveDates( aout_instance_t *, aout_fifo_t *, mtime_t );
00293 VLC_EXPORT( aout_buffer_t *, aout_FifoPop, ( aout_instance_t * p_aout, aout_fifo_t * p_fifo ) );
00294 void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo );
00295 VLC_EXPORT( mtime_t, aout_FifoFirstDate, ( aout_instance_t *, aout_fifo_t * ) );
00296 
00297 /* From intf.c :*/
00298 VLC_EXPORT( void, aout_VolumeSoftInit, ( aout_instance_t * ) );
00299 int aout_VolumeSoftGet( aout_instance_t *, audio_volume_t * );
00300 int aout_VolumeSoftSet( aout_instance_t *, audio_volume_t );
00301 int aout_VolumeSoftInfos( aout_instance_t *, audio_volume_t * );
00302 VLC_EXPORT( void, aout_VolumeNoneInit, ( aout_instance_t * ) );
00303 int aout_VolumeNoneGet( aout_instance_t *, audio_volume_t * );
00304 int aout_VolumeNoneSet( aout_instance_t *, audio_volume_t );
00305 int aout_VolumeNoneInfos( aout_instance_t *, audio_volume_t * );
00306 

Generated on Tue Dec 20 10:14:18 2005 for vlc-0.8.4a by  doxygen 1.4.2