Input slave method needs that PCR of master and slave input use the same origin.
/* Packetizer */
decoder_t *p_packetizer;
+ mtime_t i_pts;
+ mtime_t i_time_offset;
+
int i_mux_rate;
bool b_big_endian;
};
static int CheckSync( const uint8_t *p_peek, bool *p_big_endian );
#define PCM_FRAME_SIZE (1536 * 4)
-#define A52_PACKET_SIZE (4 * PCM_FRAME_SIZE)
+#define A52_PACKET_SIZE (1024)
+#define A52_PEEK_SIZE (4 * PCM_FRAME_SIZE)
#define A52_PROBE_SIZE (512*1024)
#define A52_MAX_HEADER_SIZE 10
/* Some A52 wav files don't begin with a sync code so we do a more
* extensive search */
- int i_size = stream_Peek( p_demux->s, &p_peek, i_peek + A52_PACKET_SIZE * 2);
+ int i_size = stream_Peek( p_demux->s, &p_peek, i_peek + A52_PEEK_SIZE * 2);
i_size -= (PCM_FRAME_SIZE + A52_MAX_HEADER_SIZE);
while( i_peek < i_size )
p_sys->b_start = true;
p_sys->i_mux_rate = 0;
p_sys->b_big_endian = b_big_endian;
+ p_sys->i_pts = 0;
+ p_sys->i_time_offset = 0;
/* Load the A52 packetizer */
INIT_APACKETIZER( p_sys->p_packetizer, 'a', '5', '2', ' ' );
p_sys->i_mux_rate =
p_block_out->i_buffer * INT64_C(1000000)/p_block_out->i_length;
}
+ p_sys->i_pts = p_block_out->i_pts;
+
+ /* Correct timestamp */
+ p_block_out->i_pts += p_sys->i_time_offset;
+ p_block_out->i_dts += p_sys->i_time_offset;
/* set PCR */
es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
static int Control( demux_t *p_demux, int i_query, va_list args )
{
demux_sys_t *p_sys = p_demux->p_sys;
- if( i_query == DEMUX_SET_TIME )
- {
- return VLC_EGENERIC;
- }
- else if( i_query == DEMUX_HAS_UNSUPPORTED_META )
+ bool *pb_bool;
+ int64_t *pi64;
+ int i_ret;
+
+ switch( i_query )
{
- bool *pb_bool = (bool*)va_arg( args, bool* );
+ case DEMUX_HAS_UNSUPPORTED_META:
+ pb_bool = (bool*)va_arg( args, bool* );
*pb_bool = true;
return VLC_SUCCESS;
- }
- else
- {
- return demux_vaControlHelper( p_demux->s,
+
+ case DEMUX_GET_TIME:
+ pi64 = (int64_t*)va_arg( args, int64_t * );
+ *pi64 = p_sys->i_pts + p_sys->i_time_offset;
+ return VLC_SUCCESS;
+
+ case DEMUX_SET_TIME: /* TODO implement a high precicsion seek */
+ default:
+ i_ret = demux_vaControlHelper( p_demux->s,
0, -1,
8*p_sys->i_mux_rate, 1, i_query, args );
+ if( !i_ret && p_sys->i_mux_rate > 0 &&
+ ( i_query == DEMUX_SET_POSITION || i_query == DEMUX_SET_TIME ) )
+ {
+
+ const int64_t i_time = INT64_C(1000000) * stream_Tell(p_demux->s) /
+ p_sys->i_mux_rate;
+
+ /* Fix time_offset */
+ if( i_time >= 0 )
+ p_sys->i_time_offset = i_time - p_sys->i_pts;
+ }
+ return i_ret;
}
}
/* Packetizer */
decoder_t *p_packetizer;
+ mtime_t i_pts;
+ mtime_t i_time_offset;
+
int i_mux_rate;
};
}
DEMUX_INIT_COMMON(); p_sys = p_demux->p_sys;
+ p_sys->i_mux_rate = 0;
+ p_sys->i_pts = 0;
+ p_sys->i_time_offset = 0;
INIT_APACKETIZER( p_sys->p_packetizer, 'd','t','s',' ' );
LOAD_PACKETIZER_OR_FAIL( p_sys->p_packetizer, "DTS" );
p_block_out->i_buffer * INT64_C(1000000) / p_block_out->i_length;
}
+ /* Correct timestamp */
+ p_block_out->i_pts += p_sys->i_time_offset;
+ p_block_out->i_dts += p_sys->i_time_offset;
+
/* set PCR */
es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
static int Control( demux_t *p_demux, int i_query, va_list args )
{
demux_sys_t *p_sys = p_demux->p_sys;
- if( i_query == DEMUX_SET_TIME )
- return VLC_EGENERIC;
- else
- return demux_vaControlHelper( p_demux->s,
+ bool *pb_bool;
+ int64_t *pi64;
+ int i_ret;
+
+ switch( i_query )
+ {
+ case DEMUX_HAS_UNSUPPORTED_META:
+ pb_bool = (bool*)va_arg( args, bool* );
+ *pb_bool = true;
+ return VLC_SUCCESS;
+
+ case DEMUX_GET_TIME:
+ pi64 = (int64_t*)va_arg( args, int64_t * );
+ *pi64 = p_sys->i_pts + p_sys->i_time_offset;
+ return VLC_SUCCESS;
+
+ case DEMUX_SET_TIME: /* TODO implement a high precicsion seek */
+ default:
+ i_ret = demux_vaControlHelper( p_demux->s,
0, -1,
8*p_sys->i_mux_rate, 1, i_query, args );
+ if( !i_ret && p_sys->i_mux_rate > 0 &&
+ ( i_query == DEMUX_SET_POSITION || i_query == DEMUX_SET_TIME ) )
+ {
+
+ const int64_t i_time = INT64_C(1000000) * stream_Tell(p_demux->s) /
+ p_sys->i_mux_rate;
+
+ /* Fix time_offset */
+ if( i_time >= 0 )
+ p_sys->i_time_offset = i_time - p_sys->i_pts;
+ }
+ return i_ret;
+ }
}
/*****************************************************************************
p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_out);
}
+ p_sys->i_pts = p_block_out->i_dts;
+
+ /* Correct timestamp */
+ p_block_out->i_pts += p_sys->i_time_offset;
+ p_block_out->i_dts += p_sys->i_time_offset;
+
/* set PCR */
- if( p_block_out->i_dts >= p_sys->i_pts_start )
+ if( p_block_out->i_dts >= p_sys->i_pts_start + p_sys->i_time_offset )
es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
else
es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
- p_sys->i_pts = p_block_out->i_dts;
es_out_Send( p_demux->out, p_sys->p_es, p_block_out );
p_block_out = p_next;
p_sys->i_time_offset = p_sys->seekpoint[i]->i_time_offset - p_sys->i_pts;
p_sys->i_pts_start = p_sys->i_pts+i_delta_time;
- es_out_Control( p_demux->out, ES_OUT_SET_NEXT_DISPLAY_TIME, p_sys->p_es, p_sys->i_pts_start );
+ es_out_Control( p_demux->out, ES_OUT_SET_NEXT_DISPLAY_TIME, p_sys->p_es, p_sys->i_pts_start + p_sys->i_time_offset );
}
else
{
&p_sys->p_packetizer->fmt_out);
}
- es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
-
- p_block_out->p_next = NULL;
-
p_sys->i_pts = p_block_out->i_pts;
if( p_sys->i_pts > M4A_PTS_START + INT64_C(500000) )
p_sys->i_bitrate_avg =
8*INT64_C(1000000)*p_sys->i_bytes/(p_sys->i_pts-M4A_PTS_START);
p_sys->i_bytes += p_block_out->i_buffer;
+
+ /* Correct timestamp */
+ p_block_out->i_pts += p_sys->i_time_offset;
+ p_block_out->i_dts += p_sys->i_time_offset;
+
+ /* */
+ es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
+
es_out_Send( p_demux->out, p_sys->p_es, p_block_out );
p_block_out = p_next;
{
block_t *p_next = p_block_out->p_next;
+ p_sys->i_pts = p_block_out->i_pts;
+
+ /* Correct timestamp */
+ p_block_out->i_pts += p_sys->i_time_offset;
+ p_block_out->i_dts += p_sys->i_time_offset;
+
es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
- p_block_out->p_next = NULL;
- p_sys->i_pts = p_block_out->i_pts;
es_out_Send( p_demux->out, p_sys->p_es, p_block_out );
p_block_out = p_next;
p_sys->i_bitrate_avg;
/* Fix time_offset */
- if( i_time >= 0 ) p_sys->i_time_offset = i_time - p_sys->i_pts;
+ if( i_time >= 0 )
+ p_sys->i_time_offset = i_time - p_sys->i_pts;
}
return i_ret;
}