Hi all.
My problem is described in the libav-api mailing list
https://lists.libav.org/pipermail/libav-api/2011-June/000118.html
I've developed a patch, allowing libav to skip all packets, whose PIDs are not
in the PAT/PMT. Please, see the attachment.
Unfortunately, I could not find circumstances, when av_read_packet falls in the
infinite loop.
Probably, the community could point me to the right direction in order to
reproduce the bug.
Vladimir.
>From 178f6d81c82bc46129a550f081317f5a85855089 Mon Sep 17 00:00:00 2001
From: Vladimir Eremeev <[email protected]>
Date: Mon, 20 Jun 2011 16:32:00 +0400
Subject: [PATCH] mpegts: drop all packets, whose pids are not listed in PMT/PAT
---
libavformat/mpegts.c | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 74c9ac9..61531da 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -654,6 +654,29 @@ static void new_pes_packet(PESContext *pes, AVPacket *pkt)
pes->data_index = 0;
}
+/* return 1 if the pid is listed in PAT/PMT, 0 otherwise */
+static int mpegts_check_pid_in_psi(MpegTSContext *ts, int pid)
+{
+ int result = 0;
+ int i;
+
+ if ( pid < 0x0010 )
+ return 0;
+
+ if (!ts || !ts->prg)
+ return 0;
+
+ for (i = 0; i < ts->nb_prg && !result; i++){
+ int j;
+ for(j = 0; j < ts->prg[i].nb_pids && !result; j++)
+ if(ts->prg[i].pids[j] == pid) {
+ result = 1;
+ break;
+ }
+ }
+ return result;
+}
+
/* return non zero if a packet could be constructed */
static int mpegts_push_data(MpegTSFilter *filter,
const uint8_t *buf, int buf_size, int is_start,
@@ -702,6 +725,11 @@ static int mpegts_push_data(MpegTSFilter *filter,
/* stream not present in PMT */
if (!pes->st) {
+ if(!mpegts_check_pid_in_psi(ts, pes->pid)) {
+ av_dlog(pes->stream, AV_LOG_DEBUG, "pid %d not listed in PAT/PMT, skipping", pes->pid );
+ goto skip;
+ }
+
pes->st = av_new_stream(ts->stream, pes->pid);
if (!pes->st)
return AVERROR(ENOMEM);
--
1.7.2.3
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel