Guess what... more AAC stuffs.
from Brad (maintainer)
This commit is contained in:
parent
bcb441b0f4
commit
eda8d62d5c
@ -1,11 +1,11 @@
|
||||
# $OpenBSD: Makefile,v 1.131 2015/10/13 05:44:18 ajacoutot Exp $
|
||||
# $OpenBSD: Makefile,v 1.132 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
COMMENT= audio/video converter and streamer
|
||||
|
||||
V= 20150909
|
||||
DISTNAME= ffmpeg-git-${V}
|
||||
PKGNAME= ffmpeg-${V}
|
||||
REVISION= 7
|
||||
REVISION= 8
|
||||
CATEGORIES= graphics multimedia
|
||||
MASTER_SITES= http://comstyle.com/source/
|
||||
EXTRACT_SUFX= .tar.xz
|
||||
|
14
graphics/ffmpeg/patches/patch-libavcodec_Makefile
Normal file
14
graphics/ffmpeg/patches/patch-libavcodec_Makefile
Normal file
@ -0,0 +1,14 @@
|
||||
$OpenBSD: patch-libavcodec_Makefile,v 1.21 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
aacenc: add support for encoding files using Long Term Prediction
|
||||
|
||||
--- libavcodec/Makefile.orig Fri Oct 16 23:44:46 2015
|
||||
+++ libavcodec/Makefile Fri Oct 16 23:45:34 2015
|
||||
@@ -134,6 +134,7 @@ OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o aac
|
||||
aacpsy.o aactab.o \
|
||||
aacenc_is.o \
|
||||
aacenc_tns.o \
|
||||
+ aacenc_ltp.o \
|
||||
aacenc_pred.o \
|
||||
psymodel.o mpeg4audio.o kbdwin.o
|
||||
OBJS-$(CONFIG_AASC_DECODER) += aasc.o msrledec.o
|
@ -1,10 +1,20 @@
|
||||
$OpenBSD: patch-libavcodec_aac_h,v 1.1 2015/10/13 05:44:18 ajacoutot Exp $
|
||||
$OpenBSD: patch-libavcodec_aac_h,v 1.2 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
AAC encoder: Extensive improvements
|
||||
|
||||
--- libavcodec/aac.h.orig Mon Oct 12 21:55:54 2015
|
||||
+++ libavcodec/aac.h Mon Oct 12 22:04:41 2015
|
||||
@@ -252,6 +252,7 @@ typedef struct SingleChannelElement {
|
||||
aacenc: add support for encoding files using Long Term Prediction
|
||||
|
||||
--- libavcodec/aac.h.orig Mon Sep 7 21:58:01 2015
|
||||
+++ libavcodec/aac.h Fri Oct 16 23:45:55 2015
|
||||
@@ -161,6 +161,7 @@ typedef struct PredictorState {
|
||||
typedef struct LongTermPrediction {
|
||||
int8_t present;
|
||||
int16_t lag;
|
||||
+ int coef_idx;
|
||||
INTFLOAT coef;
|
||||
int8_t used[MAX_LTP_LONG_SFB];
|
||||
} LongTermPrediction;
|
||||
@@ -252,6 +253,7 @@ typedef struct SingleChannelElement {
|
||||
INTFLOAT sf[120]; ///< scalefactors
|
||||
int sf_idx[128]; ///< scalefactor indices (used by encoder)
|
||||
uint8_t zeroes[128]; ///< band is not coded (used by encoder)
|
||||
@ -12,3 +22,11 @@ AAC encoder: Extensive improvements
|
||||
float is_ener[128]; ///< Intensity stereo pos (used by encoder)
|
||||
float pns_ener[128]; ///< Noise energy values (used by encoder)
|
||||
DECLARE_ALIGNED(32, INTFLOAT, pcoeffs)[1024]; ///< coefficients for IMDCT, pristine
|
||||
@@ -259,6 +261,7 @@ typedef struct SingleChannelElement {
|
||||
DECLARE_ALIGNED(32, INTFLOAT, saved)[1536]; ///< overlap
|
||||
DECLARE_ALIGNED(32, INTFLOAT, ret_buf)[2048]; ///< PCM output buffer
|
||||
DECLARE_ALIGNED(16, INTFLOAT, ltp_state)[3072]; ///< time signal for LTP
|
||||
+ DECLARE_ALIGNED(32, AAC_FLOAT, lcoeffs)[1024]; ///< MDCT of LTP coefficients (used by encoder)
|
||||
DECLARE_ALIGNED(32, AAC_FLOAT, prcoeffs)[1024]; ///< Main prediction coefs (used by encoder)
|
||||
PredictorState predictor_state[MAX_PREDICTORS];
|
||||
INTFLOAT *ret; ///< PCM output
|
||||
|
@ -1,4 +1,4 @@
|
||||
$OpenBSD: patch-libavcodec_aaccoder_c,v 1.4 2015/10/13 05:44:18 ajacoutot Exp $
|
||||
$OpenBSD: patch-libavcodec_aaccoder_c,v 1.5 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
aaccoder: use roundf() instead of ceilf()
|
||||
|
||||
@ -20,8 +20,10 @@ AAC encoder: Extensive improvements
|
||||
|
||||
aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
|
||||
aacenc: add support for encoding files using Long Term Prediction
|
||||
|
||||
--- libavcodec/aaccoder.c.orig Mon Sep 7 21:58:01 2015
|
||||
+++ libavcodec/aaccoder.c Mon Oct 12 22:04:45 2015
|
||||
+++ libavcodec/aaccoder.c Fri Oct 16 23:46:00 2015
|
||||
@@ -33,7 +33,9 @@
|
||||
#include "libavutil/libm.h" // brought forward to work around cygwin header breakage
|
||||
|
||||
@ -32,8 +34,11 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
#include "avcodec.h"
|
||||
#include "put_bits.h"
|
||||
#include "aac.h"
|
||||
@@ -48,18 +50,18 @@
|
||||
@@ -46,20 +48,21 @@
|
||||
|
||||
#include "aacenc_is.h"
|
||||
#include "aacenc_tns.h"
|
||||
+#include "aacenc_ltp.h"
|
||||
#include "aacenc_pred.h"
|
||||
|
||||
-/** Frequency in Hz for lower limit of noise substitution **/
|
||||
@ -60,7 +65,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
/**
|
||||
* structure used in optimal codebook search
|
||||
*/
|
||||
@@ -121,7 +123,7 @@ static void encode_window_bands_info(AACEncContext *s,
|
||||
@@ -121,7 +124,7 @@ static void encode_window_bands_info(AACEncContext *s,
|
||||
rd += quantize_band_cost(s, &sce->coeffs[start + w*128],
|
||||
&s->scoefs[start + w*128], size,
|
||||
sce->sf_idx[(win+w)*16+swb], aac_cb_out_map[cb],
|
||||
@ -69,7 +74,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
}
|
||||
cost_stay_here = path[swb][cb].cost + rd;
|
||||
cost_get_here = minrd + rd + run_bits + 4;
|
||||
@@ -182,138 +184,7 @@ static void encode_window_bands_info(AACEncContext *s,
|
||||
@@ -182,138 +185,7 @@ static void encode_window_bands_info(AACEncContext *s,
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,7 +213,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
typedef struct TrellisPath {
|
||||
float cost;
|
||||
int prev;
|
||||
@@ -332,11 +203,11 @@ static void set_special_band_scalefactors(AACEncContex
|
||||
@@ -332,11 +204,11 @@ static void set_special_band_scalefactors(AACEncContex
|
||||
start = 0;
|
||||
for (g = 0; g < sce->ics.num_swb; g++) {
|
||||
if (sce->band_type[w*16+g] == INTENSITY_BT || sce->band_type[w*16+g] == INTENSITY_BT2) {
|
||||
@ -222,7 +227,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
minscaler_n = FFMIN(minscaler_n, sce->sf_idx[w*16+g]);
|
||||
bands++;
|
||||
}
|
||||
@@ -463,7 +334,7 @@ static void search_for_quantizers_anmr(AVCodecContext
|
||||
@@ -463,7 +335,7 @@ static void search_for_quantizers_anmr(AVCodecContext
|
||||
for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
|
||||
FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
|
||||
dist += quantize_band_cost(s, coefs + w2*128, s->scoefs + start + w2*128, sce->ics.swb_sizes[g],
|
||||
@ -231,7 +236,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
}
|
||||
minrd = FFMIN(minrd, dist);
|
||||
|
||||
@@ -509,156 +380,7 @@ static void search_for_quantizers_anmr(AVCodecContext
|
||||
@@ -509,156 +381,7 @@ static void search_for_quantizers_anmr(AVCodecContext
|
||||
sce->sf_idx[(w+w2)*16+g] = sce->sf_idx[w*16+g];
|
||||
}
|
||||
|
||||
@ -388,7 +393,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s,
|
||||
SingleChannelElement *sce,
|
||||
const float lambda)
|
||||
@@ -776,7 +498,7 @@ static void search_for_quantizers_faac(AVCodecContext
|
||||
@@ -776,7 +499,7 @@ static void search_for_quantizers_faac(AVCodecContext
|
||||
ESC_BT,
|
||||
lambda,
|
||||
INFINITY,
|
||||
@ -397,7 +402,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
0);
|
||||
dist -= b;
|
||||
}
|
||||
@@ -863,92 +585,320 @@ static void search_for_quantizers_fast(AVCodecContext
|
||||
@@ -863,92 +586,320 @@ static void search_for_quantizers_fast(AVCodecContext
|
||||
|
||||
static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
|
||||
{
|
||||
@ -772,59 +777,87 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
}
|
||||
start += sce0->ics.swb_sizes[g];
|
||||
}
|
||||
@@ -962,11 +912,12 @@ AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB] = {
|
||||
@@ -961,13 +912,19 @@ AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB] = {
|
||||
encode_window_bands_info,
|
||||
quantize_and_encode_band,
|
||||
ff_aac_encode_tns_info,
|
||||
+ ff_aac_encode_ltp_info,
|
||||
ff_aac_encode_main_pred,
|
||||
- ff_aac_adjust_common_prediction,
|
||||
+ ff_aac_adjust_common_pred,
|
||||
+ ff_aac_adjust_common_ltp,
|
||||
ff_aac_apply_main_pred,
|
||||
ff_aac_apply_tns,
|
||||
+ ff_aac_update_ltp,
|
||||
+ ff_aac_ltp_insert_new_frame,
|
||||
set_special_band_scalefactors,
|
||||
search_for_pns,
|
||||
+ mark_pns,
|
||||
ff_aac_search_for_tns,
|
||||
+ ff_aac_search_for_ltp,
|
||||
search_for_ms,
|
||||
ff_aac_search_for_is,
|
||||
@@ -978,11 +929,12 @@ AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB] = {
|
||||
ff_aac_search_for_pred,
|
||||
@@ -977,13 +934,19 @@ AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB] = {
|
||||
encode_window_bands_info,
|
||||
quantize_and_encode_band,
|
||||
ff_aac_encode_tns_info,
|
||||
+ ff_aac_encode_ltp_info,
|
||||
ff_aac_encode_main_pred,
|
||||
- ff_aac_adjust_common_prediction,
|
||||
+ ff_aac_adjust_common_pred,
|
||||
+ ff_aac_adjust_common_ltp,
|
||||
ff_aac_apply_main_pred,
|
||||
ff_aac_apply_tns,
|
||||
+ ff_aac_update_ltp,
|
||||
+ ff_aac_ltp_insert_new_frame,
|
||||
set_special_band_scalefactors,
|
||||
search_for_pns,
|
||||
+ mark_pns,
|
||||
ff_aac_search_for_tns,
|
||||
+ ff_aac_search_for_ltp,
|
||||
search_for_ms,
|
||||
ff_aac_search_for_is,
|
||||
@@ -994,11 +946,12 @@ AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB] = {
|
||||
ff_aac_search_for_pred,
|
||||
@@ -993,13 +956,19 @@ AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB] = {
|
||||
codebook_trellis_rate,
|
||||
quantize_and_encode_band,
|
||||
ff_aac_encode_tns_info,
|
||||
+ ff_aac_encode_ltp_info,
|
||||
ff_aac_encode_main_pred,
|
||||
- ff_aac_adjust_common_prediction,
|
||||
+ ff_aac_adjust_common_pred,
|
||||
+ ff_aac_adjust_common_ltp,
|
||||
ff_aac_apply_main_pred,
|
||||
ff_aac_apply_tns,
|
||||
+ ff_aac_update_ltp,
|
||||
+ ff_aac_ltp_insert_new_frame,
|
||||
set_special_band_scalefactors,
|
||||
search_for_pns,
|
||||
+ mark_pns,
|
||||
ff_aac_search_for_tns,
|
||||
+ ff_aac_search_for_ltp,
|
||||
search_for_ms,
|
||||
ff_aac_search_for_is,
|
||||
@@ -1010,11 +963,12 @@ AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB] = {
|
||||
ff_aac_search_for_pred,
|
||||
@@ -1009,13 +978,19 @@ AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB] = {
|
||||
encode_window_bands_info,
|
||||
quantize_and_encode_band,
|
||||
ff_aac_encode_tns_info,
|
||||
+ ff_aac_encode_ltp_info,
|
||||
ff_aac_encode_main_pred,
|
||||
- ff_aac_adjust_common_prediction,
|
||||
+ ff_aac_adjust_common_pred,
|
||||
+ ff_aac_adjust_common_ltp,
|
||||
ff_aac_apply_main_pred,
|
||||
ff_aac_apply_tns,
|
||||
+ ff_aac_update_ltp,
|
||||
+ ff_aac_ltp_insert_new_frame,
|
||||
set_special_band_scalefactors,
|
||||
search_for_pns,
|
||||
+ mark_pns,
|
||||
ff_aac_search_for_tns,
|
||||
+ ff_aac_search_for_ltp,
|
||||
search_for_ms,
|
||||
ff_aac_search_for_is,
|
||||
ff_aac_search_for_pred,
|
||||
|
21
graphics/ffmpeg/patches/patch-libavcodec_aacdectab_h
Normal file
21
graphics/ffmpeg/patches/patch-libavcodec_aacdectab_h
Normal file
@ -0,0 +1,21 @@
|
||||
$OpenBSD: patch-libavcodec_aacdectab_h,v 1.1 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
aactab: move ltp_coef[] from aacdectab to aactab
|
||||
|
||||
--- libavcodec/aacdectab.h.orig Fri Oct 16 23:41:18 2015
|
||||
+++ libavcodec/aacdectab.h Fri Oct 16 23:41:33 2015
|
||||
@@ -35,14 +35,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
-/* @name ltp_coef
|
||||
- * Table of the LTP coefficients
|
||||
- */
|
||||
-static const INTFLOAT ltp_coef[8] = {
|
||||
- Q30(0.570829f), Q30(0.696616f), Q30(0.813004f), Q30(0.911304f),
|
||||
- Q30(0.984900f), Q30(1.067894f), Q30(1.194601f), Q30(1.369533f),
|
||||
-};
|
||||
-
|
||||
static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 4, 5, 0, 5, 0 };
|
||||
|
||||
static const uint8_t aac_channel_layout_map[16][5][3] = {
|
@ -1,4 +1,4 @@
|
||||
$OpenBSD: patch-libavcodec_aacenc_c,v 1.5 2015/10/13 05:44:18 ajacoutot Exp $
|
||||
$OpenBSD: patch-libavcodec_aacenc_c,v 1.6 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
aacenc: copy PRNG from the decoder
|
||||
|
||||
@ -16,54 +16,21 @@ aacenc: add support for changing options based on a profile
|
||||
|
||||
aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
|
||||
aacenc: indicate that TNS is off by default
|
||||
|
||||
aacenc: slightly simplify and remove a redundant variable
|
||||
|
||||
aacenc: correctly zero prediction_used array
|
||||
|
||||
aacenc: (re)enable Mid/Side coding by default
|
||||
|
||||
aacenc: add support for encoding files using Long Term Prediction
|
||||
|
||||
aacenc: partially revert previous commits to set options via a profile
|
||||
|
||||
--- libavcodec/aacenc.c.orig Mon Sep 7 21:58:01 2015
|
||||
+++ libavcodec/aacenc.c Mon Oct 12 22:07:21 2015
|
||||
@@ -46,6 +46,44 @@
|
||||
|
||||
#include "psymodel.h"
|
||||
|
||||
+struct AACProfileOptions {
|
||||
+ int profile;
|
||||
+ struct AACEncOptions opts;
|
||||
+};
|
||||
+
|
||||
+ /**
|
||||
+ * List of currently supported profiles, anything not listed isn't supported.
|
||||
+ */
|
||||
+static const struct AACProfileOptions aacenc_profiles[] = {
|
||||
+ {FF_PROFILE_AAC_MAIN,
|
||||
+ { /* Main profile, all advanced encoding abilities enabled */
|
||||
+ .mid_side = 0,
|
||||
+ .pns = 1,
|
||||
+ .tns = 0,
|
||||
+ .pred = OPT_REQUIRED,
|
||||
+ .intensity_stereo = 1,
|
||||
+ },
|
||||
+ },
|
||||
+ {FF_PROFILE_AAC_LOW,
|
||||
+ { /* Default profile, these are the settings that get set by default */
|
||||
+ .mid_side = 0,
|
||||
+ .pns = 1,
|
||||
+ .tns = 0,
|
||||
+ .pred = OPT_NEEDS_MAIN,
|
||||
+ .intensity_stereo = 1,
|
||||
+ },
|
||||
+ },
|
||||
+ {FF_PROFILE_MPEG2_AAC_LOW,
|
||||
+ { /* Strict MPEG 2 Part 7 compliance profile */
|
||||
+ .mid_side = 0,
|
||||
+ .pns = OPT_BANNED,
|
||||
+ .tns = 0,
|
||||
+ .pred = OPT_BANNED,
|
||||
+ .intensity_stereo = 1,
|
||||
+ },
|
||||
+ },
|
||||
+};
|
||||
+
|
||||
/**
|
||||
* Make AAC audio config object.
|
||||
* @see 1.6.2.1 "Syntax - AudioSpecificConfig"
|
||||
@@ -54,11 +92,12 @@ static void put_audio_specific_config(AVCodecContext *
|
||||
+++ libavcodec/aacenc.c Fri Oct 16 23:46:49 2015
|
||||
@@ -54,11 +54,12 @@ static void put_audio_specific_config(AVCodecContext *
|
||||
{
|
||||
PutBitContext pb;
|
||||
AACEncContext *s = avctx->priv_data;
|
||||
@ -77,7 +44,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
//GASpecificConfig
|
||||
put_bits(&pb, 1, 0); //frame length - 1024 samples
|
||||
put_bits(&pb, 1, 0); //does not depend on core coder
|
||||
@@ -71,6 +110,16 @@ static void put_audio_specific_config(AVCodecContext *
|
||||
@@ -71,6 +72,16 @@ static void put_audio_specific_config(AVCodecContext *
|
||||
flush_put_bits(&pb);
|
||||
}
|
||||
|
||||
@ -94,7 +61,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
#define WINDOW_FUNC(type) \
|
||||
static void apply_ ##type ##_window(AVFloatDSPContext *fdsp, \
|
||||
SingleChannelElement *sce, \
|
||||
@@ -258,6 +307,8 @@ static void apply_intensity_stereo(ChannelElement *cpe
|
||||
@@ -258,6 +269,8 @@ static void apply_intensity_stereo(ChannelElement *cpe
|
||||
start += ics->swb_sizes[g];
|
||||
continue;
|
||||
}
|
||||
@ -103,7 +70,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
for (i = 0; i < ics->swb_sizes[g]; i++) {
|
||||
float sum = (cpe->ch[0].coeffs[start+i] + p*cpe->ch[1].coeffs[start+i])*scale;
|
||||
cpe->ch[0].coeffs[start+i] = sum;
|
||||
@@ -279,7 +330,7 @@ static void apply_mid_side_stereo(ChannelElement *cpe)
|
||||
@@ -279,7 +292,7 @@ static void apply_mid_side_stereo(ChannelElement *cpe)
|
||||
for (w2 = 0; w2 < ics->group_len[w]; w2++) {
|
||||
int start = (w+w2) * 128;
|
||||
for (g = 0; g < ics->num_swb; g++) {
|
||||
@ -112,17 +79,71 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
start += ics->swb_sizes[g];
|
||||
continue;
|
||||
}
|
||||
@@ -489,7 +540,8 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
@@ -424,6 +437,8 @@ static int encode_individual_channel(AVCodecContext *a
|
||||
put_ics_info(s, &sce->ics);
|
||||
if (s->coder->encode_main_pred)
|
||||
s->coder->encode_main_pred(s, sce);
|
||||
+ if (s->coder->encode_ltp_info)
|
||||
+ s->coder->encode_ltp_info(s, sce, 0);
|
||||
}
|
||||
encode_band_info(s, sce);
|
||||
encode_scale_factors(avctx, s, sce);
|
||||
@@ -489,7 +504,9 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
float **samples = s->planar_samples, *samples2, *la, *overlap;
|
||||
ChannelElement *cpe;
|
||||
SingleChannelElement *sce;
|
||||
- int i, ch, w, chans, tag, start_ch, ret;
|
||||
+ IndividualChannelStream *ics;
|
||||
+ int i, its, ch, w, chans, tag, start_ch, ret, frame_bits;
|
||||
+ int target_bits, rate_bits, too_many_bits, too_few_bits;
|
||||
int ms_mode = 0, is_mode = 0, tns_mode = 0, pred_mode = 0;
|
||||
int chan_el_counter[4];
|
||||
FFPsyWindowInfo windows[AAC_MAX_CHANNELS];
|
||||
@@ -581,14 +633,14 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
@@ -517,10 +534,11 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
chans = tag == TYPE_CPE ? 2 : 1;
|
||||
cpe = &s->cpe[i];
|
||||
for (ch = 0; ch < chans; ch++) {
|
||||
- IndividualChannelStream *ics = &cpe->ch[ch].ics;
|
||||
- int cur_channel = start_ch + ch;
|
||||
+ sce = &cpe->ch[ch];
|
||||
+ ics = &sce->ics;
|
||||
+ s->cur_channel = start_ch + ch;
|
||||
float clip_avoidance_factor;
|
||||
- overlap = &samples[cur_channel][0];
|
||||
+ overlap = &samples[s->cur_channel][0];
|
||||
samples2 = overlap + 1024;
|
||||
la = samples2 + (448+64);
|
||||
if (!frame)
|
||||
@@ -537,7 +555,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
*/
|
||||
ics->num_swb = s->samplerate_index >= 8 ? 1 : 3;
|
||||
} else {
|
||||
- wi[ch] = s->psy.model->window(&s->psy, samples2, la, cur_channel,
|
||||
+ wi[ch] = s->psy.model->window(&s->psy, samples2, la, s->cur_channel,
|
||||
ics->window_sequence[0]);
|
||||
}
|
||||
ics->window_sequence[1] = ics->window_sequence[0];
|
||||
@@ -570,25 +588,32 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
ics->clip_avoidance_factor = 1.0f;
|
||||
}
|
||||
|
||||
- apply_window_and_mdct(s, &cpe->ch[ch], overlap);
|
||||
+ apply_window_and_mdct(s, sce, overlap);
|
||||
+
|
||||
+ if (s->options.ltp && s->coder->update_ltp) {
|
||||
+ s->coder->update_ltp(s, sce);
|
||||
+ apply_window[sce->ics.window_sequence[0]](s->fdsp, sce, &sce->ltp_state[0]);
|
||||
+ s->mdct1024.mdct_calc(&s->mdct1024, sce->lcoeffs, sce->ret_buf);
|
||||
+ }
|
||||
+
|
||||
if (isnan(cpe->ch->coeffs[0])) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Input contains NaN\n");
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
- avoid_clipping(s, &cpe->ch[ch]);
|
||||
+ avoid_clipping(s, sce);
|
||||
}
|
||||
start_ch += chans;
|
||||
}
|
||||
if ((ret = ff_alloc_packet2(avctx, avpkt, 8192 * s->channels, 0)) < 0)
|
||||
return ret;
|
||||
@ -139,7 +160,16 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
memset(chan_el_counter, 0, sizeof(chan_el_counter));
|
||||
for (i = 0; i < s->chan_map[0]; i++) {
|
||||
FFPsyWindowInfo* wi = windows + start_ch;
|
||||
@@ -611,9 +663,20 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
@@ -605,15 +630,28 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
sce = &cpe->ch[ch];
|
||||
coeffs[ch] = sce->coeffs;
|
||||
sce->ics.predictor_present = 0;
|
||||
- memset(&sce->ics.prediction_used, 0, sizeof(sce->ics.prediction_used));
|
||||
+ sce->ics.ltp.present = 0;
|
||||
+ memset(sce->ics.ltp.used, 0, sizeof(sce->ics.ltp.used));
|
||||
+ memset(sce->ics.prediction_used, 0, sizeof(sce->ics.prediction_used));
|
||||
memset(&sce->tns, 0, sizeof(TemporalNoiseShaping));
|
||||
for (w = 0; w < 128; w++)
|
||||
if (sce->band_type[w] > RESERVED_BT)
|
||||
sce->band_type[w] = 0;
|
||||
}
|
||||
@ -160,7 +190,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
s->coder->search_for_quantizers(avctx, s, &cpe->ch[ch], s->lambda);
|
||||
}
|
||||
if (chans > 1
|
||||
@@ -655,8 +718,8 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
@@ -655,8 +693,8 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
s->coder->search_for_pred(s, sce);
|
||||
if (cpe->ch[ch].ics.predictor_present) pred_mode = 1;
|
||||
}
|
||||
@ -171,7 +201,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
for (ch = 0; ch < chans; ch++) {
|
||||
sce = &cpe->ch[ch];
|
||||
s->cur_channel = start_ch + ch;
|
||||
@@ -665,13 +728,11 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
@@ -665,22 +703,34 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
}
|
||||
s->cur_channel = start_ch;
|
||||
}
|
||||
@ -187,7 +217,30 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
apply_mid_side_stereo(cpe);
|
||||
}
|
||||
adjust_frame_information(cpe, chans);
|
||||
@@ -692,36 +753,73 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
+ if (s->options.ltp) { /* LTP */
|
||||
+ for (ch = 0; ch < chans; ch++) {
|
||||
+ sce = &cpe->ch[ch];
|
||||
+ s->cur_channel = start_ch + ch;
|
||||
+ if (s->coder->search_for_ltp)
|
||||
+ s->coder->search_for_ltp(s, sce, cpe->common_window);
|
||||
+ if (sce->ics.ltp.present) pred_mode = 1;
|
||||
+ }
|
||||
+ s->cur_channel = start_ch;
|
||||
+ if (s->coder->adjust_common_ltp)
|
||||
+ s->coder->adjust_common_ltp(s, cpe);
|
||||
+ }
|
||||
if (chans == 2) {
|
||||
put_bits(&s->pb, 1, cpe->common_window);
|
||||
if (cpe->common_window) {
|
||||
put_ics_info(s, &cpe->ch[0].ics);
|
||||
if (s->coder->encode_main_pred)
|
||||
s->coder->encode_main_pred(s, &cpe->ch[0]);
|
||||
+ if (s->coder->encode_ltp_info)
|
||||
+ s->coder->encode_ltp_info(s, &cpe->ch[0], 1);
|
||||
encode_ms_info(&s->pb, cpe);
|
||||
if (cpe->ms_mode) ms_mode = 1;
|
||||
}
|
||||
@@ -692,36 +742,76 @@ static int aac_encode_frame(AVCodecContext *avctx, AVP
|
||||
start_ch += chans;
|
||||
}
|
||||
|
||||
@ -265,6 +318,9 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
+ }
|
||||
} while (1);
|
||||
|
||||
+ if (s->options.ltp && s->coder->ltp_insert_new_frame)
|
||||
+ s->coder->ltp_insert_new_frame(s);
|
||||
+
|
||||
put_bits(&s->pb, 3, TYPE_END);
|
||||
flush_put_bits(&s->pb);
|
||||
avctx->frame_bits = put_bits_count(&s->pb);
|
||||
@ -281,7 +337,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
if (!frame)
|
||||
s->last_frame++;
|
||||
|
||||
@@ -737,6 +835,8 @@ static av_cold int aac_encode_end(AVCodecContext *avct
|
||||
@@ -737,6 +827,8 @@ static av_cold int aac_encode_end(AVCodecContext *avct
|
||||
{
|
||||
AACEncContext *s = avctx->priv_data;
|
||||
|
||||
@ -290,13 +346,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
ff_mdct_end(&s->mdct1024);
|
||||
ff_mdct_end(&s->mdct128);
|
||||
ff_psy_end(&s->psy);
|
||||
@@ -790,81 +890,88 @@ alloc_fail:
|
||||
static av_cold int aac_encode_init(AVCodecContext *avctx)
|
||||
{
|
||||
AACEncContext *s = avctx->priv_data;
|
||||
+ const AACEncOptions *p_opt = NULL;
|
||||
int i, ret = 0;
|
||||
const uint8_t *sizes[2];
|
||||
@@ -795,76 +887,101 @@ static av_cold int aac_encode_init(AVCodecContext *avc
|
||||
uint8_t grouping[AAC_MAX_CHANNELS];
|
||||
int lengths[2];
|
||||
|
||||
@ -331,7 +381,27 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
WARN_IF(1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * s->channels,
|
||||
"Too many bits per frame requested, clamping to max\n");
|
||||
- if (avctx->profile == FF_PROFILE_AAC_MAIN) {
|
||||
- s->options.pred = 1;
|
||||
+
|
||||
+ for (i = 0; i < FF_ARRAY_ELEMS(aacenc_profiles); i++)
|
||||
+ if (avctx->profile == aacenc_profiles[i])
|
||||
+ break;
|
||||
+ ERROR_IF(i == FF_ARRAY_ELEMS(aacenc_profiles),
|
||||
+ "Unsupported encoding profile: %d\n", avctx->profile);
|
||||
+ if (avctx->profile == FF_PROFILE_MPEG2_AAC_LOW) {
|
||||
+ avctx->profile = FF_PROFILE_AAC_LOW;
|
||||
+ ERROR_IF(s->options.pred,
|
||||
+ "Main prediction unavailable in the \"mpeg2_aac_low\" profile\n");
|
||||
+ ERROR_IF(s->options.ltp,
|
||||
+ "LTP prediction unavailable in the \"mpeg2_aac_low\" profile\n");
|
||||
+ WARN_IF(s->options.pns,
|
||||
+ "PNS unavailable in the \"mpeg2_aac_low\" profile, turning off\n");
|
||||
+ s->options.pns = 0;
|
||||
+ } else if (avctx->profile == FF_PROFILE_AAC_LTP) {
|
||||
+ s->options.ltp = 1;
|
||||
+ ERROR_IF(s->options.pred,
|
||||
+ "Main prediction unavailable in the \"aac_ltp\" profile\n");
|
||||
+ } else if (avctx->profile == FF_PROFILE_AAC_MAIN) {
|
||||
s->options.pred = 1;
|
||||
- } else if ((avctx->profile == FF_PROFILE_AAC_LOW ||
|
||||
- avctx->profile == FF_PROFILE_UNKNOWN) && s->options.pred) {
|
||||
- s->profile = 0; /* Main */
|
||||
@ -341,24 +411,22 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
- s->profile = 1; /* Low */
|
||||
- } else {
|
||||
- ERROR_IF(1, "Unsupported profile %d\n", avctx->profile);
|
||||
+
|
||||
+ for (i = 0; i < FF_ARRAY_ELEMS(aacenc_profiles); i++) {
|
||||
+ if (avctx->profile == aacenc_profiles[i].profile) {
|
||||
+ p_opt = &aacenc_profiles[i].opts;
|
||||
+ break;
|
||||
+ }
|
||||
+ ERROR_IF(s->options.ltp,
|
||||
+ "LTP prediction unavailable in the \"aac_main\" profile\n");
|
||||
+ } else if (s->options.ltp) {
|
||||
+ avctx->profile = FF_PROFILE_AAC_LTP;
|
||||
+ WARN_IF(1,
|
||||
+ "Chainging profile to \"aac_ltp\"\n");
|
||||
+ ERROR_IF(s->options.pred,
|
||||
+ "Main prediction unavailable in the \"aac_ltp\" profile\n");
|
||||
+ } else if (s->options.pred) {
|
||||
+ avctx->profile = FF_PROFILE_AAC_MAIN;
|
||||
+ WARN_IF(1,
|
||||
+ "Chainging profile to \"aac_main\"\n");
|
||||
+ ERROR_IF(s->options.pred,
|
||||
+ "LTP prediction unavailable in the \"aac_main\" profile\n");
|
||||
}
|
||||
+ ERROR_IF(!p_opt, "Unsupported encoding profile: %d\n", avctx->profile);
|
||||
+ AAC_OPT_SET(&s->options, p_opt, 1, coder);
|
||||
+ AAC_OPT_SET(&s->options, p_opt, 0, pns);
|
||||
+ AAC_OPT_SET(&s->options, p_opt, 0, tns);
|
||||
+ AAC_OPT_SET(&s->options, p_opt, 0, pred);
|
||||
+ AAC_OPT_SET(&s->options, p_opt, 1, mid_side);
|
||||
+ AAC_OPT_SET(&s->options, p_opt, 0, intensity_stereo);
|
||||
+ if (avctx->profile == FF_PROFILE_MPEG2_AAC_LOW)
|
||||
+ s->profile = FF_PROFILE_AAC_LOW;
|
||||
+ else
|
||||
+ s->profile = avctx->profile;
|
||||
+ s->profile = avctx->profile;
|
||||
+ s->coder = &ff_aac_coders[s->options.coder];
|
||||
|
||||
- if (s->options.aac_coder != AAC_CODER_TWOLOOP) {
|
||||
@ -412,7 +480,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
ff_af_queue_init(avctx, &s->afq);
|
||||
|
||||
return 0;
|
||||
@@ -875,27 +982,16 @@ fail:
|
||||
@@ -875,27 +992,17 @@ fail:
|
||||
|
||||
#define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
|
||||
static const AVOption aacenc_options[] = {
|
||||
@ -442,11 +510,12 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
+ {"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"},
|
||||
+ {"aac_ms", "Force M/S stereo coding", offsetof(AACEncContext, options.mid_side), AV_OPT_TYPE_BOOL, {.i64 = 0}, -1, 1, AACENC_FLAGS},
|
||||
+ {"aac_is", "Intensity stereo coding", offsetof(AACEncContext, options.intensity_stereo), AV_OPT_TYPE_BOOL, {.i64 = OPT_AUTO}, -1, 1, AACENC_FLAGS},
|
||||
+ {"aac_pns", "Perceptual noise substitution", offsetof(AACEncContext, options.pns), AV_OPT_TYPE_BOOL, {.i64 = OPT_AUTO}, -1, 1, AACENC_FLAGS},
|
||||
+ {"aac_tns", "Temporal noise shaping", offsetof(AACEncContext, options.tns), AV_OPT_TYPE_BOOL, {.i64 = OPT_AUTO}, -1, 1, AACENC_FLAGS},
|
||||
+ {"aac_pred", "AAC-Main prediction", offsetof(AACEncContext, options.pred), AV_OPT_TYPE_BOOL, {.i64 = OPT_AUTO}, -1, 1, AACENC_FLAGS},
|
||||
+ {"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},
|
||||
+ {"aac_tns", "Temporal noise shaping", offsetof(AACEncContext, options.tns), AV_OPT_TYPE_BOOL, {.i64 = 0}, -1, 1, AACENC_FLAGS},
|
||||
+ {"aac_ltp", "Long term prediction", offsetof(AACEncContext, options.ltp), AV_OPT_TYPE_BOOL, {.i64 = 0}, -1, 1, AACENC_FLAGS},
|
||||
+ {"aac_pred", "AAC-Main prediction", offsetof(AACEncContext, options.pred), AV_OPT_TYPE_BOOL, {.i64 = 0}, -1, 1, AACENC_FLAGS},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
$OpenBSD: patch-libavcodec_aacenc_h,v 1.3 2015/10/13 05:44:18 ajacoutot Exp $
|
||||
$OpenBSD: patch-libavcodec_aacenc_h,v 1.4 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
aacenc: copy PRNG from the decoder
|
||||
|
||||
@ -14,9 +14,11 @@ aacenc: increase size of s->planar_samples[] from 6 to 8
|
||||
|
||||
aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
|
||||
aacenc: add support for encoding files using Long Term Prediction
|
||||
|
||||
--- libavcodec/aacenc.h.orig Mon Sep 7 21:58:01 2015
|
||||
+++ libavcodec/aacenc.h Mon Oct 12 22:06:52 2015
|
||||
@@ -42,11 +42,11 @@ typedef enum AACCoder {
|
||||
+++ libavcodec/aacenc.h Fri Oct 16 23:46:05 2015
|
||||
@@ -42,11 +42,12 @@ typedef enum AACCoder {
|
||||
}AACCoder;
|
||||
|
||||
typedef struct AACEncOptions {
|
||||
@ -25,26 +27,34 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
+ int coder;
|
||||
int pns;
|
||||
int tns;
|
||||
+ int ltp;
|
||||
int pred;
|
||||
+ int mid_side;
|
||||
int intensity_stereo;
|
||||
} AACEncOptions;
|
||||
|
||||
@@ -61,11 +61,12 @@ typedef struct AACCoefficientsEncoder {
|
||||
@@ -60,13 +61,19 @@ typedef struct AACCoefficientsEncoder {
|
||||
void (*quantize_and_encode_band)(struct AACEncContext *s, PutBitContext *pb, const float *in, float *out, int size,
|
||||
int scale_idx, int cb, const float lambda, int rtz);
|
||||
void (*encode_tns_info)(struct AACEncContext *s, SingleChannelElement *sce);
|
||||
+ void (*encode_ltp_info)(struct AACEncContext *s, SingleChannelElement *sce, int common_window);
|
||||
void (*encode_main_pred)(struct AACEncContext *s, SingleChannelElement *sce);
|
||||
- void (*adjust_common_prediction)(struct AACEncContext *s, ChannelElement *cpe);
|
||||
+ void (*adjust_common_pred)(struct AACEncContext *s, ChannelElement *cpe);
|
||||
+ void (*adjust_common_ltp)(struct AACEncContext *s, ChannelElement *cpe);
|
||||
void (*apply_main_pred)(struct AACEncContext *s, SingleChannelElement *sce);
|
||||
void (*apply_tns_filt)(struct AACEncContext *s, SingleChannelElement *sce);
|
||||
+ void (*update_ltp)(struct AACEncContext *s, SingleChannelElement *sce);
|
||||
+ void (*ltp_insert_new_frame)(struct AACEncContext *s);
|
||||
void (*set_special_band_scalefactors)(struct AACEncContext *s, SingleChannelElement *sce);
|
||||
void (*search_for_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce);
|
||||
+ void (*mark_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce);
|
||||
void (*search_for_tns)(struct AACEncContext *s, SingleChannelElement *sce);
|
||||
+ void (*search_for_ltp)(struct AACEncContext *s, SingleChannelElement *sce, int common_window);
|
||||
void (*search_for_ms)(struct AACEncContext *s, ChannelElement *cpe);
|
||||
void (*search_for_is)(struct AACEncContext *s, AVCodecContext *avctx, ChannelElement *cpe);
|
||||
@@ -74,6 +75,15 @@ typedef struct AACCoefficientsEncoder {
|
||||
void (*search_for_pred)(struct AACEncContext *s, SingleChannelElement *sce);
|
||||
@@ -74,6 +81,15 @@ typedef struct AACCoefficientsEncoder {
|
||||
|
||||
extern AACCoefficientsEncoder ff_aac_coders[];
|
||||
|
||||
@ -60,7 +70,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
/**
|
||||
* AAC encoder context
|
||||
*/
|
||||
@@ -84,7 +94,7 @@ typedef struct AACEncContext {
|
||||
@@ -84,7 +100,7 @@ typedef struct AACEncContext {
|
||||
FFTContext mdct1024; ///< long (1024 samples) frame transform context
|
||||
FFTContext mdct128; ///< short (128 samples) frame transform context
|
||||
AVFloatDSPContext *fdsp;
|
||||
@ -69,7 +79,7 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
|
||||
int profile; ///< copied from avctx
|
||||
LPCContext lpc; ///< used by TNS
|
||||
@@ -96,18 +106,27 @@ typedef struct AACEncContext {
|
||||
@@ -96,18 +112,27 @@ typedef struct AACEncContext {
|
||||
FFPsyContext psy;
|
||||
struct FFPsyPreprocessContext* psypp;
|
||||
AACCoefficientsEncoder *coder;
|
||||
|
234
graphics/ffmpeg/patches/patch-libavcodec_aacenc_ltp_c
Normal file
234
graphics/ffmpeg/patches/patch-libavcodec_aacenc_ltp_c
Normal file
@ -0,0 +1,234 @@
|
||||
$OpenBSD: patch-libavcodec_aacenc_ltp_c,v 1.1 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
aacenc: add support for encoding files using Long Term Prediction
|
||||
|
||||
--- libavcodec/aacenc_ltp.c.orig Fri Oct 16 23:44:24 2015
|
||||
+++ libavcodec/aacenc_ltp.c Fri Oct 16 23:46:10 2015
|
||||
@@ -0,0 +1,227 @@
|
||||
+/*
|
||||
+ * AAC encoder TNS
|
||||
+ * Copyright (C) 2015 Rostislav Pehlivanov
|
||||
+ *
|
||||
+ * This file is part of FFmpeg.
|
||||
+ *
|
||||
+ * FFmpeg is free software; you can redistribute it and/or
|
||||
+ * modify it under the terms of the GNU Lesser General Public
|
||||
+ * License as published by the Free Software Foundation; either
|
||||
+ * version 2.1 of the License, or (at your option) any later version.
|
||||
+ *
|
||||
+ * FFmpeg is distributed in the hope that it will be useful,
|
||||
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ * Lesser General Public License for more details.
|
||||
+ *
|
||||
+ * You should have received a copy of the GNU Lesser General Public
|
||||
+ * License along with FFmpeg; if not, write to the Free Software
|
||||
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+ */
|
||||
+
|
||||
+/**
|
||||
+ * @file
|
||||
+ * AAC encoder long term prediction
|
||||
+ * @author Rostislav Pehlivanov ( atomnuker gmail com )
|
||||
+ */
|
||||
+
|
||||
+#include "aacenc_ltp.h"
|
||||
+#include "aacenc_quantization.h"
|
||||
+#include "aacenc_utils.h"
|
||||
+
|
||||
+/**
|
||||
+ * Encode LTP data.
|
||||
+ */
|
||||
+void ff_aac_encode_ltp_info(AACEncContext *s, SingleChannelElement *sce,
|
||||
+ int common_window)
|
||||
+{
|
||||
+ int i;
|
||||
+ IndividualChannelStream *ics = &sce->ics;
|
||||
+ if (s->profile != FF_PROFILE_AAC_LTP || !ics->predictor_present)
|
||||
+ return;
|
||||
+ if (common_window)
|
||||
+ put_bits(&s->pb, 1, 0);
|
||||
+ put_bits(&s->pb, 1, ics->ltp.present);
|
||||
+ if (!ics->ltp.present)
|
||||
+ return;
|
||||
+ put_bits(&s->pb, 11, ics->ltp.lag);
|
||||
+ put_bits(&s->pb, 3, ics->ltp.coef_idx);
|
||||
+ for (i = 0; i < FFMIN(ics->max_sfb, MAX_LTP_LONG_SFB); i++)
|
||||
+ put_bits(&s->pb, 1, ics->ltp.used[i]);
|
||||
+}
|
||||
+
|
||||
+void ff_aac_ltp_insert_new_frame(AACEncContext *s)
|
||||
+{
|
||||
+ int i, ch, tag, chans, cur_channel, start_ch = 0;
|
||||
+ ChannelElement *cpe;
|
||||
+ SingleChannelElement *sce;
|
||||
+ for (i = 0; i < s->chan_map[0]; i++) {
|
||||
+ cpe = &s->cpe[i];
|
||||
+ tag = s->chan_map[i+1];
|
||||
+ chans = tag == TYPE_CPE ? 2 : 1;
|
||||
+ for (ch = 0; ch < chans; ch++) {
|
||||
+ sce = &cpe->ch[ch];
|
||||
+ cur_channel = start_ch + ch;
|
||||
+ /* New sample + overlap */
|
||||
+ memcpy(&sce->ltp_state[0], &sce->ltp_state[1024], 1024*sizeof(sce->ltp_state[0]));
|
||||
+ memcpy(&sce->ltp_state[1024], &s->planar_samples[cur_channel][2048], 1024*sizeof(sce->ltp_state[0]));
|
||||
+ memcpy(&sce->ltp_state[2048], &sce->ret_buf[0], 1024*sizeof(sce->ltp_state[0]));
|
||||
+ }
|
||||
+ start_ch += chans;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/**
|
||||
+ * Process LTP parameters
|
||||
+ * @see Patent WO2006070265A1
|
||||
+ */
|
||||
+void ff_aac_update_ltp(AACEncContext *s, SingleChannelElement *sce)
|
||||
+{
|
||||
+ int i, j, lag;
|
||||
+ float corr, s0, s1, max_corr = 0.0f;
|
||||
+ float *samples = &s->planar_samples[s->cur_channel][1024];
|
||||
+ float *pred_signal = &sce->ltp_state[0];
|
||||
+ int samples_num = 2048;
|
||||
+
|
||||
+ if (s->profile != FF_PROFILE_AAC_LTP)
|
||||
+ return;
|
||||
+
|
||||
+ /* Calculate lag */
|
||||
+ for (i = 0; i < samples_num; i++) {
|
||||
+ s0 = s1 = 0.0f;
|
||||
+ for (j = 0; j < samples_num; j++) {
|
||||
+ if (j + 1024 < i)
|
||||
+ continue;
|
||||
+ s0 += samples[j]*pred_signal[j-i+1024];
|
||||
+ s1 += pred_signal[j-i+1024]*pred_signal[j-i+1024];
|
||||
+ }
|
||||
+ corr = s1 > 0.0f ? s0/sqrt(s1) : 0.0f;
|
||||
+ if (corr > max_corr) {
|
||||
+ max_corr = corr;
|
||||
+ lag = i;
|
||||
+ }
|
||||
+ }
|
||||
+ lag = av_clip(lag, 0, 2048); /* 11 bits => 2^11 = 2048 */
|
||||
+
|
||||
+ if (!lag) {
|
||||
+ sce->ics.ltp.lag = lag;
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ s0 = s1 = 0.0f;
|
||||
+ for (i = 0; i < lag; i++) {
|
||||
+ s0 += samples[i];
|
||||
+ s1 += pred_signal[i-lag+1024];
|
||||
+ }
|
||||
+
|
||||
+ sce->ics.ltp.coef_idx = quant_array_idx(s0/s1, ltp_coef, 8);
|
||||
+ sce->ics.ltp.coef = ltp_coef[sce->ics.ltp.coef_idx];
|
||||
+
|
||||
+ /* Predict the new samples */
|
||||
+ if (lag < 1024)
|
||||
+ samples_num = lag + 1024;
|
||||
+ for (i = 0; i < samples_num; i++)
|
||||
+ pred_signal[i+1024] = sce->ics.ltp.coef*pred_signal[i-lag+1024];
|
||||
+ memset(&pred_signal[samples_num], 0, (2048 - samples_num)*sizeof(float));
|
||||
+
|
||||
+ sce->ics.ltp.lag = lag;
|
||||
+}
|
||||
+
|
||||
+void ff_aac_adjust_common_ltp(AACEncContext *s, ChannelElement *cpe)
|
||||
+{
|
||||
+ int sfb, count = 0;
|
||||
+ SingleChannelElement *sce0 = &cpe->ch[0];
|
||||
+ SingleChannelElement *sce1 = &cpe->ch[1];
|
||||
+
|
||||
+ if (!cpe->common_window ||
|
||||
+ sce0->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE ||
|
||||
+ sce1->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE)
|
||||
+ return;
|
||||
+
|
||||
+ for (sfb = 0; sfb < FFMIN(sce0->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++) {
|
||||
+ int sum = sce0->ics.ltp.used[sfb] + sce1->ics.ltp.used[sfb];
|
||||
+ if (sum != 2) {
|
||||
+ sce0->ics.ltp.used[sfb] = 0;
|
||||
+ } else if (sum == 2) {
|
||||
+ count++;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ sce0->ics.ltp.present = !!count;
|
||||
+ sce0->ics.predictor_present = !!count;
|
||||
+}
|
||||
+
|
||||
+/**
|
||||
+ * Mark LTP sfb's
|
||||
+ */
|
||||
+void ff_aac_search_for_ltp(AACEncContext *s, SingleChannelElement *sce,
|
||||
+ int common_window)
|
||||
+{
|
||||
+ int w, g, w2, i, start = 0, count = 0;
|
||||
+ int saved_bits = -(15 + FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB));
|
||||
+ float *C34 = &s->scoefs[128*0], *PCD = &s->scoefs[128*1];
|
||||
+ float *PCD34 = &s->scoefs[128*2];
|
||||
+ const int max_ltp = FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB);
|
||||
+
|
||||
+ if (sce->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE ||
|
||||
+ !sce->ics.ltp.lag)
|
||||
+ return;
|
||||
+
|
||||
+ for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
|
||||
+ start = 0;
|
||||
+ for (g = 0; g < sce->ics.num_swb; g++) {
|
||||
+ int bits1 = 0, bits2 = 0;
|
||||
+ float dist1 = 0.0f, dist2 = 0.0f;
|
||||
+ if (w*16+g > max_ltp) {
|
||||
+ start += sce->ics.swb_sizes[g];
|
||||
+ continue;
|
||||
+ }
|
||||
+ for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
|
||||
+ int bits_tmp1, bits_tmp2;
|
||||
+ FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
|
||||
+ for (i = 0; i < sce->ics.swb_sizes[g]; i++)
|
||||
+ PCD[i] = sce->coeffs[start+(w+w2)*128+i] - sce->lcoeffs[start+(w+w2)*128+i];
|
||||
+ abs_pow34_v(C34, &sce->coeffs[start+(w+w2)*128], sce->ics.swb_sizes[g]);
|
||||
+ abs_pow34_v(PCD34, PCD, sce->ics.swb_sizes[g]);
|
||||
+ dist1 += quantize_band_cost(s, &sce->coeffs[start+(w+w2)*128], C34, sce->ics.swb_sizes[g],
|
||||
+ sce->sf_idx[(w+w2)*16+g], sce->band_type[(w+w2)*16+g],
|
||||
+ s->lambda/band->threshold, INFINITY, &bits_tmp1, NULL, 0);
|
||||
+ dist2 += quantize_band_cost(s, PCD, PCD34, sce->ics.swb_sizes[g],
|
||||
+ sce->sf_idx[(w+w2)*16+g],
|
||||
+ sce->band_type[(w+w2)*16+g],
|
||||
+ s->lambda/band->threshold, INFINITY, &bits_tmp2, NULL, 0);
|
||||
+ bits1 += bits_tmp1;
|
||||
+ bits2 += bits_tmp2;
|
||||
+ }
|
||||
+ if (dist2 < dist1 && bits2 < bits1) {
|
||||
+ for (w2 = 0; w2 < sce->ics.group_len[w]; w2++)
|
||||
+ for (i = 0; i < sce->ics.swb_sizes[g]; i++)
|
||||
+ sce->coeffs[start+(w+w2)*128+i] -= sce->lcoeffs[start+(w+w2)*128+i];
|
||||
+ sce->ics.ltp.used[w*16+g] = 1;
|
||||
+ saved_bits += bits1 - bits2;
|
||||
+ count++;
|
||||
+ }
|
||||
+ start += sce->ics.swb_sizes[g];
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ sce->ics.ltp.present = !!count && (saved_bits >= 0);
|
||||
+ sce->ics.predictor_present = !!sce->ics.ltp.present;
|
||||
+
|
||||
+ /* Reset any marked sfbs */
|
||||
+ if (!sce->ics.ltp.present && !!count) {
|
||||
+ for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
|
||||
+ start = 0;
|
||||
+ for (g = 0; g < sce->ics.num_swb; g++) {
|
||||
+ if (sce->ics.ltp.used[w*16+g]) {
|
||||
+ for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
|
||||
+ for (i = 0; i < sce->ics.swb_sizes[g]; i++) {
|
||||
+ sce->coeffs[start+(w+w2)*128+i] += sce->lcoeffs[start+(w+w2)*128+i];
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ start += sce->ics.swb_sizes[g];
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+}
|
48
graphics/ffmpeg/patches/patch-libavcodec_aacenc_ltp_h
Normal file
48
graphics/ffmpeg/patches/patch-libavcodec_aacenc_ltp_h
Normal file
@ -0,0 +1,48 @@
|
||||
$OpenBSD: patch-libavcodec_aacenc_ltp_h,v 1.1 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
aacenc: add support for encoding files using Long Term Prediction
|
||||
|
||||
--- libavcodec/aacenc_ltp.h.orig Fri Oct 16 23:44:22 2015
|
||||
+++ libavcodec/aacenc_ltp.h Fri Oct 16 23:46:10 2015
|
||||
@@ -0,0 +1,41 @@
|
||||
+/*
|
||||
+ * AAC encoder long term prediction extension
|
||||
+ * Copyright (C) 2015 Rostislav Pehlivanov
|
||||
+ *
|
||||
+ * This file is part of FFmpeg.
|
||||
+ *
|
||||
+ * FFmpeg is free software; you can redistribute it and/or
|
||||
+ * modify it under the terms of the GNU Lesser General Public
|
||||
+ * License as published by the Free Software Foundation; either
|
||||
+ * version 2.1 of the License, or (at your option) any later version.
|
||||
+ *
|
||||
+ * FFmpeg is distributed in the hope that it will be useful,
|
||||
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ * Lesser General Public License for more details.
|
||||
+ *
|
||||
+ * You should have received a copy of the GNU Lesser General Public
|
||||
+ * License along with FFmpeg; if not, write to the Free Software
|
||||
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+ */
|
||||
+
|
||||
+/**
|
||||
+ * @file
|
||||
+ * AAC encoder long term prediction extension
|
||||
+ * @author Rostislav Pehlivanov ( atomnuker gmail com )
|
||||
+ */
|
||||
+
|
||||
+#ifndef AVCODEC_AACENC_LTP_H
|
||||
+#define AVCODEC_AACENC_LTP_H
|
||||
+
|
||||
+#include "aacenc.h"
|
||||
+
|
||||
+void ff_aac_encode_ltp_info(AACEncContext *s, SingleChannelElement *sce,
|
||||
+ int common_window);
|
||||
+void ff_aac_update_ltp(AACEncContext *s, SingleChannelElement *sce);
|
||||
+void ff_aac_adjust_common_ltp(AACEncContext *s, ChannelElement *cpe);
|
||||
+void ff_aac_ltp_insert_new_frame(AACEncContext *s);
|
||||
+void ff_aac_search_for_ltp(AACEncContext *s, SingleChannelElement *sce,
|
||||
+ int common_window);
|
||||
+
|
||||
+#endif /* AVCODEC_AACENC_LTP_H */
|
@ -1,4 +1,4 @@
|
||||
$OpenBSD: patch-libavcodec_aacenc_pred_c,v 1.2 2015/10/13 05:44:18 ajacoutot Exp $
|
||||
$OpenBSD: patch-libavcodec_aacenc_pred_c,v 1.3 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
aacenc_pred: disable PNS SFBs and disable right predictors with IS
|
||||
|
||||
@ -6,8 +6,21 @@ AAC encoder: Extensive improvements
|
||||
|
||||
aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
|
||||
aacenc_pred: correct header information
|
||||
|
||||
aacenc_pred: only print predictor information if profile is aac_main
|
||||
|
||||
--- libavcodec/aacenc_pred.c.orig Mon Sep 7 21:58:01 2015
|
||||
+++ libavcodec/aacenc_pred.c Mon Oct 12 22:05:12 2015
|
||||
+++ libavcodec/aacenc_pred.c Fri Oct 16 23:42:23 2015
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
- * AAC encoder Intensity Stereo
|
||||
+ * AAC encoder main-type prediction
|
||||
* @author Rostislav Pehlivanov ( atomnuker gmail com )
|
||||
*/
|
||||
|
||||
@@ -148,7 +148,7 @@ static inline int update_counters(IndividualChannelStr
|
||||
return 0;
|
||||
}
|
||||
@ -54,3 +67,13 @@ aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
for (i = 0; i < num_coeffs; i++)
|
||||
dist_spec_err += (O34[i] - P34[i])*(O34[i] - P34[i]);
|
||||
dist_spec_err *= s->lambda / band->threshold;
|
||||
@@ -331,7 +333,8 @@ void ff_aac_encode_main_pred(AACEncContext *s, SingleC
|
||||
IndividualChannelStream *ics = &sce->ics;
|
||||
const int pmax = FFMIN(ics->max_sfb, ff_aac_pred_sfb_max[s->samplerate_index]);
|
||||
|
||||
- if (!ics->predictor_present)
|
||||
+ if (s->profile != FF_PROFILE_AAC_MAIN ||
|
||||
+ !ics->predictor_present)
|
||||
return;
|
||||
|
||||
put_bits(&s->pb, 1, !!ics->predictor_reset_group);
|
||||
|
@ -1,9 +1,20 @@
|
||||
$OpenBSD: patch-libavcodec_aacenc_pred_h,v 1.1 2015/10/13 05:44:18 ajacoutot Exp $
|
||||
$OpenBSD: patch-libavcodec_aacenc_pred_h,v 1.2 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
aacenc: shorten name of ff_aac_adjust_common_prediction
|
||||
|
||||
--- libavcodec/aacenc_pred.h.orig Mon Oct 12 22:03:10 2015
|
||||
+++ libavcodec/aacenc_pred.h Mon Oct 12 22:05:15 2015
|
||||
aacenc_pred: correct header information
|
||||
|
||||
--- libavcodec/aacenc_pred.h.orig Mon Sep 7 21:58:01 2015
|
||||
+++ libavcodec/aacenc_pred.h Fri Oct 16 23:42:23 2015
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
- * AAC encoder main prediction
|
||||
+ * AAC encoder main-type prediction
|
||||
* @author Rostislav Pehlivanov ( atomnuker gmail com )
|
||||
*/
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#define PRED_SFB_START 10
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
$OpenBSD: patch-libavcodec_aacenc_utils_h,v 1.3 2015/10/13 05:44:18 ajacoutot Exp $
|
||||
$OpenBSD: patch-libavcodec_aacenc_utils_h,v 1.4 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
aacenc: copy PRNG from the decoder
|
||||
|
||||
@ -12,8 +12,10 @@ aacenc: add support for changing options based on a profile
|
||||
|
||||
aacenc_utils: fit find_form_factor() below 80 chars per line
|
||||
|
||||
aacenc: partially revert previous commits to set options via a profile
|
||||
|
||||
--- libavcodec/aacenc_utils.h.orig Mon Sep 7 21:58:01 2015
|
||||
+++ libavcodec/aacenc_utils.h Mon Oct 12 22:07:45 2015
|
||||
+++ libavcodec/aacenc_utils.h Fri Oct 16 23:46:52 2015
|
||||
@@ -89,16 +89,62 @@ static inline int find_min_book(float maxval, int sf)
|
||||
float Q34 = sqrtf(Q * sqrtf(Q));
|
||||
int qmaxval, cb;
|
||||
@ -108,47 +110,10 @@ aacenc_utils: fit find_form_factor() below 80 chars per line
|
||||
#define ERROR_IF(cond, ...) \
|
||||
if (cond) { \
|
||||
av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
|
||||
@@ -139,5 +202,43 @@ static inline int quant_array_idx(const float val, con
|
||||
@@ -138,6 +201,5 @@ static inline int quant_array_idx(const float val, con
|
||||
if (cond) { \
|
||||
av_log(avctx, AV_LOG_WARNING, __VA_ARGS__); \
|
||||
}
|
||||
|
||||
+#define AAC_OPT_SET(e_opt, p_opt, bypass, name) \
|
||||
+ ERROR_IF ((e_opt)->name == 1 && (p_opt)->name == OPT_BANNED, \
|
||||
+ "Profile %i does not allow %s\n", avctx->profile, #name); \
|
||||
+ ERROR_IF ((e_opt)->name == 0 && (p_opt)->name == OPT_REQUIRED, \
|
||||
+ "Option %s is a requirement for this profile (%i)\n", \
|
||||
+ #name, avctx->profile); \
|
||||
+ if ((e_opt)->name == 1 && (p_opt)->name == OPT_NEEDS_MAIN && \
|
||||
+ avctx->profile == FF_PROFILE_AAC_LOW) { \
|
||||
+ WARN_IF(1, "Profile %i does not allow for %s, setting profile to " \
|
||||
+ "\"aac_main\"(%i)\n", avctx->profile, #name, \
|
||||
+ FF_PROFILE_AAC_MAIN); \
|
||||
+ avctx->profile = FF_PROFILE_AAC_MAIN; \
|
||||
+ p_opt = &aacenc_profiles[FF_PROFILE_AAC_MAIN].opts; \
|
||||
+ } \
|
||||
+ if ((e_opt)->name == 1 && (p_opt)->name == OPT_NEEDS_LTP && \
|
||||
+ avctx->profile == FF_PROFILE_AAC_LOW) { \
|
||||
+ WARN_IF(1, "Profile %i does not allow for %s, setting profile to " \
|
||||
+ "\"aac_ltp\"(%i)\n", avctx->profile, #name, \
|
||||
+ FF_PROFILE_AAC_LTP); \
|
||||
+ avctx->profile = FF_PROFILE_AAC_LTP; \
|
||||
+ p_opt = &aacenc_profiles[FF_PROFILE_AAC_LTP].opts; \
|
||||
+ } \
|
||||
+ if ((e_opt)->name == OPT_AUTO) { \
|
||||
+ if ((p_opt)->name == OPT_BANNED) { \
|
||||
+ (e_opt)->name = 0; \
|
||||
+ } else if ((p_opt)->name == OPT_NEEDS_LTP) { \
|
||||
+ (e_opt)->name = 0; \
|
||||
+ } else if ((p_opt)->name == OPT_NEEDS_MAIN) { \
|
||||
+ (e_opt)->name = 0; \
|
||||
+ } else if ((p_opt)->name == OPT_REQUIRED) { \
|
||||
+ (e_opt)->name = 1; \
|
||||
+ } else if (bypass) { \
|
||||
+ (e_opt)->name = (e_opt)->name; \
|
||||
+ } else { \
|
||||
+ (e_opt)->name = (p_opt)->name; \
|
||||
+ } \
|
||||
+ } \
|
||||
+ av_log(avctx, AV_LOG_VERBOSE, "Option %s set to %i\n", #name, (e_opt)->name);
|
||||
-
|
||||
|
||||
#endif /* AVCODEC_AACENC_UTILS_H */
|
||||
|
@ -1,4 +1,4 @@
|
||||
$OpenBSD: patch-libavcodec_aacenctab_h,v 1.3 2015/10/13 05:44:18 ajacoutot Exp $
|
||||
$OpenBSD: patch-libavcodec_aacenctab_h,v 1.4 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
AAC encoder: simplify and speed up find_min_book
|
||||
|
||||
@ -8,25 +8,20 @@ aacenc: add support for encoding 7.1 channel audio
|
||||
|
||||
aacenc: add support for changing options based on a profile
|
||||
|
||||
aacenc: partially revert previous commits to set options via a profile
|
||||
|
||||
--- libavcodec/aacenctab.h.orig Mon Sep 7 21:58:01 2015
|
||||
+++ libavcodec/aacenctab.h Mon Oct 12 22:07:27 2015
|
||||
@@ -36,21 +36,30 @@
|
||||
+++ libavcodec/aacenctab.h Fri Oct 16 23:46:59 2015
|
||||
@@ -36,7 +36,7 @@
|
||||
/** Total number of codebooks, including special ones **/
|
||||
#define CB_TOT_ALL 15
|
||||
|
||||
-#define AAC_MAX_CHANNELS 6
|
||||
+/** Profile option settings **/
|
||||
+#define OPT_AUTO -1
|
||||
+#define OPT_BANNED -256
|
||||
+#define OPT_NEEDS_LTP -384
|
||||
+#define OPT_NEEDS_MAIN -512
|
||||
+#define OPT_REQUIRED -768
|
||||
|
||||
+#define AAC_MAX_CHANNELS 8
|
||||
+
|
||||
|
||||
extern const uint8_t *ff_aac_swb_size_1024[];
|
||||
extern const int ff_aac_swb_size_1024_len;
|
||||
extern const uint8_t *ff_aac_swb_size_128[];
|
||||
@@ -44,13 +44,15 @@ extern const uint8_t *ff_aac_swb_size_128[];
|
||||
extern const int ff_aac_swb_size_128_len;
|
||||
|
||||
/** default channel configurations */
|
||||
@ -49,7 +44,7 @@ aacenc: add support for changing options based on a profile
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -63,6 +72,8 @@ static const uint8_t aac_chan_maps[AAC_MAX_CHANNELS][A
|
||||
@@ -63,6 +65,8 @@ static const uint8_t aac_chan_maps[AAC_MAX_CHANNELS][A
|
||||
{ 2, 0, 1, 3 },
|
||||
{ 2, 0, 1, 3, 4 },
|
||||
{ 2, 0, 1, 4, 5, 3 },
|
||||
@ -58,13 +53,20 @@ aacenc: add support for changing options based on a profile
|
||||
};
|
||||
|
||||
/* duplicated from avpriv_mpeg4audio_sample_rates to avoid shared build
|
||||
@@ -109,5 +120,9 @@ static const uint8_t aac_cb_in_map[CB_TOT_ALL+1] = {0,
|
||||
@@ -109,5 +113,16 @@ static const uint8_t aac_cb_in_map[CB_TOT_ALL+1] = {0,
|
||||
|
||||
static const uint8_t aac_cb_range [12] = {0, 3, 3, 3, 3, 9, 9, 8, 8, 13, 13, 17};
|
||||
static const uint8_t aac_cb_maxval[12] = {0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12, 16};
|
||||
+
|
||||
+static const unsigned char aac_maxval_cb[] = {
|
||||
+ 0, 1, 3, 5, 5, 7, 7, 7, 9, 9, 9, 9, 9, 11
|
||||
+};
|
||||
+
|
||||
+static const int aacenc_profiles[] = {
|
||||
+ FF_PROFILE_AAC_MAIN,
|
||||
+ FF_PROFILE_AAC_LOW,
|
||||
+ FF_PROFILE_AAC_LTP,
|
||||
+ FF_PROFILE_MPEG2_AAC_LOW,
|
||||
+};
|
||||
|
||||
#endif /* AVCODEC_AACENCTAB_H */
|
||||
|
21
graphics/ffmpeg/patches/patch-libavcodec_aactab_h
Normal file
21
graphics/ffmpeg/patches/patch-libavcodec_aactab_h
Normal file
@ -0,0 +1,21 @@
|
||||
$OpenBSD: patch-libavcodec_aactab_h,v 1.1 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
aactab: move ltp_coef[] from aacdectab to aactab
|
||||
|
||||
--- libavcodec/aactab.h.orig Fri Oct 16 23:41:25 2015
|
||||
+++ libavcodec/aactab.h Fri Oct 16 23:41:38 2015
|
||||
@@ -41,6 +41,14 @@
|
||||
* encoder.
|
||||
*/
|
||||
|
||||
+/* @name ltp_coef
|
||||
+ * Table of the LTP coefficients
|
||||
+ */
|
||||
+static const INTFLOAT ltp_coef[8] = {
|
||||
+ Q30(0.570829f), Q30(0.696616f), Q30(0.813004f), Q30(0.911304f),
|
||||
+ Q30(0.984900f), Q30(1.067894f), Q30(1.194601f), Q30(1.369533f),
|
||||
+};
|
||||
+
|
||||
/* @name tns_tmp2_map
|
||||
* Tables of the tmp2[] arrays of LPC coefficients used for TNS.
|
||||
* The suffix _M_N[] indicate the values of coef_compress and coef_res
|
@ -1,4 +1,4 @@
|
||||
$OpenBSD: patch-libavcodec_mips_aaccoder_mips_c,v 1.2 2015/10/13 05:44:18 ajacoutot Exp $
|
||||
$OpenBSD: patch-libavcodec_mips_aaccoder_mips_c,v 1.3 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
AAC encoder: refactor to resynchronize MIPS port
|
||||
|
||||
@ -10,17 +10,20 @@ AAC encoder: memoize quantize_band_cost
|
||||
|
||||
avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build failure
|
||||
|
||||
avcodec/mips/aaccoder_mips: Sync with the generic code
|
||||
|
||||
--- libavcodec/mips/aaccoder_mips.c.orig Mon Sep 7 21:58:02 2015
|
||||
+++ libavcodec/mips/aaccoder_mips.c Mon Oct 12 22:06:02 2015
|
||||
@@ -62,6 +62,7 @@
|
||||
+++ libavcodec/mips/aaccoder_mips.c Tue Oct 13 18:31:42 2015
|
||||
@@ -62,6 +62,8 @@
|
||||
#include "libavcodec/aac.h"
|
||||
#include "libavcodec/aacenc.h"
|
||||
#include "libavcodec/aactab.h"
|
||||
+#include "libavcodec/aacenctab.h"
|
||||
+#include "libavcodec/aacenc_utils.h"
|
||||
|
||||
#if HAVE_INLINE_ASM
|
||||
typedef struct BandCodingPath {
|
||||
@@ -70,21 +71,6 @@ typedef struct BandCodingPath {
|
||||
@@ -70,21 +72,6 @@ typedef struct BandCodingPath {
|
||||
int run;
|
||||
} BandCodingPath;
|
||||
|
||||
@ -42,10 +45,59 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
static const uint8_t uquad_sign_bits[81] = {
|
||||
0, 1, 1, 1, 2, 2, 1, 2, 2,
|
||||
1, 2, 2, 2, 3, 3, 2, 3, 3,
|
||||
@@ -193,13 +179,10 @@ static int find_min_book(float maxval, int sf) {
|
||||
float Q34 = sqrtf(Q * sqrtf(Q));
|
||||
int qmaxval, cb;
|
||||
qmaxval = maxval * Q34 + 0.4054f;
|
||||
@@ -144,65 +131,6 @@ static const uint8_t esc_sign_bits[289] = {
|
||||
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
|
||||
};
|
||||
|
||||
-#define ROUND_STANDARD 0.4054f
|
||||
-#define ROUND_TO_ZERO 0.1054f
|
||||
-
|
||||
-static void abs_pow34_v(float *out, const float *in, const int size) {
|
||||
-#ifndef USE_REALLY_FULL_SEARCH
|
||||
- int i;
|
||||
- float a, b, c, d;
|
||||
- float ax, bx, cx, dx;
|
||||
-
|
||||
- for (i = 0; i < size; i += 4) {
|
||||
- a = fabsf(in[i ]);
|
||||
- b = fabsf(in[i+1]);
|
||||
- c = fabsf(in[i+2]);
|
||||
- d = fabsf(in[i+3]);
|
||||
-
|
||||
- ax = sqrtf(a);
|
||||
- bx = sqrtf(b);
|
||||
- cx = sqrtf(c);
|
||||
- dx = sqrtf(d);
|
||||
-
|
||||
- a = a * ax;
|
||||
- b = b * bx;
|
||||
- c = c * cx;
|
||||
- d = d * dx;
|
||||
-
|
||||
- out[i ] = sqrtf(a);
|
||||
- out[i+1] = sqrtf(b);
|
||||
- out[i+2] = sqrtf(c);
|
||||
- out[i+3] = sqrtf(d);
|
||||
- }
|
||||
-#endif /* USE_REALLY_FULL_SEARCH */
|
||||
-}
|
||||
-
|
||||
-static float find_max_val(int group_len, int swb_size, const float *scaled) {
|
||||
- float maxval = 0.0f;
|
||||
- int w2, i;
|
||||
- for (w2 = 0; w2 < group_len; w2++) {
|
||||
- for (i = 0; i < swb_size; i++) {
|
||||
- maxval = FFMAX(maxval, scaled[w2*128+i]);
|
||||
- }
|
||||
- }
|
||||
- return maxval;
|
||||
-}
|
||||
-
|
||||
-static int find_min_book(float maxval, int sf) {
|
||||
- float Q = ff_aac_pow2sf_tab[POW_SF2_ZERO - sf + SCALE_ONE_POS - SCALE_DIV_512];
|
||||
- float Q34 = sqrtf(Q * sqrtf(Q));
|
||||
- int qmaxval, cb;
|
||||
- qmaxval = maxval * Q34 + 0.4054f;
|
||||
- if (qmaxval == 0) cb = 0;
|
||||
- else if (qmaxval == 1) cb = 1;
|
||||
- else if (qmaxval == 2) cb = 3;
|
||||
@ -53,14 +105,13 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
- else if (qmaxval <= 7) cb = 7;
|
||||
- else if (qmaxval <= 12) cb = 9;
|
||||
- else cb = 11;
|
||||
+ if (qmaxval >= (FF_ARRAY_ELEMS(aac_maxval_cb)))
|
||||
+ cb = 11;
|
||||
+ else
|
||||
+ cb = aac_maxval_cb[qmaxval];
|
||||
return cb;
|
||||
}
|
||||
|
||||
@@ -210,14 +193,17 @@ static void quantize_and_encode_band_cost_SQUAD_mips(s
|
||||
- return cb;
|
||||
-}
|
||||
-
|
||||
/**
|
||||
* Functions developed from template function and optimized for quantizing and encoding band
|
||||
*/
|
||||
@@ -210,14 +138,17 @@ static void quantize_and_encode_band_cost_SQUAD_mips(s
|
||||
PutBitContext *pb, const float *in, float *out,
|
||||
const float *scaled, int size, int scale_idx,
|
||||
int cb, const float lambda, const float uplim,
|
||||
@ -79,7 +130,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
|
||||
abs_pow34_v(s->scoefs, in, size);
|
||||
scaled = s->scoefs;
|
||||
@@ -225,6 +211,7 @@ static void quantize_and_encode_band_cost_SQUAD_mips(s
|
||||
@@ -225,6 +156,7 @@ static void quantize_and_encode_band_cost_SQUAD_mips(s
|
||||
int curidx;
|
||||
int *in_int = (int *)&in[i];
|
||||
int t0, t1, t2, t3, t4, t5, t6, t7;
|
||||
@ -87,7 +138,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
|
||||
qc1 = scaled[i ] * Q34 + ROUND_STANDARD;
|
||||
qc2 = scaled[i+1] * Q34 + ROUND_STANDARD;
|
||||
@@ -276,21 +263,43 @@ static void quantize_and_encode_band_cost_SQUAD_mips(s
|
||||
@@ -276,21 +208,43 @@ static void quantize_and_encode_band_cost_SQUAD_mips(s
|
||||
curidx += 40;
|
||||
|
||||
put_bits(pb, p_bits[curidx], p_codes[curidx]);
|
||||
@ -132,7 +183,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
|
||||
abs_pow34_v(s->scoefs, in, size);
|
||||
scaled = s->scoefs;
|
||||
@@ -300,6 +309,7 @@ static void quantize_and_encode_band_cost_UQUAD_mips(s
|
||||
@@ -300,6 +254,7 @@ static void quantize_and_encode_band_cost_UQUAD_mips(s
|
||||
uint8_t v_bits;
|
||||
unsigned int v_codes;
|
||||
int t0, t1, t2, t3, t4;
|
||||
@ -140,7 +191,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
|
||||
qc1 = scaled[i ] * Q34 + ROUND_STANDARD;
|
||||
qc2 = scaled[i+1] * Q34 + ROUND_STANDARD;
|
||||
@@ -368,21 +378,43 @@ static void quantize_and_encode_band_cost_UQUAD_mips(s
|
||||
@@ -368,21 +323,43 @@ static void quantize_and_encode_band_cost_UQUAD_mips(s
|
||||
v_codes = (p_codes[curidx] << count) | (sign & ((1 << count) - 1));
|
||||
v_bits = p_bits[curidx] + count;
|
||||
put_bits(pb, v_bits, v_codes);
|
||||
@ -185,7 +236,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
|
||||
abs_pow34_v(s->scoefs, in, size);
|
||||
scaled = s->scoefs;
|
||||
@@ -392,6 +424,7 @@ static void quantize_and_encode_band_cost_SPAIR_mips(s
|
||||
@@ -392,6 +369,7 @@ static void quantize_and_encode_band_cost_SPAIR_mips(s
|
||||
uint8_t v_bits;
|
||||
unsigned int v_codes;
|
||||
int t0, t1, t2, t3, t4, t5, t6, t7;
|
||||
@ -193,7 +244,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
|
||||
qc1 = scaled[i ] * Q34 + ROUND_STANDARD;
|
||||
qc2 = scaled[i+1] * Q34 + ROUND_STANDARD;
|
||||
@@ -447,30 +480,54 @@ static void quantize_and_encode_band_cost_SPAIR_mips(s
|
||||
@@ -447,30 +425,54 @@ static void quantize_and_encode_band_cost_SPAIR_mips(s
|
||||
v_codes = (p_codes[curidx] << p_bits[curidx2]) | (p_codes[curidx2]);
|
||||
v_bits = p_bits[curidx] + p_bits[curidx2];
|
||||
put_bits(pb, v_bits, v_codes);
|
||||
@ -250,7 +301,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
|
||||
qc1 = scaled[i ] * Q34 + ROUND_STANDARD;
|
||||
qc2 = scaled[i+1] * Q34 + ROUND_STANDARD;
|
||||
@@ -528,43 +585,67 @@ static void quantize_and_encode_band_cost_UPAIR7_mips(
|
||||
@@ -528,43 +530,67 @@ static void quantize_and_encode_band_cost_UPAIR7_mips(
|
||||
"memory"
|
||||
);
|
||||
|
||||
@ -328,7 +379,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
|
||||
qc1 = scaled[i ] * Q34 + ROUND_STANDARD;
|
||||
qc2 = scaled[i+1] * Q34 + ROUND_STANDARD;
|
||||
@@ -621,31 +702,53 @@ static void quantize_and_encode_band_cost_UPAIR12_mips
|
||||
@@ -621,31 +647,53 @@ static void quantize_and_encode_band_cost_UPAIR12_mips
|
||||
: "memory"
|
||||
);
|
||||
|
||||
@ -391,7 +442,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
|
||||
uint8_t *p_bits = (uint8_t* )ff_aac_spectral_bits[cb-1];
|
||||
uint16_t *p_codes = (uint16_t*)ff_aac_spectral_codes[cb-1];
|
||||
@@ -661,6 +764,7 @@ static void quantize_and_encode_band_cost_ESC_mips(str
|
||||
@@ -661,6 +709,7 @@ static void quantize_and_encode_band_cost_ESC_mips(str
|
||||
uint8_t v_bits;
|
||||
unsigned int v_codes;
|
||||
int t0, t1, t2, t3, t4;
|
||||
@ -399,7 +450,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
|
||||
qc1 = scaled[i ] * Q34 + ROUNDING;
|
||||
qc2 = scaled[i+1] * Q34 + ROUNDING;
|
||||
@@ -729,6 +833,24 @@ static void quantize_and_encode_band_cost_ESC_mips(str
|
||||
@@ -729,6 +778,24 @@ static void quantize_and_encode_band_cost_ESC_mips(str
|
||||
v_codes = (p_codes[curidx2] << count2) | sign2;
|
||||
v_bits = p_bits[curidx2] + count2;
|
||||
put_bits(pb, v_bits, v_codes);
|
||||
@ -424,23 +475,13 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < size; i += 4) {
|
||||
@@ -738,6 +860,7 @@ static void quantize_and_encode_band_cost_ESC_mips(str
|
||||
unsigned int v_codes;
|
||||
int c1, c2, c3, c4;
|
||||
int t0, t1, t2, t3, t4;
|
||||
+ const float *vec1, *vec2;
|
||||
|
||||
qc1 = scaled[i ] * Q34 + ROUNDING;
|
||||
qc2 = scaled[i+1] * Q34 + ROUNDING;
|
||||
@@ -839,15 +962,35 @@ static void quantize_and_encode_band_cost_ESC_mips(str
|
||||
@@ -839,15 +906,33 @@ static void quantize_and_encode_band_cost_ESC_mips(str
|
||||
v_codes = (((1 << (len - 3)) - 2) << len) | (c4 & ((1 << len) - 1));
|
||||
put_bits(pb, len * 2 - 3, v_codes);
|
||||
}
|
||||
+
|
||||
+ if (out || energy) {
|
||||
+ float e1, e2, e3, e4;
|
||||
+ vec1 = &p_vectors[curidx*2];
|
||||
+ vec2 = &p_vectors[curidx2*2];
|
||||
+ e1 = copysignf(c1 * cbrtf(c1) * IQ, in[i+0]);
|
||||
+ e2 = copysignf(c2 * cbrtf(c2) * IQ, in[i+1]);
|
||||
+ e3 = copysignf(c3 * cbrtf(c3) * IQ, in[i+2]);
|
||||
@ -469,7 +510,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
av_assert0(0);
|
||||
}
|
||||
|
||||
@@ -855,7 +998,7 @@ static void quantize_and_encode_band_cost_ZERO_mips(st
|
||||
@@ -855,7 +940,7 @@ static void quantize_and_encode_band_cost_ZERO_mips(st
|
||||
PutBitContext *pb, const float *in, float *out,
|
||||
const float *scaled, int size, int scale_idx,
|
||||
int cb, const float lambda, const float uplim,
|
||||
@ -478,7 +519,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
int i;
|
||||
if (bits)
|
||||
*bits = 0;
|
||||
@@ -867,13 +1010,15 @@ static void quantize_and_encode_band_cost_ZERO_mips(st
|
||||
@@ -867,13 +952,15 @@ static void quantize_and_encode_band_cost_ZERO_mips(st
|
||||
out[i+3] = 0.0f;
|
||||
}
|
||||
}
|
||||
@ -495,7 +536,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
quantize_and_encode_band_cost_ZERO_mips,
|
||||
quantize_and_encode_band_cost_SQUAD_mips,
|
||||
quantize_and_encode_band_cost_SQUAD_mips,
|
||||
@@ -894,17 +1039,17 @@ static void (*const quantize_and_encode_band_cost_arr[
|
||||
@@ -894,17 +981,17 @@ static void (*const quantize_and_encode_band_cost_arr[
|
||||
|
||||
#define quantize_and_encode_band_cost( \
|
||||
s, pb, in, out, scaled, size, scale_idx, cb, \
|
||||
@ -516,7 +557,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1384,7 +1529,7 @@ static float (*const get_band_numbits_arr[])(struct AA
|
||||
@@ -1384,7 +1471,7 @@ static float (*const get_band_numbits_arr[])(struct AA
|
||||
static float quantize_band_cost_bits(struct AACEncContext *s, const float *in,
|
||||
const float *scaled, int size, int scale_idx,
|
||||
int cb, const float lambda, const float uplim,
|
||||
@ -525,7 +566,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
{
|
||||
return get_band_numbits(s, NULL, in, scaled, size, scale_idx, cb, lambda, uplim, bits);
|
||||
}
|
||||
@@ -1397,7 +1542,7 @@ static float get_band_cost_ZERO_mips(struct AACEncCont
|
||||
@@ -1397,7 +1484,7 @@ static float get_band_cost_ZERO_mips(struct AACEncCont
|
||||
PutBitContext *pb, const float *in,
|
||||
const float *scaled, int size, int scale_idx,
|
||||
int cb, const float lambda, const float uplim,
|
||||
@ -534,7 +575,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
{
|
||||
int i;
|
||||
float cost = 0;
|
||||
@@ -1410,6 +1555,8 @@ static float get_band_cost_ZERO_mips(struct AACEncCont
|
||||
@@ -1410,6 +1497,8 @@ static float get_band_cost_ZERO_mips(struct AACEncCont
|
||||
}
|
||||
if (bits)
|
||||
*bits = 0;
|
||||
@ -543,7 +584,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
return cost * lambda;
|
||||
}
|
||||
|
||||
@@ -1417,7 +1564,7 @@ static float get_band_cost_NONE_mips(struct AACEncCont
|
||||
@@ -1417,7 +1506,7 @@ static float get_band_cost_NONE_mips(struct AACEncCont
|
||||
PutBitContext *pb, const float *in,
|
||||
const float *scaled, int size, int scale_idx,
|
||||
int cb, const float lambda, const float uplim,
|
||||
@ -552,7 +593,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
{
|
||||
av_assert0(0);
|
||||
return 0;
|
||||
@@ -1427,12 +1574,13 @@ static float get_band_cost_SQUAD_mips(struct AACEncCon
|
||||
@@ -1427,12 +1516,13 @@ static float get_band_cost_SQUAD_mips(struct AACEncCon
|
||||
PutBitContext *pb, const float *in,
|
||||
const float *scaled, int size, int scale_idx,
|
||||
int cb, const float lambda, const float uplim,
|
||||
@ -567,7 +608,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
int qc1, qc2, qc3, qc4;
|
||||
int curbits = 0;
|
||||
|
||||
@@ -1499,6 +1647,9 @@ static float get_band_cost_SQUAD_mips(struct AACEncCon
|
||||
@@ -1499,6 +1589,9 @@ static float get_band_cost_SQUAD_mips(struct AACEncCon
|
||||
curbits += p_bits[curidx];
|
||||
vec = &p_codes[curidx*4];
|
||||
|
||||
@ -577,7 +618,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
__asm__ volatile (
|
||||
".set push \n\t"
|
||||
".set noreorder \n\t"
|
||||
@@ -1533,6 +1684,8 @@ static float get_band_cost_SQUAD_mips(struct AACEncCon
|
||||
@@ -1533,6 +1626,8 @@ static float get_band_cost_SQUAD_mips(struct AACEncCon
|
||||
|
||||
if (bits)
|
||||
*bits = curbits;
|
||||
@ -586,7 +627,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
return cost * lambda + curbits;
|
||||
}
|
||||
|
||||
@@ -1540,12 +1693,13 @@ static float get_band_cost_UQUAD_mips(struct AACEncCon
|
||||
@@ -1540,12 +1635,13 @@ static float get_band_cost_UQUAD_mips(struct AACEncCon
|
||||
PutBitContext *pb, const float *in,
|
||||
const float *scaled, int size, int scale_idx,
|
||||
int cb, const float lambda, const float uplim,
|
||||
@ -601,7 +642,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
int curbits = 0;
|
||||
int qc1, qc2, qc3, qc4;
|
||||
|
||||
@@ -1598,6 +1752,9 @@ static float get_band_cost_UQUAD_mips(struct AACEncCon
|
||||
@@ -1598,6 +1694,9 @@ static float get_band_cost_UQUAD_mips(struct AACEncCon
|
||||
curbits += uquad_sign_bits[curidx];
|
||||
vec = &p_codes[curidx*4];
|
||||
|
||||
@ -611,7 +652,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
__asm__ volatile (
|
||||
".set push \n\t"
|
||||
".set noreorder \n\t"
|
||||
@@ -1635,6 +1792,8 @@ static float get_band_cost_UQUAD_mips(struct AACEncCon
|
||||
@@ -1635,6 +1734,8 @@ static float get_band_cost_UQUAD_mips(struct AACEncCon
|
||||
|
||||
if (bits)
|
||||
*bits = curbits;
|
||||
@ -620,7 +661,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
return cost * lambda + curbits;
|
||||
}
|
||||
|
||||
@@ -1642,12 +1801,13 @@ static float get_band_cost_SPAIR_mips(struct AACEncCon
|
||||
@@ -1642,12 +1743,13 @@ static float get_band_cost_SPAIR_mips(struct AACEncCon
|
||||
PutBitContext *pb, const float *in,
|
||||
const float *scaled, int size, int scale_idx,
|
||||
int cb, const float lambda, const float uplim,
|
||||
@ -635,7 +676,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
int qc1, qc2, qc3, qc4;
|
||||
int curbits = 0;
|
||||
|
||||
@@ -1719,6 +1879,9 @@ static float get_band_cost_SPAIR_mips(struct AACEncCon
|
||||
@@ -1719,6 +1821,9 @@ static float get_band_cost_SPAIR_mips(struct AACEncCon
|
||||
vec = &p_codes[curidx*2];
|
||||
vec2 = &p_codes[curidx2*2];
|
||||
|
||||
@ -645,7 +686,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
__asm__ volatile (
|
||||
".set push \n\t"
|
||||
".set noreorder \n\t"
|
||||
@@ -1753,6 +1916,8 @@ static float get_band_cost_SPAIR_mips(struct AACEncCon
|
||||
@@ -1753,6 +1858,8 @@ static float get_band_cost_SPAIR_mips(struct AACEncCon
|
||||
|
||||
if (bits)
|
||||
*bits = curbits;
|
||||
@ -654,7 +695,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
return cost * lambda + curbits;
|
||||
}
|
||||
|
||||
@@ -1760,12 +1925,13 @@ static float get_band_cost_UPAIR7_mips(struct AACEncCo
|
||||
@@ -1760,12 +1867,13 @@ static float get_band_cost_UPAIR7_mips(struct AACEncCo
|
||||
PutBitContext *pb, const float *in,
|
||||
const float *scaled, int size, int scale_idx,
|
||||
int cb, const float lambda, const float uplim,
|
||||
@ -669,7 +710,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
int qc1, qc2, qc3, qc4;
|
||||
int curbits = 0;
|
||||
|
||||
@@ -1849,6 +2015,9 @@ static float get_band_cost_UPAIR7_mips(struct AACEncCo
|
||||
@@ -1849,6 +1957,9 @@ static float get_band_cost_UPAIR7_mips(struct AACEncCo
|
||||
curbits += upair7_sign_bits[curidx2];
|
||||
vec2 = &p_codes[curidx2*2];
|
||||
|
||||
@ -679,7 +720,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
__asm__ volatile (
|
||||
".set push \n\t"
|
||||
".set noreorder \n\t"
|
||||
@@ -1886,6 +2055,8 @@ static float get_band_cost_UPAIR7_mips(struct AACEncCo
|
||||
@@ -1886,6 +1997,8 @@ static float get_band_cost_UPAIR7_mips(struct AACEncCo
|
||||
|
||||
if (bits)
|
||||
*bits = curbits;
|
||||
@ -688,7 +729,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
return cost * lambda + curbits;
|
||||
}
|
||||
|
||||
@@ -1893,12 +2064,13 @@ static float get_band_cost_UPAIR12_mips(struct AACEncC
|
||||
@@ -1893,12 +2006,13 @@ static float get_band_cost_UPAIR12_mips(struct AACEncC
|
||||
PutBitContext *pb, const float *in,
|
||||
const float *scaled, int size, int scale_idx,
|
||||
int cb, const float lambda, const float uplim,
|
||||
@ -703,7 +744,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
int qc1, qc2, qc3, qc4;
|
||||
int curbits = 0;
|
||||
|
||||
@@ -1982,6 +2154,9 @@ static float get_band_cost_UPAIR12_mips(struct AACEncC
|
||||
@@ -1982,6 +2096,9 @@ static float get_band_cost_UPAIR12_mips(struct AACEncC
|
||||
vec = &p_codes[curidx*2];
|
||||
vec2 = &p_codes[curidx2*2];
|
||||
|
||||
@ -713,7 +754,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
__asm__ volatile (
|
||||
".set push \n\t"
|
||||
".set noreorder \n\t"
|
||||
@@ -2019,6 +2194,8 @@ static float get_band_cost_UPAIR12_mips(struct AACEncC
|
||||
@@ -2019,6 +2136,8 @@ static float get_band_cost_UPAIR12_mips(struct AACEncC
|
||||
|
||||
if (bits)
|
||||
*bits = curbits;
|
||||
@ -722,7 +763,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
return cost * lambda + curbits;
|
||||
}
|
||||
|
||||
@@ -2026,13 +2203,14 @@ static float get_band_cost_ESC_mips(struct AACEncConte
|
||||
@@ -2026,13 +2145,14 @@ static float get_band_cost_ESC_mips(struct AACEncConte
|
||||
PutBitContext *pb, const float *in,
|
||||
const float *scaled, int size, int scale_idx,
|
||||
int cb, const float lambda, const float uplim,
|
||||
@ -738,7 +779,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
int qc1, qc2, qc3, qc4;
|
||||
int curbits = 0;
|
||||
|
||||
@@ -2042,7 +2220,7 @@ static float get_band_cost_ESC_mips(struct AACEncConte
|
||||
@@ -2042,7 +2162,7 @@ static float get_band_cost_ESC_mips(struct AACEncConte
|
||||
for (i = 0; i < size; i += 4) {
|
||||
const float *vec, *vec2;
|
||||
int curidx, curidx2;
|
||||
@ -747,7 +788,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
float di1, di2, di3, di4;
|
||||
int cond0, cond1, cond2, cond3;
|
||||
int c1, c2, c3, c4;
|
||||
@@ -2114,38 +2292,54 @@ static float get_band_cost_ESC_mips(struct AACEncConte
|
||||
@@ -2114,38 +2234,54 @@ static float get_band_cost_ESC_mips(struct AACEncConte
|
||||
if (cond0) {
|
||||
if (t1 >= CLIPPED_ESCAPE) {
|
||||
di1 = t1 - CLIPPED_ESCAPE;
|
||||
@ -814,7 +855,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
|
||||
cost += di1 * di1 + di2 * di2
|
||||
+ di3 * di3 + di4 * di4;
|
||||
@@ -2160,7 +2354,7 @@ static float (*const get_band_cost_arr[])(struct AACEn
|
||||
@@ -2160,7 +2296,7 @@ static float (*const get_band_cost_arr[])(struct AACEn
|
||||
PutBitContext *pb, const float *in,
|
||||
const float *scaled, int size, int scale_idx,
|
||||
int cb, const float lambda, const float uplim,
|
||||
@ -823,7 +864,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
get_band_cost_ZERO_mips,
|
||||
get_band_cost_SQUAD_mips,
|
||||
get_band_cost_SQUAD_mips,
|
||||
@@ -2181,205 +2375,105 @@ static float (*const get_band_cost_arr[])(struct AACEn
|
||||
@@ -2181,205 +2317,35 @@ static float (*const get_band_cost_arr[])(struct AACEn
|
||||
|
||||
#define get_band_cost( \
|
||||
s, pb, in, scaled, size, scale_idx, cb, \
|
||||
@ -872,36 +913,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
- continue;
|
||||
- }
|
||||
- nz = 1;
|
||||
+static float find_form_factor(int group_len, int swb_size, float thresh, const float *scaled, float nzslope) {
|
||||
+ const float iswb_size = 1.0f / swb_size;
|
||||
+ const float iswb_sizem1 = 1.0f / (swb_size - 1);
|
||||
+ const float ethresh = thresh, iethresh = 1.0f / ethresh;
|
||||
+ float form = 0.0f, weight = 0.0f;
|
||||
+ int w2, i;
|
||||
+ for (w2 = 0; w2 < group_len; w2++) {
|
||||
+ float e = 0.0f, e2 = 0.0f, var = 0.0f, maxval = 0.0f;
|
||||
+ float nzl = 0;
|
||||
+ for (i = 0; i < swb_size; i+=4) {
|
||||
+ float s1 = fabsf(scaled[w2*128+i ]);
|
||||
+ float s2 = fabsf(scaled[w2*128+i+1]);
|
||||
+ float s3 = fabsf(scaled[w2*128+i+2]);
|
||||
+ float s4 = fabsf(scaled[w2*128+i+3]);
|
||||
+ maxval = FFMAX(maxval, FFMAX(FFMAX(s1, s2), FFMAX(s3, s4)));
|
||||
+ e += (s1+s2)+(s3+s4);
|
||||
+ s1 *= s1;
|
||||
+ s2 *= s2;
|
||||
+ s3 *= s3;
|
||||
+ s4 *= s4;
|
||||
+ e2 += (s1+s2)+(s3+s4);
|
||||
+ /* We really don't want a hard non-zero-line count, since
|
||||
+ * even below-threshold lines do add up towards band spectral power.
|
||||
+ * So, fall steeply towards zero, but smoothly
|
||||
+ */
|
||||
+ if (s1 >= ethresh) {
|
||||
+ nzl += 1.0f;
|
||||
+ } else {
|
||||
+ nzl += powf(s1 * iethresh, nzslope);
|
||||
}
|
||||
- }
|
||||
- uplims[w*16+g] = uplim *512;
|
||||
- sce->zeroes[w*16+g] = !nz;
|
||||
- if (nz)
|
||||
@ -914,15 +926,12 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
- if (sce->zeroes[w*16+g]) {
|
||||
- sce->sf_idx[w*16+g] = SCALE_ONE_POS;
|
||||
- continue;
|
||||
+ if (s2 >= ethresh) {
|
||||
+ nzl += 1.0f;
|
||||
+ } else {
|
||||
+ nzl += powf(s2 * iethresh, nzslope);
|
||||
}
|
||||
- }
|
||||
- sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(log2f(uplims[w*16+g]/minthr)*4,59);
|
||||
- }
|
||||
- }
|
||||
-
|
||||
+#include "libavcodec/aaccoder_twoloop.h"
|
||||
|
||||
- if (!allz)
|
||||
- return;
|
||||
- abs_pow34_v(s->scoefs, sce->coeffs, 1024);
|
||||
@ -979,11 +988,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
- prev = sce->sf_idx[w*16+g];
|
||||
- }
|
||||
- }
|
||||
+ if (s3 >= ethresh) {
|
||||
+ nzl += 1.0f;
|
||||
+ } else {
|
||||
+ nzl += powf(s3 * iethresh, nzslope);
|
||||
}
|
||||
- }
|
||||
- else {
|
||||
- for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
|
||||
- start = w*128;
|
||||
@ -1026,23 +1031,16 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
- for (i = 0; i < 128; i++)
|
||||
- if (sce->sf_idx[i] < 218 - qstep)
|
||||
- sce->sf_idx[i] += qstep;
|
||||
+ if (s4 >= ethresh) {
|
||||
+ nzl += 1.0f;
|
||||
} else {
|
||||
- } else {
|
||||
- for (i = 0; i < 128; i++)
|
||||
- if (sce->sf_idx[i] > 60 - qstep)
|
||||
- sce->sf_idx[i] -= qstep;
|
||||
+ nzl += powf(s4 * iethresh, nzslope);
|
||||
}
|
||||
- }
|
||||
- qstep >>= 1;
|
||||
- if (!qstep && tbits > destbits*1.02 && sce->sf_idx[0] < 217)
|
||||
- qstep = 1;
|
||||
- } while (qstep);
|
||||
+ }
|
||||
+ if (e2 > thresh) {
|
||||
+ float frm;
|
||||
+ e *= iswb_size;
|
||||
|
||||
-
|
||||
- fflag = 0;
|
||||
- minscaler = av_clip(minscaler, 60, 255 - SCALE_MAX_DIFF);
|
||||
- for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
|
||||
@ -1059,30 +1057,12 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
- if (sce->sf_idx[w*16+g] != prevsc)
|
||||
- fflag = 1;
|
||||
- sce->band_type[w*16+g] = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]);
|
||||
+ /** compute variance */
|
||||
+ for (i = 0; i < swb_size; i++) {
|
||||
+ float d = fabsf(scaled[w2*128+i]) - e;
|
||||
+ var += d*d;
|
||||
}
|
||||
+ var = sqrtf(var * iswb_sizem1);
|
||||
+
|
||||
+ e2 *= iswb_size;
|
||||
+ frm = e / FFMIN(e+4*var,maxval);
|
||||
+ form += e2 * sqrtf(frm) / FFMAX(0.5f,nzl);
|
||||
+ weight += e2;
|
||||
}
|
||||
- }
|
||||
- }
|
||||
- its++;
|
||||
- } while (fflag && its < 10);
|
||||
+ }
|
||||
+ if (weight > 0) {
|
||||
+ return form / weight;
|
||||
+ } else {
|
||||
+ return 1.0f;
|
||||
+ }
|
||||
}
|
||||
|
||||
+#include "libavcodec/aaccoder_twoloop.h"
|
||||
+
|
||||
-}
|
||||
-
|
||||
static void search_for_ms_mips(AACEncContext *s, ChannelElement *cpe)
|
||||
{
|
||||
int start = 0, i, w, w2, g;
|
||||
@ -1098,7 +1078,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
for (g = 0; g < sce0->ics.num_swb; g++) {
|
||||
if (!cpe->ch[0].zeroes[w*16+g] && !cpe->ch[1].zeroes[w*16+g]) {
|
||||
float dist1 = 0.0f, dist2 = 0.0f;
|
||||
@@ -2407,34 +2501,34 @@ static void search_for_ms_mips(AACEncContext *s, Chann
|
||||
@@ -2407,34 +2373,34 @@ static void search_for_ms_mips(AACEncContext *s, Chann
|
||||
S[i+3] = M[i+3]
|
||||
- sce1->coeffs[start+w2*128+i+3];
|
||||
}
|
||||
@ -1141,7 +1121,7 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
}
|
||||
cpe->ms_mask[w*16+g] = dist2 < dist1;
|
||||
}
|
||||
@@ -2444,141 +2538,24 @@ static void search_for_ms_mips(AACEncContext *s, Chann
|
||||
@@ -2444,141 +2410,24 @@ static void search_for_ms_mips(AACEncContext *s, Chann
|
||||
}
|
||||
#endif /*HAVE_MIPSFPU */
|
||||
|
||||
@ -1269,10 +1249,10 @@ avcodec/mips/aaccoder_mips: Disable ff_aac_coder_init_mips() to prevent build fa
|
||||
#endif /* HAVE_INLINE_ASM */
|
||||
|
||||
void ff_aac_coder_init_mips(AACEncContext *c) {
|
||||
-#if HAVE_INLINE_ASM
|
||||
+#if 0 // HAVE_INLINE_ASM
|
||||
#if HAVE_INLINE_ASM
|
||||
AACCoefficientsEncoder *e = c->coder;
|
||||
int option = c->options.aac_coder;
|
||||
- int option = c->options.aac_coder;
|
||||
+ int option = c->options.coder;
|
||||
|
||||
if (option == 2) {
|
||||
-// Disabled due to failure with fate-aac-pns-encode
|
||||
|
@ -1,9 +1,9 @@
|
||||
$OpenBSD: patch-libavutil_opt_c,v 1.1 2015/10/13 05:44:18 ajacoutot Exp $
|
||||
$OpenBSD: patch-libavutil_opt_c,v 1.2 2015/10/17 06:49:22 ajacoutot Exp $
|
||||
|
||||
avutil/opt: add AV_OPT_TYPE_BOOL
|
||||
|
||||
--- libavutil/opt.c.orig Mon Oct 12 22:22:56 2015
|
||||
+++ libavutil/opt.c Mon Oct 12 22:32:30 2015
|
||||
--- libavutil/opt.c.orig Mon Sep 7 21:58:02 2015
|
||||
+++ libavutil/opt.c Tue Oct 13 18:24:31 2015
|
||||
@@ -67,6 +67,7 @@ static int read_number(const AVOption *o, const void *
|
||||
case AV_OPT_TYPE_FLAGS: *intnum = *(unsigned int*)dst;return 0;
|
||||
case AV_OPT_TYPE_PIXEL_FMT: *intnum = *(enum AVPixelFormat *)dst;return 0;
|
||||
@ -102,15 +102,7 @@ avutil/opt: add AV_OPT_TYPE_BOOL
|
||||
case AV_OPT_TYPE_CONST:
|
||||
default:
|
||||
av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
|
||||
@@ -1095,6 +1142,7 @@ static void opt_list(void *obj, void *av_log_obj, cons
|
||||
|
||||
if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) {
|
||||
switch (opt->type) {
|
||||
+ case AV_OPT_TYPE_BOOL:
|
||||
case AV_OPT_TYPE_INT:
|
||||
case AV_OPT_TYPE_INT64:
|
||||
case AV_OPT_TYPE_DOUBLE:
|
||||
@@ -1121,6 +1169,9 @@ static void opt_list(void *obj, void *av_log_obj, cons
|
||||
@@ -1121,6 +1168,9 @@ static void opt_list(void *obj, void *av_log_obj, cons
|
||||
!opt->default_val.str)) {
|
||||
av_log(av_log_obj, AV_LOG_INFO, " (default ");
|
||||
switch (opt->type) {
|
||||
@ -120,6 +112,14 @@ avutil/opt: add AV_OPT_TYPE_BOOL
|
||||
case AV_OPT_TYPE_FLAGS:
|
||||
av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64);
|
||||
break;
|
||||
@@ -1196,6 +1246,7 @@ void av_opt_set_defaults2(void *s, int mask, int flags
|
||||
case AV_OPT_TYPE_CONST:
|
||||
/* Nothing to be done here */
|
||||
break;
|
||||
+ case AV_OPT_TYPE_BOOL:
|
||||
case AV_OPT_TYPE_FLAGS:
|
||||
case AV_OPT_TYPE_INT:
|
||||
case AV_OPT_TYPE_INT64:
|
||||
@@ -1554,6 +1605,7 @@ void *av_opt_ptr(const AVClass *class, void *obj, cons
|
||||
static int opt_size(enum AVOptionType type)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user