Create a common constant for large box size header

PiperOrigin-RevId: 661323230
This commit is contained in:
sheenachhabra 2024-08-09 10:45:39 -07:00 committed by Copybara-Service
parent 0411e1937b
commit 117ac2e3f4
3 changed files with 10 additions and 8 deletions

View File

@ -56,7 +56,10 @@ import java.util.List;
private static final int BYTES_PER_INTEGER = 4;
// Box size (4 bytes) + Box name (4 bytes)
public static final int BOX_HEADER_SIZE = 2 * BYTES_PER_INTEGER;
public static final int BOX_HEADER_SIZE = 8;
// Box size = 1 to indicate 64-bit box size (4 bytes) + Box name (4 bytes) + actual size (8 bytes)
public static final int LARGE_SIZE_BOX_HEADER_SIZE = 16;
public static final int MFHD_BOX_CONTENT_SIZE = 2 * BYTES_PER_INTEGER;

View File

@ -24,6 +24,7 @@ import static androidx.media3.container.Mp4Util.EDITABLE_TRACK_TYPE_DEPTH_INVERS
import static androidx.media3.container.Mp4Util.EDITABLE_TRACK_TYPE_DEPTH_LINEAR;
import static androidx.media3.container.Mp4Util.EDITABLE_TRACK_TYPE_DEPTH_METADATA;
import static androidx.media3.container.Mp4Util.EDITABLE_TRACK_TYPE_SHARP;
import static androidx.media3.muxer.Boxes.LARGE_SIZE_BOX_HEADER_SIZE;
import static java.lang.annotation.ElementType.TYPE_USE;
import android.media.MediaCodec.BufferInfo;
@ -278,9 +279,6 @@ public final class Mp4Muxer implements Muxer {
private static final String TAG = "Mp4Muxer";
// 4 bytes (indicating a 64-bit length field) + 4 byte (box type) + 8 bytes (actual length)
private static final int EDVD_BOX_HEADER_SIZE_BYTE = 16;
private final FileOutputStream outputStream;
private final FileChannel outputChannel;
private final @LastFrameDurationBehavior int lastFrameDurationBehavior;
@ -553,7 +551,7 @@ public final class Mp4Muxer implements Muxer {
MdtaMetadataEntry.TYPE_INDICATOR_UNSIGNED_INT64);
if (editableVideoMp4Writer != null) {
long editableVideoDataSize = checkNotNull(cacheFileOutputStream).getChannel().size();
long edvdBoxSize = EDVD_BOX_HEADER_SIZE_BYTE + editableVideoDataSize;
long edvdBoxSize = LARGE_SIZE_BOX_HEADER_SIZE + editableVideoDataSize;
metadataCollector.addMetadata(
new MdtaMetadataEntry(
MdtaMetadataEntry.KEY_EDITABLE_TRACKS_LENGTH,
@ -584,11 +582,11 @@ public final class Mp4Muxer implements Muxer {
}
outputChannel.position(outputChannel.size());
FileInputStream inputStream = new FileInputStream(checkNotNull(cacheFilePath));
ByteBuffer edvdBoxHeader = ByteBuffer.allocate(EDVD_BOX_HEADER_SIZE_BYTE);
ByteBuffer edvdBoxHeader = ByteBuffer.allocate(LARGE_SIZE_BOX_HEADER_SIZE);
edvdBoxHeader.putInt(1); // indicating a 64-bit length field
edvdBoxHeader.put(Util.getUtf8Bytes("edvd"));
edvdBoxHeader.putLong(
EDVD_BOX_HEADER_SIZE_BYTE + inputStream.getChannel().size()); // the actual length
LARGE_SIZE_BOX_HEADER_SIZE + inputStream.getChannel().size()); // the actual length
edvdBoxHeader.flip();
outputChannel.write(edvdBoxHeader);
ByteStreams.copy(inputStream, outputStream);

View File

@ -20,6 +20,7 @@ import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.muxer.AnnexBUtils.doesSampleContainAnnexBNalUnits;
import static androidx.media3.muxer.Boxes.BOX_HEADER_SIZE;
import static androidx.media3.muxer.Boxes.LARGE_SIZE_BOX_HEADER_SIZE;
import static java.lang.Math.max;
import static java.lang.Math.min;
@ -218,7 +219,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
// Start with an empty mdat box.
mdatStart = outputFileChannel.position();
ByteBuffer header = ByteBuffer.allocate(4 + 4 + 8);
ByteBuffer header = ByteBuffer.allocate(LARGE_SIZE_BOX_HEADER_SIZE);
header.putInt(1); // 4 bytes, indicating a 64-bit length field
header.put(Util.getUtf8Bytes("mdat")); // 4 bytes
header.putLong(16); // 8 bytes (the actual length)