Note: After studying the code in libaom, I find the SVC in libaom only work if look-ahead-processing (LAP) is disabled, since the [`LAYER_CONTEXT`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/svc_layercontext.h#82) is *only* [allocated](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/av1_cx_iface.c#3682) for [`ctx->ppi->cpi->svc`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/svc_layercontext.c#94) but not for `svc` in [`ctx->ppi->cpi_lap`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/encoder.h#2653) (`ctx->ppi->cpi_lap->svc`). If LAP is enabled, when running [`cpi_lap` with `av1_change_config`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/av1_cx_iface.c#1621), [`av1_update_layer_context_change_config` for `cpi_lap`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/encoder.c#947) will be executed, then the code will access the `null` `cpi_lap->svc->layer_context` (`layer_context` is not allocated in `cpi_lap`!) and results in a *Segment fault* error. Hence, to perform SVC, the LAP must be disabled. The LAP can be disabled in two cases: (1) if the bitrate is constant (CBR mode) (2) or if lag-in-frames is zero. libaom will disable the LAP if the [bitrate is constant](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/av1_cx_iface.c#2777). Otherwise, it will calculates the `num_lap_buffers` value to determine if LAP should be enabled. By setting `g_lag_in_frames` to `0` (e.g., via [`av_opt_set(mCodecContext->priv_data, "lag-in-frames", "0", 0)`](https://searchfox.org/mozilla-central/rev/fc76676f61ee37b4c5420649cad6677164a29405/dom/media/platforms/ffmpeg/FFmpegVideoEncoder.cpp#300)), the `num_lap_buffers` will become `0` and [`lap_enabled` will be set to `false`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/encoder.c#1008)
Bug 1876438 Comment 7 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
Note: After studying the code in libaom, I found that SVC (Scalable Video Coding) in libaom only works if look-ahead processing (LAP) is disabled. This is because the [`LAYER_CONTEXT`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/svc_layercontext.h#82) is *only* [allocated](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/av1_cx_iface.c#3682) for [`ctx->ppi->cpi->svc`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/svc_layercontext.c#94) but not for `ctx->ppi->cpi_lap->svc` (`svc` in [`ctx->ppi->cpi_lap`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/encoder.h#2653)). If LAP is enabled, running `cpi_lap` with [`av1_change_config`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/av1_cx_iface.c#1621) then [`av1_update_layer_context_change_config`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/encoder.c#947) will result in accessing the `null` [`cpi_lap->svc->layer_context`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/svc_layercontext.c#117) (since `layer_context` is not allocated in `cpi_lap`), causing a *segmentation fault*. Therefore, to use SVC, LAP must be disabled. LAP can be disabled in two cases: (1) if the bitrate is constant (CBR mode) or (2) if lag-in-frames is set to zero. The libaom automatically disables LAP if the [bitrate is constant](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/av1_cx_iface.c#2777). Otherwise, it calculates the [`num_lap_buffers`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/av1_cx_iface.c#2780) value to determine if LAP should be enabled. By setting `g_lag_in_frames` to `0` (e.g., via [`av_opt_set(mCodecContext->priv_data, "lag-in-frames", "0", 0)`](https://searchfox.org/mozilla-central/rev/fc76676f61ee37b4c5420649cad6677164a29405/dom/media/platforms/ffmpeg/FFmpegVideoEncoder.cpp#300)), the `num_lap_buffers` will [become `0`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/av1_cx_iface.c#2781) and `lap_enabled` will be set to [`false`](https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/encoder.c#1008). Accordingly, no `cpi_lap` will be used.