[FFmpeg-devel] [PATCH] force dnxhd encoder to be independent of qsort internals

Reimar Döffinger Reimar.Doeffinger
Sun Sep 20 11:08:45 CEST 2009


On Sat, Sep 19, 2009 at 01:16:51PM +0200, Reimar D?ffinger wrote:
> this change makes sure there are no equal elements in the data passed to
> qsort, thus making sure the result is independent of implementation
> internals.

Very slightly different, swapped the mb comparison so the original order
is kept by default. Seems nicer and might decreases needed memory
bandwidth if a lot of values are identical (very unlikely I think).
-------------- next part --------------
Index: libavcodec/dnxhdenc.c
===================================================================
--- libavcodec/dnxhdenc.c	(revision 19926)
+++ libavcodec/dnxhdenc.c	(working copy)
@@ -653,7 +653,12 @@
 
 static int dnxhd_rc_cmp(const void *a, const void *b)
 {
-    return ((const RCCMPEntry *)b)->value - ((const RCCMPEntry *)a)->value;
+    int delta = ((const RCCMPEntry *)b)->value - ((const RCCMPEntry *)a)->value;
+    if (delta)
+        return delta;
+    // if value is the same, keep them in the original order, this forces
+    // qsort to give identical results over implementations.
+    return ((const RCCMPEntry *)a)->mb - ((const RCCMPEntry *)b)->mb;
 }
 
 static int dnxhd_encode_fast(AVCodecContext *avctx, DNXHDEncContext *ctx)
Index: tests/vsynth.regression.ref
===================================================================
--- tests/vsynth.regression.ref	(revision 19926)
+++ tests/vsynth.regression.ref	(working copy)
@@ -162,13 +162,13 @@
 14400000 ./tests/data/a-dv50.dv
 a2ff093e93ffed10f730fa21df02fc50 *./tests/data/dv50.vsynth.out.yuv
 stddev:    1.72 PSNR: 43.37 bytes:  7603200/  7603200
-8ff3c18dabe28509b4e5b3fdaa7f0856 *./tests/data/a-dnxhd-1080i.mov
+474437fb5a7b4b12d41ae1edb49b1a7e *./tests/data/a-dnxhd-1080i.mov
 30311415 ./tests/data/a-dnxhd-1080i.mov
-52f50a8031eebf980a1303e4744a49f8 *./tests/data/dnxhd.vsynth.out.yuv
+426a1325042c65a631efd8436f157be7 *./tests/data/dnxhd.vsynth.out.yuv
 stddev:    6.28 PSNR: 32.16 bytes:  7603200/  7603200
-d206daba40f3c1be8b834de8a41e984c *./tests/data/a-dnxhd-720p.dnxhd
+3f6e753c015ed59ee8067f3d8b7dd29b *./tests/data/a-dnxhd-720p.dnxhd
 22937600 ./tests/data/a-dnxhd-720p.dnxhd
-d7f14ee0dd3a4df95f05999677da348b *./tests/data/dnxhd.vsynth.out.yuv
+5e14a3890705c6c62032822b52ea14e6 *./tests/data/dnxhd.vsynth.out.yuv
 stddev:    6.39 PSNR: 32.00 bytes:  7603200/  7603200
 c0a42b916489d3c1d0a315974821e28d *./tests/data/a-dnxhd-720p-rd.dnxhd
 22937600 ./tests/data/a-dnxhd-720p-rd.dnxhd



More information about the ffmpeg-devel mailing list