Only set hadKeyframe flag to true if we end up muxing the frame.

If we throw away the first keyframe (because it does not contain any bytes to read), we shouldn't behave as if we had written a keyframe to our track. We should instead continue waiting for the first (valid) keyframe.

PiperOrigin-RevId: 554579146
This commit is contained in:
Googler 2023-08-07 20:41:33 +00:00 committed by Tianyi Feng
parent f43146718c
commit 7d6f02dc50

View File

@ -364,6 +364,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
} }
public void writeSampleData(ByteBuffer byteBuffer, BufferInfo bufferInfo) throws IOException { public void writeSampleData(ByteBuffer byteBuffer, BufferInfo bufferInfo) throws IOException {
// TODO: b/279931840 - Confirm whether muxer should throw when writing empty samples.
// Skip empty samples.
if (bufferInfo.size == 0 || byteBuffer.remaining() == 0) {
return;
}
if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_KEY_FRAME) > 0) { if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_KEY_FRAME) > 0) {
hadKeyframe = true; hadKeyframe = true;
} }
@ -372,16 +378,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
return; return;
} }
if (bufferInfo.size == 0) { pendingSamples.addLast(Pair.create(bufferInfo, byteBuffer));
return; doInterleave();
}
// Skip empty samples.
// TODO: b/279931840 - Confirm whether muxer should throw when writing empty samples.
if (byteBuffer.remaining() > 0) {
pendingSamples.addLast(Pair.create(bufferInfo, byteBuffer));
doInterleave();
}
} }
@Override @Override