summaryrefslogtreecommitdiff
path: root/xine
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 /xine
parentb9398ee21fd7187b30d903e3413667f74b204cd6 (diff)
downloadxineliboutput-7e05e8b4d5cf8d4d6f84c3ecf98a2da635e6fa5a.tar.gz
xineliboutput-7e05e8b4d5cf8d4d6f84c3ecf98a2da635e6fa5a.tar.bz2
adjustable_scr: added buffering support to avoid messing with xine's playback speed
Diffstat (limited to 'xine')
-rw-r--r--xine/adjustable_scr.c55
-rw-r--r--xine/adjustable_scr.h4
2 files changed, 56 insertions, 3 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);
};