[MPlayer-users] [Samuel.Thibault at ens-lyon.fr: [mplayer] rtp stream reading]

Samuel Thibault Samuel.Thibault at ens-lyon.fr
Sun Nov 23 23:29:11 CET 2003


Hi,

I'm currently playing with multicast, and tried to watch Nasa TV
(rtp://224.2.231.45:54302) with mplayer, for instance, but I was
getting a lot of
RTP packet sequence error!

I'm not sure whether it's that important for later decoding, but
anyway, here is a corrected version of read_rtp_from_server()
(libmpdemux/network.c) which handles packet reordering as long as it
doesn't exceed 8 packets, and loss is just displayed. Could you have a
look and integrate it in mplayer if you like it ? (or just take the idea
and re-implement it yourself)

At least, the error message should be avoided, because one really
thinks something is broken (all the more so since nothing is displayed,
because mplayer waits for a repetition of the big headers before starting
to decode the stream)

Regards,
Samuel Thibault

#ifndef STREAMING_LIVE_DOT_COM
#define RTP_NBSAVEDPACKETS 8
int
read_rtp_from_server(int fd, char *buffer, int length) {
	struct rtpheader rh;
	char *data;
	int len;
	static char rtp_buf[RTP_NBSAVEDPACKETS][1600];
	static int rtp_len[RTP_NBSAVEDPACKETS];
	static int rtp_read;
	static int got_first;
	static unsigned short sequence;
	int i,j;

	if( buffer==NULL || length<0 ) return -1;

	while (1) {
		if (rtp_len[rtp_read]) {
			len = rtp_len[rtp_read];
			//mp_msg(MSGT_NETWORK,MSGL_ERR,"seq back %d (%d) from %d\n",sequence+1,len,rtp_read);
			memcpy(buffer,rtp_buf[rtp_read],len);
			rtp_len[rtp_read]=0;
			rtp_read=(rtp_read+1)%RTP_NBSAVEDPACKETS;
			sequence++;
			return len;
		}

		getrtp2(fd, &rh, &data, &len);
		if (!got_first || rh.b.sequence == (unsigned short)(sequence+1)) {
			got_first = 1;
			sequence = rh.b.sequence;
			rtp_len[rtp_read]=0; /* just in case ... */
			rtp_read=(rtp_read+1)%RTP_NBSAVEDPACKETS;
			//mp_msg(MSGT_NETWORK,MSGL_ERR,"seq ok %d\n",sequence);
			memcpy(buffer, data, len);
			return len;
		}
		if (((unsigned)rh.b.sequence-sequence)>RTP_NBSAVEDPACKETS+1) {
			mp_msg(MSGT_NETWORK,MSGL_ERR,"RTP packet sequence error!  Expected: %d, received: %d\n, resyncing\n", 
				sequence+1, rh.b.sequence);
			sequence = rh.b.sequence;
			bzero(rtp_len,sizeof(rtp_len));

		} else {
			i = rh.b.sequence-sequence-1;
			if (i>RTP_NBSAVEDPACKETS/2) {
				sequence++;
				rtp_read=(rtp_read+1)%RTP_NBSAVEDPACKETS;
				i--;
				mp_msg(MSGT_NETWORK,MSGL_ERR,"RTP skipped a bit\n");
			}
			j = (rtp_read+i)%RTP_NBSAVEDPACKETS;
			//mp_msg(MSGT_NETWORK,MSGL_ERR,"RTP %d (%d) stored in %d ie %d\n",rh.b.sequence,len,i,j);
			memcpy(rtp_buf[j],data,len);
			rtp_len[j]=len;
		}
	}
}
#endif



More information about the MPlayer-users mailing list