mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Supply MediaPeriodId in ExoPlaybackExceptions thrown from Renderers
PiperOrigin-RevId: 728177353
This commit is contained in:
parent
2b8700beaa
commit
75ac9cd191
@ -84,6 +84,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
|||||||
private boolean streamIsFinal;
|
private boolean streamIsFinal;
|
||||||
private boolean throwRendererExceptionIsExecuting;
|
private boolean throwRendererExceptionIsExecuting;
|
||||||
private Timeline timeline;
|
private Timeline timeline;
|
||||||
|
@Nullable private MediaSource.MediaPeriodId mediaPeriodId;
|
||||||
|
|
||||||
@GuardedBy("lock")
|
@GuardedBy("lock")
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -144,6 +145,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
|||||||
throws ExoPlaybackException {
|
throws ExoPlaybackException {
|
||||||
Assertions.checkState(state == STATE_DISABLED);
|
Assertions.checkState(state == STATE_DISABLED);
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
|
this.mediaPeriodId = mediaPeriodId;
|
||||||
state = STATE_ENABLED;
|
state = STATE_ENABLED;
|
||||||
onEnabled(joining, mayRenderStartOfStream);
|
onEnabled(joining, mayRenderStartOfStream);
|
||||||
replaceStream(formats, stream, startPositionUs, offsetUs, mediaPeriodId);
|
replaceStream(formats, stream, startPositionUs, offsetUs, mediaPeriodId);
|
||||||
@ -167,6 +169,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
|||||||
throws ExoPlaybackException {
|
throws ExoPlaybackException {
|
||||||
Assertions.checkState(!streamIsFinal);
|
Assertions.checkState(!streamIsFinal);
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
|
this.mediaPeriodId = mediaPeriodId;
|
||||||
if (readingPositionUs == C.TIME_END_OF_SOURCE) {
|
if (readingPositionUs == C.TIME_END_OF_SOURCE) {
|
||||||
readingPositionUs = startPositionUs;
|
readingPositionUs = startPositionUs;
|
||||||
}
|
}
|
||||||
@ -242,6 +245,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
|||||||
streamFormats = null;
|
streamFormats = null;
|
||||||
streamIsFinal = false;
|
streamIsFinal = false;
|
||||||
onDisabled();
|
onDisabled();
|
||||||
|
mediaPeriodId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -485,6 +489,15 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
|||||||
return timeline;
|
return timeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link MediaSource.MediaPeriodId} of the {@link MediaPeriod} producing the {@code stream},
|
||||||
|
* or {@code null} if the renderer is disabled.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
protected final MediaSource.MediaPeriodId getMediaPeriodId() {
|
||||||
|
return mediaPeriodId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an {@link ExoPlaybackException} of type {@link ExoPlaybackException#TYPE_RENDERER} for
|
* Creates an {@link ExoPlaybackException} of type {@link ExoPlaybackException#TYPE_RENDERER} for
|
||||||
* this renderer.
|
* this renderer.
|
||||||
@ -530,7 +543,14 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ExoPlaybackException.createForRenderer(
|
return ExoPlaybackException.createForRenderer(
|
||||||
cause, getName(), getIndex(), format, formatSupport, isRecoverable, errorCode);
|
cause,
|
||||||
|
getName(),
|
||||||
|
getIndex(),
|
||||||
|
format,
|
||||||
|
formatSupport,
|
||||||
|
mediaPeriodId,
|
||||||
|
isRecoverable,
|
||||||
|
errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,6 +131,31 @@ public final class ExoPlaybackException extends PlaybackException {
|
|||||||
return new ExoPlaybackException(TYPE_SOURCE, cause, errorCode);
|
return new ExoPlaybackException(TYPE_SOURCE, cause, errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #createForRenderer(Throwable, String, int, Format, int, MediaPeriodId,
|
||||||
|
* boolean, int)} instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
@UnstableApi
|
||||||
|
public static ExoPlaybackException createForRenderer(
|
||||||
|
Throwable cause,
|
||||||
|
String rendererName,
|
||||||
|
int rendererIndex,
|
||||||
|
@Nullable Format rendererFormat,
|
||||||
|
@FormatSupport int rendererFormatSupport,
|
||||||
|
boolean isRecoverable,
|
||||||
|
@ErrorCode int errorCode) {
|
||||||
|
return createForRenderer(
|
||||||
|
cause,
|
||||||
|
rendererName,
|
||||||
|
rendererIndex,
|
||||||
|
rendererFormat,
|
||||||
|
rendererFormatSupport,
|
||||||
|
/* mediaPeriodId= */ null,
|
||||||
|
isRecoverable,
|
||||||
|
errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of type {@link #TYPE_RENDERER}.
|
* Creates an instance of type {@link #TYPE_RENDERER}.
|
||||||
*
|
*
|
||||||
@ -142,6 +167,8 @@ public final class ExoPlaybackException extends PlaybackException {
|
|||||||
* or null if the renderer wasn't using a {@link Format}.
|
* or null if the renderer wasn't using a {@link Format}.
|
||||||
* @param rendererFormatSupport The {@link FormatSupport} of the renderer for {@code
|
* @param rendererFormatSupport The {@link FormatSupport} of the renderer for {@code
|
||||||
* rendererFormat}. Ignored if {@code rendererFormat} is null.
|
* rendererFormat}. Ignored if {@code rendererFormat} is null.
|
||||||
|
* @param mediaPeriodId The {@link MediaPeriodId mediaPeriodId} of the media associated with this
|
||||||
|
* error, or null if undetermined.
|
||||||
* @param isRecoverable If the failure can be recovered by disabling and re-enabling the renderer.
|
* @param isRecoverable If the failure can be recovered by disabling and re-enabling the renderer.
|
||||||
* @param errorCode See {@link #errorCode}.
|
* @param errorCode See {@link #errorCode}.
|
||||||
* @return The created instance.
|
* @return The created instance.
|
||||||
@ -153,9 +180,9 @@ public final class ExoPlaybackException extends PlaybackException {
|
|||||||
int rendererIndex,
|
int rendererIndex,
|
||||||
@Nullable Format rendererFormat,
|
@Nullable Format rendererFormat,
|
||||||
@FormatSupport int rendererFormatSupport,
|
@FormatSupport int rendererFormatSupport,
|
||||||
|
@Nullable MediaPeriodId mediaPeriodId,
|
||||||
boolean isRecoverable,
|
boolean isRecoverable,
|
||||||
@ErrorCode int errorCode) {
|
@ErrorCode int errorCode) {
|
||||||
|
|
||||||
return new ExoPlaybackException(
|
return new ExoPlaybackException(
|
||||||
TYPE_RENDERER,
|
TYPE_RENDERER,
|
||||||
cause,
|
cause,
|
||||||
@ -165,6 +192,7 @@ public final class ExoPlaybackException extends PlaybackException {
|
|||||||
rendererIndex,
|
rendererIndex,
|
||||||
rendererFormat,
|
rendererFormat,
|
||||||
rendererFormat == null ? C.FORMAT_HANDLED : rendererFormatSupport,
|
rendererFormat == null ? C.FORMAT_HANDLED : rendererFormatSupport,
|
||||||
|
mediaPeriodId,
|
||||||
isRecoverable);
|
isRecoverable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,6 +236,7 @@ public final class ExoPlaybackException extends PlaybackException {
|
|||||||
/* rendererIndex= */ C.INDEX_UNSET,
|
/* rendererIndex= */ C.INDEX_UNSET,
|
||||||
/* rendererFormat= */ null,
|
/* rendererFormat= */ null,
|
||||||
/* rendererFormatSupport= */ C.FORMAT_HANDLED,
|
/* rendererFormatSupport= */ C.FORMAT_HANDLED,
|
||||||
|
/* mediaPeriodId= */ null,
|
||||||
/* isRecoverable= */ false);
|
/* isRecoverable= */ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,6 +250,7 @@ public final class ExoPlaybackException extends PlaybackException {
|
|||||||
/* rendererIndex= */ C.INDEX_UNSET,
|
/* rendererIndex= */ C.INDEX_UNSET,
|
||||||
/* rendererFormat= */ null,
|
/* rendererFormat= */ null,
|
||||||
/* rendererFormatSupport= */ C.FORMAT_HANDLED,
|
/* rendererFormatSupport= */ C.FORMAT_HANDLED,
|
||||||
|
/* mediaPeriodId= */ null,
|
||||||
/* isRecoverable= */ false);
|
/* isRecoverable= */ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,6 +263,7 @@ public final class ExoPlaybackException extends PlaybackException {
|
|||||||
int rendererIndex,
|
int rendererIndex,
|
||||||
@Nullable Format rendererFormat,
|
@Nullable Format rendererFormat,
|
||||||
@FormatSupport int rendererFormatSupport,
|
@FormatSupport int rendererFormatSupport,
|
||||||
|
@Nullable MediaPeriodId mediaPeriodId,
|
||||||
boolean isRecoverable) {
|
boolean isRecoverable) {
|
||||||
this(
|
this(
|
||||||
deriveMessage(
|
deriveMessage(
|
||||||
@ -249,7 +280,7 @@ public final class ExoPlaybackException extends PlaybackException {
|
|||||||
rendererIndex,
|
rendererIndex,
|
||||||
rendererFormat,
|
rendererFormat,
|
||||||
rendererFormatSupport,
|
rendererFormatSupport,
|
||||||
/* mediaPeriodId= */ null,
|
mediaPeriodId,
|
||||||
/* timestampMs= */ SystemClock.elapsedRealtime(),
|
/* timestampMs= */ SystemClock.elapsedRealtime(),
|
||||||
isRecoverable);
|
isRecoverable);
|
||||||
}
|
}
|
||||||
|
@ -693,7 +693,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
} catch (ExoPlaybackException e) {
|
} catch (ExoPlaybackException e) {
|
||||||
if (e.type == ExoPlaybackException.TYPE_RENDERER) {
|
if (e.type == ExoPlaybackException.TYPE_RENDERER) {
|
||||||
@Nullable MediaPeriodHolder readingPeriod = queue.getReadingPeriod();
|
@Nullable MediaPeriodHolder readingPeriod = queue.getReadingPeriod();
|
||||||
if (readingPeriod != null) {
|
if (readingPeriod != null && e.mediaPeriodId == null) {
|
||||||
// We can assume that all renderer errors happen in the context of the reading period. See
|
// We can assume that all renderer errors happen in the context of the reading period. See
|
||||||
// [internal: b/150584930#comment4] for exceptions that aren't covered by this assumption.
|
// [internal: b/150584930#comment4] for exceptions that aren't covered by this assumption.
|
||||||
e =
|
e =
|
||||||
|
@ -312,6 +312,7 @@ public class MediaCodecAudioRendererTest {
|
|||||||
/* rendererIndex= */ 0,
|
/* rendererIndex= */ 0,
|
||||||
format,
|
format,
|
||||||
C.FORMAT_HANDLED,
|
C.FORMAT_HANDLED,
|
||||||
|
/* mediaPeriodId= */ null,
|
||||||
/* isRecoverable= */ false,
|
/* isRecoverable= */ false,
|
||||||
PlaybackException.ERROR_CODE_UNSPECIFIED));
|
PlaybackException.ERROR_CODE_UNSPECIFIED));
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,7 @@ public class FakeRenderer extends BaseRenderer {
|
|||||||
getIndex(),
|
getIndex(),
|
||||||
format,
|
format,
|
||||||
C.FORMAT_UNSUPPORTED_TYPE,
|
C.FORMAT_UNSUPPORTED_TYPE,
|
||||||
|
getMediaPeriodId(),
|
||||||
/* isRecoverable= */ false,
|
/* isRecoverable= */ false,
|
||||||
PlaybackException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED);
|
PlaybackException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user