1 /*****************************************************************************
2 * AudioOutput.cpp: BeOS audio output
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 the VideoLAN team
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Eric Petit <titer@videolan.org>
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.
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.
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 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
31 #include <SoundPlayer.h>
32 #include <media/MediaDefs.h>
43 #include <aout_internal.h>
46 /*****************************************************************************
47 * aout_sys_t: BeOS audio output method descriptor
48 *****************************************************************************/
50 typedef struct aout_sys_t
52 BSoundPlayer * p_player;
57 /*****************************************************************************
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 );
64 /*****************************************************************************
66 *****************************************************************************/
67 int OpenAudio ( vlc_object_t * p_this )
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 )
73 msg_Err( p_aout, "out of memory" );
76 aout_sys_t * p_sys = p_aout->output.p_sys;
78 aout_VolumeSoftInit( p_aout );
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 )
85 p_aout->output.output.i_physical_channels
86 = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
89 media_raw_audio_format * p_format;
90 p_format = (media_raw_audio_format*)
91 malloc( sizeof( media_raw_audio_format ) );
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;
99 p_format->byte_order = B_MEDIA_LITTLE_ENDIAN;
101 p_format->buffer_size = 8192;
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;
107 p_sys->p_player = new BSoundPlayer( p_format, "player", Play, NULL, p_aout );
108 if( p_sys->p_player->InitCheck() != B_OK )
110 msg_Err( p_aout, "BSoundPlayer InitCheck failed" );
111 delete p_sys->p_player;
117 p_sys->latency = p_sys->p_player->Latency();
118 p_sys->p_player->Start();
119 p_sys->p_player->SetHasData( true );
124 /*****************************************************************************
126 *****************************************************************************/
127 void CloseAudio ( vlc_object_t * p_this )
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;
133 p_sys->p_player->Stop();
134 delete p_sys->p_player;
138 /*****************************************************************************
140 *****************************************************************************/
141 static void Play( void * _p_aout, void * _p_buffer, size_t i_size,
142 const media_raw_audio_format &format )
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;
149 p_aout_buffer = aout_OutputNextBuffer( p_aout,
150 mdate() + p_sys->latency,
153 if( p_aout_buffer != NULL )
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 )
159 vlc_memset( p_buffer + p_aout_buffer->i_nb_bytes,
160 0, i_size - p_aout_buffer->i_nb_bytes );
162 aout_BufferFree( p_aout_buffer );
166 vlc_memset( p_buffer, 0, i_size );
170 /*****************************************************************************
172 *****************************************************************************/
173 static void DoNothing( aout_instance_t *p_aout )