]> git.sesse.net Git - vlc/commitdiff
Privatized input_clock_t to clock.c
authorLaurent Aimar <fenrir@videolan.org>
Wed, 24 Sep 2008 18:54:37 +0000 (20:54 +0200)
committerLaurent Aimar <fenrir@videolan.org>
Sun, 28 Sep 2008 01:08:36 +0000 (03:08 +0200)
src/input/clock.c
src/input/es_out.c
src/input/input_internal.h

index b2c4c4be42a7a29ad2b6603dce4d76dc0df12fd9..69f505cef9fefce170cb3e886acaf0998f9987b8 100644 (file)
  * my dice --Meuuh */
 #define CR_MEAN_PTS_GAP 300000
 
+/*****************************************************************************
+ * Structures
+ *****************************************************************************/
+struct input_clock_t
+{
+    /* Synchronization information */
+    mtime_t                 delta_cr;
+    mtime_t                 cr_ref, sysdate_ref;
+    mtime_t                 last_sysdate;
+    mtime_t                 last_cr; /* reference to detect unexpected stream
+                                      * discontinuities                      */
+    mtime_t                 last_pts;
+    mtime_t                 last_update;
+    bool                    b_has_reference;
+
+    bool                    b_master;
+
+    int                     i_rate;
+
+    /* Config */
+    int                     i_cr_average;
+    int                     i_delta_cr_residue;
+};
+
 /*****************************************************************************
  * ClockToSysdate: converts a movie clock to system date
  *****************************************************************************/
@@ -113,11 +137,14 @@ static void ClockNewRef( input_clock_t *cl,
 }
 
 /*****************************************************************************
- * input_ClockInit: reinitializes the clock reference after a stream
- *                  discontinuity
+ * input_ClockNew: create a new clock
  *****************************************************************************/
-void input_ClockInit( input_clock_t *cl, bool b_master, int i_cr_average, int i_rate )
+input_clock_t *input_ClockNew( bool b_master, int i_cr_average, int i_rate )
 {
+    input_clock_t *cl = malloc( sizeof(*cl) );
+    if( !cl )
+        return NULL;
+
     cl->b_has_reference = false;
 
     cl->last_cr = 0;
@@ -132,6 +159,16 @@ void input_ClockInit( input_clock_t *cl, bool b_master, int i_cr_average, int i_
     cl->i_cr_average = i_cr_average;
 
     cl->b_master = b_master;
+
+    return cl;
+}
+
+/*****************************************************************************
+ * input_ClockDelete: destroy a new clock
+ *****************************************************************************/
+void input_ClockDelete( input_clock_t *cl )
+{
+    free( cl );
 }
 
 /*****************************************************************************
@@ -232,6 +269,14 @@ void input_ClockSetRate( input_clock_t *cl, int i_rate )
     cl->i_rate = i_rate;
 }
 
+/*****************************************************************************
+ * input_ClockSetMaster:
+ *****************************************************************************/
+void input_ClockSetMaster( input_clock_t *cl, bool b_master )
+{
+    cl->b_master = b_master;
+}
+
 /*****************************************************************************
  * input_ClockGetWakeup
  *****************************************************************************/
index 578e93b43c0da89df08a42cd915f8401b4ce6ba5..cca6a6e1599fefc757678d603c5b3e6604004168 100644 (file)
@@ -60,7 +60,7 @@ typedef struct
     bool b_selected;
 
     /* Clock for this program */
-    input_clock_t clock;
+    input_clock_t *p_clock;
 
     char    *psz_name;
     char    *psz_now_playing;
@@ -317,6 +317,7 @@ void input_EsOutDelete( es_out_t *out )
     for( i = 0; i < p_sys->i_pgrm; i++ )
     {
         es_out_pgrm_t *p_pgrm = p_sys->pgrm[i];
+        input_ClockDelete( p_pgrm->p_clock );
         free( p_pgrm->psz_now_playing );
         free( p_pgrm->psz_publisher );
         free( p_pgrm->psz_name );
@@ -354,7 +355,7 @@ mtime_t input_EsOutGetWakeup( es_out_t *out )
 
     if( !p_sys->p_pgrm )
         return 0;
-    return input_ClockGetWakeup( p_sys->p_input, &p_sys->p_pgrm->clock );
+    return input_ClockGetWakeup( p_sys->p_input, p_sys->p_pgrm->p_clock );
 }
 
 static void EsOutDiscontinuity( es_out_t *out, bool b_flush, bool b_audio )
@@ -385,7 +386,7 @@ void input_EsOutChangeRate( es_out_t *out, int i_rate )
     EsOutDiscontinuity( out, false, false );
 
     for( i = 0; i < p_sys->i_pgrm; i++ )
-        input_ClockSetRate( &p_sys->pgrm[i]->clock, i_rate );
+        input_ClockSetRate( p_sys->pgrm[i]->p_clock, i_rate );
 }
 
 int input_EsOutSetRecord(  es_out_t *out, bool b_record )
