00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdio.h>
00030 #include <stdlib.h>
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
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
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
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
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
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
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
00132 p_sys->p_player->Stop();
00133 delete p_sys->p_player;
00134 free( p_sys );
00135 }
00136
00137
00138
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
00171
00172 static void DoNothing( aout_instance_t *p_aout )
00173 {
00174 return;
00175 }