Commit f6cc8a39 authored by Laurent Aimar's avatar Laurent Aimar

Convert stream to system timestamp after the decoder.

- This is needed for proper seek/pause/fast forward/...
- The decoder/packetizer do not need to scale packet length anymore as the
decoder thread do it.
parent 4c247f8a
......@@ -147,8 +147,31 @@ struct encoder_t
* @}
*/
/**
* This function returns a specific input attachment (using its name).
*
* You MUST release the returned value.
*/
VLC_EXPORT( input_attachment_t *, decoder_GetInputAttachment, ( decoder_t *, const char *psz_name ) LIBVLC_USED );
/**
* This function gives all input attachments at once.
*
* You MUST release the returned values
*/
VLC_EXPORT( int, decoder_GetInputAttachments, ( decoder_t *p_dec, input_attachment_t ***ppp_attachment, int *pi_attachment ) );
/**
* This function converts a decoder timestamp into a display date comparable
* to mdate().
* You MUST use it *only* for gathering statistics about speed.
*/
VLC_EXPORT( mtime_t, decoder_GetDisplayDate, ( decoder_t *, mtime_t ) LIBVLC_USED );
/**
* This function returns the current input rate.
* You MUST use it *only* for gathering statistics about speed.
*/
VLC_EXPORT( int, decoder_GetDisplayRate, ( decoder_t * ) );
#endif /* _VLC_CODEC_H */
......@@ -45,5 +45,5 @@ VLC_EXPORT( void, decoder_SynchroTrash, ( decoder_synchro_t * ) );
VLC_EXPORT( void, decoder_SynchroDecode, ( decoder_synchro_t * ) );
VLC_EXPORT( void, decoder_SynchroEnd, ( decoder_synchro_t *, int, bool ) );
VLC_EXPORT( mtime_t, decoder_SynchroDate, ( decoder_synchro_t * ) LIBVLC_USED );
VLC_EXPORT( void, decoder_SynchroNewPicture, ( decoder_synchro_t *, int, int, mtime_t, mtime_t, int, bool ) );
VLC_EXPORT( void, decoder_SynchroNewPicture, ( decoder_synchro_t *, int, int, mtime_t, mtime_t, bool ) );
......@@ -34,7 +34,6 @@
#include <vlc_plugin.h>
#include <vlc_codec.h>
#include <vlc_aout.h>
#include <vlc_input.h>
#include <vlc_block_helper.h>
#include <vlc_bits.h>
......@@ -84,8 +83,6 @@ struct decoder_sys_t
mtime_t i_pts;
int i_frame_size, i_bit_rate;
unsigned int i_rate, i_channels, i_channels_conf;
int i_input_rate;
};
enum {
......@@ -147,7 +144,6 @@ static int OpenCommon( vlc_object_t *p_this, bool b_packetizer )
aout_DateSet( &p_sys->end_date, 0 );
p_sys->bytestream = block_BytestreamInit();
p_sys->i_input_rate = INPUT_RATE_DEFAULT;
/* Set output properties */
p_dec->fmt_out.i_cat = AUDIO_ES;
......@@ -207,9 +203,6 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
if( (*pp_block)->i_rate > 0 )
p_sys->i_input_rate = (*pp_block)->i_rate;
block_BytestreamPush( &p_sys->bytestream, *pp_block );
while( 1 )
......@@ -408,8 +401,7 @@ static aout_buffer_t *GetAoutBuffer( decoder_t *p_dec )
if( p_buf == NULL ) return NULL;
p_buf->start_date = aout_DateGet( &p_sys->end_date );
p_buf->end_date = aout_DateIncrement( &p_sys->end_date,
A52_FRAME_NB * p_sys->i_input_rate / INPUT_RATE_DEFAULT );
p_buf->end_date = aout_DateIncrement( &p_sys->end_date, A52_FRAME_NB );
return p_buf;
}
......@@ -428,9 +420,7 @@ static block_t *GetSoutBuffer( decoder_t *p_dec )
p_block->i_pts = p_block->i_dts = aout_DateGet( &p_sys->end_date );
p_block->i_length =
aout_DateIncrement( &p_sys->end_date,
A52_FRAME_NB * p_sys->i_input_rate / INPUT_RATE_DEFAULT ) -
p_block->i_pts;
aout_DateIncrement( &p_sys->end_date, A52_FRAME_NB ) - p_block->i_pts;
return p_block;
}
......
......@@ -32,7 +32,6 @@
#include <vlc_common.h>
#include <vlc_aout.h>
#include <vlc_codec.h>
#include <vlc_input.h>
/* ffmpeg header */
#ifdef HAVE_LIBAVCODEC_AVCODEC_H
......@@ -82,8 +81,6 @@ struct decoder_sys_t
/* */
int i_reject_count;
int i_input_rate;
};
/*****************************************************************************
......@@ -207,7 +204,6 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
p_sys->p_samples = NULL;
p_sys->i_samples = 0;
p_sys->i_reject_count = 0;
p_sys->i_input_rate = INPUT_RATE_DEFAULT;
aout_DateSet( &p_sys->end_date, 0 );
if( p_dec->fmt_in.audio.i_rate )
......@@ -240,8 +236,7 @@ static aout_buffer_t *SplitBuffer( decoder_t *p_dec )
}
p_buffer->start_date = aout_DateGet( &p_sys->end_date );
p_buffer->end_date = aout_DateIncrement( &p_sys->end_date,
i_samples * p_sys->i_input_rate / INPUT_RATE_DEFAULT );
p_buffer->end_date = aout_DateIncrement( &p_sys->end_date, i_samples );
memcpy( p_buffer->p_buffer, p_sys->p_samples, p_buffer->i_nb_bytes );
......@@ -265,9 +260,6 @@ aout_buffer_t * DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
p_block = *pp_block;
if( p_block->i_rate > 0 )
p_sys->i_input_rate = p_block->i_rate;
if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
{
block_Release( p_block );
......
......@@ -32,7 +32,6 @@
#include <vlc_common.h>
#include <vlc_codec.h>
#include <vlc_vout.h>
#include <vlc_input.h> /* hmmm, just for INPUT_RATE_DEFAULT */
#include <vlc_codecs.h> /* BITMAPINFOHEADER */
/* ffmpeg header */
......@@ -100,7 +99,7 @@ static void ffmpeg_CopyPicture ( decoder_t *, picture_t *, AVFrame * );
static int ffmpeg_GetFrameBuf ( struct AVCodecContext *, AVFrame * );
static int ffmpeg_ReGetFrameBuf( struct AVCodecContext *, AVFrame * );
static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *, AVFrame * );
static void ffmpeg_NextPts( decoder_t *, int i_block_rate );
static void ffmpeg_NextPts( decoder_t * );
static uint32_t ffmpeg_CodecTag( vlc_fourcc_t fcc )
{
......@@ -617,7 +616,7 @@ picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
if( !b_drawpicture && p_pic )
p_dec->pf_vout_buffer_del( p_dec, p_pic );
ffmpeg_NextPts( p_dec, p_block->i_rate );
ffmpeg_NextPts( p_dec );
continue;
}
......@@ -671,7 +670,7 @@ picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
int i;
p_pic->date = p_sys->i_pts;
ffmpeg_NextPts( p_dec, p_block->i_rate );
ffmpeg_NextPts( p_dec );
if( p_sys->b_first_frame )
{
......@@ -1007,7 +1006,7 @@ static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *p_context,
}
}
static void ffmpeg_NextPts( decoder_t *p_dec, int i_block_rate )
static void ffmpeg_NextPts( decoder_t *p_dec )
{
decoder_sys_t *p_sys = p_dec->p_sys;
......@@ -1020,16 +1019,14 @@ static void ffmpeg_NextPts( decoder_t *p_dec, int i_block_rate )
{
p_sys->i_pts += INT64_C(1000000) *
(2 + p_sys->p_ff_pic->repeat_pict) *
p_dec->fmt_in.video.i_frame_rate_base *
i_block_rate / INPUT_RATE_DEFAULT /
p_dec->fmt_in.video.i_frame_rate_base /
(2 * p_dec->fmt_in.video.i_frame_rate);
}
else if( p_sys->p_context->time_base.den > 0 )
{
p_sys->i_pts += INT64_C(1000000) *
(2 + p_sys->p_ff_pic->repeat_pict) *
p_sys->p_context->time_base.num *
i_block_rate / INPUT_RATE_DEFAULT /
p_sys->p_context->time_base.num /
(2 * p_sys->p_context->time_base.den);
}
}
......@@ -85,8 +85,9 @@ struct decoder_sys_t
struct subpicture_sys_t
{
decoder_t *p_dec;
void *p_subs_data;
int i_subs_len;
void *p_subs_data;
int i_subs_len;
mtime_t i_stream_system_delta;
};
/*****************************************************************************
......@@ -165,8 +166,6 @@ static subpicture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
return NULL;
p_block = *pp_block;
if( p_block->i_rate != 0 )
p_block->i_length = p_block->i_length * p_block->i_rate / INPUT_RATE_DEFAULT;
*pp_block = NULL;
if( p_block->i_buffer == 0 || p_block->p_buffer[0] == '\0' )
......@@ -203,6 +202,8 @@ static subpicture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
}
memcpy( p_spu->p_sys->p_subs_data, p_block->p_buffer,
p_block->i_buffer );
p_spu->p_sys->i_stream_system_delta =
p_block->i_pts - decoder_GetDisplayDate( p_dec, p_block->i_pts );
p_spu->i_start = p_block->i_pts;
p_spu->i_stop = p_block->i_pts + p_block->i_length;
......@@ -241,7 +242,7 @@ static void PreRender( spu_t *p_spu, subpicture_t *p_subpic,
}
static void UpdateRegions( spu_t *p_spu, subpicture_t *p_subpic,
const video_format_t *p_fmt, mtime_t ts )
const video_format_t *p_fmt, mtime_t i_ts )
{
decoder_t *p_dec = p_subpic->p_sys->p_dec;
decoder_sys_t *p_sys = p_dec->p_sys;
......@@ -308,7 +309,7 @@ static void UpdateRegions( spu_t *p_spu, subpicture_t *p_subpic,
csri_frame.pixfmt = CSRI_F_BGRA;
csri_frame.planes[0] = (unsigned char*)p_spu_region->p_picture->Y_PIXELS;
csri_frame.strides[0] = p_spu_region->p_picture->Y_PITCH;
csri_render( p_sys->p_instance, &csri_frame, ts * 0.000001 );
csri_render( p_sys->p_instance, &csri_frame, (i_ts + p_subpic->p_sys->i_stream_system_delta) * 0.000001 );
}
}
......@@ -28,9 +28,9 @@
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_input.h>
#include <vlc_aout.h>
#include <vlc_codec.h>
#include <vlc_input.h>
#include <faad.h>
......@@ -73,8 +73,6 @@ struct decoder_sys_t
uint32_t pi_channel_positions[MAX_CHANNEL_POSITIONS];
bool b_sbr, b_ps;
int i_input_rate;
};
static const uint32_t pi_channels_in[MAX_CHANNEL_POSITIONS] =
......@@ -188,8 +186,6 @@ static int Open( vlc_object_t *p_this )
p_sys->i_buffer = p_sys->i_buffer_size = 0;
p_sys->p_buffer = NULL;
p_sys->i_input_rate = INPUT_RATE_DEFAULT;
/* Faad2 can't deal with truncated data (eg. from MPEG TS) */
p_dec->b_need_packetized = true;
......@@ -215,9 +211,6 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
if( p_block->i_rate > 0 )
p_sys->i_input_rate = p_block->i_rate;
/* Remove ADTS header if we have decoder specific config */
if( p_dec->fmt_in.i_extra && p_block->i_buffer > 7 )
{
......@@ -431,8 +424,7 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
}
p_out->start_date = aout_DateGet( &p_sys->date );
p_out->end_date = aout_DateIncrement( &p_sys->date,
(frame.samples / frame.channels) * p_sys->i_input_rate / INPUT_RATE_DEFAULT );
p_out->end_date = aout_DateIncrement( &p_sys->date, frame.samples / frame.channels );
DoReordering( (uint32_t *)p_out->p_buffer, samples,
frame.samples / frame.channels, frame.channels,
......
......@@ -103,8 +103,9 @@ static void DecSysHold( decoder_sys_t *p_sys );
struct subpicture_sys_t
{
decoder_sys_t *p_dec_sys;
void *p_subs_data;
int i_subs_len;
void *p_subs_data;
int i_subs_len;
mtime_t i_stream_system_delta;
};
typedef struct
......@@ -218,24 +219,9 @@ static subpicture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
p_block = *pp_block;
if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
{
msg_Dbg( p_dec, "Resetting libass track after time discontinuity" );
/* We need to reset our tracks for the time discontinuity to be
* handled */
vlc_mutex_lock( p_sys->p_ass->p_lock );
if( p_sys->p_track )
ass_free_track( p_sys->p_track );
p_sys->p_track = ass_new_track( p_sys->p_ass->p_library );
if( p_sys->p_track )
ass_process_codec_private( p_sys->p_track,
p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra );
vlc_mutex_unlock( p_sys->p_ass->p_lock );
block_Release( p_block );
return NULL;
}
if( p_block->i_rate != 0 )
p_block->i_length = p_block->i_length * p_block->i_rate / INPUT_RATE_DEFAULT;
*pp_block = NULL;
if( p_block->i_buffer == 0 || p_block->p_buffer[0] == '\0' )
......@@ -271,6 +257,8 @@ static subpicture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
}
memcpy( p_spu->p_sys->p_subs_data, p_block->p_buffer,
p_block->i_buffer );
p_spu->p_sys->i_stream_system_delta =
p_block->i_pts - decoder_GetDisplayDate( p_dec, p_block->i_pts );
p_spu->i_start = p_block->i_pts;
p_spu->i_stop = p_block->i_pts + p_block->i_length;
......@@ -354,7 +342,8 @@ static void UpdateRegions( spu_t *p_spu, subpicture_t *p_subpic,
/* */
int i_changed;
ass_image_t *p_img = ass_render_frame( p_ass->p_renderer, p_sys->p_track, i_ts/1000, &i_changed );
ass_image_t *p_img = ass_render_frame( p_ass->p_renderer, p_sys->p_track,
(i_ts + p_subpic->p_sys->i_stream_system_delta)/1000, &i_changed );
if( !i_changed && !b_fmt_changed )
{
......
......@@ -57,7 +57,6 @@ struct decoder_sys_t
mtime_t i_current_pts;
mtime_t i_previous_dts;
mtime_t i_current_dts;
int i_current_rate;
picture_t * p_picture_to_destroy;
bool b_garbage_pic;
bool b_after_sequence_header; /* is it the next frame after
......@@ -247,7 +246,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
if ( p_sys->b_slice_i )
{
decoder_SynchroNewPicture( p_sys->p_synchro,
I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate,
I_CODING_TYPE, 2, 0, 0,
p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
decoder_SynchroDecode( p_sys->p_synchro );
decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
......@@ -283,8 +282,6 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
p_sys->i_current_dts = p_block->i_dts;
}
p_sys->i_current_rate = p_block->i_rate;
mpeg2_buffer( p_sys->p_mpeg2dec, p_block->p_buffer,
p_block->p_buffer + p_block->i_buffer );
......@@ -355,7 +352,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
/* Intra-slice refresh. Simulate a blank I picture. */
msg_Dbg( p_dec, "intra-slice refresh stream" );
decoder_SynchroNewPicture( p_sys->p_synchro,
I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate,
I_CODING_TYPE, 2, 0, 0,
p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
decoder_SynchroDecode( p_sys->p_synchro );
decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
......@@ -405,7 +402,6 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
p_sys->p_info->current_picture->nb_fields == 1 ? 2 :
p_sys->p_info->current_picture->nb_fields, i_pts, i_dts,
p_sys->i_current_rate,
p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
if( !p_dec->b_pace_control && !p_sys->b_preroll &&
......@@ -455,7 +451,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
p_sys->b_garbage_pic );
p_sys->b_garbage_pic = 0;
if ( p_sys->p_picture_to_destroy != p_pic )
if( p_sys->p_picture_to_destroy != p_pic )
{
p_pic->date = decoder_SynchroDate( p_sys->p_synchro );
}
......@@ -535,7 +531,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
if( p_sys->b_slice_i )
{
decoder_SynchroNewPicture( p_sys->p_synchro,
I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate,
I_CODING_TYPE, 2, 0, 0,
p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
decoder_SynchroDecode( p_sys->p_synchro );
decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
......
......@@ -35,7 +35,6 @@
#include <vlc_plugin.h>
#include <vlc_codec.h>
#include <vlc_aout.h>
#include <vlc_input.h>
#include <vlc_block_helper.h>
......@@ -68,8 +67,6 @@ struct decoder_sys_t
unsigned int i_layer, i_bit_rate;
bool b_discontinuity;
int i_input_rate;
};
enum {
......@@ -160,7 +157,6 @@ static int OpenDecoder( vlc_object_t *p_this )
aout_DateSet( &p_sys->end_date, 0 );
p_sys->bytestream = block_BytestreamInit();
p_sys->b_discontinuity = false;
p_sys->i_input_rate = INPUT_RATE_DEFAULT;
/* Set output properties */
p_dec->fmt_out.i_cat = AUDIO_ES;
......@@ -226,9 +222,6 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
if( (*pp_block)->i_rate > 0 )
p_sys->i_input_rate = (*pp_block)->i_rate;
block_BytestreamPush( &p_sys->bytestream, *pp_block );
while( 1 )
......@@ -545,8 +538,7 @@ static aout_buffer_t *GetAoutBuffer( decoder_t *p_dec )
p_buf->start_date = aout_DateGet( &p_sys->end_date );
p_buf->end_date =
aout_DateIncrement( &p_sys->end_date,
p_sys->i_frame_length * p_sys->i_input_rate / INPUT_RATE_DEFAULT );
aout_DateIncrement( &p_sys->end_date, p_sys->i_frame_length );
p_buf->b_discontinuity = p_sys->b_discontinuity;
p_sys->b_discontinuity = false;
......@@ -570,9 +562,7 @@ static block_t *GetSoutBuffer( decoder_t *p_dec )
p_block->i_pts = p_block->i_dts = aout_DateGet( &p_sys->end_date );
p_block->i_length =
aout_DateIncrement( &p_sys->end_date,
p_sys->i_frame_length * p_sys->i_input_rate / INPUT_RATE_DEFAULT ) -
p_block->i_pts;
aout_DateIncrement( &p_sys->end_date, p_sys->i_frame_length ) - p_block->i_pts;
return p_block;
}
......
......@@ -185,8 +185,6 @@ static int ParseControlSeq( decoder_t *p_dec, subpicture_t *p_spu,
/* Get the control sequence date */
date = (mtime_t)GetWBE( &p_sys->buffer[i_index] ) * 11000;
if( p_sys->i_rate )
date = date * p_sys->i_rate / INPUT_RATE_DEFAULT;
/* Next offset */
i_cur_seq = i_index;
......
......@@ -151,7 +151,6 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
/* FIXME: what the, we shouldn’t need to allocate 64k of buffer --sam. */
p_sys->i_spu = block_ChainExtract( p_spu_block, p_sys->buffer, 65536 );
p_sys->i_pts = p_spu_block->i_pts;
p_sys->i_rate = p_spu_block->i_rate;
block_ChainRelease( p_spu_block );
/* Parse and decode */
......
......@@ -28,7 +28,6 @@ struct decoder_sys_t
int b_packetizer;
mtime_t i_pts;
int i_rate;
unsigned int i_spu_size;
unsigned int i_rle_size;
unsigned int i_spu;
......
......@@ -264,8 +264,6 @@ static subpicture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
block_Release( p_block );
return NULL;
}
if( p_block->i_rate != 0 )
p_block->i_length = p_block->i_length * p_block->i_rate / INPUT_RATE_DEFAULT;
p_spu = ParseText( p_dec, p_block );
......
......@@ -118,8 +118,6 @@ static subpicture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
return NULL;
p_block = *pp_block;
if( p_block->i_rate != 0 )
p_block->i_length = p_block->i_length * p_block->i_rate / INPUT_RATE_DEFAULT;
p_spu = ParseText( p_dec, p_block );
......
......@@ -33,7 +33,6 @@
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_input.h>
#include "vlc_vout.h"
#include "vlc_bits.h"
......@@ -458,8 +457,6 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
if( pp_block == NULL || *pp_block == NULL )
return NULL;
p_block = *pp_block;
if( p_block->i_rate != 0 )
p_block->i_length = p_block->i_length * p_block->i_rate / INPUT_RATE_DEFAULT;
*pp_block = NULL;
dbg((p_dec, "start of telx packet with header %2x\n",
......
......@@ -87,8 +87,6 @@ struct decoder_sys_t
audio_date_t end_date;
int i_last_block_size;
int i_input_rate;
/*
** Channel reordering
*/
......@@ -246,7 +244,6 @@ static int OpenDecoder( vlc_object_t *p_this )
p_sys->i_last_block_size = 0;
p_sys->b_packetizer = false;
p_sys->i_headers = 0;
p_sys->i_input_rate = INPUT_RATE_DEFAULT;
/* Take care of vorbis init */
vorbis_info_init( &p_sys->vi );
......@@ -301,9 +298,6 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
/* Block to Ogg packet */
oggpacket.packet = (*pp_block)->p_buffer;
oggpacket.bytes = (*pp_block)->i_buffer;
if( (*pp_block)->i_rate > 0 )
p_sys->i_input_rate = (*pp_block)->i_rate;
}
else
{
......@@ -573,8 +567,7 @@ static aout_buffer_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket )
/* Date management */
p_aout_buffer->start_date = aout_DateGet( &p_sys->end_date );
p_aout_buffer->end_date = aout_DateIncrement( &p_sys->end_date,
i_samples * p_sys->i_input_rate / INPUT_RATE_DEFAULT );
p_aout_buffer->end_date = aout_DateIncrement( &p_sys->end_date, i_samples );
return p_aout_buffer;
}
else
......@@ -601,9 +594,7 @@ static block_t *SendPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
p_block->i_dts = p_block->i_pts = aout_DateGet( &p_sys->end_date );
if( p_sys->i_headers >= 3 )
p_block->i_length = aout_DateIncrement( &p_sys->end_date,
i_samples * p_sys->i_input_rate / INPUT_RATE_DEFAULT ) -
p_block->i_pts;
p_block->i_length = aout_DateIncrement( &p_sys->end_date, i_samples ) - p_block->i_pts;
else
p_block->i_length = 0;
......
......@@ -35,9 +35,6 @@
#include <vlc_aout.h>
#include <vlc_codec.h>
#include <vlc_block.h>
#include <vlc_sout.h>
#include <vlc_codecs.h>
#include <vlc_input.h>
#include <vlc_bits.h>
#include "vlc_block_helper.h"
......@@ -209,7 +206,6 @@ static int OpenPacketizer( vlc_object_t *p_this )
p_sys->i_state = STATE_NOSYNC;
aout_DateSet( &p_sys->end_date, 0 );
p_sys->bytestream = block_BytestreamInit();
p_sys->i_input_rate = INPUT_RATE_DEFAULT;
p_sys->b_latm_cfg = false;
/* Set output properties */
......@@ -317,7 +313,7 @@ static block_t *PacketizeRawBlock( decoder_t *p_dec, block_t **pp_block )
p_block->i_pts = p_block->i_dts = aout_DateGet( &p_sys->end_date );
p_block->i_length = aout_DateIncrement( &p_sys->end_date,
p_dec->fmt_out.audio.i_frame_length * p_sys->i_input_rate / INPUT_RATE_DEFAULT ) - p_block->i_pts;
p_dec->fmt_out.audio.i_frame_length ) - p_block->i_pts;
return p_block;
}
......@@ -990,9 +986,6 @@ static block_t *PacketizeStreamBlock( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
if( (*pp_block)->i_rate > 0 )
p_sys->i_input_rate = (*pp_block)->i_rate;
block_BytestreamPush( &p_sys->bytestream, *pp_block );
for( ;; )
......@@ -1216,9 +1209,8 @@ static void SetupOutput( decoder_t *p_dec, block_t *p_block )
p_block->i_pts = p_block->i_dts = aout_DateGet( &p_sys->end_date );
p_block->i_length = aout_DateIncrement( &p_sys->end_date,
p_sys->i_frame_length * p_sys->i_input_rate / INPUT_RATE_DEFAULT ) -
p_block->i_pts;
p_block->i_length =
aout_DateIncrement( &p_sys->end_date, p_sys->i_frame_length ) - p_block->i_pts;
}
/*****************************************************************************
......
......@@ -36,7 +36,6 @@
#include <vlc_sout.h>
#include <vlc_codec.h>
#include <vlc_block.h>
#include <vlc_input.h> /* hmmm, just for INPUT_RATE_DEFAULT */
#include "vlc_bits.h"
#include "vlc_block_helper.h"
......@@ -295,7 +294,6 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
block_BytestreamFlush( &p_sys->bytestream );
p_pic->i_pts = i_pts = p_sys->bytestream.p_block->i_pts;
p_pic->i_dts = i_dts = p_sys->bytestream.p_block->i_dts;
p_pic->i_rate = p_sys->bytestream.p_block->i_rate;
block_GetBytes( &p_sys->bytestream, p_pic->p_buffer,
p_pic->i_buffer );
......@@ -569,15 +567,13 @@ static int ParseVOP( decoder_t *p_dec, block_t *p_vop )
p_dec->fmt_in.video.i_frame_rate_base > 0 )
{
p_sys->i_interpolated_pts += INT64_C(1000000) *
p_dec->fmt_in.video.i_frame_rate_base *
p_vop->i_rate / INPUT_RATE_DEFAULT /
p_dec->fmt_in.video.i_frame_rate_base /
p_dec->fmt_in.video.i_frame_rate;
}
else if( p_dec->p_sys->i_fps_num )
p_sys->i_interpolated_pts +=
( INT64_C(1000000) * (i_time_ref + i_time_increment -
p_sys->i_last_time - p_sys->i_last_timeincr) *
p_vop->i_rate / INPUT_RATE_DEFAULT /
p_sys->i_last_time - p_sys->i_last_timeincr) /
p_dec->p_sys->i_fps_num );
p_sys->i_last_time = i_time_ref;
......
......@@ -252,7 +252,6 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
block_BytestreamFlush( &p_sys->bytestream );
p_pic->i_pts = p_sys->bytestream.p_block->i_pts;
p_pic->i_dts = p_sys->bytestream.p_block->i_dts;
p_pic->i_rate = p_sys->bytestream.p_block->i_rate;
block_GetBytes( &p_sys->bytestream, p_pic->p_buffer, p_pic->i_buffer );
......
......@@ -313,6 +313,19 @@ mtime_t input_clock_GetTS( input_clock_t *cl,
return i_converted_ts + i_pts_delay;
}
/*****************************************************************************
* input_clock_GetRate: Return current rate
*****************************************************************************/
int input_clock_GetRate( input_clock_t *cl )
{
int i_rate;
vlc_mutex_lock( &cl->lock );
i_rate = cl->i_rate;
vlc_mutex_unlock( &cl->lock );
return i_rate;
}
/*****************************************************************************
* ClockStreamToSystem: converts a movie clock to system date
......
......@@ -138,8 +138,14 @@ int decoder_GetInputAttachments( decoder_t *p_dec,
*/
mtime_t decoder_GetDisplayDate( decoder_t *p_dec, mtime_t i_ts )
{
VLC_UNUSED(p_dec);
return i_ts;
decoder_owner_sys_t *p_owner = p_dec->p_owner;
return input_clock_GetTS( p_owner->p_clock, p_owner->p_input->i_pts_delay, i_ts );
}
/* decoder_GetDisplayRate:
*/
int decoder_GetDisplayRate( decoder_t *p_dec )
{
return input_clock_GetRate( p_dec->p_owner->p_clock );
}
/**
......@@ -396,6 +402,7 @@ int input_DecoderSetCcState( decoder_t *p_dec, bool b_decode, int i_channel )
vlc_object_release( p_cc );
return VLC_EGENERIC;
}
p_cc->p_owner->p_clock = p_owner->p_clock;
vlc_mutex_lock( &p_owner->lock_cc );
p_dec->p_owner->pp_cc[i_channel] = p_cc;
......@@ -626,10 +633,79 @@ static inline void DecoderUpdatePreroll( int64_t *pi_preroll, const block_t *p )
else if( p->i_dts > 0 )
*pi_preroll = __MIN( *pi_preroll, p->i_dts );
}
static mtime_t DecoderTeletextFixTs( mtime_t i_ts, mtime_t i_ts_delay )
{
mtime_t current_date = mdate();
/* FIXME I don't really like that, es_out SHOULD do it using the video pts */
if( !i_ts || i_ts > current_date + 10000000 || i_ts < current_date )
{
/* ETSI EN 300 472 Annex A : do not take into account the PTS
* for teletext streams. */
return current_date + 400000 + i_ts_delay;
}
return i_ts;
}
static void DecoderSoutBufferFixTs( block_t *p_block,
input_clock_t *p_clock, mtime_t i_ts_delay,
bool b_teletext )
{
p_block->i_rate = input_clock_GetRate( p_clock );
if( p_block->i_dts > 0 )
p_block->i_dts = input_clock_GetTS( p_clock, i_ts_delay, p_block->i_dts );
if( p_block->i_pts > 0 )
p_block->i_pts = input_clock_GetTS( p_clock, i_ts_delay, p_block->i_pts );