@@ -638,11 +639,9 @@ static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
     p_pgrm->b_selected = true;
 
     /* Switch master stream */
-    if( p_sys->p_pgrm && p_sys->p_pgrm->clock.b_master )
-    {
-        p_sys->p_pgrm->clock.b_master = false;
-    }
-    p_pgrm->clock.b_master = true;
+    if( p_sys->p_pgrm )
+        input_ClockSetMaster( p_sys->p_pgrm->p_clock, false );
+    input_ClockSetMaster( p_pgrm->p_clock, true );
     p_sys->p_pgrm = p_pgrm;
 
     /* Update "program" */
@@ -680,7 +679,8 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
     vlc_value_t       val;
 
     es_out_pgrm_t *p_pgrm = malloc( sizeof( es_out_pgrm_t ) );
-    if( !p_pgrm ) return NULL;
+    if( !p_pgrm )
+        return NULL;
 
     /* Init */
     p_pgrm->i_id = i_group;
@@ -690,7 +690,12 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
     p_pgrm->psz_now_playing = NULL;
     p_pgrm->psz_publisher = NULL;
     p_pgrm->p_epg = NULL;
-    input_ClockInit( &p_pgrm->clock, false, p_input->p->input.i_cr_average, p_sys->i_rate );
+    p_pgrm->p_clock = input_ClockNew( false, p_input->p->input.i_cr_average, p_sys->i_rate );
+    if( !p_pgrm->p_clock )
+    {
+        free( p_pgrm );
+        return NULL;
+    }
 
     /* Append it */
     TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
