Remove copying sample data in Mp4Muxer
PiperOrigin-RevId: 540623370
This commit is contained in:
parent
52878b2aca
commit
18bc893210
@ -237,6 +237,9 @@ public final class Mp4Muxer {
|
|||||||
/**
|
/**
|
||||||
* Writes encoded sample data.
|
* Writes encoded sample data.
|
||||||
*
|
*
|
||||||
|
* <p>The samples are cached and are written in batches so the caller must not change/release the
|
||||||
|
* {@link ByteBuffer} and the {@link BufferInfo} after calling this method.
|
||||||
|
*
|
||||||
* @param trackToken The {@link TrackToken} for which this sample is being written.
|
* @param trackToken The {@link TrackToken} for which this sample is being written.
|
||||||
* @param byteBuffer The encoded sample.
|
* @param byteBuffer The encoded sample.
|
||||||
* @param bufferInfo The {@link BufferInfo} related to this sample.
|
* @param bufferInfo The {@link BufferInfo} related to this sample.
|
||||||
|
@ -379,19 +379,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
// Skip empty samples.
|
// Skip empty samples.
|
||||||
// TODO: b/279931840 - Confirm whether muxer should throw when writing empty samples.
|
// TODO: b/279931840 - Confirm whether muxer should throw when writing empty samples.
|
||||||
if (byteBuffer.remaining() > 0) {
|
if (byteBuffer.remaining() > 0) {
|
||||||
// Copy sample data and release the original buffer.
|
pendingSamples.addLast(Pair.create(bufferInfo, byteBuffer));
|
||||||
ByteBuffer byteBufferCopy = ByteBuffer.allocateDirect(byteBuffer.remaining());
|
|
||||||
byteBufferCopy.put(byteBuffer);
|
|
||||||
byteBufferCopy.rewind();
|
|
||||||
|
|
||||||
BufferInfo bufferInfoCopy = new BufferInfo();
|
|
||||||
bufferInfoCopy.set(
|
|
||||||
/* newOffset= */ byteBufferCopy.position(),
|
|
||||||
/* newSize= */ byteBufferCopy.remaining(),
|
|
||||||
bufferInfo.presentationTimeUs,
|
|
||||||
bufferInfo.flags);
|
|
||||||
|
|
||||||
pendingSamples.addLast(Pair.create(bufferInfoCopy, byteBufferCopy));
|
|
||||||
doInterleave();
|
doInterleave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,19 @@ public final class InAppMuxer implements Muxer {
|
|||||||
data.position(), size, presentationTimeUs, TransformerUtil.getMediaCodecFlags(flags));
|
data.position(), size, presentationTimeUs, TransformerUtil.getMediaCodecFlags(flags));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mp4Muxer.writeSampleData(trackTokenList.get(trackIndex), data, bufferInfo);
|
// Copy sample data and release the original buffer.
|
||||||
|
ByteBuffer byteBufferCopy = ByteBuffer.allocateDirect(data.remaining());
|
||||||
|
byteBufferCopy.put(data);
|
||||||
|
byteBufferCopy.rewind();
|
||||||
|
|
||||||
|
BufferInfo bufferInfoCopy = new BufferInfo();
|
||||||
|
bufferInfoCopy.set(
|
||||||
|
/* newOffset= */ byteBufferCopy.position(),
|
||||||
|
/* newSize= */ byteBufferCopy.remaining(),
|
||||||
|
bufferInfo.presentationTimeUs,
|
||||||
|
bufferInfo.flags);
|
||||||
|
|
||||||
|
mp4Muxer.writeSampleData(trackTokenList.get(trackIndex), byteBufferCopy, bufferInfoCopy);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new MuxerException(
|
throw new MuxerException(
|
||||||
"Failed to write sample for trackIndex="
|
"Failed to write sample for trackIndex="
|
||||||
|
Loading…
x
Reference in New Issue
Block a user