+
+
+/*****************************************************************************
+ * QNXaoutThread: asynchronous thread used to DMA the data to the device
+ *****************************************************************************/
+static int QNXaoutThread( aout_instance_t * p_aout )
+{
+ struct aout_sys_t * p_sys = p_aout->output.p_sys;
+
+ while ( !p_aout->b_die )
+ {
+ aout_buffer_t * p_buffer;
+ int i_tmp, i_size;
+ byte_t * p_bytes;
+
+ if( !p_sys->b_initialized )
+ {
+ msleep( THREAD_SLEEP );
+ continue;
+ }
+
+ if ( p_aout->output.output.i_format != AOUT_FMT_SPDIF )
+ {
+ mtime_t next_date = 0;
+
+ /* Get the presentation date of the next write() operation. It
+ * is equal to the current date + duration of buffered samples.
+ * Order is important here, since GetBufInfo is believed to take
+ * more time than mdate(). */
+ next_date = (mtime_t)GetBufInfo( p_aout ) * 1000000
+ / p_aout->output.output.i_bytes_per_frame
+ / p_aout->output.output.i_rate
+ * p_aout->output.output.i_frame_length;
+ next_date += mdate();
+
+ p_buffer = aout_OutputNextBuffer( p_aout, next_date, VLC_FALSE );
+ }
+ else
+ {
+ p_buffer = aout_OutputNextBuffer( p_aout, 0, VLC_TRUE );
+ }
+
+ if ( p_buffer != NULL )
+ {
+ p_bytes = p_buffer->p_buffer;
+ i_size = p_buffer->i_nb_bytes;
+ }
+ else
+ {
+ i_size = DEFAULT_FRAME_SIZE / p_aout->output.output.i_frame_length
+ * p_aout->output.output.i_bytes_per_frame;
+ p_bytes = p_aout->output.p_sys->p_silent_buffer;
+ memset( p_bytes, 0, i_size );
+ }
+
+ i_tmp = snd_pcm_plugin_write( p_aout->output.p_sys->p_pcm_handle,
+ (void *) p_bytes,
+ (size_t) i_size );
+
+ if( i_tmp < 0 )
+ {
+ msg_Err( p_aout, "write failed (%s)", strerror(errno) );
+ }
+
+ if ( p_buffer != NULL )
+ {
+ aout_BufferFree( p_buffer );
+ }
+ }
+
+ return 0;
+}
+