@@ -743,7 +748,10 @@ static int EsOutProgramDel( es_out_t *out, int i_group )
     TAB_REMOVE( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
 
     /* If program is selected we need to unselect it */
-    if( p_sys->p_pgrm == p_pgrm ) p_sys->p_pgrm = NULL;
+    if( p_sys->p_pgrm == p_pgrm )
+        p_sys->p_pgrm = NULL;
+
+    input_ClockDelete( p_pgrm->p_clock );
 
     free( p_pgrm->psz_name );
     free( p_pgrm->psz_now_playing );
@@ -1153,7 +1161,7 @@ static void EsCreateDecoder( es_out_t *out, es_out_id_t *p_es )
 }
 static void EsDestroyDecoder( es_out_t *out, es_out_id_t *p_es )
 {
-    es_out_sys_t   *p_sys = out->p_sys;
+    VLC_UNUSED(out);
 
     if( !p_es->p_dec )
         return;
@@ -1538,7 +1546,7 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
     else if( p_block->i_dts > 0 )
     {
         p_block->i_dts =
-            input_ClockGetTS( p_input, &p_pgrm->clock, p_block->i_dts ) + i_delay;
+            input_ClockGetTS( p_input, p_pgrm->p_clock, p_block->i_dts ) + i_delay;
     }
     if( p_block->i_pts > 0 && (p_block->i_flags&BLOCK_FLAG_PREROLL) )
     {
@@ -1547,7 +1555,7 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
     else if( p_block->i_pts > 0 )
     {
         p_block->i_pts =
-            input_ClockGetTS( p_input, &p_pgrm->clock, p_block->i_pts ) + i_delay;
+            input_ClockGetTS( p_input, p_pgrm->p_clock, p_block->i_pts ) + i_delay;
     }
     if ( p_block->i_rate == INPUT_RATE_DEFAULT &&
          es->fmt.i_codec == VLC_FOURCC( 't', 'e', 'l', 'x' ) )
@@ -1902,13 +1910,13 @@ static int EsOutControl( es_out_t *out, int i_query, va_list args )
             i_pcr = (int64_t)va_arg( args, int64_t );
             /* search program
              * TODO do not use mdate() but proper stream acquisition date */
-            input_ClockSetPCR( p_sys->p_input, &p_pgrm->clock, i_pcr, mdate() );
+            input_ClockSetPCR( p_sys->p_input, p_pgrm->p_clock, i_pcr, mdate() );
             return VLC_SUCCESS;
         }
 
         case ES_OUT_RESET_PCR:
             for( i = 0; i < p_sys->i_pgrm; i++ )
-                input_ClockResetPCR( &p_sys->pgrm[i]->clock );
+                input_ClockResetPCR( p_sys->pgrm[i]->p_clock );
             return VLC_SUCCESS;
 
         case ES_OUT_GET_TS:
@@ -1917,7 +1925,7 @@ static int EsOutControl( es_out_t *out, int i_query, va_list args )
                 int64_t i_ts = (int64_t)va_arg( args, int64_t );
                 int64_t *pi_ts = (int64_t *)va_arg( args, int64_t * );
                 *pi_ts = input_ClockGetTS( p_sys->p_input,
-                                           &p_sys->p_pgrm->clock, i_ts );
+                                           p_sys->p_pgrm->p_clock, i_ts );
                 return VLC_SUCCESS;
             }
             return VLC_EGENERIC;
index 3cd94def43cd26a9f75346722e64402dbd9f1908..27e7116a1be7f3d692bb89d778ae95a24d76daec 100644 (file)
@@ -355,32 +355,17 @@ void       input_EsOutChangeState( es_out_t * );
 void       input_EsOutChangePosition( es_out_t * );
 bool input_EsOutDecodersEmpty( es_out_t * );
 
-typedef struct
-{
-    /* Synchronization information */
-    mtime_t                 delta_cr;
-    mtime_t                 cr_ref, sysdate_ref;
-    mtime_t                 last_sysdate;
-    mtime_t                 last_cr; /* reference to detect unexpected stream
-                                      * discontinuities                      */
-    mtime_t                 last_pts;
-    mtime_t                 last_update;
-    bool                    b_has_reference;
-
-    bool                    b_master;
-
-    int                     i_rate;
-
-    /* Config */
-    int                     i_cr_average;
-    int                     i_delta_cr_residue;
-} input_clock_t;
-
-void    input_ClockInit( input_clock_t *, bool b_master, int i_cr_average, int i_rate );
+/* clock.c */
+typedef struct input_clock_t input_clock_t;
+
+input_clock_t *input_ClockNew( bool b_master, int i_cr_average, int i_rate );
+void           input_ClockDelete( input_clock_t * );
+
 void    input_ClockSetPCR( input_thread_t *, input_clock_t *, mtime_t i_clock, mtime_t i_system );
 void    input_ClockResetPCR( input_clock_t * );
 mtime_t input_ClockGetTS( input_thread_t *, input_clock_t *, mtime_t );
 void    input_ClockSetRate( input_clock_t *cl, int i_rate );
+void    input_ClockSetMaster( input_clock_t *cl, bool b_master );
 mtime_t input_ClockGetWakeup( input_thread_t *, input_clock_t *cl );
 
 /* Subtitles */