feat(libSceVideodec): implement the video decoder on top of libSceVideodec2 #8094

Merged
slick-daddy merged 2 commits from upstream-pr/8094 into main 2026-10-21 04:55:51 +00:00
slick-daddy commented 2026-10-19 21:21:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slick-daddy on 2026-10-19T21:21:18Z.


What

libSceVideodec's five exports were stubs that threw. Decoder creation, decoding, flushing, resetting and deleting are now implemented with the structure layouts of shadPS4's PS4 library, and the decode runs through libSceVideodec2, which decodes H.264 with FFmpeg. The picture is copied into the caller's frame buffer as NV12 with the pitch aligned to 64 and the coded height the decoder reports, the chroma after the luma rows, and the picture information holds the timestamps and the crop offsets in the unit the H.264 offsets use. A guest test decodes the shared H.264 fixture through the library, both as it is and with a sequence parameter set that crops the picture, and checks the pictures against the reference hashes, the display order, the geometry, the crop and the argument errors.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, ctest --test-dir build -R "guest_videodec$|guest_videodec2|guest_vdecsw" passes. No title was run: no game dump was available here. python3 tools/check_conventions.py --base origin/main and python3 tools/pr_overlap.py --branch newwy pass.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4927591413 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8094). Originally posted by [slick-daddy](https://github.com/slick-daddy) on 2026-10-19T21:21:18Z. --- ### What libSceVideodec's five exports were stubs that threw. Decoder creation, decoding, flushing, resetting and deleting are now implemented with the structure layouts of shadPS4's PS4 library, and the decode runs through libSceVideodec2, which decodes H.264 with FFmpeg. The picture is copied into the caller's frame buffer as NV12 with the pitch aligned to 64 and the coded height the decoder reports, the chroma after the luma rows, and the picture information holds the timestamps and the crop offsets in the unit the H.264 offsets use. A guest test decodes the shared H.264 fixture through the library, both as it is and with a sequence parameter set that crops the picture, and checks the pictures against the reference hashes, the display order, the geometry, the crop and the argument errors. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, `ctest --test-dir build -R "guest_videodec$|guest_videodec2|guest_vdecsw"` passes. No title was run: no game dump was available here. `python3 tools/check_conventions.py --base origin/main` and `python3 tools/pr_overlap.py --branch newwy` pass. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-19 21:22:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T21:22:09Z.


Progress report (339217e → 51c6b38)

📈 System libraries: 64.03% (+0.07%, +5 implemented functions)

✅ 5 implemented
Library Name
libSceVideodec sceVideodecCreateDecoder
libSceVideodec sceVideodecDecode
libSceVideodec sceVideodecDeleteDecoder
libSceVideodec sceVideodecFlush
libSceVideodec sceVideodecReset
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6277599458 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8094#issuecomment-6277599458). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T21:22:09Z. --- <!-- progress-report --> ### Progress report (339217e → 51c6b38) 📈 **System libraries**: 64.03% (+0.07%, +5 implemented functions) <details> <summary>✅ 5 implemented</summary> | Library | Name | | - | - | | libSceVideodec | `sceVideodecCreateDecoder` | | libSceVideodec | `sceVideodecDecode` | | libSceVideodec | `sceVideodecDeleteDecoder` | | libSceVideodec | `sceVideodecFlush` | | libSceVideodec | `sceVideodecReset` | </details>
nikowolf123 commented 2026-10-20 22:03:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-20T22:03:55Z.


CodedSize is written as if libSceVideodec2 might report the visible size. It never does. Videodec2 opens FFmpeg with apply_cropping = 0 and reports the AVFrame's size as-is (L492). FFmpeg's avcodec.h documents that with 0 "the width/height fields of the output frames will be set to the coded dimensions and the crop_* fields will describe the cropping rectangle". Videodec2's own test also checks frameHeight == CodedHeight (GuestVideodec2.cpp#L544).

So size is always a multiple of 16. The first branch fires whenever one axis's crop adds up to a nonzero multiple of 16, and then it counts the crop a second time. That happens with deliberate SPS crops, or with a field-coded 1280x720 stream, which is coded at 736 rows.

