History

Merge commit 'b522000e9b2ca36fe5b2751096b9a5f5ed8f87e6'

* commit 'b522000e9b2ca36fe5b2751096b9a5f5ed8f87e6': avio: introduce avio_closep mpegtsenc: set muxing type notification to verbose vc1dec: Use correct spelling of "opposite" a64multienc: change mc_frame_counter to unsigned arm: call arm-specific rv34dsp init functions under if (ARCH_ARM) svq1: Drop a bunch of useless parentheses parseutils-test: do not print numerical error codes svq1: K&R formatting cosmetics Conflicts: doc/APIchanges libavcodec/svq1dec.c libavcodec/svq1enc.c libavformat/version.h libavutil/parseutils.c tests/ref/fate/parseutils

Michael Niedermayer committed 14 years ago

Commit de318142 parents c4aaff8 b52200022 files · +1214 −1142Browse files

Unified · Split

22 files
  1. doc/APIchanges +3 −0
  2. libavcodec/a64enc.h +1 −1
  3. libavcodec/arm/Makefile +6 −6
  4. libavcodec/arm/rv34dsp_init_arm.c +14 −9
  5. libavcodec/arm/rv40dsp_init_arm.c +14 −5
  6. libavcodec/rv34dsp.c +2 −2
  7. libavcodec/rv34dsp.h +2 −2
  8. libavcodec/rv40dsp.c +2 −2
  9. libavcodec/svq1.c +2 −2
  10. libavcodec/svq1.h +4 −4
  11. libavcodec/svq13.c +39 −38
  12. libavcodec/svq1_vlc.h +108 −123
  13. libavcodec/svq1dec.c +589 −571
  14. libavcodec/svq1enc.c +322 −283
  15. libavcodec/svq1enc_cb.h +48 −58
  16. libavcodec/vc1dec.c +5 −5
  17. libavformat/avio.h +15 −0
  18. libavformat/aviobuf.c +7 −0
  19. libavformat/mpegtsenc.c +3 −3
  20. libavformat/version.h +1 −1
  21. libavutil/parseutils.c +2 −2
  22. tests/ref/fate/parseutils +25 −25
