vlc_aout.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * audio_output.h : audio output interface
00003  *****************************************************************************
00004  * Copyright (C) 2002-2005 the VideoLAN team
00005  * $Id$
00006  *
00007  * Authors: Christophe Massiot <massiot@via.ecp.fr>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00022  *****************************************************************************/
00023 
00024 #ifndef VLC_AOUT_H
00025 #define VLC_AOUT_H 1
00026 
00027 # ifdef __cplusplus
00028 extern "C" {
00029 # endif
00030 
00031 #include "vlc_es.h"
00032 
00033 #define AOUT_FMTS_IDENTICAL( p_first, p_second ) (                          \
00034     ((p_first)->i_format == (p_second)->i_format)                           \
00035       && ((p_first)->i_rate == (p_second)->i_rate)                          \
00036       && ((p_first)->i_physical_channels == (p_second)->i_physical_channels)\
00037       && ((p_first)->i_original_channels == (p_second)->i_original_channels) )
00038 
00039 /* Check if i_rate == i_rate and i_channels == i_channels */
00040 #define AOUT_FMTS_SIMILAR( p_first, p_second ) (                            \
00041     ((p_first)->i_rate == (p_second)->i_rate)                               \
00042       && ((p_first)->i_physical_channels == (p_second)->i_physical_channels)\
00043       && ((p_first)->i_original_channels == (p_second)->i_original_channels) )
00044 
00045 #ifdef WORDS_BIGENDIAN
00046 #   define AOUT_FMT_S16_NE VLC_FOURCC('s','1','6','b')
00047 #   define AOUT_FMT_U16_NE VLC_FOURCC('u','1','6','b')
00048 #   define AOUT_FMT_S24_NE VLC_FOURCC('s','2','4','b')
00049 #   define AOUT_FMT_SPDIF_NE VLC_FOURCC('s','p','d','b')
00050 #else
00051 #   define AOUT_FMT_S16_NE VLC_FOURCC('s','1','6','l')
00052 #   define AOUT_FMT_U16_NE VLC_FOURCC('u','1','6','l')
00053 #   define AOUT_FMT_S24_NE VLC_FOURCC('s','2','4','l')
00054 #   define AOUT_FMT_SPDIF_NE VLC_FOURCC('s','p','d','i')
00055 #endif
00056 
00057 #define AOUT_FMT_NON_LINEAR( p_format )                                    \
00058     ( ((p_format)->i_format == VLC_FOURCC('s','p','d','i'))                \
00059        || ((p_format)->i_format == VLC_FOURCC('s','p','d','b'))            \
00060        || ((p_format)->i_format == VLC_FOURCC('a','5','2',' '))            \
00061        || ((p_format)->i_format == VLC_FOURCC('d','t','s',' ')) )
00062 
00063 /* This is heavily borrowed from libmad, by Robert Leslie <rob@mars.org> */
00064 /*
00065  * Fixed-point format: 0xABBBBBBB
00066  * A == whole part      (sign + 3 bits)
00067  * B == fractional part (28 bits)
00068  *
00069  * Values are signed two's complement, so the effective range is:
00070  * 0x80000000 to 0x7fffffff
00071  *       -8.0 to +7.9999999962747097015380859375
00072  *
00073  * The smallest representable value is:
00074  * 0x00000001 == 0.0000000037252902984619140625 (i.e. about 3.725e-9)
00075  *
00076  * 28 bits of fractional accuracy represent about
00077  * 8.6 digits of decimal accuracy.
00078  *
00079  * Fixed-point numbers can be added or subtracted as normal
00080  * integers, but multiplication requires shifting the 64-bit result
00081  * from 56 fractional bits back to 28 (and rounding.)
00082  */
00083 typedef int32_t vlc_fixed_t;
00084 #define FIXED32_FRACBITS 28
00085 #define FIXED32_MIN ((vlc_fixed_t) -0x80000000L)
00086 #define FIXED32_MAX ((vlc_fixed_t) +0x7fffffffL)
00087 #define FIXED32_ONE ((vlc_fixed_t) 0x10000000)
00088 
00089 
00090 /*
00091  * Channels descriptions
00092  */
00093 
00094 /* Values available for physical and original channels */
00095 #define AOUT_CHAN_CENTER            0x1
00096 #define AOUT_CHAN_LEFT              0x2
00097 #define AOUT_CHAN_RIGHT             0x4
00098 #define AOUT_CHAN_REARCENTER        0x10
00099 #define AOUT_CHAN_REARLEFT          0x20
00100 #define AOUT_CHAN_REARRIGHT         0x40
00101 #define AOUT_CHAN_MIDDLELEFT        0x100
00102 #define AOUT_CHAN_MIDDLERIGHT       0x200
00103 #define AOUT_CHAN_LFE               0x1000
00104 
00105 /* Values available for original channels only */
00106 #define AOUT_CHAN_DOLBYSTEREO       0x10000
00107 #define AOUT_CHAN_DUALMONO          0x20000
00108 #define AOUT_CHAN_REVERSESTEREO     0x40000
00109 
00110 #define AOUT_CHAN_PHYSMASK          0xFFFF
00111 #define AOUT_CHAN_MAX               9
00112 
00113 /* Values used for the audio-device and audio-channels object variables */
00114 #define AOUT_VAR_MONO               1
00115 #define AOUT_VAR_STEREO             2
00116 #define AOUT_VAR_2F2R               4
00117 #define AOUT_VAR_3F2R               5
00118 #define AOUT_VAR_5_1                6
00119 #define AOUT_VAR_6_1                7
00120 #define AOUT_VAR_7_1                8
00121 #define AOUT_VAR_SPDIF              10
00122 
00123 #define AOUT_VAR_CHAN_STEREO        1
00124 #define AOUT_VAR_CHAN_RSTEREO       2
00125 #define AOUT_VAR_CHAN_LEFT          3
00126 #define AOUT_VAR_CHAN_RIGHT         4
00127 #define AOUT_VAR_CHAN_DOLBYS        5
00128 
00129 /*****************************************************************************
00130  * Main audio output structures
00131  *****************************************************************************/
00132 
00133 /** audio output buffer */
00134 struct aout_buffer_t
00135 {
00136     uint8_t *               p_buffer;
00137     int                     i_alloc_type;
00138     /* i_size is the real size of the buffer (used for debug ONLY), i_nb_bytes
00139      * is the number of significative bytes in it. */
00140     size_t                  i_size, i_nb_bytes;
00141     unsigned int            i_nb_samples;
00142     mtime_t                 start_date, end_date;
00143     bool              b_discontinuity; /* Set on discontinuity (for non pcm stream) */
00144 
00145     struct aout_buffer_t *  p_next;
00146 
00147     /** Private data (aout_buffer_t will disappear soon so no need for an
00148      * aout_buffer_sys_t type) */
00149     void * p_sys;
00150 
00151     /** This way the release can be overloaded */
00152     void (*pf_release)( aout_buffer_t * );
00153 };
00154 
00155 #define aout_BufferFree( p_buffer ) do {                                    \
00156     if( p_buffer != NULL && (p_buffer)->i_alloc_type == AOUT_ALLOC_HEAP )   \
00157     {                                                                       \
00158         free( p_buffer );                                                   \
00159     }                                                                       \
00160     p_buffer = NULL; } while(0)
00161 
00162 /* Size of a frame for S/PDIF output. */
00163 #define AOUT_SPDIF_SIZE 6144
00164 
00165 /* Number of samples in an A/52 frame. */
00166 #define A52_FRAME_NB 1536
00167 
00168 /* Max input rate factor (1/4 -> 4) */
00169 #define AOUT_MAX_INPUT_RATE (4)
00170 
00171 /** date incrementation helper structure without long-term
00172  * rounding errors
00173  */
00174 struct audio_date_t
00175 {
00176     mtime_t  date;
00177     uint32_t i_divider;
00178     uint32_t i_remainder;
00179 };
00180 
00181 /** allocation of memory in the audio output */
00182 typedef struct aout_alloc_t
00183 {
00184     int                     i_alloc_type;
00185     int                     i_bytes_per_sec;
00186 } aout_alloc_t;
00187 
00188 #define AOUT_ALLOC_NONE     0
00189 #define AOUT_ALLOC_STACK    1
00190 #define AOUT_ALLOC_HEAP     2
00191 
00192 /** audio output mixer */
00193 typedef struct aout_mixer_t
00194 {
00195     audio_sample_format_t   mixer;
00196     aout_alloc_t            output_alloc;
00197 
00198     module_t *              p_module;
00199     struct aout_mixer_sys_t * p_sys;
00200     void                 (* pf_do_work)( struct aout_instance_t *,
00201                                          struct aout_buffer_t * );
00202 
00203     /** If b_error == 1, there is no mixer. */
00204     bool              b_error;
00205     /** Multiplier used to raise or lower the volume of the sound in
00206      * software. Beware, this creates sound distortion and should be avoided
00207      * as much as possible. This isn't available for non-float32 mixer. */
00208     float                   f_multiplier;
00209 } aout_mixer_t;
00210 
00211 /** audio output buffer FIFO */
00212 struct aout_fifo_t
00213 {
00214     aout_buffer_t *         p_first;
00215     aout_buffer_t **        pp_last;
00216     audio_date_t            end_date;
00217 };
00218 
00219 /** audio output filter */
00220 struct aout_filter_t
00221 {
00222     VLC_COMMON_MEMBERS
00223 
00224     audio_sample_format_t   input;
00225     audio_sample_format_t   output;
00226     aout_alloc_t            output_alloc;
00227 
00228     module_t *              p_module;
00229     struct aout_filter_sys_t * p_sys;
00230     void                 (* pf_do_work)( struct aout_instance_t *,
00231                                          struct aout_filter_t *,
00232                                          struct aout_buffer_t *,
00233                                          struct aout_buffer_t * );
00234     bool              b_in_place;
00235     bool              b_continuity;
00236 };
00237 
00238 #define AOUT_RESAMPLING_NONE     0
00239 #define AOUT_RESAMPLING_UP       1
00240 #define AOUT_RESAMPLING_DOWN     2
00241 /** an input stream for the audio output */
00242 struct aout_input_t
00243 {
00244     /* When this lock is taken, the pipeline cannot be changed by a
00245      * third-party. */
00246     vlc_mutex_t             lock;
00247 
00248     /* The input thread that spawned this input */
00249     input_thread_t         *p_input_thread;
00250 
00251     audio_sample_format_t   input;
00252     aout_alloc_t            input_alloc;
00253 
00254     /* pre-filters */
00255     aout_filter_t *         pp_filters[AOUT_MAX_FILTERS];
00256     int                     i_nb_filters;
00257 
00258     aout_filter_t *         p_playback_rate_filter;
00259 
00260     /* resamplers */
00261     aout_filter_t *         pp_resamplers[AOUT_MAX_FILTERS];
00262     int                     i_nb_resamplers;
00263     int                     i_resampling_type;
00264     mtime_t                 i_resamp_start_date;
00265     int                     i_resamp_start_drift;
00266 
00267     aout_fifo_t             fifo;
00268 
00269     /* Mixer information */
00270     uint8_t *               p_first_byte_to_mix;
00271     audio_replay_gain_t     replay_gain;
00272     float                   f_multiplier;
00273 
00274     /* If b_restart == 1, the input pipeline will be re-created. */
00275     bool              b_restart;
00276 
00277     /* If b_error == 1, there is no input pipeline. */
00278     bool              b_error;
00279 
00280     /* Did we just change the output format? (expect buffer inconsistencies) */
00281     bool              b_changed;
00282 
00283     /* last rate from input */
00284     int                     i_last_input_rate;
00285     /* internal caching delay from input */
00286     int                     i_pts_delay;
00287     /* desynchronisation delay request by the user */
00288     int                     i_desync;
00289 
00290 };
00291 
00292 /** an output stream for the audio output */
00293 typedef struct aout_output_t
00294 {
00295     audio_sample_format_t   output;
00296     /* Indicates whether the audio output is currently starving, to avoid
00297      * printing a 1,000 "output is starving" messages. */
00298     bool              b_starving;
00299 
00300     /* post-filters */
00301     aout_filter_t *         pp_filters[AOUT_MAX_FILTERS];
00302     int                     i_nb_filters;
00303 
00304     aout_fifo_t             fifo;
00305 
00306     struct module_t *       p_module;
00307     struct aout_sys_t *     p_sys;
00308     void                 (* pf_play)( aout_instance_t * );
00309     int                  (* pf_volume_get )( aout_instance_t *, audio_volume_t * );
00310     int                  (* pf_volume_set )( aout_instance_t *, audio_volume_t );
00311     int                  (* pf_volume_infos )( aout_instance_t *, audio_volume_t * );
00312     int                     i_nb_samples;
00313 
00314     /* Current volume for the output - it's just a placeholder, the plug-in
00315      * may or may not use it. */
00316     audio_volume_t          i_volume;
00317 
00318     /* If b_error == 1, there is no audio output pipeline. */
00319     bool              b_error;
00320 } aout_output_t;
00321 
00322 /** audio output thread descriptor */
00323 struct aout_instance_t
00324 {
00325     VLC_COMMON_MEMBERS
00326 
00327     /* Locks : please note that if you need several of these locks, it is
00328      * mandatory (to avoid deadlocks) to take them in the following order :
00329      * mixer_lock, p_input->lock, output_fifo_lock, input_fifos_lock.
00330      * --Meuuh */
00331     /* When input_fifos_lock is taken, none of the p_input->fifo structures
00332      * can be read or modified by a third-party thread. */
00333     vlc_mutex_t             input_fifos_lock;
00334     /* When mixer_lock is taken, all decoder threads willing to mix a
00335      * buffer must wait until it is released. The output pipeline cannot
00336      * be modified. No input stream can be added or removed. */
00337     vlc_mutex_t             mixer_lock;
00338     /* When output_fifo_lock is taken, the p_aout->output.fifo structure
00339      * cannot be read or written  by a third-party thread. */
00340     vlc_mutex_t             output_fifo_lock;
00341 
00342     /* Input streams & pre-filters */
00343     aout_input_t *          pp_inputs[AOUT_MAX_INPUTS];
00344     int                     i_nb_inputs;
00345 
00346     /* Mixer */
00347     aout_mixer_t            mixer;
00348 
00349     /* Output plug-in */
00350     aout_output_t           output;
00351 };
00352 
00353 /*****************************************************************************
00354  * Prototypes
00355  *****************************************************************************/
00356 
00357 /* From common.c : */
00358 VLC_EXPORT( void, aout_DateInit, ( audio_date_t *, uint32_t ) );
00359 VLC_EXPORT( void, aout_DateSet, ( audio_date_t *, mtime_t ) );
00360 VLC_EXPORT( void, aout_DateMove, ( audio_date_t *, mtime_t ) );
00361 VLC_EXPORT( mtime_t, aout_DateGet, ( const audio_date_t * ) );
00362 VLC_EXPORT( mtime_t, aout_DateIncrement, ( audio_date_t *, uint32_t ) );
00363 
00364 VLC_EXPORT( aout_buffer_t *, aout_OutputNextBuffer, ( aout_instance_t *, mtime_t, bool ) );
00365 
00366 VLC_EXPORT( int, aout_CheckChannelReorder, ( const uint32_t *, const uint32_t *, uint32_t, int, int * ) );
00367 VLC_EXPORT( void, aout_ChannelReorder, ( uint8_t *, int, int, const int *, int ) );
00368 
00369 VLC_EXPORT( unsigned int, aout_FormatNbChannels, ( const audio_sample_format_t * p_format ) );
00370 VLC_EXPORT( unsigned int, aout_BitsPerSample, ( vlc_fourcc_t i_format ) );
00371 VLC_EXPORT( void, aout_FormatPrepare, ( audio_sample_format_t * p_format ) );
00372 VLC_EXPORT( void, aout_FormatPrint, ( aout_instance_t * p_aout, const char * psz_text, const audio_sample_format_t * p_format ) );
00373 VLC_EXPORT( const char *, aout_FormatPrintChannels, ( const audio_sample_format_t * ) );
00374 
00375 VLC_EXPORT( mtime_t, aout_FifoFirstDate, ( aout_instance_t *, aout_fifo_t * ) );
00376 VLC_EXPORT( aout_buffer_t *, aout_FifoPop, ( aout_instance_t * p_aout, aout_fifo_t * p_fifo ) );
00377 
00378 /* From intf.c : */
00379 VLC_EXPORT( void, aout_VolumeSoftInit, ( aout_instance_t * ) );
00380 VLC_EXPORT( void, aout_VolumeNoneInit, ( aout_instance_t * ) );
00381 #define aout_VolumeGet(a, b) __aout_VolumeGet(VLC_OBJECT(a), b)
00382 VLC_EXPORT( int, __aout_VolumeGet, ( vlc_object_t *, audio_volume_t * ) );
00383 #define aout_VolumeSet(a, b) __aout_VolumeSet(VLC_OBJECT(a), b)
00384 VLC_EXPORT( int, __aout_VolumeSet, ( vlc_object_t *, audio_volume_t ) );
00385 #define aout_VolumeInfos(a, b) __aout_VolumeInfos(VLC_OBJECT(a), b)
00386 VLC_EXPORT( int, __aout_VolumeInfos, ( vlc_object_t *, audio_volume_t * ) );
00387 #define aout_VolumeUp(a, b, c) __aout_VolumeUp(VLC_OBJECT(a), b, c)
00388 VLC_EXPORT( int, __aout_VolumeUp, ( vlc_object_t *, int, audio_volume_t * ) );
00389 #define aout_VolumeDown(a, b, c) __aout_VolumeDown(VLC_OBJECT(a), b, c)
00390 VLC_EXPORT( int, __aout_VolumeDown, ( vlc_object_t *, int, audio_volume_t * ) );
00391 #define aout_VolumeMute(a, b) __aout_VolumeMute(VLC_OBJECT(a), b)
00392 VLC_EXPORT( int, __aout_VolumeMute, ( vlc_object_t *, audio_volume_t * ) );
00393 VLC_EXPORT( int, aout_FindAndRestart, ( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * ) );
00394 VLC_EXPORT( int, aout_ChannelsRestart, ( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * ) );
00395 
00396 VLC_EXPORT( void, aout_EnableFilter, (vlc_object_t *, const char *, bool ));
00397 
00398 #define aout_VisualNext(a) aout_VisualChange( VLC_OBJECT(a),1 )
00399 #define aout_VisualPrev(a) aout_VisualChange( VLC_OBJECT(a),-1 )
00400 
00401 VLC_EXPORT( char *, aout_VisualChange, (vlc_object_t *, int ) );
00402 
00403 # ifdef __cplusplus
00404 }
00405 # endif
00406 
00407 #endif /* _VLC_AOUT_H */

Generated on Wed Aug 13 08:02:37 2008 for VLC by  doxygen 1.5.1