]> git.sesse.net Git - vlc/blobdiff - src/input/decoder_synchro.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / input / decoder_synchro.c
index a007a4fed46eec33d552ef15ee060242119f0757..f6a35bd6558fcb6fd9887a53cd6ad9f13ad74ede 100644 (file)
@@ -98,7 +98,7 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_input.h>
 #include <vlc_codec.h>
 #include <vlc_codec_synchro.h>
@@ -116,9 +116,8 @@ struct decoder_synchro_t
 
     /* */
     int             i_frame_rate;
-    int             i_current_rate;
-    vlc_bool_t      b_no_skip;
-    vlc_bool_t      b_quiet;
+    bool            b_no_skip;
+    bool            b_quiet;
 
     /* date of the beginning of the decoding of the current picture */
     mtime_t         decoding_start;
@@ -131,7 +130,7 @@ struct decoder_synchro_t
     unsigned int    pi_meaningful[4];            /* number of durations read */
 
     /* render_time filled by SynchroChoose() */
-    int i_render_time;
+    int             i_render_time;
 
     /* stream context */
     int             i_nb_ref;                /* Number of reference pictures */
@@ -162,17 +161,13 @@ struct decoder_synchro_t
  *****************************************************************************/
 decoder_synchro_t * decoder_SynchroInit( decoder_t *p_dec, int i_frame_rate )
 {
-    decoder_synchro_t * p_synchro = malloc( sizeof(*p_synchro) );
-    if ( p_synchro == NULL )
-    {
-        msg_Err( p_dec, "out of memory" );
+    decoder_synchro_t * p_synchro = calloc( 1, sizeof(*p_synchro) );
+    if( !p_synchro )
         return NULL;
-    }
-    memset( p_synchro, 0, sizeof(*p_synchro) );
 
     p_synchro->p_dec = p_dec;
-    p_synchro->b_no_skip = !config_GetInt( p_dec, "skip-frames" );
-    p_synchro->b_quiet = config_GetInt( p_dec, "quiet-synchro" );
+    p_synchro->b_no_skip = !var_InheritBool( p_dec, "skip-frames" );
+    p_synchro->b_quiet = var_InheritBool( p_dec, "quiet-synchro" );
 
     /* We use a fake stream pattern, which is often right. */
     p_synchro->i_n_p = p_synchro->i_eta_p = DEFAULT_NB_P;
@@ -181,7 +176,7 @@ decoder_synchro_t * decoder_SynchroInit( decoder_t *p_dec, int i_frame_rate )
     memset( p_synchro->pi_meaningful, 0, 4 * sizeof(unsigned int) );
     p_synchro->i_nb_ref = 0;
     p_synchro->i_trash_nb_ref = p_synchro->i_dec_nb_ref = 0;
-    p_synchro->current_pts = mdate() + DEFAULT_PTS_DELAY;
+    p_synchro->current_pts = 1,
     p_synchro->backward_pts = 0;
     p_synchro->i_current_period = p_synchro->i_backward_period = 0;
     p_synchro->i_trashed_pic = p_synchro->i_not_chosen_pic =
@@ -212,23 +207,26 @@ void decoder_SynchroReset( decoder_synchro_t * p_synchro )
 /*****************************************************************************
  * decoder_SynchroChoose : Decide whether we will decode a picture or not
  *****************************************************************************/
-vlc_bool_t decoder_SynchroChoose( decoder_synchro_t * p_synchro, int i_coding_type,
-                               int i_render_time, vlc_bool_t b_low_delay )
+bool decoder_SynchroChoose( decoder_synchro_t * p_synchro, int i_coding_type,
+                               int i_render_time, bool b_low_delay )
 {
 #define TAU_PRIME( coding_type )    (p_synchro->p_tau[(coding_type)] \
                                     + (p_synchro->p_tau[(coding_type)] >> 1) \
                                     + p_synchro->i_render_time)
 #define S (*p_synchro)
     mtime_t         now, period;
-    mtime_t         pts = 0;
-    vlc_bool_t      b_decode = 0;
+    mtime_t         pts;
+    bool      b_decode = 0;
+    int       i_current_rate;
 
     if ( p_synchro->b_no_skip )
         return 1;
 
+    i_current_rate = decoder_GetDisplayRate( p_synchro->p_dec );
+
     now = mdate();
     period = 1000000 * 1001 / p_synchro->i_frame_rate
-                     * p_synchro->i_current_rate / INPUT_RATE_DEFAULT;
+                     * i_current_rate / INPUT_RATE_DEFAULT;
 
     p_synchro->i_render_time = i_render_time;
 
@@ -237,11 +235,11 @@ vlc_bool_t decoder_SynchroChoose( decoder_synchro_t * p_synchro, int i_coding_ty
     case I_CODING_TYPE:
         if( b_low_delay )
         {
-            pts = S.current_pts;
+            pts = decoder_GetDisplayDate( p_synchro->p_dec, S.current_pts );
         }
         else if( S.backward_pts )
         {
-            pts = S.backward_pts;
+            pts = decoder_GetDisplayDate( p_synchro->p_dec, S.backward_pts );
         }
         else
         {
@@ -250,11 +248,10 @@ vlc_bool_t decoder_SynchroChoose( decoder_synchro_t * p_synchro, int i_coding_ty
              *                      |       +- current picture
              *                      +- current PTS
              */
-            pts = S.current_pts + period * (S.i_n_b + 2);
+            pts = decoder_GetDisplayDate( p_synchro->p_dec, S.current_pts ) + period * (S.i_n_b + 2);
         }
 
-        if( (1 + S.i_n_p * (S.i_n_b + 1)) * period >
-                S.p_tau[I_CODING_TYPE] )
+        if( (1 + S.i_n_p * (S.i_n_b + 1)) * period > S.p_tau[I_CODING_TYPE] )
         {
             b_decode = 1;
         }
@@ -262,25 +259,28 @@ vlc_bool_t decoder_SynchroChoose( decoder_synchro_t * p_synchro, int i_coding_ty
         {
             b_decode = (pts - now) > (TAU_PRIME(I_CODING_TYPE) + DELTA);
         }
+        if( pts <= VLC_TS_INVALID )
+            b_decode = 1;
+
         if( !b_decode && !p_synchro->b_quiet )
         {
             msg_Warn( p_synchro->p_dec,
-                      "synchro trashing I ("I64Fd")", pts - now );
+                      "synchro trashing I (%"PRId64")", pts - now );
         }
         break;
 
     case P_CODING_TYPE:
         if( b_low_delay )
         {
-            pts = S.current_pts;
+            pts = decoder_GetDisplayDate( p_synchro->p_dec, S.current_pts );
         }
         else if( S.backward_pts )
         {
-            pts = S.backward_pts;
+            pts = decoder_GetDisplayDate( p_synchro->p_dec, S.backward_pts );
         }
         else
         {
-            pts = S.current_pts + period * (S.i_n_b + 1);
+            pts = decoder_GetDisplayDate( p_synchro->p_dec, S.current_pts + period * (S.i_n_b + 1) );
         }
 
         if( p_synchro->i_nb_ref < 1 )
@@ -310,10 +310,12 @@ vlc_bool_t decoder_SynchroChoose( decoder_synchro_t * p_synchro, int i_coding_ty
         {
             b_decode = 0;
         }
+        if( p_synchro->i_nb_ref >= 1 && pts <= VLC_TS_INVALID )
+            b_decode = 1;
         break;
 
     case B_CODING_TYPE:
-        pts = S.current_pts;
+        pts = decoder_GetDisplayDate( p_synchro->p_dec, S.current_pts );
 
         if( p_synchro->i_nb_ref < 2 )
         {
@@ -327,6 +329,9 @@ vlc_bool_t decoder_SynchroChoose( decoder_synchro_t * p_synchro, int i_coding_ty
         {
             b_decode = 0;
         }
+        if( p_synchro->i_nb_ref >= 2 && pts <= VLC_TS_INVALID )
+            b_decode = 1;
+        break;
     }
 
     if( !b_decode )
@@ -360,7 +365,7 @@ void decoder_SynchroDecode( decoder_synchro_t * p_synchro )
  * decoder_SynchroEnd : Called when the image is totally decoded
  *****************************************************************************/
 void decoder_SynchroEnd( decoder_synchro_t * p_synchro, int i_coding_type,
-                      vlc_bool_t b_garbage )
+                      bool b_garbage )
 {
     mtime_t     tau;
 
@@ -400,16 +405,13 @@ mtime_t decoder_SynchroDate( decoder_synchro_t * p_synchro )
  * decoder_SynchroNewPicture: Update stream structure and PTS
  *****************************************************************************/
 void decoder_SynchroNewPicture( decoder_synchro_t * p_synchro, int i_coding_type,
-                             int i_repeat_field, mtime_t next_pts,
-                             mtime_t next_dts, int i_current_rate,
-                             vlc_bool_t b_low_delay )
+                                int i_repeat_field, mtime_t next_pts,
+                                mtime_t next_dts, bool b_low_delay )
 {
-    mtime_t         period = 1000000 * 1001 / p_synchro->i_frame_rate
-                              * i_current_rate / INPUT_RATE_DEFAULT;
+    mtime_t         period = 1000000 * 1001 / p_synchro->i_frame_rate;
 #if 0
     mtime_t         now = mdate();
 #endif
-    p_synchro->i_current_rate = i_current_rate;
 
     switch( i_coding_type )
     {
@@ -434,8 +436,8 @@ void decoder_SynchroNewPicture( decoder_synchro_t * p_synchro, int i_coding_type
 
 #if 0
         if( !p_synchro->b_quiet )
-            msg_Dbg( p_synchro->p_dec, "I("I64Fd") P("I64Fd")[%d] B("I64Fd")"
-                  "[%d] YUV("I64Fd") : trashed %d:%d/%d",
+            msg_Dbg( p_synchro->p_dec, "I(%"PRId64") P(%"PRId64")[%d] B(%"PRId64")"
+                  "[%d] YUV(%"PRId64") : trashed %d:%d/%d",
                   p_synchro->p_tau[I_CODING_TYPE],
                   p_synchro->p_tau[P_CODING_TYPE],
                   p_synchro->i_n_p,
@@ -506,7 +508,7 @@ void decoder_SynchroNewPicture( decoder_synchro_t * p_synchro, int i_coding_type
                     > PTS_THRESHOLD) && !p_synchro->b_quiet )
             {
                 msg_Warn( p_synchro->p_dec, "decoder synchro warning: pts != "
-                          "current_date ("I64Fd")",
+                          "current_date (%"PRId64")",
                           p_synchro->current_pts
                               - next_pts );
             }
@@ -526,7 +528,7 @@ void decoder_SynchroNewPicture( decoder_synchro_t * p_synchro, int i_coding_type
                   || p_synchro->backward_pts - next_dts
                     > PTS_THRESHOLD) && !p_synchro->b_quiet )
             {
-                msg_Warn( p_synchro->p_dec, "backward_pts != dts ("I64Fd")",
+                msg_Warn( p_synchro->p_dec, "backward_pts != dts (%"PRId64")",
                            next_dts
                                - p_synchro->backward_pts );
             }
@@ -536,7 +538,7 @@ void decoder_SynchroNewPicture( decoder_synchro_t * p_synchro, int i_coding_type
                     > PTS_THRESHOLD) && !p_synchro->b_quiet )
             {
                 msg_Warn( p_synchro->p_dec,
-                          "backward_pts != current_pts ("I64Fd")",
+                          "backward_pts != current_pts (%"PRId64")",
                           p_synchro->current_pts
                               - p_synchro->backward_pts );
             }
@@ -550,7 +552,7 @@ void decoder_SynchroNewPicture( decoder_synchro_t * p_synchro, int i_coding_type
                   || p_synchro->current_pts - next_dts
                     > PTS_THRESHOLD) && !p_synchro->b_quiet )
             {
-                msg_Warn( p_synchro->p_dec, "dts != current_pts ("I64Fd")",
+                msg_Warn( p_synchro->p_dec, "dts != current_pts (%"PRId64")",
                           p_synchro->current_pts
                               - next_dts );
             }
@@ -575,7 +577,7 @@ void decoder_SynchroNewPicture( decoder_synchro_t * p_synchro, int i_coding_type
         /* We cannot be _that_ late, something must have happened, reinit
          * the dates. */
         if( !p_synchro->b_quiet )
-            msg_Warn( p_synchro->p_dec, "PTS << now ("I64Fd"), resetting",
+            msg_Warn( p_synchro->p_dec, "PTS << now (%"PRId64"), resetting",
                       now - p_synchro->current_pts - DEFAULT_PTS_DELAY );
         p_synchro->current_pts = now + DEFAULT_PTS_DELAY;
     }