summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/ac3enc.c2
-rw-r--r--libavcodec/ac3enc.h2
-rw-r--r--libavcodec/ac3enc_fixed.c17
-rw-r--r--libavcodec/ac3enc_float.c19
-rw-r--r--libavcodec/ac3enc_opts_template.c2
-rw-r--r--libavcodec/ac3enc_template.c46
-rw-r--r--libavcodec/mpeg12.c40
-rw-r--r--libavcodec/wavpack.c9
8 files changed, 79 insertions, 58 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 5bcbd726e6..44c16073a2 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2167,7 +2167,7 @@ static av_cold int validate_options(AC3EncodeContext *s)
(s->channel_mode == AC3_CHMODE_STEREO);
s->cpl_enabled = s->options.channel_coupling &&
- s->channel_mode >= AC3_CHMODE_STEREO && !s->fixed_point;
+ s->channel_mode >= AC3_CHMODE_STEREO;
return 0;
}
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 65e88c9e01..bf5ccea19f 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -52,6 +52,7 @@
#define MAC_COEF(d,a,b) ((d)+=(a)*(b))
#define COEF_MIN (-16777215.0/16777216.0)
#define COEF_MAX ( 16777215.0/16777216.0)
+#define NEW_CPL_COORD_THRESHOLD 0.03
typedef float SampleType;
typedef float CoefType;
typedef float CoefSumType;
@@ -60,6 +61,7 @@ typedef float CoefSumType;
#define MAC_COEF(d,a,b) MAC64(d,a,b)
#define COEF_MIN -16777215
#define COEF_MAX 16777215
+#define NEW_CPL_COORD_THRESHOLD 503317
typedef int16_t SampleType;
typedef int32_t CoefType;
typedef int64_t CoefSumType;
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index c2e51552bc..0c7f81b7d3 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -29,6 +29,7 @@
#define CONFIG_FFT_FLOAT 0
#undef CONFIG_AC3ENC_FLOAT
#include "ac3enc.h"
+#include "eac3enc.h"
#define AC3ENC_TYPE AC3ENC_TYPE_AC3_FIXED
#include "ac3enc_opts_template.c"
@@ -112,6 +113,22 @@ static void clip_coefficients(DSPContext *dsp, int32_t *coef, unsigned int len)
}
+/**
+ * Calculate a single coupling coordinate.
+ */
+static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl)
+{
+ if (energy_cpl <= COEF_MAX) {
+ return 1048576;
+ } else {
+ uint64_t coord = energy_ch / (energy_cpl >> 24);
+ uint32_t coord32 = FFMIN(coord, 1073741824);
+ coord32 = ff_sqrt(coord32) << 9;
+ return FFMIN(coord32, COEF_MAX);
+ }
+}
+
+
static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx)
{
AC3EncodeContext *s = avctx->priv_data;
diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index b1d1221667..3876a8007b 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -104,9 +104,10 @@ static int normalize_samples(AC3EncodeContext *s)
static void scale_coefficients(AC3EncodeContext *s)
{
int chan_size = AC3_MAX_COEFS * s->num_blocks;
- s->ac3dsp.float_to_fixed24(s->fixed_coef_buffer + chan_size,
- s->mdct_coef_buffer + chan_size,
- chan_size * s->channels);
+ int cpl = s->cpl_on;
+ s->ac3dsp.float_to_fixed24(s->fixed_coef_buffer + (chan_size * !cpl),
+ s->mdct_coef_buffer + (chan_size * !cpl),
+ chan_size * (s->channels + cpl));
}
@@ -119,6 +120,18 @@ static void clip_coefficients(DSPContext *dsp, float *coef, unsigned int len)
}
+/**
+ * Calculate a single coupling coordinate.
+ */
+static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl)
+{
+ float coord = 0.125;
+ if (energy_cpl > 0)
+ coord *= sqrtf(energy_ch / energy_cpl);
+ return FFMIN(coord, COEF_MAX);
+}
+
+
#if CONFIG_AC3_ENCODER
AVCodec ff_ac3_encoder = {
.name = "ac3",
diff --git a/libavcodec/ac3enc_opts_template.c b/libavcodec/ac3enc_opts_template.c
index fdbbd5f743..a8bbedbf9e 100644
--- a/libavcodec/ac3enc_opts_template.c
+++ b/libavcodec/ac3enc_opts_template.c
@@ -72,11 +72,9 @@ static const AVOption eac3_options[] = {
{"hdcd", "HDCD", 0, FF_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_ADCONV_HDCD }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"},
/* Other Encoding Options */
{"stereo_rematrixing", "Stereo Rematrixing", OFFSET(stereo_rematrixing), FF_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_ON }, AC3ENC_OPT_OFF, AC3ENC_OPT_ON, AC3ENC_PARAM},
-#if AC3ENC_TYPE != AC3ENC_TYPE_AC3_FIXED
{"channel_coupling", "Channel Coupling", OFFSET(channel_coupling), FF_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_AUTO }, AC3ENC_OPT_AUTO, AC3ENC_OPT_ON, AC3ENC_PARAM, "channel_coupling"},
{"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_AUTO }, INT_MIN, INT_MAX, AC3ENC_PARAM, "channel_coupling"},
{"cpl_start_band", "Coupling Start Band", OFFSET(cpl_start), FF_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_AUTO }, AC3ENC_OPT_AUTO, 15, AC3ENC_PARAM, "cpl_start_band"},
{"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_AUTO }, INT_MIN, INT_MAX, AC3ENC_PARAM, "cpl_start_band"},
-#endif
{NULL}
};
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index dd759a732b..7e2bf3a9ca 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -41,6 +41,8 @@ static int normalize_samples(AC3EncodeContext *s);
static void clip_coefficients(DSPContext *dsp, CoefType *coef, unsigned int len);
+static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl);
+
int AC3_NAME(allocate_sample_buffers)(AC3EncodeContext *s)
{
@@ -119,31 +121,24 @@ static void apply_mdct(AC3EncodeContext *s)
/**
- * Calculate a single coupling coordinate.
- */
-static inline float calc_cpl_coord(float energy_ch, float energy_cpl)
-{
- float coord = 0.125;
- if (energy_cpl > 0)
- coord *= sqrtf(energy_ch / energy_cpl);
- return FFMIN(coord, COEF_MAX);
-}
-
-
-/**
* Calculate coupling channel and coupling coordinates.
*/
static void apply_channel_coupling(AC3EncodeContext *s)
{
+ LOCAL_ALIGNED_16(CoefType, cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]);
#if CONFIG_AC3ENC_FLOAT
- LOCAL_ALIGNED_16(float, cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]);
LOCAL_ALIGNED_16(int32_t, fixed_cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]);
+#else
+ int32_t (*fixed_cpl_coords)[AC3_MAX_CHANNELS][16] = cpl_coords;
+#endif
int blk, ch, bnd, i, j;
CoefSumType energy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}};
int cpl_start, num_cpl_coefs;
memset(cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*cpl_coords));
- memset(fixed_cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*fixed_cpl_coords));
+#if CONFIG_AC3ENC_FLOAT
+ memset(fixed_cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*cpl_coords));
+#endif
/* align start to 16-byte boundary. align length to multiple of 32.
note: coupling start bin % 4 will always be 1 */
@@ -168,10 +163,6 @@ static void apply_channel_coupling(AC3EncodeContext *s)
/* coefficients must be clipped in order to be encoded */
clip_coefficients(&s->dsp, cpl_coef, num_cpl_coefs);
-
- /* scale coupling coefficients from float to 24-bit fixed-point */
- s->ac3dsp.float_to_fixed24(&block->fixed_coef[CPL_CH][cpl_start],
- cpl_coef, num_cpl_coefs);
}
/* calculate energy in each band in coupling channel and each fbw channel */
@@ -235,11 +226,11 @@ static void apply_channel_coupling(AC3EncodeContext *s)
} else {
CoefSumType coord_diff = 0;
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
- coord_diff += fabs(cpl_coords[blk-1][ch][bnd] -
- cpl_coords[blk ][ch][bnd]);
+ coord_diff += FFABS(cpl_coords[blk-1][ch][bnd] -
+ cpl_coords[blk ][ch][bnd]);
}
coord_diff /= s->num_cpl_bands;
- if (coord_diff > 0.03)
+ if (coord_diff > NEW_CPL_COORD_THRESHOLD)
block->new_cpl_coords[ch] = 1;
}
}
@@ -286,9 +277,11 @@ static void apply_channel_coupling(AC3EncodeContext *s)
if (!block->cpl_in_use)
continue;
+#if CONFIG_AC3ENC_FLOAT
s->ac3dsp.float_to_fixed24(fixed_cpl_coords[blk][1],
cpl_coords[blk][1],
s->fbw_channels * 16);
+#endif
s->ac3dsp.extract_exponents(block->cpl_coord_exp[1],
fixed_cpl_coords[blk][1],
s->fbw_channels * 16);
@@ -332,7 +325,6 @@ static void apply_channel_coupling(AC3EncodeContext *s)
if (CONFIG_EAC3_ENCODER && s->eac3)
ff_eac3_set_cpl_states(s);
-#endif /* CONFIG_AC3ENC_FLOAT */
}
@@ -352,11 +344,6 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s)
block = &s->blocks[blk];
block->new_rematrixing_strategy = !blk;
- if (!s->rematrixing_enabled) {
- block0 = block;
- continue;
- }
-
block->num_rematrixing_bands = 4;
if (block->cpl_in_use) {
block->num_rematrixing_bands -= (s->start_freq[CPL_CH] <= 61);
@@ -366,6 +353,11 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s)
}
nb_coefs = FFMIN(block->end_freq[1], block->end_freq[2]);
+ if (!s->rematrixing_enabled) {
+ block0 = block;
+ continue;
+ }
+
for (bnd = 0; bnd < block->num_rematrixing_bands; bnd++) {
/* calculate calculate sum of squared coeffs for one band in one block */
int start = ff_ac3_rematrix_band_tab[bnd];
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 069cd000a3..bff8619cbc 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -1949,7 +1949,7 @@ static int slice_decode_thread(AVCodecContext *c, void *arg){
//ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, s->start_mb_y, s->end_mb_y, s->error_count);
if(ret < 0){
if (c->error_recognition >= FF_ER_EXPLODE)
- return AVERROR_INVALIDDATA;
+ return ret;
if(s->resync_mb_x>=0 && s->resync_mb_y>=0)
ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);
}else{
@@ -2303,10 +2303,11 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
s->slice_count= 0;
- if(avctx->extradata && !avctx->frame_number &&
- decode_chunks(avctx, picture, data_size, avctx->extradata, avctx->extradata_size) < 0 &&
- avctx->error_recognition >= FF_ER_EXPLODE)
- return AVERROR_INVALIDDATA;
+ if(avctx->extradata && !avctx->frame_number) {
+ int ret = decode_chunks(avctx, picture, data_size, avctx->extradata, avctx->extradata_size);
+ if (ret < 0 && avctx->error_recognition >= FF_ER_EXPLODE)
+ return ret;
+ }
return decode_chunks(avctx, picture, data_size, buf, buf_size);
}
@@ -2381,17 +2382,17 @@ static int decode_chunks(AVCodecContext *avctx,
s->slice_count = 0;
}
if(last_code == 0 || last_code == SLICE_MIN_START_CODE){
- if(mpeg_decode_postinit(avctx) < 0){
- av_log(avctx, AV_LOG_ERROR, "mpeg_decode_postinit() failure\n");
- return -1;
- }
+ ret = mpeg_decode_postinit(avctx);
+ if(ret < 0){
+ av_log(avctx, AV_LOG_ERROR, "mpeg_decode_postinit() failure\n");
+ return ret;
+ }
- /* we have a complete image: we try to decompress it */
- if(mpeg1_decode_picture(avctx,
- buf_ptr, input_size) < 0)
- s2->pict_type=0;
+ /* we have a complete image: we try to decompress it */
+ if (mpeg1_decode_picture(avctx, buf_ptr, input_size) < 0)
+ s2->pict_type=0;
s2->first_slice = 1;
- last_code= PICTURE_START_CODE;
+ last_code= PICTURE_START_CODE;
}else{
av_log(avctx, AV_LOG_ERROR, "ignoring pic after %X\n", last_code);
if (avctx->error_recognition >= FF_ER_EXPLODE)
@@ -2437,9 +2438,8 @@ static int decode_chunks(AVCodecContext *avctx,
break;
case GOP_START_CODE:
if(last_code == 0){
- s2->first_field=0;
- mpeg_decode_gop(avctx,
- buf_ptr, input_size);
+ s2->first_field=0;
+ mpeg_decode_gop(avctx, buf_ptr, input_size);
s->sync=1;
}else{
av_log(avctx, AV_LOG_ERROR, "ignoring GOP_START_CODE after %X\n", last_code);
@@ -2501,9 +2501,7 @@ static int decode_chunks(AVCodecContext *avctx,
}
if(!s2->current_picture_ptr){
av_log(avctx, AV_LOG_ERROR, "current_picture not initialized\n");
- if (avctx->error_recognition >= FF_ER_EXPLODE)
- return AVERROR_INVALIDDATA;
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (uses_vdpau(avctx)) {
@@ -2533,7 +2531,7 @@ static int decode_chunks(AVCodecContext *avctx,
if(ret < 0){
if (avctx->error_recognition >= FF_ER_EXPLODE)
- return AVERROR_INVALIDDATA;
+ return ret;
if(s2->resync_mb_x>=0 && s2->resync_mb_y>=0)
ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);
}else{
diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index ca52d0ac74..9da1f91d1d 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -470,6 +470,7 @@ static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
static void wv_reset_saved_context(WavpackFrameContext *s)
{
s->pos = 0;
+ s->samples_left = 0;
s->sc.crc = s->extra_sc.crc = 0xFFFFFFFF;
}
@@ -582,6 +583,7 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, vo
s->samples_left -= count;
if(!s->samples_left){
+ wv_reset_saved_context(s);
if(crc != s->CRC){
av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
return -1;
@@ -590,7 +592,6 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, vo
av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
return -1;
}
- wv_reset_saved_context(s);
}else{
s->pos = pos;
s->sc.crc = crc;
@@ -660,6 +661,7 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void
s->samples_left -= count;
if(!s->samples_left){
+ wv_reset_saved_context(s);
if(crc != s->CRC){
av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
return -1;
@@ -668,7 +670,6 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void
av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
return -1;
}
- wv_reset_saved_context(s);
}else{
s->pos = pos;
s->sc.crc = crc;
@@ -779,7 +780,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
s->samples = AV_RL32(buf); buf += 4;
if(!s->samples){
*data_size = 0;
- return buf_size;
+ return 0;
}
}else{
s->samples = wc->samples;
@@ -1195,7 +1196,7 @@ static void wavpack_decode_flush(AVCodecContext *avctx)
int i;
for (i = 0; i < s->fdec_num; i++)
- s->fdec[i]->samples_left = 0;
+ wv_reset_saved_context(s->fdec[i]);
}
AVCodec ff_wavpack_decoder = {