Commit graph

644 commits

Author SHA1 Message Date
Harish Mahendrakar
2d98ce2311 rename few variables for consistency 2026-09-18 16:42:51 -07:00
Harish Mahendrakar
a054f7fca4 cosmetic changes to minimize diff with main branch 2026-09-18 14:29:25 -07:00
Harish Mahendrakar
4ffde5ebdd [decoder]: Change pu1_pic_qp and pu1_qp to WORD8 type and rename
QP can be negative in HBD path.

- Change pu1_pic_qp and pu1_qp to WORD8 type
- Rename pu1_pic_qp and pu1_qp to pi1_pic_qp and pi1_qp
- Remove redundant typecasts
2026-09-18 10:30:51 -07:00
Harish Mahendrakar
d3d855485e [decoder]: Format and clean up new functions in fmt_conv and itrans_recon_dc
Some checks are pending
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Waiting to run
- Format new functions to be consistent with existing codebase conventions
- Move local variable declarations to top of function scope (C99 style)
- Avoid datatype declarations inside for loop headers and prefer WORD32
  for loop indices without prefixes
- Remove commented code blocks
- Rename WORD32 arguments and header declarations to remove i4_ prefix
2026-09-17 15:55:36 -07:00
Harish Mahendrakar
1f208b145b [decoder]: Add few entries in codec_t and initialize them for default paths
Added few members in codec_t and initialized them for 420P, 8bit path.

When HBD support is added these will be updated based on the parsed headers.

(cherry picked from commit f35c5b1971)
2026-09-17 12:55:04 -07:00
Harish Mahendrakar
1fbe122b62 cosmetic changes to minimize diff with main branch
Some checks are pending
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Waiting to run
2026-09-16 21:34:10 -07:00
Harish Mahendrakar
8ae8e3842d Remove unused members from codec_t 2026-09-16 20:38:42 -07:00
Harish Mahendrakar
31a36da7db Rename i4_chroma_array_type to i4_chroma_format_idc for consistency 2026-09-16 20:38:42 -07:00
Vivek R Jadhav
577f3ff676 hevcdec: Add HBD format conversion support for YUV400 and YUV444
Test: ./hevcdec

Change-Id: Ie818967900b97bbebb777d375fed69108daa7ae7
2026-09-16 06:55:02 -07:00
Harish Mahendrakar
eb24aa6b80 decoder: Fix race condition and invalid CTB coordinates in slice headers
Some checks are pending
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Waiting to run
In ihevcd_copy_slice_hdr(), copying the previous slice header for dependent
slices copied i2_ctb_x and i2_ctb_y. If parsing was aborted or delayed,
the incomplete slice header retained the previous slice's coordinates,
causing concurrent worker threads in ihevcd_slice_hdr_update() to prematurely
switch to the invalid slice header. Reset i2_ctb_x and i2_ctb_y to -1
after copying.

In ihevcd_parse_slice_header(), initialize i2_ctb_x and i2_ctb_y to -1
immediately following memset so that slices rejected prior to coordinate
parsing do not retain valid-looking (0, 0) coordinates.

In ihevcd_parse_pic_init(), only skip reinitializing slice header 1 if
the first slice was missing in the current picture.

Test: ./hevc_dec_tests
Test: ./hevc_dec_fuzzer /work/misc/oss-fuzz/build/out/libhevc/crash-b74b07ae377d7450614e4534c86155d1d2999e13
TAG=agy
CONV=cfdfe257-7362-41c9-b5be-18261f1c6a3d

(cherry picked from commit 1713ca27ea)
2026-09-15 22:45:12 -07:00
Harish Mahendrakar
4bf5819c62 libhevcdec: Reset PPS scratch buffer and extension flags before parsing
Some checks failed
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Has been cancelled
When parsing PPS in ihevcd_parse_pps(), the scratch buffer
ps_codec->s_parse.ps_pps_base + MAX_PPS_CNT - 1 was not reset to zero,
unlike ihevcd_parse_sps(). In streams with concatenated sequences where
an earlier sequence set pps_extension_present_flag and range extension
flags, subsequent sequences without PPS extensions would retain the stale
flags. This caused the parser to attempt reading non-existent range
extension syntax, leading to bitstream parsing failure.

