@@ -138,6 +138,52 @@ public void lostMiddleFragmentDropsTheNal() {
138138 assertArrayEquals (b (0 , 0 , 0 , 1 , 0x65 , 0xD1 , 0xD2 ), out .get (0 ));
139139 }
140140
141+ @ Test
142+ public void salvagePassesTheNalOnCutShortAtTheGap () {
143+ nal .setSalvage (true );
144+ // 16 slice bytes before the gap: enough to be worth decoding (#133)
145+ feed (rtp (0x7C , 0x85 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ), false );
146+ feed (rtp (0x7C , 0x05 , 13 , 14 , 15 , 16 ), false );
147+ seq ++; // one packet lost
148+ feed (rtp (0x7C , 0x05 , 0xB1 ), false );
149+ assertEquals (1 , out .size ());
150+ assertArrayEquals (b (0 , 0 , 0 , 1 , 0x65 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ,
151+ 16 ), out .get (0 ));
152+ assertEquals (1 , nal .salvagedCount ());
153+ assertEquals (1 , nal .lossCount ());
154+ // The rest of that unit is skipped; the next one is complete again
155+ feed (rtp (0x7C , 0x45 , 0xC1 ), false );
156+ feed (rtp (0x7C , 0x85 , 0xD1 ), false );
157+ feed (rtp (0x7C , 0x45 , 0xD2 ), false );
158+ assertEquals (2 , out .size ());
159+ assertArrayEquals (b (0 , 0 , 0 , 1 , 0x65 , 0xD1 , 0xD2 ), out .get (1 ));
160+ }
161+
162+ @ Test
163+ public void salvageNeverPassesACutParameterSet () {
164+ nal .setSalvage (true );
165+ // FU-A of an SPS (type 7), then a lost packet (Qodo on #146)
166+ feed (rtp (0x7C , 0x87 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ), false );
167+ seq ++;
168+ feed (rtp (0x7C , 0x47 , 0xC1 ), false );
169+ assertEquals (0 , out .size ());
170+ assertEquals (0 , nal .salvagedCount ());
171+ assertTrue (NalAssembler .isSlice ((byte ) 0x65 , false ));
172+ assertFalse (NalAssembler .isSlice ((byte ) 0x68 , false ));
173+ // H.265: IDR_W_RADL (19) is a slice, VPS (32) is not
174+ assertTrue (NalAssembler .isSlice ((byte ) (19 << 1 ), true ));
175+ assertFalse (NalAssembler .isSlice ((byte ) (32 << 1 ), true ));
176+ }
177+
178+ @ Test
179+ public void salvageOffDropsAsBefore () {
180+ feed (rtp (0x7C , 0x85 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ), false );
181+ seq ++;
182+ feed (rtp (0x7C , 0x45 , 0xC1 ), false );
183+ assertEquals (0 , out .size ());
184+ assertEquals (0 , nal .salvagedCount ());
185+ }
186+
141187 @ Test
142188 public void continuationWithoutStartIsIgnoredAndCountedOnce () {
143189 feed (rtp (0x7C , 0x05 , 0xB1 ), false );
0 commit comments