* ogg.c: ogg muxer module for vlc
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
- * $Id: ogg.c,v 1.17 2003/10/09 19:31:38 gbazin Exp $
+ * $Id: ogg.c,v 1.21 2003/11/21 15:32:08 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Gildas Bazin <gbazin@netcourrier.com>
*****************************************************************************/
#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
+
+#ifdef HAVE_TIME_H
+# include <time.h>
+#endif
#include <vlc/vlc.h>
#include <vlc/input.h>
int i_streams;
mtime_t i_start_dts;
+ int i_next_serial_no;
/* number of logical streams pending to be added */
int i_add_streams;
p_mux->pf_mux = Mux;
p_mux->i_preheader = 1;
+ /* First serial number is random.
+ * (Done like this because on win32 you need to seed the random number
+ * generator once per thread). */
+ srand( (unsigned int)time( NULL ) );
+ p_sys->i_next_serial_no = rand();
+
return VLC_SUCCESS;
}
p_input->p_sys = (void *)p_stream = malloc( sizeof( ogg_stream_t ) );
p_stream->i_cat = p_input->p_fmt->i_cat;
- p_stream->i_fourcc = p_input->p_fmt->i_fourcc;
- p_stream->i_serial_no = rand();
+ p_stream->i_fourcc = p_input->p_fmt->i_codec;
+ p_stream->i_serial_no = p_sys->i_next_serial_no++;
p_stream->i_packet_no = 0;
p_stream->i_sout_headers = 0;
SetDWLE( &p_stream->oggds_header.i_buffer_size, 1024*1024 );
SetWLE( &p_stream->oggds_header.i_bits_per_sample, 0 );
SetDWLE( &p_stream->oggds_header.header.video.i_width,
- p_input->p_fmt->i_width );
+ p_input->p_fmt->video.i_width );
SetDWLE( &p_stream->oggds_header.header.video.i_height,
- p_input->p_fmt->i_height );
+ p_input->p_fmt->video.i_height );
msg_Dbg( p_mux, "mp4v/div3 stream" );
break;
SetDWLE( &p_stream->oggds_header.i_default_len, 1 );
SetDWLE( &p_stream->oggds_header.i_buffer_size, 30*1024 );
SetQWLE( &p_stream->oggds_header.i_samples_per_unit,
- p_input->p_fmt->i_sample_rate );
+ p_input->p_fmt->audio.i_rate );
SetWLE( &p_stream->oggds_header.i_bits_per_sample, 0 );
SetDWLE( &p_stream->oggds_header.header.audio.i_channels,
- p_input->p_fmt->i_channels );
+ p_input->p_fmt->audio.i_channels );
SetDWLE( &p_stream->oggds_header.header.audio.i_block_align,
- p_input->p_fmt->i_block_align );
+ p_input->p_fmt->audio.i_blockalign );
SetDWLE( &p_stream->oggds_header.header.audio.i_avgbytespersec, 0);
msg_Dbg( p_mux, "mpga/a52 stream" );
break;
msg_Dbg( p_mux, "vorbis stream" );
break;
+ case VLC_FOURCC( 's', 'p', 'x', ' ' ):
+ msg_Dbg( p_mux, "speex stream" );
+ break;
+
default:
FREE( p_input->p_sys );
return( VLC_EGENERIC );
p_stream->i_packet_no = 0;
if( p_stream->i_fourcc == VLC_FOURCC( 'v', 'o', 'r', 'b' ) ||
+ p_stream->i_fourcc == VLC_FOURCC( 's', 'p', 'x', ' ' ) ||
p_stream->i_fourcc == VLC_FOURCC( 't', 'h', 'e', 'o' ) )
{
/* Special case, headers are already there in the
* incoming stream or we backed them up earlier */
- /* first packet in order: vorbis/theora info */
+ /* first packet in order: vorbis/speex/theora info */
if( !p_stream->i_sout_headers )
{
p_og = sout_FifoGet( p_mux->pp_inputs[i]->p_fifo );
ogg_stream_t *p_stream = (ogg_stream_t*)p_mux->pp_inputs[i]->p_sys;
if( p_stream->i_fourcc == VLC_FOURCC( 'v', 'o', 'r', 'b' ) ||
+ p_stream->i_fourcc == VLC_FOURCC( 's', 'p', 'x', ' ' ) ||
p_stream->i_fourcc == VLC_FOURCC( 't', 'h', 'e', 'o' ) )
{
/* Special case, headers are already there in the incoming stream.
p_og = OggStreamFlush( p_mux, &p_stream->os, 0 );
sout_BufferChain( &p_hdr, p_og );
}
+
+ /* Special case for mp4v */
+ if( p_stream->i_fourcc == VLC_FOURCC( 'm', 'p', '4', 'v' ) &&
+ p_mux->pp_inputs[i]->p_fmt->i_extra )
+ {
+ /* Send a packet with the VOL data */
+ op.bytes = p_mux->pp_inputs[i]->p_fmt->i_extra;
+ op.packet = p_mux->pp_inputs[i]->p_fmt->p_extra;
+ op.b_o_s = 0;
+ op.e_o_s = 0;
+ op.granulepos = 0;
+ op.packetno = p_stream->i_packet_no++;
+ ogg_stream_packetin( &p_stream->os, &op );
+ p_og = OggStreamFlush( p_mux, &p_stream->os, 0 );
+ sout_BufferChain( &p_hdr, p_og );
+ }
}
/* set HEADER flag */
p_data = sout_FifoGet( p_input->p_fifo );
if( p_stream->i_fourcc != VLC_FOURCC( 'v', 'o', 'r', 'b' ) &&
+ p_stream->i_fourcc != VLC_FOURCC( 's', 'p', 'x', ' ' ) &&
p_stream->i_fourcc != VLC_FOURCC( 't', 'h', 'e', 'o' ) )
{
sout_BufferReallocFromPreHeader( p_mux->p_sout, p_data, 1 );
if( p_stream->i_cat == AUDIO_ES )
{
- if( p_stream->i_fourcc == VLC_FOURCC( 'v', 'o', 'r', 'b' ) )
+ if( p_stream->i_fourcc == VLC_FOURCC( 'v', 'o', 'r', 'b' ) ||
+ p_stream->i_fourcc == VLC_FOURCC( 's', 'p', 'x', ' ' ) )
{
/* number of sample from begining + current packet */
op.granulepos =
( i_dts + p_data->i_length - p_sys->i_start_dts ) *
- p_input->p_fmt->i_sample_rate / I64C(1000000);
+ p_input->p_fmt->audio.i_rate / I64C(1000000);
}
else
{
if( p_stream->i_fourcc == VLC_FOURCC( 't', 'h', 'e', 'o' ) )
{
/* FIXME, we assume only keyframes and 25fps */
- op.granulepos = ( ( i_dts - p_sys->i_start_dts ) * I64C(25)
+ op.granulepos = ( ( i_dts - p_sys->i_start_dts ) * I64C(25)
/ I64C(1000000) ) << p_stream->i_keyframe_granule_shift;
}
else
ogg_stream_packetin( &p_stream->os, &op );
- if( p_stream->i_cat == SPU_ES )
+ if( p_stream->i_cat == SPU_ES ||
+ p_stream->i_fourcc == VLC_FOURCC( 's', 'p', 'x', ' ' ) )
{
- /* Subtitles need to be flushed to be sent on time */
+ /* Subtitles or Speex packets are quite small so they
+ * need to be flushed to be sent on time */
sout_BufferChain( &p_og, OggStreamFlush( p_mux, &p_stream->os,
p_data->i_dts ) );
}