mpegtsdemux: create function for pcr parsing

This commit is contained in:
Janne Grunau 2011-02-23 15:21:22 +01:00 committed by Edward Hervey
parent 37f1decf78
commit f89a0abca0
3 changed files with 23 additions and 32 deletions

View file

@ -199,6 +199,21 @@ mpegts_packetizer_finalize (GObject * object)
G_OBJECT_CLASS (mpegts_packetizer_parent_class)->finalize (object); G_OBJECT_CLASS (mpegts_packetizer_parent_class)->finalize (object);
} }
guint64
mpegts_packetizer_compute_pcr (const guint8 * data)
{
guint32 pcr1;
guint16 pcr2;
guint64 pcr, pcr_ext;
pcr1 = GST_READ_UINT32_BE (data);
pcr2 = GST_READ_UINT16_BE (data + 4);
pcr = ((guint64) pcr1) << 1;
pcr |= (pcr2 & 0x8000) >> 15;
pcr_ext = (pcr2 & 0x01ff);
return pcr * 300 + pcr_ext % 300;
}
static gboolean static gboolean
mpegts_packetizer_parse_adaptation_field_control (MpegTSPacketizer2 * mpegts_packetizer_parse_adaptation_field_control (MpegTSPacketizer2 *
packetizer, MpegTSPacketizerPacket * packet) packetizer, MpegTSPacketizerPacket * packet)
@ -240,31 +255,13 @@ mpegts_packetizer_parse_adaptation_field_control (MpegTSPacketizer2 *
/* PCR */ /* PCR */
if (afcflags & MPEGTS_AFC_PCR_FLAG) { if (afcflags & MPEGTS_AFC_PCR_FLAG) {
guint32 pcr1; packet->pcr = mpegts_packetizer_compute_pcr (data);
guint16 pcr2;
guint64 pcr, pcr_ext;
pcr1 = GST_READ_UINT32_BE (data);
pcr2 = GST_READ_UINT16_BE (data + 4);
pcr = ((guint64) pcr1) << 1;
pcr |= (pcr2 & 0x8000) >> 15;
pcr_ext = (pcr2 & 0x01ff);
packet->pcr = pcr * 300 + pcr_ext % 300;;
*data += 6; *data += 6;
} }
/* OPCR */ /* OPCR */
if (afcflags & MPEGTS_AFC_OPCR_FLAG) { if (afcflags & MPEGTS_AFC_OPCR_FLAG) {
guint32 pcr1; packet->opcr = mpegts_packetizer_compute_pcr (data);
guint16 pcr2;
guint64 pcr, pcr_ext;
pcr1 = GST_READ_UINT32_BE (data);
pcr2 = GST_READ_UINT16_BE (data + 4);
pcr = ((guint64) pcr1) << 1;
pcr |= (pcr2 & 0x8000) >> 15;
pcr_ext = (pcr2 & 0x01ff);
packet->opcr = pcr * 300 + pcr_ext % 300;;
*data += 6; *data += 6;
} }

View file

@ -161,6 +161,7 @@ GstStructure *mpegts_packetizer_parse_eit (MpegTSPacketizer2 *packetizer,
MpegTSPacketizerSection *section); MpegTSPacketizerSection *section);
GstStructure *mpegts_packetizer_parse_tdt (MpegTSPacketizer2 *packetizer, GstStructure *mpegts_packetizer_parse_tdt (MpegTSPacketizer2 *packetizer,
MpegTSPacketizerSection *section); MpegTSPacketizerSection *section);
guint64 mpegts_packetizer_compute_pcr(const guint8 * data);
G_END_DECLS G_END_DECLS

View file

@ -997,20 +997,13 @@ process_pcr (MpegTSBase * base, guint64 initoff, GstClockTime * pcr,
/* GST_DEBUG ("offset %" G_GUINT64_FORMAT, GST_BUFFER_OFFSET (buf) + offset); /* GST_DEBUG ("offset %" G_GUINT64_FORMAT, GST_BUFFER_OFFSET (buf) + offset);
GST_MEMDUMP ("something", GST_BUFFER_DATA (buf) + offset, 16);*/ GST_MEMDUMP ("something", GST_BUFFER_DATA (buf) + offset, 16);*/
if ((*(br.data + offset + 5)) & 0x10) { if ((*(br.data + offset + 5)) & 0x10) {
guint16 pcr2; guint64 lpcr = mpegts_packetizer_compute_pcr (br.data + offset + 6);
guint64 pcr, pcr_ext;
pcr = ((guint64) GST_READ_UINT32_BE (br.data + offset + 6)) << 1; GST_INFO ("Found PCR %" G_GUINT64_FORMAT " %" GST_TIME_FORMAT
pcr2 = GST_READ_UINT16_BE (br.data + offset + 10); " at offset %" G_GUINT64_FORMAT, lpcr,
pcr |= (pcr2 & 0x8000) >> 15; GST_TIME_ARGS (PCRTIME_TO_GSTTIME (lpcr)),
pcr_ext = (pcr2 & 0x01ff);
pcr = pcr * 300 + pcr_ext % 300;
GST_DEBUG ("Found PCR %" G_GUINT64_FORMAT " %" GST_TIME_FORMAT
" at offset %" G_GUINT64_FORMAT, pcr,
GST_TIME_ARGS (PCRTIME_TO_GSTTIME (pcr)),
GST_BUFFER_OFFSET (buf) + offset); GST_BUFFER_OFFSET (buf) + offset);
pcrs[nbpcr] = pcr; pcrs[nbpcr] = lpcr;
pcroffs[nbpcr] = GST_BUFFER_OFFSET (buf) + offset; pcroffs[nbpcr] = GST_BUFFER_OFFSET (buf) + offset;
/* Safeguard against bogus PCR (by detecting if it's the same as the /* Safeguard against bogus PCR (by detecting if it's the same as the
* previous one or wheter the difference with the previous one is * previous one or wheter the difference with the previous one is