C API RTP - I can't see any code for dealing with packet re-ordering, is that correct?

Want to write your own code to work with a HDHomeRun or work with the HDHomeRun DVR? We are happy to help with concepts, APIs, best practices.
Post Reply
oviano
Posts: 4
Joined: Wed Dec 02, 2020 12:32 pm

C API RTP - I can't see any code for dealing with packet re-ordering, is that correct?

Post by oviano »

Unless I've misread the code, it receives the UDP packets, strips the RTP header and just logs out-of-sequence packets.

Below is after it has received a packet, calls parse_rtp:

Code: Select all

		if (length == VIDEO_RTP_DATA_PACKET_SIZE) {
			hdhomerun_video_parse_rtp(vs, &pkt);
			length = pkt.end - pkt.pos;
		}

		if (length != VIDEO_DATA_PACKET_SIZE) {
			/* Data received but not valid - ignore. */
			continue;
		}
And here is the parse function, it checks the sequence, and logs the error, but takes no action, neither dropping or buffering for re-order.

Code: Select all

static void hdhomerun_video_parse_rtp(struct hdhomerun_video_sock_t *vs, struct hdhomerun_pkt_t *pkt)
{
	pkt->pos += 2;
	uint32_t rtp_sequence = hdhomerun_pkt_read_u16(pkt);
	pkt->pos += 8;

	uint32_t previous_rtp_sequence = vs->rtp_sequence;
	vs->rtp_sequence = rtp_sequence;

	/* Initial case - first packet received. */
	if (previous_rtp_sequence == 0xFFFFFFFF) {
		return;
	}

	/* Normal case - next sequence number. */
	if (rtp_sequence == ((previous_rtp_sequence + 1) & 0xFFFF)) {
		return;
	}

	/* Error case - sequence missed. */
	vs->network_error_count++;

	/* Restart pid sequence check after packet loss. */
	int i;
	for (i = 0; i < 0x2000; i++) {
		vs->sequence[i] = 0xFF;
	}
}
I suppose over the LAN out-of-order packets are less likely to happen, at least for a wired connection, but I wonder if the official player apps take the same approach, or do they implement re-ordering? Seems pointless to send the stream using RTP and then just pretty much drop the sequence information and not do anything useful with it, so I assume the official players must make use of the extra info?

nickk
Silicondust
Posts: 16581
Joined: Tue Jan 13, 2004 9:39 am
x 129

Re: C API RTP - I can't see any code for dealing with packet re-ordering, is that correct?

Post by nickk »

You don't get out of order packets on a LAN network... the code is detecting missing/dropped packets and keeping a count.

Nick

oviano
Posts: 4
Joined: Wed Dec 02, 2020 12:32 pm

Re: C API RTP - I can't see any code for dealing with packet re-ordering, is that correct?

Post by oviano »

nickk wrote: Sat Dec 05, 2020 7:58 am You don't get out of order packets on a LAN network... the code is detecting missing/dropped packets and keeping a count.

Nick
Well it's obviously less likely, but UDP doesn't guarantee packet order so I have to disagree with you there!

Anyway, thanks for the clarification as to what the code is doing, good to know I've not missed anything.

Post Reply