]> git.sesse.net Git - vlc/blob - modules/audio_mixer/trivial.c
Do not #include <vlc_aout_mixer.h> from <vlc_aout.h>
[vlc] / modules / audio_mixer / trivial.c
1 /*****************************************************************************
2  * trivial.c : trivial mixer plug-in (1 input, no downmixing)
3  *****************************************************************************
4  * Copyright (C) 2002 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <stddef.h>
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_aout.h>
36 #include <vlc_aout_mixer.h>
37
38 /*****************************************************************************
39  * Local prototypes
40  *****************************************************************************/
41 static int  Create    ( vlc_object_t * );
42
43 static void DoWork    ( aout_mixer_t *, aout_buffer_t * );
44
45 /*****************************************************************************
46  * Module descriptor
47  *****************************************************************************/
48 vlc_module_begin ()
49     set_category( CAT_AUDIO )
50     set_subcategory( SUBCAT_AUDIO_MISC )
51     set_description( N_("Trivial audio mixer") )
52     set_capability( "audio mixer", 1 )
53     set_callbacks( Create, NULL )
54 vlc_module_end ()
55
56 /*****************************************************************************
57  * Create: allocate trivial mixer
58  *****************************************************************************/
59 static int Create( vlc_object_t *p_this )
60 {
61     aout_mixer_t *p_mixer = (aout_mixer_t *)p_this;
62
63     if ( p_mixer->fmt.i_format != VLC_CODEC_FL32
64           && p_mixer->fmt.i_format != VLC_CODEC_FI32 )
65     {
66         return -1;
67     }
68
69     p_mixer->mix = DoWork;
70
71     return 0;
72 }
73
74 /*****************************************************************************
75  * DoWork: mix a new output buffer
76  *****************************************************************************/
77 static void DoWork( aout_mixer_t *p_mixer, aout_buffer_t * p_buffer )
78 {
79     aout_mixer_input_t *p_input = p_mixer->input;
80     int i_nb_channels = aout_FormatNbChannels( &p_mixer->fmt );
81     int i_buffer = p_buffer->i_nb_samples * sizeof(int32_t)
82                       * i_nb_channels;
83     uint8_t * p_in;
84     uint8_t * p_out;
85
86     p_in = p_input->begin;
87     p_out = p_buffer->p_buffer;
88
89     for ( ; ; )
90     {
91         ptrdiff_t i_available_bytes = (p_input->fifo.p_first->p_buffer
92                                         - p_in)
93                                         + p_input->fifo.p_first->i_nb_samples
94                                            * sizeof(int32_t)
95                                            * i_nb_channels;
96
97         if ( i_available_bytes < i_buffer )
98         {
99             aout_buffer_t * p_old_buffer;
100
101             vlc_memcpy( p_out, p_in, i_available_bytes );
102             i_buffer -= i_available_bytes;
103             p_out += i_available_bytes;
104
105             /* Next buffer */
106             p_old_buffer = aout_FifoPop( NULL, &p_input->fifo );
107             aout_BufferFree( p_old_buffer );
108             if ( p_input->fifo.p_first == NULL )
109             {
110                 msg_Err( p_mixer, "internal amix error" );
111                 return;
112             }
113             p_in = p_input->fifo.p_first->p_buffer;
114         }
115         else
116         {
117             vlc_memcpy( p_out, p_in, i_buffer );
118             p_input->begin = p_in + i_buffer;
119             break;
120         }
121     }
122 }