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
public void writeSampleData(
int trackIndex, ByteBuffer data, boolean isKeyFrame, long presentationTimeUs)
int trackIndex, ByteBuffer data, long presentationTimeUs, @C.BufferFlags int flags)
throws MuxerException {
muxer.writeSampleData(trackIndex, data, isKeyFrame, presentationTimeUs);
muxer.writeSampleData(trackIndex, data, presentationTimeUs, flags);
}
@Override

View File

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

View File

@ -27,11 +27,10 @@ import java.nio.ByteBuffer;
* Abstracts media muxing operations.
*
* <p>Query whether {@linkplain Factory#getSupportedSampleMimeTypes(int) sample MIME types} are
* supported and {@linkplain #addTrack(Format) add all tracks}, then {@linkplain
* #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,
* {@linkplain #release(boolean) release} the instance to finish writing to the output and return
* any resources to the system.
* supported and {@linkplain #addTrack(Format) add all tracks}, then {@linkplain #writeSampleData
* 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, {@linkplain #release(boolean) release} the instance to
* finish writing to the output and return any resources to the system.
*/
@UnstableApi
public interface Muxer {
@ -93,11 +92,13 @@ public interface Muxer {
*
* @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 isKeyFrame Whether the sample is a key frame.
* @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.
*/
void writeSampleData(int trackIndex, ByteBuffer data, boolean isKeyFrame, long presentationTimeUs)
void writeSampleData(
int trackIndex, ByteBuffer data, long presentationTimeUs, @C.BufferFlags int flags)
throws MuxerException;
/**

View File

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

View File

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