summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Roitzsch <mroi@users.sourceforge.net>2003-06-18 13:03:44 +0000
committerMichael Roitzsch <mroi@users.sourceforge.net>2003-06-18 13:03:44 +0000
commite2e501f9edee1453b2c44a78f23cf4a4e40d4164 (patch)
tree70d82f5ad9137bb8485cc73aa72315032bf25b25
parent06f2301713235341fe3d43b1b959f414d2cfc340 (diff)
downloadxine-lib-e2e501f9edee1453b2c44a78f23cf4a4e40d4164.tar.gz
xine-lib-e2e501f9edee1453b2c44a78f23cf4a4e40d4164.tar.bz2
extract DTS (decoder timestamps) from the MPEG stream,
the DXR3 decoder can use them to improve sync (this removes a magic number from the DXR3 decoder) CVS patchset: 5065 CVS date: 2003/06/18 13:03:44
-rw-r--r--ChangeLog1
-rw-r--r--src/demuxers/demux_mpeg.c36
-rw-r--r--src/demuxers/demux_mpeg_block.c38
-rw-r--r--src/dxr3/dxr3_decode_video.c34
4 files changed, 77 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index a2117bd20..ef555526c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -25,6 +25,7 @@ xine-lib (1-beta13)
works with all video drivers. warning: cpu intensive :)
* big improvement of v4l input and associated demuxer. Including
sound capture using alsa and a/v sync. Now radio is supported as well.
+ * dxr3: using decoder timestamps will hopefully fix some last sync problems
xine-lib (1-beta12)
* enabled SVQ3 video decoding via ffmpeg
diff --git a/src/demuxers/demux_mpeg.c b/src/demuxers/demux_mpeg.c
index d473f3aca..4a9674922 100644
--- a/src/demuxers/demux_mpeg.c
+++ b/src/demuxers/demux_mpeg.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: demux_mpeg.c,v 1.119 2003/05/20 19:21:23 jcdutton Exp $
+ * $Id: demux_mpeg.c,v 1.120 2003/06/18 13:03:44 mroi Exp $
*
* demultiplexer for mpeg 1/2 program streams
* reads streams of variable blocksizes
@@ -184,7 +184,7 @@ static void find_mdat_atom(input_plugin_t *input, off_t *mdat_offset,
}
}
-static uint32_t read_bytes (demux_mpeg_t *this, int n) {
+static uint32_t read_bytes (demux_mpeg_t *this, uint32_t n) {
uint32_t res;
uint32_t i;
@@ -251,7 +251,7 @@ static void parse_mpeg2_packet (demux_mpeg_t *this, int stream_id, int64_t scr)
int len, i;
uint32_t w, flags, header_len;
- int64_t pts;
+ int64_t pts, dts;
buf_element_t *buf = NULL;
len = read_bytes(this, 2);
@@ -434,6 +434,7 @@ static void parse_mpeg2_packet (demux_mpeg_t *this, int stream_id, int64_t scr)
len -= header_len + 3;
pts = 0;
+ dts = 0;
if ((flags & 0x80) == 0x80) {
@@ -446,6 +447,18 @@ static void parse_mpeg2_packet (demux_mpeg_t *this, int stream_id, int64_t scr)
header_len -= 5 ;
}
+
+ if ((flags & 0x40) == 0x40) {
+
+ w = read_bytes(this, 1);
+ dts = (w & 0x0e) << 29 ;
+ w = read_bytes(this, 2);
+ dts |= (w & 0xFFFE) << 14;
+ w = read_bytes(this, 2);
+ dts |= (w & 0xFFFE) >> 1;
+
+ header_len -= 5 ;
+ }
/* read rest of header */
i = this->input->read (this->input, this->dummy_space, header_len);
@@ -463,6 +476,7 @@ static void parse_mpeg2_packet (demux_mpeg_t *this, int stream_id, int64_t scr)
buf->type = BUF_VIDEO_MPEG;
buf->pts = pts;
+ buf->decoder_info[0] = pts - dts;
check_newpts( this, pts, PTS_VIDEO );
pts = 0;
@@ -490,12 +504,13 @@ static void parse_mpeg1_packet (demux_mpeg_t *this, int stream_id, int64_t scr)
int len;
uint32_t w;
int i;
- int64_t pts;
+ int64_t pts, dts;
buf_element_t *buf = NULL;
len = read_bytes(this, 2);
pts=0;
+ dts=0;
if (stream_id != 0xbf) {
@@ -546,14 +561,16 @@ static void parse_mpeg1_packet (demux_mpeg_t *this, int stream_id, int64_t scr)
pts |= (w & 0xFFFE) << 14;
w = read_bytes(this, 2); len -= 2;
-
+
pts |= (w & 0xFFFE) >> 1;
-/* printf ("pts2=%lld\n",pts); */
-
- /* Decoding Time Stamp */
- w = read_bytes(this, 3); len -= 3;
+ w = read_bytes(this, 1); len -= 1;
+ dts = (w & 0x0e) << 29 ;
+ w = read_bytes(this, 2); len -= 2;
+ dts |= (w & 0xFFFE) << 14;
w = read_bytes(this, 2); len -= 2;
+ dts |= (w & 0xFFFE) >> 1;
+
} else {
/*
@@ -623,6 +640,7 @@ static void parse_mpeg1_packet (demux_mpeg_t *this, int stream_id, int64_t scr)
buf->type = BUF_VIDEO_MPEG;
buf->pts = pts;
+ buf->decoder_info[0] = pts - dts;
check_newpts( this, pts, PTS_VIDEO );
pts = 0;
diff --git a/src/demuxers/demux_mpeg_block.c b/src/demuxers/demux_mpeg_block.c
index 18d6cbf2d..648e23507 100644
--- a/src/demuxers/demux_mpeg_block.c
+++ b/src/demuxers/demux_mpeg_block.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: demux_mpeg_block.c,v 1.191 2003/06/07 14:01:38 jcdutton Exp $
+ * $Id: demux_mpeg_block.c,v 1.192 2003/06/18 13:03:45 mroi Exp $
*
* demultiplexer for mpeg 1/2 program streams
* used with fixed blocksize devices (like dvd/vcd)
@@ -85,6 +85,7 @@ typedef struct demux_mpeg_block_s {
int64_t scr;
uint32_t packet_len;
int64_t pts;
+ int64_t dts;
uint32_t stream_id;
int32_t mpeg1;
@@ -604,6 +605,8 @@ static int32_t parse_pes_for_pts(demux_mpeg_block_t *this, uint8_t *p, buf_eleme
}
this->pts = 0;
+ this->dts = 0;
+
if ((p[0] & 0xf0) == 0x20) {
this->pts = (p[ 0] & 0x0E) << 29 ;
this->pts |= p[ 1] << 22 ;
@@ -620,13 +623,13 @@ static int32_t parse_pes_for_pts(demux_mpeg_block_t *this, uint8_t *p, buf_eleme
this->pts |= (p[ 2] & 0xFE) << 14 ;
this->pts |= p[ 3] << 7 ;
this->pts |= (p[ 4] & 0xFE) >> 1 ;
- /* DTS decoding code is working, but not used in xine
- DTS = (p[ 5] & 0x0E) << 29 ;
- DTS |= p[ 6] << 22 ;
- DTS |= (p[ 7] & 0xFE) << 14 ;
- DTS |= p[ 8] << 7 ;
- DTS |= (p[ 9] & 0xFE) >> 1 ;
- */
+
+ this->dts = (p[ 5] & 0x0E) << 29 ;
+ this->dts |= p[ 6] << 22 ;
+ this->dts |= (p[ 7] & 0xFE) << 14 ;
+ this->dts |= p[ 8] << 7 ;
+ this->dts |= (p[ 9] & 0xFE) >> 1 ;
+
p += 10;
header_len += 10;
this->packet_len -= 10;
@@ -679,18 +682,16 @@ static int32_t parse_pes_for_pts(demux_mpeg_block_t *this, uint8_t *p, buf_eleme
} else
this->pts = 0;
- /* code is working but not used in xine
- if (p[7] & 0x40) {
+ if (p[7] & 0x40) { /* dts avail */
- DTS = (p[14] & 0x0E) << 29 ;
- DTS |= p[15] << 22 ;
- DTS |= (p[16] & 0xFE) << 14 ;
- DTS |= p[17] << 7 ;
- DTS |= (p[18] & 0xFE) >> 1 ;
+ this->dts = (p[14] & 0x0E) << 29 ;
+ this->dts |= p[15] << 22 ;
+ this->dts |= (p[16] & 0xFE) << 14 ;
+ this->dts |= p[17] << 7 ;
+ this->dts |= (p[18] & 0xFE) >> 1 ;
- } else
- DTS = 0;
- */
+ } else
+ this->dts = 0;
header_len = p[8];
@@ -888,6 +889,7 @@ static int32_t parse_video_stream(demux_mpeg_block_t *this, uint8_t *p, buf_elem
buf->size = this->packet_len;
buf->type = BUF_VIDEO_MPEG;
buf->pts = this->pts;
+ buf->decoder_info[0] = this->pts - this->dts;
if( !this->preview_mode )
check_newpts( this, this->pts, PTS_VIDEO );
diff --git a/src/dxr3/dxr3_decode_video.c b/src/dxr3/dxr3_decode_video.c
index 2a4721fe4..f50374a34 100644
--- a/src/dxr3/dxr3_decode_video.c
+++ b/src/dxr3/dxr3_decode_video.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: dxr3_decode_video.c,v 1.35 2003/05/28 01:52:19 komadori Exp $
+ * $Id: dxr3_decode_video.c,v 1.36 2003/06/18 13:03:45 mroi Exp $
*/
/* dxr3 video decoder plugin.
@@ -125,6 +125,7 @@ typedef struct dxr3_decoder_s {
int last_height;
int last_aspect; /* used to detect changes for event sending */
+ int dts_offset[3];
int sync_every_frame;
int sync_retry;
int enhanced_mode;
@@ -236,6 +237,9 @@ static video_decoder_t *dxr3_open_plugin(video_decoder_class_t *class_gen, xine_
this->last_height = 0;
this->last_aspect = 0;
+ this->dts_offset[0] = 21600;
+ this->dts_offset[1] = 21600;
+ this->dts_offset[2] = 21600;
this->sync_retry = 0;
this->resync_window = 0;
this->skip_count = 0;
@@ -257,10 +261,6 @@ static video_decoder_t *dxr3_open_plugin(video_decoder_class_t *class_gen, xine_
_("Enable this for streams with wrong frame durations."), 10,
dxr3_update_correct_durations, this);
- if (!this->dxr3_vo->overlay_enabled)
- /* set a/v offset to compensate dxr3 internal delay */
- this->stream->metronom->set_option(this->stream->metronom, METRONOM_AV_OFFSET, -21600);
-
/* the dxr3 needs a longer prebuffering to have time for its internal decoding */
this->stream->metronom_prebuffer = 90000;
@@ -347,6 +347,12 @@ static void dxr3_decode_data(video_decoder_t *this_gen, buf_element_t *buf)
/* extension data */
if ((buffer[0] & 0xf0) == 0x80)
this->repeat_first_field = (buffer[3] >> 1) & 1;
+#if 0
+ /* this disables frame jitter in progressive content, but
+ * unfortunately it makes the card drop one field on stills */
+ if ((buffer[0] & 0xf0) == 0x80)
+ buffer[4] &= ~(1 << 7);
+#endif
/* check if we can keep syncing */
if (this->repeat_first_field && this->sync_retry) /* reset counter */
this->sync_retry = 500;
@@ -498,6 +504,24 @@ static void dxr3_decode_data(video_decoder_t *this_gen, buf_element_t *buf)
if (vpts) {
int64_t delay;
+ /* The PTS values written to the DXR3 must be modified based on the difference
+ * between stream's PTS and DTS (decoder timestamp). We receive this
+ * difference via decoder_info */
+ buf->decoder_info[0] <<= 1;
+ if (buf->pts) {
+ if ((this->dts_offset[0] == buf->decoder_info[0]) &&
+ (this->dts_offset[1] == buf->decoder_info[0]))
+ this->dts_offset[2] = buf->decoder_info[0];
+ else {
+ this->dts_offset[1] = this->dts_offset[0];
+ this->dts_offset[0] = buf->decoder_info[0];
+ }
+#if LOG_PTS
+ printf("dxr3_decode_video: PTS to DTS correction: %d\n", this->dts_offset[1]);
+#endif
+ }
+ vpts -= this->dts_offset[2];
+
delay = vpts - this->class->clock->get_current_time(
this->class->clock);
#if LOG_PTS