| 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 |
extern "C" |
|---|
| 28 |
{ |
|---|
| 29 |
#include <errno.h> |
|---|
| 30 |
|
|---|
| 31 |
#ifdef HAVE_CONFIG_H |
|---|
| 32 |
# include "config.h" |
|---|
| 33 |
#endif |
|---|
| 34 |
|
|---|
| 35 |
#include <vlc_common.h> |
|---|
| 36 |
#include <vlc_plugin.h> |
|---|
| 37 |
#include <vlc_aout.h> |
|---|
| 38 |
|
|---|
| 39 |
#include "aout_internal.h" |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
#include <deschutes/libraries/hdmachinex225/PCMAudioPlayer.h> |
|---|
| 43 |
|
|---|
| 44 |
#define FRAME_SIZE 4096 |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
struct aout_sys_t |
|---|
| 53 |
{ |
|---|
| 54 |
u32 nAlignment; |
|---|
| 55 |
u32 nSizeMultiple; |
|---|
| 56 |
u32 nBuffers; |
|---|
| 57 |
u32 nBufferSize; |
|---|
| 58 |
void ** ppBuffers; |
|---|
| 59 |
u32 nNextBufferIndex; |
|---|
| 60 |
PCMAudioPlayer * pPlayer; |
|---|
| 61 |
}; |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
static int Open ( vlc_object_t * ); |
|---|
| 67 |
static void Close ( vlc_object_t * ); |
|---|
| 68 |
|
|---|
| 69 |
static void Play ( aout_instance_t * ); |
|---|
| 70 |
static void* Thread ( vlc_object_t * ); |
|---|
| 71 |
|
|---|
| 72 |
static void InterleaveS16( int16_t *, int16_t * ); |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
vlc_module_begin(); |
|---|
| 78 |
set_shortname( "Roku HD1000" ); |
|---|
| 79 |
set_description( N_("Roku HD1000 audio output") ); |
|---|
| 80 |
set_capability( "audio output", 100 ); |
|---|
| 81 |
set_category( CAT_AUDIO ); |
|---|
| 82 |
set_subcategory( SUBCAT_AUDIO_AOUT ); |
|---|
| 83 |
set_callbacks( Open, Close ); |
|---|
| 84 |
vlc_module_end(); |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
static int Open( vlc_object_t * p_this ) |
|---|
| 90 |
{ |
|---|
| 91 |
aout_instance_t * p_aout = (aout_instance_t *)p_this; |
|---|
| 92 |
struct aout_sys_t * p_sys; |
|---|
| 93 |
PCMAudioPlayer * pPlayer; |
|---|
| 94 |
int i_volume; |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
p_aout->output.p_sys = p_sys = |
|---|
| 98 |
(aout_sys_t *)malloc( sizeof( aout_sys_t ) ); |
|---|
| 99 |
if( p_aout->output.p_sys == NULL ) |
|---|
| 100 |
return VLC_ENOMEM; |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
p_sys->pPlayer = pPlayer = new PCMAudioPlayer(); |
|---|
| 104 |
if( p_sys->pPlayer == NULL ) |
|---|
| 105 |
{ |
|---|
| 106 |
free( p_sys ); |
|---|
| 107 |
return VLC_ENOMEM; |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
if( !pPlayer->GetBufferRequirements( p_sys->nAlignment, |
|---|
| 112 |
p_sys->nSizeMultiple, |
|---|
| 113 |
p_sys->nBuffers ) ) |
|---|
| 114 |
{ |
|---|
| 115 |
msg_Err( p_aout, "GetBufferRequirements failed" ); |
|---|
| 116 |
delete pPlayer; |
|---|
| 117 |
free( p_sys ); |
|---|
| 118 |
return VLC_EGENERIC; |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
p_sys->nBuffers = __MIN( p_sys->nBuffers, 4 ); |
|---|
| 122 |
|
|---|
| 123 |
p_sys->ppBuffers = (void **)malloc( p_sys->nBuffers * sizeof( void * ) ); |
|---|
| 124 |
if( p_sys->ppBuffers == NULL ) |
|---|
| 125 |
{ |
|---|
| 126 |
delete pPlayer; |
|---|
| 127 |
free( p_sys ); |
|---|
| 128 |
return VLC_ENOMEM; |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
p_sys->nBufferSize = FRAME_SIZE * 4; |
|---|
| 133 |
if( !pPlayer->Open( p_sys->nBuffers, p_sys->nBufferSize, |
|---|
| 134 |
p_sys->ppBuffers ) ) |
|---|
| 135 |
{ |
|---|
| 136 |
msg_Err( p_aout, "Open failed" ); |
|---|
| 137 |
delete pPlayer; |
|---|
| 138 |
free( p_sys->ppBuffers ); |
|---|
| 139 |
free( p_sys ); |
|---|
| 140 |
return VLC_EGENERIC; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
p_sys->nNextBufferIndex = 0; |
|---|
| 144 |
|
|---|
| 145 |
if( !pPlayer->SetSampleRate( p_aout->output.output.i_rate ) ) |
|---|
| 146 |
{ |
|---|
| 147 |
p_aout->output.output.i_rate = 44100; |
|---|
| 148 |
if( !pPlayer->SetSampleRate( p_aout->output.output.i_rate ) ) |
|---|
| 149 |
{ |
|---|
| 150 |
msg_Err( p_aout, "SetSampleRate failed" ); |
|---|
| 151 |
pPlayer->Close(); |
|---|
| 152 |
delete pPlayer; |
|---|
| 153 |
free( p_sys->ppBuffers ); |
|---|
| 154 |
free( p_sys ); |
|---|
| 155 |
return VLC_EGENERIC; |
|---|
| 156 |
} |
|---|
| 157 |
} |
|---|
| 158 |
|
|---|
| 159 |
p_aout->output.output.i_format = AOUT_FMT_S16_NE; |
|---|
| 160 |
p_aout->output.i_nb_samples = FRAME_SIZE; |
|---|
| 161 |
p_aout->output.output.i_physical_channels |
|---|
| 162 |
= AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT; |
|---|
| 163 |
p_aout->output.pf_play = Play; |
|---|
| 164 |
aout_VolumeSoftInit( p_aout ); |
|---|
| 165 |
|
|---|
| 166 |
i_volume = config_GetInt( p_aout->p_libvlc, "volume" ); |
|---|
| 167 |
pPlayer->SetVolume( (u32)__MIN( i_volume * 64, 0xFFFF ) ); |
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
if( vlc_thread_create( p_aout, "aout", Thread, |
|---|
| 171 |
VLC_THREAD_PRIORITY_OUTPUT, false ) ) |
|---|
| 172 |
{ |
|---|
| 173 |
msg_Err( p_aout, "cannot create OSS thread (%m)" ); |
|---|
| 174 |
pPlayer->Close(); |
|---|
| 175 |
delete pPlayer; |
|---|
| 176 |
free( p_sys->ppBuffers ); |
|---|
| 177 |
free( p_sys ); |
|---|
| 178 |
return VLC_ETHREAD; |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
return VLC_SUCCESS; |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
static void Close( vlc_object_t * p_this ) |
|---|
| 188 |
{ |
|---|
| 189 |
u32 i; |
|---|
| 190 |
aout_instance_t * p_aout = (aout_instance_t *)p_this; |
|---|
| 191 |
struct aout_sys_t * p_sys = p_aout->output.p_sys; |
|---|
| 192 |
|
|---|
| 193 |
vlc_object_kill( p_aout ); |
|---|
| 194 |
vlc_thread_join( p_aout ); |
|---|
| 195 |
p_aout->b_die = false; |
|---|
| 196 |
|
|---|
| 197 |
do |
|---|
| 198 |
{ |
|---|
| 199 |
i = p_sys->pPlayer->WaitForBuffer(); |
|---|
| 200 |
} while( i != 0 && i != p_sys->nBuffers ); |
|---|
| 201 |
|
|---|
| 202 |
p_sys->pPlayer->Close(); |
|---|
| 203 |
delete p_sys->pPlayer; |
|---|
| 204 |
|
|---|
| 205 |
free( p_sys->ppBuffers ); |
|---|
| 206 |
free( p_sys ); |
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
static void Play( aout_instance_t * p_aout ) |
|---|
| 213 |
{ |
|---|
| 214 |
} |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
static void* Thread( vlc_object_t *p_this ) |
|---|
| 220 |
{ |
|---|
| 221 |
aout_instance_t * p_aout = (aout_instance_t*)p_this; |
|---|
| 222 |
aout_buffer_t * p_buffer; |
|---|
| 223 |
struct aout_sys_t * p_sys = p_aout->output.p_sys; |
|---|
| 224 |
PCMAudioPlayer * pPlayer = p_sys->pPlayer; |
|---|
| 225 |
int canc = vlc_savecancel (); |
|---|
| 226 |
|
|---|
| 227 |
while( vlc_object_alive (p_aout) ) |
|---|
| 228 |
{ |
|---|
| 229 |
pPlayer->WaitForBuffer(); |
|---|
| 230 |
|
|---|
| 231 |
vlc_mutex_lock( &p_aout->output_fifo_lock ); |
|---|
| 232 |
p_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo ); |
|---|
| 233 |
vlc_mutex_unlock( &p_aout->output_fifo_lock ); |
|---|
| 234 |
|
|---|
| 235 |
#define i p_sys->nNextBufferIndex |
|---|
| 236 |
if( p_buffer == NULL ) |
|---|
| 237 |
{ |
|---|
| 238 |
vlc_memset( p_aout, p_sys->ppBuffers[ i ], 0, |
|---|
| 239 |
p_sys->nBufferSize ); |
|---|
| 240 |
} |
|---|
| 241 |
else |
|---|
| 242 |
{ |
|---|
| 243 |
InterleaveS16( (int16_t *)p_buffer->p_buffer, |
|---|
| 244 |
(int16_t *)p_sys->ppBuffers[ i ] ); |
|---|
| 245 |
aout_BufferFree( p_buffer ); |
|---|
| 246 |
} |
|---|
| 247 |
|
|---|
| 248 |
if( !pPlayer->QueueBuffer( (s16 *)p_sys->ppBuffers[ i ], |
|---|
| 249 |
p_sys->nBufferSize / 2 ) ) |
|---|
| 250 |
{ |
|---|
| 251 |
msg_Err( p_aout, "QueueBuffer failed" ); |
|---|
| 252 |
} |
|---|
| 253 |
|
|---|
| 254 |
i = (i + 1) % p_sys->nBuffers; |
|---|
| 255 |
#undef i |
|---|
| 256 |
} |
|---|
| 257 |
|
|---|
| 258 |
vlc_restorecancel (canc); |
|---|
| 259 |
return NULL; |
|---|
| 260 |
} |
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
static void InterleaveS16( int16_t * p_in, int16_t * p_out ) |
|---|
| 266 |
{ |
|---|
| 267 |
for( int i = 0; i < FRAME_SIZE; i++ ) |
|---|
| 268 |
{ |
|---|
| 269 |
p_out[ i * 2 + 0 ] = p_in[ i * 2 + 1 ]; |
|---|
| 270 |
p_out[ i * 2 + 1 ] = p_in[ i * 2 + 0 ]; |
|---|
| 271 |
} |
|---|
| 272 |
} |
|---|