aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2012-05-05 02:52:41 +0000
committerGuy Harris <guy@alum.mit.edu>2012-05-05 02:52:41 +0000
commit1fc695a0224e7b4d19cca7ac8458a429c1450003 (patch)
tree9b4259fdaa1c18b1c5346a9a9127320df10ce795 /wiretap
parent444187c5e8b9cb34f315ab2eb394cf6a10e63eec (diff)
Directly calculate the time stamp based on the offset in the stream from
the first bit in the stream. This prevents accumulated truncation errors. Get the seek offset from file_tell(). svn path=/trunk/; revision=42436
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/mp2t.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/wiretap/mp2t.c b/wiretap/mp2t.c
index c5cbeb88a8..7cc0b32052 100644
--- a/wiretap/mp2t.c
+++ b/wiretap/mp2t.c
@@ -58,8 +58,7 @@
typedef struct {
- guint32 offset;
- struct wtap_nstime now;
+ int start_offset;
/* length of trailing data (e.g. FEC) that's appended after each packet */
guint8 trailer_len;
} mp2t_filetype_t;
@@ -90,7 +89,8 @@ mp2t_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
mp2t = (mp2t_filetype_t*) wth->priv;
- *data_offset = mp2t->offset;
+ *data_offset = file_tell(wth->fh);
+
/* read only the actual mpeg2 ts packet, not including a trailer */
buffer_assure_space(wth->frame_buffer, MP2T_SIZE);
if (FALSE == mp2t_read_data(buffer_start_ptr(wth->frame_buffer),
@@ -105,23 +105,23 @@ mp2t_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
return FALSE;
}
- mp2t->offset += MP2T_SIZE + mp2t->trailer_len;
-
/* XXX - relative, not absolute, time stamps */
wth->phdr.presence_flags = WTAP_HAS_TS;
- /* It would be really cool to be able to configure the bitrate... */
- tmp = (MP2T_SIZE+mp2t->trailer_len) * 8;
- tmp *= 1000000000;
- tmp /= MP2T_QAM256_BITRATE;
-
- wth->phdr.ts.secs = mp2t->now.secs;
- wth->phdr.ts.nsecs = mp2t->now.nsecs;
- mp2t->now.nsecs += (guint32)tmp;
- if (1000000000 <= mp2t->now.nsecs) {
- mp2t->now.nsecs -= 1000000000;
- mp2t->now.secs++;
- }
+ /*
+ * Every packet in an MPEG2-TS stream is has a fixed size of
+ * MP2T_SIZE plus the number of trailer bytes.
+ *
+ * The bitrate is constant, so the time offset, from the beginning
+ * of the stream, of a given packet is the packet offset, in bits,
+ * divided by the bitrate.
+ *
+ * It would be really cool to be able to configure the bitrate...
+ */
+ tmp = ((guint64)(*data_offset - mp2t->start_offset) * 8); /* offset, in bits */
+ wth->phdr.ts.secs = tmp / MP2T_QAM256_BITRATE;
+ wth->phdr.ts.nsecs = (tmp % MP2T_QAM256_BITRATE) * 1000000000 / MP2T_QAM256_BITRATE;
+
wth->phdr.caplen = MP2T_SIZE;
wth->phdr.len = MP2T_SIZE;
@@ -229,9 +229,7 @@ mp2t_open(wtap *wth, int *err, gchar **err_info)
}
wth->priv = mp2t;
- mp2t->offset = (guint32) first;
- mp2t->now.secs = 0;
- mp2t->now.nsecs = 0;
+ mp2t->start_offset = first;
mp2t->trailer_len = trailer_len;
return 1;