- In ihevcd_parse_pps(), reset the scratch PPS structure to zero upon
  entry while preserving pi2_scaling_mat and ps_tile pointers.
- In both ihevcd_parse_pps() and ihevcd_parse_sps(), explicitly zero all
  extension flags when pps_extension_present_flag / sps_extension_present_flag
  is 0.

Test: ./hevc_dec_tests
TAG=agy
CONV=476d1054-10ff-4f19-88d5-a1c8dae7b57f
2026-09-11 12:42:38 -07:00
Narayan Kalaburgi
9886db71d3 libhevcdec: Unify itrans_res family and remove redundant HBD implementation
Currently, libhevc maintains two separate implementations for inverse
transform residual functions: ihevc_itrans_res_* and ihevc_hbd_itrans_res_*.

Since both 8-bit and HBD inverse transform residual routines output signed
16-bit residuals (WORD16 *pi2_dst), the only algorithmic difference between
8-bit and HBD variants is the 2nd stage shift:

    Stage 1 shift: IT_SHIFT_STAGE_1 = 7 (fixed across all bit depths)
    Stage 2 shift: shift = 20 - bit_depth
        - 8-bit:  20 - 8  = 12 (IT_SHIFT_STAGE_2)
        - 10-bit: 20 - 10 = 10

This commit cleans up the entire itrans_res family (4x4_ttype1, 4x4, dc, 8x8,
16x16, 32x32) as follows:

1. common/ihevc_itrans_res.h & common/ihevc_itrans_res.c:
   - Add 'UWORD8 bit_depth' parameter to ihevc_itrans_res_* function
     signatures and typedefs.
   - Replace hardcoded 'shift = IT_SHIFT_STAGE_2;' with 'shift = 20 - bit_depth;'.
   - Remove obsolete ihevc_hbd_itrans_res_* prototypes and typedefs.

2. common/ihevc_hbd_itrans_res.c:
   - Delete file (~2,335 redundant lines removed).

3. Update tests/common/ihevc_itrans_res_test.cc to test bit depths 8 and 10
2026-09-10 11:21:07 -07:00
Harish Mahendrakar
eb6a4dd780 Rename few local variables for consistency
Some checks failed
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Has been cancelled
2026-09-04 15:28:11 -07:00
Harish Mahendrakar
33f2a8b540 Do not allow change in bit-depth or chroma format once decoder is initialized
Adaptive playback support doesn't require supporting change in chroma format or bit-depth.
2026-09-04 13:39:54 -07:00
StevenShen3641
c7ef7d1081 Fix out-of-bounds read when an SEI payload exceeds the NAL
ihevcd_parse_sei() truncated the declared SEI payload size to the bytes
remaining with MIN() instead of rejecting it. The payload parsers do not
consult that size, so ihevcd_parse_mastering_disp_params_sei() read its
full 24-byte structure out of a one-byte payload and ran past the end of
the bitstream buffer.

(cherry picked from commit b21f809576)
2026-09-04 09:35:46 -07:00
Narayan Kalaburgi
0aa9a2566f libhevcdec: Fix HBD transquant bypass decoding mismatch
When transquant bypass is enabled in HBD streams, decoded frames
mismatched the reference output due to two issues:

1. Intra boundary filtering:
   In the 8-bit path, boundary filtering for horizontal (mode 10) and
   vertical (mode 26) intra predictions is disabled when transquant bypass
   is active with implicit RDPCM. However, the HBD reconstruction path was
   passing raw u1_luma_pred_mode instead of disable_boundary_filter, and the
   HBD filter functions ignored the mode parameter.

2. SAO Scratch Buffer Overflow:
   During shifted CTB SAO processing, transquant bypass blocks are temporarily
   backed up into pu1_tmp_buf_luma and restored afterwards to keep them lossless.
   In HBD, each sample requires 2 bytes (UWORD16), but the static scratch buffer
   was allocated for 8-bit samples (sizeof(UWORD8)).
   Because the shifted CTB processing window spans beyond standard CTB boundaries
   to handle delayed neighbor boundaries, the 16-bit luma backup exceeded the
   allocated buffer capacity and overflowed into pu1_tmp_buf_chroma. Consequently,
   chroma backup overwrote the luma backup data, resulting in corrupted samples
   upon restoration.

