mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Improve error logging for IllegalClippingException
Added start and end time details to the error message for `REASON_START_EXCEEDS_END`, helping to debug cases where the start time exceeds the end time. PiperOrigin-RevId: 688117440
This commit is contained in:
parent
847c1252e2
commit
0ecd35e24c
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package androidx.media3.exoplayer.source;
|
package androidx.media3.exoplayer.source;
|
||||||
|
|
||||||
|
import static androidx.media3.common.util.Assertions.checkState;
|
||||||
import static java.lang.Math.max;
|
import static java.lang.Math.max;
|
||||||
import static java.lang.Math.min;
|
import static java.lang.Math.min;
|
||||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||||
@ -71,18 +72,23 @@ public final class ClippingMediaSource extends WrappingMediaSource {
|
|||||||
* @param reason The reason clipping failed.
|
* @param reason The reason clipping failed.
|
||||||
*/
|
*/
|
||||||
public IllegalClippingException(@Reason int reason) {
|
public IllegalClippingException(@Reason int reason) {
|
||||||
super("Illegal clipping: " + getReasonDescription(reason));
|
this(reason, /* startUs= */ C.TIME_UNSET, /* endUs= */ C.TIME_UNSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IllegalClippingException(@Reason int reason, long startUs, long endUs) {
|
||||||
|
super("Illegal clipping: " + getReasonDescription(reason, startUs, endUs));
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getReasonDescription(@Reason int reason) {
|
private static String getReasonDescription(@Reason int reason, long startUs, long endUs) {
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case REASON_INVALID_PERIOD_COUNT:
|
case REASON_INVALID_PERIOD_COUNT:
|
||||||
return "invalid period count";
|
return "invalid period count";
|
||||||
case REASON_NOT_SEEKABLE_TO_START:
|
case REASON_NOT_SEEKABLE_TO_START:
|
||||||
return "not seekable to start";
|
return "not seekable to start";
|
||||||
case REASON_START_EXCEEDS_END:
|
case REASON_START_EXCEEDS_END:
|
||||||
return "start exceeds end";
|
checkState(startUs != C.TIME_UNSET && endUs != C.TIME_UNSET);
|
||||||
|
return "start exceeds end. Start time: " + startUs + ", End time: " + endUs;
|
||||||
default:
|
default:
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
@ -223,7 +229,7 @@ public final class ClippingMediaSource extends WrappingMediaSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releasePeriod(MediaPeriod mediaPeriod) {
|
public void releasePeriod(MediaPeriod mediaPeriod) {
|
||||||
Assertions.checkState(mediaPeriods.remove(mediaPeriod));
|
checkState(mediaPeriods.remove(mediaPeriod));
|
||||||
mediaSource.releasePeriod(((ClippingMediaPeriod) mediaPeriod).mediaPeriod);
|
mediaSource.releasePeriod(((ClippingMediaPeriod) mediaPeriod).mediaPeriod);
|
||||||
if (mediaPeriods.isEmpty() && !allowDynamicClippingUpdates) {
|
if (mediaPeriods.isEmpty() && !allowDynamicClippingUpdates) {
|
||||||
refreshClippedTimeline(Assertions.checkNotNull(clippingTimeline).timeline);
|
refreshClippedTimeline(Assertions.checkNotNull(clippingTimeline).timeline);
|
||||||
@ -323,7 +329,10 @@ public final class ClippingMediaSource extends WrappingMediaSource {
|
|||||||
resolvedEndUs = window.durationUs;
|
resolvedEndUs = window.durationUs;
|
||||||
}
|
}
|
||||||
if (startUs > resolvedEndUs) {
|
if (startUs > resolvedEndUs) {
|
||||||
throw new IllegalClippingException(IllegalClippingException.REASON_START_EXCEEDS_END);
|
throw new IllegalClippingException(
|
||||||
|
IllegalClippingException.REASON_START_EXCEEDS_END,
|
||||||
|
startUs,
|
||||||
|
/* endUs= */ resolvedEndUs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.startUs = startUs;
|
this.startUs = startUs;
|
||||||
|
@ -125,6 +125,28 @@ public final class ClippingMediaSourceTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void clippingStartExceedsEndThrows() throws IOException {
|
||||||
|
Timeline timeline =
|
||||||
|
new SinglePeriodTimeline(
|
||||||
|
TEST_PERIOD_DURATION_US,
|
||||||
|
/* isSeekable= */ true,
|
||||||
|
/* isDynamic= */ false,
|
||||||
|
/* useLiveConfiguration= */ false,
|
||||||
|
/* manifest= */ null,
|
||||||
|
MediaItem.fromUri(Uri.EMPTY));
|
||||||
|
long endUs = TEST_PERIOD_DURATION_US / 2;
|
||||||
|
long startUs = endUs + 1; // Start slightly after endUs
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Trying to clip with start time exceeding end time should throw an exception.
|
||||||
|
getClippedTimeline(timeline, startUs, endUs);
|
||||||
|
fail("Expected clipping to fail.");
|
||||||
|
} catch (IllegalClippingException e) {
|
||||||
|
assertThat(e.reason).isEqualTo(IllegalClippingException.REASON_START_EXCEEDS_END);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clippingStart() throws IOException {
|
public void clippingStart() throws IOException {
|
||||||
Timeline timeline =
|
Timeline timeline =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user