From xine-devel Sat Jun 02 20:14:50 2007 From: Andrew de Quincey Date: Sat, 02 Jun 2007 20:14:50 +0000 To: xine-devel Subject: [xine-devel] [patch] Fix video pid misdetection Message-Id: <20070602211450.xvh5mxuggskwwoo0 () lidskialf ! net> X-MARC-Message: https://marc.info/?l=xine-devel&m=118081521207400 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--=_5ra4tltwlns4" This message is in MIME format. --=_5ra4tltwlns4 Content-Type: text/plain; charset=UTF-8; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, the next bug that has been annoying me is as follows. I have some streams recorded from BBC4 on UK DVB-T. BBC4 only actually starts transmitting at about 7pm; prior to that there is a static picture saying it is not playing just now. With these streams and xine, I would get audio, but no picture. Looking at the PMT table during the static picture, all the streams have type 0x0b. However there IS a video stream in there, but there are also several streams of binary data. Xine's current video PID auto-detection code was locking on to one of these streams of binary data because it contained the magic sequence 00 00 01 e0 at one of the PUS. *HOWEVER* it is NOT a PES stream; this sequence is just an accident. The other problem is that xine can only handle one video stream; so once it was misdetected once, it was stuck at that PID. The attached patch changes the corrupted_pes flag into a counter. If a video stream has more than CORRUPT_PES_THRESHOLD corrupt PES packets in a row, then it is deselected as the video stream, and auto-detection is kicked off again. Auto-detection will now also ignore any streams seen previously which have a nonzero corrupted_pes count. This works very well; I can now see the video fine. One possible issue might be that if you get a lot of corrupt PES in a stream which really IS the video stream, it will be deselected. However, this is not actually a problem: once the corruption goes away, the corrupted_pes counter will be reset to 0, and the stream will once again be autodetected as the video stream (and playback will continue from there). --=_5ra4tltwlns4 Content-Type: text/x-diff; charset=utf-8; name="xine-1.1.6-pidfix.patch" Content-Disposition: attachment; filename="xine-1.1.6-pidfix.patch" Content-Transfer-Encoding: quoted-printable diff -Naur xine-lib-1.1.6.ORIG/src/demuxers/demux_ts.c xine-lib-1.1.6.PIDFIX= /src/demuxers/demux_ts.c --- xine-lib-1.1.6.ORIG/src/demuxers/demux_ts.c=092007-04-17 02:00:50.000000= 000 +0100 +++ xine-lib-1.1.6.PIDFIX/src/demuxers/demux_ts.c=092007-06-02 20:37:48.3672= 35323 +0100 @@ -180,6 +180,8 @@ =20 #define MAX_PES_BUF_SIZE 2048 =20 +#define CORRUPT_PES_THRESHOLD 10 + #define NULL_PID 0x1fff #define INVALID_PID ((unsigned int)(-1)) #define INVALID_PROGRAM ((unsigned int)(-1)) @@ -910,12 +912,17 @@ m->buf =3D m->fifo->buffer_pool_alloc(m->fifo); =20 if (!demux_ts_parse_pes_header(this->stream->xine, m, ts, len, this->st= ream)) { - m->corrupted_pes =3D 1; m->buf->free_buffer(m->buf); m->buf =3D NULL; - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,=20 + =20 + if (m->corrupted_pes > CORRUPT_PES_THRESHOLD) { + if (this->videoPid =3D=3D m->pid) + this->videoPid =3D INVALID_PID; + } else { + m->corrupted_pes++; + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,=20 =09 "demux_ts: PID 0x%.4x: corrupted pes encountered\n", m->pid); - + } } else { =20 m->corrupted_pes =3D 0; @@ -1785,13 +1792,27 @@ =20 if ( (pes_stream_id >=3D VIDEO_STREAM_S) && (pes_stream_id <=3D VIDEO_S= TREAM_E) ) { if ( this->videoPid =3D=3D INVALID_PID) { - -=09xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG,=20 -=09=09 "demux_ts: auto-detected video pid 0x%.4x\n", pid); - -=09this->videoPid =3D pid; -=09this->videoMedia =3D this->media_num; -=09demux_ts_pes_new(this, this->media_num++, pid, this->video_fifo, pes_str= eam_id); + int i, found =3D 0; + for(i =3D 0; i < this->media_num; i++) { + if (this->media[i].pid =3D=3D pid) { + found =3D 1; + break; + } + } + =20 + if (found && (this->media[i].corrupted_pes =3D=3D 0)) { + this->videoPid =3D pid; +=09 this->videoMedia =3D i; + } else if (!found) { +=09 this->videoPid =3D pid; +=09 this->videoMedia =3D this->media_num; +=09 demux_ts_pes_new(this, this->media_num++, pid, this->video_fifo, pes_s= tream_id); + } + =20 + if (this->videoPid !=3D INVALID_PID) { + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG,=20 + "demux_ts: auto-detected video pid 0x%.4x\n", pid); + }=20 } } else if ( (pes_stream_id >=3D AUDIO_STREAM_S) && (pes_stream_id <=3D = AUDIO_STREAM_E) ) { if (this->audio_tracks_count < MAX_AUDIO_TRACKS) { --=_5ra4tltwlns4 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ --=_5ra4tltwlns4 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ xine-devel mailing list xine-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xine-devel --=_5ra4tltwlns4--