This commit resolves the above issues with the following changes:
- common/ihevc_hbd_intra_pred_filters.c: Check 'disable_boundary_filter' to bypass
  boundary filtering in ihevc_hbd_intra_pred_luma_horz and ihevc_hbd_intra_pred_luma_ver.
- decoder/ihevcd_iquant_itrans_recon_ctb.c: Pass disable_boundary_filter
  to apf_hbd_intra_pred_luma for modes 10 and 26.
- decoder/ihevcd_api.c: Scale SAO temporary scratch buffer allocation
  (pu1_tmp_buf_luma and pu1_tmp_buf_chroma) by sizeof(UWORD16) to prevent
  buffer collision in HBD mode.
2026-09-04 09:35:33 -07:00
Rakesh Kumar
b15cb3bd00 libhevcdec: Fix dynamic bitstream buffer reallocation based on NAL unit size
Previously, the reallocation check evaluated bytes_remaining (the total
unparsed input buffer passed to the decode call, which can contain
multiple frames). This caused unnecessary reallocations on large
multi-frame input chunks.

Update the check to look ahead for the next start code using
ihevcd_nal_search_start_code to find the exact current NAL unit size
(cur_nal_size). Trigger buffer reallocation only when cur_nal_size
exceeds ps_codec->u4_bitsbuf_size.

Additionally:
- Check the return status of ihevcd_reallocate_dynamic_bitstream_buf
  and handle memory allocation failure cleanly by returning IV_FAIL with
  IVD_MEM_ALLOC_FAILED.
- Directly assign bytes_remaining = cur_nal_size for emulation prevention
  removal.
2026-09-03 14:07:39 -07:00
Anusuya K
44afce9dfb Fix PCM luma coding block size validation as per spec
As per the HEVC specification, i1_log2_min_pcm_coding_block_size shall be in the range of:
Min(MinCbLog2SizeY, 5) to Min(CtbLog2SizeY, 5), inclusive.

Updated the validation to use Min(MinCbLog2SizeY, 5) as the lower bound.
2026-09-03 11:34:08 +05:30
Anusuya K
f157554d3a Fix compliance issue 2026-09-03 11:34:08 +05:30
Harish Mahendrakar
4f5fdb3d17 decoder: Fix OOB read in ihevcd_parse_sei_payload when no SPS is valid
When parsing SEI payloads before any valid SPS has been decoded,
ihevcd_parse_sei_payload scanned ps_codec->ps_sps_base using a loop
that could step past the array bounds and dereference an invalid pointer.

Initialize ps_sps to NULL, check each entry's validity within bounds,
and return safely if no valid SPS is present.

(cherry picked from commit d42200d2f2)
2026-09-02 08:55:28 -07:00
Vivek R Jadhav
b20742d4ab libhevcdec: Add support for High Precision Weighted Prediction in HBD
Test: ./hevcdec
2026-09-02 08:38:08 -07:00
Vivek R Jadhav
0fbc9e65be libhevcdec: Add deblocking support for YUV444 HBD
Test: ./hevcdec
2026-08-31 09:40:08 -07:00
Vivek R Jadhav
34bfb05bf1 libhevcdec: Update SAO support for 444 HBD 2026-08-31 09:39:45 -07:00
Vivek R Jadhav
cb339fd3d1 libhevcdec: Fix luma stride in PCM sample copying for HBD
For High Bit Depth streams, pixel samples occupy 2 bytes (i4_pixel_size_y = 2).
In ihevcd_iquant_itrans_recon_ctb, the luma row offset in the destination buffer
for IPCM blocks was computed using `i * pic_strd` rather than `i * pic_strd *
i4_pixel_size_y`. This caused luma rows in IPCM blocks to overwrite previous rows
and corrupt reconstructed pixels.

Updated the row offset indexing to multiply by i4_pixel_size_y.

Test: ./hevcdec
2026-08-31 09:37:15 -07:00
Vivek R Jadhav
de64668c40 libhevcdec: Fix issues seen in 422 8 bit intra prediction
Some checks failed
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Has been cancelled
- In 4:2:2 chroma format, transform blocks are partitioned into
  two square sub-TUs (subtu_idx == 0 and subtu_idx == 1).