doc/APIchanges+3−0
@@ -97,6 +97,9 @@ API changes, most recent first: · 96 unmodified lines
9797 2012-03-26 - a67d9cf - lavfi 2.66.100
9898 Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions.
9999
100+2012-10-xx - xxxxxxx - lavf 54.18.0 - avio.h
101+ Add avio_closep to complement avio_close.
102+
100103 2012-10-xx - xxxxxxx - lavu 51.42.0 - pixfmt.h
101104 Rename PixelFormat to AVPixelFormat and all PIX_FMT_* to AV_PIX_FMT_*.
102105 To provide backwards compatibility, PixelFormat is now #defined as
libavcodec/a64enc.h+1−1
@@ -41,7 +41,7 @@ typedef struct A64Context { · 40 unmodified lines
4141 AVLFG randctx;
4242 int mc_lifetime;
4343 int mc_use_5col;
44− int mc_frame_counter;
44+ unsigned mc_frame_counter;
4545 int *mc_meta_charset;
4646 int *mc_charmap;
4747 int *mc_best_cb;
libavcodec/arm/Makefile+6−6
@@ -26,6 +26,10 @@ ARMV6-OBJS-$(CONFIG_VP8_DECODER) += arm/vp8_armv6.o \ · 25 unmodified lines
2626 OBJS-$(CONFIG_H264DSP) += arm/h264dsp_init_arm.o
2727 OBJS-$(CONFIG_H264PRED) += arm/h264pred_init_arm.o
2828
29+OBJS-$(CONFIG_RV30_DECODER) += arm/rv34dsp_init_arm.o
30+OBJS-$(CONFIG_RV40_DECODER) += arm/rv34dsp_init_arm.o \
31+ arm/rv40dsp_init_arm.o \
32+
2933 OBJS += arm/dsputil_init_arm.o \
3034 arm/dsputil_arm.o \
3135 arm/fft_init_arm.o \
@@ -72,12 +76,8 @@ NEON-OBJS-$(CONFIG_DCA_DECODER) += arm/dcadsp_neon.o \ · 40 unmodified lines
7276 arm/synth_filter_neon.o \
7377
7478 NEON-OBJS-$(CONFIG_MPEGVIDEO) += arm/mpegvideo_neon.o
75−NEON-OBJS-$(CONFIG_RV30_DECODER) += arm/rv34dsp_init_neon.o \
76− arm/rv34dsp_neon.o \
77−
78−NEON-OBJS-$(CONFIG_RV40_DECODER) += arm/rv34dsp_init_neon.o \
79− arm/rv34dsp_neon.o \
80− arm/rv40dsp_init_neon.o \
79+NEON-OBJS-$(CONFIG_RV30_DECODER) += arm/rv34dsp_neon.o
80+NEON-OBJS-$(CONFIG_RV40_DECODER) += arm/rv34dsp_neon.o \
8181 arm/rv40dsp_neon.o \
8282 arm/h264cmc_neon.o \
8383
libavcodec/arm/rv34dsp_init_arm.crenamed from libavcodec/arm/rv34dsp_init_neon.c+14−9
@@ -1,20 +1,20 @@
11 /*
22 * Copyright (c) 2011 Janne Grunau <janne-libav@jannau.net>
33 *
4− * This file is part of Libav.
4+ * This file is part of FFmpeg.
55 *
6− * Libav is free software; you can redistribute it and/or
6+ * FFmpeg is free software; you can redistribute it and/or
77 * modify it under the terms of the GNU Lesser General Public
88 * License as published by the Free Software Foundation; either
99 * version 2.1 of the License, or (at your option) any later version.
1010 *
11− * Libav is distributed in the hope that it will be useful,
11+ * FFmpeg is distributed in the hope that it will be useful,
1212 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1313 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1414 * Lesser General Public License for more details.
1515 *
1616 * You should have received a copy of the GNU Lesser General Public
17− * License along with Libav; if not, write to the Free Software
17+ * License along with FFmpeg; if not, write to the Free Software
1818 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1919 */
2020
@@ -22,6 +22,7 @@ · 1 unmodified line
2222
2323 #include "libavcodec/avcodec.h"
2424 #include "libavcodec/rv34dsp.h"
25+#include "libavutil/arm/cpu.h"
2526
2627 void ff_rv34_inv_transform_noround_neon(DCTELEM *block);
2728
@@ -30,11 +31,15 @@ void ff_rv34_inv_transform_noround_dc_neon(DCTELEM *block); · 2 unmodified lines
3031 void ff_rv34_idct_add_neon(uint8_t *dst, ptrdiff_t stride, DCTELEM *block);
3132 void ff_rv34_idct_dc_add_neon(uint8_t *dst, ptrdiff_t stride, int dc);
3233
33−void ff_rv34dsp_init_neon(RV34DSPContext *c, DSPContext* dsp)
34+void ff_rv34dsp_init_arm(RV34DSPContext *c, DSPContext* dsp)
3435 {
35− c->rv34_inv_transform = ff_rv34_inv_transform_noround_neon;
36− c->rv34_inv_transform_dc = ff_rv34_inv_transform_noround_dc_neon;
36+ int cpu_flags = av_get_cpu_flags();
3737
38− c->rv34_idct_add = ff_rv34_idct_add_neon;
39− c->rv34_idct_dc_add = ff_rv34_idct_dc_add_neon;
38+ if (have_neon(cpu_flags)) {
39+ c->rv34_inv_transform = ff_rv34_inv_transform_noround_neon;
40+ c->rv34_inv_transform_dc = ff_rv34_inv_transform_noround_dc_neon;
41+
42+ c->rv34_idct_add = ff_rv34_idct_add_neon;
43+ c->rv34_idct_dc_add = ff_rv34_idct_dc_add_neon;
44+ }
4045 }
libavcodec/arm/rv40dsp_init_arm.crenamed from libavcodec/arm/rv40dsp_init_neon.c+14−5
@@ -1,20 +1,20 @@
11 /*
22 * Copyright (c) 2011 Janne Grunau <janne-libav@jannau.net>
33 *
4− * This file is part of Libav.
4+ * This file is part of FFmpeg.
55 *
6− * Libav is free software; you can redistribute it and/or
6+ * FFmpeg is free software; you can redistribute it and/or
77 * modify it under the terms of the GNU Lesser General Public
88 * License as published by the Free Software Foundation; either
99 * version 2.1 of the License, or (at your option) any later version.
1010 *
11− * Libav is distributed in the hope that it will be useful,
11+ * FFmpeg is distributed in the hope that it will be useful,
1212 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1313 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1414 * Lesser General Public License for more details.
1515 *
1616 * You should have received a copy of the GNU Lesser General Public
17− * License along with Libav; if not, write to the Free Software
17+ * License along with FFmpeg; if not, write to the Free Software
1818 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1919 */
2020
@@ -22,6 +22,7 @@ · 1 unmodified line
2222
2323 #include "libavcodec/avcodec.h"
2424 #include "libavcodec/rv34dsp.h"
25+#include "libavutil/arm/cpu.h"
2526
2627 #define DECL_QPEL3(type, w, pos) \
2728 void ff_##type##_rv40_qpel##w##_mc##pos##_neon(uint8_t *dst, uint8_t *src,\
@@ -68,7 +69,7 @@ void ff_rv40_v_weak_loop_filter_neon(uint8_t *src, ptrdiff_t stride, int filter_ · 40 unmodified lines
6869 int filter_q1, int alpha, int beta,
6970 int lim_p0q0, int lim_q1, int lim_p1);
7071
71−void ff_rv40dsp_init_neon(RV34DSPContext *c, DSPContext* dsp)
72+static void ff_rv40dsp_init_neon(RV34DSPContext *c)
7273 {
7374 c->put_pixels_tab[0][ 1] = ff_put_rv40_qpel16_mc10_neon;
7475 c->put_pixels_tab[0][ 3] = ff_put_rv40_qpel16_mc30_neon;
@@ -136,3 +137,11 @@ void ff_rv40dsp_init_neon(RV34DSPContext *c, DSPContext* dsp) · 61 unmodified lines
136137 c->rv40_weak_loop_filter[0] = ff_rv40_h_weak_loop_filter_neon;
137138 c->rv40_weak_loop_filter[1] = ff_rv40_v_weak_loop_filter_neon;
138139 }
140+
141+void ff_rv40dsp_init_arm(RV34DSPContext *c, DSPContext* dsp)
142+{
143+ int cpu_flags = av_get_cpu_flags();
144+
145+ if (have_neon(cpu_flags))
146+ ff_rv40dsp_init_neon(c);
147+}
libavcodec/rv34dsp.c+2−2
@@ -135,8 +135,8 @@ av_cold void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp) { · 134 unmodified lines
135135 c->rv34_idct_add = rv34_idct_add_c;
136136 c->rv34_idct_dc_add = rv34_idct_dc_add_c;
137137
138− if (HAVE_NEON)
139− ff_rv34dsp_init_neon(c, dsp);
138+ if (ARCH_ARM)
139+ ff_rv34dsp_init_arm(c, dsp);
140140 if (ARCH_X86)
141141 ff_rv34dsp_init_x86(c, dsp);
142142 }
libavcodec/rv34dsp.h+2−2
@@ -77,10 +77,10 @@ void ff_rv30dsp_init(RV34DSPContext *c, DSPContext* dsp); · 76 unmodified lines
7777 void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp);
7878 void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp);
7979
80−void ff_rv34dsp_init_neon(RV34DSPContext *c, DSPContext *dsp);
80+void ff_rv34dsp_init_arm(RV34DSPContext *c, DSPContext *dsp);
8181 void ff_rv34dsp_init_x86(RV34DSPContext *c, DSPContext *dsp);
8282
8383 void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp);
84−void ff_rv40dsp_init_neon(RV34DSPContext *c, DSPContext *dsp);
84+void ff_rv40dsp_init_arm(RV34DSPContext *c, DSPContext *dsp);
8585
8686 #endif /* AVCODEC_RV34DSP_H */
libavcodec/rv40dsp.c+2−2
@@ -606,6 +606,6 @@ av_cold void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp) { · 605 unmodified lines
606606
607607 if (ARCH_X86)
608608 ff_rv40dsp_init_x86(c, dsp);
609− if (HAVE_NEON)
610− ff_rv40dsp_init_neon(c, dsp);
609+ if (ARCH_ARM)
610+ ff_rv40dsp_init_arm(c, dsp);
611611 }
libavcodec/svq1.c+2−2
@@ -38,6 +38,6 @@ · 37 unmodified lines
3838
3939 /* standard video sizes */
4040 const struct svq1_frame_size ff_svq1_frame_size_table[7] = {
41− { 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 },
42− { 704, 576 }, { 240, 180 }, { 320, 240 }
41+ { 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 },
42+ { 704, 576 }, { 240, 180 }, { 320, 240 }
4343 };
libavcodec/svq1.h+4−4
@@ -47,11 +47,11 @@ struct svq1_frame_size { · 46 unmodified lines
4747 uint16_t height;
4848 };
4949
50−uint16_t ff_svq1_packet_checksum (const uint8_t *data, const int length,
51− int value);
50+uint16_t ff_svq1_packet_checksum(const uint8_t *data,
51+ const int length, int value);
5252
53−extern const int8_t* const ff_svq1_inter_codebooks[6];
54−extern const int8_t* const ff_svq1_intra_codebooks[6];
53+extern const int8_t *const ff_svq1_inter_codebooks[6];
54+extern const int8_t *const ff_svq1_intra_codebooks[6];
5555
5656 extern const uint8_t ff_svq1_block_type_vlc[4][2];
5757 extern const uint8_t ff_svq1_intra_multistage_vlc[6][8][2];
libavcodec/svq13.c+39−38
@@ -23,46 +23,47 @@ · 22 unmodified lines
2323 #include "svq1.h"
2424
2525 static const uint16_t checksum_table[256] = {
26− 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
27− 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
28− 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
29− 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
30− 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
31− 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
32− 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
33− 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
34− 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
35− 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
36− 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
37− 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
38− 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
39− 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
40− 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
41− 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
42− 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
43− 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
44− 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
45− 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
46− 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
47− 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
48− 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
49− 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
50− 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
51− 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
52− 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
53− 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
54− 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
55− 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
56− 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
57− 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
26+ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
27+ 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
28+ 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
29+ 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
30+ 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
31+ 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
32+ 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
33+ 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
34+ 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
35+ 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
36+ 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
37+ 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
38+ 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
39+ 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
40+ 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
41+ 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
42+ 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
43+ 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
44+ 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
45+ 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
46+ 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
47+ 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
48+ 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
49+ 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
50+ 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
51+ 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
52+ 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
53+ 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
54+ 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
55+ 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
56+ 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
57+ 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
5858 };
5959
60−uint16_t ff_svq1_packet_checksum (const uint8_t *data, const int length, int value) {
61− int i;
60+uint16_t ff_svq1_packet_checksum (const uint8_t *data,
61+ const int length, int value)
62+{
63+ int i;
6264
63− for (i=0; i < length; i++) {
64− value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
65− }
65+ for (i = 0; i < length; i++)
66+ value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
6667
67− return value;
68+ return value;
6869 }
libavcodec/svq1_vlc.h+108−123
@@ -25,131 +25,116 @@ · 24 unmodified lines
2525
2626 /* values in this table range from 0..3; adjust retrieved value by +0 */
2727 const uint8_t ff_svq1_block_type_vlc[4][2] = {
28− /* { code, length } */
28+ /* { code, length } */
2929 { 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 }, { 0x0, 3 }
30−
3130 };
3231
3332 /* values in this table range from -1..6; adjust retrieved value by -1 */
3433 const uint8_t ff_svq1_intra_multistage_vlc[6][8][2] = {
35− /* { code, length } */
36−{
37− { 0x1, 5 }, { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 },
38− { 0x3, 4 }, { 0x2, 4 }, { 0x0, 5 }, { 0x1, 4 }
39−},{
40− { 0x1, 4 }, { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 },
41− { 0x3, 3 }, { 0x2, 3 }, { 0x0, 4 }, { 0x1, 3 }
42−},{
43− { 0x1, 5 }, { 0x1, 1 }, { 0x3, 3 }, { 0x0, 5 },
44− { 0x3, 4 }, { 0x2, 3 }, { 0x2, 4 }, { 0x1, 4 }
45−},{
46− { 0x1, 6 }, { 0x1, 1 }, { 0x1, 2 }, { 0x0, 6 },
47− { 0x3, 4 }, { 0x2, 4 }, { 0x1, 5 }, { 0x1, 4 }
48−},{
49− { 0x1, 6 }, { 0x1, 1 }, { 0x1, 2 }, { 0x3, 5 },
50− { 0x2, 5 }, { 0x0, 6 }, { 0x1, 5 }, { 0x1, 3 }
51−},{
52− { 0x1, 7 }, { 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 },
53− { 0x1, 4 }, { 0x1, 6 }, { 0x0, 7 }, { 0x1, 5 }
54−}
34+ /* { code, length } */
35+ { { 0x1, 5 }, { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 },
36+ { 0x3, 4 }, { 0x2, 4 }, { 0x0, 5 }, { 0x1, 4 } },
37+ { { 0x1, 4 }, { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 },
38+ { 0x3, 3 }, { 0x2, 3 }, { 0x0, 4 }, { 0x1, 3 } },
39+ { { 0x1, 5 }, { 0x1, 1 }, { 0x3, 3 }, { 0x0, 5 },
40+ { 0x3, 4 }, { 0x2, 3 }, { 0x2, 4 }, { 0x1, 4 } },
41+ { { 0x1, 6 }, { 0x1, 1 }, { 0x1, 2 }, { 0x0, 6 },
42+ { 0x3, 4 }, { 0x2, 4 }, { 0x1, 5 }, { 0x1, 4 } },
43+ { { 0x1, 6 }, { 0x1, 1 }, { 0x1, 2 }, { 0x3, 5 },
44+ { 0x2, 5 }, { 0x0, 6 }, { 0x1, 5 }, { 0x1, 3 } },
45+ { { 0x1, 7 }, { 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 },
46+ { 0x1, 4 }, { 0x1, 6 }, { 0x0, 7 }, { 0x1, 5 } }
5547 };
5648
5749 /* values in this table range from -1..6; adjust retrieved value by -1 */
5850 const uint8_t ff_svq1_inter_multistage_vlc[6][8][2] = {
59− /* { code, length } */
60−{
61− { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 }, { 0x3, 3 },
62− { 0x2, 3 }, { 0x1, 3 }, { 0x1, 4 }, { 0x0, 4 }
63−},{
64− { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 }, { 0x3, 3 },
65− { 0x2, 3 }, { 0x1, 3 }, { 0x1, 4 }, { 0x0, 4 }
66−},{
67− { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 },
68− { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 }
69−},{
70− { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 },
71− { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 }
72−},{
73− { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 },
74− { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 }
75−},{
76− { 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 }, { 0x3, 5 },
77− { 0x2, 5 }, { 0x1, 5 }, { 0x1, 6 }, { 0x0, 6 }
78−}
51+ /* { code, length } */
52+ { { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 }, { 0x3, 3 },
53+ { 0x2, 3 }, { 0x1, 3 }, { 0x1, 4 }, { 0x0, 4 } },
54+ { { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 }, { 0x3, 3 },
55+ { 0x2, 3 }, { 0x1, 3 }, { 0x1, 4 }, { 0x0, 4 } },
56+ { { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 },
57+ { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 } },
58+ { { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 },
59+ { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 } },
60+ { { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 },
61+ { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 } },
62+ { { 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 }, { 0x3, 5 },
63+ { 0x2, 5 }, { 0x1, 5 }, { 0x1, 6 }, { 0x0, 6 } }
7964 };
8065
8166 /* values in this table range from 0..255; adjust retrieved value by +0 */
8267 const uint16_t ff_svq1_intra_mean_vlc[256][2] = {
83− /* { code, length } */
84− { 0x37, 6 }, { 0x56, 7 }, { 0x1, 17 }, { 0x1, 20 },
85− { 0x2, 20 }, { 0x3, 20 }, { 0x0, 20 }, { 0x4, 20 },
86− { 0x5, 20 }, { 0x3, 19 }, { 0x15, 11 }, { 0x42, 9 },
87− { 0x14, 11 }, { 0x3, 14 }, { 0x2, 14 }, { 0x1, 15 },
88− { 0x1, 16 }, { 0x1, 12 }, { 0x2B, 10 }, { 0x18, 11 },
89− { 0xC, 11 }, { 0x41, 9 }, { 0x78, 8 }, { 0x6C, 8 },
90− { 0x55, 7 }, { 0xF, 4 }, { 0xE, 4 }, { 0x34, 6 },
91− { 0x51, 7 }, { 0x72, 8 }, { 0x6E, 8 }, { 0x40, 9 },
92− { 0x3F, 9 }, { 0x3E, 9 }, { 0x3D, 9 }, { 0x3C, 9 },
93− { 0x3B, 9 }, { 0x3A, 9 }, { 0x39, 9 }, { 0x38, 9 },
94− { 0x37, 9 }, { 0x43, 9 }, { 0x46, 9 }, { 0x47, 9 },
95− { 0x45, 9 }, { 0x44, 9 }, { 0x49, 9 }, { 0x48, 9 },
96− { 0x4A, 8 }, { 0x79, 8 }, { 0x76, 8 }, { 0x77, 8 },
97− { 0x71, 8 }, { 0x75, 8 }, { 0x74, 8 }, { 0x73, 8 },
98− { 0x6A, 8 }, { 0x55, 8 }, { 0x70, 8 }, { 0x6F, 8 },
99− { 0x52, 8 }, { 0x6D, 8 }, { 0x4C, 8 }, { 0x6B, 8 },
100− { 0x40, 7 }, { 0x69, 8 }, { 0x68, 8 }, { 0x67, 8 },
101− { 0x66, 8 }, { 0x65, 8 }, { 0x64, 8 }, { 0x63, 8 },
102− { 0x62, 8 }, { 0x61, 8 }, { 0x60, 8 }, { 0x5F, 8 },
103− { 0x5E, 8 }, { 0x5D, 8 }, { 0x5C, 8 }, { 0x5B, 8 },
104− { 0x5A, 8 }, { 0x59, 8 }, { 0x58, 8 }, { 0x57, 8 },
105− { 0x56, 8 }, { 0x3D, 7 }, { 0x54, 8 }, { 0x53, 8 },
106− { 0x3F, 7 }, { 0x51, 8 }, { 0x50, 8 }, { 0x4F, 8 },
107− { 0x4E, 8 }, { 0x4D, 8 }, { 0x41, 7 }, { 0x4B, 8 },
108− { 0x53, 7 }, { 0x3E, 7 }, { 0x48, 8 }, { 0x4F, 7 },
109− { 0x52, 7 }, { 0x45, 8 }, { 0x50, 7 }, { 0x43, 8 },
110− { 0x42, 8 }, { 0x41, 8 }, { 0x42, 7 }, { 0x43, 7 },
111− { 0x3E, 8 }, { 0x44, 7 }, { 0x3C, 8 }, { 0x45, 7 },
112− { 0x46, 7 }, { 0x47, 7 }, { 0x48, 7 }, { 0x49, 7 },
113− { 0x4A, 7 }, { 0x4B, 7 }, { 0x4C, 7 }, { 0x4D, 7 },
114− { 0x4E, 7 }, { 0x58, 7 }, { 0x59, 7 }, { 0x5A, 7 },
115− { 0x5B, 7 }, { 0x5C, 7 }, { 0x5D, 7 }, { 0x44, 8 },
116− { 0x49, 8 }, { 0x29, 8 }, { 0x3F, 8 }, { 0x3D, 8 },
117− { 0x3B, 8 }, { 0x2C, 8 }, { 0x28, 8 }, { 0x25, 8 },
118− { 0x26, 8 }, { 0x5E, 7 }, { 0x57, 7 }, { 0x54, 7 },
119− { 0x5F, 7 }, { 0x62, 7 }, { 0x63, 7 }, { 0x64, 7 },
120− { 0x61, 7 }, { 0x65, 7 }, { 0x67, 7 }, { 0x66, 7 },
121− { 0x35, 6 }, { 0x36, 6 }, { 0x60, 7 }, { 0x39, 8 },
122− { 0x3A, 8 }, { 0x38, 8 }, { 0x37, 8 }, { 0x36, 8 },
123− { 0x35, 8 }, { 0x34, 8 }, { 0x33, 8 }, { 0x32, 8 },
124− { 0x31, 8 }, { 0x30, 8 }, { 0x2D, 8 }, { 0x2B, 8 },
125− { 0x2A, 8 }, { 0x27, 8 }, { 0x40, 8 }, { 0x46, 8 },
126− { 0x47, 8 }, { 0x26, 9 }, { 0x25, 9 }, { 0x24, 9 },
127− { 0x23, 9 }, { 0x22, 9 }, { 0x2E, 8 }, { 0x2F, 8 },
128− { 0x1F, 9 }, { 0x36, 9 }, { 0x1D, 9 }, { 0x21, 9 },
129− { 0x1B, 9 }, { 0x1C, 9 }, { 0x19, 9 }, { 0x1A, 9 },
130− { 0x18, 9 }, { 0x17, 9 }, { 0x16, 9 }, { 0x1E, 9 },
131− { 0x20, 9 }, { 0x27, 9 }, { 0x28, 9 }, { 0x29, 9 },
132− { 0x2A, 9 }, { 0x2B, 9 }, { 0x2C, 9 }, { 0x2D, 9 },
133− { 0x2E, 9 }, { 0x2F, 9 }, { 0x30, 9 }, { 0x35, 9 },
134− { 0x31, 9 }, { 0x32, 9 }, { 0x33, 9 }, { 0x34, 9 },
68+ /* { code, length } */
69+ { 0x37, 6 }, { 0x56, 7 }, { 0x01, 17 }, { 0x01, 20 },
70+ { 0x02, 20 }, { 0x03, 20 }, { 0x00, 20 }, { 0x04, 20 },
71+ { 0x05, 20 }, { 0x03, 19 }, { 0x15, 11 }, { 0x42, 9 },
72+ { 0x14, 11 }, { 0x03, 14 }, { 0x02, 14 }, { 0x01, 15 },
73+ { 0x01, 16 }, { 0x01, 12 }, { 0x2B, 10 }, { 0x18, 11 },
74+ { 0x0C, 11 }, { 0x41, 9 }, { 0x78, 8 }, { 0x6C, 8 },
75+ { 0x55, 7 }, { 0x0F, 4 }, { 0x0E, 4 }, { 0x34, 6 },
76+ { 0x51, 7 }, { 0x72, 8 }, { 0x6E, 8 }, { 0x40, 9 },
77+ { 0x3F, 9 }, { 0x3E, 9 }, { 0x3D, 9 }, { 0x3C, 9 },
78+ { 0x3B, 9 }, { 0x3A, 9 }, { 0x39, 9 }, { 0x38, 9 },
79+ { 0x37, 9 }, { 0x43, 9 }, { 0x46, 9 }, { 0x47, 9 },
80+ { 0x45, 9 }, { 0x44, 9 }, { 0x49, 9 }, { 0x48, 9 },
81+ { 0x4A, 8 }, { 0x79, 8 }, { 0x76, 8 }, { 0x77, 8 },
82+ { 0x71, 8 }, { 0x75, 8 }, { 0x74, 8 }, { 0x73, 8 },
83+ { 0x6A, 8 }, { 0x55, 8 }, { 0x70, 8 }, { 0x6F, 8 },
84+ { 0x52, 8 }, { 0x6D, 8 }, { 0x4C, 8 }, { 0x6B, 8 },
85+ { 0x40, 7 }, { 0x69, 8 }, { 0x68, 8 }, { 0x67, 8 },
86+ { 0x66, 8 }, { 0x65, 8 }, { 0x64, 8 }, { 0x63, 8 },
87+ { 0x62, 8 }, { 0x61, 8 }, { 0x60, 8 }, { 0x5F, 8 },
88+ { 0x5E, 8 }, { 0x5D, 8 }, { 0x5C, 8 }, { 0x5B, 8 },
89+ { 0x5A, 8 }, { 0x59, 8 }, { 0x58, 8 }, { 0x57, 8 },
90+ { 0x56, 8 }, { 0x3D, 7 }, { 0x54, 8 }, { 0x53, 8 },
91+ { 0x3F, 7 }, { 0x51, 8 }, { 0x50, 8 }, { 0x4F, 8 },
92+ { 0x4E, 8 }, { 0x4D, 8 }, { 0x41, 7 }, { 0x4B, 8 },
93+ { 0x53, 7 }, { 0x3E, 7 }, { 0x48, 8 }, { 0x4F, 7 },
94+ { 0x52, 7 }, { 0x45, 8 }, { 0x50, 7 }, { 0x43, 8 },
95+ { 0x42, 8 }, { 0x41, 8 }, { 0x42, 7 }, { 0x43, 7 },
96+ { 0x3E, 8 }, { 0x44, 7 }, { 0x3C, 8 }, { 0x45, 7 },
97+ { 0x46, 7 }, { 0x47, 7 }, { 0x48, 7 }, { 0x49, 7 },
98+ { 0x4A, 7 }, { 0x4B, 7 }, { 0x4C, 7 }, { 0x4D, 7 },
99+ { 0x4E, 7 }, { 0x58, 7 }, { 0x59, 7 }, { 0x5A, 7 },
100+ { 0x5B, 7 }, { 0x5C, 7 }, { 0x5D, 7 }, { 0x44, 8 },
101+ { 0x49, 8 }, { 0x29, 8 }, { 0x3F, 8 }, { 0x3D, 8 },
102+ { 0x3B, 8 }, { 0x2C, 8 }, { 0x28, 8 }, { 0x25, 8 },
103+ { 0x26, 8 }, { 0x5E, 7 }, { 0x57, 7 }, { 0x54, 7 },
104+ { 0x5F, 7 }, { 0x62, 7 }, { 0x63, 7 }, { 0x64, 7 },
105+ { 0x61, 7 }, { 0x65, 7 }, { 0x67, 7 }, { 0x66, 7 },
106+ { 0x35, 6 }, { 0x36, 6 }, { 0x60, 7 }, { 0x39, 8 },
107+ { 0x3A, 8 }, { 0x38, 8 }, { 0x37, 8 }, { 0x36, 8 },
108+ { 0x35, 8 }, { 0x34, 8 }, { 0x33, 8 }, { 0x32, 8 },
109+ { 0x31, 8 }, { 0x30, 8 }, { 0x2D, 8 }, { 0x2B, 8 },
110+ { 0x2A, 8 }, { 0x27, 8 }, { 0x40, 8 }, { 0x46, 8 },
111+ { 0x47, 8 }, { 0x26, 9 }, { 0x25, 9 }, { 0x24, 9 },
112+ { 0x23, 9 }, { 0x22, 9 }, { 0x2E, 8 }, { 0x2F, 8 },
113+ { 0x1F, 9 }, { 0x36, 9 }, { 0x1D, 9 }, { 0x21, 9 },
114+ { 0x1B, 9 }, { 0x1C, 9 }, { 0x19, 9 }, { 0x1A, 9 },
115+ { 0x18, 9 }, { 0x17, 9 }, { 0x16, 9 }, { 0x1E, 9 },
116+ { 0x20, 9 }, { 0x27, 9 }, { 0x28, 9 }, { 0x29, 9 },
117+ { 0x2A, 9 }, { 0x2B, 9 }, { 0x2C, 9 }, { 0x2D, 9 },
118+ { 0x2E, 9 }, { 0x2F, 9 }, { 0x30, 9 }, { 0x35, 9 },
119+ { 0x31, 9 }, { 0x32, 9 }, { 0x33, 9 }, { 0x34, 9 },
135120 { 0x19, 10 }, { 0x2A, 10 }, { 0x17, 10 }, { 0x16, 10 },
136121 { 0x15, 10 }, { 0x28, 10 }, { 0x26, 10 }, { 0x25, 10 },
137122 { 0x22, 10 }, { 0x21, 10 }, { 0x18, 10 }, { 0x14, 10 },
138− { 0x29, 10 }, { 0x12, 10 }, { 0xD, 10 }, { 0xE, 10 },
139− { 0xF, 10 }, { 0x10, 10 }, { 0x11, 10 }, { 0x1A, 10 },
123+ { 0x29, 10 }, { 0x12, 10 }, { 0x0D, 10 }, { 0x0E, 10 },
124+ { 0x0F, 10 }, { 0x10, 10 }, { 0x11, 10 }, { 0x1A, 10 },
140125 { 0x1B, 10 }, { 0x1C, 10 }, { 0x1D, 10 }, { 0x1E, 10 },
141126 { 0x1F, 10 }, { 0x20, 10 }, { 0x13, 10 }, { 0x23, 10 },
142− { 0x24, 10 }, { 0x9, 11 }, { 0x8, 11 }, { 0x7, 11 },
143− { 0x27, 10 }, { 0x5, 11 }, { 0xB, 11 }, { 0x6, 11 },
144− { 0x4, 11 }, { 0x3, 11 }, { 0x2, 11 }, { 0x1, 11 },
145− { 0xA, 11 }, { 0x16, 11 }, { 0x19, 11 }, { 0x17, 11 },
146− { 0xD, 11 }, { 0xE, 11 }, { 0xF, 11 }, { 0x10, 11 },
147− { 0x11, 11 }, { 0x12, 11 }, { 0x13, 11 }, { 0x1, 14 }
127+ { 0x24, 10 }, { 0x09, 11 }, { 0x08, 11 }, { 0x07, 11 },
128+ { 0x27, 10 }, { 0x05, 11 }, { 0x0B, 11 }, { 0x06, 11 },
129+ { 0x04, 11 }, { 0x03, 11 }, { 0x02, 11 }, { 0x01, 11 },
130+ { 0x0A, 11 }, { 0x16, 11 }, { 0x19, 11 }, { 0x17, 11 },
131+ { 0x0D, 11 }, { 0x0E, 11 }, { 0x0F, 11 }, { 0x10, 11 },
132+ { 0x11, 11 }, { 0x12, 11 }, { 0x13, 11 }, { 0x01, 14 }
148133 };
149134
150135 /* values in this table range from -256..255; adjust retrieved value by -256 */
151136 const uint16_t ff_svq1_inter_mean_vlc[512][2] = {
152− /* { code, length } */
137+ /* { code, length } */
153138 { 0x5A, 22 }, { 0xD4, 22 }, { 0xD5, 22 }, { 0xD6, 22 },
154139 { 0xD7, 22 }, { 0xD8, 22 }, { 0xD9, 22 }, { 0xDA, 22 },
155140 { 0xDB, 22 }, { 0xDC, 22 }, { 0xDD, 22 }, { 0xDE, 22 },
@@ -159,12 +144,12 @@ const uint16_t ff_svq1_inter_mean_vlc[512][2] = { · 3 unmodified lines
159144 { 0xE7, 22 }, { 0xEC, 22 }, { 0xED, 22 }, { 0xEE, 22 },
160145 { 0xEF, 22 }, { 0xF0, 22 }, { 0xF1, 22 }, { 0xF2, 22 },
161146 { 0xF3, 22 }, { 0xF4, 22 }, { 0xF5, 22 }, { 0xF6, 22 },
162− { 0xF7, 22 }, { 0xF8, 22 }, { 0x102, 22 }, { 0xEB, 22 },
147+ { 0xF7, 22 }, { 0xF8, 22 }, { 0x102,22 }, { 0xEB, 22 },
163148 { 0xF9, 22 }, { 0xFC, 22 }, { 0xFD, 22 }, { 0xFE, 22 },
164− { 0x100, 22 }, { 0x5C, 22 }, { 0x60, 22 }, { 0x101, 22 },
165− { 0x71, 22 }, { 0x104, 22 }, { 0x105, 22 }, { 0xFB, 22 },
149+ { 0x100,22 }, { 0x5C, 22 }, { 0x60, 22 }, { 0x101,22 },
150+ { 0x71, 22 }, { 0x104,22 }, { 0x105,22 }, { 0xFB, 22 },
166151 { 0xFF, 22 }, { 0x86, 21 }, { 0xFA, 22 }, { 0x7C, 22 },
167− { 0x75, 22 }, { 0x103, 22 }, { 0x78, 22 }, { 0xD3, 22 },
152+ { 0x75, 22 }, { 0x103,22 }, { 0x78, 22 }, { 0xD3, 22 },
168153 { 0x7B, 22 }, { 0x82, 22 }, { 0xD2, 22 }, { 0xD1, 22 },
169154 { 0xD0, 22 }, { 0xCF, 22 }, { 0xCE, 22 }, { 0xCD, 22 },
170155 { 0xCC, 22 }, { 0xC3, 22 }, { 0xCA, 22 }, { 0xC9, 22 },
@@ -206,19 +191,19 @@ const uint16_t ff_svq1_inter_mean_vlc[512][2] = { · 35 unmodified lines
206191 { 0x21, 14 }, { 0x13, 13 }, { 0x14, 13 }, { 0x15, 13 },
207192 { 0x16, 13 }, { 0x17, 13 }, { 0x18, 13 }, { 0x19, 13 },
208193 { 0x1A, 13 }, { 0x18, 12 }, { 0x17, 12 }, { 0x15, 12 },
209− { 0x14, 12 }, { 0x13, 12 }, { 0x12, 12 }, { 0xF, 11 },
194+ { 0x14, 12 }, { 0x13, 12 }, { 0x12, 12 }, { 0x0F, 11 },
210195 { 0x10, 11 }, { 0x12, 11 }, { 0x13, 11 }, { 0x1B, 11 },
211− { 0x1A, 11 }, { 0xE, 10 }, { 0x13, 10 }, { 0xF, 10 },
212− { 0x10, 10 }, { 0x11, 10 }, { 0x12, 10 }, { 0xD, 9 },
213− { 0x14, 9 }, { 0x15, 9 }, { 0xC, 9 }, { 0x13, 9 },
214− { 0xF, 8 }, { 0xE, 8 }, { 0x10, 8 }, { 0x11, 8 },
215− { 0xC, 7 }, { 0x9, 7 }, { 0xA, 7 }, { 0x8, 6 },
216− { 0x9, 6 }, { 0x9, 5 }, { 0x8, 5 }, { 0x5, 4 },
217− { 0x1, 1 }, { 0x3, 3 }, { 0x7, 5 }, { 0x6, 5 },
218− { 0xB, 6 }, { 0xA, 6 }, { 0xE, 7 }, { 0xF, 7 },
219− { 0xB, 7 }, { 0xD, 7 }, { 0xB, 8 }, { 0xD, 8 },
220− { 0xC, 8 }, { 0xF, 9 }, { 0x10, 9 }, { 0x11, 9 },
221− { 0xE, 9 }, { 0x12, 9 }, { 0x17, 10 }, { 0x14, 10 },
196+ { 0x1A, 11 }, { 0x0E, 10 }, { 0x13, 10 }, { 0x0F, 10 },
197+ { 0x10, 10 }, { 0x11, 10 }, { 0x12, 10 }, { 0x0D, 9 },
198+ { 0x14, 9 }, { 0x15, 9 }, { 0x0C, 9 }, { 0x13, 9 },
199+ { 0x0F, 8 }, { 0x0E, 8 }, { 0x10, 8 }, { 0x11, 8 },
200+ { 0x0C, 7 }, { 0x09, 7 }, { 0x0A, 7 }, { 0x08, 6 },
201+ { 0x09, 6 }, { 0x09, 5 }, { 0x08, 5 }, { 0x05, 4 },
202+ { 0x01, 1 }, { 0x03, 3 }, { 0x07, 5 }, { 0x06, 5 },
203+ { 0x0B, 6 }, { 0x0A, 6 }, { 0x0E, 7 }, { 0x0F, 7 },
204+ { 0x0B, 7 }, { 0x0D, 7 }, { 0x0B, 8 }, { 0x0D, 8 },
205+ { 0x0C, 8 }, { 0x0F, 9 }, { 0x10, 9 }, { 0x11, 9 },
206+ { 0x0E, 9 }, { 0x12, 9 }, { 0x17, 10 }, { 0x14, 10 },
222207 { 0x16, 10 }, { 0x15, 10 }, { 0x19, 11 }, { 0x18, 11 },
223208 { 0x17, 11 }, { 0x16, 11 }, { 0x15, 11 }, { 0x14, 11 },
224209 { 0x11, 11 }, { 0x19, 12 }, { 0x1A, 12 }, { 0x16, 12 },
@@ -274,10 +259,10 @@ const uint16_t ff_svq1_inter_mean_vlc[512][2] = { · 49 unmodified lines
274259 { 0x1B, 22 }, { 0x1A, 22 }, { 0x19, 22 }, { 0x18, 22 },
275260 { 0x17, 22 }, { 0x16, 22 }, { 0x15, 22 }, { 0x14, 22 },
276261 { 0x13, 22 }, { 0x12, 22 }, { 0x11, 22 }, { 0x10, 22 },
277− { 0xF, 22 }, { 0xE, 22 }, { 0xD, 22 }, { 0xC, 22 },
278− { 0xB, 22 }, { 0xA, 22 }, { 0x9, 22 }, { 0x8, 22 },
279− { 0x7, 22 }, { 0x6, 22 }, { 0x5, 22 }, { 0x4, 22 },
280− { 0x3, 22 }, { 0x2, 22 }, { 0x1, 22 }, { 0x0, 22 }
262+ { 0x0F, 22 }, { 0x0E, 22 }, { 0x0D, 22 }, { 0x0C, 22 },
263+ { 0x0B, 22 }, { 0x0A, 22 }, { 0x09, 22 }, { 0x08, 22 },
264+ { 0x07, 22 }, { 0x06, 22 }, { 0x05, 22 }, { 0x04, 22 },
265+ { 0x03, 22 }, { 0x02, 22 }, { 0x01, 22 }, { 0x00, 22 }
281266 };
282267
283268 #endif /* AVCODEC_SVQ1_VLC_H */
libavcodec/svq1dec.c+589−571
@@ -32,12 +32,10 @@ · 31 unmodified lines
3232 * http://www.pcisys.net/~melanson/codecs/
3333 */
3434
35−
3635 #include "avcodec.h"
3736 #include "dsputil.h"
3837 #include "mpegvideo.h"
3938 #include "mathops.h"
40−
4139 #include "svq1.h"
4240
4341 #undef NDEBUG
@@ -54,655 +52,670 @@ static VLC svq1_inter_mean; · 10 unmodified lines
5452
5553 /* motion vector (prediction) */
5654 typedef struct svq1_pmv_s {
57− int x;
58− int y;
55+ int x;
56+ int y;
5957 } svq1_pmv;
6058
6159 static const uint8_t string_table[256] = {
62− 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54,
63− 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
64− 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06,
65− 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
66− 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0,
67− 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9,
68− 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2,
69− 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B,
70− 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9,
71− 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0,
72− 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B,
73− 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2,
74− 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D,
75− 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44,
76− 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F,
77− 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16,
78− 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB,
79− 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92,
80− 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9,
81− 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0,
82− 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F,
83− 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36,
84− 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D,
85− 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64,
86− 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26,
87− 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F,
88− 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74,
89− 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D,
90− 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82,
91− 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB,
92− 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0,
93− 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9
60+ 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54,
61+ 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
62+ 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06,
63+ 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
64+ 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0,
65+ 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9,
66+ 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2,
67+ 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B,
68+ 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9,
69+ 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0,
70+ 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B,
71+ 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2,
72+ 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D,
73+ 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44,
74+ 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F,
75+ 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16,
76+ 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB,
77+ 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92,
78+ 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9,
79+ 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0,
80+ 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F,
81+ 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36,
82+ 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D,
83+ 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64,
84+ 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26,
85+ 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F,
86+ 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74,
87+ 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D,
88+ 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82,
89+ 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB,
90+ 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0,
91+ 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9
9492 };
9593
96−#define SVQ1_PROCESS_VECTOR()\
97− for (; level > 0; i++) {\
98− /* process next depth */\
99− if (i == m) {\
100− m = n;\
101− if (--level == 0)\
102− break;\
103− }\
104− /* divide block if next bit set */\
105− if (get_bits1 (bitbuf) == 0)\
106− break;\
107− /* add child nodes */\
108− list[n++] = list[i];\
109− list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level >> 1) + 1));\
94+#define SVQ1_PROCESS_VECTOR() \
95+ for (; level > 0; i++) { \
96+ /* process next depth */ \
97+ if (i == m) { \
98+ m = n; \
99+ if (--level == 0) \
100+ break; \
101+ } \
102+ /* divide block if next bit set */ \
103+ if (get_bits1(bitbuf) == 0) \
104+ break; \
105+ /* add child nodes */ \
106+ list[n++] = list[i]; \
107+ list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level >> 1) + 1));\
110108 }
111109
112−#define SVQ1_ADD_CODEBOOK()\
113− /* add codebook entries to vector */\
114− for (j=0; j < stages; j++) {\
115− n3 = codebook[entries[j]] ^ 0x80808080;\
116− n1 += ((n3 & 0xFF00FF00) >> 8);\
117− n2 += (n3 & 0x00FF00FF);\
118− }\
119−\
120− /* clip to [0..255] */\
121− if (n1 & 0xFF00FF00) {\
122− n3 = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
123− n1 += 0x7F007F00;\
124− n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
125− n1 &= (n3 & 0x00FF00FF);\
126− }\
127−\
128− if (n2 & 0xFF00FF00) {\
129− n3 = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
130− n2 += 0x7F007F00;\
131− n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
132− n2 &= (n3 & 0x00FF00FF);\
133− }
134−
135−#define SVQ1_DO_CODEBOOK_INTRA()\
136− for (y=0; y < height; y++) {\
137− for (x=0; x < (width / 4); x++, codebook++) {\
138− n1 = n4;\
139− n2 = n4;\
140− SVQ1_ADD_CODEBOOK()\
141− /* store result */\
142− dst[x] = (n1 << 8) | n2;\
143− }\
144− dst += (pitch / 4);\
145− }
146−
147−#define SVQ1_DO_CODEBOOK_NONINTRA()\
148− for (y=0; y < height; y++) {\
149− for (x=0; x < (width / 4); x++, codebook++) {\
150− n3 = dst[x];\
151− /* add mean value to vector */\
152− n1 = ((n3 & 0xFF00FF00) >> 8) + n4;\
153− n2 = (n3 & 0x00FF00FF) + n4;\
154− SVQ1_ADD_CODEBOOK()\
155− /* store result */\
156− dst[x] = (n1 << 8) | n2;\
157− }\
158− dst += (pitch / 4);\
159− }
160−
161−#define SVQ1_CALC_CODEBOOK_ENTRIES(cbook)\
162− codebook = (const uint32_t *) cbook[level];\
163− if (stages > 0)\
164− bit_cache = get_bits (bitbuf, 4*stages);\
165− /* calculate codebook entries for this vector */\
166− for (j=0; j < stages; j++) {\
167− entries[j] = (((bit_cache >> (4*(stages - j - 1))) & 0xF) + 16*j) << (level + 1);\
168− }\
169− mean -= (stages * 128);\
170− n4 = (mean << 16) + mean;
171−
172−static int svq1_decode_block_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) {
173− uint32_t bit_cache;
174− uint8_t *list[63];
175− uint32_t *dst;
176− const uint32_t *codebook;
177− int entries[6];
178− int i, j, m, n;
179− int mean, stages;
180− unsigned x, y, width, height, level;
181− uint32_t n1, n2, n3, n4;
182−
183− /* initialize list for breadth first processing of vectors */
184− list[0] = pixels;
185−
186− /* recursively process vector */
187− for (i=0, m=1, n=1, level=5; i < n; i++) {
188− SVQ1_PROCESS_VECTOR();
189−
190− /* destination address and vector size */
191− dst = (uint32_t *) list[i];
192− width = 1 << ((4 + level) /2);
193− height = 1 << ((3 + level) /2);
194−
195− /* get number of stages (-1 skips vector, 0 for mean only) */
196− stages = get_vlc2(bitbuf, svq1_intra_multistage[level].table, 3, 3) - 1;
197−
198− if (stages == -1) {
199− for (y=0; y < height; y++) {
200− memset (&dst[y*(pitch / 4)], 0, width);
201− }
202− continue; /* skip vector */
110+#define SVQ1_ADD_CODEBOOK() \
111+ /* add codebook entries to vector */ \
112+ for (j = 0; j < stages; j++) { \
113+ n3 = codebook[entries[j]] ^ 0x80808080; \
114+ n1 += (n3 & 0xFF00FF00) >> 8; \
115+ n2 += n3 & 0x00FF00FF; \
116+ } \
117+ \
118+ /* clip to [0..255] */ \
119+ if (n1 & 0xFF00FF00) { \
120+ n3 = (n1 >> 15 & 0x00010001 | 0x01000100) - 0x00010001; \
121+ n1 += 0x7F007F00; \
122+ n1 |= (~n1 >> 15 & 0x00010001 | 0x01000100) - 0x00010001; \
123+ n1 &= n3 & 0x00FF00FF; \
124+ } \
125+ \
126+ if (n2 & 0xFF00FF00) { \
127+ n3 = (n2 >> 15 & 0x00010001 | 0x01000100) - 0x00010001; \
128+ n2 += 0x7F007F00; \
129+ n2 |= (~n2 >> 15 & 0x00010001 | 0x01000100) - 0x00010001; \
130+ n2 &= n3 & 0x00FF00FF; \
203131 }
204132
205− if ((stages > 0) && (level >= 4)) {
206− av_dlog(NULL,
207− "Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i\n",
208− stages, level);
209− return -1; /* invalid vector */
133+#define SVQ1_DO_CODEBOOK_INTRA() \
134+ for (y = 0; y < height; y++) { \
135+ for (x = 0; x < width / 4; x++, codebook++) { \
136+ n1 = n4; \
137+ n2 = n4; \
138+ SVQ1_ADD_CODEBOOK() \
139+ /* store result */ \
140+ dst[x] = n1 << 8 | n2; \
141+ } \
142+ dst += pitch / 4; \
210143 }
211144
212− mean = get_vlc2(bitbuf, svq1_intra_mean.table, 8, 3);
145+#define SVQ1_DO_CODEBOOK_NONINTRA() \
146+ for (y = 0; y < height; y++) { \
147+ for (x = 0; x < width / 4; x++, codebook++) { \
148+ n3 = dst[x]; \
149+ /* add mean value to vector */ \
150+ n1 = n4 + ((n3 & 0xFF00FF00) >> 8); \
151+ n2 = n4 + (n3 & 0x00FF00FF); \
152+ SVQ1_ADD_CODEBOOK() \
153+ /* store result */ \
154+ dst[x] = n1 << 8 | n2; \
155+ } \
156+ dst += pitch / 4; \
157+ }
213158
214− if (stages == 0) {
215− for (y=0; y < height; y++) {
216− memset (&dst[y*(pitch / 4)], mean, width);
217− }
218− } else {
219− SVQ1_CALC_CODEBOOK_ENTRIES(ff_svq1_intra_codebooks);
220− SVQ1_DO_CODEBOOK_INTRA()
159+#define SVQ1_CALC_CODEBOOK_ENTRIES(cbook) \
160+ codebook = (const uint32_t *)cbook[level]; \
161+ if (stages > 0) \
162+ bit_cache = get_bits(bitbuf, 4 * stages); \
163+ /* calculate codebook entries for this vector */ \
164+ for (j = 0; j < stages; j++) { \
165+ entries[j] = (((bit_cache >> (4 * (stages - j - 1))) & 0xF) + \
166+ 16 * j) << (level + 1); \
167+ } \
168+ mean -= stages * 128; \
169+ n4 = (mean << 16) + mean;
170+
171+static int svq1_decode_block_intra(GetBitContext *bitbuf, uint8_t *pixels,
172+ int pitch)
173+{
174+ uint32_t bit_cache;
175+ uint8_t *list[63];
176+ uint32_t *dst;
177+ const uint32_t *codebook;
178+ int entries[6];
179+ int i, j, m, n;
180+ int mean, stages;
181+ unsigned x, y, width, height, level;
182+ uint32_t n1, n2, n3, n4;
183+
184+ /* initialize list for breadth first processing of vectors */
185+ list[0] = pixels;
186+
187+ /* recursively process vector */
188+ for (i = 0, m = 1, n = 1, level = 5; i < n; i++) {
189+ SVQ1_PROCESS_VECTOR();
190+
191+ /* destination address and vector size */
192+ dst = (uint32_t *)list[i];
193+ width = 1 << ((4 + level) / 2);
194+ height = 1 << ((3 + level) / 2);
195+
196+ /* get number of stages (-1 skips vector, 0 for mean only) */
197+ stages = get_vlc2(bitbuf, svq1_intra_multistage[level].table, 3, 3) - 1;
198+
199+ if (stages == -1) {
200+ for (y = 0; y < height; y++)
201+ memset(&dst[y * (pitch / 4)], 0, width);
202+ continue; /* skip vector */
203+ }
204+
205+ if (stages > 0 && level >= 4) {
206+ av_dlog(NULL,
207+ "Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i\n",
208+ stages, level);
209+ return -1; /* invalid vector */
210+ }
211+
212+ mean = get_vlc2(bitbuf, svq1_intra_mean.table, 8, 3);
213+
214+ if (stages == 0) {
215+ for (y = 0; y < height; y++)
216+ memset(&dst[y * (pitch / 4)], mean, width);
217+ } else {
218+ SVQ1_CALC_CODEBOOK_ENTRIES(ff_svq1_intra_codebooks);
219+ SVQ1_DO_CODEBOOK_INTRA()
220+ }
221221 }
222− }
223222
224− return 0;
223+ return 0;
225224 }
226225
227−static int svq1_decode_block_non_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) {
228− uint32_t bit_cache;
229− uint8_t *list[63];
230− uint32_t *dst;
231− const uint32_t *codebook;
232− int entries[6];
233− int i, j, m, n;
234− int mean, stages;
235− int x, y, width, height, level;
236− uint32_t n1, n2, n3, n4;
237−
238− /* initialize list for breadth first processing of vectors */
239− list[0] = pixels;
240−
241− /* recursively process vector */
242− for (i=0, m=1, n=1, level=5; i < n; i++) {
243− SVQ1_PROCESS_VECTOR();
244−
245− /* destination address and vector size */
246− dst = (uint32_t *) list[i];
247− width = 1 << ((4 + level) /2);
248− height = 1 << ((3 + level) /2);
249−
250− /* get number of stages (-1 skips vector, 0 for mean only) */
251− stages = get_vlc2(bitbuf, svq1_inter_multistage[level].table, 3, 2) - 1;
252−
253− if (stages == -1) continue; /* skip vector */
254−
255− if ((stages > 0) && (level >= 4)) {
256− av_dlog(NULL,
257− "Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i\n",
258− stages, level);
259− return -1; /* invalid vector */
260− }
226+static int svq1_decode_block_non_intra(GetBitContext *bitbuf, uint8_t *pixels,
227+ int pitch)
228+{
229+ uint32_t bit_cache;
230+ uint8_t *list[63];
231+ uint32_t *dst;
232+ const uint32_t *codebook;
233+ int entries[6];
234+ int i, j, m, n;
235+ int mean, stages;
236+ int x, y, width, height, level;
237+ uint32_t n1, n2, n3, n4;
238+
239+ /* initialize list for breadth first processing of vectors */
240+ list[0] = pixels;
241+
242+ /* recursively process vector */
243+ for (i = 0, m = 1, n = 1, level = 5; i < n; i++) {
244+ SVQ1_PROCESS_VECTOR();
245+
246+ /* destination address and vector size */
247+ dst = (uint32_t *)list[i];
248+ width = 1 << ((4 + level) / 2);
249+ height = 1 << ((3 + level) / 2);
250+
251+ /* get number of stages (-1 skips vector, 0 for mean only) */
252+ stages = get_vlc2(bitbuf, svq1_inter_multistage[level].table, 3, 2) - 1;
253+
254+ if (stages == -1)
255+ continue; /* skip vector */
256+
257+ if ((stages > 0) && (level >= 4)) {
258+ av_dlog(NULL,
259+ "Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i\n",
260+ stages, level);
261+ return -1; /* invalid vector */
262+ }
261263
262− mean = get_vlc2(bitbuf, svq1_inter_mean.table, 9, 3) - 256;
264+ mean = get_vlc2(bitbuf, svq1_inter_mean.table, 9, 3) - 256;
263265
264− SVQ1_CALC_CODEBOOK_ENTRIES(ff_svq1_inter_codebooks);
265− SVQ1_DO_CODEBOOK_NONINTRA()
266− }
267− return 0;
266+ SVQ1_CALC_CODEBOOK_ENTRIES(ff_svq1_inter_codebooks);
267+ SVQ1_DO_CODEBOOK_NONINTRA()
268+ }
269+ return 0;
268270 }
269271
270−static int svq1_decode_motion_vector (GetBitContext *bitbuf, svq1_pmv *mv, svq1_pmv **pmv) {
271− int diff;
272− int i;
272+static int svq1_decode_motion_vector(GetBitContext *bitbuf, svq1_pmv *mv,
273+ svq1_pmv **pmv)
274+{
275+ int diff;
276+ int i;
273277
274− for (i=0; i < 2; i++) {
278+ for (i = 0; i < 2; i++) {
279+ /* get motion code */
280+ diff = get_vlc2(bitbuf, svq1_motion_component.table, 7, 2);
281+ if (diff < 0)
282+ return -1;
283+ else if (diff) {
284+ if (get_bits1(bitbuf))
285+ diff = -diff;
286+ }
275287
276− /* get motion code */
277− diff = get_vlc2(bitbuf, svq1_motion_component.table, 7, 2);
278− if(diff<0)
279− return -1;
280− else if(diff){
281− if(get_bits1(bitbuf)) diff= -diff;
288+ /* add median of motion vector predictors and clip result */
289+ if (i == 1)
290+ mv->y = sign_extend(diff + mid_pred(pmv[0]->y, pmv[1]->y, pmv[2]->y), 6);
291+ else
292+ mv->x = sign_extend(diff + mid_pred(pmv[0]->x, pmv[1]->x, pmv[2]->x), 6);
282293 }
283294
284− /* add median of motion vector predictors and clip result */
285− if (i == 1)
286− mv->y = sign_extend(diff + mid_pred(pmv[0]->y, pmv[1]->y, pmv[2]->y), 6);
287− else
288− mv->x = sign_extend(diff + mid_pred(pmv[0]->x, pmv[1]->x, pmv[2]->x), 6);
289− }
290−
291− return 0;
295+ return 0;
292296 }
293297
294−static void svq1_skip_block (uint8_t *current, uint8_t *previous, int pitch, int x, int y) {
295− uint8_t *src;
296− uint8_t *dst;
297− int i;
298+static void svq1_skip_block(uint8_t *current, uint8_t *previous,
299+ int pitch, int x, int y)
300+{
301+ uint8_t *src;
302+ uint8_t *dst;
303+ int i;
298304
299− src = &previous[x + y*pitch];
300− dst = current;
305+ src = &previous[x + y * pitch];
306+ dst = current;
301307
302− for (i=0; i < 16; i++) {
303− memcpy (dst, src, 16);
304− src += pitch;
305− dst += pitch;
306− }
308+ for (i = 0; i < 16; i++) {
309+ memcpy(dst, src, 16);
310+ src += pitch;
311+ dst += pitch;
312+ }
307313 }
308314
309−static int svq1_motion_inter_block (MpegEncContext *s, GetBitContext *bitbuf,
310− uint8_t *current, uint8_t *previous, int pitch,
311− svq1_pmv *motion, int x, int y) {
312− uint8_t *src;
313− uint8_t *dst;
314− svq1_pmv mv;
315− svq1_pmv *pmv[3];
316− int result;
317−
318− /* predict and decode motion vector */
319− pmv[0] = &motion[0];
320− if (y == 0) {
321− pmv[1] =
322− pmv[2] = pmv[0];
323− }
324− else {
325− pmv[1] = &motion[(x / 8) + 2];
326− pmv[2] = &motion[(x / 8) + 4];
327− }
328−
329− result = svq1_decode_motion_vector (bitbuf, &mv, pmv);
330−
331− if (result != 0)
332− return result;
315+static int svq1_motion_inter_block(MpegEncContext *s, GetBitContext *bitbuf,
316+ uint8_t *current, uint8_t *previous,
317+ int pitch, svq1_pmv *motion, int x, int y)
318+{
319+ uint8_t *src;
320+ uint8_t *dst;
321+ svq1_pmv mv;
322+ svq1_pmv *pmv[3];
323+ int result;
324+
325+ /* predict and decode motion vector */
326+ pmv[0] = &motion[0];
327+ if (y == 0) {
328+ pmv[1] =
329+ pmv[2] = pmv[0];
330+ } else {
331+ pmv[1] = &motion[x / 8 + 2];
332+ pmv[2] = &motion[x / 8 + 4];
333+ }
333334
334− motion[0].x =
335− motion[(x / 8) + 2].x =
336− motion[(x / 8) + 3].x = mv.x;
337− motion[0].y =
338− motion[(x / 8) + 2].y =
339− motion[(x / 8) + 3].y = mv.y;
335+ result = svq1_decode_motion_vector(bitbuf, &mv, pmv);
340336
341− if(y + (mv.y >> 1)<0)
342− mv.y= 0;
343− if(x + (mv.x >> 1)<0)
344− mv.x= 0;
337+ if (result != 0)
338+ return result;
339+
340+ motion[0].x =
341+ motion[x / 8 + 2].x =
342+ motion[x / 8 + 3].x = mv.x;
343+ motion[0].y =
344+ motion[x / 8 + 2].y =
345+ motion[x / 8 + 3].y = mv.y;
346+
347+ if (y + (mv.y >> 1) < 0)
348+ mv.y = 0;
349+ if (x + (mv.x >> 1) < 0)
350+ mv.x = 0;
345351
346− src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch];
347− dst = current;
352+ src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1)) * pitch];
353+ dst = current;
348354
349− s->dsp.put_pixels_tab[0][((mv.y & 1) << 1) | (mv.x & 1)](dst,src,pitch,16);
355+ s->dsp.put_pixels_tab[0][(mv.y & 1) << 1 | (mv.x & 1)](dst, src, pitch, 16);
350356
351− return 0;
357+ return 0;
352358 }
353359
354−static int svq1_motion_inter_4v_block (MpegEncContext *s, GetBitContext *bitbuf,
355− uint8_t *current, uint8_t *previous, int pitch,
356− svq1_pmv *motion,int x, int y) {
357− uint8_t *src;
358− uint8_t *dst;
359− svq1_pmv mv;
360− svq1_pmv *pmv[4];
361− int i, result;
362−
363− /* predict and decode motion vector (0) */
364− pmv[0] = &motion[0];
365− if (y == 0) {
366− pmv[1] =
367− pmv[2] = pmv[0];
368− }
369− else {
370− pmv[1] = &motion[(x / 8) + 2];
371− pmv[2] = &motion[(x / 8) + 4];
372− }
373−
374− result = svq1_decode_motion_vector (bitbuf, &mv, pmv);
375−
376− if (result != 0)
377− return result;
360+static int svq1_motion_inter_4v_block(MpegEncContext *s, GetBitContext *bitbuf,
361+ uint8_t *current, uint8_t *previous,
362+ int pitch, svq1_pmv *motion, int x, int y)
363+{
364+ uint8_t *src;
365+ uint8_t *dst;
366+ svq1_pmv mv;
367+ svq1_pmv *pmv[4];
368+ int i, result;
369+
370+ /* predict and decode motion vector (0) */
371+ pmv[0] = &motion[0];
372+ if (y == 0) {
373+ pmv[1] =
374+ pmv[2] = pmv[0];
375+ } else {
376+ pmv[1] = &motion[(x / 8) + 2];
377+ pmv[2] = &motion[(x / 8) + 4];
378+ }
378379
379− /* predict and decode motion vector (1) */
380− pmv[0] = &mv;
381− if (y == 0) {
382− pmv[1] =
383− pmv[2] = pmv[0];
384− }
385− else {
386− pmv[1] = &motion[(x / 8) + 3];
387− }
388− result = svq1_decode_motion_vector (bitbuf, &motion[0], pmv);
389−
390− if (result != 0)
391− return result;
380+ result = svq1_decode_motion_vector(bitbuf, &mv, pmv);
392381
393− /* predict and decode motion vector (2) */
394− pmv[1] = &motion[0];
395− pmv[2] = &motion[(x / 8) + 1];
382+ if (result != 0)
383+ return result;
396384
397− result = svq1_decode_motion_vector (bitbuf, &motion[(x / 8) + 2], pmv);
385+ /* predict and decode motion vector (1) */
386+ pmv[0] = &mv;
387+ if (y == 0) {
388+ pmv[1] =
389+ pmv[2] = pmv[0];
390+ } else {
391+ pmv[1] = &motion[(x / 8) + 3];
392+ }
393+ result = svq1_decode_motion_vector(bitbuf, &motion[0], pmv);
398394
399− if (result != 0)
400− return result;
395+ if (result != 0)
396+ return result;
401397
402− /* predict and decode motion vector (3) */
403− pmv[2] = &motion[(x / 8) + 2];
404− pmv[3] = &motion[(x / 8) + 3];
398+ /* predict and decode motion vector (2) */
399+ pmv[1] = &motion[0];
400+ pmv[2] = &motion[(x / 8) + 1];
405401
406− result = svq1_decode_motion_vector (bitbuf, pmv[3], pmv);
402+ result = svq1_decode_motion_vector(bitbuf, &motion[(x / 8) + 2], pmv);
407403
408− if (result != 0)
409− return result;
404+ if (result != 0)
405+ return result;
410406
411− /* form predictions */
412− for (i=0; i < 4; i++) {
413− int mvx= pmv[i]->x + (i&1)*16;
414− int mvy= pmv[i]->y + (i>>1)*16;
407+ /* predict and decode motion vector (3) */
408+ pmv[2] = &motion[(x / 8) + 2];
409+ pmv[3] = &motion[(x / 8) + 3];
415410
416− ///XXX /FIXME clipping or padding?
417− if(y + (mvy >> 1)<0)
418− mvy= 0;
419− if(x + (mvx >> 1)<0)
420− mvx= 0;
411+ result = svq1_decode_motion_vector(bitbuf, pmv[3], pmv);
421412
422− src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1))*pitch];
423− dst = current;
413+ if (result != 0)
414+ return result;
424415
425− s->dsp.put_pixels_tab[1][((mvy & 1) << 1) | (mvx & 1)](dst,src,pitch,8);
416+ /* form predictions */
417+ for (i = 0; i < 4; i++) {
418+ int mvx = pmv[i]->x + (i & 1) * 16;
419+ int mvy = pmv[i]->y + (i >> 1) * 16;
426420
427− /* select next block */
428− if (i & 1) {
429− current += 8*(pitch - 1);
430− } else {
431− current += 8;
432− }
433− }
421+ // FIXME: clipping or padding?
422+ if (y + (mvy >> 1) < 0)
423+ mvy = 0;
424+ if (x + (mvx >> 1) < 0)
425+ mvx = 0;
434426
435− return 0;
436−}
427+ src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1)) * pitch];
428+ dst = current;
437429
438−static int svq1_decode_delta_block (MpegEncContext *s, GetBitContext *bitbuf,
439− uint8_t *current, uint8_t *previous, int pitch,
440− svq1_pmv *motion, int x, int y) {
441− uint32_t block_type;
442− int result = 0;
443−
444− /* get block type */
445− block_type = get_vlc2(bitbuf, svq1_block_type.table, 2, 2);
446−
447− /* reset motion vectors */
448− if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) {
449− motion[0].x =
450− motion[0].y =
451− motion[(x / 8) + 2].x =
452− motion[(x / 8) + 2].y =
453− motion[(x / 8) + 3].x =
454− motion[(x / 8) + 3].y = 0;
455− }
456−
457− switch (block_type) {
458− case SVQ1_BLOCK_SKIP:
459− svq1_skip_block (current, previous, pitch, x, y);
460− break;
461−
462− case SVQ1_BLOCK_INTER:
463− result = svq1_motion_inter_block (s, bitbuf, current, previous, pitch, motion, x, y);
430+ s->dsp.put_pixels_tab[1][((mvy & 1) << 1) | (mvx & 1)](dst, src, pitch, 8);
464431
465− if (result != 0)
466− {
467− av_dlog(s->avctx, "Error in svq1_motion_inter_block %i\n", result);
468− break;
432+ /* select next block */
433+ if (i & 1)
434+ current += 8 * (pitch - 1);
435+ else
436+ current += 8;
469437 }
470− result = svq1_decode_block_non_intra (bitbuf, current, pitch);
471− break;
472438
473− case SVQ1_BLOCK_INTER_4V:
474− result = svq1_motion_inter_4v_block (s, bitbuf, current, previous, pitch, motion, x, y);
439+ return 0;
440+}
475441
476− if (result != 0)
477− {
478− av_dlog(s->avctx, "Error in svq1_motion_inter_4v_block %i\n", result);
479− break;
442+static int svq1_decode_delta_block(MpegEncContext *s, GetBitContext *bitbuf,
443+ uint8_t *current, uint8_t *previous,
444+ int pitch, svq1_pmv *motion, int x, int y)
445+{
446+ uint32_t block_type;
447+ int result = 0;
448+
449+ /* get block type */
450+ block_type = get_vlc2(bitbuf, svq1_block_type.table, 2, 2);
451+
452+ /* reset motion vectors */
453+ if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) {
454+ motion[0].x =
455+ motion[0].y =
456+ motion[x / 8 + 2].x =
457+ motion[x / 8 + 2].y =
458+ motion[x / 8 + 3].x =
459+ motion[x / 8 + 3].y = 0;
480460 }
481− result = svq1_decode_block_non_intra (bitbuf, current, pitch);
482− break;
483461
484− case SVQ1_BLOCK_INTRA:
485− result = svq1_decode_block_intra (bitbuf, current, pitch);
486− break;
487− }
462+ switch (block_type) {
463+ case SVQ1_BLOCK_SKIP:
464+ svq1_skip_block(current, previous, pitch, x, y);
465+ break;
488466
489− return result;
490−}
467+ case SVQ1_BLOCK_INTER:
468+ result = svq1_motion_inter_block(s, bitbuf, current, previous,
469+ pitch, motion, x, y);
491470
492−static void svq1_parse_string (GetBitContext *bitbuf, uint8_t *out) {
493− uint8_t seed;
494− int i;
471+ if (result != 0) {
472+ av_dlog(s->avctx, "Error in svq1_motion_inter_block %i\n", result);
473+ break;
474+ }
475+ result = svq1_decode_block_non_intra(bitbuf, current, pitch);
476+ break;
495477
496− out[0] = get_bits (bitbuf, 8);
478+ case SVQ1_BLOCK_INTER_4V:
479+ result = svq1_motion_inter_4v_block(s, bitbuf, current, previous,
480+ pitch, motion, x, y);
497481
498− seed = string_table[out[0]];
482+ if (result != 0) {
483+ av_dlog(s->avctx,
484+ "Error in svq1_motion_inter_4v_block %i\n", result);
485+ break;
486+ }
487+ result = svq1_decode_block_non_intra(bitbuf, current, pitch);
488+ break;
499489
500− for (i=1; i <= out[0]; i++) {
501− out[i] = get_bits (bitbuf, 8) ^ seed;
502− seed = string_table[out[i] ^ seed];
503− }
490+ case SVQ1_BLOCK_INTRA:
491+ result = svq1_decode_block_intra(bitbuf, current, pitch);
492+ break;
493+ }
494+
495+ return result;
504496 }
505497
506−static int svq1_decode_frame_header (GetBitContext *bitbuf,MpegEncContext *s) {
507− int frame_size_code;
498+static void svq1_parse_string(GetBitContext *bitbuf, uint8_t *out)
499+{
500+ uint8_t seed;
501+ int i;
502+
503+ out[0] = get_bits(bitbuf, 8);
504+ seed = string_table[out[0]];
508505
509− skip_bits(bitbuf, 8); /* temporal_reference */
506+ for (i = 1; i <= out[0]; i++) {
507+ out[i] = get_bits(bitbuf, 8) ^ seed;
508+ seed = string_table[out[i] ^ seed];
509+ }
510+}
510511
511− /* frame type */
512− s->pict_type= get_bits (bitbuf, 2)+1;
513− if(s->pict_type==4)
514− return -1;
512+static int svq1_decode_frame_header(GetBitContext *bitbuf, MpegEncContext *s)
513+{
514+ int frame_size_code;
515515
516− if (s->pict_type == AV_PICTURE_TYPE_I) {
516+ skip_bits(bitbuf, 8); /* temporal_reference */
517517
518− /* unknown fields */
519− if (s->f_code == 0x50 || s->f_code == 0x60) {
520− int csum = get_bits (bitbuf, 16);
518+ /* frame type */
519+ s->pict_type = get_bits(bitbuf, 2) + 1;
520+ if (s->pict_type == 4)
521+ return -1;
521522
522− csum = ff_svq1_packet_checksum (bitbuf->buffer, bitbuf->size_in_bits>>3, csum);
523+ if (s->pict_type == AV_PICTURE_TYPE_I) {
524+ /* unknown fields */
525+ if (s->f_code == 0x50 || s->f_code == 0x60) {
526+ int csum = get_bits(bitbuf, 16);
523527
524− av_dlog(s->avctx, "%s checksum (%02x) for packet data\n",
525− (csum == 0) ? "correct" : "incorrect", csum);
526− }
528+ csum = ff_svq1_packet_checksum(bitbuf->buffer,
529+ bitbuf->size_in_bits >> 3,
530+ csum);
527531
528− if ((s->f_code ^ 0x10) >= 0x50) {
529− uint8_t msg[256];
532+ av_dlog(s->avctx, "%s checksum (%02x) for packet data\n",
533+ (csum == 0) ? "correct" : "incorrect", csum);
534+ }
530535
531− svq1_parse_string (bitbuf, msg);
536+ if ((s->f_code ^ 0x10) >= 0x50) {
537+ uint8_t msg[256];
532538
533− av_log(s->avctx, AV_LOG_INFO, "embedded message: \"%s\"\n", (char *) msg);
534− }
539+ svq1_parse_string(bitbuf, msg);
535540
536− skip_bits (bitbuf, 2);
537− skip_bits (bitbuf, 2);
538− skip_bits1 (bitbuf);
541+ av_log(s->avctx, AV_LOG_ERROR,
542+ "embedded message: \"%s\"\n", (char *)msg);
543+ }
539544
540− /* load frame size */
541− frame_size_code = get_bits (bitbuf, 3);
545+ skip_bits(bitbuf, 2);
546+ skip_bits(bitbuf, 2);
547+ skip_bits1(bitbuf);
542548
543− if (frame_size_code == 7) {
544− /* load width, height (12 bits each) */
545− s->width = get_bits (bitbuf, 12);
546− s->height = get_bits (bitbuf, 12);
549+ /* load frame size */
550+ frame_size_code = get_bits(bitbuf, 3);
547551
548− if (!s->width || !s->height)
549− return -1;
550− } else {
551− /* get width, height from table */
552− s->width = ff_svq1_frame_size_table[frame_size_code].width;
553− s->height = ff_svq1_frame_size_table[frame_size_code].height;
552+ if (frame_size_code == 7) {
553+ /* load width, height (12 bits each) */
554+ s->width = get_bits(bitbuf, 12);
555+ s->height = get_bits(bitbuf, 12);
556+
557+ if (!s->width || !s->height)
558+ return -1;
559+ } else {
560+ /* get width, height from table */
561+ s->width = ff_svq1_frame_size_table[frame_size_code].width;
562+ s->height = ff_svq1_frame_size_table[frame_size_code].height;
563+ }
554564 }
555− }
556565
557− /* unknown fields */
558− if (get_bits1 (bitbuf) == 1) {
559− skip_bits1 (bitbuf); /* use packet checksum if (1) */
560− skip_bits1 (bitbuf); /* component checksums after image data if (1) */
566+ /* unknown fields */
567+ if (get_bits1(bitbuf) == 1) {
568+ skip_bits1(bitbuf); /* use packet checksum if (1) */
569+ skip_bits1(bitbuf); /* component checksums after image data if (1) */
561570
562− if (get_bits (bitbuf, 2) != 0)
563− return -1;
564− }
571+ if (get_bits(bitbuf, 2) != 0)
572+ return -1;
573+ }
565574
566− if (get_bits1 (bitbuf) == 1) {
567− skip_bits1 (bitbuf);
568− skip_bits (bitbuf, 4);
569− skip_bits1 (bitbuf);
570− skip_bits (bitbuf, 2);
575+ if (get_bits1(bitbuf) == 1) {
576+ skip_bits1(bitbuf);
577+ skip_bits(bitbuf, 4);
578+ skip_bits1(bitbuf);
579+ skip_bits(bitbuf, 2);
571580
572− while (get_bits1 (bitbuf) == 1) {
573− skip_bits (bitbuf, 8);
581+ while (get_bits1(bitbuf) == 1)
582+ skip_bits(bitbuf, 8);
574583 }
575− }
576584
577− return 0;
585+ return 0;
578586 }
579587
580−static int svq1_decode_frame(AVCodecContext *avctx,
581− void *data, int *data_size,
582− AVPacket *avpkt)
588+static int svq1_decode_frame(AVCodecContext *avctx, void *data,
589+ int *data_size, AVPacket *avpkt)
583590 {
584− const uint8_t *buf = avpkt->data;
585− int buf_size = avpkt->size;
586− MpegEncContext *s=avctx->priv_data;
587− uint8_t *current, *previous;
588− int result, i, x, y, width, height;
589− AVFrame *pict = data;
590− svq1_pmv *pmv;
591+ const uint8_t *buf = avpkt->data;
592+ int buf_size = avpkt->size;
593+ MpegEncContext *s = avctx->priv_data;
594+ uint8_t *current, *previous;
595+ int result, i, x, y, width, height;
596+ AVFrame *pict = data;
597+ svq1_pmv *pmv;
591598
592− /* initialize bit buffer */
593− init_get_bits(&s->gb,buf,buf_size*8);
599+ /* initialize bit buffer */
600+ init_get_bits(&s->gb, buf, buf_size * 8);
594601
595− /* decode frame header */
596− s->f_code = get_bits (&s->gb, 22);
602+ /* decode frame header */
603+ s->f_code = get_bits(&s->gb, 22);
597604
598− if ((s->f_code & ~0x70) || !(s->f_code & 0x60))
599− return -1;
605+ if ((s->f_code & ~0x70) || !(s->f_code & 0x60))
606+ return -1;
600607
601− /* swap some header bytes (why?) */
602− if (s->f_code != 0x20) {
603− uint32_t *src = (uint32_t *) (buf + 4);
608+ /* swap some header bytes (why?) */
609+ if (s->f_code != 0x20) {
610+ uint32_t *src = (uint32_t *)(buf + 4);
604611
605− if (buf_size < 36)
606− return AVERROR_INVALIDDATA;
612+ if (buf_size < 36)
613+ return AVERROR_INVALIDDATA;
607614
608− for (i=0; i < 4; i++) {
609− src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];
615+ for (i = 0; i < 4; i++)
616+ src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];
610617 }
611− }
612618
613− result = svq1_decode_frame_header (&s->gb, s);
619+ result = svq1_decode_frame_header(&s->gb, s);
614620
615− if (result != 0)
616− {
617− av_dlog(s->avctx, "Error in svq1_decode_frame_header %i\n",result);
618− return result;
619− }
620− avcodec_set_dimensions(avctx, s->width, s->height);
621−
622− //FIXME this avoids some confusion for "B frames" without 2 references
623− //this should be removed after libavcodec can handle more flexible picture types & ordering
624− if(s->pict_type==AV_PICTURE_TYPE_B && s->last_picture_ptr==NULL) return buf_size;
625−
626− if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B)
627− ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I)
628− || avctx->skip_frame >= AVDISCARD_ALL)
629− return buf_size;
630−
631− if(ff_MPV_frame_start(s, avctx) < 0)
632− return -1;
633−
634− pmv = av_malloc((FFALIGN(s->width, 16)/8 + 3) * sizeof(*pmv));
635− if (!pmv)
636− return -1;
637−
638− /* decode y, u and v components */
639− for (i=0; i < 3; i++) {
640− int linesize;
641− if (i == 0) {
642− width = FFALIGN(s->width, 16);
643− height = FFALIGN(s->height, 16);
644− linesize= s->linesize;
645− } else {
646− if(s->flags&CODEC_FLAG_GRAY) break;
647− width = FFALIGN(s->width/4, 16);
648− height = FFALIGN(s->height/4, 16);
649− linesize= s->uvlinesize;
621+ if (result != 0) {
622+ av_dlog(s->avctx, "Error in svq1_decode_frame_header %i\n", result);
623+ return result;
650624 }
625+ avcodec_set_dimensions(avctx, s->width, s->height);
626+
627+ /* FIXME: This avoids some confusion for "B frames" without 2 references.
628+ * This should be removed after libavcodec can handle more flexible
629+ * picture types & ordering */
630+ if (s->pict_type == AV_PICTURE_TYPE_B && s->last_picture_ptr == NULL)
631+ return buf_size;
632+
633+ if ((avctx->skip_frame >= AVDISCARD_NONREF &&
634+ s->pict_type == AV_PICTURE_TYPE_B) ||
635+ (avctx->skip_frame >= AVDISCARD_NONKEY &&
636+ s->pict_type != AV_PICTURE_TYPE_I) ||
637+ avctx->skip_frame >= AVDISCARD_ALL)
638+ return buf_size;
639+
640+ if (ff_MPV_frame_start(s, avctx) < 0)
641+ return -1;
651642
652− current = s->current_picture.f.data[i];
653−
654− if(s->pict_type==AV_PICTURE_TYPE_B){
655− previous = s->next_picture.f.data[i];
656− }else{
657− previous = s->last_picture.f.data[i];
658− }
643+ pmv = av_malloc((FFALIGN(s->width, 16) / 8 + 3) * sizeof(*pmv));
644+ if (!pmv)
645+ return -1;
659646
660− if (s->pict_type == AV_PICTURE_TYPE_I) {
661− /* keyframe */
662− for (y=0; y < height; y+=16) {
663− for (x=0; x < width; x+=16) {
664− result = svq1_decode_block_intra (&s->gb, &current[x], linesize);
665− if (result != 0)
666− {
667− av_log(s->avctx, AV_LOG_ERROR, "Error in svq1_decode_block %i (keyframe)\n",result);
668− goto err;
669− }
670− }
671− current += 16*linesize;
672− }
673− } else {
674− /* delta frame */
675− memset (pmv, 0, ((width / 8) + 3) * sizeof(svq1_pmv));
676−
677− for (y=0; y < height; y+=16) {
678− for (x=0; x < width; x+=16) {
679− result = svq1_decode_delta_block (s, &s->gb, &current[x], previous,
680− linesize, pmv, x, y);
681− if (result != 0)
682− {
683− av_dlog(s->avctx, "Error in svq1_decode_delta_block %i\n",result);
684− goto err;
685− }
647+ /* decode y, u and v components */
648+ for (i = 0; i < 3; i++) {
649+ int linesize;
650+ if (i == 0) {
651+ width = FFALIGN(s->width, 16);
652+ height = FFALIGN(s->height, 16);
653+ linesize = s->linesize;
654+ } else {
655+ if (s->flags & CODEC_FLAG_GRAY)
656+ break;
657+ width = FFALIGN(s->width / 4, 16);
658+ height = FFALIGN(s->height / 4, 16);
659+ linesize = s->uvlinesize;
686660 }
687661
688− pmv[0].x =
689− pmv[0].y = 0;
690−
691− current += 16*linesize;
692− }
662+ current = s->current_picture.f.data[i];
663+
664+ if (s->pict_type == AV_PICTURE_TYPE_B)
665+ previous = s->next_picture.f.data[i];
666+ else
667+ previous = s->last_picture.f.data[i];
668+
669+ if (s->pict_type == AV_PICTURE_TYPE_I) {
670+ /* keyframe */
671+ for (y = 0; y < height; y += 16) {
672+ for (x = 0; x < width; x += 16) {
673+ result = svq1_decode_block_intra(&s->gb, &current[x],
674+ linesize);
675+ if (result != 0) {
676+ av_log(s->avctx, AV_LOG_INFO,
677+ "Error in svq1_decode_block %i (keyframe)\n",
678+ result);
679+ goto err;
680+ }
681+ }
682+ current += 16 * linesize;
683+ }
684+ } else {
685+ /* delta frame */
686+ memset(pmv, 0, ((width / 8) + 3) * sizeof(svq1_pmv));
687+
688+ for (y = 0; y < height; y += 16) {
689+ for (x = 0; x < width; x += 16) {
690+ result = svq1_decode_delta_block(s, &s->gb, &current[x],
691+ previous, linesize,
692+ pmv, x, y);
693+ if (result != 0) {
694+ av_dlog(s->avctx,
695+ "Error in svq1_decode_delta_block %i\n",
696+ result);
697+ goto err;
698+ }
699+ }
700+
701+ pmv[0].x =
702+ pmv[0].y = 0;
703+
704+ current += 16 * linesize;
705+ }
706+ }
693707 }
694− }
695708
696− *pict = s->current_picture.f;
709+ *pict = s->current_picture.f;
697710
711+ ff_MPV_frame_end(s);
698712
699− ff_MPV_frame_end(s);
713+ *data_size = sizeof(AVFrame);
714+ result = buf_size;
700715
701− *data_size=sizeof(AVFrame);
702− result = buf_size;
703716 err:
704− av_free(pmv);
705− return result;
717+ av_free(pmv);
718+ return result;
706719 }
707720
708721 static av_cold int svq1_decode_init(AVCodecContext *avctx)
@@ -713,47 +726,52 @@ static av_cold int svq1_decode_init(AVCodecContext *avctx) · 4 unmodified lines
713726
714727 ff_MPV_decode_defaults(s);
715728
716− s->avctx = avctx;
717− s->width = (avctx->width+3)&~3;
718− s->height = (avctx->height+3)&~3;
719− s->codec_id= avctx->codec->id;
720− avctx->pix_fmt = AV_PIX_FMT_YUV410P;
721− avctx->has_b_frames= 1; // not true, but DP frames and these behave like unidirectional b frames
722− s->flags= avctx->flags;
723− if (ff_MPV_common_init(s) < 0) return -1;
729+ s->avctx = avctx;
730+ s->width = avctx->width + 3 & ~3;
731+ s->height = avctx->height + 3 & ~3;
732+ s->codec_id = avctx->codec->id;
733+ avctx->pix_fmt = AV_PIX_FMT_YUV410P;
734+ /* Not true, but DP frames and these behave like unidirectional B-frames. */
735+ avctx->has_b_frames = 1;
736+ s->flags = avctx->flags;
737+ if (ff_MPV_common_init(s) < 0)
738+ return -1;
724739
725740 INIT_VLC_STATIC(&svq1_block_type, 2, 4,
726− &ff_svq1_block_type_vlc[0][1], 2, 1,
727− &ff_svq1_block_type_vlc[0][0], 2, 1, 6);
741+ &ff_svq1_block_type_vlc[0][1], 2, 1,
742+ &ff_svq1_block_type_vlc[0][0], 2, 1, 6);
728743
729744 INIT_VLC_STATIC(&svq1_motion_component, 7, 33,
730− &ff_mvtab[0][1], 2, 1,
731− &ff_mvtab[0][0], 2, 1, 176);
745+ &ff_mvtab[0][1], 2, 1,
746+ &ff_mvtab[0][0], 2, 1, 176);
732747
733748 for (i = 0; i < 6; i++) {
734− static const uint8_t sizes[2][6] = {{14, 10, 14, 18, 16, 18}, {10, 10, 14, 14, 14, 16}};
749+ static const uint8_t sizes[2][6] = { { 14, 10, 14, 18, 16, 18 },
750+ { 10, 10, 14, 14, 14, 16 } };
735751 static VLC_TYPE table[168][2];
736− svq1_intra_multistage[i].table = &table[offset];
752+ svq1_intra_multistage[i].table = &table[offset];
737753 svq1_intra_multistage[i].table_allocated = sizes[0][i];
738− offset += sizes[0][i];
754+ offset += sizes[0][i];
739755 init_vlc(&svq1_intra_multistage[i], 3, 8,
740− &ff_svq1_intra_multistage_vlc[i][0][1], 2, 1,
741− &ff_svq1_intra_multistage_vlc[i][0][0], 2, 1, INIT_VLC_USE_NEW_STATIC);
742− svq1_inter_multistage[i].table = &table[offset];
756+ &ff_svq1_intra_multistage_vlc[i][0][1], 2, 1,
757+ &ff_svq1_intra_multistage_vlc[i][0][0], 2, 1,
758+ INIT_VLC_USE_NEW_STATIC);
759+ svq1_inter_multistage[i].table = &table[offset];
743760 svq1_inter_multistage[i].table_allocated = sizes[1][i];
744− offset += sizes[1][i];
761+ offset += sizes[1][i];
745762 init_vlc(&svq1_inter_multistage[i], 3, 8,
746− &ff_svq1_inter_multistage_vlc[i][0][1], 2, 1,
747− &ff_svq1_inter_multistage_vlc[i][0][0], 2, 1, INIT_VLC_USE_NEW_STATIC);
763+ &ff_svq1_inter_multistage_vlc[i][0][1], 2, 1,
764+ &ff_svq1_inter_multistage_vlc[i][0][0], 2, 1,
765+ INIT_VLC_USE_NEW_STATIC);
748766 }
749767
750768 INIT_VLC_STATIC(&svq1_intra_mean, 8, 256,
751− &ff_svq1_intra_mean_vlc[0][1], 4, 2,
752− &ff_svq1_intra_mean_vlc[0][0], 4, 2, 632);
769+ &ff_svq1_intra_mean_vlc[0][1], 4, 2,
770+ &ff_svq1_intra_mean_vlc[0][0], 4, 2, 632);
753771
754772 INIT_VLC_STATIC(&svq1_inter_mean, 9, 512,
755− &ff_svq1_inter_mean_vlc[0][1], 4, 2,
756− &ff_svq1_inter_mean_vlc[0][0], 4, 2, 1434);
773+ &ff_svq1_inter_mean_vlc[0][1], 4, 2,
774+ &ff_svq1_inter_mean_vlc[0][0], 4, 2, 1434);
757775
758776 return 0;
759777 }
@@ -766,7 +784,6 @@ static av_cold int svq1_decode_end(AVCodecContext *avctx) · 6 unmodified lines
766784 return 0;
767785 }
768786
769−
770787 AVCodec ff_svq1_decoder = {
771788 .name = "svq1",
772789 .type = AVMEDIA_TYPE_VIDEO,
@@ -777,6 +794,7 @@ AVCodec ff_svq1_decoder = { · 4 unmodified lines
777794 .decode = svq1_decode_frame,
778795 .capabilities = CODEC_CAP_DR1,
779796 .flush = ff_mpeg_flush,
780− .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV410P, AV_PIX_FMT_NONE },
797+ .pix_fmts = (const enum PixelFormat[]) { AV_PIX_FMT_YUV410P,
798+ AV_PIX_FMT_NONE },
781799 .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"),
782800 };
libavcodec/svq1enc.c+322−283
@@ -26,21 +26,21 @@ · 25 unmodified lines
2626 * http://www.pcisys.net/~melanson/codecs/
2727 */
2828
29−
3029 #include "avcodec.h"
3130 #include "dsputil.h"
3231 #include "mpegvideo.h"
3332 #include "h263.h"
3433 #include "internal.h"
3534 #include "libavutil/avassert.h"
36−
3735 #include "svq1.h"
3836 #include "svq1enc_cb.h"
3937
4038
41−
4239 typedef struct SVQ1Context {
43− MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independent of MpegEncContext, so this will be removed then (FIXME/XXX)
40+ /* FIXME: Needed for motion estimation, should not be used for anything
41+ * else, the idea is to make the motion estimation eventually independent
42+ * of MpegEncContext, so this will be removed then. */
43+ MpegEncContext m;
4444 AVCodecContext *avctx;
4545 DSPContext dsp;
4646 AVFrame picture;
@@ -49,7 +49,9 @@ typedef struct SVQ1Context { · 2 unmodified lines
4949 PutBitContext pb;
5050 GetBitContext gb;
5151
52− PutBitContext reorder_pb[6]; //why ooh why this sick breadth first order, everything is slower and more complex
52+ /* why ooh why this sick breadth first order,
53+ * everything is slower and more complex */
54+ PutBitContext reorder_pb[6];
5355
5456 int frame_width;
5557 int frame_height;
@@ -86,21 +88,19 @@ static void svq1_write_header(SVQ1Context *s, int frame_type) · 30 unmodified lines
8688 put_bits(&s->pb, 2, frame_type - 1);
8789
8890 if (frame_type == AV_PICTURE_TYPE_I) {
89−
9091 /* no checksum since frame code is 0x20 */
91−
9292 /* no embedded string either */
93−
9493 /* output 5 unknown bits (2 + 2 + 1) */
9594 put_bits(&s->pb, 5, 2); /* 2 needed by quicktime decoder */
9695
97− i= ff_match_2uint16((void*)ff_svq1_frame_size_table, FF_ARRAY_ELEMS(ff_svq1_frame_size_table), s->frame_width, s->frame_height);
96+ i = ff_match_2uint16((void*)ff_svq1_frame_size_table,
97+ FF_ARRAY_ELEMS(ff_svq1_frame_size_table),
98+ s->frame_width, s->frame_height);
9899 put_bits(&s->pb, 3, i);
99100
100− if (i == 7)
101− {
102− put_bits(&s->pb, 12, s->frame_width);
103− put_bits(&s->pb, 12, s->frame_height);
101+ if (i == 7) {
102+ put_bits(&s->pb, 12, s->frame_width);
103+ put_bits(&s->pb, 12, s->frame_height);
104104 }
105105 }
106106
@@ -108,391 +108,423 @@ static void svq1_write_header(SVQ1Context *s, int frame_type) · 1 unmodified line
108108 put_bits(&s->pb, 2, 0);
109109 }
110110
111−
112−#define QUALITY_THRESHOLD 100
111+#define QUALITY_THRESHOLD 100
113112 #define THRESHOLD_MULTIPLIER 0.6
114113
115−static int encode_block(SVQ1Context *s, uint8_t *src, uint8_t *ref, uint8_t *decoded, int stride, int level, int threshold, int lambda, int intra){
114+static int encode_block(SVQ1Context *s, uint8_t *src, uint8_t *ref,
115+ uint8_t *decoded, int stride, int level,
116+ int threshold, int lambda, int intra)
117+{
116118 int count, y, x, i, j, split, best_mean, best_score, best_count;
117119 int best_vector[6];
118− int block_sum[7]= {0, 0, 0, 0, 0, 0};
119− int w= 2<<((level+2)>>1);
120− int h= 2<<((level+1)>>1);
121− int size=w*h;
120+ int block_sum[7] = { 0, 0, 0, 0, 0, 0 };
121+ int w = 2 << (level + 2 >> 1);
122+ int h = 2 << (level + 1 >> 1);
123+ int size = w * h;
122124 int16_t block[7][256];
123125 const int8_t *codebook_sum, *codebook;
124− const uint16_t (*mean_vlc)[2];
125− const uint8_t (*multistage_vlc)[2];
126−
127− best_score=0;
128− //FIXME optimize, this doenst need to be done multiple times
129− if(intra){
130− codebook_sum= svq1_intra_codebook_sum[level];
131− codebook= ff_svq1_intra_codebooks[level];
132− mean_vlc= ff_svq1_intra_mean_vlc;
133− multistage_vlc= ff_svq1_intra_multistage_vlc[level];
134− for(y=0; y<h; y++){
135− for(x=0; x<w; x++){
136− int v= src[x + y*stride];
137− block[0][x + w*y]= v;
138− best_score += v*v;
139− block_sum[0] += v;
126+ const uint16_t(*mean_vlc)[2];
127+ const uint8_t(*multistage_vlc)[2];
128+
129+ best_score = 0;
130+ // FIXME: Optimize, this does not need to be done multiple times.
131+ if (intra) {
132+ codebook_sum = svq1_intra_codebook_sum[level];
133+ codebook = ff_svq1_intra_codebooks[level];
134+ mean_vlc = ff_svq1_intra_mean_vlc;
135+ multistage_vlc = ff_svq1_intra_multistage_vlc[level];
136+ for (y = 0; y < h; y++) {
137+ for (x = 0; x < w; x++) {
138+ int v = src[x + y * stride];
139+ block[0][x + w * y] = v;
140+ best_score += v * v;
141+ block_sum[0] += v;
140142 }
141143 }
142− }else{
143− codebook_sum= svq1_inter_codebook_sum[level];
144− codebook= ff_svq1_inter_codebooks[level];
145− mean_vlc= ff_svq1_inter_mean_vlc + 256;
146− multistage_vlc= ff_svq1_inter_multistage_vlc[level];
147− for(y=0; y<h; y++){
148− for(x=0; x<w; x++){
149− int v= src[x + y*stride] - ref[x + y*stride];
150− block[0][x + w*y]= v;
151− best_score += v*v;
152− block_sum[0] += v;
144+ } else {
145+ codebook_sum = svq1_inter_codebook_sum[level];
146+ codebook = ff_svq1_inter_codebooks[level];
147+ mean_vlc = ff_svq1_inter_mean_vlc + 256;
148+ multistage_vlc = ff_svq1_inter_multistage_vlc[level];
149+ for (y = 0; y < h; y++) {
150+ for (x = 0; x < w; x++) {
151+ int v = src[x + y * stride] - ref[x + y * stride];
152+ block[0][x + w * y] = v;
153+ best_score += v * v;
154+ block_sum[0] += v;
153155 }
154156 }
155157 }
156158
157− best_count=0;
158− best_score -= (int)(((unsigned)block_sum[0]*block_sum[0])>>(level+3));
159− best_mean= (block_sum[0] + (size>>1)) >> (level+3);
159+ best_count = 0;
160+ best_score -= (int)((unsigned)block_sum[0] * block_sum[0] >> (level + 3));
161+ best_mean = block_sum[0] + (size >> 1) >> (level + 3);
160162
161− if(level<4){
162− for(count=1; count<7; count++){
163− int best_vector_score= INT_MAX;
164− int best_vector_sum=-999, best_vector_mean=-999;
165− const int stage= count-1;
163+ if (level < 4) {
164+ for (count = 1; count < 7; count++) {
165+ int best_vector_score = INT_MAX;
166+ int best_vector_sum = -999, best_vector_mean = -999;
167+ const int stage = count - 1;
166168 const int8_t *vector;
167169
168− for(i=0; i<16; i++){
169− int sum= codebook_sum[stage*16 + i];
170+ for (i = 0; i < 16; i++) {
171+ int sum = codebook_sum[stage * 16 + i];
170172 int sqr, diff, score;
171173
172− vector = codebook + stage*size*16 + i*size;
173− sqr = s->dsp.ssd_int8_vs_int16(vector, block[stage], size);
174− diff= block_sum[stage] - sum;
175− score= sqr - ((diff*(int64_t)diff)>>(level+3)); //FIXME 64bit slooow
176− if(score < best_vector_score){
177− int mean= (diff + (size>>1)) >> (level+3);
178− av_assert2(mean >-300 && mean<300);
179− mean= av_clip(mean, intra?0:-256, 255);
180− best_vector_score= score;
181− best_vector[stage]= i;
182− best_vector_sum= sum;
183− best_vector_mean= mean;
174+ vector = codebook + stage * size * 16 + i * size;
175+ sqr = s->dsp.ssd_int8_vs_int16(vector, block[stage], size);
176+ diff = block_sum[stage] - sum;
177+ score = sqr - (diff * (int64_t)diff >> (level + 3)); // FIXME: 64bit slooow
178+ if (score < best_vector_score) {
179+ int mean = diff + (size >> 1) >> (level + 3);
180+ av_assert2(mean > -300 && mean < 300);
181+ mean = av_clip(mean, intra ? 0 : -256, 255);
182+ best_vector_score = score;
183+ best_vector[stage] = i;
184+ best_vector_sum = sum;
185+ best_vector_mean = mean;
184186 }
185187 }
186188 av_assert0(best_vector_mean != -999);
187− vector= codebook + stage*size*16 + best_vector[stage]*size;
188− for(j=0; j<size; j++){
189− block[stage+1][j] = block[stage][j] - vector[j];
190− }
191− block_sum[stage+1]= block_sum[stage] - best_vector_sum;
192− best_vector_score +=
193− lambda*(+ 1 + 4*count
194− + multistage_vlc[1+count][1]
195− + mean_vlc[best_vector_mean][1]);
196−
197− if(best_vector_score < best_score){
198− best_score= best_vector_score;
199− best_count= count;
200− best_mean= best_vector_mean;
189+ vector = codebook + stage * size * 16 + best_vector[stage] * size;
190+ for (j = 0; j < size; j++)
191+ block[stage + 1][j] = block[stage][j] - vector[j];
192+ block_sum[stage + 1] = block_sum[stage] - best_vector_sum;
193+ best_vector_score += lambda *
194+ (+1 + 4 * count +
195+ multistage_vlc[1 + count][1]
196+ + mean_vlc[best_vector_mean][1]);
197+
198+ if (best_vector_score < best_score) {
199+ best_score = best_vector_score;
200+ best_count = count;
201+ best_mean = best_vector_mean;
201202 }
202203 }
203204 }
204205
205− split=0;
206− if(best_score > threshold && level){
207− int score=0;
208− int offset= (level&1) ? stride*h/2 : w/2;
206+ split = 0;
207+ if (best_score > threshold && level) {
208+ int score = 0;
209+ int offset = level & 1 ? stride * h / 2 : w / 2;
209210 PutBitContext backup[6];
210211
211− for(i=level-1; i>=0; i--){
212− backup[i]= s->reorder_pb[i];
213− }
214− score += encode_block(s, src , ref , decoded , stride, level-1, threshold>>1, lambda, intra);
215− score += encode_block(s, src + offset, ref + offset, decoded + offset, stride, level-1, threshold>>1, lambda, intra);
212+ for (i = level - 1; i >= 0; i--)
213+ backup[i] = s->reorder_pb[i];
214+ score += encode_block(s, src, ref, decoded, stride, level - 1,
215+ threshold >> 1, lambda, intra);
216+ score += encode_block(s, src + offset, ref + offset, decoded + offset,
217+ stride, level - 1, threshold >> 1, lambda, intra);
216218 score += lambda;
217219
218− if(score < best_score){
219− best_score= score;
220− split=1;
221− }else{
222− for(i=level-1; i>=0; i--){
223− s->reorder_pb[i]= backup[i];
224− }
220+ if (score < best_score) {
221+ best_score = score;
222+ split = 1;
223+ } else {
224+ for (i = level - 1; i >= 0; i--)
225+ s->reorder_pb[i] = backup[i];
225226 }
226227 }
227228 if (level > 0)
228229 put_bits(&s->reorder_pb[level], 1, split);
229230
230− if(!split){
231− av_assert1((best_mean >= 0 && best_mean<256) || !intra);
232− av_assert1(best_mean >= -256 && best_mean<256);
233− av_assert1(best_count >=0 && best_count<7);
234− av_assert1(level<4 || best_count==0);
231+ if (!split) {
232+ av_assert1(best_mean >= 0 && best_mean < 256 || !intra);
233+ av_assert1(best_mean >= -256 && best_mean < 256);
234+ av_assert1(best_count >= 0 && best_count < 7);
235+ av_assert1(level < 4 || best_count == 0);
235236
236237 /* output the encoding */
237238 put_bits(&s->reorder_pb[level],
238− multistage_vlc[1 + best_count][1],
239− multistage_vlc[1 + best_count][0]);
239+ multistage_vlc[1 + best_count][1],
240+ multistage_vlc[1 + best_count][0]);
240241 put_bits(&s->reorder_pb[level], mean_vlc[best_mean][1],
241− mean_vlc[best_mean][0]);
242+ mean_vlc[best_mean][0]);
242243
243− for (i = 0; i < best_count; i++){
244− av_assert2(best_vector[i]>=0 && best_vector[i]<16);
244+ for (i = 0; i < best_count; i++) {
245+ av_assert2(best_vector[i] >= 0 && best_vector[i] < 16);
245246 put_bits(&s->reorder_pb[level], 4, best_vector[i]);
246247 }
247248
248− for(y=0; y<h; y++){
249− for(x=0; x<w; x++){
250− decoded[x + y*stride]= src[x + y*stride] - block[best_count][x + w*y] + best_mean;
251− }
252− }
249+ for (y = 0; y < h; y++)
250+ for (x = 0; x < w; x++)
251+ decoded[x + y * stride] = src[x + y * stride] -
252+ block[best_count][x + w * y] +
253+ best_mean;
253254 }
254255
255256 return best_score;
256257 }
257258
258−
259−static int svq1_encode_plane(SVQ1Context *s, int plane, unsigned char *src_plane, unsigned char *ref_plane, unsigned char *decoded_plane,
260− int width, int height, int src_stride, int stride)
259+static int svq1_encode_plane(SVQ1Context *s, int plane,
260+ unsigned char *src_plane,
261+ unsigned char *ref_plane,
262+ unsigned char *decoded_plane,
263+ int width, int height, int src_stride, int stride)
261264 {
262265 int x, y;
263266 int i;
264267 int block_width, block_height;
265268 int level;
266269 int threshold[6];
267− uint8_t *src = s->scratchbuf + stride * 16;
268− const int lambda= (s->picture.quality*s->picture.quality) >> (2*FF_LAMBDA_SHIFT);
270+ uint8_t *src = s->scratchbuf + stride * 16;
271+ const int lambda = (s->picture.quality * s->picture.quality) >>
272+ (2 * FF_LAMBDA_SHIFT);
269273
270274 /* figure out the acceptable level thresholds in advance */
271275 threshold[5] = QUALITY_THRESHOLD;
272276 for (level = 4; level >= 0; level--)
273277 threshold[level] = threshold[level + 1] * THRESHOLD_MULTIPLIER;
274278
275− block_width = (width + 15) / 16;
279+ block_width = (width + 15) / 16;
276280 block_height = (height + 15) / 16;
277281
278− if(s->picture.pict_type == AV_PICTURE_TYPE_P){
279− s->m.avctx= s->avctx;
280− s->m.current_picture_ptr= &s->m.current_picture;
281− s->m.last_picture_ptr = &s->m.last_picture;
282− s->m.last_picture.f.data[0] = ref_plane;
283− s->m.linesize=
284− s->m.last_picture.f.linesize[0] =
285− s->m.new_picture.f.linesize[0] =
282+ if (s->picture.pict_type == AV_PICTURE_TYPE_P) {
283+ s->m.avctx = s->avctx;
284+ s->m.current_picture_ptr = &s->m.current_picture;
285+ s->m.last_picture_ptr = &s->m.last_picture;
286+ s->m.last_picture.f.data[0] = ref_plane;
287+ s->m.linesize =
288+ s->m.last_picture.f.linesize[0] =
289+ s->m.new_picture.f.linesize[0] =
286290 s->m.current_picture.f.linesize[0] = stride;
287− s->m.width= width;
288− s->m.height= height;
289− s->m.mb_width= block_width;
290− s->m.mb_height= block_height;
291− s->m.mb_stride= s->m.mb_width+1;
292− s->m.b8_stride= 2*s->m.mb_width+1;
293− s->m.f_code=1;
294− s->m.pict_type= s->picture.pict_type;
295− s->m.me_method= s->avctx->me_method;
296− s->m.me.scene_change_score=0;
297− s->m.flags= s->avctx->flags;
298−// s->m.out_format = FMT_H263;
299−// s->m.unrestricted_mv= 1;
300−
301− s->m.lambda= s->picture.quality;
302− s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
303− s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT;
304−
305− if(!s->motion_val8[plane]){
306− s->motion_val8 [plane]= av_mallocz((s->m.b8_stride*block_height*2 + 2)*2*sizeof(int16_t));
307− s->motion_val16[plane]= av_mallocz((s->m.mb_stride*(block_height + 2) + 1)*2*sizeof(int16_t));
291+ s->m.width = width;
292+ s->m.height = height;
293+ s->m.mb_width = block_width;
294+ s->m.mb_height = block_height;
295+ s->m.mb_stride = s->m.mb_width + 1;
296+ s->m.b8_stride = 2 * s->m.mb_width + 1;
297+ s->m.f_code = 1;
298+ s->m.pict_type = s->picture.pict_type;
299+ s->m.me_method = s->avctx->me_method;
300+ s->m.me.scene_change_score = 0;
301+ s->m.flags = s->avctx->flags;
302+ // s->m.out_format = FMT_H263;
303+ // s->m.unrestricted_mv = 1;
304+ s->m.lambda = s->picture.quality;
305+ s->m.qscale = s->m.lambda * 139 +
306+ FF_LAMBDA_SCALE * 64 >>
307+ FF_LAMBDA_SHIFT + 7;
308+ s->m.lambda2 = s->m.lambda * s->m.lambda +
309+ FF_LAMBDA_SCALE / 2 >>
310+ FF_LAMBDA_SHIFT;
311+
312+ if (!s->motion_val8[plane]) {
313+ s->motion_val8[plane] = av_mallocz((s->m.b8_stride *
314+ block_height * 2 + 2) *
315+ 2 * sizeof(int16_t));
316+ s->motion_val16[plane] = av_mallocz((s->m.mb_stride *
317+ (block_height + 2) + 1) *
318+ 2 * sizeof(int16_t));
308319 }
309320
310− s->m.mb_type= s->mb_type;
321+ s->m.mb_type = s->mb_type;
311322
312− //dummies, to avoid segfaults
313− s->m.current_picture.mb_mean= (uint8_t *)s->dummy;
314− s->m.current_picture.mb_var= (uint16_t*)s->dummy;
315− s->m.current_picture.mc_mb_var= (uint16_t*)s->dummy;
323+ // dummies, to avoid segfaults
324+ s->m.current_picture.mb_mean = (uint8_t *)s->dummy;
325+ s->m.current_picture.mb_var = (uint16_t *)s->dummy;
326+ s->m.current_picture.mc_mb_var = (uint16_t *)s->dummy;
316327 s->m.current_picture.f.mb_type = s->dummy;
317328
318329 s->m.current_picture.f.motion_val[0] = s->motion_val8[plane] + 2;
319− s->m.p_mv_table= s->motion_val16[plane] + s->m.mb_stride + 1;
320− s->m.dsp= s->dsp; //move
330+ s->m.p_mv_table = s->motion_val16[plane] +
331+ s->m.mb_stride + 1;
332+ s->m.dsp = s->dsp; // move
321333 ff_init_me(&s->m);
322334
323− s->m.me.dia_size= s->avctx->dia_size;
324− s->m.first_slice_line=1;
335+ s->m.me.dia_size = s->avctx->dia_size;
336+ s->m.first_slice_line = 1;
325337 for (y = 0; y < block_height; y++) {
326− s->m.new_picture.f.data[0] = src - y*16*stride; //ugly
327− s->m.mb_y= y;
328−
329− for(i=0; i<16 && i + 16*y<height; i++){
330− memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width);
331− for(x=width; x<16*block_width; x++)
332− src[i*stride+x]= src[i*stride+x-1];
338+ s->m.new_picture.f.data[0] = src - y * 16 * stride; // ugly
339+ s->m.mb_y = y;
340+
341+ for (i = 0; i < 16 && i + 16 * y < height; i++) {
342+ memcpy(&src[i * stride], &src_plane[(i + 16 * y) * src_stride],
343+ width);
344+ for (x = width; x < 16 * block_width; x++)
345+ src[i * stride + x] = src[i * stride + x - 1];
333346 }
334− for(; i<16 && i + 16*y<16*block_height; i++)
335− memcpy(&src[i*stride], &src[(i-1)*stride], 16*block_width);
347+ for (; i < 16 && i + 16 * y < 16 * block_height; i++)
348+ memcpy(&src[i * stride], &src[(i - 1) * stride],
349+ 16 * block_width);
336350
337351 for (x = 0; x < block_width; x++) {
338− s->m.mb_x= x;
352+ s->m.mb_x = x;
339353 ff_init_block_index(&s->m);
340354 ff_update_block_index(&s->m);
341355
342356 ff_estimate_p_frame_motion(&s->m, x, y);
343357 }
344− s->m.first_slice_line=0;
358+ s->m.first_slice_line = 0;
345359 }
346360
347361 ff_fix_long_p_mvs(&s->m);
348− ff_fix_long_mvs(&s->m, NULL, 0, s->m.p_mv_table, s->m.f_code, CANDIDATE_MB_TYPE_INTER, 0);
362+ ff_fix_long_mvs(&s->m, NULL, 0, s->m.p_mv_table, s->m.f_code,
363+ CANDIDATE_MB_TYPE_INTER, 0);
349364 }
350365
351− s->m.first_slice_line=1;
366+ s->m.first_slice_line = 1;
352367 for (y = 0; y < block_height; y++) {
353− for(i=0; i<16 && i + 16*y<height; i++){
354− memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width);
355− for(x=width; x<16*block_width; x++)
356− src[i*stride+x]= src[i*stride+x-1];
368+ for (i = 0; i < 16 && i + 16 * y < height; i++) {
369+ memcpy(&src[i * stride], &src_plane[(i + 16 * y) * src_stride],
370+ width);
371+ for (x = width; x < 16 * block_width; x++)
372+ src[i * stride + x] = src[i * stride + x - 1];
357373 }
358− for(; i<16 && i + 16*y<16*block_height; i++)
359− memcpy(&src[i*stride], &src[(i-1)*stride], 16*block_width);
374+ for (; i < 16 && i + 16 * y < 16 * block_height; i++)
375+ memcpy(&src[i * stride], &src[(i - 1) * stride], 16 * block_width);
360376
361− s->m.mb_y= y;
377+ s->m.mb_y = y;
362378 for (x = 0; x < block_width; x++) {
363− uint8_t reorder_buffer[3][6][7*32];
379+ uint8_t reorder_buffer[3][6][7 * 32];
364380 int count[3][6];
365− int offset = y * 16 * stride + x * 16;
366− uint8_t *decoded= decoded_plane + offset;
367− uint8_t *ref= ref_plane + offset;
368− int score[4]={0,0,0,0}, best;
369− uint8_t *temp = s->scratchbuf;
370−
371− if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 3000){ //FIXME check size
381+ int offset = y * 16 * stride + x * 16;
382+ uint8_t *decoded = decoded_plane + offset;
383+ uint8_t *ref = ref_plane + offset;
384+ int score[4] = { 0, 0, 0, 0 }, best;
385+ uint8_t *temp = s->scratchbuf;
386+
387+ if (s->pb.buf_end - s->pb.buf -
388+ (put_bits_count(&s->pb) >> 3) < 3000) { // FIXME: check size
372389 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
373390 return -1;
374391 }
375392
376− s->m.mb_x= x;
393+ s->m.mb_x = x;
377394 ff_init_block_index(&s->m);
378395 ff_update_block_index(&s->m);
379396
380− if(s->picture.pict_type == AV_PICTURE_TYPE_I || (s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTRA)){
381− for(i=0; i<6; i++){
382− init_put_bits(&s->reorder_pb[i], reorder_buffer[0][i], 7*32);
383− }
384− if(s->picture.pict_type == AV_PICTURE_TYPE_P){
385− const uint8_t *vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_INTRA];
397+ if (s->picture.pict_type == AV_PICTURE_TYPE_I ||
398+ (s->m.mb_type[x + y * s->m.mb_stride] &
399+ CANDIDATE_MB_TYPE_INTRA)) {
400+ for (i = 0; i < 6; i++)
401+ init_put_bits(&s->reorder_pb[i], reorder_buffer[0][i],
402+ 7 * 32);
403+ if (s->picture.pict_type == AV_PICTURE_TYPE_P) {
404+ const uint8_t *vlc = ff_svq1_block_type_vlc[SVQ1_BLOCK_INTRA];
386405 put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
387− score[0]= vlc[1]*lambda;
406+ score[0] = vlc[1] * lambda;
388407 }
389− score[0]+= encode_block(s, src+16*x, NULL, temp, stride, 5, 64, lambda, 1);
390− for(i=0; i<6; i++){
391− count[0][i]= put_bits_count(&s->reorder_pb[i]);
408+ score[0] += encode_block(s, src + 16 * x, NULL, temp, stride,
409+ 5, 64, lambda, 1);
410+ for (i = 0; i < 6; i++) {
411+ count[0][i] = put_bits_count(&s->reorder_pb[i]);
392412 flush_put_bits(&s->reorder_pb[i]);
393413 }
394− }else
395− score[0]= INT_MAX;
414+ } else
415+ score[0] = INT_MAX;
396416
397− best=0;
417+ best = 0;
398418
399− if(s->picture.pict_type == AV_PICTURE_TYPE_P){
400− const uint8_t *vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_INTER];
419+ if (s->picture.pict_type == AV_PICTURE_TYPE_P) {
420+ const uint8_t *vlc = ff_svq1_block_type_vlc[SVQ1_BLOCK_INTER];
401421 int mx, my, pred_x, pred_y, dxy;
402422 int16_t *motion_ptr;
403423
404− motion_ptr= ff_h263_pred_motion(&s->m, 0, 0, &pred_x, &pred_y);
405− if(s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTER){
406− for(i=0; i<6; i++)
407− init_put_bits(&s->reorder_pb[i], reorder_buffer[1][i], 7*32);
424+ motion_ptr = ff_h263_pred_motion(&s->m, 0, 0, &pred_x, &pred_y);
425+ if (s->m.mb_type[x + y * s->m.mb_stride] &
426+ CANDIDATE_MB_TYPE_INTER) {
427+ for (i = 0; i < 6; i++)
428+ init_put_bits(&s->reorder_pb[i], reorder_buffer[1][i],
429+ 7 * 32);
408430
409431 put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
410432
411− s->m.pb= s->reorder_pb[5];
412− mx= motion_ptr[0];
413− my= motion_ptr[1];
414− av_assert1(mx>=-32 && mx<=31);
415− av_assert1(my>=-32 && my<=31);
416− av_assert1(pred_x>=-32 && pred_x<=31);
417− av_assert1(pred_y>=-32 && pred_y<=31);
433+ s->m.pb = s->reorder_pb[5];
434+ mx = motion_ptr[0];
435+ my = motion_ptr[1];
436+ av_assert1(mx >= -32 && mx <= 31);
437+ av_assert1(my >= -32 && my <= 31);
438+ av_assert1(pred_x >= -32 && pred_x <= 31);
439+ av_assert1(pred_y >= -32 && pred_y <= 31);
418440 ff_h263_encode_motion(&s->m, mx - pred_x, 1);
419441 ff_h263_encode_motion(&s->m, my - pred_y, 1);
420− s->reorder_pb[5]= s->m.pb;
421− score[1] += lambda*put_bits_count(&s->reorder_pb[5]);
422−
423− dxy= (mx&1) + 2*(my&1);
424−
425− s->dsp.put_pixels_tab[0][dxy](temp+16, ref + (mx>>1) + stride*(my>>1), stride, 16);
426−
427− score[1]+= encode_block(s, src+16*x, temp+16, decoded, stride, 5, 64, lambda, 0);
428− best= score[1] <= score[0];
429−
430− vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_SKIP];
431− score[2]= s->dsp.sse[0](NULL, src+16*x, ref, stride, 16);
432− score[2]+= vlc[1]*lambda;
433− if(score[2] < score[best] && mx==0 && my==0){
434− best=2;
442+ s->reorder_pb[5] = s->m.pb;
443+ score[1] += lambda * put_bits_count(&s->reorder_pb[5]);
444+
445+ dxy = (mx & 1) + 2 * (my & 1);
446+
447+ s->dsp.put_pixels_tab[0][dxy](temp + 16,
448+ ref + (mx >> 1) +
449+ stride * (my >> 1),
450+ stride, 16);
451+
452+ score[1] += encode_block(s, src + 16 * x, temp + 16,
453+ decoded, stride, 5, 64, lambda, 0);
454+ best = score[1] <= score[0];
455+
456+ vlc = ff_svq1_block_type_vlc[SVQ1_BLOCK_SKIP];
457+ score[2] = s->dsp.sse[0](NULL, src + 16 * x, ref,
458+ stride, 16);
459+ score[2] += vlc[1] * lambda;
460+ if (score[2] < score[best] && mx == 0 && my == 0) {
461+ best = 2;
435462 s->dsp.put_pixels_tab[0][0](decoded, ref, stride, 16);
436− for(i=0; i<6; i++){
437− count[2][i]=0;
438− }
463+ for (i = 0; i < 6; i++)
464+ count[2][i] = 0;
439465 put_bits(&s->pb, vlc[1], vlc[0]);
440466 }
441467 }
442468
443− if(best==1){
444− for(i=0; i<6; i++){
445− count[1][i]= put_bits_count(&s->reorder_pb[i]);
469+ if (best == 1) {
470+ for (i = 0; i < 6; i++) {
471+ count[1][i] = put_bits_count(&s->reorder_pb[i]);
446472 flush_put_bits(&s->reorder_pb[i]);
447473 }
448− }else{
449− motion_ptr[0 ] = motion_ptr[1 ]=
450− motion_ptr[2 ] = motion_ptr[3 ]=
451− motion_ptr[0+2*s->m.b8_stride] = motion_ptr[1+2*s->m.b8_stride]=
452− motion_ptr[2+2*s->m.b8_stride] = motion_ptr[3+2*s->m.b8_stride]=0;
474+ } else {
475+ motion_ptr[0] =
476+ motion_ptr[1] =
477+ motion_ptr[2] =
478+ motion_ptr[3] =
479+ motion_ptr[0 + 2 * s->m.b8_stride] =
480+ motion_ptr[1 + 2 * s->m.b8_stride] =
481+ motion_ptr[2 + 2 * s->m.b8_stride] =
482+ motion_ptr[3 + 2 * s->m.b8_stride] = 0;
453483 }
454484 }
455485
456486 s->rd_total += score[best];
457487
458− for(i=5; i>=0; i--){
459− avpriv_copy_bits(&s->pb, reorder_buffer[best][i], count[best][i]);
460− }
461− if(best==0){
488+ for (i = 5; i >= 0; i--)
489+ avpriv_copy_bits(&s->pb, reorder_buffer[best][i],
490+ count[best][i]);
491+ if (best == 0)
462492 s->dsp.put_pixels_tab[0][0](decoded, temp, stride, 16);
463− }
464493 }
465− s->m.first_slice_line=0;
494+ s->m.first_slice_line = 0;
466495 }
467496 return 0;
468497 }
469498
470499 static av_cold int svq1_encode_init(AVCodecContext *avctx)
471500 {
472− SVQ1Context * const s = avctx->priv_data;
501+ SVQ1Context *const s = avctx->priv_data;
473502
474503 ff_dsputil_init(&s->dsp, avctx);
475504 avctx->coded_frame = &s->picture;
476505
477− s->frame_width = avctx->width;
506+ s->frame_width = avctx->width;
478507 s->frame_height = avctx->height;
479508
480− s->y_block_width = (s->frame_width + 15) / 16;
509+ s->y_block_width = (s->frame_width + 15) / 16;
481510 s->y_block_height = (s->frame_height + 15) / 16;
482511
483− s->c_block_width = (s->frame_width / 4 + 15) / 16;
512+ s->c_block_width = (s->frame_width / 4 + 15) / 16;
484513 s->c_block_height = (s->frame_height / 4 + 15) / 16;
485514
486− s->avctx= avctx;
487− s->m.avctx= avctx;
515+ s->avctx = avctx;
516+ s->m.avctx = avctx;
488517 s->m.picture_structure = PICT_FRAME;
489− s->m.me.temp =
490− s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t));
491− s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t));
492− s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t));
493− s->mb_type = av_mallocz((s->y_block_width+1)*s->y_block_height*sizeof(int16_t));
494− s->dummy = av_mallocz((s->y_block_width+1)*s->y_block_height*sizeof(int32_t));
495− ff_h263_encode_init(&s->m); //mv_penalty
518+ s->m.me.temp =
519+ s->m.me.scratchpad = av_mallocz((avctx->width + 64) *
520+ 2 * 16 * 2 * sizeof(uint8_t));
521+ s->m.me.map = av_mallocz(ME_MAP_SIZE * sizeof(uint32_t));
522+ s->m.me.score_map = av_mallocz(ME_MAP_SIZE * sizeof(uint32_t));
523+ s->mb_type = av_mallocz((s->y_block_width + 1) *
524+ s->y_block_height * sizeof(int16_t));
525+ s->dummy = av_mallocz((s->y_block_width + 1) *
526+ s->y_block_height * sizeof(int32_t));
527+ ff_h263_encode_init(&s->m); // mv_penalty
496528
497529 return 0;
498530 }
@@ -500,46 +532,51 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx) · 1 unmodified line
500532 static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
501533 const AVFrame *pict, int *got_packet)
502534 {
503− SVQ1Context * const s = avctx->priv_data;
504− AVFrame * const p = &s->picture;
535+ SVQ1Context *const s = avctx->priv_data;
536+ AVFrame *const p = &s->picture;
505537 AVFrame temp;
506538 int i, ret;
507539
508− if ((ret = ff_alloc_packet2(avctx, pkt, s->y_block_width*s->y_block_height*MAX_MB_BYTES*3 + FF_MIN_BUFFER_SIZE) < 0))
540+ if ((ret = ff_alloc_packet2(avctx, pkt, s->y_block_width * s->y_block_height *
541+ MAX_MB_BYTES*3 + FF_MIN_BUFFER_SIZE) < 0))
509542 return ret;
510543
511− if(avctx->pix_fmt != AV_PIX_FMT_YUV410P){
544+ if (avctx->pix_fmt != AV_PIX_FMT_YUV410P) {
512545 av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n");
513546 return -1;
514547 }
515548
516− if(!s->current_picture.data[0]){
549+ if (!s->current_picture.data[0]) {
517550 avctx->get_buffer(avctx, &s->current_picture);
518551 avctx->get_buffer(avctx, &s->last_picture);
519552 s->scratchbuf = av_malloc(s->current_picture.linesize[0] * 16 * 2);
520553 }
521554
522− temp= s->current_picture;
523− s->current_picture= s->last_picture;
524− s->last_picture= temp;
555+ temp = s->current_picture;
556+ s->current_picture = s->last_picture;
557+ s->last_picture = temp;
525558
526559 init_put_bits(&s->pb, pkt->data, pkt->size);
527560
528− *p = *pict;
529− p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
561+ *p = *pict;
562+ p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ?
563+ AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
530564 p->key_frame = p->pict_type == AV_PICTURE_TYPE_I;
531565
532566 svq1_write_header(s, p->pict_type);
533− for(i=0; i<3; i++){
534− if(svq1_encode_plane(s, i,
535− s->picture.data[i], s->last_picture.data[i], s->current_picture.data[i],
536− s->frame_width / (i?4:1), s->frame_height / (i?4:1),
537− s->picture.linesize[i], s->current_picture.linesize[i]) < 0)
538− return -1;
539− }
540−
541−// avpriv_align_put_bits(&s->pb);
542− while(put_bits_count(&s->pb) & 31)
567+ for (i = 0; i < 3; i++)
568+ if (svq1_encode_plane(s, i,
569+ s->picture.data[i],
570+ s->last_picture.data[i],
571+ s->current_picture.data[i],
572+ s->frame_width / (i ? 4 : 1),
573+ s->frame_height / (i ? 4 : 1),
574+ s->picture.linesize[i],
575+ s->current_picture.linesize[i]) < 0)
576+ return -1;
577+
578+ // avpriv_align_put_bits(&s->pb);
579+ while (put_bits_count(&s->pb) & 31)
543580 put_bits(&s->pb, 1, 0);
544581
545582 flush_put_bits(&s->pb);
@@ -554,10 +591,12 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 8 unmodified lines
554591
555592 static av_cold int svq1_encode_end(AVCodecContext *avctx)
556593 {
557− SVQ1Context * const s = avctx->priv_data;
594+ SVQ1Context *const s = avctx->priv_data;
558595 int i;
559596
560− av_log(avctx, AV_LOG_DEBUG, "RD: %f\n", s->rd_total/(double)(avctx->width*avctx->height*avctx->frame_number));
597+ av_log(avctx, AV_LOG_DEBUG, "RD: %f\n",
598+ s->rd_total / (double)(avctx->width * avctx->height *
599+ avctx->frame_number));
561600
562601 av_freep(&s->m.me.scratchpad);
563602 av_freep(&s->m.me.map);
@@ -566,7 +605,7 @@ static av_cold int svq1_encode_end(AVCodecContext *avctx) · 2 unmodified lines
566605 av_freep(&s->dummy);
567606 av_freep(&s->scratchbuf);
568607
569− for(i=0; i<3; i++){
608+ for (i = 0; i < 3; i++) {
570609 av_freep(&s->motion_val8[i]);
571610 av_freep(&s->motion_val16[i]);
572611 }
@@ -578,7 +617,6 @@ static av_cold int svq1_encode_end(AVCodecContext *avctx) · 5 unmodified lines
578617 return 0;
579618 }
580619
581−
582620 AVCodec ff_svq1_encoder = {
583621 .name = "svq1",
584622 .type = AVMEDIA_TYPE_VIDEO,
@@ -587,6 +625,7 @@ AVCodec ff_svq1_encoder = { · 2 unmodified lines
587625 .init = svq1_encode_init,
588626 .encode2 = svq1_encode_frame,
589627 .close = svq1_encode_end,
590− .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV410P, AV_PIX_FMT_NONE },
628+ .pix_fmts = (const enum PixelFormat[]) { AV_PIX_FMT_YUV410P,
629+ AV_PIX_FMT_NONE },
591630 .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"),
592631 };
libavcodec/svq1enc_cb.h+48−58
@@ -30,67 +30,57 @@ · 29 unmodified lines
3030 #include <stdint.h>
3131
3232 static const int8_t svq1_inter_codebook_sum[4][16*6] = {
33− {
34− -1, 1, -2, 0, 1, -1, -1, -1, -2, -1, 1, -1, -1, 0, -1, -1,
35− 0, -1, -1, -1, -1, 0, -1, 0, 0, 0, -3, 1, -1, 0, 1, -1,
36− 1, -1, 2, 2, 1, 1, 2, 0, 0, 0, -1, 1, 1, 0, 0, 0,
37− 1, -1, 0, 1, -1, 1, 1, 0, 1, 0, -1, 1, 1, 0, 0, 0,
38− -2, 0, 0, -2, 0, 0, -2, 0, -2, -1, -2, -1, 0, 0, -1, 0,
39− 1, 0, 1, -1, 2, 2, 1, 2, 2, 1, 0, 1, 1, 0, 1, 1,
40− },{
41− -2, 1, -1, -1, 1, 0, 1, -1, -1, -1, 1, -1, 0, -1, 0, -1,
42− 0, 0, 0, -2, 0, 1, 0, -1, -1, 0, 2, -3, 1, -2, 3, -1,
43− 2, 0, 2, 1, 1, -1, 1, 1, 0, 0, 1, 1, 2, -2, 1, 0,
44− -2, -1, 2, -2, -2, 0, -3, 0, -1, 0, -1, 0, -1, 0, -2, -3,
45− 1, -2, -2, -1, 1, -1, -1, 1, -1, 1, 1, 0, -2, 0, 1, 1,
46− 1, 1, 2, 1, 0, 0, -1, 0, 0, 1, 0, 1, -1, 1, 0, 2,
47− },{
48− 0, 0, 0, -3, 1, 1, 1, -3, 0, -1, 0, -3, 1, -3, 0, -2,
49− 1, 2, -1, -3, 0, -3, 1, -1, 0, -1, 0, 0, 1, 2, 1, 1,
50− -1, 2, -3, 3, 1, 0, -5, 1, 0, -1, -3, 1, 0, 2, 0, -3,
51− 4, 2, 0, -2, 1, -2, 3, -2, 1, 1, 0, -1, 2, 5, 3, 1,
52− -1, 0, 2, -3, -2, 0, 0, -2, 2, -3, -1, -1, 2, 1, 0, -2,
53− 3, -1, 1, -1, 2, 4, 0, 1, 0, 1, 0, -1, -3, -2, -1, 0,
54− },{
55− 0, 2, -1, -1, 2, -4, -2, 3, 0, -1, -5, 1, 0, 1, 0, 6,
56− -2, 2, 0, 1, 1, -1, -1, -2, 1, -2, -1, 0, 2, -2, -2, -1,
57− -4, 2, -1, -3, -1, -2, 2, -1, 2, -1, 2, 0, 3, -3, -3, 0,
58− -3, 0, 0, -2, 4, -4, 0, -1, 4, 0, -2, -2, 3, -2, 0, 4,
59− 5, 0, 1, 0, -3, 3, 3, 2, 0, 0, 1, 2, -5, -2, -3, 0,
60− -3, 2, -2, 2, -2, 4, 7, -3, 4, 2, 3, 2, -1, 0, -3, 1,
61− }
33+ { -1, 1, -2, 0, 1, -1, -1, -1, -2, -1, 1, -1, -1, 0, -1, -1,
34+ 0, -1, -1, -1, -1, 0, -1, 0, 0, 0, -3, 1, -1, 0, 1, -1,
35+ 1, -1, 2, 2, 1, 1, 2, 0, 0, 0, -1, 1, 1, 0, 0, 0,
36+ 1, -1, 0, 1, -1, 1, 1, 0, 1, 0, -1, 1, 1, 0, 0, 0,
37+ -2, 0, 0, -2, 0, 0, -2, 0, -2, -1, -2, -1, 0, 0, -1, 0,
38+ 1, 0, 1, -1, 2, 2, 1, 2, 2, 1, 0, 1, 1, 0, 1, 1, },
39+ { -2, 1, -1, -1, 1, 0, 1, -1, -1, -1, 1, -1, 0, -1, 0, -1,
40+ 0, 0, 0, -2, 0, 1, 0, -1, -1, 0, 2, -3, 1, -2, 3, -1,
41+ 2, 0, 2, 1, 1, -1, 1, 1, 0, 0, 1, 1, 2, -2, 1, 0,
42+ -2, -1, 2, -2, -2, 0, -3, 0, -1, 0, -1, 0, -1, 0, -2, -3,
43+ 1, -2, -2, -1, 1, -1, -1, 1, -1, 1, 1, 0, -2, 0, 1, 1,
44+ 1, 1, 2, 1, 0, 0, -1, 0, 0, 1, 0, 1, -1, 1, 0, 2, },
45+ { 0, 0, 0, -3, 1, 1, 1, -3, 0, -1, 0, -3, 1, -3, 0, -2,
46+ 1, 2, -1, -3, 0, -3, 1, -1, 0, -1, 0, 0, 1, 2, 1, 1,
47+ -1, 2, -3, 3, 1, 0, -5, 1, 0, -1, -3, 1, 0, 2, 0, -3,
48+ 4, 2, 0, -2, 1, -2, 3, -2, 1, 1, 0, -1, 2, 5, 3, 1,
49+ -1, 0, 2, -3, -2, 0, 0, -2, 2, -3, -1, -1, 2, 1, 0, -2,
50+ 3, -1, 1, -1, 2, 4, 0, 1, 0, 1, 0, -1, -3, -2, -1, 0, },
51+ { 0, 2, -1, -1, 2, -4, -2, 3, 0, -1, -5, 1, 0, 1, 0, 6,
52+ -2, 2, 0, 1, 1, -1, -1, -2, 1, -2, -1, 0, 2, -2, -2, -1,
53+ -4, 2, -1, -3, -1, -2, 2, -1, 2, -1, 2, 0, 3, -3, -3, 0,
54+ -3, 0, 0, -2, 4, -4, 0, -1, 4, 0, -2, -2, 3, -2, 0, 4,
55+ 5, 0, 1, 0, -3, 3, 3, 2, 0, 0, 1, 2, -5, -2, -3, 0,
56+ -3, 2, -2, 2, -2, 4, 7, -3, 4, 2, 3, 2, -1, 0, -3, 1, }
6257 };
6358
6459 static const int8_t svq1_intra_codebook_sum[4][16*6] = {
65− {
66− 0, 0, 0, -1, -1, -1, -1, -2, 0, -1, -1, 0, -1, 0, 1, 0,
67− 1, 0, -1, 1, 0, 0, -1, 1, -1, 0, 0, 0, -1, 1, 0, 0,
68− -1, 0, 0, 1, -1, 1, 0, -1, -1, 0, 1, 1, 0, 0, -1, 1,
69− 0, 1, 0, 0, 1, -1, 0, 0, 0, -1, 1, 0, 1, 0, -2, 1,
70− 0, -1, 1, 0, 0, 0, 1, 0, -1, 0, 0, 0, -1, 0, 0, 0,
71− 0, 1, 1, 0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 1, 1, -1,
72− },{
73− -1, -2, 0, -1, 1, 0, -1, 0, -1, -4, -1, -2, -1, -2, 1, -2,
74− 0, 0, 4, -2, -1, 1, 1, 0, 2, 1, 1, 0, 2, 0, 0, 0,
75− 1, 1, 0, -1, -1, -1, 1, 0, -1, -3, -3, 1, -1, 1, -2, -1,
76− 1, -1, 0, 1, 2, 1, -1, -1, 1, 1, 1, 2, 1, 0, 1, -2,
77− -2, 0, -1, -2, -2, 0, -1, -1, -1, 0, 1, 0, -1, -1, 0, -1,
78− 0, 2, 1, 2, 2, 1, -1, 1, 0, 2, 0, -1, 1, 0, 0, 0,
79− },{
80− -2, 0, -1, -1, 1, 1, -2, 0, -2, 0, 1, -2, -2, 1, -1, -1,
81− 3, -2, 0, -3, -4, -3, 2, 1, 0, 3, -2, 2, 3, 2, 2, -1,
82− -3, 1, 0, 1, 0, 0, 0, 1, -2, 1, -2, -2, -1, -2, -2, 2,
83− 0, -4, 0, 2, -1, 0, 2, 2, 2, 1, 0, -1, -1, 1, -3, 2,
84− 2, 1, 0, 3, 1, -1, 1, 3, 1, 0, 1, 1, 2, -1, 1, -1,
85− -2, -1, 0, -1, 1, -1, 1, -2, -2, -1, -1, -3, 1, -4, -3, 1,
86− },{
87− -2, 0, -2, 3, -1, -1, 0, 2, 2, -1, -3, 2, 1, 0, -2, -1,
88− -3, -2, -2, 1, 2, -3, 0, 1, -5, -2, -3, 0, -2, -1, 2, 0,
89− -1, -1, 0, -2, 1, 3, -7, -2, -2, -1, 2, -1, 0, 3, 1, 3,
90− 1, 0, 0, 1, 2, 3, 1, 2, 0, -2, -2, 1, 1, 2, 2, 3,
91− 4, 1, -1, 2, -2, 4, 0, 0, 0, 4, 2, 0, -2, -2, 2, -4,
92− -1, 5, -2, -2, -3, 2, -3, -1, 3, -3, 0, 4, 3, 0, 1, -2,
93− }
60+ { 0, 0, 0, -1, -1, -1, -1, -2, 0, -1, -1, 0, -1, 0, 1, 0,
61+ 1, 0, -1, 1, 0, 0, -1, 1, -1, 0, 0, 0, -1, 1, 0, 0,
62+ -1, 0, 0, 1, -1, 1, 0, -1, -1, 0, 1, 1, 0, 0, -1, 1,
63+ 0, 1, 0, 0, 1, -1, 0, 0, 0, -1, 1, 0, 1, 0, -2, 1,
64+ 0, -1, 1, 0, 0, 0, 1, 0, -1, 0, 0, 0, -1, 0, 0, 0,
65+ 0, 1, 1, 0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 1, 1, -1, },
66+ { -1, -2, 0, -1, 1, 0, -1, 0, -1, -4, -1, -2, -1, -2, 1, -2,
67+ 0, 0, 4, -2, -1, 1, 1, 0, 2, 1, 1, 0, 2, 0, 0, 0,
68+ 1, 1, 0, -1, -1, -1, 1, 0, -1, -3, -3, 1, -1, 1, -2, -1,
69+ 1, -1, 0, 1, 2, 1, -1, -1, 1, 1, 1, 2, 1, 0, 1, -2,
70+ -2, 0, -1, -2, -2, 0, -1, -1, -1, 0, 1, 0, -1, -1, 0, -1,
71+ 0, 2, 1, 2, 2, 1, -1, 1, 0, 2, 0, -1, 1, 0, 0, 0, },
72+ { -2, 0, -1, -1, 1, 1, -2, 0, -2, 0, 1, -2, -2, 1, -1, -1,
73+ 3, -2, 0, -3, -4, -3, 2, 1, 0, 3, -2, 2, 3, 2, 2, -1,
74+ -3, 1, 0, 1, 0, 0, 0, 1, -2, 1, -2, -2, -1, -2, -2, 2,
75+ 0, -4, 0, 2, -1, 0, 2, 2, 2, 1, 0, -1, -1, 1, -3, 2,
76+ 2, 1, 0, 3, 1, -1, 1, 3, 1, 0, 1, 1, 2, -1, 1, -1,
77+ -2, -1, 0, -1, 1, -1, 1, -2, -2, -1, -1, -3, 1, -4, -3, 1, },
78+ { -2, 0, -2, 3, -1, -1, 0, 2, 2, -1, -3, 2, 1, 0, -2, -1,
79+ -3, -2, -2, 1, 2, -3, 0, 1, -5, -2, -3, 0, -2, -1, 2, 0,
80+ -1, -1, 0, -2, 1, 3, -7, -2, -2, -1, 2, -1, 0, 3, 1, 3,
81+ 1, 0, 0, 1, 2, 3, 1, 2, 0, -2, -2, 1, 1, 2, 2, 3,
82+ 4, 1, -1, 2, -2, 4, 0, 0, 0, 4, 2, 0, -2, -2, 2, -4,
83+ -1, 5, -2, -2, -3, 2, -3, -1, 3, -3, 0, 4, 3, 0, 1, -2, }
9484 };
9585
9686 #endif /* AVCODEC_SVQ1ENC_CB_H */
libavcodec/vc1dec.c+5−5
@@ -1351,7 +1351,7 @@ static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y, · 1350 unmodified lines
13511351 int px, py;
13521352 int sum;
13531353 int mixedmv_pic, num_samefield = 0, num_oppfield = 0;
1354− int opposit, a_f, b_f, c_f;
1354+ int opposite, a_f, b_f, c_f;
13551355 int16_t field_predA[2];
13561356 int16_t field_predB[2];
13571357 int16_t field_predC[2];
@@ -1460,12 +1460,12 @@ static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y, · 102 unmodified lines
14601460
14611461 if (v->field_mode) {
14621462 if (num_samefield <= num_oppfield)
1463− opposit = 1 - pred_flag;
1463+ opposite = 1 - pred_flag;
14641464 else
1465− opposit = pred_flag;
1465+ opposite = pred_flag;
14661466 } else
1467− opposit = 0;
1468− if (opposit) {
1467+ opposite = 0;
1468+ if (opposite) {
14691469 if (a_valid && !a_f) {
14701470 field_predA[0] = scaleforopp(v, field_predA[0], 0, dir);
14711471 field_predA[1] = scaleforopp(v, field_predA[1], 1, dir);
libavformat/avio.h+15−0
@@ -395,9 +395,24 @@ int avio_open2(AVIOContext **s, const char *url, int flags, · 394 unmodified lines
395395 * resource.
396396 *
397397 * @return 0 on success, an AVERROR < 0 on error.
398+ * @see avio_closep
398399 */
399400 int avio_close(AVIOContext *s);
400401
402+/**
403+ * Close the resource accessed by the AVIOContext *s, free it
404+ * and set the pointer pointing to it to NULL.
405+ * This function can only be used if s was opened by avio_open().
406+ *
407+ * The internal buffer is automatically flushed before closing the
408+ * resource.
409+ *
410+ * @return 0 on success, an AVERROR < 0 on error.
411+ * @see avio_close
412+ */
413+int avio_closep(AVIOContext **s);
414+
415+
401416 /**
402417 * Open a write only memory stream.
403418 *
libavformat/aviobuf.c+7−0
@@ -803,6 +803,13 @@ int avio_close(AVIOContext *s) · 802 unmodified lines
803803 return ffurl_close(h);
804804 }
805805
806+int avio_closep(AVIOContext **s)
807+{
808+ int ret = avio_close(*s);
809+ *s = NULL;
810+ return ret;
811+}
812+
806813 int avio_printf(AVIOContext *s, const char *fmt, ...)
807814 {
808815 va_list ap;
libavformat/mpegtsenc.c+3−3
@@ -669,10 +669,10 @@ static int mpegts_write_header(AVFormatContext *s) · 668 unmodified lines
669669 ts->sdt_packet_count = ts->sdt_packet_period-1;
670670
671671 if (ts->mux_rate == 1)
672− av_log(s, AV_LOG_INFO, "muxrate VBR, ");
672+ av_log(s, AV_LOG_VERBOSE, "muxrate VBR, ");
673673 else
674− av_log(s, AV_LOG_INFO, "muxrate %d, ", ts->mux_rate);
675− av_log(s, AV_LOG_INFO, "pcr every %d pkts, "
674+ av_log(s, AV_LOG_VERBOSE, "muxrate %d, ", ts->mux_rate);
675+ av_log(s, AV_LOG_VERBOSE, "pcr every %d pkts, "
676676 "sdt every %d, pat/pmt every %d pkts\n",
677677 service->pcr_packet_period,
678678 ts->sdt_packet_period, ts->pat_packet_period);
libavformat/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
3030 #include "libavutil/avutil.h"
3131
3232 #define LIBAVFORMAT_VERSION_MAJOR 54
33−#define LIBAVFORMAT_VERSION_MINOR 31
33+#define LIBAVFORMAT_VERSION_MINOR 32
3434 #define LIBAVFORMAT_VERSION_MICRO 100
3535
3636 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
libavutil/parseutils.c+2−2
@@ -723,8 +723,8 @@ int main(void) · 722 unmodified lines
723723 int ret;
724724 AVRational q = (AVRational){0, 0};
725725 ret = av_parse_video_rate(&q, rates[i]);
726− printf("'%s' -> %d/%d%s\n",
727− rates[i], q.num, q.den, ret ? " error" : "");
726+ printf("'%s' -> %d/%d %s\n",
727+ rates[i], q.num, q.den, ret ? "ERROR" : "OK");
728728 }
729729 }
730730
tests/ref/fate/parseutils+25−25
@@ -1,29 +1,29 @@
11 Testing av_parse_video_rate()
2−'-inf' -> -1/0 error
3−'inf' -> 1/0 error
4−'nan' -> 0/0 error
5−'123/0' -> 1/0 error
6−'-123 / 0' -> -1/0 error
7−'' -> 0/0 error
8−'/' -> 0/0 error
9−' 123 / 321' -> 41/107
10−'foo/foo' -> 0/0 error
11−'foo/1' -> 0/0 error
12−'1/foo' -> 1/0 error
13−'0/0' -> 0/0 error
14−'/0' -> 0/0 error
15−'1/' -> 1/0 error
16−'1' -> 1/1
17−'0' -> 0/1 error
18−'-123/123' -> -1/1 error
19−'-foo' -> 0/0 error
20−'123.23' -> 12323/100
21−'.23' -> 23/100
22−'-.23' -> -23/100 error
23−'-0.234' -> -117/500 error
24−'-0.0000001' -> 0/1 error
25−' 21332.2324 ' -> 917286/43
26−' -21332.2324 ' -> -917286/43 error
2+'-inf' -> -1/0 ERROR
3+'inf' -> 1/0 ERROR
4+'nan' -> 0/0 ERROR
5+'123/0' -> 1/0 ERROR
6+'-123 / 0' -> -1/0 ERROR
7+'' -> 0/0 ERROR
8+'/' -> 0/0 ERROR
9+' 123 / 321' -> 41/107 OK
10+'foo/foo' -> 0/0 ERROR
11+'foo/1' -> 0/0 ERROR
12+'1/foo' -> 1/0 ERROR
13+'0/0' -> 0/0 ERROR
14+'/0' -> 0/0 ERROR
15+'1/' -> 1/0 ERROR
16+'1' -> 1/1 OK
17+'0' -> 0/1 ERROR
18+'-123/123' -> -1/1 ERROR
19+'-foo' -> 0/0 ERROR
20+'123.23' -> 12323/100 OK
21+'.23' -> 23/100 OK
22+'-.23' -> -23/100 ERROR
23+'-0.234' -> -117/500 ERROR
24+'-0.0000001' -> 0/1 ERROR
25+' 21332.2324 ' -> 917286/43 OK
26+' -21332.2324 ' -> -917286/43 ERROR
2727
2828 Testing av_parse_color()
2929 bikeshed -> R(80) G(64) B(140) A(59)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t