Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ internal class Writer(
override fun step(state: State.Ok<WriterData>, fresh: Boolean): State<Unit> {
val (buffer, timestamp, flags) = state.value
val eos = state is State.Eos
info.set(
buffer.position(),
buffer.remaining(),
timestamp,
if (eos) {
flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM
} else flags
)
if (eos) {
info.set(0, 0, 0, flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM)
} else {
info.set(
buffer.position(),
buffer.remaining(),
timestamp,
flags
)
}
sink.writeTrack(track, buffer, info)
Comment on lines +42 to 52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last buffer might have data in theory, is it possible to send it in a separate call?

if (eos) {
    if (buffer.hasRemaining()) {
        info.set(buffer.position(), buffer.remaining(), timestamp, flags)
        sink.writeTrack(track, buffer, info)
    }    
    info.set(0, 0, 0, flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM)
} else {
    info.set(buffer.position(), buffer.remaining(), timestamp, flags)
}
sink.writeTrack(track, buffer, info)

Would this fix your crash?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@natario1 Thanks for your review.
I tried your codes. But Crashed.

W/DefaultDataSink: Failed to release the muxer.
    java.lang.IllegalStateException: Failed to stop the muxer
        at android.media.MediaMuxer.nativeStop(Native Method)
        at android.media.MediaMuxer.stop(MediaMuxer.java:466)
        at android.media.MediaMuxer.release(MediaMuxer.java:706)
        at com.otaliastudios.transcoder.sink.DefaultDataSink.release(DefaultDataSink.java:224)
        at com.otaliastudios.transcoder.internal.transcode.DefaultTranscodeEngine.cleanup(DefaultTranscodeEngine.kt:141)
        at com.otaliastudios.transcoder.internal.transcode.TranscodeEngine$Companion.transcode(TranscodeEngine.kt:63)
        at com.otaliastudios.transcoder.internal.transcode.TranscodeEngine.transcode(Unknown Source:2)
        at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:102)
        at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:99)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)

state.value.release()
return if (eos) State.Eos(Unit) else State.Ok(Unit)
Expand Down