Allow Muxer.writeSampleData to take @C.BufferFlag int flags.

PiperOrigin-RevId: 501314812
This commit is contained in:
samrobinson 2023-01-11 18:16:41 +00:00 committed by Rohit Singh
parent a2cf222117
commit 13537a170b
5 changed files with 22 additions and 16 deletions

View File

@ -80,9 +80,9 @@ public final class DefaultMuxer implements Muxer {
@Override @Override
public void writeSampleData( public void writeSampleData(
int trackIndex, ByteBuffer data, boolean isKeyFrame, long presentationTimeUs) int trackIndex, ByteBuffer data, long presentationTimeUs, @C.BufferFlags int flags)
throws MuxerException { throws MuxerException {
muxer.writeSampleData(trackIndex, data, isKeyFrame, presentationTimeUs); muxer.writeSampleData(trackIndex, data, presentationTimeUs, flags);
} }
@Override @Override

View File

@ -142,10 +142,9 @@ import java.nio.ByteBuffer;
return trackIndex; return trackIndex;
} }
@SuppressLint("WrongConstant") // C.BUFFER_FLAG_KEY_FRAME equals MediaCodec.BUFFER_FLAG_KEY_FRAME.
@Override @Override
public void writeSampleData( public void writeSampleData(
int trackIndex, ByteBuffer data, boolean isKeyFrame, long presentationTimeUs) int trackIndex, ByteBuffer data, long presentationTimeUs, @C.BufferFlags int flags)
throws MuxerException { throws MuxerException {
if (!isStarted) { if (!isStarted) {
isStarted = true; isStarted = true;
@ -157,7 +156,6 @@ import java.nio.ByteBuffer;
} }
int offset = data.position(); int offset = data.position();
int size = data.limit() - offset; int size = data.limit() - offset;
int flags = isKeyFrame ? C.BUFFER_FLAG_KEY_FRAME : 0;
bufferInfo.set(offset, size, presentationTimeUs, flags); bufferInfo.set(offset, size, presentationTimeUs, flags);
long lastSamplePresentationTimeUs = trackIndexToLastPresentationTimeUs.get(trackIndex); long lastSamplePresentationTimeUs = trackIndexToLastPresentationTimeUs.get(trackIndex);
try { try {

View File

@ -27,11 +27,10 @@ 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
* #writeSampleData(int, ByteBuffer, boolean, long) write sample data} to mux samples. Once any * write sample data} to mux samples. Once any sample data has been written, it is not possible to
* sample data has been written, it is not possible to add tracks. After writing all sample data, * add tracks. After writing all sample data, {@linkplain #release(boolean) release} the instance to
* {@linkplain #release(boolean) release} the instance to finish writing to the output and return * finish writing to the output and return any resources to the system.
* any resources to the system.
*/ */
@UnstableApi @UnstableApi
public interface Muxer { public interface Muxer {
@ -93,11 +92,13 @@ public interface Muxer {
* *
* @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 A 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. * @param presentationTimeUs The presentation time of the sample in microseconds.
* @param flags The {@link C.BufferFlags} associated with the data. Only {@link
* C#BUFFER_FLAG_KEY_FRAME} is supported.
* @throws MuxerException If the muxer fails to write the sample. * @throws MuxerException If the muxer fails to write the sample.
*/ */
void writeSampleData(int trackIndex, ByteBuffer data, boolean isKeyFrame, long presentationTimeUs) void writeSampleData(
int trackIndex, ByteBuffer data, long presentationTimeUs, @C.BufferFlags int flags)
throws MuxerException; throws MuxerException;
/** /**

View File

@ -202,7 +202,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
checkNotNull(muxer); checkNotNull(muxer);
resetAbortTimer(); resetAbortTimer();
muxer.writeSampleData(trackInfo.index, data, isKeyFrame, presentationTimeUs); muxer.writeSampleData(
trackInfo.index, data, presentationTimeUs, isKeyFrame ? C.BUFFER_FLAG_KEY_FRAME : 0);
previousTrackType = trackType; previousTrackType = trackType;
return true; return true;
} }

View File

@ -15,6 +15,7 @@
*/ */
package androidx.media3.transformer; package androidx.media3.transformer;
import androidx.media3.common.C;
import androidx.media3.common.Format; import androidx.media3.common.Format;
import androidx.media3.test.utils.DumpableFormat; import androidx.media3.test.utils.DumpableFormat;
import androidx.media3.test.utils.Dumper; import androidx.media3.test.utils.Dumper;
@ -50,10 +51,15 @@ public final class TestMuxer implements Muxer, Dumper.Dumpable {
@Override @Override
public void writeSampleData( public void writeSampleData(
int trackIndex, ByteBuffer data, boolean isKeyFrame, long presentationTimeUs) int trackIndex, ByteBuffer data, long presentationTimeUs, @C.BufferFlags int flags)
throws MuxerException { throws MuxerException {
dumpables.add(new DumpableSample(trackIndex, data, isKeyFrame, presentationTimeUs)); dumpables.add(
muxer.writeSampleData(trackIndex, data, isKeyFrame, presentationTimeUs); new DumpableSample(
trackIndex,
data,
(flags & C.BUFFER_FLAG_KEY_FRAME) == C.BUFFER_FLAG_KEY_FRAME,
presentationTimeUs));
muxer.writeSampleData(trackIndex, data, presentationTimeUs, flags);
} }
@Override @Override