Last active
May 30, 2018 06:55
-
-
Save ggarber/7e814442166339a92c6b179445b8b365 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# code from nack_module.cc | |
on_packet(rtp): | |
if rtp.seq_num < newest_seq_num: # out of order or retransmnission | |
return | |
add_missing(newest_seq_num + 1, rtp.seq_num) | |
if rtp.is_first_packet_of_keyframe: | |
keyframes.insert(rtp.seq_num) | |
newest_seq_num = packet.seq_num | |
if nack = generate_nack(SEQ): | |
send_nack(nack) | |
add_missing(from_seq_num, to_seq_num): | |
packets_lost.remove_older_than(10000) # MAX_PACKET_AGE (sequence numbers) | |
if packets_lost.size() > 1000: # MAX_SIZE | |
packets_lost.remove_until_keyframe() | |
if packets_lost.size() > 1000: # Still too big | |
packets_lost.clear() | |
sender.request_keyframe() | |
return | |
for seq_num in range(from_seq_num, to_seq_num): | |
packets_lost.insert(seq_num) | |
# called when a new decodable frame is ready | |
cleanup_to(to_seq_num): | |
packets_lost.remove(seq_num < to_seq_num); | |
generate_nack(mode): | |
seq_nums = [] | |
for packet in packets_lost: | |
if packet.retries > 10: # MAX_RETRIES | |
packets_lost.remove(packet) | |
if (mode == SEQ and packet.seq_num < newest_seq_num) or | |
(mode == TIME and packet.sent_at + rtt > now()): | |
seq_nums.insert(packet.seq_num) | |
packet.sent_at = now() | |
return seq_nums | |
every_20_msec(): | |
if nack = generate_nack(TIME): | |
send_nack(nack) | |
# code from rtp_rtcp_impl.cc | |
send_nack(seq_nums): | |
if now - time_last_full_nack_sent < 1.5 * RTT: | |
seq_nums.filter(seq_num > seq_num_last_nack_sent) | |
else: | |
time_last_full_nack_sent = now | |
if seq_nums.length > 253: | |
seq_nums = seq_nums[:-253] | |
send(new RtcpNack(seq_nums)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment