| 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 <unistd.h> |
|---|
| 29 |
|
|---|
| 30 |
#ifdef HAVE_CONFIG_H |
|---|
| 31 |
# include "config.h" |
|---|
| 32 |
#endif |
|---|
| 33 |
|
|---|
| 34 |
#include <vlc_common.h> |
|---|
| 35 |
#include <vlc_plugin.h> |
|---|
| 36 |
#include <vlc_aout.h> |
|---|
| 37 |
|
|---|
| 38 |
#include <artsc.h> |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
struct aout_sys_t |
|---|
| 47 |
{ |
|---|
| 48 |
arts_stream_t stream; |
|---|
| 49 |
|
|---|
| 50 |
mtime_t latency; |
|---|
| 51 |
int i_size; |
|---|
| 52 |
}; |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
static int Open ( vlc_object_t * ); |
|---|
| 58 |
static void Close ( vlc_object_t * ); |
|---|
| 59 |
static void Play ( aout_instance_t * ); |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
vlc_module_begin(); |
|---|
| 65 |
set_shortname( "aRts" ); |
|---|
| 66 |
set_description( N_("aRts audio output") ); |
|---|
| 67 |
set_capability( "audio output", 50 ); |
|---|
| 68 |
set_category( CAT_AUDIO ); |
|---|
| 69 |
set_subcategory( SUBCAT_AUDIO_AOUT ); |
|---|
| 70 |
set_callbacks( Open, Close ); |
|---|
| 71 |
vlc_module_end(); |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
static int Open( vlc_object_t *p_this ) |
|---|
| 77 |
{ |
|---|
| 78 |
aout_instance_t *p_aout = (aout_instance_t *)p_this; |
|---|
| 79 |
struct aout_sys_t * p_sys; |
|---|
| 80 |
int i_err; |
|---|
| 81 |
int i_nb_channels; |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
p_sys = malloc( sizeof( aout_sys_t ) ); |
|---|
| 85 |
if( p_sys == NULL ) |
|---|
| 86 |
return VLC_ENOMEM; |
|---|
| 87 |
p_aout->output.p_sys = p_sys; |
|---|
| 88 |
|
|---|
| 89 |
i_err = arts_init(); |
|---|
| 90 |
|
|---|
| 91 |
if( i_err < 0 ) |
|---|
| 92 |
{ |
|---|
| 93 |
msg_Err( p_aout, "arts_init failed (%s)", arts_error_text(i_err) ); |
|---|
| 94 |
free( p_sys ); |
|---|
| 95 |
return VLC_EGENERIC; |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
p_aout->output.pf_play = Play; |
|---|
| 99 |
aout_VolumeSoftInit( p_aout ); |
|---|
| 100 |
|
|---|
| 101 |
p_aout->output.output.i_format = AOUT_FMT_S16_NE; |
|---|
| 102 |
i_nb_channels = aout_FormatNbChannels( &p_aout->output.output ); |
|---|
| 103 |
if ( i_nb_channels > 2 ) |
|---|
| 104 |
{ |
|---|
| 105 |
|
|---|
| 106 |
i_nb_channels = 2; |
|---|
| 107 |
p_aout->output.output.i_physical_channels = |
|---|
| 108 |
AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT; |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
p_sys->stream = arts_play_stream( p_aout->output.output.i_rate, 16, |
|---|
| 113 |
i_nb_channels, "vlc" ); |
|---|
| 114 |
if( p_sys->stream == NULL ) |
|---|
| 115 |
{ |
|---|
| 116 |
msg_Err( p_aout, "cannot open aRts socket" ); |
|---|
| 117 |
free( p_sys ); |
|---|
| 118 |
return VLC_EGENERIC; |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
arts_stream_set( p_sys->stream, ARTS_P_BUFFER_TIME, 50 ); |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
p_sys->latency = (mtime_t)1000 |
|---|
| 126 |
* (mtime_t)arts_stream_get( p_sys->stream, ARTS_P_SERVER_LATENCY ); |
|---|
| 127 |
p_sys->i_size = arts_stream_get( p_sys->stream, ARTS_P_PACKET_SIZE ); |
|---|
| 128 |
|
|---|
| 129 |
msg_Dbg( p_aout, "aRts initialized, latency %i000, %i packets of size %i", |
|---|
| 130 |
arts_stream_get( p_sys->stream, ARTS_P_SERVER_LATENCY ), |
|---|
| 131 |
arts_stream_get( p_sys->stream, ARTS_P_PACKET_COUNT ), |
|---|
| 132 |
arts_stream_get( p_sys->stream, ARTS_P_PACKET_SIZE ) ); |
|---|
| 133 |
|
|---|
| 134 |
p_aout->output.i_nb_samples = p_sys->i_size / sizeof(uint16_t) |
|---|
| 135 |
/ i_nb_channels; |
|---|
| 136 |
|
|---|
| 137 |
return VLC_SUCCESS; |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
static void Play( aout_instance_t *p_aout ) |
|---|
| 144 |
{ |
|---|
| 145 |
struct aout_sys_t * p_sys = p_aout->output.p_sys; |
|---|
| 146 |
aout_buffer_t * p_buffer; |
|---|
| 147 |
int i_tmp; |
|---|
| 148 |
|
|---|
| 149 |
#if 0 |
|---|
| 150 |
while( arts_stream_get( p_sys->stream, ARTS_P_BUFFER_SPACE ) < 16384*3/2 ) |
|---|
| 151 |
{ |
|---|
| 152 |
msleep( 10000 ); |
|---|
| 153 |
} |
|---|
| 154 |
#endif |
|---|
| 155 |
|
|---|
| 156 |
p_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo ); |
|---|
| 157 |
|
|---|
| 158 |
if( p_buffer != NULL ) |
|---|
| 159 |
{ |
|---|
| 160 |
i_tmp = arts_write( p_sys->stream, p_buffer->p_buffer, |
|---|
| 161 |
p_buffer->i_nb_bytes ); |
|---|
| 162 |
|
|---|
| 163 |
if( i_tmp < 0 ) |
|---|
| 164 |
{ |
|---|
| 165 |
msg_Err( p_aout, "write failed (%s)", arts_error_text(i_tmp) ); |
|---|
| 166 |
} |
|---|
| 167 |
|
|---|
| 168 |
aout_BufferFree( p_buffer ); |
|---|
| 169 |
} |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
static void Close( vlc_object_t *p_this ) |
|---|
| 176 |
{ |
|---|
| 177 |
aout_instance_t *p_aout = (aout_instance_t *)p_this; |
|---|
| 178 |
struct aout_sys_t * p_sys = p_aout->output.p_sys; |
|---|
| 179 |
|
|---|
| 180 |
arts_close_stream( p_sys->stream ); |
|---|
| 181 |
arts_free(); |
|---|
| 182 |
free( p_sys ); |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|