summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibaut Mattern <tmattern@users.sourceforge.net>2002-10-28 07:53:52 +0000
committerThibaut Mattern <tmattern@users.sourceforge.net>2002-10-28 07:53:52 +0000
commita206b6f2843fb8d26afa63a9b80af2ea7a55b3d2 (patch)
tree5cfc9a7504e593b1386a41f01bc617341c26f8a6
parentbb440c55b969274262ba353352a433ed88070a26 (diff)
downloadxine-lib-a206b6f2843fb8d26afa63a9b80af2ea7a55b3d2.tar.gz
xine-lib-a206b6f2843fb8d26afa63a9b80af2ea7a55b3d2.tar.bz2
New way to handle streams with invalid img_duration (eg some mpeg streams).
The concept in simple : compute duration using pts. Here the formula : duration = ( pts - last_pts ) / (nb img between the 2 pts) I've tested with libmpeg2 and ffmpeg. It works. CVS patchset: 3061 CVS date: 2002/10/28 07:53:52
-rw-r--r--src/xine-engine/metronom.c37
-rw-r--r--src/xine-engine/metronom.h7
2 files changed, 39 insertions, 5 deletions
diff --git a/src/xine-engine/metronom.c b/src/xine-engine/metronom.c
index de31f1916..a779953f2 100644
--- a/src/xine-engine/metronom.c
+++ b/src/xine-engine/metronom.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: metronom.c,v 1.94 2002/10/14 15:47:38 guenter Exp $
+ * $Id: metronom.c,v 1.95 2002/10/28 07:53:52 tmattern Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -359,6 +359,7 @@ static void metronom_handle_video_discontinuity (metronom_t *this, int type,
break;
}
+ this->last_video_pts = 0;
this->discontinuity_handled_count++;
pthread_cond_signal (&this->video_discontinuity_reached);
@@ -369,6 +370,7 @@ static void metronom_got_video_frame (metronom_t *this, vo_frame_t *img) {
int64_t vpts;
int64_t pts = img->pts;
+ int64_t diff;
pthread_mutex_lock (&this->lock);
@@ -385,10 +387,28 @@ static void metronom_got_video_frame (metronom_t *this, vo_frame_t *img) {
pts = 0; /* ignore pts during discontinuities */
}
+ this->img_cpt++;
+
if (pts) {
- int64_t diff;
/*
+ * Compute img duration if it's not provided by the decoder
+ * example: mpeg streams with an invalid frame rate
+ */
+ if (!img->duration) {
+ if (this->last_video_pts && this->img_cpt) {
+ this->img_duration = (pts - this->last_video_pts) / this->img_cpt;
+#ifdef LOG
+ printf("metronom: computed frame_duration = %lld\n", this->img_duration );
+#endif
+ }
+ this->img_cpt = 0;
+ this->last_video_pts = pts;
+ img->duration = this->img_duration;
+ }
+
+
+ /*
* compare predicted (this->video_vpts) and given (pts+vpts_offset)
* pts values - hopefully they will be the same
* if not, for small diffs try to interpolate
@@ -423,8 +443,13 @@ static void metronom_got_video_frame (metronom_t *this, vo_frame_t *img) {
printf ("metronom: video drift, drift is %lld\n", this->video_drift);
#endif
}
- }
+ } else {
+ if (!img->duration) {
+ img->duration = this->img_duration;
+ }
+ }
+
img->vpts = this->video_vpts + this->av_offset;
#ifdef LOG
@@ -748,7 +773,11 @@ metronom_t * metronom_init (int have_audio, xine_stream_t *stream) {
this->video_discontinuity_count = 0;
this->discontinuity_handled_count = 0;
pthread_cond_init (&this->video_discontinuity_reached, NULL);
-
+ this->img_duration = 3000;
+ this->img_cpt = 0;
+ this->last_video_pts = 0;
+
+
/* initialize audio stuff */
this->have_audio = have_audio;
diff --git a/src/xine-engine/metronom.h b/src/xine-engine/metronom.h
index 77ec59614..8baeece10 100644
--- a/src/xine-engine/metronom.h
+++ b/src/xine-engine/metronom.h
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: metronom.h,v 1.37 2002/10/14 15:47:39 guenter Exp $
+ * $Id: metronom.h,v 1.38 2002/10/28 07:53:52 tmattern Exp $
*
* metronom: general pts => virtual calculation/assoc
*
@@ -246,6 +246,11 @@ struct metronom_s {
int allow_full_ao_fill_gap;
int force_audio_jump;
+
+ int64_t img_duration;
+ int img_cpt;
+ int64_t last_video_pts;
+
};
metronom_t *metronom_init (int have_audio, xine_stream_t *stream);