/*****************************************************************************
* clock.c: Clock/System date convertions, stream management
*****************************************************************************
- * Copyright (C) 1999-2008 the VideoLAN team
+ * Copyright (C) 1999-2008 VLC authors and VideoLAN
* Copyright (C) 2008 Laurent Aimar
* $Id$
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar < fenrir _AT_ videolan _DOT_ org >
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
*****************************************************************************/
/* Maximum gap allowed between two CRs. */
-#define CR_MAX_GAP (INT64_C(2000000)*100/9)
+#define CR_MAX_GAP (60 * CLOCK_FREQ)
/* Latency introduced on DVDs with CR == 0 on chapter change - this is from
* my dice --Meuuh */
clock_point_t ref;
bool b_has_reference;
+ /* External clock drift */
+ mtime_t i_external_clock;
+ bool b_has_external_clock;
+
/* Current modifiers */
bool b_paused;
int i_rate;
vlc_mutex_init( &cl->lock );
cl->b_has_reference = false;
cl->ref = clock_point_Create( VLC_TS_INVALID, VLC_TS_INVALID );
+ cl->b_has_external_clock = false;
cl->last = clock_point_Create( VLC_TS_INVALID, VLC_TS_INVALID );
cl->b_has_reference = true;
cl->ref = clock_point_Create( i_ck_stream,
__MAX( cl->i_ts_max + CR_MEAN_PTS_GAP, i_ck_system ) );
+ cl->b_has_external_clock = false;
}
/* Compute the drift between the stream clock and the system clock
cl->b_has_reference = false;
cl->ref = clock_point_Create( VLC_TS_INVALID, VLC_TS_INVALID );
+ cl->b_has_external_clock = false;
cl->i_ts_max = VLC_TS_INVALID;
vlc_mutex_unlock( &cl->lock );
*pi_ts0 += i_ts_delay;
}
- /* XXX we do not ipdate i_ts_max on purpose */
+ /* XXX we do not update i_ts_max on purpose */
if( pi_ts1 && *pi_ts1 > VLC_TS_INVALID )
{
*pi_ts1 = ClockStreamToSystem( cl, *pi_ts1 + AvgGet( &cl->drift ) ) +
vlc_mutex_unlock( &cl->lock );
/* Check ts validity */
- if( i_ts_bound != INT64_MAX &&
- *pi_ts0 > VLC_TS_INVALID && *pi_ts0 >= mdate() + i_ts_delay + i_ts_buffering + i_ts_bound )
- return VLC_EGENERIC;
+ if (i_ts_bound != INT64_MAX && *pi_ts0 > VLC_TS_INVALID) {
+ if (*pi_ts0 >= mdate() + i_ts_delay + i_ts_buffering + i_ts_bound) {
+ vlc_Log(NULL, VLC_MSG_ERR, "clock",
+ "Timestamp conversion failed (delay %"PRId64", buffering "
+ "%"PRId64", bound %"PRId64")",
+ i_ts_delay, i_ts_buffering, i_ts_bound);
+ return VLC_EGENERIC;
+ }
+ }
return VLC_SUCCESS;
}
return VLC_SUCCESS;
}
-void input_clock_ChangeSystemOrigin( input_clock_t *cl, mtime_t i_system )
+void input_clock_ChangeSystemOrigin( input_clock_t *cl, bool b_absolute, mtime_t i_system )
{
vlc_mutex_lock( &cl->lock );
assert( cl->b_has_reference );
- const mtime_t i_offset = i_system - cl->ref.i_system - ClockGetTsOffset( cl );
+ mtime_t i_offset;
+ if( b_absolute )
+ {
+ i_offset = i_system - cl->ref.i_system - ClockGetTsOffset( cl );
+ }
+ else
+ {
+ if( !cl->b_has_external_clock )
+ {
+ cl->b_has_external_clock = true;
+ cl->i_external_clock = i_system;
+ }
+ i_offset = i_system - cl->i_external_clock;
+ }
cl->ref.i_system += i_offset;
cl->last.i_system += i_offset;
vlc_mutex_unlock( &cl->lock );
}
+void input_clock_GetSystemOrigin( input_clock_t *cl, mtime_t *pi_system, mtime_t *pi_delay )
+{
+ vlc_mutex_lock( &cl->lock );
+
+ assert( cl->b_has_reference );
+
+ *pi_system = cl->ref.i_system;
+ if( pi_delay )
+ *pi_delay = cl->i_pts_delay;
+
+ vlc_mutex_unlock( &cl->lock );
+}
+
#warning "input_clock_SetJitter needs more work"
void input_clock_SetJitter( input_clock_t *cl,
mtime_t i_pts_delay, int i_cr_average )