Browse code

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>

Michael Niedermayer authored on 2012/03/03 08:09:47
Showing 80 changed files
... ...
@@ -9,6 +9,7 @@ version next:
9 9
 - ffprobe -count_packets and -count_frames options
10 10
 - Sun Rasterfile Encoder
11 11
 - ID3v2 attached pictures reading and writing
12
+- WMA Lossless decoder
12 13
 
13 14
 
14 15
 version 0.10:
... ...
@@ -811,6 +811,7 @@ following image formats are supported:
811 811
 @item Westwood Audio (SND1)  @tab     @tab  X
812 812
 @item Windows Media Audio 1  @tab  X  @tab  X
813 813
 @item Windows Media Audio 2  @tab  X  @tab  X
814
+@item Windows Media Audio Lossless @tab  @tab  X
814 815
 @item Windows Media Audio Pro @tab    @tab  X
815 816
 @item Windows Media Audio Voice @tab  @tab  X
816 817
 @end multitable
... ...
@@ -299,12 +299,14 @@ OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL)     += vaapi_mpeg4.o
299 299
 OBJS-$(CONFIG_MSMPEG4V1_DECODER)       += msmpeg4.o msmpeg4data.o
300 300
 OBJS-$(CONFIG_MSMPEG4V2_DECODER)       += msmpeg4.o msmpeg4data.o h263dec.o \
301 301
                                           h263.o ituh263dec.o mpeg4videodec.o
302
-OBJS-$(CONFIG_MSMPEG4V2_ENCODER)       += msmpeg4.o msmpeg4data.o h263dec.o \
303
-                                          h263.o ituh263dec.o mpeg4videodec.o
302
+OBJS-$(CONFIG_MSMPEG4V2_ENCODER)       += msmpeg4.o msmpeg4enc.o msmpeg4data.o \
303
+                                          h263dec.o h263.o ituh263dec.o        \
304
+                                          mpeg4videodec.o
304 305
 OBJS-$(CONFIG_MSMPEG4V3_DECODER)       += msmpeg4.o msmpeg4data.o h263dec.o \
305 306
                                           h263.o ituh263dec.o mpeg4videodec.o
306
-OBJS-$(CONFIG_MSMPEG4V3_ENCODER)       += msmpeg4.o msmpeg4data.o h263dec.o \
307
-                                          h263.o ituh263dec.o mpeg4videodec.o
307
+OBJS-$(CONFIG_MSMPEG4V3_ENCODER)       += msmpeg4.o msmpeg4enc.o msmpeg4data.o \
308
+                                          h263dec.o h263.o ituh263dec.o        \
309
+                                          mpeg4videodec.o
308 310
 OBJS-$(CONFIG_MSRLE_DECODER)           += msrle.o msrledec.o
309 311
 OBJS-$(CONFIG_MSVIDEO1_DECODER)        += msvideo1.o
310 312
 OBJS-$(CONFIG_MSVIDEO1_ENCODER)        += msvideo1enc.o elbg.o
... ...
@@ -471,7 +473,7 @@ OBJS-$(CONFIG_WMV2_DECODER)            += wmv2dec.o wmv2.o        \
471 471
                                           msmpeg4.o msmpeg4data.o \
472 472
                                           intrax8.o intrax8dsp.o
473 473
 OBJS-$(CONFIG_WMV2_ENCODER)            += wmv2enc.o wmv2.o \
474
-                                          msmpeg4.o msmpeg4data.o \
474
+                                          msmpeg4.o msmpeg4enc.o msmpeg4data.o \
475 475
                                           mpeg4videodec.o ituh263dec.o h263dec.o
476 476
 OBJS-$(CONFIG_WNV1_DECODER)            += wnv1.o
477 477
 OBJS-$(CONFIG_WS_SND1_DECODER)         += ws-snd1.o
... ...
@@ -246,7 +246,7 @@ static int a64multi_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
246 246
                                  const AVFrame *pict, int *got_packet)
247 247
 {
248 248
     A64Context *c = avctx->priv_data;
249
-    AVFrame *const p = (AVFrame *) & c->picture;
249
+    AVFrame *const p = &c->picture;
250 250
 
251 251
     int frame;
252 252
     int x, y;
... ...
@@ -898,10 +898,10 @@ static float auto_correlation(float *diff_isf, float mean, int lag)
898 898
  * Extrapolate a ISF vector to the 16kHz range (20th order LP)
899 899
  * used at mode 6k60 LP filter for the high frequency band.
900 900
  *
901
- * @param[out] out                 Buffer for extrapolated isf
902
- * @param[in]  isf                 Input isf vector
901
+ * @param[out] isf Buffer for extrapolated isf; contains LP_ORDER
902
+ *                 values on input
903 903
  */
904
-static void extrapolate_isf(float out[LP_ORDER_16k], float isf[LP_ORDER])
904
+static void extrapolate_isf(float isf[LP_ORDER_16k])
905 905
 {
906 906
     float diff_isf[LP_ORDER - 2], diff_mean;
907 907
     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])
909 909
     float est, scale;
910 910
     int i, i_max_corr;
911 911
 
912
-    memcpy(out, isf, (LP_ORDER - 1) * sizeof(float));
913
-    out[LP_ORDER_16k - 1] = isf[LP_ORDER - 1];
912
+    isf[LP_ORDER_16k - 1] = isf[LP_ORDER - 1];
914 913
 
915 914
     /* Calculate the difference vector */
916 915
     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])
931 931
     i_max_corr++;
932 932
 
933 933
     for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++)
934
-        out[i] = isf[i - 1] + isf[i - 1 - i_max_corr]
934
+        isf[i] = isf[i - 1] + isf[i - 1 - i_max_corr]
935 935
                             - isf[i - 2 - i_max_corr];
936 936
 
937 937
     /* Calculate an estimate for ISF(18) and scale ISF based on the error */
938
-    est   = 7965 + (out[2] - out[3] - out[4]) / 6.0;
939
-    scale = 0.5 * (FFMIN(est, 7600) - out[LP_ORDER - 2]) /
940
-            (out[LP_ORDER_16k - 2] - out[LP_ORDER - 2]);
938
+    est   = 7965 + (isf[2] - isf[3] - isf[4]) / 6.0;
939
+    scale = 0.5 * (FFMIN(est, 7600) - isf[LP_ORDER - 2]) /
940
+            (isf[LP_ORDER_16k - 2] - isf[LP_ORDER - 2]);
941 941
 
942 942
     for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++)
943
-        diff_hi[i] = scale * (out[i] - out[i - 1]);
943
+        diff_hi[i] = scale * (isf[i] - isf[i - 1]);
944 944
 
945 945
     /* Stability insurance */
946 946
     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])
952 952
         }
953 953
 
954 954
     for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++)
955
-        out[i] = out[i - 1] + diff_hi[i] * (1.0f / (1 << 15));
955
+        isf[i] = isf[i - 1] + diff_hi[i] * (1.0f / (1 << 15));
956 956
 
957 957
     /* Scale the ISF vector for 16000 Hz */
958 958
     for (i = 0; i < LP_ORDER_16k - 1; i++)
959
-        out[i] *= 0.8;
959
+        isf[i] *= 0.8;
960 960
 }
961 961
 
962 962
 /**
... ...
@@ -1003,7 +1002,7 @@ static void hb_synthesis(AMRWBContext *ctx, int subframe, float *samples,
1003 1003
         ff_weighted_vector_sumf(e_isf, isf_past, isf, isfp_inter[subframe],
1004 1004
                                 1.0 - isfp_inter[subframe], LP_ORDER);
1005 1005
 
1006
-        extrapolate_isf(e_isf, e_isf);
1006
+        extrapolate_isf(e_isf);
1007 1007
 
1008 1008
         e_isf[LP_ORDER_16k - 1] *= 2.0;
1009 1009
         ff_acelp_lsf2lspd(e_isp, e_isf, LP_ORDER_16k);
... ...
@@ -1095,23 +1094,27 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data,
1095 1095
     buf_out = (float *)ctx->avframe.data[0];
1096 1096
 
1097 1097
     header_size      = decode_mime_header(ctx, buf);
1098
+    if (ctx->fr_cur_mode > MODE_SID) {
1099
+        av_log(avctx, AV_LOG_ERROR,
1100
+               "Invalid mode %d\n", ctx->fr_cur_mode);
1101
+        return AVERROR_INVALIDDATA;
1102
+    }
1098 1103
     expected_fr_size = ((cf_sizes_wb[ctx->fr_cur_mode] + 7) >> 3) + 1;
1099 1104
 
1100 1105
     if (buf_size < expected_fr_size) {
1101 1106
         av_log(avctx, AV_LOG_ERROR,
1102 1107
             "Frame too small (%d bytes). Truncated file?\n", buf_size);
1103 1108
         *got_frame_ptr = 0;
1104
-        return buf_size;
1109
+        return AVERROR_INVALIDDATA;
1105 1110
     }
1106 1111
 
1107 1112
     if (!ctx->fr_quality || ctx->fr_cur_mode > MODE_SID)
1108 1113
         av_log(avctx, AV_LOG_ERROR, "Encountered a bad or corrupted frame\n");
1109 1114
 
1110
-    if (ctx->fr_cur_mode == MODE_SID) /* Comfort noise frame */
1115
+    if (ctx->fr_cur_mode == MODE_SID) { /* Comfort noise frame */
1111 1116
         av_log_missing_feature(avctx, "SID mode", 1);
1112
-
1113
-    if (ctx->fr_cur_mode >= MODE_SID)
1114 1117
         return -1;
1118
+    }
1115 1119
 
1116 1120
     ff_amr_bit_reorder((uint16_t *) &ctx->frame, sizeof(AMRWBFrame),
1117 1121
         buf + header_size, amr_bit_orderings_by_mode[ctx->fr_cur_mode]);
... ...
@@ -23,87 +23,87 @@ void ff_vp8_luma_dc_wht_dc_armv6(DCTELEM block[4][4][16], DCTELEM dc[16]);
23 23
 
24 24
 #define idct_funcs(opt) \
25 25
 void ff_vp8_luma_dc_wht_ ## opt(DCTELEM block[4][4][16], DCTELEM dc[16]); \
26
-void ff_vp8_idct_add_ ## opt(uint8_t *dst, DCTELEM block[16], int stride); \
27
-void ff_vp8_idct_dc_add_ ## opt(uint8_t *dst, DCTELEM block[16], int stride); \
28
-void ff_vp8_idct_dc_add4y_ ## opt(uint8_t *dst, DCTELEM block[4][16], int stride); \
29
-void ff_vp8_idct_dc_add4uv_ ## opt(uint8_t *dst, DCTELEM block[4][16], int stride)
26
+void ff_vp8_idct_add_ ## opt(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride); \
27
+void ff_vp8_idct_dc_add_ ## opt(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride); \
28
+void ff_vp8_idct_dc_add4y_ ## opt(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride); \
29
+void ff_vp8_idct_dc_add4uv_ ## opt(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride)
30 30
 
31 31
 idct_funcs(neon);
32 32
 idct_funcs(armv6);
33 33
 
34
-void ff_vp8_v_loop_filter16_neon(uint8_t *dst, int stride,
34
+void ff_vp8_v_loop_filter16_neon(uint8_t *dst, ptrdiff_t stride,
35 35
                                  int flim_E, int flim_I, int hev_thresh);
36
-void ff_vp8_h_loop_filter16_neon(uint8_t *dst, int stride,
36
+void ff_vp8_h_loop_filter16_neon(uint8_t *dst, ptrdiff_t stride,
37 37
                                  int flim_E, int flim_I, int hev_thresh);
38
-void ff_vp8_v_loop_filter8uv_neon(uint8_t *dstU, uint8_t *dstV, int stride,
38
+void ff_vp8_v_loop_filter8uv_neon(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,
39 39
                                   int flim_E, int flim_I, int hev_thresh);
40
-void ff_vp8_h_loop_filter8uv_neon(uint8_t *dstU, uint8_t *dstV, int stride,
40
+void ff_vp8_h_loop_filter8uv_neon(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,
41 41
                                   int flim_E, int flim_I, int hev_thresh);
42 42
 
43
-void ff_vp8_v_loop_filter16_inner_neon(uint8_t *dst, int stride,
43
+void ff_vp8_v_loop_filter16_inner_neon(uint8_t *dst, ptrdiff_t stride,
44 44
                                        int flim_E, int flim_I, int hev_thresh);
45
-void ff_vp8_h_loop_filter16_inner_neon(uint8_t *dst, int stride,
45
+void ff_vp8_h_loop_filter16_inner_neon(uint8_t *dst, ptrdiff_t stride,
46 46
                                        int flim_E, int flim_I, int hev_thresh);
47 47
 void ff_vp8_v_loop_filter8uv_inner_neon(uint8_t *dstU, uint8_t *dstV,
48
-                                        int stride, int flim_E, int flim_I,
48
+                                        ptrdiff_t stride, int flim_E, int flim_I,
49 49
                                         int hev_thresh);
50 50
 void ff_vp8_h_loop_filter8uv_inner_neon(uint8_t *dstU, uint8_t *dstV,
51
-                                        int stride, int flim_E, int flim_I,
51
+                                        ptrdiff_t stride, int flim_E, int flim_I,
52 52
                                         int hev_thresh);
53 53
 
54
-void ff_vp8_v_loop_filter_inner_armv6(uint8_t *dst, int stride,
54
+void ff_vp8_v_loop_filter_inner_armv6(uint8_t *dst, ptrdiff_t stride,
55 55
                                       int flim_E, int flim_I,
56 56
                                       int hev_thresh, int count);
57
-void ff_vp8_h_loop_filter_inner_armv6(uint8_t *dst, int stride,
57
+void ff_vp8_h_loop_filter_inner_armv6(uint8_t *dst, ptrdiff_t stride,
58 58
                                       int flim_E, int flim_I,
59 59
                                       int hev_thresh, int count);
60
-void ff_vp8_v_loop_filter_armv6(uint8_t *dst, int stride,
60
+void ff_vp8_v_loop_filter_armv6(uint8_t *dst, ptrdiff_t stride,
61 61
                                 int flim_E, int flim_I,
62 62
                                 int hev_thresh, int count);
63
-void ff_vp8_h_loop_filter_armv6(uint8_t *dst, int stride,
63
+void ff_vp8_h_loop_filter_armv6(uint8_t *dst, ptrdiff_t stride,
64 64
                                 int flim_E, int flim_I,
65 65
                                 int hev_thresh, int count);
66 66
 
67
-static void ff_vp8_v_loop_filter16_armv6(uint8_t *dst, int stride,
67
+static void ff_vp8_v_loop_filter16_armv6(uint8_t *dst, ptrdiff_t stride,
68 68
                                          int flim_E, int flim_I, int hev_thresh)
69 69
 {
70 70
     ff_vp8_v_loop_filter_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4);
71 71
 }
72 72
 
73
-static void ff_vp8_h_loop_filter16_armv6(uint8_t *dst, int stride,
73
+static void ff_vp8_h_loop_filter16_armv6(uint8_t *dst, ptrdiff_t stride,
74 74
                                          int flim_E, int flim_I, int hev_thresh)
75 75
 {
76 76
     ff_vp8_h_loop_filter_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4);
77 77
 }
78 78
 
79
-static void ff_vp8_v_loop_filter8uv_armv6(uint8_t *dstU, uint8_t *dstV, int stride,
79
+static void ff_vp8_v_loop_filter8uv_armv6(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,
80 80
                                           int flim_E, int flim_I, int hev_thresh)
81 81
 {
82 82
     ff_vp8_v_loop_filter_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2);
83 83
     ff_vp8_v_loop_filter_armv6(dstV, stride, flim_E, flim_I, hev_thresh, 2);
84 84
 }
85 85
 
86
-static void ff_vp8_h_loop_filter8uv_armv6(uint8_t *dstU, uint8_t *dstV, int stride,
86
+static void ff_vp8_h_loop_filter8uv_armv6(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,
87 87
                                           int flim_E, int flim_I, int hev_thresh)
88 88
 {
89 89
     ff_vp8_h_loop_filter_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2);
90 90
     ff_vp8_h_loop_filter_armv6(dstV, stride, flim_E, flim_I, hev_thresh, 2);
91 91
 }
92 92
 
93
-static void ff_vp8_v_loop_filter16_inner_armv6(uint8_t *dst, int stride,
93
+static void ff_vp8_v_loop_filter16_inner_armv6(uint8_t *dst, ptrdiff_t stride,
94 94
                                                int flim_E, int flim_I, int hev_thresh)
95 95
 {
96 96
     ff_vp8_v_loop_filter_inner_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4);
97 97
 }
98 98
 
99
-static void ff_vp8_h_loop_filter16_inner_armv6(uint8_t *dst, int stride,
99
+static void ff_vp8_h_loop_filter16_inner_armv6(uint8_t *dst, ptrdiff_t stride,
100 100
                                                int flim_E, int flim_I, int hev_thresh)
101 101
 {
102 102
     ff_vp8_h_loop_filter_inner_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4);
103 103
 }
104 104
 
105 105
 static void ff_vp8_v_loop_filter8uv_inner_armv6(uint8_t *dstU, uint8_t *dstV,
106
-                                                int stride, int flim_E, int flim_I,
106
+                                                ptrdiff_t stride, int flim_E, int flim_I,
107 107
                                                 int hev_thresh)
108 108
 {
109 109
     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,
111 111
 }
112 112
 
113 113
 static void ff_vp8_h_loop_filter8uv_inner_armv6(uint8_t *dstU, uint8_t *dstV,
114
-                                                int stride, int flim_E, int flim_I,
114
+                                                ptrdiff_t stride, int flim_E, int flim_I,
115 115
                                                 int hev_thresh)
116 116
 {
117 117
     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,
119 119
 }
120 120
 
121 121
 #define simple_lf_funcs(opt) \
122
-void ff_vp8_v_loop_filter16_simple_ ## opt(uint8_t *dst, int stride, int flim); \
123
-void ff_vp8_h_loop_filter16_simple_ ## opt(uint8_t *dst, int stride, int flim)
122
+void ff_vp8_v_loop_filter16_simple_ ## opt(uint8_t *dst, ptrdiff_t stride, int flim); \
123
+void ff_vp8_h_loop_filter16_simple_ ## opt(uint8_t *dst, ptrdiff_t stride, int flim)
124 124
 
125 125
 simple_lf_funcs(neon);
126 126
 simple_lf_funcs(armv6);
127 127
 
128
-#define VP8_MC_OPT(n, opt)                                              \
129
-    void ff_put_vp8_##n##_##opt(uint8_t *dst, int dststride,            \
130
-                                uint8_t *src, int srcstride,            \
131
-                                int h, int x, int y)
128
+#define VP8_MC(n)                                                       \
129
+    void ff_put_vp8_##n##_neon(uint8_t *dst, ptrdiff_t dststride,       \
130
+                               uint8_t *src, ptrdiff_t srcstride,       \
131
+                               int h, int x, int y)
132 132
 
133 133
 #define VP8_MC(n) \
134 134
     VP8_MC_OPT(n, neon)
... ...
@@ -454,7 +454,7 @@ static int decode_frame(AVCodecContext *avctx,
454 454
         }
455 455
     }
456 456
 
457
-    *picture= *(AVFrame*)&a->picture;
457
+    *picture   = a->picture;
458 458
     *data_size = sizeof(AVPicture);
459 459
 
460 460
     emms_c();
... ...
@@ -51,7 +51,7 @@ avs_decode_frame(AVCodecContext * avctx,
51 51
     int buf_size = avpkt->size;
52 52
     AvsContext *const avs = avctx->priv_data;
53 53
     AVFrame *picture = data;
54
-    AVFrame *const p = (AVFrame *) & avs->picture;
54
+    AVFrame *const p =  &avs->picture;
55 55
     const uint8_t *table, *vect;
56 56
     uint8_t *out;
57 57
     int i, j, x, y, stride, vect_w = 3, vect_h = 3;
... ...
@@ -151,7 +151,7 @@ avs_decode_frame(AVCodecContext * avctx,
151 151
             align_get_bits(&change_map);
152 152
     }
153 153
 
154
-    *picture = *(AVFrame *) & avs->picture;
154
+    *picture   = avs->picture;
155 155
     *data_size = sizeof(AVPicture);
156 156
 
157 157
     return buf_size;
... ...
@@ -27,8 +27,8 @@
27 27
 static av_cold int bmp_decode_init(AVCodecContext *avctx){
28 28
     BMPContext *s = avctx->priv_data;
29 29
 
30
-    avcodec_get_frame_defaults((AVFrame*)&s->picture);
31
-    avctx->coded_frame = (AVFrame*)&s->picture;
30
+    avcodec_get_frame_defaults(&s->picture);
31
+    avctx->coded_frame = &s->picture;
32 32
 
33 33
     return 0;
34 34
 }
... ...
@@ -34,8 +34,8 @@ static const uint32_t rgb444_masks[]  = { 0x0F00, 0x00F0, 0x000F };
34 34
 static av_cold int bmp_encode_init(AVCodecContext *avctx){
35 35
     BMPContext *s = avctx->priv_data;
36 36
 
37
-    avcodec_get_frame_defaults((AVFrame*)&s->picture);
38
-    avctx->coded_frame = (AVFrame*)&s->picture;
37
+    avcodec_get_frame_defaults(&s->picture);
38
+    avctx->coded_frame = &s->picture;
39 39
 
40 40
     switch (avctx->pix_fmt) {
41 41
     case PIX_FMT_BGRA:
... ...
@@ -72,7 +72,7 @@ static int bmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
72 72
                             const AVFrame *pict, int *got_packet)
73 73
 {
74 74
     BMPContext *s = avctx->priv_data;
75
-    AVFrame * const p= (AVFrame*)&s->picture;
75
+    AVFrame * const p = &s->picture;
76 76
     int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize, ret;
77 77
     const uint32_t *pal = NULL;
78 78
     uint32_t palette256[256];
... ...
@@ -501,9 +501,9 @@ static int decode_pic(AVSContext *h) {
501 501
     }
502 502
     /* release last B frame */
503 503
     if(h->picture.f.data[0])
504
-        s->avctx->release_buffer(s->avctx, (AVFrame *)&h->picture);
504
+        s->avctx->release_buffer(s->avctx, &h->picture.f);
505 505
 
506
-    s->avctx->get_buffer(s->avctx, (AVFrame *)&h->picture);
506
+    s->avctx->get_buffer(s->avctx, &h->picture.f);
507 507
     ff_cavs_init_pic(h);
508 508
     h->picture.poc = get_bits(&s->gb,8)*2;
509 509
 
... ...
@@ -592,7 +592,7 @@ static int decode_pic(AVSContext *h) {
592 592
     }
593 593
     if(h->pic_type != AV_PICTURE_TYPE_B) {
594 594
         if(h->DPB[1].f.data[0])
595
-            s->avctx->release_buffer(s->avctx, (AVFrame *)&h->DPB[1]);
595
+            s->avctx->release_buffer(s->avctx, &h->DPB[1].f);
596 596
         h->DPB[1] = h->DPB[0];
597 597
         h->DPB[0] = h->picture;
598 598
         memset(&h->picture,0,sizeof(Picture));
... ...
@@ -656,7 +656,7 @@ static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
656 656
     if (buf_size == 0) {
657 657
         if (!s->low_delay && h->DPB[0].f.data[0]) {
658 658
             *data_size = sizeof(AVPicture);
659
-            *picture = *(AVFrame *) &h->DPB[0];
659
+            *picture = h->DPB[0].f;
660 660
         }
661 661
         return 0;
662 662
     }
... ...
@@ -676,9 +676,9 @@ static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
676 676
         case PIC_I_START_CODE:
677 677
             if(!h->got_keyframe) {
678 678
                 if(h->DPB[0].f.data[0])
679
-                    avctx->release_buffer(avctx, (AVFrame *)&h->DPB[0]);
679
+                    avctx->release_buffer(avctx, &h->DPB[0].f);
680 680
                 if(h->DPB[1].f.data[0])
681
-                    avctx->release_buffer(avctx, (AVFrame *)&h->DPB[1]);
681
+                    avctx->release_buffer(avctx, &h->DPB[1].f);
682 682
                 h->got_keyframe = 1;
683 683
             }
684 684
         case PIC_PB_START_CODE:
... ...
@@ -692,12 +692,12 @@ static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
692 692
             *data_size = sizeof(AVPicture);
693 693
             if(h->pic_type != AV_PICTURE_TYPE_B) {
694 694
                 if(h->DPB[1].f.data[0]) {
695
-                    *picture = *(AVFrame *) &h->DPB[1];
695
+                    *picture = h->DPB[1].f;
696 696
                 } else {
697 697
                     *data_size = 0;
698 698
                 }
699 699
             } else
700
-                *picture = *(AVFrame *) &h->picture;
700
+                *picture = h->picture.f;
701 701
             break;
702 702
         case EXT_START_CODE:
703 703
             //mpeg_decode_extension(avctx,buf_ptr, input_size);
... ...
@@ -613,7 +613,7 @@ skip_mean_and_median:
613 613
                         if (s->avctx->codec_id == CODEC_ID_H264) {
614 614
                             // FIXME
615 615
                         } else {
616
-                            ff_thread_await_progress((AVFrame *) s->last_picture_ptr,
616
+                            ff_thread_await_progress(&s->last_picture_ptr->f,
617 617
                                                      mb_y, 0);
618 618
                         }
619 619
                         if (!s->last_picture.f.motion_val[0] ||
... ...
@@ -786,7 +786,7 @@ static int is_intra_more_likely(MpegEncContext *s)
786 786
                 if (s->avctx->codec_id == CODEC_ID_H264) {
787 787
                     // FIXME
788 788
                 } else {
789
-                    ff_thread_await_progress((AVFrame *) s->last_picture_ptr,
789
+                    ff_thread_await_progress(&s->last_picture_ptr->f,
790 790
                                              mb_y, 0);
791 791
                 }
792 792
                 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)
1170 1170
                     if (s->avctx->codec_id == CODEC_ID_H264) {
1171 1171
                         // FIXME
1172 1172
                     } else {
1173
-                        ff_thread_await_progress((AVFrame *) s->next_picture_ptr, mb_y, 0);
1173
+                        ff_thread_await_progress(&s->next_picture_ptr->f, mb_y, 0);
1174 1174
                     }
1175 1175
                     s->mv[0][0][0] = s->next_picture.f.motion_val[0][xy][0] *  time_pb            / time_pp;
1176 1176
                     s->mv[0][0][1] = s->next_picture.f.motion_val[0][xy][1] *  time_pb            / time_pp;
... ...
@@ -62,7 +62,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
62 62
     FrapsContext * const s = avctx->priv_data;
63 63
 
64 64
     avcodec_get_frame_defaults(&s->frame);
65
-    avctx->coded_frame = (AVFrame*)&s->frame;
65
+    avctx->coded_frame = &s->frame;
66 66
 
67 67
     s->avctx = avctx;
68 68
     s->tmpbuf = NULL;
... ...
@@ -132,7 +132,7 @@ static int decode_frame(AVCodecContext *avctx,
132 132
     int buf_size = avpkt->size;
133 133
     FrapsContext * const s = avctx->priv_data;
134 134
     AVFrame *frame = data;
135
-    AVFrame * const f = (AVFrame*)&s->frame;
135
+    AVFrame * const f = &s->frame;
136 136
     uint32_t header;
137 137
     unsigned int version,header_size;
138 138
     unsigned int x, y;
... ...
@@ -126,8 +126,8 @@ static int g722_decode_frame(AVCodecContext *avctx, void *data,
126 126
         c->prev_samples[c->prev_samples_pos++] = rlow - rhigh;
127 127
         ff_g722_apply_qmf(c->prev_samples + c->prev_samples_pos - 24,
128 128
                           &xout1, &xout2);
129
-        *out_buf++ = av_clip_int16(xout1 >> 12);
130
-        *out_buf++ = av_clip_int16(xout2 >> 12);
129
+        *out_buf++ = av_clip_int16(xout1 >> 11);
130
+        *out_buf++ = av_clip_int16(xout2 >> 11);
131 131
         if (c->prev_samples_pos >= PREV_SAMPLES_BUF_SIZE) {
132 132
             memmove(c->prev_samples, c->prev_samples + c->prev_samples_pos - 22,
133 133
                     22 * sizeof(c->prev_samples[0]));
... ...
@@ -136,8 +136,8 @@ static inline void filter_samples(G722Context *c, const int16_t *samples,
136 136
     c->prev_samples[c->prev_samples_pos++] = samples[0];
137 137
     c->prev_samples[c->prev_samples_pos++] = samples[1];
138 138
     ff_g722_apply_qmf(c->prev_samples + c->prev_samples_pos - 24, &xout1, &xout2);
139
-    *xlow  = xout1 + xout2 >> 13;
140
-    *xhigh = xout1 - xout2 >> 13;
139
+    *xlow  = xout1 + xout2 >> 14;
140
+    *xhigh = xout1 - xout2 >> 14;
141 141
     if (c->prev_samples_pos >= PREV_SAMPLES_BUF_SIZE) {
142 142
         memmove(c->prev_samples,
143 143
                 c->prev_samples + c->prev_samples_pos - 22,
... ...
@@ -160,7 +160,7 @@ static int gif_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
160 160
                             const AVFrame *pict, int *got_packet)
161 161
 {
162 162
     GIFContext *s = avctx->priv_data;
163
-    AVFrame *const p = (AVFrame *)&s->picture;
163
+    AVFrame *const p = &s->picture;
164 164
     uint8_t *outbuf_ptr, *end;
165 165
     int ret;
166 166
 
... ...
@@ -628,7 +628,8 @@ retry:
628 628
 
629 629
 assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);
630 630
 assert(s->current_picture.f.pict_type == s->pict_type);
631
-    *pict= *(AVFrame*)s->current_picture_ptr;
631
+
632
+    *pict = s->current_picture_ptr->f;
632 633
     ff_print_debug_info(s, pict);
633 634
 
634 635
     *data_size = sizeof(AVFrame);
... ...
@@ -357,7 +357,7 @@ uint64_t time= rdtsc();
357 357
     if (buf_size == 0) {
358 358
         /* special case for last picture */
359 359
         if (s->low_delay==0 && s->next_picture_ptr) {
360
-            *pict= *(AVFrame*)s->next_picture_ptr;
360
+            *pict = s->next_picture_ptr->f;
361 361
             s->next_picture_ptr= NULL;
362 362
 
363 363
             *data_size = sizeof(AVFrame);
... ...
@@ -727,9 +727,9 @@ intrax8_decoded:
727 727
     assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);
728 728
     assert(s->current_picture.f.pict_type == s->pict_type);
729 729
     if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
730
-        *pict= *(AVFrame*)s->current_picture_ptr;
730
+        *pict = s->current_picture_ptr->f;
731 731
     } else if (s->last_picture_ptr != NULL) {
732
-        *pict= *(AVFrame*)s->last_picture_ptr;
732
+        *pict = s->last_picture_ptr->f;
733 733
     }
734 734
 
735 735
     if(s->last_picture_ptr || s->low_delay){
... ...
@@ -367,14 +367,14 @@ static void await_references(H264Context *h){
367 367
                 nrefs[list]--;
368 368
 
369 369
                 if(!FIELD_PICTURE && ref_field_picture){ // frame referencing two fields
370
-                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) - !(row&1), pic_height-1), 1);
371
-                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1)           , pic_height-1), 0);
370
+                    ff_thread_await_progress(&ref_pic->f, FFMIN((row >> 1) - !(row & 1), pic_height - 1), 1);
371
+                    ff_thread_await_progress(&ref_pic->f, FFMIN((row >> 1),              pic_height - 1), 0);
372 372
                 }else if(FIELD_PICTURE && !ref_field_picture){ // field referencing one field of a frame
373
-                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row*2 + ref_field    , pic_height-1), 0);
373
+                    ff_thread_await_progress(&ref_pic->f, FFMIN(row * 2 + ref_field, pic_height - 1), 0);
374 374
                 }else if(FIELD_PICTURE){
375
-                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), ref_field);
375
+                    ff_thread_await_progress(&ref_pic->f, FFMIN(row, pic_height - 1), ref_field);
376 376
                 }else{
377
-                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), 0);
377
+                    ff_thread_await_progress(&ref_pic->f, FFMIN(row, pic_height - 1), 0);
378 378
                 }
379 379
             }
380 380
         }
... ...
@@ -2507,8 +2507,9 @@ static int field_end(H264Context *h, int in_setup){
2507 2507
     s->mb_y= 0;
2508 2508
 
2509 2509
     if (!in_setup && !s->dropable)
2510
-        ff_thread_report_progress((AVFrame*)s->current_picture_ptr, (16*s->mb_height >> FIELD_PICTURE) - 1,
2511
-                                 s->picture_structure==PICT_BOTTOM_FIELD);
2510
+        ff_thread_report_progress(&s->current_picture_ptr->f,
2511
+                                  (16 * s->mb_height >> FIELD_PICTURE) - 1,
2512
+                                  s->picture_structure == PICT_BOTTOM_FIELD);
2512 2513
 
2513 2514
     if (CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
2514 2515
         ff_vdpau_h264_set_reference_frames(s);
... ...
@@ -2906,8 +2907,8 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
2906 2906
             h->prev_frame_num++;
2907 2907
             h->prev_frame_num %= 1<<h->sps.log2_max_frame_num;
2908 2908
             s->current_picture_ptr->frame_num= h->prev_frame_num;
2909
-            ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 0);
2910
-            ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 1);
2909
+            ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 0);
2910
+            ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 1);
2911 2911
             ff_generate_sliding_window_mmcos(h);
2912 2912
             if (ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index) < 0 &&
2913 2913
                 (s->avctx->err_recognition & AV_EF_EXPLODE))
... ...
@@ -3577,8 +3578,8 @@ static void decode_finish_row(H264Context *h){
3577 3577
 
3578 3578
     if (s->dropable) return;
3579 3579
 
3580
-    ff_thread_report_progress((AVFrame*)s->current_picture_ptr, top + height - 1,
3581
-                             s->picture_structure==PICT_BOTTOM_FIELD);
3580
+    ff_thread_report_progress(&s->current_picture_ptr->f, top + height - 1,
3581
+                              s->picture_structure == PICT_BOTTOM_FIELD);
3582 3582
 }
3583 3583
 
3584 3584
 static int decode_slice(struct AVCodecContext *avctx, void *arg){
... ...
@@ -4067,7 +4068,7 @@ static int decode_frame(AVCodecContext *avctx,
4067 4067
 
4068 4068
         if(out){
4069 4069
             *data_size = sizeof(AVFrame);
4070
-            *pict= *(AVFrame*)out;
4070
+            *pict      = out->f;
4071 4071
         }
4072 4072
 
4073 4073
         return buf_index;
... ...
@@ -4121,7 +4122,7 @@ not_extra:
4121 4121
         *data_size = 0; /* Wait for second field. */
4122 4122
         if (h->next_output_pic && (h->next_output_pic->sync || h->sync>1)) {
4123 4123
                 *data_size = sizeof(AVFrame);
4124
-                *pict = *(AVFrame*)h->next_output_pic;
4124
+                *pict      = h->next_output_pic->f;
4125 4125
         }
4126 4126
     }
4127 4127
 
... ...
@@ -154,7 +154,8 @@ static void await_reference_mb_row(H264Context * const h, Picture *ref, int mb_y
154 154
     //FIXME it can be safe to access mb stuff
155 155
     //even if pixels aren't deblocked yet
156 156
 
157
-    ff_thread_await_progress((AVFrame*)ref, FFMIN(16*mb_y >> ref_field_picture, ref_height-1),
157
+    ff_thread_await_progress(&ref->f,
158
+                             FFMIN(16 * mb_y >> ref_field_picture, ref_height - 1),
158 159
                              ref_field_picture && ref_field);
159 160
 }
160 161
 
... ...
@@ -143,7 +143,7 @@ static int ir2_decode_frame(AVCodecContext *avctx,
143 143
     int buf_size = avpkt->size;
144 144
     Ir2Context * const s = avctx->priv_data;
145 145
     AVFrame *picture = data;
146
-    AVFrame * const p= (AVFrame*)&s->picture;
146
+    AVFrame * const p = &s->picture;
147 147
     int start;
148 148
 
149 149
     p->reference = 3;
... ...
@@ -188,7 +188,7 @@ static int ir2_decode_frame(AVCodecContext *avctx,
188 188
                          s->picture.data[1], s->picture.linesize[1], ir2_luma_table);
189 189
     }
190 190
 
191
-    *picture= *(AVFrame*)&s->picture;
191
+    *picture   = s->picture;
192 192
     *data_size = sizeof(AVPicture);
193 193
 
194 194
     return buf_size;
... ...
@@ -232,7 +232,7 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
232 232
                              const AVFrame *pict, int *got_packet)
233 233
 {
234 234
     JpeglsContext * const s = avctx->priv_data;
235
-    AVFrame * const p= (AVFrame*)&s->picture;
235
+    AVFrame * const p = &s->picture;
236 236
     const int near = avctx->prediction_method;
237 237
     PutBitContext pb, pb2;
238 238
     GetBitContext gb;
... ...
@@ -45,7 +45,7 @@ static int encode_picture_lossless(AVCodecContext *avctx, AVPacket *pkt,
45 45
     MJpegContext * const m = s->mjpeg_ctx;
46 46
     const int width= s->width;
47 47
     const int height= s->height;
48
-    AVFrame * const p= (AVFrame*)&s->current_picture;
48
+    AVFrame * const p = &s->current_picture.f;
49 49
     const int predictor= avctx->prediction_method+1;
50 50
     const int mb_width  = (width  + s->mjpeg_hsample[0] - 1) / s->mjpeg_hsample[0];
51 51
     const int mb_height = (height + s->mjpeg_vsample[0] - 1) / s->mjpeg_vsample[0];
... ...
@@ -166,7 +166,7 @@ static int decode_frame(AVCodecContext *avctx,
166 166
     const uint8_t *buf = avpkt->data;
167 167
     int buf_size = avpkt->size;
168 168
     LOCOContext * const l = avctx->priv_data;
169
-    AVFrame * const p= (AVFrame*)&l->pic;
169
+    AVFrame * const p = &l->pic;
170 170
     int decoded;
171 171
 
172 172
     if(p->data[0])
... ...
@@ -243,7 +243,7 @@ static av_cold int decode_init(AVCodecContext *avctx){
243 243
 
244 244
 static av_cold int decode_init_thread_copy(AVCodecContext *avctx){
245 245
     MDECContext * const a = avctx->priv_data;
246
-    AVFrame *p = (AVFrame*)&a->picture;
246
+    AVFrame *p = &a->picture;
247 247
 
248 248
     avctx->coded_frame= p;
249 249
     a->avctx= avctx;
... ...
@@ -1577,7 +1577,7 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
1577 1577
             goto the_end;
1578 1578
         } else if (unescaped_buf_size > (1U<<29)) {
1579 1579
             av_log(avctx, AV_LOG_ERROR, "MJPEG packet 0x%x too big (0x%x/0x%x), corrupt data?\n",
1580
-                   start_code, unescaped_buf_ptr, buf_size);
1580
+                   start_code, unescaped_buf_size, buf_size);
1581 1581
             return AVERROR_INVALIDDATA;
1582 1582
         } else {
1583 1583
             av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%td\n",
... ...
@@ -1952,7 +1952,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
1952 1952
         ff_MPV_frame_end(s);
1953 1953
 
1954 1954
         if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
1955
-            *pict = *(AVFrame*)s->current_picture_ptr;
1955
+            *pict = s->current_picture_ptr->f;
1956 1956
             ff_print_debug_info(s, pict);
1957 1957
         } else {
1958 1958
             if (avctx->active_thread_type & FF_THREAD_FRAME)
... ...
@@ -1960,7 +1960,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
1960 1960
             /* latency of 1 frame for I- and P-frames */
1961 1961
             /* XXX: use another variable than picture_number */
1962 1962
             if (s->last_picture_ptr != NULL) {
1963
-                *pict = *(AVFrame*)s->last_picture_ptr;
1963
+                *pict = s->last_picture_ptr->f;
1964 1964
                  ff_print_debug_info(s, pict);
1965 1965
             }
1966 1966
         }
... ...
@@ -2256,7 +2256,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
2256 2256
     if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) {
2257 2257
         /* special case for last picture */
2258 2258
         if (s2->low_delay == 0 && s2->next_picture_ptr) {
2259
-            *picture = *(AVFrame*)s2->next_picture_ptr;
2259
+            *picture = s2->next_picture_ptr->f;
2260 2260
             s2->next_picture_ptr = NULL;
2261 2261
 
2262 2262
             *data_size = sizeof(AVFrame);
... ...
@@ -1313,7 +1313,7 @@ static int mpeg4_decode_mb(MpegEncContext *s,
1313 1313
                 s->last_mv[i][1][1]= 0;
1314 1314
             }
1315 1315
 
1316
-            ff_thread_await_progress((AVFrame*)s->next_picture_ptr, s->mb_y, 0);
1316
+            ff_thread_await_progress(&s->next_picture_ptr->f, s->mb_y, 0);
1317 1317
         }
1318 1318
 
1319 1319
         /* if we skipped it in the future P Frame than skip it now too */
... ...
@@ -1500,7 +1500,7 @@ end:
1500 1500
 
1501 1501
             if(s->pict_type==AV_PICTURE_TYPE_B){
1502 1502
                 const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
1503
-                ff_thread_await_progress((AVFrame*)s->next_picture_ptr,
1503
+                ff_thread_await_progress(&s->next_picture_ptr->f,
1504 1504
                                         (s->mb_x + delta >= s->mb_width) ? FFMIN(s->mb_y+1, s->mb_height-1) : s->mb_y, 0);
1505 1505
                 if (s->next_picture.f.mbskip_table[xy + delta])
1506 1506
                     return SLICE_OK;
... ...
@@ -232,9 +232,9 @@ static void free_frame_buffer(MpegEncContext *s, Picture *pic)
232 232
      * dimensions; ignore user defined callbacks for these
233 233
      */
234 234
     if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
235
-        ff_thread_release_buffer(s->avctx, (AVFrame *) pic);
235
+        ff_thread_release_buffer(s->avctx, &pic->f);
236 236
     else
237
-        avcodec_default_release_buffer(s->avctx, (AVFrame *) pic);
237
+        avcodec_default_release_buffer(s->avctx, &pic->f);
238 238
     av_freep(&pic->f.hwaccel_picture_private);
239 239
 }
240 240
 
... ...
@@ -257,9 +257,9 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
257 257
     }
258 258
 
259 259
     if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
260
-        r = ff_thread_get_buffer(s->avctx, (AVFrame *) pic);
260
+        r = ff_thread_get_buffer(s->avctx, &pic->f);
261 261
     else
262
-        r = avcodec_default_get_buffer(s->avctx, (AVFrame *) pic);
262
+        r = avcodec_default_get_buffer(s->avctx, &pic->f);
263 263
 
264 264
     if (r < 0 || !pic->f.type || !pic->f.data[0]) {
265 265
         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)
729 729
     s->codec_tag        = avpriv_toupper4(s->avctx->codec_tag);
730 730
     s->stream_codec_tag = avpriv_toupper4(s->avctx->stream_codec_tag);
731 731
 
732
-    s->avctx->coded_frame = (AVFrame*)&s->current_picture;
732
+    s->avctx->coded_frame = &s->current_picture.f;
733 733
 
734 734
     FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num + 1) * sizeof(int), fail); // error ressilience code looks cleaner with this
735 735
     for (y = 0; y < s->mb_height; y++)
... ...
@@ -781,7 +781,7 @@ av_cold int ff_MPV_common_init(MpegEncContext *s)
781 781
     FF_ALLOCZ_OR_GOTO(s->avctx, s->picture,
782 782
                       s->picture_count * sizeof(Picture), fail);
783 783
     for (i = 0; i < s->picture_count; i++) {
784
-        avcodec_get_frame_defaults((AVFrame *) &s->picture[i]);
784
+        avcodec_get_frame_defaults(&s->picture[i].f);
785 785
     }
786 786
 
787 787
     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)
1247 1247
                     memset(s->last_picture_ptr->f.data[0] + s->last_picture_ptr->f.linesize[0]*i, 16, avctx->width);
1248 1248
             }
1249 1249
 
1250
-            ff_thread_report_progress((AVFrame *) s->last_picture_ptr,
1251
-                                      INT_MAX, 0);
1252
-            ff_thread_report_progress((AVFrame *) s->last_picture_ptr,
1253
-                                      INT_MAX, 1);
1250
+            ff_thread_report_progress(&s->last_picture_ptr->f, INT_MAX, 0);
1251
+            ff_thread_report_progress(&s->last_picture_ptr->f, INT_MAX, 1);
1254 1252
         }
1255 1253
         if ((s->next_picture_ptr == NULL ||
1256 1254
              s->next_picture_ptr->f.data[0] == NULL) &&
... ...
@@ -1263,10 +1261,8 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
1263 1263
             s->next_picture_ptr->f.key_frame = 0;
1264 1264
             if (ff_alloc_picture(s, s->next_picture_ptr, 0) < 0)
1265 1265
                 return -1;
1266
-            ff_thread_report_progress((AVFrame *) s->next_picture_ptr,
1267
-                                      INT_MAX, 0);
1268
-            ff_thread_report_progress((AVFrame *) s->next_picture_ptr,
1269
-                                      INT_MAX, 1);
1266
+            ff_thread_report_progress(&s->next_picture_ptr->f, INT_MAX, 0);
1267
+            ff_thread_report_progress(&s->next_picture_ptr->f, INT_MAX, 1);
1270 1268
         }
1271 1269
     }
1272 1270
 
... ...
@@ -1391,10 +1387,10 @@ void ff_MPV_frame_end(MpegEncContext *s)
1391 1391
     memset(&s->next_picture,    0, sizeof(Picture));
1392 1392
     memset(&s->current_picture, 0, sizeof(Picture));
1393 1393
 #endif
1394
-    s->avctx->coded_frame = (AVFrame *) s->current_picture_ptr;
1394
+    s->avctx->coded_frame = &s->current_picture_ptr->f;
1395 1395
 
1396 1396
     if (s->codec_id != CODEC_ID_H264 && s->current_picture.f.reference) {
1397
-        ff_thread_report_progress((AVFrame *) s->current_picture_ptr,
1397
+        ff_thread_report_progress(&s->current_picture_ptr->f,
1398 1398
                                   s->mb_height - 1, 0);
1399 1399
     }
1400 1400
 }
... ...
@@ -2346,10 +2342,14 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
2346 2346
 
2347 2347
                 if(HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) {
2348 2348
                     if (s->mv_dir & MV_DIR_FORWARD) {
2349
-                        ff_thread_await_progress((AVFrame*)s->last_picture_ptr, ff_MPV_lowest_referenced_row(s, 0), 0);
2349
+                        ff_thread_await_progress(&s->last_picture_ptr->f,
2350
+                                                 ff_MPV_lowest_referenced_row(s, 0),
2351
+                                                 0);
2350 2352
                     }
2351 2353
                     if (s->mv_dir & MV_DIR_BACKWARD) {
2352
-                        ff_thread_await_progress((AVFrame*)s->next_picture_ptr, ff_MPV_lowest_referenced_row(s, 1), 0);
2354
+                        ff_thread_await_progress(&s->next_picture_ptr->f,
2355
+                                                 ff_MPV_lowest_referenced_row(s, 1),
2356
+                                                 0);
2353 2357
                     }
2354 2358
                 }
2355 2359
 
... ...
@@ -2556,9 +2556,9 @@ void ff_draw_horiz_band(MpegEncContext *s, int y, int h){
2556 2556
         int i;
2557 2557
 
2558 2558
         if(s->pict_type==AV_PICTURE_TYPE_B || s->low_delay || (s->avctx->slice_flags&SLICE_FLAG_CODED_ORDER))
2559
-            src= (AVFrame*)s->current_picture_ptr;
2559
+            src = &s->current_picture_ptr->f;
2560 2560
         else if(s->last_picture_ptr)
2561
-            src= (AVFrame*)s->last_picture_ptr;
2561
+            src = &s->last_picture_ptr->f;
2562 2562
         else
2563 2563
             return;
2564 2564
 
... ...
@@ -2867,5 +2867,5 @@ void ff_set_qscale(MpegEncContext * s, int qscale)
2867 2867
 void ff_MPV_report_decode_progress(MpegEncContext *s)
2868 2868
 {
2869 2869
     if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->error_occurred)
2870
-        ff_thread_report_progress((AVFrame*)s->current_picture_ptr, s->mb_y, 0);
2870
+        ff_thread_report_progress(&s->current_picture_ptr->f, s->mb_y, 0);
2871 2871
 }
... ...
@@ -981,7 +981,7 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg)
981 981
         if (i < 0)
982 982
             return i;
983 983
 
984
-        pic = (AVFrame *) &s->picture[i];
984
+        pic = &s->picture[i].f;
985 985
         pic->reference = 3;
986 986
 
987 987
         for (i = 0; i < 4; i++) {
... ...
@@ -996,7 +996,7 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg)
996 996
         if (i < 0)
997 997
             return i;
998 998
 
999
-        pic = (AVFrame *) &s->picture[i];
999
+        pic = &s->picture[i].f;
1000 1000
         pic->reference = 3;
1001 1001
 
1002 1002
         if (ff_alloc_picture(s, (Picture *) pic, 0) < 0) {
... ...
@@ -1252,7 +1252,7 @@ static int select_input_picture(MpegEncContext *s)
1252 1252
                                s->input_picture[0]->f.type == FF_BUFFER_TYPE_INTERNAL);
1253 1253
 
1254 1254
                         s->avctx->release_buffer(s->avctx,
1255
-                                                 (AVFrame *) s->input_picture[0]);
1255
+                                                 &s->input_picture[0]->f);
1256 1256
                     }
1257 1257
 
1258 1258
                     emms_c();
... ...
@@ -1385,13 +1385,13 @@ no_output_pic:
1385 1385
             /* mark us unused / free shared pic */
1386 1386
             if (s->reordered_input_picture[0]->f.type == FF_BUFFER_TYPE_INTERNAL)
1387 1387
                 s->avctx->release_buffer(s->avctx,
1388
-                                         (AVFrame *) s->reordered_input_picture[0]);
1388
+                                         &s->reordered_input_picture[0]->f);
1389 1389
             for (i = 0; i < 4; i++)
1390 1390
                 s->reordered_input_picture[0]->f.data[i] = NULL;
1391 1391
             s->reordered_input_picture[0]->f.type = 0;
1392 1392
 
1393
-            copy_picture_attributes(s, (AVFrame *) pic,
1394
-                                    (AVFrame *) s->reordered_input_picture[0]);
1393
+            copy_picture_attributes(s, &pic->f,
1394
+                                    &s->reordered_input_picture[0]->f);
1395 1395
 
1396 1396
             s->current_picture_ptr = pic;
1397 1397
         } else {
... ...
@@ -34,6 +34,7 @@
34 34
 #include "libavutil/x86_cpu.h"
35 35
 #include "h263.h"
36 36
 #include "mpeg4video.h"
37
+#include "msmpeg4data.h"
37 38
 #include "vc1data.h"
38 39
 
39 40
 /*
... ...
@@ -52,22 +53,8 @@
52 52
 #define V2_MV_VLC_BITS 9
53 53
 #define TEX_VLC_BITS 9
54 54
 
55
-#define II_BITRATE 128*1024
56
-#define MBAC_BITRATE 50*1024
57
-
58 55
 #define DEFAULT_INTER_INDEX 3
59 56
 
60
-static uint32_t v2_dc_lum_table[512][2];
61
-static uint32_t v2_dc_chroma_table[512][2];
62
-
63
-#include "msmpeg4data.h"
64
-
65
-#if CONFIG_ENCODERS //strangely gcc includes this even if it is not referenced
66
-static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
67
-#endif //CONFIG_ENCODERS
68
-
69
-static uint8_t static_rl_table_store[NB_RL_TABLES][2][2*MAX_RUN + MAX_LEVEL + 3];
70
-
71 57
 /* This table is practically identical to the one from h263
72 58
  * except that it is inverted. */
73 59
 static av_cold void init_h263_dc_for_msmpeg4(void)
... ...
@@ -102,8 +89,8 @@ static av_cold void init_h263_dc_for_msmpeg4(void)
102 102
                     uni_len++;
103 103
                 }
104 104
             }
105
-            v2_dc_lum_table[level+256][0]= uni_code;
106
-            v2_dc_lum_table[level+256][1]= uni_len;
105
+            ff_v2_dc_lum_table[level + 256][0] = uni_code;
106
+            ff_v2_dc_lum_table[level + 256][1] = uni_len;
107 107
 
108 108
             /* chrominance h263 */
109 109
             uni_code= ff_mpeg4_DCtab_chrom[size][0];
... ...
@@ -118,13 +105,13 @@ static av_cold void init_h263_dc_for_msmpeg4(void)
118 118
                     uni_len++;
119 119
                 }
120 120
             }
121
-            v2_dc_chroma_table[level+256][0]= uni_code;
122
-            v2_dc_chroma_table[level+256][1]= uni_len;
121
+            ff_v2_dc_chroma_table[level + 256][0] = uni_code;
122
+            ff_v2_dc_chroma_table[level + 256][1] = uni_len;
123 123
 
124 124
         }
125 125
 }
126 126
 
127
-static av_cold void common_init(MpegEncContext * s)
127
+av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
128 128
 {
129 129
     static int initialized=0;
130 130
 
... ...
@@ -173,251 +160,6 @@ static av_cold void common_init(MpegEncContext * s)
173 173
     }
174 174
 }
175 175
 
176
-#if CONFIG_ENCODERS
177
-
178
-/* build the table which associate a (x,y) motion vector to a vlc */
179
-static void init_mv_table(MVTable *tab)
180
-{
181
-    int i, x, y;
182
-
183
-    tab->table_mv_index = av_malloc(sizeof(uint16_t) * 4096);
184
-    /* mark all entries as not used */
185
-    for(i=0;i<4096;i++)
186
-        tab->table_mv_index[i] = tab->n;
187
-
188
-    for(i=0;i<tab->n;i++) {
189
-        x = tab->table_mvx[i];
190
-        y = tab->table_mvy[i];
191
-        tab->table_mv_index[(x << 6) | y] = i;
192
-    }
193
-}
194
-
195
-void ff_msmpeg4_code012(PutBitContext *pb, int n)
196
-{
197
-    if (n == 0) {
198
-        put_bits(pb, 1, 0);
199
-    } else {
200
-        put_bits(pb, 1, 1);
201
-        put_bits(pb, 1, (n >= 2));
202
-    }
203
-}
204
-
205
-static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){
206
-    int size=0;
207
-    int code;
208
-    int run_diff= intra ? 0 : 1;
209
-
210
-    code = get_rl_index(rl, last, run, level);
211
-    size+= rl->table_vlc[code][1];
212
-    if (code == rl->n) {
213
-        int level1, run1;
214
-
215
-        level1 = level - rl->max_level[last][run];
216
-        if (level1 < 1)
217
-            goto esc2;
218
-        code = get_rl_index(rl, last, run, level1);
219
-        if (code == rl->n) {
220
-            esc2:
221
-            size++;
222
-            if (level > MAX_LEVEL)
223
-                goto esc3;
224
-            run1 = run - rl->max_run[last][level] - run_diff;
225
-            if (run1 < 0)
226
-                goto esc3;
227
-            code = get_rl_index(rl, last, run1, level);
228
-            if (code == rl->n) {
229
-            esc3:
230
-                /* third escape */
231
-                size+=1+1+6+8;
232
-            } else {
233
-                /* second escape */
234
-                size+= 1+1+ rl->table_vlc[code][1];
235
-            }
236
-        } else {
237
-            /* first escape */
238
-            size+= 1+1+ rl->table_vlc[code][1];
239
-        }
240
-    } else {
241
-        size++;
242
-    }
243
-    return size;
244
-}
245
-
246
-av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
247
-{
248
-    static int init_done=0;
249
-    int i;
250
-
251
-    common_init(s);
252
-    if(s->msmpeg4_version>=4){
253
-        s->min_qcoeff= -255;
254
-        s->max_qcoeff=  255;
255
-    }
256
-
257
-    if (!init_done) {
258
-        /* init various encoding tables */
259
-        init_done = 1;
260
-        init_mv_table(&ff_mv_tables[0]);
261
-        init_mv_table(&ff_mv_tables[1]);
262
-        for(i=0;i<NB_RL_TABLES;i++)
263
-            ff_init_rl(&ff_rl_table[i], static_rl_table_store[i]);
264
-
265
-        for(i=0; i<NB_RL_TABLES; i++){
266
-            int level;
267
-            for (level = 1; level <= MAX_LEVEL; level++) {
268
-                int run;
269
-                for(run=0; run<=MAX_RUN; run++){
270
-                    int last;
271
-                    for(last=0; last<2; last++){
272
-                        rl_length[i][level][run][last]= get_size_of_code(s, &ff_rl_table[  i], last, run, level, 0);
273
-                    }
274
-                }
275
-            }
276
-        }
277
-    }
278
-}
279
-
280
-static void find_best_tables(MpegEncContext * s)
281
-{
282
-    int i;
283
-    int best        = 0, best_size        = INT_MAX;
284
-    int chroma_best = 0, best_chroma_size = INT_MAX;
285
-
286
-    for(i=0; i<3; i++){
287
-        int level;
288
-        int chroma_size=0;
289
-        int size=0;
290
-
291
-        if(i>0){// ;)
292
-            size++;
293
-            chroma_size++;
294
-        }
295
-        for(level=0; level<=MAX_LEVEL; level++){
296
-            int run;
297
-            for(run=0; run<=MAX_RUN; run++){
298
-                int last;
299
-                const int last_size= size + chroma_size;
300
-                for(last=0; last<2; last++){
301
-                    int inter_count       = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];
302
-                    int intra_luma_count  = s->ac_stats[1][0][level][run][last];
303
-                    int intra_chroma_count= s->ac_stats[1][1][level][run][last];
304
-
305
-                    if(s->pict_type==AV_PICTURE_TYPE_I){
306
-                        size       += intra_luma_count  *rl_length[i  ][level][run][last];
307
-                        chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];
308
-                    }else{
309
-                        size+=        intra_luma_count  *rl_length[i  ][level][run][last]
310
-                                     +intra_chroma_count*rl_length[i+3][level][run][last]
311
-                                     +inter_count       *rl_length[i+3][level][run][last];
312
-                    }
313
-                }
314
-                if(last_size == size+chroma_size) break;
315
-            }
316
-        }
317
-        if(size<best_size){
318
-            best_size= size;
319
-            best= i;
320
-        }
321
-        if(chroma_size<best_chroma_size){
322
-            best_chroma_size= chroma_size;
323
-            chroma_best= i;
324
-        }
325
-    }
326
-
327
-//    printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n",
328
-//           s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size);
329
-
330
-    if(s->pict_type==AV_PICTURE_TYPE_P) chroma_best= best;
331
-
332
-    memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);
333
-
334
-    s->rl_table_index       =        best;
335
-    s->rl_chroma_table_index= chroma_best;
336
-
337
-    if(s->pict_type != s->last_non_b_pict_type){
338
-        s->rl_table_index= 2;
339
-        if(s->pict_type==AV_PICTURE_TYPE_I)
340
-            s->rl_chroma_table_index= 1;
341
-        else
342
-            s->rl_chroma_table_index= 2;
343
-    }
344
-
345
-}
346
-
347
-/* write MSMPEG4 compatible frame header */
348
-void ff_msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
349
-{
350
-    find_best_tables(s);
351
-
352
-    avpriv_align_put_bits(&s->pb);
353
-    put_bits(&s->pb, 2, s->pict_type - 1);
354
-
355
-    put_bits(&s->pb, 5, s->qscale);
356
-    if(s->msmpeg4_version<=2){
357
-        s->rl_table_index = 2;
358
-        s->rl_chroma_table_index = 2;
359
-    }
360
-
361
-    s->dc_table_index = 1;
362
-    s->mv_table_index = 1; /* only if P frame */
363
-    s->use_skip_mb_code = 1; /* only if P frame */
364
-    s->per_mb_rl_table = 0;
365
-    if(s->msmpeg4_version==4)
366
-        s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==AV_PICTURE_TYPE_P);
367
-//printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height);
368
-
369
-    if (s->pict_type == AV_PICTURE_TYPE_I) {
370
-        s->slice_height= s->mb_height/1;
371
-        put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height);
372
-
373
-        if(s->msmpeg4_version==4){
374
-            ff_msmpeg4_encode_ext_header(s);
375
-            if(s->bit_rate>MBAC_BITRATE)
376
-                put_bits(&s->pb, 1, s->per_mb_rl_table);
377
-        }
378
-
379
-        if(s->msmpeg4_version>2){
380
-            if(!s->per_mb_rl_table){
381
-                ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index);
382
-                ff_msmpeg4_code012(&s->pb, s->rl_table_index);
383
-            }
384
-
385
-            put_bits(&s->pb, 1, s->dc_table_index);
386
-        }
387
-    } else {
388
-        put_bits(&s->pb, 1, s->use_skip_mb_code);
389
-
390
-        if(s->msmpeg4_version==4 && s->bit_rate>MBAC_BITRATE)
391
-            put_bits(&s->pb, 1, s->per_mb_rl_table);
392
-
393
-        if(s->msmpeg4_version>2){
394
-            if(!s->per_mb_rl_table)
395
-                ff_msmpeg4_code012(&s->pb, s->rl_table_index);
396
-
397
-            put_bits(&s->pb, 1, s->dc_table_index);
398
-
399
-            put_bits(&s->pb, 1, s->mv_table_index);
400
-        }
401
-    }
402
-
403
-    s->esc3_level_length= 0;
404
-    s->esc3_run_length= 0;
405
-}
406
-
407
-void ff_msmpeg4_encode_ext_header(MpegEncContext * s)
408
-{
409
-        put_bits(&s->pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29
410
-
411
-        put_bits(&s->pb, 11, FFMIN(s->bit_rate/1024, 2047));
412
-
413
-        if(s->msmpeg4_version>=3)
414
-            put_bits(&s->pb, 1, s->flipflop_rounding);
415
-        else
416
-            assert(s->flipflop_rounding==0);
417
-}
418
-
419
-#endif //CONFIG_ENCODERS
420
-
421 176
 /* predict coded block */
422 177
 int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr)
423 178
 {
... ...
@@ -445,217 +187,6 @@ int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block
445 445
     return pred;
446 446
 }
447 447
 
448
-#if CONFIG_ENCODERS
449
-
450
-void ff_msmpeg4_encode_motion(MpegEncContext * s,
451
-                                  int mx, int my)
452
-{
453
-    int code;
454
-    MVTable *mv;
455
-
456
-    /* modulo encoding */
457
-    /* WARNING : you cannot reach all the MVs even with the modulo
458
-       encoding. This is a somewhat strange compromise they took !!!  */
459
-    if (mx <= -64)
460
-        mx += 64;
461
-    else if (mx >= 64)
462
-        mx -= 64;
463
-    if (my <= -64)
464
-        my += 64;
465
-    else if (my >= 64)
466
-        my -= 64;
467
-
468
-    mx += 32;
469
-    my += 32;
470
-#if 0
471
-    if ((unsigned)mx >= 64 ||
472
-        (unsigned)my >= 64)
473
-        av_log(s->avctx, AV_LOG_ERROR, "error mx=%d my=%d\n", mx, my);
474
-#endif
475
-    mv = &ff_mv_tables[s->mv_table_index];
476
-
477
-    code = mv->table_mv_index[(mx << 6) | my];
478
-    put_bits(&s->pb,
479
-             mv->table_mv_bits[code],
480
-             mv->table_mv_code[code]);
481
-    if (code == mv->n) {
482
-        /* escape : code literally */
483
-        put_bits(&s->pb, 6, mx);
484
-        put_bits(&s->pb, 6, my);
485
-    }
486
-}
487
-
488
-void ff_msmpeg4_handle_slices(MpegEncContext *s){
489
-    if (s->mb_x == 0) {
490
-        if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
491
-            if(s->msmpeg4_version < 4){
492
-                ff_mpeg4_clean_buffers(s);
493
-            }
494
-            s->first_slice_line = 1;
495
-        } else {
496
-            s->first_slice_line = 0;
497
-        }
498
-    }
499
-}
500
-
501
-static void msmpeg4v2_encode_motion(MpegEncContext * s, int val)
502
-{
503
-    int range, bit_size, sign, code, bits;
504
-
505
-    if (val == 0) {
506
-        /* zero vector */
507
-        code = 0;
508
-        put_bits(&s->pb, ff_mvtab[code][1], ff_mvtab[code][0]);
509
-    } else {
510
-        bit_size = s->f_code - 1;
511
-        range = 1 << bit_size;
512
-        if (val <= -64)
513
-            val += 64;
514
-        else if (val >= 64)
515
-            val -= 64;
516
-
517
-        if (val >= 0) {
518
-            sign = 0;
519
-        } else {
520
-            val = -val;
521
-            sign = 1;
522
-        }
523
-        val--;
524
-        code = (val >> bit_size) + 1;
525
-        bits = val & (range - 1);
526
-
527
-        put_bits(&s->pb, ff_mvtab[code][1] + 1, (ff_mvtab[code][0] << 1) | sign);
528
-        if (bit_size > 0) {
529
-            put_bits(&s->pb, bit_size, bits);
530
-        }
531
-    }
532
-}
533
-
534
-void ff_msmpeg4_encode_mb(MpegEncContext * s,
535
-                          DCTELEM block[6][64],
536
-                          int motion_x, int motion_y)
537
-{
538
-    int cbp, coded_cbp, i;
539
-    int pred_x, pred_y;
540
-    uint8_t *coded_block;
541
-
542
-    ff_msmpeg4_handle_slices(s);
543
-
544
-    if (!s->mb_intra) {
545
-        /* compute cbp */
546
-        cbp = 0;
547
-        for (i = 0; i < 6; i++) {
548
-            if (s->block_last_index[i] >= 0)
549
-                cbp |= 1 << (5 - i);
550
-        }
551
-        if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
552
-            /* skip macroblock */
553
-            put_bits(&s->pb, 1, 1);
554
-            s->last_bits++;
555
-            s->misc_bits++;
556
-            s->skip_count++;
557
-
558
-            return;
559
-        }
560
-        if (s->use_skip_mb_code)
561
-            put_bits(&s->pb, 1, 0);     /* mb coded */
562
-
563
-        if(s->msmpeg4_version<=2){
564
-            put_bits(&s->pb,
565
-                     ff_v2_mb_type[cbp&3][1],
566
-                     ff_v2_mb_type[cbp&3][0]);
567
-            if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
568
-            else             coded_cbp= cbp;
569
-
570
-            put_bits(&s->pb,
571
-                     ff_h263_cbpy_tab[coded_cbp>>2][1],
572
-                     ff_h263_cbpy_tab[coded_cbp>>2][0]);
573
-
574
-            s->misc_bits += get_bits_diff(s);
575
-
576
-            ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
577
-            msmpeg4v2_encode_motion(s, motion_x - pred_x);
578
-            msmpeg4v2_encode_motion(s, motion_y - pred_y);
579
-        }else{
580
-            put_bits(&s->pb,
581
-                     ff_table_mb_non_intra[cbp + 64][1],
582
-                     ff_table_mb_non_intra[cbp + 64][0]);
583
-
584
-            s->misc_bits += get_bits_diff(s);
585
-
586
-            /* motion vector */
587
-            ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
588
-            ff_msmpeg4_encode_motion(s, motion_x - pred_x,
589
-                                  motion_y - pred_y);
590
-        }
591
-
592
-        s->mv_bits += get_bits_diff(s);
593
-
594
-        for (i = 0; i < 6; i++) {
595
-            ff_msmpeg4_encode_block(s, block[i], i);
596
-        }
597
-        s->p_tex_bits += get_bits_diff(s);
598
-    } else {
599
-        /* compute cbp */
600
-        cbp = 0;
601
-        coded_cbp = 0;
602
-        for (i = 0; i < 6; i++) {
603
-            int val, pred;
604
-            val = (s->block_last_index[i] >= 1);
605
-            cbp |= val << (5 - i);
606
-            if (i < 4) {
607
-                /* predict value for close blocks only for luma */
608
-                pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
609
-                *coded_block = val;
610
-                val = val ^ pred;
611
-            }
612
-            coded_cbp |= val << (5 - i);
613
-        }
614
-
615
-        if(s->msmpeg4_version<=2){
616
-            if (s->pict_type == AV_PICTURE_TYPE_I) {
617
-                put_bits(&s->pb,
618
-                         ff_v2_intra_cbpc[cbp&3][1], ff_v2_intra_cbpc[cbp&3][0]);
619
-            } else {
620
-                if (s->use_skip_mb_code)
621
-                    put_bits(&s->pb, 1, 0);     /* mb coded */
622
-                put_bits(&s->pb,
623
-                         ff_v2_mb_type[(cbp&3) + 4][1],
624
-                         ff_v2_mb_type[(cbp&3) + 4][0]);
625
-            }
626
-            put_bits(&s->pb, 1, 0);             /* no AC prediction yet */
627
-            put_bits(&s->pb,
628
-                     ff_h263_cbpy_tab[cbp>>2][1],
629
-                     ff_h263_cbpy_tab[cbp>>2][0]);
630
-        }else{
631
-            if (s->pict_type == AV_PICTURE_TYPE_I) {
632
-                put_bits(&s->pb,
633
-                         ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
634
-            } else {
635
-                if (s->use_skip_mb_code)
636
-                    put_bits(&s->pb, 1, 0);     /* mb coded */
637
-                put_bits(&s->pb,
638
-                         ff_table_mb_non_intra[cbp][1],
639
-                         ff_table_mb_non_intra[cbp][0]);
640
-            }
641
-            put_bits(&s->pb, 1, 0);             /* no AC prediction yet */
642
-            if(s->inter_intra_pred){
643
-                s->h263_aic_dir=0;
644
-                put_bits(&s->pb, ff_table_inter_intra[s->h263_aic_dir][1], ff_table_inter_intra[s->h263_aic_dir][0]);
645
-            }
646
-        }
647
-        s->misc_bits += get_bits_diff(s);
648
-
649
-        for (i = 0; i < 6; i++) {
650
-            ff_msmpeg4_encode_block(s, block[i], i);
651
-        }
652
-        s->i_tex_bits += get_bits_diff(s);
653
-        s->i_count++;
654
-    }
655
-}
656
-
657
-#endif //CONFIG_ENCODERS
658
-
659 448
 static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
660 449
                                     int32_t **dc_val_ptr)
661 450
 {
... ...
@@ -685,8 +216,8 @@ static int get_dc(uint8_t *src, int stride, int scale)
685 685
 }
686 686
 
687 687
 /* dir = 0: left, dir = 1: top prediction */
688
-static inline int msmpeg4_pred_dc(MpegEncContext * s, int n,
689
-                             int16_t **dc_val_ptr, int *dir_ptr)
688
+int ff_msmpeg4_pred_dc(MpegEncContext *s, int n,
689
+                       int16_t **dc_val_ptr, int *dir_ptr)
690 690
 {
691 691
     int a, b, c, wrap, pred, scale;
692 692
     int16_t *dc_val;
... ...
@@ -832,207 +363,6 @@ static inline int msmpeg4_pred_dc(MpegEncContext * s, int n,
832 832
     return pred;
833 833
 }
834 834
 
835
-#define DC_MAX 119
836
-
837
-static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
838
-{
839
-    int sign, code;
840
-    int pred, extquant;
841
-    int extrabits = 0;
842
-
843
-    int16_t *dc_val;
844
-    pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
845
-
846
-    /* update predictor */
847
-    if (n < 4) {
848
-        *dc_val = level * s->y_dc_scale;
849
-    } else {
850
-        *dc_val = level * s->c_dc_scale;
851
-    }
852
-
853
-    /* do the prediction */
854
-    level -= pred;
855
-
856
-    if(s->msmpeg4_version<=2){
857
-        if (n < 4) {
858
-            put_bits(&s->pb,
859
-                     v2_dc_lum_table[level+256][1],
860
-                     v2_dc_lum_table[level+256][0]);
861
-        }else{
862
-            put_bits(&s->pb,
863
-                     v2_dc_chroma_table[level+256][1],
864
-                     v2_dc_chroma_table[level+256][0]);
865
-        }
866
-    }else{
867
-        sign = 0;
868
-        if (level < 0) {
869
-            level = -level;
870
-            sign = 1;
871
-        }
872
-        code = level;
873
-        if (code > DC_MAX)
874
-            code = DC_MAX;
875
-        else if( s->msmpeg4_version>=6 ) {
876
-            if( s->qscale == 1 ) {
877
-                extquant = (level + 3) & 0x3;
878
-                code  = ((level+3)>>2);
879
-            } else if( s->qscale == 2 ) {
880
-                extquant = (level + 1) & 0x1;
881
-                code  = ((level+1)>>1);
882
-            }
883
-        }
884
-
885
-        if (s->dc_table_index == 0) {
886
-            if (n < 4) {
887
-                put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]);
888
-            } else {
889
-                put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]);
890
-            }
891
-        } else {
892
-            if (n < 4) {
893
-                put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]);
894
-            } else {
895
-                put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]);
896
-            }
897
-        }
898
-
899
-        if(s->msmpeg4_version>=6 && s->qscale<=2)
900
-            extrabits = 3 - s->qscale;
901
-
902
-        if (code == DC_MAX)
903
-            put_bits(&s->pb, 8 + extrabits, level);
904
-        else if(extrabits > 0)//== VC1 && s->qscale<=2
905
-            put_bits(&s->pb, extrabits, extquant);
906
-
907
-        if (level != 0) {
908
-            put_bits(&s->pb, 1, sign);
909
-        }
910
-    }
911
-}
912
-
913
-/* Encoding of a block. Very similar to MPEG4 except for a different
914
-   escape coding (same as H263) and more vlc tables.
915
- */
916
-void ff_msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n)
917
-{
918
-    int level, run, last, i, j, last_index;
919
-    int last_non_zero, sign, slevel;
920
-    int code, run_diff, dc_pred_dir;
921
-    const RLTable *rl;
922
-    const uint8_t *scantable;
923
-
924
-    if (s->mb_intra) {
925
-        msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
926
-        i = 1;
927
-        if (n < 4) {
928
-            rl = &ff_rl_table[s->rl_table_index];
929
-        } else {
930
-            rl = &ff_rl_table[3 + s->rl_chroma_table_index];
931
-        }
932
-        run_diff = s->msmpeg4_version>=4;
933
-        scantable= s->intra_scantable.permutated;
934
-    } else {
935
-        i = 0;
936
-        rl = &ff_rl_table[3 + s->rl_table_index];
937
-        if(s->msmpeg4_version<=2)
938
-            run_diff = 0;
939
-        else
940
-            run_diff = 1;
941
-        scantable= s->inter_scantable.permutated;
942
-    }
943
-
944
-    /* recalculate block_last_index for M$ wmv1 */
945
-    if(s->msmpeg4_version>=4 && s->msmpeg4_version<6 && s->block_last_index[n]>0){
946
-        for(last_index=63; last_index>=0; last_index--){
947
-            if(block[scantable[last_index]]) break;
948
-        }
949
-        s->block_last_index[n]= last_index;
950
-    }else
951
-        last_index = s->block_last_index[n];
952
-    /* AC coefs */
953
-    last_non_zero = i - 1;
954
-    for (; i <= last_index; i++) {
955
-        j = scantable[i];
956
-        level = block[j];
957
-        if (level) {
958
-            run = i - last_non_zero - 1;
959
-            last = (i == last_index);
960
-            sign = 0;
961
-            slevel = level;
962
-            if (level < 0) {
963
-                sign = 1;
964
-                level = -level;
965
-            }
966
-
967
-            if(level<=MAX_LEVEL && run<=MAX_RUN){
968
-                s->ac_stats[s->mb_intra][n>3][level][run][last]++;
969
-            }
970
-
971
-            s->ac_stats[s->mb_intra][n > 3][40][63][0]++; //esc3 like
972
-
973
-            code = get_rl_index(rl, last, run, level);
974
-            put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
975
-            if (code == rl->n) {
976
-                int level1, run1;
977
-
978
-                level1 = level - rl->max_level[last][run];
979
-                if (level1 < 1)
980
-                    goto esc2;
981
-                code = get_rl_index(rl, last, run, level1);
982
-                if (code == rl->n) {
983
-                esc2:
984
-                    put_bits(&s->pb, 1, 0);
985
-                    if (level > MAX_LEVEL)
986
-                        goto esc3;
987
-                    run1 = run - rl->max_run[last][level] - run_diff;
988
-                    if (run1 < 0)
989
-                        goto esc3;
990
-                    code = get_rl_index(rl, last, run1+1, level);
991
-                    if (s->msmpeg4_version == 4 && code == rl->n)
992
-                        goto esc3;
993
-                    code = get_rl_index(rl, last, run1, level);
994
-                    if (code == rl->n) {
995
-                    esc3:
996
-                        /* third escape */
997
-                        put_bits(&s->pb, 1, 0);
998
-                        put_bits(&s->pb, 1, last);
999
-                        if(s->msmpeg4_version>=4){
1000
-                            if(s->esc3_level_length==0){
1001
-                                s->esc3_level_length=8;
1002
-                                s->esc3_run_length= 6;
1003
-                                //ESCLVLSZ + ESCRUNSZ
1004
-                                if(s->qscale<8)
1005
-                                    put_bits(&s->pb, 6 + (s->msmpeg4_version>=6), 3);
1006
-                                else
1007
-                                    put_bits(&s->pb, 8, 3);
1008
-                            }
1009
-                            put_bits(&s->pb, s->esc3_run_length, run);
1010
-                            put_bits(&s->pb, 1, sign);
1011
-                            put_bits(&s->pb, s->esc3_level_length, level);
1012
-                        }else{
1013
-                            put_bits(&s->pb, 6, run);
1014
-                            put_sbits(&s->pb, 8, slevel);
1015
-                        }
1016
-                    } else {
1017
-                        /* second escape */
1018
-                        put_bits(&s->pb, 1, 1);
1019
-                        put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
1020
-                        put_bits(&s->pb, 1, sign);
1021
-                    }
1022
-                } else {
1023
-                    /* first escape */
1024
-                    put_bits(&s->pb, 1, 1);
1025
-                    put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
1026
-                    put_bits(&s->pb, 1, sign);
1027
-                }
1028
-            } else {
1029
-                put_bits(&s->pb, 1, sign);
1030
-            }
1031
-            last_non_zero = i;
1032
-        }
1033
-    }
1034
-}
1035
-
1036 835
 /****************************************/
1037 836
 /* decoding stuff */
1038 837
 
... ...
@@ -1263,13 +593,13 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
1263 1263
     if (ff_h263_decode_init(avctx) < 0)
1264 1264
         return -1;
1265 1265
 
1266
-    common_init(s);
1266
+    ff_msmpeg4_common_init(s);
1267 1267
 
1268 1268
     if (!done) {
1269 1269
         done = 1;
1270 1270
 
1271 1271
         for(i=0;i<NB_RL_TABLES;i++) {
1272
-            ff_init_rl(&ff_rl_table[i], static_rl_table_store[i]);
1272
+            ff_init_rl(&ff_rl_table[i], ff_static_rl_table_store[i]);
1273 1273
         }
1274 1274
         INIT_VLC_RL(ff_rl_table[0], 642);
1275 1275
         INIT_VLC_RL(ff_rl_table[1], 1104);
... ...
@@ -1301,11 +631,11 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
1301 1301
                  &ff_table1_dc_chroma[0][0], 8, 4, 1216);
1302 1302
 
1303 1303
         INIT_VLC_STATIC(&v2_dc_lum_vlc, DC_VLC_BITS, 512,
1304
-                 &v2_dc_lum_table[0][1], 8, 4,
1305
-                 &v2_dc_lum_table[0][0], 8, 4, 1472);
1304
+                 &ff_v2_dc_lum_table[0][1], 8, 4,
1305
+                 &ff_v2_dc_lum_table[0][0], 8, 4, 1472);
1306 1306
         INIT_VLC_STATIC(&v2_dc_chroma_vlc, DC_VLC_BITS, 512,
1307
-                 &v2_dc_chroma_table[0][1], 8, 4,
1308
-                 &v2_dc_chroma_table[0][0], 8, 4, 1506);
1307
+                 &ff_v2_dc_chroma_table[0][1], 8, 4,
1308
+                 &ff_v2_dc_chroma_table[0][0], 8, 4, 1506);
1309 1309
 
1310 1310
         INIT_VLC_STATIC(&v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 4,
1311 1311
                  &ff_v2_intra_cbpc[0][1], 2, 1,
... ...
@@ -1588,7 +918,7 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
1588 1588
         *dc_val= level;
1589 1589
     }else{
1590 1590
         int16_t *dc_val;
1591
-        pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
1591
+        pred   = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
1592 1592
         level += pred;
1593 1593
 
1594 1594
         /* update predictor */
... ...
@@ -22,19 +22,29 @@
22 22
 #ifndef AVCODEC_MSMPEG4_H
23 23
 #define AVCODEC_MSMPEG4_H
24 24
 
25
+#include <stdint.h>
26
+
25 27
 #include "config.h"
26 28
 #include "avcodec.h"
27 29
 #include "dsputil.h"
28 30
 #include "mpegvideo.h"
31
+#include "msmpeg4data.h"
32
+#include "put_bits.h"
29 33
 
30 34
 #define INTER_INTRA_VLC_BITS 3
31 35
 #define MB_NON_INTRA_VLC_BITS 9
32 36
 #define MB_INTRA_VLC_BITS 9
33 37
 
38
+#define II_BITRATE 128*1024
39
+#define MBAC_BITRATE 50*1024
40
+
41
+#define DC_MAX 119
42
+
34 43
 extern VLC ff_mb_non_intra_vlc[4];
35 44
 extern VLC ff_inter_intra_vlc;
36 45
 
37 46
 void ff_msmpeg4_code012(PutBitContext *pb, int n);
47
+void ff_msmpeg4_common_init(MpegEncContext *s);
38 48
 void ff_msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n);
39 49
 void ff_msmpeg4_handle_slices(MpegEncContext *s);
40 50
 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,
43 43
 int ff_msmpeg4_decode_motion(MpegEncContext * s, int *mx_ptr, int *my_ptr);
44 44
 int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
45 45
                             int n, int coded, const uint8_t *scan_table);
46
+int ff_msmpeg4_pred_dc(MpegEncContext *s, int n,
47
+                       int16_t **dc_val_ptr, int *dir_ptr);
46 48
 int ff_wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
47 49
 
48 50
 #define CONFIG_MSMPEG4_DECODER (CONFIG_MSMPEG4V1_DECODER || \
... ...
@@ -29,6 +29,10 @@
29 29
 
30 30
 #include "msmpeg4data.h"
31 31
 
32
+uint32_t ff_v2_dc_lum_table[512][2];
33
+uint32_t ff_v2_dc_chroma_table[512][2];
34
+uint8_t  ff_static_rl_table_store[NB_RL_TABLES][2][2 * MAX_RUN + MAX_LEVEL + 3];
35
+
32 36
 VLC ff_msmp4_mb_i_vlc;
33 37
 VLC ff_msmp4_dc_luma_vlc[2];
34 38
 VLC ff_msmp4_dc_chroma_vlc[2];
... ...
@@ -59,6 +59,10 @@ extern const uint8_t ff_wmv1_scantable[WMV1_SCANTABLE_COUNT][64];
59 59
 #define NB_RL_TABLES  6
60 60
 
61 61
 extern RLTable ff_rl_table[NB_RL_TABLES];
62
+extern uint8_t ff_static_rl_table_store[NB_RL_TABLES][2][2 * MAX_RUN + MAX_LEVEL + 3];
63
+
64
+extern uint32_t ff_v2_dc_lum_table[512][2];
65
+extern uint32_t ff_v2_dc_chroma_table[512][2];
62 66
 
63 67
 extern const uint8_t ff_wmv1_y_dc_scale_table[32];
64 68
 extern const uint8_t ff_wmv1_c_dc_scale_table[32];
65 69
new file mode 100644
... ...
@@ -0,0 +1,692 @@
0
+/*
1
+ * MSMPEG4 encoder backend
2
+ * Copyright (c) 2001 Fabrice Bellard
3
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
4
+ *
5
+ * msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
6
+ *
7
+ * This file is part of FFmpeg.
8
+ *
9
+ * FFmpeg is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU Lesser General Public
11
+ * License as published by the Free Software Foundation; either
12
+ * version 2.1 of the License, or (at your option) any later version.
13
+ *
14
+ * FFmpeg is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
+ * Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with FFmpeg; if not, write to the Free Software
21
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
+ */
23
+
24
+/**
25
+ * @file
26
+ * MSMPEG4 encoder backend
27
+ */
28
+
29
+#include <stdint.h>
30
+#include <string.h>
31
+
32
+#include "libavutil/avutil.h"
33
+#include "libavutil/mem.h"
34
+#include "mpegvideo.h"
35
+#include "msmpeg4.h"
36
+#include "h263.h"
37
+#include "mpeg4video.h"
38
+#include "msmpeg4.h"
39
+#include "msmpeg4data.h"
40
+#include "put_bits.h"
41
+#include "rl.h"
42
+#include "vc1data.h"
43
+
44
+static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
45
+
46
+/* build the table which associate a (x,y) motion vector to a vlc */
47
+static void init_mv_table(MVTable *tab)
48
+{
49
+    int i, x, y;
50
+
51
+    tab->table_mv_index = av_malloc(sizeof(uint16_t) * 4096);
52
+    /* mark all entries as not used */
53
+    for(i=0;i<4096;i++)
54
+        tab->table_mv_index[i] = tab->n;
55
+
56
+    for(i=0;i<tab->n;i++) {
57
+        x = tab->table_mvx[i];
58
+        y = tab->table_mvy[i];
59
+        tab->table_mv_index[(x << 6) | y] = i;
60
+    }
61
+}
62
+
63
+void ff_msmpeg4_code012(PutBitContext *pb, int n)
64
+{
65
+    if (n == 0) {
66
+        put_bits(pb, 1, 0);
67
+    } else {
68
+        put_bits(pb, 1, 1);
69
+        put_bits(pb, 1, (n >= 2));
70
+    }
71
+}
72
+
73
+static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){
74
+    int size=0;
75
+    int code;
76
+    int run_diff= intra ? 0 : 1;
77
+
78
+    code = get_rl_index(rl, last, run, level);
79
+    size+= rl->table_vlc[code][1];
80
+    if (code == rl->n) {
81
+        int level1, run1;
82
+
83
+        level1 = level - rl->max_level[last][run];
84
+        if (level1 < 1)
85
+            goto esc2;
86
+        code = get_rl_index(rl, last, run, level1);
87
+        if (code == rl->n) {
88
+            esc2:
89
+            size++;
90
+            if (level > MAX_LEVEL)
91
+                goto esc3;
92
+            run1 = run - rl->max_run[last][level] - run_diff;
93
+            if (run1 < 0)
94
+                goto esc3;
95
+            code = get_rl_index(rl, last, run1, level);
96
+            if (code == rl->n) {
97
+            esc3:
98
+                /* third escape */
99
+                size+=1+1+6+8;
100
+            } else {
101
+                /* second escape */
102
+                size+= 1+1+ rl->table_vlc[code][1];
103
+            }
104
+        } else {
105
+            /* first escape */
106
+            size+= 1+1+ rl->table_vlc[code][1];
107
+        }
108
+    } else {
109
+        size++;
110
+    }
111
+    return size;
112
+}
113
+
114
+av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
115
+{
116
+    static int init_done=0;
117
+    int i;
118
+
119
+    ff_msmpeg4_common_init(s);
120
+    if(s->msmpeg4_version>=4){
121
+        s->min_qcoeff= -255;
122
+        s->max_qcoeff=  255;
123
+    }
124
+
125
+    if (!init_done) {
126
+        /* init various encoding tables */
127
+        init_done = 1;
128
+        init_mv_table(&ff_mv_tables[0]);
129
+        init_mv_table(&ff_mv_tables[1]);
130
+        for(i=0;i<NB_RL_TABLES;i++)
131
+            ff_init_rl(&ff_rl_table[i], ff_static_rl_table_store[i]);
132
+
133
+        for(i=0; i<NB_RL_TABLES; i++){
134
+            int level;
135
+            for (level = 1; level <= MAX_LEVEL; level++) {
136
+                int run;
137
+                for(run=0; run<=MAX_RUN; run++){
138
+                    int last;
139
+                    for(last=0; last<2; last++){
140
+                        rl_length[i][level][run][last]= get_size_of_code(s, &ff_rl_table[  i], last, run, level, 0);
141
+                    }
142
+                }
143
+            }
144
+        }
145
+    }
146
+}
147
+
148
+static void find_best_tables(MpegEncContext * s)
149
+{
150
+    int i;
151
+    int best        = 0, best_size        = INT_MAX;
152
+    int chroma_best = 0, best_chroma_size = INT_MAX;
153
+
154
+    for(i=0; i<3; i++){
155
+        int level;
156
+        int chroma_size=0;
157
+        int size=0;
158
+
159
+        if(i>0){// ;)
160
+            size++;
161
+            chroma_size++;
162
+        }
163
+        for(level=0; level<=MAX_LEVEL; level++){
164
+            int run;
165
+            for(run=0; run<=MAX_RUN; run++){
166
+                int last;
167
+                const int last_size= size + chroma_size;
168
+                for(last=0; last<2; last++){
169
+                    int inter_count       = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];
170
+                    int intra_luma_count  = s->ac_stats[1][0][level][run][last];
171
+                    int intra_chroma_count= s->ac_stats[1][1][level][run][last];
172
+
173
+                    if(s->pict_type==AV_PICTURE_TYPE_I){
174
+                        size       += intra_luma_count  *rl_length[i  ][level][run][last];
175
+                        chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];
176
+                    }else{
177
+                        size+=        intra_luma_count  *rl_length[i  ][level][run][last]
178
+                                     +intra_chroma_count*rl_length[i+3][level][run][last]
179
+                                     +inter_count       *rl_length[i+3][level][run][last];
180
+                    }
181
+                }
182
+                if(last_size == size+chroma_size) break;
183
+            }
184
+        }
185
+        if(size<best_size){
186
+            best_size= size;
187
+            best= i;
188
+        }
189
+        if(chroma_size<best_chroma_size){
190
+            best_chroma_size= chroma_size;
191
+            chroma_best= i;
192
+        }
193
+    }
194
+
195
+//    printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n",
196
+//           s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size);
197
+
198
+    if(s->pict_type==AV_PICTURE_TYPE_P) chroma_best= best;
199
+
200
+    memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);
201
+
202
+    s->rl_table_index       =        best;
203
+    s->rl_chroma_table_index= chroma_best;
204
+
205
+    if(s->pict_type != s->last_non_b_pict_type){
206
+        s->rl_table_index= 2;
207
+        if(s->pict_type==AV_PICTURE_TYPE_I)
208
+            s->rl_chroma_table_index= 1;
209
+        else
210
+            s->rl_chroma_table_index= 2;
211
+    }
212
+
213
+}
214
+
215
+/* write MSMPEG4 compatible frame header */
216
+void ff_msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
217
+{
218
+    find_best_tables(s);
219
+
220
+    avpriv_align_put_bits(&s->pb);
221
+    put_bits(&s->pb, 2, s->pict_type - 1);
222
+
223
+    put_bits(&s->pb, 5, s->qscale);
224
+    if(s->msmpeg4_version<=2){
225
+        s->rl_table_index = 2;
226
+        s->rl_chroma_table_index = 2;
227
+    }
228
+
229
+    s->dc_table_index = 1;
230
+    s->mv_table_index = 1; /* only if P frame */
231
+    s->use_skip_mb_code = 1; /* only if P frame */
232
+    s->per_mb_rl_table = 0;
233
+    if(s->msmpeg4_version==4)
234
+        s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==AV_PICTURE_TYPE_P);
235
+//printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height);
236
+
237
+    if (s->pict_type == AV_PICTURE_TYPE_I) {
238
+        s->slice_height= s->mb_height/1;
239
+        put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height);
240
+
241
+        if(s->msmpeg4_version==4){
242
+            ff_msmpeg4_encode_ext_header(s);
243
+            if(s->bit_rate>MBAC_BITRATE)
244
+                put_bits(&s->pb, 1, s->per_mb_rl_table);
245
+        }
246
+
247
+        if(s->msmpeg4_version>2){
248
+            if(!s->per_mb_rl_table){
249
+                ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index);
250
+                ff_msmpeg4_code012(&s->pb, s->rl_table_index);
251
+            }
252
+
253
+            put_bits(&s->pb, 1, s->dc_table_index);
254
+        }
255
+    } else {
256
+        put_bits(&s->pb, 1, s->use_skip_mb_code);
257
+
258
+        if(s->msmpeg4_version==4 && s->bit_rate>MBAC_BITRATE)
259
+            put_bits(&s->pb, 1, s->per_mb_rl_table);
260
+
261
+        if(s->msmpeg4_version>2){
262
+            if(!s->per_mb_rl_table)
263
+                ff_msmpeg4_code012(&s->pb, s->rl_table_index);
264
+
265
+            put_bits(&s->pb, 1, s->dc_table_index);
266
+
267
+            put_bits(&s->pb, 1, s->mv_table_index);
268
+        }
269
+    }
270
+
271
+    s->esc3_level_length= 0;
272
+    s->esc3_run_length= 0;
273
+}
274
+
275
+void ff_msmpeg4_encode_ext_header(MpegEncContext * s)
276
+{
277
+        put_bits(&s->pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29
278
+
279
+        put_bits(&s->pb, 11, FFMIN(s->bit_rate/1024, 2047));
280
+
281
+        if(s->msmpeg4_version>=3)
282
+            put_bits(&s->pb, 1, s->flipflop_rounding);
283
+        else
284
+            assert(s->flipflop_rounding==0);
285
+}
286
+
287
+void ff_msmpeg4_encode_motion(MpegEncContext * s,
288
+                                  int mx, int my)
289
+{
290
+    int code;
291
+    MVTable *mv;
292
+
293
+    /* modulo encoding */
294
+    /* WARNING : you cannot reach all the MVs even with the modulo
295
+       encoding. This is a somewhat strange compromise they took !!!  */
296
+    if (mx <= -64)
297
+        mx += 64;
298
+    else if (mx >= 64)
299
+        mx -= 64;
300
+    if (my <= -64)
301
+        my += 64;
302
+    else if (my >= 64)
303
+        my -= 64;
304
+
305
+    mx += 32;
306
+    my += 32;
307
+#if 0
308
+    if ((unsigned)mx >= 64 ||
309
+        (unsigned)my >= 64)
310
+        av_log(s->avctx, AV_LOG_ERROR, "error mx=%d my=%d\n", mx, my);
311
+#endif
312
+    mv = &ff_mv_tables[s->mv_table_index];
313
+
314
+    code = mv->table_mv_index[(mx << 6) | my];
315
+    put_bits(&s->pb,
316
+             mv->table_mv_bits[code],
317
+             mv->table_mv_code[code]);
318
+    if (code == mv->n) {
319
+        /* escape : code literally */
320
+        put_bits(&s->pb, 6, mx);
321
+        put_bits(&s->pb, 6, my);
322
+    }
323
+}
324
+
325
+void ff_msmpeg4_handle_slices(MpegEncContext *s){
326
+    if (s->mb_x == 0) {
327
+        if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
328
+            if(s->msmpeg4_version < 4){
329
+                ff_mpeg4_clean_buffers(s);
330
+            }
331
+            s->first_slice_line = 1;
332
+        } else {
333
+            s->first_slice_line = 0;
334
+        }
335
+    }
336
+}
337
+
338
+static void msmpeg4v2_encode_motion(MpegEncContext * s, int val)
339
+{
340
+    int range, bit_size, sign, code, bits;
341
+
342
+    if (val == 0) {
343
+        /* zero vector */
344
+        code = 0;
345
+        put_bits(&s->pb, ff_mvtab[code][1], ff_mvtab[code][0]);
346
+    } else {
347
+        bit_size = s->f_code - 1;
348
+        range = 1 << bit_size;
349
+        if (val <= -64)
350
+            val += 64;
351
+        else if (val >= 64)
352
+            val -= 64;
353
+
354
+        if (val >= 0) {
355
+            sign = 0;
356
+        } else {
357
+            val = -val;
358
+            sign = 1;
359
+        }
360
+        val--;
361
+        code = (val >> bit_size) + 1;
362
+        bits = val & (range - 1);
363
+
364
+        put_bits(&s->pb, ff_mvtab[code][1] + 1, (ff_mvtab[code][0] << 1) | sign);
365
+        if (bit_size > 0) {
366
+            put_bits(&s->pb, bit_size, bits);
367
+        }
368
+    }
369
+}
370
+
371
+void ff_msmpeg4_encode_mb(MpegEncContext * s,
372
+                          DCTELEM block[6][64],
373
+                          int motion_x, int motion_y)
374
+{
375
+    int cbp, coded_cbp, i;
376
+    int pred_x, pred_y;
377
+    uint8_t *coded_block;
378
+
379
+    ff_msmpeg4_handle_slices(s);
380
+
381
+    if (!s->mb_intra) {
382
+        /* compute cbp */
383
+        cbp = 0;
384
+        for (i = 0; i < 6; i++) {
385
+            if (s->block_last_index[i] >= 0)
386
+                cbp |= 1 << (5 - i);
387
+        }
388
+        if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
389
+            /* skip macroblock */
390
+            put_bits(&s->pb, 1, 1);
391
+            s->last_bits++;
392
+            s->misc_bits++;
393
+            s->skip_count++;
394
+
395
+            return;
396
+        }
397
+        if (s->use_skip_mb_code)
398
+            put_bits(&s->pb, 1, 0);     /* mb coded */
399
+
400
+        if(s->msmpeg4_version<=2){
401
+            put_bits(&s->pb,
402
+                     ff_v2_mb_type[cbp&3][1],
403
+                     ff_v2_mb_type[cbp&3][0]);
404
+            if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
405
+            else             coded_cbp= cbp;
406
+
407
+            put_bits(&s->pb,
408
+                     ff_h263_cbpy_tab[coded_cbp>>2][1],
409
+                     ff_h263_cbpy_tab[coded_cbp>>2][0]);
410
+
411
+            s->misc_bits += get_bits_diff(s);
412
+
413
+            ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
414
+            msmpeg4v2_encode_motion(s, motion_x - pred_x);
415
+            msmpeg4v2_encode_motion(s, motion_y - pred_y);
416
+        }else{
417
+            put_bits(&s->pb,
418
+                     ff_table_mb_non_intra[cbp + 64][1],
419
+                     ff_table_mb_non_intra[cbp + 64][0]);
420
+
421
+            s->misc_bits += get_bits_diff(s);
422
+
423
+            /* motion vector */
424
+            ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
425
+            ff_msmpeg4_encode_motion(s, motion_x - pred_x,
426
+                                  motion_y - pred_y);
427
+        }
428
+
429
+        s->mv_bits += get_bits_diff(s);
430
+
431
+        for (i = 0; i < 6; i++) {
432
+            ff_msmpeg4_encode_block(s, block[i], i);
433
+        }
434
+        s->p_tex_bits += get_bits_diff(s);
435
+    } else {
436
+        /* compute cbp */
437
+        cbp = 0;
438
+        coded_cbp = 0;
439
+        for (i = 0; i < 6; i++) {
440
+            int val, pred;
441
+            val = (s->block_last_index[i] >= 1);
442
+            cbp |= val << (5 - i);
443
+            if (i < 4) {
444
+                /* predict value for close blocks only for luma */
445
+                pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
446
+                *coded_block = val;
447
+                val = val ^ pred;
448
+            }
449
+            coded_cbp |= val << (5 - i);
450
+        }
451
+
452
+        if(s->msmpeg4_version<=2){
453
+            if (s->pict_type == AV_PICTURE_TYPE_I) {
454
+                put_bits(&s->pb,
455
+                         ff_v2_intra_cbpc[cbp&3][1], ff_v2_intra_cbpc[cbp&3][0]);
456
+            } else {
457
+                if (s->use_skip_mb_code)
458
+                    put_bits(&s->pb, 1, 0);     /* mb coded */
459
+                put_bits(&s->pb,
460
+                         ff_v2_mb_type[(cbp&3) + 4][1],
461
+                         ff_v2_mb_type[(cbp&3) + 4][0]);
462
+            }
463
+            put_bits(&s->pb, 1, 0);             /* no AC prediction yet */
464
+            put_bits(&s->pb,
465
+                     ff_h263_cbpy_tab[cbp>>2][1],
466
+                     ff_h263_cbpy_tab[cbp>>2][0]);
467
+        }else{
468
+            if (s->pict_type == AV_PICTURE_TYPE_I) {
469
+                put_bits(&s->pb,
470
+                         ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
471
+            } else {
472
+                if (s->use_skip_mb_code)
473
+                    put_bits(&s->pb, 1, 0);     /* mb coded */
474
+                put_bits(&s->pb,
475
+                         ff_table_mb_non_intra[cbp][1],
476
+                         ff_table_mb_non_intra[cbp][0]);
477
+            }
478
+            put_bits(&s->pb, 1, 0);             /* no AC prediction yet */
479
+            if(s->inter_intra_pred){
480
+                s->h263_aic_dir=0;
481
+                put_bits(&s->pb, ff_table_inter_intra[s->h263_aic_dir][1], ff_table_inter_intra[s->h263_aic_dir][0]);
482
+            }
483
+        }
484
+        s->misc_bits += get_bits_diff(s);
485
+
486
+        for (i = 0; i < 6; i++) {
487
+            ff_msmpeg4_encode_block(s, block[i], i);
488
+        }
489
+        s->i_tex_bits += get_bits_diff(s);
490
+        s->i_count++;
491
+    }
492
+}
493
+
494
+static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
495
+{
496
+    int sign, code;
497
+    int pred, extquant;
498
+    int extrabits = 0;
499
+
500
+    int16_t *dc_val;
501
+    pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
502
+
503
+    /* update predictor */
504
+    if (n < 4) {
505
+        *dc_val = level * s->y_dc_scale;
506
+    } else {
507
+        *dc_val = level * s->c_dc_scale;
508
+    }
509
+
510
+    /* do the prediction */
511
+    level -= pred;
512
+
513
+    if(s->msmpeg4_version<=2){
514
+        if (n < 4) {
515
+            put_bits(&s->pb,
516
+                     ff_v2_dc_lum_table[level + 256][1],
517
+                     ff_v2_dc_lum_table[level + 256][0]);
518
+        }else{
519
+            put_bits(&s->pb,
520
+                     ff_v2_dc_chroma_table[level + 256][1],
521
+                     ff_v2_dc_chroma_table[level + 256][0]);
522
+        }
523
+    }else{
524
+        sign = 0;
525
+        if (level < 0) {
526
+            level = -level;
527
+            sign = 1;
528
+        }
529
+        code = level;
530
+        if (code > DC_MAX)
531
+            code = DC_MAX;
532
+        else if( s->msmpeg4_version>=6 ) {
533
+            if( s->qscale == 1 ) {
534
+                extquant = (level + 3) & 0x3;
535
+                code  = ((level+3)>>2);
536
+            } else if( s->qscale == 2 ) {
537
+                extquant = (level + 1) & 0x1;
538
+                code  = ((level+1)>>1);
539
+            }
540
+        }
541
+
542
+        if (s->dc_table_index == 0) {
543
+            if (n < 4) {
544
+                put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]);
545
+            } else {
546
+                put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]);
547
+            }
548
+        } else {
549
+            if (n < 4) {
550
+                put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]);
551
+            } else {
552
+                put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]);
553
+            }
554
+        }
555
+
556
+        if(s->msmpeg4_version>=6 && s->qscale<=2)
557
+            extrabits = 3 - s->qscale;
558
+
559
+        if (code == DC_MAX)
560
+            put_bits(&s->pb, 8 + extrabits, level);
561
+        else if(extrabits > 0)//== VC1 && s->qscale<=2
562
+            put_bits(&s->pb, extrabits, extquant);
563
+
564
+        if (level != 0) {
565
+            put_bits(&s->pb, 1, sign);
566
+        }
567
+    }
568
+}
569
+
570
+/* Encoding of a block. Very similar to MPEG4 except for a different
571
+   escape coding (same as H263) and more vlc tables.
572
+ */
573
+void ff_msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n)
574
+{
575
+    int level, run, last, i, j, last_index;
576
+    int last_non_zero, sign, slevel;
577
+    int code, run_diff, dc_pred_dir;
578
+    const RLTable *rl;
579
+    const uint8_t *scantable;
580
+
581
+    if (s->mb_intra) {
582
+        msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
583
+        i = 1;
584
+        if (n < 4) {
585
+            rl = &ff_rl_table[s->rl_table_index];
586
+        } else {
587
+            rl = &ff_rl_table[3 + s->rl_chroma_table_index];
588
+        }
589
+        run_diff = s->msmpeg4_version>=4;
590
+        scantable= s->intra_scantable.permutated;
591
+    } else {
592
+        i = 0;
593
+        rl = &ff_rl_table[3 + s->rl_table_index];
594
+        if(s->msmpeg4_version<=2)
595
+            run_diff = 0;
596
+        else
597
+            run_diff = 1;
598
+        scantable= s->inter_scantable.permutated;
599
+    }
600
+
601
+    /* recalculate block_last_index for M$ wmv1 */
602
+    if(s->msmpeg4_version>=4 && s->msmpeg4_version<6 && s->block_last_index[n]>0){
603
+        for(last_index=63; last_index>=0; last_index--){
604
+            if(block[scantable[last_index]]) break;
605
+        }
606
+        s->block_last_index[n]= last_index;
607
+    }else
608
+        last_index = s->block_last_index[n];
609
+    /* AC coefs */
610
+    last_non_zero = i - 1;
611
+    for (; i <= last_index; i++) {
612
+        j = scantable[i];
613
+        level = block[j];
614
+        if (level) {
615
+            run = i - last_non_zero - 1;
616
+            last = (i == last_index);
617
+            sign = 0;
618
+            slevel = level;
619
+            if (level < 0) {
620
+                sign = 1;
621
+                level = -level;
622
+            }
623
+
624
+            if(level<=MAX_LEVEL && run<=MAX_RUN){
625
+                s->ac_stats[s->mb_intra][n>3][level][run][last]++;
626
+            }
627
+
628
+            s->ac_stats[s->mb_intra][n > 3][40][63][0]++; //esc3 like
629
+
630
+            code = get_rl_index(rl, last, run, level);
631
+            put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
632
+            if (code == rl->n) {
633
+                int level1, run1;
634
+
635
+                level1 = level - rl->max_level[last][run];
636
+                if (level1 < 1)
637
+                    goto esc2;
638
+                code = get_rl_index(rl, last, run, level1);
639
+                if (code == rl->n) {
640
+                esc2:
641
+                    put_bits(&s->pb, 1, 0);
642
+                    if (level > MAX_LEVEL)
643
+                        goto esc3;
644
+                    run1 = run - rl->max_run[last][level] - run_diff;
645
+                    if (run1 < 0)
646
+                        goto esc3;
647
+                    code = get_rl_index(rl, last, run1+1, level);
648
+                    if (s->msmpeg4_version == 4 && code == rl->n)
649
+                        goto esc3;
650
+                    code = get_rl_index(rl, last, run1, level);
651
+                    if (code == rl->n) {
652
+                    esc3:
653
+                        /* third escape */
654
+                        put_bits(&s->pb, 1, 0);
655
+                        put_bits(&s->pb, 1, last);
656
+                        if(s->msmpeg4_version>=4){
657
+                            if(s->esc3_level_length==0){
658
+                                s->esc3_level_length=8;
659
+                                s->esc3_run_length= 6;
660
+                                //ESCLVLSZ + ESCRUNSZ
661
+                                if(s->qscale<8)
662
+                                    put_bits(&s->pb, 6 + (s->msmpeg4_version>=6), 3);
663
+                                else
664
+                                    put_bits(&s->pb, 8, 3);
665
+                            }
666
+                            put_bits(&s->pb, s->esc3_run_length, run);
667
+                            put_bits(&s->pb, 1, sign);
668
+                            put_bits(&s->pb, s->esc3_level_length, level);
669
+                        }else{
670
+                            put_bits(&s->pb, 6, run);
671
+                            put_sbits(&s->pb, 8, slevel);
672
+                        }
673
+                    } else {
674
+                        /* second escape */
675
+                        put_bits(&s->pb, 1, 1);
676
+                        put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
677
+                        put_bits(&s->pb, 1, sign);
678
+                    }
679
+                } else {
680
+                    /* first escape */
681
+                    put_bits(&s->pb, 1, 1);
682
+                    put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
683
+                    put_bits(&s->pb, 1, sign);
684
+                }
685
+            } else {
686
+                put_bits(&s->pb, 1, sign);
687
+            }
688
+            last_non_zero = i;
689
+        }
690
+    }
691
+}
... ...
@@ -28,7 +28,7 @@ static int pam_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
28 28
                             const AVFrame *pict, int *got_packet)
29 29
 {
30 30
     PNMContext *s     = avctx->priv_data;
31
-    AVFrame * const p = (AVFrame*)&s->picture;
31
+    AVFrame * const p = &s->picture;
32 32
     int i, h, w, n, linesize, depth, maxval, ret;
33 33
     const char *tuple_type;
34 34
     uint8_t *ptr;
... ...
@@ -198,8 +198,8 @@ av_cold int ff_pnm_init(AVCodecContext *avctx)
198 198
 {
199 199
     PNMContext *s = avctx->priv_data;
200 200
 
201
-    avcodec_get_frame_defaults((AVFrame*)&s->picture);
202
-    avctx->coded_frame = (AVFrame*)&s->picture;
201
+    avcodec_get_frame_defaults(&s->picture);
202
+    avctx->coded_frame = &s->picture;
203 203
 
204 204
     return 0;
205 205
 }
... ...
@@ -31,7 +31,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
31 31
     int buf_size         = avpkt->size;
32 32
     PNMContext * const s = avctx->priv_data;
33 33
     AVFrame *picture     = data;
34
-    AVFrame * const p    = (AVFrame*)&s->picture;
34
+    AVFrame * const p    = &s->picture;
35 35
     int i, j, n, linesize, h, upgrade = 0, is_mono = 0;
36 36
     unsigned char *ptr;
37 37
     int components, sample_len;
... ...
@@ -184,7 +184,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
184 184
         }
185 185
         break;
186 186
     }
187
-    *picture   = *(AVFrame*)&s->picture;
187
+    *picture   = s->picture;
188 188
     *data_size = sizeof(AVPicture);
189 189
 
190 190
     return s->bytestream - s->bytestream_start;
... ...
@@ -28,7 +28,7 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
28 28
                             const AVFrame *pict, int *got_packet)
29 29
 {
30 30
     PNMContext *s     = avctx->priv_data;
31
-    AVFrame * const p = (AVFrame*)&s->picture;
31
+    AVFrame * const p = &s->picture;
32 32
     int i, h, h1, c, n, linesize, ret;
33 33
     uint8_t *ptr, *ptr1, *ptr2;
34 34
 
... ...
@@ -75,8 +75,8 @@ static const vec_s8 h_subpel_filters_outer[3] =
75 75
     dstv = vec_sra(dstv, c7)
76 76
 
77 77
 static av_always_inline
78
-void put_vp8_epel_h_altivec_core(uint8_t *dst, int dst_stride,
79
-                                 uint8_t *src, int src_stride,
78
+void put_vp8_epel_h_altivec_core(uint8_t *dst, ptrdiff_t dst_stride,
79
+                                 uint8_t *src, ptrdiff_t src_stride,
80 80
                                  int h, int mx, int w, int is6tap)
81 81
 {
82 82
     LOAD_H_SUBPEL_FILTER(mx-1);
... ...
@@ -161,8 +161,8 @@ static const vec_u8 v_subpel_filters[7] =
161 161
     dstv = vec_sra(dstv, c7)
162 162
 
163 163
 static av_always_inline
164
-void put_vp8_epel_v_altivec_core(uint8_t *dst, int dst_stride,
165
-                                 uint8_t *src, int src_stride,
164
+void put_vp8_epel_v_altivec_core(uint8_t *dst, ptrdiff_t dst_stride,
165
+                                 uint8_t *src, ptrdiff_t src_stride,
166 166
                                  int h, int my, int w, int is6tap)
167 167
 {
168 168
     LOAD_V_SUBPEL_FILTER(my-1);
... ...
@@ -226,19 +226,19 @@ void put_vp8_epel_v_altivec_core(uint8_t *dst, int dst_stride,
226 226
 
227 227
 #define EPEL_FUNCS(WIDTH, TAPS) \
228 228
 static av_noinline \
229
-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) \
229
+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) \
230 230
 { \
231 231
     put_vp8_epel_h_altivec_core(dst, dst_stride, src, src_stride, h, mx, WIDTH, TAPS == 6); \
232 232
 } \
233 233
 \
234 234
 static av_noinline \
235
-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) \
235
+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) \
236 236
 { \
237 237
     put_vp8_epel_v_altivec_core(dst, dst_stride, src, src_stride, h, my, WIDTH, TAPS == 6); \
238 238
 }
239 239
 
240 240
 #define EPEL_HV(WIDTH, HTAPS, VTAPS) \
241
-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) \
241
+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) \
242 242
 { \
243 243
     DECLARE_ALIGNED(16, uint8_t, tmp)[(2*WIDTH+5)*16]; \
244 244
     if (VTAPS == 6) { \
... ...
@@ -266,7 +266,7 @@ EPEL_HV(4,  4,6)
266 266
 EPEL_HV(4,  6,4)
267 267
 EPEL_HV(4,  4,4)
268 268
 
269
-static void put_vp8_pixels16_altivec(uint8_t *dst, int stride, uint8_t *src, int s, int h, int mx, int my)
269
+static void put_vp8_pixels16_altivec(uint8_t *dst, ptrdiff_t stride, uint8_t *src, ptrdiff_t s, int h, int mx, int my)
270 270
 {
271 271
     ff_put_pixels16_altivec(dst, src, stride, h);
272 272
 }
... ...
@@ -40,7 +40,7 @@ static int decode_frame(AVCodecContext *avctx,
40 40
     const uint8_t *buf_end = avpkt->data + avpkt->size;
41 41
     int buf_size = avpkt->size;
42 42
     QdrawContext * const a = avctx->priv_data;
43
-    AVFrame * const p= (AVFrame*)&a->pic;
43
+    AVFrame * const p = &a->pic;
44 44
     uint8_t* outdata;
45 45
     int colors;
46 46
     int i;
... ...
@@ -259,8 +259,8 @@ static int decode_frame(AVCodecContext *avctx,
259 259
     const uint8_t *buf = avpkt->data;
260 260
     int buf_size = avpkt->size;
261 261
     QpegContext * const a = avctx->priv_data;
262
-    AVFrame * p= (AVFrame*)&a->pic;
263
-    AVFrame * ref= (AVFrame*)&a->ref;
262
+    AVFrame *  p = &a->pic;
263
+    AVFrame * ref= &a->ref;
264 264
     uint8_t* outdata;
265 265
     int delta, ret = 0;
266 266
     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){
311 311
 
312 312
 static av_cold int decode_end(AVCodecContext *avctx){
313 313
     QpegContext * const a = avctx->priv_data;
314
-    AVFrame * const p= (AVFrame*)&a->pic;
315
-    AVFrame * const ref= (AVFrame*)&a->ref;
314
+    AVFrame * const p = &a->pic;
315
+    AVFrame * const ref= &a->ref;
316 316
 
317 317
     if(p->data[0])
318 318
         avctx->release_buffer(avctx, p);
... ...
@@ -140,8 +140,8 @@ static int raw_decode(AVCodecContext *avctx,
140 140
     int linesize_align = 4;
141 141
     RawVideoContext *context = avctx->priv_data;
142 142
 
143
-    AVFrame * frame = (AVFrame *) data;
144
-    AVPicture * picture = (AVPicture *) data;
143
+    AVFrame   *frame   = data;
144
+    AVPicture *picture = data;
145 145
 
146 146
     frame->pict_type        = avctx->coded_frame->pict_type;
147 147
     frame->interlaced_frame = avctx->coded_frame->interlaced_frame;
... ...
@@ -32,7 +32,7 @@
32 32
 
33 33
 static av_cold int raw_init_encoder(AVCodecContext *avctx)
34 34
 {
35
-    avctx->coded_frame = (AVFrame *)avctx->priv_data;
35
+    avctx->coded_frame            = avctx->priv_data;
36 36
     avcodec_get_frame_defaults(avctx->coded_frame);
37 37
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
38 38
     avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]);
... ...
@@ -515,9 +515,10 @@ static int rv10_decode_packet(AVCodecContext *avctx,
515 515
                              const uint8_t *buf, int buf_size, int buf_size2)
516 516
 {
517 517
     MpegEncContext *s = avctx->priv_data;
518
-    int mb_count, mb_pos, left, start_mb_x;
518
+    int mb_count, mb_pos, left, start_mb_x, active_bits_size;
519 519
 
520
-    init_get_bits(&s->gb, buf, buf_size*8);
520
+    active_bits_size = buf_size * 8;
521
+    init_get_bits(&s->gb, buf, FFMAX(buf_size, buf_size2) * 8);
521 522
     if(s->codec_id ==CODEC_ID_RV10)
522 523
         mb_count = rv10_decode_picture_header(s);
523 524
     else
... ...
@@ -601,13 +602,26 @@ static int rv10_decode_packet(AVCodecContext *avctx,
601 601
         s->mv_type = MV_TYPE_16X16;
602 602
         ret=ff_h263_decode_mb(s, s->block);
603 603
 
604
-        if (ret != SLICE_ERROR && s->gb.size_in_bits < get_bits_count(&s->gb) && 8*buf_size2 >= get_bits_count(&s->gb)){
605
-            av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n", s->gb.size_in_bits, 8*buf_size2);
606
-            s->gb.size_in_bits= 8*buf_size2;
604
+        // Repeat the slice end check from ff_h263_decode_mb with our active
605
+        // bitstream size
606
+        if (ret != SLICE_ERROR) {
607
+            int v = show_bits(&s->gb, 16);
608
+
609
+            if (get_bits_count(&s->gb) + 16 > active_bits_size)
610
+                v >>= get_bits_count(&s->gb) + 16 - active_bits_size;
611
+
612
+            if (!v)
613
+                ret = SLICE_END;
614
+        }
615
+        if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&s->gb) &&
616
+            8 * buf_size2 >= get_bits_count(&s->gb)) {
617
+            active_bits_size = buf_size2 * 8;
618
+            av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n",
619
+                   8 * buf_size, active_bits_size);
607 620
             ret= SLICE_OK;
608 621
         }
609 622
 
610
-        if (ret == SLICE_ERROR || s->gb.size_in_bits < get_bits_count(&s->gb)) {
623
+        if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&s->gb)) {
611 624
             av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x, s->mb_y);
612 625
             return -1;
613 626
         }
... ...
@@ -629,7 +643,7 @@ static int rv10_decode_packet(AVCodecContext *avctx,
629 629
 
630 630
     ff_er_add_slice(s, start_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END);
631 631
 
632
-    return s->gb.size_in_bits;
632
+    return active_bits_size;
633 633
 }
634 634
 
635 635
 static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n)
... ...
@@ -661,8 +675,12 @@ static int rv10_decode_frame(AVCodecContext *avctx,
661 661
 
662 662
     if(!avctx->slice_count){
663 663
         slice_count = (*buf++) + 1;
664
+        buf_size--;
664 665
         slices_hdr = buf + 4;
665 666
         buf += 8 * slice_count;
667
+        buf_size -= 8 * slice_count;
668
+        if (buf_size <= 0)
669
+            return AVERROR_INVALIDDATA;
666 670
     }else
667 671
         slice_count = avctx->slice_count;
668 672
 
... ...
@@ -696,9 +714,9 @@ static int rv10_decode_frame(AVCodecContext *avctx,
696 696
         ff_MPV_frame_end(s);
697 697
 
698 698
         if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
699
-            *pict= *(AVFrame*)s->current_picture_ptr;
699
+            *pict = s->current_picture_ptr->f;
700 700
         } else if (s->last_picture_ptr != NULL) {
701
-            *pict= *(AVFrame*)s->last_picture_ptr;
701
+            *pict = s->last_picture_ptr->f;
702 702
         }
703 703
 
704 704
         if(s->last_picture_ptr || s->low_delay){
... ...
@@ -708,7 +726,7 @@ static int rv10_decode_frame(AVCodecContext *avctx,
708 708
         s->current_picture_ptr= NULL; //so we can detect if frame_end wasnt called (find some nicer solution...)
709 709
     }
710 710
 
711
-    return buf_size;
711
+    return avpkt->size;
712 712
 }
713 713
 
714 714
 AVCodec ff_rv10_decoder = {
... ...
@@ -1660,7 +1660,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
1660 1660
     if (buf_size == 0) {
1661 1661
         /* special case for last picture */
1662 1662
         if (s->low_delay==0 && s->next_picture_ptr) {
1663
-            *pict = *(AVFrame*)s->next_picture_ptr;
1663
+            *pict = s->next_picture_ptr->f;
1664 1664
             s->next_picture_ptr = NULL;
1665 1665
 
1666 1666
             *data_size = sizeof(AVFrame);
... ...
@@ -1747,9 +1747,9 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
1747 1747
             ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 0);
1748 1748
 
1749 1749
         if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
1750
-            *pict = *(AVFrame*)s->current_picture_ptr;
1750
+            *pict = s->current_picture_ptr->f;
1751 1751
         } else if (s->last_picture_ptr != NULL) {
1752
-            *pict = *(AVFrame*)s->last_picture_ptr;
1752
+            *pict = s->last_picture_ptr->f;
1753 1753
         }
1754 1754
 
1755 1755
         if(s->last_picture_ptr || s->low_delay){
... ...
@@ -735,7 +735,7 @@ static int svq1_decode_frame(AVCodecContext *avctx,
735 735
     }
736 736
   }
737 737
 
738
-  *pict = *(AVFrame*)&s->current_picture;
738
+  *pict = s->current_picture.f;
739 739
 
740 740
 
741 741
   ff_MPV_frame_end(s);
... ...
@@ -473,7 +473,7 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
473 473
     SVQ1Context * const s = avctx->priv_data;
474 474
 
475 475
     ff_dsputil_init(&s->dsp, avctx);
476
-    avctx->coded_frame= (AVFrame*)&s->picture;
476
+    avctx->coded_frame = &s->picture;
477 477
 
478 478
     s->frame_width = avctx->width;
479 479
     s->frame_height = avctx->height;
... ...
@@ -501,7 +501,7 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
501 501
                              const AVFrame *pict, int *got_packet)
502 502
 {
503 503
     SVQ1Context * const s = avctx->priv_data;
504
-    AVFrame * const p= (AVFrame*)&s->picture;
504
+    AVFrame * const p = &s->picture;
505 505
     AVFrame temp;
506 506
     int i, ret;
507 507
 
... ...
@@ -958,7 +958,7 @@ static int svq3_decode_frame(AVCodecContext *avctx,
958 958
     /* special case for last picture */
959 959
     if (buf_size == 0) {
960 960
         if (s->next_picture_ptr && !s->low_delay) {
961
-            *(AVFrame *) data = *(AVFrame *) &s->next_picture;
961
+            *(AVFrame *) data   = s->next_picture.f;
962 962
             s->next_picture_ptr = NULL;
963 963
             *data_size = sizeof(AVFrame);
964 964
         }
... ...
@@ -1101,9 +1101,9 @@ static int svq3_decode_frame(AVCodecContext *avctx,
1101 1101
     ff_MPV_frame_end(s);
1102 1102
 
1103 1103
     if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
1104
-        *(AVFrame *) data = *(AVFrame *) &s->current_picture;
1104
+        *(AVFrame *) data = s->current_picture.f;
1105 1105
     } else {
1106
-        *(AVFrame *) data = *(AVFrame *) &s->last_picture;
1106
+        *(AVFrame *) data = s->last_picture.f;
1107 1107
     }
1108 1108
 
1109 1109
     /* Do not output the last pic after seeking. */
... ...
@@ -106,7 +106,7 @@ static int decode_frame(AVCodecContext *avctx,
106 106
     const uint8_t *buf_end = avpkt->data + avpkt->size;
107 107
     TargaContext * const s = avctx->priv_data;
108 108
     AVFrame *picture = data;
109
-    AVFrame * const p= (AVFrame*)&s->picture;
109
+    AVFrame * const p = &s->picture;
110 110
     uint8_t *dst;
111 111
     int stride;
112 112
     int idlen, pal, compr, y, w, h, bpp, flags;
... ...
@@ -262,7 +262,7 @@ static int decode_frame(AVCodecContext *avctx,
262 262
         }
263 263
     }
264 264
 
265
-    *picture= *(AVFrame*)&s->picture;
265
+    *picture   = s->picture;
266 266
     *data_size = sizeof(AVPicture);
267 267
 
268 268
     return avpkt->size;
... ...
@@ -271,8 +271,8 @@ static int decode_frame(AVCodecContext *avctx,
271 271
 static av_cold int targa_init(AVCodecContext *avctx){
272 272
     TargaContext *s = avctx->priv_data;
273 273
 
274
-    avcodec_get_frame_defaults((AVFrame*)&s->picture);
275
-    avctx->coded_frame= (AVFrame*)&s->picture;
274
+    avcodec_get_frame_defaults(&s->picture);
275
+    avctx->coded_frame = &s->picture;
276 276
 
277 277
     return 0;
278 278
 }
... ...
@@ -577,7 +577,7 @@ static int decode_frame(AVCodecContext *avctx,
577 577
     int buf_size = avpkt->size;
578 578
     TiffContext * const s = avctx->priv_data;
579 579
     AVFrame *picture = data;
580
-    AVFrame * const p= (AVFrame*)&s->picture;
580
+    AVFrame * const p = &s->picture;
581 581
     const uint8_t *orig_buf = buf, *end_buf = buf + buf_size;
582 582
     unsigned off;
583 583
     int id, le, ret;
... ...
@@ -691,7 +691,7 @@ static int decode_frame(AVCodecContext *avctx,
691 691
             dst += s->picture.linesize[0];
692 692
         }
693 693
     }
694
-    *picture= *(AVFrame*)&s->picture;
694
+    *picture   = s->picture;
695 695
     *data_size = sizeof(AVPicture);
696 696
 
697 697
     return buf_size;
... ...
@@ -703,8 +703,8 @@ static av_cold int tiff_init(AVCodecContext *avctx){
703 703
     s->width = 0;
704 704
     s->height = 0;
705 705
     s->avctx = avctx;
706
-    avcodec_get_frame_defaults((AVFrame*)&s->picture);
707
-    avctx->coded_frame= (AVFrame*)&s->picture;
706
+    avcodec_get_frame_defaults(&s->picture);
707
+    avctx->coded_frame = &s->picture;
708 708
     ff_lzw_decode_open(&s->lzw);
709 709
     ff_ccitt_unpack_init();
710 710
 
... ...
@@ -206,7 +206,7 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt,
206 206
                         const AVFrame *pict, int *got_packet)
207 207
 {
208 208
     TiffEncoderContext *s = avctx->priv_data;
209
-    AVFrame *const p = (AVFrame *) & s->picture;
209
+    AVFrame *const p = &s->picture;
210 210
     int i;
211 211
     uint8_t *ptr;
212 212
     uint8_t *offset;
... ...
@@ -767,7 +767,7 @@ static int decode_frame(AVCodecContext *avctx,
767 767
     const uint8_t *buf = avpkt->data;
768 768
     int buf_size = avpkt->size;
769 769
     TM2Context * const l = avctx->priv_data;
770
-    AVFrame * const p= (AVFrame*)&l->pic;
770
+    AVFrame * const p = &l->pic;
771 771
     int i, skip, t;
772 772
 
773 773
     av_fast_padded_malloc(&l->buffer, &l->buffer_size, buf_size);
... ...
@@ -50,7 +50,7 @@ static av_cold int ulti_decode_init(AVCodecContext *avctx)
50 50
     s->height = avctx->height;
51 51
     s->blocks = (s->width / 8) * (s->height / 8);
52 52
     avctx->pix_fmt = PIX_FMT_YUV410P;
53
-    avcodec_get_frame_defaults(&s->frame);
53
+    avctx->coded_frame = &s->frame;
54 54
     avctx->coded_frame = (AVFrame*) &s->frame;
55 55
     s->ulti_codebook = ulti_codebook;
56 56
 
... ...
@@ -1226,6 +1226,12 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
1226 1226
                 avpkt->data = new_data;
1227 1227
         }
1228 1228
 
1229
+        if (!user_packet && avpkt->data) {
1230
+            uint8_t *new_data = av_realloc(avpkt->data, avpkt->size);
1231
+            if (new_data)
1232
+                avpkt->data = new_data;
1233
+        }
1234
+
1229 1235
         avctx->frame_number++;
1230 1236
     }
1231 1237
 
... ...
@@ -5456,7 +5456,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data,
5456 5456
     if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)) {
5457 5457
         /* special case for last picture */
5458 5458
         if (s->low_delay == 0 && s->next_picture_ptr) {
5459
-            *pict = *(AVFrame*)s->next_picture_ptr;
5459
+            *pict = s->next_picture_ptr->f;
5460 5460
             s->next_picture_ptr = NULL;
5461 5461
 
5462 5462
             *data_size = sizeof(AVFrame);
... ...
@@ -5764,9 +5764,9 @@ image:
5764 5764
         *data_size = sizeof(AVFrame);
5765 5765
     } else {
5766 5766
         if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
5767
-            *pict = *(AVFrame*)s->current_picture_ptr;
5767
+            *pict = s->current_picture_ptr->f;
5768 5768
         } else if (s->last_picture_ptr != NULL) {
5769
-            *pict = *(AVFrame*)s->last_picture_ptr;
5769
+            *pict = s->last_picture_ptr->f;
5770 5770
         }
5771 5771
         if (s->last_picture_ptr || s->low_delay) {
5772 5772
             *data_size = sizeof(AVFrame);
... ...
@@ -49,7 +49,7 @@ static int decode_frame(AVCodecContext *avctx,
49 49
     int buf_size = avpkt->size;
50 50
     VCR1Context * const a = avctx->priv_data;
51 51
     AVFrame *picture = data;
52
-    AVFrame * const p= (AVFrame*)&a->picture;
52
+    AVFrame * const p = &a->picture;
53 53
     const uint8_t *bytestream= buf;
54 54
     int i, x, y;
55 55
 
... ...
@@ -116,7 +116,7 @@ static int decode_frame(AVCodecContext *avctx,
116 116
         }
117 117
     }
118 118
 
119
-    *picture= *(AVFrame*)&a->picture;
119
+    *picture   = a->picture;
120 120
     *data_size = sizeof(AVPicture);
121 121
 
122 122
     return buf_size;
... ...
@@ -126,7 +126,7 @@ static int decode_frame(AVCodecContext *avctx,
126 126
 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
127 127
     VCR1Context * const a = avctx->priv_data;
128 128
     AVFrame *pict = data;
129
-    AVFrame * const p= (AVFrame*)&a->picture;
129
+    AVFrame * const p = &a->picture;
130 130
     int size;
131 131
 
132 132
     *p = *pict;
... ...
@@ -146,7 +146,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
146 146
 static av_cold void common_init(AVCodecContext *avctx){
147 147
     VCR1Context * const a = avctx->priv_data;
148 148
 
149
-    avctx->coded_frame= (AVFrame*)&a->picture;
149
+    avctx->coded_frame = &a->picture;
150 150
     avcodec_get_frame_defaults(&a->picture);
151 151
     a->avctx= avctx;
152 152
 }
... ...
@@ -21,7 +21,7 @@
21 21
 #define AVCODEC_VERSION_H
22 22
 
23 23
 #define LIBAVCODEC_VERSION_MAJOR 54
24
-#define LIBAVCODEC_VERSION_MINOR  5
24
+#define LIBAVCODEC_VERSION_MINOR  6
25 25
 #define LIBAVCODEC_VERSION_MICRO 100
26 26
 
27 27
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
... ...
@@ -77,7 +77,7 @@ static void vp8_luma_dc_wht_dc_c(DCTELEM block[4][4][16], DCTELEM dc[16])
77 77
 #define MUL_20091(a) ((((a)*20091) >> 16) + (a))
78 78
 #define MUL_35468(a)  (((a)*35468) >> 16)
79 79
 
80
-static void vp8_idct_add_c(uint8_t *dst, DCTELEM block[16], int stride)
80
+static void vp8_idct_add_c(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride)
81 81
 {
82 82
     int i, t0, t1, t2, t3;
83 83
     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)
113 113
     }
114 114
 }
115 115
 
116
-static void vp8_idct_dc_add_c(uint8_t *dst, DCTELEM block[16], int stride)
116
+static void vp8_idct_dc_add_c(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride)
117 117
 {
118 118
     int i, dc = (block[0] + 4) >> 3;
119 119
     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)
128 128
     }
129 129
 }
130 130
 
131
-static void vp8_idct_dc_add4uv_c(uint8_t *dst, DCTELEM block[4][16], int stride)
131
+static void vp8_idct_dc_add4uv_c(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride)
132 132
 {
133 133
     vp8_idct_dc_add_c(dst+stride*0+0, block[0], stride);
134 134
     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)
136 136
     vp8_idct_dc_add_c(dst+stride*4+4, block[3], stride);
137 137
 }
138 138
 
139
-static void vp8_idct_dc_add4y_c(uint8_t *dst, DCTELEM block[4][16], int stride)
139
+static void vp8_idct_dc_add4y_c(uint8_t *dst, DCTELEM block[4][16], ptrdiff_t stride)
140 140
 {
141 141
     vp8_idct_dc_add_c(dst+ 0, block[0], stride);
142 142
     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)
157 157
 
158 158
 #define clip_int8(n) (cm[n+0x80]-0x80)
159 159
 
160
-static av_always_inline void filter_common(uint8_t *p, int stride, int is4tap)
160
+static av_always_inline void filter_common(uint8_t *p, ptrdiff_t stride, int is4tap)
161 161
 {
162 162
     LOAD_PIXELS
163 163
     int a, f1, f2;
... ...
@@ -188,7 +188,7 @@ static av_always_inline void filter_common(uint8_t *p, int stride, int is4tap)
188 188
     }
189 189
 }
190 190
 
191
-static av_always_inline int simple_limit(uint8_t *p, int stride, int flim)
191
+static av_always_inline int simple_limit(uint8_t *p, ptrdiff_t stride, int flim)
192 192
 {
193 193
     LOAD_PIXELS
194 194
     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)
198 198
  * E - limit at the macroblock edge
199 199
  * I - limit for interior difference
200 200
  */
201
-static av_always_inline int normal_limit(uint8_t *p, int stride, int E, int I)
201
+static av_always_inline int normal_limit(uint8_t *p, ptrdiff_t stride, int E, int I)
202 202
 {
203 203
     LOAD_PIXELS
204 204
     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)
207 207
 }
208 208
 
209 209
 // high edge variance
210
-static av_always_inline int hev(uint8_t *p, int stride, int thresh)
210
+static av_always_inline int hev(uint8_t *p, ptrdiff_t stride, int thresh)
211 211
 {
212 212
     LOAD_PIXELS
213 213
     return FFABS(p1-p0) > thresh || FFABS(q1-q0) > thresh;
214 214
 }
215 215
 
216
-static av_always_inline void filter_mbedge(uint8_t *p, int stride)
216
+static av_always_inline void filter_mbedge(uint8_t *p, ptrdiff_t stride)
217 217
 {
218 218
     int a0, a1, a2, w;
219 219
     uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
... ...
@@ -236,7 +236,7 @@ static av_always_inline void filter_mbedge(uint8_t *p, int stride)
236 236
 }
237 237
 
238 238
 #define LOOP_FILTER(dir, size, stridea, strideb, maybe_inline) \
239
-static maybe_inline void vp8_ ## dir ## _loop_filter ## size ## _c(uint8_t *dst, int stride,\
239
+static maybe_inline void vp8_ ## dir ## _loop_filter ## size ## _c(uint8_t *dst, ptrdiff_t stride,\
240 240
                                      int flim_E, int flim_I, int hev_thresh)\
241 241
 {\
242 242
     int i;\
... ...
@@ -250,7 +250,7 @@ static maybe_inline void vp8_ ## dir ## _loop_filter ## size ## _c(uint8_t *dst,
250 250
         }\
251 251
 }\
252 252
 \
253
-static maybe_inline void vp8_ ## dir ## _loop_filter ## size ## _inner_c(uint8_t *dst, int stride,\
253
+static maybe_inline void vp8_ ## dir ## _loop_filter ## size ## _inner_c(uint8_t *dst, ptrdiff_t stride,\
254 254
                                       int flim_E, int flim_I, int hev_thresh)\
255 255
 {\
256 256
     int i;\
... ...
@@ -270,13 +270,13 @@ LOOP_FILTER(h, 16, stride, 1,)
270 270
 
271 271
 #define UV_LOOP_FILTER(dir, stridea, strideb) \
272 272
 LOOP_FILTER(dir, 8, stridea, strideb, av_always_inline) \
273
-static void vp8_ ## dir ## _loop_filter8uv_c(uint8_t *dstU, uint8_t *dstV, int stride,\
273
+static void vp8_ ## dir ## _loop_filter8uv_c(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,\
274 274
                                       int fE, int fI, int hev_thresh)\
275 275
 {\
276 276
   vp8_ ## dir ## _loop_filter8_c(dstU, stride, fE, fI, hev_thresh);\
277 277
   vp8_ ## dir ## _loop_filter8_c(dstV, stride, fE, fI, hev_thresh);\
278 278
 }\
279
-static void vp8_ ## dir ## _loop_filter8uv_inner_c(uint8_t *dstU, uint8_t *dstV, int stride,\
279
+static void vp8_ ## dir ## _loop_filter8uv_inner_c(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,\
280 280
                                       int fE, int fI, int hev_thresh)\
281 281
 {\
282 282
   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,
286 286
 UV_LOOP_FILTER(v, 1, stride)
287 287
 UV_LOOP_FILTER(h, stride, 1)
288 288
 
289
-static void vp8_v_loop_filter_simple_c(uint8_t *dst, int stride, int flim)
289
+static void vp8_v_loop_filter_simple_c(uint8_t *dst, ptrdiff_t stride, int flim)
290 290
 {
291 291
     int i;
292 292
 
... ...
@@ -295,7 +295,7 @@ static void vp8_v_loop_filter_simple_c(uint8_t *dst, int stride, int flim)
295 295
             filter_common(dst+i, stride, 1);
296 296
 }
297 297
 
298
-static void vp8_h_loop_filter_simple_c(uint8_t *dst, int stride, int flim)
298
+static void vp8_h_loop_filter_simple_c(uint8_t *dst, ptrdiff_t stride, int flim)
299 299
 {
300 300
     int i;
301 301
 
... ...
@@ -315,7 +315,7 @@ static const uint8_t subpel_filters[7][6] = {
315 315
 };
316 316
 
317 317
 #define PUT_PIXELS(WIDTH) \
318
-static void put_vp8_pixels ## WIDTH ##_c(uint8_t *dst, int dststride, uint8_t *src, int srcstride, int h, int x, int y) { \
318
+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) { \
319 319
     int i; \
320 320
     for (i = 0; i < h; i++, dst+= dststride, src+= srcstride) { \
321 321
         memcpy(dst, src, WIDTH); \
... ...
@@ -335,7 +335,7 @@ PUT_PIXELS(4)
335 335
         F[3]*src[x+1*stride] - F[4]*src[x+2*stride] + 64) >> 7]
336 336
 
337 337
 #define VP8_EPEL_H(SIZE, TAPS) \
338
-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) \
338
+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) \
339 339
 { \
340 340
     const uint8_t *filter = subpel_filters[mx-1]; \
341 341
     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
349 349
     } \
350 350
 }
351 351
 #define VP8_EPEL_V(SIZE, TAPS) \
352
-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) \
352
+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) \
353 353
 { \
354 354
     const uint8_t *filter = subpel_filters[my-1]; \
355 355
     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
363 363
     } \
364 364
 }
365 365
 #define VP8_EPEL_HV(SIZE, HTAPS, VTAPS) \
366
-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) \
366
+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) \
367 367
 { \
368 368
     const uint8_t *filter = subpel_filters[mx-1]; \
369 369
     uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; \
... ...
@@ -416,7 +416,7 @@ VP8_EPEL_HV(8,  6, 6)
416 416
 VP8_EPEL_HV(4,  6, 6)
417 417
 
418 418
 #define VP8_BILINEAR(SIZE) \
419
-static void put_vp8_bilinear ## SIZE ## _h_c(uint8_t *dst, int stride, uint8_t *src, int s2, int h, int mx, int my) \
419
+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) \
420 420
 { \
421 421
     int a = 8-mx, b = mx; \
422 422
     int x, y; \
... ...
@@ -428,7 +428,7 @@ static void put_vp8_bilinear ## SIZE ## _h_c(uint8_t *dst, int stride, uint8_t *
428 428
         src += stride; \
429 429
     } \
430 430
 } \
431
-static void put_vp8_bilinear ## SIZE ## _v_c(uint8_t *dst, int stride, uint8_t *src, int s2, int h, int mx, int my) \
431
+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) \
432 432
 { \
433 433
     int c = 8-my, d = my; \
434 434
     int x, y; \
... ...
@@ -441,7 +441,7 @@ static void put_vp8_bilinear ## SIZE ## _v_c(uint8_t *dst, int stride, uint8_t *
441 441
     } \
442 442
 } \
443 443
 \
444
-static void put_vp8_bilinear ## SIZE ## _hv_c(uint8_t *dst, int stride, uint8_t *src, int s2, int h, int mx, int my) \
444
+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) \
445 445
 { \
446 446
     int a = 8-mx, b = mx; \
447 447
     int c = 8-my, d = my; \
... ...
@@ -29,40 +29,44 @@
29 29
 
30 30
 #include "dsputil.h"
31 31
 
32
-typedef void (*vp8_mc_func)(uint8_t *dst/*align 8*/, int dstStride,
33
-                            uint8_t *src/*align 1*/, int srcStride,
32
+typedef void (*vp8_mc_func)(uint8_t *dst/*align 8*/, ptrdiff_t dstStride,
33
+                            uint8_t *src/*align 1*/, ptrdiff_t srcStride,
34 34
                             int h, int x, int y);
35 35
 
36 36
 typedef struct VP8DSPContext {
37 37
     void (*vp8_luma_dc_wht)(DCTELEM block[4][4][16], DCTELEM dc[16]);
38 38
     void (*vp8_luma_dc_wht_dc)(DCTELEM block[4][4][16], DCTELEM dc[16]);
39
-    void (*vp8_idct_add)(uint8_t *dst, DCTELEM block[16], int stride);
40
-    void (*vp8_idct_dc_add)(uint8_t *dst, DCTELEM block[16], int stride);
41
-    void (*vp8_idct_dc_add4y)(uint8_t *dst, DCTELEM block[4][16], int stride);
42
-    void (*vp8_idct_dc_add4uv)(uint8_t *dst, DCTELEM block[4][16], int stride);
39
+    void (*vp8_idct_add)(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride);
40
+    void (*vp8_idct_dc_add)(uint8_t *dst, DCTELEM block[16], ptrdiff_t stride);
41
+    void (*vp8_idct_dc_add4y)(uint8_t *dst, DCTELEM block[4][16],
42
+                              ptrdiff_t stride);
43
+    void (*vp8_idct_dc_add4uv)(uint8_t *dst, DCTELEM block[4][16],
44
+                               ptrdiff_t stride);
43 45
 
44 46
     // loop filter applied to edges between macroblocks
45
-    void (*vp8_v_loop_filter16y)(uint8_t *dst, int stride,
47
+    void (*vp8_v_loop_filter16y)(uint8_t *dst, ptrdiff_t stride,
46 48
                                  int flim_E, int flim_I, int hev_thresh);
47
-    void (*vp8_h_loop_filter16y)(uint8_t *dst, int stride,
49
+    void (*vp8_h_loop_filter16y)(uint8_t *dst, ptrdiff_t stride,
48 50
                                  int flim_E, int flim_I, int hev_thresh);
49
-    void (*vp8_v_loop_filter8uv)(uint8_t *dstU, uint8_t *dstV, int stride,
51
+    void (*vp8_v_loop_filter8uv)(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,
50 52
                                  int flim_E, int flim_I, int hev_thresh);
51
-    void (*vp8_h_loop_filter8uv)(uint8_t *dstU, uint8_t *dstV, int stride,
53
+    void (*vp8_h_loop_filter8uv)(uint8_t *dstU, uint8_t *dstV, ptrdiff_t stride,
52 54
                                  int flim_E, int flim_I, int hev_thresh);
53 55
 
54 56
     // loop filter applied to inner macroblock edges
55
-    void (*vp8_v_loop_filter16y_inner)(uint8_t *dst, int stride,
57
+    void (*vp8_v_loop_filter16y_inner)(uint8_t *dst, ptrdiff_t stride,
56 58
                                        int flim_E, int flim_I, int hev_thresh);
57
-    void (*vp8_h_loop_filter16y_inner)(uint8_t *dst, int stride,
59
+    void (*vp8_h_loop_filter16y_inner)(uint8_t *dst, ptrdiff_t stride,
58 60
                                        int flim_E, int flim_I, int hev_thresh);
59
-    void (*vp8_v_loop_filter8uv_inner)(uint8_t *dstU, uint8_t *dstV, int stride,
61
+    void (*vp8_v_loop_filter8uv_inner)(uint8_t *dstU, uint8_t *dstV,
62
+                                       ptrdiff_t stride,
60 63
                                        int flim_E, int flim_I, int hev_thresh);
61
-    void (*vp8_h_loop_filter8uv_inner)(uint8_t *dstU, uint8_t *dstV, int stride,
64
+    void (*vp8_h_loop_filter8uv_inner)(uint8_t *dstU, uint8_t *dstV,
65
+                                       ptrdiff_t stride,
62 66
                                        int flim_E, int flim_I, int hev_thresh);
63 67
 
64
-    void (*vp8_v_loop_filter_simple)(uint8_t *dst, int stride, int flim);
65
-    void (*vp8_h_loop_filter_simple)(uint8_t *dst, int stride, int flim);
68
+    void (*vp8_v_loop_filter_simple)(uint8_t *dst, ptrdiff_t stride, int flim);
69
+    void (*vp8_h_loop_filter_simple)(uint8_t *dst, ptrdiff_t stride, int flim);
66 70
 
67 71
     /**
68 72
      * first dimension: width>>3, height is assumed equal to width
... ...
@@ -76,9 +80,12 @@ typedef struct VP8DSPContext {
76 76
     vp8_mc_func put_vp8_bilinear_pixels_tab[3][3][3];
77 77
 } VP8DSPContext;
78 78
 
79
-void ff_put_vp8_pixels16_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y);
80
-void ff_put_vp8_pixels8_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y);
81
-void ff_put_vp8_pixels4_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y);
79
+void ff_put_vp8_pixels16_c(uint8_t *dst, uint8_t *src, ptrdiff_t stride,
80
+                           int h, int x, int y);
81
+void ff_put_vp8_pixels8_c(uint8_t *dst, uint8_t *src, ptrdiff_t stride,
82
+                          int h, int x, int y);
83
+void ff_put_vp8_pixels4_c(uint8_t *dst, uint8_t *src, ptrdiff_t stride,
84
+                          int h, int x, int y);
82 85
 
83 86
 void ff_vp8dsp_init(VP8DSPContext *c);
84 87
 void ff_vp8dsp_init_x86(VP8DSPContext *c);
... ...
@@ -124,7 +124,7 @@ typedef struct WMACodecContext {
124 124
     /* output buffer for one frame and the last for IMDCT windowing */
125 125
     DECLARE_ALIGNED(32, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
126 126
     /* last frame info */
127
-    uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
127
+    uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; /* padding added */
128 128
     int last_bitoffset;
129 129
     int last_superframe_len;
130 130
     float noise_table[NOISE_TAB_SIZE];
... ...
@@ -863,6 +863,12 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
863 863
 
864 864
     if (s->use_bit_reservoir) {
865 865
         bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3);
866
+        if (bit_offset > get_bits_left(&s->gb)) {
867
+            av_log(avctx, AV_LOG_ERROR,
868
+                   "Invalid last frame bit offset %d > buf size %d (%d)\n",
869
+                   bit_offset, get_bits_left(&s->gb), buf_size);
870
+            goto fail;
871
+        }
866 872
 
867 873
         if (s->last_superframe_len > 0) {
868 874
             //        printf("skip=%d\n", s->last_bitoffset);
... ...
@@ -879,9 +885,10 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
879 879
             if (len > 0) {
880 880
                 *q++ = (get_bits)(&s->gb, len) << (8 - len);
881 881
             }
882
+            memset(q, 0, FF_INPUT_BUFFER_PADDING_SIZE);
882 883
 
883 884
             /* XXX: bit_offset bits into last frame */
884
-            init_get_bits(&s->gb, s->last_superframe, MAX_CODED_SUPERFRAME_SIZE*8);
885
+            init_get_bits(&s->gb, s->last_superframe, s->last_superframe_len * 8 + bit_offset);
885 886
             /* skip unused bits */
886 887
             if (s->last_bitoffset > 0)
887 888
                 skip_bits(&s->gb, s->last_bitoffset);
... ...
@@ -895,9 +902,9 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
895 895
 
896 896
         /* read each frame starting from bit_offset */
897 897
         pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3;
898
-        if (pos >= MAX_CODED_SUPERFRAME_SIZE * 8)
898
+        if (pos >= MAX_CODED_SUPERFRAME_SIZE * 8 || pos > buf_size * 8)
899 899
             return AVERROR_INVALIDDATA;
900
-        init_get_bits(&s->gb, buf + (pos >> 3), (MAX_CODED_SUPERFRAME_SIZE - (pos >> 3))*8);
900
+        init_get_bits(&s->gb, buf + (pos >> 3), (buf_size - (pos >> 3))*8);
901 901
         len = pos & 7;
902 902
         if (len > 0)
903 903
             skip_bits(&s->gb, len);
... ...
@@ -1,8 +1,9 @@
1 1
 /*
2
- * Wmall compatible decoder
2
+ * Windows Media Audio Lossless decoder
3 3
  * Copyright (c) 2007 Baptiste Coudurier, Benjamin Larsson, Ulion
4 4
  * Copyright (c) 2008 - 2011 Sascha Sommer, Benjamin Larsson
5 5
  * Copyright (c) 2011 Andreas Öman
6
+ * Copyright (c) 2011 - 2012 Mashiat Sarker Shakkhar
6 7
  *
7 8
  * This file is part of FFmpeg.
8 9
  *
... ...
@@ -21,210 +22,94 @@
21 21
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 22
  */
23 23
 
24
-/**
25
- * @file
26
- * @brief wmall decoder implementation
27
- * Wmall is an MDCT based codec comparable to wma standard or AAC.
28
- * The decoding therefore consists of the following steps:
29
- * - bitstream decoding
30
- * - reconstruction of per-channel data
31
- * - rescaling and inverse quantization
32
- * - IMDCT
33
- * - windowing and overlapp-add
34
- *
35
- * The compressed wmall bitstream is split into individual packets.
36
- * Every such packet contains one or more wma frames.
37
- * The compressed frames may have a variable length and frames may
38
- * cross packet boundaries.
39
- * Common to all wmall frames is the number of samples that are stored in
40
- * a frame.
41
- * The number of samples and a few other decode flags are stored
42
- * as extradata that has to be passed to the decoder.
43
- *
44
- * The wmall frames themselves are again split into a variable number of
45
- * subframes. Every subframe contains the data for 2^N time domain samples
46
- * where N varies between 7 and 12.
47
- *
48
- * Example wmall bitstream (in samples):
49
- *
50
- * ||   packet 0           || packet 1 || packet 2      packets
51
- * ---------------------------------------------------
52
- * || frame 0      || frame 1       || frame 2    ||    frames
53
- * ---------------------------------------------------
54
- * ||   |      |   ||   |   |   |   ||            ||    subframes of channel 0
55
- * ---------------------------------------------------
56
- * ||      |   |   ||   |   |   |   ||            ||    subframes of channel 1
57
- * ---------------------------------------------------
58
- *
59
- * The frame layouts for the individual channels of a wma frame does not need
60
- * to be the same.
61
- *
62
- * However, if the offsets and lengths of several subframes of a frame are the
63
- * same, the subframes of the channels can be grouped.
64
- * Every group may then use special coding techniques like M/S stereo coding
65
- * to improve the compression ratio. These channel transformations do not
66
- * need to be applied to a whole subframe. Instead, they can also work on
67
- * individual scale factor bands (see below).
68
- * The coefficients that carry the audio signal in the frequency domain
69
- * are transmitted as huffman-coded vectors with 4, 2 and 1 elements.
70
- * In addition to that, the encoder can switch to a runlevel coding scheme
71
- * by transmitting subframe_length / 128 zero coefficients.
72
- *
73
- * Before the audio signal can be converted to the time domain, the
74
- * coefficients have to be rescaled and inverse quantized.
75
- * A subframe is therefore split into several scale factor bands that get
76
- * scaled individually.
77
- * Scale factors are submitted for every frame but they might be shared
78
- * between the subframes of a channel. Scale factors are initially DPCM-coded.
79
- * Once scale factors are shared, the differences are transmitted as runlevel
80
- * codes.
81
- * Every subframe length and offset combination in the frame layout shares a
82
- * common quantization factor that can be adjusted for every channel by a
83
- * modifier.
84
- * After the inverse quantization, the coefficients get processed by an IMDCT.
85
- * The resulting values are then windowed with a sine window and the first half
86
- * of the values are added to the second half of the output from the previous
87
- * subframe in order to reconstruct the output samples.
88
- */
89
-
90 24
 #include "avcodec.h"
91 25
 #include "internal.h"
92 26
 #include "get_bits.h"
93 27
 #include "put_bits.h"
94
-#include "dsputil.h"
95 28
 #include "wma.h"
96 29
 
97 30
 /** current decoder limitations */
98
-#define WMALL_MAX_CHANNELS    8                             ///< max number of handled channels
99
-#define MAX_SUBFRAMES  32                                    ///< max number of subframes per channel
100
-#define MAX_BANDS      29                                    ///< max number of scale factor bands
101
-#define MAX_FRAMESIZE  32768                                 ///< maximum compressed frame size
102
-
103
-#define WMALL_BLOCK_MIN_BITS  6                                           ///< log2 of min block size
104
-#define WMALL_BLOCK_MAX_BITS 12                                           ///< log2 of max block size
105
-#define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS)                 ///< maximum block size
31
+#define WMALL_MAX_CHANNELS      8                       ///< max number of handled channels
32
+#define MAX_SUBFRAMES          32                       ///< max number of subframes per channel
33
+#define MAX_BANDS              29                       ///< max number of scale factor bands
34
+#define MAX_FRAMESIZE       32768                       ///< maximum compressed frame size
35
+
36
+#define WMALL_BLOCK_MIN_BITS    6                       ///< log2 of min block size
37
+#define WMALL_BLOCK_MAX_BITS   12                       ///< log2 of max block size
38
+#define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS)    ///< maximum block size
106 39
 #define WMALL_BLOCK_SIZES    (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1) ///< possible block sizes
107 40
 
108 41
 
109
-#define VLCBITS            9
110
-#define SCALEVLCBITS       8
111
-#define VEC4MAXDEPTH    ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS)
112
-#define VEC2MAXDEPTH    ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS)
113
-#define VEC1MAXDEPTH    ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS)
114
-#define SCALEMAXDEPTH   ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)
115
-#define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)
116
-
117
-static float            sin64[33];        ///< sinus table for decorrelation
118
-
119 42
 /**
120
- * @brief frame specific decoder context for a single channel
43
+ * @brief frame-specific decoder context for a single channel
121 44
  */
122 45
 typedef struct {
123
-    int16_t  prev_block_len;                          ///< length of the previous block
124
-    uint8_t  transmit_coefs;
125
-    uint8_t  num_subframes;
126
-    uint16_t subframe_len[MAX_SUBFRAMES];             ///< subframe length in samples
127
-    uint16_t subframe_offset[MAX_SUBFRAMES];          ///< subframe positions in the current frame
128
-    uint8_t  cur_subframe;                            ///< current subframe number
129
-    uint16_t decoded_samples;                         ///< number of already processed samples
130
-    uint8_t  grouped;                                 ///< channel is part of a group
131
-    int      quant_step;                              ///< quantization step for the current subframe
132
-    int8_t   reuse_sf;                                ///< share scale factors between subframes
133
-    int8_t   scale_factor_step;                       ///< scaling step for the current subframe
134
-    int      max_scale_factor;                        ///< maximum scale factor for the current subframe
135
-    int      saved_scale_factors[2][MAX_BANDS];       ///< resampled and (previously) transmitted scale factor values
136
-    int8_t   scale_factor_idx;                        ///< index for the transmitted scale factor values (used for resampling)
137
-    int*     scale_factors;                           ///< pointer to the scale factor values used for decoding
138
-    uint8_t  table_idx;                               ///< index in sf_offsets for the scale factor reference block
139
-    float*   coeffs;                                  ///< pointer to the subframe decode buffer
140
-    uint16_t num_vec_coeffs;                          ///< number of vector coded coefficients
141
-    DECLARE_ALIGNED(16, float, out)[WMALL_BLOCK_MAX_SIZE + WMALL_BLOCK_MAX_SIZE / 2]; ///< output buffer
142
-    int      transient_counter;                       ///< number of transient samples from the beginning of transient zone
46
+    int16_t     prev_block_len;                         ///< length of the previous block
47
+    uint8_t     transmit_coefs;
48
+    uint8_t     num_subframes;
49
+    uint16_t    subframe_len[MAX_SUBFRAMES];            ///< subframe length in samples
50
+    uint16_t    subframe_offsets[MAX_SUBFRAMES];        ///< subframe positions in the current frame
51
+    uint8_t     cur_subframe;                           ///< current subframe number
52
+    uint16_t    decoded_samples;                        ///< number of already processed samples
53
+    int         quant_step;                             ///< quantization step for the current subframe
54
+    int         transient_counter;                      ///< number of transient samples from the beginning of the transient zone
143 55
 } WmallChannelCtx;
144 56
 
145 57
 /**
146
- * @brief channel group for channel transformations
147
- */
148
-typedef struct {
149
-    uint8_t num_channels;                                     ///< number of channels in the group
150
-    int8_t  transform;                                        ///< transform on / off
151
-    int8_t  transform_band[MAX_BANDS];                        ///< controls if the transform is enabled for a certain band
152
-    float   decorrelation_matrix[WMALL_MAX_CHANNELS*WMALL_MAX_CHANNELS];
153
-    float*  channel_data[WMALL_MAX_CHANNELS];                ///< transformation coefficients
154
-} WmallChannelGrp;
155
-
156
-/**
157 58
  * @brief main decoder context
158 59
  */
159 60
 typedef struct WmallDecodeCtx {
160 61
     /* generic decoder variables */
161
-    AVCodecContext*  avctx;                         ///< codec context for av_log
162
-    DSPContext       dsp;                           ///< accelerated DSP functions
163
-    AVFrame          frame;
164
-    uint8_t          frame_data[MAX_FRAMESIZE +
165
-                      FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data
166
-    PutBitContext    pb;                            ///< context for filling the frame_data buffer
167
-    FFTContext       mdct_ctx[WMALL_BLOCK_SIZES];  ///< MDCT context per block size
168
-    DECLARE_ALIGNED(16, float, tmp)[WMALL_BLOCK_MAX_SIZE]; ///< IMDCT output buffer
169
-    float*           windows[WMALL_BLOCK_SIZES];   ///< windows for the different block sizes
62
+    AVCodecContext  *avctx;
63
+    AVFrame         frame;
64
+    uint8_t         frame_data[MAX_FRAMESIZE + FF_INPUT_BUFFER_PADDING_SIZE];  ///< compressed frame data
65
+    PutBitContext   pb;                             ///< context for filling the frame_data buffer
170 66
 
171 67
     /* frame size dependent frame information (set during initialization) */
172
-    uint32_t         decode_flags;                  ///< used compression features
173
-    uint8_t          len_prefix;                    ///< frame is prefixed with its length
174
-    uint8_t          dynamic_range_compression;     ///< frame contains DRC data
175
-    uint8_t          bits_per_sample;               ///< integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0])
176
-    uint16_t         samples_per_frame;             ///< number of samples to output
177
-    uint16_t         log2_frame_size;
178
-    int8_t           num_channels;                  ///< number of channels in the stream (same as AVCodecContext.num_channels)
179
-    int8_t           lfe_channel;                   ///< lfe channel index
180
-    uint8_t          max_num_subframes;
181
-    uint8_t          subframe_len_bits;             ///< number of bits used for the subframe length
182
-    uint8_t          max_subframe_len_bit;          ///< flag indicating that the subframe is of maximum size when the first subframe length bit is 1
183
-    uint16_t         min_samples_per_subframe;
184
-    int8_t           num_sfb[WMALL_BLOCK_SIZES];   ///< scale factor bands per block size
185
-    int16_t          sfb_offsets[WMALL_BLOCK_SIZES][MAX_BANDS];                    ///< scale factor band offsets (multiples of 4)
186
-    int8_t           sf_offsets[WMALL_BLOCK_SIZES][WMALL_BLOCK_SIZES][MAX_BANDS]; ///< scale factor resample matrix
187
-    int16_t          subwoofer_cutoffs[WMALL_BLOCK_SIZES]; ///< subwoofer cutoff values
68
+    uint32_t        decode_flags;                   ///< used compression features
69
+    int             len_prefix;                     ///< frame is prefixed with its length
70
+    int             dynamic_range_compression;      ///< frame contains DRC data
71
+    uint8_t         bits_per_sample;                ///< integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0])
72
+    uint16_t        samples_per_frame;              ///< number of samples to output
73
+    uint16_t        log2_frame_size;
74
+    int8_t          num_channels;                   ///< number of channels in the stream (same as AVCodecContext.num_channels)
75
+    int8_t          lfe_channel;                    ///< lfe channel index
76
+    uint8_t         max_num_subframes;
77
+    uint8_t         subframe_len_bits;              ///< number of bits used for the subframe length
78
+    uint8_t         max_subframe_len_bit;           ///< flag indicating that the subframe is of maximum size when the first subframe length bit is 1
79
+    uint16_t        min_samples_per_subframe;
188 80
 
189 81
     /* packet decode state */
190
-    GetBitContext    pgb;                           ///< bitstream reader context for the packet
191
-    int              next_packet_start;             ///< start offset of the next wma packet in the demuxer packet
192
-    uint8_t          packet_offset;                 ///< frame offset in the packet
193
-    uint8_t          packet_sequence_number;        ///< current packet number
194
-    int              num_saved_bits;                ///< saved number of bits
195
-    int              frame_offset;                  ///< frame offset in the bit reservoir
196
-    int              subframe_offset;               ///< subframe offset in the bit reservoir
197
-    uint8_t          packet_loss;                   ///< set in case of bitstream error
198
-    uint8_t          packet_done;                   ///< set when a packet is fully decoded
82
+    GetBitContext   pgb;                            ///< bitstream reader context for the packet
83
+    int             next_packet_start;              ///< start offset of the next WMA packet in the demuxer packet
84
+    uint8_t         packet_offset;                  ///< offset to the frame in the packet
85
+    uint8_t         packet_sequence_number;         ///< current packet number
86
+    int             num_saved_bits;                 ///< saved number of bits
87
+    int             frame_offset;                   ///< frame offset in the bit reservoir
88
+    int             subframe_offset;                ///< subframe offset in the bit reservoir
89
+    uint8_t         packet_loss;                    ///< set in case of bitstream error
90
+    uint8_t         packet_done;                    ///< set when a packet is fully decoded
199 91
 
200 92
     /* frame decode state */
201
-    uint32_t         frame_num;                     ///< current frame number (not used for decoding)
202
-    GetBitContext    gb;                            ///< bitstream reader context
203
-    int              buf_bit_size;                  ///< buffer size in bits
204
-    int16_t*         samples_16;                    ///< current samplebuffer pointer (16-bit)
205
-    int16_t*         samples_16_end;                ///< maximum samplebuffer pointer
93
+    uint32_t        frame_num;                      ///< current frame number (not used for decoding)
94
+    GetBitContext   gb;                             ///< bitstream reader context
95
+    int             buf_bit_size;                   ///< buffer size in bits
96
+    int16_t         *samples_16;                    ///< current samplebuffer pointer (16-bit)
97
+    int16_t         *samples_16_end;                ///< maximum samplebuffer pointer
206 98
     int             *samples_32;                    ///< current samplebuffer pointer (24-bit)
207 99
     int             *samples_32_end;                ///< maximum samplebuffer pointer
208
-    uint8_t          drc_gain;                      ///< gain for the DRC tool
209
-    int8_t           skip_frame;                    ///< skip output step
210
-    int8_t           parsed_all_subframes;          ///< all subframes decoded?
100
+    uint8_t         drc_gain;                       ///< gain for the DRC tool
101
+    int8_t          skip_frame;                     ///< skip output step
102
+    int8_t          parsed_all_subframes;           ///< all subframes decoded?
211 103
 
212 104
     /* subframe/block decode state */
213
-    int16_t          subframe_len;                  ///< current subframe length
214
-    int8_t           channels_for_cur_subframe;     ///< number of channels that contain the subframe
215
-    int8_t           channel_indexes_for_cur_subframe[WMALL_MAX_CHANNELS];
216
-    int8_t           num_bands;                     ///< number of scale factor bands
217
-    int8_t           transmit_num_vec_coeffs;       ///< number of vector coded coefficients is part of the bitstream
218
-    int16_t*         cur_sfb_offsets;               ///< sfb offsets for the current block
219
-    uint8_t          table_idx;                     ///< index for the num_sfb, sfb_offsets, sf_offsets and subwoofer_cutoffs tables
220
-    int8_t           esc_len;                       ///< length of escaped coefficients
221
-
222
-    uint8_t          num_chgroups;                  ///< number of channel groups
223
-    WmallChannelGrp chgroup[WMALL_MAX_CHANNELS];    ///< channel group information
105
+    int16_t         subframe_len;                   ///< current subframe length
106
+    int8_t          channels_for_cur_subframe;      ///< number of channels that contain the subframe
107
+    int8_t          channel_indexes_for_cur_subframe[WMALL_MAX_CHANNELS];
224 108
 
225 109
     WmallChannelCtx channel[WMALL_MAX_CHANNELS];    ///< per channel data
226 110
 
227
-    // WMA lossless
111
+    // WMA Lossless-specific
228 112
 
229 113
     uint8_t do_arith_coding;
230 114
     uint8_t do_ac_filter;
... ...
@@ -232,41 +117,38 @@ typedef struct WmallDecodeCtx {
232 232
     uint8_t do_mclms;
233 233
     uint8_t do_lpc;
234 234
 
235
-    int8_t acfilter_order;
236
-    int8_t acfilter_scaling;
235
+    int8_t  acfilter_order;
236
+    int8_t  acfilter_scaling;
237 237
     int64_t acfilter_coeffs[16];
238
-    int acfilter_prevvalues[2][16];
238
+    int     acfilter_prevvalues[2][16];
239 239
 
240
-    int8_t mclms_order;
241
-    int8_t mclms_scaling;
240
+    int8_t  mclms_order;
241
+    int8_t  mclms_scaling;
242 242
     int16_t mclms_coeffs[128];
243 243
     int16_t mclms_coeffs_cur[4];
244
-    int mclms_prevvalues[64];   // FIXME: should be 32-bit / 16-bit depending on bit-depth
244
+    int16_t mclms_prevvalues[64];
245 245
     int16_t mclms_updates[64];
246
-    int mclms_recent;
246
+    int     mclms_recent;
247 247
 
248
-    int movave_scaling;
249
-    int quant_stepsize;
248
+    int     movave_scaling;
249
+    int     quant_stepsize;
250 250
 
251 251
     struct {
252
-    int order;
253
-    int scaling;
254
-    int coefsend;
255
-    int bitsend;
256
-    int16_t coefs[256];
257
-    int lms_prevvalues[512];    // FIXME: see above
258
-    int16_t lms_updates[512];   // and here too
259
-    int recent;
260
-    } cdlms[2][9];              /* XXX: Here, 2 is the max. no. of channels allowed,
261
-                                        9 is the maximum no. of filters per channel.
262
-                                        Question is, why 2 if WMALL_MAX_CHANNELS == 8 */
263
-
252
+        int order;
253
+        int scaling;
254
+        int coefsend;
255
+        int bitsend;
256
+        int16_t coefs[256];
257
+        int16_t lms_prevvalues[512];
258
+        int16_t lms_updates[512];
259
+        int recent;
260
+    } cdlms[2][9];
264 261
 
265 262
     int cdlms_ttl[2];
266 263
 
267 264
     int bV3RTM;
268 265
 
269
-    int is_channel_coded[2];    // XXX: same question as above applies here too (and below)
266
+    int is_channel_coded[2];
270 267
     int update_speed[2];
271 268
 
272 269
     int transient[2];
... ...
@@ -277,139 +159,76 @@ typedef struct WmallDecodeCtx {
277 277
 
278 278
     int channel_residues[2][2048];
279 279
 
280
-
281 280
     int lpc_coefs[2][40];
282 281
     int lpc_order;
283 282
     int lpc_scaling;
284 283
     int lpc_intbits;
285 284
 
286
-    int channel_coeffs[2][2048]; // FIXME: should be 32-bit / 16-bit depending on bit-depth
287
-
285
+    int channel_coeffs[2][2048];
288 286
 } WmallDecodeCtx;
289 287
 
290 288
 
291
-#undef dprintf
292
-#define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
293
-
294
-
295
-static int num_logged_tiles = 0;
296
-static int num_logged_subframes = 0;
297
-static int num_lms_update_call = 0;
298
-
299
-/**
300
- *@brief helper function to print the most important members of the context
301
- *@param s context
302
- */
303
-static void av_cold dump_context(WmallDecodeCtx *s)
304
-{
305
-#define PRINT(a, b)     av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b);
306
-#define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %x\n", a, b);
307
-
308
-    PRINT("ed sample bit depth", s->bits_per_sample);
309
-    PRINT_HEX("ed decode flags", s->decode_flags);
310
-    PRINT("samples per frame",   s->samples_per_frame);
311
-    PRINT("log2 frame size",     s->log2_frame_size);
312
-    PRINT("max num subframes",   s->max_num_subframes);
313
-    PRINT("len prefix",          s->len_prefix);
314
-    PRINT("num channels",        s->num_channels);
315
-}
316
-
317
-static void dump_int_buffer(uint8_t *buffer, int size, int length, int delimiter)
318
-{
319
-    int i;
320
-
321
-    for (i=0 ; i<length ; i++) {
322
-        if (!(i%delimiter))
323
-            av_log(0, 0, "\n[%d] ", i);
324
-        av_log(0, 0, "%d, ", *(int16_t *)(buffer + i * size));
325
-    }
326
-    av_log(0, 0, "\n");
327
-}
328
-
329
-/**
330
- *@brief Uninitialize the decoder and free all resources.
331
- *@param avctx codec context
332
- *@return 0 on success, < 0 otherwise
333
- */
334
-static av_cold int decode_end(AVCodecContext *avctx)
335
-{
336
-    WmallDecodeCtx *s = avctx->priv_data;
337
-    int i;
338
-
339
-    for (i = 0; i < WMALL_BLOCK_SIZES; i++)
340
-        ff_mdct_end(&s->mdct_ctx[i]);
341
-
342
-    return 0;
343
-}
344
-
345
-/**
346
- *@brief Initialize the decoder.
347
- *@param avctx codec context
348
- *@return 0 on success, -1 otherwise
349
- */
350 289
 static av_cold int decode_init(AVCodecContext *avctx)
351 290
 {
352
-    WmallDecodeCtx *s = avctx->priv_data;
291
+    WmallDecodeCtx *s  = avctx->priv_data;
353 292
     uint8_t *edata_ptr = avctx->extradata;
354 293
     unsigned int channel_mask;
355
-    int i;
356
-    int log2_max_num_subframes;
357
-    int num_possible_block_sizes;
294
+    int i, log2_max_num_subframes, num_possible_block_sizes;
358 295
 
359 296
     s->avctx = avctx;
360
-    dsputil_init(&s->dsp, avctx);
361 297
     init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
362 298
 
363 299
     if (avctx->extradata_size >= 18) {
364
-        s->decode_flags    = AV_RL16(edata_ptr+14);
365
-        channel_mask       = AV_RL32(edata_ptr+2);
300
+        s->decode_flags    = AV_RL16(edata_ptr + 14);
301
+        channel_mask       = AV_RL32(edata_ptr +  2);
366 302
         s->bits_per_sample = AV_RL16(edata_ptr);
367 303
         if (s->bits_per_sample == 16)
368 304
             avctx->sample_fmt = AV_SAMPLE_FMT_S16;
369
-        else if (s->bits_per_sample == 24)
305
+        else if (s->bits_per_sample == 24) {
370 306
             avctx->sample_fmt = AV_SAMPLE_FMT_S32;
371
-        else {
307
+            av_log_missing_feature(avctx, "bit-depth higher than 16", 0);
308
+            return AVERROR_PATCHWELCOME;
309
+        } else {
372 310
             av_log(avctx, AV_LOG_ERROR, "Unknown bit-depth: %d\n",
373 311
                    s->bits_per_sample);
374 312
             return AVERROR_INVALIDDATA;
375 313
         }
376
-        /** dump the extradata */
314
+        /* dump the extradata */
377 315
         for (i = 0; i < avctx->extradata_size; i++)
378
-            dprintf(avctx, "[%x] ", avctx->extradata[i]);
379
-        dprintf(avctx, "\n");
316
+            av_dlog(avctx, AV_LOG_DEBUG, "[%x] ", avctx->extradata[i]);
317
+        av_dlog(avctx, AV_LOG_DEBUG, "\n");
380 318
 
381 319
     } else {
382
-        av_log_ask_for_sample(avctx, "Unknown extradata size\n");
320
+        av_log_ask_for_sample(avctx, "Unsupported extradata size\n");
383 321
         return AVERROR_INVALIDDATA;
384 322
     }
385 323
 
386
-    /** generic init */
324
+    /* generic init */
387 325
     s->log2_frame_size = av_log2(avctx->block_align) + 4;
388 326
 
389
-    /** frame info */
327
+    /* frame info */
390 328
     s->skip_frame  = 1; /* skip first frame */
391 329
     s->packet_loss = 1;
392
-    s->len_prefix  = (s->decode_flags & 0x40);
330
+    s->len_prefix  = s->decode_flags & 0x40;
393 331
 
394
-    /** get frame len */
332
+    /* get frame len */
395 333
     s->samples_per_frame = 1 << ff_wma_get_frame_len_bits(avctx->sample_rate,
396 334
                                                           3, s->decode_flags);
397 335
 
398
-    /** init previous block len */
336
+    /* init previous block len */
399 337
     for (i = 0; i < avctx->channels; i++)
400 338
         s->channel[i].prev_block_len = s->samples_per_frame;
401 339
 
402
-    /** subframe info */
403
-    log2_max_num_subframes  = ((s->decode_flags & 0x38) >> 3);
340
+    /* subframe info */
341
+    log2_max_num_subframes  = (s->decode_flags & 0x38) >> 3;
404 342
     s->max_num_subframes    = 1 << log2_max_num_subframes;
405 343
     s->max_subframe_len_bit = 0;
406 344
     s->subframe_len_bits    = av_log2(log2_max_num_subframes) + 1;
407 345
 
408 346
     num_possible_block_sizes     = log2_max_num_subframes + 1;
409 347
     s->min_samples_per_subframe  = s->samples_per_frame / s->max_num_subframes;
410
-    s->dynamic_range_compression = (s->decode_flags & 0x80);
411
-
412
-    s->bV3RTM = s->decode_flags & 0x100;
348
+    s->dynamic_range_compression = s->decode_flags & 0x80;
349
+    s->bV3RTM                    = s->decode_flags & 0x100;
413 350
 
414 351
     if (s->max_num_subframes > MAX_SUBFRAMES) {
415 352
         av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %i\n",
... ...
@@ -419,19 +238,19 @@ static av_cold int decode_init(AVCodecContext *avctx)
419 419
 
420 420
     s->num_channels = avctx->channels;
421 421
 
422
-    /** extract lfe channel position */
422
+    /* extract lfe channel position */
423 423
     s->lfe_channel = -1;
424 424
 
425 425
     if (channel_mask & 8) {
426 426
         unsigned int mask;
427
-        for (mask = 1; mask < 16; mask <<= 1) {
427
+        for (mask = 1; mask < 16; mask <<= 1)
428 428
             if (channel_mask & mask)
429 429
                 ++s->lfe_channel;
430
-        }
431 430
     }
432 431
 
433 432
     if (s->num_channels < 0) {
434
-        av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->num_channels);
433
+        av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n",
434
+               s->num_channels);
435 435
         return AVERROR_INVALIDDATA;
436 436
     } else if (s->num_channels > WMALL_MAX_CHANNELS) {
437 437
         av_log_ask_for_sample(avctx, "unsupported number of channels\n");
... ...
@@ -439,33 +258,30 @@ static av_cold int decode_init(AVCodecContext *avctx)
439 439
     }
440 440
 
441 441
     avcodec_get_frame_defaults(&s->frame);
442
-    avctx->coded_frame = &s->frame;
443
-
442
+    avctx->coded_frame    = &s->frame;
444 443
     avctx->channel_layout = channel_mask;
445 444
     return 0;
446 445
 }
447 446
 
448 447
 /**
449
- *@brief Decode the subframe length.
450
- *@param s context
451
- *@param offset sample offset in the frame
452
- *@return decoded subframe length on success, < 0 in case of an error
448
+ * @brief Decode the subframe length.
449
+ * @param s      context
450
+ * @param offset sample offset in the frame
451
+ * @return decoded subframe length on success, < 0 in case of an error
453 452
  */
454 453
 static int decode_subframe_length(WmallDecodeCtx *s, int offset)
455 454
 {
456
-    int frame_len_ratio;
457
-    int subframe_len, len;
455
+    int frame_len_ratio, subframe_len, len;
458 456
 
459
-    /** no need to read from the bitstream when only one length is possible */
457
+    /* no need to read from the bitstream when only one length is possible */
460 458
     if (offset == s->samples_per_frame - s->min_samples_per_subframe)
461 459
         return s->min_samples_per_subframe;
462 460
 
463
-    len = av_log2(s->max_num_subframes - 1) + 1;
461
+    len             = av_log2(s->max_num_subframes - 1) + 1;
464 462
     frame_len_ratio = get_bits(&s->gb, len);
463
+    subframe_len    = s->min_samples_per_subframe * (frame_len_ratio + 1);
465 464
 
466
-    subframe_len = s->min_samples_per_subframe * (frame_len_ratio + 1);
467
-
468
-    /** sanity check the length */
465
+    /* sanity check the length */
469 466
     if (subframe_len < s->min_samples_per_subframe ||
470 467
         subframe_len > s->samples_per_frame) {
471 468
         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)
476 476
 }
477 477
 
478 478
 /**
479
- *@brief Decode how the data in the frame is split into subframes.
479
+ * @brief Decode how the data in the frame is split into subframes.
480 480
  *       Every WMA frame contains the encoded data for a fixed number of
481 481
  *       samples per channel. The data for every channel might be split
482 482
  *       into several subframes. This function will reconstruct the list of
... ...
@@ -492,38 +308,31 @@ static int decode_subframe_length(WmallDecodeCtx *s, int offset)
492 492
  *       The algorithm repeats these steps until the frame is properly divided
493 493
  *       between the individual channels.
494 494
  *
495
- *@param s context
496
- *@return 0 on success, < 0 in case of an error
495
+ * @param s context
496
+ * @return 0 on success, < 0 in case of an error
497 497
  */
498 498
 static int decode_tilehdr(WmallDecodeCtx *s)
499 499
 {
500
-    uint16_t num_samples[WMALL_MAX_CHANNELS];        /**< sum of samples for all currently known subframes of a channel */
501
-    uint8_t  contains_subframe[WMALL_MAX_CHANNELS];  /**< flag indicating if a channel contains the current subframe */
502
-    int channels_for_cur_subframe = s->num_channels;  /**< number of channels that contain the current subframe */
503
-    int fixed_channel_layout = 0;                     /**< flag indicating that all channels use the same subfra2me offsets and sizes */
504
-    int min_channel_len = 0;                          /**< smallest sum of samples (channels with this length will be processed first) */
505
-    int c;
506
-
507
-    /* Should never consume more than 3073 bits (256 iterations for the
508
-     * while loop when always the minimum amount of 128 samples is substracted
509
-     * from missing samples in the 8 channel case).
510
-     * 1 + BLOCK_MAX_SIZE * MAX_CHANNELS / BLOCK_MIN_SIZE * (MAX_CHANNELS  + 4)
511
-     */
512
-
513
-    /** reset tiling information */
500
+    uint16_t num_samples[WMALL_MAX_CHANNELS] = { 0 }; /* sum of samples for all currently known subframes of a channel */
501
+    uint8_t  contains_subframe[WMALL_MAX_CHANNELS];   /* flag indicating if a channel contains the current subframe */
502
+    int channels_for_cur_subframe = s->num_channels;  /* number of channels that contain the current subframe */
503
+    int fixed_channel_layout = 0;                     /* flag indicating that all channels use the same subfra2me offsets and sizes */
504
+    int min_channel_len = 0;                          /* smallest sum of samples (channels with this length will be processed first) */
505
+    int c, tile_aligned;
506
+
507
+    /* reset tiling information */
514 508
     for (c = 0; c < s->num_channels; c++)
515 509
         s->channel[c].num_subframes = 0;
516 510
 
517
-    memset(num_samples, 0, sizeof(num_samples));
518
-
519
-    if (s->max_num_subframes == 1 || get_bits1(&s->gb))
511
+    tile_aligned = get_bits1(&s->gb);
512
+    if (s->max_num_subframes == 1 || tile_aligned)
520 513
         fixed_channel_layout = 1;
521 514
 
522
-    /** loop until the frame data is split between the subframes */
515
+    /* loop until the frame data is split between the subframes */
523 516
     do {
524 517
         int subframe_len;
525 518
 
526
-        /** check which channels contain the subframe */
519
+        /* check which channels contain the subframe */
527 520
         for (c = 0; c < s->num_channels; c++) {
528 521
             if (num_samples[c] == min_channel_len) {
529 522
                 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
... ...
@@ -536,13 +345,13 @@ static int decode_tilehdr(WmallDecodeCtx *s)
536 536
                 contains_subframe[c] = 0;
537 537
         }
538 538
 
539
-        /** get subframe length, subframe_len == 0 is not allowed */
539
+        /* get subframe length, subframe_len == 0 is not allowed */
540 540
         if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0)
541 541
             return AVERROR_INVALIDDATA;
542
-        /** add subframes to the individual channels and find new min_channel_len */
542
+        /* add subframes to the individual channels and find new min_channel_len */
543 543
         min_channel_len += subframe_len;
544 544
         for (c = 0; c < s->num_channels; c++) {
545
-            WmallChannelCtx* chan = &s->channel[c];
545
+            WmallChannelCtx *chan = &s->channel[c];
546 546
 
547 547
             if (contains_subframe[c]) {
548 548
                 if (chan->num_subframes >= MAX_SUBFRAMES) {
... ...
@@ -570,10 +379,9 @@ static int decode_tilehdr(WmallDecodeCtx *s)
570 570
     } while (min_channel_len < s->samples_per_frame);
571 571
 
572 572
     for (c = 0; c < s->num_channels; c++) {
573
-        int i;
574
-        int offset = 0;
573
+        int i, offset = 0;
575 574
         for (i = 0; i < s->channel[c].num_subframes; i++) {
576
-            s->channel[c].subframe_offset[i] = offset;
575
+            s->channel[c].subframe_offsets[i] = offset;
577 576
             offset += s->channel[c].subframe_len[i];
578 577
         }
579 578
     }
... ...
@@ -581,215 +389,175 @@ static int decode_tilehdr(WmallDecodeCtx *s)
581 581
     return 0;
582 582
 }
583 583
 
584
-
585
-static int my_log2(unsigned int i)
586
-{
587
-    unsigned int iLog2 = 0;
588
-    while ((i >> iLog2) > 1)
589
-        iLog2++;
590
-    return iLog2;
591
-}
592
-
593
-
594
-/**
595
- *
596
- */
597 584
 static void decode_ac_filter(WmallDecodeCtx *s)
598 585
 {
599 586
     int i;
600
-    s->acfilter_order = get_bits(&s->gb, 4) + 1;
587
+    s->acfilter_order   = get_bits(&s->gb, 4) + 1;
601 588
     s->acfilter_scaling = get_bits(&s->gb, 4);
602 589
 
603
-    for(i = 0; i < s->acfilter_order; i++) {
590
+    for (i = 0; i < s->acfilter_order; i++)
604 591
         s->acfilter_coeffs[i] = get_bits(&s->gb, s->acfilter_scaling) + 1;
605
-    }
606 592
 }
607 593
 
608
-
609
-/**
610
- *
611
- */
612 594
 static void decode_mclms(WmallDecodeCtx *s)
613 595
 {
614
-    s->mclms_order = (get_bits(&s->gb, 4) + 1) * 2;
596
+    s->mclms_order   = (get_bits(&s->gb, 4) + 1) * 2;
615 597
     s->mclms_scaling = get_bits(&s->gb, 4);
616
-    if(get_bits1(&s->gb)) {
617
-        // mclms_send_coef
618
-        int i;
619
-        int send_coef_bits;
598
+    if (get_bits1(&s->gb)) {
599
+        int i, send_coef_bits;
620 600
         int cbits = av_log2(s->mclms_scaling + 1);
621 601
         assert(cbits == my_log2(s->mclms_scaling + 1));
622
-        if(1 << cbits < s->mclms_scaling + 1)
602
+        if (1 << cbits < s->mclms_scaling + 1)
623 603
             cbits++;
624 604
 
625 605
         send_coef_bits = (cbits ? get_bits(&s->gb, cbits) : 0) + 2;
626 606
 
627
-        for(i = 0; i < s->mclms_order * s->num_channels * s->num_channels; i++) {
607
+        for (i = 0; i < s->mclms_order * s->num_channels * s->num_channels; i++)
628 608
             s->mclms_coeffs[i] = get_bits(&s->gb, send_coef_bits);
629
-        }
630 609
 
631
-        for(i = 0; i < s->num_channels; i++) {
610
+        for (i = 0; i < s->num_channels; i++) {
632 611
             int c;
633
-            for(c = 0; c < i; c++) {
612
+            for (c = 0; c < i; c++)
634 613
                 s->mclms_coeffs_cur[i * s->num_channels + c] = get_bits(&s->gb, send_coef_bits);
635
-            }
636 614
         }
637 615
     }
638 616
 }
639 617
 
640
-
641
-/**
642
- *
643
- */
644 618
 static void decode_cdlms(WmallDecodeCtx *s)
645 619
 {
646 620
     int c, i;
647 621
     int cdlms_send_coef = get_bits1(&s->gb);
648 622
 
649
-    for(c = 0; c < s->num_channels; c++) {
623
+    for (c = 0; c < s->num_channels; c++) {
650 624
         s->cdlms_ttl[c] = get_bits(&s->gb, 3) + 1;
651
-        for(i = 0; i < s->cdlms_ttl[c]; i++) {
625
+        for (i = 0; i < s->cdlms_ttl[c]; i++)
652 626
             s->cdlms[c][i].order = (get_bits(&s->gb, 7) + 1) * 8;
653
-        }
654 627
 
655
-        for(i = 0; i < s->cdlms_ttl[c]; i++) {
628
+        for (i = 0; i < s->cdlms_ttl[c]; i++)
656 629
             s->cdlms[c][i].scaling = get_bits(&s->gb, 4);
657
-        }
658 630
 
659
-        if(cdlms_send_coef) {
660
-            for(i = 0; i < s->cdlms_ttl[c]; i++) {
631
+        if (cdlms_send_coef) {
632
+            for (i = 0; i < s->cdlms_ttl[c]; i++) {
661 633
                 int cbits, shift_l, shift_r, j;
662 634
                 cbits = av_log2(s->cdlms[c][i].order);
663
-                if(1 << cbits < s->cdlms[c][i].order)
635
+                if ((1 << cbits) < s->cdlms[c][i].order)
664 636
                     cbits++;
665 637
                 s->cdlms[c][i].coefsend = get_bits(&s->gb, cbits) + 1;
666 638
 
667 639
                 cbits = av_log2(s->cdlms[c][i].scaling + 1);
668
-                if(1 << cbits < s->cdlms[c][i].scaling + 1)
640
+                if ((1 << cbits) < s->cdlms[c][i].scaling + 1)
669 641
                     cbits++;
670 642
 
671 643
                 s->cdlms[c][i].bitsend = get_bits(&s->gb, cbits) + 2;
672 644
                 shift_l = 32 - s->cdlms[c][i].bitsend;
673
-                shift_r = 32 - 2 - s->cdlms[c][i].scaling;
674
-                for(j = 0; j < s->cdlms[c][i].coefsend; j++) {
645
+                shift_r = 32 - s->cdlms[c][i].scaling - 2;
646
+                for (j = 0; j < s->cdlms[c][i].coefsend; j++)
675 647
                     s->cdlms[c][i].coefs[j] =
676 648
                         (get_bits(&s->gb, s->cdlms[c][i].bitsend) << shift_l) >> shift_r;
677
-                }
678 649
             }
679 650
         }
680 651
     }
681 652
 }
682 653
 
683
-/**
684
- *
685
- */
686 654
 static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
687 655
 {
688 656
     int i = 0;
689 657
     unsigned int ave_mean;
690 658
     s->transient[ch] = get_bits1(&s->gb);
691
-    if(s->transient[ch]) {
692
-            s->transient_pos[ch] = get_bits(&s->gb, av_log2(tile_size));
659
+    if (s->transient[ch]) {
660
+        s->transient_pos[ch] = get_bits(&s->gb, av_log2(tile_size));
693 661
         if (s->transient_pos[ch])
694
-                s->transient[ch] = 0;
695
-            s->channel[ch].transient_counter =
696
-                FFMAX(s->channel[ch].transient_counter, s->samples_per_frame / 2);
697
-        } else if (s->channel[ch].transient_counter)
698
-            s->transient[ch] = 1;
662
+            s->transient[ch] = 0;
663
+        s->channel[ch].transient_counter =
664
+            FFMAX(s->channel[ch].transient_counter, s->samples_per_frame / 2);
665
+    } else if (s->channel[ch].transient_counter)
666
+        s->transient[ch] = 1;
699 667
 
700
-    if(s->seekable_tile) {
668
+    if (s->seekable_tile) {
701 669
         ave_mean = get_bits(&s->gb, s->bits_per_sample);
702 670
         s->ave_sum[ch] = ave_mean << (s->movave_scaling + 1);
703
-//        s->ave_sum[ch] *= 2;
704 671
     }
705 672
 
706
-    if(s->seekable_tile) {
707
-        if(s->do_inter_ch_decorr)
673
+    if (s->seekable_tile) {
674
+        if (s->do_inter_ch_decorr)
708 675
             s->channel_residues[ch][0] = get_sbits(&s->gb, s->bits_per_sample + 1);
709 676
         else
710 677
             s->channel_residues[ch][0] = get_sbits(&s->gb, s->bits_per_sample);
711 678
         i++;
712 679
     }
713
-    //av_log(0, 0, "%8d: ", num_logged_tiles++);
714
-    for(; i < tile_size; i++) {
680
+    for (; i < tile_size; i++) {
715 681
         int quo = 0, rem, rem_bits, residue;
716 682
         while(get_bits1(&s->gb)) {
717 683
             quo++;
718 684
             if (get_bits_left(&s->gb) <= 0)
719 685
                 return -1;
720 686
         }
721
-        if(quo >= 32)
687
+        if (quo >= 32)
722 688
             quo += get_bits_long(&s->gb, get_bits(&s->gb, 5) + 1);
723 689
 
724
-    ave_mean = (s->ave_sum[ch] + (1 << s->movave_scaling)) >> (s->movave_scaling + 1);
725
-    if (ave_mean <= 1)
726
-        residue = quo;
727
-    else
728
-    {
729
-        rem_bits = av_ceil_log2(ave_mean);
730
-        rem = rem_bits ? get_bits(&s->gb, rem_bits) : 0;
731
-        residue = (quo << rem_bits) + rem;
732
-    }
690
+        ave_mean = (s->ave_sum[ch] + (1 << s->movave_scaling)) >> (s->movave_scaling + 1);
691
+        if (ave_mean <= 1)
692
+            residue = quo;
693
+        else {
694
+            rem_bits = av_ceil_log2(ave_mean);
695
+            rem      = rem_bits ? get_bits(&s->gb, rem_bits) : 0;
696
+            residue  = (quo << rem_bits) + rem;
697
+        }
733 698
 
734
-        s->ave_sum[ch] = residue + s->ave_sum[ch] - (s->ave_sum[ch] >> s->movave_scaling);
699
+        s->ave_sum[ch] = residue + s->ave_sum[ch] -
700
+                         (s->ave_sum[ch] >> s->movave_scaling);
735 701
 
736
-        if(residue & 1)
702
+        if (residue & 1)
737 703
             residue = -(residue >> 1) - 1;
738 704
         else
739 705
             residue = residue >> 1;
740 706
         s->channel_residues[ch][i] = residue;
741 707
     }
742
-    //dump_int_buffer(s->channel_residues[ch], 4, tile_size, 16);
743 708
 
744 709
     return 0;
745 710
 
746 711
 }
747 712
 
748
-
749
-/**
750
- *
751
- */
752
-static void
753
-decode_lpc(WmallDecodeCtx *s)
713
+static void decode_lpc(WmallDecodeCtx *s)
754 714
 {
755 715
     int ch, i, cbits;
756
-    s->lpc_order = get_bits(&s->gb, 5) + 1;
716
+    s->lpc_order   = get_bits(&s->gb, 5) + 1;
757 717
     s->lpc_scaling = get_bits(&s->gb, 4);
758 718
     s->lpc_intbits = get_bits(&s->gb, 3) + 1;
759 719
     cbits = s->lpc_scaling + s->lpc_intbits;
760
-    for(ch = 0; ch < s->num_channels; ch++) {
761
-        for(i = 0; i < s->lpc_order; i++) {
720
+    for (ch = 0; ch < s->num_channels; ch++)
721
+        for (i = 0; i < s->lpc_order; i++)
762 722
             s->lpc_coefs[ch][i] = get_sbits(&s->gb, cbits);
763
-        }
764
-    }
765 723
 }
766 724
 
767
-
768 725
 static void clear_codec_buffers(WmallDecodeCtx *s)
769 726
 {
770 727
     int ich, ilms;
771 728
 
772
-    memset(s->acfilter_coeffs    , 0, 16 * sizeof(int));
773
-    memset(s->acfilter_prevvalues, 0, 16 * 2 * sizeof(int)); // may be wrong
774
-    memset(s->lpc_coefs          , 0, 40 * 2 * sizeof(int));
729
+    memset(s->acfilter_coeffs,     0, sizeof(s->acfilter_coeffs));
730
+    memset(s->acfilter_prevvalues, 0, sizeof(s->acfilter_prevvalues));
731
+    memset(s->lpc_coefs,           0, sizeof(s->lpc_coefs));
775 732
 
776
-    memset(s->mclms_coeffs    , 0, 128 * sizeof(int16_t));
777
-    memset(s->mclms_coeffs_cur, 0,   4 * sizeof(int16_t));
778
-    memset(s->mclms_prevvalues, 0,  64 * sizeof(int));
779
-    memset(s->mclms_updates   , 0,  64 * sizeof(int16_t));
733
+    memset(s->mclms_coeffs,     0, sizeof(s->mclms_coeffs));
734
+    memset(s->mclms_coeffs_cur, 0, sizeof(s->mclms_coeffs_cur));
735
+    memset(s->mclms_prevvalues, 0, sizeof(s->mclms_prevvalues));
736
+    memset(s->mclms_updates,    0, sizeof(s->mclms_updates));
780 737
 
781 738
     for (ich = 0; ich < s->num_channels; ich++) {
782 739
         for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++) {
783
-            memset(s->cdlms[ich][ilms].coefs         , 0, 256 * sizeof(int16_t));
784
-            memset(s->cdlms[ich][ilms].lms_prevvalues, 0, 512 * sizeof(int));
785
-            memset(s->cdlms[ich][ilms].lms_updates   , 0, 512 * sizeof(int16_t));
740
+            memset(s->cdlms[ich][ilms].coefs, 0,
741
+                   sizeof(s->cdlms[ich][ilms].coefs));
742
+            memset(s->cdlms[ich][ilms].lms_prevvalues, 0,
743
+                   sizeof(s->cdlms[ich][ilms].lms_prevvalues));
744
+            memset(s->cdlms[ich][ilms].lms_updates, 0,
745
+                   sizeof(s->cdlms[ich][ilms].lms_updates));
786 746
         }
787 747
         s->ave_sum[ich] = 0;
788 748
     }
789 749
 }
790 750
 
791 751
 /**
792
- *@brief Resets filter parameters and transient area at new seekable tile
752
+ * @brief Reset filter parameters and transient area at new seekable tile.
793 753
  */
794 754
 static void reset_codec(WmallDecodeCtx *s)
795 755
 {
... ...
@@ -799,23 +567,19 @@ static void reset_codec(WmallDecodeCtx *s)
799 799
         for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++)
800 800
             s->cdlms[ich][ilms].recent = s->cdlms[ich][ilms].order;
801 801
         /* first sample of a seekable subframe is considered as the starting of
802
-           a transient area which is samples_per_frame samples long */
802
+            a transient area which is samples_per_frame samples long */
803 803
         s->channel[ich].transient_counter = s->samples_per_frame;
804
-        s->transient[ich] = 1;
804
+        s->transient[ich]     = 1;
805 805
         s->transient_pos[ich] = 0;
806 806
     }
807 807
 }
808 808
 
809
-
810
-
811 809
 static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
812 810
 {
813
-    int i, j, ich;
814
-    int pred_error;
815
-    int order = s->mclms_order;
811
+    int i, j, ich, pred_error;
812
+    int order        = s->mclms_order;
816 813
     int num_channels = s->num_channels;
817
-    int range = 1 << (s->bits_per_sample - 1);
818
-    //int bps = s->bits_per_sample > 16 ? 4 : 2; // bytes per sample
814
+    int range        = 1 << (s->bits_per_sample - 1);
819 815
 
820 816
     for (ich = 0; ich < num_channels; ich++) {
821 817
         pred_error = s->channel_residues[ich][icoef] - pred[ich];
... ...
@@ -860,7 +624,7 @@ static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
860 860
     if (s->mclms_recent == 0) {
861 861
         memcpy(&s->mclms_prevvalues[order * num_channels],
862 862
                s->mclms_prevvalues,
863
-               4 * order * num_channels);
863
+               2 * order * num_channels);
864 864
         memcpy(&s->mclms_updates[order * num_channels],
865 865
                s->mclms_updates,
866 866
                2 * order * num_channels);
... ...
@@ -871,7 +635,7 @@ static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
871 871
 static void mclms_predict(WmallDecodeCtx *s, int icoef, int *pred)
872 872
 {
873 873
     int ich, i;
874
-    int order = s->mclms_order;
874
+    int order        = s->mclms_order;
875 875
     int num_channels = s->num_channels;
876 876
 
877 877
     for (ich = 0; ich < num_channels; ich++) {
... ...
@@ -892,7 +656,7 @@ static void mclms_predict(WmallDecodeCtx *s, int icoef, int *pred)
892 892
 
893 893
 static void revert_mclms(WmallDecodeCtx *s, int tile_size)
894 894
 {
895
-    int icoef, pred[WMALL_MAX_CHANNELS] = {0};
895
+    int icoef, pred[WMALL_MAX_CHANNELS] = { 0 };
896 896
     for (icoef = 0; icoef < tile_size; icoef++) {
897 897
         mclms_predict(s, icoef, pred);
898 898
         mclms_update(s, icoef, pred);
... ...
@@ -901,28 +665,22 @@ static void revert_mclms(WmallDecodeCtx *s, int tile_size)
901 901
 
902 902
 static int lms_predict(WmallDecodeCtx *s, int ich, int ilms)
903 903
 {
904
-    int pred = 0;
905
-    int icoef;
904
+    int pred = 0, icoef;
906 905
     int recent = s->cdlms[ich][ilms].recent;
907 906
 
908 907
     for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
909 908
         pred += s->cdlms[ich][ilms].coefs[icoef] *
910
-                    s->cdlms[ich][ilms].lms_prevvalues[icoef + recent];
909
+                s->cdlms[ich][ilms].lms_prevvalues[icoef + recent];
911 910
 
912
-    //pred += (1 << (s->cdlms[ich][ilms].scaling - 1));
913
-    /* XXX: Table 29 has:
914
-            iPred >= cdlms[iCh][ilms].scaling;
915
-       seems to me like a missing > */
916
-    //pred >>= s->cdlms[ich][ilms].scaling;
917 911
     return pred;
918 912
 }
919 913
 
920
-static void lms_update(WmallDecodeCtx *s, int ich, int ilms, int input, int residue)
914
+static void lms_update(WmallDecodeCtx *s, int ich, int ilms,
915
+                       int input, int residue)
921 916
 {
922 917
     int icoef;
923 918
     int recent = s->cdlms[ich][ilms].recent;
924
-    int range = 1 << s->bits_per_sample - 1;
925
-    //int bps = s->bits_per_sample > 16 ? 4 : 2; // bytes per sample
919
+    int range  = 1 << s->bits_per_sample - 1;
926 920
 
927 921
     if (residue < 0) {
928 922
         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
931 931
     } else if (residue > 0) {
932 932
         for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
933 933
             s->cdlms[ich][ilms].coefs[icoef] +=
934
-                s->cdlms[ich][ilms].lms_updates[icoef + recent];    /* spec mistakenly
935
-                                                                    dropped the recent */
934
+                s->cdlms[ich][ilms].lms_updates[icoef + recent];
936 935
     }
937 936
 
938 937
     if (recent)
939 938
         recent--;
940 939
     else {
941
-        /* XXX: This memcpy()s will probably fail if a fixed 32-bit buffer is used.
942
-                follow kshishkov's suggestion of using a union. */
943 940
         memcpy(&s->cdlms[ich][ilms].lms_prevvalues[s->cdlms[ich][ilms].order],
944 941
                s->cdlms[ich][ilms].lms_prevvalues,
945
-               4 * s->cdlms[ich][ilms].order);
942
+               2 * s->cdlms[ich][ilms].order);
946 943
         memcpy(&s->cdlms[ich][ilms].lms_updates[s->cdlms[ich][ilms].order],
947 944
                s->cdlms[ich][ilms].lms_updates,
948 945
                2 * s->cdlms[ich][ilms].order);
... ...
@@ -957,14 +712,6 @@ static void lms_update(WmallDecodeCtx *s, int ich, int ilms, int input, int resi
957 957
     else
958 958
         s->cdlms[ich][ilms].lms_updates[recent] = s->update_speed[ich];
959 959
 
960
-    /* XXX: spec says:
961
-    cdlms[iCh][ilms].updates[iRecent + cdlms[iCh][ilms].order >> 4] >>= 2;
962
-    lms_updates[iCh][ilms][iRecent + cdlms[iCh][ilms].order >> 3] >>= 1;
963
-
964
-        Questions is - are cdlms[iCh][ilms].updates[] and lms_updates[][][] two
965
-        seperate buffers? Here I've assumed that the two are same which makes
966
-        more sense to me.
967
-    */
968 960
     s->cdlms[ich][ilms].lms_updates[recent + (s->cdlms[ich][ilms].order >> 4)] >>= 2;
969 961
     s->cdlms[ich][ilms].lms_updates[recent + (s->cdlms[ich][ilms].order >> 3)] >>= 1;
970 962
     s->cdlms[ich][ilms].recent = recent;
... ...
@@ -995,27 +742,23 @@ static void use_normal_update_speed(WmallDecodeCtx *s, int ich)
995 995
         recent = s->cdlms[ich][ilms].recent;
996 996
         if (s->update_speed[ich] == 8)
997 997
             continue;
998
-        if (s->bV3RTM) {
998
+        if (s->bV3RTM)
999 999
             for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
1000 1000
                 s->cdlms[ich][ilms].lms_updates[icoef + recent] /= 2;
1001
-        } else {
1001
+        else
1002 1002
             for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
1003 1003
                 s->cdlms[ich][ilms].lms_updates[icoef] /= 2;
1004
-        }
1005 1004
     }
1006 1005
     s->update_speed[ich] = 8;
1007 1006
 }
1008 1007
 
1009
-static void revert_cdlms(WmallDecodeCtx *s, int ch, int coef_begin, int coef_end)
1008
+static void revert_cdlms(WmallDecodeCtx *s, int ch,
1009
+                         int coef_begin, int coef_end)
1010 1010
 {
1011
-    int icoef;
1012
-    int pred;
1013
-    int ilms, num_lms;
1014
-    int residue, input;
1011
+    int icoef, pred, ilms, num_lms, residue, input;
1015 1012
 
1016 1013
     num_lms = s->cdlms_ttl[ch];
1017 1014
     for (ilms = num_lms - 1; ilms >= 0; ilms--) {
1018
-        //s->cdlms[ch][ilms].recent = s->cdlms[ch][ilms].order;
1019 1015
         for (icoef = coef_begin; icoef < coef_end; icoef++) {
1020 1016
             pred = 1 << (s->cdlms[ch][ilms].scaling - 1);
1021 1017
             residue = s->channel_residues[ch][icoef];
... ...
@@ -1029,10 +772,10 @@ static void revert_cdlms(WmallDecodeCtx *s, int ch, int coef_begin, int coef_end
1029 1029
 
1030 1030
 static void revert_inter_ch_decorr(WmallDecodeCtx *s, int tile_size)
1031 1031
 {
1032
-    int icoef;
1033 1032
     if (s->num_channels != 2)
1034 1033
         return;
1035 1034
     else if (s->is_channel_coded[0] && s->is_channel_coded[1]) {
1035
+        int icoef;
1036 1036
         for (icoef = 0; icoef < tile_size; icoef++) {
1037 1037
             s->channel_residues[0][icoef] -= s->channel_residues[1][icoef] >> 1;
1038 1038
             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)
1042 1042
 
1043 1043
 static void revert_acfilter(WmallDecodeCtx *s, int tile_size)
1044 1044
 {
1045
-    int ich, icoef;
1046
-    int pred;
1047
-    int i, j;
1045
+    int ich, pred, i, j;
1048 1046
     int64_t *filter_coeffs = s->acfilter_coeffs;
1049
-    int scaling = s->acfilter_scaling;
1050
-    int order = s->acfilter_order;
1047
+    int scaling            = s->acfilter_scaling;
1048
+    int order              = s->acfilter_order;
1051 1049
 
1052 1050
     for (ich = 0; ich < s->num_channels; ich++) {
1053 1051
         int *prevvalues = s->acfilter_prevvalues[ich];
... ...
@@ -1074,28 +815,19 @@ static void revert_acfilter(WmallDecodeCtx *s, int tile_size)
1074 1074
     }
1075 1075
 }
1076 1076
 
1077
-/**
1078
- *@brief Decode a single subframe (block).
1079
- *@param s codec context
1080
- *@return 0 on success, < 0 when decoding failed
1081
- */
1082 1077
 static int decode_subframe(WmallDecodeCtx *s)
1083 1078
 {
1084
-    int offset = s->samples_per_frame;
1085
-    int subframe_len = s->samples_per_frame;
1086
-    int i, j;
1087
-    int total_samples   = s->samples_per_frame * s->num_channels;
1088
-    int rawpcm_tile;
1089
-    int padding_zeroes;
1079
+    int offset        = s->samples_per_frame;
1080
+    int subframe_len  = s->samples_per_frame;
1081
+    int total_samples = s->samples_per_frame * s->num_channels;
1082
+    int i, j, rawpcm_tile, padding_zeroes;
1090 1083
 
1091 1084
     s->subframe_offset = get_bits_count(&s->gb);
1092 1085
 
1093
-    /** reset channel context and find the next block offset and size
1086
+    /* reset channel context and find the next block offset and size
1094 1087
         == the next block of the channel with the smallest number of
1095
-        decoded samples
1096
-    */
1088
+        decoded samples */
1097 1089
     for (i = 0; i < s->num_channels; i++) {
1098
-        s->channel[i].grouped = 0;
1099 1090
         if (offset > s->channel[i].decoded_samples) {
1100 1091
             offset = s->channel[i].decoded_samples;
1101 1092
             subframe_len =
... ...
@@ -1103,14 +835,14 @@ static int decode_subframe(WmallDecodeCtx *s)
1103 1103
         }
1104 1104
     }
1105 1105
 
1106
-    /** get a list of all channels that contain the estimated block */
1106
+    /* get a list of all channels that contain the estimated block */
1107 1107
     s->channels_for_cur_subframe = 0;
1108 1108
     for (i = 0; i < s->num_channels; i++) {
1109 1109
         const int cur_subframe = s->channel[i].cur_subframe;
1110
-        /** substract already processed samples */
1110
+        /* subtract already processed samples */
1111 1111
         total_samples -= s->channel[i].decoded_samples;
1112 1112
 
1113
-        /** and count if there are multiple subframes that match our profile */
1113
+        /* and count if there are multiple subframes that match our profile */
1114 1114
         if (offset == s->channel[i].decoded_samples &&
1115 1115
             subframe_len == s->channel[i].subframe_len[cur_subframe]) {
1116 1116
             total_samples -= s->channel[i].subframe_len[cur_subframe];
... ...
@@ -1121,95 +853,89 @@ static int decode_subframe(WmallDecodeCtx *s)
1121 1121
         }
1122 1122
     }
1123 1123
 
1124
-    /** check if the frame will be complete after processing the
1124
+    /* check if the frame will be complete after processing the
1125 1125
         estimated block */
1126 1126
     if (!total_samples)
1127 1127
         s->parsed_all_subframes = 1;
1128 1128
 
1129 1129
 
1130 1130
     s->seekable_tile = get_bits1(&s->gb);
1131
-    if(s->seekable_tile) {
1131
+    if (s->seekable_tile) {
1132 1132
         clear_codec_buffers(s);
1133 1133
 
1134 1134
         s->do_arith_coding    = get_bits1(&s->gb);
1135
-        if(s->do_arith_coding) {
1136
-            dprintf(s->avctx, "do_arith_coding == 1");
1135
+        if (s->do_arith_coding) {
1136
+            av_dlog(s->avctx, AV_LOG_DEBUG, "do_arith_coding == 1");
1137 1137
             abort();
1138 1138
         }
1139 1139
         s->do_ac_filter       = get_bits1(&s->gb);
1140 1140
         s->do_inter_ch_decorr = get_bits1(&s->gb);
1141 1141
         s->do_mclms           = get_bits1(&s->gb);
1142 1142
 
1143
-        if(s->do_ac_filter)
1143
+        if (s->do_ac_filter)
1144 1144
             decode_ac_filter(s);
1145 1145
 
1146
-        if(s->do_mclms)
1146
+        if (s->do_mclms)
1147 1147
             decode_mclms(s);
1148 1148
 
1149 1149
         decode_cdlms(s);
1150 1150
         s->movave_scaling = get_bits(&s->gb, 3);
1151 1151
         s->quant_stepsize = get_bits(&s->gb, 8) + 1;
1152 1152
 
1153
-            reset_codec(s);
1153
+        reset_codec(s);
1154 1154
     }
1155 1155
 
1156 1156
     rawpcm_tile = get_bits1(&s->gb);
1157 1157
 
1158
-    for(i = 0; i < s->num_channels; i++) {
1158
+    for (i = 0; i < s->num_channels; i++)
1159 1159
         s->is_channel_coded[i] = 1;
1160
-    }
1161 1160
 
1162
-    if(!rawpcm_tile) {
1163
-
1164
-        for(i = 0; i < s->num_channels; i++) {
1161
+    if (!rawpcm_tile) {
1162
+        for (i = 0; i < s->num_channels; i++)
1165 1163
             s->is_channel_coded[i] = get_bits1(&s->gb);
1166
-        }
1167 1164
 
1168
-        if(s->bV3RTM) {
1165
+        if (s->bV3RTM) {
1169 1166
             // LPC
1170 1167
             s->do_lpc = get_bits1(&s->gb);
1171
-            if(s->do_lpc) {
1168
+            if (s->do_lpc) {
1172 1169
                 decode_lpc(s);
1170
+                av_log_ask_for_sample(s->avctx, "Inverse LPC filter not "
1171
+                                      "implemented. Expect wrong output.\n");
1173 1172
             }
1174
-        } else {
1173
+        } else
1175 1174
             s->do_lpc = 0;
1176
-        }
1177 1175
     }
1178 1176
 
1179 1177
 
1180
-    if(get_bits1(&s->gb)) {
1178
+    if (get_bits1(&s->gb))
1181 1179
         padding_zeroes = get_bits(&s->gb, 5);
1182
-    } else {
1180
+    else
1183 1181
         padding_zeroes = 0;
1184
-    }
1185
-
1186
-    if(rawpcm_tile) {
1187 1182
 
1183
+    if (rawpcm_tile) {
1188 1184
         int bits = s->bits_per_sample - padding_zeroes;
1189
-        dprintf(s->avctx, "RAWPCM %d bits per sample. total %d bits, remain=%d\n", bits,
1185
+        av_dlog(s->avctx, AV_LOG_DEBUG, "RAWPCM %d bits per sample. "
1186
+                "total %d bits, remain=%d\n", bits,
1190 1187
                 bits * s->num_channels * subframe_len, get_bits_count(&s->gb));
1191
-        for(i = 0; i < s->num_channels; i++) {
1192
-            for(j = 0; j < subframe_len; j++) {
1188
+        for (i = 0; i < s->num_channels; i++)
1189
+            for (j = 0; j < subframe_len; j++)
1193 1190
                 s->channel_coeffs[i][j] = get_sbits(&s->gb, bits);
1194
-//                dprintf(s->avctx, "PCM[%d][%d] = 0x%04x\n", i, j, s->channel_coeffs[i][j]);
1195
-            }
1196
-        }
1197 1191
     } else {
1198
-        for(i = 0; i < s->num_channels; i++)
1199
-            if(s->is_channel_coded[i]) {
1200
-            decode_channel_residues(s, i, subframe_len);
1201
-            if (s->seekable_tile)
1202
-                use_high_update_speed(s, i);
1203
-            else
1204
-                use_normal_update_speed(s, i);
1205
-            revert_cdlms(s, i, 0, subframe_len);
1206
-        }
1192
+        for (i = 0; i < s->num_channels; i++)
1193
+            if (s->is_channel_coded[i]) {
1194
+                decode_channel_residues(s, i, subframe_len);
1195
+                if (s->seekable_tile)
1196
+                    use_high_update_speed(s, i);
1197
+                else
1198
+                    use_normal_update_speed(s, i);
1199
+                revert_cdlms(s, i, 0, subframe_len);
1200
+            }
1207 1201
     }
1208 1202
     if (s->do_mclms)
1209 1203
         revert_mclms(s, subframe_len);
1210 1204
     if (s->do_inter_ch_decorr)
1211 1205
         revert_inter_ch_decorr(s, subframe_len);
1212
-    if(s->do_ac_filter)
1206
+    if (s->do_ac_filter)
1213 1207
         revert_acfilter(s, subframe_len);
1214 1208
 
1215 1209
     /* Dequantize */
... ...
@@ -1218,7 +944,7 @@ static int decode_subframe(WmallDecodeCtx *s)
1218 1218
             for (j = 0; j < subframe_len; j++)
1219 1219
                 s->channel_residues[i][j] *= s->quant_stepsize;
1220 1220
 
1221
-    // Write to proper output buffer depending on bit-depth
1221
+    /* Write to proper output buffer depending on bit-depth */
1222 1222
     for (i = 0; i < subframe_len; i++)
1223 1223
         for (j = 0; j < s->num_channels; j++) {
1224 1224
             if (s->bits_per_sample == 16)
... ...
@@ -1227,8 +953,7 @@ static int decode_subframe(WmallDecodeCtx *s)
1227 1227
                 *s->samples_32++ = s->channel_residues[j][i];
1228 1228
         }
1229 1229
 
1230
-    /** handled one subframe */
1231
-
1230
+    /* handled one subframe */
1232 1231
     for (i = 0; i < s->channels_for_cur_subframe; i++) {
1233 1232
         int c = s->channel_indexes_for_cur_subframe[i];
1234 1233
         if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) {
... ...
@@ -1237,77 +962,72 @@ static int decode_subframe(WmallDecodeCtx *s)
1237 1237
         }
1238 1238
         ++s->channel[c].cur_subframe;
1239 1239
     }
1240
-    num_logged_subframes++;
1241 1240
     return 0;
1242 1241
 }
1243 1242
 
1244 1243
 /**
1245
- *@brief Decode one WMA frame.
1246
- *@param s codec context
1247
- *@return 0 if the trailer bit indicates that this is the last frame,
1248
- *        1 if there are additional frames
1244
+ * @brief Decode one WMA frame.
1245
+ * @param s codec context
1246
+ * @return 0 if the trailer bit indicates that this is the last frame,
1247
+ *         1 if there are additional frames
1249 1248
  */
1250 1249
 static int decode_frame(WmallDecodeCtx *s)
1251 1250
 {
1252 1251
     GetBitContext* gb = &s->gb;
1253
-    int more_frames = 0;
1254
-    int len = 0;
1255
-    int i, ret;
1252
+    int more_frames = 0, len = 0, i, ret;
1256 1253
 
1257 1254
     s->frame.nb_samples = s->samples_per_frame;
1258 1255
     if ((ret = s->avctx->get_buffer(s->avctx, &s->frame)) < 0) {
1259
-        /** return an error if no frame could be decoded at all */
1256
+        /* return an error if no frame could be decoded at all */
1260 1257
         av_log(s->avctx, AV_LOG_ERROR,
1261 1258
                "not enough space for the output samples\n");
1262 1259
         s->packet_loss = 1;
1263
-        return 0;
1260
+        return ret;
1264 1261
     }
1265 1262
     s->samples_16 = (int16_t *)s->frame.data[0];
1266 1263
     s->samples_32 = (int32_t *)s->frame.data[0];
1267 1264
 
1268
-    /** get frame length */
1265
+    /* get frame length */
1269 1266
     if (s->len_prefix)
1270 1267
         len = get_bits(gb, s->log2_frame_size);
1271 1268
 
1272
-    /** decode tile information */
1269
+    /* decode tile information */
1273 1270
     if (decode_tilehdr(s)) {
1274 1271
         s->packet_loss = 1;
1275 1272
         return 0;
1276 1273
     }
1277 1274
 
1278
-    /** read drc info */
1279
-    if (s->dynamic_range_compression) {
1275
+    /* read drc info */
1276
+    if (s->dynamic_range_compression)
1280 1277
         s->drc_gain = get_bits(gb, 8);
1281
-    }
1282 1278
 
1283
-    /** no idea what these are for, might be the number of samples
1284
-        that need to be skipped at the beginning or end of a stream */
1279
+    /* no idea what these are for, might be the number of samples
1280
+       that need to be skipped at the beginning or end of a stream */
1285 1281
     if (get_bits1(gb)) {
1286 1282
         int skip;
1287 1283
 
1288
-        /** usually true for the first frame */
1284
+        /* usually true for the first frame */
1289 1285
         if (get_bits1(gb)) {
1290 1286
             skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1291
-            dprintf(s->avctx, "start skip: %i\n", skip);
1287
+            av_dlog(s->avctx, AV_LOG_DEBUG, "start skip: %i\n", skip);
1292 1288
         }
1293 1289
 
1294
-        /** sometimes true for the last frame */
1290
+        /* sometimes true for the last frame */
1295 1291
         if (get_bits1(gb)) {
1296 1292
             skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1297
-            dprintf(s->avctx, "end skip: %i\n", skip);
1293
+            av_dlog(s->avctx, AV_LOG_DEBUG, "end skip: %i\n", skip);
1298 1294
         }
1299 1295
 
1300 1296
     }
1301 1297
 
1302
-    /** reset subframe states */
1298
+    /* reset subframe states */
1303 1299
     s->parsed_all_subframes = 0;
1304 1300
     for (i = 0; i < s->num_channels; i++) {
1305 1301
         s->channel[i].decoded_samples = 0;
1306 1302
         s->channel[i].cur_subframe    = 0;
1307
-        s->channel[i].reuse_sf        = 0;
1308 1303
     }
1309 1304
 
1310
-    /** decode all subframes */
1305
+    /* decode all subframes */
1311 1306
     while (!s->parsed_all_subframes) {
1312 1307
         if (decode_subframe(s) < 0) {
1313 1308
             s->packet_loss = 1;
... ...
@@ -1315,15 +1035,14 @@ static int decode_frame(WmallDecodeCtx *s)
1315 1315
         }
1316 1316
     }
1317 1317
 
1318
-    dprintf(s->avctx, "Frame done\n");
1318
+    av_dlog(s->avctx, AV_LOG_DEBUG, "Frame done\n");
1319 1319
 
1320
-    if (s->skip_frame) {
1320
+    if (s->skip_frame)
1321 1321
         s->skip_frame = 0;
1322
-    }
1323 1322
 
1324 1323
     if (s->len_prefix) {
1325 1324
         if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
1326
-            /** FIXME: not sure if this is always an error */
1325
+            /* FIXME: not sure if this is always an error */
1327 1326
             av_log(s->avctx, AV_LOG_ERROR,
1328 1327
                    "frame[%i] would have to skip %i bits\n", s->frame_num,
1329 1328
                    len - (get_bits_count(gb) - s->frame_offset) - 1);
... ...
@@ -1331,27 +1050,21 @@ static int decode_frame(WmallDecodeCtx *s)
1331 1331
             return 0;
1332 1332
         }
1333 1333
 
1334
-        /** skip the rest of the frame data */
1334
+        /* skip the rest of the frame data */
1335 1335
         skip_bits_long(gb, len - (get_bits_count(gb) - s->frame_offset) - 1);
1336
-    } else {
1337
-/*
1338
-        while (get_bits_count(gb) < s->num_saved_bits && get_bits1(gb) == 0) {
1339
-            dprintf(s->avctx, "skip1\n");
1340
-        }
1341
-*/
1342 1336
     }
1343 1337
 
1344
-    /** decode trailer bit */
1338
+    /* decode trailer bit */
1345 1339
     more_frames = get_bits1(gb);
1346 1340
     ++s->frame_num;
1347 1341
     return more_frames;
1348 1342
 }
1349 1343
 
1350 1344
 /**
1351
- *@brief Calculate remaining input buffer length.
1352
- *@param s codec context
1353
- *@param gb bitstream reader context
1354
- *@return remaining size in bits
1345
+ * @brief Calculate remaining input buffer length.
1346
+ * @param s  codec context
1347
+ * @param gb bitstream reader context
1348
+ * @return remaining size in bits
1355 1349
  */
1356 1350
 static int remaining_bits(WmallDecodeCtx *s, GetBitContext *gb)
1357 1351
 {
... ...
@@ -1359,23 +1072,24 @@ static int remaining_bits(WmallDecodeCtx *s, GetBitContext *gb)
1359 1359
 }
1360 1360
 
1361 1361
 /**
1362
- *@brief Fill the bit reservoir with a (partial) frame.
1363
- *@param s codec context
1364
- *@param gb bitstream reader context
1365
- *@param len length of the partial frame
1366
- *@param append decides wether to reset the buffer or not
1362
+ * @brief Fill the bit reservoir with a (partial) frame.
1363
+ * @param s      codec context
1364
+ * @param gb     bitstream reader context
1365
+ * @param len    length of the partial frame
1366
+ * @param append decides whether to reset the buffer or not
1367 1367
  */
1368 1368
 static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len,
1369 1369
                       int append)
1370 1370
 {
1371 1371
     int buflen;
1372
+    PutBitContext tmp;
1372 1373
 
1373
-    /** when the frame data does not need to be concatenated, the input buffer
1374
-        is resetted and additional bits from the previous frame are copyed
1374
+    /* when the frame data does not need to be concatenated, the input buffer
1375
+        is reset and additional bits from the previous frame are copied
1375 1376
         and skipped later so that a fast byte copy is possible */
1376 1377
 
1377 1378
     if (!append) {
1378
-        s->frame_offset = get_bits_count(gb) & 7;
1379
+        s->frame_offset   = get_bits_count(gb) & 7;
1379 1380
         s->num_saved_bits = s->frame_offset;
1380 1381
         init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
1381 1382
     }
... ...
@@ -1391,7 +1105,7 @@ static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len,
1391 1391
     s->num_saved_bits += len;
1392 1392
     if (!append) {
1393 1393
         avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3),
1394
-                     s->num_saved_bits);
1394
+                         s->num_saved_bits);
1395 1395
     } else {
1396 1396
         int align = 8 - (get_bits_count(gb) & 7);
1397 1397
         align = FFMIN(align, len);
... ...
@@ -1401,57 +1115,52 @@ static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len,
1401 1401
     }
1402 1402
     skip_bits_long(gb, len);
1403 1403
 
1404
-    {
1405
-        PutBitContext tmp = s->pb;
1406
-        flush_put_bits(&tmp);
1407
-    }
1404
+    tmp = s->pb;
1405
+    flush_put_bits(&tmp);
1408 1406
 
1409 1407
     init_get_bits(&s->gb, s->frame_data, s->num_saved_bits);
1410 1408
     skip_bits(&s->gb, s->frame_offset);
1411 1409
 }
1412 1410
 
1413 1411
 /**
1414
- *@brief Decode a single WMA packet.
1415
- *@param avctx codec context
1416
- *@param data the output buffer
1417
- *@param data_size number of bytes that were written to the output buffer
1418
- *@param avpkt input packet
1419
- *@return number of bytes that were read from the input buffer
1412
+ * @brief Decode a single WMA packet.
1413
+ * @param avctx     codec context
1414
+ * @param data      the output buffer
1415
+ * @param data_size number of bytes that were written to the output buffer
1416
+ * @param avpkt     input packet
1417
+ * @return number of bytes that were read from the input buffer
1420 1418
  */
1421
-static int decode_packet(AVCodecContext *avctx,
1422
-                         void *data, int *got_frame_ptr, AVPacket* avpkt)
1419
+static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr,
1420
+                         AVPacket* avpkt)
1423 1421
 {
1424 1422
     WmallDecodeCtx *s = avctx->priv_data;
1425 1423
     GetBitContext* gb  = &s->pgb;
1426 1424
     const uint8_t* buf = avpkt->data;
1427 1425
     int buf_size       = avpkt->size;
1428
-    int num_bits_prev_frame;
1429
-    int packet_sequence_number;
1430
-    int seekable_frame_in_packet;
1431
-    int spliced_packet;
1426
+    int num_bits_prev_frame, packet_sequence_number,
1427
+        seekable_frame_in_packet, spliced_packet;
1432 1428
 
1433 1429
     if (s->packet_done || s->packet_loss) {
1434
-        int seekable_frame_in_packet, spliced_packet;
1435 1430
         s->packet_done = 0;
1436 1431
 
1437
-        /** sanity check for the buffer length */
1432
+        /* sanity check for the buffer length */
1438 1433
         if (buf_size < avctx->block_align)
1439 1434
             return 0;
1440 1435
 
1441 1436
         s->next_packet_start = buf_size - avctx->block_align;
1442
-        buf_size = avctx->block_align;
1443
-        s->buf_bit_size = buf_size << 3;
1437
+        buf_size             = avctx->block_align;
1438
+        s->buf_bit_size      = buf_size << 3;
1444 1439
 
1445
-        /** parse packet header */
1440
+        /* parse packet header */
1446 1441
         init_get_bits(gb, buf, s->buf_bit_size);
1447
-        packet_sequence_number = get_bits(gb, 4);
1442
+        packet_sequence_number   = get_bits(gb, 4);
1448 1443
         seekable_frame_in_packet = get_bits1(gb);
1449
-        spliced_packet = get_bits1(gb);
1444
+        spliced_packet           = get_bits1(gb);
1450 1445
 
1451
-        /** get number of bits that need to be added to the previous frame */
1446
+        /* get number of bits that need to be added to the previous frame */
1452 1447
         num_bits_prev_frame = get_bits(gb, s->log2_frame_size);
1453 1448
 
1454
-        /** check for packet loss */
1449
+        /* check for packet loss */
1455 1450
         if (!s->packet_loss &&
1456 1451
             ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1457 1452
             s->packet_loss = 1;
... ...
@@ -1467,24 +1176,23 @@ static int decode_packet(AVCodecContext *avctx,
1467 1467
                 s->packet_done = 1;
1468 1468
             }
1469 1469
 
1470
-            /** append the previous frame data to the remaining data from the
1471
-                previous packet to create a full frame */
1470
+            /* Append the previous frame data to the remaining data from the
1471
+             * previous packet to create a full frame. */
1472 1472
             save_bits(s, gb, num_bits_prev_frame, 1);
1473 1473
 
1474
-            /** decode the cross packet frame if it is valid */
1474
+            /* decode the cross packet frame if it is valid */
1475 1475
             if (!s->packet_loss)
1476 1476
                 decode_frame(s);
1477 1477
         } else if (s->num_saved_bits - s->frame_offset) {
1478
-            dprintf(avctx, "ignoring %x previously saved bits\n",
1478
+            av_dlog(avctx, AV_LOG_DEBUG, "ignoring %x previously saved bits\n",
1479 1479
                     s->num_saved_bits - s->frame_offset);
1480 1480
         }
1481 1481
 
1482 1482
         if (s->packet_loss) {
1483
-            /** reset number of saved bits so that the decoder
1484
-                does not start to decode incomplete frames in the
1485
-                s->len_prefix == 0 case */
1483
+            /* Reset number of saved bits so that the decoder does not start
1484
+             * to decode incomplete frames in the s->len_prefix == 0 case. */
1486 1485
             s->num_saved_bits = 0;
1487
-            s->packet_loss = 0;
1486
+            s->packet_loss    = 0;
1488 1487
         }
1489 1488
 
1490 1489
     } else {
... ...
@@ -1501,13 +1209,12 @@ static int decode_packet(AVCodecContext *avctx,
1501 1501
             s->packet_done = !decode_frame(s);
1502 1502
         } else if (!s->len_prefix
1503 1503
                    && s->num_saved_bits > get_bits_count(&s->gb)) {
1504
-            /** when the frames do not have a length prefix, we don't know
1505
-                the compressed length of the individual frames
1506
-                however, we know what part of a new packet belongs to the
1507
-                previous frame
1508
-                therefore we save the incoming packet first, then we append
1509
-                the "previous frame" data from the next packet so that
1510
-                we get a buffer that only contains full frames */
1504
+            /* when the frames do not have a length prefix, we don't know the
1505
+             * compressed length of the individual frames however, we know what
1506
+             * part of a new packet belongs to the previous frame therefore we
1507
+             * save the incoming packet first, then we append the "previous
1508
+             * frame" data from the next packet so that we get a buffer that
1509
+             * only contains full frames */
1511 1510
             s->packet_done = !decode_frame(s);
1512 1511
         } else {
1513 1512
             s->packet_done = 1;
... ...
@@ -1516,47 +1223,26 @@ static int decode_packet(AVCodecContext *avctx,
1516 1516
 
1517 1517
     if (s->packet_done && !s->packet_loss &&
1518 1518
         remaining_bits(s, gb) > 0) {
1519
-        /** save the rest of the data so that it can be decoded
1520
-            with the next packet */
1519
+        /* save the rest of the data so that it can be decoded
1520
+         * with the next packet */
1521 1521
         save_bits(s, gb, remaining_bits(s, gb), 0);
1522 1522
     }
1523 1523
 
1524 1524
     *(AVFrame *)data = s->frame;
1525
-    *got_frame_ptr = 1;
1525
+    *got_frame_ptr   = 1;
1526 1526
     s->packet_offset = get_bits_count(gb) & 7;
1527 1527
 
1528 1528
     return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3;
1529 1529
 }
1530 1530
 
1531
-/**
1532
- *@brief Clear decoder buffers (for seeking).
1533
- *@param avctx codec context
1534
- */
1535
-static void flush(AVCodecContext *avctx)
1536
-{
1537
-    WmallDecodeCtx *s = avctx->priv_data;
1538
-    int i;
1539
-    /** reset output buffer as a part of it is used during the windowing of a
1540
-        new frame */
1541
-    for (i = 0; i < s->num_channels; i++)
1542
-        memset(s->channel[i].out, 0, s->samples_per_frame *
1543
-               sizeof(*s->channel[i].out));
1544
-    s->packet_loss = 1;
1545
-}
1546
-
1547 1531
 
1548
-/**
1549
- *@brief wmall decoder
1550
- */
1551 1532
 AVCodec ff_wmalossless_decoder = {
1552 1533
     .name           = "wmalossless",
1553 1534
     .type           = AVMEDIA_TYPE_AUDIO,
1554 1535
     .id             = CODEC_ID_WMALOSSLESS,
1555 1536
     .priv_data_size = sizeof(WmallDecodeCtx),
1556 1537
     .init           = decode_init,
1557
-    .close          = decode_end,
1558 1538
     .decode         = decode_packet,
1559
-    .flush          = flush,
1560
-    .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_EXPERIMENTAL | CODEC_CAP_DR1,
1561
-    .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 9 Lossless"),
1539
+    .capabilities   = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1,
1540
+    .long_name      = NULL_IF_CONFIG_SMALL("Windows Media Audio Lossless"),
1562 1541
 };
... ...
@@ -64,7 +64,7 @@ static int decode_frame(AVCodecContext *avctx,
64 64
     const uint8_t *buf = avpkt->data;
65 65
     int buf_size = avpkt->size;
66 66
     WNV1Context * const l = avctx->priv_data;
67
-    AVFrame * const p= (AVFrame*)&l->pic;
67
+    AVFrame * const p = &l->pic;
68 68
     unsigned char *Y,*U,*V;
69 69
     int i, j;
70 70
     int prev_y = 0, prev_u = 0, prev_v = 0;
... ...
@@ -619,7 +619,7 @@ MC MC33
619 619
 %define PAD 12
620 620
 %define COUNT 2
621 621
 %else
622
-%define PAD 0
622
+%define PAD 4
623 623
 %define COUNT 3
624 624
 %endif
625 625
 put_hv%2_10_%1:
... ...
@@ -29,98 +29,98 @@
29 29
 /*
30 30
  * MC functions
31 31
  */
32
-extern void ff_put_vp8_epel4_h4_mmxext(uint8_t *dst, int dststride,
33
-                                       uint8_t *src, int srcstride,
32
+extern void ff_put_vp8_epel4_h4_mmxext(uint8_t *dst, ptrdiff_t dststride,
33
+                                       uint8_t *src, ptrdiff_t srcstride,
34 34
                                        int height, int mx, int my);
35
-extern void ff_put_vp8_epel4_h6_mmxext(uint8_t *dst, int dststride,
36
-                                       uint8_t *src, int srcstride,
35
+extern void ff_put_vp8_epel4_h6_mmxext(uint8_t *dst, ptrdiff_t dststride,
36
+                                       uint8_t *src, ptrdiff_t srcstride,
37 37
                                        int height, int mx, int my);
38
-extern void ff_put_vp8_epel4_v4_mmxext(uint8_t *dst, int dststride,
39
-                                       uint8_t *src, int srcstride,
38
+extern void ff_put_vp8_epel4_v4_mmxext(uint8_t *dst, ptrdiff_t dststride,
39
+                                       uint8_t *src, ptrdiff_t srcstride,
40 40
                                        int height, int mx, int my);
41
-extern void ff_put_vp8_epel4_v6_mmxext(uint8_t *dst, int dststride,
42
-                                       uint8_t *src, int srcstride,
41
+extern void ff_put_vp8_epel4_v6_mmxext(uint8_t *dst, ptrdiff_t dststride,
42
+                                       uint8_t *src, ptrdiff_t srcstride,
43 43
                                        int height, int mx, int my);
44 44
 
45
-extern void ff_put_vp8_epel8_h4_sse2  (uint8_t *dst, int dststride,
46
-                                       uint8_t *src, int srcstride,
45
+extern void ff_put_vp8_epel8_h4_sse2  (uint8_t *dst, ptrdiff_t dststride,
46
+                                       uint8_t *src, ptrdiff_t srcstride,
47 47
                                        int height, int mx, int my);
48
-extern void ff_put_vp8_epel8_h6_sse2  (uint8_t *dst, int dststride,
49
-                                       uint8_t *src, int srcstride,
48
+extern void ff_put_vp8_epel8_h6_sse2  (uint8_t *dst, ptrdiff_t dststride,
49
+                                       uint8_t *src, ptrdiff_t srcstride,
50 50
                                        int height, int mx, int my);
51
-extern void ff_put_vp8_epel8_v4_sse2  (uint8_t *dst, int dststride,
52
-                                       uint8_t *src, int srcstride,
51
+extern void ff_put_vp8_epel8_v4_sse2  (uint8_t *dst, ptrdiff_t dststride,
52
+                                       uint8_t *src, ptrdiff_t srcstride,
53 53
                                        int height, int mx, int my);
54
-extern void ff_put_vp8_epel8_v6_sse2  (uint8_t *dst, int dststride,
55
-                                       uint8_t *src, int srcstride,
54
+extern void ff_put_vp8_epel8_v6_sse2  (uint8_t *dst, ptrdiff_t dststride,
55
+                                       uint8_t *src, ptrdiff_t srcstride,
56 56
                                        int height, int mx, int my);
57 57
 
58
-extern void ff_put_vp8_epel4_h4_ssse3 (uint8_t *dst, int dststride,
59
-                                       uint8_t *src, int srcstride,
58
+extern void ff_put_vp8_epel4_h4_ssse3 (uint8_t *dst, ptrdiff_t dststride,
59
+                                       uint8_t *src, ptrdiff_t srcstride,
60 60
                                        int height, int mx, int my);
61
-extern void ff_put_vp8_epel4_h6_ssse3 (uint8_t *dst, int dststride,
62
-                                       uint8_t *src, int srcstride,
61
+extern void ff_put_vp8_epel4_h6_ssse3 (uint8_t *dst, ptrdiff_t dststride,
62
+                                       uint8_t *src, ptrdiff_t srcstride,
63 63
                                        int height, int mx, int my);
64
-extern void ff_put_vp8_epel4_v4_ssse3 (uint8_t *dst, int dststride,
65
-                                       uint8_t *src, int srcstride,
64
+extern void ff_put_vp8_epel4_v4_ssse3 (uint8_t *dst, ptrdiff_t dststride,
65
+                                       uint8_t *src, ptrdiff_t srcstride,
66 66
                                        int height, int mx, int my);
67
-extern void ff_put_vp8_epel4_v6_ssse3 (uint8_t *dst, int dststride,
68
-                                       uint8_t *src, int srcstride,
67
+extern void ff_put_vp8_epel4_v6_ssse3 (uint8_t *dst, ptrdiff_t dststride,
68
+                                       uint8_t *src, ptrdiff_t srcstride,
69 69
                                        int height, int mx, int my);
70
-extern void ff_put_vp8_epel8_h4_ssse3 (uint8_t *dst, int dststride,
71
-                                       uint8_t *src, int srcstride,
70
+extern void ff_put_vp8_epel8_h4_ssse3 (uint8_t *dst, ptrdiff_t dststride,
71
+                                       uint8_t *src, ptrdiff_t srcstride,
72 72
                                        int height, int mx, int my);
73
-extern void ff_put_vp8_epel8_h6_ssse3 (uint8_t *dst, int dststride,
74
-                                       uint8_t *src, int srcstride,
73
+extern void ff_put_vp8_epel8_h6_ssse3 (uint8_t *dst, ptrdiff_t dststride,
74
+                                       uint8_t *src, ptrdiff_t srcstride,
75 75
                                        int height, int mx, int my);
76
-extern void ff_put_vp8_epel8_v4_ssse3 (uint8_t *dst, int dststride,
77
-                                       uint8_t *src, int srcstride,
76
+extern void ff_put_vp8_epel8_v4_ssse3 (uint8_t *dst, ptrdiff_t dststride,
77
+                                       uint8_t *src, ptrdiff_t srcstride,
78 78
                                        int height, int mx, int my);
79
-extern void ff_put_vp8_epel8_v6_ssse3 (uint8_t *dst, int dststride,
80
-                                       uint8_t *src, int srcstride,
79
+extern void ff_put_vp8_epel8_v6_ssse3 (uint8_t *dst, ptrdiff_t dststride,
80
+                                       uint8_t *src, ptrdiff_t srcstride,
81 81
                                        int height, int mx, int my);
82 82
 
83
-extern void ff_put_vp8_bilinear4_h_mmxext(uint8_t *dst, int dststride,
84
-                                          uint8_t *src, int srcstride,
83
+extern void ff_put_vp8_bilinear4_h_mmxext(uint8_t *dst, ptrdiff_t dststride,
84
+                                          uint8_t *src, ptrdiff_t srcstride,
85 85
                                           int height, int mx, int my);
86
-extern void ff_put_vp8_bilinear8_h_sse2  (uint8_t *dst, int dststride,
87
-                                          uint8_t *src, int srcstride,
86
+extern void ff_put_vp8_bilinear8_h_sse2  (uint8_t *dst, ptrdiff_t dststride,
87
+                                          uint8_t *src, ptrdiff_t srcstride,
88 88
                                           int height, int mx, int my);
89
-extern void ff_put_vp8_bilinear4_h_ssse3 (uint8_t *dst, int dststride,
90
-                                          uint8_t *src, int srcstride,
89
+extern void ff_put_vp8_bilinear4_h_ssse3 (uint8_t *dst, ptrdiff_t dststride,
90
+                                          uint8_t *src, ptrdiff_t srcstride,
91 91
                                           int height, int mx, int my);
92
-extern void ff_put_vp8_bilinear8_h_ssse3 (uint8_t *dst, int dststride,
93
-                                          uint8_t *src, int srcstride,
92
+extern void ff_put_vp8_bilinear8_h_ssse3 (uint8_t *dst, ptrdiff_t dststride,
93
+                                          uint8_t *src, ptrdiff_t srcstride,
94 94
                                           int height, int mx, int my);
95 95
 
96
-extern void ff_put_vp8_bilinear4_v_mmxext(uint8_t *dst, int dststride,
97
-                                          uint8_t *src, int srcstride,
96
+extern void ff_put_vp8_bilinear4_v_mmxext(uint8_t *dst, ptrdiff_t dststride,
97
+                                          uint8_t *src, ptrdiff_t srcstride,
98 98
                                           int height, int mx, int my);
99
-extern void ff_put_vp8_bilinear8_v_sse2  (uint8_t *dst, int dststride,
100
-                                          uint8_t *src, int srcstride,
99
+extern void ff_put_vp8_bilinear8_v_sse2  (uint8_t *dst, ptrdiff_t dststride,
100
+                                          uint8_t *src, ptrdiff_t srcstride,
101 101
                                           int height, int mx, int my);
102
-extern void ff_put_vp8_bilinear4_v_ssse3 (uint8_t *dst, int dststride,
103
-                                          uint8_t *src, int srcstride,
102
+extern void ff_put_vp8_bilinear4_v_ssse3 (uint8_t *dst, ptrdiff_t dststride,
103
+                                          uint8_t *src, ptrdiff_t srcstride,
104 104
                                           int height, int mx, int my);
105
-extern void ff_put_vp8_bilinear8_v_ssse3 (uint8_t *dst, int dststride,
106
-                                          uint8_t *src, int srcstride,
105
+extern void ff_put_vp8_bilinear8_v_ssse3 (uint8_t *dst, ptrdiff_t dststride,
106
+                                          uint8_t *src, ptrdiff_t srcstride,
107 107
                                           int height, int mx, int my);
108 108
 
109 109
 
110
-extern void ff_put_vp8_pixels8_mmx (uint8_t *dst, int dststride,
111
-                                    uint8_t *src, int srcstride,
110
+extern void ff_put_vp8_pixels8_mmx (uint8_t *dst, ptrdiff_t dststride,
111
+                                    uint8_t *src, ptrdiff_t srcstride,
112 112
                                     int height, int mx, int my);
113
-extern void ff_put_vp8_pixels16_mmx(uint8_t *dst, int dststride,
114
-                                    uint8_t *src, int srcstride,
113
+extern void ff_put_vp8_pixels16_mmx(uint8_t *dst, ptrdiff_t dststride,
114
+                                    uint8_t *src, ptrdiff_t srcstride,
115 115
                                     int height, int mx, int my);
116
-extern void ff_put_vp8_pixels16_sse(uint8_t *dst, int dststride,
117
-                                    uint8_t *src, int srcstride,
116
+extern void ff_put_vp8_pixels16_sse(uint8_t *dst, ptrdiff_t dststride,
117
+                                    uint8_t *src, ptrdiff_t srcstride,
118 118
                                     int height, int mx, int my);
119 119
 
120 120
 #define TAP_W16(OPT, FILTERTYPE, TAPTYPE) \
121 121
 static void ff_put_vp8_ ## FILTERTYPE ## 16_ ## TAPTYPE ## _ ## OPT( \
122
-    uint8_t *dst,  int dststride, uint8_t *src, \
123
-    int srcstride, int height, int mx, int my) \
122
+    uint8_t *dst,  ptrdiff_t dststride, uint8_t *src, \
123
+    ptrdiff_t srcstride, int height, int mx, int my) \
124 124
 { \
125 125
     ff_put_vp8_ ## FILTERTYPE ## 8_ ## TAPTYPE ## _ ## OPT( \
126 126
         dst,     dststride, src,     srcstride, height, mx, my); \
... ...
@@ -129,8 +129,8 @@ static void ff_put_vp8_ ## FILTERTYPE ## 16_ ## TAPTYPE ## _ ## OPT( \
129 129
 }
130 130
 #define TAP_W8(OPT, FILTERTYPE, TAPTYPE) \
131 131
 static void ff_put_vp8_ ## FILTERTYPE ## 8_ ## TAPTYPE ## _ ## OPT( \
132
-    uint8_t *dst,  int dststride, uint8_t *src, \
133
-    int srcstride, int height, int mx, int my) \
132
+    uint8_t *dst,  ptrdiff_t dststride, uint8_t *src, \
133
+    ptrdiff_t srcstride, int height, int mx, int my) \
134 134
 { \
135 135
     ff_put_vp8_ ## FILTERTYPE ## 4_ ## TAPTYPE ## _ ## OPT( \
136 136
         dst,     dststride, src,     srcstride, height, mx, my); \
... ...
@@ -138,6 +138,7 @@ static void ff_put_vp8_ ## FILTERTYPE ## 8_ ## TAPTYPE ## _ ## OPT( \
138 138
         dst + 4, dststride, src + 4, srcstride, height, mx, my); \
139 139
 }
140 140
 
141
+#if ARCH_X86_32
141 142
 TAP_W8 (mmxext, epel, h4)
142 143
 TAP_W8 (mmxext, epel, h6)
143 144
 TAP_W16(mmxext, epel, h6)
... ...
@@ -148,6 +149,7 @@ TAP_W8 (mmxext, bilinear, h)
148 148
 TAP_W16(mmxext, bilinear, h)
149 149
 TAP_W8 (mmxext, bilinear, v)
150 150
 TAP_W16(mmxext, bilinear, v)
151
+#endif
151 152
 
152 153
 TAP_W16(sse2,   epel, h6)
153 154
 TAP_W16(sse2,   epel, v6)
... ...
@@ -161,8 +163,8 @@ TAP_W16(ssse3,  bilinear, v)
161 161
 
162 162
 #define HVTAP(OPT, ALIGN, TAPNUMX, TAPNUMY, SIZE, MAXHEIGHT) \
163 163
 static void ff_put_vp8_epel ## SIZE ## _h ## TAPNUMX ## v ## TAPNUMY ## _ ## OPT( \
164
-    uint8_t *dst, int dststride, uint8_t *src, \
165
-    int srcstride, int height, int mx, int my) \
164
+    uint8_t *dst, ptrdiff_t dststride, uint8_t *src, \
165
+    ptrdiff_t srcstride, int height, int mx, int my) \
166 166
 { \
167 167
     DECLARE_ALIGNED(ALIGN, uint8_t, tmp)[SIZE * (MAXHEIGHT + TAPNUMY - 1)]; \
168 168
     uint8_t *tmpptr = tmp + SIZE * (TAPNUMY / 2 - 1); \
... ...
@@ -173,15 +175,21 @@ static void ff_put_vp8_epel ## SIZE ## _h ## TAPNUMX ## v ## TAPNUMY ## _ ## OPT
173 173
         dst, dststride, tmpptr, SIZE,      height,               mx, my); \
174 174
 }
175 175
 
176
+#if ARCH_X86_32
176 177
 #define HVTAPMMX(x, y) \
177 178
 HVTAP(mmxext, 8, x, y,  4,  8) \
178 179
 HVTAP(mmxext, 8, x, y,  8, 16)
179 180
 
181
+HVTAP(mmxext, 8, 6, 6, 16, 16)
182
+#else
183
+#define HVTAPMMX(x, y) \
184
+HVTAP(mmxext, 8, x, y,  4,  8)
185
+#endif
186
+
180 187
 HVTAPMMX(4, 4)
181 188
 HVTAPMMX(4, 6)
182 189
 HVTAPMMX(6, 4)
183 190
 HVTAPMMX(6, 6)
184
-HVTAP(mmxext, 8, 6, 6, 16, 16)
185 191
 
186 192
 #define HVTAPSSE2(x, y, w) \
187 193
 HVTAP(sse2,  16, x, y, w, 16) \
... ...
@@ -200,8 +208,8 @@ HVTAP(ssse3, 16, 6, 6, 4, 8)
200 200
 
201 201
 #define HVBILIN(OPT, ALIGN, SIZE, MAXHEIGHT) \
202 202
 static void ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT( \
203
-    uint8_t *dst, int dststride, uint8_t *src, \
204
-    int srcstride, int height, int mx, int my) \
203
+    uint8_t *dst, ptrdiff_t dststride, uint8_t *src, \
204
+    ptrdiff_t srcstride, int height, int mx, int my) \
205 205
 { \
206 206
     DECLARE_ALIGNED(ALIGN, uint8_t, tmp)[SIZE * (MAXHEIGHT + 2)]; \
207 207
     ff_put_vp8_bilinear ## SIZE ## _h_ ## OPT( \
... ...
@@ -211,43 +219,68 @@ static void ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT( \
211 211
 }
212 212
 
213 213
 HVBILIN(mmxext, 8,  4,  8)
214
+#if ARCH_X86_32
214 215
 HVBILIN(mmxext, 8,  8, 16)
215 216
 HVBILIN(mmxext, 8, 16, 16)
217
+#endif
216 218
 HVBILIN(sse2,   8,  8, 16)
217 219
 HVBILIN(sse2,   8, 16, 16)
218 220
 HVBILIN(ssse3,  8,  4,  8)
219 221
 HVBILIN(ssse3,  8,  8, 16)
220 222
 HVBILIN(ssse3,  8, 16, 16)
221 223
 
222
-extern void ff_vp8_idct_dc_add_mmx(uint8_t *dst, DCTELEM block[16], int stride);
223
-extern void ff_vp8_idct_dc_add_sse4(uint8_t *dst, DCTELEM block[16], int stride);
224
-extern void ff_vp8_idct_dc_add4y_mmx(uint8_t *dst, DCTELEM block[4][16], int stride);
225
-extern void ff_vp8_idct_dc_add4y_sse2(uint8_t *dst, DCTELEM block[4][16], int stride);
226
-extern void ff_vp8_idct_dc_add4uv_mmx(uint8_t *dst, DCTELEM block[2][16], int stride);
224
+extern void ff_vp8_idct_dc_add_mmx(uint8_t *dst, DCTELEM block[16],
225
+                                   ptrdiff_t stride);
226
+extern void ff_vp8_idct_dc_add_sse4(uint8_t *dst, DCTELEM block[16],
227
+                                    ptrdiff_t stride);
228
+extern void ff_vp8_idct_dc_add4y_mmx(uint8_t *dst, DCTELEM block[4][16],
229
+                                      ptrdiff_t stride);
230
+extern void ff_vp8_idct_dc_add4y_sse2(uint8_t *dst, DCTELEM block[4][16],
231
+                                      ptrdiff_t stride);
232
+extern void ff_vp8_idct_dc_add4uv_mmx(uint8_t *dst, DCTELEM block[2][16],
233
+                                      ptrdiff_t stride);
227 234
 extern void ff_vp8_luma_dc_wht_mmx(DCTELEM block[4][4][16], DCTELEM dc[16]);
228 235
 extern void ff_vp8_luma_dc_wht_sse(DCTELEM block[4][4][16], DCTELEM dc[16]);
229
-extern void ff_vp8_idct_add_mmx(uint8_t *dst, DCTELEM block[16], int stride);
230
-extern void ff_vp8_idct_add_sse(uint8_t *dst, DCTELEM block[16], int stride);
236
+extern void ff_vp8_idct_add_mmx(uint8_t *dst, DCTELEM block[16],
237
+                                ptrdiff_t stride);
238
+extern void ff_vp8_idct_add_sse(uint8_t *dst, DCTELEM block[16],
239
+                                ptrdiff_t stride);
231 240
 
232 241
 #define DECLARE_LOOP_FILTER(NAME)\
233
-extern void ff_vp8_v_loop_filter_simple_ ## NAME(uint8_t *dst, int stride, int flim);\
234
-extern void ff_vp8_h_loop_filter_simple_ ## NAME(uint8_t *dst, int stride, int flim);\
235
-extern void ff_vp8_v_loop_filter16y_inner_ ## NAME (uint8_t *dst, int stride,\
242
+extern void ff_vp8_v_loop_filter_simple_ ## NAME(uint8_t *dst, \
243
+                                                 ptrdiff_t stride, \
244
+                                                 int flim);\
245
+extern void ff_vp8_h_loop_filter_simple_ ## NAME(uint8_t *dst, \
246
+                                                 ptrdiff_t stride, \
247
+                                                 int flim);\
248
+extern void ff_vp8_v_loop_filter16y_inner_ ## NAME (uint8_t *dst, \
249
+                                                     ptrdiff_t stride,\
250
+                                                    int e, int i, int hvt);\
251
+extern void ff_vp8_h_loop_filter16y_inner_ ## NAME (uint8_t *dst, \
252
+                                                    ptrdiff_t stride,\
253
+                                                    int e, int i, int hvt);\
254
+extern void ff_vp8_v_loop_filter8uv_inner_ ## NAME (uint8_t *dstU, \
255
+                                                    uint8_t *dstV,\
256
+                                                    ptrdiff_t s, \
257
+                                                    int e, int i, int hvt);\
258
+extern void ff_vp8_h_loop_filter8uv_inner_ ## NAME (uint8_t *dstU, \
259
+                                                    uint8_t *dstV,\
260
+                                                    ptrdiff_t s, \
236 261
                                                     int e, int i, int hvt);\
237
-extern void ff_vp8_h_loop_filter16y_inner_ ## NAME (uint8_t *dst, int stride,\
262
+extern void ff_vp8_v_loop_filter16y_mbedge_ ## NAME(uint8_t *dst, \
263
+                                                    ptrdiff_t stride,\
238 264
                                                     int e, int i, int hvt);\
239
-extern void ff_vp8_v_loop_filter8uv_inner_ ## NAME (uint8_t *dstU, uint8_t *dstV,\
240
-                                                    int s, int e, int i, int hvt);\
241
-extern void ff_vp8_h_loop_filter8uv_inner_ ## NAME (uint8_t *dstU, uint8_t *dstV,\
242
-                                                    int s, int e, int i, int hvt);\
243
-extern void ff_vp8_v_loop_filter16y_mbedge_ ## NAME(uint8_t *dst, int stride,\
265
+extern void ff_vp8_h_loop_filter16y_mbedge_ ## NAME(uint8_t *dst, \
266
+                                                    ptrdiff_t stride,\
244 267
                                                     int e, int i, int hvt);\
245
-extern void ff_vp8_h_loop_filter16y_mbedge_ ## NAME(uint8_t *dst, int stride,\
268
+extern void ff_vp8_v_loop_filter8uv_mbedge_ ## NAME(uint8_t *dstU, \
269
+                                                    uint8_t *dstV,\
270
+                                                    ptrdiff_t s, \
246 271
                                                     int e, int i, int hvt);\
247
-extern void ff_vp8_v_loop_filter8uv_mbedge_ ## NAME(uint8_t *dstU, uint8_t *dstV,\
248
-                                                    int s, int e, int i, int hvt);\
249
-extern void ff_vp8_h_loop_filter8uv_mbedge_ ## NAME(uint8_t *dstU, uint8_t *dstV,\
250
-                                                    int s, int e, int i, int hvt);
272
+extern void ff_vp8_h_loop_filter8uv_mbedge_ ## NAME(uint8_t *dstU, \
273
+                                                    uint8_t *dstV,\
274
+                                                    ptrdiff_t s, \
275
+                                                    int e, int i, int hvt);
251 276
 
252 277
 DECLARE_LOOP_FILTER(mmx)
253 278
 DECLARE_LOOP_FILTER(mmxext)
... ...
@@ -288,15 +321,18 @@ av_cold void ff_vp8dsp_init_x86(VP8DSPContext* c)
288 288
 
289 289
     if (mm_flags & AV_CPU_FLAG_MMX) {
290 290
         c->vp8_idct_dc_add    = ff_vp8_idct_dc_add_mmx;
291
-        c->vp8_idct_dc_add4y  = ff_vp8_idct_dc_add4y_mmx;
292 291
         c->vp8_idct_dc_add4uv = ff_vp8_idct_dc_add4uv_mmx;
292
+#if ARCH_X86_32
293
+        c->vp8_idct_dc_add4y  = ff_vp8_idct_dc_add4y_mmx;
293 294
         c->vp8_idct_add       = ff_vp8_idct_add_mmx;
294 295
         c->vp8_luma_dc_wht    = ff_vp8_luma_dc_wht_mmx;
295 296
         c->put_vp8_epel_pixels_tab[0][0][0]     =
296 297
         c->put_vp8_bilinear_pixels_tab[0][0][0] = ff_put_vp8_pixels16_mmx;
298
+#endif
297 299
         c->put_vp8_epel_pixels_tab[1][0][0]     =
298 300
         c->put_vp8_bilinear_pixels_tab[1][0][0] = ff_put_vp8_pixels8_mmx;
299 301
 
302
+#if ARCH_X86_32
300 303
         c->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter_simple_mmx;
301 304
         c->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter_simple_mmx;
302 305
 
... ...
@@ -309,17 +345,19 @@ av_cold void ff_vp8dsp_init_x86(VP8DSPContext* c)
309 309
         c->vp8_h_loop_filter16y       = ff_vp8_h_loop_filter16y_mbedge_mmx;
310 310
         c->vp8_v_loop_filter8uv       = ff_vp8_v_loop_filter8uv_mbedge_mmx;
311 311
         c->vp8_h_loop_filter8uv       = ff_vp8_h_loop_filter8uv_mbedge_mmx;
312
+#endif
312 313
     }
313 314
 
314 315
     /* note that 4-tap width=16 functions are missing because w=16
315 316
      * is only used for luma, and luma is always a copy or sixtap. */
316 317
     if (mm_flags & AV_CPU_FLAG_MMX2) {
318
+        VP8_MC_FUNC(2, 4, mmxext);
319
+        VP8_BILINEAR_MC_FUNC(2, 4, mmxext);
320
+#if ARCH_X86_32
317 321
         VP8_LUMA_MC_FUNC(0, 16, mmxext);
318 322
         VP8_MC_FUNC(1, 8, mmxext);
319
-        VP8_MC_FUNC(2, 4, mmxext);
320 323
         VP8_BILINEAR_MC_FUNC(0, 16, mmxext);
321 324
         VP8_BILINEAR_MC_FUNC(1, 8, mmxext);
322
-        VP8_BILINEAR_MC_FUNC(2, 4, mmxext);
323 325
 
324 326
         c->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter_simple_mmxext;
325 327
         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)
333 333
         c->vp8_h_loop_filter16y       = ff_vp8_h_loop_filter16y_mbedge_mmxext;
334 334
         c->vp8_v_loop_filter8uv       = ff_vp8_v_loop_filter8uv_mbedge_mmxext;
335 335
         c->vp8_h_loop_filter8uv       = ff_vp8_h_loop_filter8uv_mbedge_mmxext;
336
+#endif
336 337
     }
337 338
 
338 339
     if (mm_flags & AV_CPU_FLAG_SSE) {
... ...
@@ -865,6 +865,7 @@ cglobal put_vp8_pixels8_mmx, 5,5
865 865
     jg .nextrow
866 866
     REP_RET
867 867
 
868
+%if ARCH_X86_32
868 869
 cglobal put_vp8_pixels16_mmx, 5,5
869 870
 .nextrow:
870 871
     movq  mm0, [r2+r3*0+0]
... ...
@@ -880,6 +881,7 @@ cglobal put_vp8_pixels16_mmx, 5,5
880 880
     sub   r4d, 2
881 881
     jg .nextrow
882 882
     REP_RET
883
+%endif
883 884
 
884 885
 cglobal put_vp8_pixels16_sse, 5,5,2
885 886
 .nextrow:
... ...
@@ -973,6 +975,7 @@ cglobal vp8_idct_dc_add_sse4, 3, 3, 6
973 973
 ; void vp8_idct_dc_add4y_<opt>(uint8_t *dst, DCTELEM block[4][16], int stride);
974 974
 ;-----------------------------------------------------------------------------
975 975
 
976
+%if ARCH_X86_32
976 977
 INIT_MMX
977 978
 cglobal vp8_idct_dc_add4y_mmx, 3, 3
978 979
     ; load data
... ...
@@ -1007,6 +1010,7 @@ cglobal vp8_idct_dc_add4y_mmx, 3, 3
1007 1007
     ADD_DC    m0, m6, 0, mova
1008 1008
     ADD_DC    m1, m7, 8, mova
1009 1009
     RET
1010
+%endif
1010 1011
 
1011 1012
 INIT_XMM
1012 1013
 cglobal vp8_idct_dc_add4y_sse2, 3, 3, 6
... ...
@@ -1152,7 +1156,9 @@ cglobal vp8_idct_add_%1, 3, 3
1152 1152
     RET
1153 1153
 %endmacro
1154 1154
 
1155
+%if ARCH_X86_32
1155 1156
 VP8_IDCT_ADD mmx
1157
+%endif
1156 1158
 VP8_IDCT_ADD sse
1157 1159
 
1158 1160
 ;-----------------------------------------------------------------------------
... ...
@@ -1217,7 +1223,9 @@ cglobal vp8_luma_dc_wht_%1, 2,3
1217 1217
 %endmacro
1218 1218
 
1219 1219
 INIT_MMX
1220
+%if ARCH_X86_32
1220 1221
 VP8_DC_WHT mmx
1222
+%endif
1221 1223
 VP8_DC_WHT sse
1222 1224
 
1223 1225
 ;-----------------------------------------------------------------------------
... ...
@@ -1610,6 +1618,7 @@ cglobal vp8_%2_loop_filter_simple_%1, 3, %3, %4
1610 1610
 %endif
1611 1611
 %endmacro
1612 1612
 
1613
+%if ARCH_X86_32
1613 1614
 INIT_MMX
1614 1615
 %define SPLATB_REG SPLATB_REG_MMX
1615 1616
 SIMPLE_LOOPFILTER mmx,    v, 4, 0
... ...
@@ -1617,6 +1626,8 @@ SIMPLE_LOOPFILTER mmx,    h, 5, 0
1617 1617
 %define SPLATB_REG SPLATB_REG_MMXEXT
1618 1618
 SIMPLE_LOOPFILTER mmxext, v, 4, 0
1619 1619
 SIMPLE_LOOPFILTER mmxext, h, 5, 0
1620
+%endif
1621
+
1620 1622
 INIT_XMM
1621 1623
 %define SPLATB_REG SPLATB_REG_SSE2
1622 1624
 %define WRITE_8W   WRITE_8W_SSE2
... ...
@@ -2118,6 +2129,7 @@ cglobal vp8_%2_loop_filter16y_inner_%1, 5, %3, %5
2118 2118
     RET
2119 2119
 %endmacro
2120 2120
 
2121
+%if ARCH_X86_32
2121 2122
 INIT_MMX
2122 2123
 %define SPLATB_REG SPLATB_REG_MMX
2123 2124
 INNER_LOOPFILTER mmx,    v, 6, 16, 0
... ...
@@ -2130,6 +2142,7 @@ INNER_LOOPFILTER mmxext, v, 6, 16, 0
2130 2130
 INNER_LOOPFILTER mmxext, h, 6, 16, 0
2131 2131
 INNER_LOOPFILTER mmxext, v, 6,  8, 0
2132 2132
 INNER_LOOPFILTER mmxext, h, 6,  8, 0
2133
+%endif
2133 2134
 
2134 2135
 INIT_XMM
2135 2136
 %define SPLATB_REG SPLATB_REG_SSE2
... ...
@@ -2814,6 +2827,7 @@ cglobal vp8_%2_loop_filter16y_mbedge_%1, 5, %3, %5
2814 2814
     RET
2815 2815
 %endmacro
2816 2816
 
2817
+%if ARCH_X86_32
2817 2818
 INIT_MMX
2818 2819
 %define SPLATB_REG SPLATB_REG_MMX
2819 2820
 MBEDGE_LOOPFILTER mmx,    v, 6, 16, 0
... ...
@@ -2826,6 +2840,7 @@ MBEDGE_LOOPFILTER mmxext, v, 6, 16, 0
2826 2826
 MBEDGE_LOOPFILTER mmxext, h, 6, 16, 0
2827 2827
 MBEDGE_LOOPFILTER mmxext, v, 6,  8, 0
2828 2828
 MBEDGE_LOOPFILTER mmxext, h, 6,  8, 0
2829
+%endif
2829 2830
 
2830 2831
 INIT_XMM
2831 2832
 %define SPLATB_REG SPLATB_REG_SSE2
... ...
@@ -45,7 +45,7 @@ static int decode_frame(AVCodecContext *avctx,
45 45
     const uint8_t *buf = avpkt->data;
46 46
     int buf_size = avpkt->size;
47 47
     VideoXLContext * const a = avctx->priv_data;
48
-    AVFrame * const p= (AVFrame*)&a->pic;
48
+    AVFrame * const p = &a->pic;
49 49
     uint8_t *Y, *U, *V;
50 50
     int i, j;
51 51
     int stride;
... ...
@@ -313,7 +313,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
313 313
         return -1;
314 314
     }
315 315
 
316
-    avctx->coded_frame = (AVFrame*)&c->pic;
316
+    avctx->coded_frame = &c->pic;
317 317
 
318 318
     return 0;
319 319
 }
... ...
@@ -188,8 +188,8 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt)
188 188
                     avs->st_video->codec->height = avs->height;
189 189
                     avs->st_video->codec->bits_per_coded_sample=avs->bits_per_sample;
190 190
                     avs->st_video->nb_frames = avs->nb_frames;
191
-                    avs->st_video->codec->time_base = (AVRational) {
192
-                    1, avs->fps};
191
+                    avs->st_video->r_frame_rate = avs->st_video->avg_frame_rate =
192
+                                                  (AVRational){avs->fps, 1};
193 193
                 }
194 194
                 return avs_read_video_packet(s, pkt, type, sub_type, size,
195 195
                                              palette, palette_size);
... ...
@@ -283,6 +283,20 @@ static int process_video_header_vp6(AVFormatContext *s)
283 283
     return 1;
284 284
 }
285 285
 
286
+static int process_video_header_cmv(AVFormatContext *s)
287
+{
288
+    EaDemuxContext *ea = s->priv_data;
289
+    int fps;
290
+
291
+    avio_skip(s->pb, 10);
292
+    fps = avio_rl16(s->pb);
293
+    if (fps)
294
+        ea->time_base = (AVRational){1, fps};
295
+    ea->video_codec = CODEC_ID_CMV;
296
+
297
+    return 0;
298
+}
299
+
286 300
 /*
287 301
  * Process EA file header
288 302
  * Returns 1 if the EA file is valid and successfully opened, 0 otherwise
... ...
@@ -330,7 +344,7 @@ static int process_ea_header(AVFormatContext *s) {
330 330
                 break;
331 331
 
332 332
             case MVIh_TAG :
333
-                ea->video_codec = CODEC_ID_CMV;
333
+                err = process_video_header_cmv(s);
334 334
                 break;
335 335
 
336 336
             case kVGT_TAG:
... ...
@@ -418,10 +432,12 @@ static int ea_read_header(AVFormatContext *s)
418 418
         if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO)
419 419
             st->need_parsing = AVSTREAM_PARSE_HEADERS;
420 420
         st->codec->codec_tag = 0;  /* no fourcc */
421
-        if (ea->time_base.num)
422
-            avpriv_set_pts_info(st, 64, ea->time_base.num, ea->time_base.den);
423 421
         st->codec->width = ea->width;
424 422
         st->codec->height = ea->height;
423
+        if (ea->time_base.num)
424
+            avpriv_set_pts_info(st, 64, ea->time_base.num, ea->time_base.den);
425
+        st->r_frame_rate = st->avg_frame_rate = (AVRational){ea->time_base.den,
426
+                                                             ea->time_base.num};
425 427
     }
426 428
 
427 429
     if (ea->audio_codec) {
... ...
@@ -1921,15 +1921,31 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
1921 1921
                 if (!track->audio.pkt_cnt) {
1922 1922
                     if (track->audio.sub_packet_cnt == 0)
1923 1923
                         track->audio.buf_timecode = timecode;
1924
-                    if (st->codec->codec_id == CODEC_ID_RA_288)
1924
+                    if (st->codec->codec_id == CODEC_ID_RA_288) {
1925
+                        if (size < cfs * h / 2) {
1926
+                            av_log(matroska->ctx, AV_LOG_ERROR,
1927
+                                   "Corrupt int4 RM-style audio packet size\n");
1928
+                            return AVERROR_INVALIDDATA;
1929
+                        }
1925 1930
                         for (x=0; x<h/2; x++)
1926 1931
                             memcpy(track->audio.buf+x*2*w+y*cfs,
1927 1932
                                    data+x*cfs, cfs);
1928
-                    else if (st->codec->codec_id == CODEC_ID_SIPR)
1933
+                    } else if (st->codec->codec_id == CODEC_ID_SIPR) {
1934
+                        if (size < w) {
1935
+                            av_log(matroska->ctx, AV_LOG_ERROR,
1936
+                                   "Corrupt sipr RM-style audio packet size\n");
1937
+                            return AVERROR_INVALIDDATA;
1938
+                        }
1929 1939
                         memcpy(track->audio.buf + y*w, data, w);
1930
-                    else
1940
+                    } else {
1941
+                        if (size < sps * w / sps) {
1942
+                            av_log(matroska->ctx, AV_LOG_ERROR,
1943
+                                   "Corrupt generic RM-style audio packet size\n");
1944
+                            return AVERROR_INVALIDDATA;
1945
+                        }
1931 1946
                         for (x=0; x<w/sps; x++)
1932 1947
                             memcpy(track->audio.buf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), data+x*sps, sps);
1948
+                    }
1933 1949
 
1934 1950
                     if (++track->audio.sub_packet_cnt >= h) {
1935 1951
                         if (st->codec->codec_id == CODEC_ID_SIPR)
... ...
@@ -84,9 +84,7 @@ ogm_header(AVFormatContext *s, int idx)
84 84
         if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){
85 85
             st->codec->width = bytestream_get_le32(&p);
86 86
             st->codec->height = bytestream_get_le32(&p);
87
-            st->codec->time_base.den = spu * 10000000;
88
-            st->codec->time_base.num = time_unit;
89
-            avpriv_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den);
87
+            avpriv_set_pts_info(st, 64, spu * 10000000, time_unit);
90 88
         } else {
91 89
             st->codec->channels = bytestream_get_le16(&p);
92 90
             p += 2;                 /* block_align */
... ...
@@ -132,8 +130,7 @@ ogm_dshow_header(AVFormatContext *s, int idx)
132 132
     if(t == 0x05589f80){
133 133
         st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
134 134
         st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(p + 68));
135
-        st->codec->time_base.den = 10000000;
136
-        st->codec->time_base.num = AV_RL64(p + 164);
135
+        avpriv_set_pts_info(st, 64, AV_RL64(p + 164), 10000000);
137 136
         st->codec->width = AV_RL32(p + 176);
138 137
         st->codec->height = AV_RL32(p + 180);
139 138
     } else if(t == 0x05589f81){
... ...
@@ -56,6 +56,7 @@ theora_header (AVFormatContext * s, int idx)
56 56
     if (os->buf[os->pstart] == 0x80) {
57 57
         GetBitContext gb;
58 58
         int width, height;
59
+        AVRational timebase;
59 60
 
60 61
         init_get_bits(&gb, os->buf + os->pstart, os->psize*8);
61 62
 
... ...
@@ -85,14 +86,14 @@ theora_header (AVFormatContext * s, int idx)
85 85
 
86 86
             skip_bits(&gb, 16);
87 87
         }
88
-        st->codec->time_base.den = get_bits_long(&gb, 32);
89
-        st->codec->time_base.num = get_bits_long(&gb, 32);
90
-        if (!(st->codec->time_base.num > 0 && st->codec->time_base.den > 0)) {
88
+        timebase.den = get_bits_long(&gb, 32);
89
+        timebase.num = get_bits_long(&gb, 32);
90
+        if (!(timebase.num > 0 && timebase.den > 0)) {
91 91
             av_log(s, AV_LOG_WARNING, "Invalid time base in theora stream, assuming 25 FPS\n");
92
-            st->codec->time_base.num = 1;
93
-            st->codec->time_base.den = 25;
92
+            timebase.num = 1;
93
+            timebase.den = 25;
94 94
         }
95
-        avpriv_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den);
95
+        avpriv_set_pts_info(st, 64, timebase.num, timebase.den);
96 96
 
97 97
         st->sample_aspect_ratio.num = get_bits_long(&gb, 24);
98 98
         st->sample_aspect_ratio.den = get_bits_long(&gb, 24);
... ...
@@ -57,6 +57,7 @@ static int r3d_read_red1(AVFormatContext *s)
57 57
     char filename[258];
58 58
     int tmp;
59 59
     int av_unused tmp2;
60
+    AVRational framerate;
60 61
 
61 62
     if (!st)
62 63
         return AVERROR(ENOMEM);
... ...
@@ -84,8 +85,10 @@ static int r3d_read_red1(AVFormatContext *s)
84 84
     tmp = avio_rb16(s->pb); // unknown
85 85
     av_dlog(s, "unknown2 %d\n", tmp);
86 86
 
87
-    st->codec->time_base.den = avio_rb16(s->pb);
88
-    st->codec->time_base.num = avio_rb16(s->pb);
87
+    framerate.num = avio_rb16(s->pb);
88
+    framerate.den = avio_rb16(s->pb);
89
+    if (framerate.num && framerate.den)
90
+        st->r_frame_rate = st->avg_frame_rate = framerate;
89 91
 
90 92
     tmp = avio_r8(s->pb); // audio channels
91 93
     av_dlog(s, "audio channels %d\n", tmp);
... ...
@@ -107,7 +110,7 @@ static int r3d_read_red1(AVFormatContext *s)
107 107
     av_dlog(s, "resolution %dx%d\n", st->codec->width, st->codec->height);
108 108
     av_dlog(s, "timescale %d\n", st->time_base.den);
109 109
     av_dlog(s, "frame rate %d/%d\n",
110
-            st->codec->time_base.num, st->codec->time_base.den);
110
+            framerate.num, framerate.den);
111 111
 
112 112
     return 0;
113 113
 }
... ...
@@ -132,9 +135,11 @@ static int r3d_read_rdvo(AVFormatContext *s, Atom *atom)
132 132
         av_dlog(s, "video offset %d: %#x\n", i, r3d->video_offsets[i]);
133 133
     }
134 134
 
135
-    if (st->codec->time_base.den)
136
-        st->duration = (uint64_t)r3d->video_offsets_count*
137
-            st->time_base.den*st->codec->time_base.num/st->codec->time_base.den;
135
+    if (st->r_frame_rate.num)
136
+        st->duration = av_rescale_q(r3d->video_offsets_count,
137
+                                    (AVRational){st->r_frame_rate.den,
138
+                                                 st->r_frame_rate.num},
139
+                                    st->time_base);
138 140
     av_dlog(s, "duration %"PRId64"\n", st->duration);
139 141
 
140 142
     return 0;
... ...
@@ -257,9 +262,9 @@ static int r3d_read_redv(AVFormatContext *s, AVPacket *pkt, Atom *atom)
257 257
 
258 258
     pkt->stream_index = 0;
259 259
     pkt->dts = dts;
260
-    if (st->codec->time_base.den)
260
+    if (st->r_frame_rate.num)
261 261
         pkt->duration = (uint64_t)st->time_base.den*
262
-            st->codec->time_base.num/st->codec->time_base.den;
262
+            st->r_frame_rate.den/st->r_frame_rate.num;
263 263
     av_dlog(s, "pkt dts %"PRId64" duration %d\n", pkt->dts, pkt->duration);
264 264
 
265 265
     return 0;
... ...
@@ -357,11 +362,11 @@ static int r3d_seek(AVFormatContext *s, int stream_index, int64_t sample_time, i
357 357
     R3DContext *r3d = s->priv_data;
358 358
     int frame_num;
359 359
 
360
-    if (!st->codec->time_base.num || !st->time_base.den)
360
+    if (!st->r_frame_rate.num)
361 361
         return -1;
362 362
 
363
-    frame_num = sample_time*st->codec->time_base.den/
364
-        ((int64_t)st->codec->time_base.num*st->time_base.den);
363
+    frame_num = av_rescale_q(sample_time, st->time_base,
364
+                             (AVRational){st->r_frame_rate.den, st->r_frame_rate.num});
365 365
     av_dlog(s, "seek frame num %d timestamp %"PRId64"\n",
366 366
             frame_num, sample_time);
367 367
 
... ...
@@ -439,10 +439,8 @@ static int rm_read_header(AVFormatContext *s)
439 439
         return AVERROR(EIO);
440 440
     }
441 441
 
442
-    avio_rb32(pb); /* header size */
443
-    avio_rb16(pb);
444
-    avio_rb32(pb);
445
-    avio_rb32(pb); /* number of headers */
442
+    tag_size = avio_rb32(pb);
443
+    avio_skip(pb, tag_size - 8);
446 444
 
447 445
     for(;;) {
448 446
         if (url_feof(pb))
... ...
@@ -21,75 +21,76 @@
21 21
  */
22 22
 
23 23
 /*
24
-Convert I420 YV12 to RGB in various formats,
25
-  it rejects images that are not in 420 formats,
26
-  it rejects images that don't have widths of multiples of 16,
27
-  it rejects images that don't have heights of multiples of 2.
28
-Reject defers to C simulation code.
29
-
30
-Lots of optimizations to be done here.
31
-
32
-1. Need to fix saturation code. I just couldn't get it to fly with packs
33
-   and adds, so we currently use max/min to clip.
34
-
35
-2. The inefficient use of chroma loading needs a bit of brushing up.
36
-
37
-3. Analysis of pipeline stalls needs to be done. Use shark to identify
38
-   pipeline stalls.
39
-
40
-
41
-MODIFIED to calculate coeffs from currently selected color space.
42
-MODIFIED core to be a macro where you specify the output format.
43
-ADDED UYVY conversion which is never called due to some thing in swscale.
44
-CORRECTED algorithim selection to be strict on input formats.
45
-ADDED runtime detection of AltiVec.
46
-
47
-ADDED altivec_yuv2packedX vertical scl + RGB converter
48
-
49
-March 27,2004
50
-PERFORMANCE ANALYSIS
51
-
52
-The C version uses 25% of the processor or ~250Mips for D1 video rawvideo
53
-used as test.
54
-The AltiVec version uses 10% of the processor or ~100Mips for D1 video
55
-same sequence.
56
-
57
-720 * 480 * 30  ~10MPS
58
-
59
-so we have roughly 10 clocks per pixel. This is too high, something has
60
-to be wrong.
61
-
62
-OPTIMIZED clip codes to utilize vec_max and vec_packs removing the
63
-need for vec_min.
64
-
65
-OPTIMIZED DST OUTPUT cache/DMA controls. We are pretty much guaranteed to have
66
-the input video frame, it was just decompressed so it probably resides in L1
67
-caches. However, we are creating the output video stream. This needs to use the
68
-DSTST instruction to optimize for the cache. We couple this with the fact that
69
-we are not going to be visiting the input buffer again so we mark it Least
70
-Recently Used. This shaves 25% of the processor cycles off.
71
-
72
-Now memcpy is the largest mips consumer in the system, probably due
73
-to the inefficient X11 stuff.
74
-
75
-GL libraries seem to be very slow on this machine 1.33Ghz PB running
76
-Jaguar, this is not the case for my 1Ghz PB.  I thought it might be
77
-a versioning issue, however I have libGL.1.2.dylib for both
78
-machines. (We need to figure this out now.)
79
-
80
-GL2 libraries work now with patch for RGB32.
81
-
82
-NOTE: quartz vo driver ARGB32_to_RGB24 consumes 30% of the processor.
83
-
84
-Integrated luma prescaling adjustment for saturation/contrast/brightness
85
-adjustment.
86
-*/
24
+ * Convert I420 YV12 to RGB in various formats,
25
+ * it rejects images that are not in 420 formats,
26
+ * it rejects images that don't have widths of multiples of 16,
27
+ * it rejects images that don't have heights of multiples of 2.
28
+ * Reject defers to C simulation code.
29
+ *
30
+ * Lots of optimizations to be done here.
31
+ *
32
+ * 1. Need to fix saturation code. I just couldn't get it to fly with packs
33
+ * and adds, so we currently use max/min to clip.
34
+ *
35
+ * 2. The inefficient use of chroma loading needs a bit of brushing up.
36
+ *
37
+ * 3. Analysis of pipeline stalls needs to be done. Use shark to identify
38
+ * pipeline stalls.
39
+ *
40
+ *
41
+ * MODIFIED to calculate coeffs from currently selected color space.
42
+ * MODIFIED core to be a macro where you specify the output format.
43
+ * ADDED UYVY conversion which is never called due to some thing in swscale.
44
+ * CORRECTED algorithim selection to be strict on input formats.
45
+ * ADDED runtime detection of AltiVec.
46
+ *
47
+ * ADDED altivec_yuv2packedX vertical scl + RGB converter
48
+ *
49
+ * March 27,2004
50
+ * PERFORMANCE ANALYSIS
51
+ *
52
+ * The C version uses 25% of the processor or ~250Mips for D1 video rawvideo
53
+ * used as test.
54
+ * The AltiVec version uses 10% of the processor or ~100Mips for D1 video
55
+ * same sequence.
56
+ *
57
+ * 720 * 480 * 30  ~10MPS
58
+ *
59
+ * so we have roughly 10 clocks per pixel. This is too high, something has
60
+ * to be wrong.
61
+ *
62
+ * OPTIMIZED clip codes to utilize vec_max and vec_packs removing the
63
+ * need for vec_min.
64
+ *
65
+ * OPTIMIZED DST OUTPUT cache/DMA controls. We are pretty much guaranteed to
66
+ * have the input video frame, it was just decompressed so it probably resides
67
+ * in L1 caches. However, we are creating the output video stream. This needs
68
+ * to use the DSTST instruction to optimize for the cache. We couple this with
69
+ * the fact that we are not going to be visiting the input buffer again so we
70
+ * mark it Least Recently Used. This shaves 25% of the processor cycles off.
71
+ *
72
+ * Now memcpy is the largest mips consumer in the system, probably due
73
+ * to the inefficient X11 stuff.
74
+ *
75
+ * GL libraries seem to be very slow on this machine 1.33Ghz PB running
76
+ * Jaguar, this is not the case for my 1Ghz PB.  I thought it might be
77
+ * a versioning issue, however I have libGL.1.2.dylib for both
78
+ * machines. (We need to figure this out now.)
79
+ *
80
+ * GL2 libraries work now with patch for RGB32.
81
+ *
82
+ * NOTE: quartz vo driver ARGB32_to_RGB24 consumes 30% of the processor.
83
+ *
84
+ * Integrated luma prescaling adjustment for saturation/contrast/brightness
85
+ * adjustment.
86
+ */
87 87
 
88 88
 #include <stdio.h>
89 89
 #include <stdlib.h>
90 90
 #include <string.h>
91 91
 #include <inttypes.h>
92 92
 #include <assert.h>
93
+
93 94
 #include "config.h"
94 95
 #include "libswscale/rgb2rgb.h"
95 96
 #include "libswscale/swscale.h"
... ...
@@ -104,456 +105,451 @@ adjustment.
104 104
 typedef unsigned char ubyte;
105 105
 typedef signed char   sbyte;
106 106
 
107
-
108 107
 /* RGB interleaver, 16 planar pels 8-bit samples per channel in
109
-   homogeneous vector registers x0,x1,x2 are interleaved with the
110
-   following technique:
111
-
112
-      o0 = vec_mergeh (x0,x1);
113
-      o1 = vec_perm (o0, x2, perm_rgb_0);
114
-      o2 = vec_perm (o0, x2, perm_rgb_1);
115
-      o3 = vec_mergel (x0,x1);
116
-      o4 = vec_perm (o3,o2,perm_rgb_2);
117
-      o5 = vec_perm (o3,o2,perm_rgb_3);
118
-
119
-  perm_rgb_0:   o0(RG).h v1(B) --> o1*
120
-              0   1  2   3   4
121
-             rgbr|gbrg|brgb|rgbr
122
-             0010 0100 1001 0010
123
-             0102 3145 2673 894A
124
-
125
-  perm_rgb_1:   o0(RG).h v1(B) --> o2
126
-              0   1  2   3   4
127
-             gbrg|brgb|bbbb|bbbb
128
-             0100 1001 1111 1111
129
-             B5CD 6EF7 89AB CDEF
130
-
131
-  perm_rgb_2:   o3(RG).l o2(rgbB.l) --> o4*
132
-              0   1  2   3   4
133
-             gbrg|brgb|rgbr|gbrg
134
-             1111 1111 0010 0100
135
-             89AB CDEF 0182 3945
136
-
137
-  perm_rgb_2:   o3(RG).l o2(rgbB.l) ---> o5*
138
-              0   1  2   3   4
139
-             brgb|rgbr|gbrg|brgb
140
-             1001 0010 0100 1001
141
-             a67b 89cA BdCD eEFf
142
-
143
-*/
144
-static
145
-const vector unsigned char
146
-  perm_rgb_0 = {0x00,0x01,0x10,0x02,0x03,0x11,0x04,0x05,
147
-                0x12,0x06,0x07,0x13,0x08,0x09,0x14,0x0a},
148
-  perm_rgb_1 = {0x0b,0x15,0x0c,0x0d,0x16,0x0e,0x0f,0x17,
149
-                0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f},
150
-  perm_rgb_2 = {0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,
151
-                0x00,0x01,0x18,0x02,0x03,0x19,0x04,0x05},
152
-  perm_rgb_3 = {0x1a,0x06,0x07,0x1b,0x08,0x09,0x1c,0x0a,
153
-                0x0b,0x1d,0x0c,0x0d,0x1e,0x0e,0x0f,0x1f};
154
-
155
-#define vec_merge3(x2,x1,x0,y0,y1,y2)       \
156
-do {                                        \
157
-    __typeof__(x0) o0,o2,o3;                \
158
-        o0 = vec_mergeh (x0,x1);            \
159
-        y0 = vec_perm (o0, x2, perm_rgb_0); \
160
-        o2 = vec_perm (o0, x2, perm_rgb_1); \
161
-        o3 = vec_mergel (x0,x1);            \
162
-        y1 = vec_perm (o3,o2,perm_rgb_2);   \
163
-        y2 = vec_perm (o3,o2,perm_rgb_3);   \
164
-} while(0)
165
-
166
-#define vec_mstbgr24(x0,x1,x2,ptr)      \
167
-do {                                    \
168
-    __typeof__(x0) _0,_1,_2;            \
169
-    vec_merge3 (x0,x1,x2,_0,_1,_2);     \
170
-    vec_st (_0, 0, ptr++);              \
171
-    vec_st (_1, 0, ptr++);              \
172
-    vec_st (_2, 0, ptr++);              \
173
-}  while (0)
174
-
175
-#define vec_mstrgb24(x0,x1,x2,ptr)      \
176
-do {                                    \
177
-    __typeof__(x0) _0,_1,_2;            \
178
-    vec_merge3 (x2,x1,x0,_0,_1,_2);     \
179
-    vec_st (_0, 0, ptr++);              \
180
-    vec_st (_1, 0, ptr++);              \
181
-    vec_st (_2, 0, ptr++);              \
182
-}  while (0)
108
+ * homogeneous vector registers x0,x1,x2 are interleaved with the
109
+ * following technique:
110
+ *
111
+ *    o0 = vec_mergeh(x0, x1);
112
+ *    o1 = vec_perm(o0, x2, perm_rgb_0);
113
+ *    o2 = vec_perm(o0, x2, perm_rgb_1);
114
+ *    o3 = vec_mergel(x0, x1);
115
+ *    o4 = vec_perm(o3, o2, perm_rgb_2);
116
+ *    o5 = vec_perm(o3, o2, perm_rgb_3);
117
+ *
118
+ * perm_rgb_0:   o0(RG).h v1(B) --> o1*
119
+ *            0   1  2   3   4
120
+ *           rgbr|gbrg|brgb|rgbr
121
+ *           0010 0100 1001 0010
122
+ *           0102 3145 2673 894A
123
+ *
124
+ * perm_rgb_1:   o0(RG).h v1(B) --> o2
125
+ *            0   1  2   3   4
126
+ *           gbrg|brgb|bbbb|bbbb
127
+ *           0100 1001 1111 1111
128
+ *           B5CD 6EF7 89AB CDEF
129
+ *
130
+ * perm_rgb_2:   o3(RG).l o2(rgbB.l) --> o4*
131
+ *            0   1  2   3   4
132
+ *           gbrg|brgb|rgbr|gbrg
133
+ *           1111 1111 0010 0100
134
+ *           89AB CDEF 0182 3945
135
+ *
136
+ * perm_rgb_2:   o3(RG).l o2(rgbB.l) ---> o5*
137
+ *            0   1  2   3   4
138
+ *           brgb|rgbr|gbrg|brgb
139
+ *           1001 0010 0100 1001
140
+ *           a67b 89cA BdCD eEFf
141
+ *
142
+ */
143
+static const vector unsigned char
144
+    perm_rgb_0 = { 0x00, 0x01, 0x10, 0x02, 0x03, 0x11, 0x04, 0x05,
145
+                   0x12, 0x06, 0x07, 0x13, 0x08, 0x09, 0x14, 0x0a },
146
+    perm_rgb_1 = { 0x0b, 0x15, 0x0c, 0x0d, 0x16, 0x0e, 0x0f, 0x17,
147
+                   0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
148
+    perm_rgb_2 = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
149
+                   0x00, 0x01, 0x18, 0x02, 0x03, 0x19, 0x04, 0x05 },
150
+    perm_rgb_3 = { 0x1a, 0x06, 0x07, 0x1b, 0x08, 0x09, 0x1c, 0x0a,
151
+                   0x0b, 0x1d, 0x0c, 0x0d, 0x1e, 0x0e, 0x0f, 0x1f };
152
+
153
+#define vec_merge3(x2, x1, x0, y0, y1, y2)     \
154
+    do {                                       \
155
+        __typeof__(x0) o0, o2, o3;             \
156
+        o0 = vec_mergeh(x0, x1);               \
157
+        y0 = vec_perm(o0, x2, perm_rgb_0);     \
158
+        o2 = vec_perm(o0, x2, perm_rgb_1);     \
159
+        o3 = vec_mergel(x0, x1);               \
160
+        y1 = vec_perm(o3, o2, perm_rgb_2);     \
161
+        y2 = vec_perm(o3, o2, perm_rgb_3);     \
162
+    } while (0)
163
+
164
+#define vec_mstbgr24(x0, x1, x2, ptr)          \
165
+    do {                                       \
166
+        __typeof__(x0) _0, _1, _2;             \
167
+        vec_merge3(x0, x1, x2, _0, _1, _2);    \
168
+        vec_st(_0, 0, ptr++);                  \
169
+        vec_st(_1, 0, ptr++);                  \
170
+        vec_st(_2, 0, ptr++);                  \
171
+    } while (0)
172
+
173
+#define vec_mstrgb24(x0, x1, x2, ptr)          \
174
+    do {                                       \
175
+        __typeof__(x0) _0, _1, _2;             \
176
+        vec_merge3(x2, x1, x0, _0, _1, _2);    \
177
+        vec_st(_0, 0, ptr++);                  \
178
+        vec_st(_1, 0, ptr++);                  \
179
+        vec_st(_2, 0, ptr++);                  \
180
+    } while (0)
183 181
 
184 182
 /* pack the pixels in rgb0 format
185
-   msb R
186
-   lsb 0
187
-*/
188
-#define vec_mstrgb32(T,x0,x1,x2,x3,ptr)                                       \
189
-do {                                                                          \
190
-    T _0,_1,_2,_3;                                                            \
191
-    _0 = vec_mergeh (x0,x1);                                                  \
192
-    _1 = vec_mergeh (x2,x3);                                                  \
193
-    _2 = (T)vec_mergeh ((vector unsigned short)_0,(vector unsigned short)_1); \
194
-    _3 = (T)vec_mergel ((vector unsigned short)_0,(vector unsigned short)_1); \
195
-    vec_st (_2, 0*16, (T *)ptr);                                              \
196
-    vec_st (_3, 1*16, (T *)ptr);                                              \
197
-    _0 = vec_mergel (x0,x1);                                                  \
198
-    _1 = vec_mergel (x2,x3);                                                  \
199
-    _2 = (T)vec_mergeh ((vector unsigned short)_0,(vector unsigned short)_1); \
200
-    _3 = (T)vec_mergel ((vector unsigned short)_0,(vector unsigned short)_1); \
201
-    vec_st (_2, 2*16, (T *)ptr);                                              \
202
-    vec_st (_3, 3*16, (T *)ptr);                                              \
203
-    ptr += 4;                                                                 \
204
-}  while (0)
183
+ * msb R
184
+ * lsb 0
185
+ */
186
+#define vec_mstrgb32(T, x0, x1, x2, x3, ptr)                            \
187
+    do {                                                                \
188
+        T _0, _1, _2, _3;                                               \
189
+        _0 = vec_mergeh(x0, x1);                                        \
190
+        _1 = vec_mergeh(x2, x3);                                        \
191
+        _2 = (T) vec_mergeh((vector unsigned short) _0,                 \
192
+                            (vector unsigned short) _1);                \
193
+        _3 = (T) vec_mergel((vector unsigned short) _0,                 \
194
+                            (vector unsigned short) _1);                \
195
+        vec_st(_2, 0 * 16, (T *) ptr);                                  \
196
+        vec_st(_3, 1 * 16, (T *) ptr);                                  \
197
+        _0 = vec_mergel(x0, x1);                                        \
198
+        _1 = vec_mergel(x2, x3);                                        \
199
+        _2 = (T) vec_mergeh((vector unsigned short) _0,                 \
200
+                            (vector unsigned short) _1);                \
201
+        _3 = (T) vec_mergel((vector unsigned short) _0,                 \
202
+                            (vector unsigned short) _1);                \
203
+        vec_st(_2, 2 * 16, (T *) ptr);                                  \
204
+        vec_st(_3, 3 * 16, (T *) ptr);                                  \
205
+        ptr += 4;                                                       \
206
+    } while (0)
205 207
 
206 208
 /*
209
+ * 1     0       1.4021   | | Y |
210
+ * 1    -0.3441 -0.7142   |x| Cb|
211
+ * 1     1.7718  0        | | Cr|
212
+ *
213
+ *
214
+ * Y:      [-128 127]
215
+ * Cb/Cr : [-128 127]
216
+ *
217
+ * typical YUV conversion works on Y: 0-255 this version has been
218
+ * optimized for JPEG decoding.
219
+ */
207 220
 
208
-  | 1     0       1.4021   | | Y |
209
-  | 1    -0.3441 -0.7142   |x| Cb|
210
-  | 1     1.7718  0        | | Cr|
211
-
212
-
213
-  Y:      [-128 127]
214
-  Cb/Cr : [-128 127]
215
-
216
-  typical yuv conversion work on Y: 0-255 this version has been optimized for jpeg decode.
217
-
218
-*/
219
-
220
-
221
-
222
-
223
-#define vec_unh(x) \
224
-    (vector signed short) \
225
-        vec_perm(x,(__typeof__(x)){0}, \
226
-                 ((vector unsigned char){0x10,0x00,0x10,0x01,0x10,0x02,0x10,0x03,\
227
-                                         0x10,0x04,0x10,0x05,0x10,0x06,0x10,0x07}))
228
-#define vec_unl(x) \
229
-    (vector signed short) \
230
-        vec_perm(x,(__typeof__(x)){0}, \
231
-                 ((vector unsigned char){0x10,0x08,0x10,0x09,0x10,0x0A,0x10,0x0B,\
232
-                                         0x10,0x0C,0x10,0x0D,0x10,0x0E,0x10,0x0F}))
233
-
234
-#define vec_clip_s16(x) \
235
-    vec_max (vec_min (x, ((vector signed short){235,235,235,235,235,235,235,235})), \
236
-                         ((vector signed short){ 16, 16, 16, 16, 16, 16, 16, 16}))
237
-
238
-#define vec_packclp(x,y) \
239
-    (vector unsigned char)vec_packs \
240
-        ((vector unsigned short)vec_max (x,((vector signed short) {0})), \
241
-         (vector unsigned short)vec_max (y,((vector signed short) {0})))
242
-
243
-//#define out_pixels(a,b,c,ptr) vec_mstrgb32(__typeof__(a),((__typeof__ (a)){255}),a,a,a,ptr)
244
-
245
-
246
-static inline void cvtyuvtoRGB (SwsContext *c,
247
-                                vector signed short Y, vector signed short U, vector signed short V,
248
-                                vector signed short *R, vector signed short *G, vector signed short *B)
221
+#define vec_unh(x)                                                      \
222
+    (vector signed short)                                               \
223
+        vec_perm(x, (__typeof__(x)) { 0 },                              \
224
+                 ((vector unsigned char) {                              \
225
+                     0x10, 0x00, 0x10, 0x01, 0x10, 0x02, 0x10, 0x03,    \
226
+                     0x10, 0x04, 0x10, 0x05, 0x10, 0x06, 0x10, 0x07 }))
227
+
228
+#define vec_unl(x)                                                      \
229
+    (vector signed short)                                               \
230
+        vec_perm(x, (__typeof__(x)) { 0 },                              \
231
+                 ((vector unsigned char) {                              \
232
+                     0x10, 0x08, 0x10, 0x09, 0x10, 0x0A, 0x10, 0x0B,    \
233
+                     0x10, 0x0C, 0x10, 0x0D, 0x10, 0x0E, 0x10, 0x0F }))
234
+
235
+#define vec_clip_s16(x)                                                 \
236
+    vec_max(vec_min(x, ((vector signed short) {                         \
237
+                    235, 235, 235, 235, 235, 235, 235, 235 })),         \
238
+            ((vector signed short) { 16, 16, 16, 16, 16, 16, 16, 16 }))
239
+
240
+#define vec_packclp(x, y)                                               \
241
+    (vector unsigned char)                                              \
242
+        vec_packs((vector unsigned short)                               \
243
+                      vec_max(x, ((vector signed short) { 0 })),        \
244
+                  (vector unsigned short)                               \
245
+                      vec_max(y, ((vector signed short) { 0 })))
246
+
247
+//#define out_pixels(a, b, c, ptr) vec_mstrgb32(__typeof__(a), ((__typeof__(a)) { 255 }), a, a, a, ptr)
248
+
249
+static inline void cvtyuvtoRGB(SwsContext *c, vector signed short Y,
250
+                               vector signed short U, vector signed short V,
251
+                               vector signed short *R, vector signed short *G,
252
+                               vector signed short *B)
249 253
 {
250
-    vector signed   short vx,ux,uvx;
254
+    vector signed short vx, ux, uvx;
251 255
 
252
-    Y = vec_mradds (Y, c->CY, c->OY);
253
-    U  = vec_sub (U,(vector signed short)
254
-                    vec_splat((vector signed short){128},0));
255
-    V  = vec_sub (V,(vector signed short)
256
-                    vec_splat((vector signed short){128},0));
256
+    Y = vec_mradds(Y, c->CY, c->OY);
257
+    U = vec_sub(U, (vector signed short)
258
+                       vec_splat((vector signed short) { 128 }, 0));
259
+    V = vec_sub(V, (vector signed short)
260
+                       vec_splat((vector signed short) { 128 }, 0));
257 261
 
258
-    //   ux  = (CBU*(u<<c->CSHIFT)+0x4000)>>15;
259
-    ux = vec_sl (U, c->CSHIFT);
260
-    *B = vec_mradds (ux, c->CBU, Y);
262
+    // ux  = (CBU * (u << c->CSHIFT) + 0x4000) >> 15;
263
+    ux = vec_sl(U, c->CSHIFT);
264
+    *B = vec_mradds(ux, c->CBU, Y);
261 265
 
262
-    // vx  = (CRV*(v<<c->CSHIFT)+0x4000)>>15;
263
-    vx = vec_sl (V, c->CSHIFT);
264
-    *R = vec_mradds (vx, c->CRV, Y);
266
+    // vx  = (CRV * (v << c->CSHIFT) + 0x4000) >> 15;
267
+    vx = vec_sl(V, c->CSHIFT);
268
+    *R = vec_mradds(vx, c->CRV, Y);
265 269
 
266
-    // uvx = ((CGU*u) + (CGV*v))>>15;
267
-    uvx = vec_mradds (U, c->CGU, Y);
268
-    *G  = vec_mradds (V, c->CGV, uvx);
270
+    // uvx = ((CGU * u) + (CGV * v)) >> 15;
271
+    uvx = vec_mradds(U, c->CGU, Y);
272
+    *G  = vec_mradds(V, c->CGV, uvx);
269 273
 }
270 274
 
271
-
272 275
 /*
273
-  ------------------------------------------------------------------------------
274
-  CS converters
275
-  ------------------------------------------------------------------------------
276
-*/
277
-
276
+ * ------------------------------------------------------------------------------
277
+ * CS converters
278
+ * ------------------------------------------------------------------------------
279
+ */
278 280
 
279
-#define DEFCSP420_CVT(name,out_pixels)                                  \
280
-static int altivec_##name (SwsContext *c,                               \
281
-                           const unsigned char **in, int *instrides,    \
282
-                           int srcSliceY,        int srcSliceH,         \
283
-                           unsigned char **oplanes, int *outstrides)    \
284
-{                                                                       \
285
-    int w = c->srcW;                                                    \
286
-    int h = srcSliceH;                                                  \
287
-    int i,j;                                                            \
288
-    int instrides_scl[3];                                               \
289
-    vector unsigned char y0,y1;                                         \
290
-                                                                        \
291
-    vector signed char  u,v;                                            \
292
-                                                                        \
293
-    vector signed short Y0,Y1,Y2,Y3;                                    \
294
-    vector signed short U,V;                                            \
295
-    vector signed short vx,ux,uvx;                                      \
296
-    vector signed short vx0,ux0,uvx0;                                   \
297
-    vector signed short vx1,ux1,uvx1;                                   \
298
-    vector signed short R0,G0,B0;                                       \
299
-    vector signed short R1,G1,B1;                                       \
300
-    vector unsigned char R,G,B;                                         \
301
-                                                                        \
302
-    const vector unsigned char *y1ivP, *y2ivP, *uivP, *vivP;            \
303
-    vector unsigned char align_perm;                                    \
304
-                                                                        \
305
-    vector signed short                                                 \
306
-        lCY  = c->CY,                                                   \
307
-        lOY  = c->OY,                                                   \
308
-        lCRV = c->CRV,                                                  \
309
-        lCBU = c->CBU,                                                  \
310
-        lCGU = c->CGU,                                                  \
311
-        lCGV = c->CGV;                                                  \
312
-                                                                        \
313
-    vector unsigned short lCSHIFT = c->CSHIFT;                          \
314
-                                                                        \
315
-    const ubyte *y1i   = in[0];                                         \
316
-    const ubyte *y2i   = in[0]+instrides[0];                            \
317
-    const ubyte *ui    = in[1];                                         \
318
-    const ubyte *vi    = in[2];                                         \
319
-                                                                        \
320
-    vector unsigned char *oute                                          \
321
-        = (vector unsigned char *)                                      \
322
-            (oplanes[0]+srcSliceY*outstrides[0]);                       \
323
-    vector unsigned char *outo                                          \
324
-        = (vector unsigned char *)                                      \
325
-            (oplanes[0]+srcSliceY*outstrides[0]+outstrides[0]);         \
326
-                                                                        \
327
-                                                                        \
328
-    instrides_scl[0] = instrides[0]*2-w;  /* the loop moves y{1,2}i by w */ \
329
-    instrides_scl[1] = instrides[1]-w/2;  /* the loop moves ui by w/2 */    \
330
-    instrides_scl[2] = instrides[2]-w/2;  /* the loop moves vi by w/2 */    \
331
-                                                                        \
332
-                                                                        \
333
-    for (i=0;i<h/2;i++) {                                               \
334
-        vec_dstst (outo, (0x02000002|(((w*3+32)/32)<<16)), 0);          \
335
-        vec_dstst (oute, (0x02000002|(((w*3+32)/32)<<16)), 1);          \
336
-                                                                        \
337
-        for (j=0;j<w/16;j++) {                                          \
338
-                                                                        \
339
-            y1ivP = (const vector unsigned char *)y1i;                  \
340
-            y2ivP = (const vector unsigned char *)y2i;                  \
341
-            uivP  = (const vector unsigned char *)ui;                   \
342
-            vivP  = (const vector unsigned char *)vi;                   \
343
-                                                                        \
344
-            align_perm = vec_lvsl (0, y1i);                             \
345
-            y0 = (vector unsigned char)                                 \
346
-                 vec_perm (y1ivP[0], y1ivP[1], align_perm);             \
347
-                                                                        \
348
-            align_perm = vec_lvsl (0, y2i);                             \
349
-            y1 = (vector unsigned char)                                 \
350
-                 vec_perm (y2ivP[0], y2ivP[1], align_perm);             \
351
-                                                                        \
352
-            align_perm = vec_lvsl (0, ui);                              \
353
-            u = (vector signed char)                                    \
354
-                vec_perm (uivP[0], uivP[1], align_perm);                \
355
-                                                                        \
356
-            align_perm = vec_lvsl (0, vi);                              \
357
-            v = (vector signed char)                                    \
358
-                vec_perm (vivP[0], vivP[1], align_perm);                \
359
-                                                                        \
360
-            u  = (vector signed char)                                   \
361
-                 vec_sub (u,(vector signed char)                        \
362
-                          vec_splat((vector signed char){128},0));      \
363
-            v  = (vector signed char)                                   \
364
-                 vec_sub (v,(vector signed char)                        \
365
-                          vec_splat((vector signed char){128},0));      \
366
-                                                                        \
367
-            U  = vec_unpackh (u);                                       \
368
-            V  = vec_unpackh (v);                                       \
369
-                                                                        \
370
-                                                                        \
371
-            Y0 = vec_unh (y0);                                          \
372
-            Y1 = vec_unl (y0);                                          \
373
-            Y2 = vec_unh (y1);                                          \
374
-            Y3 = vec_unl (y1);                                          \
375
-                                                                        \
376
-            Y0 = vec_mradds (Y0, lCY, lOY);                             \
377
-            Y1 = vec_mradds (Y1, lCY, lOY);                             \
378
-            Y2 = vec_mradds (Y2, lCY, lOY);                             \
379
-            Y3 = vec_mradds (Y3, lCY, lOY);                             \
380
-                                                                        \
381
-            /*   ux  = (CBU*(u<<CSHIFT)+0x4000)>>15 */                  \
382
-            ux = vec_sl (U, lCSHIFT);                                   \
383
-            ux = vec_mradds (ux, lCBU, (vector signed short){0});       \
384
-            ux0  = vec_mergeh (ux,ux);                                  \
385
-            ux1  = vec_mergel (ux,ux);                                  \
386
-                                                                        \
387
-            /* vx  = (CRV*(v<<CSHIFT)+0x4000)>>15;        */            \
388
-            vx = vec_sl (V, lCSHIFT);                                   \
389
-            vx = vec_mradds (vx, lCRV, (vector signed short){0});       \
390
-            vx0  = vec_mergeh (vx,vx);                                  \
391
-            vx1  = vec_mergel (vx,vx);                                  \
392
-                                                                        \
393
-            /* uvx = ((CGU*u) + (CGV*v))>>15 */                         \
394
-            uvx = vec_mradds (U, lCGU, (vector signed short){0});       \
395
-            uvx = vec_mradds (V, lCGV, uvx);                            \
396
-            uvx0 = vec_mergeh (uvx,uvx);                                \
397
-            uvx1 = vec_mergel (uvx,uvx);                                \
398
-                                                                        \
399
-            R0 = vec_add (Y0,vx0);                                      \
400
-            G0 = vec_add (Y0,uvx0);                                     \
401
-            B0 = vec_add (Y0,ux0);                                      \
402
-            R1 = vec_add (Y1,vx1);                                      \
403
-            G1 = vec_add (Y1,uvx1);                                     \
404
-            B1 = vec_add (Y1,ux1);                                      \
405
-                                                                        \
406
-            R  = vec_packclp (R0,R1);                                   \
407
-            G  = vec_packclp (G0,G1);                                   \
408
-            B  = vec_packclp (B0,B1);                                   \
409
-                                                                        \
410
-            out_pixels(R,G,B,oute);                                     \
411
-                                                                        \
412
-            R0 = vec_add (Y2,vx0);                                      \
413
-            G0 = vec_add (Y2,uvx0);                                     \
414
-            B0 = vec_add (Y2,ux0);                                      \
415
-            R1 = vec_add (Y3,vx1);                                      \
416
-            G1 = vec_add (Y3,uvx1);                                     \
417
-            B1 = vec_add (Y3,ux1);                                      \
418
-            R  = vec_packclp (R0,R1);                                   \
419
-            G  = vec_packclp (G0,G1);                                   \
420
-            B  = vec_packclp (B0,B1);                                   \
421
-                                                                        \
422
-                                                                        \
423
-            out_pixels(R,G,B,outo);                                     \
424
-                                                                        \
425
-            y1i  += 16;                                                 \
426
-            y2i  += 16;                                                 \
427
-            ui   += 8;                                                  \
428
-            vi   += 8;                                                  \
429
-                                                                        \
430
-        }                                                               \
431
-                                                                        \
432
-        outo  += (outstrides[0])>>4;                                    \
433
-        oute  += (outstrides[0])>>4;                                    \
434
-                                                                        \
435
-        ui    += instrides_scl[1];                                      \
436
-        vi    += instrides_scl[2];                                      \
437
-        y1i   += instrides_scl[0];                                      \
438
-        y2i   += instrides_scl[0];                                      \
439
-    }                                                                   \
440
-    return srcSliceH;                                                   \
281
+#define DEFCSP420_CVT(name, out_pixels)                                       \
282
+static int altivec_ ## name(SwsContext *c, const unsigned char **in,          \
283
+                            int *instrides, int srcSliceY, int srcSliceH,     \
284
+                            unsigned char **oplanes, int *outstrides)         \
285
+{                                                                             \
286
+    int w = c->srcW;                                                          \
287
+    int h = srcSliceH;                                                        \
288
+    int i, j;                                                                 \
289
+    int instrides_scl[3];                                                     \
290
+    vector unsigned char y0, y1;                                              \
291
+                                                                              \
292
+    vector signed char u, v;                                                  \
293
+                                                                              \
294
+    vector signed short Y0, Y1, Y2, Y3;                                       \
295
+    vector signed short U, V;                                                 \
296
+    vector signed short vx, ux, uvx;                                          \
297
+    vector signed short vx0, ux0, uvx0;                                       \
298
+    vector signed short vx1, ux1, uvx1;                                       \
299
+    vector signed short R0, G0, B0;                                           \
300
+    vector signed short R1, G1, B1;                                           \
301
+    vector unsigned char R, G, B;                                             \
302
+                                                                              \
303
+    const vector unsigned char *y1ivP, *y2ivP, *uivP, *vivP;                  \
304
+    vector unsigned char align_perm;                                          \
305
+                                                                              \
306
+    vector signed short lCY       = c->CY;                                    \
307
+    vector signed short lOY       = c->OY;                                    \
308
+    vector signed short lCRV      = c->CRV;                                   \
309
+    vector signed short lCBU      = c->CBU;                                   \
310
+    vector signed short lCGU      = c->CGU;                                   \
311
+    vector signed short lCGV      = c->CGV;                                   \
312
+    vector unsigned short lCSHIFT = c->CSHIFT;                                \
313
+                                                                              \
314
+    const ubyte *y1i = in[0];                                                 \
315
+    const ubyte *y2i = in[0] + instrides[0];                                  \
316
+    const ubyte *ui  = in[1];                                                 \
317
+    const ubyte *vi  = in[2];                                                 \
318
+                                                                              \
319
+    vector unsigned char *oute =                                              \
320
+        (vector unsigned char *)                                              \
321
+            (oplanes[0] + srcSliceY * outstrides[0]);                         \
322
+    vector unsigned char *outo =                                              \
323
+        (vector unsigned char *)                                              \
324
+            (oplanes[0] + srcSliceY * outstrides[0] + outstrides[0]);         \
325
+                                                                              \
326
+    /* loop moves y{1, 2}i by w */                                            \
327
+    instrides_scl[0] = instrides[0] * 2 - w;                                  \
328
+    /* loop moves ui by w / 2 */                                              \
329
+    instrides_scl[1] = instrides[1] - w / 2;                                  \
330
+    /* loop moves vi by w / 2 */                                              \
331
+    instrides_scl[2] = instrides[2] - w / 2;                                  \
332
+                                                                              \
333
+    for (i = 0; i < h / 2; i++) {                                             \
334
+        vec_dstst(outo, (0x02000002 | (((w * 3 + 32) / 32) << 16)), 0);       \
335
+        vec_dstst(oute, (0x02000002 | (((w * 3 + 32) / 32) << 16)), 1);       \
336
+                                                                              \
337
+        for (j = 0; j < w / 16; j++) {                                        \
338
+            y1ivP = (const vector unsigned char *) y1i;                       \
339
+            y2ivP = (const vector unsigned char *) y2i;                       \
340
+            uivP  = (const vector unsigned char *) ui;                        \
341
+            vivP  = (const vector unsigned char *) vi;                        \
342
+                                                                              \
343
+            align_perm = vec_lvsl(0, y1i);                                    \
344
+            y0 = (vector unsigned char)                                       \
345
+                     vec_perm(y1ivP[0], y1ivP[1], align_perm);                \
346
+                                                                              \
347
+            align_perm = vec_lvsl(0, y2i);                                    \
348
+            y1 = (vector unsigned char)                                       \
349
+                     vec_perm(y2ivP[0], y2ivP[1], align_perm);                \
350
+                                                                              \
351
+            align_perm = vec_lvsl(0, ui);                                     \
352
+            u = (vector signed char)                                          \
353
+                    vec_perm(uivP[0], uivP[1], align_perm);                   \
354
+                                                                              \
355
+            align_perm = vec_lvsl(0, vi);                                     \
356
+            v = (vector signed char)                                          \
357
+                    vec_perm(vivP[0], vivP[1], align_perm);                   \
358
+                                                                              \
359
+            u = (vector signed char)                                          \
360
+                    vec_sub(u,                                                \
361
+                            (vector signed char)                              \
362
+                                vec_splat((vector signed char) { 128 }, 0));  \
363
+            v = (vector signed char)                                          \
364
+                    vec_sub(v,                                                \
365
+                            (vector signed char)                              \
366
+                                vec_splat((vector signed char) { 128 }, 0));  \
367
+                                                                              \
368
+            U = vec_unpackh(u);                                               \
369
+            V = vec_unpackh(v);                                               \
370
+                                                                              \
371
+            Y0 = vec_unh(y0);                                                 \
372
+            Y1 = vec_unl(y0);                                                 \
373
+            Y2 = vec_unh(y1);                                                 \
374
+            Y3 = vec_unl(y1);                                                 \
375
+                                                                              \
376
+            Y0 = vec_mradds(Y0, lCY, lOY);                                    \
377
+            Y1 = vec_mradds(Y1, lCY, lOY);                                    \
378
+            Y2 = vec_mradds(Y2, lCY, lOY);                                    \
379
+            Y3 = vec_mradds(Y3, lCY, lOY);                                    \
380
+                                                                              \
381
+            /* ux  = (CBU * (u << CSHIFT) + 0x4000) >> 15 */                  \
382
+            ux  = vec_sl(U, lCSHIFT);                                         \
383
+            ux  = vec_mradds(ux, lCBU, (vector signed short) { 0 });          \
384
+            ux0 = vec_mergeh(ux, ux);                                         \
385
+            ux1 = vec_mergel(ux, ux);                                         \
386
+                                                                              \
387
+            /* vx  = (CRV * (v << CSHIFT) + 0x4000) >> 15; */                 \
388
+            vx  = vec_sl(V, lCSHIFT);                                         \
389
+            vx  = vec_mradds(vx, lCRV, (vector signed short) { 0 });          \
390
+            vx0 = vec_mergeh(vx, vx);                                         \
391
+            vx1 = vec_mergel(vx, vx);                                         \
392
+                                                                              \
393
+            /* uvx = ((CGU * u) + (CGV * v)) >> 15 */                         \
394
+            uvx  = vec_mradds(U, lCGU, (vector signed short) { 0 });          \
395
+            uvx  = vec_mradds(V, lCGV, uvx);                                  \
396
+            uvx0 = vec_mergeh(uvx, uvx);                                      \
397
+            uvx1 = vec_mergel(uvx, uvx);                                      \
398
+                                                                              \
399
+            R0 = vec_add(Y0, vx0);                                            \
400
+            G0 = vec_add(Y0, uvx0);                                           \
401
+            B0 = vec_add(Y0, ux0);                                            \
402
+            R1 = vec_add(Y1, vx1);                                            \
403
+            G1 = vec_add(Y1, uvx1);                                           \
404
+            B1 = vec_add(Y1, ux1);                                            \
405
+                                                                              \
406
+            R = vec_packclp(R0, R1);                                          \
407
+            G = vec_packclp(G0, G1);                                          \
408
+            B = vec_packclp(B0, B1);                                          \
409
+                                                                              \
410
+            out_pixels(R, G, B, oute);                                        \
411
+                                                                              \
412
+            R0 = vec_add(Y2, vx0);                                            \
413
+            G0 = vec_add(Y2, uvx0);                                           \
414
+            B0 = vec_add(Y2, ux0);                                            \
415
+            R1 = vec_add(Y3, vx1);                                            \
416
+            G1 = vec_add(Y3, uvx1);                                           \
417
+            B1 = vec_add(Y3, ux1);                                            \
418
+            R  = vec_packclp(R0, R1);                                         \
419
+            G  = vec_packclp(G0, G1);                                         \
420
+            B  = vec_packclp(B0, B1);                                         \
421
+                                                                              \
422
+                                                                              \
423
+            out_pixels(R, G, B, outo);                                        \
424
+                                                                              \
425
+            y1i += 16;                                                        \
426
+            y2i += 16;                                                        \
427
+            ui  += 8;                                                         \
428
+            vi  += 8;                                                         \
429
+        }                                                                     \
430
+                                                                              \
431
+        outo += (outstrides[0]) >> 4;                                         \
432
+        oute += (outstrides[0]) >> 4;                                         \
433
+                                                                              \
434
+        ui  += instrides_scl[1];                                              \
435
+        vi  += instrides_scl[2];                                              \
436
+        y1i += instrides_scl[0];                                              \
437
+        y2i += instrides_scl[0];                                              \
438
+    }                                                                         \
439
+    return srcSliceH;                                                         \
441 440
 }
442 441
 
443
-
444
-#define out_abgr(a,b,c,ptr)  vec_mstrgb32(__typeof__(a),((__typeof__ (a)){255}),c,b,a,ptr)
445
-#define out_bgra(a,b,c,ptr)  vec_mstrgb32(__typeof__(a),c,b,a,((__typeof__ (a)){255}),ptr)
446
-#define out_rgba(a,b,c,ptr)  vec_mstrgb32(__typeof__(a),a,b,c,((__typeof__ (a)){255}),ptr)
447
-#define out_argb(a,b,c,ptr)  vec_mstrgb32(__typeof__(a),((__typeof__ (a)){255}),a,b,c,ptr)
448
-#define out_rgb24(a,b,c,ptr) vec_mstrgb24(a,b,c,ptr)
449
-#define out_bgr24(a,b,c,ptr) vec_mstbgr24(a,b,c,ptr)
450
-
451
-DEFCSP420_CVT (yuv2_abgr, out_abgr)
452
-DEFCSP420_CVT (yuv2_bgra, out_bgra)
453
-DEFCSP420_CVT (yuv2_rgba, out_rgba)
454
-DEFCSP420_CVT (yuv2_argb, out_argb)
455
-DEFCSP420_CVT (yuv2_rgb24,  out_rgb24)
456
-DEFCSP420_CVT (yuv2_bgr24,  out_bgr24)
457
-
442
+#define out_abgr(a, b, c, ptr)                                          \
443
+    vec_mstrgb32(__typeof__(a), ((__typeof__(a)) { 255 }), c, b, a, ptr)
444
+#define out_bgra(a, b, c, ptr)                                          \
445
+    vec_mstrgb32(__typeof__(a), c, b, a, ((__typeof__(a)) { 255 }), ptr)
446
+#define out_rgba(a, b, c, ptr)                                          \
447
+    vec_mstrgb32(__typeof__(a), a, b, c, ((__typeof__(a)) { 255 }), ptr)
448
+#define out_argb(a, b, c, ptr)                                          \
449
+    vec_mstrgb32(__typeof__(a), ((__typeof__(a)) { 255 }), a, b, c, ptr)
450
+#define out_rgb24(a, b, c, ptr) vec_mstrgb24(a, b, c, ptr)
451
+#define out_bgr24(a, b, c, ptr) vec_mstbgr24(a, b, c, ptr)
452
+
453
+DEFCSP420_CVT(yuv2_abgr,  out_abgr)
454
+DEFCSP420_CVT(yuv2_bgra,  out_bgra)
455
+DEFCSP420_CVT(yuv2_rgba,  out_rgba)
456
+DEFCSP420_CVT(yuv2_argb,  out_argb)
457
+DEFCSP420_CVT(yuv2_rgb24, out_rgb24)
458
+DEFCSP420_CVT(yuv2_bgr24, out_bgr24)
458 459
 
459 460
 // uyvy|uyvy|uyvy|uyvy
460 461
 // 0123 4567 89ab cdef
461
-static
462
-const vector unsigned char
463
-    demux_u = {0x10,0x00,0x10,0x00,
464
-               0x10,0x04,0x10,0x04,
465
-               0x10,0x08,0x10,0x08,
466
-               0x10,0x0c,0x10,0x0c},
467
-    demux_v = {0x10,0x02,0x10,0x02,
468
-               0x10,0x06,0x10,0x06,
469
-               0x10,0x0A,0x10,0x0A,
470
-               0x10,0x0E,0x10,0x0E},
471
-    demux_y = {0x10,0x01,0x10,0x03,
472
-               0x10,0x05,0x10,0x07,
473
-               0x10,0x09,0x10,0x0B,
474
-               0x10,0x0D,0x10,0x0F};
462
+static const vector unsigned char
463
+    demux_u = { 0x10, 0x00, 0x10, 0x00,
464
+                0x10, 0x04, 0x10, 0x04,
465
+                0x10, 0x08, 0x10, 0x08,
466
+                0x10, 0x0c, 0x10, 0x0c },
467
+    demux_v = { 0x10, 0x02, 0x10, 0x02,
468
+                0x10, 0x06, 0x10, 0x06,
469
+                0x10, 0x0A, 0x10, 0x0A,
470
+                0x10, 0x0E, 0x10, 0x0E },
471
+    demux_y = { 0x10, 0x01, 0x10, 0x03,
472
+                0x10, 0x05, 0x10, 0x07,
473
+                0x10, 0x09, 0x10, 0x0B,
474
+                0x10, 0x0D, 0x10, 0x0F };
475 475
 
476 476
 /*
477
-  this is so I can play live CCIR raw video
478
-*/
479
-static int altivec_uyvy_rgb32 (SwsContext *c,
480
-                               const unsigned char **in, int *instrides,
481
-                               int srcSliceY,        int srcSliceH,
482
-                               unsigned char **oplanes, int *outstrides)
477
+ * this is so I can play live CCIR raw video
478
+ */
479
+static int altivec_uyvy_rgb32(SwsContext *c, const unsigned char **in,
480
+                              int *instrides, int srcSliceY, int srcSliceH,
481
+                              unsigned char **oplanes, int *outstrides)
483 482
 {
484 483
     int w = c->srcW;
485 484
     int h = srcSliceH;
486
-    int i,j;
485
+    int i, j;
487 486
     vector unsigned char uyvy;
488
-    vector signed   short Y,U,V;
489
-    vector signed   short R0,G0,B0,R1,G1,B1;
490
-    vector unsigned char  R,G,B;
487
+    vector signed short Y, U, V;
488
+    vector signed short R0, G0, B0, R1, G1, B1;
489
+    vector unsigned char R, G, B;
491 490
     vector unsigned char *out;
492 491
     const ubyte *img;
493 492
 
494 493
     img = in[0];
495
-    out = (vector unsigned char *)(oplanes[0]+srcSliceY*outstrides[0]);
494
+    out = (vector unsigned char *) (oplanes[0] + srcSliceY * outstrides[0]);
496 495
 
497
-    for (i=0;i<h;i++) {
498
-        for (j=0;j<w/16;j++) {
499
-            uyvy = vec_ld (0, img);
500
-            U = (vector signed short)
501
-                vec_perm (uyvy, (vector unsigned char){0}, demux_u);
496
+    for (i = 0; i < h; i++)
497
+        for (j = 0; j < w / 16; j++) {
498
+            uyvy = vec_ld(0, img);
502 499
 
500
+            U = (vector signed short)
501
+                    vec_perm(uyvy, (vector unsigned char) { 0 }, demux_u);
503 502
             V = (vector signed short)
504
-                vec_perm (uyvy, (vector unsigned char){0}, demux_v);
505
-
503
+                    vec_perm(uyvy, (vector unsigned char) { 0 }, demux_v);
506 504
             Y = (vector signed short)
507
-                vec_perm (uyvy, (vector unsigned char){0}, demux_y);
505
+                    vec_perm(uyvy, (vector unsigned char) { 0 }, demux_y);
508 506
 
509
-            cvtyuvtoRGB (c, Y,U,V,&R0,&G0,&B0);
507
+            cvtyuvtoRGB(c, Y, U, V, &R0, &G0, &B0);
510 508
 
511
-            uyvy = vec_ld (16, img);
512
-            U = (vector signed short)
513
-                vec_perm (uyvy, (vector unsigned char){0}, demux_u);
509
+            uyvy = vec_ld(16, img);
514 510
 
511
+            U = (vector signed short)
512
+                    vec_perm(uyvy, (vector unsigned char) { 0 }, demux_u);
515 513
             V = (vector signed short)
516
-                vec_perm (uyvy, (vector unsigned char){0}, demux_v);
517
-
514
+                    vec_perm(uyvy, (vector unsigned char) { 0 }, demux_v);
518 515
             Y = (vector signed short)
519
-                vec_perm (uyvy, (vector unsigned char){0}, demux_y);
516
+                    vec_perm(uyvy, (vector unsigned char) { 0 }, demux_y);
520 517
 
521
-            cvtyuvtoRGB (c, Y,U,V,&R1,&G1,&B1);
518
+            cvtyuvtoRGB(c, Y, U, V, &R1, &G1, &B1);
522 519
 
523
-            R  = vec_packclp (R0,R1);
524
-            G  = vec_packclp (G0,G1);
525
-            B  = vec_packclp (B0,B1);
520
+            R = vec_packclp(R0, R1);
521
+            G = vec_packclp(G0, G1);
522
+            B = vec_packclp(B0, B1);
526 523
 
527
-            //      vec_mstbgr24 (R,G,B, out);
528
-            out_rgba (R,G,B,out);
524
+            // vec_mstbgr24 (R,G,B, out);
525
+            out_rgba(R, G, B, out);
529 526
 
530 527
             img += 32;
531 528
         }
532
-    }
533 529
     return srcSliceH;
534 530
 }
535 531
 
536
-
537
-
538 532
 /* Ok currently the acceleration routine only supports
539
-   inputs of widths a multiple of 16
540
-   and heights a multiple 2
541
-
542
-   So we just fall back to the C codes for this.
543
-*/
533
+ * inputs of widths a multiple of 16
534
+ * and heights a multiple 2
535
+ *
536
+ * So we just fall back to the C codes for this.
537
+ */
544 538
 SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c)
545 539
 {
546 540
     if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC))
547 541
         return NULL;
548 542
 
549 543
     /*
550
-      and this seems not to matter too much I tried a bunch of
551
-      videos with abnormal widths and MPlayer crashes elsewhere.
552
-      mplayer -vo x11 -rawvideo on:w=350:h=240 raw-350x240.eyuv
553
-      boom with X11 bad match.
554
-
555
-    */
556
-    if ((c->srcW & 0xf) != 0)    return NULL;
544
+     * and this seems not to matter too much I tried a bunch of
545
+     * videos with abnormal widths and MPlayer crashes elsewhere.
546
+     * mplayer -vo x11 -rawvideo on:w=350:h=240 raw-350x240.eyuv
547
+     * boom with X11 bad match.
548
+     *
549
+     */
550
+    if ((c->srcW & 0xf) != 0)
551
+        return NULL;
557 552
 
558 553
     switch (c->srcFormat) {
559 554
     case PIX_FMT_YUV410P:
... ...
@@ -565,7 +561,7 @@ SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c)
565 565
         if ((c->srcH & 0x1) != 0)
566 566
             return NULL;
567 567
 
568
-        switch(c->dstFormat) {
568
+        switch (c->dstFormat) {
569 569
         case PIX_FMT_RGB24:
570 570
             av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGB24\n");
571 571
             return altivec_yuv2_rgb24;
... ...
@@ -589,143 +585,160 @@ SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c)
589 589
         break;
590 590
 
591 591
     case PIX_FMT_UYVY422:
592
-        switch(c->dstFormat) {
592
+        switch (c->dstFormat) {
593 593
         case PIX_FMT_BGR32:
594 594
             av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space UYVY -> RGB32\n");
595 595
             return altivec_uyvy_rgb32;
596 596
         default: return NULL;
597 597
         }
598 598
         break;
599
-
600 599
     }
601 600
     return NULL;
602 601
 }
603 602
 
604
-void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4], int brightness, int contrast, int saturation)
603
+void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4],
604
+                                    int brightness, int contrast,
605
+                                    int saturation)
605 606
 {
606 607
     union {
607 608
         DECLARE_ALIGNED(16, signed short, tmp)[8];
608 609
         vector signed short vec;
609 610
     } buf;
610 611
 
611
-    buf.tmp[0] =  ((0xffffLL) * contrast>>8)>>9;                        //cy
612
-    buf.tmp[1] =  -256*brightness;                                      //oy
613
-    buf.tmp[2] =  (inv_table[0]>>3) *(contrast>>16)*(saturation>>16);   //crv
614
-    buf.tmp[3] =  (inv_table[1]>>3) *(contrast>>16)*(saturation>>16);   //cbu
615
-    buf.tmp[4] = -((inv_table[2]>>1)*(contrast>>16)*(saturation>>16));  //cgu
616
-    buf.tmp[5] = -((inv_table[3]>>1)*(contrast>>16)*(saturation>>16));  //cgv
617
-
618
-
619
-    c->CSHIFT = (vector unsigned short)vec_splat_u16(2);
620
-    c->CY   = vec_splat ((vector signed short)buf.vec, 0);
621
-    c->OY   = vec_splat ((vector signed short)buf.vec, 1);
622
-    c->CRV  = vec_splat ((vector signed short)buf.vec, 2);
623
-    c->CBU  = vec_splat ((vector signed short)buf.vec, 3);
624
-    c->CGU  = vec_splat ((vector signed short)buf.vec, 4);
625
-    c->CGV  = vec_splat ((vector signed short)buf.vec, 5);
612
+    buf.tmp[0] = ((0xffffLL) * contrast >> 8) >> 9;                               // cy
613
+    buf.tmp[1] = -256 * brightness;                                               // oy
614
+    buf.tmp[2] =   (inv_table[0] >> 3) * (contrast >> 16) * (saturation >> 16);   // crv
615
+    buf.tmp[3] =   (inv_table[1] >> 3) * (contrast >> 16) * (saturation >> 16);   // cbu
616
+    buf.tmp[4] = -((inv_table[2] >> 1) * (contrast >> 16) * (saturation >> 16));  // cgu
617
+    buf.tmp[5] = -((inv_table[3] >> 1) * (contrast >> 16) * (saturation >> 16));  // cgv
618
+
619
+    c->CSHIFT = (vector unsigned short) vec_splat_u16(2);
620
+    c->CY     = vec_splat((vector signed short) buf.vec, 0);
621
+    c->OY     = vec_splat((vector signed short) buf.vec, 1);
622
+    c->CRV    = vec_splat((vector signed short) buf.vec, 2);
623
+    c->CBU    = vec_splat((vector signed short) buf.vec, 3);
624
+    c->CGU    = vec_splat((vector signed short) buf.vec, 4);
625
+    c->CGV    = vec_splat((vector signed short) buf.vec, 5);
626 626
     return;
627 627
 }
628 628
 
629
-
630
-static av_always_inline void
631
-ff_yuv2packedX_altivec(SwsContext *c, const int16_t *lumFilter,
632
-                       const int16_t **lumSrc, int lumFilterSize,
633
-                       const int16_t *chrFilter, const int16_t **chrUSrc,
634
-                       const int16_t **chrVSrc, int chrFilterSize,
635
-                       const int16_t **alpSrc, uint8_t *dest,
636
-                       int dstW, int dstY, enum PixelFormat target)
629
+static av_always_inline void ff_yuv2packedX_altivec(SwsContext *c,
630
+                                                    const int16_t *lumFilter,
631
+                                                    const int16_t **lumSrc,
632
+                                                    int lumFilterSize,
633
+                                                    const int16_t *chrFilter,
634
+                                                    const int16_t **chrUSrc,
635
+                                                    const int16_t **chrVSrc,
636
+                                                    int chrFilterSize,
637
+                                                    const int16_t **alpSrc,
638
+                                                    uint8_t *dest,
639
+                                                    int dstW, int dstY,
640
+                                                    enum PixelFormat target)
637 641
 {
638
-    int i,j;
639
-    vector signed short X,X0,X1,Y0,U0,V0,Y1,U1,V1,U,V;
640
-    vector signed short R0,G0,B0,R1,G1,B1;
642
+    int i, j;
643
+    vector signed short X, X0, X1, Y0, U0, V0, Y1, U1, V1, U, V;
644
+    vector signed short R0, G0, B0, R1, G1, B1;
641 645
 
642
-    vector unsigned char R,G,B;
643
-    vector unsigned char *out,*nout;
646
+    vector unsigned char R, G, B;
647
+    vector unsigned char *out, *nout;
644 648
 
645
-    vector signed short   RND = vec_splat_s16(1<<3);
649
+    vector signed short RND   = vec_splat_s16(1 << 3);
646 650
     vector unsigned short SCL = vec_splat_u16(4);
647 651
     DECLARE_ALIGNED(16, unsigned int, scratch)[16];
648 652
 
649 653
     vector signed short *YCoeffs, *CCoeffs;
650 654
 
651
-    YCoeffs = c->vYCoeffsBank+dstY*lumFilterSize;
652
-    CCoeffs = c->vCCoeffsBank+dstY*chrFilterSize;
655
+    YCoeffs = c->vYCoeffsBank + dstY * lumFilterSize;
656
+    CCoeffs = c->vCCoeffsBank + dstY * chrFilterSize;
653 657
 
654
-    out = (vector unsigned char *)dest;
658
+    out = (vector unsigned char *) dest;
655 659
 
656
-    for (i=0; i<dstW; i+=16) {
660
+    for (i = 0; i < dstW; i += 16) {
657 661
         Y0 = RND;
658 662
         Y1 = RND;
659 663
         /* extract 16 coeffs from lumSrc */
660
-        for (j=0; j<lumFilterSize; j++) {
661
-            X0 = vec_ld (0,  &lumSrc[j][i]);
662
-            X1 = vec_ld (16, &lumSrc[j][i]);
663
-            Y0 = vec_mradds (X0, YCoeffs[j], Y0);
664
-            Y1 = vec_mradds (X1, YCoeffs[j], Y1);
664
+        for (j = 0; j < lumFilterSize; j++) {
665
+            X0 = vec_ld(0, &lumSrc[j][i]);
666
+            X1 = vec_ld(16, &lumSrc[j][i]);
667
+            Y0 = vec_mradds(X0, YCoeffs[j], Y0);
668
+            Y1 = vec_mradds(X1, YCoeffs[j], Y1);
665 669
         }
666 670
 
667 671
         U = RND;
668 672
         V = RND;
669 673
         /* extract 8 coeffs from U,V */
670
-        for (j=0; j<chrFilterSize; j++) {
671
-            X  = vec_ld (0, &chrUSrc[j][i/2]);
672
-            U  = vec_mradds (X, CCoeffs[j], U);
673
-            X  = vec_ld (0, &chrVSrc[j][i/2]);
674
-            V  = vec_mradds (X, CCoeffs[j], V);
674
+        for (j = 0; j < chrFilterSize; j++) {
675
+            X = vec_ld(0, &chrUSrc[j][i / 2]);
676
+            U = vec_mradds(X, CCoeffs[j], U);
677
+            X = vec_ld(0, &chrVSrc[j][i / 2]);
678
+            V = vec_mradds(X, CCoeffs[j], V);
675 679
         }
676 680
 
677 681
         /* scale and clip signals */
678
-        Y0 = vec_sra (Y0, SCL);
679
-        Y1 = vec_sra (Y1, SCL);
680
-        U  = vec_sra (U,  SCL);
681
-        V  = vec_sra (V,  SCL);
682
+        Y0 = vec_sra(Y0, SCL);
683
+        Y1 = vec_sra(Y1, SCL);
684
+        U  = vec_sra(U, SCL);
685
+        V  = vec_sra(V, SCL);
682 686
 
683
-        Y0 = vec_clip_s16 (Y0);
684
-        Y1 = vec_clip_s16 (Y1);
685
-        U  = vec_clip_s16 (U);
686
-        V  = vec_clip_s16 (V);
687
+        Y0 = vec_clip_s16(Y0);
688
+        Y1 = vec_clip_s16(Y1);
689
+        U  = vec_clip_s16(U);
690
+        V  = vec_clip_s16(V);
687 691
 
688 692
         /* now we have
689
-          Y0= y0 y1 y2 y3 y4 y5 y6 y7     Y1= y8 y9 y10 y11 y12 y13 y14 y15
690
-          U= u0 u1 u2 u3 u4 u5 u6 u7      V= v0 v1 v2 v3 v4 v5 v6 v7
691
-
692
-          Y0= y0 y1 y2 y3 y4 y5 y6 y7    Y1= y8 y9 y10 y11 y12 y13 y14 y15
693
-          U0= u0 u0 u1 u1 u2 u2 u3 u3    U1= u4 u4 u5 u5 u6 u6 u7 u7
694
-          V0= v0 v0 v1 v1 v2 v2 v3 v3    V1= v4 v4 v5 v5 v6 v6 v7 v7
695
-        */
696
-
697
-        U0 = vec_mergeh (U,U);
698
-        V0 = vec_mergeh (V,V);
699
-
700
-        U1 = vec_mergel (U,U);
701
-        V1 = vec_mergel (V,V);
702
-
703
-        cvtyuvtoRGB (c, Y0,U0,V0,&R0,&G0,&B0);
704
-        cvtyuvtoRGB (c, Y1,U1,V1,&R1,&G1,&B1);
705
-
706
-        R  = vec_packclp (R0,R1);
707
-        G  = vec_packclp (G0,G1);
708
-        B  = vec_packclp (B0,B1);
709
-
710
-        switch(target) {
711
-        case PIX_FMT_ABGR:  out_abgr  (R,G,B,out); break;
712
-        case PIX_FMT_BGRA:  out_bgra  (R,G,B,out); break;
713
-        case PIX_FMT_RGBA:  out_rgba  (R,G,B,out); break;
714
-        case PIX_FMT_ARGB:  out_argb  (R,G,B,out); break;
715
-        case PIX_FMT_RGB24: out_rgb24 (R,G,B,out); break;
716
-        case PIX_FMT_BGR24: out_bgr24 (R,G,B,out); break;
693
+         * Y0 = y0 y1 y2 y3 y4 y5 y6 y7    Y1 = y8 y9 y10 y11 y12 y13 y14 y15
694
+         * U  = u0 u1 u2 u3 u4 u5 u6 u7    V  = v0 v1 v2 v3 v4 v5 v6 v7
695
+         *
696
+         * Y0 = y0 y1 y2 y3 y4 y5 y6 y7    Y1 = y8 y9 y10 y11 y12 y13 y14 y15
697
+         * U0 = u0 u0 u1 u1 u2 u2 u3 u3    U1 = u4 u4 u5 u5 u6 u6 u7 u7
698
+         * V0 = v0 v0 v1 v1 v2 v2 v3 v3    V1 = v4 v4 v5 v5 v6 v6 v7 v7
699
+         */
700
+
701
+        U0 = vec_mergeh(U, U);
702
+        V0 = vec_mergeh(V, V);
703
+
704
+        U1 = vec_mergel(U, U);
705
+        V1 = vec_mergel(V, V);
706
+
707
+        cvtyuvtoRGB(c, Y0, U0, V0, &R0, &G0, &B0);
708
+        cvtyuvtoRGB(c, Y1, U1, V1, &R1, &G1, &B1);
709
+
710
+        R = vec_packclp(R0, R1);
711
+        G = vec_packclp(G0, G1);
712
+        B = vec_packclp(B0, B1);
713
+
714
+        switch (target) {
715
+        case PIX_FMT_ABGR:
716
+            out_abgr(R, G, B, out);
717
+            break;
718
+        case PIX_FMT_BGRA:
719
+            out_bgra(R, G, B, out);
720
+            break;
721
+        case PIX_FMT_RGBA:
722
+            out_rgba(R, G, B, out);
723
+            break;
724
+        case PIX_FMT_ARGB:
725
+            out_argb(R, G, B, out);
726
+            break;
727
+        case PIX_FMT_RGB24:
728
+            out_rgb24(R, G, B, out);
729
+            break;
730
+        case PIX_FMT_BGR24:
731
+            out_bgr24(R, G, B, out);
732
+            break;
717 733
         default:
718
-            {
719
-                /* If this is reached, the caller should have called yuv2packedXinC
720
-                   instead. */
721
-                static int printed_error_message;
722
-                if (!printed_error_message) {
723
-                    av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n",
724
-                           av_get_pix_fmt_name(c->dstFormat));
725
-                    printed_error_message=1;
726
-                }
727
-                return;
734
+        {
735
+            /* If this is reached, the caller should have called yuv2packedXinC
736
+             * instead. */
737
+            static int printed_error_message;
738
+            if (!printed_error_message) {
739
+                av_log(c, AV_LOG_ERROR,
740
+                       "altivec_yuv2packedX doesn't support %s output\n",
741
+                       av_get_pix_fmt_name(c->dstFormat));
742
+                printed_error_message = 1;
728 743
             }
744
+            return;
745
+        }
729 746
         }
730 747
     }
731 748
 
... ...
@@ -735,87 +748,104 @@ ff_yuv2packedX_altivec(SwsContext *c, const int16_t *lumFilter,
735 735
         Y0 = RND;
736 736
         Y1 = RND;
737 737
         /* extract 16 coeffs from lumSrc */
738
-        for (j=0; j<lumFilterSize; j++) {
739
-            X0 = vec_ld (0,  &lumSrc[j][i]);
740
-            X1 = vec_ld (16, &lumSrc[j][i]);
741
-            Y0 = vec_mradds (X0, YCoeffs[j], Y0);
742
-            Y1 = vec_mradds (X1, YCoeffs[j], Y1);
738
+        for (j = 0; j < lumFilterSize; j++) {
739
+            X0 = vec_ld(0, &lumSrc[j][i]);
740
+            X1 = vec_ld(16, &lumSrc[j][i]);
741
+            Y0 = vec_mradds(X0, YCoeffs[j], Y0);
742
+            Y1 = vec_mradds(X1, YCoeffs[j], Y1);
743 743
         }
744 744
 
745 745
         U = RND;
746 746
         V = RND;
747 747
         /* extract 8 coeffs from U,V */
748
-        for (j=0; j<chrFilterSize; j++) {
749
-            X  = vec_ld (0, &chrUSrc[j][i/2]);
750
-            U  = vec_mradds (X, CCoeffs[j], U);
751
-            X  = vec_ld (0, &chrVSrc[j][i/2]);
752
-            V  = vec_mradds (X, CCoeffs[j], V);
748
+        for (j = 0; j < chrFilterSize; j++) {
749
+            X = vec_ld(0, &chrUSrc[j][i / 2]);
750
+            U = vec_mradds(X, CCoeffs[j], U);
751
+            X = vec_ld(0, &chrVSrc[j][i / 2]);
752
+            V = vec_mradds(X, CCoeffs[j], V);
753 753
         }
754 754
 
755 755
         /* scale and clip signals */
756
-        Y0 = vec_sra (Y0, SCL);
757
-        Y1 = vec_sra (Y1, SCL);
758
-        U  = vec_sra (U,  SCL);
759
-        V  = vec_sra (V,  SCL);
756
+        Y0 = vec_sra(Y0, SCL);
757
+        Y1 = vec_sra(Y1, SCL);
758
+        U  = vec_sra(U, SCL);
759
+        V  = vec_sra(V, SCL);
760 760
 
761
-        Y0 = vec_clip_s16 (Y0);
762
-        Y1 = vec_clip_s16 (Y1);
763
-        U  = vec_clip_s16 (U);
764
-        V  = vec_clip_s16 (V);
761
+        Y0 = vec_clip_s16(Y0);
762
+        Y1 = vec_clip_s16(Y1);
763
+        U  = vec_clip_s16(U);
764
+        V  = vec_clip_s16(V);
765 765
 
766 766
         /* now we have
767
-           Y0= y0 y1 y2 y3 y4 y5 y6 y7     Y1= y8 y9 y10 y11 y12 y13 y14 y15
768
-           U = u0 u1 u2 u3 u4 u5 u6 u7     V = v0 v1 v2 v3 v4 v5 v6 v7
769
-
770
-           Y0= y0 y1 y2 y3 y4 y5 y6 y7    Y1= y8 y9 y10 y11 y12 y13 y14 y15
771
-           U0= u0 u0 u1 u1 u2 u2 u3 u3    U1= u4 u4 u5 u5 u6 u6 u7 u7
772
-           V0= v0 v0 v1 v1 v2 v2 v3 v3    V1= v4 v4 v5 v5 v6 v6 v7 v7
773
-        */
774
-
775
-        U0 = vec_mergeh (U,U);
776
-        V0 = vec_mergeh (V,V);
777
-
778
-        U1 = vec_mergel (U,U);
779
-        V1 = vec_mergel (V,V);
780
-
781
-        cvtyuvtoRGB (c, Y0,U0,V0,&R0,&G0,&B0);
782
-        cvtyuvtoRGB (c, Y1,U1,V1,&R1,&G1,&B1);
783
-
784
-        R  = vec_packclp (R0,R1);
785
-        G  = vec_packclp (G0,G1);
786
-        B  = vec_packclp (B0,B1);
787
-
788
-        nout = (vector unsigned char *)scratch;
789
-        switch(target) {
790
-        case PIX_FMT_ABGR:  out_abgr  (R,G,B,nout); break;
791
-        case PIX_FMT_BGRA:  out_bgra  (R,G,B,nout); break;
792
-        case PIX_FMT_RGBA:  out_rgba  (R,G,B,nout); break;
793
-        case PIX_FMT_ARGB:  out_argb  (R,G,B,nout); break;
794
-        case PIX_FMT_RGB24: out_rgb24 (R,G,B,nout); break;
795
-        case PIX_FMT_BGR24: out_bgr24 (R,G,B,nout); break;
767
+         * Y0 = y0 y1 y2 y3 y4 y5 y6 y7    Y1 = y8 y9 y10 y11 y12 y13 y14 y15
768
+         * U  = u0 u1 u2 u3 u4 u5 u6 u7    V  = v0 v1 v2 v3 v4 v5 v6 v7
769
+         *
770
+         * Y0 = y0 y1 y2 y3 y4 y5 y6 y7    Y1 = y8 y9 y10 y11 y12 y13 y14 y15
771
+         * U0 = u0 u0 u1 u1 u2 u2 u3 u3    U1 = u4 u4 u5 u5 u6 u6 u7 u7
772
+         * V0 = v0 v0 v1 v1 v2 v2 v3 v3    V1 = v4 v4 v5 v5 v6 v6 v7 v7
773
+         */
774
+
775
+        U0 = vec_mergeh(U, U);
776
+        V0 = vec_mergeh(V, V);
777
+
778
+        U1 = vec_mergel(U, U);
779
+        V1 = vec_mergel(V, V);
780
+
781
+        cvtyuvtoRGB(c, Y0, U0, V0, &R0, &G0, &B0);
782
+        cvtyuvtoRGB(c, Y1, U1, V1, &R1, &G1, &B1);
783
+
784
+        R = vec_packclp(R0, R1);
785
+        G = vec_packclp(G0, G1);
786
+        B = vec_packclp(B0, B1);
787
+
788
+        nout = (vector unsigned char *) scratch;
789
+        switch (target) {
790
+        case PIX_FMT_ABGR:
791
+            out_abgr(R, G, B, nout);
792
+            break;
793
+        case PIX_FMT_BGRA:
794
+            out_bgra(R, G, B, nout);
795
+            break;
796
+        case PIX_FMT_RGBA:
797
+            out_rgba(R, G, B, nout);
798
+            break;
799
+        case PIX_FMT_ARGB:
800
+            out_argb(R, G, B, nout);
801
+            break;
802
+        case PIX_FMT_RGB24:
803
+            out_rgb24(R, G, B, nout);
804
+            break;
805
+        case PIX_FMT_BGR24:
806
+            out_bgr24(R, G, B, nout);
807
+            break;
796 808
         default:
797 809
             /* Unreachable, I think. */
798
-            av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n",
810
+            av_log(c, AV_LOG_ERROR,
811
+                   "altivec_yuv2packedX doesn't support %s output\n",
799 812
                    av_get_pix_fmt_name(c->dstFormat));
800 813
             return;
801 814
         }
802 815
 
803
-        memcpy (&((uint32_t*)dest)[i], scratch, (dstW-i)/4);
816
+        memcpy(&((uint32_t *) dest)[i], scratch, (dstW - i) / 4);
804 817
     }
805
-
806 818
 }
807 819
 
808
-#define YUV2PACKEDX_WRAPPER(suffix, pixfmt) \
809
-void ff_yuv2 ## suffix ## _X_altivec(SwsContext *c, const int16_t *lumFilter, \
810
-                            const int16_t **lumSrc, int lumFilterSize, \
811
-                            const int16_t *chrFilter, const int16_t **chrUSrc, \
812
-                            const int16_t **chrVSrc, int chrFilterSize, \
813
-                            const int16_t **alpSrc, uint8_t *dest, \
814
-                            int dstW, int dstY) \
815
-{ \
816
-    ff_yuv2packedX_altivec(c, lumFilter, lumSrc, lumFilterSize, \
817
-                           chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
818
-                           alpSrc, dest, dstW, dstY, pixfmt); \
820
+#define YUV2PACKEDX_WRAPPER(suffix, pixfmt)                             \
821
+void ff_yuv2 ## suffix ## _X_altivec(SwsContext *c,                     \
822
+                                     const int16_t *lumFilter,          \
823
+                                     const int16_t **lumSrc,            \
824
+                                     int lumFilterSize,                 \
825
+                                     const int16_t *chrFilter,          \
826
+                                     const int16_t **chrUSrc,           \
827
+                                     const int16_t **chrVSrc,           \
828
+                                     int chrFilterSize,                 \
829
+                                     const int16_t **alpSrc,            \
830
+                                     uint8_t *dest, int dstW, int dstY) \
831
+{                                                                       \
832
+    ff_yuv2packedX_altivec(c, lumFilter, lumSrc, lumFilterSize,         \
833
+                           chrFilter, chrUSrc, chrVSrc,                 \
834
+                           chrFilterSize, alpSrc,                       \
835
+                           dest, dstW, dstY, pixfmt);                   \
819 836
 }
820 837
 
821 838
 YUV2PACKEDX_WRAPPER(abgr,  PIX_FMT_ABGR);
... ...
@@ -1,4 +1,4 @@
1
-b813a52d4efe6cf7974190ea9c4c7e8c *./tests/data/acodec/g722.wav
1
+d1a10c4d35f752f60798114a156be3a8 *./tests/data/acodec/g722.wav
2 2
 48053 ./tests/data/acodec/g722.wav
3
-d8344d14a11eef0418b856af70694cbe *./tests/data/g722.acodec.out.wav
4
-stddev: 8841.18 PSNR: 17.40 MAXDIFF:36225 bytes:   191980/  1058400
3
+8dafe5b74ccd5f08fed2fb2a69c5475f *./tests/data/g722.acodec.out.wav
4
+stddev: 8939.47 PSNR: 17.30 MAXDIFF:40370 bytes:   191980/  1058400
... ...
@@ -1,168 +1,168 @@
1 1
 #tb 0: 1/16000
2
-0,          0,          0,     2048,     4096, 0xde68394d
3
-0,       2048,       2048,     2048,     4096, 0xa5c28cb7
4
-0,       4096,       4096,     2048,     4096, 0x2e3c2f23
5
-0,       6144,       6144,     2048,     4096, 0xd7757825
6
-0,       8192,       8192,     2048,     4096, 0xafd1fd61
7
-0,      10240,      10240,     2048,     4096, 0x686afcbe
8
-0,      12288,      12288,     2048,     4096, 0x2290e848
9
-0,      14336,      14336,     2048,     4096, 0xddd484ad
10
-0,      16384,      16384,     2048,     4096, 0x148811a6
11
-0,      18432,      18432,     2048,     4096, 0x8b965613
12
-0,      20480,      20480,     2048,     4096, 0x8b095d51
13
-0,      22528,      22528,     2048,     4096, 0xf7625485
14
-0,      24576,      24576,     2048,     4096, 0x982a688c
15
-0,      26624,      26624,     2048,     4096, 0xc290dcfc
16
-0,      28672,      28672,     2048,     4096, 0x8bdef225
17
-0,      30720,      30720,     2048,     4096, 0xfca27fdc
18
-0,      32768,      32768,     2048,     4096, 0x95eff313
19
-0,      34816,      34816,     2048,     4096, 0x691ed4f7
20
-0,      36864,      36864,     2048,     4096, 0xd7e7b492
21
-0,      38912,      38912,     2048,     4096, 0xb0416bfe
22
-0,      40960,      40960,     2048,     4096, 0xf94b3ebd
23
-0,      43008,      43008,     2048,     4096, 0x7f73ca12
24
-0,      45056,      45056,     2048,     4096, 0xe91da4a3
25
-0,      47104,      47104,     2048,     4096, 0x1f74dc0e
26
-0,      49152,      49152,     2048,     4096, 0xd95b35e8
27
-0,      51200,      51200,     2048,     4096, 0x6dcdde1a
28
-0,      53248,      53248,     2048,     4096, 0x614fd4e4
29
-0,      55296,      55296,     2048,     4096, 0xe38d0fd5
30
-0,      57344,      57344,     2048,     4096, 0xfeba2999
31
-0,      59392,      59392,     2048,     4096, 0x1bf541e1
32
-0,      61440,      61440,     2048,     4096, 0x689f50d8
33
-0,      63488,      63488,     2048,     4096, 0x0aa60f5f
34
-0,      65536,      65536,     2048,     4096, 0x60ac3116
35
-0,      67584,      67584,     2048,     4096, 0xfa60e5e6
36
-0,      69632,      69632,     2048,     4096, 0xc7207c5b
37
-0,      71680,      71680,     2048,     4096, 0x01196277
38
-0,      73728,      73728,     2048,     4096, 0x609ca46c
39
-0,      75776,      75776,     2048,     4096, 0xfb799142
40
-0,      77824,      77824,     2048,     4096, 0x720910df
41
-0,      79872,      79872,     2048,     4096, 0xe21a8662
42
-0,      81920,      81920,     2048,     4096, 0x07105120
43
-0,      83968,      83968,     2048,     4096, 0x593f627e
44
-0,      86016,      86016,     2048,     4096, 0x28ddc80c
45
-0,      88064,      88064,     2048,     4096, 0xc69ef356
46
-0,      90112,      90112,     2048,     4096, 0x2defc5bd
47
-0,      92160,      92160,     2048,     4096, 0x82a4f418
48
-0,      94208,      94208,     2048,     4096, 0x424cb997
49
-0,      96256,      96256,     2048,     4096, 0x167a49b7
50
-0,      98304,      98304,     2048,     4096, 0x32a3e0d4
51
-0,     100352,     100352,     2048,     4096, 0x08a353ae
52
-0,     102400,     102400,     2048,     4096, 0x9543577b
53
-0,     104448,     104448,     2048,     4096, 0x2ed137cf
54
-0,     106496,     106496,     2048,     4096, 0xd80b0538
55
-0,     108544,     108544,     2048,     4096, 0x2ad31bef
56
-0,     110592,     110592,     2048,     4096, 0x1060cff8
57
-0,     112640,     112640,     2048,     4096, 0x76ab5ab8
58
-0,     114688,     114688,     2048,     4096, 0x8eedb68d
59
-0,     116736,     116736,     2048,     4096, 0xf4e2dc46
60
-0,     118784,     118784,     2048,     4096, 0xc52d3326
61
-0,     120832,     120832,     2048,     4096, 0x25201a26
62
-0,     122880,     122880,     2048,     4096, 0x16419378
63
-0,     124928,     124928,     2048,     4096, 0x97061f3c
64
-0,     126976,     126976,     2048,     4096, 0xd54edecd
65
-0,     129024,     129024,     2048,     4096, 0xc830b07b
66
-0,     131072,     131072,     2048,     4096, 0x804bae00
67
-0,     133120,     133120,     2048,     4096, 0xbb279150
68
-0,     135168,     135168,     2048,     4096, 0x95c4d5aa
69
-0,     137216,     137216,     2048,     4096, 0xc51d5259
70
-0,     139264,     139264,     2048,     4096, 0x856e1ab0
71
-0,     141312,     141312,     2048,     4096, 0x9e6ccb12
72
-0,     143360,     143360,     2048,     4096, 0xa2e5c1bb
73
-0,     145408,     145408,     2048,     4096, 0xe62fb62f
74
-0,     147456,     147456,     2048,     4096, 0xf10e3df0
75
-0,     149504,     149504,     2048,     4096, 0x76def18b
76
-0,     151552,     151552,     2048,     4096, 0xc9c3a26d
77
-0,     153600,     153600,     2048,     4096, 0x8ec0e061
78
-0,     155648,     155648,     2048,     4096, 0x3d4e8512
79
-0,     157696,     157696,     2048,     4096, 0xec45cd46
80
-0,     159744,     159744,     2048,     4096, 0xa34f3ddf
81
-0,     161792,     161792,     2048,     4096, 0x52b81c53
82
-0,     163840,     163840,     2048,     4096, 0xd0f0397a
83
-0,     165888,     165888,     2048,     4096, 0x7c0de231
84
-0,     167936,     167936,     2048,     4096, 0xfe86c032
85
-0,     169984,     169984,     2048,     4096, 0x67cdb848
86
-0,     172032,     172032,     2048,     4096, 0x90532cc0
87
-0,     174080,     174080,     2048,     4096, 0x03bca9e9
88
-0,     176128,     176128,     2048,     4096, 0x73169fd1
89
-0,     178176,     178176,     2048,     4096, 0x0b93967d
90
-0,     180224,     180224,     2048,     4096, 0x6486d8be
91
-0,     182272,     182272,     2048,     4096, 0x555cc2ac
92
-0,     184320,     184320,     2048,     4096, 0x07c1912e
93
-0,     186368,     186368,     2048,     4096, 0xe0423c66
94
-0,     188416,     188416,     2048,     4096, 0xc12d0fa1
95
-0,     190464,     190464,     2048,     4096, 0xdf497c2f
96
-0,     192512,     192512,     2048,     4096, 0x9298d1ba
97
-0,     194560,     194560,     2048,     4096, 0x691a4e15
98
-0,     196608,     196608,     2048,     4096, 0x725adc6e
99
-0,     198656,     198656,     2048,     4096, 0xf68e88de
100
-0,     200704,     200704,     2048,     4096, 0x37a234aa
101
-0,     202752,     202752,     2048,     4096, 0x43fb0558
102
-0,     204800,     204800,     2048,     4096, 0x653e4320
103
-0,     206848,     206848,     2048,     4096, 0x651e2f13
104
-0,     208896,     208896,     2048,     4096, 0x179049f9
105
-0,     210944,     210944,     2048,     4096, 0xe02fbb9d
106
-0,     212992,     212992,     2048,     4096, 0xb7e9f2a0
107
-0,     215040,     215040,     2048,     4096, 0x94ee81df
108
-0,     217088,     217088,     2048,     4096, 0x398a98de
109
-0,     219136,     219136,     2048,     4096, 0x1267594a
110
-0,     221184,     221184,     2048,     4096, 0x715adbaf
111
-0,     223232,     223232,     2048,     4096, 0x28ce1a20
112
-0,     225280,     225280,     2048,     4096, 0x4f8073d0
113
-0,     227328,     227328,     2048,     4096, 0x536846d3
114
-0,     229376,     229376,     2048,     4096, 0x7dc7defe
115
-0,     231424,     231424,     2048,     4096, 0x08a28e2a
116
-0,     233472,     233472,     2048,     4096, 0xd717c5cd
117
-0,     235520,     235520,     2048,     4096, 0x5d6e1efd
118
-0,     237568,     237568,     2048,     4096, 0x4d0eea27
119
-0,     239616,     239616,     2048,     4096, 0x70fff90c
120
-0,     241664,     241664,     2048,     4096, 0xd5cc8207
121
-0,     243712,     243712,     2048,     4096, 0xf87cae0e
122
-0,     245760,     245760,     2048,     4096, 0x26814ab5
123
-0,     247808,     247808,     2048,     4096, 0x9569fb8d
124
-0,     249856,     249856,     2048,     4096, 0x7835122e
125
-0,     251904,     251904,     2048,     4096, 0xa38840dd
126
-0,     253952,     253952,     2048,     4096, 0xfc499ba3
127
-0,     256000,     256000,     2048,     4096, 0x0aa60cb0
128
-0,     258048,     258048,     2048,     4096, 0x530ef56e
129
-0,     260096,     260096,     2048,     4096, 0xead968db
130
-0,     262144,     262144,     2048,     4096, 0x64484214
131
-0,     264192,     264192,     2048,     4096, 0xfd0cc89e
132
-0,     266240,     266240,     2048,     4096, 0x0d452a5d
133
-0,     268288,     268288,     2048,     4096, 0x36ef8482
134
-0,     270336,     270336,     2048,     4096, 0x462b641b
135
-0,     272384,     272384,     2048,     4096, 0x2a5c1c0c
136
-0,     274432,     274432,     2048,     4096, 0x8837ff80
137
-0,     276480,     276480,     2048,     4096, 0x27a3de22
138
-0,     278528,     278528,     2048,     4096, 0xf88d28c1
139
-0,     280576,     280576,     2048,     4096, 0xed85ea97
140
-0,     282624,     282624,     2048,     4096, 0x50c3e7db
141
-0,     284672,     284672,     2048,     4096, 0x82bcb480
142
-0,     286720,     286720,     2048,     4096, 0xc50ee536
143
-0,     288768,     288768,     2048,     4096, 0x086280ee
144
-0,     290816,     290816,     2048,     4096, 0x6f18f2b2
145
-0,     292864,     292864,     2048,     4096, 0x1c7c0856
146
-0,     294912,     294912,     2048,     4096, 0xc576268a
147
-0,     296960,     296960,     2048,     4096, 0x7a9af56d
148
-0,     299008,     299008,     2048,     4096, 0x6d058fc5
149
-0,     301056,     301056,     2048,     4096, 0x8fb1107b
150
-0,     303104,     303104,     2048,     4096, 0x807588d1
151
-0,     305152,     305152,     2048,     4096, 0x56178443
152
-0,     307200,     307200,     2048,     4096, 0xf2460763
153
-0,     309248,     309248,     2048,     4096, 0x284255f2
154
-0,     311296,     311296,     2048,     4096, 0xb29d17fb
155
-0,     313344,     313344,     2048,     4096, 0x5e7e4633
156
-0,     315392,     315392,     2048,     4096, 0x57704db1
157
-0,     317440,     317440,     2048,     4096, 0xd87dcc1d
158
-0,     319488,     319488,     2048,     4096, 0x28d4bb93
159
-0,     321536,     321536,     2048,     4096, 0x3a2e5c6c
160
-0,     323584,     323584,     2048,     4096, 0xf3581656
161
-0,     325632,     325632,     2048,     4096, 0x42f1942f
162
-0,     327680,     327680,     2048,     4096, 0xe75c5092
163
-0,     329728,     329728,     2048,     4096, 0x3fae7f6d
164
-0,     331776,     331776,     2048,     4096, 0xf99ad73e
165
-0,     333824,     333824,     2048,     4096, 0x80564e3e
166
-0,     335872,     335872,     2048,     4096, 0x8ff6ebe5
167
-0,     337920,     337920,     2048,     4096, 0x436d5e69
168
-0,     339968,     339968,      684,     1368, 0xe0ebeda3
2
+0,          0,          0,     2048,     4096, 0x4f9228b3
3
+0,       2048,       2048,     2048,     4096, 0xfab58157
4
+0,       4096,       4096,     2048,     4096, 0x0b641c78
5
+0,       6144,       6144,     2048,     4096, 0x601c6803
6
+0,       8192,       8192,     2048,     4096, 0xb3e2f166
7
+0,      10240,      10240,     2048,     4096, 0x5681f206
8
+0,      12288,      12288,     2048,     4096, 0x1e69e71f
9
+0,      14336,      14336,     2048,     4096, 0x05628be3
10
+0,      16384,      16384,     2048,     4096, 0x109b1aef
11
+0,      18432,      18432,     2048,     4096, 0xd5435a9e
12
+0,      20480,      20480,     2048,     4096, 0xb38b5d28
13
+0,      22528,      22528,     2048,     4096, 0x64514c93
14
+0,      24576,      24576,     2048,     4096, 0x453350e7
15
+0,      26624,      26624,     2048,     4096, 0x6deccce6
16
+0,      28672,      28672,     2048,     4096, 0xd427ede1
17
+0,      30720,      30720,     2048,     4096, 0xdecb8c42
18
+0,      32768,      32768,     2048,     4096, 0x3841e4d2
19
+0,      34816,      34816,     2048,     4096, 0x858ac1b1
20
+0,      36864,      36864,     2048,     4096, 0x8e9dbfa0
21
+0,      38912,      38912,     2048,     4096, 0xcbc0766f
22
+0,      40960,      40960,     2048,     4096, 0x78d52555
23
+0,      43008,      43008,     2048,     4096, 0x600ac7d5
24
+0,      45056,      45056,     2048,     4096, 0xafadb7ee
25
+0,      47104,      47104,     2048,     4096, 0x8009d5a1
26
+0,      49152,      49152,     2048,     4096, 0xb07d475e
27
+0,      51200,      51200,     2048,     4096, 0xfcfecceb
28
+0,      53248,      53248,     2048,     4096, 0x38b5d85f
29
+0,      55296,      55296,     2048,     4096, 0xbd48072e
30
+0,      57344,      57344,     2048,     4096, 0xd04724d8
31
+0,      59392,      59392,     2048,     4096, 0x08425144
32
+0,      61440,      61440,     2048,     4096, 0x7b14483e
33
+0,      63488,      63488,     2048,     4096, 0x8858ef4c
34
+0,      65536,      65536,     2048,     4096, 0x1e3024c2
35
+0,      67584,      67584,     2048,     4096, 0xcd6bfe4f
36
+0,      69632,      69632,     2048,     4096, 0x8cde8d18
37
+0,      71680,      71680,     2048,     4096, 0xbbd856b8
38
+0,      73728,      73728,     2048,     4096, 0x988c9b7a
39
+0,      75776,      75776,     2048,     4096, 0x2a858e03
40
+0,      77824,      77824,     2048,     4096, 0x6dee1e4a
41
+0,      79872,      79872,     2048,     4096, 0x8cc38b41
42
+0,      81920,      81920,     2048,     4096, 0x48bd5cec
43
+0,      83968,      83968,     2048,     4096, 0xeb7f606b
44
+0,      86016,      86016,     2048,     4096, 0x75f5d28c
45
+0,      88064,      88064,     2048,     4096, 0x5bfeec4b
46
+0,      90112,      90112,     2048,     4096, 0xfc35c22a
47
+0,      92160,      92160,     2048,     4096, 0x3a95efba
48
+0,      94208,      94208,     2048,     4096, 0xefdbce9c
49
+0,      96256,      96256,     2048,     4096, 0x00594ada
50
+0,      98304,      98304,     2048,     4096, 0x20ffebfa
51
+0,     100352,     100352,     2048,     4096, 0x1b31370a
52
+0,     102400,     102400,     2048,     4096, 0x50766a56
53
+0,     104448,     104448,     2048,     4096, 0x0058315a
54
+0,     106496,     106496,     2048,     4096, 0x98090cbf
55
+0,     108544,     108544,     2048,     4096, 0x66ed2d40
56
+0,     110592,     110592,     2048,     4096, 0xdfd7c0a7
57
+0,     112640,     112640,     2048,     4096, 0x2adc57e1
58
+0,     114688,     114688,     2048,     4096, 0x838bbc82
59
+0,     116736,     116736,     2048,     4096, 0x2c55de1a
60
+0,     118784,     118784,     2048,     4096, 0xeae027f4
61
+0,     120832,     120832,     2048,     4096, 0x09fe00f6
62
+0,     122880,     122880,     2048,     4096, 0xa25d9970
63
+0,     124928,     124928,     2048,     4096, 0xedb11a20
64
+0,     126976,     126976,     2048,     4096, 0x9ce2e63e
65
+0,     129024,     129024,     2048,     4096, 0xeb699974
66
+0,     131072,     131072,     2048,     4096, 0xcc04a296
67
+0,     133120,     133120,     2048,     4096, 0xe90e9a12
68
+0,     135168,     135168,     2048,     4096, 0xae85c0f7
69
+0,     137216,     137216,     2048,     4096, 0x7ee877db
70
+0,     139264,     139264,     2048,     4096, 0x9ecf14ee
71
+0,     141312,     141312,     2048,     4096, 0xa821cecd
72
+0,     143360,     143360,     2048,     4096, 0x2714bb11
73
+0,     145408,     145408,     2048,     4096, 0x28f1c1e0
74
+0,     147456,     147456,     2048,     4096, 0xf81c4f60
75
+0,     149504,     149504,     2048,     4096, 0x1ae0e5a1
76
+0,     151552,     151552,     2048,     4096, 0xbdae9d9a
77
+0,     153600,     153600,     2048,     4096, 0x5202e560
78
+0,     155648,     155648,     2048,     4096, 0x82408396
79
+0,     157696,     157696,     2048,     4096, 0xc850ce0c
80
+0,     159744,     159744,     2048,     4096, 0x1d732d88
81
+0,     161792,     161792,     2048,     4096, 0xc5c01e33
82
+0,     163840,     163840,     2048,     4096, 0x84942d6c
83
+0,     165888,     165888,     2048,     4096, 0x7c27cd3a
84
+0,     167936,     167936,     2048,     4096, 0x22adc503
85
+0,     169984,     169984,     2048,     4096, 0xfbc3af31
86
+0,     172032,     172032,     2048,     4096, 0xe9652b18
87
+0,     174080,     174080,     2048,     4096, 0xae75987e
88
+0,     176128,     176128,     2048,     4096, 0x0f7ea428
89
+0,     178176,     178176,     2048,     4096, 0x92b89582
90
+0,     180224,     180224,     2048,     4096, 0xf393d910
91
+0,     182272,     182272,     2048,     4096, 0x6349b600
92
+0,     184320,     184320,     2048,     4096, 0x16918dbd
93
+0,     186368,     186368,     2048,     4096, 0x14ee15ad
94
+0,     188416,     188416,     2048,     4096, 0x26b510d3
95
+0,     190464,     190464,     2048,     4096, 0x97007bf8
96
+0,     192512,     192512,     2048,     4096, 0x3718c509
97
+0,     194560,     194560,     2048,     4096, 0x24a54ccd
98
+0,     196608,     196608,     2048,     4096, 0xc960df4e
99
+0,     198656,     198656,     2048,     4096, 0xc7cb6e6f
100
+0,     200704,     200704,     2048,     4096, 0x4c563ae5
101
+0,     202752,     202752,     2048,     4096, 0x0dd51432
102
+0,     204800,     204800,     2048,     4096, 0xdb4243c8
103
+0,     206848,     206848,     2048,     4096, 0x9bb6417f
104
+0,     208896,     208896,     2048,     4096, 0xec6a40a1
105
+0,     210944,     210944,     2048,     4096, 0x82d6c3b4
106
+0,     212992,     212992,     2048,     4096, 0xd181e2ec
107
+0,     215040,     215040,     2048,     4096, 0xba5d7b55
108
+0,     217088,     217088,     2048,     4096, 0x78fcb938
109
+0,     219136,     219136,     2048,     4096, 0x6691671c
110
+0,     221184,     221184,     2048,     4096, 0x44fadee7
111
+0,     223232,     223232,     2048,     4096, 0xa42720d5
112
+0,     225280,     225280,     2048,     4096, 0xc1165a91
113
+0,     227328,     227328,     2048,     4096, 0x86aa3e3f
114
+0,     229376,     229376,     2048,     4096, 0xab5ae57d
115
+0,     231424,     231424,     2048,     4096, 0x291a91f3
116
+0,     233472,     233472,     2048,     4096, 0xfdf0dcfc
117
+0,     235520,     235520,     2048,     4096, 0x1ef91f67
118
+0,     237568,     237568,     2048,     4096, 0xc899efee
119
+0,     239616,     239616,     2048,     4096, 0x5ade15ac
120
+0,     241664,     241664,     2048,     4096, 0x04516beb
121
+0,     243712,     243712,     2048,     4096, 0xbf5ebbb9
122
+0,     245760,     245760,     2048,     4096, 0x4a235122
123
+0,     247808,     247808,     2048,     4096, 0xd7a3f4a6
124
+0,     249856,     249856,     2048,     4096, 0x5f900f20
125
+0,     251904,     251904,     2048,     4096, 0xa90b4365
126
+0,     253952,     253952,     2048,     4096, 0x63149dc4
127
+0,     256000,     256000,     2048,     4096, 0xf12c1ee8
128
+0,     258048,     258048,     2048,     4096, 0x6d0fec8c
129
+0,     260096,     260096,     2048,     4096, 0x65e07850
130
+0,     262144,     262144,     2048,     4096, 0x16d951cc
131
+0,     264192,     264192,     2048,     4096, 0xd296d0c4
132
+0,     266240,     266240,     2048,     4096, 0x619b2a53
133
+0,     268288,     268288,     2048,     4096, 0x316972d5
134
+0,     270336,     270336,     2048,     4096, 0xcfd64e21
135
+0,     272384,     272384,     2048,     4096, 0xcbcb10c6
136
+0,     274432,     274432,     2048,     4096, 0x20aeff7c
137
+0,     276480,     276480,     2048,     4096, 0xd205dabd
138
+0,     278528,     278528,     2048,     4096, 0xac9d3001
139
+0,     280576,     280576,     2048,     4096, 0x6d53dfdd
140
+0,     282624,     282624,     2048,     4096, 0xbb9fe15c
141
+0,     284672,     284672,     2048,     4096, 0x1852b88b
142
+0,     286720,     286720,     2048,     4096, 0xb0acec01
143
+0,     288768,     288768,     2048,     4096, 0xb52a9342
144
+0,     290816,     290816,     2048,     4096, 0x7529faee
145
+0,     292864,     292864,     2048,     4096, 0x150ff449
146
+0,     294912,     294912,     2048,     4096, 0xa81d31d9
147
+0,     296960,     296960,     2048,     4096, 0xbcb8084a
148
+0,     299008,     299008,     2048,     4096, 0x07229514
149
+0,     301056,     301056,     2048,     4096, 0xa85cfd88
150
+0,     303104,     303104,     2048,     4096, 0x0aef9c27
151
+0,     305152,     305152,     2048,     4096, 0x8ec47b39
152
+0,     307200,     307200,     2048,     4096, 0x910b0560
153
+0,     309248,     309248,     2048,     4096, 0x99a8578e
154
+0,     311296,     311296,     2048,     4096, 0xb3df1d84
155
+0,     313344,     313344,     2048,     4096, 0x48e52559
156
+0,     315392,     315392,     2048,     4096, 0xb25c4800
157
+0,     317440,     317440,     2048,     4096, 0x913bc8ce
158
+0,     319488,     319488,     2048,     4096, 0xb736cc8c
159
+0,     321536,     321536,     2048,     4096, 0x13c66646
160
+0,     323584,     323584,     2048,     4096, 0x70a71221
161
+0,     325632,     325632,     2048,     4096, 0x3a50a08e
162
+0,     327680,     327680,     2048,     4096, 0xc0a037b0
163
+0,     329728,     329728,     2048,     4096, 0x9a789475
164
+0,     331776,     331776,     2048,     4096, 0xc890ca16
165
+0,     333824,     333824,     2048,     4096, 0xa0d34bed
166
+0,     335872,     335872,     2048,     4096, 0x1689fa60
167
+0,     337920,     337920,     2048,     4096, 0x5bac4c83
168
+0,     339968,     339968,      684,     1368, 0x904be5e5
... ...
@@ -1 +1 @@
1
-750269cc236541df28e15da5c7b0df7a
1
+94e2f200d6e05b47cec4aa3e94571cf3