]> git.sesse.net Git - vlc/blob - modules/gui/beos/AudioOutput.cpp
Remove E_()
[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 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38
39 #include <vlc/vlc.h>
40 #include <vlc_aout.h>
41 extern "C"
42 {
43     #include <aout_internal.h>
44 }
45
46 /*****************************************************************************
47  * aout_sys_t: BeOS audio output method descriptor
48  *****************************************************************************/
49
50 typedef struct aout_sys_t
51 {
52     BSoundPlayer * p_player;
53     mtime_t        latency;
54
55 } aout_sys_t;
56
57 /*****************************************************************************
58  * Local prototypes.
59  *****************************************************************************/
60 static void Play         ( void * p_aout, void * p_buffer, size_t size,
61                            const media_raw_audio_format & format );
62 static void DoNothing    ( aout_instance_t * p_aout );
63
64 /*****************************************************************************
65  * OpenAudio
66  *****************************************************************************/
67 int OpenAudio ( vlc_object_t * p_this )
68 {
69     aout_instance_t * p_aout = (aout_instance_t*) p_this;
70     p_aout->output.p_sys = (aout_sys_t*) malloc( sizeof( aout_sys_t ) );
71     if( p_aout->output.p_sys == NULL )
72     {
73         msg_Err( p_aout, "out of memory" );
74         return -1;
75     }
76     aout_sys_t * p_sys = p_aout->output.p_sys;
77
78     aout_VolumeSoftInit( p_aout );
79
80     int i_nb_channels = aout_FormatNbChannels( &p_aout->output.output );
81     /* BSoundPlayer does not support more than 2 channels AFAIK */
82     if( i_nb_channels > 2 )
83     {
84         i_nb_channels = 2;
85         p_aout->output.output.i_physical_channels
86             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
87     }
88
89     media_raw_audio_format * p_format;
90     p_format = (media_raw_audio_format*)
91         malloc( sizeof( media_raw_audio_format ) );
92
93     p_format->channel_count = i_nb_channels;
94     p_format->frame_rate = p_aout->output.output.i_rate;
95     p_format->format = media_raw_audio_format::B_AUDIO_FLOAT;
96 #ifdef WORDS_BIGENDIAN
97     p_format->byte_order = B_MEDIA_BIG_ENDIAN;
98 #else
99     p_format->byte_order = B_MEDIA_LITTLE_ENDIAN;
100 #endif
101     p_format->buffer_size = 8192;
102
103     p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2');
104     p_aout->output.i_nb_samples = 2048 / i_nb_channels;
105     p_aout->output.pf_play = DoNothing;
106
107     p_sys->p_player = new BSoundPlayer( p_format, "player", Play, NULL, p_aout );
108     if( p_sys->p_player->InitCheck() != B_OK )
109     {
110         msg_Err( p_aout, "BSoundPlayer InitCheck failed" );
111         delete p_sys->p_player;
112         free( p_sys );
113         return -1;
114     }
115
116     /* Start playing */
117     p_sys->latency = p_sys->p_player->Latency();
118     p_sys->p_player->Start();
119     p_sys->p_player->SetHasData( true );
120
121     return 0;
122 }
123
124 /*****************************************************************************
125  * CloseAudio
126  *****************************************************************************/
127 void CloseAudio ( vlc_object_t * p_this )
128 {
129     aout_instance_t * p_aout = (aout_instance_t *) p_this;
130     aout_sys_t * p_sys = (aout_sys_t *) p_aout->output.p_sys;
131
132     /* Clean up */
133     p_sys->p_player->Stop();
134     delete p_sys->p_player;
135     free( p_sys );
136 }
137
138 /*****************************************************************************
139  * Play
140  *****************************************************************************/
141 static void Play( void * _p_aout, void * _p_buffer, size_t i_size,
142                   const media_raw_audio_format &format )
143 {
144     aout_instance_t * p_aout = (aout_instance_t*) _p_aout;
145     float * p_buffer = (float*) _p_buffer;
146     aout_sys_t * p_sys = (aout_sys_t*) p_aout->output.p_sys;
147     aout_buffer_t * p_aout_buffer;
148
149     p_aout_buffer = aout_OutputNextBuffer( p_aout,
150                                            mdate() + p_sys->latency,
151                                            false );
152
153     if( p_aout_buffer != NULL )
154     {
155         vlc_memcpy( p_buffer, p_aout_buffer->p_buffer,
156                     MIN( i_size, p_aout_buffer->i_nb_bytes ) );
157         if( p_aout_buffer->i_nb_bytes < i_size )
158         {
159             vlc_memset(  p_buffer + p_aout_buffer->i_nb_bytes,
160                          0, i_size - p_aout_buffer->i_nb_bytes );
161         }
162         aout_BufferFree( p_aout_buffer );
163     }
164     else
165     {
166         vlc_memset( p_buffer, 0, i_size );
167     }
168 }
169
170 /*****************************************************************************
171  * DoNothing
172  *****************************************************************************/
173 static void DoNothing( aout_instance_t *p_aout )
174 {
175     return;
176 }