Skip to content

Commit 8208fec

Browse files
committed
Look for SPS instead of keyframe with H264 packetization_mode=0
1 parent 598dc4e commit 8208fec

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/ex_webrtc/rtp/h264.ex

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ defmodule ExWebRTC.RTP.H264 do
77

88
# Copied nearly 1-to-1 from https://github.com/membraneframework/membrane_rtp_h264_plugin/blob/master/lib/rtp_h264/utils.ex
99
# originally based on galene's implementation https://github.com/jech/galene/blob/6fbdf0eab2c9640e673d9f9ec0331da24cbf2c4c/codecs/codecs.go#L119
10-
# but only looks for SPS
11-
# it is also unclear why we sometimes check against nalu type == 7
12-
# and sometimes against nalu type == 5 but galene does it this way
13-
# and it works
10+
# but only looks for SPS, in packetization_mode=0 as well as packetization_mode=1.
11+
#
12+
# It's been empirically tested with simulated packet loss that for packetization_mode=0 (`nalu_type in 1..23` clause):
13+
# * if we're checking against `nalu_type == 5`, the stream breaks regularly when switching layers,
14+
# * if we're checking against `nalu_type == 5 or nalu_type == 7`, the stream breaks occasionally when switching layers,
15+
# this happens when we've lost the packet containing SPS, but received the following one containing the keyframe,
16+
# * if we're checking against `nalu_type == 7`, no issues were encountered.
17+
#
18+
# Janus also does it this way.
19+
# https://github.com/meetecho/janus-gateway/blob/3367f41de9225daed812ca0991c259f1458fe49f/src/utils.h#L352
1420

1521
@doc """
1622
Returns a boolean telling if the packets contains a beginning of a H264 intra-frame.
@@ -22,7 +28,7 @@ defmodule ExWebRTC.RTP.H264 do
2228
def keyframe?(%Packet{}), do: false
2329

2430
defp do_keyframe?(0, _), do: false
25-
defp do_keyframe?(nalu_type, _) when nalu_type in 1..23, do: nalu_type == 5
31+
defp do_keyframe?(nalu_type, _) when nalu_type in 1..23, do: nalu_type == 7
2632
defp do_keyframe?(24, aus), do: check_aggr_units(24, aus)
2733

2834
defp do_keyframe?(nalu_type, <<_don::16, aus::binary>>)

0 commit comments

Comments
 (0)