Remove forCancellation flag from Transformer/Muxer.release() method
PiperOrigin-RevId: 630337930
This commit is contained in:
parent
10e29be8b6
commit
24305c043e
@ -469,8 +469,8 @@ public class TransformerPauseResumeTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(boolean forCancellation) throws MuxerException {
|
||||
wrappedMuxer.release(forCancellation);
|
||||
public void release() throws MuxerException {
|
||||
wrappedMuxer.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public final class DefaultMuxer implements Muxer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(boolean forCancellation) throws MuxerException {
|
||||
muxer.release(forCancellation);
|
||||
public void release() throws MuxerException {
|
||||
muxer.release();
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ import java.util.Map;
|
||||
|
||||
/** {@link Muxer} implementation that uses a {@link MediaMuxer}. */
|
||||
/* package */ final class FrameworkMuxer implements Muxer {
|
||||
public static final String MUXER_STOPPING_FAILED_ERROR_MESSAGE = "Failed to stop the MediaMuxer";
|
||||
|
||||
// MediaMuxer supported sample formats are documented in MediaMuxer.addTrack(MediaFormat).
|
||||
private static final ImmutableList<String> SUPPORTED_VIDEO_SAMPLE_MIME_TYPES =
|
||||
getSupportedVideoSampleMimeTypes();
|
||||
@ -193,7 +195,7 @@ import java.util.Map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(boolean forCancellation) throws MuxerException {
|
||||
public void release() throws MuxerException {
|
||||
if (isReleased) {
|
||||
return;
|
||||
}
|
||||
@ -218,10 +220,7 @@ import java.util.Map;
|
||||
try {
|
||||
stopMuxer(mediaMuxer);
|
||||
} catch (RuntimeException e) {
|
||||
// It doesn't matter that stopping the muxer throws if the export is being cancelled.
|
||||
if (!forCancellation) {
|
||||
throw new MuxerException("Failed to stop the muxer", e);
|
||||
}
|
||||
throw new MuxerException(MUXER_STOPPING_FAILED_ERROR_MESSAGE, e);
|
||||
} finally {
|
||||
mediaMuxer.release();
|
||||
isReleased = true;
|
||||
|
@ -202,7 +202,7 @@ public final class InAppMuxer implements Muxer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(boolean forCancellation) throws MuxerException {
|
||||
public void release() throws MuxerException {
|
||||
writeMetadata();
|
||||
|
||||
try {
|
||||
|
@ -31,8 +31,8 @@ import java.nio.ByteBuffer;
|
||||
* <p>Query whether {@linkplain Factory#getSupportedSampleMimeTypes(int) sample MIME types} are
|
||||
* supported and {@linkplain #addTrack(Format) add all tracks}, then {@linkplain #writeSampleData
|
||||
* write sample data} to mux samples. Once any sample data has been written, it is not possible to
|
||||
* add tracks. After writing all sample data, {@linkplain #release(boolean) release} the instance to
|
||||
* finish writing to the output and return any resources to the system.
|
||||
* add tracks. After writing all sample data, {@linkplain #release() release} the instance to finish
|
||||
* writing to the output and return any resources to the system.
|
||||
*/
|
||||
@UnstableApi
|
||||
// TODO: b/330695864 - Replace with the Muxer interface from the Muxer module.
|
||||
@ -99,10 +99,8 @@ public interface Muxer {
|
||||
*
|
||||
* <p>The muxer cannot be used anymore once this method has been called.
|
||||
*
|
||||
* @param forCancellation Whether the reason for releasing the resources is the export
|
||||
* cancellation.
|
||||
* @throws MuxerException If the muxer fails to finish writing the output and {@code
|
||||
* forCancellation} is false.
|
||||
*/
|
||||
void release(boolean forCancellation) throws MuxerException;
|
||||
void release() throws MuxerException;
|
||||
}
|
||||
|
@ -655,7 +655,18 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
isReady = false;
|
||||
abortScheduledExecutorService.shutdownNow();
|
||||
if (muxer != null) {
|
||||
muxer.release(releaseReason == MUXER_RELEASE_REASON_CANCELLED);
|
||||
try {
|
||||
muxer.release();
|
||||
} catch (Muxer.MuxerException e) {
|
||||
if (releaseReason == MUXER_RELEASE_REASON_CANCELLED
|
||||
&& checkNotNull(e.getMessage())
|
||||
.equals(FrameworkMuxer.MUXER_STOPPING_FAILED_ERROR_MESSAGE)) {
|
||||
// When releasing the muxer, FrameworkMuxer may sometimes fail before the actual release.
|
||||
// When the release is due to cancellation, swallow this exception.
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,9 +142,9 @@ public final class CapturingMuxer implements Muxer, Dumpable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(boolean forCancellation) throws MuxerException {
|
||||
public void release() throws MuxerException {
|
||||
released = true;
|
||||
wrappedMuxer.release(forCancellation);
|
||||
wrappedMuxer.release();
|
||||
}
|
||||
|
||||
// Dumper.Dumpable implementation.
|
||||
|
Loading…
x
Reference in New Issue
Block a user