BlueGit

ict rusty-teams

fix(calling): VAAPI packed slice header gets its start code (#95)

Co-authored-by: Lukas Grundtner <lukas.grundtner@automatics.ai>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

metis Lukas · pushed by metis

Authored 2026-11-25 · 6 days ago

Hash
47f0b8c18d87e9da5fdc2d9c4a8713f70f0a6d7c
Parent
a0f84959
2 files changed +4 −1
vendor/webrtc-sys/PATCH.md +1 −0
@@ -10,3 +10,4 @@ Upstream: crates.io `webrtc-sys 0.3.48` (livekit/rust-sdks). Wired in via `[patc
10 10 | `src/adm_proxy.cpp` | `BuiltInAECIsAvailable()` returns false on Windows | the voice capture DMO fails `StartRecording` ("Playout must be started before recording") when no remote audio plays yet - mic silent for the whole call (seen in the app log 2026-10-13) |
11 11 | `src/adm_proxy.cpp`, `include/livekit/adm_proxy.h` | `SetPlayoutDevice` / `SetRecordingDevice(WindowsDeviceType)` turn `kDefaultCommunicationDevice` into `kDefaultDevice` | `WebRtcVoiceEngine::Init` selects the communications default at every call start; the app's "Default device" means the Windows default device (seen 2026-10-14: speaker came up on the communications default, user picked the default device by hand every call) |
12 12 | `src/noise_hook.rs`, `src/noise_hook.cpp`, `include/livekit/noise_hook.h`, `build.rs`, `src/lib.rs`, `src/peer_connection_factory.cpp` | The factory's APM gets a capture post processor that calls a Rust hook (`noise_hook::set_capture_hook`) on the full-band capture buffer | ML noise suppression (RNNoise) on the device track, keeping echo cancellation on the real playout reference |
13 | `src/vaapi/vaapi_h264_encoder_wrapper.cpp` | `bitstream_put_ui()` no longer shifts a 32-bit word by 32 when a value fills a fresh word | That shift is undefined; built with clang -O2 it wrote the NAL start code of the packed slice header as `00 00 00 00`, and the Intel iHD driver (26.3.5) read past the buffer and segfaulted in `vaRenderPicture` on the first camera frame (2026-11-24, Core Ultra 7 165U). gcc -O0 happened to produce `00 00 00 01`, which hid it |
@@ -10,3 +10,4 @@ Upstream: crates.io `webrtc-sys 0.3.48` (livekit/rust-sdks). Wired in via `[patc
10| `src/adm_proxy.cpp` | `BuiltInAECIsAvailable()` returns false on Windows | the voice capture DMO fails `StartRecording` ("Playout must be started before recording") when no remote audio plays yet - mic silent for the whole call (seen in the app log 2026-10-13) |
10| `src/adm_proxy.cpp` | `BuiltInAECIsAvailable()` returns false on Windows | the voice capture DMO fails `StartRecording` ("Playout must be started before recording") when no remote audio plays yet - mic silent for the whole call (seen in the app log 2026-10-13) |
11| `src/adm_proxy.cpp`, `include/livekit/adm_proxy.h` | `SetPlayoutDevice` / `SetRecordingDevice(WindowsDeviceType)` turn `kDefaultCommunicationDevice` into `kDefaultDevice` | `WebRtcVoiceEngine::Init` selects the communications default at every call start; the app's "Default device" means the Windows default device (seen 2026-10-14: speaker came up on the communications default, user picked the default device by hand every call) |
11| `src/adm_proxy.cpp`, `include/livekit/adm_proxy.h` | `SetPlayoutDevice` / `SetRecordingDevice(WindowsDeviceType)` turn `kDefaultCommunicationDevice` into `kDefaultDevice` | `WebRtcVoiceEngine::Init` selects the communications default at every call start; the app's "Default device" means the Windows default device (seen 2026-10-14: speaker came up on the communications default, user picked the default device by hand every call) |
12| `src/noise_hook.rs`, `src/noise_hook.cpp`, `include/livekit/noise_hook.h`, `build.rs`, `src/lib.rs`, `src/peer_connection_factory.cpp` | The factory's APM gets a capture post processor that calls a Rust hook (`noise_hook::set_capture_hook`) on the full-band capture buffer | ML noise suppression (RNNoise) on the device track, keeping echo cancellation on the real playout reference |
12| `src/noise_hook.rs`, `src/noise_hook.cpp`, `include/livekit/noise_hook.h`, `build.rs`, `src/lib.rs`, `src/peer_connection_factory.cpp` | The factory's APM gets a capture post processor that calls a Rust hook (`noise_hook::set_capture_hook`) on the full-band capture buffer | ML noise suppression (RNNoise) on the device track, keeping echo cancellation on the real playout reference |
13| `src/vaapi/vaapi_h264_encoder_wrapper.cpp` | `bitstream_put_ui()` no longer shifts a 32-bit word by 32 when a value fills a fresh word | That shift is undefined; built with clang -O2 it wrote the NAL start code of the packed slice header as `00 00 00 00`, and the Intel iHD driver (26.3.5) read past the buffer and segfaulted in `vaRenderPicture` on the first camera frame (2026-11-24, Core Ultra 7 165U). gcc -O0 happened to produce `00 00 00 01`, which hid it |
vendor/webrtc-sys/src/vaapi/vaapi_h264_encoder_wrapper.cpp +3 −1
@@ -184,7 +184,9 @@ static void bitstream_put_ui(bitstream* bs, uint32_t val, int size_in_bits) {
184 184 bs->buffer[pos] = (bs->buffer[pos] << size_in_bits | val);
185 185 } else {
186 186 size_in_bits -= bit_left;
187 bs->buffer[pos] = (bs->buffer[pos] << bit_left) | (val >> size_in_bits);
187 // A word with no bits yet has bit_left == 32, and shifting a uint32_t by 32 is undefined.
188 uint32_t kept = bit_left == 32 ? 0 : bs->buffer[pos] << bit_left;
189 bs->buffer[pos] = kept | (val >> size_in_bits);
188 190 bs->buffer[pos] = va_swap32(bs->buffer[pos]);
189 191
190 192 if (pos + 1 == bs->max_size_in_dword) {
@@ -184,7 +184,9 @@ static void bitstream_put_ui(bitstream* bs, uint32_t val, int size_in_bits) {
184 bs->buffer[pos] = (bs->buffer[pos] << size_in_bits | val);
184 bs->buffer[pos] = (bs->buffer[pos] << size_in_bits | val);
185 } else {
185 } else {
186 size_in_bits -= bit_left;
186 size_in_bits -= bit_left;
187 bs->buffer[pos] = (bs->buffer[pos] << bit_left) | (val >> size_in_bits);
187 // A word with no bits yet has bit_left == 32, and shifting a uint32_t by 32 is undefined.
188 uint32_t kept = bit_left == 32 ? 0 : bs->buffer[pos] << bit_left;
189 bs->buffer[pos] = kept | (val >> size_in_bits);
188 bs->buffer[pos] = va_swap32(bs->buffer[pos]);
190 bs->buffer[pos] = va_swap32(bs->buffer[pos]);
189
191
190 if (pos + 1 == bs->max_size_in_dword) {
192 if (pos + 1 == bs->max_size_in_dword) {