summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-03-03 00:09:47 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-03-03 00:23:10 +0100
commit268098d8b2a6e3dd84be788a2cd6fda10f7b3e71 (patch)
treeafd9e17a980920b66edb38331e5a608308da711d
parent689f65126be8a55e8a1e706cb56b19bb975c20ce (diff)
parent9d87374ec0f382c8394ad511243db6980afa42af (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: (29 commits) amrwb: remove duplicate arguments from extrapolate_isf(). amrwb: error out early if mode is invalid. h264: change underread for 10bit QPEL to overread. matroska: check buffer size for RM-style byte reordering. vp8: disable mmx functions with sse/sse2 counterparts on x86-64. vp8: change int stride to ptrdiff_t stride. wma: fix invalid buffer size assumptions causing random overreads. Windows Media Audio Lossless decoder rv10/20: Fix slice overflow with checked bitstream reader. h263dec: Disallow width/height changing with frame threads. rv10/20: Fix a buffer overread caused by losing track of the remaining buffer size. rmdec: Honor .RMF tag size rather than assuming 18. g722: Fix the QMF scaling r3d: don't set codec timebase. electronicarts: set timebase for tgv video. electronicarts: parse the framerate for cmv video. ogg: don't set codec timebase electronicarts: don't set codec timebase avs: don't set codec timebase wavpack: Fix an integer overflow ... Conflicts: libavcodec/arm/vp8dsp_init_arm.c libavcodec/fraps.c libavcodec/h264.c libavcodec/mpeg4videodec.c libavcodec/mpegvideo.c libavcodec/msmpeg4.c libavcodec/pnmdec.c libavcodec/qpeg.c libavcodec/rawenc.c libavcodec/ulti.c libavcodec/vcr1.c libavcodec/version.h libavcodec/wmalosslessdec.c libavformat/electronicarts.c libswscale/ppc/yuv2rgb_altivec.c tests/ref/acodec/g722 tests/ref/fate/ea-cmv Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--Changelog1
-rw-r--r--doc/general.texi1
-rw-r--r--libavcodec/Makefile12
-rw-r--r--libavcodec/a64multienc.c2
-rw-r--r--libavcodec/amrwbdec.c37
-rw-r--r--libavcodec/arm/vp8dsp_init_arm.c60
-rw-r--r--libavcodec/asv1.c2
-rw-r--r--libavcodec/avs.c4
-rw-r--r--libavcodec/bmp.c4
-rw-r--r--libavcodec/bmpenc.c6
-rw-r--r--libavcodec/cavsdec.c16
-rw-r--r--libavcodec/error_resilience.c6
-rw-r--r--libavcodec/fraps.c4
-rw-r--r--libavcodec/g722dec.c4
-rw-r--r--libavcodec/g722enc.c4
-rw-r--r--libavcodec/gif.c2
-rw-r--r--libavcodec/h261dec.c3
-rw-r--r--libavcodec/h263dec.c6
-rw-r--r--libavcodec/h264.c27
-rw-r--r--libavcodec/h264_direct.c3
-rw-r--r--libavcodec/indeo2.c4
-rw-r--r--libavcodec/jpeglsenc.c2
-rw-r--r--libavcodec/ljpegenc.c2
-rw-r--r--libavcodec/loco.c2
-rw-r--r--libavcodec/mdec.c2
-rw-r--r--libavcodec/mjpegdec.c2
-rw-r--r--libavcodec/mpeg12.c6
-rw-r--r--libavcodec/mpeg4videodec.c4
-rw-r--r--libavcodec/mpegvideo.c42
-rw-r--r--libavcodec/mpegvideo_enc.c12
-rw-r--r--libavcodec/msmpeg4.c700
-rw-r--r--libavcodec/msmpeg4.h12
-rw-r--r--libavcodec/msmpeg4data.c4
-rw-r--r--libavcodec/msmpeg4data.h4
-rw-r--r--libavcodec/msmpeg4enc.c692
-rw-r--r--libavcodec/pamenc.c2
-rw-r--r--libavcodec/pnm.c4
-rw-r--r--libavcodec/pnmdec.c4
-rw-r--r--libavcodec/pnmenc.c2
-rw-r--r--libavcodec/ppc/vp8dsp_altivec.c16
-rw-r--r--libavcodec/qdrw.c2
-rw-r--r--libavcodec/qpeg.c8
-rw-r--r--libavcodec/rawdec.c4
-rw-r--r--libavcodec/rawenc.c2
-rw-r--r--libavcodec/rv10.c38
-rw-r--r--libavcodec/rv34.c6
-rw-r--r--libavcodec/svq1dec.c2
-rw-r--r--libavcodec/svq1enc.c4
-rw-r--r--libavcodec/svq3.c6
-rw-r--r--libavcodec/targa.c8
-rw-r--r--libavcodec/tiff.c8
-rw-r--r--libavcodec/tiffenc.c2
-rw-r--r--libavcodec/truemotion2.c2
-rw-r--r--libavcodec/ulti.c2
-rw-r--r--libavcodec/utils.c6
-rw-r--r--libavcodec/vc1dec.c6
-rw-r--r--libavcodec/vcr1.c8
-rw-r--r--libavcodec/version.h2
-rw-r--r--libavcodec/vp8dsp.c44
-rw-r--r--libavcodec/vp8dsp.h45
-rw-r--r--libavcodec/wma.h2
-rw-r--r--libavcodec/wmadec.c13
-rw-r--r--libavcodec/wmalosslessdec.c982
-rw-r--r--libavcodec/wnv1.c2
-rw-r--r--libavcodec/x86/h264_qpel_10bit.asm2
-rw-r--r--libavcodec/x86/vp8dsp-init.c213
-rw-r--r--libavcodec/x86/vp8dsp.asm15
-rw-r--r--libavcodec/xl.c2
-rw-r--r--libavcodec/zmbvenc.c2
-rw-r--r--libavformat/avs.c4
-rw-r--r--libavformat/electronicarts.c22
-rw-r--r--libavformat/matroskadec.c22
-rw-r--r--libavformat/oggparseogm.c7
-rw-r--r--libavformat/oggparsetheora.c13
-rw-r--r--libavformat/r3d.c27
-rw-r--r--libavformat/rmdec.c6
-rw-r--r--libswscale/ppc/yuv2rgb_altivec.c1254
-rw-r--r--tests/ref/acodec/g7226
-rw-r--r--tests/ref/fate/g722dec-1334
-rw-r--r--tests/ref/fate/g722enc2
80 files changed, 2375 insertions, 2482 deletions
diff --git a/Changelog b/Changelog
index c1cb488ace..8741e24806 100644
--- a/Changelog
+++ b/Changelog
@@ -9,6 +9,7 @@ version next:
- ffprobe -count_packets and -count_frames options
- Sun Rasterfile Encoder
- ID3v2 attached pictures reading and writing
+- WMA Lossless decoder
version 0.10:
diff --git a/doc/general.texi b/doc/general.texi
index d9b47b0c32..b945c0b3f2 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -811,6 +811,7 @@ following image formats are supported:
@item Westwood Audio (SND1) @tab @tab X
@item Windows Media Audio 1 @tab X @tab X
@item Windows Media Audio 2 @tab X @tab X
+@item Windows Media Audio Lossless @tab @tab X
@item Windows Media Audio Pro @tab @tab X
@item Windows Media Audio Voice @tab @tab X
@end multitable
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 880e30b07e..44dafb9626 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -299,12 +299,14 @@ OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL) += vaapi_mpeg4.o
OBJS-$(CONFIG_MSMPEG4V1_DECODER) += msmpeg4.o msmpeg4data.o
OBJS-$(CONFIG_MSMPEG4V2_DECODER) += msmpeg4.o msmpeg4data.o h263dec.o \
h263.o ituh263dec.o mpeg4videodec.o
-OBJS-$(CONFIG_MSMPEG4V2_ENCODER) += msmpeg4.o msmpeg4data.o h263dec.o \
- h263.o ituh263dec.o mpeg4videodec.o
+OBJS-$(CONFIG_MSMPEG4V2_ENCODER) += msmpeg4.o msmpeg4enc.o msmpeg4data.o \
+ h263dec.o h263.o ituh263dec.o \
+ mpeg4videodec.o
OBJS-$(CONFIG_MSMPEG4V3_DECODER) += msmpeg4.o msmpeg4data.o h263dec.o \
h263.o ituh263dec.o mpeg4videodec.o
-OBJS-$(CONFIG_MSMPEG4V3_ENCODER) += msmpeg4.o msmpeg4data.o h263dec.o \
- h263.o ituh263dec.o mpeg4videodec.o
+OBJS-$(CONFIG_MSMPEG4V3_ENCODER) += msmpeg4.o msmpeg4enc.o msmpeg4data.o \
+ h263dec.o h263.o ituh263dec.o \
+ mpeg4videodec.o
OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o msrledec.o
OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o
OBJS-$(CONFIG_MSVIDEO1_ENCODER) += msvideo1enc.o elbg.o
@@ -471,7 +473,7 @@ OBJS-$(CONFIG_WMV2_DECODER) += wmv2dec.o wmv2.o \
msmpeg4.o msmpeg4data.o \
intrax8.o intrax8dsp.o
OBJS-$(CONFIG_WMV2_ENCODER) += wmv2enc.o wmv2.o \
- msmpeg4.o msmpeg4data.o \
+ msmpeg4.o msmpeg4enc.o msmpeg4data.o \
mpeg4videodec.o ituh263dec.o h263dec.o
OBJS-$(CONFIG_WNV1_DECODER) += wnv1.o
OBJS-$(CONFIG_WS_SND1_DECODER) += ws-snd1.o
diff --git a/libavcodec/a64multienc.c b/libavcodec/a64multienc.c
index 0d88f72e34..a432069d26 100644
--- a/libavcodec/a64multienc.c
+++ b/libavcodec/a64multienc.c
@@ -246,7 +246,7 @@ static int a64multi_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pict, int *got_packet)
{
A64Context *c = avctx->priv_data;
- AVFrame *const p = (AVFrame *) & c->picture;
+ AVFrame *const p = &c->picture;
int frame;
int x, y;
diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c
index 524979d755..663fd0f2e9 100644
--- a/libavcodec/amrwbdec.c
+++ b/libavcodec/amrwbdec.c
@@ -898,10 +898,10 @@ static float auto_correlation(float *diff_isf, float mean, int lag)
* Extrapolate a ISF vector to the 16kHz range (20th order LP)
* used at mode 6k60 LP filter for the high frequency band.
*
- * @param[out] out Buffer for extrapolated isf
- * @param[in] isf Input isf vector
+ * @param[out] isf Buffer for extrapolated isf; contains LP_ORDER
+ * values on input
*/
-static void extrapolate_isf(float out[LP_ORDER_16k], float isf[LP_ORDER])
+static void extrapolate_isf(float isf[LP_ORDER_16k])
{
float diff_isf[LP_ORDER - 2], diff_mean;
float *diff_hi = diff_isf - LP_ORDER + 1; // diff array for extrapolated indexes
@@ -909,8 +909,7 @@ static void extrapolate_isf(float out[LP_ORDER_16k], float isf[LP_ORDER])
float est, scale;
int i, i_max_corr;
- memcpy(out, isf, (LP_ORDER - 1) * sizeof(float));
- out[LP_ORDER_16k - 1] = isf[LP_ORDER - 1];
+ isf[LP_ORDER_16k - 1] = isf[LP_ORDER - 1];
/* Calculate the difference vector */
for (i = 0; i < LP_ORDER - 2; i++)
@@ -931,16 +930,16 @@ static void extrapolate_isf(float out[LP_ORDER_16k], float isf[LP_ORDER])
i_max_corr++;
for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++)
- out[i] = isf[i - 1] + isf[i - 1 - i_max_corr]
+ isf[i] = isf[i - 1] + isf[i - 1 - i_max_corr]
- isf[i - 2 - i_max_corr];
/* Calculate an estimate for ISF(18) and scale ISF based on the error */
- est = 7965 + (out[2] - out[3] - out[4]) / 6.0;
- scale = 0.5 * (FFMIN(est, 7600) - out[LP_ORDER - 2]) /
- (out[LP_ORDER_16k - 2] - out[LP_ORDER - 2]);
+ est = 7965 + (isf[2] - isf[3] - isf[4]) / 6.0;
+ scale = 0.5 * (FFMIN(est, 7600) - isf[LP_ORDER - 2]) /
+ (isf[LP_ORDER_16k - 2] - isf[LP_ORDER - 2]);
for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++)
- diff_hi[i] = scale * (out[i] - out[i - 1]);
+ diff_hi[i] = scale * (isf[i] - isf[i - 1]);
/* Stability insurance */
for (i = LP_ORDER; i < LP_ORDER_16k - 1; i++)
@@ -952,11 +951,11 @@ static void extrapolate_isf(float out[LP_ORDER_16k], float isf[LP_ORDER])
}
for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++)
- out[i] = out[i - 1] + diff_hi[i] * (1.0f / (1 << 15));
+ isf[i] = isf[i - 1] + diff_hi[i] * (1.0f / (1 << 15));
/* Scale the ISF vector for 16000 Hz */
for (i = 0; i < LP_ORDER_16k - 1; i++)
- out[i] *= 0.8;
+ isf[i] *= 0.8;
}
/**
@@ -1003,7 +1002,7 @@ static void hb_synthesis(AMRWBContext *ctx, int subframe, float *samples,
ff_weighted_vector_sumf(e_isf, isf_past, isf, isfp_inter[subframe],
1.0 - isfp_inter[subframe], LP_ORDER);
- extrapolate_isf(e_isf, e_isf);
+ extrapolate_isf(e_isf);
e_isf[LP_ORDER_16k - 1] *= 2.0;
ff_acelp_lsf2lspd(e_isp, e_isf, LP_ORDER_16k);
@@ -1095,23 +1094,27 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data,
buf_out = (float *)ctx->avframe.data[0];
header_size = decode_mime_header(ctx, buf);
+ if (ctx->fr_cur_mode > MODE_SID) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Invalid mode %d\n", ctx->fr_cur_mode);
+ return AVERROR_INVALIDDATA;
+ }
expected_fr_size = ((cf_sizes_wb[ctx->fr_cur_mode] + 7) >> 3) + 1;
if (buf_size < expected_fr_size) {
av_log(avctx, AV_LOG_ERROR,
"Frame too small (%d bytes). Truncated file?\n", buf_size);
*got_frame_ptr = 0;
- return buf_size;
+ return AVERROR_INVALIDDATA;
}
if (!ctx->fr_quality || ctx->fr_cur_mode > MODE_SID)
av_log(avctx, AV_LOG_ERROR, "Encountered a bad or corrupted frame\n");
- if (ctx->fr_cur_mode == MODE_SID) /* Comfort noise frame */
+ if (ctx->fr_cur_mode == MODE_SID) { /* Comfort noise frame */
av_log_missing_feature(avctx, "SID mode", 1);
-
- if (ctx->fr_cur_mode >= MODE_SID)
return -1;
+ }
ff_amr_bit_reorder((uint16_t *) &ctx->frame, sizeof(AMRWBFrame),
buf + header_size, amr_bit_orderings_by_mode[ctx->fr_cur_mode]);
diff --git a/libavcodec/arm/vp8dsp_init_arm.c b/libavcodec/arm/vp8dsp_init_arm.c
index 14021c954d..91f0dc95b4 100644
--- a/libavcodec/arm/vp8dsp_init_arm.c
+++ b/libavcodec/arm/vp8dsp_init_arm.c
@@ -23,87 +23,87 @@ void ff_vp8_luma_dc_wht_dc_armv6(DCTELEM block[4][4][16], DCTELEM dc[16]);
#define idct_funcs(opt) \
void ff_vp8_luma_dc_wht_ ## opt(DCTELEM block[4][4][16], DCTELEM dc[16]); \
-void ff_vp8_idct_add_ ## opt(uint8_t *dst, DCTELEM block[16], int stride); \
-void ff_vp8_idct_dc_add_ ## opt(uint8_t *dst, DCTELEM block[16], int stride); \
-void ff_vp8_idct_dc_add4y_ ## opt(uint8_t *dst, DCTELEM block[4][16], int stride); \
-void ff_vp8_idct_dc_add4uv_ ## opt(uint8_t *dst, DCTELEM block[4][16], int stride)
+void ff_vp8_idct_add_ ## opt(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride); \
+void ff_vp8_idct_dc_add_ ## opt(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride); \
+void ff_vp8_idct_dc_add4y_ ## opt(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride); \
+void ff_vp8_idct_dc_add4uv_ ## opt(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride)
idct_funcs(neon);
idct_funcs(armv6);
-void ff_vp8_v_loop_filter16_neon(uint8_t *dst, int stride,
+void ff_vp8_v_loop_filter16_neon(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
-void ff_vp8_h_loop_filter16_neon(uint8_t *dst, int stride,
+void ff_vp8_h_loop_filter16_neon(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
-void ff_vp8_v_loop_filter8uv_neon(uint8_t *dstU, uint8_t *dstV, int stride,
+void ff_vp8_v_loop_filter8uv_neon(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
-void ff_vp8_h_loop_filter8uv_neon(uint8_t *dstU, uint8_t *dstV, int stride,
+void ff_vp8_h_loop_filter8uv_neon(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
-void ff_vp8_v_loop_filter16_inner_neon(uint8_t *dst, int stride,
+void ff_vp8_v_loop_filter16_inner_neon(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
-void ff_vp8_h_loop_filter16_inner_neon(uint8_t *dst, int stride,
+void ff_vp8_h_loop_filter16_inner_neon(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
void ff_vp8_v_loop_filter8uv_inner_neon(uint8_t *dstU, uint8_t *dstV,
- int stride, int flim_E, int flim_I,
+ ptrdiff_t stride, int flim_E, int flim_I,
int hev_thresh);
void ff_vp8_h_loop_filter8uv_inner_neon(uint8_t *dstU, uint8_t *dstV,
- int stride, int flim_E, int flim_I,
+ ptrdiff_t stride, int flim_E, int flim_I,
int hev_thresh);
-void ff_vp8_v_loop_filter_inner_armv6(uint8_t *dst, int stride,
+void ff_vp8_v_loop_filter_inner_armv6(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I,
int hev_thresh, int count);
-void ff_vp8_h_loop_filter_inner_armv6(uint8_t *dst, int stride,
+void ff_vp8_h_loop_filter_inner_armv6(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I,
int hev_thresh, int count);
-void ff_vp8_v_loop_filter_armv6(uint8_t *dst, int stride,
+void ff_vp8_v_loop_filter_armv6(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I,
int hev_thresh, int count);
-void ff_vp8_h_loop_filter_armv6(uint8_t *dst, int stride,
+void ff_vp8_h_loop_filter_armv6(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I,
int hev_thresh, int count);
-static void ff_vp8_v_loop_filter16_armv6(uint8_t *dst, int stride,
+static void ff_vp8_v_loop_filter16_armv6(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh)
{
ff_vp8_v_loop_filter_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4);
}
-static void ff_vp8_h_loop_filter16_armv6(uint8_t *dst, int stride,
+static void ff_vp8_h_loop_filter16_armv6(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh)
{
ff_vp8_h_loop_filter_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4);
}
-static void ff_vp8_v_loop_filter8uv_armv6(uint8_t *dstU, uint8_t *dstV, int stride,
+static void ff_vp8_v_loop_filter8uv_armv6(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh)
{
ff_vp8_v_loop_filter_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2);
ff_vp8_v_loop_filter_armv6(dstV, stride, flim_E, flim_I, hev_thresh, 2);
}
-static void ff_vp8_h_loop_filter8uv_armv6(uint8_t *dstU, uint8_t *dstV, int stride,
+static void ff_vp8_h_loop_filter8uv_armv6(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh)
{
ff_vp8_h_loop_filter_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2);
ff_vp8_h_loop_filter_armv6(dstV, stride, flim_E, flim_I, hev_thresh, 2);
}
-static void ff_vp8_v_loop_filter16_inner_armv6(uint8_t *dst, int stride,
+static void ff_vp8_v_loop_filter16_inner_armv6(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh)
{
ff_vp8_v_loop_filter_inner_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4);
}
-static void ff_vp8_h_loop_filter16_inner_armv6(uint8_t *dst, int stride,
+static void ff_vp8_h_loop_filter16_inner_armv6(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh)
{
ff_vp8_h_loop_filter_inner_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4);
}
static void ff_vp8_v_loop_filter8uv_inner_armv6(uint8_t *dstU, uint8_t *dstV,
- int stride, int flim_E, int flim_I,
+ ptrdiff_t stride, int flim_E, int flim_I,
int hev_thresh)
{
ff_vp8_v_loop_filter_inner_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2);
@@ -111,7 +111,7 @@ static void ff_vp8_v_loop_filter8uv_inner_armv6(uint8_t *dstU, uint8_t *dstV,
}
static void ff_vp8_h_loop_filter8uv_inner_armv6(uint8_t *dstU, uint8_t *dstV,
- int stride, int flim_E, int flim_I,
+ ptrdiff_t stride, int flim_E, int flim_I,
int hev_thresh)
{
ff_vp8_h_loop_filter_inner_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2);
@@ -119,16 +119,16 @@ static void ff_vp8_h_loop_filter8uv_inner_armv6(uint8_t *dstU, uint8_t *dstV,
}
#define simple_lf_funcs(opt) \
-void ff_vp8_v_loop_filter16_simple_ ## opt(uint8_t *dst, int stride, int flim); \
-void ff_vp8_h_loop_filter16_simple_ ## opt(uint8_t *dst, int stride, int flim)
+void ff_vp8_v_loop_filter16_simple_ ## opt(uint8_t *dst, ptrdiff_t stride, int flim); \
+void ff_vp8_h_loop_filter16_simple_ ## opt(uint8_t *dst, ptrdiff_t stride, int flim)
simple_lf_funcs(neon);
simple_lf_funcs(armv6);
-#define VP8_MC_OPT(n, opt) \
- void ff_put_vp8_##n##_##opt(uint8_t *dst, int dststride, \
- uint8_t *src, int srcstride, \
- int h, int x, int y)
+#define VP8_MC(n) \
+ void ff_put_vp8_##n##_neon(uint8_t *dst, ptrdiff_t dststride, \
+ uint8_t *src, ptrdiff_t srcstride, \
+ int h, int x, int y)
#define VP8_MC(n) \
VP8_MC_OPT(n, neon)
diff --git a/libavcodec/asv1.c b/libavcodec/asv1.c
index 4bcc8d72b1..c123125d46 100644
--- a/libavcodec/asv1.c
+++ b/libavcodec/asv1.c
@@ -454,7 +454,7 @@ static int decode_frame(AVCodecContext *avctx,
}
}
- *picture= *(AVFrame*)&a->picture;
+ *picture = a->picture;
*data_size = sizeof(AVPicture);
emms_c();
diff --git a/libavcodec/avs.c b/libavcodec/avs.c
index 05cb815fd8..4dcbb27fe0 100644
--- a/libavcodec/avs.c
+++ b/libavcodec/avs.c
@@ -51,7 +51,7 @@ avs_decode_frame(AVCodecContext * avctx,
int buf_size = avpkt->size;
AvsContext *const avs = avctx->priv_data;
AVFrame *picture = data;
- AVFrame *const p = (AVFrame *) & avs->picture;
+ AVFrame *const p = &avs->picture;
const uint8_t *table, *vect;
uint8_t *out;
int i, j, x, y, stride, vect_w = 3, vect_h = 3;
@@ -151,7 +151,7 @@ avs_decode_frame(AVCodecContext * avctx,
align_get_bits(&change_map);
}
- *picture = *(AVFrame *) & avs->picture;
+ *picture = avs->picture;
*data_size = sizeof(AVPicture);
return buf_size;
diff --git a/libavcodec/bmp.c b/libavcodec/bmp.c
index b7853d1093..b249f312d4 100644
--- a/libavcodec/bmp.c
+++ b/libavcodec/bmp.c
@@ -27,8 +27,8 @@
static av_cold int bmp_decode_init(AVCodecContext *avctx){
BMPContext *s = avctx->priv_data;
- avcodec_get_frame_defaults((AVFrame*)&s->picture);
- avctx->coded_frame = (AVFrame*)&s->picture;
+ avcodec_get_frame_defaults(&s->picture);
+ avctx->coded_frame = &s->picture;
return 0;
}
diff --git a/libavcodec/bmpenc.c b/libavcodec/bmpenc.c
index 4455af7d8c..1c40b13add 100644
--- a/libavcodec/bmpenc.c
+++ b/libavcodec/bmpenc.c
@@ -34,8 +34,8 @@ static const uint32_t rgb444_masks[] = { 0x0F00, 0x00F0, 0x000F };
static av_cold int bmp_encode_init(AVCodecContext *avctx){
BMPContext *s = avctx->priv_data;
- avcodec_get_frame_defaults((AVFrame*)&s->picture);
- avctx->coded_frame = (AVFrame*)&s->picture;
+ avcodec_get_frame_defaults(&s->picture);
+ avctx->coded_frame = &s->picture;
switch (avctx->pix_fmt) {
case PIX_FMT_BGRA:
@@ -72,7 +72,7 @@ static int bmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pict, int *got_packet)
{
BMPContext *s = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&s->picture;
+ AVFrame * const p = &s->picture;
int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize, ret;
const uint32_t *pal = NULL;
uint32_t palette256[256];
diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index fb0ec841ce..b06bd53c00 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -501,9 +501,9 @@ static int decode_pic(AVSContext *h) {
}
/* release last B frame */
if(h->picture.f.data[0])
- s->avctx->release_buffer(s->avctx, (AVFrame *)&h->picture);
+ s->avctx->release_buffer(s->avctx, &h->picture.f);
- s->avctx->get_buffer(s->avctx, (AVFrame *)&h->picture);
+ s->avctx->get_buffer(s->avctx, &h->picture.f);
ff_cavs_init_pic(h);
h->picture.poc = get_bits(&s->gb,8)*2;
@@ -592,7 +592,7 @@ static int decode_pic(AVSContext *h) {
}
if(h->pic_type != AV_PICTURE_TYPE_B) {
if(h->DPB[1].f.data[0])
- s->avctx->release_buffer(s->avctx, (AVFrame *)&h->DPB[1]);
+ s->avctx->release_buffer(s->avctx, &h->DPB[1].f);
h->DPB[1] = h->DPB[0];
h->DPB[0] = h->picture;
memset(&h->picture,0,sizeof(Picture));
@@ -656,7 +656,7 @@ static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
if (buf_size == 0) {
if (!s->low_delay && h->DPB[0].f.data[0]) {
*data_size = sizeof(AVPicture);
- *picture = *(AVFrame *) &h->DPB[0];
+ *picture = h->DPB[0].f;
}
return 0;
}
@@ -676,9 +676,9 @@ static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
case PIC_I_START_CODE:
if(!h->got_keyframe) {
if(h->DPB[0].f.data[0])
- avctx->release_buffer(avctx, (AVFrame *)&h->DPB[0]);
+ avctx->release_buffer(avctx, &h->DPB[0].f);
if(h->DPB[1].f.data[0])
- avctx->release_buffer(avctx, (AVFrame *)&h->DPB[1]);
+ avctx->release_buffer(avctx, &h->DPB[1].f);
h->got_keyframe = 1;
}
case PIC_PB_START_CODE:
@@ -692,12 +692,12 @@ static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
*data_size = sizeof(AVPicture);
if(h->pic_type != AV_PICTURE_TYPE_B) {
if(h->DPB[1].f.data[0]) {
- *picture = *(AVFrame *) &h->DPB[1];
+ *picture = h->DPB[1].f;
} else {
*data_size = 0;
}
} else
- *picture = *(AVFrame *) &h->picture;
+ *picture = h->picture.f;
break;
case EXT_START_CODE:
//mpeg_decode_extension(avctx,buf_ptr, input_size);
diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index 2391e57f90..1c1420f93c 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -613,7 +613,7 @@ skip_mean_and_median:
if (s->avctx->codec_id == CODEC_ID_H264) {
// FIXME
} else {
- ff_thread_await_progress((AVFrame *) s->last_picture_ptr,
+ ff_thread_await_progress(&s->last_picture_ptr->f,
mb_y, 0);
}
if (!s->last_picture.f.motion_val[0] ||
@@ -786,7 +786,7 @@ static int is_intra_more_likely(MpegEncContext *s)
if (s->avctx->codec_id == CODEC_ID_H264) {
// FIXME
} else {
- ff_thread_await_progress((AVFrame *) s->last_picture_ptr,
+ ff_thread_await_progress(&s->last_picture_ptr->f,
mb_y, 0);
}
is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr , s->linesize, 16);
@@ -1170,7 +1170,7 @@ void ff_er_frame_end(MpegEncContext *s)
if (s->avctx->codec_id == CODEC_ID_H264) {
// FIXME
} else {
- ff_thread_await_progress((AVFrame *) s->next_picture_ptr, mb_y, 0);
+ ff_thread_await_progress(&s->next_picture_ptr->f, mb_y, 0);
}
s->mv[0][0][0] = s->next_picture.f.motion_val[0][xy][0] * time_pb / time_pp;
s->mv[0][0][1] = s->next_picture.f.motion_val[0][xy][1] * time_pb / time_pp;
diff --git a/libavcodec/fraps.c b/libavcodec/fraps.c
index 45d95c9c24..e8c0b18b5d 100644
--- a/libavcodec/fraps.c
+++ b/libavcodec/fraps.c
@@ -62,7 +62,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
FrapsContext * const s = avctx->priv_data;
avcodec_get_frame_defaults(&s->frame);
- avctx->coded_frame = (AVFrame*)&s->frame;
+ avctx->coded_frame = &s->frame;
s->avctx = avctx;
s->tmpbuf = NULL;
@@ -132,7 +132,7 @@ static int decode_frame(AVCodecContext *avctx,
int buf_size = avpkt->size;
FrapsContext * const s = avctx->priv_data;
AVFrame *frame = data;
- AVFrame * const f = (AVFrame*)&s->frame;
+ AVFrame * const f = &s->frame;
uint32_t header;
unsigned int version,header_size;
unsigned int x, y;
diff --git a/libavcodec/g722dec.c b/libavcodec/g722dec.c
index 50a224ba10..72bb0ef3c7 100644
--- a/libavcodec/g722dec.c
+++ b/libavcodec/g722dec.c
@@ -126,8 +126,8 @@ static int g722_decode_frame(AVCodecContext *avctx, void *data,
c->prev_samples[c->prev_samples_pos++] = rlow - rhigh;
ff_g722_apply_qmf(c->prev_samples + c->prev_samples_pos - 24,
&xout1, &xout2);
- *out_buf++ = av_clip_int16(xout1 >> 12);
- *out_buf++ = av_clip_int16(xout2 >> 12);
+ *out_buf++ = av_clip_int16(xout1 >> 11);
+ *out_buf++ = av_clip_int16(xout2 >> 11);
if (c->prev_samples_pos >= PREV_SAMPLES_BUF_SIZE) {
memmove(c->prev_samples, c->prev_samples + c->prev_samples_pos - 22,
22 * sizeof(c->prev_samples[0]));
diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index a5ae0a5153..ba8ceeff86 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -136,8 +136,8 @@ static inline void filter_samples(G722Context *c, const int16_t *samples,
c->prev_samples[c->prev_samples_pos++] = samples[0];
c->prev_samples[c->prev_samples_pos++] = samples[1];
ff_g722_apply_qmf(c->prev_samples + c->prev_samples_pos - 24, &xout1, &xout2);
- *xlow = xout1 + xout2 >> 13;
- *xhigh = xout1 - xout2 >> 13;
+ *xlow = xout1 + xout2 >> 14;
+ *xhigh = xout1 - xout2 >> 14;
if (c->prev_samples_pos >= PREV_SAMPLES_BUF_SIZE) {
memmove(c->prev_samples,
c->prev_samples + c->prev_samples_pos - 22,
diff --git a/libavcodec/gif.c b/libavcodec/gif.c
index 875c5b15dc..2ae63865d2 100644
--- a/libavcodec/gif.c
+++ b/libavcodec/gif.c
@@ -160,7 +160,7 @@ static int gif_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pict, int *got_packet)
{
GIFContext *s = avctx->priv_data;
- AVFrame *const p = (AVFrame *)&s->picture;
+ AVFrame *const p = &s->picture;
uint8_t *outbuf_ptr, *end;
int ret;
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 68e3212a19..e97c76dab4 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -628,7 +628,8 @@ retry:
assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);
assert(s->current_picture.f.pict_type == s->pict_type);
- *pict= *(AVFrame*)s->current_picture_ptr;
+
+ *pict = s->current_picture_ptr->f;
ff_print_debug_info(s, pict);
*data_size = sizeof(AVFrame);
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index ac2aeaf424..b5b6d8c863 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -357,7 +357,7 @@ uint64_t time= rdtsc();
if (buf_size == 0) {
/* special case for last picture */
if (s->low_delay==0 && s->next_picture_ptr) {
- *pict= *(AVFrame*)s->next_picture_ptr;
+ *pict = s->next_picture_ptr->f;
s->next_picture_ptr= NULL;
*data_size = sizeof(AVFrame);
@@ -727,9 +727,9 @@ intrax8_decoded:
assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);
assert(s->current_picture.f.pict_type == s->pict_type);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
- *pict= *(AVFrame*)s->current_picture_ptr;
+ *pict = s->current_picture_ptr->f;
} else if (s->last_picture_ptr != NULL) {
- *pict= *(AVFrame*)s->last_picture_ptr;
+ *pict = s->last_picture_ptr->f;
}
if(s->last_picture_ptr || s->low_delay){
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 20daa2e0a8..caf4b8ae5f 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -367,14 +367,14 @@ static void await_references(H264Context *h){
nrefs[list]--;
if(!FIELD_PICTURE && ref_field_picture){ // frame referencing two fields
- ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) - !(row&1), pic_height-1), 1);
- ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) , pic_height-1), 0);
+ ff_thread_await_progress(&ref_pic->f, FFMIN((row >> 1) - !(row & 1), pic_height - 1), 1);
+ ff_thread_await_progress(&ref_pic->f, FFMIN((row >> 1), pic_height - 1), 0);
}else if(FIELD_PICTURE && !ref_field_picture){ // field referencing one field of a frame
- ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row*2 + ref_field , pic_height-1), 0);
+ ff_thread_await_progress(&ref_pic->f, FFMIN(row * 2 + ref_field, pic_height - 1), 0);
}else if(FIELD_PICTURE){
- ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), ref_field);
+ ff_thread_await_progress(&ref_pic->f, FFMIN(row, pic_height - 1), ref_field);
}else{
- ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), 0);
+ ff_thread_await_progress(&ref_pic->f, FFMIN(row, pic_height - 1), 0);
}
}
}
@@ -2507,8 +2507,9 @@ static int field_end(H264Context *h, int in_setup){
s->mb_y= 0;
if (!in_setup && !s->dropable)
- ff_thread_report_progress((AVFrame*)s->current_picture_ptr, (16*s->mb_height >> FIELD_PICTURE) - 1,
- s->picture_structure==PICT_BOTTOM_FIELD);
+ ff_thread_report_progress(&s->current_picture_ptr->f,
+ (16 * s->mb_height >> FIELD_PICTURE) - 1,
+ s->picture_structure == PICT_BOTTOM_FIELD);
if (CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
ff_vdpau_h264_set_reference_frames(s);
@@ -2906,8 +2907,8 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
h->prev_frame_num++;
h->prev_frame_num %= 1<<h->sps.log2_max_frame_num;
s->current_picture_ptr->frame_num= h->prev_frame_num;
- ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 0);
- ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 1);
+ ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 0);
+ ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 1);
ff_generate_sliding_window_mmcos(h);
if (ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index) < 0 &&
(s->avctx->err_recognition & AV_EF_EXPLODE))
@@ -3577,8 +3578,8 @@ static void decode_finish_row(H264Context *h){
if (s->dropable) return;
- ff_thread_report_progress((AVFrame*)s->current_picture_ptr, top + height - 1,
- s->picture_structure==PICT_BOTTOM_FIELD);
+ ff_thread_report_progress(&s->current_picture_ptr->f, top + height - 1,
+ s->picture_structure == PICT_BOTTOM_FIELD);
}
static int decode_slice(struct AVCodecContext *avctx, void *arg){
@@ -4067,7 +4068,7 @@ static int decode_frame(AVCodecContext *avctx,
if(out){
*data_size = sizeof(AVFrame);
- *pict= *(AVFrame*)out;
+ *pict = out->f;
}
return buf_index;
@@ -4121,7 +4122,7 @@ not_extra:
*data_size = 0; /* Wait for second field. */
if (h->next_output_pic && (h->next_output_pic->sync || h->sync>1)) {
*data_size = sizeof(AVFrame);
- *pict = *(AVFrame*)h->next_output_pic;
+ *pict = h->next_output_pic->f;
}
}
diff --git a/libavcodec/h264_direct.c b/libavcodec/h264_direct.c
index 079c665509..263832d829 100644
--- a/libavcodec/h264_direct.c
+++ b/libavcodec/h264_direct.c
@@ -154,7 +154,8 @@ static void await_reference_mb_row(H264Context * const h, Picture *ref, int mb_y
//FIXME it can be safe to access mb stuff
//even if pixels aren't deblocked yet
- ff_thread_await_progress((AVFrame*)ref, FFMIN(16*mb_y >> ref_field_picture, ref_height-1),
+ ff_thread_await_progress(&ref->f,
+ FFMIN(16 * mb_y >> ref_field_picture, ref_height - 1),
ref_field_picture && ref_field);
}
diff --git a/libavcodec/indeo2.c b/libavcodec/indeo2.c
index eb58939338..ec5a86ad76 100644
--- a/libavcodec/indeo2.c
+++ b/libavcodec/indeo2.c
@@ -143,7 +143,7 @@ static int ir2_decode_frame(AVCodecContext *avctx,
int buf_size = avpkt->size;
Ir2Context * const s = avctx->priv_data;
AVFrame *picture = data;
- AVFrame * const p= (AVFrame*)&s->picture;
+ AVFrame * const p = &s->picture;
int start;
p->reference = 3;
@@ -188,7 +188,7 @@ static int ir2_decode_frame(AVCodecContext *avctx,
s->picture.data[1], s->picture.linesize[1], ir2_luma_table);
}
- *picture= *(AVFrame*)&s->picture;
+ *picture = s->picture;
*data_size = sizeof(AVPicture);
return buf_size;
diff --git a/libavcodec/jpeglsenc.c b/libavcodec/jpeglsenc.c
index d5135adb30..62a2328a0a 100644
--- a/libavcodec/jpeglsenc.c
+++ b/libavcodec/jpeglsenc.c
@@ -232,7 +232,7 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pict, int *got_packet)
{
JpeglsContext * const s = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&s->picture;
+ AVFrame * const p = &s->picture;
const int near = avctx->prediction_method;
PutBitContext pb, pb2;
GetBitContext gb;
diff --git a/libavcodec/ljpegenc.c b/libavcodec/ljpegenc.c
index 00d34ecc9c..b5b443e7cc 100644
--- a/libavcodec/ljpegenc.c
+++ b/libavcodec/ljpegenc.c
@@ -45,7 +45,7 @@ static int encode_picture_lossless(AVCodecContext *avctx, AVPacket *pkt,
MJpegContext * const m = s->mjpeg_ctx;
const int width= s->width;
const int height= s->height;
- AVFrame * const p= (AVFrame*)&s->current_picture;
+ AVFrame * const p = &s->current_picture.f;
const int predictor= avctx->prediction_method+1;
const int mb_width = (width + s->mjpeg_hsample[0] - 1) / s->mjpeg_hsample[0];
const int mb_height = (height + s->mjpeg_vsample[0] - 1) / s->mjpeg_vsample[0];
diff --git a/libavcodec/loco.c b/libavcodec/loco.c
index 75701e970b..eaf7e81cd4 100644
--- a/libavcodec/loco.c
+++ b/libavcodec/loco.c
@@ -166,7 +166,7 @@ static int decode_frame(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
LOCOContext * const l = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&l->pic;
+ AVFrame * const p = &l->pic;
int decoded;
if(p->data[0])
diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index 9a417ee45b..03361c7c79 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -243,7 +243,7 @@ static av_cold int decode_init(AVCodecContext *avctx){
static av_cold int decode_init_thread_copy(AVCodecContext *avctx){
MDECContext * const a = avctx->priv_data;
- AVFrame *p = (AVFrame*)&a->picture;
+ AVFrame *p = &a->picture;
avctx->coded_frame= p;
a->avctx= avctx;
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 0a9d03061f..c5db0f1d41 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -1577,7 +1577,7 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
goto the_end;
} else if (unescaped_buf_size > (1U<<29)) {
av_log(avctx, AV_LOG_ERROR, "MJPEG packet 0x%x too big (0x%x/0x%x), corrupt data?\n",
- start_code, unescaped_buf_ptr, buf_size);
+ start_code, unescaped_buf_size, buf_size);
return AVERROR_INVALIDDATA;
} else {
av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%td\n",
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index a4e4661d18..5c5e09ec2d 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -1952,7 +1952,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
ff_MPV_frame_end(s);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
- *pict = *(AVFrame*)s->current_picture_ptr;
+ *pict = s->current_picture_ptr->f;
ff_print_debug_info(s, pict);
} else {
if (avctx->active_thread_type & FF_THREAD_FRAME)
@@ -1960,7 +1960,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
/* latency of 1 frame for I- and P-frames */
/* XXX: use another variable than picture_number */
if (s->last_picture_ptr != NULL) {
- *pict = *(AVFrame*)s->last_picture_ptr;
+ *pict = s->last_picture_ptr->f;
ff_print_debug_info(s, pict);
}
}
@@ -2256,7 +2256,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) {
/* special case for last picture */
if (s2->low_delay == 0 && s2->next_picture_ptr) {
- *picture = *(AVFrame*)s2->next_picture_ptr;
+ *picture = s2->next_picture_ptr->f;
s2->next_picture_ptr = NULL;
*data_size = sizeof(AVFrame);
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index a12ad99348..c87af8216e 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -1313,7 +1313,7 @@ static int mpeg4_decode_mb(MpegEncContext *s,
s->last_mv[i][1][1]= 0;
}
- ff_thread_await_progress((AVFrame*)s->next_picture_ptr, s->mb_y, 0);
+ ff_thread_await_progress(&s->next_picture_ptr->f, s->mb_y, 0);
}
/* if we skipped it in the future P Frame than skip it now too */
@@ -1500,7 +1500,7 @@ end:
if(s->pict_type==AV_PICTURE_TYPE_B){
const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
- ff_thread_await_progress((AVFrame*)s->next_picture_ptr,
+ ff_thread_await_progress(&s->next_picture_ptr->f,
(s->mb_x + delta >= s->mb_width) ? FFMIN(s->mb_y+1, s->mb_height-1) : s->mb_y, 0);
if (s->next_picture.f.mbskip_table[xy + delta])
return SLICE_OK;
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index efe4cae762..9577c9d38f 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -232,9 +232,9 @@ static void free_frame_buffer(MpegEncContext *s, Picture *pic)
* dimensions; ignore user defined callbacks for these
*/
if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
- ff_thread_release_buffer(s->avctx, (AVFrame *) pic);
+ ff_thread_release_buffer(s->avctx, &pic->f);
else
- avcodec_default_release_buffer(s->avctx, (AVFrame *) pic);
+ avcodec_default_release_buffer(s->avctx, &pic->f);
av_freep(&pic->f.hwaccel_picture_private);
}
@@ -257,9 +257,9 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
}
if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
- r = ff_thread_get_buffer(s->avctx, (AVFrame *) pic);
+ r = ff_thread_get_buffer(s->avctx, &pic->f);
else
- r = avcodec_default_get_buffer(s->avctx, (AVFrame *) pic);
+ r = avcodec_default_get_buffer(s->avctx, &pic->f);
if (r < 0 || !pic->f.type || !pic->f.data[0]) {
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %p)\n",
@@ -729,7 +729,7 @@ av_cold int ff_MPV_common_init(MpegEncContext *s)
s->codec_tag = avpriv_toupper4(s->avctx->codec_tag);
s->stream_codec_tag = avpriv_toupper4(s->avctx->stream_codec_tag);
- s->avctx->coded_frame = (AVFrame*)&s->current_picture;
+ s->avctx->coded_frame = &s->current_picture.f;
FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num + 1) * sizeof(int), fail); // error ressilience code looks cleaner with this
for (y = 0; y < s->mb_height; y++)
@@ -781,7 +781,7 @@ av_cold int ff_MPV_common_init(MpegEncContext *s)
FF_ALLOCZ_OR_GOTO(s->avctx, s->picture,
s->picture_count * sizeof(Picture), fail);
for (i = 0; i < s->picture_count; i++) {
- avcodec_get_frame_defaults((AVFrame *) &s->picture[i]);
+ avcodec_get_frame_defaults(&s->picture[i].f);
}
FF_ALLOCZ_OR_GOTO(s->avctx, s->error_status_table, mb_array_size*sizeof(uint8_t), fail)
@@ -1247,10 +1247,8 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
memset(s->last_picture_ptr->f.data[0] + s->last_picture_ptr->f.linesize[0]*i, 16, avctx->width);
}
- ff_thread_report_progress((AVFrame *) s->last_picture_ptr,
- INT_MAX, 0);
- ff_thread_report_progress((AVFrame *) s->last_picture_ptr,
- INT_MAX, 1);
+ ff_thread_report_progress(&s->last_picture_ptr->f, INT_MAX, 0);
+ ff_thread_report_progress(&s->last_picture_ptr->f, INT_MAX, 1);
}
if ((s->next_picture_ptr == NULL ||
s->next_picture_ptr->f.data[0] == NULL) &&
@@ -1263,10 +1261,8 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
s->next_picture_ptr->f.key_frame = 0;
if (ff_alloc_picture(s, s->next_picture_ptr, 0) < 0)
return -1;
- ff_thread_report_progress((AVFrame *) s->next_picture_ptr,
- INT_MAX, 0);
- ff_thread_report_progress((AVFrame *) s->next_picture_ptr,
- INT_MAX, 1);
+ ff_thread_report_progress(&s->next_picture_ptr->f, INT_MAX, 0);
+ ff_thread_report_progress(&s->next_picture_ptr->f, INT_MAX, 1);
}
}
@@ -1391,10 +1387,10 @@ void ff_MPV_frame_end(MpegEncContext *s)
memset(&s->next_picture, 0, sizeof(Picture));
memset(&s->current_picture, 0, sizeof(Picture));
#endif
- s->avctx->coded_frame = (AVFrame *) s->current_picture_ptr;
+ s->avctx->coded_frame = &s->current_picture_ptr->f;
if (s->codec_id != CODEC_ID_H264 && s->current_picture.f.reference) {
- ff_thread_report_progress((AVFrame *) s->current_picture_ptr,
+ ff_thread_report_progress(&s->current_picture_ptr->f,
s->mb_height - 1, 0);
}
}
@@ -2346,10 +2342,14 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
if(HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) {
if (s->mv_dir & MV_DIR_FORWARD) {
- ff_thread_await_progress((AVFrame*)s->last_picture_ptr, ff_MPV_lowest_referenced_row(s, 0), 0);
+ ff_thread_await_progress(&s->last_picture_ptr->f,
+ ff_MPV_lowest_referenced_row(s, 0),
+ 0);
}
if (s->mv_dir & MV_DIR_BACKWARD) {
- ff_thread_await_progress((AVFrame*)s->next_picture_ptr, ff_MPV_lowest_referenced_row(s, 1), 0);
+ ff_thread_await_progress(&s->next_picture_ptr->f,
+ ff_MPV_lowest_referenced_row(s, 1),
+ 0);
}
}
@@ -2556,9 +2556,9 @@ void ff_draw_horiz_band(MpegEncContext *s, int y, int h){
int i;
if(s->pict_type==AV_PICTURE_TYPE_B || s->low_delay || (s->avctx->slice_flags&SLICE_FLAG_CODED_ORDER))
- src= (AVFrame*)s->current_picture_ptr;
+ src = &s->current_picture_ptr->f;
else if(s->last_picture_ptr)
- src= (AVFrame*)s->last_picture_ptr;
+ src = &s->last_picture_ptr->f;
else
return;
@@ -2867,5 +2867,5 @@ void ff_set_qscale(MpegEncContext * s, int qscale)
void ff_MPV_report_decode_progress(MpegEncContext *s)
{
if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->error_occurred)
- ff_thread_report_progress((AVFrame*)s->current_picture_ptr, s->mb_y, 0);
+ ff_thread_report_progress(&s->current_picture_ptr->f, s->mb_y, 0);
}
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index af57644626..9c7b889b97 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -981,7 +981,7 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg)
if (i < 0)
return i;
- pic = (AVFrame *) &s->picture[i];
+ pic = &s->picture[i].f;
pic->reference = 3;
for (i = 0; i < 4; i++) {
@@ -996,7 +996,7 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg)
if (i < 0)
return i;
- pic = (AVFrame *) &s->picture[i];
+ pic = &s->picture[i].f;
pic->reference = 3;
if (ff_alloc_picture(s, (Picture *) pic, 0) < 0) {
@@ -1252,7 +1252,7 @@ static int select_input_picture(MpegEncContext *s)
s->input_picture[0]->f.type == FF_BUFFER_TYPE_INTERNAL);
s->avctx->release_buffer(s->avctx,
- (AVFrame *) s->input_picture[0]);
+ &s->input_picture[0]->f);
}
emms_c();
@@ -1385,13 +1385,13 @@ no_output_pic:
/* mark us unused / free shared pic */
if (s->reordered_input_picture[0]->f.type == FF_BUFFER_TYPE_INTERNAL)
s->avctx->release_buffer(s->avctx,
- (AVFrame *) s->reordered_input_picture[0]);
+ &s->reordered_input_picture[0]->f);
for (i = 0; i < 4; i++)
s->reordered_input_picture[0]->f.data[i] = NULL;
s->reordered_input_picture[0]->f.type = 0;
- copy_picture_attributes(s, (AVFrame *) pic,
- (AVFrame *) s->reordered_input_picture[0]);
+ copy_picture_attributes(s, &pic->f,
+ &s->reordered_input_picture[0]->f);
s->current_picture_ptr = pic;
} else {
diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c
index 232b82b219..b182da1f90 100644
--- a/libavcodec/msmpeg4.c
+++ b/libavcodec/msmpeg4.c
@@ -34,6 +34,7 @@
#include "libavutil/x86_cpu.h"
#include "h263.h"
#include "mpeg4video.h"
+#include "msmpeg4data.h"
#include "vc1data.h"
/*
@@ -52,22 +53,8 @@
#define V2_MV_VLC_BITS 9
#define TEX_VLC_BITS 9
-#define II_BITRATE 128*1024
-#define MBAC_BITRATE 50*1024
-
#define DEFAULT_INTER_INDEX 3
-static uint32_t v2_dc_lum_table[512][2];
-static uint32_t v2_dc_chroma_table[512][2];
-
-#include "msmpeg4data.h"
-
-#if CONFIG_ENCODERS //strangely gcc includes this even if it is not referenced
-static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
-#endif //CONFIG_ENCODERS
-
-static uint8_t static_rl_table_store[NB_RL_TABLES][2][2*MAX_RUN + MAX_LEVEL + 3];
-
/* This table is practically identical to the one from h263
* except that it is inverted. */
static av_cold void init_h263_dc_for_msmpeg4(void)
@@ -102,8 +89,8 @@ static av_cold void init_h263_dc_for_msmpeg4(void)
uni_len++;
}
}
- v2_dc_lum_table[level+256][0]= uni_code;
- v2_dc_lum_table[level+256][1]= uni_len;
+ ff_v2_dc_lum_table[level + 256][0] = uni_code;
+ ff_v2_dc_lum_table[level + 256][1] = uni_len;
/* chrominance h263 */
uni_code= ff_mpeg4_DCtab_chrom[size][0];
@@ -118,13 +105,13 @@ static av_cold void init_h263_dc_for_msmpeg4(void)
uni_len++;
}
}
- v2_dc_chroma_table[level+256][0]= uni_code;
- v2_dc_chroma_table[level+256][1]= uni_len;
+ ff_v2_dc_chroma_table[level + 256][0] = uni_code;
+ ff_v2_dc_chroma_table[level + 256][1] = uni_len;
}
}
-static av_cold void common_init(MpegEncContext * s)
+av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
{
static int initialized=0;
@@ -173,251 +160,6 @@ static av_cold void common_init(MpegEncContext * s)
}
}
-#if CONFIG_ENCODERS
-
-/* build the table which associate a (x,y) motion vector to a vlc */
-static void init_mv_table(MVTable *tab)
-{
- int i, x, y;
-
- tab->table_mv_index = av_malloc(sizeof(uint16_t) * 4096);
- /* mark all entries as not used */
- for(i=0;i<4096;i++)
- tab->table_mv_index[i] = tab->n;
-
- for(i=0;i<tab->n;i++) {
- x = tab->table_mvx[i];
- y = tab->table_mvy[i];
- tab->table_mv_index[(x << 6) | y] = i;
- }
-}
-
-void ff_msmpeg4_code012(PutBitContext *pb, int n)
-{
- if (n == 0) {
- put_bits(pb, 1, 0);
- } else {
- put_bits(pb, 1, 1);
- put_bits(pb, 1, (n >= 2));
- }
-}
-
-static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){
- int size=0;
- int code;
- int run_diff= intra ? 0 : 1;
-
- code = get_rl_index(rl, last, run, level);
- size+= rl->table_vlc[code][1];
- if (code == rl->n) {
- int level1, run1;
-
- level1 = level - rl->max_level[last][run];
- if (level1 < 1)
- goto esc2;
- code = get_rl_index(rl, last, run, level1);
- if (code == rl->n) {
- esc2:
- size++;
- if (level > MAX_LEVEL)
- goto esc3;
- run1 = run - rl->max_run[last][level] - run_diff;
- if (run1 < 0)
- goto esc3;
- code = get_rl_index(rl, last, run1, level);
- if (code == rl->n) {
- esc3:
- /* third escape */
- size+=1+1+6+8;
- } else {
- /* second escape */
- size+= 1+1+ rl->table_vlc[code][1];
- }
- } else {
- /* first escape */
- size+= 1+1+ rl->table_vlc[code][1];
- }
- } else {
- size++;
- }
- return size;
-}
-
-av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
-{
- static int init_done=0;
- int i;
-
- common_init(s);
- if(s->msmpeg4_version>=4){
- s->min_qcoeff= -255;
- s->max_qcoeff= 255;
- }
-
- if (!init_done) {
- /* init various encoding tables */
- init_done = 1;
- init_mv_table(&ff_mv_tables[0]);
- init_mv_table(&ff_mv_tables[1]);
- for(i=0;i<NB_RL_TABLES;i++)
- ff_init_rl(&ff_rl_table[i], static_rl_table_store[i]);
-
- for(i=0; i<NB_RL_TABLES; i++){
- int level;
- for (level = 1; level <= MAX_LEVEL; level++) {
- int run;
- for(run=0; run<=MAX_RUN; run++){
- int last;
- for(last=0; last<2; last++){
- rl_length[i][level][run][last]= get_size_of_code(s, &ff_rl_table[ i], last, run, level, 0);
- }
- }
- }
- }
- }
-}
-
-static void find_best_tables(MpegEncContext * s)
-{
- int i;
- int best = 0, best_size = INT_MAX;
- int chroma_best = 0, best_chroma_size = INT_MAX;
-
- for(i=0; i<3; i++){
- int level;
- int chroma_size=0;
- int size=0;
-
- if(i>0){// ;)
- size++;
- chroma_size++;
- }
- for(level=0; level<=MAX_LEVEL; level++){
- int run;
- for(run=0; run<=MAX_RUN; run++){
- int last;
- const int last_size= size + chroma_size;
- for(last=0; last<2; last++){
- int inter_count = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];
- int intra_luma_count = s->ac_stats[1][0][level][run][last];
- int intra_chroma_count= s->ac_stats[1][1][level][run][last];
-
- if(s->pict_type==AV_PICTURE_TYPE_I){
- size += intra_luma_count *rl_length[i ][level][run][last];
- chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];
- }else{
- size+= intra_luma_count *rl_length[i ][level][run][last]
- +intra_chroma_count*rl_length[i+3][level][run][last]
- +inter_count *rl_length[i+3][level][run][last];
- }
- }
- if(last_size == size+chroma_size) break;
- }
- }
- if(size<best_size){
- best_size= size;
- best= i;
- }
- if(chroma_size<best_chroma_size){
- best_chroma_size= chroma_size;
- chroma_best= i;
- }
- }
-
-// printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n",
-// s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size);
-
- if(s->pict_type==AV_PICTURE_TYPE_P) chroma_best= best;
-
- memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);
-
- s->rl_table_index = best;
- s->rl_chroma_table_index= chroma_best;
-
- if(s->pict_type != s->last_non_b_pict_type){
- s->rl_table_index= 2;
- if(s->pict_type==AV_PICTURE_TYPE_I)
- s->rl_chroma_table_index= 1;
- else
- s->rl_chroma_table_index= 2;
- }
-
-}
-
-/* write MSMPEG4 compatible frame header */
-void ff_msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
-{
- find_best_tables(s);
-
- avpriv_align_put_bits(&s->pb);
- put_bits(&s->pb, 2, s->pict_type - 1);
-
- put_bits(&s->pb, 5, s->qscale);
- if(s->msmpeg4_version<=2){
- s->rl_table_index = 2;
- s->rl_chroma_table_index = 2;
- }
-
- s->dc_table_index = 1;
- s->mv_table_index = 1; /* only if P frame */
- s->use_skip_mb_code = 1; /* only if P frame */
- s->per_mb_rl_table = 0;
- if(s->msmpeg4_version==4)
- s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==AV_PICTURE_TYPE_P);
-//printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height);
-
- if (s->pict_type == AV_PICTURE_TYPE_I) {
- s->slice_height= s->mb_height/1;
- put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height);
-
- if(s->msmpeg4_version==4){
- ff_msmpeg4_encode_ext_header(s);
- if(s->bit_rate>MBAC_BITRATE)
- put_bits(&s->pb, 1, s->per_mb_rl_table);
- }
-
- if(s->msmpeg4_version>2){
- if(!s->per_mb_rl_table){
- ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index);
- ff_msmpeg4_code012(&s->pb, s->rl_table_index);
- }
-
- put_bits(&s->pb, 1, s->dc_table_index);
- }
- } else {
- put_bits(&s->pb, 1, s->use_skip_mb_code);
-
- if(s->msmpeg4_version==4 && s->bit_rate>MBAC_BITRATE)
- put_bits(&s->pb, 1, s->per_mb_rl_table);
-
- if(s->msmpeg4_version>2){
- if(!s->per_mb_rl_table)
- ff_msmpeg4_code012(&s->pb, s->rl_table_index);
-
- put_bits(&s->pb, 1, s->dc_table_index);
-
- put_bits(&s->pb, 1, s->mv_table_index);
- }
- }
-
- s->esc3_level_length= 0;
- s->esc3_run_length= 0;
-}
-
-void ff_msmpeg4_encode_ext_header(MpegEncContext * s)
-{
- put_bits(&s->pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29
-
- put_bits(&s->pb, 11, FFMIN(s->bit_rate/1024, 2047));
-
- if(s->msmpeg4_version>=3)
- put_bits(&s->pb, 1, s->flipflop_rounding);
- else
- assert(s->flipflop_rounding==0);
-}
-
-#endif //CONFIG_ENCODERS
-
/* predict coded block */
int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr)
{
@@ -445,217 +187,6 @@ int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block
return pred;
}
-#if CONFIG_ENCODERS
-
-void ff_msmpeg4_encode_motion(MpegEncContext * s,
- int mx, int my)
-{
- int code;
- MVTable *mv;
-
- /* modulo encoding */
- /* WARNING : you cannot reach all the MVs even with the modulo
- encoding. This is a somewhat strange compromise they took !!! */
- if (mx <= -64)
- mx += 64;
- else if (mx >= 64)
- mx -= 64;
- if (my <= -64)
- my += 64;
- else if (my >= 64)
- my -= 64;
-
- mx += 32;
- my += 32;
-#if 0
- if ((unsigned)mx >= 64 ||
- (unsigned)my >= 64)
- av_log(s->avctx, AV_LOG_ERROR, "error mx=%d my=%d\n", mx, my);
-#endif
- mv = &ff_mv_tables[s->mv_table_index];
-
- code = mv->table_mv_index[(mx << 6) | my];
- put_bits(&s->pb,
- mv->table_mv_bits[code],
- mv->table_mv_code[code]);
- if (code == mv->n) {
- /* escape : code literally */
- put_bits(&s->pb, 6, mx);
- put_bits(&s->pb, 6, my);
- }
-}
-
-void ff_msmpeg4_handle_slices(MpegEncContext *s){
- if (s->mb_x == 0) {
- if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
- if(s->msmpeg4_version < 4){
- ff_mpeg4_clean_buffers(s);
- }
- s->first_slice_line = 1;
- } else {
- s->first_slice_line = 0;
- }
- }
-}
-
-static void msmpeg4v2_encode_motion(MpegEncContext * s, int val)
-{
- int range, bit_size, sign, code, bits;
-
- if (val == 0) {
- /* zero vector */
- code = 0;
- put_bits(&s->pb, ff_mvtab[code][1], ff_mvtab[code][0]);
- } else {
- bit_size = s->f_code - 1;
- range = 1 << bit_size;
- if (val <= -64)
- val += 64;
- else if (val >= 64)
- val -= 64;
-
- if (val >= 0) {
- sign = 0;
- } else {
- val = -val;
- sign = 1;
- }
- val--;
- code = (val >> bit_size) + 1;
- bits = val & (range - 1);
-
- put_bits(&s->pb, ff_mvtab[code][1] + 1, (ff_mvtab[code][0] << 1) | sign);
- if (bit_size > 0) {
- put_bits(&s->pb, bit_size, bits);
- }
- }
-}
-
-void ff_msmpeg4_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- int motion_x, int motion_y)
-{
- int cbp, coded_cbp, i;
- int pred_x, pred_y;
- uint8_t *coded_block;
-
- ff_msmpeg4_handle_slices(s);
-
- if (!s->mb_intra) {
- /* compute cbp */
- cbp = 0;
- for (i = 0; i < 6; i++) {
- if (s->block_last_index[i] >= 0)
- cbp |= 1 << (5 - i);
- }
- if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
- /* skip macroblock */
- put_bits(&s->pb, 1, 1);
- s->last_bits++;
- s->misc_bits++;
- s->skip_count++;
-
- return;
- }
- if (s->use_skip_mb_code)
- put_bits(&s->pb, 1, 0); /* mb coded */
-
- if(s->msmpeg4_version<=2){
- put_bits(&s->pb,
- ff_v2_mb_type[cbp&3][1],
- ff_v2_mb_type[cbp&3][0]);
- if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
- else coded_cbp= cbp;
-
- put_bits(&s->pb,
- ff_h263_cbpy_tab[coded_cbp>>2][1],
- ff_h263_cbpy_tab[coded_cbp>>2][0]);
-
- s->misc_bits += get_bits_diff(s);
-
- ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
- msmpeg4v2_encode_motion(s, motion_x - pred_x);
- msmpeg4v2_encode_motion(s, motion_y - pred_y);
- }else{
- put_bits(&s->pb,
- ff_table_mb_non_intra[cbp + 64][1],
- ff_table_mb_non_intra[cbp + 64][0]);
-
- s->misc_bits += get_bits_diff(s);
-
- /* motion vector */
- ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
- ff_msmpeg4_encode_motion(s, motion_x - pred_x,
- motion_y - pred_y);
- }
-
- s->mv_bits += get_bits_diff(s);
-
- for (i = 0; i < 6; i++) {
- ff_msmpeg4_encode_block(s, block[i], i);
- }
- s->p_tex_bits += get_bits_diff(s);
- } else {
- /* compute cbp */
- cbp = 0;
- coded_cbp = 0;
- for (i = 0; i < 6; i++) {
- int val, pred;
- val = (s->block_last_index[i] >= 1);
- cbp |= val << (5 - i);
- if (i < 4) {
- /* predict value for close blocks only for luma */
- pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
- *coded_block = val;
- val = val ^ pred;
- }
- coded_cbp |= val << (5 - i);
- }
-
- if(s->msmpeg4_version<=2){
- if (s->pict_type == AV_PICTURE_TYPE_I) {
- put_bits(&s->pb,
- ff_v2_intra_cbpc[cbp&3][1], ff_v2_intra_cbpc[cbp&3][0]);
- } else {
- if (s->use_skip_mb_code)
- put_bits(&s->pb, 1, 0); /* mb coded */
- put_bits(&s->pb,
- ff_v2_mb_type[(cbp&3) + 4][1],
- ff_v2_mb_type[(cbp&3) + 4][0]);
- }
- put_bits(&s->pb, 1, 0); /* no AC prediction yet */
- put_bits(&s->pb,
- ff_h263_cbpy_tab[cbp>>2][1],
- ff_h263_cbpy_tab[cbp>>2][0]);
- }else{
- if (s->pict_type == AV_PICTURE_TYPE_I) {
- put_bits(&s->pb,
- ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
- } else {
- if (s->use_skip_mb_code)
- put_bits(&s->pb, 1, 0); /* mb coded */
- put_bits(&s->pb,
- ff_table_mb_non_intra[cbp][1],
- ff_table_mb_non_intra[cbp][0]);
- }
- put_bits(&s->pb, 1, 0); /* no AC prediction yet */
- if(s->inter_intra_pred){
- s->h263_aic_dir=0;
- put_bits(&s->pb, ff_table_inter_intra[s->h263_aic_dir][1], ff_table_inter_intra[s->h263_aic_dir][0]);
- }
- }
- s->misc_bits += get_bits_diff(s);
-
- for (i = 0; i < 6; i++) {
- ff_msmpeg4_encode_block(s, block[i], i);
- }
- s->i_tex_bits += get_bits_diff(s);
- s->i_count++;
- }
-}
-
-#endif //CONFIG_ENCODERS
-
static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
int32_t **dc_val_ptr)
{
@@ -685,8 +216,8 @@ static int get_dc(uint8_t *src, int stride, int scale)
}
/* dir = 0: left, dir = 1: top prediction */
-static inline int msmpeg4_pred_dc(MpegEncContext * s, int n,
- int16_t **dc_val_ptr, int *dir_ptr)
+int ff_msmpeg4_pred_dc(MpegEncContext *s, int n,
+ int16_t **dc_val_ptr, int *dir_ptr)
{
int a, b, c, wrap, pred, scale;
int16_t *dc_val;
@@ -832,207 +363,6 @@ static inline int msmpeg4_pred_dc(MpegEncContext * s, int n,
return pred;
}
-#define DC_MAX 119
-
-static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
-{
- int sign, code;
- int pred, extquant;
- int extrabits = 0;
-
- int16_t *dc_val;
- pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
-
- /* update predictor */
- if (n < 4) {
- *dc_val = level * s->y_dc_scale;
- } else {
- *dc_val = level * s->c_dc_scale;
- }
-
- /* do the prediction */
- level -= pred;
-
- if(s->msmpeg4_version<=2){
- if (n < 4) {
- put_bits(&s->pb,
- v2_dc_lum_table[level+256][1],
- v2_dc_lum_table[level+256][0]);
- }else{
- put_bits(&s->pb,
- v2_dc_chroma_table[level+256][1],
- v2_dc_chroma_table[level+256][0]);
- }
- }else{
- sign = 0;
- if (level < 0) {
- level = -level;
- sign = 1;
- }
- code = level;
- if (code > DC_MAX)
- code = DC_MAX;
- else if( s->msmpeg4_version>=6 ) {
- if( s->qscale == 1 ) {
- extquant = (level + 3) & 0x3;
- code = ((level+3)>>2);
- } else if( s->qscale == 2 ) {
- extquant = (level + 1) & 0x1;
- code = ((level+1)>>1);
- }
- }
-
- if (s->dc_table_index == 0) {
- if (n < 4) {
- put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]);
- } else {
- put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]);
- }
- } else {
- if (n < 4) {
- put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]);
- } else {
- put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]);
- }
- }
-
- if(s->msmpeg4_version>=6 && s->qscale<=2)
- extrabits = 3 - s->qscale;
-
- if (code == DC_MAX)
- put_bits(&s->pb, 8 + extrabits, level);
- else if(extrabits > 0)//== VC1 && s->qscale<=2
- put_bits(&s->pb, extrabits, extquant);
-
- if (level != 0) {
- put_bits(&s->pb, 1, sign);
- }
- }
-}
-
-/* Encoding of a block. Very similar to MPEG4 except for a different
- escape coding (same as H263) and more vlc tables.
- */
-void ff_msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n)
-{
- int level, run, last, i, j, last_index;
- int last_non_zero, sign, slevel;
- int code, run_diff, dc_pred_dir;
- const RLTable *rl;
- const uint8_t *scantable;
-
- if (s->mb_intra) {
- msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
- i = 1;
- if (n < 4) {
- rl = &ff_rl_table[s->rl_table_index];
- } else {
- rl = &ff_rl_table[3 + s->rl_chroma_table_index];
- }
- run_diff = s->msmpeg4_version>=4;
- scantable= s->intra_scantable.permutated;
- } else {
- i = 0;
- rl = &ff_rl_table[3 + s->rl_table_index];
- if(s->msmpeg4_version<=2)
- run_diff = 0;
- else
- run_diff = 1;
- scantable= s->inter_scantable.permutated;
- }
-
- /* recalculate block_last_index for M$ wmv1 */
- if(s->msmpeg4_version>=4 && s->msmpeg4_version<6 && s->block_last_index[n]>0){
- for(last_index=63; last_index>=0; last_index--){
- if(block[scantable[last_index]]) break;
- }
- s->block_last_index[n]= last_index;
- }else
- last_index = s->block_last_index[n];
- /* AC coefs */
- last_non_zero = i - 1;
- for (; i <= last_index; i++) {
- j = scantable[i];
- level = block[j];
- if (level) {
- run = i - last_non_zero - 1;
- last = (i == last_index);
- sign = 0;
- slevel = level;
- if (level < 0) {
- sign = 1;
- level = -level;
- }
-
- if(level<=MAX_LEVEL && run<=MAX_RUN){
- s->ac_stats[s->mb_intra][n>3][level][run][last]++;
- }
-
- s->ac_stats[s->mb_intra][n > 3][40][63][0]++; //esc3 like
-
- code = get_rl_index(rl, last, run, level);
- put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- if (code == rl->n) {
- int level1, run1;
-
- level1 = level - rl->max_level[last][run];
- if (level1 < 1)
- goto esc2;
- code = get_rl_index(rl, last, run, level1);
- if (code == rl->n) {
- esc2:
- put_bits(&s->pb, 1, 0);
- if (level > MAX_LEVEL)
- goto esc3;
- run1 = run - rl->max_run[last][level] - run_diff;
- if (run1 < 0)
- goto esc3;
- code = get_rl_index(rl, last, run1+1, level);
- if (s->msmpeg4_version == 4 && code == rl->n)
- goto esc3;
- code = get_rl_index(rl, last, run1, level);
- if (code == rl->n) {
- esc3:
- /* third escape */
- put_bits(&s->pb, 1, 0);
- put_bits(&s->pb, 1, last);
- if(s->msmpeg4_version>=4){
- if(s->esc3_level_length==0){
- s->esc3_level_length=8;
- s->esc3_run_length= 6;
- //ESCLVLSZ + ESCRUNSZ
- if(s->qscale<8)
- put_bits(&s->pb, 6 + (s->msmpeg4_version>=6), 3);
- else
- put_bits(&s->pb, 8, 3);
- }
- put_bits(&s->pb, s->esc3_run_length, run);
- put_bits(&s->pb, 1, sign);
- put_bits(&s->pb, s->esc3_level_length, level);
- }else{
- put_bits(&s->pb, 6, run);
- put_sbits(&s->pb, 8, slevel);
- }
- } else {
- /* second escape */
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- put_bits(&s->pb, 1, sign);
- }
- } else {
- /* first escape */
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- put_bits(&s->pb, 1, sign);
- }
- } else {
- put_bits(&s->pb, 1, sign);
- }
- last_non_zero = i;
- }
- }
-}
-
/****************************************/
/* decoding stuff */
@@ -1263,13 +593,13 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
if (ff_h263_decode_init(avctx) < 0)
return -1;
- common_init(s);
+ ff_msmpeg4_common_init(s);
if (!done) {
done = 1;
for(i=0;i<NB_RL_TABLES;i++) {
- ff_init_rl(&ff_rl_table[i], static_rl_table_store[i]);
+ ff_init_rl(&ff_rl_table[i], ff_static_rl_table_store[i]);
}
INIT_VLC_RL(ff_rl_table[0], 642);
INIT_VLC_RL(ff_rl_table[1], 1104);
@@ -1301,11 +631,11 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
&ff_table1_dc_chroma[0][0], 8, 4, 1216);
INIT_VLC_STATIC(&v2_dc_lum_vlc, DC_VLC_BITS, 512,
- &v2_dc_lum_table[0][1], 8, 4,
- &v2_dc_lum_table[0][0], 8, 4, 1472);
+ &ff_v2_dc_lum_table[0][1], 8, 4,
+ &ff_v2_dc_lum_table[0][0], 8, 4, 1472);
INIT_VLC_STATIC(&v2_dc_chroma_vlc, DC_VLC_BITS, 512,
- &v2_dc_chroma_table[0][1], 8, 4,
- &v2_dc_chroma_table[0][0], 8, 4, 1506);
+ &ff_v2_dc_chroma_table[0][1], 8, 4,
+ &ff_v2_dc_chroma_table[0][0], 8, 4, 1506);
INIT_VLC_STATIC(&v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 4,
&ff_v2_intra_cbpc[0][1], 2, 1,
@@ -1588,7 +918,7 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
*dc_val= level;
}else{
int16_t *dc_val;
- pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
+ pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
level += pred;
/* update predictor */
diff --git a/libavcodec/msmpeg4.h b/libavcodec/msmpeg4.h
index 463c72fa49..abc414cfdd 100644
--- a/libavcodec/msmpeg4.h
+++ b/libavcodec/msmpeg4.h
@@ -22,19 +22,29 @@
#ifndef AVCODEC_MSMPEG4_H
#define AVCODEC_MSMPEG4_H
+#include <stdint.h>
+
#include "config.h"
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
+#include "msmpeg4data.h"
+#include "put_bits.h"
#define INTER_INTRA_VLC_BITS 3
#define MB_NON_INTRA_VLC_BITS 9
#define MB_INTRA_VLC_BITS 9
+#define II_BITRATE 128*1024
+#define MBAC_BITRATE 50*1024
+
+#define DC_MAX 119
+
extern VLC ff_mb_non_intra_vlc[4];
extern VLC ff_inter_intra_vlc;
void ff_msmpeg4_code012(PutBitContext *pb, int n);
+void ff_msmpeg4_common_init(MpegEncContext *s);
void ff_msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n);
void ff_msmpeg4_handle_slices(MpegEncContext *s);
void ff_msmpeg4_encode_motion(MpegEncContext * s, int mx, int my);
@@ -43,6 +53,8 @@ int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n,
int ff_msmpeg4_decode_motion(MpegEncContext * s, int *mx_ptr, int *my_ptr);
int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
int n, int coded, const uint8_t *scan_table);
+int ff_msmpeg4_pred_dc(MpegEncContext *s, int n,
+ int16_t **dc_val_ptr, int *dir_ptr);
int ff_wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
#define CONFIG_MSMPEG4_DECODER (CONFIG_MSMPEG4V1_DECODER || \
diff --git a/libavcodec/msmpeg4data.c b/libavcodec/msmpeg4data.c
index 266ea2ec5d..50ba18c8cc 100644
--- a/libavcodec/msmpeg4data.c
+++ b/libavcodec/msmpeg4data.c
@@ -29,6 +29,10 @@
#include "msmpeg4data.h"
+uint32_t ff_v2_dc_lum_table[512][2];
+uint32_t ff_v2_dc_chroma_table[512][2];
+uint8_t ff_static_rl_table_store[NB_RL_TABLES][2][2 * MAX_RUN + MAX_LEVEL + 3];
+
VLC ff_msmp4_mb_i_vlc;
VLC ff_msmp4_dc_luma_vlc[2];
VLC ff_msmp4_dc_chroma_vlc[2];
diff --git a/libavcodec/msmpeg4data.h b/libavcodec/msmpeg4data.h
index c32c09e241..24a10d9f2e 100644
--- a/libavcodec/msmpeg4data.h
+++ b/libavcodec/msmpeg4data.h
@@ -59,6 +59,10 @@ extern const uint8_t ff_wmv1_scantable[WMV1_SCANTABLE_COUNT][64];
#define NB_RL_TABLES 6
extern RLTable ff_rl_table[NB_RL_TABLES];
+extern uint8_t ff_static_rl_table_store[NB_RL_TABLES][2][2 * MAX_RUN + MAX_LEVEL + 3];
+
+extern uint32_t ff_v2_dc_lum_table[512][2];
+extern uint32_t ff_v2_dc_chroma_table[512][2];
extern const uint8_t ff_wmv1_y_dc_scale_table[32];
extern const uint8_t ff_wmv1_c_dc_scale_table[32];
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
new file mode 100644
index 0000000000..527d2840e1
--- /dev/null
+++ b/libavcodec/msmpeg4enc.c
@@ -0,0 +1,692 @@
+/*
+ * MSMPEG4 encoder backend
+ * Copyright (c) 2001 Fabrice Bellard
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
+ *
+ * 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
+ * MSMPEG4 encoder backend
+ */
+
+#include <stdint.h>
+#include <string.h>
+
+#include "libavutil/avutil.h"
+#include "libavutil/mem.h"
+#include "mpegvideo.h"
+#include "msmpeg4.h"
+#include "h263.h"
+#include "mpeg4video.h"
+#include "msmpeg4.h"
+#include "msmpeg4data.h"
+#include "put_bits.h"
+#include "rl.h"
+#include "vc1data.h"
+
+static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
+
+/* build the table which associate a (x,y) motion vector to a vlc */
+static void init_mv_table(MVTable *tab)
+{
+ int i, x, y;
+
+ tab->table_mv_index = av_malloc(sizeof(uint16_t) * 4096);
+ /* mark all entries as not used */
+ for(i=0;i<4096;i++)
+ tab->table_mv_index[i] = tab->n;
+
+ for(i=0;i<tab->n;i++) {
+ x = tab->table_mvx[i];
+ y = tab->table_mvy[i];
+ tab->table_mv_index[(x << 6) | y] = i;
+ }
+}
+
+void ff_msmpeg4_code012(PutBitContext *pb, int n)
+{
+ if (n == 0) {
+ put_bits(pb, 1, 0);
+ } else {
+ put_bits(pb, 1, 1);
+ put_bits(pb, 1, (n >= 2));
+ }
+}
+
+static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){
+ int size=0;
+ int code;
+ int run_diff= intra ? 0 : 1;
+
+ code = get_rl_index(rl, last, run, level);
+ size+= rl->table_vlc[code][1];
+ if (code == rl->n) {
+ int level1, run1;
+
+ level1 = level - rl->max_level[last][run];
+ if (level1 < 1)
+ goto esc2;
+ code = get_rl_index(rl, last, run, level1);
+ if (code == rl->n) {
+ esc2:
+ size++;
+ if (level > MAX_LEVEL)
+ goto esc3;
+ run1 = run - rl->max_run[last][level] - run_diff;
+ if (run1 < 0)
+ goto esc3;
+ code = get_rl_index(rl, last, run1, level);
+ if (code == rl->n) {
+ esc3:
+ /* third escape */
+ size+=1+1+6+8;
+ } else {
+ /* second escape */
+ size+= 1+1+ rl->table_vlc[code][1];
+ }
+ } else {
+ /* first escape */
+ size+= 1+1+ rl->table_vlc[code][1];
+ }
+ } else {
+ size++;
+ }
+ return size;
+}
+
+av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
+{
+ static int init_done=0;
+ int i;
+
+ ff_msmpeg4_common_init(s);
+ if(s->msmpeg4_version>=4){
+ s->min_qcoeff= -255;
+ s->max_qcoeff= 255;
+ }
+
+ if (!init_done) {
+ /* init various encoding tables */
+ init_done = 1;
+ init_mv_table(&ff_mv_tables[0]);
+ init_mv_table(&ff_mv_tables[1]);
+ for(i=0;i<NB_RL_TABLES;i++)
+ ff_init_rl(&ff_rl_table[i], ff_static_rl_table_store[i]);
+
+ for(i=0; i<NB_RL_TABLES; i++){
+ int level;
+ for (level = 1; level <= MAX_LEVEL; level++) {
+ int run;
+ for(run=0; run<=MAX_RUN; run++){
+ int last;
+ for(last=0; last<2; last++){
+ rl_length[i][level][run][last]= get_size_of_code(s, &ff_rl_table[ i], last, run, level, 0);
+ }
+ }
+ }
+ }
+ }
+}
+
+static void find_best_tables(MpegEncContext * s)
+{
+ int i;
+ int best = 0, best_size = INT_MAX;
+ int chroma_best = 0, best_chroma_size = INT_MAX;
+
+ for(i=0; i<3; i++){
+ int level;
+ int chroma_size=0;
+ int size=0;
+
+ if(i>0){// ;)
+ size++;
+ chroma_size++;
+ }
+ for(level=0; level<=MAX_LEVEL; level++){
+ int run;
+ for(run=0; run<=MAX_RUN; run++){
+ int last;
+ const int last_size= size + chroma_size;
+ for(last=0; last<2; last++){
+ int inter_count = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];
+ int intra_luma_count = s->ac_stats[1][0][level][run][last];
+ int intra_chroma_count= s->ac_stats[1][1][level][run][last];
+
+ if(s->pict_type==AV_PICTURE_TYPE_I){
+ size += intra_luma_count *rl_length[i ][level][run][last];
+ chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];
+ }else{
+ size+= intra_luma_count *rl_length[i ][level][run][last]
+ +intra_chroma_count*rl_length[i+3][level][run][last]
+ +inter_count *rl_length[i+3][level][run][last];
+ }
+ }
+ if(last_size == size+chroma_size) break;
+ }
+ }
+ if(size<best_size){
+ best_size= size;
+ best= i;
+ }
+ if(chroma_size<best_chroma_size){
+ best_chroma_size= chroma_size;
+ chroma_best= i;
+ }
+ }
+
+// printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n",
+// s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size);
+
+ if(s->pict_type==AV_PICTURE_TYPE_P) chroma_best= best;
+
+ memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);
+
+ s->rl_table_index = best;
+ s->rl_chroma_table_index= chroma_best;
+
+ if(s->pict_type != s->last_non_b_pict_type){
+ s->rl_table_index= 2;
+ if(s->pict_type==AV_PICTURE_TYPE_I)
+ s->rl_chroma_table_index= 1;
+ else
+ s->rl_chroma_table_index= 2;
+ }
+
+}
+
+/* write MSMPEG4 compatible frame header */
+void ff_msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
+{
+ find_best_tables(s);
+
+ avpriv_align_put_bits(&s->pb);
+ put_bits(&s->pb, 2, s->pict_type - 1);
+
+ put_bits(&s->pb, 5, s->qscale);
+ if(s->msmpeg4_version<=2){
+ s->rl_table_index = 2;
+ s->rl_chroma_table_index = 2;
+ }
+
+ s->dc_table_index = 1;
+ s->mv_table_index = 1; /* only if P frame */
+ s->use_skip_mb_code = 1; /* only if P frame */
+ s->per_mb_rl_table = 0;
+ if(s->msmpeg4_version==4)
+ s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==AV_PICTURE_TYPE_P);
+//printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height);
+
+ if (s->pict_type == AV_PICTURE_TYPE_I) {
+ s->slice_height= s->mb_height/1;
+ put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height);
+
+ if(s->msmpeg4_version==4){
+ ff_msmpeg4_encode_ext_header(s);
+ if(s->bit_rate>MBAC_BITRATE)
+ put_bits(&s->pb, 1, s->per_mb_rl_table);
+ }
+
+ if(s->msmpeg4_version>2){
+ if(!s->per_mb_rl_table){
+ ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index);
+ ff_msmpeg4_code012(&s->pb, s->rl_table_index);
+ }
+
+ put_bits(&s->pb, 1, s->dc_table_index);
+ }
+ } else {
+ put_bits(&s->pb, 1, s->use_skip_mb_code);
+
+ if(s->msmpeg4_version==4 && s->bit_rate>MBAC_BITRATE)
+ put_bits(&s->pb, 1, s->per_mb_rl_table);
+
+ if(s->msmpeg4_version>2){
+ if(!s->per_mb_rl_table)
+ ff_msmpeg4_code012(&s->pb, s->rl_table_index);
+
+ put_bits(&s->pb, 1, s->dc_table_index);
+
+ put_bits(&s->pb, 1, s->mv_table_index);
+ }
+ }
+
+ s->esc3_level_length= 0;
+ s->esc3_run_length= 0;
+}
+
+void ff_msmpeg4_encode_ext_header(MpegEncContext * s)
+{
+ put_bits(&s->pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29
+
+ put_bits(&s->pb, 11, FFMIN(s->bit_rate/1024, 2047));
+
+ if(s->msmpeg4_version>=3)
+ put_bits(&s->pb, 1, s->flipflop_rounding);
+ else
+ assert(s->flipflop_rounding==0);
+}
+
+void ff_msmpeg4_encode_motion(MpegEncContext * s,
+ int mx, int my)
+{
+ int code;
+ MVTable *mv;
+
+ /* modulo encoding */
+ /* WARNING : you cannot reach all the MVs even with the modulo
+ encoding. This is a somewhat strange compromise they took !!! */
+ if (mx <= -64)
+ mx += 64;
+ else if (mx >= 64)
+ mx -= 64;
+ if (my <= -64)
+ my += 64;
+ else if (my >= 64)
+ my -= 64;
+
+ mx += 32;
+ my += 32;
+#if 0
+ if ((unsigned)mx >= 64 ||
+ (unsigned)my >= 64)
+ av_log(s->avctx, AV_LOG_ERROR, "error mx=%d my=%d\n", mx, my);
+#endif
+ mv = &ff_mv_tables[s->mv_table_index];
+
+ code = mv->table_mv_index[(mx << 6) | my];
+ put_bits(&s->pb,
+ mv->table_mv_bits[code],
+ mv->table_mv_code[code]);
+ if (code == mv->n) {
+ /* escape : code literally */
+ put_bits(&s->pb, 6, mx);
+ put_bits(&s->pb, 6, my);
+ }
+}
+
+void ff_msmpeg4_handle_slices(MpegEncContext *s){
+ if (s->mb_x == 0) {
+ if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
+ if(s->msmpeg4_version < 4){
+ ff_mpeg4_clean_buffers(s);
+ }
+ s->first_slice_line = 1;
+ } else {
+ s->first_slice_line = 0;
+ }
+ }
+}
+
+static void msmpeg4v2_encode_motion(MpegEncContext * s, int val)
+{
+ int range, bit_size, sign, code, bits;
+
+ if (val == 0) {
+ /* zero vector */
+ code = 0;
+ put_bits(&s->pb, ff_mvtab[code][1], ff_mvtab[code][0]);
+ } else {
+ bit_size = s->f_code - 1;
+ range = 1 << bit_size;
+ if (val <= -64)
+ val += 64;
+ else if (val >= 64)
+ val -= 64;
+
+ if (val >= 0) {
+ sign = 0;
+ } else {
+ val = -val;
+ sign = 1;
+ }
+ val--;
+ code = (val >> bit_size) + 1;
+ bits = val & (range - 1);
+
+ put_bits(&s->pb, ff_mvtab[code][1] + 1, (ff_mvtab[code][0] << 1) | sign);
+ if (bit_size > 0) {
+ put_bits(&s->pb, bit_size, bits);
+ }
+ }
+}
+
+void ff_msmpeg4_encode_mb(MpegEncContext * s,
+ DCTELEM block[6][64],
+ int motion_x, int motion_y)
+{
+ int cbp, coded_cbp, i;
+ int pred_x, pred_y;
+ uint8_t *coded_block;
+
+ ff_msmpeg4_handle_slices(s);
+
+ if (!s->mb_intra) {
+ /* compute cbp */
+ cbp = 0;
+ for (i = 0; i < 6; i++) {
+ if (s->block_last_index[i] >= 0)
+ cbp |= 1 << (5 - i);
+ }
+ if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
+ /* skip macroblock */
+ put_bits(&s->pb, 1, 1);
+ s->last_bits++;
+ s->misc_bits++;
+ s->skip_count++;
+
+ return;
+ }
+ if (s->use_skip_mb_code)
+ put_bits(&s->pb, 1, 0); /* mb coded */
+
+ if(s->msmpeg4_version<=2){
+ put_bits(&s->pb,
+ ff_v2_mb_type[cbp&3][1],
+ ff_v2_mb_type[cbp&3][0]);
+ if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
+ else coded_cbp= cbp;
+
+ put_bits(&s->pb,
+ ff_h263_cbpy_tab[coded_cbp>>2][1],
+ ff_h263_cbpy_tab[coded_cbp>>2][0]);
+
+ s->misc_bits += get_bits_diff(s);
+
+ ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
+ msmpeg4v2_encode_motion(s, motion_x - pred_x);
+ msmpeg4v2_encode_motion(s, motion_y - pred_y);
+ }else{
+ put_bits(&s->pb,
+ ff_table_mb_non_intra[cbp + 64][1],
+ ff_table_mb_non_intra[cbp + 64][0]);
+
+ s->misc_bits += get_bits_diff(s);
+
+ /* motion vector */
+ ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
+ ff_msmpeg4_encode_motion(s, motion_x - pred_x,
+ motion_y - pred_y);
+ }
+
+ s->mv_bits += get_bits_diff(s);
+
+ for (i = 0; i < 6; i++) {
+ ff_msmpeg4_encode_block(s, block[i], i);
+ }
+ s->p_tex_bits += get_bits_diff(s);
+ } else {
+ /* compute cbp */
+ cbp = 0;
+ coded_cbp = 0;
+ for (i = 0; i < 6; i++) {
+ int val, pred;
+ val = (s->block_last_index[i] >= 1);
+ cbp |= val << (5 - i);
+ if (i < 4) {
+ /* predict value for close blocks only for luma */
+ pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
+ *coded_block = val;
+ val = val ^ pred;
+ }
+ coded_cbp |= val << (5 - i);
+ }
+
+ if(s->msmpeg4_version<=2){
+ if (s->pict_type == AV_PICTURE_TYPE_I) {
+ put_bits(&s->pb,
+ ff_v2_intra_cbpc[cbp&3][1], ff_v2_intra_cbpc[cbp&3][0]);
+ } else {
+ if (s->use_skip_mb_code)
+ put_bits(&s->pb, 1, 0); /* mb coded */
+ put_bits(&s->pb,
+ ff_v2_mb_type[(cbp&3) + 4][1],
+ ff_v2_mb_type[(cbp&3) + 4][0]);
+ }
+ put_bits(&s->pb, 1, 0); /* no AC prediction yet */
+ put_bits(&s->pb,
+ ff_h263_cbpy_tab[cbp>>2][1],
+ ff_h263_cbpy_tab[cbp>>2][0]);
+ }else{
+ if (s->pict_type == AV_PICTURE_TYPE_I) {
+ put_bits(&s->pb,
+ ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
+ } else {
+ if (s->use_skip_mb_code)
+ put_bits(&s->pb, 1, 0); /* mb coded */
+ put_bits(&s->pb,
+ ff_table_mb_non_intra[cbp][1],
+ ff_table_mb_non_intra[cbp][0]);
+ }
+ put_bits(&s->pb, 1, 0); /* no AC prediction yet */
+ if(s->inter_intra_pred){
+ s->h263_aic_dir=0;
+ put_bits(&s->pb, ff_table_inter_intra[s->h263_aic_dir][1], ff_table_inter_intra[s->h263_aic_dir][0]);
+ }
+ }
+ s->misc_bits += get_bits_diff(s);
+
+ for (i = 0; i < 6; i++) {
+ ff_msmpeg4_encode_block(s, block[i], i);
+ }
+ s->i_tex_bits += get_bits_diff(s);
+ s->i_count++;
+ }
+}
+
+static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
+{
+ int sign, code;
+ int pred, extquant;
+ int extrabits = 0;
+
+ int16_t *dc_val;
+ pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
+
+ /* update predictor */
+ if (n < 4) {
+ *dc_val = level * s->y_dc_scale;
+ } else {
+ *dc_val = level * s->c_dc_scale;
+ }
+
+ /* do the prediction */
+ level -= pred;
+
+ if(s->msmpeg4_version<=2){
+ if (n < 4) {
+ put_bits(&s->pb,
+ ff_v2_dc_lum_table[level + 256][1],
+ ff_v2_dc_lum_table[level + 256][0]);
+ }else{
+ put_bits(&s->pb,
+ ff_v2_dc_chroma_table[level + 256][1],
+ ff_v2_dc_chroma_table[level + 256][0]);
+ }
+ }else{
+ sign = 0;
+ if (level < 0) {
+ level = -level;
+ sign = 1;
+ }
+ code = level;
+ if (code > DC_MAX)
+ code = DC_MAX;
+ else if( s->msmpeg4_version>=6 ) {
+ if( s->qscale == 1 ) {
+ extquant = (level + 3) & 0x3;
+ code = ((level+3)>>2);
+ } else if( s->qscale == 2 ) {
+ extquant = (level + 1) & 0x1;
+ code = ((level+1)>>1);
+ }
+ }
+
+ if (s->dc_table_index == 0) {
+ if (n < 4) {
+ put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]);
+ } else {
+ put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]);
+ }
+ } else {
+ if (n < 4) {
+ put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]);
+ } else {
+ put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]);
+ }
+ }
+
+ if(s->msmpeg4_version>=6 && s->qscale<=2)
+ extrabits = 3 - s->qscale;
+
+ if (code == DC_MAX)
+ put_bits(&s->pb, 8 + extrabits, level);
+ else if(extrabits > 0)//== VC1 && s->qscale<=2
+ put_bits(&s->pb, extrabits, extquant);
+
+ if (level != 0) {
+ put_bits(&s->pb, 1, sign);
+ }
+ }
+}
+
+/* Encoding of a block. Very similar to MPEG4 except for a different
+ escape coding (same as H263) and more vlc tables.
+ */
+void ff_msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n)
+{
+ int level, run, last, i, j, last_index;
+ int last_non_zero, sign, slevel;
+ int code, run_diff, dc_pred_dir;
+ const RLTable *rl;
+ const uint8_t *scantable;
+
+ if (s->mb_intra) {
+ msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
+ i = 1;
+ if (n < 4) {
+ rl = &ff_rl_table[s->rl_table_index];
+ } else {
+ rl = &ff_rl_table[3 + s->rl_chroma_table_index];
+ }
+ run_diff = s->msmpeg4_version>=4;
+ scantable= s->intra_scantable.permutated;
+ } else {
+ i = 0;
+ rl = &ff_rl_table[3 + s->rl_table_index];
+ if(s->msmpeg4_version<=2)
+ run_diff = 0;
+ else
+ run_diff = 1;
+ scantable= s->inter_scantable.permutated;
+ }
+
+ /* recalculate block_last_index for M$ wmv1 */
+ if(s->msmpeg4_version>=4 && s->msmpeg4_version<6 && s->block_last_index[n]>0){
+ for(last_index=63; last_index>=0; last_index--){
+ if(block[scantable[last_index]]) break;
+ }
+ s->block_last_index[n]= last_index;
+ }else
+ last_index = s->block_last_index[n];
+ /* AC coefs */
+ last_non_zero = i - 1;
+ for (; i <= last_index; i++) {
+ j = scantable[i];
+ level = block[j];
+ if (level) {
+ run = i - last_non_zero - 1;
+ last = (i == last_index);
+ sign = 0;
+ slevel = level;
+ if (level < 0) {
+ sign = 1;
+ level = -level;
+ }
+
+ if(level<=MAX_LEVEL && run<=MAX_RUN){
+ s->ac_stats[s->mb_intra][n>3][level][run][last]++;
+ }
+
+ s->ac_stats[s->mb_intra][n > 3][40][63][0]++; //esc3 like
+
+ code = get_rl_index(rl, last, run, level);
+ put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
+ if (code == rl->n) {
+ int level1, run1;
+
+ level1 = level - rl->max_level[last][run];
+ if (level1 < 1)
+ goto esc2;
+ code = get_rl_index(rl, last, run, level1);
+ if (code == rl->n) {
+ esc2:
+ put_bits(&s->pb, 1, 0);
+ if (level > MAX_LEVEL)
+ goto esc3;
+ run1 = run - rl->max_run[last][level] - run_diff;
+ if (run1 < 0)
+ goto esc3;
+ code = get_rl_index(rl, last, run1+1, level);
+ if (s->msmpeg4_version == 4 && code == rl->n)
+ goto esc3;
+ code = get_rl_index(rl, last, run1, level);
+ if (code == rl->n) {
+ esc3:
+ /* third escape */
+ put_bits(&s->pb, 1, 0);
+ put_bits(&s->pb, 1, last);
+ if(s->msmpeg4_version>=4){
+ if(s->esc3_level_length==0){
+ s->esc3_level_length=8;
+ s->esc3_run_length= 6;
+ //ESCLVLSZ + ESCRUNSZ
+ if(s->qscale<8)
+ put_bits(&s->pb, 6 + (s->msmpeg4_version>=6), 3);
+ else
+ put_bits(&s->pb, 8, 3);
+ }
+ put_bits(&s->pb, s->esc3_run_length, run);
+ put_bits(&s->pb, 1, sign);
+ put_bits(&s->pb, s->esc3_level_length, level);
+ }else{
+ put_bits(&s->pb, 6, run);
+ put_sbits(&s->pb, 8, slevel);
+ }
+ } else {
+ /* second escape */
+ put_bits(&s->pb, 1, 1);
+ put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
+ put_bits(&s->pb, 1, sign);
+ }
+ } else {
+ /* first escape */
+ put_bits(&s->pb, 1, 1);
+ put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
+ put_bits(&s->pb, 1, sign);
+ }
+ } else {
+ put_bits(&s->pb, 1, sign);
+ }
+ last_non_zero = i;
+ }
+ }
+}
diff --git a/libavcodec/pamenc.c b/libavcodec/pamenc.c
index d1de7a0e33..7a3499e579 100644
--- a/libavcodec/pamenc.c
+++ b/libavcodec/pamenc.c
@@ -28,7 +28,7 @@ static int pam_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pict, int *got_packet)
{
PNMContext *s = avctx->priv_data;
- AVFrame * const p = (AVFrame*)&s->picture;
+ AVFrame * const p = &s->picture;
int i, h, w, n, linesize, depth, maxval, ret;
const char *tuple_type;
uint8_t *ptr;
diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c
index 0e547deb5f..bfb4a25b7c 100644
--- a/libavcodec/pnm.c
+++ b/libavcodec/pnm.c
@@ -198,8 +198,8 @@ av_cold int ff_pnm_init(AVCodecContext *avctx)
{
PNMContext *s = avctx->priv_data;
- avcodec_get_frame_defaults((AVFrame*)&s->picture);
- avctx->coded_frame = (AVFrame*)&s->picture;
+ avcodec_get_frame_defaults(&s->picture);
+ avctx->coded_frame = &s->picture;
return 0;
}
diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c
index 0be7ec9326..0c1fad868b 100644
--- a/libavcodec/pnmdec.c
+++ b/libavcodec/pnmdec.c
@@ -31,7 +31,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
int buf_size = avpkt->size;
PNMContext * const s = avctx->priv_data;
AVFrame *picture = data;
- AVFrame * const p = (AVFrame*)&s->picture;
+ AVFrame * const p = &s->picture;
int i, j, n, linesize, h, upgrade = 0, is_mono = 0;
unsigned char *ptr;
int components, sample_len;
@@ -184,7 +184,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
}
break;
}
- *picture = *(AVFrame*)&s->picture;
+ *picture = s->picture;
*data_size = sizeof(AVPicture);
return s->bytestream - s->bytestream_start;
diff --git a/libavcodec/pnmenc.c b/libavcodec/pnmenc.c
index 1f96db51b9..b1f27b4a3e 100644
--- a/libavcodec/pnmenc.c
+++ b/libavcodec/pnmenc.c
@@ -28,7 +28,7 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pict, int *got_packet)
{
PNMContext *s = avctx->priv_data;
- AVFrame * const p = (AVFrame*)&s->picture;
+ AVFrame * const p = &s->picture;
int i, h, h1, c, n, linesize, ret;
uint8_t *ptr, *ptr1, *ptr2;
diff --git a/libavcodec/ppc/vp8dsp_altivec.c b/libavcodec/ppc/vp8dsp_altivec.c
index e9defbc67f..7f7d3bd35c 100644
--- a/libavcodec/ppc/vp8dsp_altivec.c
+++ b/libavcodec/ppc/vp8dsp_altivec.c
@@ -75,8 +75,8 @@ static const vec_s8 h_subpel_filters_outer[3] =
dstv = vec_sra(dstv, c7)
static av_always_inline
-void put_vp8_epel_h_altivec_core(uint8_t *dst, int dst_stride,
- uint8_t *src, int src_stride,
+void put_vp8_epel_h_altivec_core(uint8_t *dst, ptrdiff_t dst_stride,
+ uint8_t *src, ptrdiff_t src_stride,
int h, int mx, int w, int is6tap)
{
LOAD_H_SUBPEL_FILTER(mx-1);
@@ -161,8 +161,8 @@ static const vec_u8 v_subpel_filters[7] =
dstv = vec_sra(dstv, c7)
static av_always_inline
-void put_vp8_epel_v_altivec_core(uint8_t *dst, int dst_stride,
- uint8_t *src, int src_stride,
+void put_vp8_epel_v_altivec_core(uint8_t *dst, ptrdiff_t dst_stride,
+ uint8_t *src, ptrdiff_t src_stride,
int h, int my, int w, int is6tap)
{
LOAD_V_SUBPEL_FILTER(my-1);
@@ -226,19 +226,19 @@ void put_vp8_epel_v_altivec_core(uint8_t *dst, int dst_stride,
#define EPEL_FUNCS(WIDTH, TAPS) \
static av_noinline \
-void put_vp8_epel ## WIDTH ## _h ## TAPS ## _altivec(uint8_t *dst, int dst_stride, uint8_t *src, int src_stride, int h, int mx, int my) \
+void put_vp8_epel ## WIDTH ## _h ## TAPS ## _altivec(uint8_t *dst, ptrdiff_t dst_stride, uint8_t *src, ptrdiff_t src_stride, int h, int mx, int my) \
{ \
put_vp8_epel_h_altivec_core(dst, dst_stride, src, src_stride, h, mx, WIDTH, TAPS == 6); \
} \
\
static av_noinline \
-void put_vp8_epel ## WIDTH ## _v ## TAPS ## _altivec(uint8_t *dst, int dst_stride, uint8_t *src, int src_stride, int h, int mx, int my) \
+void put_vp8_epel ## WIDTH ## _v ## TAPS ## _altivec(uint8_t *dst, ptrdiff_t dst_stride, uint8_t *src, ptrdiff_t src_stride, int h, int mx, int my) \
{ \
put_vp8_epel_v_altivec_core(dst, dst_stride, src, src_stride, h, my, WIDTH, TAPS == 6); \
}
#define EPEL_HV(WIDTH, HTAPS, VTAPS) \
-static void put_vp8_epel ## WIDTH ## _h ## HTAPS ## v ## VTAPS ## _altivec(uint8_t *dst, int stride, uint8_t *src, int s, int h, int mx, int my) \
+static void put_vp8_epel ## WIDTH ## _h ## HTAPS ## v ## VTAPS ## _altivec(uint8_t *dst, ptrdiff_t stride, uint8_t *src, ptrdiff_t s, int h, int mx, int my) \
{ \
DECLARE_ALIGNED(16, uint8_t, tmp)[(2*WIDTH+5)*16]; \
if (VTAPS == 6) { \
@@ -266,7 +266,7 @@ EPEL_HV(4, 4,6)
EPEL_HV(4, 6,4)
EPEL_HV(4, 4,4)
-static void put_vp8_pixels16_altivec(uint8_t *dst, int stride, uint8_t *src, int s, int h, int mx, int my)
+static void put_vp8_pixels16_altivec(uint8_t *dst, ptrdiff_t stride, uint8_t *src, ptrdiff_t s, int h, int mx, int my)
{
ff_put_pixels16_altivec(dst, src, stride, h);
}
diff --git a/libavcodec/qdrw.c b/libavcodec/qdrw.c
index 54deec5c83..751e1a1909 100644
--- a/libavcodec/qdrw.c
+++ b/libavcodec/qdrw.c
@@ -40,7 +40,7 @@ static int decode_frame(AVCodecContext *avctx,
const uint8_t *buf_end = avpkt->data + avpkt->size;
int buf_size = avpkt->size;
QdrawContext * const a = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&a->pic;
+ AVFrame * const p = &a->pic;
uint8_t* outdata;
int colors;
int i;
diff --git a/libavcodec/qpeg.c b/libavcodec/qpeg.c
index bbb9f71aae..ca48b6bcf3 100644
--- a/libavcodec/qpeg.c
+++ b/libavcodec/qpeg.c
@@ -259,8 +259,8 @@ static int decode_frame(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
QpegContext * const a = avctx->priv_data;
- AVFrame * p= (AVFrame*)&a->pic;
- AVFrame * ref= (AVFrame*)&a->ref;
+ AVFrame * p = &a->pic;
+ AVFrame * ref= &a->ref;
uint8_t* outdata;
int delta, ret = 0;
const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
@@ -311,8 +311,8 @@ static av_cold int decode_init(AVCodecContext *avctx){
static av_cold int decode_end(AVCodecContext *avctx){
QpegContext * const a = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&a->pic;
- AVFrame * const ref= (AVFrame*)&a->ref;
+ AVFrame * const p = &a->pic;
+ AVFrame * const ref= &a->ref;
if(p->data[0])
avctx->release_buffer(avctx, p);
diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index d912ca285d..71ab5df501 100644
--- a/libavcodec/rawdec.c
+++ b/libavcodec/rawdec.c
@@ -140,8 +140,8 @@ static int raw_decode(AVCodecContext *avctx,
int linesize_align = 4;
RawVideoContext *context = avctx->priv_data;
- AVFrame * frame = (AVFrame *) data;
- AVPicture * picture = (AVPicture *) data;
+ AVFrame *frame = data;
+ AVPicture *picture = data;
frame->pict_type = avctx->coded_frame->pict_type;
frame->interlaced_frame = avctx->coded_frame->interlaced_frame;
diff --git a/libavcodec/rawenc.c b/libavcodec/rawenc.c
index 577a8fc98a..cb491e9094 100644
--- a/libavcodec/rawenc.c
+++ b/libavcodec/rawenc.c
@@ -32,7 +32,7 @@
static av_cold int raw_init_encoder(AVCodecContext *avctx)
{
- avctx->coded_frame = (AVFrame *)avctx->priv_data;
+ avctx->coded_frame = avctx->priv_data;
avcodec_get_frame_defaults(avctx->coded_frame);
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]);
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index dd8715b300..bc86b69a2e 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -515,9 +515,10 @@ static int rv10_decode_packet(AVCodecContext *avctx,
const uint8_t *buf, int buf_size, int buf_size2)
{
MpegEncContext *s = avctx->priv_data;
- int mb_count, mb_pos, left, start_mb_x;
+ int mb_count, mb_pos, left, start_mb_x, active_bits_size;
- init_get_bits(&s->gb, buf, buf_size*8);
+ active_bits_size = buf_size * 8;
+ init_get_bits(&s->gb, buf, FFMAX(buf_size, buf_size2) * 8);
if(s->codec_id ==CODEC_ID_RV10)
mb_count = rv10_decode_picture_header(s);
else
@@ -601,13 +602,26 @@ static int rv10_decode_packet(AVCodecContext *avctx,
s->mv_type = MV_TYPE_16X16;
ret=ff_h263_decode_mb(s, s->block);
- if (ret != SLICE_ERROR && s->gb.size_in_bits < get_bits_count(&s->gb) && 8*buf_size2 >= get_bits_count(&s->gb)){
- av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n", s->gb.size_in_bits, 8*buf_size2);
- s->gb.size_in_bits= 8*buf_size2;
+ // Repeat the slice end check from ff_h263_decode_mb with our active
+ // bitstream size
+ if (ret != SLICE_ERROR) {
+ int v = show_bits(&s->gb, 16);
+
+ if (get_bits_count(&s->gb) + 16 > active_bits_size)
+ v >>= get_bits_count(&s->gb) + 16 - active_bits_size;
+
+ if (!v)
+ ret = SLICE_END;
+ }
+ if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&s->gb) &&
+ 8 * buf_size2 >= get_bits_count(&s->gb)) {
+ active_bits_size = buf_size2 * 8;
+ av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n",
+ 8 * buf_size, active_bits_size);
ret= SLICE_OK;
}
- if (ret == SLICE_ERROR || s->gb.size_in_bits < get_bits_count(&s->gb)) {
+ if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&s->gb)) {
av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x, s->mb_y);
return -1;
}
@@ -629,7 +643,7 @@ static int rv10_decode_packet(AVCodecContext *avctx,
ff_er_add_slice(s, start_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END);
- return s->gb.size_in_bits;
+ return active_bits_size;
}
static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n)
@@ -661,8 +675,12 @@ static int rv10_decode_frame(AVCodecContext *avctx,
if(!avctx->slice_count){
slice_count = (*buf++) + 1;
+ buf_size--;
slices_hdr = buf + 4;
buf += 8 * slice_count;
+ buf_size -= 8 * slice_count;
+ if (buf_size <= 0)
+ return AVERROR_INVALIDDATA;
}else
slice_count = avctx->slice_count;
@@ -696,9 +714,9 @@ static int rv10_decode_frame(AVCodecContext *avctx,
ff_MPV_frame_end(s);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
- *pict= *(AVFrame*)s->current_picture_ptr;
+ *pict = s->current_picture_ptr->f;
} else if (s->last_picture_ptr != NULL) {
- *pict= *(AVFrame*)s->last_picture_ptr;
+ *pict = s->last_picture_ptr->f;
}
if(s->last_picture_ptr || s->low_delay){
@@ -708,7 +726,7 @@ static int rv10_decode_frame(AVCodecContext *avctx,
s->current_picture_ptr= NULL; //so we can detect if frame_end wasnt called (find some nicer solution...)
}
- return buf_size;
+ return avpkt->size;
}
AVCodec ff_rv10_decoder = {
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index 69273874c2..5550a74d0b 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -1660,7 +1660,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
if (buf_size == 0) {
/* special case for last picture */
if (s->low_delay==0 && s->next_picture_ptr) {
- *pict = *(AVFrame*)s->next_picture_ptr;
+ *pict = s->next_picture_ptr->f;
s->next_picture_ptr = NULL;
*data_size = sizeof(AVFrame);
@@ -1747,9 +1747,9 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 0);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
- *pict = *(AVFrame*)s->current_picture_ptr;
+ *pict = s->current_picture_ptr->f;
} else if (s->last_picture_ptr != NULL) {
- *pict = *(AVFrame*)s->last_picture_ptr;
+ *pict = s->last_picture_ptr->f;
}
if(s->last_picture_ptr || s->low_delay){
diff --git a/libavcodec/svq1dec.c b/libavcodec/svq1dec.c
index cb89b3f619..381cd63937 100644
--- a/libavcodec/svq1dec.c
+++ b/libavcodec/svq1dec.c
@@ -735,7 +735,7 @@ static int svq1_decode_frame(AVCodecContext *avctx,
}
}
- *pict = *(AVFrame*)&s->current_picture;
+ *pict = s->current_picture.f;
ff_MPV_frame_end(s);
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 84ff0d8814..a3936a8b37 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -473,7 +473,7 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
SVQ1Context * const s = avctx->priv_data;
ff_dsputil_init(&s->dsp, avctx);
- avctx->coded_frame= (AVFrame*)&s->picture;
+ avctx->coded_frame = &s->picture;
s->frame_width = avctx->width;
s->frame_height = avctx->height;
@@ -501,7 +501,7 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pict, int *got_packet)
{
SVQ1Context * const s = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&s->picture;
+ AVFrame * const p = &s->picture;
AVFrame temp;
int i, ret;
diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
index 3ebe95ef7f..8b112412cd 100644
--- a/libavcodec/svq3.c
+++ b/libavcodec/svq3.c
@@ -958,7 +958,7 @@ static int svq3_decode_frame(AVCodecContext *avctx,
/* special case for last picture */
if (buf_size == 0) {
if (s->next_picture_ptr && !s->low_delay) {
- *(AVFrame *) data = *(AVFrame *) &s->next_picture;
+ *(AVFrame *) data = s->next_picture.f;
s->next_picture_ptr = NULL;
*data_size = sizeof(AVFrame);
}
@@ -1101,9 +1101,9 @@ static int svq3_decode_frame(AVCodecContext *avctx,
ff_MPV_frame_end(s);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
- *(AVFrame *) data = *(AVFrame *) &s->current_picture;
+ *(AVFrame *) data = s->current_picture.f;
} else {
- *(AVFrame *) data = *(AVFrame *) &s->last_picture;
+ *(AVFrame *) data = s->last_picture.f;
}
/* Do not output the last pic after seeking. */
diff --git a/libavcodec/targa.c b/libavcodec/targa.c
index 573992ff8a..5ddd21bfef 100644
--- a/libavcodec/targa.c
+++ b/libavcodec/targa.c
@@ -106,7 +106,7 @@ static int decode_frame(AVCodecContext *avctx,
const uint8_t *buf_end = avpkt->data + avpkt->size;
TargaContext * const s = avctx->priv_data;
AVFrame *picture = data;
- AVFrame * const p= (AVFrame*)&s->picture;
+ AVFrame * const p = &s->picture;
uint8_t *dst;
int stride;
int idlen, pal, compr, y, w, h, bpp, flags;
@@ -262,7 +262,7 @@ static int decode_frame(AVCodecContext *avctx,
}
}
- *picture= *(AVFrame*)&s->picture;
+ *picture = s->picture;
*data_size = sizeof(AVPicture);
return avpkt->size;
@@ -271,8 +271,8 @@ static int decode_frame(AVCodecContext *avctx,
static av_cold int targa_init(AVCodecContext *avctx){
TargaContext *s = avctx->priv_data;
- avcodec_get_frame_defaults((AVFrame*)&s->picture);
- avctx->coded_frame= (AVFrame*)&s->picture;
+ avcodec_get_frame_defaults(&s->picture);
+ avctx->coded_frame = &s->picture;
return 0;
}
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 5d01e44ad8..5adf5a3b55 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -577,7 +577,7 @@ static int decode_frame(AVCodecContext *avctx,
int buf_size = avpkt->size;
TiffContext * const s = avctx->priv_data;
AVFrame *picture = data;
- AVFrame * const p= (AVFrame*)&s->picture;
+ AVFrame * const p = &s->picture;
const uint8_t *orig_buf = buf, *end_buf = buf + buf_size;
unsigned off;
int id, le, ret;
@@ -691,7 +691,7 @@ static int decode_frame(AVCodecContext *avctx,
dst += s->picture.linesize[0];
}
}
- *picture= *(AVFrame*)&s->picture;
+ *picture = s->picture;
*data_size = sizeof(AVPicture);
return buf_size;
@@ -703,8 +703,8 @@ static av_cold int tiff_init(AVCodecContext *avctx){
s->width = 0;
s->height = 0;
s->avctx = avctx;
- avcodec_get_frame_defaults((AVFrame*)&s->picture);
- avctx->coded_frame= (AVFrame*)&s->picture;
+ avcodec_get_frame_defaults(&s->picture);
+ avctx->coded_frame = &s->picture;
ff_lzw_decode_open(&s->lzw);
ff_ccitt_unpack_init();
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index a0fecf7b0f..c061ac985f 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -206,7 +206,7 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt,
const AVFrame *pict, int *got_packet)
{
TiffEncoderContext *s = avctx->priv_data;
- AVFrame *const p = (AVFrame *) & s->picture;
+ AVFrame *const p = &s->picture;
int i;
uint8_t *ptr;
uint8_t *offset;
diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c
index 985823dc25..ead7a39dbf 100644
--- a/libavcodec/truemotion2.c
+++ b/libavcodec/truemotion2.c
@@ -767,7 +767,7 @@ static int decode_frame(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
TM2Context * const l = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&l->pic;
+ AVFrame * const p = &l->pic;
int i, skip, t;
av_fast_padded_malloc(&l->buffer, &l->buffer_size, buf_size);
diff --git a/libavcodec/ulti.c b/libavcodec/ulti.c
index cd6f2d24ab..22b932a7e7 100644
--- a/libavcodec/ulti.c
+++ b/libavcodec/ulti.c
@@ -50,7 +50,7 @@ static av_cold int ulti_decode_init(AVCodecContext *avctx)
s->height = avctx->height;
s->blocks = (s->width / 8) * (s->height / 8);
avctx->pix_fmt = PIX_FMT_YUV410P;
- avcodec_get_frame_defaults(&s->frame);
+ avctx->coded_frame = &s->frame;
avctx->coded_frame = (AVFrame*) &s->frame;
s->ulti_codebook = ulti_codebook;
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index b612ca1ace..2b6e30e5bf 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1226,6 +1226,12 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
avpkt->data = new_data;
}
+ if (!user_packet && avpkt->data) {
+ uint8_t *new_data = av_realloc(avpkt->data, avpkt->size);
+ if (new_data)
+ avpkt->data = new_data;
+ }
+
avctx->frame_number++;
}
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index 6fb6b17ff8..15e5adb5c5 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -5456,7 +5456,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data,
if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)) {
/* special case for last picture */
if (s->low_delay == 0 && s->next_picture_ptr) {
- *pict = *(AVFrame*)s->next_picture_ptr;
+ *pict = s->next_picture_ptr->f;
s->next_picture_ptr = NULL;
*data_size = sizeof(AVFrame);
@@ -5764,9 +5764,9 @@ image:
*data_size = sizeof(AVFrame);
} else {
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
- *pict = *(AVFrame*)s->current_picture_ptr;
+ *pict = s->current_picture_ptr->f;
} else if (s->last_picture_ptr != NULL) {
- *pict = *(AVFrame*)s->last_picture_ptr;
+ *pict = s->last_picture_ptr->f;
}
if (s->last_picture_ptr || s->low_delay) {
*data_size = sizeof(AVFrame);
diff --git a/libavcodec/vcr1.c b/libavcodec/vcr1.c
index 1526215314..7b0e7a53b4 100644
--- a/libavcodec/vcr1.c
+++ b/libavcodec/vcr1.c
@@ -49,7 +49,7 @@ static int decode_frame(AVCodecContext *avctx,
int buf_size = avpkt->size;
VCR1Context * const a = avctx->priv_data;
AVFrame *picture = data;
- AVFrame * const p= (AVFrame*)&a->picture;
+ AVFrame * const p = &a->picture;
const uint8_t *bytestream= buf;
int i, x, y;
@@ -116,7 +116,7 @@ static int decode_frame(AVCodecContext *avctx,
}
}
- *picture= *(AVFrame*)&a->picture;
+ *picture = a->picture;
*data_size = sizeof(AVPicture);
return buf_size;
@@ -126,7 +126,7 @@ static int decode_frame(AVCodecContext *avctx,
static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
VCR1Context * const a = avctx->priv_data;
AVFrame *pict = data;
- AVFrame * const p= (AVFrame*)&a->picture;
+ AVFrame * const p = &a->picture;
int size;
*p = *pict;
@@ -146,7 +146,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
static av_cold void common_init(AVCodecContext *avctx){
VCR1Context * const a = avctx->priv_data;
- avctx->coded_frame= (AVFrame*)&a->picture;
+ avctx->coded_frame = &a->picture;
avcodec_get_frame_defaults(&a->picture);
a->avctx= avctx;
}
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 1b72037572..1aa75eabbd 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -21,7 +21,7 @@
#define AVCODEC_VERSION_H
#define LIBAVCODEC_VERSION_MAJOR 54
-#define LIBAVCODEC_VERSION_MINOR 5
+#define LIBAVCODEC_VERSION_MINOR 6
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavcodec/vp8dsp.c b/libavcodec/vp8dsp.c
index ce90675d87..12f6988bff 100644
--- a/libavcodec/vp8dsp.c
+++ b/libavcodec/vp8dsp.c
@@ -77,7 +77,7 @@ static void vp8_luma_dc_wht_dc_c(DCTELEM block[4][4][16], DCTELEM dc[16])
#define MUL_20091(a) ((((a)*20091) >> 16) + (a))
#define MUL_35468(a) (((a)*35468) >> 16)
-static void vp8_idct_add_c(uint8_t *dst, DCTELEM block[16], int stride)
+static void vp8_idct_add_c(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride)
{
int i, t0, t1, t2, t3;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
@@ -113,7 +113,7 @@ static void vp8_idct_add_c(uint8_t *dst, DCTELEM block[16], int stride)
}
}
-static void vp8_idct_dc_add_c(uint8_t *dst, DCTELEM block[16], int stride)
+static void vp8_idct_dc_add_c(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride)
{
int i, dc = (block[0] + 4) >> 3;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP + dc;
@@ -128,7 +128,7 @@ static void vp8_idct_dc_add_c(uint8_t *dst, DCTELEM block[16], int stride)
}
}
-static void vp8_idct_dc_add4uv_c(uint8_t *dst, DCTELEM block[4][16], int stride)
+static void vp8_idct_dc_add4uv_c(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride)
{
vp8_idct_dc_add_c(dst+stride*0+0, block[0], stride);
vp8_idct_dc_add_c(dst+stride*0+4, block[1], stride);
@@ -136,7 +136,7 @@ static void vp8_idct_dc_add4uv_c(uint8_t *dst, DCTELEM block[4][16], int stride)
vp8_idct_dc_add_c(dst+stride*4+4, block[3], stride);
}
-static void vp8_idct_dc_add4y_c(uint8_t *dst, DCTELEM block[4][16], int stride)
+static void vp8_idct_dc_add4y_c(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride)
{
vp8_idct_dc_add_c(dst+ 0, block[0], stride);
vp8_idct_dc_add_c(dst+ 4, block[1], stride);
@@ -157,7 +157,7 @@ static void vp8_idct_dc_add4y_c(uint8_t *dst, DCTELEM block[4][16], int stride)
#define clip_int8(n) (cm[n+0x80]-0x80)
-static av_always_inline void filter_common(uint8_t *p, int stride, int is4tap)
+static av_always_inline void filter_common(uint8_t *p, ptrdiff_t stride, int is4tap)
{
LOAD_PIXELS
int a, f1, f2;
@@ -188,7 +188,7 @@ static av_always_inline void filter_common(uint8_t *p, int stride, int is4tap)
}
}
-static av_always_inline int simple_limit(uint8_t *p, int stride, int flim)
+static av_always_inline int simple_limit(uint8_t *p, ptrdiff_t stride, int flim)
{
LOAD_PIXELS
return 2*FFABS(p0-q0) + (FFABS(p1-q1) >> 1) <= flim;
@@ -198,7 +198,7 @@ static av_always_inline int simple_limit(uint8_t *p, int stride, int flim)
* E - limit at the macroblock edge
* I - limit for interior difference
*/
-static av_always_inline int normal_limit(uint8_t *p, int stride, int E, int I)
+static av_always_inline int normal_limit(uint8_t *p, ptrdiff_t stride, int E, int I)
{
LOAD_PIXELS
return simple_limit(p, stride, E)
@@ -207,13 +207,13 @@ static av_always_inline int normal_limit(uint8_t *p, int stride, int E, int I)
}
// high edge variance
-static av_always_inline int hev(uint8_t *p, int stride, int thresh)
+static av_always_inline int hev(uint8_t *p, ptrdiff_t stride, int thresh)
{
LOAD_PIXELS
return FFABS(p1-p0) > thresh || FFABS(q1-q0) > thresh;
}
-static av_always_inline void filter_mbedge(uint8_t *p, int stride)
+static av_always_inline void filter_mbedge(uint8_t *p, ptrdiff_t stride)
{
int a0, a1, a2, w;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
@@ -236,7 +236,7 @@ static av_always_inline void filter_mbedge(uint8_t *p, int stride)
}
#define LOOP_FILTER(dir, size, stridea, strideb, maybe_inline) \
-static maybe_inline void vp8_ ## dir ## _loop_filter ## size ## _c(uint8_t *dst, int stride,\
+static maybe_inline void vp8_ ## dir ## _loop_filter ## size ## _c(uint8_t *dst, ptrdiff_t stride,\
int flim_E, int flim_I, int hev_thresh)\
{\
int i;\
@@ -250,7 +250,7 @@ static maybe_inline void vp8_ ## dir ## _loop_filter ## size ## _c(uint8_t *dst,
}\
}\
\
-static maybe_inline void vp8_ ## dir ## _loop_filter ## size ## _inner_c(uint8_t *dst, int stride,\
+static maybe_inline void vp8_ ## dir ## _loop_filter ## size ## _inner_c(uint8_t *dst, ptrdiff_t stride,\
int flim_E, int flim_I, int hev_thresh)\
{\
int i;\
@@ -270,13 +270,13 @@ LOOP_FILTER(h, 16, stride, 1,)
#define UV_LOOP_FILTER(dir, stridea, strideb) \
LOOP_FILTER(dir, 8, stridea, strideb, av_always_inline) \
-static void vp8_ ## dir ## _loop_filter8uv_c(uint8_t *dstU, uint8_t *dstV, int stride,\
+static void vp8_ ## dir ## _loop_filter8uv_c(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,\
int fE, int fI, int hev_thresh)\
{\
vp8_ ## dir ## _loop_filter8_c(dstU, stride, fE, fI, hev_thresh);\
vp8_ ## dir ## _loop_filter8_c(dstV, stride, fE, fI, hev_thresh);\
}\
-static void vp8_ ## dir ## _loop_filter8uv_inner_c(uint8_t *dstU, uint8_t *dstV, int stride,\
+static void vp8_ ## dir ## _loop_filter8uv_inner_c(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,\
int fE, int fI, int hev_thresh)\
{\
vp8_ ## dir ## _loop_filter8_inner_c(dstU, stride, fE, fI, hev_thresh);\
@@ -286,7 +286,7 @@ static void vp8_ ## dir ## _loop_filter8uv_inner_c(uint8_t *dstU, uint8_t *dstV,
UV_LOOP_FILTER(v, 1, stride)
UV_LOOP_FILTER(h, stride, 1)
-static void vp8_v_loop_filter_simple_c(uint8_t *dst, int stride, int flim)
+static void vp8_v_loop_filter_simple_c(uint8_t *dst, ptrdiff_t stride, int flim)
{
int i;
@@ -295,7 +295,7 @@ static void vp8_v_loop_filter_simple_c(uint8_t *dst, int stride, int flim)
filter_common(dst+i, stride, 1);
}
-static void vp8_h_loop_filter_simple_c(uint8_t *dst, int stride, int flim)
+static void vp8_h_loop_filter_simple_c(uint8_t *dst, ptrdiff_t stride, int flim)
{
int i;
@@ -315,7 +315,7 @@ static const uint8_t subpel_filters[7][6] = {
};
#define PUT_PIXELS(WIDTH) \
-static void put_vp8_pixels ## WIDTH ##_c(uint8_t *dst, int dststride, uint8_t *src, int srcstride, int h, int x, int y) { \
+static void put_vp8_pixels ## WIDTH ##_c(uint8_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride, int h, int x, int y) { \
int i; \
for (i = 0; i < h; i++, dst+= dststride, src+= srcstride) { \
memcpy(dst, src, WIDTH); \
@@ -335,7 +335,7 @@ PUT_PIXELS(4)
F[3]*src[x+1*stride] - F[4]*src[x+2*stride] + 64) >> 7]
#define VP8_EPEL_H(SIZE, TAPS) \
-static void put_vp8_epel ## SIZE ## _h ## TAPS ## _c(uint8_t *dst, int dststride, uint8_t *src, int srcstride, int h, int mx, int my) \
+static void put_vp8_epel ## SIZE ## _h ## TAPS ## _c(uint8_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride, int h, int mx, int my) \
{ \
const uint8_t *filter = subpel_filters[mx-1]; \
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; \
@@ -349,7 +349,7 @@ static void put_vp8_epel ## SIZE ## _h ## TAPS ## _c(uint8_t *dst, int dststride
} \
}
#define VP8_EPEL_V(SIZE, TAPS) \
-static void put_vp8_epel ## SIZE ## _v ## TAPS ## _c(uint8_t *dst, int dststride, uint8_t *src, int srcstride, int h, int mx, int my) \
+static void put_vp8_epel ## SIZE ## _v ## TAPS ## _c(uint8_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride, int h, int mx, int my) \
{ \
const uint8_t *filter = subpel_filters[my-1]; \
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; \
@@ -363,7 +363,7 @@ static void put_vp8_epel ## SIZE ## _v ## TAPS ## _c(uint8_t *dst, int dststride
} \
}
#define VP8_EPEL_HV(SIZE, HTAPS, VTAPS) \
-static void put_vp8_epel ## SIZE ## _h ## HTAPS ## v ## VTAPS ## _c(uint8_t *dst, int dststride, uint8_t *src, int srcstride, int h, int mx, int my) \
+static void put_vp8_epel ## SIZE ## _h ## HTAPS ## v ## VTAPS ## _c(uint8_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride, int h, int mx, int my) \
{ \
const uint8_t *filter = subpel_filters[mx-1]; \
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; \
@@ -416,7 +416,7 @@ VP8_EPEL_HV(8, 6, 6)
VP8_EPEL_HV(4, 6, 6)
#define VP8_BILINEAR(SIZE) \
-static void put_vp8_bilinear ## SIZE ## _h_c(uint8_t *dst, int stride, uint8_t *src, int s2, int h, int mx, int my) \
+static void put_vp8_bilinear ## SIZE ## _h_c(uint8_t *dst, ptrdiff_t stride, uint8_t *src, ptrdiff_t s2, int h, int mx, int my) \
{ \
int a = 8-mx, b = mx; \
int x, y; \
@@ -428,7 +428,7 @@ static void put_vp8_bilinear ## SIZE ## _h_c(uint8_t *dst, int stride, uint8_t *
src += stride; \
} \
} \
-static void put_vp8_bilinear ## SIZE ## _v_c(uint8_t *dst, int stride, uint8_t *src, int s2, int h, int mx, int my) \
+static void put_vp8_bilinear ## SIZE ## _v_c(uint8_t *dst, ptrdiff_t stride, uint8_t *src, ptrdiff_t s2, int h, int mx, int my) \
{ \
int c = 8-my, d = my; \
int x, y; \
@@ -441,7 +441,7 @@ static void put_vp8_bilinear ## SIZE ## _v_c(uint8_t *dst, int stride, uint8_t *
} \
} \
\
-static void put_vp8_bilinear ## SIZE ## _hv_c(uint8_t *dst, int stride, uint8_t *src, int s2, int h, int mx, int my) \
+static void put_vp8_bilinear ## SIZE ## _hv_c(uint8_t *dst, ptrdiff_t stride, uint8_t *src, ptrdiff_t s2, int h, int mx, int my) \
{ \
int a = 8-mx, b = mx; \
int c = 8-my, d = my; \
diff --git a/libavcodec/vp8dsp.h b/libavcodec/vp8dsp.h
index 951a5566a7..d0c7d4aacc 100644
--- a/libavcodec/vp8dsp.h
+++ b/libavcodec/vp8dsp.h
@@ -29,40 +29,44 @@
#include "dsputil.h"
-typedef void (*vp8_mc_func)(uint8_t *dst/*align 8*/, int dstStride,
- uint8_t *src/*align 1*/, int srcStride,
+typedef void (*vp8_mc_func)(uint8_t *dst/*align 8*/, ptrdiff_t dstStride,
+ uint8_t *src/*align 1*/, ptrdiff_t srcStride,
int h, int x, int y);
typedef struct VP8DSPContext {
void (*vp8_luma_dc_wht)(DCTELEM block[4][4][16], DCTELEM dc[16]);
void (*vp8_luma_dc_wht_dc)(DCTELEM block[4][4][16], DCTELEM dc[16]);
- void (*vp8_idct_add)(uint8_t *dst, DCTELEM block[16], int stride);
- void (*vp8_idct_dc_add)(uint8_t *dst, DCTELEM block[16], int stride);
- void (*vp8_idct_dc_add4y)(uint8_t *dst, DCTELEM block[4][16], int stride);
- void (*vp8_idct_dc_add4uv)(uint8_t *dst, DCTELEM block[4][16], int stride);
+ void (*vp8_idct_add)(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride);
+ void (*vp8_idct_dc_add)(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride);
+ void (*vp8_idct_dc_add4y)(uint8_t *dst, DCTELEM block[4][16],
+ ptrdiff_t stride);
+ void (*vp8_idct_dc_add4uv)(uint8_t *dst, DCTELEM block[4][16],
+ ptrdiff_t stride);
// loop filter applied to edges between macroblocks
- void (*vp8_v_loop_filter16y)(uint8_t *dst, int stride,
+ void (*vp8_v_loop_filter16y)(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
- void (*vp8_h_loop_filter16y)(uint8_t *dst, int stride,
+ void (*vp8_h_loop_filter16y)(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
- void (*vp8_v_loop_filter8uv)(uint8_t *dstU, uint8_t *dstV, int stride,
+ void (*vp8_v_loop_filter8uv)(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
- void (*vp8_h_loop_filter8uv)(uint8_t *dstU, uint8_t *dstV, int stride,
+ void (*vp8_h_loop_filter8uv)(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
// loop filter applied to inner macroblock edges
- void (*vp8_v_loop_filter16y_inner)(uint8_t *dst, int stride,
+ void (*vp8_v_loop_filter16y_inner)(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
- void (*vp8_h_loop_filter16y_inner)(uint8_t *dst, int stride,
+ void (*vp8_h_loop_filter16y_inner)(uint8_t *dst, ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
- void (*vp8_v_loop_filter8uv_inner)(uint8_t *dstU, uint8_t *dstV, int stride,
+ void (*vp8_v_loop_filter8uv_inner)(uint8_t *dstU, uint8_t *dstV,
+ ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
- void (*vp8_h_loop_filter8uv_inner)(uint8_t *dstU, uint8_t *dstV, int stride,
+ void (*vp8_h_loop_filter8uv_inner)(uint8_t *dstU, uint8_t *dstV,
+ ptrdiff_t stride,
int flim_E, int flim_I, int hev_thresh);
- void (*vp8_v_loop_filter_simple)(uint8_t *dst, int stride, int flim);
- void (*vp8_h_loop_filter_simple)(uint8_t *dst, int stride, int flim);
+ void (*vp8_v_loop_filter_simple)(uint8_t *dst, ptrdiff_t stride, int flim);
+ void (*vp8_h_loop_filter_simple)(uint8_t *dst, ptrdiff_t stride, int flim);
/**
* first dimension: width>>3, height is assumed equal to width
@@ -76,9 +80,12 @@ typedef struct VP8DSPContext {
vp8_mc_func put_vp8_bilinear_pixels_tab[3][3][3];
} VP8DSPContext;
-void ff_put_vp8_pixels16_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y);
-void ff_put_vp8_pixels8_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y);
-void ff_put_vp8_pixels4_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y);
+void ff_put_vp8_pixels16_c(uint8_t *dst, uint8_t *src, ptrdiff_t stride,
+ int h, int x, int y);
+void ff_put_vp8_pixels8_c(uint8_t *dst, uint8_t *src, ptrdiff_t stride,
+ int h, int x, int y);
+void ff_put_vp8_pixels4_c(uint8_t *dst, uint8_t *src, ptrdiff_t stride,
+ int h, int x, int y);
void ff_vp8dsp_init(VP8DSPContext *c);
void ff_vp8dsp_init_x86(VP8DSPContext *c);
diff --git a/libavcodec/wma.h b/libavcodec/wma.h
index 6c8e944b79..954153fac0 100644
--- a/libavcodec/wma.h
+++ b/libavcodec/wma.h
@@ -124,7 +124,7 @@ typedef struct WMACodecContext {
/* output buffer for one frame and the last for IMDCT windowing */
DECLARE_ALIGNED(32, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
/* last frame info */
- uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
+ uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; /* padding added */
int last_bitoffset;
int last_superframe_len;
float noise_table[NOISE_TAB_SIZE];
diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index 7dae379ba8..f26a1433a9 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -863,6 +863,12 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
if (s->use_bit_reservoir) {
bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3);
+ if (bit_offset > get_bits_left(&s->gb)) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Invalid last frame bit offset %d > buf size %d (%d)\n",
+ bit_offset, get_bits_left(&s->gb), buf_size);
+ goto fail;
+ }
if (s->last_superframe_len > 0) {
// printf("skip=%d\n", s->last_bitoffset);
@@ -879,9 +885,10 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
if (len > 0) {
*q++ = (get_bits)(&s->gb, len) << (8 - len);
}
+ memset(q, 0, FF_INPUT_BUFFER_PADDING_SIZE);
/* XXX: bit_offset bits into last frame */
- init_get_bits(&s->gb, s->last_superframe, MAX_CODED_SUPERFRAME_SIZE*8);
+ init_get_bits(&s->gb, s->last_superframe, s->last_superframe_len * 8 + bit_offset);
/* skip unused bits */
if (s->last_bitoffset > 0)
skip_bits(&s->gb, s->last_bitoffset);
@@ -895,9 +902,9 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
/* read each frame starting from bit_offset */
pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3;
- if (pos >= MAX_CODED_SUPERFRAME_SIZE * 8)
+ if (pos >= MAX_CODED_SUPERFRAME_SIZE * 8 || pos > buf_size * 8)
return AVERROR_INVALIDDATA;
- init_get_bits(&s->gb, buf + (pos >> 3), (MAX_CODED_SUPERFRAME_SIZE - (pos >> 3))*8);
+ init_get_bits(&s->gb, buf + (pos >> 3), (buf_size - (pos >> 3))*8);
len = pos & 7;
if (len > 0)
skip_bits(&s->gb, len);
diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c
index b32731f96e..973edc438a 100644
--- a/libavcodec/wmalosslessdec.c
+++ b/libavcodec/wmalosslessdec.c
@@ -1,8 +1,9 @@
/*
- * Wmall compatible decoder
+ * Windows Media Audio Lossless decoder
* Copyright (c) 2007 Baptiste Coudurier, Benjamin Larsson, Ulion
* Copyright (c) 2008 - 2011 Sascha Sommer, Benjamin Larsson
* Copyright (c) 2011 Andreas Öman
+ * Copyright (c) 2011 - 2012 Mashiat Sarker Shakkhar
*
* This file is part of FFmpeg.
*
@@ -21,210 +22,94 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/**
- * @file
- * @brief wmall decoder implementation
- * Wmall is an MDCT based codec comparable to wma standard or AAC.
- * The decoding therefore consists of the following steps:
- * - bitstream decoding
- * - reconstruction of per-channel data
- * - rescaling and inverse quantization
- * - IMDCT
- * - windowing and overlapp-add
- *
- * The compressed wmall bitstream is split into individual packets.
- * Every such packet contains one or more wma frames.
- * The compressed frames may have a variable length and frames may
- * cross packet boundaries.
- * Common to all wmall frames is the number of samples that are stored in
- * a frame.
- * The number of samples and a few other decode flags are stored
- * as extradata that has to be passed to the decoder.
- *
- * The wmall frames themselves are again split into a variable number of
- * subframes. Every subframe contains the data for 2^N time domain samples
- * where N varies between 7 and 12.
- *
- * Example wmall bitstream (in samples):
- *
- * || packet 0 || packet 1 || packet 2 packets
- * ---------------------------------------------------
- * || frame 0 || frame 1 || frame 2 || frames
- * ---------------------------------------------------
- * || | | || | | | || || subframes of channel 0
- * ---------------------------------------------------
- * || | | || | | | || || subframes of channel 1
- * ---------------------------------------------------
- *
- * The frame layouts for the individual channels of a wma frame does not need
- * to be the same.
- *
- * However, if the offsets and lengths of several subframes of a frame are the
- * same, the subframes of the channels can be grouped.
- * Every group may then use special coding techniques like M/S stereo coding
- * to improve the compression ratio. These channel transformations do not
- * need to be applied to a whole subframe. Instead, they can also work on
- * individual scale factor bands (see below).
- * The coefficients that carry the audio signal in the frequency domain
- * are transmitted as huffman-coded vectors with 4, 2 and 1 elements.
- * In addition to that, the encoder can switch to a runlevel coding scheme
- * by transmitting subframe_length / 128 zero coefficients.
- *
- * Before the audio signal can be converted to the time domain, the
- * coefficients have to be rescaled and inverse quantized.
- * A subframe is therefore split into several scale factor bands that get
- * scaled individually.
- * Scale factors are submitted for every frame but they might be shared
- * between the subframes of a channel. Scale factors are initially DPCM-coded.
- * Once scale factors are shared, the differences are transmitted as runlevel
- * codes.
- * Every subframe length and offset combination in the frame layout shares a
- * common quantization factor that can be adjusted for every channel by a
- * modifier.
- * After the inverse quantization, the coefficients get processed by an IMDCT.
- * The resulting values are then windowed with a sine window and the first half
- * of the values are added to the second half of the output from the previous
- * subframe in order to reconstruct the output samples.
- */
-
#include "avcodec.h"
#include "internal.h"
#include "get_bits.h"
#include "put_bits.h"
-#include "dsputil.h"
#include "wma.h"
/** current decoder limitations */
-#define WMALL_MAX_CHANNELS 8 ///< max number of handled channels
-#define MAX_SUBFRAMES 32 ///< max number of subframes per channel
-#define MAX_BANDS 29 ///< max number of scale factor bands
-#define MAX_FRAMESIZE 32768 ///< maximum compressed frame size
-
-#define WMALL_BLOCK_MIN_BITS 6 ///< log2 of min block size
-#define WMALL_BLOCK_MAX_BITS 12 ///< log2 of max block size
-#define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS) ///< maximum block size
+#define WMALL_MAX_CHANNELS 8 ///< max number of handled channels
+#define MAX_SUBFRAMES 32 ///< max number of subframes per channel
+#define MAX_BANDS 29 ///< max number of scale factor bands
+#define MAX_FRAMESIZE 32768 ///< maximum compressed frame size
+
+#define WMALL_BLOCK_MIN_BITS 6 ///< log2 of min block size
+#define WMALL_BLOCK_MAX_BITS 12 ///< log2 of max block size
+#define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS) ///< maximum block size
#define WMALL_BLOCK_SIZES (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1) ///< possible block sizes
-#define VLCBITS 9
-#define SCALEVLCBITS 8
-#define VEC4MAXDEPTH ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS)
-#define VEC2MAXDEPTH ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS)
-#define VEC1MAXDEPTH ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS)
-#define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)
-#define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)
-
-static float sin64[33]; ///< sinus table for decorrelation
-
/**
- * @brief frame specific decoder context for a single channel
+ * @brief frame-specific decoder context for a single channel
*/
typedef struct {
- int16_t prev_block_len; ///< length of the previous block
- uint8_t transmit_coefs;
- uint8_t num_subframes;
- uint16_t subframe_len[MAX_SUBFRAMES]; ///< subframe length in samples
- uint16_t subframe_offset[MAX_SUBFRAMES]; ///< subframe positions in the current frame
- uint8_t cur_subframe; ///< current subframe number
- uint16_t decoded_samples; ///< number of already processed samples
- uint8_t grouped; ///< channel is part of a group
- int quant_step; ///< quantization step for the current subframe
- int8_t reuse_sf; ///< share scale factors between subframes
- int8_t scale_factor_step; ///< scaling step for the current subframe
- int max_scale_factor; ///< maximum scale factor for the current subframe
- int saved_scale_factors[2][MAX_BANDS]; ///< resampled and (previously) transmitted scale factor values
- int8_t scale_factor_idx; ///< index for the transmitted scale factor values (used for resampling)
- int* scale_factors; ///< pointer to the scale factor values used for decoding
- uint8_t table_idx; ///< index in sf_offsets for the scale factor reference block
- float* coeffs; ///< pointer to the subframe decode buffer
- uint16_t num_vec_coeffs; ///< number of vector coded coefficients
- DECLARE_ALIGNED(16, float, out)[WMALL_BLOCK_MAX_SIZE + WMALL_BLOCK_MAX_SIZE / 2]; ///< output buffer
- int transient_counter; ///< number of transient samples from the beginning of transient zone
+ int16_t prev_block_len; ///< length of the previous block
+ uint8_t transmit_coefs;
+ uint8_t num_subframes;
+ uint16_t subframe_len[MAX_SUBFRAMES]; ///< subframe length in samples
+ uint16_t subframe_offsets[MAX_SUBFRAMES]; ///< subframe positions in the current frame
+ uint8_t cur_subframe; ///< current subframe number
+ uint16_t decoded_samples; ///< number of already processed samples
+ int quant_step; ///< quantization step for the current subframe
+ int transient_counter; ///< number of transient samples from the beginning of the transient zone
} WmallChannelCtx;
/**
- * @brief channel group for channel transformations
- */
-typedef struct {
- uint8_t num_channels; ///< number of channels in the group
- int8_t transform; ///< transform on / off
- int8_t transform_band[MAX_BANDS]; ///< controls if the transform is enabled for a certain band
- float decorrelation_matrix[WMALL_MAX_CHANNELS*WMALL_MAX_CHANNELS];
- float* channel_data[WMALL_MAX_CHANNELS]; ///< transformation coefficients
-} WmallChannelGrp;
-
-/**
* @brief main decoder context
*/
typedef struct WmallDecodeCtx {
/* generic decoder variables */
- AVCodecContext* avctx; ///< codec context for av_log
- DSPContext dsp; ///< accelerated DSP functions
- AVFrame frame;
- uint8_t frame_data[MAX_FRAMESIZE +
- FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data
- PutBitContext pb; ///< context for filling the frame_data buffer
- FFTContext mdct_ctx[WMALL_BLOCK_SIZES]; ///< MDCT context per block size
- DECLARE_ALIGNED(16, float, tmp)[WMALL_BLOCK_MAX_SIZE]; ///< IMDCT output buffer
- float* windows[WMALL_BLOCK_SIZES]; ///< windows for the different block sizes
+ AVCodecContext *avctx;
+ AVFrame frame;
+ uint8_t frame_data[MAX_FRAMESIZE + FF_INPUT_BUFFER_PADDING_SIZE]; ///< compressed frame data
+ PutBitContext pb; ///< context for filling the frame_data buffer
/* frame size dependent frame information (set during initialization) */
- uint32_t decode_flags; ///< used compression features
- uint8_t len_prefix; ///< frame is prefixed with its length
- uint8_t dynamic_range_compression; ///< frame contains DRC data
- uint8_t bits_per_sample; ///< integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0])
- uint16_t samples_per_frame; ///< number of samples to output
- uint16_t log2_frame_size;
- int8_t num_channels; ///< number of channels in the stream (same as AVCodecContext.num_channels)
- int8_t lfe_channel; ///< lfe channel index
- uint8_t max_num_subframes;
- uint8_t subframe_len_bits; ///< number of bits used for the subframe length
- uint8_t max_subframe_len_bit; ///< flag indicating that the subframe is of maximum size when the first subframe length bit is 1
- uint16_t min_samples_per_subframe;
- int8_t num_sfb[WMALL_BLOCK_SIZES]; ///< scale factor bands per block size
- int16_t sfb_offsets[WMALL_BLOCK_SIZES][MAX_BANDS]; ///< scale factor band offsets (multiples of 4)
- int8_t sf_offsets[WMALL_BLOCK_SIZES][WMALL_BLOCK_SIZES][MAX_BANDS]; ///< scale factor resample matrix
- int16_t subwoofer_cutoffs[WMALL_BLOCK_SIZES]; ///< subwoofer cutoff values
+ uint32_t decode_flags; ///< used compression features
+ int len_prefix; ///< frame is prefixed with its length
+ int dynamic_range_compression; ///< frame contains DRC data
+ uint8_t bits_per_sample; ///< integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0])
+ uint16_t samples_per_frame; ///< number of samples to output
+ uint16_t log2_frame_size;
+ int8_t num_channels; ///< number of channels in the stream (same as AVCodecContext.num_channels)
+ int8_t lfe_channel; ///< lfe channel index
+ uint8_t max_num_subframes;
+ uint8_t subframe_len_bits; ///< number of bits used for the subframe length
+ uint8_t max_subframe_len_bit; ///< flag indicating that the subframe is of maximum size when the first subframe length bit is 1
+ uint16_t min_samples_per_subframe;
/* packet decode state */
- GetBitContext pgb; ///< bitstream reader context for the packet
- int next_packet_start; ///< start offset of the next wma packet in the demuxer packet
- uint8_t packet_offset; ///< frame offset in the packet
- uint8_t packet_sequence_number; ///< current packet number
- int num_saved_bits; ///< saved number of bits
- int frame_offset; ///< frame offset in the bit reservoir
- int subframe_offset; ///< subframe offset in the bit reservoir
- uint8_t packet_loss; ///< set in case of bitstream error
- uint8_t packet_done; ///< set when a packet is fully decoded
+ GetBitContext pgb; ///< bitstream reader context for the packet
+ int next_packet_start; ///< start offset of the next WMA packet in the demuxer packet
+ uint8_t packet_offset; ///< offset to the frame in the packet
+ uint8_t packet_sequence_number; ///< current packet number
+ int num_saved_bits; ///< saved number of bits
+ int frame_offset; ///< frame offset in the bit reservoir
+ int subframe_offset; ///< subframe offset in the bit reservoir
+ uint8_t packet_loss; ///< set in case of bitstream error
+ uint8_t packet_done; ///< set when a packet is fully decoded
/* frame decode state */
- uint32_t frame_num; ///< current frame number (not used for decoding)
- GetBitContext gb; ///< bitstream reader context
- int buf_bit_size; ///< buffer size in bits
- int16_t* samples_16; ///< current samplebuffer pointer (16-bit)
- int16_t* samples_16_end; ///< maximum samplebuffer pointer
+ uint32_t frame_num; ///< current frame number (not used for decoding)
+ GetBitContext gb; ///< bitstream reader context
+ int buf_bit_size; ///< buffer size in bits
+ int16_t *samples_16; ///< current samplebuffer pointer (16-bit)
+ int16_t *samples_16_end; ///< maximum samplebuffer pointer
int *samples_32; ///< current samplebuffer pointer (24-bit)
int *samples_32_end; ///< maximum samplebuffer pointer
- uint8_t drc_gain; ///< gain for the DRC tool
- int8_t skip_frame; ///< skip output step
- int8_t parsed_all_subframes; ///< all subframes decoded?
+ uint8_t drc_gain; ///< gain for the DRC tool
+ int8_t skip_frame; ///< skip output step
+ int8_t parsed_all_subframes; ///< all subframes decoded?
/* subframe/block decode state */
- int16_t subframe_len; ///< current subframe length
- int8_t channels_for_cur_subframe; ///< number of channels that contain the subframe
- int8_t channel_indexes_for_cur_subframe[WMALL_MAX_CHANNELS];
- int8_t num_bands; ///< number of scale factor bands
- int8_t transmit_num_vec_coeffs; ///< number of vector coded coefficients is part of the bitstream
- int16_t* cur_sfb_offsets; ///< sfb offsets for the current block
- uint8_t table_idx; ///< index for the num_sfb, sfb_offsets, sf_offsets and subwoofer_cutoffs tables
- int8_t esc_len; ///< length of escaped coefficients
-
- uint8_t num_chgroups; ///< number of channel groups
- WmallChannelGrp chgroup[WMALL_MAX_CHANNELS]; ///< channel group information
+ int16_t subframe_len; ///< current subframe length
+ int8_t channels_for_cur_subframe; ///< number of channels that contain the subframe
+ int8_t channel_indexes_for_cur_subframe[WMALL_MAX_CHANNELS];
WmallChannelCtx channel[WMALL_MAX_CHANNELS]; ///< per channel data
- // WMA lossless
+ // WMA Lossless-specific
uint8_t do_arith_coding;
uint8_t do_ac_filter;
@@ -232,41 +117,38 @@ typedef struct WmallDecodeCtx {
uint8_t do_mclms;
uint8_t do_lpc;
- int8_t acfilter_order;
- int8_t acfilter_scaling;
+ int8_t acfilter_order;
+ int8_t acfilter_scaling;
int64_t acfilter_coeffs[16];
- int acfilter_prevvalues[2][16];
+ int acfilter_prevvalues[2][16];
- int8_t mclms_order;
- int8_t mclms_scaling;
+ int8_t mclms_order;
+ int8_t mclms_scaling;
int16_t mclms_coeffs[128];
int16_t mclms_coeffs_cur[4];
- int mclms_prevvalues[64]; // FIXME: should be 32-bit / 16-bit depending on bit-depth
+ int16_t mclms_prevvalues[64];
int16_t mclms_updates[64];
- int mclms_recent;
+ int mclms_recent;
- int movave_scaling;
- int quant_stepsize;
+ int movave_scaling;
+ int quant_stepsize;
struct {
- int order;
- int scaling;
- int coefsend;
- int bitsend;
- int16_t coefs[256];
- int lms_prevvalues[512]; // FIXME: see above
- int16_t lms_updates[512]; // and here too
- int recent;
- } cdlms[2][9]; /* XXX: Here, 2 is the max. no. of channels allowed,
- 9 is the maximum no. of filters per channel.
- Question is, why 2 if WMALL_MAX_CHANNELS == 8 */
-
+ int order;
+ int scaling;
+ int coefsend;
+ int bitsend;
+ int16_t coefs[256];
+ int16_t lms_prevvalues[512];
+ int16_t lms_updates[512];
+ int recent;
+ } cdlms[2][9];
int cdlms_ttl[2];
int bV3RTM;
- int is_channel_coded[2]; // XXX: same question as above applies here too (and below)
+ int is_channel_coded[2];
int update_speed[2];
int transient[2];
@@ -277,139 +159,76 @@ typedef struct WmallDecodeCtx {
int channel_residues[2][2048];
-
int lpc_coefs[2][40];
int lpc_order;
int lpc_scaling;
int lpc_intbits;
- int channel_coeffs[2][2048]; // FIXME: should be 32-bit / 16-bit depending on bit-depth
-
+ int channel_coeffs[2][2048];
} WmallDecodeCtx;
-#undef dprintf
-#define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
-
-
-static int num_logged_tiles = 0;
-static int num_logged_subframes = 0;
-static int num_lms_update_call = 0;
-
-/**
- *@brief helper function to print the most important members of the context
- *@param s context
- */
-static void av_cold dump_context(WmallDecodeCtx *s)
-{
-#define PRINT(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b);
-#define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %x\n", a, b);
-
- PRINT("ed sample bit depth", s->bits_per_sample);
- PRINT_HEX("ed decode flags", s->decode_flags);
- PRINT("samples per frame", s->samples_per_frame);
- PRINT("log2 frame size", s->log2_frame_size);
- PRINT("max num subframes", s->max_num_subframes);
- PRINT("len prefix", s->len_prefix);
- PRINT("num channels", s->num_channels);
-}
-
-static void dump_int_buffer(uint8_t *buffer, int size, int length, int delimiter)
-{
- int i;
-
- for (i=0 ; i<length ; i++) {
- if (!(i%delimiter))
- av_log(0, 0, "\n[%d] ", i);
- av_log(0, 0, "%d, ", *(int16_t *)(buffer + i * size));
- }
- av_log(0, 0, "\n");
-}
-
-/**
- *@brief Uninitialize the decoder and free all resources.
- *@param avctx codec context
- *@return 0 on success, < 0 otherwise
- */
-static av_cold int decode_end(AVCodecContext *avctx)
-{
- WmallDecodeCtx *s = avctx->priv_data;
- int i;
-
- for (i = 0; i < WMALL_BLOCK_SIZES; i++)
- ff_mdct_end(&s->mdct_ctx[i]);
-
- return 0;
-}
-
-/**
- *@brief Initialize the decoder.
- *@param avctx codec context
- *@return 0 on success, -1 otherwise
- */
static av_cold int decode_init(AVCodecContext *avctx)
{
- WmallDecodeCtx *s = avctx->priv_data;
+ WmallDecodeCtx *s = avctx->priv_data;
uint8_t *edata_ptr = avctx->extradata;
unsigned int channel_mask;
- int i;
- int log2_max_num_subframes;
- int num_possible_block_sizes;
+ int i, log2_max_num_subframes, num_possible_block_sizes;
s->avctx = avctx;
- dsputil_init(&s->dsp, avctx);
init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
if (avctx->extradata_size >= 18) {
- s->decode_flags = AV_RL16(edata_ptr+14);
- channel_mask = AV_RL32(edata_ptr+2);
+ s->decode_flags = AV_RL16(edata_ptr + 14);
+ channel_mask = AV_RL32(edata_ptr + 2);
s->bits_per_sample = AV_RL16(edata_ptr);
if (s->bits_per_sample == 16)
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
- else if (s->bits_per_sample == 24)
+ else if (s->bits_per_sample == 24) {
avctx->sample_fmt = AV_SAMPLE_FMT_S32;
- else {
+ av_log_missing_feature(avctx, "bit-depth higher than 16", 0);
+ return AVERROR_PATCHWELCOME;
+ } else {
av_log(avctx, AV_LOG_ERROR, "Unknown bit-depth: %d\n",
s->bits_per_sample);
return AVERROR_INVALIDDATA;
}
- /** dump the extradata */
+ /* dump the extradata */
for (i = 0; i < avctx->extradata_size; i++)
- dprintf(avctx, "[%x] ", avctx->extradata[i]);
- dprintf(avctx, "\n");
+ av_dlog(avctx, AV_LOG_DEBUG, "[%x] ", avctx->extradata[i]);
+ av_dlog(avctx, AV_LOG_DEBUG, "\n");
} else {
- av_log_ask_for_sample(avctx, "Unknown extradata size\n");
+ av_log_ask_for_sample(avctx, "Unsupported extradata size\n");
return AVERROR_INVALIDDATA;
}
- /** generic init */
+ /* generic init */
s->log2_frame_size = av_log2(avctx->block_align) + 4;
- /** frame info */
+ /* frame info */
s->skip_frame = 1; /* skip first frame */
s->packet_loss = 1;
- s->len_prefix = (s->decode_flags & 0x40);
+ s->len_prefix = s->decode_flags & 0x40;
- /** get frame len */
+ /* get frame len */
s->samples_per_frame = 1 << ff_wma_get_frame_len_bits(avctx->sample_rate,
3, s->decode_flags);
- /** init previous block len */
+ /* init previous block len */
for (i = 0; i < avctx->channels; i++)
s->channel[i].prev_block_len = s->samples_per_frame;
- /** subframe info */
- log2_max_num_subframes = ((s->decode_flags & 0x38) >> 3);
+ /* subframe info */
+ log2_max_num_subframes = (s->decode_flags & 0x38) >> 3;
s->max_num_subframes = 1 << log2_max_num_subframes;
s->max_subframe_len_bit = 0;
s->subframe_len_bits = av_log2(log2_max_num_subframes) + 1;
num_possible_block_sizes = log2_max_num_subframes + 1;
s->min_samples_per_subframe = s->samples_per_frame / s->max_num_subframes;
- s->dynamic_range_compression = (s->decode_flags & 0x80);
-
- s->bV3RTM = s->decode_flags & 0x100;
+ s->dynamic_range_compression = s->decode_flags & 0x80;
+ s->bV3RTM = s->decode_flags & 0x100;
if (s->max_num_subframes > MAX_SUBFRAMES) {
av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %i\n",
@@ -419,19 +238,19 @@ static av_cold int decode_init(AVCodecContext *avctx)
s->num_channels = avctx->channels;
- /** extract lfe channel position */
+ /* extract lfe channel position */
s->lfe_channel = -1;
if (channel_mask & 8) {
unsigned int mask;
- for (mask = 1; mask < 16; mask <<= 1) {
+ for (mask = 1; mask < 16; mask <<= 1)
if (channel_mask & mask)
++s->lfe_channel;
- }
}
if (s->num_channels < 0) {
- av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->num_channels);
+ av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n",
+ s->num_channels);
return AVERROR_INVALIDDATA;
} else if (s->num_channels > WMALL_MAX_CHANNELS) {
av_log_ask_for_sample(avctx, "unsupported number of channels\n");
@@ -439,33 +258,30 @@ static av_cold int decode_init(AVCodecContext *avctx)
}
avcodec_get_frame_defaults(&s->frame);
- avctx->coded_frame = &s->frame;
-
+ avctx->coded_frame = &s->frame;
avctx->channel_layout = channel_mask;
return 0;
}
/**
- *@brief Decode the subframe length.
- *@param s context
- *@param offset sample offset in the frame
- *@return decoded subframe length on success, < 0 in case of an error
+ * @brief Decode the subframe length.
+ * @param s context
+ * @param offset sample offset in the frame
+ * @return decoded subframe length on success, < 0 in case of an error
*/
static int decode_subframe_length(WmallDecodeCtx *s, int offset)
{
- int frame_len_ratio;
- int subframe_len, len;
+ int frame_len_ratio, subframe_len, len;
- /** no need to read from the bitstream when only one length is possible */
+ /* no need to read from the bitstream when only one length is possible */
if (offset == s->samples_per_frame - s->min_samples_per_subframe)
return s->min_samples_per_subframe;
- len = av_log2(s->max_num_subframes - 1) + 1;
+ len = av_log2(s->max_num_subframes - 1) + 1;
frame_len_ratio = get_bits(&s->gb, len);
+ subframe_len = s->min_samples_per_subframe * (frame_len_ratio + 1);
- subframe_len = s->min_samples_per_subframe * (frame_len_ratio + 1);
-
- /** sanity check the length */
+ /* sanity check the length */
if (subframe_len < s->min_samples_per_subframe ||
subframe_len > s->samples_per_frame) {
av_log(s->avctx, AV_LOG_ERROR, "broken frame: subframe_len %i\n",
@@ -476,7 +292,7 @@ static int decode_subframe_length(WmallDecodeCtx *s, int offset)
}
/**
- *@brief Decode how the data in the frame is split into subframes.
+ * @brief Decode how the data in the frame is split into subframes.
* Every WMA frame contains the encoded data for a fixed number of
* samples per channel. The data for every channel might be split
* into several subframes. This function will reconstruct the list of
@@ -492,38 +308,31 @@ static int decode_subframe_length(WmallDecodeCtx *s, int offset)
* The algorithm repeats these steps until the frame is properly divided
* between the individual channels.
*
- *@param s context
- *@return 0 on success, < 0 in case of an error
+ * @param s context
+ * @return 0 on success, < 0 in case of an error
*/
static int decode_tilehdr(WmallDecodeCtx *s)
{
- uint16_t num_samples[WMALL_MAX_CHANNELS]; /**< sum of samples for all currently known subframes of a channel */
- uint8_t contains_subframe[WMALL_MAX_CHANNELS]; /**< flag indicating if a channel contains the current subframe */
- int channels_for_cur_subframe = s->num_channels; /**< number of channels that contain the current subframe */
- int fixed_channel_layout = 0; /**< flag indicating that all channels use the same subfra2me offsets and sizes */
- int min_channel_len = 0; /**< smallest sum of samples (channels with this length will be processed first) */
- int c;
-
- /* Should never consume more than 3073 bits (256 iterations for the
- * while loop when always the minimum amount of 128 samples is substracted
- * from missing samples in the 8 channel case).
- * 1 + BLOCK_MAX_SIZE * MAX_CHANNELS / BLOCK_MIN_SIZE * (MAX_CHANNELS + 4)
- */
-
- /** reset tiling information */
+ uint16_t num_samples[WMALL_MAX_CHANNELS] = { 0 }; /* sum of samples for all currently known subframes of a channel */
+ uint8_t contains_subframe[WMALL_MAX_CHANNELS]; /* flag indicating if a channel contains the current subframe */
+ int channels_for_cur_subframe = s->num_channels; /* number of channels that contain the current subframe */
+ int fixed_channel_layout = 0; /* flag indicating that all channels use the same subfra2me offsets and sizes */
+ int min_channel_len = 0; /* smallest sum of samples (channels with this length will be processed first) */
+ int c, tile_aligned;
+
+ /* reset tiling information */
for (c = 0; c < s->num_channels; c++)
s->channel[c].num_subframes = 0;
- memset(num_samples, 0, sizeof(num_samples));
-
- if (s->max_num_subframes == 1 || get_bits1(&s->gb))
+ tile_aligned = get_bits1(&s->gb);
+ if (s->max_num_subframes == 1 || tile_aligned)
fixed_channel_layout = 1;
- /** loop until the frame data is split between the subframes */
+ /* loop until the frame data is split between the subframes */
do {
int subframe_len;
- /** check which channels contain the subframe */
+ /* check which channels contain the subframe */
for (c = 0; c < s->num_channels; c++) {
if (num_samples[c] == min_channel_len) {
if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
@@ -536,13 +345,13 @@ static int decode_tilehdr(WmallDecodeCtx *s)
contains_subframe[c] = 0;
}
- /** get subframe length, subframe_len == 0 is not allowed */
+ /* get subframe length, subframe_len == 0 is not allowed */
if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0)
return AVERROR_INVALIDDATA;
- /** add subframes to the individual channels and find new min_channel_len */
+ /* add subframes to the individual channels and find new min_channel_len */
min_channel_len += subframe_len;
for (c = 0; c < s->num_channels; c++) {
- WmallChannelCtx* chan = &s->channel[c];
+ WmallChannelCtx *chan = &s->channel[c];
if (contains_subframe[c]) {
if (chan->num_subframes >= MAX_SUBFRAMES) {
@@ -570,10 +379,9 @@ static int decode_tilehdr(WmallDecodeCtx *s)
} while (min_channel_len < s->samples_per_frame);
for (c = 0; c < s->num_channels; c++) {
- int i;
- int offset = 0;
+ int i, offset = 0;
for (i = 0; i < s->channel[c].num_subframes; i++) {
- s->channel[c].subframe_offset[i] = offset;
+ s->channel[c].subframe_offsets[i] = offset;
offset += s->channel[c].subframe_len[i];
}
}
@@ -581,215 +389,175 @@ static int decode_tilehdr(WmallDecodeCtx *s)
return 0;
}
-
-static int my_log2(unsigned int i)
-{
- unsigned int iLog2 = 0;
- while ((i >> iLog2) > 1)
- iLog2++;
- return iLog2;
-}
-
-
-/**
- *
- */
static void decode_ac_filter(WmallDecodeCtx *s)
{
int i;
- s->acfilter_order = get_bits(&s->gb, 4) + 1;
+ s->acfilter_order = get_bits(&s->gb, 4) + 1;
s->acfilter_scaling = get_bits(&s->gb, 4);
- for(i = 0; i < s->acfilter_order; i++) {
+ for (i = 0; i < s->acfilter_order; i++)
s->acfilter_coeffs[i] = get_bits(&s->gb, s->acfilter_scaling) + 1;
- }
}
-
-/**
- *
- */
static void decode_mclms(WmallDecodeCtx *s)
{
- s->mclms_order = (get_bits(&s->gb, 4) + 1) * 2;
+ s->mclms_order = (get_bits(&s->gb, 4) + 1) * 2;
s->mclms_scaling = get_bits(&s->gb, 4);
- if(get_bits1(&s->gb)) {
- // mclms_send_coef
- int i;
- int send_coef_bits;
+ if (get_bits1(&s->gb)) {
+ int i, send_coef_bits;
int cbits = av_log2(s->mclms_scaling + 1);
assert(cbits == my_log2(s->mclms_scaling + 1));
- if(1 << cbits < s->mclms_scaling + 1)
+ if (1 << cbits < s->mclms_scaling + 1)
cbits++;
send_coef_bits = (cbits ? get_bits(&s->gb, cbits) : 0) + 2;
- for(i = 0; i < s->mclms_order * s->num_channels * s->num_channels; i++) {
+ for (i = 0; i < s->mclms_order * s->num_channels * s->num_channels; i++)
s->mclms_coeffs[i] = get_bits(&s->gb, send_coef_bits);
- }
- for(i = 0; i < s->num_channels; i++) {
+ for (i = 0; i < s->num_channels; i++) {
int c;
- for(c = 0; c < i; c++) {
+ for (c = 0; c < i; c++)
s->mclms_coeffs_cur[i * s->num_channels + c] = get_bits(&s->gb, send_coef_bits);
- }
}
}
}
-
-/**
- *
- */
static void decode_cdlms(WmallDecodeCtx *s)
{
int c, i;
int cdlms_send_coef = get_bits1(&s->gb);
- for(c = 0; c < s->num_channels; c++) {
+ for (c = 0; c < s->num_channels; c++) {
s->cdlms_ttl[c] = get_bits(&s->gb, 3) + 1;
- for(i = 0; i < s->cdlms_ttl[c]; i++) {
+ for (i = 0; i < s->cdlms_ttl[c]; i++)
s->cdlms[c][i].order = (get_bits(&s->gb, 7) + 1) * 8;
- }
- for(i = 0; i < s->cdlms_ttl[c]; i++) {
+ for (i = 0; i < s->cdlms_ttl[c]; i++)
s->cdlms[c][i].scaling = get_bits(&s->gb, 4);
- }
- if(cdlms_send_coef) {
- for(i = 0; i < s->cdlms_ttl[c]; i++) {
+ if (cdlms_send_coef) {
+ for (i = 0; i < s->cdlms_ttl[c]; i++) {
int cbits, shift_l, shift_r, j;
cbits = av_log2(s->cdlms[c][i].order);
- if(1 << cbits < s->cdlms[c][i].order)
+ if ((1 << cbits) < s->cdlms[c][i].order)
cbits++;
s->cdlms[c][i].coefsend = get_bits(&s->gb, cbits) + 1;
cbits = av_log2(s->cdlms[c][i].scaling + 1);
- if(1 << cbits < s->cdlms[c][i].scaling + 1)
+ if ((1 << cbits) < s->cdlms[c][i].scaling + 1)
cbits++;
s->cdlms[c][i].bitsend = get_bits(&s->gb, cbits) + 2;
shift_l = 32 - s->cdlms[c][i].bitsend;
- shift_r = 32 - 2 - s->cdlms[c][i].scaling;
- for(j = 0; j < s->cdlms[c][i].coefsend; j++) {
+ shift_r = 32 - s->cdlms[c][i].scaling - 2;
+ for (j = 0; j < s->cdlms[c][i].coefsend; j++)
s->cdlms[c][i].coefs[j] =
(get_bits(&s->gb, s->cdlms[c][i].bitsend) << shift_l) >> shift_r;
- }
}
}
}
}
-/**
- *
- */
static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
{
int i = 0;
unsigned int ave_mean;
s->transient[ch] = get_bits1(&s->gb);
- if(s->transient[ch]) {
- s->transient_pos[ch] = get_bits(&s->gb, av_log2(tile_size));
+ if (s->transient[ch]) {
+ s->transient_pos[ch] = get_bits(&s->gb, av_log2(tile_size));
if (s->transient_pos[ch])
- s->transient[ch] = 0;
- s->channel[ch].transient_counter =
- FFMAX(s->channel[ch].transient_counter, s->samples_per_frame / 2);
- } else if (s->channel[ch].transient_counter)
- s->transient[ch] = 1;
+ s->transient[ch] = 0;
+ s->channel[ch].transient_counter =
+ FFMAX(s->channel[ch].transient_counter, s->samples_per_frame / 2);
+ } else if (s->channel[ch].transient_counter)
+ s->transient[ch] = 1;
- if(s->seekable_tile) {
+ if (s->seekable_tile) {
ave_mean = get_bits(&s->gb, s->bits_per_sample);
s->ave_sum[ch] = ave_mean << (s->movave_scaling + 1);
-// s->ave_sum[ch] *= 2;
}
- if(s->seekable_tile) {
- if(s->do_inter_ch_decorr)
+ if (s->seekable_tile) {
+ if (s->do_inter_ch_decorr)
s->channel_residues[ch][0] = get_sbits(&s->gb, s->bits_per_sample + 1);
else
s->channel_residues[ch][0] = get_sbits(&s->gb, s->bits_per_sample);
i++;
}
- //av_log(0, 0, "%8d: ", num_logged_tiles++);
- for(; i < tile_size; i++) {
+ for (; i < tile_size; i++) {
int quo = 0, rem, rem_bits, residue;
while(get_bits1(&s->gb)) {
quo++;
if (get_bits_left(&s->gb) <= 0)
return -1;
}
- if(quo >= 32)
+ if (quo >= 32)
quo += get_bits_long(&s->gb, get_bits(&s->gb, 5) + 1);
- ave_mean = (s->ave_sum[ch] + (1 << s->movave_scaling)) >> (s->movave_scaling + 1);
- if (ave_mean <= 1)
- residue = quo;
- else
- {
- rem_bits = av_ceil_log2(ave_mean);
- rem = rem_bits ? get_bits(&s->gb, rem_bits) : 0;
- residue = (quo << rem_bits) + rem;
- }
+ ave_mean = (s->ave_sum[ch] + (1 << s->movave_scaling)) >> (s->movave_scaling + 1);
+ if (ave_mean <= 1)
+ residue = quo;
+ else {
+ rem_bits = av_ceil_log2(ave_mean);
+ rem = rem_bits ? get_bits(&s->gb, rem_bits) : 0;
+ residue = (quo << rem_bits) + rem;
+ }
- s->ave_sum[ch] = residue + s->ave_sum[ch] - (s->ave_sum[ch] >> s->movave_scaling);
+ s->ave_sum[ch] = residue + s->ave_sum[ch] -
+ (s->ave_sum[ch] >> s->movave_scaling);
- if(residue & 1)
+ if (residue & 1)
residue = -(residue >> 1) - 1;
else
residue = residue >> 1;
s->channel_residues[ch][i] = residue;
}
- //dump_int_buffer(s->channel_residues[ch], 4, tile_size, 16);
return 0;
}
-
-/**
- *
- */
-static void
-decode_lpc(WmallDecodeCtx *s)
+static void decode_lpc(WmallDecodeCtx *s)
{
int ch, i, cbits;
- s->lpc_order = get_bits(&s->gb, 5) + 1;
+ s->lpc_order = get_bits(&s->gb, 5) + 1;
s->lpc_scaling = get_bits(&s->gb, 4);
s->lpc_intbits = get_bits(&s->gb, 3) + 1;
cbits = s->lpc_scaling + s->lpc_intbits;
- for(ch = 0; ch < s->num_channels; ch++) {
- for(i = 0; i < s->lpc_order; i++) {
+ for (ch = 0; ch < s->num_channels; ch++)
+ for (i = 0; i < s->lpc_order; i++)
s->lpc_coefs[ch][i] = get_sbits(&s->gb, cbits);
- }
- }
}
-
static void clear_codec_buffers(WmallDecodeCtx *s)
{
int ich, ilms;
- memset(s->acfilter_coeffs , 0, 16 * sizeof(int));
- memset(s->acfilter_prevvalues, 0, 16 * 2 * sizeof(int)); // may be wrong
- memset(s->lpc_coefs , 0, 40 * 2 * sizeof(int));
+ memset(s->acfilter_coeffs, 0, sizeof(s->acfilter_coeffs));
+ memset(s->acfilter_prevvalues, 0, sizeof(s->acfilter_prevvalues));
+ memset(s->lpc_coefs, 0, sizeof(s->lpc_coefs));
- memset(s->mclms_coeffs , 0, 128 * sizeof(int16_t));
- memset(s->mclms_coeffs_cur, 0, 4 * sizeof(int16_t));
- memset(s->mclms_prevvalues, 0, 64 * sizeof(int));
- memset(s->mclms_updates , 0, 64 * sizeof(int16_t));
+ memset(s->mclms_coeffs, 0, sizeof(s->mclms_coeffs));
+ memset(s->mclms_coeffs_cur, 0, sizeof(s->mclms_coeffs_cur));
+ memset(s->mclms_prevvalues, 0, sizeof(s->mclms_prevvalues));
+ memset(s->mclms_updates, 0, sizeof(s->mclms_updates));
for (ich = 0; ich < s->num_channels; ich++) {
for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++) {
- memset(s->cdlms[ich][ilms].coefs , 0, 256 * sizeof(int16_t));
- memset(s->cdlms[ich][ilms].lms_prevvalues, 0, 512 * sizeof(int));
- memset(s->cdlms[ich][ilms].lms_updates , 0, 512 * sizeof(int16_t));
+ memset(s->cdlms[ich][ilms].coefs, 0,
+ sizeof(s->cdlms[ich][ilms].coefs));
+ memset(s->cdlms[ich][ilms].lms_prevvalues, 0,
+ sizeof(s->cdlms[ich][ilms].lms_prevvalues));
+ memset(s->cdlms[ich][ilms].lms_updates, 0,
+ sizeof(s->cdlms[ich][ilms].lms_updates));
}
s->ave_sum[ich] = 0;
}
}
/**
- *@brief Resets filter parameters and transient area at new seekable tile
+ * @brief Reset filter parameters and transient area at new seekable tile.
*/
static void reset_codec(WmallDecodeCtx *s)
{
@@ -799,23 +567,19 @@ static void reset_codec(WmallDecodeCtx *s)
for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++)
s->cdlms[ich][ilms].recent = s->cdlms[ich][ilms].order;
/* first sample of a seekable subframe is considered as the starting of
- a transient area which is samples_per_frame samples long */
+ a transient area which is samples_per_frame samples long */
s->channel[ich].transient_counter = s->samples_per_frame;
- s->transient[ich] = 1;
+ s->transient[ich] = 1;
s->transient_pos[ich] = 0;
}
}
-
-
static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
{
- int i, j, ich;
- int pred_error;
- int order = s->mclms_order;
+ int i, j, ich, pred_error;
+ int order = s->mclms_order;
int num_channels = s->num_channels;
- int range = 1 << (s->bits_per_sample - 1);
- //int bps = s->bits_per_sample > 16 ? 4 : 2; // bytes per sample
+ int range = 1 << (s->bits_per_sample - 1);
for (ich = 0; ich < num_channels; ich++) {
pred_error = s->channel_residues[ich][icoef] - pred[ich];
@@ -860,7 +624,7 @@ static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
if (s->mclms_recent == 0) {
memcpy(&s->mclms_prevvalues[order * num_channels],
s->mclms_prevvalues,
- 4 * order * num_channels);
+ 2 * order * num_channels);
memcpy(&s->mclms_updates[order * num_channels],
s->mclms_updates,
2 * order * num_channels);
@@ -871,7 +635,7 @@ static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
static void mclms_predict(WmallDecodeCtx *s, int icoef, int *pred)
{
int ich, i;
- int order = s->mclms_order;
+ int order = s->mclms_order;
int num_channels = s->num_channels;
for (ich = 0; ich < num_channels; ich++) {
@@ -892,7 +656,7 @@ static void mclms_predict(WmallDecodeCtx *s, int icoef, int *pred)
static void revert_mclms(WmallDecodeCtx *s, int tile_size)
{
- int icoef, pred[WMALL_MAX_CHANNELS] = {0};
+ int icoef, pred[WMALL_MAX_CHANNELS] = { 0 };
for (icoef = 0; icoef < tile_size; icoef++) {
mclms_predict(s, icoef, pred);
mclms_update(s, icoef, pred);
@@ -901,28 +665,22 @@ static void revert_mclms(WmallDecodeCtx *s, int tile_size)
static int lms_predict(WmallDecodeCtx *s, int ich, int ilms)
{
- int pred = 0;
- int icoef;
+ int pred = 0, icoef;
int recent = s->cdlms[ich][ilms].recent;
for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
pred += s->cdlms[ich][ilms].coefs[icoef] *
- s->cdlms[ich][ilms].lms_prevvalues[icoef + recent];
+ s->cdlms[ich][ilms].lms_prevvalues[icoef + recent];
- //pred += (1 << (s->cdlms[ich][ilms].scaling - 1));
- /* XXX: Table 29 has:
- iPred >= cdlms[iCh][ilms].scaling;
- seems to me like a missing > */
- //pred >>= s->cdlms[ich][ilms].scaling;
return pred;
}
-static void lms_update(WmallDecodeCtx *s, int ich, int ilms, int input, int residue)
+static void lms_update(WmallDecodeCtx *s, int ich, int ilms,
+ int input, int residue)
{
int icoef;
int recent = s->cdlms[ich][ilms].recent;
- int range = 1 << s->bits_per_sample - 1;
- //int bps = s->bits_per_sample > 16 ? 4 : 2; // bytes per sample
+ int range = 1 << s->bits_per_sample - 1;
if (residue < 0) {
for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
@@ -931,18 +689,15 @@ static void lms_update(WmallDecodeCtx *s, int ich, int ilms, int input, int resi
} else if (residue > 0) {
for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
s->cdlms[ich][ilms].coefs[icoef] +=
- s->cdlms[ich][ilms].lms_updates[icoef + recent]; /* spec mistakenly
- dropped the recent */
+ s->cdlms[ich][ilms].lms_updates[icoef + recent];
}
if (recent)
recent--;
else {
- /* XXX: This memcpy()s will probably fail if a fixed 32-bit buffer is used.
- follow kshishkov's suggestion of using a union. */
memcpy(&s->cdlms[ich][ilms].lms_prevvalues[s->cdlms[ich][ilms].order],
s->cdlms[ich][ilms].lms_prevvalues,
- 4 * s->cdlms[ich][ilms].order);
+ 2 * s->cdlms[ich][ilms].order);
memcpy(&s->cdlms[ich][ilms].lms_updates[s->cdlms[ich][ilms].order],
s->cdlms[ich][ilms].lms_updates,
2 * s->cdlms[ich][ilms].order);
@@ -957,14 +712,6 @@ static void lms_update(WmallDecodeCtx *s, int ich, int ilms, int input, int resi
else
s->cdlms[ich][ilms].lms_updates[recent] = s->update_speed[ich];
- /* XXX: spec says:
- cdlms[iCh][ilms].updates[iRecent + cdlms[iCh][ilms].order >> 4] >>= 2;
- lms_updates[iCh][ilms][iRecent + cdlms[iCh][ilms].order >> 3] >>= 1;
-
- Questions is - are cdlms[iCh][ilms].updates[] and lms_updates[][][] two
- seperate buffers? Here I've assumed that the two are same which makes
- more sense to me.
- */
s->cdlms[ich][ilms].lms_updates[recent + (s->cdlms[ich][ilms].order >> 4)] >>= 2;
s->cdlms[ich][ilms].lms_updates[recent + (s->cdlms[ich][ilms].order >> 3)] >>= 1;
s->cdlms[ich][ilms].recent = recent;
@@ -995,27 +742,23 @@ static void use_normal_update_speed(WmallDecodeCtx *s, int ich)
recent = s->cdlms[ich][ilms].recent;
if (s->update_speed[ich] == 8)
continue;
- if (s->bV3RTM) {
+ if (s->bV3RTM)
for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
s->cdlms[ich][ilms].lms_updates[icoef + recent] /= 2;
- } else {
+ else
for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
s->cdlms[ich][ilms].lms_updates[icoef] /= 2;
- }
}
s->update_speed[ich] = 8;
}
-static void revert_cdlms(WmallDecodeCtx *s, int ch, int coef_begin, int coef_end)
+static void revert_cdlms(WmallDecodeCtx *s, int ch,
+ int coef_begin, int coef_end)
{
- int icoef;
- int pred;
- int ilms, num_lms;
- int residue, input;
+ int icoef, pred, ilms, num_lms, residue, input;
num_lms = s->cdlms_ttl[ch];
for (ilms = num_lms - 1; ilms >= 0; ilms--) {
- //s->cdlms[ch][ilms].recent = s->cdlms[ch][ilms].order;
for (icoef = coef_begin; icoef < coef_end; icoef++) {
pred = 1 << (s->cdlms[ch][ilms].scaling - 1);
residue = s->channel_residues[ch][icoef];
@@ -1029,10 +772,10 @@ static void revert_cdlms(WmallDecodeCtx *s, int ch, int coef_begin, int coef_end
static void revert_inter_ch_decorr(WmallDecodeCtx *s, int tile_size)
{
- int icoef;
if (s->num_channels != 2)
return;
else if (s->is_channel_coded[0] && s->is_channel_coded[1]) {
+ int icoef;
for (icoef = 0; icoef < tile_size; icoef++) {
s->channel_residues[0][icoef] -= s->channel_residues[1][icoef] >> 1;
s->channel_residues[1][icoef] += s->channel_residues[0][icoef];
@@ -1042,12 +785,10 @@ static void revert_inter_ch_decorr(WmallDecodeCtx *s, int tile_size)
static void revert_acfilter(WmallDecodeCtx *s, int tile_size)
{
- int ich, icoef;
- int pred;
- int i, j;
+ int ich, pred, i, j;
int64_t *filter_coeffs = s->acfilter_coeffs;
- int scaling = s->acfilter_scaling;
- int order = s->acfilter_order;
+ int scaling = s->acfilter_scaling;
+ int order = s->acfilter_order;
for (ich = 0; ich < s->num_channels; ich++) {
int *prevvalues = s->acfilter_prevvalues[ich];
@@ -1074,28 +815,19 @@ static void revert_acfilter(WmallDecodeCtx *s, int tile_size)
}
}
-/**
- *@brief Decode a single subframe (block).
- *@param s codec context
- *@return 0 on success, < 0 when decoding failed
- */
static int decode_subframe(WmallDecodeCtx *s)
{
- int offset = s->samples_per_frame;
- int subframe_len = s->samples_per_frame;
- int i, j;
- int total_samples = s->samples_per_frame * s->num_channels;
- int rawpcm_tile;
- int padding_zeroes;
+ int offset = s->samples_per_frame;
+ int subframe_len = s->samples_per_frame;
+ int total_samples = s->samples_per_frame * s->num_channels;
+ int i, j, rawpcm_tile, padding_zeroes;
s->subframe_offset = get_bits_count(&s->gb);
- /** reset channel context and find the next block offset and size
+ /* reset channel context and find the next block offset and size
== the next block of the channel with the smallest number of
- decoded samples
- */
+ decoded samples */
for (i = 0; i < s->num_channels; i++) {
- s->channel[i].grouped = 0;
if (offset > s->channel[i].decoded_samples) {
offset = s->channel[i].decoded_samples;
subframe_len =
@@ -1103,14 +835,14 @@ static int decode_subframe(WmallDecodeCtx *s)
}
}
- /** get a list of all channels that contain the estimated block */
+ /* get a list of all channels that contain the estimated block */
s->channels_for_cur_subframe = 0;
for (i = 0; i < s->num_channels; i++) {
const int cur_subframe = s->channel[i].cur_subframe;
- /** substract already processed samples */
+ /* subtract already processed samples */
total_samples -= s->channel[i].decoded_samples;
- /** and count if there are multiple subframes that match our profile */
+ /* and count if there are multiple subframes that match our profile */
if (offset == s->channel[i].decoded_samples &&
subframe_len == s->channel[i].subframe_len[cur_subframe]) {
total_samples -= s->channel[i].subframe_len[cur_subframe];
@@ -1121,95 +853,89 @@ static int decode_subframe(WmallDecodeCtx *s)
}
}
- /** check if the frame will be complete after processing the
+ /* check if the frame will be complete after processing the
estimated block */
if (!total_samples)
s->parsed_all_subframes = 1;
s->seekable_tile = get_bits1(&s->gb);
- if(s->seekable_tile) {
+ if (s->seekable_tile) {
clear_codec_buffers(s);
s->do_arith_coding = get_bits1(&s->gb);
- if(s->do_arith_coding) {
- dprintf(s->avctx, "do_arith_coding == 1");
+ if (s->do_arith_coding) {
+ av_dlog(s->avctx, AV_LOG_DEBUG, "do_arith_coding == 1");
abort();
}
s->do_ac_filter = get_bits1(&s->gb);
s->do_inter_ch_decorr = get_bits1(&s->gb);
s->do_mclms = get_bits1(&s->gb);
- if(s->do_ac_filter)
+ if (s->do_ac_filter)
decode_ac_filter(s);
- if(s->do_mclms)
+ if (s->do_mclms)
decode_mclms(s);
decode_cdlms(s);
s->movave_scaling = get_bits(&s->gb, 3);
s->quant_stepsize = get_bits(&s->gb, 8) + 1;
- reset_codec(s);
+ reset_codec(s);
}
rawpcm_tile = get_bits1(&s->gb);
- for(i = 0; i < s->num_channels; i++) {
+ for (i = 0; i < s->num_channels; i++)
s->is_channel_coded[i] = 1;
- }
- if(!rawpcm_tile) {
-
- for(i = 0; i < s->num_channels; i++) {
+ if (!rawpcm_tile) {
+ for (i = 0; i < s->num_channels; i++)
s->is_channel_coded[i] = get_bits1(&s->gb);
- }
- if(s->bV3RTM) {
+ if (s->bV3RTM) {
// LPC
s->do_lpc = get_bits1(&s->gb);
- if(s->do_lpc) {
+ if (s->do_lpc) {
decode_lpc(s);
+ av_log_ask_for_sample(s->avctx, "Inverse LPC filter not "
+ "implemented. Expect wrong output.\n");
}
- } else {
+ } else
s->do_lpc = 0;
- }
}
- if(get_bits1(&s->gb)) {
+ if (get_bits1(&s->gb))
padding_zeroes = get_bits(&s->gb, 5);
- } else {
+ else
padding_zeroes = 0;
- }
-
- if(rawpcm_tile) {
+ if (rawpcm_tile) {
int bits = s->bits_per_sample - padding_zeroes;
- dprintf(s->avctx, "RAWPCM %d bits per sample. total %d bits, remain=%d\n", bits,
+ av_dlog(s->avctx, AV_LOG_DEBUG, "RAWPCM %d bits per sample. "
+ "total %d bits, remain=%d\n", bits,
bits * s->num_channels * subframe_len, get_bits_count(&s->gb));
- for(i = 0; i < s->num_channels; i++) {
- for(j = 0; j < subframe_len; j++) {
+ for (i = 0; i < s->num_channels; i++)
+ for (j = 0; j < subframe_len; j++)
s->channel_coeffs[i][j] = get_sbits(&s->gb, bits);
-// dprintf(s->avctx, "PCM[%d][%d] = 0x%04x\n", i, j, s->channel_coeffs[i][j]);
- }
- }
} else {
- for(i = 0; i < s->num_channels; i++)
- if(s->is_channel_coded[i]) {
- decode_channel_residues(s, i, subframe_len);
- if (s->seekable_tile)
- use_high_update_speed(s, i);
- else
- use_normal_update_speed(s, i);
- revert_cdlms(s, i, 0, subframe_len);
- }
+ for (i = 0; i < s->num_channels; i++)
+ if (s->is_channel_coded[i]) {
+ decode_channel_residues(s, i, subframe_len);
+ if (s->seekable_tile)
+ use_high_update_speed(s, i);
+ else
+ use_normal_update_speed(s, i);
+ revert_cdlms(s, i, 0, subframe_len);
+ }
}
if (s->do_mclms)
revert_mclms(s, subframe_len);
if (s->do_inter_ch_decorr)
revert_inter_ch_decorr(s, subframe_len);
- if(s->do_ac_filter)
+ if (s->do_ac_filter)
revert_acfilter(s, subframe_len);
/* Dequantize */
@@ -1218,7 +944,7 @@ static int decode_subframe(WmallDecodeCtx *s)
for (j = 0; j < subframe_len; j++)
s->channel_residues[i][j] *= s->quant_stepsize;
- // Write to proper output buffer depending on bit-depth
+ /* Write to proper output buffer depending on bit-depth */
for (i = 0; i < subframe_len; i++)
for (j = 0; j < s->num_channels; j++) {
if (s->bits_per_sample == 16)
@@ -1227,8 +953,7 @@ static int decode_subframe(WmallDecodeCtx *s)
*s->samples_32++ = s->channel_residues[j][i];
}
- /** handled one subframe */
-
+ /* handled one subframe */
for (i = 0; i < s->channels_for_cur_subframe; i++) {
int c = s->channel_indexes_for_cur_subframe[i];
if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) {
@@ -1237,77 +962,72 @@ static int decode_subframe(WmallDecodeCtx *s)
}
++s->channel[c].cur_subframe;
}
- num_logged_subframes++;
return 0;
}
/**
- *@brief Decode one WMA frame.
- *@param s codec context
- *@return 0 if the trailer bit indicates that this is the last frame,
- * 1 if there are additional frames
+ * @brief Decode one WMA frame.
+ * @param s codec context
+ * @return 0 if the trailer bit indicates that this is the last frame,
+ * 1 if there are additional frames
*/
static int decode_frame(WmallDecodeCtx *s)
{
GetBitContext* gb = &s->gb;
- int more_frames = 0;
- int len = 0;
- int i, ret;
+ int more_frames = 0, len = 0, i, ret;
s->frame.nb_samples = s->samples_per_frame;
if ((ret = s->avctx->get_buffer(s->avctx, &s->frame)) < 0) {
- /** return an error if no frame could be decoded at all */
+ /* return an error if no frame could be decoded at all */
av_log(s->avctx, AV_LOG_ERROR,
"not enough space for the output samples\n");
s->packet_loss = 1;
- return 0;
+ return ret;
}
s->samples_16 = (int16_t *)s->frame.data[0];
s->samples_32 = (int32_t *)s->frame.data[0];
- /** get frame length */
+ /* get frame length */
if (s->len_prefix)
len = get_bits(gb, s->log2_frame_size);
- /** decode tile information */
+ /* decode tile information */
if (decode_tilehdr(s)) {
s->packet_loss = 1;
return 0;
}
- /** read drc info */
- if (s->dynamic_range_compression) {
+ /* read drc info */
+ if (s->dynamic_range_compression)
s->drc_gain = get_bits(gb, 8);
- }
- /** no idea what these are for, might be the number of samples
- that need to be skipped at the beginning or end of a stream */
+ /* no idea what these are for, might be the number of samples
+ that need to be skipped at the beginning or end of a stream */
if (get_bits1(gb)) {
int skip;
- /** usually true for the first frame */
+ /* usually true for the first frame */
if (get_bits1(gb)) {
skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
- dprintf(s->avctx, "start skip: %i\n", skip);
+ av_dlog(s->avctx, AV_LOG_DEBUG, "start skip: %i\n", skip);
}
- /** sometimes true for the last frame */
+ /* sometimes true for the last frame */
if (get_bits1(gb)) {
skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
- dprintf(s->avctx, "end skip: %i\n", skip);
+ av_dlog(s->avctx, AV_LOG_DEBUG, "end skip: %i\n", skip);
}
}
- /** reset subframe states */
+ /* reset subframe states */
s->parsed_all_subframes = 0;
for (i = 0; i < s->num_channels; i++) {
s->channel[i].decoded_samples = 0;
s->channel[i].cur_subframe = 0;
- s->channel[i].reuse_sf = 0;
}
- /** decode all subframes */
+ /* decode all subframes */
while (!s->parsed_all_subframes) {
if (decode_subframe(s) < 0) {
s->packet_loss = 1;
@@ -1315,15 +1035,14 @@ static int decode_frame(WmallDecodeCtx *s)
}
}
- dprintf(s->avctx, "Frame done\n");
+ av_dlog(s->avctx, AV_LOG_DEBUG, "Frame done\n");
- if (s->skip_frame) {
+ if (s->skip_frame)
s->skip_frame = 0;
- }
if (s->len_prefix) {
if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
- /** FIXME: not sure if this is always an error */
+ /* FIXME: not sure if this is always an error */
av_log(s->avctx, AV_LOG_ERROR,
"frame[%i] would have to skip %i bits\n", s->frame_num,
len - (get_bits_count(gb) - s->frame_offset) - 1);
@@ -1331,27 +1050,21 @@ static int decode_frame(WmallDecodeCtx *s)
return 0;
}
- /** skip the rest of the frame data */
+ /* skip the rest of the frame data */
skip_bits_long(gb, len - (get_bits_count(gb) - s->frame_offset) - 1);
- } else {
-/*
- while (get_bits_count(gb) < s->num_saved_bits && get_bits1(gb) == 0) {
- dprintf(s->avctx, "skip1\n");
- }
-*/
}
- /** decode trailer bit */
+ /* decode trailer bit */
more_frames = get_bits1(gb);
++s->frame_num;
return more_frames;
}
/**
- *@brief Calculate remaining input buffer length.
- *@param s codec context
- *@param gb bitstream reader context
- *@return remaining size in bits
+ * @brief Calculate remaining input buffer length.
+ * @param s codec context
+ * @param gb bitstream reader context
+ * @return remaining size in bits
*/
static int remaining_bits(WmallDecodeCtx *s, GetBitContext *gb)
{
@@ -1359,23 +1072,24 @@ static int remaining_bits(WmallDecodeCtx *s, GetBitContext *gb)
}
/**
- *@brief Fill the bit reservoir with a (partial) frame.
- *@param s codec context
- *@param gb bitstream reader context
- *@param len length of the partial frame
- *@param append decides wether to reset the buffer or not
+ * @brief Fill the bit reservoir with a (partial) frame.
+ * @param s codec context
+ * @param gb bitstream reader context
+ * @param len length of the partial frame
+ * @param append decides whether to reset the buffer or not
*/
static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len,
int append)
{
int buflen;
+ PutBitContext tmp;
- /** when the frame data does not need to be concatenated, the input buffer
- is resetted and additional bits from the previous frame are copyed
+ /* when the frame data does not need to be concatenated, the input buffer
+ is reset and additional bits from the previous frame are copied
and skipped later so that a fast byte copy is possible */
if (!append) {
- s->frame_offset = get_bits_count(gb) & 7;
+ s->frame_offset = get_bits_count(gb) & 7;
s->num_saved_bits = s->frame_offset;
init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
}
@@ -1391,7 +1105,7 @@ static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len,
s->num_saved_bits += len;
if (!append) {
avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3),
- s->num_saved_bits);
+ s->num_saved_bits);
} else {
int align = 8 - (get_bits_count(gb) & 7);
align = FFMIN(align, len);
@@ -1401,57 +1115,52 @@ static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len,
}
skip_bits_long(gb, len);
- {
- PutBitContext tmp = s->pb;
- flush_put_bits(&tmp);
- }
+ tmp = s->pb;
+ flush_put_bits(&tmp);
init_get_bits(&s->gb, s->frame_data, s->num_saved_bits);
skip_bits(&s->gb, s->frame_offset);
}
/**
- *@brief Decode a single WMA packet.
- *@param avctx codec context
- *@param data the output buffer
- *@param data_size number of bytes that were written to the output buffer
- *@param avpkt input packet
- *@return number of bytes that were read from the input buffer
+ * @brief Decode a single WMA packet.
+ * @param avctx codec context
+ * @param data the output buffer
+ * @param data_size number of bytes that were written to the output buffer
+ * @param avpkt input packet
+ * @return number of bytes that were read from the input buffer
*/
-static int decode_packet(AVCodecContext *avctx,
- void *data, int *got_frame_ptr, AVPacket* avpkt)
+static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr,
+ AVPacket* avpkt)
{
WmallDecodeCtx *s = avctx->priv_data;
GetBitContext* gb = &s->pgb;
const uint8_t* buf = avpkt->data;
int buf_size = avpkt->size;
- int num_bits_prev_frame;
- int packet_sequence_number;
- int seekable_frame_in_packet;
- int spliced_packet;
+ int num_bits_prev_frame, packet_sequence_number,
+ seekable_frame_in_packet, spliced_packet;
if (s->packet_done || s->packet_loss) {
- int seekable_frame_in_packet, spliced_packet;
s->packet_done = 0;
- /** sanity check for the buffer length */
+ /* sanity check for the buffer length */
if (buf_size < avctx->block_align)
return 0;
s->next_packet_start = buf_size - avctx->block_align;
- buf_size = avctx->block_align;
- s->buf_bit_size = buf_size << 3;
+ buf_size = avctx->block_align;
+ s->buf_bit_size = buf_size << 3;
- /** parse packet header */
+ /* parse packet header */
init_get_bits(gb, buf, s->buf_bit_size);
- packet_sequence_number = get_bits(gb, 4);
+ packet_sequence_number = get_bits(gb, 4);
seekable_frame_in_packet = get_bits1(gb);
- spliced_packet = get_bits1(gb);
+ spliced_packet = get_bits1(gb);
- /** get number of bits that need to be added to the previous frame */
+ /* get number of bits that need to be added to the previous frame */
num_bits_prev_frame = get_bits(gb, s->log2_frame_size);
- /** check for packet loss */
+ /* check for packet loss */
if (!s->packet_loss &&
((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
s->packet_loss = 1;
@@ -1467,24 +1176,23 @@ static int decode_packet(AVCodecContext *avctx,
s->packet_done = 1;
}
- /** append the previous frame data to the remaining data from the
- previous packet to create a full frame */
+ /* Append the previous frame data to the remaining data from the
+ * previous packet to create a full frame. */
save_bits(s, gb, num_bits_prev_frame, 1);
- /** decode the cross packet frame if it is valid */
+ /* decode the cross packet frame if it is valid */
if (!s->packet_loss)
decode_frame(s);
} else if (s->num_saved_bits - s->frame_offset) {
- dprintf(avctx, "ignoring %x previously saved bits\n",
+ av_dlog(avctx, AV_LOG_DEBUG, "ignoring %x previously saved bits\n",
s->num_saved_bits - s->frame_offset);
}
if (s->packet_loss) {
- /** reset number of saved bits so that the decoder
- does not start to decode incomplete frames in the
- s->len_prefix == 0 case */
+ /* Reset number of saved bits so that the decoder does not start
+ * to decode incomplete frames in the s->len_prefix == 0 case. */
s->num_saved_bits = 0;
- s->packet_loss = 0;
+ s->packet_loss = 0;
}
} else {
@@ -1501,13 +1209,12 @@ static int decode_packet(AVCodecContext *avctx,
s->packet_done = !decode_frame(s);
} else if (!s->len_prefix
&& s->num_saved_bits > get_bits_count(&s->gb)) {
- /** when the frames do not have a length prefix, we don't know
- the compressed length of the individual frames
- however, we know what part of a new packet belongs to the
- previous frame
- therefore we save the incoming packet first, then we append
- the "previous frame" data from the next packet so that
- we get a buffer that only contains full frames */
+ /* when the frames do not have a length prefix, we don't know the
+ * compressed length of the individual frames however, we know what
+ * part of a new packet belongs to the previous frame therefore we
+ * save the incoming packet first, then we append the "previous
+ * frame" data from the next packet so that we get a buffer that
+ * only contains full frames */
s->packet_done = !decode_frame(s);
} else {
s->packet_done = 1;
@@ -1516,47 +1223,26 @@ static int decode_packet(AVCodecContext *avctx,
if (s->packet_done && !s->packet_loss &&
remaining_bits(s, gb) > 0) {
- /** save the rest of the data so that it can be decoded
- with the next packet */
+ /* save the rest of the data so that it can be decoded
+ * with the next packet */
save_bits(s, gb, remaining_bits(s, gb), 0);
}
*(AVFrame *)data = s->frame;
- *got_frame_ptr = 1;
+ *got_frame_ptr = 1;
s->packet_offset = get_bits_count(gb) & 7;
return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3;
}
-/**
- *@brief Clear decoder buffers (for seeking).
- *@param avctx codec context
- */
-static void flush(AVCodecContext *avctx)
-{
- WmallDecodeCtx *s = avctx->priv_data;
- int i;
- /** reset output buffer as a part of it is used during the windowing of a
- new frame */
- for (i = 0; i < s->num_channels; i++)
- memset(s->channel[i].out, 0, s->samples_per_frame *
- sizeof(*s->channel[i].out));
- s->packet_loss = 1;
-}
-
-/**
- *@brief wmall decoder
- */
AVCodec ff_wmalossless_decoder = {
.name = "wmalossless",
.type = AVMEDIA_TYPE_AUDIO,
.id = CODEC_ID_WMALOSSLESS,
.priv_data_size = sizeof(WmallDecodeCtx),
.init = decode_init,
- .close = decode_end,
.decode = decode_packet,
- .flush = flush,
- .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_EXPERIMENTAL | CODEC_CAP_DR1,
- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 9 Lossless"),
+ .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1,
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio Lossless"),
};
diff --git a/libavcodec/wnv1.c b/libavcodec/wnv1.c
index 6429a5b748..5ce5e9db51 100644
--- a/libavcodec/wnv1.c
+++ b/libavcodec/wnv1.c
@@ -64,7 +64,7 @@ static int decode_frame(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
WNV1Context * const l = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&l->pic;
+ AVFrame * const p = &l->pic;
unsigned char *Y,*U,*V;
int i, j;
int prev_y = 0, prev_u = 0, prev_v = 0;
diff --git a/libavcodec/x86/h264_qpel_10bit.asm b/libavcodec/x86/h264_qpel_10bit.asm
index 51412e3977..bdacf9f472 100644
--- a/libavcodec/x86/h264_qpel_10bit.asm
+++ b/libavcodec/x86/h264_qpel_10bit.asm
@@ -619,7 +619,7 @@ MC MC33
%define PAD 12
%define COUNT 2
%else
-%define PAD 0
+%define PAD 4
%define COUNT 3
%endif
put_hv%2_10_%1:
diff --git a/libavcodec/x86/vp8dsp-init.c b/libavcodec/x86/vp8dsp-init.c
index a75fdf5bc5..e3b727d1b1 100644
--- a/libavcodec/x86/vp8dsp-init.c
+++ b/libavcodec/x86/vp8dsp-init.c
@@ -29,98 +29,98 @@
/*
* MC functions
*/
-extern void ff_put_vp8_epel4_h4_mmxext(uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel4_h4_mmxext(uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel4_h6_mmxext(uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel4_h6_mmxext(uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel4_v4_mmxext(uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel4_v4_mmxext(uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel4_v6_mmxext(uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel4_v6_mmxext(uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel8_h4_sse2 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel8_h4_sse2 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel8_h6_sse2 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel8_h6_sse2 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel8_v4_sse2 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel8_v4_sse2 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel8_v6_sse2 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel8_v6_sse2 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel4_h4_ssse3 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel4_h4_ssse3 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel4_h6_ssse3 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel4_h6_ssse3 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel4_v4_ssse3 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel4_v4_ssse3 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel4_v6_ssse3 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel4_v6_ssse3 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel8_h4_ssse3 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel8_h4_ssse3 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel8_h6_ssse3 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel8_h6_ssse3 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel8_v4_ssse3 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel8_v4_ssse3 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_epel8_v6_ssse3 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_epel8_v6_ssse3 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_bilinear4_h_mmxext(uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_bilinear4_h_mmxext(uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_bilinear8_h_sse2 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_bilinear8_h_sse2 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_bilinear4_h_ssse3 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_bilinear4_h_ssse3 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_bilinear8_h_ssse3 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_bilinear8_h_ssse3 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_bilinear4_v_mmxext(uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_bilinear4_v_mmxext(uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_bilinear8_v_sse2 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_bilinear8_v_sse2 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_bilinear4_v_ssse3 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_bilinear4_v_ssse3 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_bilinear8_v_ssse3 (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_bilinear8_v_ssse3 (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_pixels8_mmx (uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_pixels8_mmx (uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_pixels16_mmx(uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_pixels16_mmx(uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
-extern void ff_put_vp8_pixels16_sse(uint8_t *dst, int dststride,
- uint8_t *src, int srcstride,
+extern void ff_put_vp8_pixels16_sse(uint8_t *dst, ptrdiff_t dststride,
+ uint8_t *src, ptrdiff_t srcstride,
int height, int mx, int my);
#define TAP_W16(OPT, FILTERTYPE, TAPTYPE) \
static void ff_put_vp8_ ## FILTERTYPE ## 16_ ## TAPTYPE ## _ ## OPT( \
- uint8_t *dst, int dststride, uint8_t *src, \
- int srcstride, int height, int mx, int my) \
+ uint8_t *dst, ptrdiff_t dststride, uint8_t *src, \
+ ptrdiff_t srcstride, int height, int mx, int my) \
{ \
ff_put_vp8_ ## FILTERTYPE ## 8_ ## TAPTYPE ## _ ## OPT( \
dst, dststride, src, srcstride, height, mx, my); \
@@ -129,8 +129,8 @@ static void ff_put_vp8_ ## FILTERTYPE ## 16_ ## TAPTYPE ## _ ## OPT( \
}
#define TAP_W8(OPT, FILTERTYPE, TAPTYPE) \
static void ff_put_vp8_ ## FILTERTYPE ## 8_ ## TAPTYPE ## _ ## OPT( \
- uint8_t *dst, int dststride, uint8_t *src, \
- int srcstride, int height, int mx, int my) \
+ uint8_t *dst, ptrdiff_t dststride, uint8_t *src, \
+ ptrdiff_t srcstride, int height, int mx, int my) \
{ \
ff_put_vp8_ ## FILTERTYPE ## 4_ ## TAPTYPE ## _ ## OPT( \
dst, dststride, src, srcstride, height, mx, my); \
@@ -138,6 +138,7 @@ static void ff_put_vp8_ ## FILTERTYPE ## 8_ ## TAPTYPE ## _ ## OPT( \
dst + 4, dststride, src + 4, srcstride, height, mx, my); \
}
+#if ARCH_X86_32
TAP_W8 (mmxext, epel, h4)
TAP_W8 (mmxext, epel, h6)
TAP_W16(mmxext, epel, h6)
@@ -148,6 +149,7 @@ TAP_W8 (mmxext, bilinear, h)
TAP_W16(mmxext, bilinear, h)
TAP_W8 (mmxext, bilinear, v)
TAP_W16(mmxext, bilinear, v)
+#endif
TAP_W16(sse2, epel, h6)
TAP_W16(sse2, epel, v6)
@@ -161,8 +163,8 @@ TAP_W16(ssse3, bilinear, v)
#define HVTAP(OPT, ALIGN, TAPNUMX, TAPNUMY, SIZE, MAXHEIGHT) \
static void ff_put_vp8_epel ## SIZE ## _h ## TAPNUMX ## v ## TAPNUMY ## _ ## OPT( \
- uint8_t *dst, int dststride, uint8_t *src, \
- int srcstride, int height, int mx, int my) \
+ uint8_t *dst, ptrdiff_t dststride, uint8_t *src, \
+ ptrdiff_t srcstride, int height, int mx, int my) \
{ \
DECLARE_ALIGNED(ALIGN, uint8_t, tmp)[SIZE * (MAXHEIGHT + TAPNUMY - 1)]; \
uint8_t *tmpptr = tmp + SIZE * (TAPNUMY / 2 - 1); \
@@ -173,15 +175,21 @@ static void ff_put_vp8_epel ## SIZE ## _h ## TAPNUMX ## v ## TAPNUMY ## _ ## OPT
dst, dststride, tmpptr, SIZE, height, mx, my); \
}
+#if ARCH_X86_32
#define HVTAPMMX(x, y) \
HVTAP(mmxext, 8, x, y, 4, 8) \
HVTAP(mmxext, 8, x, y, 8, 16)
+HVTAP(mmxext, 8, 6, 6, 16, 16)
+#else
+#define HVTAPMMX(x, y) \
+HVTAP(mmxext, 8, x, y, 4, 8)
+#endif
+
HVTAPMMX(4, 4)
HVTAPMMX(4, 6)
HVTAPMMX(6, 4)
HVTAPMMX(6, 6)
-HVTAP(mmxext, 8, 6, 6, 16, 16)
#define HVTAPSSE2(x, y, w) \
HVTAP(sse2, 16, x, y, w, 16) \
@@ -200,8 +208,8 @@ HVTAP(ssse3, 16, 6, 6, 4, 8)
#define HVBILIN(OPT, ALIGN, SIZE, MAXHEIGHT) \
static void ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT( \
- uint8_t *dst, int dststride, uint8_t *src, \
- int srcstride, int height, int mx, int my) \
+ uint8_t *dst, ptrdiff_t dststride, uint8_t *src, \
+ ptrdiff_t srcstride, int height, int mx, int my) \
{ \
DECLARE_ALIGNED(ALIGN, uint8_t, tmp)[SIZE * (MAXHEIGHT + 2)]; \
ff_put_vp8_bilinear ## SIZE ## _h_ ## OPT( \
@@ -211,43 +219,68 @@ static void ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT( \
}
HVBILIN(mmxext, 8, 4, 8)
+#if ARCH_X86_32
HVBILIN(mmxext, 8, 8, 16)
HVBILIN(mmxext, 8, 16, 16)
+#endif
HVBILIN(sse2, 8, 8, 16)
HVBILIN(sse2, 8, 16, 16)
HVBILIN(ssse3, 8, 4, 8)
HVBILIN(ssse3, 8, 8, 16)
HVBILIN(ssse3, 8, 16, 16)
-extern void ff_vp8_idct_dc_add_mmx(uint8_t *dst, DCTELEM block[16], int stride);
-extern void ff_vp8_idct_dc_add_sse4(uint8_t *dst, DCTELEM block[16], int stride);
-extern void ff_vp8_idct_dc_add4y_mmx(uint8_t *dst, DCTELEM block[4][16], int stride);
-extern void ff_vp8_idct_dc_add4y_sse2(uint8_t *dst, DCTELEM block[4][16], int stride);
-extern void ff_vp8_idct_dc_add4uv_mmx(uint8_t *dst, DCTELEM block[2][16], int stride);
+extern void ff_vp8_idct_dc_add_mmx(uint8_t *dst, DCTELEM block[16],
+ ptrdiff_t stride);
+extern void ff_vp8_idct_dc_add_sse4(uint8_t *dst, DCTELEM block[16],
+ ptrdiff_t stride);
+extern void ff_vp8_idct_dc_add4y_mmx(uint8_t *dst, DCTELEM block[4][16],
+ ptrdiff_t stride);
+extern void ff_vp8_idct_dc_add4y_sse2(uint8_t *dst, DCTELEM block[4][16],
+ ptrdiff_t stride);
+extern void ff_vp8_idct_dc_add4uv_mmx(uint8_t *dst, DCTELEM block[2][16],
+ ptrdiff_t stride);
extern void ff_vp8_luma_dc_wht_mmx(DCTELEM block[4][4][16], DCTELEM dc[16]);
extern void ff_vp8_luma_dc_wht_sse(DCTELEM block[4][4][16], DCTELEM dc[16]);
-extern void ff_vp8_idct_add_mmx(uint8_t *dst, DCTELEM block[16], int stride);
-extern void ff_vp8_idct_add_sse(uint8_t *dst, DCTELEM block[16], int stride);
+extern void ff_vp8_idct_add_mmx(uint8_t *dst, DCTELEM block[16],
+ ptrdiff_t stride);
+extern void ff_vp8_idct_add_sse(uint8_t *dst, DCTELEM block[16],
+ ptrdiff_t stride);
#define DECLARE_LOOP_FILTER(NAME)\
-extern void ff_vp8_v_loop_filter_simple_ ## NAME(uint8_t *dst, int stride, int flim);\
-extern void ff_vp8_h_loop_filter_simple_ ## NAME(uint8_t *dst, int stride, int flim);\
-extern void ff_vp8_v_loop_filter16y_inner_ ## NAME (uint8_t *dst, int stride,\
+extern void ff_vp8_v_loop_filter_simple_ ## NAME(uint8_t *dst, \
+ ptrdiff_t stride, \
+ int flim);\
+extern void ff_vp8_h_loop_filter_simple_ ## NAME(uint8_t *dst, \
+ ptrdiff_t stride, \
+ int flim);\
+extern void ff_vp8_v_loop_filter16y_inner_ ## NAME (uint8_t *dst, \
+ ptrdiff_t stride,\
+ int e, int i, int hvt);\
+extern void ff_vp8_h_loop_filter16y_inner_ ## NAME (uint8_t *dst, \
+ ptrdiff_t stride,\
+ int e, int i, int hvt);\
+extern void ff_vp8_v_loop_filter8uv_inner_ ## NAME (uint8_t *dstU, \
+ uint8_t *dstV,\
+ ptrdiff_t s, \
+ int e, int i, int hvt);\
+extern void ff_vp8_h_loop_filter8uv_inner_ ## NAME (uint8_t *dstU, \
+ uint8_t *dstV,\
+ ptrdiff_t s, \
int e, int i, int hvt);\
-extern void ff_vp8_h_loop_filter16y_inner_ ## NAME (uint8_t *dst, int stride,\
+extern void ff_vp8_v_loop_filter16y_mbedge_ ## NAME(uint8_t *dst, \
+ ptrdiff_t stride,\
int e, int i, int hvt);\
-extern void ff_vp8_v_loop_filter8uv_inner_ ## NAME (uint8_t *dstU, uint8_t *dstV,\
- int s, int e, int i, int hvt);\
-extern void ff_vp8_h_loop_filter8uv_inner_ ## NAME (uint8_t *dstU, uint8_t *dstV,\
- int s, int e, int i, int hvt);\
-extern void ff_vp8_v_loop_filter16y_mbedge_ ## NAME(uint8_t *dst, int stride,\
+extern void ff_vp8_h_loop_filter16y_mbedge_ ## NAME(uint8_t *dst, \
+ ptrdiff_t stride,\
int e, int i, int hvt);\
-extern void ff_vp8_h_loop_filter16y_mbedge_ ## NAME(uint8_t *dst, int stride,\
+extern void ff_vp8_v_loop_filter8uv_mbedge_ ## NAME(uint8_t *dstU, \
+ uint8_t *dstV,\
+ ptrdiff_t s, \
int e, int i, int hvt);\
-extern void ff_vp8_v_loop_filter8uv_mbedge_ ## NAME(uint8_t *dstU, uint8_t *dstV,\
- int s, int e, int i, int hvt);\
-extern void ff_vp8_h_loop_filter8uv_mbedge_ ## NAME(uint8_t *dstU, uint8_t *dstV,\
- int s, int e, int i, int hvt);
+extern void ff_vp8_h_loop_filter8uv_mbedge_ ## NAME(uint8_t *dstU, \
+ uint8_t *dstV,\
+ ptrdiff_t s, \
+ int e, int i, int hvt);
DECLARE_LOOP_FILTER(mmx)
DECLARE_LOOP_FILTER(mmxext)
@@ -288,15 +321,18 @@ av_cold void ff_vp8dsp_init_x86(VP8DSPContext* c)
if (mm_flags & AV_CPU_FLAG_MMX) {
c->vp8_idct_dc_add = ff_vp8_idct_dc_add_mmx;
- c->vp8_idct_dc_add4y = ff_vp8_idct_dc_add4y_mmx;
c->vp8_idct_dc_add4uv = ff_vp8_idct_dc_add4uv_mmx;
+#if ARCH_X86_32
+ c->vp8_idct_dc_add4y = ff_vp8_idct_dc_add4y_mmx;
c->vp8_idct_add = ff_vp8_idct_add_mmx;
c->vp8_luma_dc_wht = ff_vp8_luma_dc_wht_mmx;
c->put_vp8_epel_pixels_tab[0][0][0] =
c->put_vp8_bilinear_pixels_tab[0][0][0] = ff_put_vp8_pixels16_mmx;
+#endif
c->put_vp8_epel_pixels_tab[1][0][0] =
c->put_vp8_bilinear_pixels_tab[1][0][0] = ff_put_vp8_pixels8_mmx;
+#if ARCH_X86_32
c->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter_simple_mmx;
c->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter_simple_mmx;
@@ -309,17 +345,19 @@ av_cold void ff_vp8dsp_init_x86(VP8DSPContext* c)
c->vp8_h_loop_filter16y = ff_vp8_h_loop_filter16y_mbedge_mmx;
c->vp8_v_loop_filter8uv = ff_vp8_v_loop_filter8uv_mbedge_mmx;
c->vp8_h_loop_filter8uv = ff_vp8_h_loop_filter8uv_mbedge_mmx;
+#endif
}
/* note that 4-tap width=16 functions are missing because w=16
* is only used for luma, and luma is always a copy or sixtap. */
if (mm_flags & AV_CPU_FLAG_MMX2) {
+ VP8_MC_FUNC(2, 4, mmxext);
+ VP8_BILINEAR_MC_FUNC(2, 4, mmxext);
+#if ARCH_X86_32
VP8_LUMA_MC_FUNC(0, 16, mmxext);
VP8_MC_FUNC(1, 8, mmxext);
- VP8_MC_FUNC(2, 4, mmxext);
VP8_BILINEAR_MC_FUNC(0, 16, mmxext);
VP8_BILINEAR_MC_FUNC(1, 8, mmxext);
- VP8_BILINEAR_MC_FUNC(2, 4, mmxext);
c->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter_simple_mmxext;
c->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter_simple_mmxext;
@@ -333,6 +371,7 @@ av_cold void ff_vp8dsp_init_x86(VP8DSPContext* c)
c->vp8_h_loop_filter16y = ff_vp8_h_loop_filter16y_mbedge_mmxext;
c->vp8_v_loop_filter8uv = ff_vp8_v_loop_filter8uv_mbedge_mmxext;
c->vp8_h_loop_filter8uv = ff_vp8_h_loop_filter8uv_mbedge_mmxext;
+#endif
}
if (mm_flags & AV_CPU_FLAG_SSE) {
diff --git a/libavcodec/x86/vp8dsp.asm b/libavcodec/x86/vp8dsp.asm
index 833c88a1a0..140597031f 100644
--- a/libavcodec/x86/vp8dsp.asm
+++ b/libavcodec/x86/vp8dsp.asm
@@ -865,6 +865,7 @@ cglobal put_vp8_pixels8_mmx, 5,5
jg .nextrow
REP_RET
+%if ARCH_X86_32
cglobal put_vp8_pixels16_mmx, 5,5
.nextrow:
movq mm0, [r2+r3*0+0]
@@ -880,6 +881,7 @@ cglobal put_vp8_pixels16_mmx, 5,5
sub r4d, 2
jg .nextrow
REP_RET
+%endif
cglobal put_vp8_pixels16_sse, 5,5,2
.nextrow:
@@ -973,6 +975,7 @@ cglobal vp8_idct_dc_add_sse4, 3, 3, 6
; void vp8_idct_dc_add4y_<opt>(uint8_t *dst, DCTELEM block[4][16], int stride);
;-----------------------------------------------------------------------------
+%if ARCH_X86_32
INIT_MMX
cglobal vp8_idct_dc_add4y_mmx, 3, 3
; load data
@@ -1007,6 +1010,7 @@ cglobal vp8_idct_dc_add4y_mmx, 3, 3
ADD_DC m0, m6, 0, mova
ADD_DC m1, m7, 8, mova
RET
+%endif
INIT_XMM
cglobal vp8_idct_dc_add4y_sse2, 3, 3, 6
@@ -1152,7 +1156,9 @@ cglobal vp8_idct_add_%1, 3, 3
RET
%endmacro
+%if ARCH_X86_32
VP8_IDCT_ADD mmx
+%endif
VP8_IDCT_ADD sse
;-----------------------------------------------------------------------------
@@ -1217,7 +1223,9 @@ cglobal vp8_luma_dc_wht_%1, 2,3
%endmacro
INIT_MMX
+%if ARCH_X86_32
VP8_DC_WHT mmx
+%endif
VP8_DC_WHT sse
;-----------------------------------------------------------------------------
@@ -1610,6 +1618,7 @@ cglobal vp8_%2_loop_filter_simple_%1, 3, %3, %4
%endif
%endmacro
+%if ARCH_X86_32
INIT_MMX
%define SPLATB_REG SPLATB_REG_MMX
SIMPLE_LOOPFILTER mmx, v, 4, 0
@@ -1617,6 +1626,8 @@ SIMPLE_LOOPFILTER mmx, h, 5, 0
%define SPLATB_REG SPLATB_REG_MMXEXT
SIMPLE_LOOPFILTER mmxext, v, 4, 0
SIMPLE_LOOPFILTER mmxext, h, 5, 0
+%endif
+
INIT_XMM
%define SPLATB_REG SPLATB_REG_SSE2
%define WRITE_8W WRITE_8W_SSE2
@@ -2118,6 +2129,7 @@ cglobal vp8_%2_loop_filter16y_inner_%1, 5, %3, %5
RET
%endmacro
+%if ARCH_X86_32
INIT_MMX
%define SPLATB_REG SPLATB_REG_MMX
INNER_LOOPFILTER mmx, v, 6, 16, 0
@@ -2130,6 +2142,7 @@ INNER_LOOPFILTER mmxext, v, 6, 16, 0
INNER_LOOPFILTER mmxext, h, 6, 16, 0
INNER_LOOPFILTER mmxext, v, 6, 8, 0
INNER_LOOPFILTER mmxext, h, 6, 8, 0
+%endif
INIT_XMM
%define SPLATB_REG SPLATB_REG_SSE2
@@ -2814,6 +2827,7 @@ cglobal vp8_%2_loop_filter16y_mbedge_%1, 5, %3, %5
RET
%endmacro
+%if ARCH_X86_32
INIT_MMX
%define SPLATB_REG SPLATB_REG_MMX
MBEDGE_LOOPFILTER mmx, v, 6, 16, 0
@@ -2826,6 +2840,7 @@ MBEDGE_LOOPFILTER mmxext, v, 6, 16, 0
MBEDGE_LOOPFILTER mmxext, h, 6, 16, 0
MBEDGE_LOOPFILTER mmxext, v, 6, 8, 0
MBEDGE_LOOPFILTER mmxext, h, 6, 8, 0
+%endif
INIT_XMM
%define SPLATB_REG SPLATB_REG_SSE2
diff --git a/libavcodec/xl.c b/libavcodec/xl.c
index 78f34afa4e..91a0df0683 100644
--- a/libavcodec/xl.c
+++ b/libavcodec/xl.c
@@ -45,7 +45,7 @@ static int decode_frame(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
VideoXLContext * const a = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&a->pic;
+ AVFrame * const p = &a->pic;
uint8_t *Y, *U, *V;
int i, j;
int stride;
diff --git a/libavcodec/zmbvenc.c b/libavcodec/zmbvenc.c
index abb34a9bdb..a7fdc280a5 100644
--- a/libavcodec/zmbvenc.c
+++ b/libavcodec/zmbvenc.c
@@ -313,7 +313,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
return -1;
}
- avctx->coded_frame = (AVFrame*)&c->pic;
+ avctx->coded_frame = &c->pic;
return 0;
}
diff --git a/libavformat/avs.c b/libavformat/avs.c
index 75efe15306..8f3dd27dae 100644
--- a/libavformat/avs.c
+++ b/libavformat/avs.c
@@ -188,8 +188,8 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt)
avs->st_video->codec->height = avs->height;
avs->st_video->codec->bits_per_coded_sample=avs->bits_per_sample;
avs->st_video->nb_frames = avs->nb_frames;
- avs->st_video->codec->time_base = (AVRational) {
- 1, avs->fps};
+ avs->st_video->r_frame_rate = avs->st_video->avg_frame_rate =
+ (AVRational){avs->fps, 1};
}
return avs_read_video_packet(s, pkt, type, sub_type, size,
palette, palette_size);
diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c
index 55cab7c70f..9719c6711a 100644
--- a/libavformat/electronicarts.c
+++ b/libavformat/electronicarts.c
@@ -283,6 +283,20 @@ static int process_video_header_vp6(AVFormatContext *s)
return 1;
}
+static int process_video_header_cmv(AVFormatContext *s)
+{
+ EaDemuxContext *ea = s->priv_data;
+ int fps;
+
+ avio_skip(s->pb, 10);
+ fps = avio_rl16(s->pb);
+ if (fps)
+ ea->time_base = (AVRational){1, fps};
+ ea->video_codec = CODEC_ID_CMV;
+
+ return 0;
+}
+
/*
* Process EA file header
* Returns 1 if the EA file is valid and successfully opened, 0 otherwise
@@ -330,7 +344,7 @@ static int process_ea_header(AVFormatContext *s) {
break;
case MVIh_TAG :
- ea->video_codec = CODEC_ID_CMV;
+ err = process_video_header_cmv(s);
break;
case kVGT_TAG:
@@ -418,10 +432,12 @@ static int ea_read_header(AVFormatContext *s)
if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO)
st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->codec->codec_tag = 0; /* no fourcc */
- if (ea->time_base.num)
- avpriv_set_pts_info(st, 64, ea->time_base.num, ea->time_base.den);
st->codec->width = ea->width;
st->codec->height = ea->height;
+ if (ea->time_base.num)
+ avpriv_set_pts_info(st, 64, ea->time_base.num, ea->time_base.den);
+ st->r_frame_rate = st->avg_frame_rate = (AVRational){ea->time_base.den,
+ ea->time_base.num};
}
if (ea->audio_codec) {
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 690eac6499..882660e668 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1921,15 +1921,31 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
if (!track->audio.pkt_cnt) {
if (track->audio.sub_packet_cnt == 0)
track->audio.buf_timecode = timecode;
- if (st->codec->codec_id == CODEC_ID_RA_288)
+ if (st->codec->codec_id == CODEC_ID_RA_288) {
+ if (size < cfs * h / 2) {
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Corrupt int4 RM-style audio packet size\n");
+ return AVERROR_INVALIDDATA;
+ }
for (x=0; x<h/2; x++)
memcpy(track->audio.buf+x*2*w+y*cfs,
data+x*cfs, cfs);
- else if (st->codec->codec_id == CODEC_ID_SIPR)
+ } else if (st->codec->codec_id == CODEC_ID_SIPR) {
+ if (size < w) {
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Corrupt sipr RM-style audio packet size\n");
+ return AVERROR_INVALIDDATA;
+ }
memcpy(track->audio.buf + y*w, data, w);
- else
+ } else {
+ if (size < sps * w / sps) {
+ av_log(matroska->ctx, AV_LOG_ERROR,
+ "Corrupt generic RM-style audio packet size\n");
+ return AVERROR_INVALIDDATA;
+ }
for (x=0; x<w/sps; x++)
memcpy(track->audio.buf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), data+x*sps, sps);
+ }
if (++track->audio.sub_packet_cnt >= h) {
if (st->codec->codec_id == CODEC_ID_SIPR)
diff --git a/libavformat/oggparseogm.c b/libavformat/oggparseogm.c
index 36f61c7680..a69e3baff1 100644
--- a/libavformat/oggparseogm.c
+++ b/libavformat/oggparseogm.c
@@ -84,9 +84,7 @@ ogm_header(AVFormatContext *s, int idx)
if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){
st->codec->width = bytestream_get_le32(&p);
st->codec->height = bytestream_get_le32(&p);
- st->codec->time_base.den = spu * 10000000;
- st->codec->time_base.num = time_unit;
- avpriv_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den);
+ avpriv_set_pts_info(st, 64, spu * 10000000, time_unit);
} else {
st->codec->channels = bytestream_get_le16(&p);
p += 2; /* block_align */
@@ -132,8 +130,7 @@ ogm_dshow_header(AVFormatContext *s, int idx)
if(t == 0x05589f80){
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(p + 68));
- st->codec->time_base.den = 10000000;
- st->codec->time_base.num = AV_RL64(p + 164);
+ avpriv_set_pts_info(st, 64, AV_RL64(p + 164), 10000000);
st->codec->width = AV_RL32(p + 176);
st->codec->height = AV_RL32(p + 180);
} else if(t == 0x05589f81){
diff --git a/libavformat/oggparsetheora.c b/libavformat/oggparsetheora.c
index 993db3ee55..d1559f4632 100644
--- a/libavformat/oggparsetheora.c
+++ b/libavformat/oggparsetheora.c
@@ -56,6 +56,7 @@ theora_header (AVFormatContext * s, int idx)
if (os->buf[os->pstart] == 0x80) {
GetBitContext gb;
int width, height;
+ AVRational timebase;
init_get_bits(&gb, os->buf + os->pstart, os->psize*8);
@@ -85,14 +86,14 @@ theora_header (AVFormatContext * s, int idx)
skip_bits(&gb, 16);
}
- st->codec->time_base.den = get_bits_long(&gb, 32);
- st->codec->time_base.num = get_bits_long(&gb, 32);
- if (!(st->codec->time_base.num > 0 && st->codec->time_base.den > 0)) {
+ timebase.den = get_bits_long(&gb, 32);
+ timebase.num = get_bits_long(&gb, 32);
+ if (!(timebase.num > 0 && timebase.den > 0)) {
av_log(s, AV_LOG_WARNING, "Invalid time base in theora stream, assuming 25 FPS\n");
- st->codec->time_base.num = 1;
- st->codec->time_base.den = 25;
+ timebase.num = 1;
+ timebase.den = 25;
}
- avpriv_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den);
+ avpriv_set_pts_info(st, 64, timebase.num, timebase.den);
st->sample_aspect_ratio.num = get_bits_long(&gb, 24);
st->sample_aspect_ratio.den = get_bits_long(&gb, 24);
diff --git a/libavformat/r3d.c b/libavformat/r3d.c
index 1e0e73ea6b..b37f065693 100644
--- a/libavformat/r3d.c
+++ b/libavformat/r3d.c
@@ -57,6 +57,7 @@ static int r3d_read_red1(AVFormatContext *s)
char filename[258];
int tmp;
int av_unused tmp2;
+ AVRational framerate;
if (!st)
return AVERROR(ENOMEM);
@@ -84,8 +85,10 @@ static int r3d_read_red1(AVFormatContext *s)
tmp = avio_rb16(s->pb); // unknown
av_dlog(s, "unknown2 %d\n", tmp);
- st->codec->time_base.den = avio_rb16(s->pb);
- st->codec->time_base.num = avio_rb16(s->pb);
+ framerate.num = avio_rb16(s->pb);
+ framerate.den = avio_rb16(s->pb);
+ if (framerate.num && framerate.den)
+ st->r_frame_rate = st->avg_frame_rate = framerate;
tmp = avio_r8(s->pb); // audio channels
av_dlog(s, "audio channels %d\n", tmp);
@@ -107,7 +110,7 @@ static int r3d_read_red1(AVFormatContext *s)
av_dlog(s, "resolution %dx%d\n", st->codec->width, st->codec->height);
av_dlog(s, "timescale %d\n", st->time_base.den);
av_dlog(s, "frame rate %d/%d\n",
- st->codec->time_base.num, st->codec->time_base.den);
+ framerate.num, framerate.den);
return 0;
}
@@ -132,9 +135,11 @@ static int r3d_read_rdvo(AVFormatContext *s, Atom *atom)
av_dlog(s, "video offset %d: %#x\n", i, r3d->video_offsets[i]);
}
- if (st->codec->time_base.den)
- st->duration = (uint64_t)r3d->video_offsets_count*
- st->time_base.den*st->codec->time_base.num/st->codec->time_base.den;
+ if (st->r_frame_rate.num)
+ st->duration = av_rescale_q(r3d->video_offsets_count,
+ (AVRational){st->r_frame_rate.den,
+ st->r_frame_rate.num},
+ st->time_base);
av_dlog(s, "duration %"PRId64"\n", st->duration);
return 0;
@@ -257,9 +262,9 @@ static int r3d_read_redv(AVFormatContext *s, AVPacket *pkt, Atom *atom)
pkt->stream_index = 0;
pkt->dts = dts;
- if (st->codec->time_base.den)
+ if (st->r_frame_rate.num)
pkt->duration = (uint64_t)st->time_base.den*
- st->codec->time_base.num/st->codec->time_base.den;
+ st->r_frame_rate.den/st->r_frame_rate.num;
av_dlog(s, "pkt dts %"PRId64" duration %d\n", pkt->dts, pkt->duration);
return 0;
@@ -357,11 +362,11 @@ static int r3d_seek(AVFormatContext *s, int stream_index, int64_t sample_time, i
R3DContext *r3d = s->priv_data;
int frame_num;
- if (!st->codec->time_base.num || !st->time_base.den)
+ if (!st->r_frame_rate.num)
return -1;
- frame_num = sample_time*st->codec->time_base.den/
- ((int64_t)st->codec->time_base.num*st->time_base.den);
+ frame_num = av_rescale_q(sample_time, st->time_base,
+ (AVRational){st->r_frame_rate.den, st->r_frame_rate.num});
av_dlog(s, "seek frame num %d timestamp %"PRId64"\n",
frame_num, sample_time);
diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 0245411baf..5fb43106c8 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -439,10 +439,8 @@ static int rm_read_header(AVFormatContext *s)
return AVERROR(EIO);
}
- avio_rb32(pb); /* header size */
- avio_rb16(pb);
- avio_rb32(pb);
- avio_rb32(pb); /* number of headers */
+ tag_size = avio_rb32(pb);
+ avio_skip(pb, tag_size - 8);
for(;;) {
if (url_feof(pb))
diff --git a/libswscale/ppc/yuv2rgb_altivec.c b/libswscale/ppc/yuv2rgb_altivec.c
index 8e84c26382..5c2e2c8196 100644
--- a/libswscale/ppc/yuv2rgb_altivec.c
+++ b/libswscale/ppc/yuv2rgb_altivec.c
@@ -21,75 +21,76 @@
*/
/*
-Convert I420 YV12 to RGB in various formats,
- it rejects images that are not in 420 formats,
- it rejects images that don't have widths of multiples of 16,
- it rejects images that don't have heights of multiples of 2.
-Reject defers to C simulation code.
-
-Lots of optimizations to be done here.
-
-1. Need to fix saturation code. I just couldn't get it to fly with packs
- and adds, so we currently use max/min to clip.
-
-2. The inefficient use of chroma loading needs a bit of brushing up.
-
-3. Analysis of pipeline stalls needs to be done. Use shark to identify
- pipeline stalls.
-
-
-MODIFIED to calculate coeffs from currently selected color space.
-MODIFIED core to be a macro where you specify the output format.
-ADDED UYVY conversion which is never called due to some thing in swscale.
-CORRECTED algorithim selection to be strict on input formats.
-ADDED runtime detection of AltiVec.
-
-ADDED altivec_yuv2packedX vertical scl + RGB converter
-
-March 27,2004
-PERFORMANCE ANALYSIS
-
-The C version uses 25% of the processor or ~250Mips for D1 video rawvideo
-used as test.
-The AltiVec version uses 10% of the processor or ~100Mips for D1 video
-same sequence.
-
-720 * 480 * 30 ~10MPS
-
-so we have roughly 10 clocks per pixel. This is too high, something has
-to be wrong.
-
-OPTIMIZED clip codes to utilize vec_max and vec_packs removing the
-need for vec_min.
-
-OPTIMIZED DST OUTPUT cache/DMA controls. We are pretty much guaranteed to have
-the input video frame, it was just decompressed so it probably resides in L1
-caches. However, we are creating the output video stream. This needs to use the
-DSTST instruction to optimize for the cache. We couple this with the fact that
-we are not going to be visiting the input buffer again so we mark it Least
-Recently Used. This shaves 25% of the processor cycles off.
-
-Now memcpy is the largest mips consumer in the system, probably due
-to the inefficient X11 stuff.
-
-GL libraries seem to be very slow on this machine 1.33Ghz PB running
-Jaguar, this is not the case for my 1Ghz PB. I thought it might be
-a versioning issue, however I have libGL.1.2.dylib for both
-machines. (We need to figure this out now.)
-
-GL2 libraries work now with patch for RGB32.
-
-NOTE: quartz vo driver ARGB32_to_RGB24 consumes 30% of the processor.
-
-Integrated luma prescaling adjustment for saturation/contrast/brightness
-adjustment.
-*/
+ * Convert I420 YV12 to RGB in various formats,
+ * it rejects images that are not in 420 formats,
+ * it rejects images that don't have widths of multiples of 16,
+ * it rejects images that don't have heights of multiples of 2.
+ * Reject defers to C simulation code.
+ *
+ * Lots of optimizations to be done here.
+ *
+ * 1. Need to fix saturation code. I just couldn't get it to fly with packs
+ * and adds, so we currently use max/min to clip.
+ *
+ * 2. The inefficient use of chroma loading needs a bit of brushing up.
+ *
+ * 3. Analysis of pipeline stalls needs to be done. Use shark to identify
+ * pipeline stalls.
+ *
+ *
+ * MODIFIED to calculate coeffs from currently selected color space.
+ * MODIFIED core to be a macro where you specify the output format.
+ * ADDED UYVY conversion which is never called due to some thing in swscale.
+ * CORRECTED algorithim selection to be strict on input formats.
+ * ADDED runtime detection of AltiVec.
+ *
+ * ADDED altivec_yuv2packedX vertical scl + RGB converter
+ *
+ * March 27,2004
+ * PERFORMANCE ANALYSIS
+ *
+ * The C version uses 25% of the processor or ~250Mips for D1 video rawvideo
+ * used as test.
+ * The AltiVec version uses 10% of the processor or ~100Mips for D1 video
+ * same sequence.
+ *
+ * 720 * 480 * 30 ~10MPS
+ *
+ * so we have roughly 10 clocks per pixel. This is too high, something has
+ * to be wrong.
+ *
+ * OPTIMIZED clip codes to utilize vec_max and vec_packs removing the
+ * need for vec_min.
+ *
+ * OPTIMIZED DST OUTPUT cache/DMA controls. We are pretty much guaranteed to
+ * have the input video frame, it was just decompressed so it probably resides
+ * in L1 caches. However, we are creating the output video stream. This needs
+ * to use the DSTST instruction to optimize for the cache. We couple this with
+ * the fact that we are not going to be visiting the input buffer again so we
+ * mark it Least Recently Used. This shaves 25% of the processor cycles off.
+ *
+ * Now memcpy is the largest mips consumer in the system, probably due
+ * to the inefficient X11 stuff.
+ *
+ * GL libraries seem to be very slow on this machine 1.33Ghz PB running
+ * Jaguar, this is not the case for my 1Ghz PB. I thought it might be
+ * a versioning issue, however I have libGL.1.2.dylib for both
+ * machines. (We need to figure this out now.)
+ *
+ * GL2 libraries work now with patch for RGB32.
+ *
+ * NOTE: quartz vo driver ARGB32_to_RGB24 consumes 30% of the processor.
+ *
+ * Integrated luma prescaling adjustment for saturation/contrast/brightness
+ * adjustment.
+ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <assert.h>
+
#include "config.h"
#include "libswscale/rgb2rgb.h"
#include "libswscale/swscale.h"
@@ -104,456 +105,451 @@ adjustment.
typedef unsigned char ubyte;
typedef signed char sbyte;
-
/* RGB interleaver, 16 planar pels 8-bit samples per channel in
- homogeneous vector registers x0,x1,x2 are interleaved with the
- following technique:
-
- o0 = vec_mergeh (x0,x1);
- o1 = vec_perm (o0, x2, perm_rgb_0);
- o2 = vec_perm (o0, x2, perm_rgb_1);
- o3 = vec_mergel (x0,x1);
- o4 = vec_perm (o3,o2,perm_rgb_2);
- o5 = vec_perm (o3,o2,perm_rgb_3);
-
- perm_rgb_0: o0(RG).h v1(B) --> o1*
- 0 1 2 3 4
- rgbr|gbrg|brgb|rgbr
- 0010 0100 1001 0010
- 0102 3145 2673 894A
-
- perm_rgb_1: o0(RG).h v1(B) --> o2
- 0 1 2 3 4
- gbrg|brgb|bbbb|bbbb
- 0100 1001 1111 1111
- B5CD 6EF7 89AB CDEF
-
- perm_rgb_2: o3(RG).l o2(rgbB.l) --> o4*
- 0 1 2 3 4
- gbrg|brgb|rgbr|gbrg
- 1111 1111 0010 0100
- 89AB CDEF 0182 3945
-
- perm_rgb_2: o3(RG).l o2(rgbB.l) ---> o5*
- 0 1 2 3 4
- brgb|rgbr|gbrg|brgb
- 1001 0010 0100 1001
- a67b 89cA BdCD eEFf
-
-*/
-static
-const vector unsigned char
- perm_rgb_0 = {0x00,0x01,0x10,0x02,0x03,0x11,0x04,0x05,
- 0x12,0x06,0x07,0x13,0x08,0x09,0x14,0x0a},
- perm_rgb_1 = {0x0b,0x15,0x0c,0x0d,0x16,0x0e,0x0f,0x17,
- 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f},
- perm_rgb_2 = {0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,
- 0x00,0x01,0x18,0x02,0x03,0x19,0x04,0x05},
- perm_rgb_3 = {0x1a,0x06,0x07,0x1b,0x08,0x09,0x1c,0x0a,
- 0x0b,0x1d,0x0c,0x0d,0x1e,0x0e,0x0f,0x1f};
-
-#define vec_merge3(x2,x1,x0,y0,y1,y2) \
-do { \
- __typeof__(x0) o0,o2,o3; \
- o0 = vec_mergeh (x0,x1); \
- y0 = vec_perm (o0, x2, perm_rgb_0); \
- o2 = vec_perm (o0, x2, perm_rgb_1); \
- o3 = vec_mergel (x0,x1); \
- y1 = vec_perm (o3,o2,perm_rgb_2); \
- y2 = vec_perm (o3,o2,perm_rgb_3); \
-} while(0)
-
-#define vec_mstbgr24(x0,x1,x2,ptr) \
-do { \
- __typeof__(x0) _0,_1,_2; \
- vec_merge3 (x0,x1,x2,_0,_1,_2); \
- vec_st (_0, 0, ptr++); \
- vec_st (_1, 0, ptr++); \
- vec_st (_2, 0, ptr++); \
-} while (0)
-
-#define vec_mstrgb24(x0,x1,x2,ptr) \
-do { \
- __typeof__(x0) _0,_1,_2; \
- vec_merge3 (x2,x1,x0,_0,_1,_2); \
- vec_st (_0, 0, ptr++); \
- vec_st (_1, 0, ptr++); \
- vec_st (_2, 0, ptr++); \
-} while (0)
+ * homogeneous vector registers x0,x1,x2 are interleaved with the
+ * following technique:
+ *
+ * o0 = vec_mergeh(x0, x1);
+ * o1 = vec_perm(o0, x2, perm_rgb_0);
+ * o2 = vec_perm(o0, x2, perm_rgb_1);
+ * o3 = vec_mergel(x0, x1);
+ * o4 = vec_perm(o3, o2, perm_rgb_2);
+ * o5 = vec_perm(o3, o2, perm_rgb_3);
+ *
+ * perm_rgb_0: o0(RG).h v1(B) --> o1*
+ * 0 1 2 3 4
+ * rgbr|gbrg|brgb|rgbr
+ * 0010 0100 1001 0010
+ * 0102 3145 2673 894A
+ *
+ * perm_rgb_1: o0(RG).h v1(B) --> o2
+ * 0 1 2 3 4
+ * gbrg|brgb|bbbb|bbbb
+ * 0100 1001 1111 1111
+ * B5CD 6EF7 89AB CDEF
+ *
+ * perm_rgb_2: o3(RG).l o2(rgbB.l) --> o4*
+ * 0 1 2 3 4
+ * gbrg|brgb|rgbr|gbrg
+ * 1111 1111 0010 0100
+ * 89AB CDEF 0182 3945
+ *
+ * perm_rgb_2: o3(RG).l o2(rgbB.l) ---> o5*
+ * 0 1 2 3 4
+ * brgb|rgbr|gbrg|brgb
+ * 1001 0010 0100 1001
+ * a67b 89cA BdCD eEFf
+ *
+ */
+static const vector unsigned char
+ perm_rgb_0 = { 0x00, 0x01, 0x10, 0x02, 0x03, 0x11, 0x04, 0x05,
+ 0x12, 0x06, 0x07, 0x13, 0x08, 0x09, 0x14, 0x0a },
+ perm_rgb_1 = { 0x0b, 0x15, 0x0c, 0x0d, 0x16, 0x0e, 0x0f, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
+ perm_rgb_2 = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x00, 0x01, 0x18, 0x02, 0x03, 0x19, 0x04, 0x05 },
+ perm_rgb_3 = { 0x1a, 0x06, 0x07, 0x1b, 0x08, 0x09, 0x1c, 0x0a,
+ 0x0b, 0x1d, 0x0c, 0x0d, 0x1e, 0x0e, 0x0f, 0x1f };
+
+#define vec_merge3(x2, x1, x0, y0, y1, y2) \
+ do { \
+ __typeof__(x0) o0, o2, o3; \
+ o0 = vec_mergeh(x0, x1); \
+ y0 = vec_perm(o0, x2, perm_rgb_0); \
+ o2 = vec_perm(o0, x2, perm_rgb_1); \
+ o3 = vec_mergel(x0, x1); \
+ y1 = vec_perm(o3, o2, perm_rgb_2); \
+ y2 = vec_perm(o3, o2, perm_rgb_3); \
+ } while (0)
+
+#define vec_mstbgr24(x0, x1, x2, ptr) \
+ do { \
+ __typeof__(x0) _0, _1, _2; \
+ vec_merge3(x0, x1, x2, _0, _1, _2); \
+ vec_st(_0, 0, ptr++); \
+ vec_st(_1, 0, ptr++); \
+ vec_st(_2, 0, ptr++); \
+ } while (0)
+
+#define vec_mstrgb24(x0, x1, x2, ptr) \
+ do { \
+ __typeof__(x0) _0, _1, _2; \
+ vec_merge3(x2, x1, x0, _0, _1, _2); \
+ vec_st(_0, 0, ptr++); \
+ vec_st(_1, 0, ptr++); \
+ vec_st(_2, 0, ptr++); \
+ } while (0)
/* pack the pixels in rgb0 format
- msb R
- lsb 0
-*/
-#define vec_mstrgb32(T,x0,x1,x2,x3,ptr) \
-do { \
- T _0,_1,_2,_3; \
- _0 = vec_mergeh (x0,x1); \
- _1 = vec_mergeh (x2,x3); \
- _2 = (T)vec_mergeh ((vector unsigned short)_0,(vector unsigned short)_1); \
- _3 = (T)vec_mergel ((vector unsigned short)_0,(vector unsigned short)_1); \
- vec_st (_2, 0*16, (T *)ptr); \
- vec_st (_3, 1*16, (T *)ptr); \
- _0 = vec_mergel (x0,x1); \
- _1 = vec_mergel (x2,x3); \
- _2 = (T)vec_mergeh ((vector unsigned short)_0,(vector unsigned short)_1); \
- _3 = (T)vec_mergel ((vector unsigned short)_0,(vector unsigned short)_1); \
- vec_st (_2, 2*16, (T *)ptr); \
- vec_st (_3, 3*16, (T *)ptr); \
- ptr += 4; \
-} while (0)
+ * msb R
+ * lsb 0
+ */
+#define vec_mstrgb32(T, x0, x1, x2, x3, ptr) \
+ do { \
+ T _0, _1, _2, _3; \
+ _0 = vec_mergeh(x0, x1); \
+ _1 = vec_mergeh(x2, x3); \
+ _2 = (T) vec_mergeh((vector unsigned short) _0, \
+ (vector unsigned short) _1); \
+ _3 = (T) vec_mergel((vector unsigned short) _0, \
+ (vector unsigned short) _1); \
+ vec_st(_2, 0 * 16, (T *) ptr); \
+ vec_st(_3, 1 * 16, (T *) ptr); \
+ _0 = vec_mergel(x0, x1); \
+ _1 = vec_mergel(x2, x3); \
+ _2 = (T) vec_mergeh((vector unsigned short) _0, \
+ (vector unsigned short) _1); \
+ _3 = (T) vec_mergel((vector unsigned short) _0, \
+ (vector unsigned short) _1); \
+ vec_st(_2, 2 * 16, (T *) ptr); \
+ vec_st(_3, 3 * 16, (T *) ptr); \
+ ptr += 4; \
+ } while (0)
/*
+ * 1 0 1.4021 | | Y |
+ * 1 -0.3441 -0.7142 |x| Cb|
+ * 1 1.7718 0 | | Cr|
+ *
+ *
+ * Y: [-128 127]
+ * Cb/Cr : [-128 127]
+ *
+ * typical YUV conversion works on Y: 0-255 this version has been
+ * optimized for JPEG decoding.
+ */
- | 1 0 1.4021 | | Y |
- | 1 -0.3441 -0.7142 |x| Cb|
- | 1 1.7718 0 | | Cr|
-
-
- Y: [-128 127]
- Cb/Cr : [-128 127]
-
- typical yuv conversion work on Y: 0-255 this version has been optimized for jpeg decode.
-
-*/
-
-
-
-
-#define vec_unh(x) \
- (vector signed short) \
- vec_perm(x,(__typeof__(x)){0}, \
- ((vector unsigned char){0x10,0x00,0x10,0x01,0x10,0x02,0x10,0x03,\
- 0x10,0x04,0x10,0x05,0x10,0x06,0x10,0x07}))
-#define vec_unl(x) \
- (vector signed short) \
- vec_perm(x,(__typeof__(x)){0}, \
- ((vector unsigned char){0x10,0x08,0x10,0x09,0x10,0x0A,0x10,0x0B,\
- 0x10,0x0C,0x10,0x0D,0x10,0x0E,0x10,0x0F}))
-
-#define vec_clip_s16(x) \
- vec_max (vec_min (x, ((vector signed short){235,235,235,235,235,235,235,235})), \
- ((vector signed short){ 16, 16, 16, 16, 16, 16, 16, 16}))
-
-#define vec_packclp(x,y) \
- (vector unsigned char)vec_packs \
- ((vector unsigned short)vec_max (x,((vector signed short) {0})), \
- (vector unsigned short)vec_max (y,((vector signed short) {0})))
-
-//#define out_pixels(a,b,c,ptr) vec_mstrgb32(__typeof__(a),((__typeof__ (a)){255}),a,a,a,ptr)
-
-
-static inline void cvtyuvtoRGB (SwsContext *c,
- vector signed short Y, vector signed short U, vector signed short V,
- vector signed short *R, vector signed short *G, vector signed short *B)
+#define vec_unh(x) \
+ (vector signed short) \
+ vec_perm(x, (__typeof__(x)) { 0 }, \
+ ((vector unsigned char) { \
+ 0x10, 0x00, 0x10, 0x01, 0x10, 0x02, 0x10, 0x03, \
+ 0x10, 0x04, 0x10, 0x05, 0x10, 0x06, 0x10, 0x07 }))
+
+#define vec_unl(x) \
+ (vector signed short) \
+ vec_perm(x, (__typeof__(x)) { 0 }, \
+ ((vector unsigned char) { \
+ 0x10, 0x08, 0x10, 0x09, 0x10, 0x0A, 0x10, 0x0B, \
+ 0x10, 0x0C, 0x10, 0x0D, 0x10, 0x0E, 0x10, 0x0F }))
+
+#define vec_clip_s16(x) \
+ vec_max(vec_min(x, ((vector signed short) { \
+ 235, 235, 235, 235, 235, 235, 235, 235 })), \
+ ((vector signed short) { 16, 16, 16, 16, 16, 16, 16, 16 }))
+
+#define vec_packclp(x, y) \
+ (vector unsigned char) \
+ vec_packs((vector unsigned short) \
+ vec_max(x, ((vector signed short) { 0 })), \
+ (vector unsigned short) \
+ vec_max(y, ((vector signed short) { 0 })))
+
+//#define out_pixels(a, b, c, ptr) vec_mstrgb32(__typeof__(a), ((__typeof__(a)) { 255 }), a, a, a, ptr)
+
+static inline void cvtyuvtoRGB(SwsContext *c, vector signed short Y,
+ vector signed short U, vector signed short V,
+ vector signed short *R, vector signed short *G,
+ vector signed short *B)
{
- vector signed short vx,ux,uvx;
+ vector signed short vx, ux, uvx;
- Y = vec_mradds (Y, c->CY, c->OY);
- U = vec_sub (U,(vector signed short)
- vec_splat((vector signed short){128},0));
- V = vec_sub (V,(vector signed short)
- vec_splat((vector signed short){128},0));
+ Y = vec_mradds(Y, c->CY, c->OY);
+ U = vec_sub(U, (vector signed short)
+ vec_splat((vector signed short) { 128 }, 0));
+ V = vec_sub(V, (vector signed short)
+ vec_splat((vector signed short) { 128 }, 0));
- // ux = (CBU*(u<<c->CSHIFT)+0x4000)>>15;
- ux = vec_sl (U, c->CSHIFT);
- *B = vec_mradds (ux, c->CBU, Y);
+ // ux = (CBU * (u << c->CSHIFT) + 0x4000) >> 15;
+ ux = vec_sl(U, c->CSHIFT);
+ *B = vec_mradds(ux, c->CBU, Y);
- // vx = (CRV*(v<<c->CSHIFT)+0x4000)>>15;
- vx = vec_sl (V, c->CSHIFT);
- *R = vec_mradds (vx, c->CRV, Y);
+ // vx = (CRV * (v << c->CSHIFT) + 0x4000) >> 15;
+ vx = vec_sl(V, c->CSHIFT);
+ *R = vec_mradds(vx, c->CRV, Y);
- // uvx = ((CGU*u) + (CGV*v))>>15;
- uvx = vec_mradds (U, c->CGU, Y);
- *G = vec_mradds (V, c->CGV, uvx);
+ // uvx = ((CGU * u) + (CGV * v)) >> 15;
+ uvx = vec_mradds(U, c->CGU, Y);
+ *G = vec_mradds(V, c->CGV, uvx);
}
-
/*
- ------------------------------------------------------------------------------
- CS converters
- ------------------------------------------------------------------------------
-*/
-
+ * ------------------------------------------------------------------------------
+ * CS converters
+ * ------------------------------------------------------------------------------
+ */
-#define DEFCSP420_CVT(name,out_pixels) \
-static int altivec_##name (SwsContext *c, \
- const unsigned char **in, int *instrides, \
- int srcSliceY, int srcSliceH, \
- unsigned char **oplanes, int *outstrides) \
-{ \
- int w = c->srcW; \
- int h = srcSliceH; \
- int i,j; \
- int instrides_scl[3]; \
- vector unsigned char y0,y1; \
- \
- vector signed char u,v; \
- \
- vector signed short Y0,Y1,Y2,Y3; \
- vector signed short U,V; \
- vector signed short vx,ux,uvx; \
- vector signed short vx0,ux0,uvx0; \
- vector signed short vx1,ux1,uvx1; \
- vector signed short R0,G0,B0; \
- vector signed short R1,G1,B1; \
- vector unsigned char R,G,B; \
- \
- const vector unsigned char *y1ivP, *y2ivP, *uivP, *vivP; \
- vector unsigned char align_perm; \
- \
- vector signed short \
- lCY = c->CY, \
- lOY = c->OY, \
- lCRV = c->CRV, \
- lCBU = c->CBU, \
- lCGU = c->CGU, \
- lCGV = c->CGV; \
- \
- vector unsigned short lCSHIFT = c->CSHIFT; \
- \
- const ubyte *y1i = in[0]; \
- const ubyte *y2i = in[0]+instrides[0]; \
- const ubyte *ui = in[1]; \
- const ubyte *vi = in[2]; \
- \
- vector unsigned char *oute \
- = (vector unsigned char *) \
- (oplanes[0]+srcSliceY*outstrides[0]); \
- vector unsigned char *outo \
- = (vector unsigned char *) \
- (oplanes[0]+srcSliceY*outstrides[0]+outstrides[0]); \
- \
- \
- instrides_scl[0] = instrides[0]*2-w; /* the loop moves y{1,2}i by w */ \
- instrides_scl[1] = instrides[1]-w/2; /* the loop moves ui by w/2 */ \
- instrides_scl[2] = instrides[2]-w/2; /* the loop moves vi by w/2 */ \
- \
- \
- for (i=0;i<h/2;i++) { \
- vec_dstst (outo, (0x02000002|(((w*3+32)/32)<<16)), 0); \
- vec_dstst (oute, (0x02000002|(((w*3+32)/32)<<16)), 1); \
- \
- for (j=0;j<w/16;j++) { \
- \
- y1ivP = (const vector unsigned char *)y1i; \
- y2ivP = (const vector unsigned char *)y2i; \
- uivP = (const vector unsigned char *)ui; \
- vivP = (const vector unsigned char *)vi; \
- \
- align_perm = vec_lvsl (0, y1i); \
- y0 = (vector unsigned char) \
- vec_perm (y1ivP[0], y1ivP[1], align_perm); \
- \
- align_perm = vec_lvsl (0, y2i); \
- y1 = (vector unsigned char) \
- vec_perm (y2ivP[0], y2ivP[1], align_perm); \
- \
- align_perm = vec_lvsl (0, ui); \
- u = (vector signed char) \
- vec_perm (uivP[0], uivP[1], align_perm); \
- \
- align_perm = vec_lvsl (0, vi); \
- v = (vector signed char) \
- vec_perm (vivP[0], vivP[1], align_perm); \
- \
- u = (vector signed char) \
- vec_sub (u,(vector signed char) \
- vec_splat((vector signed char){128},0)); \
- v = (vector signed char) \
- vec_sub (v,(vector signed char) \
- vec_splat((vector signed char){128},0)); \
- \
- U = vec_unpackh (u); \
- V = vec_unpackh (v); \
- \
- \
- Y0 = vec_unh (y0); \
- Y1 = vec_unl (y0); \
- Y2 = vec_unh (y1); \
- Y3 = vec_unl (y1); \
- \
- Y0 = vec_mradds (Y0, lCY, lOY); \
- Y1 = vec_mradds (Y1, lCY, lOY); \
- Y2 = vec_mradds (Y2, lCY, lOY); \
- Y3 = vec_mradds (Y3, lCY, lOY); \
- \
- /* ux = (CBU*(u<<CSHIFT)+0x4000)>>15 */ \
- ux = vec_sl (U, lCSHIFT); \
- ux = vec_mradds (ux, lCBU, (vector signed short){0}); \
- ux0 = vec_mergeh (ux,ux); \
- ux1 = vec_mergel (ux,ux); \
- \
- /* vx = (CRV*(v<<CSHIFT)+0x4000)>>15; */ \
- vx = vec_sl (V, lCSHIFT); \
- vx = vec_mradds (vx, lCRV, (vector signed short){0}); \
- vx0 = vec_mergeh (vx,vx); \
- vx1 = vec_mergel (vx,vx); \
- \
- /* uvx = ((CGU*u) + (CGV*v))>>15 */ \
- uvx = vec_mradds (U, lCGU, (vector signed short){0}); \
- uvx = vec_mradds (V, lCGV, uvx); \
- uvx0 = vec_mergeh (uvx,uvx); \
- uvx1 = vec_mergel (uvx,uvx); \
- \
- R0 = vec_add (Y0,vx0); \
- G0 = vec_add (Y0,uvx0); \
- B0 = vec_add (Y0,ux0); \
- R1 = vec_add (Y1,vx1); \
- G1 = vec_add (Y1,uvx1); \
- B1 = vec_add (Y1,ux1); \
- \
- R = vec_packclp (R0,R1); \
- G = vec_packclp (G0,G1); \
- B = vec_packclp (B0,B1); \
- \
- out_pixels(R,G,B,oute); \
- \
- R0 = vec_add (Y2,vx0); \
- G0 = vec_add (Y2,uvx0); \
- B0 = vec_add (Y2,ux0); \
- R1 = vec_add (Y3,vx1); \
- G1 = vec_add (Y3,uvx1); \
- B1 = vec_add (Y3,ux1); \
- R = vec_packclp (R0,R1); \
- G = vec_packclp (G0,G1); \
- B = vec_packclp (B0,B1); \
- \
- \
- out_pixels(R,G,B,outo); \
- \
- y1i += 16; \
- y2i += 16; \
- ui += 8; \
- vi += 8; \
- \
- } \
- \
- outo += (outstrides[0])>>4; \
- oute += (outstrides[0])>>4; \
- \
- ui += instrides_scl[1]; \
- vi += instrides_scl[2]; \
- y1i += instrides_scl[0]; \
- y2i += instrides_scl[0]; \
- } \
- return srcSliceH; \
+#define DEFCSP420_CVT(name, out_pixels) \
+static int altivec_ ## name(SwsContext *c, const unsigned char **in, \
+ int *instrides, int srcSliceY, int srcSliceH, \
+ unsigned char **oplanes, int *outstrides) \
+{ \
+ int w = c->srcW; \
+ int h = srcSliceH; \
+ int i, j; \
+ int instrides_scl[3]; \
+ vector unsigned char y0, y1; \
+ \
+ vector signed char u, v; \
+ \
+ vector signed short Y0, Y1, Y2, Y3; \
+ vector signed short U, V; \
+ vector signed short vx, ux, uvx; \
+ vector signed short vx0, ux0, uvx0; \
+ vector signed short vx1, ux1, uvx1; \
+ vector signed short R0, G0, B0; \
+ vector signed short R1, G1, B1; \
+ vector unsigned char R, G, B; \
+ \
+ const vector unsigned char *y1ivP, *y2ivP, *uivP, *vivP; \
+ vector unsigned char align_perm; \
+ \
+ vector signed short lCY = c->CY; \
+ vector signed short lOY = c->OY; \
+ vector signed short lCRV = c->CRV; \
+ vector signed short lCBU = c->CBU; \
+ vector signed short lCGU = c->CGU; \
+ vector signed short lCGV = c->CGV; \
+ vector unsigned short lCSHIFT = c->CSHIFT; \
+ \
+ const ubyte *y1i = in[0]; \
+ const ubyte *y2i = in[0] + instrides[0]; \
+ const ubyte *ui = in[1]; \
+ const ubyte *vi = in[2]; \
+ \
+ vector unsigned char *oute = \
+ (vector unsigned char *) \
+ (oplanes[0] + srcSliceY * outstrides[0]); \
+ vector unsigned char *outo = \
+ (vector unsigned char *) \
+ (oplanes[0] + srcSliceY * outstrides[0] + outstrides[0]); \
+ \
+ /* loop moves y{1, 2}i by w */ \
+ instrides_scl[0] = instrides[0] * 2 - w; \
+ /* loop moves ui by w / 2 */ \
+ instrides_scl[1] = instrides[1] - w / 2; \
+ /* loop moves vi by w / 2 */ \
+ instrides_scl[2] = instrides[2] - w / 2; \
+ \
+ for (i = 0; i < h / 2; i++) { \
+ vec_dstst(outo, (0x02000002 | (((w * 3 + 32) / 32) << 16)), 0); \
+ vec_dstst(oute, (0x02000002 | (((w * 3 + 32) / 32) << 16)), 1); \
+ \
+ for (j = 0; j < w / 16; j++) { \
+ y1ivP = (const vector unsigned char *) y1i; \
+ y2ivP = (const vector unsigned char *) y2i; \
+ uivP = (const vector unsigned char *) ui; \
+ vivP = (const vector unsigned char *) vi; \
+ \
+ align_perm = vec_lvsl(0, y1i); \
+ y0 = (vector unsigned char) \
+ vec_perm(y1ivP[0], y1ivP[1], align_perm); \
+ \
+ align_perm = vec_lvsl(0, y2i); \
+ y1 = (vector unsigned char) \
+ vec_perm(y2ivP[0], y2ivP[1], align_perm); \
+ \
+ align_perm = vec_lvsl(0, ui); \
+ u = (vector signed char) \
+ vec_perm(uivP[0], uivP[1], align_perm); \
+ \
+ align_perm = vec_lvsl(0, vi); \
+ v = (vector signed char) \
+ vec_perm(vivP[0], vivP[1], align_perm); \
+ \
+ u = (vector signed char) \
+ vec_sub(u, \
+ (vector signed char) \
+ vec_splat((vector signed char) { 128 }, 0)); \
+ v = (vector signed char) \
+ vec_sub(v, \
+ (vector signed char) \
+ vec_splat((vector signed char) { 128 }, 0)); \
+ \
+ U = vec_unpackh(u); \
+ V = vec_unpackh(v); \
+ \
+ Y0 = vec_unh(y0); \
+ Y1 = vec_unl(y0); \
+ Y2 = vec_unh(y1); \
+ Y3 = vec_unl(y1); \
+ \
+ Y0 = vec_mradds(Y0, lCY, lOY); \
+ Y1 = vec_mradds(Y1, lCY, lOY); \
+ Y2 = vec_mradds(Y2, lCY, lOY); \
+ Y3 = vec_mradds(Y3, lCY, lOY); \
+ \
+ /* ux = (CBU * (u << CSHIFT) + 0x4000) >> 15 */ \
+ ux = vec_sl(U, lCSHIFT); \
+ ux = vec_mradds(ux, lCBU, (vector signed short) { 0 }); \
+ ux0 = vec_mergeh(ux, ux); \
+ ux1 = vec_mergel(ux, ux); \
+ \
+ /* vx = (CRV * (v << CSHIFT) + 0x4000) >> 15; */ \
+ vx = vec_sl(V, lCSHIFT); \
+ vx = vec_mradds(vx, lCRV, (vector signed short) { 0 }); \
+ vx0 = vec_mergeh(vx, vx); \
+ vx1 = vec_mergel(vx, vx); \
+ \
+ /* uvx = ((CGU * u) + (CGV * v)) >> 15 */ \
+ uvx = vec_mradds(U, lCGU, (vector signed short) { 0 }); \
+ uvx = vec_mradds(V, lCGV, uvx); \
+ uvx0 = vec_mergeh(uvx, uvx); \
+ uvx1 = vec_mergel(uvx, uvx); \
+ \
+ R0 = vec_add(Y0, vx0); \
+ G0 = vec_add(Y0, uvx0); \
+ B0 = vec_add(Y0, ux0); \
+ R1 = vec_add(Y1, vx1); \
+ G1 = vec_add(Y1, uvx1); \
+ B1 = vec_add(Y1, ux1); \
+ \
+ R = vec_packclp(R0, R1); \
+ G = vec_packclp(G0, G1); \
+ B = vec_packclp(B0, B1); \
+ \
+ out_pixels(R, G, B, oute); \
+ \
+ R0 = vec_add(Y2, vx0); \
+ G0 = vec_add(Y2, uvx0); \
+ B0 = vec_add(Y2, ux0); \
+ R1 = vec_add(Y3, vx1); \
+ G1 = vec_add(Y3, uvx1); \
+ B1 = vec_add(Y3, ux1); \
+ R = vec_packclp(R0, R1); \
+ G = vec_packclp(G0, G1); \
+ B = vec_packclp(B0, B1); \
+ \
+ \
+ out_pixels(R, G, B, outo); \
+ \
+ y1i += 16; \
+ y2i += 16; \
+ ui += 8; \
+ vi += 8; \
+ } \
+ \
+ outo += (outstrides[0]) >> 4; \
+ oute += (outstrides[0]) >> 4; \
+ \
+ ui += instrides_scl[1]; \
+ vi += instrides_scl[2]; \
+ y1i += instrides_scl[0]; \
+ y2i += instrides_scl[0]; \
+ } \
+ return srcSliceH; \
}
-
-#define out_abgr(a,b,c,ptr) vec_mstrgb32(__typeof__(a),((__typeof__ (a)){255}),c,b,a,ptr)
-#define out_bgra(a,b,c,ptr) vec_mstrgb32(__typeof__(a),c,b,a,((__typeof__ (a)){255}),ptr)
-#define out_rgba(a,b,c,ptr) vec_mstrgb32(__typeof__(a),a,b,c,((__typeof__ (a)){255}),ptr)
-#define out_argb(a,b,c,ptr) vec_mstrgb32(__typeof__(a),((__typeof__ (a)){255}),a,b,c,ptr)
-#define out_rgb24(a,b,c,ptr) vec_mstrgb24(a,b,c,ptr)
-#define out_bgr24(a,b,c,ptr) vec_mstbgr24(a,b,c,ptr)
-
-DEFCSP420_CVT (yuv2_abgr, out_abgr)
-DEFCSP420_CVT (yuv2_bgra, out_bgra)
-DEFCSP420_CVT (yuv2_rgba, out_rgba)
-DEFCSP420_CVT (yuv2_argb, out_argb)
-DEFCSP420_CVT (yuv2_rgb24, out_rgb24)
-DEFCSP420_CVT (yuv2_bgr24, out_bgr24)
-
+#define out_abgr(a, b, c, ptr) \
+ vec_mstrgb32(__typeof__(a), ((__typeof__(a)) { 255 }), c, b, a, ptr)
+#define out_bgra(a, b, c, ptr) \
+ vec_mstrgb32(__typeof__(a), c, b, a, ((__typeof__(a)) { 255 }), ptr)
+#define out_rgba(a, b, c, ptr) \
+ vec_mstrgb32(__typeof__(a), a, b, c, ((__typeof__(a)) { 255 }), ptr)
+#define out_argb(a, b, c, ptr) \
+ vec_mstrgb32(__typeof__(a), ((__typeof__(a)) { 255 }), a, b, c, ptr)
+#define out_rgb24(a, b, c, ptr) vec_mstrgb24(a, b, c, ptr)
+#define out_bgr24(a, b, c, ptr) vec_mstbgr24(a, b, c, ptr)
+
+DEFCSP420_CVT(yuv2_abgr, out_abgr)
+DEFCSP420_CVT(yuv2_bgra, out_bgra)
+DEFCSP420_CVT(yuv2_rgba, out_rgba)
+DEFCSP420_CVT(yuv2_argb, out_argb)
+DEFCSP420_CVT(yuv2_rgb24, out_rgb24)
+DEFCSP420_CVT(yuv2_bgr24, out_bgr24)
// uyvy|uyvy|uyvy|uyvy
// 0123 4567 89ab cdef
-static
-const vector unsigned char
- demux_u = {0x10,0x00,0x10,0x00,
- 0x10,0x04,0x10,0x04,
- 0x10,0x08,0x10,0x08,
- 0x10,0x0c,0x10,0x0c},
- demux_v = {0x10,0x02,0x10,0x02,
- 0x10,0x06,0x10,0x06,
- 0x10,0x0A,0x10,0x0A,
- 0x10,0x0E,0x10,0x0E},
- demux_y = {0x10,0x01,0x10,0x03,
- 0x10,0x05,0x10,0x07,
- 0x10,0x09,0x10,0x0B,
- 0x10,0x0D,0x10,0x0F};
+static const vector unsigned char
+ demux_u = { 0x10, 0x00, 0x10, 0x00,
+ 0x10, 0x04, 0x10, 0x04,
+ 0x10, 0x08, 0x10, 0x08,
+ 0x10, 0x0c, 0x10, 0x0c },
+ demux_v = { 0x10, 0x02, 0x10, 0x02,
+ 0x10, 0x06, 0x10, 0x06,
+ 0x10, 0x0A, 0x10, 0x0A,
+ 0x10, 0x0E, 0x10, 0x0E },
+ demux_y = { 0x10, 0x01, 0x10, 0x03,
+ 0x10, 0x05, 0x10, 0x07,
+ 0x10, 0x09, 0x10, 0x0B,
+ 0x10, 0x0D, 0x10, 0x0F };
/*
- this is so I can play live CCIR raw video
-*/
-static int altivec_uyvy_rgb32 (SwsContext *c,
- const unsigned char **in, int *instrides,
- int srcSliceY, int srcSliceH,
- unsigned char **oplanes, int *outstrides)
+ * this is so I can play live CCIR raw video
+ */
+static int altivec_uyvy_rgb32(SwsContext *c, const unsigned char **in,
+ int *instrides, int srcSliceY, int srcSliceH,
+ unsigned char **oplanes, int *outstrides)
{
int w = c->srcW;
int h = srcSliceH;
- int i,j;
+ int i, j;
vector unsigned char uyvy;
- vector signed short Y,U,V;
- vector signed short R0,G0,B0,R1,G1,B1;
- vector unsigned char R,G,B;
+ vector signed short Y, U, V;
+ vector signed short R0, G0, B0, R1, G1, B1;
+ vector unsigned char R, G, B;
vector unsigned char *out;
const ubyte *img;
img = in[0];
- out = (vector unsigned char *)(oplanes[0]+srcSliceY*outstrides[0]);
+ out = (vector unsigned char *) (oplanes[0] + srcSliceY * outstrides[0]);
- for (i=0;i<h;i++) {
- for (j=0;j<w/16;j++) {
- uyvy = vec_ld (0, img);
- U = (vector signed short)
- vec_perm (uyvy, (vector unsigned char){0}, demux_u);
+ for (i = 0; i < h; i++)
+ for (j = 0; j < w / 16; j++) {
+ uyvy = vec_ld(0, img);
+ U = (vector signed short)
+ vec_perm(uyvy, (vector unsigned char) { 0 }, demux_u);
V = (vector signed short)
- vec_perm (uyvy, (vector unsigned char){0}, demux_v);
-
+ vec_perm(uyvy, (vector unsigned char) { 0 }, demux_v);
Y = (vector signed short)
- vec_perm (uyvy, (vector unsigned char){0}, demux_y);
+ vec_perm(uyvy, (vector unsigned char) { 0 }, demux_y);
- cvtyuvtoRGB (c, Y,U,V,&R0,&G0,&B0);
+ cvtyuvtoRGB(c, Y, U, V, &R0, &G0, &B0);
- uyvy = vec_ld (16, img);
- U = (vector signed short)
- vec_perm (uyvy, (vector unsigned char){0}, demux_u);
+ uyvy = vec_ld(16, img);
+ U = (vector signed short)
+ vec_perm(uyvy, (vector unsigned char) { 0 }, demux_u);
V = (vector signed short)
- vec_perm (uyvy, (vector unsigned char){0}, demux_v);
-
+ vec_perm(uyvy, (vector unsigned char) { 0 }, demux_v);
Y = (vector signed short)
- vec_perm (uyvy, (vector unsigned char){0}, demux_y);
+ vec_perm(uyvy, (vector unsigned char) { 0 }, demux_y);
- cvtyuvtoRGB (c, Y,U,V,&R1,&G1,&B1);
+ cvtyuvtoRGB(c, Y, U, V, &R1, &G1, &B1);
- R = vec_packclp (R0,R1);
- G = vec_packclp (G0,G1);
- B = vec_packclp (B0,B1);
+ R = vec_packclp(R0, R1);
+ G = vec_packclp(G0, G1);
+ B = vec_packclp(B0, B1);
- // vec_mstbgr24 (R,G,B, out);
- out_rgba (R,G,B,out);
+ // vec_mstbgr24 (R,G,B, out);
+ out_rgba(R, G, B, out);
img += 32;
}
- }
return srcSliceH;
}
-
-
/* Ok currently the acceleration routine only supports
- inputs of widths a multiple of 16
- and heights a multiple 2
-
- So we just fall back to the C codes for this.
-*/
+ * inputs of widths a multiple of 16
+ * and heights a multiple 2
+ *
+ * So we just fall back to the C codes for this.
+ */
SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c)
{
if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC))
return NULL;
/*
- and this seems not to matter too much I tried a bunch of
- videos with abnormal widths and MPlayer crashes elsewhere.
- mplayer -vo x11 -rawvideo on:w=350:h=240 raw-350x240.eyuv
- boom with X11 bad match.
-
- */
- if ((c->srcW & 0xf) != 0) return NULL;
+ * and this seems not to matter too much I tried a bunch of
+ * videos with abnormal widths and MPlayer crashes elsewhere.
+ * mplayer -vo x11 -rawvideo on:w=350:h=240 raw-350x240.eyuv
+ * boom with X11 bad match.
+ *
+ */
+ if ((c->srcW & 0xf) != 0)
+ return NULL;
switch (c->srcFormat) {
case PIX_FMT_YUV410P:
@@ -565,7 +561,7 @@ SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c)
if ((c->srcH & 0x1) != 0)
return NULL;
- switch(c->dstFormat) {
+ switch (c->dstFormat) {
case PIX_FMT_RGB24:
av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGB24\n");
return altivec_yuv2_rgb24;
@@ -589,143 +585,160 @@ SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c)
break;
case PIX_FMT_UYVY422:
- switch(c->dstFormat) {
+ switch (c->dstFormat) {
case PIX_FMT_BGR32:
av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space UYVY -> RGB32\n");
return altivec_uyvy_rgb32;
default: return NULL;
}
break;
-
}
return NULL;
}
-void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4], int brightness, int contrast, int saturation)
+void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4],
+ int brightness, int contrast,
+ int saturation)
{
union {
DECLARE_ALIGNED(16, signed short, tmp)[8];
vector signed short vec;
} buf;
- buf.tmp[0] = ((0xffffLL) * contrast>>8)>>9; //cy
- buf.tmp[1] = -256*brightness; //oy
- buf.tmp[2] = (inv_table[0]>>3) *(contrast>>16)*(saturation>>16); //crv
- buf.tmp[3] = (inv_table[1]>>3) *(contrast>>16)*(saturation>>16); //cbu
- buf.tmp[4] = -((inv_table[2]>>1)*(contrast>>16)*(saturation>>16)); //cgu
- buf.tmp[5] = -((inv_table[3]>>1)*(contrast>>16)*(saturation>>16)); //cgv
-
-
- c->CSHIFT = (vector unsigned short)vec_splat_u16(2);
- c->CY = vec_splat ((vector signed short)buf.vec, 0);
- c->OY = vec_splat ((vector signed short)buf.vec, 1);
- c->CRV = vec_splat ((vector signed short)buf.vec, 2);
- c->CBU = vec_splat ((vector signed short)buf.vec, 3);
- c->CGU = vec_splat ((vector signed short)buf.vec, 4);
- c->CGV = vec_splat ((vector signed short)buf.vec, 5);
+ buf.tmp[0] = ((0xffffLL) * contrast >> 8) >> 9; // cy
+ buf.tmp[1] = -256 * brightness; // oy
+ buf.tmp[2] = (inv_table[0] >> 3) * (contrast >> 16) * (saturation >> 16); // crv
+ buf.tmp[3] = (inv_table[1] >> 3) * (contrast >> 16) * (saturation >> 16); // cbu
+ buf.tmp[4] = -((inv_table[2] >> 1) * (contrast >> 16) * (saturation >> 16)); // cgu
+ buf.tmp[5] = -((inv_table[3] >> 1) * (contrast >> 16) * (saturation >> 16)); // cgv
+
+ c->CSHIFT = (vector unsigned short) vec_splat_u16(2);
+ c->CY = vec_splat((vector signed short) buf.vec, 0);
+ c->OY = vec_splat((vector signed short) buf.vec, 1);
+ c->CRV = vec_splat((vector signed short) buf.vec, 2);
+ c->CBU = vec_splat((vector signed short) buf.vec, 3);
+ c->CGU = vec_splat((vector signed short) buf.vec, 4);
+ c->CGV = vec_splat((vector signed short) buf.vec, 5);
return;
}
-
-static av_always_inline void
-ff_yuv2packedX_altivec(SwsContext *c, const int16_t *lumFilter,
- const int16_t **lumSrc, int lumFilterSize,
- const int16_t *chrFilter, const int16_t **chrUSrc,
- const int16_t **chrVSrc, int chrFilterSize,
- const int16_t **alpSrc, uint8_t *dest,
- int dstW, int dstY, enum PixelFormat target)
+static av_always_inline void ff_yuv2packedX_altivec(SwsContext *c,
+ const int16_t *lumFilter,
+ const int16_t **lumSrc,
+ int lumFilterSize,
+ const int16_t *chrFilter,
+ const int16_t **chrUSrc,
+ const int16_t **chrVSrc,
+ int chrFilterSize,
+ const int16_t **alpSrc,
+ uint8_t *dest,
+ int dstW, int dstY,
+ enum PixelFormat target)
{
- int i,j;
- vector signed short X,X0,X1,Y0,U0,V0,Y1,U1,V1,U,V;
- vector signed short R0,G0,B0,R1,G1,B1;
+ int i, j;
+ vector signed short X, X0, X1, Y0, U0, V0, Y1, U1, V1, U, V;
+ vector signed short R0, G0, B0, R1, G1, B1;
- vector unsigned char R,G,B;
- vector unsigned char *out,*nout;
+ vector unsigned char R, G, B;
+ vector unsigned char *out, *nout;
- vector signed short RND = vec_splat_s16(1<<3);
+ vector signed short RND = vec_splat_s16(1 << 3);
vector unsigned short SCL = vec_splat_u16(4);
DECLARE_ALIGNED(16, unsigned int, scratch)[16];
vector signed short *YCoeffs, *CCoeffs;
- YCoeffs = c->vYCoeffsBank+dstY*lumFilterSize;
- CCoeffs = c->vCCoeffsBank+dstY*chrFilterSize;
+ YCoeffs = c->vYCoeffsBank + dstY * lumFilterSize;
+ CCoeffs = c->vCCoeffsBank + dstY * chrFilterSize;
- out = (vector unsigned char *)dest;
+ out = (vector unsigned char *) dest;
- for (i=0; i<dstW; i+=16) {
+ for (i = 0; i < dstW; i += 16) {
Y0 = RND;
Y1 = RND;
/* extract 16 coeffs from lumSrc */
- for (j=0; j<lumFilterSize; j++) {
- X0 = vec_ld (0, &lumSrc[j][i]);
- X1 = vec_ld (16, &lumSrc[j][i]);
- Y0 = vec_mradds (X0, YCoeffs[j], Y0);
- Y1 = vec_mradds (X1, YCoeffs[j], Y1);
+ for (j = 0; j < lumFilterSize; j++) {
+ X0 = vec_ld(0, &lumSrc[j][i]);
+ X1 = vec_ld(16, &lumSrc[j][i]);
+ Y0 = vec_mradds(X0, YCoeffs[j], Y0);
+ Y1 = vec_mradds(X1, YCoeffs[j], Y1);
}
U = RND;
V = RND;
/* extract 8 coeffs from U,V */
- for (j=0; j<chrFilterSize; j++) {
- X = vec_ld (0, &chrUSrc[j][i/2]);
- U = vec_mradds (X, CCoeffs[j], U);
- X = vec_ld (0, &chrVSrc[j][i/2]);
- V = vec_mradds (X, CCoeffs[j], V);
+ for (j = 0; j < chrFilterSize; j++) {
+ X = vec_ld(0, &chrUSrc[j][i / 2]);
+ U = vec_mradds(X, CCoeffs[j], U);
+ X = vec_ld(0, &chrVSrc[j][i / 2]);
+ V = vec_mradds(X, CCoeffs[j], V);
}
/* scale and clip signals */
- Y0 = vec_sra (Y0, SCL);
- Y1 = vec_sra (Y1, SCL);
- U = vec_sra (U, SCL);
- V = vec_sra (V, SCL);
+ Y0 = vec_sra(Y0, SCL);
+ Y1 = vec_sra(Y1, SCL);
+ U = vec_sra(U, SCL);
+ V = vec_sra(V, SCL);
- Y0 = vec_clip_s16 (Y0);
- Y1 = vec_clip_s16 (Y1);
- U = vec_clip_s16 (U);
- V = vec_clip_s16 (V);
+ Y0 = vec_clip_s16(Y0);
+ Y1 = vec_clip_s16(Y1);
+ U = vec_clip_s16(U);
+ V = vec_clip_s16(V);
/* now we have
- Y0= y0 y1 y2 y3 y4 y5 y6 y7 Y1= y8 y9 y10 y11 y12 y13 y14 y15
- U= u0 u1 u2 u3 u4 u5 u6 u7 V= v0 v1 v2 v3 v4 v5 v6 v7
-
- Y0= y0 y1 y2 y3 y4 y5 y6 y7 Y1= y8 y9 y10 y11 y12 y13 y14 y15
- U0= u0 u0 u1 u1 u2 u2 u3 u3 U1= u4 u4 u5 u5 u6 u6 u7 u7
- V0= v0 v0 v1 v1 v2 v2 v3 v3 V1= v4 v4 v5 v5 v6 v6 v7 v7
- */
-
- U0 = vec_mergeh (U,U);
- V0 = vec_mergeh (V,V);
-
- U1 = vec_mergel (U,U);
- V1 = vec_mergel (V,V);
-
- cvtyuvtoRGB (c, Y0,U0,V0,&R0,&G0,&B0);
- cvtyuvtoRGB (c, Y1,U1,V1,&R1,&G1,&B1);
-
- R = vec_packclp (R0,R1);
- G = vec_packclp (G0,G1);
- B = vec_packclp (B0,B1);
-
- switch(target) {
- case PIX_FMT_ABGR: out_abgr (R,G,B,out); break;
- case PIX_FMT_BGRA: out_bgra (R,G,B,out); break;
- case PIX_FMT_RGBA: out_rgba (R,G,B,out); break;
- case PIX_FMT_ARGB: out_argb (R,G,B,out); break;
- case PIX_FMT_RGB24: out_rgb24 (R,G,B,out); break;
- case PIX_FMT_BGR24: out_bgr24 (R,G,B,out); break;
+ * Y0 = y0 y1 y2 y3 y4 y5 y6 y7 Y1 = y8 y9 y10 y11 y12 y13 y14 y15
+ * U = u0 u1 u2 u3 u4 u5 u6 u7 V = v0 v1 v2 v3 v4 v5 v6 v7
+ *
+ * Y0 = y0 y1 y2 y3 y4 y5 y6 y7 Y1 = y8 y9 y10 y11 y12 y13 y14 y15
+ * U0 = u0 u0 u1 u1 u2 u2 u3 u3 U1 = u4 u4 u5 u5 u6 u6 u7 u7
+ * V0 = v0 v0 v1 v1 v2 v2 v3 v3 V1 = v4 v4 v5 v5 v6 v6 v7 v7
+ */
+
+ U0 = vec_mergeh(U, U);
+ V0 = vec_mergeh(V, V);
+
+ U1 = vec_mergel(U, U);
+ V1 = vec_mergel(V, V);
+
+ cvtyuvtoRGB(c, Y0, U0, V0, &R0, &G0, &B0);
+ cvtyuvtoRGB(c, Y1, U1, V1, &R1, &G1, &B1);
+
+ R = vec_packclp(R0, R1);
+ G = vec_packclp(G0, G1);
+ B = vec_packclp(B0, B1);
+
+ switch (target) {
+ case PIX_FMT_ABGR:
+ out_abgr(R, G, B, out);
+ break;
+ case PIX_FMT_BGRA:
+ out_bgra(R, G, B, out);
+ break;
+ case PIX_FMT_RGBA:
+ out_rgba(R, G, B, out);
+ break;
+ case PIX_FMT_ARGB:
+ out_argb(R, G, B, out);
+ break;
+ case PIX_FMT_RGB24:
+ out_rgb24(R, G, B, out);
+ break;
+ case PIX_FMT_BGR24:
+ out_bgr24(R, G, B, out);
+ break;
default:
- {
- /* If this is reached, the caller should have called yuv2packedXinC
- instead. */
- static int printed_error_message;
- if (!printed_error_message) {
- av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n",
- av_get_pix_fmt_name(c->dstFormat));
- printed_error_message=1;
- }
- return;
+ {
+ /* If this is reached, the caller should have called yuv2packedXinC
+ * instead. */
+ static int printed_error_message;
+ if (!printed_error_message) {
+ av_log(c, AV_LOG_ERROR,
+ "altivec_yuv2packedX doesn't support %s output\n",
+ av_get_pix_fmt_name(c->dstFormat));
+ printed_error_message = 1;
}
+ return;
+ }
}
}
@@ -735,87 +748,104 @@ ff_yuv2packedX_altivec(SwsContext *c, const int16_t *lumFilter,
Y0 = RND;
Y1 = RND;
/* extract 16 coeffs from lumSrc */
- for (j=0; j<lumFilterSize; j++) {
- X0 = vec_ld (0, &lumSrc[j][i]);
- X1 = vec_ld (16, &lumSrc[j][i]);
- Y0 = vec_mradds (X0, YCoeffs[j], Y0);
- Y1 = vec_mradds (X1, YCoeffs[j], Y1);
+ for (j = 0; j < lumFilterSize; j++) {
+ X0 = vec_ld(0, &lumSrc[j][i]);
+ X1 = vec_ld(16, &lumSrc[j][i]);
+ Y0 = vec_mradds(X0, YCoeffs[j], Y0);
+ Y1 = vec_mradds(X1, YCoeffs[j], Y1);
}
U = RND;
V = RND;
/* extract 8 coeffs from U,V */
- for (j=0; j<chrFilterSize; j++) {
- X = vec_ld (0, &chrUSrc[j][i/2]);
- U = vec_mradds (X, CCoeffs[j], U);
- X = vec_ld (0, &chrVSrc[j][i/2]);
- V = vec_mradds (X, CCoeffs[j], V);
+ for (j = 0; j < chrFilterSize; j++) {
+ X = vec_ld(0, &chrUSrc[j][i / 2]);
+ U = vec_mradds(X, CCoeffs[j], U);
+ X = vec_ld(0, &chrVSrc[j][i / 2]);
+ V = vec_mradds(X, CCoeffs[j], V);
}
/* scale and clip signals */
- Y0 = vec_sra (Y0, SCL);
- Y1 = vec_sra (Y1, SCL);
- U = vec_sra (U, SCL);
- V = vec_sra (V, SCL);
+ Y0 = vec_sra(Y0, SCL);
+ Y1 = vec_sra(Y1, SCL);
+ U = vec_sra(U, SCL);
+ V = vec_sra(V, SCL);
- Y0 = vec_clip_s16 (Y0);
- Y1 = vec_clip_s16 (Y1);
- U = vec_clip_s16 (U);
- V = vec_clip_s16 (V);
+ Y0 = vec_clip_s16(Y0);
+ Y1 = vec_clip_s16(Y1);
+ U = vec_clip_s16(U);
+ V = vec_clip_s16(V);
/* now we have
- Y0= y0 y1 y2 y3 y4 y5 y6 y7 Y1= y8 y9 y10 y11 y12 y13 y14 y15
- U = u0 u1 u2 u3 u4 u5 u6 u7 V = v0 v1 v2 v3 v4 v5 v6 v7
-
- Y0= y0 y1 y2 y3 y4 y5 y6 y7 Y1= y8 y9 y10 y11 y12 y13 y14 y15
- U0= u0 u0 u1 u1 u2 u2 u3 u3 U1= u4 u4 u5 u5 u6 u6 u7 u7
- V0= v0 v0 v1 v1 v2 v2 v3 v3 V1= v4 v4 v5 v5 v6 v6 v7 v7
- */
-
- U0 = vec_mergeh (U,U);
- V0 = vec_mergeh (V,V);
-
- U1 = vec_mergel (U,U);
- V1 = vec_mergel (V,V);
-
- cvtyuvtoRGB (c, Y0,U0,V0,&R0,&G0,&B0);
- cvtyuvtoRGB (c, Y1,U1,V1,&R1,&G1,&B1);
-
- R = vec_packclp (R0,R1);
- G = vec_packclp (G0,G1);
- B = vec_packclp (B0,B1);
-
- nout = (vector unsigned char *)scratch;
- switch(target) {
- case PIX_FMT_ABGR: out_abgr (R,G,B,nout); break;
- case PIX_FMT_BGRA: out_bgra (R,G,B,nout); break;
- case PIX_FMT_RGBA: out_rgba (R,G,B,nout); break;
- case PIX_FMT_ARGB: out_argb (R,G,B,nout); break;
- case PIX_FMT_RGB24: out_rgb24 (R,G,B,nout); break;
- case PIX_FMT_BGR24: out_bgr24 (R,G,B,nout); break;
+ * Y0 = y0 y1 y2 y3 y4 y5 y6 y7 Y1 = y8 y9 y10 y11 y12 y13 y14 y15
+ * U = u0 u1 u2 u3 u4 u5 u6 u7 V = v0 v1 v2 v3 v4 v5 v6 v7
+ *
+ * Y0 = y0 y1 y2 y3 y4 y5 y6 y7 Y1 = y8 y9 y10 y11 y12 y13 y14 y15
+ * U0 = u0 u0 u1 u1 u2 u2 u3 u3 U1 = u4 u4 u5 u5 u6 u6 u7 u7
+ * V0 = v0 v0 v1 v1 v2 v2 v3 v3 V1 = v4 v4 v5 v5 v6 v6 v7 v7
+ */
+
+ U0 = vec_mergeh(U, U);
+ V0 = vec_mergeh(V, V);
+
+ U1 = vec_mergel(U, U);
+ V1 = vec_mergel(V, V);
+
+ cvtyuvtoRGB(c, Y0, U0, V0, &R0, &G0, &B0);
+ cvtyuvtoRGB(c, Y1, U1, V1, &R1, &G1, &B1);
+
+ R = vec_packclp(R0, R1);
+ G = vec_packclp(G0, G1);
+ B = vec_packclp(B0, B1);
+
+ nout = (vector unsigned char *) scratch;
+ switch (target) {
+ case PIX_FMT_ABGR:
+ out_abgr(R, G, B, nout);
+ break;
+ case PIX_FMT_BGRA:
+ out_bgra(R, G, B, nout);
+ break;
+ case PIX_FMT_RGBA:
+ out_rgba(R, G, B, nout);
+ break;
+ case PIX_FMT_ARGB:
+ out_argb(R, G, B, nout);
+ break;
+ case PIX_FMT_RGB24:
+ out_rgb24(R, G, B, nout);
+ break;
+ case PIX_FMT_BGR24:
+ out_bgr24(R, G, B, nout);
+ break;
default:
/* Unreachable, I think. */
- av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n",
+ av_log(c, AV_LOG_ERROR,
+ "altivec_yuv2packedX doesn't support %s output\n",
av_get_pix_fmt_name(c->dstFormat));
return;
}
- memcpy (&((uint32_t*)dest)[i], scratch, (dstW-i)/4);
+ memcpy(&((uint32_t *) dest)[i], scratch, (dstW - i) / 4);
}
-
}
-#define YUV2PACKEDX_WRAPPER(suffix, pixfmt) \
-void ff_yuv2 ## suffix ## _X_altivec(SwsContext *c, const int16_t *lumFilter, \
- const int16_t **lumSrc, int lumFilterSize, \
- const int16_t *chrFilter, const int16_t **chrUSrc, \
- const int16_t **chrVSrc, int chrFilterSize, \
- const int16_t **alpSrc, uint8_t *dest, \
- int dstW, int dstY) \
-{ \
- ff_yuv2packedX_altivec(c, lumFilter, lumSrc, lumFilterSize, \
- chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
- alpSrc, dest, dstW, dstY, pixfmt); \
+#define YUV2PACKEDX_WRAPPER(suffix, pixfmt) \
+void ff_yuv2 ## suffix ## _X_altivec(SwsContext *c, \
+ const int16_t *lumFilter, \
+ const int16_t **lumSrc, \
+ int lumFilterSize, \
+ const int16_t *chrFilter, \
+ const int16_t **chrUSrc, \
+ const int16_t **chrVSrc, \
+ int chrFilterSize, \
+ const int16_t **alpSrc, \
+ uint8_t *dest, int dstW, int dstY) \
+{ \
+ ff_yuv2packedX_altivec(c, lumFilter, lumSrc, lumFilterSize, \
+ chrFilter, chrUSrc, chrVSrc, \
+ chrFilterSize, alpSrc, \
+ dest, dstW, dstY, pixfmt); \
}
YUV2PACKEDX_WRAPPER(abgr, PIX_FMT_ABGR);
diff --git a/tests/ref/acodec/g722 b/tests/ref/acodec/g722
index 67e4442a86..1e766d8455 100644
--- a/tests/ref/acodec/g722
+++ b/tests/ref/acodec/g722
@@ -1,4 +1,4 @@
-b813a52d4efe6cf7974190ea9c4c7e8c *./tests/data/acodec/g722.wav
+d1a10c4d35f752f60798114a156be3a8 *./tests/data/acodec/g722.wav
48053 ./tests/data/acodec/g722.wav
-d8344d14a11eef0418b856af70694cbe *./tests/data/g722.acodec.out.wav
-stddev: 8841.18 PSNR: 17.40 MAXDIFF:36225 bytes: 191980/ 1058400
+8dafe5b74ccd5f08fed2fb2a69c5475f *./tests/data/g722.acodec.out.wav
+stddev: 8939.47 PSNR: 17.30 MAXDIFF:40370 bytes: 191980/ 1058400
diff --git a/tests/ref/fate/g722dec-1 b/tests/ref/fate/g722dec-1
index 55f125995d..e94c3e6a11 100644
--- a/tests/ref/fate/g722dec-1
+++ b/tests/ref/fate/g722dec-1
@@ -1,168 +1,168 @@
#tb 0: 1/16000
-0, 0, 0, 2048, 4096, 0xde68394d
-0, 2048, 2048, 2048, 4096, 0xa5c28cb7
-0, 4096, 4096, 2048, 4096, 0x2e3c2f23
-0, 6144, 6144, 2048, 4096, 0xd7757825
-0, 8192, 8192, 2048, 4096, 0xafd1fd61
-0, 10240, 10240, 2048, 4096, 0x686afcbe
-0, 12288, 12288, 2048, 4096, 0x2290e848
-0, 14336, 14336, 2048, 4096, 0xddd484ad
-0, 16384, 16384, 2048, 4096, 0x148811a6
-0, 18432, 18432, 2048, 4096, 0x8b965613
-0, 20480, 20480, 2048, 4096, 0x8b095d51
-0, 22528, 22528, 2048, 4096, 0xf7625485
-0, 24576, 24576, 2048, 4096, 0x982a688c
-0, 26624, 26624, 2048, 4096, 0xc290dcfc
-0, 28672, 28672, 2048, 4096, 0x8bdef225
-0, 30720, 30720, 2048, 4096, 0xfca27fdc
-0, 32768, 32768, 2048, 4096, 0x95eff313
-0, 34816, 34816, 2048, 4096, 0x691ed4f7
-0, 36864, 36864, 2048, 4096, 0xd7e7b492
-0, 38912, 38912, 2048, 4096, 0xb0416bfe
-0, 40960, 40960, 2048, 4096, 0xf94b3ebd
-0, 43008, 43008, 2048, 4096, 0x7f73ca12
-0, 45056, 45056, 2048, 4096, 0xe91da4a3
-0, 47104, 47104, 2048, 4096, 0x1f74dc0e
-0, 49152, 49152, 2048, 4096, 0xd95b35e8
-0, 51200, 51200, 2048, 4096, 0x6dcdde1a
-0, 53248, 53248, 2048, 4096, 0x614fd4e4
-0, 55296, 55296, 2048, 4096, 0xe38d0fd5
-0, 57344, 57344, 2048, 4096, 0xfeba2999
-0, 59392, 59392, 2048, 4096, 0x1bf541e1
-0, 61440, 61440, 2048, 4096, 0x689f50d8
-0, 63488, 63488, 2048, 4096, 0x0aa60f5f
-0, 65536, 65536, 2048, 4096, 0x60ac3116
-0, 67584, 67584, 2048, 4096, 0xfa60e5e6
-0, 69632, 69632, 2048, 4096, 0xc7207c5b
-0, 71680, 71680, 2048, 4096, 0x01196277
-0, 73728, 73728, 2048, 4096, 0x609ca46c
-0, 75776, 75776, 2048, 4096, 0xfb799142
-0, 77824, 77824, 2048, 4096, 0x720910df
-0, 79872, 79872, 2048, 4096, 0xe21a8662
-0, 81920, 81920, 2048, 4096, 0x07105120
-0, 83968, 83968, 2048, 4096, 0x593f627e
-0, 86016, 86016, 2048, 4096, 0x28ddc80c
-0, 88064, 88064, 2048, 4096, 0xc69ef356
-0, 90112, 90112, 2048, 4096, 0x2defc5bd
-0, 92160, 92160, 2048, 4096, 0x82a4f418
-0, 94208, 94208, 2048, 4096, 0x424cb997
-0, 96256, 96256, 2048, 4096, 0x167a49b7
-0, 98304, 98304, 2048, 4096, 0x32a3e0d4
-0, 100352, 100352, 2048, 4096, 0x08a353ae
-0, 102400, 102400, 2048, 4096, 0x9543577b
-0, 104448, 104448, 2048, 4096, 0x2ed137cf
-0, 106496, 106496, 2048, 4096, 0xd80b0538
-0, 108544, 108544, 2048, 4096, 0x2ad31bef
-0, 110592, 110592, 2048, 4096, 0x1060cff8
-0, 112640, 112640, 2048, 4096, 0x76ab5ab8
-0, 114688, 114688, 2048, 4096, 0x8eedb68d
-0, 116736, 116736, 2048, 4096, 0xf4e2dc46
-0, 118784, 118784, 2048, 4096, 0xc52d3326
-0, 120832, 120832, 2048, 4096, 0x25201a26
-0, 122880, 122880, 2048, 4096, 0x16419378
-0, 124928, 124928, 2048, 4096, 0x97061f3c
-0, 126976, 126976, 2048, 4096, 0xd54edecd
-0, 129024, 129024, 2048, 4096, 0xc830b07b
-0, 131072, 131072, 2048, 4096, 0x804bae00
-0, 133120, 133120, 2048, 4096, 0xbb279150
-0, 135168, 135168, 2048, 4096, 0x95c4d5aa
-0, 137216, 137216, 2048, 4096, 0xc51d5259
-0, 139264, 139264, 2048, 4096, 0x856e1ab0
-0, 141312, 141312, 2048, 4096, 0x9e6ccb12
-0, 143360, 143360, 2048, 4096, 0xa2e5c1bb
-0, 145408, 145408, 2048, 4096, 0xe62fb62f
-0, 147456, 147456, 2048, 4096, 0xf10e3df0
-0, 149504, 149504, 2048, 4096, 0x76def18b
-0, 151552, 151552, 2048, 4096, 0xc9c3a26d
-0, 153600, 153600, 2048, 4096, 0x8ec0e061
-0, 155648, 155648, 2048, 4096, 0x3d4e8512
-0, 157696, 157696, 2048, 4096, 0xec45cd46
-0, 159744, 159744, 2048, 4096, 0xa34f3ddf
-0, 161792, 161792, 2048, 4096, 0x52b81c53
-0, 163840, 163840, 2048, 4096, 0xd0f0397a
-0, 165888, 165888, 2048, 4096, 0x7c0de231
-0, 167936, 167936, 2048, 4096, 0xfe86c032
-0, 169984, 169984, 2048, 4096, 0x67cdb848
-0, 172032, 172032, 2048, 4096, 0x90532cc0
-0, 174080, 174080, 2048, 4096, 0x03bca9e9
-0, 176128, 176128, 2048, 4096, 0x73169fd1
-0, 178176, 178176, 2048, 4096, 0x0b93967d
-0, 180224, 180224, 2048, 4096, 0x6486d8be
-0, 182272, 182272, 2048, 4096, 0x555cc2ac
-0, 184320, 184320, 2048, 4096, 0x07c1912e
-0, 186368, 186368, 2048, 4096, 0xe0423c66
-0, 188416, 188416, 2048, 4096, 0xc12d0fa1
-0, 190464, 190464, 2048, 4096, 0xdf497c2f
-0, 192512, 192512, 2048, 4096, 0x9298d1ba
-0, 194560, 194560, 2048, 4096, 0x691a4e15
-0, 196608, 196608, 2048, 4096, 0x725adc6e
-0, 198656, 198656, 2048, 4096, 0xf68e88de
-0, 200704, 200704, 2048, 4096, 0x37a234aa
-0, 202752, 202752, 2048, 4096, 0x43fb0558
-0, 204800, 204800, 2048, 4096, 0x653e4320
-0, 206848, 206848, 2048, 4096, 0x651e2f13
-0, 208896, 208896, 2048, 4096, 0x179049f9
-0, 210944, 210944, 2048, 4096, 0xe02fbb9d
-0, 212992, 212992, 2048, 4096, 0xb7e9f2a0
-0, 215040, 215040, 2048, 4096, 0x94ee81df
-0, 217088, 217088, 2048, 4096, 0x398a98de
-0, 219136, 219136, 2048, 4096, 0x1267594a
-0, 221184, 221184, 2048, 4096, 0x715adbaf
-0, 223232, 223232, 2048, 4096, 0x28ce1a20
-0, 225280, 225280, 2048, 4096, 0x4f8073d0
-0, 227328, 227328, 2048, 4096, 0x536846d3
-0, 229376, 229376, 2048, 4096, 0x7dc7defe
-0, 231424, 231424, 2048, 4096, 0x08a28e2a
-0, 233472, 233472, 2048, 4096, 0xd717c5cd
-0, 235520, 235520, 2048, 4096, 0x5d6e1efd
-0, 237568, 237568, 2048, 4096, 0x4d0eea27
-0, 239616, 239616, 2048, 4096, 0x70fff90c
-0, 241664, 241664, 2048, 4096, 0xd5cc8207
-0, 243712, 243712, 2048, 4096, 0xf87cae0e
-0, 245760, 245760, 2048, 4096, 0x26814ab5
-0, 247808, 247808, 2048, 4096, 0x9569fb8d
-0, 249856, 249856, 2048, 4096, 0x7835122e
-0, 251904, 251904, 2048, 4096, 0xa38840dd
-0, 253952, 253952, 2048, 4096, 0xfc499ba3
-0, 256000, 256000, 2048, 4096, 0x0aa60cb0
-0, 258048, 258048, 2048, 4096, 0x530ef56e
-0, 260096, 260096, 2048, 4096, 0xead968db
-0, 262144, 262144, 2048, 4096, 0x64484214
-0, 264192, 264192, 2048, 4096, 0xfd0cc89e
-0, 266240, 266240, 2048, 4096, 0x0d452a5d
-0, 268288, 268288, 2048, 4096, 0x36ef8482
-0, 270336, 270336, 2048, 4096, 0x462b641b
-0, 272384, 272384, 2048, 4096, 0x2a5c1c0c
-0, 274432, 274432, 2048, 4096, 0x8837ff80
-0, 276480, 276480, 2048, 4096, 0x27a3de22
-0, 278528, 278528, 2048, 4096, 0xf88d28c1
-0, 280576, 280576, 2048, 4096, 0xed85ea97
-0, 282624, 282624, 2048, 4096, 0x50c3e7db
-0, 284672, 284672, 2048, 4096, 0x82bcb480
-0, 286720, 286720, 2048, 4096, 0xc50ee536
-0, 288768, 288768, 2048, 4096, 0x086280ee
-0, 290816, 290816, 2048, 4096, 0x6f18f2b2
-0, 292864, 292864, 2048, 4096, 0x1c7c0856
-0, 294912, 294912, 2048, 4096, 0xc576268a
-0, 296960, 296960, 2048, 4096, 0x7a9af56d
-0, 299008, 299008, 2048, 4096, 0x6d058fc5
-0, 301056, 301056, 2048, 4096, 0x8fb1107b
-0, 303104, 303104, 2048, 4096, 0x807588d1
-0, 305152, 305152, 2048, 4096, 0x56178443
-0, 307200, 307200, 2048, 4096, 0xf2460763
-0, 309248, 309248, 2048, 4096, 0x284255f2
-0, 311296, 311296, 2048, 4096, 0xb29d17fb
-0, 313344, 313344, 2048, 4096, 0x5e7e4633
-0, 315392, 315392, 2048, 4096, 0x57704db1
-0, 317440, 317440, 2048, 4096, 0xd87dcc1d
-0, 319488, 319488, 2048, 4096, 0x28d4bb93
-0, 321536, 321536, 2048, 4096, 0x3a2e5c6c
-0, 323584, 323584, 2048, 4096, 0xf3581656
-0, 325632, 325632, 2048, 4096, 0x42f1942f
-0, 327680, 327680, 2048, 4096, 0xe75c5092
-0, 329728, 329728, 2048, 4096, 0x3fae7f6d
-0, 331776, 331776, 2048, 4096, 0xf99ad73e
-0, 333824, 333824, 2048, 4096, 0x80564e3e
-0, 335872, 335872, 2048, 4096, 0x8ff6ebe5
-0, 337920, 337920, 2048, 4096, 0x436d5e69
-0, 339968, 339968, 684, 1368, 0xe0ebeda3
+0, 0, 0, 2048, 4096, 0x4f9228b3
+0, 2048, 2048, 2048, 4096, 0xfab58157
+0, 4096, 4096, 2048, 4096, 0x0b641c78
+0, 6144, 6144, 2048, 4096, 0x601c6803
+0, 8192, 8192, 2048, 4096, 0xb3e2f166
+0, 10240, 10240, 2048, 4096, 0x5681f206
+0, 12288, 12288, 2048, 4096, 0x1e69e71f
+0, 14336, 14336, 2048, 4096, 0x05628be3
+0, 16384, 16384, 2048, 4096, 0x109b1aef
+0, 18432, 18432, 2048, 4096, 0xd5435a9e
+0, 20480, 20480, 2048, 4096, 0xb38b5d28
+0, 22528, 22528, 2048, 4096, 0x64514c93
+0, 24576, 24576, 2048, 4096, 0x453350e7
+0, 26624, 26624, 2048, 4096, 0x6deccce6
+0, 28672, 28672, 2048, 4096, 0xd427ede1
+0, 30720, 30720, 2048, 4096, 0xdecb8c42
+0, 32768, 32768, 2048, 4096, 0x3841e4d2
+0, 34816, 34816, 2048, 4096, 0x858ac1b1
+0, 36864, 36864, 2048, 4096, 0x8e9dbfa0
+0, 38912, 38912, 2048, 4096, 0xcbc0766f
+0, 40960, 40960, 2048, 4096, 0x78d52555
+0, 43008, 43008, 2048, 4096, 0x600ac7d5
+0, 45056, 45056, 2048, 4096, 0xafadb7ee
+0, 47104, 47104, 2048, 4096, 0x8009d5a1
+0, 49152, 49152, 2048, 4096, 0xb07d475e
+0, 51200, 51200, 2048, 4096, 0xfcfecceb
+0, 53248, 53248, 2048, 4096, 0x38b5d85f
+0, 55296, 55296, 2048, 4096, 0xbd48072e
+0, 57344, 57344, 2048, 4096, 0xd04724d8
+0, 59392, 59392, 2048, 4096, 0x08425144
+0, 61440, 61440, 2048, 4096, 0x7b14483e
+0, 63488, 63488, 2048, 4096, 0x8858ef4c
+0, 65536, 65536, 2048, 4096, 0x1e3024c2
+0, 67584, 67584, 2048, 4096, 0xcd6bfe4f
+0, 69632, 69632, 2048, 4096, 0x8cde8d18
+0, 71680, 71680, 2048, 4096, 0xbbd856b8
+0, 73728, 73728, 2048, 4096, 0x988c9b7a
+0, 75776, 75776, 2048, 4096, 0x2a858e03
+0, 77824, 77824, 2048, 4096, 0x6dee1e4a
+0, 79872, 79872, 2048, 4096, 0x8cc38b41
+0, 81920, 81920, 2048, 4096, 0x48bd5cec
+0, 83968, 83968, 2048, 4096, 0xeb7f606b
+0, 86016, 86016, 2048, 4096, 0x75f5d28c
+0, 88064, 88064, 2048, 4096, 0x5bfeec4b
+0, 90112, 90112, 2048, 4096, 0xfc35c22a
+0, 92160, 92160, 2048, 4096, 0x3a95efba
+0, 94208, 94208, 2048, 4096, 0xefdbce9c
+0, 96256, 96256, 2048, 4096, 0x00594ada
+0, 98304, 98304, 2048, 4096, 0x20ffebfa
+0, 100352, 100352, 2048, 4096, 0x1b31370a
+0, 102400, 102400, 2048, 4096, 0x50766a56
+0, 104448, 104448, 2048, 4096, 0x0058315a
+0, 106496, 106496, 2048, 4096, 0x98090cbf
+0, 108544, 108544, 2048, 4096, 0x66ed2d40
+0, 110592, 110592, 2048, 4096, 0xdfd7c0a7
+0, 112640, 112640, 2048, 4096, 0x2adc57e1
+0, 114688, 114688, 2048, 4096, 0x838bbc82
+0, 116736, 116736, 2048, 4096, 0x2c55de1a
+0, 118784, 118784, 2048, 4096, 0xeae027f4
+0, 120832, 120832, 2048, 4096, 0x09fe00f6
+0, 122880, 122880, 2048, 4096, 0xa25d9970
+0, 124928, 124928, 2048, 4096, 0xedb11a20
+0, 126976, 126976, 2048, 4096, 0x9ce2e63e
+0, 129024, 129024, 2048, 4096, 0xeb699974
+0, 131072, 131072, 2048, 4096, 0xcc04a296
+0, 133120, 133120, 2048, 4096, 0xe90e9a12
+0, 135168, 135168, 2048, 4096, 0xae85c0f7
+0, 137216, 137216, 2048, 4096, 0x7ee877db
+0, 139264, 139264, 2048, 4096, 0x9ecf14ee
+0, 141312, 141312, 2048, 4096, 0xa821cecd
+0, 143360, 143360, 2048, 4096, 0x2714bb11
+0, 145408, 145408, 2048, 4096, 0x28f1c1e0
+0, 147456, 147456, 2048, 4096, 0xf81c4f60
+0, 149504, 149504, 2048, 4096, 0x1ae0e5a1
+0, 151552, 151552, 2048, 4096, 0xbdae9d9a
+0, 153600, 153600, 2048, 4096, 0x5202e560
+0, 155648, 155648, 2048, 4096, 0x82408396
+0, 157696, 157696, 2048, 4096, 0xc850ce0c
+0, 159744, 159744, 2048, 4096, 0x1d732d88
+0, 161792, 161792, 2048, 4096, 0xc5c01e33
+0, 163840, 163840, 2048, 4096, 0x84942d6c
+0, 165888, 165888, 2048, 4096, 0x7c27cd3a
+0, 167936, 167936, 2048, 4096, 0x22adc503
+0, 169984, 169984, 2048, 4096, 0xfbc3af31
+0, 172032, 172032, 2048, 4096, 0xe9652b18
+0, 174080, 174080, 2048, 4096, 0xae75987e
+0, 176128, 176128, 2048, 4096, 0x0f7ea428
+0, 178176, 178176, 2048, 4096, 0x92b89582
+0, 180224, 180224, 2048, 4096, 0xf393d910
+0, 182272, 182272, 2048, 4096, 0x6349b600
+0, 184320, 184320, 2048, 4096, 0x16918dbd
+0, 186368, 186368, 2048, 4096, 0x14ee15ad
+0, 188416, 188416, 2048, 4096, 0x26b510d3
+0, 190464, 190464, 2048, 4096, 0x97007bf8
+0, 192512, 192512, 2048, 4096, 0x3718c509
+0, 194560, 194560, 2048, 4096, 0x24a54ccd
+0, 196608, 196608, 2048, 4096, 0xc960df4e
+0, 198656, 198656, 2048, 4096, 0xc7cb6e6f
+0, 200704, 200704, 2048, 4096, 0x4c563ae5
+0, 202752, 202752, 2048, 4096, 0x0dd51432
+0, 204800, 204800, 2048, 4096, 0xdb4243c8
+0, 206848, 206848, 2048, 4096, 0x9bb6417f
+0, 208896, 208896, 2048, 4096, 0xec6a40a1
+0, 210944, 210944, 2048, 4096, 0x82d6c3b4
+0, 212992, 212992, 2048, 4096, 0xd181e2ec
+0, 215040, 215040, 2048, 4096, 0xba5d7b55
+0, 217088, 217088, 2048, 4096, 0x78fcb938
+0, 219136, 219136, 2048, 4096, 0x6691671c
+0, 221184, 221184, 2048, 4096, 0x44fadee7
+0, 223232, 223232, 2048, 4096, 0xa42720d5
+0, 225280, 225280, 2048, 4096, 0xc1165a91
+0, 227328, 227328, 2048, 4096, 0x86aa3e3f
+0, 229376, 229376, 2048, 4096, 0xab5ae57d
+0, 231424, 231424, 2048, 4096, 0x291a91f3
+0, 233472, 233472, 2048, 4096, 0xfdf0dcfc
+0, 235520, 235520, 2048, 4096, 0x1ef91f67
+0, 237568, 237568, 2048, 4096, 0xc899efee
+0, 239616, 239616, 2048, 4096, 0x5ade15ac
+0, 241664, 241664, 2048, 4096, 0x04516beb
+0, 243712, 243712, 2048, 4096, 0xbf5ebbb9
+0, 245760, 245760, 2048, 4096, 0x4a235122
+0, 247808, 247808, 2048, 4096, 0xd7a3f4a6
+0, 249856, 249856, 2048, 4096, 0x5f900f20
+0, 251904, 251904, 2048, 4096, 0xa90b4365
+0, 253952, 253952, 2048, 4096, 0x63149dc4
+0, 256000, 256000, 2048, 4096, 0xf12c1ee8
+0, 258048, 258048, 2048, 4096, 0x6d0fec8c
+0, 260096, 260096, 2048, 4096, 0x65e07850
+0, 262144, 262144, 2048, 4096, 0x16d951cc
+0, 264192, 264192, 2048, 4096, 0xd296d0c4
+0, 266240, 266240, 2048, 4096, 0x619b2a53
+0, 268288, 268288, 2048, 4096, 0x316972d5
+0, 270336, 270336, 2048, 4096, 0xcfd64e21
+0, 272384, 272384, 2048, 4096, 0xcbcb10c6
+0, 274432, 274432, 2048, 4096, 0x20aeff7c
+0, 276480, 276480, 2048, 4096, 0xd205dabd
+0, 278528, 278528, 2048, 4096, 0xac9d3001
+0, 280576, 280576, 2048, 4096, 0x6d53dfdd
+0, 282624, 282624, 2048, 4096, 0xbb9fe15c
+0, 284672, 284672, 2048, 4096, 0x1852b88b
+0, 286720, 286720, 2048, 4096, 0xb0acec01
+0, 288768, 288768, 2048, 4096, 0xb52a9342
+0, 290816, 290816, 2048, 4096, 0x7529faee
+0, 292864, 292864, 2048, 4096, 0x150ff449
+0, 294912, 294912, 2048, 4096, 0xa81d31d9
+0, 296960, 296960, 2048, 4096, 0xbcb8084a
+0, 299008, 299008, 2048, 4096, 0x07229514
+0, 301056, 301056, 2048, 4096, 0xa85cfd88
+0, 303104, 303104, 2048, 4096, 0x0aef9c27
+0, 305152, 305152, 2048, 4096, 0x8ec47b39
+0, 307200, 307200, 2048, 4096, 0x910b0560
+0, 309248, 309248, 2048, 4096, 0x99a8578e
+0, 311296, 311296, 2048, 4096, 0xb3df1d84
+0, 313344, 313344, 2048, 4096, 0x48e52559
+0, 315392, 315392, 2048, 4096, 0xb25c4800
+0, 317440, 317440, 2048, 4096, 0x913bc8ce
+0, 319488, 319488, 2048, 4096, 0xb736cc8c
+0, 321536, 321536, 2048, 4096, 0x13c66646
+0, 323584, 323584, 2048, 4096, 0x70a71221
+0, 325632, 325632, 2048, 4096, 0x3a50a08e
+0, 327680, 327680, 2048, 4096, 0xc0a037b0
+0, 329728, 329728, 2048, 4096, 0x9a789475
+0, 331776, 331776, 2048, 4096, 0xc890ca16
+0, 333824, 333824, 2048, 4096, 0xa0d34bed
+0, 335872, 335872, 2048, 4096, 0x1689fa60
+0, 337920, 337920, 2048, 4096, 0x5bac4c83
+0, 339968, 339968, 684, 1368, 0x904be5e5
diff --git a/tests/ref/fate/g722enc b/tests/ref/fate/g722enc
index c1094565b5..9b8e469a8b 100644
--- a/tests/ref/fate/g722enc
+++ b/tests/ref/fate/g722enc
@@ -1 +1 @@
-750269cc236541df28e15da5c7b0df7a
+94e2f200d6e05b47cec4aa3e94571cf3