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
This commit is contained in:
kimvde 2022-10-19 14:31:06 +00:00 committed by Rohit Singh
parent 601eaba7a6
commit cf14d0687d
3 changed files with 26 additions and 23 deletions

View File

@ -19,6 +19,7 @@ import android.os.ParcelFileDescriptor;
import androidx.media3.common.C; import androidx.media3.common.C;
import androidx.media3.common.Format; import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes; import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.UnstableApi;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -26,17 +27,18 @@ import java.nio.ByteBuffer;
/** /**
* Abstracts media muxing operations. * 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 * supported and {@linkplain #addTrack(Format) add all tracks}, then {@linkplain
* #writeSampleData(int, ByteBuffer, boolean, long) write sample data} to mux samples. Once any * #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, * 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 * {@linkplain #release(boolean) release} the instance to finish writing to the output and return
* any resources to the system. * any resources to the system.
*/ */
/* package */ interface Muxer { @UnstableApi
public interface Muxer {
/** Thrown when a muxing failure occurs. */ /** Thrown when a muxing failure occurs. */
/* package */ final class MuxerException extends Exception { final class MuxerException extends Exception {
/** /**
* Creates an instance. * Creates an instance.
* *
@ -91,7 +93,7 @@ import java.nio.ByteBuffer;
* Writes the specified sample. * Writes the specified sample.
* *
* @param trackIndex The index of the track, previously returned by {@link #addTrack(Format)}. * @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 isKeyFrame Whether the sample is a key frame.
* @param presentationTimeUs The presentation time of the sample in microseconds. * @param presentationTimeUs The presentation time of the sample in microseconds.
* @throws MuxerException If the muxer fails to write the sample. * @throws MuxerException If the muxer fails to write the sample.
@ -100,11 +102,13 @@ import java.nio.ByteBuffer;
throws MuxerException; 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 * @param forCancellation Whether the reason for releasing the resources is the transformation
* cancellation. * 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. * forCancellation} is false.
*/ */
void release(boolean forCancellation) throws MuxerException; 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. * <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 * @param forCancellation Whether the reason for releasing the resources is the transformation
* cancellation. * 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. * {@code forCancellation} is false.
*/ */
public void release(boolean forCancellation) throws Muxer.MuxerException { public void release(boolean forCancellation) throws Muxer.MuxerException {

View File

@ -373,6 +373,20 @@ public final class Transformer {
return this; 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 * Sets a provider for views to show diagnostic information (if available) during
* transformation. * transformation.
@ -407,21 +421,6 @@ public final class Transformer {
return this; 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. * Builds a {@link Transformer} instance.
* *