Repository navigation
fix(libSceVdecsw): report idrPictureFlag only for an H.264 IDR access unit - #21194
Merged
oneandonlydean merged 1 commit intoNov 16, 2026
Conversation
… unit The AVC picture info took idrPictureFlag from FFmpeg's AV_FRAME_FLAG_KEY, which FFmpeg also sets on a non-IDR picture whose access unit carries a recovery point SEI with recovery_frame_cnt 0. Videodec2 now records, as it already does for HEVC, whether the first VCL NAL unit of the access unit has nal_unit_type 5 (H.264 IdrPicFlag), and Vdecsw reports that. The HEVC flags and keyFrame are unchanged.
PrivacyOnion
approved these changes
Nov 16, 2026
PrivacyOnion
left a comment
Contributor
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 7bd610087c:
- Conventions:
tools/check_conventions.pypassed;git diff --checkclean. - Build:
guest_vdecsw_testsbuilt cleanly. - CTest (
guest_vdecsw):1/1 Test #4788: guest_vdecsw ..................... Passed 0.05 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceVdecsw/Export.cpp,core/libs/prx/libSceVideodec2/Export.cpp,core/libs/prx/libSceVideodec2/include/PictureMetadata.hppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #4788: guest_vdecsw .....................***Failed 0.07 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified
StartsAvcIdrincore/libs/prx/libSceVideodec2/Export.cpp:389-397safely checksindex + 3 < unit.size()before indexingunit[index .. index + 3], mirrorsStartsHevcIdr, and inspects the first VCL NAL unit (nal_unit_type1..5) fortype == 5(IDR). - Verified
Picture.avcIdrincore/libs/prx/libSceVideodec2/Export.cpp:220,664,832andPictureHeader.avcIdrincore/libs/prx/libSceVideodec2/include/PictureMetadata.hpp:25are initialized and propagated throughVideodec2PictureHeader_nid_no_patchtopictureInfoincore/libs/prx/libSceVdecsw/Export.cpp:163. - Verified
testDecodeandtestDecodeRecoveryPointincore/libs/tests/GuestVdecsw.cpp:228-295insert a recovery point SEI (recovery_frame_cnt == 0) into a non-IDR access unit and verifyinfo.idrPictureFlagmatchesunit == 0 ? 1 : 0across display-reordered frames. - Verified LP64/LLP64 portability (
std::size_t,std::uint8_t,bool), lock scopes insceVideodec2Decode_nid_postfixandVideodec2PictureHeader_nid_no_patch, and compliance withAGENTS.md.
- Verified
Looks Good To Me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
On
maind4a1472pictureInfo(core/libs/prx/libSceVdecsw/Export.cpp:122-175), behindsceVdecswGetAvcPictureInfoandsceVdecswGetPictureInfo, fillsAvcPictureInfo.idrPictureFlagfromheader.keyFrame(:163). That field isPicture.idr(core/libs/prx/libSceVideodec2/Export.cpp:820), whichEmitDecodedsets from FFmpeg'sAV_FRAME_FLAG_KEYon the output frame (:470). FFmpeg sets that flag on more than IDR pictures: the pinned3rdparty/ffmpeg-core(9ac4cfd) builds the vcpkg FFmpeg port at df8bfe51, version 7.1.1, and in FFmpeg n7.1.1libavcodec/h264dec.c:896-897addsAV_FRAME_FLAG_KEYto the output frame of any picture whose access unit carries a recovery point SEI withrecovery_frame_cnt0 (h264_slice.c:510copies the count from the access unit's SEI), whileh264_slice.c:1651sets it on the picture itself only for an IDR slice. A P, B or open-GOP I picture with such an SEI is therefore reported as IDR (counter-check under Tested). The field is H.264'sIdrPicFlag, which is 1 exactly whennal_unit_typeis 5 (ITU-T H.264 (08/2024), 7.4.1, equation 7-1). The repository already uses that definition twice: Videodec2's own AVC picture info setsinfo.idrPictureFlag = first->idr(core/libs/prx/libSceVideodec2/AvcMetadata.cpp:341, withidr=type == 5at:314, #12633), and for HEVC #7517 (3aee4b3) separated the NAL-basedhevcIdr(StartsHevcIdr,Export.cpp:378-386, set at:652) from FFmpeg's key flag, which Vdecsw reports asirapPictureFlag(Vdecsw/Export.cpp:143-144). AVC was the only path left on the key flag. This is consistency with the standard and the sibling code, not a measurement of console output.StartsAvcIdr, next toStartsHevcIdrand built the same way, scans the Annex B access unit for start codes; the first NAL unit of type 1 to 5 (a coded slice or slice data partition, the VCL types of Table 7-1, asCarriesAvcSliceat:368-376counts them) decides, and the result istype == 5.sceVideodec2Decode_nid_postfixstores it astagged.avcIdrfor an AVC decoder next totagged.hevcIdr,PictureHeader(core/libs/prx/libSceVideodec2/include/PictureMetadata.hpp:15-25) gainsbool avcIdras its last member,Videodec2PictureHeader_nid_no_patchpasses it last in the positional initializer, and Vdecsw's AVC branch reportsheader.avcIdr.keyFrame,Export.cpp:470and the HEVCidrPictureFlagandirapPictureFlagare unchanged, and so is Videodec2's own AVC picture info. The NAL scan is used instead ofstored.avc.info.idrPictureFlagbecauseVideodec2Avc::Parse_nid_no_patchcatches slice-header errors (AvcMetadata.cpp:326-329) and can leave that info unset for a unit that has a slice; the scan is defined for every unit and mirrors the HEVC precedent.recovery_frame_cntis 0. A conforming access unit cannot mix IDR and non-IDR slices (7.4.1, semantics ofnal_unit_type), so the first VCL NAL unit stands for the whole picture. The other readers ofPictureHeader,libSceVideodec(core/libs/prx/libSceVideodec/Export.cpp:231,:300, read byMeasureat:82) andGuestVideodec2.cpp:318, value-initialize it with{}and read named fields, so the appended member changes nothing for them.docs/dev/debt/libSceVdecsw.mdsays only that the AVC picture info carries Videodec2's leading fields and the cropping fields, which stays true, and no entry underdocs/dev/debt/mentionsidrPictureFlagorkeyFramefor Vdecsw.core/libs/tests/GuestVdecsw.cpp(ctestguest_vdecsw; no other test name starts with it, no CMake change).testDecodenow takes the access units, and itsidrPictureFlagcheck moved out of the display-order check into its own check,info.idrPictureFlag == (unit == 0 ? 1 : 0)withunit = DisplayOrderUnits[pictures], which for the plain fixture is the oldpictures == 0; it has its own line so that a failure namesidrPictureFlaginstead of the display order. The fixtureH264Fixture::Streamhas six access units: unit 0 holds an AUD, SPS, PPS, an x264 user-data SEI and an IDR slice, and units 1 to 5 an AUD and one non-IDR slice (type 1) each; it has no recovery point SEI, so no non-IDR picture is flagged as key by FFmpeg. The newtestDecodeRecoveryPointchecks that unit 1 is an AUD followed by a type 1 slice (a reference P picture,nal_ref_idc2, displayed at index 3), inserts the recovery point SEI00 00 00 01 06 06 01 84 80(H.264 D.1.8:recovery_frame_cnt0,exact_match_flag0,broken_link_flag0,changing_slice_group_idc0) after its 6-byte AUD and runstestDecodeon the result. Every picture must still matchPictureHashes, andcheckGenericPictureInfocompares thesceVdecswGetPictureInfobytes with thesceVdecswGetAvcPictureInforesult, so both exports are checked. The unchanged HEVC check (info.idrPictureFlagandinfo.irapPictureFlagat picture 0 only) passes.h264dec.c:896-897), not from anything host-specific.guest_vdecswis registered underif(BUILD_TESTING)with no host condition (core/libs/prx/libSceVdecsw/CMakeLists.txt:10-15). Without the change Vdecsw reports that flag, so the new case fails on Linux at display index 3 as it does here. Nothing was run on Linux here.pr_overlap.py --namesforsceVdecswGetAvcPictureInfoandsceVdecswGetPictureInfofinds no open pull request that implements them, andpr_overlap.py --branchreports no shared lines or exports with any open pull request (maind4a1472). The only open pull requests that change these files, fix(libSceVideodec2): safely copy guest decode and flush buffers #20614 (PrivacyOnion) and fix(videodec2): validate ClearOutput destinations upfront before mutating output #21081 (Kikoarl), both incore/libs/prx/libSceVideodec2/Export.cpp, do not mentionidrPictureFlag,keyFrame,avcIdrorPictureHeader.Tested
Windows 11, WinLibs GCC 15.2.0, Ninja, Release,
BUILD_TESTING=ON, build directory configured through its 8.3 short path, on d4a1472. Built withcmake --build <build> --parallel 4 --target guest_vdecsw_tests guest_videodec_tests guest_hevc_metadata_tests guest_videodec2_tests guest_videodec2_hevc_aliases_tests guest_videodec2_unimplemented_tests; the counter-check and the negative control were built with--target guest_vdecsw_testsonly. Every build exited 0. Before every run eachcore/libs/libs/unpatched/*.prxthat also exists in<build>/tests(libSceVdecsw.prx,libSceVideodec.prxonce built,libSceVideodec2.prx,libc.prx,libkernel.prx) was copied there withcmake -E copy_if_different, and themd5sumof each copy matched its source each time.ctest --test-dir <build> -R '^guest_vdecsw$' --output-on-failurefails withpicture 3 IDR flag differs from its nal_unit_type. The plain fixture run before it passes, and pictures 0 to 2 of the recovery point run, hashes included, pass before the failure. This confirms at run time that FFmpeg flags the recovery point picture as key.ctest --test-dir <build> -R '^guest_vdecsw$' --output-on-failurepasses.ctest --test-dir <build> -R '^(guest_vdecsw|guest_videodec|guest_videodec2|guest_videodec2_hevc_aliases|guest_videodec2_unimplemented|guest_hevc_metadata)$' --output-on-failureruns the 6 tests oflibSceVdecsw,libSceVideodecandlibSceVideodec2(--show-only=json-v1lists no other): 6/6 passed.guest_vdecsw_testsrebuilt,-R '^guest_vdecsw$'failed again withpicture 3 IDR flag differs from its nal_unit_type. With the change restored (the source diff byte-identical to the saved patch) and all six targets rebuilt, the same 6-test command passed 6/6.python tools/check_conventions.py --base upstream/main --head HEADwith this title and description passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)