diff --git a/graphics/ffmpeg/Makefile b/graphics/ffmpeg/Makefile index f80d60dcf3e..cadf9994fc6 100644 --- a/graphics/ffmpeg/Makefile +++ b/graphics/ffmpeg/Makefile @@ -1,11 +1,11 @@ -# $OpenBSD: Makefile,v 1.147 2016/03/10 20:41:22 naddy Exp $ +# $OpenBSD: Makefile,v 1.148 2016/04/07 06:01:19 ajacoutot Exp $ COMMENT= audio/video converter and streamer V= 20160113 DISTNAME= ffmpeg-git-${V} PKGNAME= ffmpeg-${V} -REVISION= 6 +REVISION= 7 CATEGORIES= graphics multimedia MASTER_SITES= http://comstyle.com/source/ EXTRACT_SUFX= .tar.xz diff --git a/graphics/ffmpeg/patches/patch-libavcodec_aaccoder_twoloop_h b/graphics/ffmpeg/patches/patch-libavcodec_aaccoder_twoloop_h index e187bcab762..40fde5004d2 100644 --- a/graphics/ffmpeg/patches/patch-libavcodec_aaccoder_twoloop_h +++ b/graphics/ffmpeg/patches/patch-libavcodec_aaccoder_twoloop_h @@ -1,4 +1,4 @@ -$OpenBSD: patch-libavcodec_aaccoder_twoloop_h,v 1.3 2015/12/06 08:51:46 ajacoutot Exp $ +$OpenBSD: patch-libavcodec_aaccoder_twoloop_h,v 1.4 2016/04/07 06:01:19 ajacoutot Exp $ AAC encoder: refactor to resynchronize MIPS port @@ -12,9 +12,15 @@ avcodec/aac_tablegen: get rid of hardcoded tables entirely AAC encoder: improve SF range utilization ---- libavcodec/aaccoder_twoloop.h.orig Sat Dec 5 15:13:02 2015 -+++ libavcodec/aaccoder_twoloop.h Sat Dec 5 15:01:19 2015 -@@ -0,0 +1,755 @@ +AAC encoder: fix signed integer overflow + +AAC encoder: fix undefined behavior + +AAC encoder: fix initialization of minsf + +--- libavcodec/aaccoder_twoloop.h.orig Sun Apr 3 18:33:06 2016 ++++ libavcodec/aaccoder_twoloop.h Sun Apr 3 18:33:32 2016 +@@ -0,0 +1,763 @@ +/* + * AAC encoder twoloop coder + * Copyright (C) 2008-2009 Konstantin Shishkov @@ -94,7 +100,7 @@ AAC encoder: improve SF range utilization + int toomanybits, toofewbits; + char nzs[128]; + uint8_t nextband[128]; -+ int maxsf[128]; ++ int maxsf[128], minsf[128]; + float dists[128] = { 0 }, qenergies[128] = { 0 }, uplims[128], euplims[128], energies[128]; + float maxvals[128], spread_thr_r[128]; + float min_spread_thr_r, max_spread_thr_r; @@ -311,11 +317,19 @@ AAC encoder: improve SF range utilization + abs_pow34_v(s->scoefs, sce->coeffs, 1024); + ff_quantize_band_cost_cache_init(s); + ++ for (i = 0; i < sizeof(minsf) / sizeof(minsf[0]); ++i) ++ minsf[i] = 0; + for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { + start = w*128; + for (g = 0; g < sce->ics.num_swb; g++) { + const float *scaled = s->scoefs + start; ++ int minsfidx; + maxvals[w*16+g] = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled); ++ if (maxvals[w*16+g] > 0) { ++ minsfidx = coef2minsf(maxvals[w*16+g]); ++ for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) ++ minsf[(w+w2)*16+g] = minsfidx; ++ } + start += sce->ics.swb_sizes[g]; + } + } @@ -442,7 +456,7 @@ AAC encoder: improve SF range utilization + recomprd = 1; + for (i = 0; i < 128; i++) { + if (sce->sf_idx[i] > SCALE_ONE_POS) { -+ int new_sf = FFMAX(SCALE_ONE_POS, sce->sf_idx[i] - qstep); ++ int new_sf = FFMAX3(minsf[i], SCALE_ONE_POS, sce->sf_idx[i] - qstep); + if (new_sf != sce->sf_idx[i]) { + sce->sf_idx[i] = new_sf; + changed = 1; @@ -612,7 +626,7 @@ AAC encoder: improve SF range utilization + int cmb = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]); + int mindeltasf = FFMAX(0, prev - SCALE_MAX_DIFF); + int maxdeltasf = FFMIN(SCALE_MAX_POS - SCALE_DIV_512, prev + SCALE_MAX_DIFF); -+ if ((!cmb || dists[w*16+g] > uplims[w*16+g]) && sce->sf_idx[w*16+g] > mindeltasf) { ++ if ((!cmb || dists[w*16+g] > uplims[w*16+g]) && sce->sf_idx[w*16+g] > FFMAX(mindeltasf, minsf[w*16+g])) { + /* Try to make sure there is some energy in every nonzero band + * NOTE: This algorithm must be forcibly imbalanced, pushing harder + * on holes or more distorted bands at first, otherwise there's diff --git a/graphics/ffmpeg/patches/patch-libavcodec_aacenc_c b/graphics/ffmpeg/patches/patch-libavcodec_aacenc_c index 17eb0e58319..d3d7df4d251 100644 --- a/graphics/ffmpeg/patches/patch-libavcodec_aacenc_c +++ b/graphics/ffmpeg/patches/patch-libavcodec_aacenc_c @@ -1,4 +1,4 @@ -$OpenBSD: patch-libavcodec_aacenc_c,v 1.14 2016/03/09 17:29:36 ajacoutot Exp $ +$OpenBSD: patch-libavcodec_aacenc_c,v 1.15 2016/04/07 06:01:19 ajacoutot Exp $ aacenc: copy PRNG from the decoder @@ -76,8 +76,10 @@ aacenc: temporarily disable Mid/Side coding with multichannel files aacenc: use generational cache instead of resetting. +AAC encoder: fix valgrind errors + --- libavcodec/aacenc.c.orig Wed Jan 13 15:27:48 2016 -+++ libavcodec/aacenc.c Tue Mar 8 19:23:12 2016 ++++ libavcodec/aacenc.c Wed Apr 6 18:35:10 2016 @@ -29,6 +29,7 @@ * add sane pulse detection ***********************************/ @@ -169,7 +171,7 @@ aacenc: use generational cache instead of resetting. int ms_mode = 0, is_mode = 0, tns_mode = 0, pred_mode = 0; int chan_el_counter[4]; FFPsyWindowInfo windows[AAC_MAX_CHANNELS]; -@@ -517,10 +540,12 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP +@@ -517,19 +540,22 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP chans = tag == TYPE_CPE ? 2 : 1; cpe = &s->cpe[i]; for (ch = 0; ch < chans; ch++) { @@ -185,7 +187,18 @@ aacenc: use generational cache instead of resetting. samples2 = overlap + 1024; la = samples2 + (448+64); if (!frame) -@@ -537,7 +562,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP + la = NULL; + if (tag == TYPE_LFE) { +- wi[ch].window_type[0] = ONLY_LONG_SEQUENCE; ++ wi[ch].window_type[0] = wi[ch].window_type[1] = ONLY_LONG_SEQUENCE; + wi[ch].window_shape = 0; + wi[ch].num_windows = 1; + wi[ch].grouping[0] = 1; ++ wi[ch].clipping[0] = 0; + + /* Only the lowest 12 coefficients are used in a LFE channel. + * The expression below results in only the bottom 8 coefficients +@@ -537,7 +563,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP */ ics->num_swb = s->samplerate_index >= 8 ? 1 : 3; } else { @@ -194,7 +207,32 @@ aacenc: use generational cache instead of resetting. ics->window_sequence[0]); } ics->window_sequence[1] = ics->window_sequence[0]; -@@ -571,25 +596,34 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP +@@ -554,10 +580,23 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP + ics->tns_max_bands = wi[ch].window_type[0] == EIGHT_SHORT_SEQUENCE ? + ff_tns_max_bands_128 [s->samplerate_index]: + ff_tns_max_bands_1024[s->samplerate_index]; +- clip_avoidance_factor = 0.0f; ++ + for (w = 0; w < ics->num_windows; w++) + ics->group_len[w] = wi[ch].grouping[w]; ++ ++ /* Calculate input sample maximums and evaluate clipping risk */ ++ clip_avoidance_factor = 0.0f; + for (w = 0; w < ics->num_windows; w++) { ++ const float *wbuf = overlap + w * 128; ++ const int wlen = 2048 / ics->num_windows; ++ float max = 0; ++ int j; ++ /* mdct input is 2 * output */ ++ for (j = 0; j < wlen; j++) ++ max = FFMAX(max, fabsf(wbuf[j])); ++ wi[ch].clipping[w] = max; ++ } ++ for (w = 0; w < ics->num_windows; w++) { + if (wi[ch].clipping[w] > CLIP_AVOIDANCE_FACTOR) { + ics->window_clipping[w] = 1; + clip_avoidance_factor = FFMAX(clip_avoidance_factor, wi[ch].clipping[w]); +@@ -571,25 +610,34 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP ics->clip_avoidance_factor = 1.0f; } @@ -236,7 +274,7 @@ aacenc: use generational cache instead of resetting. memset(chan_el_counter, 0, sizeof(chan_el_counter)); for (i = 0; i < s->chan_map[0]; i++) { FFPsyWindowInfo* wi = windows + start_ch; -@@ -606,15 +640,28 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP +@@ -606,15 +654,28 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP sce = &cpe->ch[ch]; coeffs[ch] = sce->coeffs; sce->ics.predictor_present = 0; @@ -266,7 +304,7 @@ aacenc: use generational cache instead of resetting. s->coder->search_for_quantizers(avctx, s, &cpe->ch[ch], s->lambda); } if (chans > 1 -@@ -632,14 +679,14 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP +@@ -632,14 +693,14 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP for (ch = 0; ch < chans; ch++) { /* TNS and PNS */ sce = &cpe->ch[ch]; s->cur_channel = start_ch + ch; @@ -283,7 +321,7 @@ aacenc: use generational cache instead of resetting. } s->cur_channel = start_ch; if (s->options.intensity_stereo) { /* Intensity Stereo */ -@@ -656,8 +703,8 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP +@@ -656,8 +717,8 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP s->coder->search_for_pred(s, sce); if (cpe->ch[ch].ics.predictor_present) pred_mode = 1; } @@ -294,7 +332,7 @@ aacenc: use generational cache instead of resetting. for (ch = 0; ch < chans; ch++) { sce = &cpe->ch[ch]; s->cur_channel = start_ch + ch; -@@ -666,22 +713,34 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP +@@ -666,22 +727,34 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP } s->cur_channel = start_ch; } @@ -333,7 +371,7 @@ aacenc: use generational cache instead of resetting. encode_ms_info(&s->pb, cpe); if (cpe->ms_mode) ms_mode = 1; } -@@ -693,36 +752,78 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP +@@ -693,36 +766,78 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP start_ch += chans; } @@ -432,7 +470,7 @@ aacenc: use generational cache instead of resetting. if (!frame) s->last_frame++; -@@ -738,6 +839,8 @@ static av_cold int aac_encode_end(AVCodecContext *avct +@@ -738,6 +853,8 @@ static av_cold int aac_encode_end(AVCodecContext *avct { AACEncContext *s = avctx->priv_data; @@ -441,7 +479,7 @@ aacenc: use generational cache instead of resetting. ff_mdct_end(&s->mdct1024); ff_mdct_end(&s->mdct128); ff_psy_end(&s->psy); -@@ -796,76 +899,123 @@ static av_cold int aac_encode_init(AVCodecContext *avc +@@ -796,76 +913,123 @@ static av_cold int aac_encode_init(AVCodecContext *avc uint8_t grouping[AAC_MAX_CHANNELS]; int lengths[2]; @@ -599,7 +637,7 @@ aacenc: use generational cache instead of resetting. ff_af_queue_init(avctx, &s->afq); return 0; -@@ -876,27 +1026,16 @@ fail: +@@ -876,27 +1040,16 @@ fail: #define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM static const AVOption aacenc_options[] = { @@ -637,7 +675,7 @@ aacenc: use generational cache instead of resetting. {NULL} }; -@@ -907,6 +1046,11 @@ static const AVClass aacenc_class = { +@@ -907,6 +1060,11 @@ static const AVClass aacenc_class = { LIBAVUTIL_VERSION_INT, }; @@ -649,7 +687,7 @@ aacenc: use generational cache instead of resetting. AVCodec ff_aac_encoder = { .name = "aac", .long_name = NULL_IF_CONFIG_SMALL("AAC (Advanced Audio Coding)"), -@@ -916,9 +1060,9 @@ AVCodec ff_aac_encoder = { +@@ -916,9 +1074,9 @@ AVCodec ff_aac_encoder = { .init = aac_encode_init, .encode2 = aac_encode_frame, .close = aac_encode_end, diff --git a/graphics/ffmpeg/patches/patch-libavcodec_aacenc_utils_h b/graphics/ffmpeg/patches/patch-libavcodec_aacenc_utils_h index 702130b8ae2..505135c8d81 100644 --- a/graphics/ffmpeg/patches/patch-libavcodec_aacenc_utils_h +++ b/graphics/ffmpeg/patches/patch-libavcodec_aacenc_utils_h @@ -1,4 +1,4 @@ -$OpenBSD: patch-libavcodec_aacenc_utils_h,v 1.9 2016/03/09 17:29:36 ajacoutot Exp $ +$OpenBSD: patch-libavcodec_aacenc_utils_h,v 1.10 2016/04/07 06:01:19 ajacoutot Exp $ aacenc: copy PRNG from the decoder @@ -28,11 +28,15 @@ aacenc: avoid double in quantize_bands. aacenc_utils: Use temporary variable. +lavc/aacenc_utils: replace powf(x,y) by expf(logf(x), y) + --- libavcodec/aacenc_utils.h.orig Wed Jan 13 15:27:48 2016 -+++ libavcodec/aacenc_utils.h Tue Mar 8 19:24:00 2016 -@@ -29,8 +29,8 @@ ++++ libavcodec/aacenc_utils.h Fri Mar 18 20:59:09 2016 +@@ -28,9 +28,10 @@ + #ifndef AVCODEC_AACENC_UTILS_H #define AVCODEC_AACENC_UTILS_H ++#include "libavutil/internal.h" #include "aac.h" -#include "aac_tablegen_decl.h" #include "aacenctab.h" @@ -40,7 +44,7 @@ aacenc_utils: Use temporary variable. #define ROUND_STANDARD 0.4054f #define ROUND_TO_ZERO 0.1054f -@@ -45,6 +45,11 @@ static inline void abs_pow34_v(float *out, const float +@@ -45,6 +46,11 @@ static inline void abs_pow34_v(float *out, const float } } @@ -52,7 +56,7 @@ aacenc_utils: Use temporary variable. /** * Quantize one coefficient. * @return absolute value of the quantized coefficient -@@ -61,13 +66,13 @@ static inline void quantize_bands(int *out, const floa +@@ -61,13 +67,13 @@ static inline void quantize_bands(int *out, const floa const float rounding) { int i; @@ -70,7 +74,7 @@ aacenc_utils: Use temporary variable. } } -@@ -85,20 +90,65 @@ static inline float find_max_val(int group_len, int sw +@@ -85,20 +91,68 @@ static inline float find_max_val(int group_len, int sw static inline int find_min_book(float maxval, int sf) { @@ -115,7 +119,10 @@ aacenc_utils: Use temporary variable. + if (s >= ethresh) { + nzl += 1.0f; + } else { -+ nzl += powf(s / ethresh, nzslope); ++ if (nzslope == 2.f) ++ nzl += (s / ethresh) * (s / ethresh); ++ else ++ nzl += ff_fast_powf(s / ethresh, nzslope); + } + } + if (e2 > thresh) { @@ -145,7 +152,7 @@ aacenc_utils: Use temporary variable. /** Return the minimum scalefactor where the quantized coef does not clip. */ static inline uint8_t coef2minsf(float coef) { -@@ -128,6 +178,76 @@ static inline int quant_array_idx(const float val, con +@@ -128,6 +182,76 @@ static inline int quant_array_idx(const float val, con return index; } @@ -222,7 +229,7 @@ aacenc_utils: Use temporary variable. #define ERROR_IF(cond, ...) \ if (cond) { \ av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \ -@@ -138,6 +258,5 @@ static inline int quant_array_idx(const float val, con +@@ -138,6 +262,5 @@ static inline int quant_array_idx(const float val, con if (cond) { \ av_log(avctx, AV_LOG_WARNING, __VA_ARGS__); \ } diff --git a/graphics/ffmpeg/patches/patch-libavcodec_aacpsy_c b/graphics/ffmpeg/patches/patch-libavcodec_aacpsy_c index 686ef57c8ce..f338d3ed164 100644 --- a/graphics/ffmpeg/patches/patch-libavcodec_aacpsy_c +++ b/graphics/ffmpeg/patches/patch-libavcodec_aacpsy_c @@ -1,4 +1,4 @@ -$OpenBSD: patch-libavcodec_aacpsy_c,v 1.5 2015/12/06 08:51:46 ajacoutot Exp $ +$OpenBSD: patch-libavcodec_aacpsy_c,v 1.6 2016/04/07 06:01:19 ajacoutot Exp $ AAC encoder: tweak rate-distortion logic @@ -10,9 +10,21 @@ AAC encoder: make pe.min a local minimum AAC encoder: improve SF range utilization ---- libavcodec/aacpsy.c.orig Sat Dec 5 15:14:00 2015 -+++ libavcodec/aacpsy.c Sat Dec 5 15:01:19 2015 -@@ -80,6 +80,8 @@ +AAC encoder: fix filling of wi.clipping array + +AAC encoder: fix valgrind errors + +--- libavcodec/aacpsy.c.orig Wed Jan 13 15:27:48 2016 ++++ libavcodec/aacpsy.c Wed Apr 6 18:31:01 2016 +@@ -25,6 +25,7 @@ + */ + + #include "libavutil/attributes.h" ++#include "libavutil/internal.h" + #include "libavutil/libm.h" + + #include "avcodec.h" +@@ -80,6 +81,8 @@ #define PSY_3GPP_AH_THR_LONG 0.5f #define PSY_3GPP_AH_THR_SHORT 0.63f @@ -21,7 +33,7 @@ AAC encoder: improve SF range utilization enum { PSY_3GPP_AH_NONE, PSY_3GPP_AH_INACTIVE, -@@ -87,6 +89,7 @@ enum { +@@ -87,6 +90,7 @@ enum { }; #define PSY_3GPP_BITS_TO_PE(bits) ((bits) * 1.18f) @@ -29,7 +41,7 @@ AAC encoder: improve SF range utilization /* LAME psy model constants */ #define PSY_LAME_FIR_LEN 21 ///< LAME psy model FIR order -@@ -157,6 +160,7 @@ typedef struct AacPsyContext{ +@@ -157,6 +161,7 @@ typedef struct AacPsyContext{ } pe; AacPsyCoeffs psy_coef[2][64]; AacPsyChannel *ch; @@ -37,7 +49,7 @@ AAC encoder: improve SF range utilization }AacPsyContext; /** -@@ -299,17 +303,24 @@ static av_cold int psy_3gpp_init(FFPsyContext *ctx) { +@@ -299,17 +304,24 @@ static av_cold int psy_3gpp_init(FFPsyContext *ctx) { float bark; int i, j, g, start; float prev, minscale, minath, minsnr, pe_min; @@ -65,7 +77,22 @@ AAC encoder: improve SF range utilization pctx->pe.min = 8.0f * AAC_BLOCK_SIZE_LONG * bandwidth / (ctx->avctx->sample_rate * 2.0f); pctx->pe.max = 12.0f * AAC_BLOCK_SIZE_LONG * bandwidth / (ctx->avctx->sample_rate * 2.0f); ctx->bitres.size = 6144 - pctx->frame_bits; -@@ -397,7 +408,7 @@ static av_unused FFPsyWindowInfo psy_3gpp_window(FFPsy +@@ -338,10 +350,10 @@ static av_cold int psy_3gpp_init(FFPsyContext *ctx) { + for (g = 0; g < ctx->num_bands[j] - 1; g++) { + AacPsyCoeffs *coeff = &coeffs[g]; + float bark_width = coeffs[g+1].barks - coeffs->barks; +- coeff->spread_low[0] = pow(10.0, -bark_width * PSY_3GPP_THR_SPREAD_LOW); +- coeff->spread_hi [0] = pow(10.0, -bark_width * PSY_3GPP_THR_SPREAD_HI); +- coeff->spread_low[1] = pow(10.0, -bark_width * en_spread_low); +- coeff->spread_hi [1] = pow(10.0, -bark_width * en_spread_hi); ++ coeff->spread_low[0] = ff_exp10(-bark_width * PSY_3GPP_THR_SPREAD_LOW); ++ coeff->spread_hi [0] = ff_exp10(-bark_width * PSY_3GPP_THR_SPREAD_HI); ++ coeff->spread_low[1] = ff_exp10(-bark_width * en_spread_low); ++ coeff->spread_hi [1] = ff_exp10(-bark_width * en_spread_hi); + pe_min = bark_pe * bark_width; + minsnr = exp2(pe_min / band_sizes[g]) - 1.5f; + coeff->min_snr = av_clipf(1.0f / minsnr, PSY_SNR_25DB, PSY_SNR_1DB); +@@ -397,7 +409,7 @@ static av_unused FFPsyWindowInfo psy_3gpp_window(FFPsy int channel, int prev_type) { int i, j; @@ -74,7 +101,7 @@ AAC encoder: improve SF range utilization int attack_ratio = br <= 16000 ? 18 : 10; AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data; AacPsyChannel *pch = &pctx->ch[channel]; -@@ -486,7 +497,7 @@ static int calc_bit_demand(AacPsyContext *ctx, float p +@@ -486,7 +498,7 @@ static int calc_bit_demand(AacPsyContext *ctx, float p const float bitspend_add = short_window ? PSY_3GPP_SPEND_ADD_S : PSY_3GPP_SPEND_ADD_L; const float clip_low = short_window ? PSY_3GPP_CLIP_LO_S : PSY_3GPP_CLIP_LO_L; const float clip_high = short_window ? PSY_3GPP_CLIP_HI_S : PSY_3GPP_CLIP_HI_L; @@ -83,7 +110,7 @@ AAC encoder: improve SF range utilization ctx->fill_level += ctx->frame_bits - bits; ctx->fill_level = av_clip(ctx->fill_level, 0, size); -@@ -503,11 +514,21 @@ static int calc_bit_demand(AacPsyContext *ctx, float p +@@ -503,11 +515,21 @@ static int calc_bit_demand(AacPsyContext *ctx, float p * Hopefully below is correct. */ bit_factor = 1.0f - bit_save + ((bit_spend - bit_save) / (ctx->pe.max - ctx->pe.min)) * (clipped_pe - ctx->pe.min); @@ -108,7 +135,7 @@ AAC encoder: improve SF range utilization } static float calc_pe_3gpp(AacPsyBand *band) -@@ -574,26 +595,30 @@ static float calc_reduced_thr_3gpp(AacPsyBand *band, f +@@ -574,26 +596,30 @@ static float calc_reduced_thr_3gpp(AacPsyBand *band, f #ifndef calc_thr_3gpp static void calc_thr_3gpp(const FFPsyWindowInfo *wi, const int num_bands, AacPsyChannel *pch, @@ -144,7 +171,7 @@ AAC encoder: improve SF range utilization } } } -@@ -634,9 +659,11 @@ static void psy_3gpp_analyze_channel(FFPsyContext *ctx +@@ -634,9 +660,11 @@ static void psy_3gpp_analyze_channel(FFPsyContext *ctx const uint8_t *band_sizes = ctx->bands[wi->num_windows == 8]; AacPsyCoeffs *coeffs = pctx->psy_coef[wi->num_windows == 8]; const float avoid_hole_thr = wi->num_windows == 8 ? PSY_3GPP_AH_THR_SHORT : PSY_3GPP_AH_THR_LONG; @@ -157,7 +184,16 @@ AAC encoder: improve SF range utilization //modify thresholds and energies - spread, threshold in quiet, pre-echo control for (w = 0; w < wi->num_windows*16; w += 16) { -@@ -677,16 +704,36 @@ static void psy_3gpp_analyze_channel(FFPsyContext *ctx +@@ -658,7 +686,7 @@ static void psy_3gpp_analyze_channel(FFPsyContext *ctx + + band->thr_quiet = band->thr = FFMAX(band->thr, coeffs[g].ath); + //5.4.2.5 "Pre-echo control" +- if (!(wi->window_type[0] == LONG_STOP_SEQUENCE || (wi->window_type[1] == LONG_START_SEQUENCE && !w))) ++ if (!(wi->window_type[0] == LONG_STOP_SEQUENCE || (!w && wi->window_type[1] == LONG_START_SEQUENCE))) + band->thr = FFMAX(PSY_3GPP_RPEMIN*band->thr, FFMIN(band->thr, + PSY_3GPP_RPELEV*pch->prev_band[w+g].thr_quiet)); + +@@ -677,16 +705,36 @@ static void psy_3gpp_analyze_channel(FFPsyContext *ctx /* 5.6.1.3.2 "Calculation of the desired perceptual entropy" */ ctx->ch[channel].entropy = pe; @@ -203,7 +239,7 @@ AAC encoder: improve SF range utilization if (desired_pe < pe) { /* 5.6.1.3.4 "First Estimation of the reduction value" */ -@@ -788,6 +835,7 @@ static void psy_3gpp_analyze_channel(FFPsyContext *ctx +@@ -788,6 +836,7 @@ static void psy_3gpp_analyze_channel(FFPsyContext *ctx psy_band->threshold = band->thr; psy_band->energy = band->energy; psy_band->spread = band->active_lines * 2.0f / band_sizes[g]; @@ -211,3 +247,38 @@ AAC encoder: improve SF range utilization } } +@@ -927,21 +976,6 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *c + + lame_apply_block_type(pch, &wi, uselongblock); + +- /* Calculate input sample maximums and evaluate clipping risk */ +- if (audio) { +- for (i = 0; i < AAC_NUM_BLOCKS_SHORT; i++) { +- const float *wbuf = audio + i * AAC_BLOCK_SIZE_SHORT; +- float max = 0; +- int j; +- for (j = 0; j < AAC_BLOCK_SIZE_SHORT; j++) +- max = FFMAX(max, fabsf(wbuf[j])); +- clippings[i] = max; +- } +- } else { +- for (i = 0; i < 8; i++) +- clippings[i] = 0; +- } +- + wi.window_type[1] = prev_type; + if (wi.window_type[0] != EIGHT_SHORT_SEQUENCE) { + float clipping = 0.0f; +@@ -970,9 +1004,10 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *c + for (i = 0; i < 8; i += wi.grouping[i]) { + int w; + float clipping = 0.0f; +- for (w = 0; w < wi.grouping[i] && !clipping; w++) ++ for (w = 0; w < wi.grouping[i]; w++) + clipping = FFMAX(clipping, clippings[i+w]); +- wi.clipping[i] = clipping; ++ for (w = 0; w < wi.grouping[i]; w++) ++ wi.clipping[i+w] = clipping; + } + } + diff --git a/graphics/ffmpeg/patches/patch-libavcodec_lpc_c b/graphics/ffmpeg/patches/patch-libavcodec_lpc_c index 216cdbb3332..dd204c2315f 100644 --- a/graphics/ffmpeg/patches/patch-libavcodec_lpc_c +++ b/graphics/ffmpeg/patches/patch-libavcodec_lpc_c @@ -1,10 +1,12 @@ -$OpenBSD: patch-libavcodec_lpc_c,v 1.1 2015/10/13 05:44:18 ajacoutot Exp $ +$OpenBSD: patch-libavcodec_lpc_c,v 1.2 2016/04/07 06:01:19 ajacoutot Exp $ lpc: correctly apply windowing to the samples in the float-only lpc ---- libavcodec/lpc.c.orig Mon Oct 12 23:03:10 2015 -+++ libavcodec/lpc.c Mon Oct 12 23:03:21 2015 -@@ -173,11 +173,13 @@ double ff_lpc_calc_ref_coefs_f(LPCContext *s, const fl +lavc/lpc: exploit even symmetry of window function + +--- libavcodec/lpc.c.orig Wed Jan 13 15:27:48 2016 ++++ libavcodec/lpc.c Thu Mar 24 20:27:56 2016 +@@ -173,11 +173,14 @@ double ff_lpc_calc_ref_coefs_f(LPCContext *s, const fl int i; double signal = 0.0f, avg_err = 0.0f; double autoc[MAX_LPC_ORDER+1] = {0}, error[MAX_LPC_ORDER+1] = {0}; @@ -15,9 +17,10 @@ lpc: correctly apply windowing to the samples in the float-only lpc - for (i = 0; i < len; i++) - s->windowed_samples[i] = 1.0f - ((samples[i]-c)/c)*((samples[i]-c)/c); + /* Apply windowing */ -+ for (i = 0; i < len; i++) { ++ for (i = 0; i <= len / 2; i++) { + double weight = a - b*cos((2*M_PI*i)/(len - 1)); + s->windowed_samples[i] = weight*samples[i]; ++ s->windowed_samples[len-1-i] = weight*samples[len-1-i]; + } s->lpc_compute_autocorr(s->windowed_samples, len, order, autoc); diff --git a/graphics/ffmpeg/patches/patch-libavutil_internal_h b/graphics/ffmpeg/patches/patch-libavutil_internal_h new file mode 100644 index 00000000000..fe9412b1f1d --- /dev/null +++ b/graphics/ffmpeg/patches/patch-libavutil_internal_h @@ -0,0 +1,51 @@ +$OpenBSD: patch-libavutil_internal_h,v 1.1 2016/04/07 06:01:19 ajacoutot Exp $ + +lavu/internal: add ff_exp10 + +lavc/aacenc_utils: replace powf(x,y) by expf(logf(x), y) + +--- libavutil/internal.h.orig Wed Jan 13 15:27:50 2016 ++++ libavutil/internal.h Wed Apr 6 19:54:16 2016 +@@ -257,6 +257,42 @@ void avpriv_request_sample(void *avc, + #endif + + /** ++ * Compute 10^x for floating point values. Note: this function is by no means ++ * "correctly rounded", and is meant as a fast, reasonably accurate approximation. ++ * For instance, maximum relative error for the double precision variant is ++ * ~ 1e-13 for very small and very large values. ++ * This is ~2x faster than GNU libm's approach, which is still off by 2ulp on ++ * some inputs. ++ * @param x exponent ++ * @return 10^x ++ */ ++static av_always_inline double ff_exp10(double x) ++{ ++ return exp2(M_LOG2_10 * x); ++} ++ ++static av_always_inline float ff_exp10f(float x) ++{ ++ return exp2f(M_LOG2_10 * x); ++} ++ ++/** ++ * Compute x^y for floating point x, y. Note: this function is faster than the ++ * libm variant due to mainly 2 reasons: ++ * 1. It does not handle any edge cases. In particular, this is only guaranteed ++ * to work correctly for x > 0. ++ * 2. It is not as accurate as a standard nearly "correctly rounded" libm variant. ++ * @param x base ++ * @param y exponent ++ * @return x^y ++ */ ++static av_always_inline float ff_fast_powf(float x, float y) ++{ ++ return expf(logf(x) * y); ++} ++ ++ ++/** + * A wrapper for open() setting O_CLOEXEC. + */ + int avpriv_open(const char *filename, int flags, ...); diff --git a/graphics/ffmpeg/patches/patch-libavutil_libm_h b/graphics/ffmpeg/patches/patch-libavutil_libm_h new file mode 100644 index 00000000000..34a6740dc19 --- /dev/null +++ b/graphics/ffmpeg/patches/patch-libavutil_libm_h @@ -0,0 +1,14 @@ +$OpenBSD: patch-libavutil_libm_h,v 1.1 2016/04/07 06:01:19 ajacoutot Exp $ + +lavu/libm: add exp10 support + +--- libavutil/libm.h.orig Wed Apr 6 20:45:13 2016 ++++ libavutil/libm.h Wed Apr 6 20:45:27 2016 +@@ -28,6 +28,7 @@ + #include "config.h" + #include "attributes.h" + #include "intfloat.h" ++#include "mathematics.h" + + #if HAVE_MIPSFPU && HAVE_INLINE_ASM + #include "libavutil/mips/libm_mips.h" diff --git a/graphics/ffmpeg/patches/patch-tests_fate_aac_mak b/graphics/ffmpeg/patches/patch-tests_fate_aac_mak index e3d1819bb6b..2fb0f9b906a 100644 --- a/graphics/ffmpeg/patches/patch-tests_fate_aac_mak +++ b/graphics/ffmpeg/patches/patch-tests_fate_aac_mak @@ -1,4 +1,4 @@ -$OpenBSD: patch-tests_fate_aac_mak,v 1.9 2016/03/07 07:11:35 ajacoutot Exp $ +$OpenBSD: patch-tests_fate_aac_mak,v 1.10 2016/04/07 06:01:19 ajacoutot Exp $ fate: adjust AAC encoder tests values @@ -70,9 +70,11 @@ tests/fate/aac: remove unneeded strict arguments from the encoder tests fate/aac: Increase fuzz from of fate-aac-pns-encode from 72 to 74 for Loongson +AAC encoder: new regression test + --- tests/fate/aac.mak.orig Wed Jan 13 15:27:50 2016 -+++ tests/fate/aac.mak Sun Mar 6 19:41:20 2016 -@@ -142,56 +142,84 @@ FATE_AAC += $(FATE_AAC_CT:%=fate-aac-ct-%) ++++ tests/fate/aac.mak Sun Apr 3 18:34:00 2016 +@@ -142,56 +142,95 @@ FATE_AAC += $(FATE_AAC_CT:%=fate-aac-ct-%) FATE_AAC_ENCODE += fate-aac-aref-encode fate-aac-aref-encode: ./tests/data/asynth-44100-2.wav @@ -160,6 +162,17 @@ fate/aac: Increase fuzz from of fate-aac-pns-encode from 72 to 74 for Loongson +fate-aac-ltp-encode: CMP_TARGET = 1270 +fate-aac-ltp-encode: SIZE_TOLERANCE = 3560 +fate-aac-ltp-encode: FUZZ = 17 ++ ++#Ticket1784 ++FATE_AAC_ENCODE += fate-aac-yoraw-encode ++fate-aac-yoraw-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-reference/yo.raw-short.wav -c:a aac -fflags +bitexact -flags +bitexact ++fate-aac-yoraw-encode: CMP = stddev ++fate-aac-yoraw-encode: REF = $(SAMPLES)/audio-reference/yo.raw-short.wav ++fate-aac-yoraw-encode: CMP_SHIFT = -12288 ++fate-aac-yoraw-encode: CMP_TARGET = 259 ++fate-aac-yoraw-encode: SIZE_TOLERANCE = 3560 ++fate-aac-yoraw-encode: FUZZ = 17 ++ + FATE_AAC_ENCODE += fate-aac-pred-encode -fate-aac-pred-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav -strict -2 -profile:a aac_main -c:a aac -aac_is 0 -aac_pns 0 -b:a 128k