Example: a 1920x1072 stream coded as 1920x1088 with frame_crop_top_offset = frame_crop_bottom_offset = 4. Videodec2 reports 1920x1088 with crop 8/8, and CodedSize(1088, 8, 8) returns 1104. Decode then needs 3,179,520 bytes. A buffer sized the way the PR's test sizes it (pitch × coded height × 1.5 = 3,133,440) gets 0x80C1000B on every picture. Each refused picture is lost, because Videodec2 has already dequeued it. With a larger buffer the caller gets frameHeight 1104, rows 1088-1103 repeat row 1087, and offsets 4/4 leave a 1088-row window instead of 1072. A left+right crop of 8+8 inflates the width the same way (1936, pitch 1984).

I checked this with the PR's own test. I replaced only the shared fixture's SPS (bytes 10-34) with the same SPS cropping 4 at the top and 4 at the bottom: 67 64 00 0a ac d9 44 7f 29 70 11 00 00 03 00 01 00 00 03 00 3c 0f 12 25 96. The coded pictures don't change, so the existing hashes still apply. At abf83aa, guest_videodec fails with decode of unit 2 failed with -2134835189 (0x80C1000B). With this change in Measure, both the modified fixture and the original one pass:

geometry.codedWidth = output.frameWidth;
geometry.codedHeight = output.frameHeight;

After that change, CodedSize, the visible/coded split in Geometry and the row-repeat loops in CopyPicture (L271) no longer do anything and can be removed. The debt sentence at libSceVideodec.md#L13 about repeated crop rows and lost top/side rows is also wrong, because the caller always gets the whole coded picture. Running testDecode on the cropped fixture as well would cover this case.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6302766558 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8094#issuecomment-6302766558). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-20T22:03:55Z. --- [`CodedSize`](https://github.com/boykopovar/AnyPS5/blob/abf83aa4a8c3930dd7541b1d1d690d168697706f/core/libs/prx/libSceVideodec/Export.cpp#L196) is written as if libSceVideodec2 might report the visible size. It never does. Videodec2 opens FFmpeg with [`apply_cropping = 0`](https://github.com/boykopovar/AnyPS5/blob/abf83aa4a8c3930dd7541b1d1d690d168697706f/core/libs/prx/libSceVideodec2/Export.cpp#L377) and reports the AVFrame's size as-is ([L492](https://github.com/boykopovar/AnyPS5/blob/abf83aa4a8c3930dd7541b1d1d690d168697706f/core/libs/prx/libSceVideodec2/Export.cpp#L492)). FFmpeg's `avcodec.h` documents that with 0 "the width/height fields of the output frames will be set to the coded dimensions and the crop_* fields will describe the cropping rectangle". Videodec2's own test also checks `frameHeight == CodedHeight` ([GuestVideodec2.cpp#L544](https://github.com/boykopovar/AnyPS5/blob/abf83aa4a8c3930dd7541b1d1d690d168697706f/core/libs/tests/GuestVideodec2.cpp#L544)). So `size` is always a multiple of 16. The first branch fires whenever one axis's crop adds up to a nonzero multiple of 16, and then it counts the crop a second time. That happens with deliberate SPS crops, or with a field-coded 1280x720 stream, which is coded at 736 rows. Example: a 1920x1072 stream coded as 1920x1088 with `frame_crop_top_offset = frame_crop_bottom_offset = 4`. Videodec2 reports 1920x1088 with crop 8/8, and `CodedSize(1088, 8, 8)` returns 1104. Decode then needs 3,179,520 bytes. A buffer sized the way the PR's test sizes it (pitch × coded height × 1.5 = 3,133,440) gets 0x80C1000B on every picture. Each refused picture is lost, because Videodec2 has already dequeued it. With a larger buffer the caller gets frameHeight 1104, rows 1088-1103 repeat row 1087, and offsets 4/4 leave a 1088-row window instead of 1072. A left+right crop of 8+8 inflates the width the same way (1936, pitch 1984). I checked this with the PR's own test. I replaced only the shared fixture's SPS (bytes 10-34) with the same SPS cropping 4 at the top and 4 at the bottom: `67 64 00 0a ac d9 44 7f 29 70 11 00 00 03 00 01 00 00 03 00 3c 0f 12 25 96`. The coded pictures don't change, so the existing hashes still apply. At abf83aa, `guest_videodec` fails with `decode of unit 2 failed with -2134835189` (0x80C1000B). With this change in `Measure`, both the modified fixture and the original one pass: ```cpp geometry.codedWidth = output.frameWidth; geometry.codedHeight = output.frameHeight; ``` After that change, `CodedSize`, the visible/coded split in `Geometry` and the row-repeat loops in `CopyPicture` ([L271](https://github.com/boykopovar/AnyPS5/blob/abf83aa4a8c3930dd7541b1d1d690d168697706f/core/libs/prx/libSceVideodec/Export.cpp#L271)) no longer do anything and can be removed. The debt sentence at [libSceVideodec.md#L13](https://github.com/boykopovar/AnyPS5/blob/abf83aa4a8c3930dd7541b1d1d690d168697706f/docs/dev/debt/libSceVideodec.md#L13) about repeated crop rows and lost top/side rows is also wrong, because the caller always gets the whole coded picture. Running `testDecode` on the cropped fixture as well would cover this case.
slick-daddy commented 2026-10-20 22:13:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slick-daddy on 2026-10-20T22:13:40Z.