- Fix neighbor availability bitfield mapping for sub-TU 0 and sub-TU 1
  based on trans_size (8, 16, 32).
- Add reference documentation from ITU-T H.265 Section 7.3.8.8 and
  Section 8.4.4.2.2.

Test: ./hevcdec

Change-Id: I013e44e024258f2f84690fdc0109201129042155
2026-08-28 05:40:22 +00:00
Vivek R Jadhav
0d889fcf00 libhevcdec: Fix chroma SAO neighbor handling for CTB size 16
- For CTB size 16 in 4:2:2, sub-block width is 0, causing the Top
  and Current SAO blocks to be skipped.
- Fix Top-Right neighbor in Left block to read from picture buffer
  when ctb_size == 16 and ctb_y != 0, while keeping line buffer for
  larger CTBs (32, 64).
- Fix Bottom-Left neighbor in Left block to read from picture buffer
  when ctb_size == 16 to avoid uninitialized backup buffer access.
- Generalize Top-Left block condition to (8 * v_samp_factor).

Test: ./hevcdec

Change-Id: I013e44e024258f2f84690fdc0109210129042245
2026-08-28 05:40:03 +00:00
Narayan Kalaburgi
df28e1e8ab libhevcdec: Implement 10-bit decoding support for Cross Component Prediction
Some checks failed
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Has been cancelled
This commit implements HBD inverse transform residual functions, which is a
prerequisite to enable 10-bit decoding with Cross Component Prediction (CCP).

When CCP is enabled, the inverse transform and prediction addition cannot be
performed in a single pass (`itrans_recon`). Instead, the decoder must first
compute the unclipped transform residuals (`itrans_res`), scale them for CCP,
and then add the prediction. For 10-bit bitstreams, the decoder was missing
HBD implementations for `itrans_res` and improperly falling back to 8-bit
implementations. This resulted in the use of an incorrect second-stage inverse
transform shift (hardcoded to 12 instead of `20 - bit_depth`), significantly
corrupting the residuals.

Key Changes:
1. Created `common/ihevc_hbd_itrans_res.c` providing mathematically compliant
   HBD implementations of `itrans_res` for all Transform Unit sizes (4x4, 8x8,
   16x16, 32x32, and DC) using intermediate `CLIP_S16` logic and dynamic
   bit-depth shifting (`20 - bit_depth`).

2. Implemented `ihevc_hbd_chroma_recon_nxn_ccp` to properly scale 10-bit residuals
   with the cross-component alpha and add the prediction.

3. Modified `ihevcd_iquant_itrans_resi_recon_tu_plane` to dynamically branch to
   `ps_codec->apf_hbd_itrans_res` and `ihevc_hbd_chroma_recon_nxn_ccp` when
   `pixel_size > 1`. This cleanly handles 10-bit CCP while keeping 8-bit paths
   untouched.
2026-08-24 05:35:06 +00:00
Vivek R Jadhav
21c7ab373d libhevcdec: Update dynamic size allocation for HBD
Test: ./hevcdec
2026-08-24 05:33:38 +00:00
Harish Mahendrakar
57199ce059 Fix hbd sao for 422 2026-08-23 05:26:29 +00:00
Harish Mahendrakar
dd439b3a40 hevcdec: fix HBD chroma SAO ctb-size check for 4:4:4
Some checks are pending
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Waiting to run
Earlier condition in ihevcd_hbd_sao_shift_ctb was hardcoded
for 420 with luma ctb size as 16. Updated the condition to scale
for other chroma factors with vert and horz subsample factors.
2026-08-22 21:17:29 +00:00
Sushant
dc7cdc11b2 hevcdec: fix chroma SAO ctb-size check for 4:4:4
Earlier condition was correctly hardcoded for 420 with
luma ctb size as 16. Updated the condition to scale for
other chroma factors with vert, and horz subsample factor.

Change-Id: I013e67e024258f2f84690fdcc01b4cd52f0fac52
(cherry picked from commit 7da5afcd72)
2026-08-22 21:17:29 +00:00
Harish Mahendrakar
224370bb21 libhevcdec: Fix compiler warnings in ihevcd_parse_slice
Some checks are pending
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Waiting to run
- Explicitly cast IHEVCD_SUCCESS to IHEVCD_ERROR_T in ihevcd_10bd_parse_sao to fix -Wimplicit-enum-enum-cast.
- Fix pointer comparison in ihevcd_parse_slice_data by replacing UWORD32 pointer cast with UWORD8* arithmetic to fix -Wpointer-to-int-cast.
2026-08-22 02:33:24 +00:00
Harish Mahendrakar
4d290449c1 Add support to return bit depth after decode header call 2026-08-22 02:22:06 +00:00
Rakesh Kumar
c38cfe068d hevcdec: Remove rext generic function pointer override for 422/444
Some checks are pending
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Waiting to run
With SIMD optimizations updated and enabled for 422 and 444 chroma formats,
the fallback override in ihevcd_init_function_ptr_rext_generic is no longer
necessary.

Test: ./build
(cherry picked from commit e3ce7e69cb)
2026-08-19 22:18:26 +00:00
Rakesh Kumar
93a34ee902 hevcdec: Enable assembly and intrinsic intra prediction functions for 444 and 422 chroma formats
Remove generic C overrides for chroma and luma intra prediction in ihevcd_init_function_ptr_rext_generic to allow architecture-specific assembly and SIMD intrinsics to be used during 422 and 444 decoding.

(cherry picked from commit efa8b27448)
2026-08-19 22:18:26 +00:00
Narayan Kalaburgi
e8aef78199 libhevcdec: Add 10-bit decoding support for Implicit RDPCM
Some checks are pending
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Waiting to run
This commit enables 10-bit decoding support for Implicit Residual DPCM

Key changes include:
- Removed the ASSERT(0) bypass limitation in ihevcd_iquant_itrans_resi_recon_tu_plane when i4_pixel_size_y > 1.
- Dynamically determining the bit_depth for luma/chroma plane.
- Branching the apf_recon calls to correctly use apf_hbd_recon for HBD reconstruction.
2026-08-19 14:48:24 +00:00
Vivek R Jadhav
36cb41a03d libhevcdec: Fix slice QP delta lower bound validation for HBD
According to ITU-T H.265 Section 7.4.7.1, the initial SliceQpY value
shall be in the range of -QpBdOffsetY to +51, inclusive, where
QpBdOffsetY = 6 * (bit_depth_luma - 8).

Previously, the slice_qp_delta validity check in ihevcd_parse_slice_header
assumed an 8-bit lower bound of MIN_HEVC_QP (0), causing valid negative
slice QP values in high bit depth (10-bit/12-bit) streams to fail header
parsing with IHEVCD_INVALID_PARAMETER.

Updated the lower bound check to account for (6 * bit_depth_luma_minus8),
allowing valid HBD low QP bitstreams (such as QP = 0) to parse and decode
correctly.

Test: ./hevcdec
2026-08-19 14:32:49 +00:00
Vivek R Jadhav
4a17459d7a libhevcdec: Fix chroma QP capping for YUV422/444 HBD quantization
Apply Min(chroma_qp, 51) cap before adding QpBdOffsetC in HBD path for YUV422
and YUV444, matching the HEVC specification (Section 8.6.2).

Test: ./hevcdec
2026-08-19 14:32:49 +00:00
Narayan Kalaburgi
268af95978 libhevcdec: Add dynamic bitstream buffer reallocation for edge cases
Some checks failed
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Has been cancelled
This commit introduces on-the-fly dynamic reallocation to safely decode
extreme edge-case bitstreams (e.g., random noise causing CABAC inflation)
that exceed standard MaxCPB size constraints.

It adds a dedicated `ihevcd_reallocate_dynamic_bitstream_buf` setup
function in `ihevcd_api.c`. If an incoming bitstream exceeds the currently
allocated internal buffer during parsing (`ihevcd_decode.c`), the decoder
will cleanly reallocate the buffer. This prevents truncation failures and
memory corruption for highly incompressible streams.
2026-08-17 18:50:13 +00:00
Narayan Kalaburgi
00cd256a04 libhevcdec: Fix missing chroma ref filtering function call for HBD 444 2026-08-17 18:50:13 +00:00
Narayan Kalaburgi
fb13a491ed libhevc: Implement 10-bit 444 sp to p Output format conversion
This commit implements the output formatting stage required to output
uncompressed 10-bit 444 frames to the application.

Changes include:
- Added `ihevcd_fmt_conv_hbd_444sp_to_444p` to handle de-interleaving of
  16-bit U and V chroma channels into a planar format.
- Leveraged existing `ihevcd_fmt_conv_luma_copy` for 16-bit Luma copying
  by doubling the width and stride parameters.
- Hooked the new conversion function into `ihevcd_fmt_conv` when processing
  `IV_YUV_444P` formats with `pixel_size > 1`.
2026-08-14 21:34:32 +00:00
Narayan Kalaburgi
5782c001a3 libhevc: Implement HBD 444 chroma inv txfm & Recon
This commit adds the core math and CTB integration required for
inverse transform and reconstruction of 10-bit 4:4:4 chroma blocks.

Changes include:
- Added `ihevc_hbd_chroma_itrans_recon_32x32.c` to support the
  maximum 32x32 chroma block size required by the 444 profile.
- Added 10-bit chroma recon functions in `ihevc_hbd_chroma_recon.c`.
- Updated CTB decoding in `ihevcd_iquant_itrans_recon_ctb.c` to
  dynamically calculate 10-bit QP indices for 444 chroma blocks while
  preserving the original 420 fallback behavior.
- Updated headers with new HBD function declarations.
2026-08-14 21:34:32 +00:00
Narayan Kalaburgi
f90307a9d6 libhevc: Implement 10-bit 444 Chroma Intra-Prediction
This commit adds spatial intra-prediction support for 10-bit 444
chroma blocks during the decoder's prediction stage.

Changes include:
- Updated ihevc_hbd_chroma_intra_pred_filters.c to add 444 scaling
  (sub_sample = 2 vs sub_sample = 1).
- Added support for 32x32 chroma block predictions (nt == 32), which
  is the maximum chroma transform unit size in the 444 profile.
- Integrated the new filtering logic by updating the CTB intra-prediction
  loop in ihevcd_iquant_itrans_recon_ctb.c
2026-08-14 21:34:32 +00:00
Harish Mahendrakar
a2ff0ddeff libhevcdec: Cast pu1_pic_qp to WORD8 * in boundary strength calculation
Some checks are pending
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Waiting to run
Cast pu1_pic_qp (UWORD8 *) to (WORD8 *) when assigning to pi1_qp
to resolve -Wpointer-sign compiler error.

Test: mm -j64 SANITIZE_TARGET=address SANITIZE_HOST=address
2026-08-14 01:13:07 +00:00
Vivek R Jadhav
c4025d1ec0 libhevcdec: Fix chroma QP derivation for YUV422 HBD
Bypass 420 chroma QP mapping table for YUV422 and YUV444 in HBD path.
2026-08-13 01:17:59 +00:00
Vivek R Jadhav
c8c9eb7e0b libhevcdec: Add support for conversion from 422 10 bit to 420 10 bit
Test: ./hevcdec
2026-08-13 01:17:59 +00:00
Vivek R Jadhav
51c80727c3 libhevcdec: Add initial support for YUV422 10 bit
Test: ./hevcdec
2026-08-13 01:17:59 +00:00
Harish Mahendrakar
2a74434513 Few minor cleanups in headers to minimize the differences with main branch
Some checks failed
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Has been cancelled
2026-08-12 05:24:06 +00:00
Rakesh Kumar
35eb80040b Remove dead dependency on decoder e_profile in hbd branch
Some checks are pending
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Waiting to run
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Waiting to run
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Waiting to run
Remove vestigial HEVC_DEC_PROFILE_T enum and e_profile member from codec_t, along with its hardcoded initialization in ihevcd_init and assignment block in ihevcd_parse_sps. All dynamic bit depth, pixel size, and function selection logic in HBD relies directly on bitstream syntax elements.

TAG=agy
CONV=af8f01f3-0862-4fb5-a5ce-b37c3025b633
2026-08-11 19:49:05 +00:00
Harish Mahendrakar
c5ad9a03e3 Remove SAO wrapper
Some checks failed
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Has been cancelled
2026-08-09 23:47:45 +00:00