+
+/*****************************************************************************
+ * BeOSThread: asynchronous thread used to DMA the data to the device
+ *****************************************************************************/
+static int BeOSThread( aout_instance_t * p_aout )
+{
+ struct aout_sys_t * p_sys = p_aout->output.p_sys;
+
+ static uint i_buffer_pos;
+
+ p_sys->p_sound->StartPlaying( );
+ p_sys->p_sound->LockForCyclic( &p_sys->p_buffer,
+ (size_t *)&p_sys->i_buffer_size );
+
+ 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;
+ }
+ 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 );
+
+ int i_newbuf_pos;
+ if ( p_buffer != NULL )
+ {
+ p_bytes = p_buffer->p_buffer;
+ i_size = p_buffer->i_nb_bytes;
+ }
+ else
+ {
+ i_size = FRAME_SIZE / p_aout->output.output.i_frame_length
+ * p_aout->output.output.i_bytes_per_frame;
+ p_bytes = (byte_t *)malloc( i_size );
+ memset( p_bytes, 0, i_size );
+ }
+
+ if( (i_newbuf_pos = i_buffer_pos + p_buffer->i_size)
+ > p_aout->output.p_sys->i_buffer_size )
+ {
+ p_aout->p_vlc->pf_memcpy( (void *)((int)p_aout->output.p_sys->p_buffer
+ + i_buffer_pos),
+ p_buffer->p_buffer,
+ p_aout->output.p_sys->i_buffer_size - i_buffer_pos );
+
+ p_aout->p_vlc->pf_memcpy( (void *)((int)p_aout->output.p_sys->p_buffer),
+ p_buffer->p_buffer + p_aout->output.p_sys->i_buffer_size - i_buffer_pos,
+ p_buffer->i_size - ( p_aout->output.p_sys->i_buffer_size - i_buffer_pos ) );
+
+ i_buffer_pos = i_newbuf_pos - i_buffer_pos;
+ }
+ else
+ {
+ p_aout->p_vlc->pf_memcpy( (void *)((int)p_aout->output.p_sys->p_buffer + i_buffer_pos),
+ p_buffer->p_buffer, p_buffer->i_size );
+
+ i_buffer_pos = i_newbuf_pos;
+ }
+ }
+
+ return 0;
+
+}
\ No newline at end of file