Change Mp4Writer to an interface
The Mp4Writer does not have any default implementation, hence it can be an interface rather than an abstract class. PiperOrigin-RevId: 611110415
This commit is contained in:
parent
08993b6fb1
commit
6809c0a642
@ -30,16 +30,24 @@ import com.google.common.collect.Range;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* The default implementation of {@link Mp4Writer} which writes all the samples in a single mdat
|
||||
* box.
|
||||
*/
|
||||
/* package */ final class DefaultMp4Writer extends Mp4Writer {
|
||||
/* package */ final class DefaultMp4Writer implements Mp4Writer {
|
||||
private static final long INTERLEAVE_DURATION_US = 1_000_000L;
|
||||
|
||||
private final FileOutputStream outputStream;
|
||||
private final FileChannel output;
|
||||
private final Mp4MoovStructure moovGenerator;
|
||||
private final AnnexBToAvccConverter annexBToAvccConverter;
|
||||
private final List<Track> tracks;
|
||||
private final AtomicBoolean hasWrittenSamples;
|
||||
|
||||
private long mdatStart;
|
||||
@ -62,7 +70,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
FileOutputStream outputStream,
|
||||
Mp4MoovStructure moovGenerator,
|
||||
AnnexBToAvccConverter annexBToAvccConverter) {
|
||||
super(outputStream, moovGenerator, annexBToAvccConverter);
|
||||
this.outputStream = outputStream;
|
||||
this.output = outputStream.getChannel();
|
||||
this.moovGenerator = moovGenerator;
|
||||
this.annexBToAvccConverter = annexBToAvccConverter;
|
||||
tracks = new ArrayList<>();
|
||||
hasWrittenSamples = new AtomicBoolean(false);
|
||||
lastMoovWritten = Range.closed(0L, 0L);
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import com.google.common.collect.ImmutableList;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
@ -43,7 +44,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
* An {@link Mp4Writer} implementation which writes samples into multiple fragments as per the
|
||||
* fragmented MP4 (ISO/IEC 14496-12) standard.
|
||||
*/
|
||||
/* package */ final class FragmentedMp4Writer extends Mp4Writer {
|
||||
/* package */ final class FragmentedMp4Writer implements Mp4Writer {
|
||||
/** Provides a limited set of sample metadata. */
|
||||
public static class SampleMetadata {
|
||||
public final long durationVu;
|
||||
@ -57,6 +58,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
}
|
||||
}
|
||||
|
||||
private final FileOutputStream outputStream;
|
||||
private final FileChannel output;
|
||||
private final Mp4MoovStructure moovGenerator;
|
||||
private final AnnexBToAvccConverter annexBToAvccConverter;
|
||||
private final List<Track> tracks;
|
||||
private final int fragmentDurationUs;
|
||||
|
||||
private @MonotonicNonNull Track videoTrack;
|
||||
@ -70,7 +76,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
Mp4MoovStructure moovGenerator,
|
||||
AnnexBToAvccConverter annexBToAvccConverter,
|
||||
int fragmentDurationUs) {
|
||||
super(outputStream, moovGenerator, annexBToAvccConverter);
|
||||
this.outputStream = outputStream;
|
||||
this.output = outputStream.getChannel();
|
||||
this.moovGenerator = moovGenerator;
|
||||
this.annexBToAvccConverter = annexBToAvccConverter;
|
||||
tracks = new ArrayList<>();
|
||||
this.fragmentDurationUs = fragmentDurationUs;
|
||||
minInputPresentationTimeUs = Long.MAX_VALUE;
|
||||
currentFragmentSequenceNumber = 1;
|
||||
|
@ -24,52 +24,24 @@ import androidx.media3.common.Format;
|
||||
import androidx.media3.common.MimeTypes;
|
||||
import androidx.media3.muxer.Mp4Muxer.TrackToken;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
|
||||
/** Writes MP4 data to the disk. */
|
||||
/* package */ abstract class Mp4Writer {
|
||||
protected final FileOutputStream outputStream;
|
||||
protected final FileChannel output;
|
||||
protected final Mp4MoovStructure moovGenerator;
|
||||
protected final AnnexBToAvccConverter annexBToAvccConverter;
|
||||
protected final List<Track> tracks;
|
||||
/* package */ interface Mp4Writer {
|
||||
|
||||
/**
|
||||
* Creates an instance.
|
||||
*
|
||||
* @param outputStream The {@link FileOutputStream} to write the data to.
|
||||
* @param moovGenerator An {@link Mp4MoovStructure} instance to generate the moov box.
|
||||
* @param annexBToAvccConverter The {@link AnnexBToAvccConverter} to be used to convert H.264 and
|
||||
* H.265 NAL units from the Annex-B format (using start codes to delineate NAL units) to the
|
||||
* AVCC format (which uses length prefixes).
|
||||
*/
|
||||
public Mp4Writer(
|
||||
FileOutputStream outputStream,
|
||||
Mp4MoovStructure moovGenerator,
|
||||
AnnexBToAvccConverter annexBToAvccConverter) {
|
||||
this.outputStream = outputStream;
|
||||
this.output = outputStream.getChannel();
|
||||
this.moovGenerator = moovGenerator;
|
||||
this.annexBToAvccConverter = annexBToAvccConverter;
|
||||
tracks = new ArrayList<>();
|
||||
}
|
||||
TrackToken addTrack(int sortKey, Format format);
|
||||
|
||||
public abstract TrackToken addTrack(int sortKey, Format format);
|
||||
void writeSampleData(Mp4Muxer.TrackToken token, ByteBuffer byteBuffer, BufferInfo bufferInfo)
|
||||
throws IOException;
|
||||
|
||||
public abstract void writeSampleData(
|
||||
Mp4Muxer.TrackToken token, ByteBuffer byteBuffer, BufferInfo bufferInfo) throws IOException;
|
||||
void close() throws IOException;
|
||||
|
||||
public abstract void close() throws IOException;
|
||||
|
||||
protected static class Track
|
||||
implements Mp4Muxer.TrackToken, Mp4MoovStructure.TrackMetadataProvider {
|
||||
class Track implements Mp4Muxer.TrackToken, Mp4MoovStructure.TrackMetadataProvider {
|
||||
public final Format format;
|
||||
public final int sortKey;
|
||||
public final List<BufferInfo> writtenSamples;
|
||||
|
Loading…
x
Reference in New Issue
Block a user