diff --git a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/AudioSpecificConfig.kt b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/AudioSpecificConfig.kt index 50b2a1c0c..f5341316d 100644 --- a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/AudioSpecificConfig.kt +++ b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/AudioSpecificConfig.kt @@ -69,7 +69,7 @@ data class AudioSpecificConfig( ) } - override fun write(writer: BitBuffer) { + override fun write(output: BitBuffer) { TODO("Not yet implemented") } @@ -325,7 +325,7 @@ data class AudioSpecificConfig( } } - override fun write(writer: BitBuffer) { + override fun write(output: BitBuffer) { TODO("Not yet implemented") } diff --git a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/AudioMuxElement.kt b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/AudioMuxElement.kt index 109d2dd7c..3116c330c 100644 --- a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/AudioMuxElement.kt +++ b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/AudioMuxElement.kt @@ -15,10 +15,10 @@ */ package io.github.thibaultbee.streampack.internal.utils.av.audio.aac +import io.github.thibaultbee.streampack.internal.utils.av.audio.AudioSpecificConfig import io.github.thibaultbee.streampack.internal.utils.av.buffer.BitBuffer import io.github.thibaultbee.streampack.internal.utils.av.buffer.BitBufferWriter import io.github.thibaultbee.streampack.internal.utils.av.buffer.ByteBufferWriter -import io.github.thibaultbee.streampack.internal.utils.av.audio.AudioSpecificConfig import java.nio.ByteBuffer class AudioMuxElement( @@ -30,7 +30,8 @@ class AudioMuxElement( private val payloadLengthInfo = PayloadLengthInfo() private val payloadMux = PayloadMux() - override val bitSize: Int + override val size = (bitSize + Byte.SIZE_BITS - 1) / Byte.SIZE_BITS + private val bitSize: Int get() = 1 + if (!useSameStreamMuxConfig) { streamMuxConfig!!.bitSize } else { @@ -69,16 +70,16 @@ class AudioMuxElement( private inner class PayloadLengthInfo : BitBufferWriter() { private val payloadSize = payload!!.remaining() - override val size = (payloadSize / 255) + 1 + override val bitSize = ((payloadSize / 255) + 1) * Byte.SIZE_BITS - override fun write(writer: BitBuffer) { + override fun write(output: BitBuffer) { if (streamMuxConfig!!.allStreamsSameTimeFraming == true) { var remainingPayloadLength = payloadSize for (i in 0..(payloadSize - 255) step 255) { - writer.put(0xFF, 8) + output.put(0xFF, 8) remainingPayloadLength -= 255 } - writer.put(remainingPayloadLength, 8) + output.put(remainingPayloadLength, 8) } else { throw NotImplementedError("Not implemented yet") } @@ -86,10 +87,10 @@ class AudioMuxElement( } private inner class PayloadMux : BitBufferWriter() { - override val size = payload!!.remaining() + override val bitSize = payload!!.remaining() * Byte.SIZE_BITS - override fun write(writer: BitBuffer) { - writer.put(payload!!) + override fun write(output: BitBuffer) { + output.put(payload!!) } } @@ -115,7 +116,10 @@ class AudioMuxElement( ) } - fun fromDecoderSpecificInfo(payload: ByteBuffer, decoderSpecificInfo: ByteBuffer): AudioMuxElement { + fun fromDecoderSpecificInfo( + payload: ByteBuffer, + decoderSpecificInfo: ByteBuffer + ): AudioMuxElement { return AudioMuxElement( muxConfigPresent = true, useSameStreamMuxConfig = false, @@ -158,23 +162,23 @@ class StreamMuxConfig( } } - override fun write(writer: BitBuffer) { - writer.put(audioMuxVersion, 1) + override fun write(output: BitBuffer) { + output.put(audioMuxVersion, 1) if (audioMuxVersion == 1) { - writer.put(audioMuxVersionA, 1) + output.put(audioMuxVersionA, 1) } if (audioMuxVersionA == 0) { - writer.put(allStreamsSameTimeFraming!!) - writer.put(numSubFrames!!, 6) - writer.put(numProgram!!, 4) // numProgram - writer.put(numLayer!!, 3) // numLayer + output.put(allStreamsSameTimeFraming!!) + output.put(numSubFrames!!, 6) + output.put(numProgram!!, 4) // numProgram + output.put(numLayer!!, 3) // numLayer - writer.put(audioSpecificConfig!!) + output.put(audioSpecificConfig!!) - writer.put(frameLengthType!!, 3) - writer.put(0xFF, 8) // latmBufferFullness - writer.put(0, 1) // otherDataPresent - writer.put(0, 1) // crcCheckPresent + output.put(frameLengthType!!, 3) + output.put(0xFF, 8) // latmBufferFullness + output.put(0, 1) // otherDataPresent + output.put(0, 1) // crcCheckPresent } } diff --git a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/ProgramConfigElement.kt b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/ProgramConfigElement.kt index 740a82c7c..30cf9bf08 100644 --- a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/ProgramConfigElement.kt +++ b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/ProgramConfigElement.kt @@ -22,7 +22,7 @@ class ProgramConfigElement : BitBufferWriter() { override val bitSize: Int get() = TODO("Not yet implemented") - override fun write(writer: BitBuffer) { + override fun write(output: BitBuffer) { TODO("Not yet implemented") } diff --git a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/config/ELDSpecificConfig.kt b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/config/ELDSpecificConfig.kt index 733984727..6344d58fe 100644 --- a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/config/ELDSpecificConfig.kt +++ b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/config/ELDSpecificConfig.kt @@ -15,9 +15,9 @@ */ package io.github.thibaultbee.streampack.internal.utils.av.audio.aac.config -import io.github.thibaultbee.streampack.internal.utils.av.buffer.BitBufferWriter -import io.github.thibaultbee.streampack.internal.utils.av.buffer.BitBuffer import io.github.thibaultbee.streampack.internal.utils.av.audio.ChannelConfiguration +import io.github.thibaultbee.streampack.internal.utils.av.buffer.BitBuffer +import io.github.thibaultbee.streampack.internal.utils.av.buffer.BitBufferWriter data class ELDSpecificConfig( val channelConfiguration: ChannelConfiguration, @@ -46,7 +46,7 @@ data class ELDSpecificConfig( } } - override fun write(writer: BitBuffer) { + override fun write(output: BitBuffer) { TODO("Not yet implemented") } @@ -120,10 +120,10 @@ data class ELDSpecificConfig( class LdSbrHeader( private val sbrHeaders: List ) : BitBufferWriter() { - override val size = 5 + sbrHeaders.size * 8 + override val bitSize = (5 + sbrHeaders.size * 8) * Byte.SIZE_BITS - override fun write(writer: BitBuffer) { - sbrHeaders.forEach { it.write(writer) } + override fun write(output: BitBuffer) { + sbrHeaders.forEach { it.write(output) } } companion object { @@ -134,17 +134,21 @@ data class ELDSpecificConfig( ChannelConfiguration.CHANNEL_2 -> { 1 } + ChannelConfiguration.CHANNEL_3 -> { 2 } + ChannelConfiguration.CHANNEL_4, ChannelConfiguration.CHANNEL_5, ChannelConfiguration.CHANNEL_6 -> { 3 } + ChannelConfiguration.CHANNEL_8 -> { 4 } + else -> { 0 } diff --git a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/config/GASpecificConfig.kt b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/config/GASpecificConfig.kt index ae6a10f29..784b58e91 100644 --- a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/config/GASpecificConfig.kt +++ b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/config/GASpecificConfig.kt @@ -71,7 +71,7 @@ data class GASpecificConfig( } } - override fun write(writer: BitBuffer) { + override fun write(output: BitBuffer) { TODO("Not yet implemented") } diff --git a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/config/SbrHeader.kt b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/config/SbrHeader.kt index 1ebed2491..14450c7ac 100644 --- a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/config/SbrHeader.kt +++ b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/audio/aac/config/SbrHeader.kt @@ -15,8 +15,8 @@ */ package io.github.thibaultbee.streampack.internal.utils.av.audio.aac.config -import io.github.thibaultbee.streampack.internal.utils.av.buffer.BitBufferWriter import io.github.thibaultbee.streampack.internal.utils.av.buffer.BitBuffer +import io.github.thibaultbee.streampack.internal.utils.av.buffer.BitBufferWriter data class SbrHeader( val bsAmpRes: Boolean, @@ -33,7 +33,9 @@ data class SbrHeader( val bsInterpolFreq: Boolean? = null, val bsSmoothingMode: Boolean? = null ) : BitBufferWriter() { - override fun write(writer: BitBuffer) { + override val bitSize = 0 + + override fun write(output: BitBuffer) { TODO("Not yet implemented") } diff --git a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/buffer/BitBufferWriter.kt b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/buffer/BitBufferWriter.kt index 2c20f6cb4..2f9209ab8 100644 --- a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/buffer/BitBufferWriter.kt +++ b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/buffer/BitBufferWriter.kt @@ -22,12 +22,15 @@ import java.nio.ByteBuffer * For sub classes of a [ByteBufferWriter] that need to write a [ByteBuffer] to a [BitBuffer] */ abstract class BitBufferWriter : ByteBufferWriter() { + abstract val bitSize: Int + override val size by lazy { (bitSize + Byte.SIZE_BITS - 1) / Byte.SIZE_BITS } + override fun write(output: ByteBuffer) { val writer = BitBuffer(output) write(writer) } - abstract fun write(writer: BitBuffer) + abstract fun write(output: BitBuffer) fun toBitBuffer(): BitBuffer { val buffer = ByteBuffer.allocate(size) diff --git a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/buffer/ByteBufferWriter.kt b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/buffer/ByteBufferWriter.kt index c70350b48..425cbb8db 100644 --- a/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/buffer/ByteBufferWriter.kt +++ b/core/src/main/java/io/github/thibaultbee/streampack/internal/utils/av/buffer/ByteBufferWriter.kt @@ -20,13 +20,9 @@ import io.github.thibaultbee.streampack.internal.utils.extensions.isAvcc import io.github.thibaultbee.streampack.internal.utils.extensions.removeStartCode import io.github.thibaultbee.streampack.internal.utils.extensions.startCodeSize import java.nio.ByteBuffer -import kotlin.math.ceil abstract class ByteBufferWriter { - open val size: Int - get() = ceil(bitSize.toFloat() / Byte.SIZE_BITS).toInt() - open val bitSize: Int - get() = size * Byte.SIZE_BITS + abstract val size: Int open fun toByteBuffer(): ByteBuffer { val output = ByteBuffer.allocate(size)