| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
#include <errno.h> |
|---|
| 29 |
|
|---|
| 30 |
#ifdef HAVE_CONFIG_H |
|---|
| 31 |
# include "config.h" |
|---|
| 32 |
#endif |
|---|
| 33 |
|
|---|
| 34 |
#include <vlc_common.h> |
|---|
| 35 |
|
|---|
| 36 |
#ifdef HAVE_ALLOCA_H |
|---|
| 37 |
# include <alloca.h> |
|---|
| 38 |
#endif |
|---|
| 39 |
|
|---|
| 40 |
#include <vlc_aout.h> |
|---|
| 41 |
|
|---|
| 42 |
#include <sys/asoundlib.h> |
|---|
| 43 |
|
|---|
| 44 |
struct aout_sys_t |
|---|
| 45 |
{ |
|---|
| 46 |
snd_pcm_t * p_pcm_handle; |
|---|
| 47 |
int i_card; |
|---|
| 48 |
int i_device; |
|---|
| 49 |
|
|---|
| 50 |
uint8_t * p_silent_buffer; |
|---|
| 51 |
}; |
|---|
| 52 |
|
|---|
| 53 |
#define DEFAULT_FRAME_SIZE 2048 |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
int OpenAudio ( vlc_object_t *p_this ); |
|---|
| 59 |
void CloseAudio ( vlc_object_t *p_this ); |
|---|
| 60 |
static int GetBufInfo ( aout_instance_t * ); |
|---|
| 61 |
static void Play ( aout_instance_t * ); |
|---|
| 62 |
static void* QNXaoutThread ( vlc_object_t * ); |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
int OpenAudio( vlc_object_t *p_this ) |
|---|
| 70 |
{ |
|---|
| 71 |
aout_instance_t *p_aout = (aout_instance_t *)p_this; |
|---|
| 72 |
int i_ret; |
|---|
| 73 |
int i_bytes_per_sample; |
|---|
| 74 |
int i_nb_channels; |
|---|
| 75 |
snd_pcm_channel_info_t pi; |
|---|
| 76 |
snd_pcm_channel_params_t pp; |
|---|
| 77 |
aout_instance_t *p_aout = (aout_instance_t *)p_this; |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
p_aout->output.p_sys = malloc( sizeof( aout_sys_t ) ); |
|---|
| 81 |
if( p_aout->output.p_sys == NULL ) |
|---|
| 82 |
{ |
|---|
| 83 |
msg_Err( p_aout, "out of memory" ); |
|---|
| 84 |
return -1; |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
if( ( i_ret = snd_pcm_open_preferred( &p_aout->output.p_sys->p_pcm_handle, |
|---|
| 89 |
&p_aout->output.p_sys->i_card, |
|---|
| 90 |
&p_aout->output.p_sys->i_device, |
|---|
| 91 |
SND_PCM_OPEN_PLAYBACK ) ) < 0 ) |
|---|
| 92 |
{ |
|---|
| 93 |
msg_Err( p_aout, "unable to open audio device (%s)", |
|---|
| 94 |
snd_strerror( i_ret ) ); |
|---|
| 95 |
free( p_aout->output.p_sys ); |
|---|
| 96 |
return -1; |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
if( ( i_ret = snd_pcm_plugin_set_disable( p_aout->output.p_sys->p_pcm_handle, |
|---|
| 101 |
PLUGIN_DISABLE_MMAP ) ) < 0 ) |
|---|
| 102 |
{ |
|---|
| 103 |
msg_Err( p_aout, "unable to disable mmap (%s)", snd_strerror(i_ret) ); |
|---|
| 104 |
CloseAudio( p_this ); |
|---|
| 105 |
free( p_aout->output.p_sys ); |
|---|
| 106 |
return -1; |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
p_aout->output.p_sys->p_silent_buffer = malloc( DEFAULT_FRAME_SIZE * 4 ); |
|---|
| 110 |
p_aout->output.pf_play = Play; |
|---|
| 111 |
aout_VolumeSoftInit( p_aout ); |
|---|
| 112 |
|
|---|
| 113 |
memset( &pi, 0, sizeof(pi) ); |
|---|
| 114 |
memset( &pp, 0, sizeof(pp) ); |
|---|
| 115 |
|
|---|
| 116 |
pi.channel = SND_PCM_CHANNEL_PLAYBACK; |
|---|
| 117 |
if( ( i_ret = snd_pcm_plugin_info( p_aout->output.p_sys->p_pcm_handle, |
|---|
| 118 |
&pi ) ) < 0 ) |
|---|
| 119 |
{ |
|---|
| 120 |
msg_Err( p_aout, "unable to get plugin info (%s)", |
|---|
| 121 |
snd_strerror( i_ret ) ); |
|---|
| 122 |
CloseAudio( p_this ); |
|---|
| 123 |
free( p_aout->output.p_sys ); |
|---|
| 124 |
return -1; |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
pp.mode = SND_PCM_MODE_BLOCK; |
|---|
| 128 |
pp.channel = SND_PCM_CHANNEL_PLAYBACK; |
|---|
| 129 |
pp.start_mode = SND_PCM_START_FULL; |
|---|
| 130 |
pp.stop_mode = SND_PCM_STOP_STOP; |
|---|
| 131 |
|
|---|
| 132 |
pp.buf.block.frags_max = 3; |
|---|
| 133 |
pp.buf.block.frags_min = 1; |
|---|
| 134 |
|
|---|
| 135 |
pp.format.interleave = 1; |
|---|
| 136 |
pp.format.rate = p_aout->output.output.i_rate; |
|---|
| 137 |
|
|---|
| 138 |
i_nb_channels = aout_FormatNbChannels( &p_aout->output.output ); |
|---|
| 139 |
if ( i_nb_channels > 2 ) |
|---|
| 140 |
{ |
|---|
| 141 |
|
|---|
| 142 |
i_nb_channels = 2; |
|---|
| 143 |
p_aout->output.output.i_channels = AOUT_CHAN_STEREO; |
|---|
| 144 |
} |
|---|
| 145 |
pp.format.voices = i_nb_channels; |
|---|
| 146 |
|
|---|
| 147 |
p_aout->output.output.i_format = AOUT_FMT_S16_NE; |
|---|
| 148 |
p_aout->output.i_nb_samples = DEFAULT_FRAME_SIZE; |
|---|
| 149 |
pp.format.format = SND_PCM_SFMT_S16; |
|---|
| 150 |
i_bytes_per_sample = 2; |
|---|
| 151 |
|
|---|
| 152 |
pp.buf.block.frag_size = p_aout->output.i_nb_samples * |
|---|
| 153 |
p_aout->output.output.i_channels * |
|---|
| 154 |
i_bytes_per_sample; |
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
if( ( i_ret = snd_pcm_plugin_params( p_aout->output.p_sys->p_pcm_handle, |
|---|
| 158 |
&pp ) ) < 0 ) |
|---|
| 159 |
{ |
|---|
| 160 |
msg_Err( p_aout, "unable to set parameters (%s)", snd_strerror(i_ret) ); |
|---|
| 161 |
CloseAudio( p_this ); |
|---|
| 162 |
free( p_aout->output.p_sys ); |
|---|
| 163 |
return -1; |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
if( ( i_ret = snd_pcm_plugin_prepare( p_aout->output.p_sys->p_pcm_handle, |
|---|
| 168 |
SND_PCM_CHANNEL_PLAYBACK ) ) < 0 ) |
|---|
| 169 |
{ |
|---|
| 170 |
msg_Err( p_aout, "unable to prepare channel (%s)", |
|---|
| 171 |
snd_strerror( i_ret ) ); |
|---|
| 172 |
CloseAudio( p_this ); |
|---|
| 173 |
free( p_aout->output.p_sys ); |
|---|
| 174 |
return -1; |
|---|
| 175 |
} |
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
if( vlc_thread_create( p_aout, "aout", QNXaoutThread, |
|---|
| 179 |
VLC_THREAD_PRIORITY_OUTPUT, false ) ) |
|---|
| 180 |
{ |
|---|
| 181 |
msg_Err( p_aout, "cannot create QNX audio thread (%m)" ); |
|---|
| 182 |
CloseAudio( p_this ); |
|---|
| 183 |
free( p_aout->output.p_sys ); |
|---|
| 184 |
return -1; |
|---|
| 185 |
} |
|---|
| 186 |
|
|---|
| 187 |
return( 0 ); |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
static int GetBufInfo( aout_instance_t *p_aout ) |
|---|
| 199 |
{ |
|---|
| 200 |
int i_ret; |
|---|
| 201 |
snd_pcm_channel_status_t status; |
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
memset( &status, 0, sizeof(status) ); |
|---|
| 205 |
if( ( i_ret = snd_pcm_plugin_status( p_aout->output.p_sys->p_pcm_handle, |
|---|
| 206 |
&status ) ) < 0 ) |
|---|
| 207 |
{ |
|---|
| 208 |
msg_Err( p_aout, "unable to get device status (%s)", |
|---|
| 209 |
snd_strerror( i_ret ) ); |
|---|
| 210 |
return( -1 ); |
|---|
| 211 |
} |
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
switch( status.status ) |
|---|
| 215 |
{ |
|---|
| 216 |
case SND_PCM_STATUS_READY: |
|---|
| 217 |
case SND_PCM_STATUS_UNDERRUN: |
|---|
| 218 |
if( ( i_ret = snd_pcm_plugin_prepare( p_aout->output.p_sys->p_pcm_handle, |
|---|
| 219 |
SND_PCM_CHANNEL_PLAYBACK ) ) < 0 ) |
|---|
| 220 |
{ |
|---|
| 221 |
msg_Err( p_aout, "unable to prepare channel (%s)", |
|---|
| 222 |
snd_strerror( i_ret ) ); |
|---|
| 223 |
} |
|---|
| 224 |
break; |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
return( status.count ); |
|---|
| 228 |
} |
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
static void Play( aout_instance_t *p_aout ) |
|---|
| 236 |
{ |
|---|
| 237 |
} |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
void CloseAudio ( vlc_object_t *p_this ) |
|---|
| 243 |
{ |
|---|
| 244 |
aout_instance_t *p_aout = (aout_instance_t *)p_this; |
|---|
| 245 |
int i_ret; |
|---|
| 246 |
|
|---|
| 247 |
vlc_object_kill( p_aout ); |
|---|
| 248 |
vlc_thread_join( p_aout ); |
|---|
| 249 |
|
|---|
| 250 |
if( ( i_ret = snd_pcm_close( p_aout->output.p_sys->p_pcm_handle ) ) < 0 ) |
|---|
| 251 |
{ |
|---|
| 252 |
msg_Err( p_aout, "unable to close audio device (%s)", |
|---|
| 253 |
snd_strerror( i_ret ) ); |
|---|
| 254 |
} |
|---|
| 255 |
|
|---|
| 256 |
free( p_aout->output.p_sys->p_silent_buffer ); |
|---|
| 257 |
free( p_aout->output.p_sys ); |
|---|
| 258 |
} |
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
static void* QNXaoutThread( vlc_object_t *p_this ) |
|---|
| 265 |
{ |
|---|
| 266 |
aout_instance_t * p_aout = (aout_instance_t*)p_this; |
|---|
| 267 |
struct aout_sys_t * p_sys = p_aout->output.p_sys; |
|---|
| 268 |
int canc = vlc_savecancel (); |
|---|
| 269 |
|
|---|
| 270 |
while ( vlc_object_alive (p_aout) ) |
|---|
| 271 |
{ |
|---|
| 272 |
aout_buffer_t * p_buffer; |
|---|
| 273 |
int i_tmp, i_size; |
|---|
| 274 |
uint8_t * p_bytes; |
|---|
| 275 |
|
|---|
| 276 |
if ( p_aout->output.output.i_format != VLC_FOURCC('s','p','d','i') ) |
|---|
| 277 |
{ |
|---|
| 278 |
mtime_t next_date = 0; |
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
next_date = (mtime_t)GetBufInfo( p_aout ) * 1000000 |
|---|
| 285 |
/ p_aout->output.output.i_bytes_per_frame |
|---|
| 286 |
/ p_aout->output.output.i_rate |
|---|
| 287 |
* p_aout->output.output.i_frame_length; |
|---|
| 288 |
next_date += mdate(); |
|---|
| 289 |
|
|---|
| 290 |
p_buffer = aout_OutputNextBuffer( p_aout, next_date, false ); |
|---|
| 291 |
} |
|---|
| 292 |
else |
|---|
| 293 |
{ |
|---|
| 294 |
p_buffer = aout_OutputNextBuffer( p_aout, 0, true ); |
|---|
| 295 |
} |
|---|
| 296 |
|
|---|
| 297 |
if ( p_buffer != NULL ) |
|---|
| 298 |
{ |
|---|
| 299 |
p_bytes = p_buffer->p_buffer; |
|---|
| 300 |
i_size = p_buffer->i_nb_bytes; |
|---|
| 301 |
} |
|---|
| 302 |
else |
|---|
| 303 |
{ |
|---|
| 304 |
i_size = DEFAULT_FRAME_SIZE / p_aout->output.output.i_frame_length |
|---|
| 305 |
* p_aout->output.output.i_bytes_per_frame; |
|---|
| 306 |
p_bytes = p_aout->output.p_sys->p_silent_buffer; |
|---|
| 307 |
memset( p_bytes, 0, i_size ); |
|---|
| 308 |
} |
|---|
| 309 |
|
|---|
| 310 |
i_tmp = snd_pcm_plugin_write( p_aout->output.p_sys->p_pcm_handle, |
|---|
| 311 |
(void *) p_bytes, |
|---|
| 312 |
(size_t) i_size ); |
|---|
| 313 |
|
|---|
| 314 |
if( i_tmp < 0 ) |
|---|
| 315 |
{ |
|---|
| 316 |
msg_Err( p_aout, "write failed (%m)" ); |
|---|
| 317 |
} |
|---|
| 318 |
|
|---|
| 319 |
if ( p_buffer != NULL ) |
|---|
| 320 |
{ |
|---|
| 321 |
aout_BufferFree( p_buffer ); |
|---|
| 322 |
} |
|---|
| 323 |
} |
|---|
| 324 |
|
|---|
| 325 |
vlc_restorecancel (canc); |
|---|
| 326 |
return NULL; |
|---|
| 327 |
} |
|---|
| 328 |
|
|---|