• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.google.android.exoplayer2.trackselection;
17 
18 import androidx.annotation.Nullable;
19 import com.google.android.exoplayer2.RendererConfiguration;
20 import com.google.android.exoplayer2.util.Util;
21 import org.checkerframework.checker.nullness.compatqual.NullableType;
22 
23 /**
24  * The result of a {@link TrackSelector} operation.
25  */
26 public final class TrackSelectorResult {
27 
28   /** The number of selections in the result. Greater than or equal to zero. */
29   public final int length;
30   /**
31    * A {@link RendererConfiguration} for each renderer. A null entry indicates the corresponding
32    * renderer should be disabled.
33    */
34   public final @NullableType RendererConfiguration[] rendererConfigurations;
35   /**
36    * A {@link TrackSelectionArray} containing the track selection for each renderer.
37    */
38   public final TrackSelectionArray selections;
39   /**
40    * An opaque object that will be returned to {@link TrackSelector#onSelectionActivated(Object)}
41    * should the selections be activated.
42    */
43   public final Object info;
44 
45   /**
46    * @param rendererConfigurations A {@link RendererConfiguration} for each renderer. A null entry
47    *     indicates the corresponding renderer should be disabled.
48    * @param selections A {@link TrackSelectionArray} containing the selection for each renderer.
49    * @param info An opaque object that will be returned to {@link
50    *     TrackSelector#onSelectionActivated(Object)} should the selection be activated.
51    */
TrackSelectorResult( @ullableType RendererConfiguration[] rendererConfigurations, @NullableType TrackSelection[] selections, Object info)52   public TrackSelectorResult(
53       @NullableType RendererConfiguration[] rendererConfigurations,
54       @NullableType TrackSelection[] selections,
55       Object info) {
56     this.rendererConfigurations = rendererConfigurations;
57     this.selections = new TrackSelectionArray(selections);
58     this.info = info;
59     length = rendererConfigurations.length;
60   }
61 
62   /** Returns whether the renderer at the specified index is enabled. */
isRendererEnabled(int index)63   public boolean isRendererEnabled(int index) {
64     return rendererConfigurations[index] != null;
65   }
66 
67   /**
68    * Returns whether this result is equivalent to {@code other} for all renderers.
69    *
70    * @param other The other {@link TrackSelectorResult}. May be null, in which case {@code false}
71    *     will be returned.
72    * @return Whether this result is equivalent to {@code other} for all renderers.
73    */
isEquivalent(@ullable TrackSelectorResult other)74   public boolean isEquivalent(@Nullable TrackSelectorResult other) {
75     if (other == null || other.selections.length != selections.length) {
76       return false;
77     }
78     for (int i = 0; i < selections.length; i++) {
79       if (!isEquivalent(other, i)) {
80         return false;
81       }
82     }
83     return true;
84   }
85 
86   /**
87    * Returns whether this result is equivalent to {@code other} for the renderer at the given index.
88    * The results are equivalent if they have equal track selections and configurations for the
89    * renderer.
90    *
91    * @param other The other {@link TrackSelectorResult}. May be null, in which case {@code false}
92    *     will be returned.
93    * @param index The renderer index to check for equivalence.
94    * @return Whether this result is equivalent to {@code other} for the renderer at the specified
95    *     index.
96    */
isEquivalent(@ullable TrackSelectorResult other, int index)97   public boolean isEquivalent(@Nullable TrackSelectorResult other, int index) {
98     if (other == null) {
99       return false;
100     }
101     return Util.areEqual(rendererConfigurations[index], other.rendererConfigurations[index])
102         && Util.areEqual(selections.get(index), other.selections.get(index));
103   }
104 
105 }
106