]> git.sesse.net Git - vlc/blob - plugins/beos/aout_beos.cpp
. autod�tection des plugins
[vlc] / plugins / beos / aout_beos.cpp
1 /*****************************************************************************
2  * aout_beos.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors:
7  * Samuel Hocevar <sam@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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "defs.h"
28
29 #include <stdio.h>
30 #include <stdlib.h>                                      /* malloc(), free() */
31 #include <sys/types.h>                        /* on BSD, uio.h needs types.h */
32 #include <sys/uio.h>                                            /* "input.h" */
33 #include <kernel/OS.h>
34 #include <View.h>
35 #include <Application.h>
36 #include <Message.h>
37 #include <Locker.h>
38 #include <media/MediaDefs.h>
39 #include <game/PushGameSound.h>
40 #include <malloc.h>
41 #include <string.h>
42
43 extern "C"
44 {
45 #include "config.h"
46 #include "common.h"
47 #include "threads.h"
48 #include "mtime.h"
49 #include "plugins.h"
50
51 #include "audio_output.h"
52
53 #include "intf_msg.h"
54
55 #include "main.h"
56 }
57
58 /*****************************************************************************
59  * aout_sys_t: esd audio output method descriptor
60  *****************************************************************************
61  * This structure is part of the audio output thread descriptor.
62  * It describes some esd specific variables.
63  *****************************************************************************/
64 typedef struct aout_sys_s
65 {
66     BPushGameSound * p_sound;
67     gs_audio_format * p_format;
68     void * p_buffer;
69     long i_buffer_size;
70     long i_buffer_pos;
71
72 } aout_sys_t;
73
74 extern "C"
75 {
76
77 /*****************************************************************************
78  * aout_BeOpen: opens a BPushGameSound
79  *****************************************************************************/
80 int aout_BeOpen( aout_thread_t *p_aout )
81 {
82     /* Allocate structure */
83     p_aout->p_sys = (aout_sys_t*) malloc( sizeof( aout_sys_t ) );
84     if( p_aout->p_sys == NULL )
85     {
86         intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
87         return( 1 );
88     }
89
90     /* Allocate gs_audio_format */
91     p_aout->p_sys->p_format = (gs_audio_format *) malloc( sizeof( gs_audio_format ) );
92     if( p_aout->p_sys->p_format == NULL )
93     {
94         free( p_aout->p_sys );
95         intf_ErrMsg("error: cannot allocate memory for gs_audio_format\n" );
96         return( 1 );
97     }
98
99     /* Initialize some variables */
100     p_aout->i_format = AOUT_DEFAULT_FORMAT;
101     p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR,
102                                                   AOUT_STEREO_DEFAULT );
103     p_aout->l_rate = main_GetIntVariable( AOUT_RATE_VAR, AOUT_RATE_DEFAULT );
104
105     p_aout->p_sys->p_format->frame_rate = 44100.0;
106     p_aout->p_sys->p_format->channel_count = p_aout->i_channels;
107     p_aout->p_sys->p_format->format = gs_audio_format::B_GS_S16;
108     p_aout->p_sys->p_format->byte_order = B_MEDIA_LITTLE_ENDIAN;
109     p_aout->p_sys->p_format->buffer_size = 8192;
110
111     /* Allocate BPushGameSound */
112     p_aout->p_sys->p_sound = new BPushGameSound( 8192,
113                                                  p_aout->p_sys->p_format,
114                                                  2, NULL );
115     if( p_aout->p_sys->p_sound == NULL )
116     {
117         free( p_aout->p_sys->p_format );
118         free( p_aout->p_sys );
119         intf_ErrMsg("error: cannot allocate memory for BPushGameSound\n" );
120         return( 1 );
121     }
122
123     if( p_aout->p_sys->p_sound->InitCheck() != B_OK )
124     {
125         free( p_aout->p_sys->p_format );
126         free( p_aout->p_sys );
127         intf_ErrMsg("error: cannot allocate memory for BPushGameSound\n" );
128         return( 1 );
129     }
130
131     p_aout->p_sys->p_sound->StartPlaying( );
132
133     p_aout->p_sys->p_sound->LockForCyclic( &p_aout->p_sys->p_buffer,
134                             (size_t *)&p_aout->p_sys->i_buffer_size );
135
136     return( 0 );
137 }
138 /*****************************************************************************
139  * aout_BeReset: resets the dsp
140  *****************************************************************************/
141 int aout_BeReset( aout_thread_t *p_aout )
142 {
143     return( 0 );
144 }
145
146 /*****************************************************************************
147  * aout_BeSetFormat: sets the dsp output format
148  *****************************************************************************/
149 int aout_BeSetFormat( aout_thread_t *p_aout )
150 {
151     return( 0 );
152 }
153
154 /*****************************************************************************
155  * aout_BeSetChannels: sets the dsp's stereo or mono mode
156  *****************************************************************************/
157 int aout_BeSetChannels( aout_thread_t *p_aout )
158 {
159     return( 0 );
160 }
161
162 /*****************************************************************************
163  * aout_BeSetRate: sets the dsp's audio output rate
164  *****************************************************************************/
165 int aout_BeSetRate( aout_thread_t *p_aout )
166 {
167     return( 0 );
168 }
169
170 /*****************************************************************************
171  * aout_BeGetBufInfo: buffer status query
172  *****************************************************************************/
173 long aout_BeGetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
174 {
175
176     long i_hard_pos = 4 * p_aout->p_sys->p_sound->CurrentPosition();
177
178     /*fprintf( stderr, "read 0x%.6lx - write 0x%.6lx = ",
179              i_hard_pos, p_aout->p_sys->i_buffer_pos );*/
180
181     if( i_hard_pos < p_aout->p_sys->i_buffer_pos )
182     {
183         i_hard_pos += p_aout->p_sys->i_buffer_size;
184     }
185
186     /*fprintf( stderr, "0x%.6lx\n", i_hard_pos - p_aout->p_sys->i_buffer_pos ); */
187
188     return( (p_aout->p_sys->i_buffer_size - (i_hard_pos - p_aout->p_sys->i_buffer_pos)) );
189 }
190
191 /*****************************************************************************
192  * aout_BePlaySamples: plays a sound samples buffer
193  *****************************************************************************
194  * This function writes a buffer of i_length bytes in the dsp
195  *****************************************************************************/
196 void aout_BePlaySamples( aout_thread_t *p_aout, byte_t *buffer, int i_size )
197 {
198     long i_newbuf_pos;
199
200     //fprintf( stderr, "writing %i\n", i_size );
201
202     if( (i_newbuf_pos = p_aout->p_sys->i_buffer_pos + i_size)
203               > p_aout->p_sys->i_buffer_size )
204     {
205         memcpy( (void *)((int)p_aout->p_sys->p_buffer
206                         + p_aout->p_sys->i_buffer_pos),
207                 buffer,
208                 p_aout->p_sys->i_buffer_size - p_aout->p_sys->i_buffer_pos );
209
210         memcpy( (void *)((int)p_aout->p_sys->p_buffer),
211                 buffer,
212                 i_size - ( p_aout->p_sys->i_buffer_size
213                              - p_aout->p_sys->i_buffer_pos ) );
214
215         p_aout->p_sys->i_buffer_pos = i_newbuf_pos - p_aout->p_sys->i_buffer_size;
216     }
217     else
218     {
219         memcpy( (void *)((int)p_aout->p_sys->p_buffer + p_aout->p_sys->i_buffer_pos),
220                 buffer, i_size );
221         p_aout->p_sys->i_buffer_pos = i_newbuf_pos;
222     }
223 }
224
225 /*****************************************************************************
226  * aout_BeClose: closes the dsp audio device
227  *****************************************************************************/
228 void aout_BeClose( aout_thread_t *p_aout )
229 {
230     p_aout->p_sys->p_sound->UnlockCyclic();
231     p_aout->p_sys->p_sound->StopPlaying( );
232     delete p_aout->p_sys->p_sound;
233     free( p_aout->p_sys->p_format );
234     free( p_aout->p_sys );
235 }
236
237 } /* extern "C" */
238