Repository navigation
Conversation
libvmaf.h says the context takes ownership of both pictures, but a call that returned an error left them with the caller: a caller that followed the header leaked the pair, and one that took the pair from vmaf_preallocate_pictures() hung in vmaf_close(), which waits for every pool picture. Once the call has a context and two pictures, every return now drops both references through the caller's pointers. vmaf_picture_unref() clears the struct, so a caller that unrefs after the error gets -EINVAL and releases nothing twice. A call without a context, with only one of the two pictures, or the flush call still takes nothing. The new test submits a pair of another shape than the stream's and checks the references, the harmless second unref, the calls that take nothing, and that vmaf_close() returns with a pool pair; its meson entry carries a timeout so a regression fails instead of hanging.
vmaf_read_pictures incremented pic_cnt before a rejected picture pair passed validation and picture-pool setup. This made output pooling look for a score at the rejected index, leaving pooled metrics empty and including rejected input in fps. Add a public API regression test that writes JSON after five accepted pairs and a rejected mismatched pair. It verifies that the rejected pair is released and that the PSNR pooled metrics are populated. Signed-off-by: Lusoris <lusoris@pm.me>
mangeshraut712
left a comment
There was a problem hiding this comment.
A few ownership / error-handling gaps in the new vmaf_read_pictures failure paths:
-
libvmaf/src/libvmaf.c— aftertranslate_pictureforrefyou correctly release and return on error, but the followingtranslate_picturefordist(around thedist_host/dist_devicesetup) still has noif (err)check. A failed dist translate leaveserrset and falls into the extractor loop with incomplete host/device pictures. -
On the CUDA error returns you added inside the extractor loop (and after
check_ring_buffer/ ref translate),release_picture_pair(ref_in, dist_in)runs butref_host/ref_device/dist_host/dist_deviceare not unreferenced, so those translated pictures can leak. -
vmaf->pic_cnt++still happens beforecheck_ring_buffer/translate_picture/ extract. If any of those fail, the pictures are released butpic_cntstays incremented, so the next accepted frame sees a skewed count.
Also worth double-checking the thread_pool path: threaded_read_pictures_batch already unrefs the caller's pictures on the successful enqueue path (return vmaf_picture_unref(ref) | vmaf_picture_unref(dist)). If that combined unref returns non-zero, the new if (err) release_picture_pair(ref_in, dist_in) will unref again on already-cleared structs.
Under HAVE_CUDA, check_ring_buffer() and the reference translate_picture() can still reject the pair after pic_cnt was incremented; move the increment below them.
|
Thanks for the review.
|
vmaf_write_output() opens the output file in text mode, so on Windows
every newline is written as CRLF. test_read_pictures_output read the
file back in binary mode and looked for "{\n \"min\":", which
never matched under MSVC.
Read the file in text mode so CRLF folds back to LF, and accept a
short fread(): a text-mode read returns fewer bytes than ftell()
reports once CRLF pairs fold.
Signed-off-by: Lusoris <lusoris@pm.me>
Depends on #1652.
vmaf_read_pictures()counts a picture pair before checking it, so a pair that is then rejected still counts. This change moves the increment after the checks.Problem
vmaf->pic_cnt++runs beforevalidate_pic_params()andcheck_picture_pool(). When either of them rejects a pair (for example a 96x64 pair after 64x64 pairs), the call returns-EINVAL, butpic_cnthas already been incremented.The output writers use
pic_cntas the end of the pooling range, so the rejected index is part of it:<metric name="psnr_y" />with no values), because the rejected index has no score. Per-frame scores for the accepted pairs are still written.pic_cnt, so it counts the rejected pair.vmaf_score_pooled()with an explicit range is not affected.Reproduction: feed five 64x64 pairs, then one 96x64 pair (rejected with
-EINVAL), flush, and write JSON. Thepooled_metricssection has no PSNR entries.Change
This branch is stacked on #1652, so the diff here also shows its commit (
libvmaf: release both pictures on every return of vmaf_read_pictures()). Only the last commit belongs to this PR:libvmaf/src/libvmaf.c: incrementpic_cntonly aftervalidate_pic_params()andcheck_picture_pool()have accepted the pair. Nothing else changes.libvmaf/test/test_read_pictures_output.c: new test for the scenario above. It checks that the rejected pair is released, as libvmaf: release both pictures on every return of vmaf_read_pictures() #1652 specifies, then writes JSON and checks that the pooled PSNR metrics are present.Testing
Run on this branch (on top of #1652, 76afad3):
meson test -C build: 29 of 29 pass.libvmaf.chunk reverted, the new test fails (pooled psnr metrics should be populated after a rejected pair) andtest_read_pictures_releasefrom libvmaf: release both pictures on every return of vmaf_read_pictures() #1652 still passes.Related
#1639 also touches
vmaf_read_pictures(), in a hunk next to this line, and does not change where the count is incremented. #1652 and #1639 are unchanged by this PR.