diff --git a/configure b/configure index 1c3e505b041cd9ea8e841ee6fadcac4e297d1730..5d533621ae114e0598a68c85560f7e9530f428db 100755 --- a/configure +++ b/configure @@ -5939,7 +5939,7 @@ enabled libwebp && { enabled libwebp_encoder && require_pkg_config libwebp "libwebp >= 0.2.0" webp/encode.h WebPGetEncoderVersion enabled libwebp_anim_encoder && check_pkg_config libwebp_anim_encoder "libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit; } enabled libx264 && { check_pkg_config libx264 x264 "stdint.h x264.h" x264_encoder_encode || - { require libx264 "stdint.h x264.h" x264_encoder_encode -lx264 && + { require libx264 "stdint.h x264.h" x264_encoder_encode "-lx264 $pthreads_extralibs $libm_extralibs" && warn "using libx264 without pkg-config"; } } && require_cpp_condition x264.h "X264_BUILD >= 118" && { check_cpp_condition x264.h "X264_MPEG2" && @@ -6010,15 +6010,13 @@ fi if enabled sdl2; then SDL2_CONFIG="${cross_prefix}sdl2-config" - if test_pkg_config sdl2 "sdl2 >= 2.0.1 sdl2 < 2.1.0" SDL_events.h SDL_PollEvent; then - check_func_headers SDL.h SDL_Init $sdl2_extralibs $sdl2_cflags || - disable sdl2 - elif "${SDL2_CONFIG}" --version > /dev/null 2>&1; then + test_pkg_config sdl2 "sdl2 >= 2.0.1 sdl2 < 2.1.0" SDL_events.h SDL_PollEvent + if disabled sdl2 && "${SDL2_CONFIG}" --version > /dev/null 2>&1; then sdl2_cflags=$("${SDL2_CONFIG}" --cflags) sdl2_extralibs=$("${SDL2_CONFIG}" --libs) check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x020001" $sdl2_cflags && check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x020100" $sdl2_cflags && - check_func_headers SDL.h SDL_Init $sdl2_extralibs $sdl2_cflags && + check_func_headers SDL_events.h SDL_PollEvent $sdl2_extralibs $sdl2_cflags && enable sdl2 fi if test $target_os = "mingw32"; then diff --git a/doc/encoders.texi b/doc/encoders.texi index 88ef8f9b230b4548455e3c0f39b3d6978cbb29fc..6a410a8cb643a5ce8caf173e2f62367cf8369b50 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -64,7 +64,6 @@ to find an optimal combination by adding or subtracting a specific value from all quantizers and adjusting some individual quantizer a little. Will tune itself based on whether @option{aac_is}, @option{aac_ms} and @option{aac_pns} are enabled. -This is the default choice for a coder. @item anmr Average noise to mask ratio (ANMR) trellis-based solution. @@ -77,10 +76,10 @@ Not currently recommended. @item fast Constant quantizer method. -This method sets a constant quantizer for all bands. This is the fastest of all -the methods and has no rate control or support for @option{aac_is} or -@option{aac_pns}. -Not recommended. +Uses a cheaper version of twoloop algorithm that doesn't try to do as many +clever adjustments. Worse with low bitrates (less than 64kbps), but is better +and much faster at higher bitrates. +This is the default choice for a coder @end table diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c index f66a4a7c488dc998abffb5e4d5938c4093c07bfc..6425b1c98c35412900f42c2ab9437ffc223edcdc 100644 --- a/doc/examples/vaapi_encode.c +++ b/doc/examples/vaapi_encode.c @@ -217,8 +217,7 @@ close: fclose(fout); av_frame_free(&sw_frame); av_frame_free(&hw_frame); - if (avctx) - avcodec_free_context(&avctx); + avcodec_free_context(&avctx); av_buffer_unref(&hw_device_ctx); return err; diff --git a/doc/filters.texi b/doc/filters.texi index a13aef21960c2d69044f9e1a677a3482ac291fc2..bd93e0ab84f390afb89cd18fd5fdf8852879abb0 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -1084,7 +1084,36 @@ Set output gain. @item f Set coefficients format. -Can be @code{tf} - transfer function or @code{zp} - Z-plane zeros/poles. + +@table @samp +@item tf +transfer function +@item zp +Z-plane zeros/poles, cartesian (default) +@item pr +Z-plane zeros/poles, polar radians +@item pd +Z-plane zeros/poles, polar degrees +@end table + +@item r +Set kind of processing. +Can be @code{d} - direct or @code{s} - serial cascading. Defauls is @code{s}. + +@item e +Set filtering precision. + +@table @samp +@item dbl +double-precision floating-point (default) +@item flt +single-precision floating-point +@item i32 +32-bit integers +@item i16 +16-bit integers +@end table + @end table Coefficients in @code{tf} format are separated by spaces and are in ascending @@ -1104,13 +1133,13 @@ used for all remaining channels. @item Apply 2 pole elliptic notch at arround 5000Hz for 48000 Hz sample rate: @example -aiir=k=1:z=7.957584807809675810E-1 -2.575128568908332300 3.674839853930788710 -2.57512875289799137 7.957586296317130880E-1:p=1 -2.86950072432325953 3.63022088054647218 -2.28075678147272232 6.361362326477423500E-1:f=tf +aiir=k=1:z=7.957584807809675810E-1 -2.575128568908332300 3.674839853930788710 -2.57512875289799137 7.957586296317130880E-1:p=1 -2.86950072432325953 3.63022088054647218 -2.28075678147272232 6.361362326477423500E-1:f=tf:r=d @end example @item Same as above but in @code{zp} format: @example -aiir=k=0.79575848078096756:z=0.80918701+0.58773007i 0.80918701-0.58773007i 0.80884700+0.58784055i 0.80884700-0.58784055i:p=0.63892345+0.59951235i 0.63892345-0.59951235i 0.79582691+0.44198673i 0.79582691-0.44198673i:f=zp +aiir=k=0.79575848078096756:z=0.80918701+0.58773007i 0.80918701-0.58773007i 0.80884700+0.58784055i 0.80884700-0.58784055i:p=0.63892345+0.59951235i 0.63892345-0.59951235i 0.79582691+0.44198673i 0.79582691-0.44198673i:f=zp:r=s @end example @end itemize @@ -12785,7 +12814,7 @@ sequential number of the input frame, starting from 1 Mean Square Error pixel-by-pixel average difference of the compared frames, averaged over all the image components. -@item mse_y, mse_u, mse_v, mse_r, mse_g, mse_g, mse_a +@item mse_y, mse_u, mse_v, mse_r, mse_g, mse_b, mse_a Mean Square Error pixel-by-pixel average difference of the compared frames for the component specified by the suffix. diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index fa7932d42d71caafc9760e2070ed8faa15004fab..6d94c769059940baf7f417673ab1371fbf66d6d0 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -1118,10 +1118,10 @@ fail: #define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM static const AVOption aacenc_options[] = { - {"aac_coder", "Coding algorithm", offsetof(AACEncContext, options.coder), AV_OPT_TYPE_INT, {.i64 = AAC_CODER_TWOLOOP}, 0, AAC_CODER_NB-1, AACENC_FLAGS, "coder"}, + {"aac_coder", "Coding algorithm", offsetof(AACEncContext, options.coder), AV_OPT_TYPE_INT, {.i64 = AAC_CODER_FAST}, 0, AAC_CODER_NB-1, AACENC_FLAGS, "coder"}, {"anmr", "ANMR method", 0, AV_OPT_TYPE_CONST, {.i64 = AAC_CODER_ANMR}, INT_MIN, INT_MAX, AACENC_FLAGS, "coder"}, {"twoloop", "Two loop searching method", 0, AV_OPT_TYPE_CONST, {.i64 = AAC_CODER_TWOLOOP}, INT_MIN, INT_MAX, AACENC_FLAGS, "coder"}, - {"fast", "Constant quantizer", 0, AV_OPT_TYPE_CONST, {.i64 = AAC_CODER_FAST}, INT_MIN, INT_MAX, AACENC_FLAGS, "coder"}, + {"fast", "Default fast search", 0, AV_OPT_TYPE_CONST, {.i64 = AAC_CODER_FAST}, INT_MIN, INT_MAX, AACENC_FLAGS, "coder"}, {"aac_ms", "Force M/S stereo coding", offsetof(AACEncContext, options.mid_side), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, AACENC_FLAGS}, {"aac_is", "Intensity stereo coding", offsetof(AACEncContext, options.intensity_stereo), AV_OPT_TYPE_BOOL, {.i64 = 1}, -1, 1, AACENC_FLAGS}, {"aac_pns", "Perceptual noise substitution", offsetof(AACEncContext, options.pns), AV_OPT_TYPE_BOOL, {.i64 = 1}, -1, 1, AACENC_FLAGS}, diff --git a/libavcodec/arm/sbrdsp_neon.S b/libavcodec/arm/sbrdsp_neon.S index e66abd682a8fe1efcd338693038d58c708997411..003b04ea05653b7ab1111d89f931fd64c0a4f2b6 100644 --- a/libavcodec/arm/sbrdsp_neon.S +++ b/libavcodec/arm/sbrdsp_neon.S @@ -336,11 +336,11 @@ function ff_sbr_hf_apply_noise_0_neon, export=1 vld1.32 {d0}, [r0,:64] vld1.32 {d6}, [lr,:64] vld1.32 {d2[]}, [r1,:32]! - vld1.32 {d3[]}, [r2,:32]! + vld1.32 {d18[]}, [r2,:32]! vceq.f32 d4, d2, #0 veor d2, d2, d3 vmov d1, d0 - vmla.f32 d0, d6, d3 + vmla.f32 d0, d6, d18 vadd.f32 s2, s2, s4 vbif d0, d1, d4 vst1.32 {d0}, [r0,:64]! diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index c13deb599fc215d0c1de235822492ad54fb637bc..8fbbc798a2e65e27a2aa0a33220989c83fd81cbc 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -767,7 +767,7 @@ typedef struct AVCodecDescriptor { * Note: If the first 23 bits of the additional bytes are not 0, then damaged * MPEG bitstreams could cause overread and segfault. */ -#define AV_INPUT_BUFFER_PADDING_SIZE 32 +#define AV_INPUT_BUFFER_PADDING_SIZE 64 /** * @ingroup lavc_encoding diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c index dd601ffae0077f2fa0bc2cab589cf09d019e9a7e..186997c6311d254a91cf03d87542f87442b452c3 100644 --- a/libavcodec/dcaenc.c +++ b/libavcodec/dcaenc.c @@ -21,6 +21,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#define FFT_FLOAT 0 +#define FFT_FIXED_32 1 + #include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "libavutil/common.h" @@ -33,6 +36,7 @@ #include "dca_core.h" #include "dcadata.h" #include "dcaenc.h" +#include "fft.h" #include "internal.h" #include "mathops.h" #include "put_bits.h" @@ -48,6 +52,8 @@ #define SUBBAND_SAMPLES (SUBFRAMES * SUBSUBFRAMES * 8) #define AUBANDS 25 +#define COS_T(x) (c->cos_table[(x) & 2047]) + typedef struct CompressionOptions { int adpcm_mode; } CompressionOptions; @@ -56,6 +62,7 @@ typedef struct DCAEncContext { AVClass *class; PutBitContext pb; DCAADPCMEncContext adpcm_ctx; + FFTContext mdct; CompressionOptions options; int frame_size; int frame_bits; @@ -92,15 +99,15 @@ typedef struct DCAEncContext { int32_t worst_noise_ever; int consumed_bits; int consumed_adpcm_bits; ///< Number of bits to transmit ADPCM related info -} DCAEncContext; -static int32_t cos_table[2048]; -static int32_t band_interpolation[2][512]; -static int32_t band_spectrum[2][8]; -static int32_t auf[9][AUBANDS][256]; -static int32_t cb_to_add[256]; -static int32_t cb_to_level[2048]; -static int32_t lfe_fir_64i[512]; + int32_t cos_table[2048]; + int32_t band_interpolation_tab[2][512]; + int32_t band_spectrum_tab[2][8]; + int32_t auf[9][AUBANDS][256]; + int32_t cb_to_add[256]; + int32_t cb_to_level[2048]; + int32_t lfe_fir_64i[512]; +} DCAEncContext; /* Transfer function of outer and middle ear, Hz -> dB */ static double hom(double f) @@ -153,15 +160,16 @@ static int encode_init(AVCodecContext *avctx) { DCAEncContext *c = avctx->priv_data; uint64_t layout = avctx->channel_layout; - int i, j, min_frame_bits; + int i, j, k, min_frame_bits; + int ret; if (subband_bufer_alloc(c)) return AVERROR(ENOMEM); c->fullband_channels = c->channels = avctx->channels; c->lfe_channel = (avctx->channels == 3 || avctx->channels == 6); - c->band_interpolation = band_interpolation[1]; - c->band_spectrum = band_spectrum[1]; + c->band_interpolation = c->band_interpolation_tab[1]; + c->band_spectrum = c->band_spectrum_tab[1]; c->worst_quantization_noise = -2047; c->worst_noise_ever = -2047; c->consumed_adpcm_bits = 0; @@ -231,91 +239,77 @@ static int encode_init(AVCodecContext *avctx) avctx->frame_size = 32 * SUBBAND_SAMPLES; - if (!cos_table[0]) { - int j, k; - - cos_table[0] = 0x7fffffff; - cos_table[512] = 0; - cos_table[1024] = -cos_table[0]; - for (i = 1; i < 512; i++) { - cos_table[i] = (int32_t)(0x7fffffff * cos(M_PI * i / 1024)); - cos_table[1024-i] = -cos_table[i]; - cos_table[1024+i] = -cos_table[i]; - cos_table[2048-i] = cos_table[i]; - } - for (i = 0; i < 2048; i++) { - cb_to_level[i] = (int32_t)(0x7fffffff * ff_exp10(-0.005 * i)); - } + if ((ret = ff_mdct_init(&c->mdct, 9, 0, 1.0)) < 0) + return ret; - for (k = 0; k < 32; k++) { - for (j = 0; j < 8; j++) { - lfe_fir_64i[64 * j + k] = (int32_t)(0xffffff800000ULL * ff_dca_lfe_fir_64[8 * k + j]); - lfe_fir_64i[64 * (7-j) + (63 - k)] = (int32_t)(0xffffff800000ULL * ff_dca_lfe_fir_64[8 * k + j]); - } - } + /* Init all tables */ + c->cos_table[0] = 0x7fffffff; + c->cos_table[512] = 0; + c->cos_table[1024] = -c->cos_table[0]; + for (i = 1; i < 512; i++) { + c->cos_table[i] = (int32_t)(0x7fffffff * cos(M_PI * i / 1024)); + c->cos_table[1024-i] = -c->cos_table[i]; + c->cos_table[1024+i] = -c->cos_table[i]; + c->cos_table[2048-i] = +c->cos_table[i]; + } - for (i = 0; i < 512; i++) { - band_interpolation[0][i] = (int32_t)(0x1000000000ULL * ff_dca_fir_32bands_perfect[i]); - band_interpolation[1][i] = (int32_t)(0x1000000000ULL * ff_dca_fir_32bands_nonperfect[i]); + for (i = 0; i < 2048; i++) + c->cb_to_level[i] = (int32_t)(0x7fffffff * ff_exp10(-0.005 * i)); + + for (k = 0; k < 32; k++) { + for (j = 0; j < 8; j++) { + c->lfe_fir_64i[64 * j + k] = (int32_t)(0xffffff800000ULL * ff_dca_lfe_fir_64[8 * k + j]); + c->lfe_fir_64i[64 * (7-j) + (63 - k)] = (int32_t)(0xffffff800000ULL * ff_dca_lfe_fir_64[8 * k + j]); } + } + + for (i = 0; i < 512; i++) { + c->band_interpolation_tab[0][i] = (int32_t)(0x1000000000ULL * ff_dca_fir_32bands_perfect[i]); + c->band_interpolation_tab[1][i] = (int32_t)(0x1000000000ULL * ff_dca_fir_32bands_nonperfect[i]); + } - for (i = 0; i < 9; i++) { - for (j = 0; j < AUBANDS; j++) { - for (k = 0; k < 256; k++) { - double freq = sample_rates[i] * (k + 0.5) / 512; + for (i = 0; i < 9; i++) { + for (j = 0; j < AUBANDS; j++) { + for (k = 0; k < 256; k++) { + double freq = sample_rates[i] * (k + 0.5) / 512; - auf[i][j][k] = (int32_t)(10 * (hom(freq) + gammafilter(j, freq))); - } + c->auf[i][j][k] = (int32_t)(10 * (hom(freq) + gammafilter(j, freq))); } } + } - for (i = 0; i < 256; i++) { - double add = 1 + ff_exp10(-0.01 * i); - cb_to_add[i] = (int32_t)(100 * log10(add)); - } - for (j = 0; j < 8; j++) { - double accum = 0; - for (i = 0; i < 512; i++) { - double reconst = ff_dca_fir_32bands_perfect[i] * ((i & 64) ? (-1) : 1); - accum += reconst * cos(2 * M_PI * (i + 0.5 - 256) * (j + 0.5) / 512); - } - band_spectrum[0][j] = (int32_t)(200 * log10(accum)); + for (i = 0; i < 256; i++) { + double add = 1 + ff_exp10(-0.01 * i); + c->cb_to_add[i] = (int32_t)(100 * log10(add)); + } + for (j = 0; j < 8; j++) { + double accum = 0; + for (i = 0; i < 512; i++) { + double reconst = ff_dca_fir_32bands_perfect[i] * ((i & 64) ? (-1) : 1); + accum += reconst * cos(2 * M_PI * (i + 0.5 - 256) * (j + 0.5) / 512); } - for (j = 0; j < 8; j++) { - double accum = 0; - for (i = 0; i < 512; i++) { - double reconst = ff_dca_fir_32bands_nonperfect[i] * ((i & 64) ? (-1) : 1); - accum += reconst * cos(2 * M_PI * (i + 0.5 - 256) * (j + 0.5) / 512); - } - band_spectrum[1][j] = (int32_t)(200 * log10(accum)); + c->band_spectrum_tab[0][j] = (int32_t)(200 * log10(accum)); + } + for (j = 0; j < 8; j++) { + double accum = 0; + for (i = 0; i < 512; i++) { + double reconst = ff_dca_fir_32bands_nonperfect[i] * ((i & 64) ? (-1) : 1); + accum += reconst * cos(2 * M_PI * (i + 0.5 - 256) * (j + 0.5) / 512); } + c->band_spectrum_tab[1][j] = (int32_t)(200 * log10(accum)); } - return 0; -} -static av_cold int encode_close(AVCodecContext *avctx) -{ - if (avctx->priv_data) { - DCAEncContext *c = avctx->priv_data; - subband_bufer_free(c); - ff_dcaadpcm_free(&c->adpcm_ctx); - } return 0; } -static inline int32_t cos_t(int x) -{ - return cos_table[x & 2047]; -} - -static inline int32_t sin_t(int x) +static av_cold int encode_close(AVCodecContext *avctx) { - return cos_t(x - 512); -} + DCAEncContext *c = avctx->priv_data; + ff_mdct_end(&c->mdct); + subband_bufer_free(c); + ff_dcaadpcm_free(&c->adpcm_ctx); -static inline int32_t half32(int32_t a) -{ - return (a + 1) >> 1; + return 0; } static void subband_transform(DCAEncContext *c, const int32_t *input) @@ -353,7 +347,7 @@ static void subband_transform(DCAEncContext *c, const int32_t *input) resp = 0; for (i = 16; i < 48; i++) { int s = (2 * band + 1) * (2 * (i + 16) + 1); - resp += mul32(accum[i], cos_t(s << 3)) >> 3; + resp += mul32(accum[i], COS_T(s << 3)) >> 3; } c->subband[ch][band][subs] = ((band + 1) & 2) ? -resp : resp; @@ -384,9 +378,9 @@ static void lfe_downsample(DCAEncContext *c, const int32_t *input) accum = 0; for (i = hist_start, j = 0; i < 512; i++, j++) - accum += mul32(hist[i], lfe_fir_64i[j]); + accum += mul32(hist[i], c->lfe_fir_64i[j]); for (i = 0; i < hist_start; i++, j++) - accum += mul32(hist[i], lfe_fir_64i[j]); + accum += mul32(hist[i], c->lfe_fir_64i[j]); c->downsampled_lfe[lfes] = accum; @@ -398,131 +392,72 @@ static void lfe_downsample(DCAEncContext *c, const int32_t *input) } } -typedef struct { - int32_t re; - int32_t im; -} cplx32; - -static void fft(const int32_t in[2 * 256], cplx32 out[256]) -{ - cplx32 buf[256], rin[256], rout[256]; - int i, j, k, l; - - /* do two transforms in parallel */ - for (i = 0; i < 256; i++) { - /* Apply the Hann window */ - rin[i].re = mul32(in[2 * i], 0x3fffffff - (cos_t(8 * i + 2) >> 1)); - rin[i].im = mul32(in[2 * i + 1], 0x3fffffff - (cos_t(8 * i + 6) >> 1)); - } - /* pre-rotation */ - for (i = 0; i < 256; i++) { - buf[i].re = mul32(cos_t(4 * i + 2), rin[i].re) - - mul32(sin_t(4 * i + 2), rin[i].im); - buf[i].im = mul32(cos_t(4 * i + 2), rin[i].im) - + mul32(sin_t(4 * i + 2), rin[i].re); - } - - for (j = 256, l = 1; j != 1; j >>= 1, l <<= 1) { - for (k = 0; k < 256; k += j) { - for (i = k; i < k + j / 2; i++) { - cplx32 sum, diff; - int t = 8 * l * i; - - sum.re = buf[i].re + buf[i + j / 2].re; - sum.im = buf[i].im + buf[i + j / 2].im; - - diff.re = buf[i].re - buf[i + j / 2].re; - diff.im = buf[i].im - buf[i + j / 2].im; - - buf[i].re = half32(sum.re); - buf[i].im = half32(sum.im); - - buf[i + j / 2].re = mul32(diff.re, cos_t(t)) - - mul32(diff.im, sin_t(t)); - buf[i + j / 2].im = mul32(diff.im, cos_t(t)) - + mul32(diff.re, sin_t(t)); - } - } - } - /* post-rotation */ - for (i = 0; i < 256; i++) { - int b = ff_reverse[i]; - rout[i].re = mul32(buf[b].re, cos_t(4 * i)) - - mul32(buf[b].im, sin_t(4 * i)); - rout[i].im = mul32(buf[b].im, cos_t(4 * i)) - + mul32(buf[b].re, sin_t(4 * i)); - } - for (i = 0; i < 256; i++) { - /* separate the results of the two transforms */ - cplx32 o1, o2; - - o1.re = rout[i].re - rout[255 - i].re; - o1.im = rout[i].im + rout[255 - i].im; - - o2.re = rout[i].im - rout[255 - i].im; - o2.im = -rout[i].re - rout[255 - i].re; - - /* combine them into one long transform */ - out[i].re = mul32( o1.re + o2.re, cos_t(2 * i + 1)) - + mul32( o1.im - o2.im, sin_t(2 * i + 1)); - out[i].im = mul32( o1.im + o2.im, cos_t(2 * i + 1)) - + mul32(-o1.re + o2.re, sin_t(2 * i + 1)); - } -} - -static int32_t get_cb(int32_t in) +static int32_t get_cb(DCAEncContext *c, int32_t in) { - int i, res; + int i, res = 0; + in = FFABS(in); - res = 0; - if (in < 0) - in = -in; for (i = 1024; i > 0; i >>= 1) { - if (cb_to_level[i + res] >= in) + if (c->cb_to_level[i + res] >= in) res += i; } return -res; } -static int32_t add_cb(int32_t a, int32_t b) +static int32_t add_cb(DCAEncContext *c, int32_t a, int32_t b) { if (a < b) FFSWAP(int32_t, a, b); if (a - b >= 256) return a; - return a + cb_to_add[a - b]; + return a + c->cb_to_add[a - b]; +} + +static void calc_power(DCAEncContext *c, + const int32_t in[2 * 256], int32_t power[256]) +{ + int i; + LOCAL_ALIGNED_32(int32_t, data, [512]); + LOCAL_ALIGNED_32(int32_t, coeff, [256]); + + for (i = 0; i < 512; i++) + data[i] = norm__(mul32(in[i], 0x3fffffff - (COS_T(4 * i + 2) >> 1)), 4); + + c->mdct.mdct_calc(&c->mdct, coeff, data); + for (i = 0; i < 256; i++) { + const int32_t cb = get_cb(c, coeff[i]); + power[i] = add_cb(c, cb, cb); + } } -static void adjust_jnd(int samplerate_index, +static void adjust_jnd(DCAEncContext *c, const int32_t in[512], int32_t out_cb[256]) { int32_t power[256]; - cplx32 out[256]; int32_t out_cb_unnorm[256]; int32_t denom; const int32_t ca_cb = -1114; const int32_t cs_cb = 928; + const int samplerate_index = c->samplerate_index; int i, j; - fft(in, out); + calc_power(c, in, power); - for (j = 0; j < 256; j++) { - power[j] = add_cb(get_cb(out[j].re), get_cb(out[j].im)); + for (j = 0; j < 256; j++) out_cb_unnorm[j] = -2047; /* and can only grow */ - } for (i = 0; i < AUBANDS; i++) { denom = ca_cb; /* and can only grow */ for (j = 0; j < 256; j++) - denom = add_cb(denom, power[j] + auf[samplerate_index][i][j]); + denom = add_cb(c, denom, power[j] + c->auf[samplerate_index][i][j]); for (j = 0; j < 256; j++) - out_cb_unnorm[j] = add_cb(out_cb_unnorm[j], - -denom + auf[samplerate_index][i][j]); + out_cb_unnorm[j] = add_cb(c, out_cb_unnorm[j], + -denom + c->auf[samplerate_index][i][j]); } for (j = 0; j < 256; j++) - out_cb[j] = add_cb(out_cb[j], -out_cb_unnorm[j] - ca_cb - cs_cb); + out_cb[j] = add_cb(c, out_cb[j], -out_cb_unnorm[j] - ca_cb - cs_cb); } typedef void (*walk_band_t)(DCAEncContext *c, int band1, int band2, int f, @@ -586,7 +521,7 @@ static void calc_masking(DCAEncContext *c, const int32_t *input) data[i] = c->history[ch][k]; for (k -= 512; i < 512; i++, k++) data[i] = input[k * c->channels + chi]; - adjust_jnd(c->samplerate_index, data, c->masking_curve_cb[ssf]); + adjust_jnd(c, data, c->masking_curve_cb[ssf]); } for (i = 0; i < 256; i++) { int32_t m = 2048; @@ -604,16 +539,16 @@ static void calc_masking(DCAEncContext *c, const int32_t *input) } } -static inline int32_t find_peak(const int32_t *in, int len) { +static inline int32_t find_peak(DCAEncContext *c, const int32_t *in, int len) +{ int sample; int32_t m = 0; for (sample = 0; sample < len; sample++) { int32_t s = abs(in[sample]); - if (m < s) { + if (m < s) m = s; - } } - return get_cb(m); + return get_cb(c, m); } static void find_peaks(DCAEncContext *c) @@ -621,14 +556,13 @@ static void find_peaks(DCAEncContext *c) int band, ch; for (ch = 0; ch < c->fullband_channels; ch++) { - for (band = 0; band < 32; band++) { - c->peak_cb[ch][band] = find_peak(c->subband[ch][band], SUBBAND_SAMPLES); - } + for (band = 0; band < 32; band++) + c->peak_cb[ch][band] = find_peak(c, c->subband[ch][band], + SUBBAND_SAMPLES); } - if (c->lfe_channel) { - c->lfe_peak_cb = find_peak(c->downsampled_lfe, DCA_LFE_SAMPLES); - } + if (c->lfe_channel) + c->lfe_peak_cb = find_peak(c, c->downsampled_lfe, DCA_LFE_SAMPLES); } static void adpcm_analysis(DCAEncContext *c) @@ -642,11 +576,12 @@ static void adpcm_analysis(DCAEncContext *c) for (ch = 0; ch < c->fullband_channels; ch++) { for (band = 0; band < 32; band++) { samples = c->subband[ch][band] - DCA_ADPCM_COEFFS; - pred_vq_id = ff_dcaadpcm_subband_analysis(&c->adpcm_ctx, samples, SUBBAND_SAMPLES, estimated_diff); + pred_vq_id = ff_dcaadpcm_subband_analysis(&c->adpcm_ctx, samples, + SUBBAND_SAMPLES, estimated_diff); if (pred_vq_id >= 0) { c->prediction_mode[ch][band] = pred_vq_id; c->consumed_adpcm_bits += 12; //12 bits to transmit prediction vq index - c->diff_peak_cb[ch][band] = find_peak(estimated_diff, 16); + c->diff_peak_cb[ch][band] = find_peak(c, estimated_diff, 16); } else { c->prediction_mode[ch][band] = -1; } @@ -658,7 +593,7 @@ static const int snr_fudge = 128; #define USED_1ABITS 1 #define USED_26ABITS 4 -static inline int32_t get_step_size(const DCAEncContext *c, int ch, int band) +static inline int32_t get_step_size(DCAEncContext *c, int ch, int band) { int32_t step_size; @@ -670,7 +605,8 @@ static inline int32_t get_step_size(const DCAEncContext *c, int ch, int band) return step_size; } -static int calc_one_scale(int32_t peak_cb, int abits, softfloat *quant) +static int calc_one_scale(DCAEncContext *c, int32_t peak_cb, int abits, + softfloat *quant) { int32_t peak; int our_nscale, try_remove; @@ -680,7 +616,7 @@ static int calc_one_scale(int32_t peak_cb, int abits, softfloat *quant) av_assert0(peak_cb >= -2047); our_nscale = 127; - peak = cb_to_level[-peak_cb]; + peak = c->cb_to_level[-peak_cb]; for (try_remove = 64; try_remove > 0; try_remove >>= 1) { if (scalefactor_inv[our_nscale - try_remove].e + stepsize_inv[abits].e <= 17) @@ -706,15 +642,17 @@ static inline void quantize_adpcm_subband(DCAEncContext *c, int ch, int band) { int32_t step_size; int32_t diff_peak_cb = c->diff_peak_cb[ch][band]; - c->scale_factor[ch][band] = calc_one_scale(diff_peak_cb, + c->scale_factor[ch][band] = calc_one_scale(c, diff_peak_cb, c->abits[ch][band], &c->quant[ch][band]); step_size = get_step_size(c, ch, band); ff_dcaadpcm_do_real(c->prediction_mode[ch][band], - c->quant[ch][band], ff_dca_scale_factor_quant7[c->scale_factor[ch][band]], step_size, - c->adpcm_history[ch][band], c->subband[ch][band], c->adpcm_history[ch][band]+4, c->quantized[ch][band], - SUBBAND_SAMPLES, cb_to_level[-diff_peak_cb]); + c->quant[ch][band], + ff_dca_scale_factor_quant7[c->scale_factor[ch][band]], + step_size, c->adpcm_history[ch][band], c->subband[ch][band], + c->adpcm_history[ch][band] + 4, c->quantized[ch][band], + SUBBAND_SAMPLES, c->cb_to_level[-diff_peak_cb]); } static void quantize_adpcm(DCAEncContext *c) @@ -731,21 +669,31 @@ static void quantize_pcm(DCAEncContext *c) { int sample, band, ch; - for (ch = 0; ch < c->fullband_channels; ch++) - for (band = 0; band < 32; band++) - if (c->prediction_mode[ch][band] == -1) - for (sample = 0; sample < SUBBAND_SAMPLES; sample++) - c->quantized[ch][band][sample] = quantize_value(c->subband[ch][band][sample], c->quant[ch][band]); + for (ch = 0; ch < c->fullband_channels; ch++) { + for (band = 0; band < 32; band++) { + if (c->prediction_mode[ch][band] == -1) { + for (sample = 0; sample < SUBBAND_SAMPLES; sample++) { + int32_t val = quantize_value(c->subband[ch][band][sample], + c->quant[ch][band]); + c->quantized[ch][band][sample] = val; + } + } + } + } } -static void accumulate_huff_bit_consumption(int abits, int32_t *quantized, uint32_t *result) +static void accumulate_huff_bit_consumption(int abits, int32_t *quantized, + uint32_t *result) { uint8_t sel, id = abits - 1; for (sel = 0; sel < ff_dca_quant_index_group_size[id]; sel++) - result[sel] += ff_dca_vlc_calc_quant_bits(quantized, SUBBAND_SAMPLES, sel, id); + result[sel] += ff_dca_vlc_calc_quant_bits(quantized, SUBBAND_SAMPLES, + sel, id); } -static uint32_t set_best_code(uint32_t vlc_bits[DCA_CODE_BOOKS][7], uint32_t clc_bits[DCA_CODE_BOOKS], int32_t res[DCA_CODE_BOOKS]) +static uint32_t set_best_code(uint32_t vlc_bits[DCA_CODE_BOOKS][7], + uint32_t clc_bits[DCA_CODE_BOOKS], + int32_t res[DCA_CODE_BOOKS]) { uint8_t i, sel; uint32_t best_sel_bits[DCA_CODE_BOOKS]; @@ -784,7 +732,8 @@ static uint32_t set_best_code(uint32_t vlc_bits[DCA_CODE_BOOKS][7], uint32_t clc return bits; } -static uint32_t set_best_abits_code(int abits[DCAENC_SUBBANDS], int bands, int32_t *res) +static uint32_t set_best_abits_code(int abits[DCAENC_SUBBANDS], int bands, + int32_t *res) { uint8_t i; uint32_t t; @@ -845,7 +794,8 @@ static int init_quantization_noise(DCAEncContext *c, int noise, int forbid_zero) ret &= ~(USED_26ABITS | USED_1ABITS); } } - c->consumed_bits += set_best_abits_code(c->abits[ch], 32, &c->bit_allocation_sel[ch]); + c->consumed_bits += set_best_abits_code(c->abits[ch], 32, + &c->bit_allocation_sel[ch]); } /* Recalc scale_factor each time to get bits consumption in case of Huffman coding. @@ -854,7 +804,7 @@ static int init_quantization_noise(DCAEncContext *c, int noise, int forbid_zero) for (ch = 0; ch < c->fullband_channels; ch++) { for (band = 0; band < 32; band++) { if (c->prediction_mode[ch][band] == -1) { - c->scale_factor[ch][band] = calc_one_scale(c->peak_cb[ch][band], + c->scale_factor[ch][band] = calc_one_scale(c, c->peak_cb[ch][band], c->abits[ch][band], &c->quant[ch][band]); } @@ -868,7 +818,9 @@ static int init_quantization_noise(DCAEncContext *c, int noise, int forbid_zero) for (ch = 0; ch < c->fullband_channels; ch++) { for (band = 0; band < 32; band++) { if (c->abits[ch][band] && c->abits[ch][band] <= DCA_CODE_BOOKS) { - accumulate_huff_bit_consumption(c->abits[ch][band], c->quantized[ch][band], huff_bit_count_accum[ch][c->abits[ch][band] - 1]); + accumulate_huff_bit_consumption(c->abits[ch][band], + c->quantized[ch][band], + huff_bit_count_accum[ch][c->abits[ch][band] - 1]); clc_bit_count_accum[ch][c->abits[ch][band] - 1] += bit_consumption[c->abits[ch][band]]; } else { bits_counter += bit_consumption[c->abits[ch][band]]; @@ -877,7 +829,9 @@ static int init_quantization_noise(DCAEncContext *c, int noise, int forbid_zero) } for (ch = 0; ch < c->fullband_channels; ch++) { - bits_counter += set_best_code(huff_bit_count_accum[ch], clc_bit_count_accum[ch], c->quant_index_sel[ch]); + bits_counter += set_best_code(huff_bit_count_accum[ch], + clc_bit_count_accum[ch], + c->quant_index_sel[ch]); } c->consumed_bits += bits_counter; @@ -954,7 +908,8 @@ static void fill_in_adpcm_bufer(DCAEncContext *c) step_size = get_step_size(c, ch, band); ff_dca_core_dequantize(c->adpcm_history[ch][band], - c->quantized[ch][band]+12, step_size, ff_dca_scale_factor_quant7[c->scale_factor[ch][band]], 0, 4); + c->quantized[ch][band]+12, step_size, + ff_dca_scale_factor_quant7[c->scale_factor[ch][band]], 0, 4); } else { AV_COPY128U(c->adpcm_history[ch][band], c->adpcm_history[ch][band]+4); } @@ -977,7 +932,7 @@ static void fill_in_adpcm_bufer(DCAEncContext *c) static void calc_lfe_scales(DCAEncContext *c) { if (c->lfe_channel) - c->lfe_scale_factor = calc_one_scale(c->lfe_peak_cb, 11, &c->lfe_quant); + c->lfe_scale_factor = calc_one_scale(c, c->lfe_peak_cb, 11, &c->lfe_quant); } static void put_frame_header(DCAEncContext *c) @@ -1118,7 +1073,8 @@ static void put_subframe_samples(DCAEncContext *c, int ss, int band, int ch) sel = c->quant_index_sel[ch][c->abits[ch][band] - 1]; // Huffman codes if (sel < ff_dca_quant_index_group_size[c->abits[ch][band] - 1]) { - ff_dca_vlc_enc_quant(&c->pb, &c->quantized[ch][band][ss * 8], 8, sel, c->abits[ch][band] - 1); + ff_dca_vlc_enc_quant(&c->pb, &c->quantized[ch][band][ss * 8], 8, + sel, c->abits[ch][band] - 1); return; } @@ -1171,7 +1127,8 @@ static void put_subframe(DCAEncContext *c, int subframe) put_bits(&c->pb, 5, c->abits[ch][band]); } } else { - ff_dca_vlc_enc_alloc(&c->pb, c->abits[ch], DCAENC_SUBBANDS, c->bit_allocation_sel[ch]); + ff_dca_vlc_enc_alloc(&c->pb, c->abits[ch], DCAENC_SUBBANDS, + c->bit_allocation_sel[ch]); } } @@ -1287,6 +1244,7 @@ AVCodec ff_dca_encoder = { .close = encode_close, .encode2 = encode_frame, .capabilities = AV_CODEC_CAP_EXPERIMENTAL, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE }, .supported_samplerates = sample_rates, diff --git a/libavcodec/dirac_dwt.h b/libavcodec/dirac_dwt.h index f9828d95a493b082038b7c2a0d979a4683490895..1af41e07025fe3b5e17d1f0ad20c654e6a487aac 100644 --- a/libavcodec/dirac_dwt.h +++ b/libavcodec/dirac_dwt.h @@ -105,10 +105,10 @@ void ff_spatial_idwt_slice2(DWTContext *d, int y); (int)(((unsigned)(b2) - ((int)(-b0 + 9U*b1 + 9U*b3 - b4 + 16) >> 5))) #define COMPOSE_HAARiL0(b0, b1)\ - (b0 - ((b1 + 1) >> 1)) + ((int)(b0 - (unsigned)((int)(b1 + 1U) >> 1))) #define COMPOSE_HAARiH0(b0, b1)\ - (b0 + b1) + ((int)(b0 + (unsigned)(b1))) #define COMPOSE_FIDELITYiL0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\ ((unsigned)b4 - ((int)(-8*(b0+(unsigned)b8) + 21*(b1+(unsigned)b7) - 46*(b2+(unsigned)b6) + 161*(b3+(unsigned)b5) + 128) >> 8)) diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c index 7157357d593c64313014df13fccfe4be472b778c..530e1c6ffd269a413b613a1f22ae54c185e30d41 100644 --- a/libavcodec/diracdec.c +++ b/libavcodec/diracdec.c @@ -509,16 +509,16 @@ static inline void codeblock(DiracContext *s, SubBand *b, } if (s->codeblock_mode && !(s->old_delta_quant && blockcnt_one)) { - int quant = b->quant; + int quant; if (is_arith) - quant += dirac_get_arith_int(c, CTX_DELTA_Q_F, CTX_DELTA_Q_DATA); + quant = dirac_get_arith_int(c, CTX_DELTA_Q_F, CTX_DELTA_Q_DATA); else - quant += dirac_get_se_golomb(gb); - if (quant < 0) { + quant = dirac_get_se_golomb(gb); + if (quant > INT_MAX - b->quant || b->quant + quant < 0) { av_log(s->avctx, AV_LOG_ERROR, "Invalid quant\n"); return; } - b->quant = quant; + b->quant += quant; } if (b->quant > (DIRAC_MAX_QUANT_INDEX - 1)) { diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 09df4c0c57f07ff8b258fc98b365c09800611ef2..c0c1558ffe634d969d970ef6531b060a9f830007 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -630,10 +630,6 @@ FF_ENABLE_DEPRECATION_WARNINGS s->bits_per_raw_sample = 16; s->use32bit = 1; s->version = FFMAX(s->version, 1); - if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { - av_log(avctx, AV_LOG_ERROR, "16bit RGB is experimental and under development, only use it for experiments\n"); - return AVERROR_INVALIDDATA; - } break; case AV_PIX_FMT_0RGB32: s->colorspace = 1; diff --git a/libavcodec/h264addpx_template.c b/libavcodec/h264addpx_template.c index b71aaea439480002b80612682d63908b7f22b1d7..9a1e6a2f2f603270b9b32a5c12c0108412a329d4 100644 --- a/libavcodec/h264addpx_template.c +++ b/libavcodec/h264addpx_template.c @@ -35,10 +35,10 @@ static void FUNCC(ff_h264_add_pixels4)(uint8_t *_dst, int16_t *_src, int stride) stride /= sizeof(pixel); for (i = 0; i < 4; i++) { - dst[0] += src[0]; - dst[1] += src[1]; - dst[2] += src[2]; - dst[3] += src[3]; + dst[0] += (unsigned)src[0]; + dst[1] += (unsigned)src[1]; + dst[2] += (unsigned)src[2]; + dst[3] += (unsigned)src[3]; dst += stride; src += 4; @@ -55,14 +55,14 @@ static void FUNCC(ff_h264_add_pixels8)(uint8_t *_dst, int16_t *_src, int stride) stride /= sizeof(pixel); for (i = 0; i < 8; i++) { - dst[0] += src[0]; - dst[1] += src[1]; - dst[2] += src[2]; - dst[3] += src[3]; - dst[4] += src[4]; - dst[5] += src[5]; - dst[6] += src[6]; - dst[7] += src[7]; + dst[0] += (unsigned)src[0]; + dst[1] += (unsigned)src[1]; + dst[2] += (unsigned)src[2]; + dst[3] += (unsigned)src[3]; + dst[4] += (unsigned)src[4]; + dst[5] += (unsigned)src[5]; + dst[6] += (unsigned)src[6]; + dst[7] += (unsigned)src[7]; dst += stride; src += 8; diff --git a/libavcodec/jpeg2000dsp.c b/libavcodec/jpeg2000dsp.c index 85a12d0e9b715cbafc8f91564630e20d215d3387..90e73b1e202debf2d73254e05f4332506c3e0238 100644 --- a/libavcodec/jpeg2000dsp.c +++ b/libavcodec/jpeg2000dsp.c @@ -64,9 +64,9 @@ static void ict_int(void *_src0, void *_src1, void *_src2, int csize) int i; for (i = 0; i < csize; i++) { - i0 = *src0 + *src2 + (((26345 * *src2) + (1 << 15)) >> 16); + i0 = *src0 + *src2 + ((int)((26345U * *src2) + (1 << 15)) >> 16); i1 = *src0 - ((int)(((unsigned)i_ict_params[1] * *src1) + (1 << 15)) >> 16) - - (((i_ict_params[2] * *src2) + (1 << 15)) >> 16); + - ((int)(((unsigned)i_ict_params[2] * *src2) + (1 << 15)) >> 16); i2 = *src0 + (2 * *src1) + ((int)((-14942U * *src1) + (1 << 15)) >> 16); *src0++ = i0; *src1++ = i1; diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 52ad2312a3d76cec30741a98056c4e89fc310f32..3c97800ccb5a73d58efa0d98b63be9a02d28981d 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -115,11 +115,11 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx) ctx->params->sourceHeight = avctx->height; ctx->params->bEnablePsnr = !!(avctx->flags & AV_CODEC_FLAG_PSNR); - if ((avctx->color_primaries <= AVCOL_PRI_BT2020 && + if ((avctx->color_primaries <= AVCOL_PRI_SMPTE432 && avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) || - (avctx->color_trc <= AVCOL_TRC_BT2020_12 && + (avctx->color_trc <= AVCOL_TRC_ARIB_STD_B67 && avctx->color_trc != AVCOL_TRC_UNSPECIFIED) || - (avctx->colorspace <= AVCOL_SPC_BT2020_CL && + (avctx->colorspace <= AVCOL_SPC_ICTCP && avctx->colorspace != AVCOL_SPC_UNSPECIFIED)) { ctx->params->vui.bEnableVideoSignalTypePresentFlag = 1; diff --git a/libavcodec/opus.c b/libavcodec/opus.c index 9cbf4aed92868794264b344acb3fae8d6788136b..aa827b604c53340ca84b6ab3edb5943f5329ddba 100644 --- a/libavcodec/opus.c +++ b/libavcodec/opus.c @@ -566,13 +566,14 @@ void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode) int bits2[CELT_MAX_BANDS]; /* Spread */ - if (opus_rc_tell(rc) + 4 <= f->framebits) + if (opus_rc_tell(rc) + 4 <= f->framebits) { if (encode) ff_opus_rc_enc_cdf(rc, f->spread, ff_celt_model_spread); else f->spread = ff_opus_rc_dec_cdf(rc, ff_celt_model_spread); - else + } else { f->spread = CELT_SPREAD_NORMAL; + } /* Initialize static allocation caps */ for (i = 0; i < CELT_MAX_BANDS; i++) diff --git a/libavcodec/opus_parser.c b/libavcodec/opus_parser.c index 893573eb822988b0860bd84d95d57f38f9fa0f8f..28b093390099e6dd9a753acd689f2074317bb27d 100644 --- a/libavcodec/opus_parser.c +++ b/libavcodec/opus_parser.c @@ -43,6 +43,7 @@ static const uint8_t *parse_opus_ts_header(const uint8_t *start, int *payload_le const uint8_t *buf = start + 1; int start_trim_flag, end_trim_flag, control_extension_flag, control_extension_length; uint8_t flags; + uint64_t payload_len_tmp; GetByteContext gb; bytestream2_init(&gb, buf, buf_len); @@ -52,11 +53,11 @@ static const uint8_t *parse_opus_ts_header(const uint8_t *start, int *payload_le end_trim_flag = (flags >> 3) & 1; control_extension_flag = (flags >> 2) & 1; - *payload_len = 0; + payload_len_tmp = *payload_len = 0; while (bytestream2_peek_byte(&gb) == 0xff) - *payload_len += bytestream2_get_byte(&gb); + payload_len_tmp += bytestream2_get_byte(&gb); - *payload_len += bytestream2_get_byte(&gb); + payload_len_tmp += bytestream2_get_byte(&gb); if (start_trim_flag) bytestream2_skip(&gb, 2); @@ -67,6 +68,11 @@ static const uint8_t *parse_opus_ts_header(const uint8_t *start, int *payload_le bytestream2_skip(&gb, control_extension_length); } + if (bytestream2_tell(&gb) + payload_len_tmp > buf_len) + return NULL; + + *payload_len = payload_len_tmp; + return buf + bytestream2_tell(&gb); } @@ -104,6 +110,10 @@ static int opus_find_frame_end(AVCodecParserContext *ctx, AVCodecContext *avctx, state = (state << 8) | payload[i]; if ((state & OPUS_TS_MASK) == OPUS_TS_HEADER) { payload = parse_opus_ts_header(payload, &payload_len, buf_size - i); + if (!payload) { + av_log(avctx, AV_LOG_ERROR, "Error parsing Ogg TS header.\n"); + return AVERROR_INVALIDDATA; + } *header_len = payload - buf; start_found = 1; break; diff --git a/libavcodec/opusenc_psy.c b/libavcodec/opusenc_psy.c index b7126033441e3b27ba423a691f34bfe52b649d26..8aded2140de152c2c55354996b787ef27e2a3dbb 100644 --- a/libavcodec/opusenc_psy.c +++ b/libavcodec/opusenc_psy.c @@ -119,7 +119,7 @@ static void step_collect_psy_metrics(OpusPsyContext *s, int index) for (j = 0; j < range; j++) { const float c_s = coeffs[j]*coeffs[j]; - dist_dev = (avg_c_s - c_s)*(avg_c_s - c_s); + dist_dev += (avg_c_s - c_s)*(avg_c_s - c_s); } st->tone[ch][i] += sqrtf(dist_dev); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 4d736d2e7d2fdb106519b61b5941732b2fa1d815..4c718432ad06c5712074ef75e95cbd6b011dc7f9 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -608,7 +608,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code ff_lock_avcodec(avctx, codec); - avctx->internal = av_mallocz(sizeof(AVCodecInternal)); + avctx->internal = av_mallocz(sizeof(*avctx->internal)); if (!avctx->internal) { ret = AVERROR(ENOMEM); goto end; @@ -1099,7 +1099,7 @@ void avsubtitle_free(AVSubtitle *sub) av_freep(&sub->rects); - memset(sub, 0, sizeof(AVSubtitle)); + memset(sub, 0, sizeof(*sub)); } av_cold int avcodec_close(AVCodecContext *avctx) diff --git a/libavcodec/x86/hevc_sao.asm b/libavcodec/x86/hevc_sao.asm index 888a28afa7c48444e3a077e769b84d14107133e4..756adfee5784cbd3fc672f7494055b5c1e7ca9cc 100644 --- a/libavcodec/x86/hevc_sao.asm +++ b/libavcodec/x86/hevc_sao.asm @@ -198,7 +198,7 @@ HEVC_SAO_BAND_FILTER 64, 2 ;****************************************************************************** %define MAX_PB_SIZE 64 -%define PADDING_SIZE 32 ; AV_INPUT_BUFFER_PADDING_SIZE +%define PADDING_SIZE 64 ; AV_INPUT_BUFFER_PADDING_SIZE %define EDGE_SRCSTRIDE 2 * MAX_PB_SIZE + PADDING_SIZE %macro HEVC_SAO_EDGE_FILTER_INIT 0 diff --git a/libavcodec/x86/hevc_sao_10bit.asm b/libavcodec/x86/hevc_sao_10bit.asm index f81e2d503391db6d19843ddf9f9bfb6b0934b4d1..b30583dd2f8782eb503c3476cb4e7875260cf344 100644 --- a/libavcodec/x86/hevc_sao_10bit.asm +++ b/libavcodec/x86/hevc_sao_10bit.asm @@ -190,7 +190,7 @@ HEVC_SAO_BAND_FILTER 12, 64, 4 ;****************************************************************************** %define MAX_PB_SIZE 64 -%define PADDING_SIZE 32 ; AV_INPUT_BUFFER_PADDING_SIZE +%define PADDING_SIZE 64 ; AV_INPUT_BUFFER_PADDING_SIZE %define EDGE_SRCSTRIDE 2 * MAX_PB_SIZE + PADDING_SIZE %macro PMINUW 4 diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c index 87f5012034ce97c7441fbc4aaa13cdbbb5d46f78..ff2ef3b1629f34faf7c91791be198cf73de77f02 100644 --- a/libavdevice/gdigrab.c +++ b/libavdevice/gdigrab.c @@ -235,7 +235,9 @@ gdigrab_read_header(AVFormatContext *s1) AVStream *st = NULL; int bpp; + int horzres; int vertres; + int desktophorzres; int desktopvertres; RECT virtual_rect; RECT clip_rect; @@ -279,11 +281,13 @@ gdigrab_read_header(AVFormatContext *s1) GetClientRect(hwnd, &virtual_rect); } else { /* desktop -- get the right height and width for scaling DPI */ + horzres = GetDeviceCaps(source_hdc, HORZRES); vertres = GetDeviceCaps(source_hdc, VERTRES); + desktophorzres = GetDeviceCaps(source_hdc, DESKTOPHORZRES); desktopvertres = GetDeviceCaps(source_hdc, DESKTOPVERTRES); virtual_rect.left = GetSystemMetrics(SM_XVIRTUALSCREEN); virtual_rect.top = GetSystemMetrics(SM_YVIRTUALSCREEN); - virtual_rect.right = (virtual_rect.left + GetSystemMetrics(SM_CXVIRTUALSCREEN)) * desktopvertres / vertres; + virtual_rect.right = (virtual_rect.left + GetSystemMetrics(SM_CXVIRTUALSCREEN)) * desktophorzres / horzres; virtual_rect.bottom = (virtual_rect.top + GetSystemMetrics(SM_CYVIRTUALSCREEN)) * desktopvertres / vertres; } @@ -447,7 +451,9 @@ static void paint_mouse_pointer(AVFormatContext *s1, struct gdigrab *gdigrab) POINT pos; RECT clip_rect = gdigrab->clip_rect; HWND hwnd = gdigrab->hwnd; + int horzres = GetDeviceCaps(gdigrab->source_hdc, HORZRES); int vertres = GetDeviceCaps(gdigrab->source_hdc, VERTRES); + int desktophorzres = GetDeviceCaps(gdigrab->source_hdc, DESKTOPHORZRES); int desktopvertres = GetDeviceCaps(gdigrab->source_hdc, DESKTOPVERTRES); info.hbmMask = NULL; info.hbmColor = NULL; @@ -483,7 +489,7 @@ static void paint_mouse_pointer(AVFormatContext *s1, struct gdigrab *gdigrab) } //that would keep the correct location of mouse with hidpi screens - pos.x = pos.x * desktopvertres / vertres; + pos.x = pos.x * desktophorzres / horzres; pos.y = pos.y * desktopvertres / vertres; av_log(s1, AV_LOG_DEBUG, "Cursor pos (%li,%li) -> (%li,%li)\n", diff --git a/libavfilter/af_aiir.c b/libavfilter/af_aiir.c index f4485b019470eb58829a092f09470f2f1478aded..1f2a568c1d906713358e58dfda45c3ecf9808eee 100644 --- a/libavfilter/af_aiir.c +++ b/libavfilter/af_aiir.c @@ -27,31 +27,52 @@ #include "avfilter.h" #include "internal.h" +typedef struct ThreadData { + AVFrame *in, *out; +} ThreadData; + +typedef struct Pair { + int a, b; +} Pair; + +typedef struct BiquadContext { + double a0, a1, a2; + double b0, b1, b2; + double i1, i2; + double o1, o2; +} BiquadContext; + +typedef struct IIRChannel { + int nb_ab[2]; + double *ab[2]; + double g; + double *cache[2]; + BiquadContext *biquads; + int clippings; +} IIRChannel; + typedef struct AudioIIRContext { const AVClass *class; char *a_str, *b_str, *g_str; double dry_gain, wet_gain; int format; + int process; + int precision; - int *nb_a, *nb_b; - double **a, **b; - double *g; - double **input, **output; - int clippings; + IIRChannel *iir; int channels; + enum AVSampleFormat sample_format; - void (*iir_frame)(AVFilterContext *ctx, AVFrame *in, AVFrame *out); + int (*iir_channel)(AVFilterContext *ctx, void *arg, int ch, int nb_jobs); } AudioIIRContext; static int query_formats(AVFilterContext *ctx) { + AudioIIRContext *s = ctx->priv; AVFilterFormats *formats; AVFilterChannelLayouts *layouts; - static const enum AVSampleFormat sample_fmts[] = { + enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_DBLP, - AV_SAMPLE_FMT_FLTP, - AV_SAMPLE_FMT_S32P, - AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE }; int ret; @@ -63,6 +84,7 @@ static int query_formats(AVFilterContext *ctx) if (ret < 0) return ret; + sample_fmts[0] = s->sample_format; formats = ff_make_format_list(sample_fmts); if (!formats) return AVERROR(ENOMEM); @@ -76,56 +98,118 @@ static int query_formats(AVFilterContext *ctx) return ff_set_common_samplerates(ctx, formats); } -#define IIR_FRAME(name, type, min, max, need_clipping) \ -static void iir_frame_## name(AVFilterContext *ctx, AVFrame *in, AVFrame *out) \ +#define IIR_CH(name, type, min, max, need_clipping) \ +static int iir_ch_## name(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) \ { \ AudioIIRContext *s = ctx->priv; \ const double ig = s->dry_gain; \ const double og = s->wet_gain; \ - int ch, n; \ + ThreadData *td = arg; \ + AVFrame *in = td->in, *out = td->out; \ + const type *src = (const type *)in->extended_data[ch]; \ + double *ic = (double *)s->iir[ch].cache[0]; \ + double *oc = (double *)s->iir[ch].cache[1]; \ + const int nb_a = s->iir[ch].nb_ab[0]; \ + const int nb_b = s->iir[ch].nb_ab[1]; \ + const double *a = s->iir[ch].ab[0]; \ + const double *b = s->iir[ch].ab[1]; \ + int *clippings = &s->iir[ch].clippings; \ + type *dst = (type *)out->extended_data[ch]; \ + int n; \ \ - for (ch = 0; ch < out->channels; ch++) { \ - const type *src = (const type *)in->extended_data[ch]; \ - double *ic = (double *)s->input[ch]; \ - double *oc = (double *)s->output[ch]; \ - const int nb_a = s->nb_a[ch]; \ - const int nb_b = s->nb_b[ch]; \ - const double *a = s->a[ch]; \ - const double *b = s->b[ch]; \ - type *dst = (type *)out->extended_data[ch]; \ + for (n = 0; n < in->nb_samples; n++) { \ + double sample = 0.; \ + int x; \ \ - for (n = 0; n < in->nb_samples; n++) { \ - double sample = 0.; \ - int x; \ + memmove(&ic[1], &ic[0], (nb_b - 1) * sizeof(*ic)); \ + memmove(&oc[1], &oc[0], (nb_a - 1) * sizeof(*oc)); \ + ic[0] = src[n] * ig; \ + for (x = 0; x < nb_b; x++) \ + sample += b[x] * ic[x]; \ \ - memmove(&ic[1], &ic[0], (nb_b - 1) * sizeof(*ic)); \ - memmove(&oc[1], &oc[0], (nb_a - 1) * sizeof(*oc)); \ - ic[0] = src[n] * ig; \ - for (x = 0; x < nb_b; x++) \ - sample += b[x] * ic[x]; \ + for (x = 1; x < nb_a; x++) \ + sample -= a[x] * oc[x]; \ \ - for (x = 1; x < nb_a; x++) \ - sample -= a[x] * oc[x]; \ + oc[0] = sample; \ + sample *= og; \ + if (need_clipping && sample < min) { \ + (*clippings)++; \ + dst[n] = min; \ + } else if (need_clipping && sample > max) { \ + (*clippings)++; \ + dst[n] = max; \ + } else { \ + dst[n] = sample; \ + } \ + } \ \ - oc[0] = sample; \ - sample *= og; \ - if (need_clipping && sample < min) { \ - s->clippings++; \ + return 0; \ +} + +IIR_CH(s16p, int16_t, INT16_MIN, INT16_MAX, 1) +IIR_CH(s32p, int32_t, INT32_MIN, INT32_MAX, 1) +IIR_CH(fltp, float, -1., 1., 0) +IIR_CH(dblp, double, -1., 1., 0) + +#define SERIAL_IIR_CH(name, type, min, max, need_clipping) \ +static int iir_ch_serial_## name(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) \ +{ \ + AudioIIRContext *s = ctx->priv; \ + const double ig = s->dry_gain; \ + const double og = s->wet_gain; \ + ThreadData *td = arg; \ + AVFrame *in = td->in, *out = td->out; \ + const type *src = (const type *)in->extended_data[ch]; \ + type *dst = (type *)out->extended_data[ch]; \ + IIRChannel *iir = &s->iir[ch]; \ + int *clippings = &iir->clippings; \ + int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2; \ + int n, i; \ + \ + for (i = 0; i < nb_biquads; i++) { \ + const double a1 = -iir->biquads[i].a1; \ + const double a2 = -iir->biquads[i].a2; \ + const double b0 = iir->biquads[i].b0; \ + const double b1 = iir->biquads[i].b1; \ + const double b2 = iir->biquads[i].b2; \ + double i1 = iir->biquads[i].i1; \ + double i2 = iir->biquads[i].i2; \ + double o1 = iir->biquads[i].o1; \ + double o2 = iir->biquads[i].o2; \ + \ + for (n = 0; n < in->nb_samples; n++) { \ + double sample = ig * (i ? dst[n] : src[n]); \ + double o0 = sample * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \ + \ + i2 = i1; \ + i1 = src[n]; \ + o2 = o1; \ + o1 = o0; \ + o0 *= og; \ + \ + if (need_clipping && o0 < min) { \ + (*clippings)++; \ dst[n] = min; \ - } else if (need_clipping && sample > max) { \ - s->clippings++; \ + } else if (need_clipping && o0 > max) { \ + (*clippings)++; \ dst[n] = max; \ } else { \ - dst[n] = sample; \ + dst[n] = o0; \ } \ } \ + iir->biquads[i].i1 = i1; \ + iir->biquads[i].i2 = i2; \ + iir->biquads[i].o1 = o1; \ + iir->biquads[i].o2 = o2; \ } \ + \ + return 0; \ } -IIR_FRAME(s16p, int16_t, INT16_MIN, INT16_MAX, 1) -IIR_FRAME(s32p, int32_t, INT32_MIN, INT32_MAX, 1) -IIR_FRAME(fltp, float, -1., 1., 0) -IIR_FRAME(dblp, double, -1., 1., 0) +SERIAL_IIR_CH(s16p, int16_t, INT16_MIN, INT16_MAX, 1) +SERIAL_IIR_CH(s32p, int32_t, INT32_MIN, INT32_MAX, 1) +SERIAL_IIR_CH(fltp, float, -1., 1., 0) +SERIAL_IIR_CH(dblp, double, -1., 1., 0) static void count_coefficients(char *item_str, int *nb_items) { @@ -141,8 +225,9 @@ static void count_coefficients(char *item_str, int *nb_items) } } -static int read_gains(AVFilterContext *ctx, char *item_str, int nb_items, double *dst) +static int read_gains(AVFilterContext *ctx, char *item_str, int nb_items) { + AudioIIRContext *s = ctx->priv; char *p, *arg, *old_str, *prev_arg = NULL, *saveptr = NULL; int i; @@ -159,7 +244,7 @@ static int read_gains(AVFilterContext *ctx, char *item_str, int nb_items, double } p = NULL; - if (sscanf(arg, "%lf", &dst[i]) != 1) { + if (sscanf(arg, "%lf", &s->iir[i].g) != 1) { av_log(ctx, AV_LOG_ERROR, "Invalid gains supplied: %s\n", arg); av_freep(&old_str); return AVERROR(EINVAL); @@ -198,7 +283,7 @@ static int read_tf_coefficients(AVFilterContext *ctx, char *item_str, int nb_ite return 0; } -static int read_zp_coefficients(AVFilterContext *ctx, char *item_str, int nb_items, double *dst) +static int read_zp_coefficients(AVFilterContext *ctx, char *item_str, int nb_items, double *dst, const char *format) { char *p, *arg, *old_str, *saveptr = NULL; int i; @@ -211,7 +296,7 @@ static int read_zp_coefficients(AVFilterContext *ctx, char *item_str, int nb_ite break; p = NULL; - if (sscanf(arg, "%lf %lfi", &dst[i*2], &dst[i*2+1]) != 2) { + if (sscanf(arg, format, &dst[i*2], &dst[i*2+1]) != 2) { av_log(ctx, AV_LOG_ERROR, "Invalid coefficients supplied: %s\n", arg); av_freep(&old_str); return AVERROR(EINVAL); @@ -223,7 +308,9 @@ static int read_zp_coefficients(AVFilterContext *ctx, char *item_str, int nb_ite return 0; } -static int read_channels(AVFilterContext *ctx, int channels, uint8_t *item_str, int *nb, double **c, double **cache) +static const char *format[] = { "%lf", "%lf %lfi", "%lf %lfr", "%lf %lfd" }; + +static int read_channels(AVFilterContext *ctx, int channels, uint8_t *item_str, int ab) { AudioIIRContext *s = ctx->priv; char *p, *arg, *old_str, *prev_arg = NULL, *saveptr = NULL; @@ -233,6 +320,8 @@ static int read_channels(AVFilterContext *ctx, int channels, uint8_t *item_str, if (!p) return AVERROR(ENOMEM); for (i = 0; i < channels; i++) { + IIRChannel *iir = &s->iir[i]; + if (!(arg = av_strtok(p, "|", &saveptr))) arg = prev_arg; @@ -241,20 +330,20 @@ static int read_channels(AVFilterContext *ctx, int channels, uint8_t *item_str, return AVERROR(EINVAL); } - count_coefficients(arg, &nb[i]); + count_coefficients(arg, &iir->nb_ab[ab]); p = NULL; - cache[i] = av_calloc(nb[i] + 1, sizeof(double)); - c[i] = av_calloc(nb[i] * (s->format + 1), sizeof(double)); - if (!c[i] || !cache[i]) { + iir->cache[ab] = av_calloc(iir->nb_ab[ab] + 1, sizeof(double)); + iir->ab[ab] = av_calloc(iir->nb_ab[ab] * (!!s->format + 1), sizeof(double)); + if (!iir->ab[ab] || !iir->cache[ab]) { av_freep(&old_str); return AVERROR(ENOMEM); } if (s->format) { - ret = read_zp_coefficients(ctx, arg, nb[i], c[i]); + ret = read_zp_coefficients(ctx, arg, iir->nb_ab[ab], iir->ab[ab], format[s->format]); } else { - ret = read_tf_coefficients(ctx, arg, nb[i], c[i]); + ret = read_tf_coefficients(ctx, arg, iir->nb_ab[ab], iir->ab[ab]); } if (ret < 0) { av_freep(&old_str); @@ -304,7 +393,7 @@ static int expand(AVFilterContext *ctx, double *pz, int nb, double *coeffs) multiply(pz[2 * i], pz[2 * i + 1], nb, coeffs); for (i = 0; i < nb + 1; i++) { - if (fabs(coeffs[2 * i + 1]) > DBL_EPSILON) { + if (fabs(coeffs[2 * i + 1]) > FLT_EPSILON) { av_log(ctx, AV_LOG_ERROR, "coeff: %lf of z^%d is not real; poles/zeros are not complex conjugates.\n", coeffs[2 * i + 1], i); return AVERROR(EINVAL); @@ -317,47 +406,242 @@ static int expand(AVFilterContext *ctx, double *pz, int nb, double *coeffs) static int convert_zp2tf(AVFilterContext *ctx, int channels) { AudioIIRContext *s = ctx->priv; - int ch, i, j, ret; + int ch, i, j, ret = 0; for (ch = 0; ch < channels; ch++) { + IIRChannel *iir = &s->iir[ch]; double *topc, *botc; - topc = av_calloc((s->nb_b[ch] + 1) * 2, sizeof(*topc)); - botc = av_calloc((s->nb_a[ch] + 1) * 2, sizeof(*botc)); - if (!topc || !botc) - return AVERROR(ENOMEM); + topc = av_calloc((iir->nb_ab[0] + 1) * 2, sizeof(*topc)); + botc = av_calloc((iir->nb_ab[1] + 1) * 2, sizeof(*botc)); + if (!topc || !botc) { + ret = AVERROR(ENOMEM); + goto fail; + } - ret = expand(ctx, s->a[ch], s->nb_a[ch], botc); + ret = expand(ctx, iir->ab[0], iir->nb_ab[0], botc); if (ret < 0) { - av_free(topc); - av_free(botc); - return ret; + goto fail; } - ret = expand(ctx, s->b[ch], s->nb_b[ch], topc); + ret = expand(ctx, iir->ab[1], iir->nb_ab[1], topc); if (ret < 0) { - av_free(topc); - av_free(botc); - return ret; + goto fail; } - for (j = 0, i = s->nb_b[ch]; i >= 0; j++, i--) { - s->b[ch][j] = topc[2 * i]; + for (j = 0, i = iir->nb_ab[1]; i >= 0; j++, i--) { + iir->ab[1][j] = topc[2 * i]; } - s->nb_b[ch]++; + iir->nb_ab[1]++; - for (j = 0, i = s->nb_a[ch]; i >= 0; j++, i--) { - s->a[ch][j] = botc[2 * i]; + for (j = 0, i = iir->nb_ab[0]; i >= 0; j++, i--) { + iir->ab[0][j] = botc[2 * i]; } - s->nb_a[ch]++; + iir->nb_ab[0]++; +fail: av_free(topc); av_free(botc); + if (ret < 0) + break; + } + + return ret; +} + +static int decompose_zp2biquads(AVFilterContext *ctx, int channels) +{ + AudioIIRContext *s = ctx->priv; + int ch, ret; + + for (ch = 0; ch < channels; ch++) { + IIRChannel *iir = &s->iir[ch]; + int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2; + int current_biquad = 0; + + iir->biquads = av_calloc(nb_biquads, sizeof(BiquadContext)); + if (!iir->biquads) + return AVERROR(ENOMEM); + + while (nb_biquads--) { + Pair outmost_pole = { -1, -1 }; + Pair nearest_zero = { -1, -1 }; + double zeros[4] = { 0 }; + double poles[4] = { 0 }; + double b[6] = { 0 }; + double a[6] = { 0 }; + double min_distance = DBL_MAX; + double max_mag = 0; + int i; + + for (i = 0; i < iir->nb_ab[0]; i++) { + double mag; + + if (isnan(iir->ab[0][2 * i]) || isnan(iir->ab[0][2 * i + 1])) + continue; + mag = hypot(iir->ab[0][2 * i], iir->ab[0][2 * i + 1]); + + if (mag > max_mag) { + max_mag = mag; + outmost_pole.a = i; + } + } + + for (i = 0; i < iir->nb_ab[1]; i++) { + if (isnan(iir->ab[0][2 * i]) || isnan(iir->ab[0][2 * i + 1])) + continue; + + if (iir->ab[0][2 * i ] == iir->ab[0][2 * outmost_pole.a ] && + iir->ab[0][2 * i + 1] == -iir->ab[0][2 * outmost_pole.a + 1]) { + outmost_pole.b = i; + break; + } + } + + av_log(ctx, AV_LOG_VERBOSE, "outmost_pole is %d.%d\n", outmost_pole.a, outmost_pole.b); + + if (outmost_pole.a < 0 || outmost_pole.b < 0) + return AVERROR(EINVAL); + + for (i = 0; i < iir->nb_ab[1]; i++) { + double distance; + + if (isnan(iir->ab[1][2 * i]) || isnan(iir->ab[1][2 * i + 1])) + continue; + distance = hypot(iir->ab[0][2 * outmost_pole.a ] - iir->ab[1][2 * i ], + iir->ab[0][2 * outmost_pole.a + 1] - iir->ab[1][2 * i + 1]); + + if (distance < min_distance) { + min_distance = distance; + nearest_zero.a = i; + } + } + + for (i = 0; i < iir->nb_ab[1]; i++) { + if (isnan(iir->ab[1][2 * i]) || isnan(iir->ab[1][2 * i + 1])) + continue; + + if (iir->ab[1][2 * i ] == iir->ab[1][2 * nearest_zero.a ] && + iir->ab[1][2 * i + 1] == -iir->ab[1][2 * nearest_zero.a + 1]) { + nearest_zero.b = i; + break; + } + } + + av_log(ctx, AV_LOG_VERBOSE, "nearest_zero is %d.%d\n", nearest_zero.a, nearest_zero.b); + + if (nearest_zero.a < 0 || nearest_zero.b < 0) + return AVERROR(EINVAL); + + poles[0] = iir->ab[0][2 * outmost_pole.a ]; + poles[1] = iir->ab[0][2 * outmost_pole.a + 1]; + + zeros[0] = iir->ab[1][2 * nearest_zero.a ]; + zeros[1] = iir->ab[1][2 * nearest_zero.a + 1]; + + if (nearest_zero.a == nearest_zero.b && outmost_pole.a == outmost_pole.b) { + zeros[2] = 0; + zeros[3] = 0; + + poles[2] = 0; + poles[3] = 0; + } else { + poles[2] = iir->ab[0][2 * outmost_pole.b ]; + poles[3] = iir->ab[0][2 * outmost_pole.b + 1]; + + zeros[2] = iir->ab[1][2 * nearest_zero.b ]; + zeros[3] = iir->ab[1][2 * nearest_zero.b + 1]; + } + + ret = expand(ctx, zeros, 2, b); + if (ret < 0) + return ret; + + ret = expand(ctx, poles, 2, a); + if (ret < 0) + return ret; + + iir->ab[0][2 * outmost_pole.a] = iir->ab[0][2 * outmost_pole.a + 1] = NAN; + iir->ab[0][2 * outmost_pole.b] = iir->ab[0][2 * outmost_pole.b + 1] = NAN; + iir->ab[1][2 * nearest_zero.a] = iir->ab[1][2 * nearest_zero.a + 1] = NAN; + iir->ab[1][2 * nearest_zero.b] = iir->ab[1][2 * nearest_zero.b + 1] = NAN; + + iir->biquads[current_biquad].a0 = 1.0; + iir->biquads[current_biquad].a1 = a[2] / a[4]; + iir->biquads[current_biquad].a2 = a[0] / a[4]; + iir->biquads[current_biquad].b0 = b[4] / a[4] * (current_biquad ? 1.0 : iir->g); + iir->biquads[current_biquad].b1 = b[2] / a[4] * (current_biquad ? 1.0 : iir->g); + iir->biquads[current_biquad].b2 = b[0] / a[4] * (current_biquad ? 1.0 : iir->g); + + av_log(ctx, AV_LOG_VERBOSE, "a=%lf %lf %lf:b=%lf %lf %lf\n", + iir->biquads[current_biquad].a0, + iir->biquads[current_biquad].a1, + iir->biquads[current_biquad].a2, + iir->biquads[current_biquad].b0, + iir->biquads[current_biquad].b1, + iir->biquads[current_biquad].b2); + + current_biquad++; + } } return 0; } +static void convert_pr2zp(AVFilterContext *ctx, int channels) +{ + AudioIIRContext *s = ctx->priv; + int ch; + + for (ch = 0; ch < channels; ch++) { + IIRChannel *iir = &s->iir[ch]; + int n; + + for (n = 0; n < iir->nb_ab[0]; n++) { + double r = iir->ab[0][2*n]; + double angle = iir->ab[0][2*n+1]; + + iir->ab[0][2*n] = r * cos(angle); + iir->ab[0][2*n+1] = r * sin(angle); + } + + for (n = 0; n < iir->nb_ab[1]; n++) { + double r = iir->ab[1][2*n]; + double angle = iir->ab[1][2*n+1]; + + iir->ab[1][2*n] = r * cos(angle); + iir->ab[1][2*n+1] = r * sin(angle); + } + } +} + +static void convert_pd2zp(AVFilterContext *ctx, int channels) +{ + AudioIIRContext *s = ctx->priv; + int ch; + + for (ch = 0; ch < channels; ch++) { + IIRChannel *iir = &s->iir[ch]; + int n; + + for (n = 0; n < iir->nb_ab[0]; n++) { + double r = iir->ab[0][2*n]; + double angle = M_PI*iir->ab[0][2*n+1]/180.; + + iir->ab[0][2*n] = r * cos(angle); + iir->ab[0][2*n+1] = r * sin(angle); + } + + for (n = 0; n < iir->nb_ab[1]; n++) { + double r = iir->ab[1][2*n]; + double angle = M_PI*iir->ab[1][2*n+1]/180.; + + iir->ab[1][2*n] = r * cos(angle); + iir->ab[1][2*n+1] = r * sin(angle); + } + } +} + static int config_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; @@ -366,49 +650,66 @@ static int config_output(AVFilterLink *outlink) int ch, ret, i; s->channels = inlink->channels; - s->a = av_calloc(inlink->channels, sizeof(*s->a)); - s->b = av_calloc(inlink->channels, sizeof(*s->b)); - s->g = av_calloc(inlink->channels, sizeof(*s->g)); - s->nb_a = av_calloc(inlink->channels, sizeof(*s->nb_a)); - s->nb_b = av_calloc(inlink->channels, sizeof(*s->nb_b)); - s->input = av_calloc(inlink->channels, sizeof(*s->input)); - s->output = av_calloc(inlink->channels, sizeof(*s->output)); - if (!s->a || !s->b || !s->nb_a || !s->nb_b || !s->input || !s->output) + s->iir = av_calloc(s->channels, sizeof(*s->iir)); + if (!s->iir) return AVERROR(ENOMEM); - ret = read_gains(ctx, s->g_str, inlink->channels, s->g); + ret = read_gains(ctx, s->g_str, inlink->channels); if (ret < 0) return ret; - ret = read_channels(ctx, inlink->channels, s->a_str, s->nb_a, s->a, s->output); + ret = read_channels(ctx, inlink->channels, s->a_str, 0); if (ret < 0) return ret; - ret = read_channels(ctx, inlink->channels, s->b_str, s->nb_b, s->b, s->input); + ret = read_channels(ctx, inlink->channels, s->b_str, 1); if (ret < 0) return ret; - if (s->format) { + if (s->format == 2) { + convert_pr2zp(ctx, inlink->channels); + } else if (s->format == 3) { + convert_pd2zp(ctx, inlink->channels); + } + + if (s->format == 0) + av_log(ctx, AV_LOG_WARNING, "tf coefficients format is not recommended for too high number of zeros/poles.\n"); + + if (s->format > 0 && s->process == 0) { + av_log(ctx, AV_LOG_WARNING, "Direct processsing is not recommended for zp coefficients format.\n"); + ret = convert_zp2tf(ctx, inlink->channels); if (ret < 0) return ret; + } else if (s->format == 0 && s->process == 1) { + av_log(ctx, AV_LOG_ERROR, "Serial cascading is not implemented for transfer function.\n"); + return AVERROR_PATCHWELCOME; + } else if (s->format > 0 && s->process == 1) { + if (inlink->format == AV_SAMPLE_FMT_S16P) + av_log(ctx, AV_LOG_WARNING, "Serial cascading is not recommended for i16 precision.\n"); + + ret = decompose_zp2biquads(ctx, inlink->channels); + if (ret < 0) + return ret; } for (ch = 0; ch < inlink->channels; ch++) { - for (i = 1; i < s->nb_a[ch]; i++) { - s->a[ch][i] /= s->a[ch][0]; + IIRChannel *iir = &s->iir[ch]; + + for (i = 1; i < iir->nb_ab[0]; i++) { + iir->ab[0][i] /= iir->ab[0][0]; } - for (i = 0; i < s->nb_b[ch]; i++) { - s->b[ch][i] *= s->g[ch] / s->a[ch][0]; + for (i = 0; i < iir->nb_ab[1]; i++) { + iir->ab[1][i] *= iir->g / iir->ab[0][0]; } } switch (inlink->format) { - case AV_SAMPLE_FMT_DBLP: s->iir_frame = iir_frame_dblp; break; - case AV_SAMPLE_FMT_FLTP: s->iir_frame = iir_frame_fltp; break; - case AV_SAMPLE_FMT_S32P: s->iir_frame = iir_frame_s32p; break; - case AV_SAMPLE_FMT_S16P: s->iir_frame = iir_frame_s16p; break; + case AV_SAMPLE_FMT_DBLP: s->iir_channel = s->process == 1 ? iir_ch_serial_dblp : iir_ch_dblp; break; + case AV_SAMPLE_FMT_FLTP: s->iir_channel = s->process == 1 ? iir_ch_serial_fltp : iir_ch_fltp; break; + case AV_SAMPLE_FMT_S32P: s->iir_channel = s->process == 1 ? iir_ch_serial_s32p : iir_ch_s32p; break; + case AV_SAMPLE_FMT_S16P: s->iir_channel = s->process == 1 ? iir_ch_serial_s16p : iir_ch_s16p; break; } return 0; @@ -419,7 +720,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AVFilterContext *ctx = inlink->dst; AudioIIRContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; + ThreadData td; AVFrame *out; + int ch; if (av_frame_is_writable(in)) { out = in; @@ -432,11 +735,16 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) av_frame_copy_props(out, in); } - s->iir_frame(ctx, in, out); + td.in = in; + td.out = out; + ctx->internal->execute(ctx, s->iir_channel, &td, NULL, outlink->channels); - if (s->clippings > 0) - av_log(ctx, AV_LOG_WARNING, "clipping %d times. Please reduce gain.\n", s->clippings); - s->clippings = 0; + for (ch = 0; ch < outlink->channels; ch++) { + if (s->iir[ch].clippings > 0) + av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n", + ch, s->iir[ch].clippings); + s->iir[ch].clippings = 0; + } if (in != out) av_frame_free(&in); @@ -453,6 +761,14 @@ static av_cold int init(AVFilterContext *ctx) return AVERROR(EINVAL); } + switch (s->precision) { + case 0: s->sample_format = AV_SAMPLE_FMT_DBLP; break; + case 1: s->sample_format = AV_SAMPLE_FMT_FLTP; break; + case 2: s->sample_format = AV_SAMPLE_FMT_S32P; break; + case 3: s->sample_format = AV_SAMPLE_FMT_S16P; break; + default: return AVERROR_BUG; + } + return 0; } @@ -461,29 +777,17 @@ static av_cold void uninit(AVFilterContext *ctx) AudioIIRContext *s = ctx->priv; int ch; - if (s->a) { - for (ch = 0; ch < s->channels; ch++) { - av_freep(&s->a[ch]); - av_freep(&s->output[ch]); - } - } - av_freep(&s->a); - - if (s->b) { + if (s->iir) { for (ch = 0; ch < s->channels; ch++) { - av_freep(&s->b[ch]); - av_freep(&s->input[ch]); + IIRChannel *iir = &s->iir[ch]; + av_freep(&iir->ab[0]); + av_freep(&iir->ab[1]); + av_freep(&iir->cache[0]); + av_freep(&iir->cache[1]); + av_freep(&iir->biquads); } } - av_freep(&s->b); - - av_freep(&s->g); - - av_freep(&s->input); - av_freep(&s->output); - - av_freep(&s->nb_a); - av_freep(&s->nb_b); + av_freep(&s->iir); } static const AVFilterPad inputs[] = { @@ -508,14 +812,24 @@ static const AVFilterPad outputs[] = { #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM static const AVOption aiir_options[] = { - { "z", "set B/numerator/zeros coefficients", OFFSET(b_str), AV_OPT_TYPE_STRING, {.str="1 1"}, 0, 0, AF }, - { "p", "set A/denominator/poles coefficients", OFFSET(a_str), AV_OPT_TYPE_STRING, {.str="1 1"}, 0, 0, AF }, + { "z", "set B/numerator/zeros coefficients", OFFSET(b_str), AV_OPT_TYPE_STRING, {.str="1+0i 1-0i"}, 0, 0, AF }, + { "p", "set A/denominator/poles coefficients", OFFSET(a_str), AV_OPT_TYPE_STRING, {.str="1+0i 1-0i"}, 0, 0, AF }, { "k", "set channels gains", OFFSET(g_str), AV_OPT_TYPE_STRING, {.str="1|1"}, 0, 0, AF }, { "dry", "set dry gain", OFFSET(dry_gain), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, AF }, { "wet", "set wet gain", OFFSET(wet_gain), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, AF }, - { "f", "set coefficients format", OFFSET(format), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, AF, "format" }, + { "f", "set coefficients format", OFFSET(format), AV_OPT_TYPE_INT, {.i64=1}, 0, 3, AF, "format" }, { "tf", "transfer function", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "format" }, { "zp", "Z-plane zeros/poles", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "format" }, + { "pr", "Z-plane zeros/poles (polar radians)", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "format" }, + { "pd", "Z-plane zeros/poles (polar degrees)", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "format" }, + { "r", "set kind of processing", OFFSET(process), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, AF, "process" }, + { "d", "direct", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "process" }, + { "s", "serial cascading", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "process" }, + { "e", "set precision", OFFSET(precision),AV_OPT_TYPE_INT, {.i64=0}, 0, 3, AF, "precision" }, + { "dbl", "double-precision floating-point", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision" }, + { "flt", "single-precision floating-point", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision" }, + { "i32", "32-bit integers", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision" }, + { "i16", "16-bit integers", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision" }, { NULL }, }; @@ -525,10 +839,11 @@ AVFilter ff_af_aiir = { .name = "aiir", .description = NULL_IF_CONFIG_SMALL("Apply Infinite Impulse Response filter with supplied coefficients."), .priv_size = sizeof(AudioIIRContext), + .priv_class = &aiir_class, .init = init, .uninit = uninit, .query_formats = query_formats, .inputs = inputs, .outputs = outputs, - .priv_class = &aiir_class, + .flags = AVFILTER_FLAG_SLICE_THREADS, }; diff --git a/libavfilter/vf_framerate.c b/libavfilter/vf_framerate.c index 38f45a8033c13a1be8067d8b2e36f6cf66456b60..a5ae6ddb7135c4387d2e29b53f7119e00303557a 100644 --- a/libavfilter/vf_framerate.c +++ b/libavfilter/vf_framerate.c @@ -39,8 +39,6 @@ #include "internal.h" #include "video.h" -#define N_SRCE 3 - typedef struct FrameRateContext { const AVClass *class; // parameters @@ -55,30 +53,25 @@ typedef struct FrameRateContext { int line_size[4]; ///< bytes of pixel data per line for each plane int vsub; - int frst, next, prev, crnt, last; - int pending_srce_frames; ///< how many input frames are still waiting to be processed - int flush; ///< are we flushing final frames - int pending_end_frame; ///< flag indicating we are waiting to call filter_frame() - AVRational srce_time_base; ///< timebase of source - AVRational dest_time_base; ///< timebase of destination - int32_t dest_frame_num; - int64_t last_dest_frame_pts; ///< pts of the last frame output - int64_t average_srce_pts_dest_delta;///< average input pts delta converted from input rate to output rate - int64_t average_dest_pts_delta; ///< calculated average output pts delta av_pixelutils_sad_fn sad; ///< Sum of the absolute difference function (scene detect only) double prev_mafd; ///< previous MAFD (scene detect only) - AVFrame *srce[N_SRCE]; ///< buffered source frames - int64_t srce_pts_dest[N_SRCE]; ///< pts for source frames scaled to output timebase - double srce_score[N_SRCE]; ///< scene change score compared to the next srce frame - int64_t pts; ///< pts of frame we are working on - int max; int bitdepth; AVFrame *work; + + AVFrame *f0; ///< last frame + AVFrame *f1; ///< current frame + int64_t pts0; ///< last frame pts in dest_time_base + int64_t pts1; ///< current frame pts in dest_time_base + int64_t delta; ///< pts1 to pts0 delta + double score; ///< scene change score (f0 to f1) + int flush; ///< 1 if the filter is being flushed + int64_t start_pts; ///< pts of the first output frame + int64_t n; ///< output frame counter } FrameRateContext; #define OFFSET(x) offsetof(FrameRateContext, x) @@ -102,27 +95,6 @@ static const AVOption framerate_options[] = { AVFILTER_DEFINE_CLASS(framerate); -static void next_source(AVFilterContext *ctx) -{ - FrameRateContext *s = ctx->priv; - int i; - - ff_dlog(ctx, "next_source()\n"); - - if (s->srce[s->last] && s->srce[s->last] != s->srce[s->last-1]) { - ff_dlog(ctx, "next_source() unlink %d\n", s->last); - av_frame_free(&s->srce[s->last]); - } - for (i = s->last; i > s->frst; i--) { - ff_dlog(ctx, "next_source() copy %d to %d\n", i - 1, i); - s->srce[i] = s->srce[i - 1]; - s->srce_score[i] = s->srce_score[i - 1]; - } - ff_dlog(ctx, "next_source() make %d null\n", s->frst); - s->srce[s->frst] = NULL; - s->srce_score[s->frst] = -1.0; -} - static av_always_inline int64_t sad_8x8_16(const uint16_t *src1, ptrdiff_t stride1, const uint16_t *src2, ptrdiff_t stride2) { @@ -307,28 +279,25 @@ static int filter_slice16(AVFilterContext *ctx, void *arg, int job, int nb_jobs) return 0; } -static int blend_frames(AVFilterContext *ctx, int interpolate, - int src1, int src2) +static int blend_frames(AVFilterContext *ctx, int interpolate) { FrameRateContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; double interpolate_scene_score = 0; - if ((s->flags & FRAMERATE_FLAG_SCD) && s->srce[src1] && s->srce[src2]) { - int i1 = src1 < src2 ? src1 : src2; - int i2 = src1 < src2 ? src2 : src1; - if (i2 == i1 + 1 && s->srce_score[i1] >= 0.0) - interpolate_scene_score = s->srce_score[i1]; + if ((s->flags & FRAMERATE_FLAG_SCD)) { + if (s->score >= 0.0) + interpolate_scene_score = s->score; else - interpolate_scene_score = s->srce_score[i1] = get_scene_score(ctx, s->srce[i1], s->srce[i2]); + interpolate_scene_score = s->score = get_scene_score(ctx, s->f0, s->f1); ff_dlog(ctx, "blend_frames() interpolate scene score:%f\n", interpolate_scene_score); } // decide if the shot-change detection allows us to blend two frames - if (interpolate_scene_score < s->scene_score && s->srce[src2]) { + if (interpolate_scene_score < s->scene_score) { ThreadData td; - td.copy_src1 = s->srce[src1]; - td.copy_src2 = s->srce[src2]; - td.src2_factor = FFABS(interpolate); + td.copy_src1 = s->f0; + td.copy_src2 = s->f1; + td.src2_factor = interpolate; td.src1_factor = s->max - td.src2_factor; // get work-space for output frame @@ -336,7 +305,7 @@ static int blend_frames(AVFilterContext *ctx, int interpolate, if (!s->work) return AVERROR(ENOMEM); - av_frame_copy_props(s->work, s->srce[s->crnt]); + av_frame_copy_props(s->work, s->f0); ff_dlog(ctx, "blend_frames() INTERPOLATE to create work frame\n"); ctx->internal->execute(ctx, s->bitdepth == 8 ? filter_slice8 : filter_slice16, &td, NULL, FFMIN(outlink->h, ff_filter_get_nb_threads(ctx))); @@ -345,198 +314,65 @@ static int blend_frames(AVFilterContext *ctx, int interpolate, return 0; } -static int process_work_frame(AVFilterContext *ctx, int stop) +static int process_work_frame(AVFilterContext *ctx) { FrameRateContext *s = ctx->priv; - int64_t work_next_pts; + int64_t work_pts; int interpolate; - int src1, src2; - - ff_dlog(ctx, "process_work_frame()\n"); - - ff_dlog(ctx, "process_work_frame() pending_input_frames %d\n", s->pending_srce_frames); - - if (s->srce[s->prev]) ff_dlog(ctx, "process_work_frame() srce prev pts:%"PRId64"\n", s->srce[s->prev]->pts); - if (s->srce[s->crnt]) ff_dlog(ctx, "process_work_frame() srce crnt pts:%"PRId64"\n", s->srce[s->crnt]->pts); - if (s->srce[s->next]) ff_dlog(ctx, "process_work_frame() srce next pts:%"PRId64"\n", s->srce[s->next]->pts); + int ret; - if (!s->srce[s->crnt]) { - // the filter cannot do anything - ff_dlog(ctx, "process_work_frame() no current frame cached: move on to next frame, do not output a frame\n"); - next_source(ctx); + if (!s->f1) return 0; - } - - work_next_pts = s->pts + s->average_dest_pts_delta; - - ff_dlog(ctx, "process_work_frame() work crnt pts:%"PRId64"\n", s->pts); - ff_dlog(ctx, "process_work_frame() work next pts:%"PRId64"\n", work_next_pts); - if (s->srce[s->prev]) - ff_dlog(ctx, "process_work_frame() srce prev pts:%"PRId64" at dest time base:%u/%u\n", - s->srce_pts_dest[s->prev], s->dest_time_base.num, s->dest_time_base.den); - if (s->srce[s->crnt]) - ff_dlog(ctx, "process_work_frame() srce crnt pts:%"PRId64" at dest time base:%u/%u\n", - s->srce_pts_dest[s->crnt], s->dest_time_base.num, s->dest_time_base.den); - if (s->srce[s->next]) - ff_dlog(ctx, "process_work_frame() srce next pts:%"PRId64" at dest time base:%u/%u\n", - s->srce_pts_dest[s->next], s->dest_time_base.num, s->dest_time_base.den); - - av_assert0(s->srce[s->next]); - - // should filter be skipping input frame (output frame rate is lower than input frame rate) - if (!s->flush && s->pts >= s->srce_pts_dest[s->next]) { - ff_dlog(ctx, "process_work_frame() work crnt pts >= srce next pts: SKIP FRAME, move on to next frame, do not output a frame\n"); - next_source(ctx); - s->pending_srce_frames--; + if (!s->f0 && !s->flush) return 0; - } - // calculate interpolation - interpolate = av_rescale(s->pts - s->srce_pts_dest[s->crnt], s->max, s->average_srce_pts_dest_delta); - ff_dlog(ctx, "process_work_frame() interpolate:%d/%d\n", interpolate, s->max); - src1 = s->crnt; - if (interpolate > s->interp_end) { - ff_dlog(ctx, "process_work_frame() source is:NEXT\n"); - src1 = s->next; - } - if (s->srce[s->prev] && interpolate < -s->interp_end) { - ff_dlog(ctx, "process_work_frame() source is:PREV\n"); - src1 = s->prev; - } + work_pts = s->start_pts + av_rescale_q(s->n, av_inv_q(s->dest_frame_rate), s->dest_time_base); + + if (work_pts >= s->pts1 && !s->flush) + return 0; - // decide whether to blend two frames - if ((interpolate >= s->interp_start && interpolate <= s->interp_end) || (interpolate <= -s->interp_start && interpolate >= -s->interp_end)) { - if (interpolate > 0) { - ff_dlog(ctx, "process_work_frame() interpolate source is:NEXT\n"); - src2 = s->next; + if (!s->f0) { + s->work = av_frame_clone(s->f1); + } else { + if (work_pts >= s->pts1 + s->delta && s->flush) + return 0; + + interpolate = av_rescale(work_pts - s->pts0, s->max, s->delta); + ff_dlog(ctx, "process_work_frame() interpolate:%d/%d\n", interpolate, s->max); + if (interpolate > s->interp_end) { + s->work = av_frame_clone(s->f1); + } else if (interpolate < s->interp_start) { + s->work = av_frame_clone(s->f0); } else { - ff_dlog(ctx, "process_work_frame() interpolate source is:PREV\n"); - src2 = s->prev; + ret = blend_frames(ctx, interpolate); + if (ret < 0) + return ret; + if (ret == 0) + s->work = av_frame_clone(interpolate > (s->max >> 1) ? s->f1 : s->f0); } - if (blend_frames(ctx, interpolate, src1, src2)) - goto copy_done; - else - ff_dlog(ctx, "process_work_frame() CUT - DON'T INTERPOLATE\n"); } - ff_dlog(ctx, "process_work_frame() COPY to the work frame\n"); - // copy the frame we decided is our base source - s->work = av_frame_clone(s->srce[src1]); if (!s->work) return AVERROR(ENOMEM); -copy_done: - s->work->pts = s->pts; - - // should filter be re-using input frame (output frame rate is higher than input frame rate) - if (!s->flush && (work_next_pts + s->average_dest_pts_delta) < (s->srce_pts_dest[s->crnt] + s->average_srce_pts_dest_delta)) { - ff_dlog(ctx, "process_work_frame() REPEAT FRAME\n"); - } else { - ff_dlog(ctx, "process_work_frame() CONSUME FRAME, move to next frame\n"); - s->pending_srce_frames--; - next_source(ctx); - } - ff_dlog(ctx, "process_work_frame() output a frame\n"); - s->dest_frame_num++; - if (stop) - s->pending_end_frame = 0; - s->last_dest_frame_pts = s->work->pts; + s->work->pts = work_pts; + s->n++; return 1; } -static void set_srce_frame_dest_pts(AVFilterContext *ctx) -{ - FrameRateContext *s = ctx->priv; - - ff_dlog(ctx, "set_srce_frame_output_pts()\n"); - - // scale the input pts from the timebase difference between input and output - if (s->srce[s->prev]) - s->srce_pts_dest[s->prev] = av_rescale_q(s->srce[s->prev]->pts, s->srce_time_base, s->dest_time_base); - if (s->srce[s->crnt]) - s->srce_pts_dest[s->crnt] = av_rescale_q(s->srce[s->crnt]->pts, s->srce_time_base, s->dest_time_base); - if (s->srce[s->next]) - s->srce_pts_dest[s->next] = av_rescale_q(s->srce[s->next]->pts, s->srce_time_base, s->dest_time_base); -} - -static void set_work_frame_pts(AVFilterContext *ctx) -{ - FrameRateContext *s = ctx->priv; - int64_t pts, average_srce_pts_delta = 0; - - ff_dlog(ctx, "set_work_frame_pts()\n"); - - av_assert0(s->srce[s->next]); - av_assert0(s->srce[s->crnt]); - - ff_dlog(ctx, "set_work_frame_pts() srce crnt pts:%"PRId64"\n", s->srce[s->crnt]->pts); - ff_dlog(ctx, "set_work_frame_pts() srce next pts:%"PRId64"\n", s->srce[s->next]->pts); - if (s->srce[s->prev]) - ff_dlog(ctx, "set_work_frame_pts() srce prev pts:%"PRId64"\n", s->srce[s->prev]->pts); - - average_srce_pts_delta = s->average_srce_pts_dest_delta; - ff_dlog(ctx, "set_work_frame_pts() initial average srce pts:%"PRId64"\n", average_srce_pts_delta); - - set_srce_frame_dest_pts(ctx); - - // calculate the PTS delta - if ((pts = (s->srce_pts_dest[s->next] - s->srce_pts_dest[s->crnt]))) { - average_srce_pts_delta = average_srce_pts_delta?((average_srce_pts_delta+pts)>>1):pts; - } else if (s->srce[s->prev] && (pts = (s->srce_pts_dest[s->crnt] - s->srce_pts_dest[s->prev]))) { - average_srce_pts_delta = average_srce_pts_delta?((average_srce_pts_delta+pts)>>1):pts; - } - - s->average_srce_pts_dest_delta = average_srce_pts_delta; - ff_dlog(ctx, "set_work_frame_pts() average srce pts:%"PRId64"\n", average_srce_pts_delta); - ff_dlog(ctx, "set_work_frame_pts() average srce pts:%"PRId64" at dest time base:%u/%u\n", - s->average_srce_pts_dest_delta, s->dest_time_base.num, s->dest_time_base.den); - - if (ctx->inputs[0] && !s->average_dest_pts_delta) { - int64_t d = av_q2d(av_inv_q(av_mul_q(s->dest_time_base, s->dest_frame_rate))); - s->average_dest_pts_delta = d; - ff_dlog(ctx, "set_work_frame_pts() average dest pts delta:%"PRId64"\n", s->average_dest_pts_delta); - } - - if (!s->dest_frame_num) { - s->pts = s->last_dest_frame_pts = s->srce_pts_dest[s->crnt]; - } else { - s->pts = s->last_dest_frame_pts + s->average_dest_pts_delta; - } - - ff_dlog(ctx, "set_work_frame_pts() calculated pts:%"PRId64" at dest time base:%u/%u\n", - s->pts, s->dest_time_base.num, s->dest_time_base.den); -} - static av_cold int init(AVFilterContext *ctx) { FrameRateContext *s = ctx->priv; - int i; - - s->dest_frame_num = 0; - - s->crnt = (N_SRCE)>>1; - s->last = N_SRCE - 1; - - s->next = s->crnt - 1; - s->prev = s->crnt + 1; - - for (i = 0; i < N_SRCE; i++) - s->srce_score[i] = -1.0; - + s->start_pts = AV_NOPTS_VALUE; return 0; } static av_cold void uninit(AVFilterContext *ctx) { FrameRateContext *s = ctx->priv; - int i; - - for (i = s->frst; i < s->last; i++) { - if (s->srce[i] && (s->srce[i] != s->srce[i + 1])) - av_frame_free(&s->srce[i]); - } - av_frame_free(&s->srce[s->last]); + av_frame_free(&s->f0); + av_frame_free(&s->f1); } static int query_formats(AVFilterContext *ctx) @@ -593,28 +429,48 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) int ret; AVFilterContext *ctx = inlink->dst; FrameRateContext *s = ctx->priv; - - // we have one new frame - s->pending_srce_frames++; + int64_t pts; if (inpicref->interlaced_frame) av_log(ctx, AV_LOG_WARNING, "Interlaced frame found - the output will not be correct.\n"); - // store the pointer to the new frame - av_frame_free(&s->srce[s->frst]); - s->srce[s->frst] = inpicref; + if (inpicref->pts == AV_NOPTS_VALUE) { + av_log(ctx, AV_LOG_WARNING, "Ignoring frame without PTS.\n"); + return 0; + } - if (!s->pending_end_frame && s->srce[s->crnt]) { - set_work_frame_pts(ctx); - s->pending_end_frame = 1; - } else { - set_srce_frame_dest_pts(ctx); + pts = av_rescale_q(inpicref->pts, s->srce_time_base, s->dest_time_base); + if (s->f1 && pts == s->pts1) { + av_log(ctx, AV_LOG_WARNING, "Ignoring frame with same PTS.\n"); + return 0; } - ret = process_work_frame(ctx, 1); - if (ret < 0) - return ret; - return ret ? ff_filter_frame(ctx->outputs[0], s->work) : 0; + av_frame_free(&s->f0); + s->f0 = s->f1; + s->pts0 = s->pts1; + s->f1 = inpicref; + s->pts1 = pts; + s->delta = s->pts1 - s->pts0; + s->score = -1.0; + + if (s->delta < 0) { + av_log(ctx, AV_LOG_WARNING, "PTS discontinuity.\n"); + s->start_pts = s->pts1; + s->n = 0; + av_frame_free(&s->f0); + } + + if (s->start_pts == AV_NOPTS_VALUE) + s->start_pts = s->pts1; + + do { + ret = process_work_frame(ctx); + if (ret <= 0) + return ret; + ret = ff_filter_frame(ctx->outputs[0], s->work); + } while (ret >= 0); + + return ret; } static int config_output(AVFilterLink *outlink) @@ -666,50 +522,21 @@ static int request_frame(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; FrameRateContext *s = ctx->priv; - int ret, i; + int ret; ff_dlog(ctx, "request_frame()\n"); - // if there is no "next" frame AND we are not in flush then get one from our input filter - if (!s->srce[s->frst] && !s->flush) - goto request; - - ff_dlog(ctx, "request_frame() REPEAT or FLUSH\n"); - - if (s->pending_srce_frames <= 0) { - ff_dlog(ctx, "request_frame() nothing else to do, return:EOF\n"); - return AVERROR_EOF; - } - - // otherwise, make brand-new frame and pass to our output filter - ff_dlog(ctx, "request_frame() FLUSH\n"); - - // back fill at end of file when source has no more frames - for (i = s->last; i > s->frst; i--) { - if (!s->srce[i - 1] && s->srce[i]) { - ff_dlog(ctx, "request_frame() copy:%d to:%d\n", i, i - 1); - s->srce[i - 1] = s->srce[i]; - } - } - - set_work_frame_pts(ctx); - ret = process_work_frame(ctx, 0); - if (ret < 0) - return ret; - if (ret) - return ff_filter_frame(ctx->outputs[0], s->work); - -request: - ff_dlog(ctx, "request_frame() call source's request_frame()\n"); ret = ff_request_frame(ctx->inputs[0]); - if (ret < 0 && (ret != AVERROR_EOF)) { - ff_dlog(ctx, "request_frame() source's request_frame() returned error:%d\n", ret); - return ret; - } else if (ret == AVERROR_EOF) { + if (ret == AVERROR_EOF && s->f1 && !s->flush) { s->flush = 1; + ret = process_work_frame(ctx); + if (ret < 0) + return ret; + ret = ret ? ff_filter_frame(ctx->outputs[0], s->work) : AVERROR_EOF; } + ff_dlog(ctx, "request_frame() source's request_frame() returned:%d\n", ret); - return 0; + return ret; } static const AVFilterPad framerate_inputs[] = { diff --git a/libavfilter/vf_overlay_opencl.c b/libavfilter/vf_overlay_opencl.c index 46ce42df847b3e391bc36b4e3e868073c1f56dea..ee8381dfee2df45904ed89a866fecd16f7ac2b52 100644 --- a/libavfilter/vf_overlay_opencl.c +++ b/libavfilter/vf_overlay_opencl.c @@ -250,6 +250,7 @@ fail_kernel_arg: kernel_arg, cle); err = AVERROR(EIO); fail: + av_frame_free(&output); return err; } diff --git a/libavfilter/vf_program_opencl.c b/libavfilter/vf_program_opencl.c index d49365aa55889001e8b19491c8a339164b73655f..4ee9668236c246f35cb131da604630ce79863c8b 100644 --- a/libavfilter/vf_program_opencl.c +++ b/libavfilter/vf_program_opencl.c @@ -116,12 +116,14 @@ static int program_opencl_run(AVFilterContext *avctx) if (cle != CL_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " "destination image argument: %d.\n", cle); + err = AVERROR_UNKNOWN; goto fail; } cle = clSetKernelArg(ctx->kernel, 1, sizeof(cl_uint), &ctx->index); if (cle != CL_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " "index argument: %d.\n", cle); + err = AVERROR_UNKNOWN; goto fail; } @@ -135,6 +137,7 @@ static int program_opencl_run(AVFilterContext *avctx) if (cle != CL_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " "source image argument %d: %d.\n", input, cle); + err = AVERROR_UNKNOWN; goto fail; } } diff --git a/libavfilter/x86/vf_interlace.asm b/libavfilter/x86/vf_interlace.asm index 06b269828a27e0280bbeb51c0288bb94e4be8c24..a6c65b805dc266ec567d50675bf58cebdec6e2db 100644 --- a/libavfilter/x86/vf_interlace.asm +++ b/libavfilter/x86/vf_interlace.asm @@ -39,6 +39,20 @@ SECTION .text pcmpeq%1 m6, m6 + test hq, mmsize + je .loop + + ;process 1 * mmsize + movu m0, [mrefq+hq] + pavg%1 m0, [prefq+hq] + pxor m0, m6 + pxor m2, m6, [srcq+hq] + pavg%1 m0, m2 + pxor m0, m6 + mova [dstq+hq], m0 + add hq, mmsize + jge .end + .loop: movu m0, [mrefq+hq] movu m1, [mrefq+hq+mmsize] @@ -57,7 +71,9 @@ SECTION .text add hq, 2*mmsize jl .loop -REP_RET + +.end: + REP_RET %endmacro %macro LOWPASS_LINE 0 @@ -201,5 +217,10 @@ LOWPASS_LINE INIT_XMM avx LOWPASS_LINE +%if HAVE_AVX2_EXTERNAL +INIT_YMM avx2 +LOWPASS_LINE +%endif + INIT_XMM sse2 LOWPASS_LINE_COMPLEX diff --git a/libavfilter/x86/vf_interlace_init.c b/libavfilter/x86/vf_interlace_init.c index b024b6173574978d72879678097022a5cd879998..0de0fea382e53a5bd1441aeba90e25f3a27197a7 100644 --- a/libavfilter/x86/vf_interlace_init.c +++ b/libavfilter/x86/vf_interlace_init.c @@ -32,6 +32,9 @@ void ff_lowpass_line_sse2(uint8_t *dstp, ptrdiff_t linesize, void ff_lowpass_line_avx (uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp, ptrdiff_t mref, ptrdiff_t pref, int clip_max); +void ff_lowpass_line_avx2 (uint8_t *dstp, ptrdiff_t linesize, + const uint8_t *srcp, ptrdiff_t mref, + ptrdiff_t pref, int clip_max); void ff_lowpass_line_16_sse2(uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp, ptrdiff_t mref, @@ -39,6 +42,9 @@ void ff_lowpass_line_16_sse2(uint8_t *dstp, ptrdiff_t linesize, void ff_lowpass_line_16_avx (uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp, ptrdiff_t mref, ptrdiff_t pref, int clip_max); +void ff_lowpass_line_16_avx2 (uint8_t *dstp, ptrdiff_t linesize, + const uint8_t *srcp, ptrdiff_t mref, + ptrdiff_t pref, int clip_max); void ff_lowpass_line_complex_sse2(uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp, ptrdiff_t mref, @@ -62,6 +68,9 @@ av_cold void ff_interlace_init_x86(InterlaceContext *s, int depth) if (EXTERNAL_AVX(cpu_flags)) if (s->lowpass == VLPF_LIN) s->lowpass_line = ff_lowpass_line_16_avx; + if (EXTERNAL_AVX2_FAST(cpu_flags)) + if (s->lowpass == VLPF_LIN) + s->lowpass_line = ff_lowpass_line_16_avx2; } else { if (EXTERNAL_SSE2(cpu_flags)) { if (s->lowpass == VLPF_LIN) @@ -72,5 +81,8 @@ av_cold void ff_interlace_init_x86(InterlaceContext *s, int depth) if (EXTERNAL_AVX(cpu_flags)) if (s->lowpass == VLPF_LIN) s->lowpass_line = ff_lowpass_line_avx; + if (EXTERNAL_AVX2_FAST(cpu_flags)) + if (s->lowpass == VLPF_LIN) + s->lowpass_line = ff_lowpass_line_avx2; } } diff --git a/libavfilter/x86/vf_tinterlace_init.c b/libavfilter/x86/vf_tinterlace_init.c index 209812964d0ed0131e08f3a7d86bd5866ea933ba..2c9b1de581f37c3771f2570d736cdbe845d657bf 100644 --- a/libavfilter/x86/vf_tinterlace_init.c +++ b/libavfilter/x86/vf_tinterlace_init.c @@ -33,6 +33,9 @@ void ff_lowpass_line_sse2(uint8_t *dstp, ptrdiff_t linesize, void ff_lowpass_line_avx (uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp, ptrdiff_t mref, ptrdiff_t pref, int clip_max); +void ff_lowpass_line_avx2 (uint8_t *dstp, ptrdiff_t linesize, + const uint8_t *srcp, ptrdiff_t mref, + ptrdiff_t pref, int clip_max); void ff_lowpass_line_16_sse2(uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp, ptrdiff_t mref, @@ -40,6 +43,9 @@ void ff_lowpass_line_16_sse2(uint8_t *dstp, ptrdiff_t linesize, void ff_lowpass_line_16_avx (uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp, ptrdiff_t mref, ptrdiff_t pref, int clip_max); +void ff_lowpass_line_16_avx2 (uint8_t *dstp, ptrdiff_t linesize, + const uint8_t *srcp, ptrdiff_t mref, + ptrdiff_t pref, int clip_max); void ff_lowpass_line_complex_sse2(uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp, ptrdiff_t mref, @@ -63,6 +69,11 @@ av_cold void ff_tinterlace_init_x86(TInterlaceContext *s) if (EXTERNAL_AVX(cpu_flags)) if (!(s->flags & TINTERLACE_FLAG_CVLPF)) s->lowpass_line = ff_lowpass_line_16_avx; + if (EXTERNAL_AVX2_FAST(cpu_flags)) { + if (!(s->flags & TINTERLACE_FLAG_CVLPF)) { + s->lowpass_line = ff_lowpass_line_16_avx2; + } + } } else { if (EXTERNAL_SSE2(cpu_flags)) { if (!(s->flags & TINTERLACE_FLAG_CVLPF)) @@ -73,5 +84,10 @@ av_cold void ff_tinterlace_init_x86(TInterlaceContext *s) if (EXTERNAL_AVX(cpu_flags)) if (!(s->flags & TINTERLACE_FLAG_CVLPF)) s->lowpass_line = ff_lowpass_line_avx; + if (EXTERNAL_AVX2_FAST(cpu_flags)) { + if (!(s->flags & TINTERLACE_FLAG_CVLPF)) { + s->lowpass_line = ff_lowpass_line_avx2; + } + } } } diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c index e87fbc5661c1fc0a9a58ff7fdd6eb7a185b350e5..7c701e0c700769d5e47b990f463393f9aca153e1 100644 --- a/libavformat/aiffdec.c +++ b/libavformat/aiffdec.c @@ -81,11 +81,10 @@ static void get_meta(AVFormatContext *s, const char *key, int size) av_free(str); return; } - size += (size&1)-res; + size -= res; str[res] = 0; av_dict_set(&s->metadata, key, str, AV_DICT_DONT_STRDUP_VAL); - }else - size+= size&1; + } avio_skip(s->pb, size); } diff --git a/libavformat/http.c b/libavformat/http.c index 4806b1e59b38fab8ceb3585f10fa11a56f495677..510b23375a301f7a78869ea8af8b45dd68d25edb 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -824,6 +824,7 @@ static int parse_cookie(HTTPContext *s, const char *p, AVDictionary **cookies) } } } + av_dict_free(&new_params); // duplicate the cookie name (dict will dupe the value) if (!(eql = strchr(p, '='))) return AVERROR(EINVAL); diff --git a/libavformat/libopenmpt.c b/libavformat/libopenmpt.c index af6eb1ac4a02865bdae377dc1436958e605fdc94..30c3d6e646f018b3087eee83d6bc89d981ad499c 100644 --- a/libavformat/libopenmpt.c +++ b/libavformat/libopenmpt.c @@ -21,6 +21,14 @@ #include #include +#include +/* Shims to support libopenmpt < 0.3.0 (as documented by libopenmpt) */ +#if !defined(OPENMPT_API_VERSION_MAKE) +#define OPENMPT_API_VERSION_MAKE(major, minor, patch) (((major)<<24)|((minor)<<16)|((patch)<<0)) +#endif +#if !defined(OPENMPT_API_VERSION_AT_LEAST) +#define OPENMPT_API_VERSION_AT_LEAST(major, minor, patch) (OPENMPT_API_VERSION >= OPENMPT_API_VERSION_MAKE((major), (minor), (patch))) +#endif #include "libavutil/avstring.h" #include "libavutil/opt.h" @@ -72,13 +80,17 @@ static int read_header_openmpt(AVFormatContext *s) { AVStream *st; OpenMPTContext *openmpt = s->priv_data; - int64_t size = avio_size(s->pb); - if (size <= 0) - return AVERROR_INVALIDDATA; - char *buf = av_malloc(size); + int64_t size; + char *buf; +#if OPENMPT_API_VERSION_AT_LEAST(0,3,0) + int error; +#endif int ret; - + size = avio_size(s->pb); + if (size <= 0) + return AVERROR_INVALIDDATA; + buf = av_malloc(size); if (!buf) return AVERROR(ENOMEM); size = avio_read(s->pb, buf, size); @@ -88,10 +100,24 @@ static int read_header_openmpt(AVFormatContext *s) return size; } +#if OPENMPT_API_VERSION_AT_LEAST(0,3,0) + error = OPENMPT_ERROR_OK; + openmpt->module = openmpt_module_create_from_memory2(buf, size, openmpt_logfunc, s, NULL, NULL, &error, NULL, NULL); + av_freep(&buf); + if (!openmpt->module) { + if (error == OPENMPT_ERROR_OUT_OF_MEMORY) + return AVERROR(ENOMEM); + else if (error >= OPENMPT_ERROR_GENERAL) + return AVERROR_INVALIDDATA; + else + return AVERROR_UNKNOWN; + } +#else openmpt->module = openmpt_module_create_from_memory(buf, size, openmpt_logfunc, s, NULL); av_freep(&buf); if (!openmpt->module) return AVERROR_INVALIDDATA; +#endif openmpt->channels = av_get_channel_layout_nb_channels(openmpt->layout); diff --git a/libavformat/oggparseogm.c b/libavformat/oggparseogm.c index 3c5c7abbda7daedbd1253038975915ff2880789b..ca6b62669d5a5182ed2566cfbe445b8078deef60 100644 --- a/libavformat/oggparseogm.c +++ b/libavformat/oggparseogm.c @@ -24,7 +24,6 @@ #include -#include "libavutil/avassert.h" #include "libavutil/intreadwrite.h" #include "libavcodec/bytestream.h" diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index b016185a1b733056c12533bcf906aeaac640e466..e280be4d44e650895db7a5ef7473960c9a4efa61 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -822,6 +822,7 @@ static int w64_read_header(AVFormatContext *s) samples = avio_rl64(pb); if (samples > 0) st->duration = samples; + avio_skip(pb, FFALIGN(size, INT64_C(8)) - 32); } else if (!memcmp(guid, ff_w64_guid_data, 16)) { wav->data_end = avio_tell(pb) + size - 24; diff --git a/libavresample/avresample.h b/libavresample/avresample.h index 440e1a16e749ee7f6d5755acab3295089add9362..5ac9adb44b9de1f4c0103b10d17d4bd56baa7519 100644 --- a/libavresample/avresample.h +++ b/libavresample/avresample.h @@ -103,7 +103,7 @@ #define AVRESAMPLE_MAX_CHANNELS 32 -typedef attribute_deprecated struct AVAudioResampleContext AVAudioResampleContext; +typedef struct AVAudioResampleContext AVAudioResampleContext; /** * @deprecated use libswresample diff --git a/libavutil/mastering_display_metadata.h b/libavutil/mastering_display_metadata.h index 847b0b62c6cf510609a9ab562ae36abb0658996c..c23b07c3cd80d9239138eb5589b7203c2e11ccb0 100644 --- a/libavutil/mastering_display_metadata.h +++ b/libavutil/mastering_display_metadata.h @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2016 Neil Birkbeck * * This file is part of FFmpeg. diff --git a/tests/fate/aac.mak b/tests/fate/aac.mak index e8cbcef54d7a9227080b48a6f69e8aaf55e48504..bd283225c1f918ef52a9cf504d6dbe5ef6466f2c 100644 --- a/tests/fate/aac.mak +++ b/tests/fate/aac.mak @@ -154,7 +154,7 @@ fate-aac-aref-encode: CMD = enc_dec_pcm adts wav s16le $(REF) -c:a aac -aac_is 0 fate-aac-aref-encode: CMP = stddev fate-aac-aref-encode: REF = ./tests/data/asynth-44100-2.wav fate-aac-aref-encode: CMP_SHIFT = -4096 -fate-aac-aref-encode: CMP_TARGET = 669 +fate-aac-aref-encode: CMP_TARGET = 596 fate-aac-aref-encode: SIZE_TOLERANCE = 2464 fate-aac-aref-encode: FUZZ = 89 @@ -163,7 +163,7 @@ fate-aac-ln-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-ref fate-aac-ln-encode: CMP = stddev fate-aac-ln-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav fate-aac-ln-encode: CMP_SHIFT = -4096 -fate-aac-ln-encode: CMP_TARGET = 61 +fate-aac-ln-encode: CMP_TARGET = 72 fate-aac-ln-encode: SIZE_TOLERANCE = 3560 fate-aac-ln-encode: FUZZ = 30 @@ -172,7 +172,7 @@ fate-aac-ln-encode-128k: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audi fate-aac-ln-encode-128k: CMP = stddev fate-aac-ln-encode-128k: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav fate-aac-ln-encode-128k: CMP_SHIFT = -4096 -fate-aac-ln-encode-128k: CMP_TARGET = 800 +fate-aac-ln-encode-128k: CMP_TARGET = 622 fate-aac-ln-encode-128k: SIZE_TOLERANCE = 3560 fate-aac-ln-encode-128k: FUZZ = 5 @@ -181,7 +181,7 @@ fate-aac-pns-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-re fate-aac-pns-encode: CMP = stddev fate-aac-pns-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav fate-aac-pns-encode: CMP_SHIFT = -4096 -fate-aac-pns-encode: CMP_TARGET = 616 +fate-aac-pns-encode: CMP_TARGET = 655 fate-aac-pns-encode: SIZE_TOLERANCE = 3560 fate-aac-pns-encode: FUZZ = 74 @@ -190,7 +190,7 @@ fate-aac-tns-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-re fate-aac-tns-encode: CMP = stddev fate-aac-tns-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav fate-aac-tns-encode: CMP_SHIFT = -4096 -fate-aac-tns-encode: CMP_TARGET = 817 +fate-aac-tns-encode: CMP_TARGET = 637 fate-aac-tns-encode: FUZZ = 7 fate-aac-tns-encode: SIZE_TOLERANCE = 3560 @@ -199,7 +199,7 @@ fate-aac-is-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-ref fate-aac-is-encode: CMP = stddev fate-aac-is-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav fate-aac-is-encode: CMP_SHIFT = -4096 -fate-aac-is-encode: CMP_TARGET = 615 +fate-aac-is-encode: CMP_TARGET = 514 fate-aac-is-encode: SIZE_TOLERANCE = 3560 fate-aac-is-encode: FUZZ = 10 @@ -208,26 +208,17 @@ fate-aac-ms-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-ref fate-aac-ms-encode: CMP = stddev fate-aac-ms-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav fate-aac-ms-encode: CMP_SHIFT = -4096 -fate-aac-ms-encode: CMP_TARGET = 675 +fate-aac-ms-encode: CMP_TARGET = 558 fate-aac-ms-encode: SIZE_TOLERANCE = 3560 fate-aac-ms-encode: FUZZ = 15 -FATE_AAC_ENCODE += fate-aac-ltp-encode -fate-aac-ltp-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav -strict -2 -c:a aac -profile:a aac_ltp -aac_pns 0 -aac_is 0 -aac_ms 0 -aac_tns 0 -b:a 36k -fflags +bitexact -flags +bitexact -fate-aac-ltp-encode: CMP = stddev -fate-aac-ltp-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav -fate-aac-ltp-encode: CMP_SHIFT = -4096 -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: CMP_TARGET = 226 fate-aac-yoraw-encode: SIZE_TOLERANCE = 3560 fate-aac-yoraw-encode: FUZZ = 17 @@ -237,7 +228,7 @@ fate-aac-pred-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-r fate-aac-pred-encode: CMP = stddev fate-aac-pred-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav fate-aac-pred-encode: CMP_SHIFT = -4096 -fate-aac-pred-encode: CMP_TARGET = 841 +fate-aac-pred-encode: CMP_TARGET = 662 fate-aac-pred-encode: FUZZ = 12 fate-aac-pred-encode: SIZE_TOLERANCE = 3560 diff --git a/tests/fate/acodec.mak b/tests/fate/acodec.mak index 5c3fea90c582230743519be9a3b1c2eef7b9f40b..80d26de0f9c9178a46cf5c7c489ad4210cabfcb5 100644 --- a/tests/fate/acodec.mak +++ b/tests/fate/acodec.mak @@ -104,14 +104,14 @@ fate-acodec-dca: tests/data/asynth-44100-2.wav fate-acodec-dca: SRC = tests/data/asynth-44100-2.wav fate-acodec-dca: CMD = md5 -i $(TARGET_PATH)/$(SRC) -c:a dca -strict -2 -f dts -flags +bitexact fate-acodec-dca: CMP = oneline -fate-acodec-dca: REF = 7cd79a3717943a06b217f1130223a86f +fate-acodec-dca: REF = 2aa580ac67820fce4f581b96ebb34acc FATE_ACODEC-$(call ENCDEC, DCA, WAV) += fate-acodec-dca2 fate-acodec-dca2: CMD = enc_dec_pcm dts wav s16le $(SRC) -c:a dca -strict -2 -flags +bitexact fate-acodec-dca2: REF = $(SRC) fate-acodec-dca2: CMP = stddev fate-acodec-dca2: CMP_SHIFT = -2048 -fate-acodec-dca2: CMP_TARGET = 527 +fate-acodec-dca2: CMP_TARGET = 535 fate-acodec-dca2: SIZE_TOLERANCE = 1632 FATE_ACODEC-$(call ENCDEC, FLAC, FLAC) += fate-acodec-flac fate-acodec-flac-exact-rice diff --git a/tests/ref/fate/filter-framerate-12bit-up b/tests/ref/fate/filter-framerate-12bit-up index 686fe8e82bd713eda22782caec884fcb0db33b09..ef709a8fc805253113ca93e3cba1e8fd7f6d9f40 100644 --- a/tests/ref/fate/filter-framerate-12bit-up +++ b/tests/ref/fate/filter-framerate-12bit-up @@ -62,3 +62,4 @@ 0, 56, 56, 1, 307200, 0x8cf55128 0, 57, 57, 1, 307200, 0x4e740b42 0, 58, 58, 1, 307200, 0x8e7e705c +0, 59, 59, 1, 307200, 0xe73f29ef