[MPlayer-dev-eng] [PATCH] set correct_pts from demuxer if not overridden by user

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sat Feb 2 15:44:45 CET 2008


Hello,
how does this patch look to you? I used a CRTL to get the default value
instead of a constant in the demuxer struct since the latter can never
work right for e.g. demux_demuxers.
This means though that the current correct_pts checks in the demuxers
need to be changed.
Currently only implements things for lavf demuxers, but it is trivial
to set for others.

Greetings,
Reimar Döffinger
-------------- next part --------------
diff --git a/cfg-mplayer.h b/cfg-mplayer.h
index 24c7fe3..7d157f0 100644
--- a/cfg-mplayer.h
+++ b/cfg-mplayer.h
@@ -319,8 +319,8 @@ const m_option_t mplayer_opts[]={
 	{"playlist", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL},
 
 	// a-v sync stuff:
-        {"correct-pts", &correct_pts, CONF_TYPE_FLAG, 0, 0, 1, NULL},
-        {"no-correct-pts", &correct_pts, CONF_TYPE_FLAG, 0, 1, 0, NULL},
+        {"correct-pts", &user_correct_pts, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+        {"no-correct-pts", &user_correct_pts, CONF_TYPE_FLAG, 0, 1, 0, NULL},
 	{"noautosync", &autosync, CONF_TYPE_FLAG, 0, 0, -1, NULL},
 	{"autosync", &autosync, CONF_TYPE_INT, CONF_RANGE, 0, 10000, NULL},
 //	{"dapsync", &dapsync, CONF_TYPE_FLAG, 0, 0, 1, NULL},
diff --git a/libmpdemux/demux_lavf.c b/libmpdemux/demux_lavf.c
index 90b4ba1..edb2b2e 100644
--- a/libmpdemux/demux_lavf.c
+++ b/libmpdemux/demux_lavf.c
@@ -463,7 +463,7 @@ static demuxer_t* demux_open_lavf(demuxer_t *demuxer){
 
     if (opt_cryptokey)
         parse_cryptokey(avfc, opt_cryptokey);
-    if (correct_pts)
+    if (user_correct_pts != 0)
         avfc->flags |= AVFMT_FLAG_GENPTS;
     if (index_mode == 0)
         avfc->flags |= AVFMT_FLAG_IGNIDX;
@@ -644,6 +644,8 @@ static int demux_lavf_control(demuxer_t *demuxer, int cmd, void *arg)
     lavf_priv_t *priv = demuxer->priv;
 
     switch (cmd) {
+        case DEMUXER_CTRL_CORRECT_PTS:
+	    return DEMUXER_CTRL_OK;
         case DEMUXER_CTRL_GET_TIME_LENGTH:
 	    if (priv->avfc->duration == 0 || priv->avfc->duration == AV_NOPTS_VALUE)
 	        return DEMUXER_CTRL_DONTKNOW;
diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c
index b8e96ec..8b68736 100644
--- a/libmpdemux/demuxer.c
+++ b/libmpdemux/demuxer.c
@@ -684,6 +684,7 @@ int get_demuxer_type_from_name(char *demuxer_name, int *force)
 int extension_parsing=1; // 0=off 1=mixed (used only for unstable formats)
 
 int correct_pts=0;
+int user_correct_pts=-1;
 
 /*
   NOTE : Several demuxers may be opened at the same time so
@@ -869,6 +870,7 @@ extern float stream_cache_seek_min_percent;
 demuxer_t* demux_open(stream_t *vs,int file_format,int audio_id,int video_id,int dvdsub_id,char* filename){
   stream_t *as = NULL,*ss = NULL;
   demuxer_t *vd,*ad = NULL,*sd = NULL;
+  demuxer_t *res;
   int afmt =DEMUXER_TYPE_UNKNOWN,sfmt = DEMUXER_TYPE_UNKNOWN ;
   int audio_demuxer_type = 0, sub_demuxer_type = 0;
   int demuxer_force = 0, audio_demuxer_force = 0,
@@ -935,13 +937,18 @@ demuxer_t* demux_open(stream_t *vs,int file_format,int audio_id,int video_id,int
   }
 
   if(ad && sd)
-    return new_demuxers_demuxer(vd,ad,sd);
+    res = new_demuxers_demuxer(vd,ad,sd);
   else if(ad)
-    return new_demuxers_demuxer(vd,ad,vd);
+    res = new_demuxers_demuxer(vd,ad,vd);
   else if(sd)
-    return new_demuxers_demuxer(vd,vd,sd);
+    res = new_demuxers_demuxer(vd,vd,sd);
   else
-    return vd;
+    res = vd;
+
+  correct_pts = user_correct_pts;
+  if (correct_pts < 0)
+    correct_pts = demux_control(res, DEMUXER_CTRL_CORRECT_PTS, NULL) == DEMUXER_CTRL_OK;
+  return res;
 }
 
 
diff --git a/libmpdemux/demuxer.h b/libmpdemux/demuxer.h
index 987aaac..d640d0e 100644
--- a/libmpdemux/demuxer.h
+++ b/libmpdemux/demuxer.h
@@ -82,6 +82,7 @@
 #define DEMUXER_CTRL_RESYNC 13
 #define DEMUXER_CTRL_SWITCH_VIDEO 14
 #define DEMUXER_CTRL_IDENTIFY_PROGRAM 15
+#define DEMUXER_CTRL_CORRECT_PTS 16
 
 #define SEEK_ABSOLUTE (1 << 0)
 #define SEEK_FACTOR   (1 << 1)
@@ -143,6 +144,7 @@ typedef struct demuxer_info_st {
 struct demuxer_st;
 
 extern int correct_pts;
+extern int user_correct_pts;
 
 /**
  * Demuxer description structure


More information about the MPlayer-dev-eng mailing list