mirror of
https://github.com/samsonjs/media.git
synced 2026-04-26 14:57:47 +00:00
Add non-null by default to source package (last one!)
Note on UnknownNull: Where there exists a generically typed base class and both null and non-null types are permitted, we need to clear the default non-null that's otherwise propagated everywhere. This then lets the nullness of the type work properly. PiperOrigin-RevId: 295582444
This commit is contained in:
parent
e77ff2a3b0
commit
5b3ed8286c
3 changed files with 64 additions and 11 deletions
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2019 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.google.android.exoplayer2.util;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.meta.TypeQualifierDefault;
|
||||||
|
import javax.annotation.meta.When;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotation for specifiying unknown nullness. Useful for clearing the effects of an automatically
|
||||||
|
* propagated {@link Nonnull} annotation.
|
||||||
|
*/
|
||||||
|
@Nonnull(when = When.UNKNOWN)
|
||||||
|
@TypeQualifierDefault(ElementType.TYPE_USE)
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
public @interface UnknownNull {}
|
||||||
|
|
@ -21,6 +21,7 @@ import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.Timeline;
|
import com.google.android.exoplayer2.Timeline;
|
||||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
|
import com.google.android.exoplayer2.util.UnknownNull;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -91,7 +92,7 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
|
||||||
* @param timeline The timeline of the child source.
|
* @param timeline The timeline of the child source.
|
||||||
*/
|
*/
|
||||||
protected abstract void onChildSourceInfoRefreshed(
|
protected abstract void onChildSourceInfoRefreshed(
|
||||||
T id, MediaSource mediaSource, Timeline timeline);
|
@UnknownNull T id, MediaSource mediaSource, Timeline timeline);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares a child source.
|
* Prepares a child source.
|
||||||
|
|
@ -105,7 +106,7 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
|
||||||
* @param id A unique id to identify the child source preparation. Null is allowed as an id.
|
* @param id A unique id to identify the child source preparation. Null is allowed as an id.
|
||||||
* @param mediaSource The child {@link MediaSource}.
|
* @param mediaSource The child {@link MediaSource}.
|
||||||
*/
|
*/
|
||||||
protected final void prepareChildSource(final T id, MediaSource mediaSource) {
|
protected final void prepareChildSource(@UnknownNull T id, MediaSource mediaSource) {
|
||||||
Assertions.checkArgument(!childSources.containsKey(id));
|
Assertions.checkArgument(!childSources.containsKey(id));
|
||||||
MediaSourceCaller caller =
|
MediaSourceCaller caller =
|
||||||
(source, timeline) -> onChildSourceInfoRefreshed(id, source, timeline);
|
(source, timeline) -> onChildSourceInfoRefreshed(id, source, timeline);
|
||||||
|
|
@ -123,7 +124,7 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
|
||||||
*
|
*
|
||||||
* @param id The unique id used to prepare the child source.
|
* @param id The unique id used to prepare the child source.
|
||||||
*/
|
*/
|
||||||
protected final void enableChildSource(final T id) {
|
protected final void enableChildSource(@UnknownNull T id) {
|
||||||
MediaSourceAndListener enabledChild = Assertions.checkNotNull(childSources.get(id));
|
MediaSourceAndListener enabledChild = Assertions.checkNotNull(childSources.get(id));
|
||||||
enabledChild.mediaSource.enable(enabledChild.caller);
|
enabledChild.mediaSource.enable(enabledChild.caller);
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +134,7 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
|
||||||
*
|
*
|
||||||
* @param id The unique id used to prepare the child source.
|
* @param id The unique id used to prepare the child source.
|
||||||
*/
|
*/
|
||||||
protected final void disableChildSource(final T id) {
|
protected final void disableChildSource(@UnknownNull T id) {
|
||||||
MediaSourceAndListener disabledChild = Assertions.checkNotNull(childSources.get(id));
|
MediaSourceAndListener disabledChild = Assertions.checkNotNull(childSources.get(id));
|
||||||
disabledChild.mediaSource.disable(disabledChild.caller);
|
disabledChild.mediaSource.disable(disabledChild.caller);
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +144,7 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
|
||||||
*
|
*
|
||||||
* @param id The unique id used to prepare the child source.
|
* @param id The unique id used to prepare the child source.
|
||||||
*/
|
*/
|
||||||
protected final void releaseChildSource(T id) {
|
protected final void releaseChildSource(@UnknownNull T id) {
|
||||||
MediaSourceAndListener removedChild = Assertions.checkNotNull(childSources.remove(id));
|
MediaSourceAndListener removedChild = Assertions.checkNotNull(childSources.remove(id));
|
||||||
removedChild.mediaSource.releaseSource(removedChild.caller);
|
removedChild.mediaSource.releaseSource(removedChild.caller);
|
||||||
removedChild.mediaSource.removeEventListener(removedChild.eventListener);
|
removedChild.mediaSource.removeEventListener(removedChild.eventListener);
|
||||||
|
|
@ -157,7 +158,7 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
|
||||||
* @param windowIndex A window index of the child source.
|
* @param windowIndex A window index of the child source.
|
||||||
* @return The corresponding window index in the composite source.
|
* @return The corresponding window index in the composite source.
|
||||||
*/
|
*/
|
||||||
protected int getWindowIndexForChildWindowIndex(T id, int windowIndex) {
|
protected int getWindowIndexForChildWindowIndex(@UnknownNull T id, int windowIndex) {
|
||||||
return windowIndex;
|
return windowIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,8 +172,9 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
|
||||||
* @return The corresponding {@link MediaPeriodId} in the composite source. Null if no
|
* @return The corresponding {@link MediaPeriodId} in the composite source. Null if no
|
||||||
* corresponding media period id can be determined.
|
* corresponding media period id can be determined.
|
||||||
*/
|
*/
|
||||||
protected @Nullable MediaPeriodId getMediaPeriodIdForChildMediaPeriodId(
|
@Nullable
|
||||||
T id, MediaPeriodId mediaPeriodId) {
|
protected MediaPeriodId getMediaPeriodIdForChildMediaPeriodId(
|
||||||
|
@UnknownNull T id, MediaPeriodId mediaPeriodId) {
|
||||||
return mediaPeriodId;
|
return mediaPeriodId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,7 +186,7 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
|
||||||
* @param mediaTimeMs A media time of the child source, in milliseconds.
|
* @param mediaTimeMs A media time of the child source, in milliseconds.
|
||||||
* @return The corresponding media time in the composite source, in milliseconds.
|
* @return The corresponding media time in the composite source, in milliseconds.
|
||||||
*/
|
*/
|
||||||
protected long getMediaTimeForChildMediaTime(@Nullable T id, long mediaTimeMs) {
|
protected long getMediaTimeForChildMediaTime(@UnknownNull T id, long mediaTimeMs) {
|
||||||
return mediaTimeMs;
|
return mediaTimeMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,10 +218,10 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
|
||||||
|
|
||||||
private final class ForwardingEventListener implements MediaSourceEventListener {
|
private final class ForwardingEventListener implements MediaSourceEventListener {
|
||||||
|
|
||||||
private final T id;
|
@UnknownNull private final T id;
|
||||||
private EventDispatcher eventDispatcher;
|
private EventDispatcher eventDispatcher;
|
||||||
|
|
||||||
public ForwardingEventListener(T id) {
|
public ForwardingEventListener(@UnknownNull T id) {
|
||||||
this.eventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null);
|
this.eventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null);
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2019 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
@NonNullApi
|
||||||
|
package com.google.android.exoplayer2.source;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer2.util.NonNullApi;
|
||||||
Loading…
Reference in a new issue