@@ -248,7 +248,7 @@ public void initial_updateSelectedTrack_usesFactoryProvidedTrackFormatComparator
248248 }
249249
250250 @ Test
251- public void initial_updateSelectedTrack_withNoSelectableFormat_fallsBackToLowestBitrate () {
251+ public void initial_updateSelectedTrack_withNoSelectableFormat_fallsBackToLowestPriorityFormat () {
252252 Format format1 = videoFormat (/* bitrate= */ 500 , /* width= */ 320 , /* height= */ 240 );
253253 Format format2 = videoFormat (/* bitrate= */ 1000 , /* width= */ 640 , /* height= */ 480 );
254254 Format format3 = videoFormat (/* bitrate= */ 2000 , /* width= */ 960 , /* height= */ 720 );
@@ -259,60 +259,7 @@ public void initial_updateSelectedTrack_withNoSelectableFormat_fallsBackToLowest
259259 prepareAdaptiveTrackSelectionWithFormatComparator (
260260 trackGroup , formatComparatorInOrder (ImmutableList .of (format2 , format1 , format3 )));
261261
262- assertThat (adaptiveTrackSelection .getSelectedFormat ()).isEqualTo (format1 );
263- assertThat (adaptiveTrackSelection .getSelectionReason ()).isEqualTo (C .SELECTION_REASON_INITIAL );
264- }
265-
266- @ Test
267- public void initial_updateSelectedTrack_withInvalidComparator_fallsBackToDefaultOrdering () {
268- Format format1 = videoFormat (/* bitrate= */ 500 , /* width= */ 320 , /* height= */ 240 );
269- Format format2 = videoFormat (/* bitrate= */ 1000 , /* width= */ 640 , /* height= */ 480 );
270- Format format3 = videoFormat (/* bitrate= */ 2000 , /* width= */ 960 , /* height= */ 720 );
271- TrackGroup trackGroup = new TrackGroup (format1 , format2 , format3 );
272- Comparator <Format > throwingComparator =
273- (firstFormat , secondFormat ) -> {
274- throw new RuntimeException ("Comparator failure" );
275- };
276-
277- when (mockBandwidthMeter .getBitrateEstimate ()).thenReturn (1000L );
278- AdaptiveTrackSelection adaptiveTrackSelection =
279- prepareAdaptiveTrackSelectionWithFormatComparator (trackGroup , throwingComparator );
280-
281- assertThat (adaptiveTrackSelection .getSelectedFormat ()).isEqualTo (format2 );
282- assertThat (adaptiveTrackSelection .getSelectionReason ()).isEqualTo (C .SELECTION_REASON_INITIAL );
283- }
284-
285- @ Test
286- public void
287- updateSelectedTrack_withInvalidComparator_preservesDefaultDownSwitchDeferralWhenBufferedEnough () {
288- Format format1 = videoFormat (/* bitrate= */ 500 , /* width= */ 320 , /* height= */ 240 );
289- Format format2 = videoFormat (/* bitrate= */ 1000 , /* width= */ 640 , /* height= */ 480 );
290- Format format3 = videoFormat (/* bitrate= */ 2000 , /* width= */ 960 , /* height= */ 720 );
291- TrackGroup trackGroup = new TrackGroup (format1 , format2 , format3 );
292- Comparator <Format > throwingComparator =
293- (firstFormat , secondFormat ) -> {
294- throw new RuntimeException ("Comparator failure" );
295- };
296-
297- // The second measurement onward returns 500L, which prompts the track selection to switch down
298- // if necessary.
299- when (mockBandwidthMeter .getBitrateEstimate ()).thenReturn (1000L , 500L );
300- AdaptiveTrackSelection adaptiveTrackSelection =
301- prepareAdaptiveTrackSelectionWithFormatComparatorAndDurations (
302- trackGroup ,
303- AdaptiveTrackSelection .DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS ,
304- /* maxDurationForQualityDecreaseMs= */ 25_000 ,
305- throwingComparator );
306-
307- adaptiveTrackSelection .updateSelectedTrack (
308- /* playbackPositionUs= */ 0 ,
309- /* bufferedDurationUs= */ 25_000_000 ,
310- /* availableDurationUs= */ C .TIME_UNSET ,
311- /* queue= */ Collections .emptyList (),
312- createMediaChunkIterators (trackGroup , TEST_CHUNK_DURATION_US ));
313-
314- // Invalid comparators fall back to the default ordering and preserve the default behavior.
315- assertThat (adaptiveTrackSelection .getSelectedFormat ()).isEqualTo (format2 );
262+ assertThat (adaptiveTrackSelection .getSelectedFormat ()).isEqualTo (format3 );
316263 assertThat (adaptiveTrackSelection .getSelectionReason ()).isEqualTo (C .SELECTION_REASON_INITIAL );
317264 }
318265
@@ -622,7 +569,7 @@ public void updateSelectedTrack_withCustomFormatOrder_usesCustomOrderForSwitchDi
622569
623570 @ Test
624571 public void
625- updateSelectedTrack_withCustomFormatOrder_switchesDownIfCurrentTrackExceedsBandwidth () {
572+ updateSelectedTrack_withCustomFormatOrder_defersSwitchDownWhenBufferedEnough () {
626573 Format format1 = videoFormat (/* bitrate= */ 500 , /* width= */ 320 , /* height= */ 240 );
627574 Format format2 = videoFormat (/* bitrate= */ 1000 , /* width= */ 640 , /* height= */ 480 );
628575 Format format3 = videoFormat (/* bitrate= */ 2000 , /* width= */ 960 , /* height= */ 720 );
@@ -645,8 +592,10 @@ public void updateSelectedTrack_withCustomFormatOrder_usesCustomOrderForSwitchDi
645592 /* queue= */ Collections .emptyList (),
646593 createMediaChunkIterators (trackGroup , TEST_CHUNK_DURATION_US ));
647594
648- assertThat (adaptiveTrackSelection .getSelectedFormat ()).isEqualTo (format1 );
649- assertThat (adaptiveTrackSelection .getSelectionReason ()).isEqualTo (C .SELECTION_REASON_ADAPTIVE );
595+ // With sufficient buffer (bufferedDurationUs >= maxDurationForQualityDecreaseUs), the
596+ // down-switch is deferred regardless of which comparator is in use.
597+ assertThat (adaptiveTrackSelection .getSelectedFormat ()).isEqualTo (format2 );
598+ assertThat (adaptiveTrackSelection .getSelectionReason ()).isEqualTo (C .SELECTION_REASON_INITIAL );
650599 }
651600
652601 @ Test
0 commit comments