Index: cfg-mplayer.h
===================================================================
--- cfg-mplayer.h	(revisione 26415)
+++ cfg-mplayer.h	(copia locale)
@@ -57,6 +57,8 @@
 extern int readPPOpt(void *conf, char *arg);
 extern void revertPPOpt(void *conf, char* opt);
 extern char* pp_help;
+extern int autospeed;
+extern double autospeed_period, autospeed_threshold;
 
 const m_option_t vd_conf[]={
 	{"help", "Use MPlayer with an appropriate video file instead of live partners to avoid vd.\n", CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL},
@@ -99,6 +101,9 @@
 	{"rootwin", &vo_rootwin, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 	{"border", &vo_border, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 	{"noborder", &vo_border, CONF_TYPE_FLAG, 0, 1, 0, NULL},
+	{"autospeed", &autospeed, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+	{"autospeed-period", &autospeed_period, CONF_TYPE_DOUBLE, CONF_RANGE, 0, 99, NULL},
+	{"autospeed-threshold", &autospeed_threshold, CONF_TYPE_DOUBLE, CONF_RANGE, 0, 99, NULL},
 
 	{"aop", "-aop has been removed, use -af instead.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
 	{"dsp", "-dsp has been removed. Use -ao oss:dsp_path instead.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
Index: mplayer.c
===================================================================
--- mplayer.c	(revisione 26415)
+++ mplayer.c	(copia locale)
@@ -86,6 +86,9 @@
 int player_idle_mode=0;
 int quiet=0;
 int enable_mouse_movements=0;
+int autospeed=0;
+double autospeed_period=30; //seconds
+double autospeed_threshold=0.3; //seconds
 
 #ifdef WIN32
 char * proc_priority=NULL;
@@ -2547,6 +2550,8 @@
 int i;
 
 int gui_no_filename=0;
+double init_reference_clock, init_time;
+int last_clock_adj = init_time;
 
   srand((int) time(NULL)); 
 
@@ -3660,9 +3665,31 @@
 }
 #endif
 
+init_reference_clock = MP_NOPTS_VALUE;
+init_time = (double) GetTimerMS() / (double)1000.0;
+
 while(!mpctx->eof){
     float aq_sleep_time=0;
 
+if(autospeed && (mpctx->demuxer->reference_clock != MP_NOPTS_VALUE)) {
+  double tm, ref_clock_diff, real_time_diff, perc;
+  if(init_reference_clock!=MP_NOPTS_VALUE) {
+    tm = (double) GetTimerMS() / 1000.0;
+    ref_clock_diff = mpctx->demuxer->reference_clock - init_reference_clock;
+    real_time_diff = tm - init_time;
+    perc = ref_clock_diff / real_time_diff;
+    if((ref_clock_diff > autospeed_period) &&
+       (tm - last_clock_adj > autospeed_period) &&
+       (real_time_diff - ref_clock_diff > autospeed_threshold)) {
+         char cmd[16];
+         sprintf(cmd, "speed_set %.3lf", perc);
+         mp_input_queue_cmd(mp_input_parse_cmd(cmd));
+         last_clock_adj = tm;
+    }
+  }
+  else
+    init_reference_clock = mpctx->demuxer->reference_clock;
+}
 if(dvd_last_chapter>0) {
   int cur_chapter = demuxer_get_current_chapter(mpctx->demuxer);
   if(cur_chapter!=-1 && cur_chapter+1>dvd_last_chapter)
