Fixes ticket #4628.

The problem arose, in the sample file at least, in the last block where the
minimum and maximum Rice partition orders were both 0. In that case, and any
other where pmax == pmin, the original UINT32_MAX placeholder value for
bits[opt_porder] was getting overwritten before the comparison to check if the
current partition order is a new optimal, so the correct partition order and
RiceContext params were not being set.

Regression test sample to be added to `$(SAMPLES)/audio-reference/`:
http://thebuds.net/chorusnoise_2ch_44kHz_s16.wav

Signed-off-by: George Boyle <geo...@thebuds.net>
---
 libavcodec/flacenc.c | 2 +-
 tests/fate/flac.mak  | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index cdfeaf8..29bd999 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -705,7 +705,7 @@ static uint64_t calc_rice_params(RiceContext *rc,
     bits[pmin] = UINT32_MAX;
     for (i = pmax; ; ) {
         bits[i] = calc_optimal_rice_params(&tmp_rc, i, sums, n, pred_order, 
kmax, exact);
-        if (bits[i] < bits[opt_porder]) {
+        if (bits[i] < bits[opt_porder] || pmax == pmin) {
             opt_porder = i;
             *rc = tmp_rc;
         }
diff --git a/tests/fate/flac.mak b/tests/fate/flac.mak
index 4a13404..115cc96 100644
--- a/tests/fate/flac.mak
+++ b/tests/fate/flac.mak
@@ -6,6 +6,7 @@ FATE_FLAC += fate-flac-16-chmode-indep                          
        \
              fate-flac-16-lpc-cholesky                                  \
              fate-flac-16-lpc-levinson                                  \
              fate-flac-24-comp-8                                        \
+             fate-flac-rice-params                                      \
 
 fate-flac-16-chmode-%: OPTS = -ch_mode $(@:fate-flac-16-chmode-%=%)
 fate-flac-16-fixed:    OPTS = -lpc_type fixed
@@ -19,6 +20,9 @@ fate-flac-24-comp-%: OPTS = -compression_level 
$(@:fate-flac-24-comp-%=%)
 fate-flac-24-%: REF = $(SAMPLES)/audio-reference/divertimenti_2ch_96kHz_s24.wav
 fate-flac-24-%: CMD = enc_dec_pcm flac wav s24le $(subst 
$(SAMPLES),$(TARGET_SAMPLES),$(REF)) -c flac $(OPTS)
 
+fate-flac-rice-params: REF = 
$(SAMPLES)/audio-reference/chorusnoise_2ch_44kHz_s16.wav
+fate-flac-rice-params: CMD = enc_dec_pcm flac wav s16le $(subst 
$(SAMPLES),$(TARGET_SAMPLES),$(REF)) -c flac
+
 fate-flac-%: CMP = oneoff
 fate-flac-%: FUZZ = 0
 
-- 
2.4.3

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to