]> git.sesse.net Git - vlc/blobdiff - src/input/clock.c
demux: dash: return meta from manifest
[vlc] / src / input / clock.c
index 799b8a5da086e918c1689fd4ded741f85f8bea47..1419f8f8131c018468ed2344d985a0aaa1a1aa52 100644 (file)
@@ -1,26 +1,26 @@
 /*****************************************************************************
  * 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.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -80,7 +80,7 @@
  *****************************************************************************/
 
 /* 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 */
@@ -169,6 +169,10 @@ struct input_clock_t
     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;
@@ -193,6 +197,7 @@ input_clock_t *input_clock_New( 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 );
 
@@ -272,6 +277,7 @@ void input_clock_Update( input_clock_t *cl, vlc_object_t *p_log,
         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
@@ -329,6 +335,7 @@ void input_clock_Reset( input_clock_t *cl )
 
     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 );
@@ -429,7 +436,7 @@ int input_clock_ConvertTS( input_clock_t *cl,
         *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 ) ) +
@@ -439,9 +446,15 @@ int input_clock_ConvertTS( input_clock_t *cl,
     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;
 }
@@ -482,12 +495,25 @@ int input_clock_GetState( input_clock_t *cl,
     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;
@@ -495,6 +521,19 @@ void input_clock_ChangeSystemOrigin( input_clock_t *cl, mtime_t i_system )
     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 )