Skip to content

Commit

Permalink
Move FormatSupport in common
Browse files Browse the repository at this point in the history
#player-to-common

PiperOrigin-RevId: 344558028
  • Loading branch information
krocard authored and icbaker committed Nov 30, 2020
1 parent 50bbfb5 commit 5384455
Show file tree
Hide file tree
Showing 30 changed files with 236 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ public String getName() {
public final int supportsFormat(Format format) {
if (!MimeTypes.VIDEO_AV1.equalsIgnoreCase(format.sampleMimeType)
|| !Gav1Library.isAvailable()) {
return RendererCapabilities.create(FORMAT_UNSUPPORTED_TYPE);
return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_TYPE);
}
if (format.exoMediaCryptoType != null) {
return RendererCapabilities.create(FORMAT_UNSUPPORTED_DRM);
return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_DRM);
}
return RendererCapabilities.create(FORMAT_HANDLED, ADAPTIVE_SEAMLESS, TUNNELING_NOT_SUPPORTED);
return RendererCapabilities.create(
C.FORMAT_HANDLED, ADAPTIVE_SEAMLESS, TUNNELING_NOT_SUPPORTED);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ public String getName() {
}

@Override
@FormatSupport
@C.FormatSupport
protected int supportsFormatInternal(Format format) {
String mimeType = Assertions.checkNotNull(format.sampleMimeType);
if (!FfmpegLibrary.isAvailable() || !MimeTypes.isAudio(mimeType)) {
return FORMAT_UNSUPPORTED_TYPE;
return C.FORMAT_UNSUPPORTED_TYPE;
} else if (!FfmpegLibrary.supportsFormat(mimeType)
|| (!sinkSupportsFormat(format, C.ENCODING_PCM_16BIT)
&& !sinkSupportsFormat(format, C.ENCODING_PCM_FLOAT))) {
return FORMAT_UNSUPPORTED_SUBTYPE;
return C.FORMAT_UNSUPPORTED_SUBTYPE;
} else if (format.exoMediaCryptoType != null) {
return FORMAT_UNSUPPORTED_DRM;
return C.FORMAT_UNSUPPORTED_DRM;
} else {
return FORMAT_HANDLED;
return C.FORMAT_HANDLED;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public String getName() {
@RendererCapabilities.Capabilities
public final int supportsFormat(Format format) {
// TODO: Remove this line and uncomment the implementation below.
return FORMAT_UNSUPPORTED_TYPE;
return C.FORMAT_UNSUPPORTED_TYPE;
/*
String mimeType = Assertions.checkNotNull(format.sampleMimeType);
if (!FfmpegLibrary.isAvailable() || !MimeTypes.isVideo(mimeType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public String getName() {
}

@Override
@FormatSupport
@C.FormatSupport
protected int supportsFormatInternal(Format format) {
if (!FlacLibrary.isAvailable()
|| !MimeTypes.AUDIO_FLAC.equalsIgnoreCase(format.sampleMimeType)) {
return FORMAT_UNSUPPORTED_TYPE;
return C.FORMAT_UNSUPPORTED_TYPE;
}
// Compute the format that the FLAC decoder will output.
Format outputFormat;
Expand All @@ -102,11 +102,11 @@ protected int supportsFormatInternal(Format format) {
outputFormat = getOutputFormat(streamMetadata);
}
if (!sinkSupportsFormat(outputFormat)) {
return FORMAT_UNSUPPORTED_SUBTYPE;
return C.FORMAT_UNSUPPORTED_SUBTYPE;
} else if (format.exoMediaCryptoType != null) {
return FORMAT_UNSUPPORTED_DRM;
return C.FORMAT_UNSUPPORTED_DRM;
} else {
return FORMAT_HANDLED;
return C.FORMAT_HANDLED;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ public String getName() {
}

@Override
@FormatSupport
@C.FormatSupport
protected int supportsFormatInternal(Format format) {
boolean drmIsSupported =
format.exoMediaCryptoType == null
|| OpusLibrary.matchesExpectedExoMediaCryptoType(format.exoMediaCryptoType);
if (!OpusLibrary.isAvailable()
|| !MimeTypes.AUDIO_OPUS.equalsIgnoreCase(format.sampleMimeType)) {
return FORMAT_UNSUPPORTED_TYPE;
return C.FORMAT_UNSUPPORTED_TYPE;
} else if (!sinkSupportsFormat(
Util.getPcmFormat(C.ENCODING_PCM_16BIT, format.channelCount, format.sampleRate))) {
return FORMAT_UNSUPPORTED_SUBTYPE;
return C.FORMAT_UNSUPPORTED_SUBTYPE;
} else if (!drmIsSupported) {
return FORMAT_UNSUPPORTED_DRM;
return C.FORMAT_UNSUPPORTED_DRM;
} else {
return FORMAT_HANDLED;
return C.FORMAT_HANDLED;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,16 @@ public String getName() {
@Capabilities
public final int supportsFormat(Format format) {
if (!VpxLibrary.isAvailable() || !MimeTypes.VIDEO_VP9.equalsIgnoreCase(format.sampleMimeType)) {
return RendererCapabilities.create(FORMAT_UNSUPPORTED_TYPE);
return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_TYPE);
}
boolean drmIsSupported =
format.exoMediaCryptoType == null
|| VpxLibrary.matchesExpectedExoMediaCryptoType(format.exoMediaCryptoType);
if (!drmIsSupported) {
return RendererCapabilities.create(FORMAT_UNSUPPORTED_DRM);
return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_DRM);
}
return RendererCapabilities.create(FORMAT_HANDLED, ADAPTIVE_SEAMLESS, TUNNELING_NOT_SUPPORTED);
return RendererCapabilities.create(
C.FORMAT_HANDLED, ADAPTIVE_SEAMLESS, TUNNELING_NOT_SUPPORTED);
}

@Override
Expand Down
82 changes: 80 additions & 2 deletions library/common/src/main/java/com/google/android/exoplayer2/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
Expand Down Expand Up @@ -1100,8 +1101,63 @@ private C() {}
/* package */ static final int REPEAT_MODE_ALL = 2;

/**
* Converts a time in microseconds to the corresponding time in milliseconds, preserving
* {@link #TIME_UNSET} and {@link #TIME_END_OF_SOURCE} values.
* Level of renderer support for a format. One of {@link #FORMAT_HANDLED}, {@link
* #FORMAT_EXCEEDS_CAPABILITIES}, {@link #FORMAT_UNSUPPORTED_DRM}, {@link
* #FORMAT_UNSUPPORTED_SUBTYPE} or {@link #FORMAT_UNSUPPORTED_TYPE}.
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@IntDef({
FORMAT_HANDLED,
FORMAT_EXCEEDS_CAPABILITIES,
FORMAT_UNSUPPORTED_DRM,
FORMAT_UNSUPPORTED_SUBTYPE,
FORMAT_UNSUPPORTED_TYPE
})
public static @interface FormatSupport {}
// TODO(b/172315872) Renderer was a link. Link to equivalent concept or remove @code.
/** The {@code Renderer} is capable of rendering the format. */
public static final int FORMAT_HANDLED = 0b100;
/**
* The {@code Renderer} is capable of rendering formats with the same MIME type, but the
* properties of the format exceed the renderer's capabilities. There is a chance the renderer
* will be able to play the format in practice because some renderers report their capabilities
* conservatively, but the expected outcome is that playback will fail.
*
* <p>Example: The {@code Renderer} is capable of rendering H264 and the format's MIME type is
* {@code MimeTypes#VIDEO_H264}, but the format's resolution exceeds the maximum limit supported
* by the underlying H264 decoder.
*/
public static final int FORMAT_EXCEEDS_CAPABILITIES = 0b011;
/**
* The {@code Renderer} is capable of rendering formats with the same MIME type, but is not
* capable of rendering the format because the format's drm protection is not supported.
*
* <p>Example: The {@code Renderer} is capable of rendering H264 and the format's MIME type is
* {@link MimeTypes#VIDEO_H264}, but the format indicates PlayReady drm protection whereas the
* renderer only supports Widevine.
*/
public static final int FORMAT_UNSUPPORTED_DRM = 0b010;
/**
* The {@code Renderer} is a general purpose renderer for formats of the same top-level type, but
* is not capable of rendering the format or any other format with the same MIME type because the
* sub-type is not supported.
*
* <p>Example: The {@code Renderer} is a general purpose audio renderer and the format's MIME type
* matches audio/[subtype], but there does not exist a suitable decoder for [subtype].
*/
public static final int FORMAT_UNSUPPORTED_SUBTYPE = 0b001;
/**
* The {@code Renderer} is not capable of rendering the format, either because it does not support
* the format's top-level type, or because it's a specialized renderer for a different MIME type.
*
* <p>Example: The {@code Renderer} is a general purpose video renderer, but the format has an
* audio MIME type.
*/
public static final int FORMAT_UNSUPPORTED_TYPE = 0b000;
/**
* Converts a time in microseconds to the corresponding time in milliseconds, preserving {@link
* #TIME_UNSET} and {@link #TIME_END_OF_SOURCE} values.
*
* @param timeUs The time in microseconds.
* @return The corresponding time in milliseconds.
Expand Down Expand Up @@ -1134,4 +1190,26 @@ public static int generateAudioSessionIdV21(Context context) {
return audioManager == null ? AudioManager.ERROR : audioManager.generateAudioSessionId();
}

/**
* Returns string representation of a {@link FormatSupport} flag.
*
* @param formatSupport A {@link FormatSupport} flag.
* @return A string representation of the flag.
*/
public static String getFormatSupportString(@FormatSupport int formatSupport) {
switch (formatSupport) {
case FORMAT_HANDLED:
return "YES";
case FORMAT_EXCEEDS_CAPABILITIES:
return "NO_EXCEEDS_CAPABILITIES";
case FORMAT_UNSUPPORTED_DRM:
return "NO_UNSUPPORTED_DRM";
case FORMAT_UNSUPPORTED_SUBTYPE:
return "NO_UNSUPPORTED_TYPE";
case FORMAT_UNSUPPORTED_TYPE:
return "NO";
default:
throw new IllegalStateException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ protected final ExoPlaybackException createRendererException(
*/
protected final ExoPlaybackException createRendererException(
Exception cause, @Nullable Format format, boolean isRecoverable) {
@FormatSupport int formatSupport = RendererCapabilities.FORMAT_HANDLED;
@C.FormatSupport int formatSupport = C.FORMAT_HANDLED;
if (format != null && !throwRendererExceptionIsExecuting) {
// Prevent recursive re-entry from subclass supportsFormat implementations.
throwRendererExceptionIsExecuting = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import androidx.annotation.CheckResult;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.RendererCapabilities.FormatSupport;
import com.google.android.exoplayer2.C.FormatSupport;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.util.Assertions;
import java.io.IOException;
Expand Down Expand Up @@ -121,7 +121,7 @@ public final class ExoPlaybackException extends Exception {
/**
* If {@link #type} is {@link #TYPE_RENDERER}, this is the level of {@link FormatSupport} of the
* renderer for {@link #rendererFormat}. If {@link #rendererFormat} is null, this is {@link
* RendererCapabilities#FORMAT_HANDLED}.
* C#FORMAT_HANDLED}.
*/
@FormatSupport public final int rendererFormatSupport;

Expand Down Expand Up @@ -214,7 +214,7 @@ public static ExoPlaybackException createForRenderer(
rendererName,
rendererIndex,
rendererFormat,
rendererFormat == null ? RendererCapabilities.FORMAT_HANDLED : rendererFormatSupport,
rendererFormat == null ? C.FORMAT_HANDLED : rendererFormatSupport,
TIMEOUT_OPERATION_UNDEFINED,
isRecoverable);
}
Expand Down Expand Up @@ -265,7 +265,7 @@ public static ExoPlaybackException createForTimeout(
/* rendererName= */ null,
/* rendererIndex= */ C.INDEX_UNSET,
/* rendererFormat= */ null,
/* rendererFormatSupport= */ RendererCapabilities.FORMAT_HANDLED,
/* rendererFormatSupport= */ C.FORMAT_HANDLED,
timeoutOperation,
/* isRecoverable= */ false);
}
Expand All @@ -278,7 +278,7 @@ private ExoPlaybackException(@Type int type, Throwable cause) {
/* rendererName= */ null,
/* rendererIndex= */ C.INDEX_UNSET,
/* rendererFormat= */ null,
/* rendererFormatSupport= */ RendererCapabilities.FORMAT_HANDLED,
/* rendererFormatSupport= */ C.FORMAT_HANDLED,
TIMEOUT_OPERATION_UNDEFINED,
/* isRecoverable= */ false);
}
Expand All @@ -291,7 +291,7 @@ private ExoPlaybackException(@Type int type, String message) {
/* rendererName= */ null,
/* rendererIndex= */ C.INDEX_UNSET,
/* rendererFormat= */ null,
/* rendererFormatSupport= */ RendererCapabilities.FORMAT_HANDLED,
/* rendererFormatSupport= */ C.FORMAT_HANDLED,
/* timeoutOperation= */ TIMEOUT_OPERATION_UNDEFINED,
/* isRecoverable= */ false);
}
Expand Down Expand Up @@ -446,7 +446,7 @@ private static String deriveMessage(
+ ", format="
+ rendererFormat
+ ", format_supported="
+ RendererCapabilities.getFormatSupportString(rendererFormatSupport);
+ C.getFormatSupportString(rendererFormatSupport);
break;
case TYPE_REMOTE:
message = "Remote error";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public boolean isEnded() {
@Override
@Capabilities
public int supportsFormat(Format format) throws ExoPlaybackException {
return RendererCapabilities.create(FORMAT_UNSUPPORTED_TYPE);
return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_TYPE);
}

@Override
Expand Down
Loading

0 comments on commit 5384455

Please sign in to comment.