Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

AudioOutput.cpp

00001 /*****************************************************************************
00002  * AudioOutput.cpp: BeOS audio output
00003  *****************************************************************************
00004  * Copyright (C) 1999, 2000, 2001 the VideoLAN team
00005  * $Id: AudioOutput.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Jean-Marc Dressler <[email protected]>
00008  *          Samuel Hocevar <[email protected]>
00009  *          Eric Petit <[email protected]>
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027  * Preamble
00028  *****************************************************************************/
00029 #include <stdio.h>
00030 #include <stdlib.h>                                      /* malloc(), free() */
00031 #include <malloc.h>
00032 #include <string.h>
00033 
00034 #include <SoundPlayer.h>
00035 #include <media/MediaDefs.h>
00036 
00037 
00038 #include <vlc/vlc.h>
00039 #include <vlc/aout.h>
00040 extern "C"
00041 {
00042     #include <aout_internal.h>
00043 }
00044 
00045 /*****************************************************************************
00046  * aout_sys_t: BeOS audio output method descriptor
00047  *****************************************************************************/
00048 
00049 typedef struct aout_sys_t
00050 {
00051     BSoundPlayer * p_player;
00052     mtime_t        latency;
00053 
00054 } aout_sys_t;
00055 
00056 /*****************************************************************************
00057  * Local prototypes.
00058  *****************************************************************************/
00059 static void Play         ( void * p_aout, void * p_buffer, size_t size,
00060                            const media_raw_audio_format & format );
00061 static void DoNothing    ( aout_instance_t * p_aout );
00062 
00063 /*****************************************************************************
00064  * OpenAudio
00065  *****************************************************************************/
00066 int E_(OpenAudio) ( vlc_object_t * p_this )
00067 {
00068     aout_instance_t * p_aout = (aout_instance_t*) p_this;
00069     p_aout->output.p_sys = (aout_sys_t*) malloc( sizeof( aout_sys_t ) );
00070     if( p_aout->output.p_sys == NULL )
00071     {
00072         msg_Err( p_aout, "out of memory" );
00073         return -1;
00074     }
00075     aout_sys_t * p_sys = p_aout->output.p_sys;
00076 
00077     aout_VolumeSoftInit( p_aout );
00078 
00079     int i_nb_channels = aout_FormatNbChannels( &p_aout->output.output );
00080     /* BSoundPlayer does not support more than 2 channels AFAIK */
00081     if( i_nb_channels > 2 )
00082     {
00083         i_nb_channels = 2;
00084         p_aout->output.output.i_physical_channels
00085             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
00086     }
00087 
00088     media_raw_audio_format * p_format;
00089     p_format = (media_raw_audio_format*)
00090         malloc( sizeof( media_raw_audio_format ) );
00091 
00092     p_format->channel_count = i_nb_channels;
00093     p_format->frame_rate = p_aout->output.output.i_rate;
00094     p_format->format = media_raw_audio_format::B_AUDIO_FLOAT;
00095 #ifdef WORDS_BIGENDIAN
00096     p_format->byte_order = B_MEDIA_BIG_ENDIAN;
00097 #else
00098     p_format->byte_order = B_MEDIA_LITTLE_ENDIAN;
00099 #endif
00100     p_format->buffer_size = 8192;
00101 
00102     p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2');
00103     p_aout->output.i_nb_samples = 2048 / i_nb_channels;
00104     p_aout->output.pf_play = DoNothing;
00105 
00106     p_sys->p_player = new BSoundPlayer( p_format, "player", Play, NULL, p_aout );
00107     if( p_sys->p_player->InitCheck() != B_OK )
00108     {
00109         msg_Err( p_aout, "BSoundPlayer InitCheck failed" );
00110         delete p_sys->p_player;
00111         free( p_sys );
00112         return -1;
00113     }
00114 
00115     /* Start playing */
00116     p_sys->latency = p_sys->p_player->Latency();
00117     p_sys->p_player->Start();
00118     p_sys->p_player->SetHasData( true );
00119 
00120     return 0;
00121 }
00122 
00123 /*****************************************************************************
00124  * CloseAudio
00125  *****************************************************************************/
00126 void E_(CloseAudio) ( vlc_object_t * p_this )
00127 {
00128     aout_instance_t * p_aout = (aout_instance_t *) p_this;
00129     aout_sys_t * p_sys = (aout_sys_t *) p_aout->output.p_sys;
00130 
00131     /* Clean up */
00132     p_sys->p_player->Stop();
00133     delete p_sys->p_player;
00134     free( p_sys );
00135 }
00136 
00137 /*****************************************************************************
00138  * Play
00139  *****************************************************************************/
00140 static void Play( void * _p_aout, void * _p_buffer, size_t i_size,
00141                   const media_raw_audio_format &format )
00142 {
00143     aout_instance_t * p_aout = (aout_instance_t*) _p_aout;
00144     float * p_buffer = (float*) _p_buffer;
00145     aout_sys_t * p_sys = (aout_sys_t*) p_aout->output.p_sys;
00146     aout_buffer_t * p_aout_buffer;
00147 
00148     p_aout_buffer = aout_OutputNextBuffer( p_aout,
00149                                            mdate() + p_sys->latency,
00150                                            VLC_FALSE );
00151 
00152     if( p_aout_buffer != NULL )
00153     {
00154         p_aout->p_vlc->pf_memcpy( p_buffer, p_aout_buffer->p_buffer,
00155                                   MIN( i_size, p_aout_buffer->i_nb_bytes ) );
00156         if( p_aout_buffer->i_nb_bytes < i_size )
00157         {
00158             p_aout->p_vlc->pf_memset( p_buffer + p_aout_buffer->i_nb_bytes,
00159                                       0, i_size - p_aout_buffer->i_nb_bytes );
00160         }
00161         aout_BufferFree( p_aout_buffer );
00162     }
00163     else
00164     {
00165         p_aout->p_vlc->pf_memset( p_buffer, 0, i_size );
00166     }
00167 }
00168 
00169 /*****************************************************************************
00170  * DoNothing
00171  *****************************************************************************/
00172 static void DoNothing( aout_instance_t *p_aout )
00173 {
00174     return;
00175 }

Generated on Tue Dec 20 10:14:36 2005 for vlc-0.8.4a by  doxygen 1.4.2