+ i_buffer_pos = id->i_buffer_pos;
+
+ /* encode as much data as possible */
+
+#ifdef HAVE_VORBIS_VORBISENC_H
+ if( id->i_buffer_pos == 0 );
+ else if( id->f_dst.i_fourcc == VLC_FOURCC( 'v', 'o', 'r', 'b' ) )
+ {
+ float **buffer;
+ int i, j, i_samples;
+ sout_buffer_t *p_out;
+ ogg_packet op;
+
+ if( !id->b_headers_sent )
+ {
+ ogg_packet header[3];
+ vorbis_analysis_headerout( id->p_vd, id->p_vc,
+ &header[0], &header[1], &header[2]);
+ for( i = 0; i < 3; i++ )
+ {
+ p_out = sout_BufferNew( p_stream->p_sout, header[i].bytes);
+ memcpy( p_out->p_buffer, header[i].packet,
+ header[i].bytes );
+
+ p_out->i_size = header[i].bytes;
+ p_out->i_length = 0;
+
+ p_out->i_dts = p_out->i_pts = id->i_dts;
+
+ sout_BufferChain( out, p_out );
+ }
+ id->b_headers_sent = VLC_TRUE;
+ }
+
+ i_samples = id->i_buffer_pos / id->f_src.i_channels / 2;
+ id->i_samples_delay += i_samples;
+ id->i_buffer_pos = 0;
+
+ buffer = vorbis_analysis_buffer( id->p_vd, i_samples );
+
+ /* convert samples to float and uninterleave */
+ for( i = 0; i < id->f_dst.i_channels; i++ )
+ {
+ for( j = 0 ; j < i_samples ; j++ )
+ {
+ buffer[i][j]= ((float)( ((int16_t *)id->p_buffer)
+ [j*id->f_src.i_channels + i ] ))/ 32768.f;
+ }
+ }
+
+ vorbis_analysis_wrote( id->p_vd, i_samples );
+
+ while( vorbis_analysis_blockout( id->p_vd, id->p_vb ) == 1 )
+ {
+ vorbis_analysis( id->p_vb, NULL );
+ vorbis_bitrate_addblock( id->p_vb );
+
+ while( vorbis_bitrate_flushpacket( id->p_vd, &op ) )
+ {
+ int i_block_size;
+ p_out = sout_BufferNew( p_stream->p_sout, op.bytes );
+ memcpy( p_out->p_buffer, op.packet, op.bytes );
+
+ i_block_size = vorbis_packet_blocksize( id->p_vi, &op );
+
+ if( i_block_size < 0 ) i_block_size = 0;
+ i_samples = ( id->i_last_block_size +
+ i_block_size ) >> 2;
+ id->i_last_block_size = i_block_size;
+
+ p_out->i_size = op.bytes;
+ p_out->i_length = (mtime_t)1000000 *
+ (mtime_t)i_samples /
+ (mtime_t)id->f_dst.i_sample_rate;
+
+ //msg_Err( p_stream, "i_dts: %lld", id->i_dts );
+
+ /* FIXME */
+ p_out->i_dts = id->i_dts;
+ p_out->i_pts = id->i_dts;
+
+ id->i_samples_delay -= i_samples;
+
+ /* update dts */
+ id->i_dts += p_out->i_length;
+ sout_BufferChain( out, p_out );
+
+ }
+ }
+ }
+ else
+#endif
+