From 3dee237c8265f79080c24f599309b5e3a564900e Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Sun, 11 Aug 2024 21:39:07 +0200 Subject: [PATCH] Add writer comments and use or instead of and (#201) --- .../com/otaliastudios/transcoder/internal/data/Writer.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/otaliastudios/transcoder/internal/data/Writer.kt b/lib/src/main/java/com/otaliastudios/transcoder/internal/data/Writer.kt index 12aa1c2f..ce2a67bf 100644 --- a/lib/src/main/java/com/otaliastudios/transcoder/internal/data/Writer.kt +++ b/lib/src/main/java/com/otaliastudios/transcoder/internal/data/Writer.kt @@ -38,9 +38,14 @@ internal class Writer( override fun step(state: State.Ok, fresh: Boolean): State { val (buffer, timestamp, flags) = state.value + // Note: flags does NOT include BUFFER_FLAG_END_OF_STREAM. That's passed via State.Eos. val eos = state is State.Eos if (eos) { - info.set(0, 0, 0, flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM) + // Note: it may happen that at this point, buffer has some data. but creating an extra writeTrack() call + // can cause some crashes that were not properly debugged, probably related to wrong timestamp. + // I think if we could ensure that timestamp is valid (> previous, > 0) and buffer.hasRemaining(), there should + // be an extra call here. See #159. Reluctant to do so without a repro test. + info.set(0, 0, 0, flags or MediaCodec.BUFFER_FLAG_END_OF_STREAM) } else { info.set( buffer.position(),