Commit 8c40a0d2 authored by Gildas Bazin's avatar Gildas Bazin

* modules/codec/flac.c: several fixes to the flac decoder and encoder.
* modules/mux/ogg.c: fixed flac in ogg.
* modules/demux/ogg.c: fix for flac seeking.
parent e852a093
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* flac.c: flac decoder/packetizer/encoder module making use of libflac * flac.c: flac decoder/packetizer/encoder module making use of libflac
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2001 VideoLAN * Copyright (C) 1999-2001 VideoLAN
* $Id: flac.c,v 1.5 2003/11/22 23:39:14 fenrir Exp $ * $Id: flac.c,v 1.6 2003/12/04 22:37:02 gbazin Exp $
* *
* Authors: Gildas Bazin <gbazin@netcourrier.com> * Authors: Gildas Bazin <gbazin@netcourrier.com>
* Sigmund Augdal <sigmunau@idi.ntnu.no> * Sigmund Augdal <sigmunau@idi.ntnu.no>
...@@ -41,9 +41,6 @@ ...@@ -41,9 +41,6 @@
*****************************************************************************/ *****************************************************************************/
struct decoder_sys_t struct decoder_sys_t
{ {
/* Module mode */
vlc_bool_t b_packetizer;
/* /*
* Input properties * Input properties
*/ */
...@@ -184,7 +181,6 @@ static int OpenDecoder( vlc_object_t *p_this ) ...@@ -184,7 +181,6 @@ static int OpenDecoder( vlc_object_t *p_this )
/* Misc init */ /* Misc init */
aout_DateSet( &p_sys->end_date, 0 ); aout_DateSet( &p_sys->end_date, 0 );
p_sys->b_packetizer = VLC_FALSE;
p_sys->i_state = STATE_NOSYNC; p_sys->i_state = STATE_NOSYNC;
p_sys->b_stream_info = VLC_FALSE; p_sys->b_stream_info = VLC_FALSE;
...@@ -237,8 +233,6 @@ static int OpenPacketizer( vlc_object_t *p_this ) ...@@ -237,8 +233,6 @@ static int OpenPacketizer( vlc_object_t *p_this )
if( i_ret != VLC_SUCCESS ) return i_ret; if( i_ret != VLC_SUCCESS ) return i_ret;
p_dec->p_sys->b_packetizer = VLC_TRUE;
es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in ); es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
return i_ret; return i_ret;
...@@ -257,12 +251,17 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block ) ...@@ -257,12 +251,17 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
if( !pp_block || !*pp_block ) return NULL; if( !pp_block || !*pp_block ) return NULL;
#if 0 if( !aout_DateGet( &p_sys->end_date ) && !(*pp_block)->i_pts )
{
/* We've just started the stream, wait for the first PTS. */
block_Release( *pp_block );
return NULL;
}
if( (*pp_block)->b_discontinuity ) if( (*pp_block)->b_discontinuity )
{ {
p_sys->i_state = STATE_NOSYNC; p_sys->i_state = STATE_NOSYNC;
} }
#endif
block_BytestreamPush( &p_sys->bytestream, *pp_block ); block_BytestreamPush( &p_sys->bytestream, *pp_block );
...@@ -343,14 +342,14 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block ) ...@@ -343,14 +342,14 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
if( p_header[0] == 0xFF && p_header[1] == 0xF8 ) if( p_header[0] == 0xFF && p_header[1] == 0xF8 )
{ {
/* Check if frame is valid and get frame info */ /* Check if frame is valid and get frame info */
p_sys->i_frame_length = int i_frame_length =
SyncInfo( p_dec, p_header, SyncInfo( p_dec, p_header,
&p_sys->i_channels, &p_sys->i_channels,
&p_sys->i_channels_conf, &p_sys->i_channels_conf,
&p_sys->i_rate, &p_sys->i_rate,
&p_sys->i_bits_per_sample ); &p_sys->i_bits_per_sample );
if( p_sys->i_frame_length ) if( i_frame_length )
{ {
p_sys->i_state = STATE_SEND_DATA; p_sys->i_state = STATE_SEND_DATA;
break; break;
...@@ -386,8 +385,9 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block ) ...@@ -386,8 +385,9 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
/* Date management */ /* Date management */
p_sout_block->i_pts = p_sout_block->i_pts =
p_sout_block->i_dts = aout_DateGet( &p_sys->end_date ); p_sout_block->i_dts = aout_DateGet( &p_sys->end_date );
p_sout_block->i_length =
aout_DateIncrement( &p_sys->end_date, p_sys->i_frame_length ); aout_DateIncrement( &p_sys->end_date, p_sys->i_frame_length );
p_sout_block->i_length =
aout_DateGet( &p_sys->end_date ) - p_sout_block->i_pts;
return p_sout_block; return p_sout_block;
} }
...@@ -405,13 +405,6 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) ...@@ -405,13 +405,6 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
if( !pp_block || !*pp_block ) return NULL; if( !pp_block || !*pp_block ) return NULL;
if( !aout_DateGet( &p_sys->end_date ) && !(*pp_block)->i_pts )
{
/* We've just started the stream, wait for the first PTS. */
block_Release( *pp_block );
return NULL;
}
p_sys->p_aout_buffer = 0; p_sys->p_aout_buffer = 0;
if( ( p_sys->p_block = PacketizeBlock( p_dec, pp_block ) ) ) if( ( p_sys->p_block = PacketizeBlock( p_dec, pp_block ) ) )
{ {
...@@ -486,18 +479,6 @@ DecoderWriteCallback( const FLAC__StreamDecoder *decoder, ...@@ -486,18 +479,6 @@ DecoderWriteCallback( const FLAC__StreamDecoder *decoder,
decoder_t *p_dec = (decoder_t *)client_data; decoder_t *p_dec = (decoder_t *)client_data;
decoder_sys_t *p_sys = p_dec->p_sys; decoder_sys_t *p_sys = p_dec->p_sys;
if( p_sys->p_block && p_sys->p_block->i_pts != 0 &&
p_sys->p_block->i_pts != aout_DateGet( &p_sys->end_date ) )
{
aout_DateSet( &p_sys->end_date, p_sys->p_block->i_pts );
}
else if( !aout_DateGet( &p_sys->end_date ) )
{
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
if( p_sys->p_block ) p_sys->p_block->i_pts = 0;
p_sys->p_aout_buffer = p_sys->p_aout_buffer =
p_dec->pf_aout_buffer_new( p_dec, frame->header.blocksize ); p_dec->pf_aout_buffer_new( p_dec, frame->header.blocksize );
...@@ -515,10 +496,10 @@ DecoderWriteCallback( const FLAC__StreamDecoder *decoder, ...@@ -515,10 +496,10 @@ DecoderWriteCallback( const FLAC__StreamDecoder *decoder,
frame->header.channels, frame->header.blocksize ); frame->header.channels, frame->header.blocksize );
} }
/* Date management */ /* Date management (already done by packetizer) */
p_sys->p_aout_buffer->start_date = aout_DateGet( &p_sys->end_date ); p_sys->p_aout_buffer->start_date = p_sys->p_block->i_pts;
p_sys->p_aout_buffer->end_date = p_sys->p_aout_buffer->end_date =
aout_DateIncrement( &p_sys->end_date, frame->header.blocksize ); p_sys->p_block->i_pts + p_sys->p_block->i_length;
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
} }
...@@ -1093,6 +1074,7 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -1093,6 +1074,7 @@ static int OpenEncoder( vlc_object_t *p_this )
p_sys->i_headers = 0; p_sys->i_headers = 0;
p_sys->p_buffer = 0; p_sys->p_buffer = 0;
p_sys->i_buffer = 0; p_sys->i_buffer = 0;
p_sys->i_samples_delay = 0;
/* Create flac encoder */ /* Create flac encoder */
p_sys->p_flac = FLAC__stream_encoder_new(); p_sys->p_flac = FLAC__stream_encoder_new();
...@@ -1197,18 +1179,18 @@ EncoderWriteCallback( const FLAC__StreamEncoder *encoder, ...@@ -1197,18 +1179,18 @@ EncoderWriteCallback( const FLAC__StreamEncoder *encoder,
encoder_sys_t *p_sys = p_enc->p_sys; encoder_sys_t *p_sys = p_enc->p_sys;
block_t *p_block; block_t *p_block;
if( samples == 0 && p_sys->i_headers <= 1 ) if( samples == 0 )
{ {
if( p_sys->i_headers == 1 ) if( p_sys->i_headers == 1 )
{ {
msg_Err( p_enc, "Writing STREAMINFO: %i", bytes ); msg_Dbg( p_enc, "Writing STREAMINFO: %i", bytes );
/* Backup the STREAMINFO metadata block */ /* Backup the STREAMINFO metadata block */
p_enc->fmt_out.i_extra = STREAMINFO_SIZE + 4; p_enc->fmt_out.i_extra = STREAMINFO_SIZE + 4;
p_enc->fmt_out.p_extra = malloc( STREAMINFO_SIZE + 4 ); p_enc->fmt_out.p_extra = malloc( STREAMINFO_SIZE + 4 );
memcpy( p_enc->fmt_out.p_extra, "fLaC", 4 ); memcpy( p_enc->fmt_out.p_extra, "fLaC", 4 );
memcpy( ((uint8_t *)p_enc->fmt_out.p_extra) + 4, buffer, memcpy( ((uint8_t *)p_enc->fmt_out.p_extra) + 4, buffer,
STREAMINFO_SIZE + 4 ); STREAMINFO_SIZE );
/* Fake this as the last metadata block */ /* Fake this as the last metadata block */
((uint8_t*)p_enc->fmt_out.p_extra)[4] |= 0x80; ((uint8_t*)p_enc->fmt_out.p_extra)[4] |= 0x80;
...@@ -1220,7 +1202,15 @@ EncoderWriteCallback( const FLAC__StreamEncoder *encoder, ...@@ -1220,7 +1202,15 @@ EncoderWriteCallback( const FLAC__StreamEncoder *encoder,
p_block = block_New( p_enc, bytes ); p_block = block_New( p_enc, bytes );
memcpy( p_block->p_buffer, buffer, bytes ); memcpy( p_block->p_buffer, buffer, bytes );
p_block->i_dts = p_block->i_pts = p_block->i_length = 0; p_block->i_dts = p_block->i_pts = p_sys->i_pts;
p_sys->i_samples_delay -= samples;
p_block->i_length = (mtime_t)1000000 *
(mtime_t)samples / (mtime_t)p_enc->fmt_in.audio.i_rate;
/* Update pts */
p_sys->i_pts += p_block->i_length;
block_ChainAppend( &p_sys->p_chain, p_block ); block_ChainAppend( &p_sys->p_chain, p_block );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ogg.c : ogg stream input module for vlc * ogg.c : ogg stream input module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001-2003 VideoLAN * Copyright (C) 2001-2003 VideoLAN
* $Id: ogg.c,v 1.48 2003/11/27 04:11:40 fenrir Exp $ * $Id: ogg.c,v 1.49 2003/12/04 22:37:02 gbazin Exp $
* *
* Authors: Gildas Bazin <gbazin@netcourrier.com> * Authors: Gildas Bazin <gbazin@netcourrier.com>
* *
...@@ -77,7 +77,7 @@ struct demux_sys_t ...@@ -77,7 +77,7 @@ struct demux_sys_t
/* program clock reference (in units of 90kHz) derived from the pcr of /* program clock reference (in units of 90kHz) derived from the pcr of
* the sub-streams */ * the sub-streams */
mtime_t i_pcr; mtime_t i_pcr;
int b_reinit; int i_old_synchro_state;
/* stream state */ /* stream state */
int i_eos; int i_eos;
...@@ -1027,6 +1027,8 @@ static int Activate( vlc_object_t * p_this ) ...@@ -1027,6 +1027,8 @@ static int Activate( vlc_object_t * p_this )
/* Begnning of stream, tell the demux to look for elementary streams. */ /* Begnning of stream, tell the demux to look for elementary streams. */
p_ogg->i_eos = 0; p_ogg->i_eos = 0;
p_ogg->i_old_synchro_state = !SYNCHRO_REINIT;
return 0; return 0;
error: error:
...@@ -1161,6 +1163,7 @@ static int Demux( input_thread_t * p_input ) ...@@ -1161,6 +1163,7 @@ static int Demux( input_thread_t * p_input )
{ {
msg_Warn( p_input, "synchro reinit" ); msg_Warn( p_input, "synchro reinit" );
if( p_ogg->i_old_synchro_state != SYNCHRO_REINIT )
for( i_stream = 0; i_stream < p_ogg->i_streams; i_stream++ ) for( i_stream = 0; i_stream < p_ogg->i_streams; i_stream++ )
{ {
/* we'll trash all the data until we find the next pcr */ /* we'll trash all the data until we find the next pcr */
...@@ -1169,6 +1172,7 @@ static int Demux( input_thread_t * p_input ) ...@@ -1169,6 +1172,7 @@ static int Demux( input_thread_t * p_input )
p_stream->i_interpolated_pcr = -1; p_stream->i_interpolated_pcr = -1;
ogg_stream_reset( &p_stream->os ); ogg_stream_reset( &p_stream->os );
} }
if( p_ogg->i_old_synchro_state != SYNCHRO_REINIT )
ogg_sync_reset( &p_ogg->oy ); ogg_sync_reset( &p_ogg->oy );
} }
...@@ -1251,6 +1255,9 @@ static int Demux( input_thread_t * p_input ) ...@@ -1251,6 +1255,9 @@ static int Demux( input_thread_t * p_input )
#undef p_stream #undef p_stream
p_ogg->i_old_synchro_state =
p_input->stream.p_selected_program->i_synchro_state;
return 1; return 1;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ogg.c: ogg muxer module for vlc * ogg.c: ogg muxer module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: ogg.c,v 1.23 2003/11/24 00:01:42 gbazin Exp $ * $Id: ogg.c,v 1.24 2003/12/04 22:37:02 gbazin Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Gildas Bazin <gbazin@netcourrier.com> * Gildas Bazin <gbazin@netcourrier.com>
...@@ -912,6 +912,7 @@ static int Mux( sout_mux_t *p_mux ) ...@@ -912,6 +912,7 @@ static int Mux( sout_mux_t *p_mux )
p_data = sout_FifoGet( p_input->p_fifo ); p_data = sout_FifoGet( p_input->p_fifo );
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( 'f', 'l', 'a', 'c' ) &&
p_stream->i_fourcc != VLC_FOURCC( 's', 'p', 'x', ' ' ) && p_stream->i_fourcc != VLC_FOURCC( 's', 'p', 'x', ' ' ) &&
p_stream->i_fourcc != VLC_FOURCC( 't', 'h', 'e', 'o' ) ) p_stream->i_fourcc != VLC_FOURCC( 't', 'h', 'e', 'o' ) )
{ {
...@@ -928,12 +929,13 @@ static int Mux( sout_mux_t *p_mux ) ...@@ -928,12 +929,13 @@ static int Mux( sout_mux_t *p_mux )
if( p_stream->i_cat == AUDIO_ES ) 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( 'f', 'l', 'a', 'c' ) ||
p_stream->i_fourcc == VLC_FOURCC( 's', 'p', 'x', ' ' ) ) p_stream->i_fourcc == VLC_FOURCC( 's', 'p', 'x', ' ' ) )
{ {
/* number of sample from begining + current packet */ /* number of sample from begining + current packet */
op.granulepos = op.granulepos =
( i_dts + p_data->i_length - p_sys->i_start_dts ) * ( i_dts - p_sys->i_start_dts + p_data->i_length ) *
p_input->p_fmt->audio.i_rate / I64C(1000000); (mtime_t)p_input->p_fmt->audio.i_rate / I64C(1000000);
} }
else else
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment