diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a7f2745 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,19 @@ +name: Test + +on: + push: + branches: [master] + pull_request: + branches: [master] + workflow_dispatch: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v7 + - uses: prantlf/setup-v-action@v4 + - run: v test . diff --git a/README.md b/README.md index 5f16574..5be607d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,55 @@ +# H.264 bitstream parser for V +This module parses the H.264/AVC syntax needed by Vulkan Video applications: +NAL headers, sequence and picture parameter sets (SPS/PPS), video usability +information (VUI), and slice headers. -# h264 Video Decoder -Provides functions to decode h264 video data. -See [ITU-T H.264 (08/2021)](https://www.itu.int/ITU-T/recommendations/rec.aspx?rec=14659) for details. +It is **not** a video decoder: it does not perform entropy decoding, motion +compensation, inverse transforms, or produce pixels. The +[`v_vulkan_video`](https://github.com/antono2/v_vulkan_video) player uses these +parsed structures to prepare hardware decode operations. ## Install -`v install https://github.com/antono2/h264` +```bash +v install https://github.com/antono2/h264 +``` + +## Minimal example + +```v +import h264 + +mut stream := h264.Bitstream{} +stream.init([u8(0x67)]) // forbidden_zero_bit=0, nal_ref_idc=3, type=SPS + +mut header := h264.NetworkAbstractionLayerHeader{} +header.read_nal_header(mut stream) +assert header.type == .sequence_parameter_set +``` + +`Bitstream.init()` expects raw RBSP/NAL bytes in memory. Container extraction, +length prefixes or Annex-B start codes, emulation-prevention removal, frame +reordering, and decoded-picture management remain the caller's responsibility. + +## Safety and supported scope + +The parser exposes low-level syntax structures rather than a defensive media +API. Some invalid syntax is rejected with assertions, while truncated fields +can read as zero at end of input. Validate untrusted container lengths and NAL +boundaries before parsing them. + +The implementation covers the syntax exercised by the Vulkan Video H.264 +player and is not yet a claim of complete support for every profile, extension, +bit depth, chroma format, or interlaced stream. + +## Tests + +The included tests are software-only and require no GPU: + +```bash +v test . +``` + +They cover RBSP look-ahead behavior and representative High-profile SPS/PPS +parsing used by the player. diff --git a/h264.v b/h264.v index a29b9dc..46a2866 100644 --- a/h264.v +++ b/h264.v @@ -884,7 +884,7 @@ pub fn (mut sh SliceHeader) read_slice_header(nal &NetworkAbstractionLayerHeader } sh.read_ref_pic_list_reordering(mut b) if pps.weighted_pred_flag != 0 - && ((sh.is_slice_type(SH_SLICE_TYPE.p) || sh.is_slice_type(SH_SLICE_TYPE.sp)) + && (sh.is_slice_type(SH_SLICE_TYPE.p) || sh.is_slice_type(SH_SLICE_TYPE.sp) || (pps.weighted_bipred_idc == 1 && sh.is_slice_type(SH_SLICE_TYPE.b))) { sh.read_pred_weight_table(sps, pps, mut b) } diff --git a/v.mod b/v.mod index e53faad..1cd99ba 100644 --- a/v.mod +++ b/v.mod @@ -1,11 +1,11 @@ Module { name: 'h264' author: 'Anton Oreskin' - description: 'Decoder for the h264 video format' + description: 'Low-level H.264 bitstream and parameter-set parser' version: '1.0.0' repo_url: 'https://github.com/antono2/h264' vcs: 'git' - tags: ['V','h264','decoder'] + tags: ['V','h264','parser','bitstream'] license: 'MIT' dependencies: [] }