Verified: Videodec2 opens FFmpeg with apply_cropping = 0 and reports the AVFrame's size as-is, so the size is the coded size and crop_* only describes the cropping rectangle. The CodedSize heuristic counted the crop a second time whenever it added up to a multiple of 16.

Fixed in 51c6b3897:

  • Measure takes the frame's size as the coded size; CodedSize, the visible/coded split in Geometry and the row-repeat loops in CopyPicture are gone. The frame buffer now holds the coded picture, so the rows the crop covers are in it and the caller crops them.
  • The debt sentence about the repeated rows and the lost top and side rows was wrong and is corrected.
  • The fixture's SPS is also decoded with a crop of four units at the top and four at the bottom now (H264Fixture.hpp gains croppedStream() and accessUnits() takes a stream), and the guest test runs the decode over that stream too. At abf83aa that case fails with decode of unit 2 failed with -2134835189 (0x80C1000B); with the fix both streams pass.

One correction to my earlier report: the guest_videodec2 failure I mentioned was a stale build in my tree, not a real failure. It passes with the current sources.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6302959236 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8094#issuecomment-6302959236). Originally posted by [slick-daddy](https://github.com/slick-daddy) on 2026-10-20T22:13:40Z. --- Verified: Videodec2 opens FFmpeg with `apply_cropping = 0` and reports the AVFrame's size as-is, so the size is the coded size and `crop_*` only describes the cropping rectangle. The `CodedSize` heuristic counted the crop a second time whenever it added up to a multiple of 16. Fixed in 51c6b3897: - `Measure` takes the frame's size as the coded size; `CodedSize`, the visible/coded split in `Geometry` and the row-repeat loops in `CopyPicture` are gone. The frame buffer now holds the coded picture, so the rows the crop covers are in it and the caller crops them. - The debt sentence about the repeated rows and the lost top and side rows was wrong and is corrected. - The fixture's SPS is also decoded with a crop of four units at the top and four at the bottom now (`H264Fixture.hpp` gains `croppedStream()` and `accessUnits()` takes a stream), and the guest test runs the decode over that stream too. At abf83aa that case fails with `decode of unit 2 failed with -2134835189` (0x80C1000B); with the fix both streams pass. One correction to my earlier report: the `guest_videodec2` failure I mentioned was a stale build in my tree, not a real failure. It passes with the current sources.
github-actions[bot] commented 2026-10-20 22:28:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T22:28:47Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6044 core/libs/tests/H264Fixture.hpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6303197838 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8094#issuecomment-6303197838). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T22:28:47Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/H264Fixture.hpp` |
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!8094
No description provided.