Make Muxer public

The reason for making the Muxer public is that we want to add an option
to disable or configure the timer that will throw when the muxer doesn't
receive any data for a given period of time.

PiperOrigin-RevId: 482199360
(cherry picked from commit d213b93958fce7e2a25851ec44b7c1938fcf0d7d)
This commit is contained in:
kimvde 2022-10-19 14:31:06 +00:00 committed by microkatz
parent 5c0175e4e3
commit f42d18f213
3 changed files with 24 additions and 23 deletions

View File

@ -26,17 +26,17 @@ import java.nio.ByteBuffer;
/**
* Abstracts media muxing operations.
*
* <p>Query whether {@linkplain Factory#getSupportedSampleMimeTypes(int)} sample MIME types} are
* <p>Query whether {@linkplain Factory#getSupportedSampleMimeTypes(int) sample MIME types} are
* supported and {@linkplain #addTrack(Format) add all tracks}, then {@linkplain
* #writeSampleData(int, ByteBuffer, boolean, long) 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.
*/
/* package */ interface Muxer {
public interface Muxer {
/** Thrown when a muxing failure occurs. */
/* package */ final class MuxerException extends Exception {
final class MuxerException extends Exception {
/**
* Creates an instance.
*
@ -91,7 +91,7 @@ import java.nio.ByteBuffer;
* Writes the specified sample.
*
* @param trackIndex The index of the track, previously returned by {@link #addTrack(Format)}.
* @param data Buffer containing the sample data to write to the container.
* @param data A buffer containing the sample data to write to the container.
* @param isKeyFrame Whether the sample is a key frame.
* @param presentationTimeUs The presentation time of the sample in microseconds.
* @throws MuxerException If the muxer fails to write the sample.
@ -100,11 +100,13 @@ import java.nio.ByteBuffer;
throws MuxerException;
/**
* Releases any resources associated with muxing.
* Finishes writing the output and releases any resources associated with muxing.
*
* <p>The muxer cannot be used anymore once this method has been called.
*
* @param forCancellation Whether the reason for releasing the resources is the transformation
* cancellation.
* @throws MuxerException If the muxer fails to stop or release resources and {@code
* @throws MuxerException If the muxer fails to finish writing the output and {@code
* forCancellation} is false.
*/
void release(boolean forCancellation) throws MuxerException;

View File

@ -184,13 +184,13 @@ import java.nio.ByteBuffer;
}
/**
* Releases any resources associated with muxing.
* Finishes writing the output and releases any resources associated with muxing.
*
* <p>The muxer cannot be used anymore once this method has been called.
*
* @param forCancellation Whether the reason for releasing the resources is the transformation
* cancellation.
* @throws Muxer.MuxerException If the underlying muxer fails to stop and to release resources and
* @throws Muxer.MuxerException If the underlying muxer fails to finish writing the output and
* {@code forCancellation} is false.
*/
public void release(boolean forCancellation) throws Muxer.MuxerException {

View File

@ -371,6 +371,20 @@ public final class Transformer {
return this;
}
/**
* Sets the factory for muxers that write the media container.
*
* <p>The default value is a {@link DefaultMuxer.Factory}.
*
* @param muxerFactory A {@link Muxer.Factory}.
* @return This builder.
*/
@CanIgnoreReturnValue
public Builder setMuxerFactory(Muxer.Factory muxerFactory) {
this.muxerFactory = muxerFactory;
return this;
}
/**
* Sets a provider for views to show diagnostic information (if available) during
* transformation.
@ -405,21 +419,6 @@ public final class Transformer {
return this;
}
/**
* Sets the factory for muxers that write the media container.
*
* <p>The default value is a {@link DefaultMuxer.Factory}.
*
* @param muxerFactory A {@link Muxer.Factory}.
* @return This builder.
*/
@CanIgnoreReturnValue
@VisibleForTesting
/* package */ Builder setMuxerFactory(Muxer.Factory muxerFactory) {
this.muxerFactory = muxerFactory;
return this;
}
/**
* Builds a {@link Transformer} instance.
*