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: 4e5007678a039834ea4408c29af9333b37936439 $
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 /**
00028  * \file
00029  * This file defines functions, structures and macros for audio output object
00030  */
00031 
00032 # ifdef __cplusplus
00033 extern "C" {
00034 # endif
00035 
00036 #include "vlc_es.h"
00037 
00038 #define AOUT_FMTS_IDENTICAL( p_first, p_second ) (                          \
00039     ((p_first)->i_format == (p_second)->i_format)                           \
00040       && ((p_first)->i_rate == (p_second)->i_rate)                          \
00041       && ((p_first)->i_physical_channels == (p_second)->i_physical_channels)\
00042       && ((p_first)->i_original_channels == (p_second)->i_original_channels) )
00043 
00044 /* Check if i_rate == i_rate and i_channels == i_channels */
00045 #define AOUT_FMTS_SIMILAR( p_first, p_second ) (                            \
00046     ((p_first)->i_rate == (p_second)->i_rate)                               \
00047       && ((p_first)->i_physical_channels == (p_second)->i_physical_channels)\
00048       && ((p_first)->i_original_channels == (p_second)->i_original_channels) )
00049 
00050 #define VLC_CODEC_SPDIFL VLC_FOURCC('s','p','d','i')
00051 #define VLC_CODEC_SPDIFB VLC_FOURCC('s','p','d','b')
00052 
00053 #define AOUT_FMT_NON_LINEAR( p_format )                 \
00054     ( ((p_format)->i_format == VLC_CODEC_SPDIFL)       \
00055        || ((p_format)->i_format == VLC_CODEC_SPDIFB)   \
00056        || ((p_format)->i_format == VLC_CODEC_A52)       \
00057        || ((p_format)->i_format == VLC_CODEC_DTS) )
00058 
00059 /* This is heavily borrowed from libmad, by Robert Leslie <rob@mars.org> */
00060 /*
00061  * Fixed-point format: 0xABBBBBBB
00062  * A == whole part      (sign + 3 bits)
00063  * B == fractional part (28 bits)
00064  *
00065  * Values are signed two's complement, so the effective range is:
00066  * 0x80000000 to 0x7fffffff
00067  *       -8.0 to +7.9999999962747097015380859375
00068  *
00069  * The smallest representable value is:
00070  * 0x00000001 == 0.0000000037252902984619140625 (i.e. about 3.725e-9)
00071  *
00072  * 28 bits of fractional accuracy represent about
00073  * 8.6 digits of decimal accuracy.
00074  *
00075  * Fixed-point numbers can be added or subtracted as normal
00076  * integers, but multiplication requires shifting the 64-bit result
00077  * from 56 fractional bits back to 28 (and rounding.)
00078  */
00079 typedef int32_t vlc_fixed_t;
00080 #define FIXED32_FRACBITS 28
00081 #define FIXED32_MIN ((vlc_fixed_t) -0x80000000L)
00082 #define FIXED32_MAX ((vlc_fixed_t) +0x7fffffffL)
00083 #define FIXED32_ONE ((vlc_fixed_t) 0x10000000)
00084 
00085 /*
00086  * Channels descriptions
00087  */
00088 
00089 /* Values available for physical and original channels */
00090 #define AOUT_CHAN_CENTER            0x1
00091 #define AOUT_CHAN_LEFT              0x2
00092 #define AOUT_CHAN_RIGHT             0x4
00093 #define AOUT_CHAN_REARCENTER        0x10
00094 #define AOUT_CHAN_REARLEFT          0x20
00095 #define AOUT_CHAN_REARRIGHT         0x40
00096 #define AOUT_CHAN_MIDDLELEFT        0x100
00097 #define AOUT_CHAN_MIDDLERIGHT       0x200
00098 #define AOUT_CHAN_LFE               0x1000
00099 
00100 /* Values available for original channels only */
00101 #define AOUT_CHAN_DOLBYSTEREO       0x10000
00102 #define AOUT_CHAN_DUALMONO          0x20000
00103 #define AOUT_CHAN_REVERSESTEREO     0x40000
00104 
00105 #define AOUT_CHAN_PHYSMASK          0xFFFF
00106 #define AOUT_CHAN_MAX               9
00107 
00108 /* Values used for the audio-device and audio-channels object variables */
00109 #define AOUT_VAR_MONO               1
00110 #define AOUT_VAR_STEREO             2
00111 #define AOUT_VAR_2F2R               4
00112 #define AOUT_VAR_3F2R               5
00113 #define AOUT_VAR_5_1                6
00114 #define AOUT_VAR_6_1                7
00115 #define AOUT_VAR_7_1                8
00116 #define AOUT_VAR_SPDIF              10
00117 
00118 #define AOUT_VAR_CHAN_STEREO        1
00119 #define AOUT_VAR_CHAN_RSTEREO       2
00120 #define AOUT_VAR_CHAN_LEFT          3
00121 #define AOUT_VAR_CHAN_RIGHT         4
00122 #define AOUT_VAR_CHAN_DOLBYS        5
00123 
00124 /*****************************************************************************
00125  * Main audio output structures
00126  *****************************************************************************/
00127 
00128 #define aout_BufferFree( buffer ) block_Release( buffer )
00129 
00130 /* Size of a frame for S/PDIF output. */
00131 #define AOUT_SPDIF_SIZE 6144
00132 
00133 /* Number of samples in an A/52 frame. */
00134 #define A52_FRAME_NB 1536
00135 
00136 /* Max input rate factor (1/4 -> 4) */
00137 #define AOUT_MAX_INPUT_RATE (4)
00138 
00139 /** allocation of memory in the audio output */
00140 typedef struct aout_alloc_t
00141 {
00142     bool                    b_alloc;
00143     int                     i_bytes_per_sec;
00144 } aout_alloc_t;
00145 
00146 /** audio output buffer FIFO */
00147 struct aout_fifo_t
00148 {
00149     aout_buffer_t *         p_first;
00150     aout_buffer_t **        pp_last;
00151     date_t                  end_date;
00152 };
00153 
00154 /* FIXME to remove once aout.h is cleaned a bit more */
00155 #include <vlc_aout_mixer.h>
00156 #include <vlc_block.h>
00157 
00158 /** audio output filter */
00159 typedef struct aout_filter_owner_sys_t aout_filter_owner_sys_t;
00160 typedef struct aout_filter_sys_t aout_filter_sys_t;
00161 struct aout_filter_t
00162 {
00163     VLC_COMMON_MEMBERS
00164 
00165     module_t *              p_module;
00166     aout_filter_sys_t       *p_sys;
00167 
00168     es_format_t             fmt_in;
00169     es_format_t             fmt_out;
00170 
00171     aout_alloc_t            output_alloc;
00172 
00173     bool                    b_in_place;
00174 
00175     void                    (*pf_do_work)( aout_instance_t *, aout_filter_t *,
00176                                            aout_buffer_t *, aout_buffer_t * );
00177 
00178     /* Private structure for the owner of the filter */
00179     aout_filter_owner_sys_t *p_owner;
00180 };
00181 
00182 #define AOUT_RESAMPLING_NONE     0
00183 #define AOUT_RESAMPLING_UP       1
00184 #define AOUT_RESAMPLING_DOWN     2
00185 
00186 /** an output stream for the audio output */
00187 typedef struct aout_output_t
00188 {
00189     audio_sample_format_t   output;
00190     /* Indicates whether the audio output is currently starving, to avoid
00191      * printing a 1,000 "output is starving" messages. */
00192     bool              b_starving;
00193 
00194     /* post-filters */
00195     filter_t *              pp_filters[AOUT_MAX_FILTERS];
00196     int                     i_nb_filters;
00197 
00198     aout_fifo_t             fifo;
00199 
00200     struct module_t *       p_module;
00201     struct aout_sys_t *     p_sys;
00202     void                 (* pf_play)( aout_instance_t * );
00203     int                  (* pf_volume_get )( aout_instance_t *, audio_volume_t * );
00204     int                  (* pf_volume_set )( aout_instance_t *, audio_volume_t );
00205     int                     i_nb_samples;
00206 
00207     /* Current volume for the output - it's just a placeholder, the plug-in
00208      * may or may not use it. */
00209     audio_volume_t          i_volume;
00210 
00211     /* If b_error == 1, there is no audio output pipeline. */
00212     bool              b_error;
00213 } aout_output_t;
00214 
00215 /** audio output thread descriptor */
00216 struct aout_instance_t
00217 {
00218     VLC_COMMON_MEMBERS
00219 
00220     /* Locks : please note that if you need several of these locks, it is
00221      * mandatory (to avoid deadlocks) to take them in the following order :
00222      * mixer_lock, p_input->lock, output_fifo_lock, input_fifos_lock.
00223      * --Meuuh */
00224     /* When input_fifos_lock is taken, none of the p_input->fifo structures
00225      * can be read or modified by a third-party thread. */
00226     vlc_mutex_t             input_fifos_lock;
00227     /* When mixer_lock is taken, all decoder threads willing to mix a
00228      * buffer must wait until it is released. The output pipeline cannot
00229      * be modified. No input stream can be added or removed. */
00230     vlc_mutex_t             mixer_lock;
00231     /* When output_fifo_lock is taken, the p_aout->output.fifo structure
00232      * cannot be read or written  by a third-party thread. */
00233     vlc_mutex_t             output_fifo_lock;
00234 
00235     /* Input streams & pre-filters */
00236     aout_input_t *          pp_inputs[AOUT_MAX_INPUTS];
00237     int                     i_nb_inputs;
00238 
00239     /* Mixer */
00240     audio_sample_format_t   mixer_format;
00241     aout_alloc_t            mixer_allocation;
00242     float                   mixer_multiplier;
00243     aout_mixer_t            *p_mixer;
00244 
00245     /* Output plug-in */
00246     aout_output_t           output;
00247 };
00248 
00249 /**
00250  * It describes the audio channel order VLC except.
00251  */
00252 static const uint32_t pi_vlc_chan_order_wg4[] =
00253 {
00254     AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
00255     AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT,
00256     AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, AOUT_CHAN_REARCENTER,
00257     AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0
00258 };
00259 
00260 /*****************************************************************************
00261  * Prototypes
00262  *****************************************************************************/
00263 
00264 VLC_EXPORT( aout_buffer_t *, aout_OutputNextBuffer, ( aout_instance_t *, mtime_t, bool ) LIBVLC_USED );
00265 
00266 /**
00267  * This function computes the reordering needed to go from pi_chan_order_in to
00268  * pi_chan_order_out.
00269  * If pi_chan_order_in or pi_chan_order_out is NULL, it will assume that vlc
00270  * internal (WG4) order is requested.
00271  */
00272 VLC_EXPORT( int, aout_CheckChannelReorder, ( const uint32_t *pi_chan_order_in, const uint32_t *pi_chan_order_out, uint32_t i_channel_mask, int i_channels, int *pi_chan_table ) );
00273 VLC_EXPORT( void, aout_ChannelReorder, ( uint8_t *, int, int, const int *, int ) );
00274 
00275 /**
00276  * This fonction will compute the extraction parameter into pi_selection to go
00277  * from i_channels with their type given by pi_order_src[] into the order
00278  * describe by pi_order_dst.
00279  * It will also set :
00280  * - *pi_channels as the number of channels that will be extracted which is
00281  * lower (in case of non understood channels type) or equal to i_channels.
00282  * - the layout of the channels (*pi_layout).
00283  *
00284  * It will return true if channel extraction is really needed, in which case
00285  * aout_ChannelExtract must be used
00286  *
00287  * XXX It must be used when the source may have channel type not understood
00288  * by VLC. In this case the channel type pi_order_src[] must be set to 0.
00289  * XXX It must also be used if multiple channels have the same type.
00290  */
00291 VLC_EXPORT( bool, aout_CheckChannelExtraction, ( int *pi_selection, uint32_t *pi_layout, int *pi_channels, const uint32_t pi_order_dst[AOUT_CHAN_MAX], const uint32_t *pi_order_src, int i_channels ) );
00292 
00293 /**
00294  * Do the actual channels extraction using the parameters created by
00295  * aout_CheckChannelExtraction.
00296  *
00297  * XXX this function does not work in place (p_dst and p_src must not overlap).
00298  * XXX Only 8, 16, 24, 32, 64 bits per sample are supported.
00299  */
00300 VLC_EXPORT( void, aout_ChannelExtract, ( void *p_dst, int i_dst_channels, const void *p_src, int i_src_channels, int i_sample_count, const int *pi_selection, int i_bits_per_sample ) );
00301 
00302 /* */
00303 VLC_EXPORT( unsigned int, aout_FormatNbChannels, ( const audio_sample_format_t * p_format ) LIBVLC_USED );
00304 VLC_EXPORT( unsigned int, aout_BitsPerSample, ( vlc_fourcc_t i_format ) LIBVLC_USED );
00305 VLC_EXPORT( void, aout_FormatPrepare, ( audio_sample_format_t * p_format ) );
00306 VLC_EXPORT( void, aout_FormatPrint, ( aout_instance_t * p_aout, const char * psz_text, const audio_sample_format_t * p_format ) );
00307 VLC_EXPORT( const char *, aout_FormatPrintChannels, ( const audio_sample_format_t * ) LIBVLC_USED );
00308 
00309 VLC_EXPORT( mtime_t, aout_FifoFirstDate, ( aout_instance_t *, aout_fifo_t * ) LIBVLC_USED );
00310 VLC_EXPORT( aout_buffer_t *, aout_FifoPop, ( aout_instance_t * p_aout, aout_fifo_t * p_fifo ) LIBVLC_USED );
00311 
00312 /* From intf.c : */
00313 VLC_EXPORT( void, aout_VolumeSoftInit, ( aout_instance_t * ) );
00314 VLC_EXPORT( void, aout_VolumeNoneInit, ( aout_instance_t * ) );
00315 #define aout_VolumeGet(a, b) __aout_VolumeGet(VLC_OBJECT(a), b)
00316 VLC_EXPORT( int, __aout_VolumeGet, ( vlc_object_t *, audio_volume_t * ) );
00317 #define aout_VolumeSet(a, b) __aout_VolumeSet(VLC_OBJECT(a), b)
00318 VLC_EXPORT( int, __aout_VolumeSet, ( vlc_object_t *, audio_volume_t ) );
00319 #define aout_VolumeUp(a, b, c) __aout_VolumeUp(VLC_OBJECT(a), b, c)
00320 VLC_EXPORT( int, __aout_VolumeUp, ( vlc_object_t *, int, audio_volume_t * ) );
00321 #define aout_VolumeDown(a, b, c) __aout_VolumeDown(VLC_OBJECT(a), b, c)
00322 VLC_EXPORT( int, __aout_VolumeDown, ( vlc_object_t *, int, audio_volume_t * ) );
00323 #define aout_ToggleMute(a, b) __aout_ToggleMute(VLC_OBJECT(a), b)
00324 VLC_EXPORT( int, __aout_ToggleMute, ( vlc_object_t *, audio_volume_t * ) );
00325 VLC_EXPORT( int, aout_FindAndRestart, ( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * ) );
00326 VLC_EXPORT( int, aout_ChannelsRestart, ( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * ) );
00327 
00328 VLC_EXPORT( void, aout_EnableFilter, (vlc_object_t *, const char *, bool ));
00329 #define aout_EnableFilter( o, n, b ) \
00330         aout_EnableFilter( VLC_OBJECT(o), n, b )
00331 
00332 /* */
00333 VLC_EXPORT( vout_thread_t *, aout_filter_RequestVout, ( filter_t *, vout_thread_t *p_vout, video_format_t *p_fmt ) );
00334 
00335 # ifdef __cplusplus
00336 }
00337 # endif
00338 
00339 #endif /* _VLC_AOUT_H */

Generated on Sat Nov 21 08:05:14 2009 for VLC by  doxygen 1.5.6