aout_internal.h 7.1 KB
Newer Older
zorglub's avatar
zorglub committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*****************************************************************************
 * aout_internal.h : internal defines for audio output
 *****************************************************************************
 * Copyright (C) 2002 the VideoLAN team
 * $Id$
 *
 * Authors: Christophe Massiot <massiot@via.ecp.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

24 25
#ifndef LIBVLC_AOUT_INTERNAL_H
# define LIBVLC_AOUT_INTERNAL_H 1
26

27 28 29 30 31 32 33 34 35
/* Max input rate factor (1/4 -> 4) */
# define AOUT_MAX_INPUT_RATE (4)

enum {
    AOUT_RESAMPLING_NONE=0,
    AOUT_RESAMPLING_UP,
    AOUT_RESAMPLING_DOWN
};

36 37
# include <vlc_aout_mixer.h>

38 39 40 41 42 43 44
typedef struct
{
    struct vout_thread_t  *(*pf_request_vout)( void *, struct vout_thread_t *,
                                               video_format_t *, bool );
    void *p_private;
} aout_request_vout_t;

45
struct filter_owner_sys_t
46
{
47
    audio_output_t *p_aout;
48 49 50
    aout_input_t    *p_input;
};

51 52
block_t *aout_FilterBufferNew( filter_t *, int );

53 54 55 56
/** an input stream for the audio output */
struct aout_input_t
{
    audio_sample_format_t   input;
57
    float                   multiplier; /**< Replay gain multiplier */
58 59

    /* pre-filters */
60
    filter_t *              pp_filters[AOUT_MAX_FILTERS];
61 62
    int                     i_nb_filters;

63
    filter_t *              p_playback_rate_filter;
64 65

    /* resamplers */
66
    filter_t *              pp_resamplers[AOUT_MAX_FILTERS];
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
    int                     i_nb_resamplers;
    int                     i_resampling_type;
    mtime_t                 i_resamp_start_date;
    int                     i_resamp_start_drift;

    /* Mixer information */
    audio_replay_gain_t     replay_gain;

    /* If b_restart == 1, the input pipeline will be re-created. */
    bool              b_restart;

    /* If b_error == 1, there is no input pipeline. */
    bool              b_error;

    /* last rate from input */
    int               i_last_input_rate;

    /* */
    int               i_buffer_lost;

    /* */
    bool              b_paused;
    mtime_t           i_pause_date;

    /* */
    bool                b_recycle_vout;
    aout_request_vout_t request_vout;

    /* */
96
    aout_fifo_t       fifo;
97 98
 };

zorglub's avatar
zorglub committed
99 100 101
/****************************************************************************
 * Prototypes
 *****************************************************************************/
102

zorglub's avatar
zorglub committed
103
/* From input.c : */
104 105 106
int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_request_vout_t * );
int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input );
void aout_InputPlay( audio_output_t * p_aout, aout_input_t * p_input,
107
                     aout_buffer_t * p_buffer, int i_input_rate );
108
void aout_InputCheckAndRestart( audio_output_t * p_aout, aout_input_t * p_input );
zorglub's avatar
zorglub committed
109 110

/* From filters.c : */
111
int aout_FiltersCreatePipeline( audio_output_t *, filter_t **, int *,
112
    const audio_sample_format_t *, const audio_sample_format_t * );
113 114
void aout_FiltersDestroyPipeline( filter_t *const *, unsigned );
void aout_FiltersPlay( filter_t *const *, unsigned, aout_buffer_t ** );
zorglub's avatar
zorglub committed
115 116

/* From mixer.c : */
117 118 119
int aout_MixerNew( audio_output_t * p_aout );
void aout_MixerDelete( audio_output_t * p_aout );
void aout_MixerRun( audio_output_t * p_aout, float );
zorglub's avatar
zorglub committed
120 121

/* From output.c : */
122
int aout_OutputNew( audio_output_t * p_aout,
123
                    const audio_sample_format_t * p_format );
124 125
void aout_OutputPlay( audio_output_t * p_aout, aout_buffer_t * p_buffer );
void aout_OutputPause( audio_output_t * p_aout, bool, mtime_t );
126
void aout_OutputFlush( audio_output_t * p_aout, bool );
127
void aout_OutputDelete( audio_output_t * p_aout );
zorglub's avatar
zorglub committed
128 129 130


