summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphintuka <phintuka>2012-03-22 11:30:02 +0000
committerphintuka <phintuka>2012-03-22 11:30:02 +0000
commit7e05e8b4d5cf8d4d6f84c3ecf98a2da635e6fa5a (patch)
tree6ea7208994bc1008a9fd2557b40d0882c3a51f11
parentb9398ee21fd7187b30d903e3413667f74b204cd6 (diff)
downloadxineliboutput-7e05e8b4d5cf8d4d6f84c3ecf98a2da635e6fa5a.tar.gz
xineliboutput-7e05e8b4d5cf8d4d6f84c3ecf98a2da635e6fa5a.tar.bz2
adjustable_scr: added buffering support to avoid messing with xine's playback speed
-rw-r--r--xine/adjustable_scr.c55
-rw-r--r--xine/adjustable_scr.h4
-rw-r--r--xine_input_vdr.c44
3 files changed, 67 insertions, 36 deletions
diff --git a/xine/adjustable_scr.c b/xine/adjustable_scr.c
index 1855cdc9..a06f59d7 100644
--- a/xine/adjustable_scr.c
+++ b/xine/adjustable_scr.c
@@ -4,7 +4,7 @@
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
- * $Id: adjustable_scr.c,v 1.3 2012-03-20 07:58:23 phintuka Exp $
+ * $Id: adjustable_scr.c,v 1.4 2012-03-22 11:30:02 phintuka Exp $
*
*/
@@ -13,6 +13,12 @@
#include <xine/xineutils.h>
#include <xine/metronom.h>
+#include "../tools/time_ms.h"
+
+#define LOG_MODULENAME "[scr ] "
+#define SysLogLevel iSysLogLevel
+#include "../logdefs.h"
+
#include "adjustable_scr.h"
/*
@@ -58,6 +64,9 @@ struct scr_impl_s {
double speed_factor;
double speed_tuning;
+ int buffering; /* clock is freezed while buffering */
+ uint64_t buffering_start_time;
+
pthread_mutex_t lock;
};
@@ -68,6 +77,11 @@ static void set_pivot (scr_impl_t *this)
int64_t pts;
double pts_calc;
+ if (this->buffering) {
+ xine_monotonic_clock(&this->cur_time, NULL);
+ return;
+ }
+
xine_monotonic_clock(&tv,NULL);
pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor;
@@ -144,14 +158,22 @@ static int64_t scr_get_current (scr_plugin_t *scr)
struct timeval tv;
int64_t pts;
double pts_calc;
+
pthread_mutex_lock (&this->lock);
+ pts = this->cur_pts;
+
+ if (this->buffering) {
+ pthread_mutex_unlock (&this->lock);
+ return pts;
+ }
+
xine_monotonic_clock(&tv,NULL);
pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor;
pts_calc += (tv.tv_usec - this->cur_time.tv_usec) * this->speed_factor / 1e6;
- pts = this->cur_pts + pts_calc;
+ pts += pts_calc;
pthread_mutex_unlock (&this->lock);
@@ -228,6 +250,34 @@ static void adjustable_scr_jump (adjustable_scr_t *scr, int pts)
}
/*
+ *
+ */
+static void adjustable_scr_set_buffering (adjustable_scr_t *scr, int buffering)
+{
+ scr_impl_t *this = (scr_impl_t*) scr;
+
+ pthread_mutex_lock (&this->lock);
+
+ if (buffering) {
+ if (!this->buffering) {
+ set_pivot( this );
+ this->buffering = 1;
+ this->buffering_start_time = time_ms();
+ LOGMSG("start buffering at %"PRId64, this->cur_pts);
+ }
+ } else {
+ if (this->buffering) {
+ set_pivot( this );
+ this->buffering = 0;
+ LOGMSG("stop buffering at %"PRId64" (buffering took %"PRIu64" ms)",
+ this->cur_pts, elapsed(this->buffering_start_time));
+ }
+ }
+
+ pthread_mutex_unlock (&this->lock);
+}
+
+/*
* dispose()
*
* - unregister, stop and free resources
@@ -267,6 +317,7 @@ adjustable_scr_t* adjustable_scr_start (xine_t *xine)
this->ascr.set_speed_tuning = adjustable_scr_speed_tuning;
this->ascr.set_speed_base = adjustable_scr_speed_base;
this->ascr.jump = adjustable_scr_jump;
+ this->ascr.set_buffering = adjustable_scr_set_buffering;
this->ascr.dispose = adjustable_scr_dispose;
/* initialize */
diff --git a/xine/adjustable_scr.h b/xine/adjustable_scr.h
index 61707684..64e448cb 100644
--- a/xine/adjustable_scr.h
+++ b/xine/adjustable_scr.h
@@ -4,7 +4,7 @@
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
- * $Id: adjustable_scr.h,v 1.1 2008-12-03 22:50:04 phintuka Exp $
+ * $Id: adjustable_scr.h,v 1.2 2012-03-22 11:30:02 phintuka Exp $
*
*/
@@ -28,6 +28,8 @@ struct adjustable_scr_s {
void (*set_speed_base) (adjustable_scr_t *this, int hz);
void (*jump) (adjustable_scr_t *this, int pts);
+ void (*set_buffering) (adjustable_scr_t *this, int on);
+
void (*dispose) (adjustable_scr_t *this);
};
diff --git a/xine_input_vdr.c b/xine_input_vdr.c
index 27ba5aee..ba07650d 100644
--- a/xine_input_vdr.c
+++ b/xine_input_vdr.c
@@ -4,7 +4,7 @@
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
- * $Id: xine_input_vdr.c,v 1.356 2012-03-10 23:51:10 phintuka Exp $
+ * $Id: xine_input_vdr.c,v 1.357 2012-03-22 11:30:01 phintuka Exp $
*
*/
@@ -136,7 +136,7 @@ typedef struct {
# include <linux/unistd.h> /* syscall(__NR_gettid) */
#endif
-static const char module_revision[] = "$Id: xine_input_vdr.c,v 1.356 2012-03-10 23:51:10 phintuka Exp $";
+static const char module_revision[] = "$Id: xine_input_vdr.c,v 1.357 2012-03-22 11:30:01 phintuka Exp $";
static const char log_module_input_vdr[] = "[input_vdr] ";
#define LOG_MODULENAME log_module_input_vdr
#define SysLogLevel iSysLogLevel
@@ -580,15 +580,10 @@ static void scr_tuning_set_paused(vdr_input_plugin_t *this)
if (this->scr_tuning != SCR_TUNING_PAUSED) {
this->scr_tuning = SCR_TUNING_PAUSED; /* marked as paused */
- if (this->scr)
- this->scr->set_speed_tuning(this->scr, 1.0);
-#ifdef TEST_SCR_PAUSE
- if (_x_get_fine_speed(this->stream) != XINE_SPEED_PAUSE)
- _x_set_fine_speed(this->stream, XINE_SPEED_PAUSE);
-#else
- _x_set_fine_speed(this->stream, 1000000 / 1000); /* -> speed to 0.1% */
-#endif
+ this->scr->set_speed_tuning(this->scr, 1.0);
+ this->scr->set_buffering(this->scr, 1);
+
this->I_frames = this->P_frames = this->B_frames = 0;
}
}
@@ -603,17 +598,11 @@ static void reset_scr_tuning(vdr_input_plugin_t *this)
CHECK_FALSE(this->is_paused);
this->scr_tuning = SCR_TUNING_OFF; /* marked as normal */
- if (this->scr)
- this->scr->set_speed_tuning(this->scr, 1.0);
- if (_x_get_fine_speed(this->stream) != XINE_FINE_SPEED_NORMAL) {
- if (!this->is_paused)
- _x_set_fine_speed(this->stream, XINE_FINE_SPEED_NORMAL);
- else
- LOGDBG("reset_scr_tuning: playback is paused");
- }
+ this->scr->set_speed_tuning(this->scr, 1.0);
+ this->scr->set_buffering(this->scr, 0);
- this->scr->scr.set_fine_speed(&this->scr->scr, XINE_FINE_SPEED_NORMAL);
+ //this->scr->scr.set_fine_speed(&this->scr->scr, XINE_FINE_SPEED_NORMAL);
}
}
@@ -1619,12 +1608,7 @@ static void set_live_mode(vdr_input_plugin_t *this, int onoff)
set_still_mode(this, 0);
/* SCR tuning */
- if (this->live_mode) {
-#ifndef TEST_SCR_PAUSE
- LOGSCR("pause scr tuning by set_live_mode");
- scr_tuning_set_paused(this);
-#endif
- } else {
+ if (!this->live_mode) {
LOGSCR("reset scr tuning by set_live_mode");
reset_scr_tuning(this);
}
@@ -1681,8 +1665,7 @@ static void set_trick_speed(vdr_input_plugin_t *this, int speed, int backwards)
else
speed = XINE_FINE_SPEED_NORMAL * (-speed);
- if (this->scr_tuning != SCR_TUNING_PAUSED &&
- _x_get_fine_speed(this->stream) != speed) {
+ if (_x_get_fine_speed(this->stream) != speed) {
_x_set_fine_speed (this->stream, speed);
}
@@ -4842,7 +4825,6 @@ static buf_element_t *preprocess_buf(vdr_input_plugin_t *this, buf_element_t *bu
*/
static void postprocess_buf(vdr_input_plugin_t *this, buf_element_t *buf, int need_pause)
{
-#ifdef TEST_SCR_PAUSE
if (need_pause) {
pthread_mutex_lock(&this->lock);
@@ -4850,7 +4832,6 @@ static void postprocess_buf(vdr_input_plugin_t *this, buf_element_t *buf, int ne
pthread_mutex_unlock(&this->lock);
}
-#endif
if (buf->type != BUF_DEMUX_BLOCK || DATA_IS_TS(buf->content))
return;
@@ -4910,16 +4891,13 @@ static int adjust_scr_speed(vdr_input_plugin_t *this)
if(this->scr_tuning)
reset_scr_tuning(this);
} else {
-#ifdef TEST_SCR_PAUSE
+
if(this->stream_start) {
reset_scr_tuning(this);
need_pause = 1;
} else {
vdr_adjust_realtime_speed(this);
}
-#else
- vdr_adjust_realtime_speed(this);
-#endif
}
pthread_mutex_unlock(&this->lock);