]> git.sesse.net Git - vlc/blob - modules/gui/beos/AudioOutput.cpp
Remove stdio while we're at it.
[vlc] / modules / gui / beos / AudioOutput.cpp
1 /*****************************************************************************
2  * AudioOutput.cpp: BeOS audio output
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Eric Petit <titer@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <malloc.h>
30
31 #include <SoundPlayer.h>
32 #include <media/MediaDefs.h>
33
34
35 #include <vlc/vlc.h>
36 #include <vlc_aout.h>
37 extern "C"
38 {
39     #include <aout_internal.h>
40 }
41
42 /*****************************************************************************
43  * aout_sys_t: BeOS audio output method descriptor
44  *****************************************************************************/
45
46 typedef struct aout_sys_t
47 {
48     BSoundPlayer * p_player;
49     mtime_t        latency;
50
51 } aout_sys_t;
52
53 /*****************************************************************************
54  * Local prototypes.
55  *****************************************************************************/
56 static void Play         ( void * p_aout, void * p_buffer, size_t size,
57                            const media_raw_audio_format & format );
58 static void DoNothing    ( aout_instance_t * p_aout );
59
60 /*****************************************************************************
61  * OpenAudio
62  *****************************************************************************/
63 int E_(OpenAudio) ( vlc_object_t * p_this )
64 {
65     aout_instance_t * p_aout = (aout_instance_t*) p_this;
66     p_aout->output.p_sys = (aout_sys_t*) malloc( sizeof( aout_sys_t ) );
67     if( p_aout->output.p_sys == NULL )
68     {
69         msg_Err( p_aout, "out of memory" );
70         return -1;
71     }
72     aout_sys_t * p_sys = p_aout->output.p_sys;
73
74     aout_VolumeSoftInit( p_aout );
75
76     int i_nb_channels = aout_FormatNbChannels( &p_aout->output.output );
77     /* BSoundPlayer does not support more than 2 channels AFAIK */
78     if( i_nb_channels > 2 )
79     {
80         i_nb_channels = 2;
81         p_aout->output.output.i_physical_channels
82             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
83     }
84
85     media_raw_audio_format * p_format;
86     p_format = (media_raw_audio_format*)
87         malloc( sizeof( media_raw_audio_format ) );
88
89     p_format->channel_count = i_nb_channels;
90     p_format->frame_rate = p_aout->output.output.i_rate;
91     p_format->format = media_raw_audio_format::B_AUDIO_FLOAT;
92 #ifdef WORDS_BIGENDIAN
93     p_format->byte_order = B_MEDIA_BIG_ENDIAN;
94 #else
95     p_format->byte_order = B_MEDIA_LITTLE_ENDIAN;
96 #endif
97     p_format->buffer_size = 8192;
98
99     p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2');
100     p_aout->output.i_nb_samples = 2048 / i_nb_channels;
101     p_aout->output.pf_play = DoNothing;
102
103     p_sys->p_player = new BSoundPlayer( p_format, "player", Play, NULL, p_aout );
104     if( p_sys->p_player->InitCheck() != B_OK )
105     {
106         msg_Err( p_aout, "BSoundPlayer InitCheck failed" );
107         delete p_sys->p_player;
108         free( p_sys );
109         return -1;
110     }
111
112     /* Start playing */
113     p_sys->latency = p_sys->p_player->Latency();
114     p_sys->p_player->Start();
115     p_sys->p_player->SetHasData( true );
116
117     return 0;
118 }
119
120 /*****************************************************************************
121  * CloseAudio
122  *****************************************************************************/
123 void E_(CloseAudio) ( vlc_object_t * p_this )
124 {
125     aout_instance_t * p_aout = (aout_instance_t *) p_this;
126     aout_sys_t * p_sys = (aout_sys_t *) p_aout->output.p_sys;
127
128     /* Clean up */
129     p_sys->p_player->Stop();
130     delete p_sys->p_player;
131     free( p_sys );
132 }
133
134 /*****************************************************************************
135  * Play
136  *****************************************************************************/
137 static void Play( void * _p_aout, void * _p_buffer, size_t i_size,
138                   const media_raw_audio_format &format )
139 {
140     aout_instance_t * p_aout = (aout_instance_t*) _p_aout;
141     float * p_buffer = (float*) _p_buffer;
142     aout_sys_t * p_sys = (aout_sys_t*) p_aout->output.p_sys;
143     aout_buffer_t * p_aout_buffer;
144
145     p_aout_buffer = aout_OutputNextBuffer( p_aout,
146                                            mdate() + p_sys->latency,
147                                            VLC_FALSE );
148
149     if( p_aout_buffer != NULL )
150     {
151         p_aout->p_libvlc->pf_memcpy( p_buffer, p_aout_buffer->p_buffer,
152                                   MIN( i_size, p_aout_buffer->i_nb_bytes ) );
153         if( p_aout_buffer->i_nb_bytes < i_size )
154         {
155             p_aout->p_libvlc->pf_memset( p_buffer + p_aout_buffer->i_nb_bytes,
156                                       0, i_size - p_aout_buffer->i_nb_bytes );
157         }
158         aout_BufferFree( p_aout_buffer );
159     }
160     else
161     {
162         p_aout->p_libvlc->pf_memset( p_buffer, 0, i_size );
163     }
164 }
165
166 /*****************************************************************************
167  * DoNothing
168  *****************************************************************************/
169 static void DoNothing( aout_instance_t *p_aout )
170 {
171     return;
172 }