/* From common.c : */
131
/* Release with vlc_object_release() */
132
audio_output_t *aout_New ( vlc_object_t * );
133
#define aout_New(a) aout_New(VLC_OBJECT(a))
zorglub's avatar
zorglub committed
134

135 136 137 138
void aout_FifoInit( vlc_object_t *, aout_fifo_t *, uint32_t );
#define aout_FifoInit(o, f, r) aout_FifoInit(VLC_OBJECT(o), f, r)
mtime_t aout_FifoNextStart( const aout_fifo_t * ) VLC_USED;
void aout_FifoPush( aout_fifo_t *, aout_buffer_t * );
139
void aout_FifoReset( aout_fifo_t * );
140 141
void aout_FifoMoveDates( aout_fifo_t *, mtime_t );
void aout_FifoDestroy( aout_fifo_t * p_fifo );
142 143
void aout_FormatsPrint( audio_output_t * p_aout, const char * psz_text, const audio_sample_format_t * p_format1, const audio_sample_format_t * p_format2 );
bool aout_ChangeFilterString( vlc_object_t *, audio_output_t *, const char *psz_variable, const char *psz_name, bool b_add );
zorglub's avatar
zorglub committed
144 145

/* From dec.c */
146
aout_input_t *aout_DecNew( audio_output_t *, audio_sample_format_t *,
147
                   const audio_replay_gain_t *, const aout_request_vout_t * );
148
void aout_DecDelete ( audio_output_t *, aout_input_t * );
149
aout_buffer_t * aout_DecNewBuffer( aout_input_t *, size_t );
150 151 152 153 154 155
void aout_DecDeleteBuffer( audio_output_t *, aout_input_t *, aout_buffer_t * );
int aout_DecPlay( audio_output_t *, aout_input_t *, aout_buffer_t *, int i_input_rate );
int aout_DecGetResetLost( audio_output_t *, aout_input_t * );
void aout_DecChangePause( audio_output_t *, aout_input_t *, bool b_paused, mtime_t i_date );
void aout_DecFlush( audio_output_t *, aout_input_t * );
bool aout_DecIsEmpty( audio_output_t * p_aout, aout_input_t * p_input );
zorglub's avatar
zorglub committed
156

157 158 159 160 161 162 163 164 165 166
/* Audio output locking */

#if !defined (NDEBUG) \
 && defined __linux__ && (defined (__i386__) || defined (__x86_64__))
# define AOUT_DEBUG 1
#endif

#ifdef AOUT_DEBUG
enum
{
167 168
    OUTPUT_LOCK=1,
    VOLUME_LOCK=2,
169 170
};

171 172
void aout_lock_check (unsigned);
void aout_unlock_check (unsigned);
173 174

#else
175 176
# define aout_lock_check( i )   (void)0
# define aout_unlock_check( i ) (void)0
177
#endif
178

179
static inline void aout_lock( audio_output_t *p_aout )
180
{
181 182
    aout_lock_check( OUTPUT_LOCK );
    vlc_mutex_lock( &p_aout->lock );
183 184
}

185
static inline void aout_unlock( audio_output_t *p_aout )
186
{
187 188
    aout_unlock_check( OUTPUT_LOCK );
    vlc_mutex_unlock( &p_aout->lock );
189 190
}

191
static inline void aout_lock_volume( audio_output_t *p_aout )
192
{
193 194
    aout_lock_check( VOLUME_LOCK );
    vlc_mutex_lock( &p_aout->volume_lock );
195 196
}

197
static inline void aout_unlock_volume( audio_output_t *p_aout )
198
{
199 200
    aout_unlock_check( VOLUME_LOCK );
    vlc_mutex_unlock( &p_aout->volume_lock );
201
}
202

203 204
/* Helpers */

205 206 207
/**
 * This function will safely mark aout input to be restarted as soon as
 * possible to take configuration changes into account */
208
static inline void AoutInputsMarkToRestart( audio_output_t *p_aout )
209
{
210
    aout_lock( p_aout );
211 212
    if( p_aout->p_input != NULL )
        p_aout->p_input->b_restart = true;
213
    aout_unlock( p_aout );
214 215
}

216
#endif /* !LIBVLC_AOUT_INTERNAL_H */