audio: send the AAC codec config to AAC-only sinks

A GalReceiver 2014 head unit, whose media sink takes only raw AAC-LC,
reset the connection on the first audio frame. Raw AAC-LC has no header
of its own, so send the AudioSpecificConfig right after Start, as video
does with SPS/PPS. PCM and ADTS sinks are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jorgeandClaude Opus 5.5 committed 2026-10-25 13:26:35 +01:00
1 parent f2344169af
commit 89e5bbd2bb
2 files changed
+19 -3

No files matched your search

@@ -87,8 +87,17 @@ internal class AacEncoder(private val sampleRate: Int, private val channels: Int
runCatching { codec.release() }
}
private companion object {
const val INPUT_WAIT_US = 10_000L
val FREQUENCIES = listOf(96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350)
companion object {
private const val INPUT_WAIT_US = 10_000L
private val FREQUENCIES = listOf(96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350)
/** The two-byte AudioSpecificConfig for AAC-LC: object type 2, rate index, channel count. */
fun audioSpecificConfig(sampleRate: Int, channels: Int): ByteArray {
val freq = FREQUENCIES.indexOf(sampleRate).let { if (it < 0) 3 else it }
return byteArrayOf(
((2 shl 3) or (freq shr 1)).toByte(),
(((freq and 1) shl 7) or (channels shl 3)).toByte(),
)
}
}
}
@@ -251,6 +251,12 @@ class AudioLink(
MSG_START,
Protobuf.varintField(1, sessionId.toLong()) + Protobuf.varintField(2, configIndex.toLong()),
)
// Raw AAC-LC has no header of its own: the car needs the codec config before the first frame.
if (service.codecType == ServiceDiscovery.CODEC_AAC_LC) {
val asc = AacEncoder.audioSpecificConfig(sampleRate, channels)
sendOnChannel(MSG_CODEC_CONFIG, asc)
GearslipLog.hex("$tag: -> CodecConfig (AudioSpecificConfig)", asc)
}
inFlight = 0
lastAckAt = System.currentTimeMillis()
if (aacSink && aac == null) {
@@ -364,6 +370,7 @@ class AudioLink(
const val MSG_FOCUS_RESPONSE = 19
private const val MSG_CHANNEL_OPEN_RESPONSE = 8
private const val MSG_DATA = 0
private const val MSG_CODEC_CONFIG = 1
private const val MSG_SETUP = 32768
private const val MSG_START = 32769
private const val MSG_STOP = 32770