mirror of
https://github.com/androidx/media.git
synced 2025-05-17 20:49:53 +08:00
Implement Muxer
interface in MP4 and Fragmented MP4 muxers
PiperOrigin-RevId: 755945054
This commit is contained in:
parent
38ac6ba711
commit
2e18e5073c
@ -84,7 +84,7 @@ import java.nio.ByteBuffer;
|
||||
* </ul>
|
||||
*/
|
||||
@UnstableApi
|
||||
public final class FragmentedMp4Muxer implements AutoCloseable {
|
||||
public final class FragmentedMp4Muxer implements Muxer {
|
||||
/** The default fragment duration. */
|
||||
public static final long DEFAULT_FRAGMENT_DURATION_MS = 2_000;
|
||||
|
||||
@ -186,14 +186,7 @@ public final class FragmentedMp4Muxer implements AutoCloseable {
|
||||
trackIdToTrack = new SparseArray<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a track of the given media format.
|
||||
*
|
||||
* <p>All tracks must be added before {@linkplain #writeSampleData writing any samples}.
|
||||
*
|
||||
* @param format The {@link Format} of the track.
|
||||
* @return A track id for this track, which should be passed to {@link #writeSampleData}.
|
||||
*/
|
||||
@Override
|
||||
public int addTrack(Format format) {
|
||||
Track track = fragmentedMp4Writer.addTrack(/* sortKey= */ 1, format);
|
||||
trackIdToTrack.append(track.id, track);
|
||||
@ -201,7 +194,7 @@ public final class FragmentedMp4Muxer implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes encoded sample data.
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>Samples are written to the disk in batches. If {@link
|
||||
* Builder#setSampleCopyingEnabled(boolean) sample copying} is disabled, the {@code byteBuffer}
|
||||
@ -217,6 +210,7 @@ public final class FragmentedMp4Muxer implements AutoCloseable {
|
||||
* @param bufferInfo The {@link BufferInfo} related to this sample.
|
||||
* @throws MuxerException If there is any error while writing data to the disk.
|
||||
*/
|
||||
@Override
|
||||
public void writeSampleData(int trackId, ByteBuffer byteBuffer, BufferInfo bufferInfo)
|
||||
throws MuxerException {
|
||||
try {
|
||||
@ -232,7 +226,7 @@ public final class FragmentedMp4Muxer implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds {@linkplain Metadata.Entry metadata} about the output file.
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>List of supported {@linkplain Metadata.Entry metadata entries}:
|
||||
*
|
||||
@ -250,18 +244,12 @@ public final class FragmentedMp4Muxer implements AutoCloseable {
|
||||
* IllegalArgumentException} is thrown if the {@linkplain Metadata.Entry metadata} is not
|
||||
* supported.
|
||||
*/
|
||||
@Override
|
||||
public void addMetadataEntry(Metadata.Entry metadataEntry) {
|
||||
checkArgument(MuxerUtil.isMetadataSupported(metadataEntry), "Unsupported metadata");
|
||||
metadataCollector.addMetadata(metadataEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the file.
|
||||
*
|
||||
* <p>The muxer cannot be used anymore once this method returns.
|
||||
*
|
||||
* @throws MuxerException If the muxer fails to finish writing the output.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws MuxerException {
|
||||
try {
|
||||
|
@ -109,7 +109,7 @@ import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
|
||||
* </ul>
|
||||
*/
|
||||
@UnstableApi
|
||||
public final class Mp4Muxer implements AutoCloseable {
|
||||
public final class Mp4Muxer implements Muxer {
|
||||
/** Parameters for {@link #FILE_FORMAT_MP4_WITH_AUXILIARY_TRACKS_EXTENSION}. */
|
||||
public static final class Mp4AtFileParameters {
|
||||
/** Provides temporary cache files to be used by the muxer. */
|
||||
@ -426,7 +426,7 @@ public final class Mp4Muxer implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a track of the given media format.
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>Tracks can be added at any point before the muxer is closed, even after writing samples to
|
||||
* other tracks.
|
||||
@ -438,6 +438,7 @@ public final class Mp4Muxer implements AutoCloseable {
|
||||
* #writeSampleData}.
|
||||
* @throws MuxerException If an error occurs while adding track.
|
||||
*/
|
||||
@Override
|
||||
public int addTrack(Format format) throws MuxerException {
|
||||
return addTrack(/* sortKey= */ 1, format);
|
||||
}
|
||||
@ -483,7 +484,7 @@ public final class Mp4Muxer implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes encoded sample data.
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @param trackId The track id for which this sample is being written.
|
||||
* @param byteBuffer The encoded sample. The muxer takes ownership of the buffer if {@link
|
||||
@ -492,6 +493,7 @@ public final class Mp4Muxer implements AutoCloseable {
|
||||
* @param bufferInfo The {@link BufferInfo} related to this sample.
|
||||
* @throws MuxerException If an error occurs while writing data to the output file.
|
||||
*/
|
||||
@Override
|
||||
public void writeSampleData(int trackId, ByteBuffer byteBuffer, BufferInfo bufferInfo)
|
||||
throws MuxerException {
|
||||
Track track = trackIdToTrack.get(trackId);
|
||||
@ -512,7 +514,7 @@ public final class Mp4Muxer implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds {@linkplain Metadata.Entry metadata} about the output file.
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>List of supported {@linkplain Metadata.Entry metadata entries}:
|
||||
*
|
||||
@ -530,18 +532,12 @@ public final class Mp4Muxer implements AutoCloseable {
|
||||
* IllegalArgumentException} is thrown if the {@linkplain Metadata.Entry metadata} is not
|
||||
* supported.
|
||||
*/
|
||||
@Override
|
||||
public void addMetadataEntry(Metadata.Entry metadataEntry) {
|
||||
checkArgument(isMetadataSupported(metadataEntry), "Unsupported metadata");
|
||||
metadataCollector.addMetadata(metadataEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the file.
|
||||
*
|
||||
* <p>The muxer cannot be used anymore once this method returns.
|
||||
*
|
||||
* @throws MuxerException If the muxer fails to finish writing the output.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws MuxerException {
|
||||
@Nullable MuxerException exception = null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user