* 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
Unified · Split
| @@ -97,6 +97,9 @@ API changes, most recent first: · 96 unmodified lines | |||
| 97 | 2012-03-26 - a67d9cf - lavfi 2.66.100 | 97 | 2012-03-26 - a67d9cf - lavfi 2.66.100 |
| 98 | Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions. | 98 | Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions. |
| 99 | 99 | ||
| 100 | 2012-10-xx - xxxxxxx - lavf 54.18.0 - avio.h | ||
| 101 | Add avio_closep to complement avio_close. | ||
| 102 | |||
| 100 | 2012-10-xx - xxxxxxx - lavu 51.42.0 - pixfmt.h | 103 | 2012-10-xx - xxxxxxx - lavu 51.42.0 - pixfmt.h |
| 101 | Rename PixelFormat to AVPixelFormat and all PIX_FMT_* to AV_PIX_FMT_*. | 104 | Rename PixelFormat to AVPixelFormat and all PIX_FMT_* to AV_PIX_FMT_*. |
| 102 | To provide backwards compatibility, PixelFormat is now #defined as | 105 | To provide backwards compatibility, PixelFormat is now #defined as |
| @@ -41,7 +41,7 @@ typedef struct A64Context { · 40 unmodified lines | |||
| 41 | AVLFG randctx; | 41 | AVLFG randctx; |
| 42 | int mc_lifetime; | 42 | int mc_lifetime; |
| 43 | int mc_use_5col; | 43 | int mc_use_5col; |
| 44 | int mc_frame_counter; | 44 | unsigned mc_frame_counter; |
| 45 | int *mc_meta_charset; | 45 | int *mc_meta_charset; |
| 46 | int *mc_charmap; | 46 | int *mc_charmap; |
| 47 | int *mc_best_cb; | 47 | int *mc_best_cb; |
| @@ -26,6 +26,10 @@ ARMV6-OBJS-$(CONFIG_VP8_DECODER) += arm/vp8_armv6.o \ · 25 unmodified lines | |||
| 26 | OBJS-$(CONFIG_H264DSP) += arm/h264dsp_init_arm.o | 26 | OBJS-$(CONFIG_H264DSP) += arm/h264dsp_init_arm.o |
| 27 | OBJS-$(CONFIG_H264PRED) += arm/h264pred_init_arm.o | 27 | OBJS-$(CONFIG_H264PRED) += arm/h264pred_init_arm.o |
| 28 | 28 | ||
| 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 | |||
| 29 | OBJS += arm/dsputil_init_arm.o \ | 33 | OBJS += arm/dsputil_init_arm.o \ |
| 30 | arm/dsputil_arm.o \ | 34 | arm/dsputil_arm.o \ |
| 31 | arm/fft_init_arm.o \ | 35 | arm/fft_init_arm.o \ |
| @@ -72,12 +76,8 @@ NEON-OBJS-$(CONFIG_DCA_DECODER) += arm/dcadsp_neon.o \ · 40 unmodified lines | |||
| 72 | arm/synth_filter_neon.o \ | 76 | arm/synth_filter_neon.o \ |
| 73 | 77 | ||
| 74 | NEON-OBJS-$(CONFIG_MPEGVIDEO) += arm/mpegvideo_neon.o | 78 | NEON-OBJS-$(CONFIG_MPEGVIDEO) += arm/mpegvideo_neon.o |
| 75 | NEON-OBJS-$(CONFIG_RV30_DECODER) += arm/rv34dsp_init_neon.o \ | 79 | NEON-OBJS-$(CONFIG_RV30_DECODER) += arm/rv34dsp_neon.o |
| 76 | arm/rv34dsp_neon.o \ | 80 | NEON-OBJS-$(CONFIG_RV40_DECODER) += 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 \ | ||
| 81 | arm/rv40dsp_neon.o \ | 81 | arm/rv40dsp_neon.o \ |
| 82 | arm/h264cmc_neon.o \ | 82 | arm/h264cmc_neon.o \ |
| 83 | 83 | ||
| @@ -1,20 +1,20 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2011 Janne Grunau <janne-libav@jannau.net> | 2 | * Copyright (c) 2011 Janne Grunau <janne-libav@jannau.net> |
| 3 | * | 3 | * |
| 4 | * This file is part of Libav. | 4 | * This file is part of FFmpeg. |
| 5 | * | 5 | * |
| 6 | * Libav is free software; you can redistribute it and/or | 6 | * FFmpeg is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public | 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either | 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. | 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * | 10 | * |
| 11 | * Libav is distributed in the hope that it will be useful, | 11 | * FFmpeg is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. | 14 | * Lesser General Public License for more details. |
| 15 | * | 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public | 16 | * 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 |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ | 19 | */ |
| 20 | 20 | ||
| @@ -22,6 +22,7 @@ · 1 unmodified line | |||
| 22 | 22 | ||
| 23 | #include "libavcodec/avcodec.h" | 23 | #include "libavcodec/avcodec.h" |
| 24 | #include "libavcodec/rv34dsp.h" | 24 | #include "libavcodec/rv34dsp.h" |
| 25 | #include "libavutil/arm/cpu.h" | ||
| 25 | 26 | ||
| 26 | void ff_rv34_inv_transform_noround_neon(DCTELEM *block); | 27 | void ff_rv34_inv_transform_noround_neon(DCTELEM *block); |
| 27 | 28 | ||
| @@ -30,11 +31,15 @@ void ff_rv34_inv_transform_noround_dc_neon(DCTELEM *block); · 2 unmodified lines | |||
| 30 | void ff_rv34_idct_add_neon(uint8_t *dst, ptrdiff_t stride, DCTELEM *block); | 31 | void ff_rv34_idct_add_neon(uint8_t *dst, ptrdiff_t stride, DCTELEM *block); |
| 31 | void ff_rv34_idct_dc_add_neon(uint8_t *dst, ptrdiff_t stride, int dc); | 32 | void ff_rv34_idct_dc_add_neon(uint8_t *dst, ptrdiff_t stride, int dc); |
| 32 | 33 | ||
| 33 | void ff_rv34dsp_init_neon(RV34DSPContext *c, DSPContext* dsp) | 34 | void ff_rv34dsp_init_arm(RV34DSPContext *c, DSPContext* dsp) |
| 34 | { | 35 | { |
| 35 | c->rv34_inv_transform = ff_rv34_inv_transform_noround_neon; | 36 | int cpu_flags = av_get_cpu_flags(); |
| 36 | c->rv34_inv_transform_dc = ff_rv34_inv_transform_noround_dc_neon; | ||
| 37 | 37 | ||
| 38 | c->rv34_idct_add = ff_rv34_idct_add_neon; | 38 | if (have_neon(cpu_flags)) { |
| 39 | c->rv34_idct_dc_add = ff_rv34_idct_dc_add_neon; | 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 | } | ||
| 40 | } | 45 | } |
| @@ -1,20 +1,20 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2011 Janne Grunau <janne-libav@jannau.net> | 2 | * Copyright (c) 2011 Janne Grunau <janne-libav@jannau.net> |
| 3 | * | 3 | * |
| 4 | * This file is part of Libav. | 4 | * This file is part of FFmpeg. |
| 5 | * | 5 | * |
| 6 | * Libav is free software; you can redistribute it and/or | 6 | * FFmpeg is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public | 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either | 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. | 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * | 10 | * |
| 11 | * Libav is distributed in the hope that it will be useful, | 11 | * FFmpeg is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. | 14 | * Lesser General Public License for more details. |
| 15 | * | 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public | 16 | * 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 |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ | 19 | */ |
| 20 | 20 | ||
| @@ -22,6 +22,7 @@ · 1 unmodified line | |||
| 22 | 22 | ||
| 23 | #include "libavcodec/avcodec.h" | 23 | #include "libavcodec/avcodec.h" |
| 24 | #include "libavcodec/rv34dsp.h" | 24 | #include "libavcodec/rv34dsp.h" |
| 25 | #include "libavutil/arm/cpu.h" | ||
| 25 | 26 | ||
| 26 | #define DECL_QPEL3(type, w, pos) \ | 27 | #define DECL_QPEL3(type, w, pos) \ |
| 27 | void ff_##type##_rv40_qpel##w##_mc##pos##_neon(uint8_t *dst, uint8_t *src,\ | 28 | 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 | |||
| 68 | int filter_q1, int alpha, int beta, | 69 | int filter_q1, int alpha, int beta, |
| 69 | int lim_p0q0, int lim_q1, int lim_p1); | 70 | int lim_p0q0, int lim_q1, int lim_p1); |
| 70 | 71 | ||
| 71 | void ff_rv40dsp_init_neon(RV34DSPContext *c, DSPContext* dsp) | 72 | static void ff_rv40dsp_init_neon(RV34DSPContext *c) |
| 72 | { | 73 | { |
| 73 | c->put_pixels_tab[0][ 1] = ff_put_rv40_qpel16_mc10_neon; | 74 | c->put_pixels_tab[0][ 1] = ff_put_rv40_qpel16_mc10_neon; |
| 74 | c->put_pixels_tab[0][ 3] = ff_put_rv40_qpel16_mc30_neon; | 75 | 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 | |||
| 136 | c->rv40_weak_loop_filter[0] = ff_rv40_h_weak_loop_filter_neon; | 137 | c->rv40_weak_loop_filter[0] = ff_rv40_h_weak_loop_filter_neon; |
| 137 | c->rv40_weak_loop_filter[1] = ff_rv40_v_weak_loop_filter_neon; | 138 | c->rv40_weak_loop_filter[1] = ff_rv40_v_weak_loop_filter_neon; |
| 138 | } | 139 | } |
| 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 | } | ||
| @@ -135,8 +135,8 @@ av_cold void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp) { · 134 unmodified lines | |||
| 135 | c->rv34_idct_add = rv34_idct_add_c; | 135 | c->rv34_idct_add = rv34_idct_add_c; |
| 136 | c->rv34_idct_dc_add = rv34_idct_dc_add_c; | 136 | c->rv34_idct_dc_add = rv34_idct_dc_add_c; |
| 137 | 137 | ||
| 138 | if (HAVE_NEON) | 138 | if (ARCH_ARM) |
| 139 | ff_rv34dsp_init_neon(c, dsp); | 139 | ff_rv34dsp_init_arm(c, dsp); |
| 140 | if (ARCH_X86) | 140 | if (ARCH_X86) |
| 141 | ff_rv34dsp_init_x86(c, dsp); | 141 | ff_rv34dsp_init_x86(c, dsp); |
| 142 | } | 142 | } |
| @@ -77,10 +77,10 @@ void ff_rv30dsp_init(RV34DSPContext *c, DSPContext* dsp); · 76 unmodified lines | |||
| 77 | void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp); | 77 | void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp); |
| 78 | void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp); | 78 | void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp); |
| 79 | 79 | ||
| 80 | void ff_rv34dsp_init_neon(RV34DSPContext *c, DSPContext *dsp); | 80 | void ff_rv34dsp_init_arm(RV34DSPContext *c, DSPContext *dsp); |
| 81 | void ff_rv34dsp_init_x86(RV34DSPContext *c, DSPContext *dsp); | 81 | void ff_rv34dsp_init_x86(RV34DSPContext *c, DSPContext *dsp); |
| 82 | 82 | ||
| 83 | void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp); | 83 | 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); |
| 85 | 85 | ||
| 86 | #endif /* AVCODEC_RV34DSP_H */ | 86 | #endif /* AVCODEC_RV34DSP_H */ |
| @@ -606,6 +606,6 @@ av_cold void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp) { · 605 unmodified lines | |||
| 606 | 606 | ||
| 607 | if (ARCH_X86) | 607 | if (ARCH_X86) |
| 608 | ff_rv40dsp_init_x86(c, dsp); | 608 | ff_rv40dsp_init_x86(c, dsp); |
| 609 | if (HAVE_NEON) | 609 | if (ARCH_ARM) |
| 610 | ff_rv40dsp_init_neon(c, dsp); | 610 | ff_rv40dsp_init_arm(c, dsp); |
| 611 | } | 611 | } |
| @@ -38,6 +38,6 @@ · 37 unmodified lines | |||
| 38 | 38 | ||
| 39 | /* standard video sizes */ | 39 | /* standard video sizes */ |
| 40 | const struct svq1_frame_size ff_svq1_frame_size_table[7] = { | 40 | const struct svq1_frame_size ff_svq1_frame_size_table[7] = { |
| 41 | { 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 }, | 41 | { 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 }, |
| 42 | { 704, 576 }, { 240, 180 }, { 320, 240 } | 42 | { 704, 576 }, { 240, 180 }, { 320, 240 } |
| 43 | }; | 43 | }; |
| @@ -47,11 +47,11 @@ struct svq1_frame_size { · 46 unmodified lines | |||
| 47 | uint16_t height; | 47 | uint16_t height; |
| 48 | }; | 48 | }; |
| 49 | 49 | ||
| 50 | uint16_t ff_svq1_packet_checksum (const uint8_t *data, const int length, | 50 | uint16_t ff_svq1_packet_checksum(const uint8_t *data, |
| 51 | int value); | 51 | const int length, int value); |
| 52 | 52 | ||
| 53 | extern const int8_t* const ff_svq1_inter_codebooks[6]; | 53 | extern const int8_t *const ff_svq1_inter_codebooks[6]; |
| 54 | extern const int8_t* const ff_svq1_intra_codebooks[6]; | 54 | extern const int8_t *const ff_svq1_intra_codebooks[6]; |
| 55 | 55 | ||
| 56 | extern const uint8_t ff_svq1_block_type_vlc[4][2]; | 56 | extern const uint8_t ff_svq1_block_type_vlc[4][2]; |
| 57 | extern const uint8_t ff_svq1_intra_multistage_vlc[6][8][2]; | 57 | extern const uint8_t ff_svq1_intra_multistage_vlc[6][8][2]; |
| @@ -23,46 +23,47 @@ · 22 unmodified lines | |||
| 23 | #include "svq1.h" | 23 | #include "svq1.h" |
| 24 | 24 | ||
| 25 | static const uint16_t checksum_table[256] = { | 25 | static const uint16_t checksum_table[256] = { |
| 26 | 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, | 26 | 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, |
| 27 | 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, | 27 | 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, |
| 28 | 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, | 28 | 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, |
| 29 | 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, | 29 | 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, |
| 30 | 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, | 30 | 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, |
| 31 | 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, | 31 | 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, |
| 32 | 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, | 32 | 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, |
| 33 | 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, | 33 | 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, |
| 34 | 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, | 34 | 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, |
| 35 | 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, | 35 | 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, |
| 36 | 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, | 36 | 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, |
| 37 | 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, | 37 | 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, |
| 38 | 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, | 38 | 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, |
| 39 | 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, | 39 | 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, |
| 40 | 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, | 40 | 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, |
| 41 | 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, | 41 | 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, |
| 42 | 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, | 42 | 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, |
| 43 | 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, | 43 | 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, |
| 44 | 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, | 44 | 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, |
| 45 | 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, | 45 | 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, |
| 46 | 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, | 46 | 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, |
| 47 | 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, | 47 | 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, |
| 48 | 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, | 48 | 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, |
| 49 | 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, | 49 | 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, |
| 50 | 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, | 50 | 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, |
| 51 | 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, | 51 | 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, |
| 52 | 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, | 52 | 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, |
| 53 | 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, | 53 | 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, |
| 54 | 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, | 54 | 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, |
| 55 | 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, | 55 | 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, |
| 56 | 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, | 56 | 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, |
| 57 | 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 | 57 | 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 |
| 58 | }; | 58 | }; |
| 59 | 59 | ||
| 60 | uint16_t ff_svq1_packet_checksum (const uint8_t *data, const int length, int value) { | 60 | uint16_t ff_svq1_packet_checksum (const uint8_t *data, |
| 61 | int i; | 61 | const int length, int value) |
| 62 | { | ||
| 63 | int i; | ||
| 62 | 64 | ||
| 63 | for (i=0; i < length; i++) { | 65 | for (i = 0; i < length; i++) |
| 64 | value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8); | 66 | value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8); |
| 65 | } | ||
| 66 | 67 | ||
| 67 | return value; | 68 | return value; |
| 68 | } | 69 | } |
| @@ -25,131 +25,116 @@ · 24 unmodified lines | |||
| 25 | 25 | ||
| 26 | /* values in this table range from 0..3; adjust retrieved value by +0 */ | 26 | /* values in this table range from 0..3; adjust retrieved value by +0 */ |
| 27 | const uint8_t ff_svq1_block_type_vlc[4][2] = { | 27 | const uint8_t ff_svq1_block_type_vlc[4][2] = { |
| 28 | /* { code, length } */ | 28 | /* { code, length } */ |
| 29 | { 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 }, { 0x0, 3 } | 29 | { 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 }, { 0x0, 3 } |
| 30 | |||
| 31 | }; | 30 | }; |
| 32 | 31 | ||
| 33 | /* values in this table range from -1..6; adjust retrieved value by -1 */ | 32 | /* values in this table range from -1..6; adjust retrieved value by -1 */ |
| 34 | const uint8_t ff_svq1_intra_multistage_vlc[6][8][2] = { | 33 | const uint8_t ff_svq1_intra_multistage_vlc[6][8][2] = { |
| 35 | /* { code, length } */ | 34 | /* { code, length } */ |
| 36 | { | 35 | { { 0x1, 5 }, { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, |
| 37 | { 0x1, 5 }, { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, | 36 | { 0x3, 4 }, { 0x2, 4 }, { 0x0, 5 }, { 0x1, 4 } }, |
| 38 | { 0x3, 4 }, { 0x2, 4 }, { 0x0, 5 }, { 0x1, 4 } | 37 | { { 0x1, 4 }, { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 }, |
| 39 | },{ | 38 | { 0x3, 3 }, { 0x2, 3 }, { 0x0, 4 }, { 0x1, 3 } }, |
| 40 | { 0x1, 4 }, { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 }, | 39 | { { 0x1, 5 }, { 0x1, 1 }, { 0x3, 3 }, { 0x0, 5 }, |
| 41 | { 0x3, 3 }, { 0x2, 3 }, { 0x0, 4 }, { 0x1, 3 } | 40 | { 0x3, 4 }, { 0x2, 3 }, { 0x2, 4 }, { 0x1, 4 } }, |
| 42 | },{ | 41 | { { 0x1, 6 }, { 0x1, 1 }, { 0x1, 2 }, { 0x0, 6 }, |
| 43 | { 0x1, 5 }, { 0x1, 1 }, { 0x3, 3 }, { 0x0, 5 }, | 42 | { 0x3, 4 }, { 0x2, 4 }, { 0x1, 5 }, { 0x1, 4 } }, |
| 44 | { 0x3, 4 }, { 0x2, 3 }, { 0x2, 4 }, { 0x1, 4 } | 43 | { { 0x1, 6 }, { 0x1, 1 }, { 0x1, 2 }, { 0x3, 5 }, |
| 45 | },{ | 44 | { 0x2, 5 }, { 0x0, 6 }, { 0x1, 5 }, { 0x1, 3 } }, |
| 46 | { 0x1, 6 }, { 0x1, 1 }, { 0x1, 2 }, { 0x0, 6 }, | 45 | { { 0x1, 7 }, { 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 }, |
| 47 | { 0x3, 4 }, { 0x2, 4 }, { 0x1, 5 }, { 0x1, 4 } | 46 | { 0x1, 4 }, { 0x1, 6 }, { 0x0, 7 }, { 0x1, 5 } } |
| 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 | } | ||
| 55 | }; | 47 | }; |
| 56 | 48 | ||
| 57 | /* values in this table range from -1..6; adjust retrieved value by -1 */ | 49 | /* values in this table range from -1..6; adjust retrieved value by -1 */ |
| 58 | const uint8_t ff_svq1_inter_multistage_vlc[6][8][2] = { | 50 | const uint8_t ff_svq1_inter_multistage_vlc[6][8][2] = { |
| 59 | /* { code, length } */ | 51 | /* { code, length } */ |
| 60 | { | 52 | { { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 }, { 0x3, 3 }, |
| 61 | { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 }, { 0x3, 3 }, | 53 | { 0x2, 3 }, { 0x1, 3 }, { 0x1, 4 }, { 0x0, 4 } }, |
| 62 | { 0x2, 3 }, { 0x1, 3 }, { 0x1, 4 }, { 0x0, 4 } | 54 | { { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 }, { 0x3, 3 }, |
| 63 | },{ | 55 | { 0x2, 3 }, { 0x1, 3 }, { 0x1, 4 }, { 0x0, 4 } }, |
| 64 | { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 }, { 0x3, 3 }, | 56 | { { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 }, |
| 65 | { 0x2, 3 }, { 0x1, 3 }, { 0x1, 4 }, { 0x0, 4 } | 57 | { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 } }, |
| 66 | },{ | 58 | { { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 }, |
| 67 | { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 }, | 59 | { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 } }, |
| 68 | { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 } | 60 | { { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 }, |
| 69 | },{ | 61 | { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 } }, |
| 70 | { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 }, | 62 | { { 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 }, { 0x3, 5 }, |
| 71 | { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 } | 63 | { 0x2, 5 }, { 0x1, 5 }, { 0x1, 6 }, { 0x0, 6 } } |
| 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 | } | ||
| 79 | }; | 64 | }; |
| 80 | 65 | ||
| 81 | /* values in this table range from 0..255; adjust retrieved value by +0 */ | 66 | /* values in this table range from 0..255; adjust retrieved value by +0 */ |
| 82 | const uint16_t ff_svq1_intra_mean_vlc[256][2] = { | 67 | const uint16_t ff_svq1_intra_mean_vlc[256][2] = { |
| 83 | /* { code, length } */ | 68 | /* { code, length } */ |
| 84 | { 0x37, 6 }, { 0x56, 7 }, { 0x1, 17 }, { 0x1, 20 }, | 69 | { 0x37, 6 }, { 0x56, 7 }, { 0x01, 17 }, { 0x01, 20 }, |
| 85 | { 0x2, 20 }, { 0x3, 20 }, { 0x0, 20 }, { 0x4, 20 }, | 70 | { 0x02, 20 }, { 0x03, 20 }, { 0x00, 20 }, { 0x04, 20 }, |
| 86 | { 0x5, 20 }, { 0x3, 19 }, { 0x15, 11 }, { 0x42, 9 }, | 71 | { 0x05, 20 }, { 0x03, 19 }, { 0x15, 11 }, { 0x42, 9 }, |
| 87 | { 0x14, 11 }, { 0x3, 14 }, { 0x2, 14 }, { 0x1, 15 }, | 72 | { 0x14, 11 }, { 0x03, 14 }, { 0x02, 14 }, { 0x01, 15 }, |
| 88 | { 0x1, 16 }, { 0x1, 12 }, { 0x2B, 10 }, { 0x18, 11 }, | 73 | { 0x01, 16 }, { 0x01, 12 }, { 0x2B, 10 }, { 0x18, 11 }, |
| 89 | { 0xC, 11 }, { 0x41, 9 }, { 0x78, 8 }, { 0x6C, 8 }, | 74 | { 0x0C, 11 }, { 0x41, 9 }, { 0x78, 8 }, { 0x6C, 8 }, |
| 90 | { 0x55, 7 }, { 0xF, 4 }, { 0xE, 4 }, { 0x34, 6 }, | 75 | { 0x55, 7 }, { 0x0F, 4 }, { 0x0E, 4 }, { 0x34, 6 }, |
| 91 | { 0x51, 7 }, { 0x72, 8 }, { 0x6E, 8 }, { 0x40, 9 }, | 76 | { 0x51, 7 }, { 0x72, 8 }, { 0x6E, 8 }, { 0x40, 9 }, |
| 92 | { 0x3F, 9 }, { 0x3E, 9 }, { 0x3D, 9 }, { 0x3C, 9 }, | 77 | { 0x3F, 9 }, { 0x3E, 9 }, { 0x3D, 9 }, { 0x3C, 9 }, |
| 93 | { 0x3B, 9 }, { 0x3A, 9 }, { 0x39, 9 }, { 0x38, 9 }, | 78 | { 0x3B, 9 }, { 0x3A, 9 }, { 0x39, 9 }, { 0x38, 9 }, |
| 94 | { 0x37, 9 }, { 0x43, 9 }, { 0x46, 9 }, { 0x47, 9 }, | 79 | { 0x37, 9 }, { 0x43, 9 }, { 0x46, 9 }, { 0x47, 9 }, |
| 95 | { 0x45, 9 }, { 0x44, 9 }, { 0x49, 9 }, { 0x48, 9 }, | 80 | { 0x45, 9 }, { 0x44, 9 }, { 0x49, 9 }, { 0x48, 9 }, |
| 96 | { 0x4A, 8 }, { 0x79, 8 }, { 0x76, 8 }, { 0x77, 8 }, | 81 | { 0x4A, 8 }, { 0x79, 8 }, { 0x76, 8 }, { 0x77, 8 }, |
| 97 | { 0x71, 8 }, { 0x75, 8 }, { 0x74, 8 }, { 0x73, 8 }, | 82 | { 0x71, 8 }, { 0x75, 8 }, { 0x74, 8 }, { 0x73, 8 }, |
| 98 | { 0x6A, 8 }, { 0x55, 8 }, { 0x70, 8 }, { 0x6F, 8 }, | 83 | { 0x6A, 8 }, { 0x55, 8 }, { 0x70, 8 }, { 0x6F, 8 }, |
| 99 | { 0x52, 8 }, { 0x6D, 8 }, { 0x4C, 8 }, { 0x6B, 8 }, | 84 | { 0x52, 8 }, { 0x6D, 8 }, { 0x4C, 8 }, { 0x6B, 8 }, |
| 100 | { 0x40, 7 }, { 0x69, 8 }, { 0x68, 8 }, { 0x67, 8 }, | 85 | { 0x40, 7 }, { 0x69, 8 }, { 0x68, 8 }, { 0x67, 8 }, |
| 101 | { 0x66, 8 }, { 0x65, 8 }, { 0x64, 8 }, { 0x63, 8 }, | 86 | { 0x66, 8 }, { 0x65, 8 }, { 0x64, 8 }, { 0x63, 8 }, |
| 102 | { 0x62, 8 }, { 0x61, 8 }, { 0x60, 8 }, { 0x5F, 8 }, | 87 | { 0x62, 8 }, { 0x61, 8 }, { 0x60, 8 }, { 0x5F, 8 }, |
| 103 | { 0x5E, 8 }, { 0x5D, 8 }, { 0x5C, 8 }, { 0x5B, 8 }, | 88 | { 0x5E, 8 }, { 0x5D, 8 }, { 0x5C, 8 }, { 0x5B, 8 }, |
| 104 | { 0x5A, 8 }, { 0x59, 8 }, { 0x58, 8 }, { 0x57, 8 }, | 89 | { 0x5A, 8 }, { 0x59, 8 }, { 0x58, 8 }, { 0x57, 8 }, |
| 105 | { 0x56, 8 }, { 0x3D, 7 }, { 0x54, 8 }, { 0x53, 8 }, | 90 | { 0x56, 8 }, { 0x3D, 7 }, { 0x54, 8 }, { 0x53, 8 }, |
| 106 | { 0x3F, 7 }, { 0x51, 8 }, { 0x50, 8 }, { 0x4F, 8 }, | 91 | { 0x3F, 7 }, { 0x51, 8 }, { 0x50, 8 }, { 0x4F, 8 }, |
| 107 | { 0x4E, 8 }, { 0x4D, 8 }, { 0x41, 7 }, { 0x4B, 8 }, | 92 | { 0x4E, 8 }, { 0x4D, 8 }, { 0x41, 7 }, { 0x4B, 8 }, |
| 108 | { 0x53, 7 }, { 0x3E, 7 }, { 0x48, 8 }, { 0x4F, 7 }, | 93 | { 0x53, 7 }, { 0x3E, 7 }, { 0x48, 8 }, { 0x4F, 7 }, |
| 109 | { 0x52, 7 }, { 0x45, 8 }, { 0x50, 7 }, { 0x43, 8 }, | 94 | { 0x52, 7 }, { 0x45, 8 }, { 0x50, 7 }, { 0x43, 8 }, |
| 110 | { 0x42, 8 }, { 0x41, 8 }, { 0x42, 7 }, { 0x43, 7 }, | 95 | { 0x42, 8 }, { 0x41, 8 }, { 0x42, 7 }, { 0x43, 7 }, |
| 111 | { 0x3E, 8 }, { 0x44, 7 }, { 0x3C, 8 }, { 0x45, 7 }, | 96 | { 0x3E, 8 }, { 0x44, 7 }, { 0x3C, 8 }, { 0x45, 7 }, |
| 112 | { 0x46, 7 }, { 0x47, 7 }, { 0x48, 7 }, { 0x49, 7 }, | 97 | { 0x46, 7 }, { 0x47, 7 }, { 0x48, 7 }, { 0x49, 7 }, |
| 113 | { 0x4A, 7 }, { 0x4B, 7 }, { 0x4C, 7 }, { 0x4D, 7 }, | 98 | { 0x4A, 7 }, { 0x4B, 7 }, { 0x4C, 7 }, { 0x4D, 7 }, |
| 114 | { 0x4E, 7 }, { 0x58, 7 }, { 0x59, 7 }, { 0x5A, 7 }, | 99 | { 0x4E, 7 }, { 0x58, 7 }, { 0x59, 7 }, { 0x5A, 7 }, |
| 115 | { 0x5B, 7 }, { 0x5C, 7 }, { 0x5D, 7 }, { 0x44, 8 }, | 100 | { 0x5B, 7 }, { 0x5C, 7 }, { 0x5D, 7 }, { 0x44, 8 }, |
| 116 | { 0x49, 8 }, { 0x29, 8 }, { 0x3F, 8 }, { 0x3D, 8 }, | 101 | { 0x49, 8 }, { 0x29, 8 }, { 0x3F, 8 }, { 0x3D, 8 }, |
| 117 | { 0x3B, 8 }, { 0x2C, 8 }, { 0x28, 8 }, { 0x25, 8 }, | 102 | { 0x3B, 8 }, { 0x2C, 8 }, { 0x28, 8 }, { 0x25, 8 }, |
| 118 | { 0x26, 8 }, { 0x5E, 7 }, { 0x57, 7 }, { 0x54, 7 }, | 103 | { 0x26, 8 }, { 0x5E, 7 }, { 0x57, 7 }, { 0x54, 7 }, |
| 119 | { 0x5F, 7 }, { 0x62, 7 }, { 0x63, 7 }, { 0x64, 7 }, | 104 | { 0x5F, 7 }, { 0x62, 7 }, { 0x63, 7 }, { 0x64, 7 }, |
| 120 | { 0x61, 7 }, { 0x65, 7 }, { 0x67, 7 }, { 0x66, 7 }, | 105 | { 0x61, 7 }, { 0x65, 7 }, { 0x67, 7 }, { 0x66, 7 }, |
| 121 | { 0x35, 6 }, { 0x36, 6 }, { 0x60, 7 }, { 0x39, 8 }, | 106 | { 0x35, 6 }, { 0x36, 6 }, { 0x60, 7 }, { 0x39, 8 }, |
| 122 | { 0x3A, 8 }, { 0x38, 8 }, { 0x37, 8 }, { 0x36, 8 }, | 107 | { 0x3A, 8 }, { 0x38, 8 }, { 0x37, 8 }, { 0x36, 8 }, |
| 123 | { 0x35, 8 }, { 0x34, 8 }, { 0x33, 8 }, { 0x32, 8 }, | 108 | { 0x35, 8 }, { 0x34, 8 }, { 0x33, 8 }, { 0x32, 8 }, |
| 124 | { 0x31, 8 }, { 0x30, 8 }, { 0x2D, 8 }, { 0x2B, 8 }, | 109 | { 0x31, 8 }, { 0x30, 8 }, { 0x2D, 8 }, { 0x2B, 8 }, |
| 125 | { 0x2A, 8 }, { 0x27, 8 }, { 0x40, 8 }, { 0x46, 8 }, | 110 | { 0x2A, 8 }, { 0x27, 8 }, { 0x40, 8 }, { 0x46, 8 }, |
| 126 | { 0x47, 8 }, { 0x26, 9 }, { 0x25, 9 }, { 0x24, 9 }, | 111 | { 0x47, 8 }, { 0x26, 9 }, { 0x25, 9 }, { 0x24, 9 }, |
| 127 | { 0x23, 9 }, { 0x22, 9 }, { 0x2E, 8 }, { 0x2F, 8 }, | 112 | { 0x23, 9 }, { 0x22, 9 }, { 0x2E, 8 }, { 0x2F, 8 }, |
| 128 | { 0x1F, 9 }, { 0x36, 9 }, { 0x1D, 9 }, { 0x21, 9 }, | 113 | { 0x1F, 9 }, { 0x36, 9 }, { 0x1D, 9 }, { 0x21, 9 }, |
| 129 | { 0x1B, 9 }, { 0x1C, 9 }, { 0x19, 9 }, { 0x1A, 9 }, | 114 | { 0x1B, 9 }, { 0x1C, 9 }, { 0x19, 9 }, { 0x1A, 9 }, |
| 130 | { 0x18, 9 }, { 0x17, 9 }, { 0x16, 9 }, { 0x1E, 9 }, | 115 | { 0x18, 9 }, { 0x17, 9 }, { 0x16, 9 }, { 0x1E, 9 }, |
| 131 | { 0x20, 9 }, { 0x27, 9 }, { 0x28, 9 }, { 0x29, 9 }, | 116 | { 0x20, 9 }, { 0x27, 9 }, { 0x28, 9 }, { 0x29, 9 }, |
| 132 | { 0x2A, 9 }, { 0x2B, 9 }, { 0x2C, 9 }, { 0x2D, 9 }, | 117 | { 0x2A, 9 }, { 0x2B, 9 }, { 0x2C, 9 }, { 0x2D, 9 }, |
| 133 | { 0x2E, 9 }, { 0x2F, 9 }, { 0x30, 9 }, { 0x35, 9 }, | 118 | { 0x2E, 9 }, { 0x2F, 9 }, { 0x30, 9 }, { 0x35, 9 }, |
| 134 | { 0x31, 9 }, { 0x32, 9 }, { 0x33, 9 }, { 0x34, 9 }, | 119 | { 0x31, 9 }, { 0x32, 9 }, { 0x33, 9 }, { 0x34, 9 }, |
| 135 | { 0x19, 10 }, { 0x2A, 10 }, { 0x17, 10 }, { 0x16, 10 }, | 120 | { 0x19, 10 }, { 0x2A, 10 }, { 0x17, 10 }, { 0x16, 10 }, |
| 136 | { 0x15, 10 }, { 0x28, 10 }, { 0x26, 10 }, { 0x25, 10 }, | 121 | { 0x15, 10 }, { 0x28, 10 }, { 0x26, 10 }, { 0x25, 10 }, |
| 137 | { 0x22, 10 }, { 0x21, 10 }, { 0x18, 10 }, { 0x14, 10 }, | 122 | { 0x22, 10 }, { 0x21, 10 }, { 0x18, 10 }, { 0x14, 10 }, |
| 138 | { 0x29, 10 }, { 0x12, 10 }, { 0xD, 10 }, { 0xE, 10 }, | 123 | { 0x29, 10 }, { 0x12, 10 }, { 0x0D, 10 }, { 0x0E, 10 }, |
| 139 | { 0xF, 10 }, { 0x10, 10 }, { 0x11, 10 }, { 0x1A, 10 }, | 124 | { 0x0F, 10 }, { 0x10, 10 }, { 0x11, 10 }, { 0x1A, 10 }, |
| 140 | { 0x1B, 10 }, { 0x1C, 10 }, { 0x1D, 10 }, { 0x1E, 10 }, | 125 | { 0x1B, 10 }, { 0x1C, 10 }, { 0x1D, 10 }, { 0x1E, 10 }, |
| 141 | { 0x1F, 10 }, { 0x20, 10 }, { 0x13, 10 }, { 0x23, 10 }, | 126 | { 0x1F, 10 }, { 0x20, 10 }, { 0x13, 10 }, { 0x23, 10 }, |
| 142 | { 0x24, 10 }, { 0x9, 11 }, { 0x8, 11 }, { 0x7, 11 }, | 127 | { 0x24, 10 }, { 0x09, 11 }, { 0x08, 11 }, { 0x07, 11 }, |
| 143 | { 0x27, 10 }, { 0x5, 11 }, { 0xB, 11 }, { 0x6, 11 }, | 128 | { 0x27, 10 }, { 0x05, 11 }, { 0x0B, 11 }, { 0x06, 11 }, |
| 144 | { 0x4, 11 }, { 0x3, 11 }, { 0x2, 11 }, { 0x1, 11 }, | 129 | { 0x04, 11 }, { 0x03, 11 }, { 0x02, 11 }, { 0x01, 11 }, |
| 145 | { 0xA, 11 }, { 0x16, 11 }, { 0x19, 11 }, { 0x17, 11 }, | 130 | { 0x0A, 11 }, { 0x16, 11 }, { 0x19, 11 }, { 0x17, 11 }, |
| 146 | { 0xD, 11 }, { 0xE, 11 }, { 0xF, 11 }, { 0x10, 11 }, | 131 | { 0x0D, 11 }, { 0x0E, 11 }, { 0x0F, 11 }, { 0x10, 11 }, |
| 147 | { 0x11, 11 }, { 0x12, 11 }, { 0x13, 11 }, { 0x1, 14 } | 132 | { 0x11, 11 }, { 0x12, 11 }, { 0x13, 11 }, { 0x01, 14 } |
| 148 | }; | 133 | }; |
| 149 | 134 | ||
| 150 | /* values in this table range from -256..255; adjust retrieved value by -256 */ | 135 | /* values in this table range from -256..255; adjust retrieved value by -256 */ |
| 151 | const uint16_t ff_svq1_inter_mean_vlc[512][2] = { | 136 | const uint16_t ff_svq1_inter_mean_vlc[512][2] = { |
| 152 | /* { code, length } */ | 137 | /* { code, length } */ |
| 153 | { 0x5A, 22 }, { 0xD4, 22 }, { 0xD5, 22 }, { 0xD6, 22 }, | 138 | { 0x5A, 22 }, { 0xD4, 22 }, { 0xD5, 22 }, { 0xD6, 22 }, |
| 154 | { 0xD7, 22 }, { 0xD8, 22 }, { 0xD9, 22 }, { 0xDA, 22 }, | 139 | { 0xD7, 22 }, { 0xD8, 22 }, { 0xD9, 22 }, { 0xDA, 22 }, |
| 155 | { 0xDB, 22 }, { 0xDC, 22 }, { 0xDD, 22 }, { 0xDE, 22 }, | 140 | { 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 | |||
| 159 | { 0xE7, 22 }, { 0xEC, 22 }, { 0xED, 22 }, { 0xEE, 22 }, | 144 | { 0xE7, 22 }, { 0xEC, 22 }, { 0xED, 22 }, { 0xEE, 22 }, |
| 160 | { 0xEF, 22 }, { 0xF0, 22 }, { 0xF1, 22 }, { 0xF2, 22 }, | 145 | { 0xEF, 22 }, { 0xF0, 22 }, { 0xF1, 22 }, { 0xF2, 22 }, |
| 161 | { 0xF3, 22 }, { 0xF4, 22 }, { 0xF5, 22 }, { 0xF6, 22 }, | 146 | { 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 }, |
| 163 | { 0xF9, 22 }, { 0xFC, 22 }, { 0xFD, 22 }, { 0xFE, 22 }, | 148 | { 0xF9, 22 }, { 0xFC, 22 }, { 0xFD, 22 }, { 0xFE, 22 }, |
| 164 | { 0x100, 22 }, { 0x5C, 22 }, { 0x60, 22 }, { 0x101, 22 }, | 149 | { 0x100,22 }, { 0x5C, 22 }, { 0x60, 22 }, { 0x101,22 }, |
| 165 | { 0x71, 22 }, { 0x104, 22 }, { 0x105, 22 }, { 0xFB, 22 }, | 150 | { 0x71, 22 }, { 0x104,22 }, { 0x105,22 }, { 0xFB, 22 }, |
| 166 | { 0xFF, 22 }, { 0x86, 21 }, { 0xFA, 22 }, { 0x7C, 22 }, | 151 | { 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 }, |
| 168 | { 0x7B, 22 }, { 0x82, 22 }, { 0xD2, 22 }, { 0xD1, 22 }, | 153 | { 0x7B, 22 }, { 0x82, 22 }, { 0xD2, 22 }, { 0xD1, 22 }, |
| 169 | { 0xD0, 22 }, { 0xCF, 22 }, { 0xCE, 22 }, { 0xCD, 22 }, | 154 | { 0xD0, 22 }, { 0xCF, 22 }, { 0xCE, 22 }, { 0xCD, 22 }, |
| 170 | { 0xCC, 22 }, { 0xC3, 22 }, { 0xCA, 22 }, { 0xC9, 22 }, | 155 | { 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 | |||
| 206 | { 0x21, 14 }, { 0x13, 13 }, { 0x14, 13 }, { 0x15, 13 }, | 191 | { 0x21, 14 }, { 0x13, 13 }, { 0x14, 13 }, { 0x15, 13 }, |
| 207 | { 0x16, 13 }, { 0x17, 13 }, { 0x18, 13 }, { 0x19, 13 }, | 192 | { 0x16, 13 }, { 0x17, 13 }, { 0x18, 13 }, { 0x19, 13 }, |
| 208 | { 0x1A, 13 }, { 0x18, 12 }, { 0x17, 12 }, { 0x15, 12 }, | 193 | { 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 }, |
| 210 | { 0x10, 11 }, { 0x12, 11 }, { 0x13, 11 }, { 0x1B, 11 }, | 195 | { 0x10, 11 }, { 0x12, 11 }, { 0x13, 11 }, { 0x1B, 11 }, |
| 211 | { 0x1A, 11 }, { 0xE, 10 }, { 0x13, 10 }, { 0xF, 10 }, | 196 | { 0x1A, 11 }, { 0x0E, 10 }, { 0x13, 10 }, { 0x0F, 10 }, |
| 212 | { 0x10, 10 }, { 0x11, 10 }, { 0x12, 10 }, { 0xD, 9 }, | 197 | { 0x10, 10 }, { 0x11, 10 }, { 0x12, 10 }, { 0x0D, 9 }, |
| 213 | { 0x14, 9 }, { 0x15, 9 }, { 0xC, 9 }, { 0x13, 9 }, | 198 | { 0x14, 9 }, { 0x15, 9 }, { 0x0C, 9 }, { 0x13, 9 }, |
| 214 | { 0xF, 8 }, { 0xE, 8 }, { 0x10, 8 }, { 0x11, 8 }, | 199 | { 0x0F, 8 }, { 0x0E, 8 }, { 0x10, 8 }, { 0x11, 8 }, |
| 215 | { 0xC, 7 }, { 0x9, 7 }, { 0xA, 7 }, { 0x8, 6 }, | 200 | { 0x0C, 7 }, { 0x09, 7 }, { 0x0A, 7 }, { 0x08, 6 }, |
| 216 | { 0x9, 6 }, { 0x9, 5 }, { 0x8, 5 }, { 0x5, 4 }, | 201 | { 0x09, 6 }, { 0x09, 5 }, { 0x08, 5 }, { 0x05, 4 }, |
| 217 | { 0x1, 1 }, { 0x3, 3 }, { 0x7, 5 }, { 0x6, 5 }, | 202 | { 0x01, 1 }, { 0x03, 3 }, { 0x07, 5 }, { 0x06, 5 }, |
| 218 | { 0xB, 6 }, { 0xA, 6 }, { 0xE, 7 }, { 0xF, 7 }, | 203 | { 0x0B, 6 }, { 0x0A, 6 }, { 0x0E, 7 }, { 0x0F, 7 }, |
| 219 | { 0xB, 7 }, { 0xD, 7 }, { 0xB, 8 }, { 0xD, 8 }, | 204 | { 0x0B, 7 }, { 0x0D, 7 }, { 0x0B, 8 }, { 0x0D, 8 }, |
| 220 | { 0xC, 8 }, { 0xF, 9 }, { 0x10, 9 }, { 0x11, 9 }, | 205 | { 0x0C, 8 }, { 0x0F, 9 }, { 0x10, 9 }, { 0x11, 9 }, |
| 221 | { 0xE, 9 }, { 0x12, 9 }, { 0x17, 10 }, { 0x14, 10 }, | 206 | { 0x0E, 9 }, { 0x12, 9 }, { 0x17, 10 }, { 0x14, 10 }, |
| 222 | { 0x16, 10 }, { 0x15, 10 }, { 0x19, 11 }, { 0x18, 11 }, | 207 | { 0x16, 10 }, { 0x15, 10 }, { 0x19, 11 }, { 0x18, 11 }, |
| 223 | { 0x17, 11 }, { 0x16, 11 }, { 0x15, 11 }, { 0x14, 11 }, | 208 | { 0x17, 11 }, { 0x16, 11 }, { 0x15, 11 }, { 0x14, 11 }, |
| 224 | { 0x11, 11 }, { 0x19, 12 }, { 0x1A, 12 }, { 0x16, 12 }, | 209 | { 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 | |||
| 274 | { 0x1B, 22 }, { 0x1A, 22 }, { 0x19, 22 }, { 0x18, 22 }, | 259 | { 0x1B, 22 }, { 0x1A, 22 }, { 0x19, 22 }, { 0x18, 22 }, |
| 275 | { 0x17, 22 }, { 0x16, 22 }, { 0x15, 22 }, { 0x14, 22 }, | 260 | { 0x17, 22 }, { 0x16, 22 }, { 0x15, 22 }, { 0x14, 22 }, |
| 276 | { 0x13, 22 }, { 0x12, 22 }, { 0x11, 22 }, { 0x10, 22 }, | 261 | { 0x13, 22 }, { 0x12, 22 }, { 0x11, 22 }, { 0x10, 22 }, |
| 277 | { 0xF, 22 }, { 0xE, 22 }, { 0xD, 22 }, { 0xC, 22 }, | 262 | { 0x0F, 22 }, { 0x0E, 22 }, { 0x0D, 22 }, { 0x0C, 22 }, |
| 278 | { 0xB, 22 }, { 0xA, 22 }, { 0x9, 22 }, { 0x8, 22 }, | 263 | { 0x0B, 22 }, { 0x0A, 22 }, { 0x09, 22 }, { 0x08, 22 }, |
| 279 | { 0x7, 22 }, { 0x6, 22 }, { 0x5, 22 }, { 0x4, 22 }, | 264 | { 0x07, 22 }, { 0x06, 22 }, { 0x05, 22 }, { 0x04, 22 }, |
| 280 | { 0x3, 22 }, { 0x2, 22 }, { 0x1, 22 }, { 0x0, 22 } | 265 | { 0x03, 22 }, { 0x02, 22 }, { 0x01, 22 }, { 0x00, 22 } |
| 281 | }; | 266 | }; |
| 282 | 267 | ||
| 283 | #endif /* AVCODEC_SVQ1_VLC_H */ | 268 | #endif /* AVCODEC_SVQ1_VLC_H */ |
| @@ -32,12 +32,10 @@ · 31 unmodified lines | |||
| 32 | * http://www.pcisys.net/~melanson/codecs/ | 32 | * http://www.pcisys.net/~melanson/codecs/ |
| 33 | */ | 33 | */ |
| 34 | 34 | ||
| 35 | |||
| 36 | #include "avcodec.h" | 35 | #include "avcodec.h" |
| 37 | #include "dsputil.h" | 36 | #include "dsputil.h" |
| 38 | #include "mpegvideo.h" | 37 | #include "mpegvideo.h" |
| 39 | #include "mathops.h" | 38 | #include "mathops.h" |
| 40 | |||
| 41 | #include "svq1.h" | 39 | #include "svq1.h" |
| 42 | 40 | ||
| 43 | #undef NDEBUG | 41 | #undef NDEBUG |
| @@ -54,655 +52,670 @@ static VLC svq1_inter_mean; · 10 unmodified lines | |||
| 54 | 52 | ||
| 55 | /* motion vector (prediction) */ | 53 | /* motion vector (prediction) */ |
| 56 | typedef struct svq1_pmv_s { | 54 | typedef struct svq1_pmv_s { |
| 57 | int x; | 55 | int x; |
| 58 | int y; | 56 | int y; |
| 59 | } svq1_pmv; | 57 | } svq1_pmv; |
| 60 | 58 | ||
| 61 | static const uint8_t string_table[256] = { | 59 | static const uint8_t string_table[256] = { |
| 62 | 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, | 60 | 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, |
| 63 | 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, | 61 | 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, |
| 64 | 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, | 62 | 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, |
| 65 | 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, | 63 | 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, |
| 66 | 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, | 64 | 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, |
| 67 | 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, | 65 | 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, |
| 68 | 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, | 66 | 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, |
| 69 | 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, | 67 | 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, |
| 70 | 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, | 68 | 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, |
| 71 | 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, | 69 | 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, |
| 72 | 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, | 70 | 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, |
| 73 | 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, | 71 | 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, |
| 74 | 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, | 72 | 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, |
| 75 | 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, | 73 | 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, |
| 76 | 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, | 74 | 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, |
| 77 | 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, | 75 | 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, |
| 78 | 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, | 76 | 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, |
| 79 | 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, | 77 | 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, |
| 80 | 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, | 78 | 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, |
| 81 | 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, | 79 | 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, |
| 82 | 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, | 80 | 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, |
| 83 | 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, | 81 | 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, |
| 84 | 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, | 82 | 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, |
| 85 | 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, | 83 | 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, |
| 86 | 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, | 84 | 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, |
| 87 | 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, | 85 | 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, |
| 88 | 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, | 86 | 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, |
| 89 | 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, | 87 | 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, |
| 90 | 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, | 88 | 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, |
| 91 | 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, | 89 | 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, |
| 92 | 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, | 90 | 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, |
| 93 | 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9 | 91 | 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9 |
| 94 | }; | 92 | }; |
| 95 | 93 | ||
| 96 | #define SVQ1_PROCESS_VECTOR()\ | 94 | #define SVQ1_PROCESS_VECTOR() \ |
| 97 | for (; level > 0; i++) {\ | 95 | for (; level > 0; i++) { \ |
| 98 | /* process next depth */\ | 96 | /* process next depth */ \ |
| 99 | if (i == m) {\ | 97 | if (i == m) { \ |
| 100 | m = n;\ | 98 | m = n; \ |
| 101 | if (--level == 0)\ | 99 | if (--level == 0) \ |
| 102 | break;\ | 100 | break; \ |
| 103 | }\ | 101 | } \ |
| 104 | /* divide block if next bit set */\ | 102 | /* divide block if next bit set */ \ |
| 105 | if (get_bits1 (bitbuf) == 0)\ | 103 | if (get_bits1(bitbuf) == 0) \ |
| 106 | break;\ | 104 | break; \ |
| 107 | /* add child nodes */\ | 105 | /* add child nodes */ \ |
| 108 | list[n++] = list[i];\ | 106 | list[n++] = list[i]; \ |
| 109 | list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level >> 1) + 1));\ | 107 | list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level >> 1) + 1));\ |
| 110 | } | 108 | } |
| 111 | 109 | ||
| 112 | #define SVQ1_ADD_CODEBOOK()\ | 110 | #define SVQ1_ADD_CODEBOOK() \ |
| 113 | /* add codebook entries to vector */\ | 111 | /* add codebook entries to vector */ \ |
| 114 | for (j=0; j < stages; j++) {\ | 112 | for (j = 0; j < stages; j++) { \ |
| 115 | n3 = codebook[entries[j]] ^ 0x80808080;\ | 113 | n3 = codebook[entries[j]] ^ 0x80808080; \ |
| 116 | n1 += ((n3 & 0xFF00FF00) >> 8);\ | 114 | n1 += (n3 & 0xFF00FF00) >> 8; \ |
| 117 | n2 += (n3 & 0x00FF00FF);\ | 115 | n2 += n3 & 0x00FF00FF; \ |
| 118 | }\ | 116 | } \ |
| 119 | \ | 117 | \ |
| 120 | /* clip to [0..255] */\ | 118 | /* clip to [0..255] */ \ |
| 121 | if (n1 & 0xFF00FF00) {\ | 119 | if (n1 & 0xFF00FF00) { \ |
| 122 | n3 = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ | 120 | n3 = (n1 >> 15 & 0x00010001 | 0x01000100) - 0x00010001; \ |
| 123 | n1 += 0x7F007F00;\ | 121 | n1 += 0x7F007F00; \ |
| 124 | n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ | 122 | n1 |= (~n1 >> 15 & 0x00010001 | 0x01000100) - 0x00010001; \ |
| 125 | n1 &= (n3 & 0x00FF00FF);\ | 123 | n1 &= n3 & 0x00FF00FF; \ |
| 126 | }\ | 124 | } \ |
| 127 | \ | 125 | \ |
| 128 | if (n2 & 0xFF00FF00) {\ | 126 | if (n2 & 0xFF00FF00) { \ |
| 129 | n3 = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ | 127 | n3 = (n2 >> 15 & 0x00010001 | 0x01000100) - 0x00010001; \ |
| 130 | n2 += 0x7F007F00;\ | 128 | n2 += 0x7F007F00; \ |
| 131 | n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ | 129 | n2 |= (~n2 >> 15 & 0x00010001 | 0x01000100) - 0x00010001; \ |
| 132 | n2 &= (n3 & 0x00FF00FF);\ | 130 | 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 */ | ||
| 203 | } | 131 | } |
| 204 | 132 | ||
| 205 | if ((stages > 0) && (level >= 4)) { | 133 | #define SVQ1_DO_CODEBOOK_INTRA() \ |
| 206 | av_dlog(NULL, | 134 | for (y = 0; y < height; y++) { \ |
| 207 | "Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i\n", | 135 | for (x = 0; x < width / 4; x++, codebook++) { \ |
| 208 | stages, level); | 136 | n1 = n4; \ |
| 209 | return -1; /* invalid vector */ | 137 | n2 = n4; \ |
| 138 | SVQ1_ADD_CODEBOOK() \ | ||
| 139 | /* store result */ \ | ||
| 140 | dst[x] = n1 << 8 | n2; \ | ||
| 141 | } \ | ||
| 142 | dst += pitch / 4; \ | ||
| 210 | } | 143 | } |
| 211 | 144 | ||
| 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 | } | ||
| 213 | 158 | ||
| 214 | if (stages == 0) { | 159 | #define SVQ1_CALC_CODEBOOK_ENTRIES(cbook) \ |
| 215 | for (y=0; y < height; y++) { | 160 | codebook = (const uint32_t *)cbook[level]; \ |
| 216 | memset (&dst[y*(pitch / 4)], mean, width); | 161 | if (stages > 0) \ |
| 217 | } | 162 | bit_cache = get_bits(bitbuf, 4 * stages); \ |
| 218 | } else { | 163 | /* calculate codebook entries for this vector */ \ |
| 219 | SVQ1_CALC_CODEBOOK_ENTRIES(ff_svq1_intra_codebooks); | 164 | for (j = 0; j < stages; j++) { \ |
| 220 | SVQ1_DO_CODEBOOK_INTRA() | 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 | } | ||
| 221 | } | 221 | } |
| 222 | } | ||
| 223 | 222 | ||
| 224 | return 0; | 223 | return 0; |
| 225 | } | 224 | } |
| 226 | 225 | ||
| 227 | static int svq1_decode_block_non_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) { | 226 | static int svq1_decode_block_non_intra(GetBitContext *bitbuf, uint8_t *pixels, |
| 228 | uint32_t bit_cache; | 227 | int pitch) |
| 229 | uint8_t *list[63]; | 228 | { |
| 230 | uint32_t *dst; | 229 | uint32_t bit_cache; |
| 231 | const uint32_t *codebook; | 230 | uint8_t *list[63]; |
| 232 | int entries[6]; | 231 | uint32_t *dst; |
| 233 | int i, j, m, n; | 232 | const uint32_t *codebook; |
| 234 | int mean, stages; | 233 | int entries[6]; |
| 235 | int x, y, width, height, level; | 234 | int i, j, m, n; |
| 236 | uint32_t n1, n2, n3, n4; | 235 | int mean, stages; |
| 237 | 236 | int x, y, width, height, level; | |
| 238 | /* initialize list for breadth first processing of vectors */ | 237 | uint32_t n1, n2, n3, n4; |
| 239 | list[0] = pixels; | 238 | |
| 240 | 239 | /* initialize list for breadth first processing of vectors */ | |
| 241 | /* recursively process vector */ | 240 | list[0] = pixels; |
| 242 | for (i=0, m=1, n=1, level=5; i < n; i++) { | 241 | |
| 243 | SVQ1_PROCESS_VECTOR(); | 242 | /* recursively process vector */ |
| 244 | 243 | for (i = 0, m = 1, n = 1, level = 5; i < n; i++) { | |
| 245 | /* destination address and vector size */ | 244 | SVQ1_PROCESS_VECTOR(); |
| 246 | dst = (uint32_t *) list[i]; | 245 | |
| 247 | width = 1 << ((4 + level) /2); | 246 | /* destination address and vector size */ |
| 248 | height = 1 << ((3 + level) /2); | 247 | dst = (uint32_t *)list[i]; |
| 249 | 248 | width = 1 << ((4 + level) / 2); | |
| 250 | /* get number of stages (-1 skips vector, 0 for mean only) */ | 249 | height = 1 << ((3 + level) / 2); |
| 251 | stages = get_vlc2(bitbuf, svq1_inter_multistage[level].table, 3, 2) - 1; | 250 | |
| 252 | 251 | /* get number of stages (-1 skips vector, 0 for mean only) */ | |
| 253 | if (stages == -1) continue; /* skip vector */ | 252 | stages = get_vlc2(bitbuf, svq1_inter_multistage[level].table, 3, 2) - 1; |
| 254 | 253 | ||
| 255 | if ((stages > 0) && (level >= 4)) { | 254 | if (stages == -1) |
| 256 | av_dlog(NULL, | 255 | continue; /* skip vector */ |
| 257 | "Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i\n", | 256 | |
| 258 | stages, level); | 257 | if ((stages > 0) && (level >= 4)) { |
| 259 | return -1; /* invalid vector */ | 258 | av_dlog(NULL, |
| 260 | } | 259 | "Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i\n", |
| 260 | stages, level); | ||
| 261 | return -1; /* invalid vector */ | ||
| 262 | } | ||
| 261 | 263 | ||
| 262 | mean = get_vlc2(bitbuf, svq1_inter_mean.table, 9, 3) - 256; | 264 | mean = get_vlc2(bitbuf, svq1_inter_mean.table, 9, 3) - 256; |
| 263 | 265 | ||
| 264 | SVQ1_CALC_CODEBOOK_ENTRIES(ff_svq1_inter_codebooks); | 266 | SVQ1_CALC_CODEBOOK_ENTRIES(ff_svq1_inter_codebooks); |
| 265 | SVQ1_DO_CODEBOOK_NONINTRA() | 267 | SVQ1_DO_CODEBOOK_NONINTRA() |
| 266 | } | 268 | } |
| 267 | return 0; | 269 | return 0; |
| 268 | } | 270 | } |
| 269 | 271 | ||
| 270 | static int svq1_decode_motion_vector (GetBitContext *bitbuf, svq1_pmv *mv, svq1_pmv **pmv) { | 272 | static int svq1_decode_motion_vector(GetBitContext *bitbuf, svq1_pmv *mv, |
| 271 | int diff; | 273 | svq1_pmv **pmv) |
| 272 | int i; | 274 | { |
| 275 | int diff; | ||
| 276 | int i; | ||
| 273 | 277 | ||
| 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 | } | ||
| 275 | 287 | ||
| 276 | /* get motion code */ | 288 | /* add median of motion vector predictors and clip result */ |
| 277 | diff = get_vlc2(bitbuf, svq1_motion_component.table, 7, 2); | 289 | if (i == 1) |
| 278 | if(diff<0) | 290 | mv->y = sign_extend(diff + mid_pred(pmv[0]->y, pmv[1]->y, pmv[2]->y), 6); |
| 279 | return -1; | 291 | else |
| 280 | else if(diff){ | 292 | mv->x = sign_extend(diff + mid_pred(pmv[0]->x, pmv[1]->x, pmv[2]->x), 6); |
| 281 | if(get_bits1(bitbuf)) diff= -diff; | ||
| 282 | } | 293 | } |
| 283 | 294 | ||
| 284 | /* add median of motion vector predictors and clip result */ | 295 | return 0; |
| 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; | ||
| 292 | } | 296 | } |
| 293 | 297 | ||
| 294 | static void svq1_skip_block (uint8_t *current, uint8_t *previous, int pitch, int x, int y) { | 298 | static void svq1_skip_block(uint8_t *current, uint8_t *previous, |
| 295 | uint8_t *src; | 299 | int pitch, int x, int y) |
| 296 | uint8_t *dst; | 300 | { |
| 297 | int i; | 301 | uint8_t *src; |
| 302 | uint8_t *dst; | ||
| 303 | int i; | ||
| 298 | 304 | ||
| 299 | src = &previous[x + y*pitch]; | 305 | src = &previous[x + y * pitch]; |
| 300 | dst = current; | 306 | dst = current; |
| 301 | 307 | ||
| 302 | for (i=0; i < 16; i++) { | 308 | for (i = 0; i < 16; i++) { |
| 303 | memcpy (dst, src, 16); | 309 | memcpy(dst, src, 16); |
| 304 | src += pitch; | 310 | src += pitch; |
| 305 | dst += pitch; | 311 | dst += pitch; |
| 306 | } | 312 | } |
| 307 | } | 313 | } |
| 308 | 314 | ||
| 309 | static int svq1_motion_inter_block (MpegEncContext *s, GetBitContext *bitbuf, | 315 | static int svq1_motion_inter_block(MpegEncContext *s, GetBitContext *bitbuf, |
| 310 | uint8_t *current, uint8_t *previous, int pitch, | 316 | uint8_t *current, uint8_t *previous, |
| 311 | svq1_pmv *motion, int x, int y) { | 317 | int pitch, svq1_pmv *motion, int x, int y) |
| 312 | uint8_t *src; | 318 | { |
| 313 | uint8_t *dst; | 319 | uint8_t *src; |
| 314 | svq1_pmv mv; | 320 | uint8_t *dst; |
| 315 | svq1_pmv *pmv[3]; | 321 | svq1_pmv mv; |
| 316 | int result; | 322 | svq1_pmv *pmv[3]; |
| 317 | 323 | int result; | |
| 318 | /* predict and decode motion vector */ | 324 | |
| 319 | pmv[0] = &motion[0]; | 325 | /* predict and decode motion vector */ |
| 320 | if (y == 0) { | 326 | pmv[0] = &motion[0]; |
| 321 | pmv[1] = | 327 | if (y == 0) { |
| 322 | pmv[2] = pmv[0]; | 328 | pmv[1] = |
| 323 | } | 329 | pmv[2] = pmv[0]; |
| 324 | else { | 330 | } else { |
| 325 | pmv[1] = &motion[(x / 8) + 2]; | 331 | pmv[1] = &motion[x / 8 + 2]; |
| 326 | pmv[2] = &motion[(x / 8) + 4]; | 332 | pmv[2] = &motion[x / 8 + 4]; |
| 327 | } | 333 | } |
| 328 | |||
| 329 | result = svq1_decode_motion_vector (bitbuf, &mv, pmv); | ||
| 330 | |||
| 331 | if (result != 0) | ||
| 332 | return result; | ||
| 333 | 334 | ||
| 334 | motion[0].x = | 335 | result = svq1_decode_motion_vector(bitbuf, &mv, pmv); |
| 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; | ||
| 340 | 336 | ||
| 341 | if(y + (mv.y >> 1)<0) | 337 | if (result != 0) |
| 342 | mv.y= 0; | 338 | return result; |
| 343 | if(x + (mv.x >> 1)<0) | 339 | |
| 344 | mv.x= 0; | 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; | ||
| 345 | 351 | ||
| 346 | src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch]; | 352 | src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1)) * pitch]; |
| 347 | dst = current; | 353 | dst = current; |
| 348 | 354 | ||
| 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); |
| 350 | 356 | ||
| 351 | return 0; | 357 | return 0; |
| 352 | } | 358 | } |
| 353 | 359 | ||
| 354 | static int svq1_motion_inter_4v_block (MpegEncContext *s, GetBitContext *bitbuf, | 360 | static int svq1_motion_inter_4v_block(MpegEncContext *s, GetBitContext *bitbuf, |
| 355 | uint8_t *current, uint8_t *previous, int pitch, | 361 | uint8_t *current, uint8_t *previous, |
| 356 | svq1_pmv *motion,int x, int y) { | 362 | int pitch, svq1_pmv *motion, int x, int y) |
| 357 | uint8_t *src; | 363 | { |
| 358 | uint8_t *dst; | 364 | uint8_t *src; |
| 359 | svq1_pmv mv; | 365 | uint8_t *dst; |
| 360 | svq1_pmv *pmv[4]; | 366 | svq1_pmv mv; |
| 361 | int i, result; | 367 | svq1_pmv *pmv[4]; |
| 362 | 368 | int i, result; | |
| 363 | /* predict and decode motion vector (0) */ | 369 | |
| 364 | pmv[0] = &motion[0]; | 370 | /* predict and decode motion vector (0) */ |
| 365 | if (y == 0) { | 371 | pmv[0] = &motion[0]; |
| 366 | pmv[1] = | 372 | if (y == 0) { |
| 367 | pmv[2] = pmv[0]; | 373 | pmv[1] = |
| 368 | } | 374 | pmv[2] = pmv[0]; |
| 369 | else { | 375 | } else { |
| 370 | pmv[1] = &motion[(x / 8) + 2]; | 376 | pmv[1] = &motion[(x / 8) + 2]; |
| 371 | pmv[2] = &motion[(x / 8) + 4]; | 377 | pmv[2] = &motion[(x / 8) + 4]; |
| 372 | } | 378 | } |
| 373 | |||
| 374 | result = svq1_decode_motion_vector (bitbuf, &mv, pmv); | ||
| 375 | |||
| 376 | if (result != 0) | ||
| 377 | return result; | ||
| 378 | 379 | ||
| 379 | /* predict and decode motion vector (1) */ | 380 | result = svq1_decode_motion_vector(bitbuf, &mv, pmv); |
| 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; | ||
| 392 | 381 | ||
| 393 | /* predict and decode motion vector (2) */ | 382 | if (result != 0) |
| 394 | pmv[1] = &motion[0]; | 383 | return result; |
| 395 | pmv[2] = &motion[(x / 8) + 1]; | ||
| 396 | 384 | ||
| 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); | ||
| 398 | 394 | ||
| 399 | if (result != 0) | 395 | if (result != 0) |
| 400 | return result; | 396 | return result; |
| 401 | 397 | ||
| 402 | /* predict and decode motion vector (3) */ | 398 | /* predict and decode motion vector (2) */ |
| 403 | pmv[2] = &motion[(x / 8) + 2]; | 399 | pmv[1] = &motion[0]; |
| 404 | pmv[3] = &motion[(x / 8) + 3]; | 400 | pmv[2] = &motion[(x / 8) + 1]; |
| 405 | 401 | ||
| 406 | result = svq1_decode_motion_vector (bitbuf, pmv[3], pmv); | 402 | result = svq1_decode_motion_vector(bitbuf, &motion[(x / 8) + 2], pmv); |
| 407 | 403 | ||
| 408 | if (result != 0) | 404 | if (result != 0) |
| 409 | return result; | 405 | return result; |
| 410 | 406 | ||
| 411 | /* form predictions */ | 407 | /* predict and decode motion vector (3) */ |
| 412 | for (i=0; i < 4; i++) { | 408 | pmv[2] = &motion[(x / 8) + 2]; |
| 413 | int mvx= pmv[i]->x + (i&1)*16; | 409 | pmv[3] = &motion[(x / 8) + 3]; |
| 414 | int mvy= pmv[i]->y + (i>>1)*16; | ||
| 415 | 410 | ||
| 416 | ///XXX /FIXME clipping or padding? | 411 | result = svq1_decode_motion_vector(bitbuf, pmv[3], pmv); |
| 417 | if(y + (mvy >> 1)<0) | ||
| 418 | mvy= 0; | ||
| 419 | if(x + (mvx >> 1)<0) | ||
| 420 | mvx= 0; | ||
| 421 | 412 | ||
| 422 | src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1))*pitch]; | 413 | if (result != 0) |
| 423 | dst = current; | 414 | return result; |
| 424 | 415 | ||
| 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; | ||
| 426 | 420 | ||
| 427 | /* select next block */ | 421 | // FIXME: clipping or padding? |
| 428 | if (i & 1) { | 422 | if (y + (mvy >> 1) < 0) |
| 429 | current += 8*(pitch - 1); | 423 | mvy = 0; |
| 430 | } else { | 424 | if (x + (mvx >> 1) < 0) |
| 431 | current += 8; | 425 | mvx = 0; |
| 432 | } | ||
| 433 | } | ||
| 434 | 426 | ||
| 435 | return 0; | 427 | src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1)) * pitch]; |
| 436 | } | 428 | dst = current; |
| 437 | 429 | ||
| 438 | static int svq1_decode_delta_block (MpegEncContext *s, GetBitContext *bitbuf, | 430 | s->dsp.put_pixels_tab[1][((mvy & 1) << 1) | (mvx & 1)](dst, src, pitch, 8); |
| 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); | ||
| 464 | 431 | ||
| 465 | if (result != 0) | 432 | /* select next block */ |
| 466 | { | 433 | if (i & 1) |
| 467 | av_dlog(s->avctx, "Error in svq1_motion_inter_block %i\n", result); | 434 | current += 8 * (pitch - 1); |
| 468 | break; | 435 | else |
| 436 | current += 8; | ||
| 469 | } | 437 | } |
| 470 | result = svq1_decode_block_non_intra (bitbuf, current, pitch); | ||
| 471 | break; | ||
| 472 | 438 | ||
| 473 | case SVQ1_BLOCK_INTER_4V: | 439 | return 0; |
| 474 | result = svq1_motion_inter_4v_block (s, bitbuf, current, previous, pitch, motion, x, y); | 440 | } |
| 475 | 441 | ||
| 476 | if (result != 0) | 442 | static int svq1_decode_delta_block(MpegEncContext *s, GetBitContext *bitbuf, |
| 477 | { | 443 | uint8_t *current, uint8_t *previous, |
| 478 | av_dlog(s->avctx, "Error in svq1_motion_inter_4v_block %i\n", result); | 444 | int pitch, svq1_pmv *motion, int x, int y) |
| 479 | break; | 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; | ||
| 480 | } | 460 | } |
| 481 | result = svq1_decode_block_non_intra (bitbuf, current, pitch); | ||
| 482 | break; | ||
| 483 | 461 | ||
| 484 | case SVQ1_BLOCK_INTRA: | 462 | switch (block_type) { |
| 485 | result = svq1_decode_block_intra (bitbuf, current, pitch); | 463 | case SVQ1_BLOCK_SKIP: |
| 486 | break; | 464 | svq1_skip_block(current, previous, pitch, x, y); |
| 487 | } | 465 | break; |
| 488 | 466 | ||
| 489 | return result; | 467 | case SVQ1_BLOCK_INTER: |
| 490 | } | 468 | result = svq1_motion_inter_block(s, bitbuf, current, previous, |
| 469 | pitch, motion, x, y); | ||
| 491 | 470 | ||
| 492 | static void svq1_parse_string (GetBitContext *bitbuf, uint8_t *out) { | 471 | if (result != 0) { |
| 493 | uint8_t seed; | 472 | av_dlog(s->avctx, "Error in svq1_motion_inter_block %i\n", result); |
| 494 | int i; | 473 | break; |
| 474 | } | ||
| 475 | result = svq1_decode_block_non_intra(bitbuf, current, pitch); | ||
| 476 | break; | ||
| 495 | 477 | ||
| 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); | ||
| 497 | 481 | ||
| 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; | ||
| 499 | 489 | ||
| 500 | for (i=1; i <= out[0]; i++) { | 490 | case SVQ1_BLOCK_INTRA: |
| 501 | out[i] = get_bits (bitbuf, 8) ^ seed; | 491 | result = svq1_decode_block_intra(bitbuf, current, pitch); |
| 502 | seed = string_table[out[i] ^ seed]; | 492 | break; |
| 503 | } | 493 | } |
| 494 | |||
| 495 | return result; | ||
| 504 | } | 496 | } |
| 505 | 497 | ||
| 506 | static int svq1_decode_frame_header (GetBitContext *bitbuf,MpegEncContext *s) { | 498 | static void svq1_parse_string(GetBitContext *bitbuf, uint8_t *out) |
| 507 | int frame_size_code; | 499 | { |
| 500 | uint8_t seed; | ||
| 501 | int i; | ||
| 502 | |||
| 503 | out[0] = get_bits(bitbuf, 8); | ||
| 504 | seed = string_table[out[0]]; | ||
| 508 | 505 | ||
| 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 | } | ||
| 510 | 511 | ||
| 511 | /* frame type */ | 512 | static int svq1_decode_frame_header(GetBitContext *bitbuf, MpegEncContext *s) |
| 512 | s->pict_type= get_bits (bitbuf, 2)+1; | 513 | { |
| 513 | if(s->pict_type==4) | 514 | int frame_size_code; |
| 514 | return -1; | ||
| 515 | 515 | ||
| 516 | if (s->pict_type == AV_PICTURE_TYPE_I) { | 516 | skip_bits(bitbuf, 8); /* temporal_reference */ |
| 517 | 517 | ||
| 518 | /* unknown fields */ | 518 | /* frame type */ |
| 519 | if (s->f_code == 0x50 || s->f_code == 0x60) { | 519 | s->pict_type = get_bits(bitbuf, 2) + 1; |
| 520 | int csum = get_bits (bitbuf, 16); | 520 | if (s->pict_type == 4) |
| 521 | return -1; | ||
| 521 | 522 | ||
| 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); | ||
| 523 | 527 | ||
| 524 | av_dlog(s->avctx, "%s checksum (%02x) for packet data\n", | 528 | csum = ff_svq1_packet_checksum(bitbuf->buffer, |
| 525 | (csum == 0) ? "correct" : "incorrect", csum); | 529 | bitbuf->size_in_bits >> 3, |
| 526 | } | 530 | csum); |
| 527 | 531 | ||
| 528 | if ((s->f_code ^ 0x10) >= 0x50) { | 532 | av_dlog(s->avctx, "%s checksum (%02x) for packet data\n", |
| 529 | uint8_t msg[256]; | 533 | (csum == 0) ? "correct" : "incorrect", csum); |
| 534 | } | ||
| 530 | 535 | ||
| 531 | svq1_parse_string (bitbuf, msg); | 536 | if ((s->f_code ^ 0x10) >= 0x50) { |
| 537 | uint8_t msg[256]; | ||
| 532 | 538 | ||
| 533 | av_log(s->avctx, AV_LOG_INFO, "embedded message: \"%s\"\n", (char *) msg); | 539 | svq1_parse_string(bitbuf, msg); |
| 534 | } | ||
| 535 | 540 | ||
| 536 | skip_bits (bitbuf, 2); | 541 | av_log(s->avctx, AV_LOG_ERROR, |
| 537 | skip_bits (bitbuf, 2); | 542 | "embedded message: \"%s\"\n", (char *)msg); |
| 538 | skip_bits1 (bitbuf); | 543 | } |
| 539 | 544 | ||
| 540 | /* load frame size */ | 545 | skip_bits(bitbuf, 2); |
| 541 | frame_size_code = get_bits (bitbuf, 3); | 546 | skip_bits(bitbuf, 2); |
| 547 | skip_bits1(bitbuf); | ||
| 542 | 548 | ||
| 543 | if (frame_size_code == 7) { | 549 | /* load frame size */ |
| 544 | /* load width, height (12 bits each) */ | 550 | frame_size_code = get_bits(bitbuf, 3); |
| 545 | s->width = get_bits (bitbuf, 12); | ||
| 546 | s->height = get_bits (bitbuf, 12); | ||
| 547 | 551 | ||
| 548 | if (!s->width || !s->height) | 552 | if (frame_size_code == 7) { |
| 549 | return -1; | 553 | /* load width, height (12 bits each) */ |
| 550 | } else { | 554 | s->width = get_bits(bitbuf, 12); |
| 551 | /* get width, height from table */ | 555 | s->height = get_bits(bitbuf, 12); |
| 552 | s->width = ff_svq1_frame_size_table[frame_size_code].width; | 556 | |
| 553 | s->height = ff_svq1_frame_size_table[frame_size_code].height; | 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 | } | ||
| 554 | } | 564 | } |
| 555 | } | ||
| 556 | 565 | ||
| 557 | /* unknown fields */ | 566 | /* unknown fields */ |
| 558 | if (get_bits1 (bitbuf) == 1) { | 567 | if (get_bits1(bitbuf) == 1) { |
| 559 | skip_bits1 (bitbuf); /* use packet checksum if (1) */ | 568 | skip_bits1(bitbuf); /* use packet checksum if (1) */ |
| 560 | skip_bits1 (bitbuf); /* component checksums after image data if (1) */ | 569 | skip_bits1(bitbuf); /* component checksums after image data if (1) */ |
| 561 | 570 | ||
| 562 | if (get_bits (bitbuf, 2) != 0) | 571 | if (get_bits(bitbuf, 2) != 0) |
| 563 | return -1; | 572 | return -1; |
| 564 | } | 573 | } |
| 565 | 574 | ||
| 566 | if (get_bits1 (bitbuf) == 1) { | 575 | if (get_bits1(bitbuf) == 1) { |
| 567 | skip_bits1 (bitbuf); | 576 | skip_bits1(bitbuf); |
| 568 | skip_bits (bitbuf, 4); | 577 | skip_bits(bitbuf, 4); |
| 569 | skip_bits1 (bitbuf); | 578 | skip_bits1(bitbuf); |
| 570 | skip_bits (bitbuf, 2); | 579 | skip_bits(bitbuf, 2); |
| 571 | 580 | ||
| 572 | while (get_bits1 (bitbuf) == 1) { | 581 | while (get_bits1(bitbuf) == 1) |
| 573 | skip_bits (bitbuf, 8); | 582 | skip_bits(bitbuf, 8); |
| 574 | } | 583 | } |
| 575 | } | ||
| 576 | 584 | ||
| 577 | return 0; | 585 | return 0; |
| 578 | } | 586 | } |
| 579 | 587 | ||
| 580 | static int svq1_decode_frame(AVCodecContext *avctx, | 588 | static int svq1_decode_frame(AVCodecContext *avctx, void *data, |
| 581 | void *data, int *data_size, | 589 | int *data_size, AVPacket *avpkt) |
| 582 | AVPacket *avpkt) | ||
| 583 | { | 590 | { |
| 584 | const uint8_t *buf = avpkt->data; | 591 | const uint8_t *buf = avpkt->data; |
| 585 | int buf_size = avpkt->size; | 592 | int buf_size = avpkt->size; |
| 586 | MpegEncContext *s=avctx->priv_data; | 593 | MpegEncContext *s = avctx->priv_data; |
| 587 | uint8_t *current, *previous; | 594 | uint8_t *current, *previous; |
| 588 | int result, i, x, y, width, height; | 595 | int result, i, x, y, width, height; |
| 589 | AVFrame *pict = data; | 596 | AVFrame *pict = data; |
| 590 | svq1_pmv *pmv; | 597 | svq1_pmv *pmv; |
| 591 | 598 | ||
| 592 | /* initialize bit buffer */ | 599 | /* initialize bit buffer */ |
| 593 | init_get_bits(&s->gb,buf,buf_size*8); | 600 | init_get_bits(&s->gb, buf, buf_size * 8); |
| 594 | 601 | ||
| 595 | /* decode frame header */ | 602 | /* decode frame header */ |
| 596 | s->f_code = get_bits (&s->gb, 22); | 603 | s->f_code = get_bits(&s->gb, 22); |
| 597 | 604 | ||
| 598 | if ((s->f_code & ~0x70) || !(s->f_code & 0x60)) | 605 | if ((s->f_code & ~0x70) || !(s->f_code & 0x60)) |
| 599 | return -1; | 606 | return -1; |
| 600 | 607 | ||
| 601 | /* swap some header bytes (why?) */ | 608 | /* swap some header bytes (why?) */ |
| 602 | if (s->f_code != 0x20) { | 609 | if (s->f_code != 0x20) { |
| 603 | uint32_t *src = (uint32_t *) (buf + 4); | 610 | uint32_t *src = (uint32_t *)(buf + 4); |
| 604 | 611 | ||
| 605 | if (buf_size < 36) | 612 | if (buf_size < 36) |
| 606 | return AVERROR_INVALIDDATA; | 613 | return AVERROR_INVALIDDATA; |
| 607 | 614 | ||
| 608 | for (i=0; i < 4; i++) { | 615 | for (i = 0; i < 4; i++) |
| 609 | src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i]; | 616 | src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i]; |
| 610 | } | 617 | } |
| 611 | } | ||
| 612 | 618 | ||
| 613 | result = svq1_decode_frame_header (&s->gb, s); | 619 | result = svq1_decode_frame_header(&s->gb, s); |
| 614 | 620 | ||
| 615 | if (result != 0) | 621 | if (result != 0) { |
| 616 | { | 622 | av_dlog(s->avctx, "Error in svq1_decode_frame_header %i\n", result); |
| 617 | av_dlog(s->avctx, "Error in svq1_decode_frame_header %i\n",result); | 623 | return 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; | ||
| 650 | } | 624 | } |
| 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; | ||
| 651 | 642 | ||
| 652 | current = s->current_picture.f.data[i]; | 643 | pmv = av_malloc((FFALIGN(s->width, 16) / 8 + 3) * sizeof(*pmv)); |
| 653 | 644 | if (!pmv) | |
| 654 | if(s->pict_type==AV_PICTURE_TYPE_B){ | 645 | return -1; |
| 655 | previous = s->next_picture.f.data[i]; | ||
| 656 | }else{ | ||
| 657 | previous = s->last_picture.f.data[i]; | ||
| 658 | } | ||
| 659 | 646 | ||
| 660 | if (s->pict_type == AV_PICTURE_TYPE_I) { | 647 | /* decode y, u and v components */ |
| 661 | /* keyframe */ | 648 | for (i = 0; i < 3; i++) { |
| 662 | for (y=0; y < height; y+=16) { | 649 | int linesize; |
| 663 | for (x=0; x < width; x+=16) { | 650 | if (i == 0) { |
| 664 | result = svq1_decode_block_intra (&s->gb, ¤t[x], linesize); | 651 | width = FFALIGN(s->width, 16); |
| 665 | if (result != 0) | 652 | height = FFALIGN(s->height, 16); |
| 666 | { | 653 | linesize = s->linesize; |
| 667 | av_log(s->avctx, AV_LOG_ERROR, "Error in svq1_decode_block %i (keyframe)\n",result); | 654 | } else { |
| 668 | goto err; | 655 | if (s->flags & CODEC_FLAG_GRAY) |
| 669 | } | 656 | break; |
| 670 | } | 657 | width = FFALIGN(s->width / 4, 16); |
| 671 | current += 16*linesize; | 658 | height = FFALIGN(s->height / 4, 16); |
| 672 | } | 659 | linesize = s->uvlinesize; |
| 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, ¤t[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 | } | ||
| 686 | } | 660 | } |
| 687 | 661 | ||
| 688 | pmv[0].x = | 662 | current = s->current_picture.f.data[i]; |
| 689 | pmv[0].y = 0; | 663 | |
| 690 | 664 | if (s->pict_type == AV_PICTURE_TYPE_B) | |
| 691 | current += 16*linesize; | 665 | previous = s->next_picture.f.data[i]; |
| 692 | } | 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, ¤t[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, ¤t[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 | } | ||
| 693 | } | 707 | } |
| 694 | } | ||
| 695 | 708 | ||
| 696 | *pict = s->current_picture.f; | 709 | *pict = s->current_picture.f; |
| 697 | 710 | ||
| 711 | ff_MPV_frame_end(s); | ||
| 698 | 712 | ||
| 699 | ff_MPV_frame_end(s); | 713 | *data_size = sizeof(AVFrame); |
| 714 | result = buf_size; | ||
| 700 | 715 | ||
| 701 | *data_size=sizeof(AVFrame); | ||
| 702 | result = buf_size; | ||
| 703 | err: | 716 | err: |
| 704 | av_free(pmv); | 717 | av_free(pmv); |
| 705 | return result; | 718 | return result; |
| 706 | } | 719 | } |
| 707 | 720 | ||
| 708 | static av_cold int svq1_decode_init(AVCodecContext *avctx) | 721 | 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 | |||
| 713 | 726 | ||
| 714 | ff_MPV_decode_defaults(s); | 727 | ff_MPV_decode_defaults(s); |
| 715 | 728 | ||
| 716 | s->avctx = avctx; | 729 | s->avctx = avctx; |
| 717 | s->width = (avctx->width+3)&~3; | 730 | s->width = avctx->width + 3 & ~3; |
| 718 | s->height = (avctx->height+3)&~3; | 731 | s->height = avctx->height + 3 & ~3; |
| 719 | s->codec_id= avctx->codec->id; | 732 | s->codec_id = avctx->codec->id; |
| 720 | avctx->pix_fmt = AV_PIX_FMT_YUV410P; | 733 | 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 | 734 | /* Not true, but DP frames and these behave like unidirectional B-frames. */ |
| 722 | s->flags= avctx->flags; | 735 | avctx->has_b_frames = 1; |
| 723 | if (ff_MPV_common_init(s) < 0) return -1; | 736 | s->flags = avctx->flags; |
| 737 | if (ff_MPV_common_init(s) < 0) | ||
| 738 | return -1; | ||
| 724 | 739 | ||
| 725 | INIT_VLC_STATIC(&svq1_block_type, 2, 4, | 740 | INIT_VLC_STATIC(&svq1_block_type, 2, 4, |
| 726 | &ff_svq1_block_type_vlc[0][1], 2, 1, | 741 | &ff_svq1_block_type_vlc[0][1], 2, 1, |
| 727 | &ff_svq1_block_type_vlc[0][0], 2, 1, 6); | 742 | &ff_svq1_block_type_vlc[0][0], 2, 1, 6); |
| 728 | 743 | ||
| 729 | INIT_VLC_STATIC(&svq1_motion_component, 7, 33, | 744 | INIT_VLC_STATIC(&svq1_motion_component, 7, 33, |
| 730 | &ff_mvtab[0][1], 2, 1, | 745 | &ff_mvtab[0][1], 2, 1, |
| 731 | &ff_mvtab[0][0], 2, 1, 176); | 746 | &ff_mvtab[0][0], 2, 1, 176); |
| 732 | 747 | ||
| 733 | for (i = 0; i < 6; i++) { | 748 | 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 } }; | ||
| 735 | static VLC_TYPE table[168][2]; | 751 | static VLC_TYPE table[168][2]; |
| 736 | svq1_intra_multistage[i].table = &table[offset]; | 752 | svq1_intra_multistage[i].table = &table[offset]; |
| 737 | svq1_intra_multistage[i].table_allocated = sizes[0][i]; | 753 | svq1_intra_multistage[i].table_allocated = sizes[0][i]; |
| 738 | offset += sizes[0][i]; | 754 | offset += sizes[0][i]; |
| 739 | init_vlc(&svq1_intra_multistage[i], 3, 8, | 755 | init_vlc(&svq1_intra_multistage[i], 3, 8, |
| 740 | &ff_svq1_intra_multistage_vlc[i][0][1], 2, 1, | 756 | &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); | 757 | &ff_svq1_intra_multistage_vlc[i][0][0], 2, 1, |
| 742 | svq1_inter_multistage[i].table = &table[offset]; | 758 | INIT_VLC_USE_NEW_STATIC); |
| 759 | svq1_inter_multistage[i].table = &table[offset]; | ||
| 743 | svq1_inter_multistage[i].table_allocated = sizes[1][i]; | 760 | svq1_inter_multistage[i].table_allocated = sizes[1][i]; |
| 744 | offset += sizes[1][i]; | 761 | offset += sizes[1][i]; |
| 745 | init_vlc(&svq1_inter_multistage[i], 3, 8, | 762 | init_vlc(&svq1_inter_multistage[i], 3, 8, |
| 746 | &ff_svq1_inter_multistage_vlc[i][0][1], 2, 1, | 763 | &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); | 764 | &ff_svq1_inter_multistage_vlc[i][0][0], 2, 1, |
| 765 | INIT_VLC_USE_NEW_STATIC); | ||
| 748 | } | 766 | } |
| 749 | 767 | ||
| 750 | INIT_VLC_STATIC(&svq1_intra_mean, 8, 256, | 768 | INIT_VLC_STATIC(&svq1_intra_mean, 8, 256, |
| 751 | &ff_svq1_intra_mean_vlc[0][1], 4, 2, | 769 | &ff_svq1_intra_mean_vlc[0][1], 4, 2, |
| 752 | &ff_svq1_intra_mean_vlc[0][0], 4, 2, 632); | 770 | &ff_svq1_intra_mean_vlc[0][0], 4, 2, 632); |
| 753 | 771 | ||
| 754 | INIT_VLC_STATIC(&svq1_inter_mean, 9, 512, | 772 | INIT_VLC_STATIC(&svq1_inter_mean, 9, 512, |
| 755 | &ff_svq1_inter_mean_vlc[0][1], 4, 2, | 773 | &ff_svq1_inter_mean_vlc[0][1], 4, 2, |
| 756 | &ff_svq1_inter_mean_vlc[0][0], 4, 2, 1434); | 774 | &ff_svq1_inter_mean_vlc[0][0], 4, 2, 1434); |
| 757 | 775 | ||
| 758 | return 0; | 776 | return 0; |
| 759 | } | 777 | } |
| @@ -766,7 +784,6 @@ static av_cold int svq1_decode_end(AVCodecContext *avctx) · 6 unmodified lines | |||
| 766 | return 0; | 784 | return 0; |
| 767 | } | 785 | } |
| 768 | 786 | ||
| 769 | |||
| 770 | AVCodec ff_svq1_decoder = { | 787 | AVCodec ff_svq1_decoder = { |
| 771 | .name = "svq1", | 788 | .name = "svq1", |
| 772 | .type = AVMEDIA_TYPE_VIDEO, | 789 | .type = AVMEDIA_TYPE_VIDEO, |
| @@ -777,6 +794,7 @@ AVCodec ff_svq1_decoder = { · 4 unmodified lines | |||
| 777 | .decode = svq1_decode_frame, | 794 | .decode = svq1_decode_frame, |
| 778 | .capabilities = CODEC_CAP_DR1, | 795 | .capabilities = CODEC_CAP_DR1, |
| 779 | .flush = ff_mpeg_flush, | 796 | .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 }, | ||
| 781 | .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"), | 799 | .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"), |
| 782 | }; | 800 | }; |
| @@ -26,21 +26,21 @@ · 25 unmodified lines | |||
| 26 | * http://www.pcisys.net/~melanson/codecs/ | 26 | * http://www.pcisys.net/~melanson/codecs/ |
| 27 | */ | 27 | */ |
| 28 | 28 | ||
| 29 | |||
| 30 | #include "avcodec.h" | 29 | #include "avcodec.h" |
| 31 | #include "dsputil.h" | 30 | #include "dsputil.h" |
| 32 | #include "mpegvideo.h" | 31 | #include "mpegvideo.h" |
| 33 | #include "h263.h" | 32 | #include "h263.h" |
| 34 | #include "internal.h" | 33 | #include "internal.h" |
| 35 | #include "libavutil/avassert.h" | 34 | #include "libavutil/avassert.h" |
| 36 | |||
| 37 | #include "svq1.h" | 35 | #include "svq1.h" |
| 38 | #include "svq1enc_cb.h" | 36 | #include "svq1enc_cb.h" |
| 39 | 37 | ||
| 40 | 38 | ||
| 41 | |||
| 42 | typedef struct SVQ1Context { | 39 | 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; | ||
| 44 | AVCodecContext *avctx; | 44 | AVCodecContext *avctx; |
| 45 | DSPContext dsp; | 45 | DSPContext dsp; |
| 46 | AVFrame picture; | 46 | AVFrame picture; |
| @@ -49,7 +49,9 @@ typedef struct SVQ1Context { · 2 unmodified lines | |||
| 49 | PutBitContext pb; | 49 | PutBitContext pb; |
| 50 | GetBitContext gb; | 50 | GetBitContext gb; |
| 51 | 51 | ||
| 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]; | ||
| 53 | 55 | ||
| 54 | int frame_width; | 56 | int frame_width; |
| 55 | int frame_height; | 57 | int frame_height; |
| @@ -86,21 +88,19 @@ static void svq1_write_header(SVQ1Context *s, int frame_type) · 30 unmodified lines | |||
| 86 | put_bits(&s->pb, 2, frame_type - 1); | 88 | put_bits(&s->pb, 2, frame_type - 1); |
| 87 | 89 | ||
| 88 | if (frame_type == AV_PICTURE_TYPE_I) { | 90 | if (frame_type == AV_PICTURE_TYPE_I) { |
| 89 | |||
| 90 | /* no checksum since frame code is 0x20 */ | 91 | /* no checksum since frame code is 0x20 */ |
| 91 | |||
| 92 | /* no embedded string either */ | 92 | /* no embedded string either */ |
| 93 | |||
| 94 | /* output 5 unknown bits (2 + 2 + 1) */ | 93 | /* output 5 unknown bits (2 + 2 + 1) */ |
| 95 | put_bits(&s->pb, 5, 2); /* 2 needed by quicktime decoder */ | 94 | put_bits(&s->pb, 5, 2); /* 2 needed by quicktime decoder */ |
| 96 | 95 | ||
| 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); | ||
| 98 | put_bits(&s->pb, 3, i); | 99 | put_bits(&s->pb, 3, i); |
| 99 | 100 | ||
| 100 | if (i == 7) | 101 | if (i == 7) { |
| 101 | { | 102 | put_bits(&s->pb, 12, s->frame_width); |
| 102 | put_bits(&s->pb, 12, s->frame_width); | 103 | put_bits(&s->pb, 12, s->frame_height); |
| 103 | put_bits(&s->pb, 12, s->frame_height); | ||
| 104 | } | 104 | } |
| 105 | } | 105 | } |
| 106 | 106 | ||
| @@ -108,391 +108,423 @@ static void svq1_write_header(SVQ1Context *s, int frame_type) · 1 unmodified line | |||
| 108 | put_bits(&s->pb, 2, 0); | 108 | put_bits(&s->pb, 2, 0); |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | 111 | #define QUALITY_THRESHOLD 100 | |
| 112 | #define QUALITY_THRESHOLD 100 | ||
| 113 | #define THRESHOLD_MULTIPLIER 0.6 | 112 | #define THRESHOLD_MULTIPLIER 0.6 |
| 114 | 113 | ||
| 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 | { | ||
| 116 | int count, y, x, i, j, split, best_mean, best_score, best_count; | 118 | int count, y, x, i, j, split, best_mean, best_score, best_count; |
| 117 | int best_vector[6]; | 119 | int best_vector[6]; |
| 118 | int block_sum[7]= {0, 0, 0, 0, 0, 0}; | 120 | int block_sum[7] = { 0, 0, 0, 0, 0, 0 }; |
| 119 | int w= 2<<((level+2)>>1); | 121 | int w = 2 << (level + 2 >> 1); |
| 120 | int h= 2<<((level+1)>>1); | 122 | int h = 2 << (level + 1 >> 1); |
| 121 | int size=w*h; | 123 | int size = w * h; |
| 122 | int16_t block[7][256]; | 124 | int16_t block[7][256]; |
| 123 | const int8_t *codebook_sum, *codebook; | 125 | const int8_t *codebook_sum, *codebook; |
| 124 | const uint16_t (*mean_vlc)[2]; | 126 | const uint16_t(*mean_vlc)[2]; |
| 125 | const uint8_t (*multistage_vlc)[2]; | 127 | const uint8_t(*multistage_vlc)[2]; |
| 126 | 128 | ||
| 127 | best_score=0; | 129 | best_score = 0; |
| 128 | //FIXME optimize, this doenst need to be done multiple times | 130 | // FIXME: Optimize, this does not need to be done multiple times. |
| 129 | if(intra){ | 131 | if (intra) { |
| 130 | codebook_sum= svq1_intra_codebook_sum[level]; | 132 | codebook_sum = svq1_intra_codebook_sum[level]; |
| 131 | codebook= ff_svq1_intra_codebooks[level]; | 133 | codebook = ff_svq1_intra_codebooks[level]; |
| 132 | mean_vlc= ff_svq1_intra_mean_vlc; | 134 | mean_vlc = ff_svq1_intra_mean_vlc; |
| 133 | multistage_vlc= ff_svq1_intra_multistage_vlc[level]; | 135 | multistage_vlc = ff_svq1_intra_multistage_vlc[level]; |
| 134 | for(y=0; y<h; y++){ | 136 | for (y = 0; y < h; y++) { |
| 135 | for(x=0; x<w; x++){ | 137 | for (x = 0; x < w; x++) { |
| 136 | int v= src[x + y*stride]; | 138 | int v = src[x + y * stride]; |
| 137 | block[0][x + w*y]= v; | 139 | block[0][x + w * y] = v; |
| 138 | best_score += v*v; | 140 | best_score += v * v; |
| 139 | block_sum[0] += v; | 141 | block_sum[0] += v; |
| 140 | } | 142 | } |
| 141 | } | 143 | } |
| 142 | }else{ | 144 | } else { |
| 143 | codebook_sum= svq1_inter_codebook_sum[level]; | 145 | codebook_sum = svq1_inter_codebook_sum[level]; |
| 144 | codebook= ff_svq1_inter_codebooks[level]; | 146 | codebook = ff_svq1_inter_codebooks[level]; |
| 145 | mean_vlc= ff_svq1_inter_mean_vlc + 256; | 147 | mean_vlc = ff_svq1_inter_mean_vlc + 256; |
| 146 | multistage_vlc= ff_svq1_inter_multistage_vlc[level]; | 148 | multistage_vlc = ff_svq1_inter_multistage_vlc[level]; |
| 147 | for(y=0; y<h; y++){ | 149 | for (y = 0; y < h; y++) { |
| 148 | for(x=0; x<w; x++){ | 150 | for (x = 0; x < w; x++) { |
| 149 | int v= src[x + y*stride] - ref[x + y*stride]; | 151 | int v = src[x + y * stride] - ref[x + y * stride]; |
| 150 | block[0][x + w*y]= v; | 152 | block[0][x + w * y] = v; |
| 151 | best_score += v*v; | 153 | best_score += v * v; |
| 152 | block_sum[0] += v; | 154 | block_sum[0] += v; |
| 153 | } | 155 | } |
| 154 | } | 156 | } |
| 155 | } | 157 | } |
| 156 | 158 | ||
| 157 | best_count=0; | 159 | best_count = 0; |
| 158 | best_score -= (int)(((unsigned)block_sum[0]*block_sum[0])>>(level+3)); | 160 | best_score -= (int)((unsigned)block_sum[0] * block_sum[0] >> (level + 3)); |
| 159 | best_mean= (block_sum[0] + (size>>1)) >> (level+3); | 161 | best_mean = block_sum[0] + (size >> 1) >> (level + 3); |
| 160 | 162 | ||
| 161 | if(level<4){ | 163 | if (level < 4) { |
| 162 | for(count=1; count<7; count++){ | 164 | for (count = 1; count < 7; count++) { |
| 163 | int best_vector_score= INT_MAX; | 165 | int best_vector_score = INT_MAX; |
| 164 | int best_vector_sum=-999, best_vector_mean=-999; | 166 | int best_vector_sum = -999, best_vector_mean = -999; |
| 165 | const int stage= count-1; | 167 | const int stage = count - 1; |
| 166 | const int8_t *vector; | 168 | const int8_t *vector; |
| 167 | 169 | ||
| 168 | for(i=0; i<16; i++){ | 170 | for (i = 0; i < 16; i++) { |
| 169 | int sum= codebook_sum[stage*16 + i]; | 171 | int sum = codebook_sum[stage * 16 + i]; |
| 170 | int sqr, diff, score; | 172 | int sqr, diff, score; |
| 171 | 173 | ||
| 172 | vector = codebook + stage*size*16 + i*size; | 174 | vector = codebook + stage * size * 16 + i * size; |
| 173 | sqr = s->dsp.ssd_int8_vs_int16(vector, block[stage], size); | 175 | sqr = s->dsp.ssd_int8_vs_int16(vector, block[stage], size); |
| 174 | diff= block_sum[stage] - sum; | 176 | diff = block_sum[stage] - sum; |
| 175 | score= sqr - ((diff*(int64_t)diff)>>(level+3)); //FIXME 64bit slooow | 177 | score = sqr - (diff * (int64_t)diff >> (level + 3)); // FIXME: 64bit slooow |
| 176 | if(score < best_vector_score){ | 178 | if (score < best_vector_score) { |
| 177 | int mean= (diff + (size>>1)) >> (level+3); | 179 | int mean = diff + (size >> 1) >> (level + 3); |
| 178 | av_assert2(mean >-300 && mean<300); | 180 | av_assert2(mean > -300 && mean < 300); |
| 179 | mean= av_clip(mean, intra?0:-256, 255); | 181 | mean = av_clip(mean, intra ? 0 : -256, 255); |
| 180 | best_vector_score= score; | 182 | best_vector_score = score; |
| 181 | best_vector[stage]= i; | 183 | best_vector[stage] = i; |
| 182 | best_vector_sum= sum; | 184 | best_vector_sum = sum; |
| 183 | best_vector_mean= mean; | 185 | best_vector_mean = mean; |
| 184 | } | 186 | } |
| 185 | } | 187 | } |
| 186 | av_assert0(best_vector_mean != -999); | 188 | av_assert0(best_vector_mean != -999); |
| 187 | vector= codebook + stage*size*16 + best_vector[stage]*size; | 189 | vector = codebook + stage * size * 16 + best_vector[stage] * size; |
| 188 | for(j=0; j<size; j++){ | 190 | for (j = 0; j < size; j++) |
| 189 | block[stage+1][j] = block[stage][j] - vector[j]; | 191 | block[stage + 1][j] = block[stage][j] - vector[j]; |
| 190 | } | 192 | block_sum[stage + 1] = block_sum[stage] - best_vector_sum; |
| 191 | block_sum[stage+1]= block_sum[stage] - best_vector_sum; | 193 | best_vector_score += lambda * |
| 192 | best_vector_score += | 194 | (+1 + 4 * count + |
| 193 | lambda*(+ 1 + 4*count | 195 | multistage_vlc[1 + count][1] |
| 194 | + multistage_vlc[1+count][1] | 196 | + mean_vlc[best_vector_mean][1]); |
| 195 | + mean_vlc[best_vector_mean][1]); | 197 | |
| 196 | 198 | if (best_vector_score < best_score) { | |
| 197 | if(best_vector_score < best_score){ | 199 | best_score = best_vector_score; |
| 198 | best_score= best_vector_score; | 200 | best_count = count; |
| 199 | best_count= count; | 201 | best_mean = best_vector_mean; |
| 200 | best_mean= best_vector_mean; | ||
| 201 | } | 202 | } |
| 202 | } | 203 | } |
| 203 | } | 204 | } |
| 204 | 205 | ||
| 205 | split=0; | 206 | split = 0; |
| 206 | if(best_score > threshold && level){ | 207 | if (best_score > threshold && level) { |
| 207 | int score=0; | 208 | int score = 0; |
| 208 | int offset= (level&1) ? stride*h/2 : w/2; | 209 | int offset = level & 1 ? stride * h / 2 : w / 2; |
| 209 | PutBitContext backup[6]; | 210 | PutBitContext backup[6]; |
| 210 | 211 | ||
| 211 | for(i=level-1; i>=0; i--){ | 212 | for (i = level - 1; i >= 0; i--) |
| 212 | backup[i]= s->reorder_pb[i]; | 213 | backup[i] = s->reorder_pb[i]; |
| 213 | } | 214 | score += encode_block(s, src, ref, decoded, stride, level - 1, |
| 214 | score += encode_block(s, src , ref , decoded , stride, level-1, threshold>>1, lambda, intra); | 215 | threshold >> 1, lambda, intra); |
| 215 | score += encode_block(s, src + offset, ref + offset, decoded + offset, stride, level-1, threshold>>1, lambda, intra); | 216 | score += encode_block(s, src + offset, ref + offset, decoded + offset, |
| 217 | stride, level - 1, threshold >> 1, lambda, intra); | ||
| 216 | score += lambda; | 218 | score += lambda; |
| 217 | 219 | ||
| 218 | if(score < best_score){ | 220 | if (score < best_score) { |
| 219 | best_score= score; | 221 | best_score = score; |
| 220 | split=1; | 222 | split = 1; |
| 221 | }else{ | 223 | } else { |
| 222 | for(i=level-1; i>=0; i--){ | 224 | for (i = level - 1; i >= 0; i--) |
| 223 | s->reorder_pb[i]= backup[i]; | 225 | s->reorder_pb[i] = backup[i]; |
| 224 | } | ||
| 225 | } | 226 | } |
| 226 | } | 227 | } |
| 227 | if (level > 0) | 228 | if (level > 0) |
| 228 | put_bits(&s->reorder_pb[level], 1, split); | 229 | put_bits(&s->reorder_pb[level], 1, split); |
| 229 | 230 | ||
| 230 | if(!split){ | 231 | if (!split) { |
| 231 | av_assert1((best_mean >= 0 && best_mean<256) || !intra); | 232 | av_assert1(best_mean >= 0 && best_mean < 256 || !intra); |
| 232 | av_assert1(best_mean >= -256 && best_mean<256); | 233 | av_assert1(best_mean >= -256 && best_mean < 256); |
| 233 | av_assert1(best_count >=0 && best_count<7); | 234 | av_assert1(best_count >= 0 && best_count < 7); |
| 234 | av_assert1(level<4 || best_count==0); | 235 | av_assert1(level < 4 || best_count == 0); |
| 235 | 236 | ||
| 236 | /* output the encoding */ | 237 | /* output the encoding */ |
| 237 | put_bits(&s->reorder_pb[level], | 238 | put_bits(&s->reorder_pb[level], |
| 238 | multistage_vlc[1 + best_count][1], | 239 | multistage_vlc[1 + best_count][1], |
| 239 | multistage_vlc[1 + best_count][0]); | 240 | multistage_vlc[1 + best_count][0]); |
| 240 | put_bits(&s->reorder_pb[level], mean_vlc[best_mean][1], | 241 | put_bits(&s->reorder_pb[level], mean_vlc[best_mean][1], |
| 241 | mean_vlc[best_mean][0]); | 242 | mean_vlc[best_mean][0]); |
| 242 | 243 | ||
| 243 | for (i = 0; i < best_count; i++){ | 244 | for (i = 0; i < best_count; i++) { |
| 244 | av_assert2(best_vector[i]>=0 && best_vector[i]<16); | 245 | av_assert2(best_vector[i] >= 0 && best_vector[i] < 16); |
| 245 | put_bits(&s->reorder_pb[level], 4, best_vector[i]); | 246 | put_bits(&s->reorder_pb[level], 4, best_vector[i]); |
| 246 | } | 247 | } |
| 247 | 248 | ||
| 248 | for(y=0; y<h; y++){ | 249 | for (y = 0; y < h; y++) |
| 249 | for(x=0; x<w; x++){ | 250 | for (x = 0; x < w; x++) |
| 250 | decoded[x + y*stride]= src[x + y*stride] - block[best_count][x + w*y] + best_mean; | 251 | decoded[x + y * stride] = src[x + y * stride] - |
| 251 | } | 252 | block[best_count][x + w * y] + |
| 252 | } | 253 | best_mean; |
| 253 | } | 254 | } |
| 254 | 255 | ||
| 255 | return best_score; | 256 | return best_score; |
| 256 | } | 257 | } |
| 257 | 258 | ||
| 258 | 259 | static int svq1_encode_plane(SVQ1Context *s, int plane, | |
| 259 | static int svq1_encode_plane(SVQ1Context *s, int plane, unsigned char *src_plane, unsigned char *ref_plane, unsigned char *decoded_plane, | 260 | unsigned char *src_plane, |
| 260 | int width, int height, int src_stride, int stride) | 261 | unsigned char *ref_plane, |
| 262 | unsigned char *decoded_plane, | ||
| 263 | int width, int height, int src_stride, int stride) | ||
| 261 | { | 264 | { |
| 262 | int x, y; | 265 | int x, y; |
| 263 | int i; | 266 | int i; |
| 264 | int block_width, block_height; | 267 | int block_width, block_height; |
| 265 | int level; | 268 | int level; |
| 266 | int threshold[6]; | 269 | int threshold[6]; |
| 267 | uint8_t *src = s->scratchbuf + stride * 16; | 270 | uint8_t *src = s->scratchbuf + stride * 16; |
| 268 | const int lambda= (s->picture.quality*s->picture.quality) >> (2*FF_LAMBDA_SHIFT); | 271 | const int lambda = (s->picture.quality * s->picture.quality) >> |
| 272 | (2 * FF_LAMBDA_SHIFT); | ||
| 269 | 273 | ||
| 270 | /* figure out the acceptable level thresholds in advance */ | 274 | /* figure out the acceptable level thresholds in advance */ |
| 271 | threshold[5] = QUALITY_THRESHOLD; | 275 | threshold[5] = QUALITY_THRESHOLD; |
| 272 | for (level = 4; level >= 0; level--) | 276 | for (level = 4; level >= 0; level--) |
| 273 | threshold[level] = threshold[level + 1] * THRESHOLD_MULTIPLIER; | 277 | threshold[level] = threshold[level + 1] * THRESHOLD_MULTIPLIER; |
| 274 | 278 | ||
| 275 | block_width = (width + 15) / 16; | 279 | block_width = (width + 15) / 16; |
| 276 | block_height = (height + 15) / 16; | 280 | block_height = (height + 15) / 16; |
| 277 | 281 | ||
| 278 | if(s->picture.pict_type == AV_PICTURE_TYPE_P){ | 282 | if (s->picture.pict_type == AV_PICTURE_TYPE_P) { |
| 279 | s->m.avctx= s->avctx; | 283 | s->m.avctx = s->avctx; |
| 280 | s->m.current_picture_ptr= &s->m.current_picture; | 284 | s->m.current_picture_ptr = &s->m.current_picture; |
| 281 | s->m.last_picture_ptr = &s->m.last_picture; | 285 | s->m.last_picture_ptr = &s->m.last_picture; |
| 282 | s->m.last_picture.f.data[0] = ref_plane; | 286 | s->m.last_picture.f.data[0] = ref_plane; |
| 283 | s->m.linesize= | 287 | s->m.linesize = |
| 284 | s->m.last_picture.f.linesize[0] = | 288 | s->m.last_picture.f.linesize[0] = |
| 285 | s->m.new_picture.f.linesize[0] = | 289 | s->m.new_picture.f.linesize[0] = |
| 286 | s->m.current_picture.f.linesize[0] = stride; | 290 | s->m.current_picture.f.linesize[0] = stride; |
| 287 | s->m.width= width; | 291 | s->m.width = width; |
| 288 | s->m.height= height; | 292 | s->m.height = height; |
| 289 | s->m.mb_width= block_width; | 293 | s->m.mb_width = block_width; |
| 290 | s->m.mb_height= block_height; | 294 | s->m.mb_height = block_height; |
| 291 | s->m.mb_stride= s->m.mb_width+1; | 295 | s->m.mb_stride = s->m.mb_width + 1; |
| 292 | s->m.b8_stride= 2*s->m.mb_width+1; | 296 | s->m.b8_stride = 2 * s->m.mb_width + 1; |
| 293 | s->m.f_code=1; | 297 | s->m.f_code = 1; |
| 294 | s->m.pict_type= s->picture.pict_type; | 298 | s->m.pict_type = s->picture.pict_type; |
| 295 | s->m.me_method= s->avctx->me_method; | 299 | s->m.me_method = s->avctx->me_method; |
| 296 | s->m.me.scene_change_score=0; | 300 | s->m.me.scene_change_score = 0; |
| 297 | s->m.flags= s->avctx->flags; | 301 | s->m.flags = s->avctx->flags; |
| 298 | // s->m.out_format = FMT_H263; | 302 | // s->m.out_format = FMT_H263; |
| 299 | // s->m.unrestricted_mv= 1; | 303 | // s->m.unrestricted_mv = 1; |
| 300 | 304 | s->m.lambda = s->picture.quality; | |
| 301 | s->m.lambda= s->picture.quality; | 305 | s->m.qscale = s->m.lambda * 139 + |
| 302 | s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); | 306 | FF_LAMBDA_SCALE * 64 >> |
| 303 | s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; | 307 | FF_LAMBDA_SHIFT + 7; |
| 304 | 308 | s->m.lambda2 = s->m.lambda * s->m.lambda + | |
| 305 | if(!s->motion_val8[plane]){ | 309 | FF_LAMBDA_SCALE / 2 >> |
| 306 | s->motion_val8 [plane]= av_mallocz((s->m.b8_stride*block_height*2 + 2)*2*sizeof(int16_t)); | 310 | FF_LAMBDA_SHIFT; |
| 307 | s->motion_val16[plane]= av_mallocz((s->m.mb_stride*(block_height + 2) + 1)*2*sizeof(int16_t)); | 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)); | ||
| 308 | } | 319 | } |
| 309 | 320 | ||
| 310 | s->m.mb_type= s->mb_type; | 321 | s->m.mb_type = s->mb_type; |
| 311 | 322 | ||
| 312 | //dummies, to avoid segfaults | 323 | // dummies, to avoid segfaults |
| 313 | s->m.current_picture.mb_mean= (uint8_t *)s->dummy; | 324 | s->m.current_picture.mb_mean = (uint8_t *)s->dummy; |
| 314 | s->m.current_picture.mb_var= (uint16_t*)s->dummy; | 325 | s->m.current_picture.mb_var = (uint16_t *)s->dummy; |
| 315 | s->m.current_picture.mc_mb_var= (uint16_t*)s->dummy; | 326 | s->m.current_picture.mc_mb_var = (uint16_t *)s->dummy; |
| 316 | s->m.current_picture.f.mb_type = s->dummy; | 327 | s->m.current_picture.f.mb_type = s->dummy; |
| 317 | 328 | ||
| 318 | s->m.current_picture.f.motion_val[0] = s->motion_val8[plane] + 2; | 329 | 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; | 330 | s->m.p_mv_table = s->motion_val16[plane] + |
| 320 | s->m.dsp= s->dsp; //move | 331 | s->m.mb_stride + 1; |
| 332 | s->m.dsp = s->dsp; // move | ||
| 321 | ff_init_me(&s->m); | 333 | ff_init_me(&s->m); |
| 322 | 334 | ||
| 323 | s->m.me.dia_size= s->avctx->dia_size; | 335 | s->m.me.dia_size = s->avctx->dia_size; |
| 324 | s->m.first_slice_line=1; | 336 | s->m.first_slice_line = 1; |
| 325 | for (y = 0; y < block_height; y++) { | 337 | for (y = 0; y < block_height; y++) { |
| 326 | s->m.new_picture.f.data[0] = src - y*16*stride; //ugly | 338 | s->m.new_picture.f.data[0] = src - y * 16 * stride; // ugly |
| 327 | s->m.mb_y= y; | 339 | s->m.mb_y = y; |
| 328 | 340 | ||
| 329 | for(i=0; i<16 && i + 16*y<height; i++){ | 341 | for (i = 0; i < 16 && i + 16 * y < height; i++) { |
| 330 | memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width); | 342 | memcpy(&src[i * stride], &src_plane[(i + 16 * y) * src_stride], |
| 331 | for(x=width; x<16*block_width; x++) | 343 | width); |
| 332 | src[i*stride+x]= src[i*stride+x-1]; | 344 | for (x = width; x < 16 * block_width; x++) |
| 345 | src[i * stride + x] = src[i * stride + x - 1]; | ||
| 333 | } | 346 | } |
| 334 | for(; i<16 && i + 16*y<16*block_height; i++) | 347 | for (; i < 16 && i + 16 * y < 16 * block_height; i++) |
| 335 | memcpy(&src[i*stride], &src[(i-1)*stride], 16*block_width); | 348 | memcpy(&src[i * stride], &src[(i - 1) * stride], |
| 349 | 16 * block_width); | ||
| 336 | 350 | ||
| 337 | for (x = 0; x < block_width; x++) { | 351 | for (x = 0; x < block_width; x++) { |
| 338 | s->m.mb_x= x; | 352 | s->m.mb_x = x; |
| 339 | ff_init_block_index(&s->m); | 353 | ff_init_block_index(&s->m); |
| 340 | ff_update_block_index(&s->m); | 354 | ff_update_block_index(&s->m); |
| 341 | 355 | ||
| 342 | ff_estimate_p_frame_motion(&s->m, x, y); | 356 | ff_estimate_p_frame_motion(&s->m, x, y); |
| 343 | } | 357 | } |
| 344 | s->m.first_slice_line=0; | 358 | s->m.first_slice_line = 0; |
| 345 | } | 359 | } |
| 346 | 360 | ||
| 347 | ff_fix_long_p_mvs(&s->m); | 361 | 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); | ||
| 349 | } | 364 | } |
| 350 | 365 | ||
| 351 | s->m.first_slice_line=1; | 366 | s->m.first_slice_line = 1; |
| 352 | for (y = 0; y < block_height; y++) { | 367 | for (y = 0; y < block_height; y++) { |
| 353 | for(i=0; i<16 && i + 16*y<height; i++){ | 368 | for (i = 0; i < 16 && i + 16 * y < height; i++) { |
| 354 | memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width); | 369 | memcpy(&src[i * stride], &src_plane[(i + 16 * y) * src_stride], |
| 355 | for(x=width; x<16*block_width; x++) | 370 | width); |
| 356 | src[i*stride+x]= src[i*stride+x-1]; | 371 | for (x = width; x < 16 * block_width; x++) |
| 372 | src[i * stride + x] = src[i * stride + x - 1]; | ||
| 357 | } | 373 | } |
| 358 | for(; i<16 && i + 16*y<16*block_height; i++) | 374 | for (; i < 16 && i + 16 * y < 16 * block_height; i++) |
| 359 | memcpy(&src[i*stride], &src[(i-1)*stride], 16*block_width); | 375 | memcpy(&src[i * stride], &src[(i - 1) * stride], 16 * block_width); |
| 360 | 376 | ||
| 361 | s->m.mb_y= y; | 377 | s->m.mb_y = y; |
| 362 | for (x = 0; x < block_width; x++) { | 378 | 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]; |
| 364 | int count[3][6]; | 380 | int count[3][6]; |
| 365 | int offset = y * 16 * stride + x * 16; | 381 | int offset = y * 16 * stride + x * 16; |
| 366 | uint8_t *decoded= decoded_plane + offset; | 382 | uint8_t *decoded = decoded_plane + offset; |
| 367 | uint8_t *ref= ref_plane + offset; | 383 | uint8_t *ref = ref_plane + offset; |
| 368 | int score[4]={0,0,0,0}, best; | 384 | int score[4] = { 0, 0, 0, 0 }, best; |
| 369 | uint8_t *temp = s->scratchbuf; | 385 | uint8_t *temp = s->scratchbuf; |
| 370 | 386 | ||
| 371 | if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 3000){ //FIXME check size | 387 | if (s->pb.buf_end - s->pb.buf - |
| 388 | (put_bits_count(&s->pb) >> 3) < 3000) { // FIXME: check size | ||
| 372 | av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); | 389 | av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); |
| 373 | return -1; | 390 | return -1; |
| 374 | } | 391 | } |
| 375 | 392 | ||
| 376 | s->m.mb_x= x; | 393 | s->m.mb_x = x; |
| 377 | ff_init_block_index(&s->m); | 394 | ff_init_block_index(&s->m); |
| 378 | ff_update_block_index(&s->m); | 395 | ff_update_block_index(&s->m); |
| 379 | 396 | ||
| 380 | if(s->picture.pict_type == AV_PICTURE_TYPE_I || (s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTRA)){ | 397 | if (s->picture.pict_type == AV_PICTURE_TYPE_I || |
| 381 | for(i=0; i<6; i++){ | 398 | (s->m.mb_type[x + y * s->m.mb_stride] & |
| 382 | init_put_bits(&s->reorder_pb[i], reorder_buffer[0][i], 7*32); | 399 | CANDIDATE_MB_TYPE_INTRA)) { |
| 383 | } | 400 | for (i = 0; i < 6; i++) |
| 384 | if(s->picture.pict_type == AV_PICTURE_TYPE_P){ | 401 | init_put_bits(&s->reorder_pb[i], reorder_buffer[0][i], |
| 385 | const uint8_t *vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_INTRA]; | 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]; | ||
| 386 | put_bits(&s->reorder_pb[5], vlc[1], vlc[0]); | 405 | put_bits(&s->reorder_pb[5], vlc[1], vlc[0]); |
| 387 | score[0]= vlc[1]*lambda; | 406 | score[0] = vlc[1] * lambda; |
| 388 | } | 407 | } |
| 389 | score[0]+= encode_block(s, src+16*x, NULL, temp, stride, 5, 64, lambda, 1); | 408 | score[0] += encode_block(s, src + 16 * x, NULL, temp, stride, |
| 390 | for(i=0; i<6; i++){ | 409 | 5, 64, lambda, 1); |
| 391 | count[0][i]= put_bits_count(&s->reorder_pb[i]); | 410 | for (i = 0; i < 6; i++) { |
| 411 | count[0][i] = put_bits_count(&s->reorder_pb[i]); | ||
| 392 | flush_put_bits(&s->reorder_pb[i]); | 412 | flush_put_bits(&s->reorder_pb[i]); |
| 393 | } | 413 | } |
| 394 | }else | 414 | } else |
| 395 | score[0]= INT_MAX; | 415 | score[0] = INT_MAX; |
| 396 | 416 | ||
| 397 | best=0; | 417 | best = 0; |
| 398 | 418 | ||
| 399 | if(s->picture.pict_type == AV_PICTURE_TYPE_P){ | 419 | if (s->picture.pict_type == AV_PICTURE_TYPE_P) { |
| 400 | const uint8_t *vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_INTER]; | 420 | const uint8_t *vlc = ff_svq1_block_type_vlc[SVQ1_BLOCK_INTER]; |
| 401 | int mx, my, pred_x, pred_y, dxy; | 421 | int mx, my, pred_x, pred_y, dxy; |
| 402 | int16_t *motion_ptr; | 422 | int16_t *motion_ptr; |
| 403 | 423 | ||
| 404 | motion_ptr= ff_h263_pred_motion(&s->m, 0, 0, &pred_x, &pred_y); | 424 | 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){ | 425 | if (s->m.mb_type[x + y * s->m.mb_stride] & |
| 406 | for(i=0; i<6; i++) | 426 | CANDIDATE_MB_TYPE_INTER) { |
| 407 | init_put_bits(&s->reorder_pb[i], reorder_buffer[1][i], 7*32); | 427 | for (i = 0; i < 6; i++) |
| 428 | init_put_bits(&s->reorder_pb[i], reorder_buffer[1][i], | ||
| 429 | 7 * 32); | ||
| 408 | 430 | ||
| 409 | put_bits(&s->reorder_pb[5], vlc[1], vlc[0]); | 431 | put_bits(&s->reorder_pb[5], vlc[1], vlc[0]); |
| 410 | 432 | ||
| 411 | s->m.pb= s->reorder_pb[5]; | 433 | s->m.pb = s->reorder_pb[5]; |
| 412 | mx= motion_ptr[0]; | 434 | mx = motion_ptr[0]; |
| 413 | my= motion_ptr[1]; | 435 | my = motion_ptr[1]; |
| 414 | av_assert1(mx>=-32 && mx<=31); | 436 | av_assert1(mx >= -32 && mx <= 31); |
| 415 | av_assert1(my>=-32 && my<=31); | 437 | av_assert1(my >= -32 && my <= 31); |
| 416 | av_assert1(pred_x>=-32 && pred_x<=31); | 438 | av_assert1(pred_x >= -32 && pred_x <= 31); |
| 417 | av_assert1(pred_y>=-32 && pred_y<=31); | 439 | av_assert1(pred_y >= -32 && pred_y <= 31); |
| 418 | ff_h263_encode_motion(&s->m, mx - pred_x, 1); | 440 | ff_h263_encode_motion(&s->m, mx - pred_x, 1); |
| 419 | ff_h263_encode_motion(&s->m, my - pred_y, 1); | 441 | ff_h263_encode_motion(&s->m, my - pred_y, 1); |
| 420 | s->reorder_pb[5]= s->m.pb; | 442 | s->reorder_pb[5] = s->m.pb; |
| 421 | score[1] += lambda*put_bits_count(&s->reorder_pb[5]); | 443 | score[1] += lambda * put_bits_count(&s->reorder_pb[5]); |
| 422 | 444 | ||
| 423 | dxy= (mx&1) + 2*(my&1); | 445 | dxy = (mx & 1) + 2 * (my & 1); |
| 424 | 446 | ||
| 425 | s->dsp.put_pixels_tab[0][dxy](temp+16, ref + (mx>>1) + stride*(my>>1), stride, 16); | 447 | s->dsp.put_pixels_tab[0][dxy](temp + 16, |
| 426 | 448 | ref + (mx >> 1) + | |
| 427 | score[1]+= encode_block(s, src+16*x, temp+16, decoded, stride, 5, 64, lambda, 0); | 449 | stride * (my >> 1), |
| 428 | best= score[1] <= score[0]; | 450 | stride, 16); |
| 429 | 451 | ||
| 430 | vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_SKIP]; | 452 | score[1] += encode_block(s, src + 16 * x, temp + 16, |
| 431 | score[2]= s->dsp.sse[0](NULL, src+16*x, ref, stride, 16); | 453 | decoded, stride, 5, 64, lambda, 0); |
| 432 | score[2]+= vlc[1]*lambda; | 454 | best = score[1] <= score[0]; |
| 433 | if(score[2] < score[best] && mx==0 && my==0){ | 455 | |
| 434 | best=2; | 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; | ||
| 435 | s->dsp.put_pixels_tab[0][0](decoded, ref, stride, 16); | 462 | s->dsp.put_pixels_tab[0][0](decoded, ref, stride, 16); |
| 436 | for(i=0; i<6; i++){ | 463 | for (i = 0; i < 6; i++) |
| 437 | count[2][i]=0; | 464 | count[2][i] = 0; |
| 438 | } | ||
| 439 | put_bits(&s->pb, vlc[1], vlc[0]); | 465 | put_bits(&s->pb, vlc[1], vlc[0]); |
| 440 | } | 466 | } |
| 441 | } | 467 | } |
| 442 | 468 | ||
| 443 | if(best==1){ | 469 | if (best == 1) { |
| 444 | for(i=0; i<6; i++){ | 470 | for (i = 0; i < 6; i++) { |
| 445 | count[1][i]= put_bits_count(&s->reorder_pb[i]); | 471 | count[1][i] = put_bits_count(&s->reorder_pb[i]); |
| 446 | flush_put_bits(&s->reorder_pb[i]); | 472 | flush_put_bits(&s->reorder_pb[i]); |
| 447 | } | 473 | } |
| 448 | }else{ | 474 | } else { |
| 449 | motion_ptr[0 ] = motion_ptr[1 ]= | 475 | motion_ptr[0] = |
| 450 | motion_ptr[2 ] = motion_ptr[3 ]= | 476 | motion_ptr[1] = |
| 451 | motion_ptr[0+2*s->m.b8_stride] = motion_ptr[1+2*s->m.b8_stride]= | 477 | motion_ptr[2] = |
| 452 | motion_ptr[2+2*s->m.b8_stride] = motion_ptr[3+2*s->m.b8_stride]=0; | 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; | ||
| 453 | } | 483 | } |
| 454 | } | 484 | } |
| 455 | 485 | ||
| 456 | s->rd_total += score[best]; | 486 | s->rd_total += score[best]; |
| 457 | 487 | ||
| 458 | for(i=5; i>=0; i--){ | 488 | for (i = 5; i >= 0; i--) |
| 459 | avpriv_copy_bits(&s->pb, reorder_buffer[best][i], count[best][i]); | 489 | avpriv_copy_bits(&s->pb, reorder_buffer[best][i], |
| 460 | } | 490 | count[best][i]); |
| 461 | if(best==0){ | 491 | if (best == 0) |
| 462 | s->dsp.put_pixels_tab[0][0](decoded, temp, stride, 16); | 492 | s->dsp.put_pixels_tab[0][0](decoded, temp, stride, 16); |
| 463 | } | ||
| 464 | } | 493 | } |
| 465 | s->m.first_slice_line=0; | 494 | s->m.first_slice_line = 0; |
| 466 | } | 495 | } |
| 467 | return 0; | 496 | return 0; |
| 468 | } | 497 | } |
| 469 | 498 | ||
| 470 | static av_cold int svq1_encode_init(AVCodecContext *avctx) | 499 | static av_cold int svq1_encode_init(AVCodecContext *avctx) |
| 471 | { | 500 | { |
| 472 | SVQ1Context * const s = avctx->priv_data; | 501 | SVQ1Context *const s = avctx->priv_data; |
| 473 | 502 | ||
| 474 | ff_dsputil_init(&s->dsp, avctx); | 503 | ff_dsputil_init(&s->dsp, avctx); |
| 475 | avctx->coded_frame = &s->picture; | 504 | avctx->coded_frame = &s->picture; |
| 476 | 505 | ||
| 477 | s->frame_width = avctx->width; | 506 | s->frame_width = avctx->width; |
| 478 | s->frame_height = avctx->height; | 507 | s->frame_height = avctx->height; |
| 479 | 508 | ||
| 480 | s->y_block_width = (s->frame_width + 15) / 16; | 509 | s->y_block_width = (s->frame_width + 15) / 16; |
| 481 | s->y_block_height = (s->frame_height + 15) / 16; | 510 | s->y_block_height = (s->frame_height + 15) / 16; |
| 482 | 511 | ||
| 483 | s->c_block_width = (s->frame_width / 4 + 15) / 16; | 512 | s->c_block_width = (s->frame_width / 4 + 15) / 16; |
| 484 | s->c_block_height = (s->frame_height / 4 + 15) / 16; | 513 | s->c_block_height = (s->frame_height / 4 + 15) / 16; |
| 485 | 514 | ||
| 486 | s->avctx= avctx; | 515 | s->avctx = avctx; |
| 487 | s->m.avctx= avctx; | 516 | s->m.avctx = avctx; |
| 488 | s->m.picture_structure = PICT_FRAME; | 517 | s->m.picture_structure = PICT_FRAME; |
| 489 | s->m.me.temp = | 518 | s->m.me.temp = |
| 490 | s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t)); | 519 | s->m.me.scratchpad = av_mallocz((avctx->width + 64) * |
| 491 | s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); | 520 | 2 * 16 * 2 * sizeof(uint8_t)); |
| 492 | s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); | 521 | s->m.me.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)); | 522 | s->m.me.score_map = av_mallocz(ME_MAP_SIZE * sizeof(uint32_t)); |
| 494 | s->dummy = av_mallocz((s->y_block_width+1)*s->y_block_height*sizeof(int32_t)); | 523 | s->mb_type = av_mallocz((s->y_block_width + 1) * |
| 495 | ff_h263_encode_init(&s->m); //mv_penalty | 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 | ||
| 496 | 528 | ||
| 497 | return 0; | 529 | return 0; |
| 498 | } | 530 | } |
| @@ -500,46 +532,51 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx) · 1 unmodified line | |||
| 500 | static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt, | 532 | static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
| 501 | const AVFrame *pict, int *got_packet) | 533 | const AVFrame *pict, int *got_packet) |
| 502 | { | 534 | { |
| 503 | SVQ1Context * const s = avctx->priv_data; | 535 | SVQ1Context *const s = avctx->priv_data; |
| 504 | AVFrame * const p = &s->picture; | 536 | AVFrame *const p = &s->picture; |
| 505 | AVFrame temp; | 537 | AVFrame temp; |
| 506 | int i, ret; | 538 | int i, ret; |
| 507 | 539 | ||
| 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)) | ||
| 509 | return ret; | 542 | return ret; |
| 510 | 543 | ||
| 511 | if(avctx->pix_fmt != AV_PIX_FMT_YUV410P){ | 544 | if (avctx->pix_fmt != AV_PIX_FMT_YUV410P) { |
| 512 | av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n"); | 545 | av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n"); |
| 513 | return -1; | 546 | return -1; |
| 514 | } | 547 | } |
| 515 | 548 | ||
| 516 | if(!s->current_picture.data[0]){ | 549 | if (!s->current_picture.data[0]) { |
| 517 | avctx->get_buffer(avctx, &s->current_picture); | 550 | avctx->get_buffer(avctx, &s->current_picture); |
| 518 | avctx->get_buffer(avctx, &s->last_picture); | 551 | avctx->get_buffer(avctx, &s->last_picture); |
| 519 | s->scratchbuf = av_malloc(s->current_picture.linesize[0] * 16 * 2); | 552 | s->scratchbuf = av_malloc(s->current_picture.linesize[0] * 16 * 2); |
| 520 | } | 553 | } |
| 521 | 554 | ||
| 522 | temp= s->current_picture; | 555 | temp = s->current_picture; |
| 523 | s->current_picture= s->last_picture; | 556 | s->current_picture = s->last_picture; |
| 524 | s->last_picture= temp; | 557 | s->last_picture = temp; |
| 525 | 558 | ||
| 526 | init_put_bits(&s->pb, pkt->data, pkt->size); | 559 | init_put_bits(&s->pb, pkt->data, pkt->size); |
| 527 | 560 | ||
| 528 | *p = *pict; | 561 | *p = *pict; |
| 529 | p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; | 562 | p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ? |
| 563 | AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; | ||
| 530 | p->key_frame = p->pict_type == AV_PICTURE_TYPE_I; | 564 | p->key_frame = p->pict_type == AV_PICTURE_TYPE_I; |
| 531 | 565 | ||
| 532 | svq1_write_header(s, p->pict_type); | 566 | svq1_write_header(s, p->pict_type); |
| 533 | for(i=0; i<3; i++){ | 567 | for (i = 0; i < 3; i++) |
| 534 | if(svq1_encode_plane(s, i, | 568 | if (svq1_encode_plane(s, i, |
| 535 | s->picture.data[i], s->last_picture.data[i], s->current_picture.data[i], | 569 | s->picture.data[i], |
| 536 | s->frame_width / (i?4:1), s->frame_height / (i?4:1), | 570 | s->last_picture.data[i], |
| 537 | s->picture.linesize[i], s->current_picture.linesize[i]) < 0) | 571 | s->current_picture.data[i], |
| 538 | return -1; | 572 | s->frame_width / (i ? 4 : 1), |
| 539 | } | 573 | s->frame_height / (i ? 4 : 1), |
| 540 | 574 | s->picture.linesize[i], | |
| 541 | // avpriv_align_put_bits(&s->pb); | 575 | s->current_picture.linesize[i]) < 0) |
| 542 | while(put_bits_count(&s->pb) & 31) | 576 | return -1; |
| 577 | |||
| 578 | // avpriv_align_put_bits(&s->pb); | ||
| 579 | while (put_bits_count(&s->pb) & 31) | ||
| 543 | put_bits(&s->pb, 1, 0); | 580 | put_bits(&s->pb, 1, 0); |
| 544 | 581 | ||
| 545 | flush_put_bits(&s->pb); | 582 | flush_put_bits(&s->pb); |
| @@ -554,10 +591,12 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 8 unmodified lines | |||
| 554 | 591 | ||
| 555 | static av_cold int svq1_encode_end(AVCodecContext *avctx) | 592 | static av_cold int svq1_encode_end(AVCodecContext *avctx) |
| 556 | { | 593 | { |
| 557 | SVQ1Context * const s = avctx->priv_data; | 594 | SVQ1Context *const s = avctx->priv_data; |
| 558 | int i; | 595 | int i; |
| 559 | 596 | ||
| 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)); | ||
| 561 | 600 | ||
| 562 | av_freep(&s->m.me.scratchpad); | 601 | av_freep(&s->m.me.scratchpad); |
| 563 | av_freep(&s->m.me.map); | 602 | av_freep(&s->m.me.map); |
| @@ -566,7 +605,7 @@ static av_cold int svq1_encode_end(AVCodecContext *avctx) · 2 unmodified lines | |||
| 566 | av_freep(&s->dummy); | 605 | av_freep(&s->dummy); |
| 567 | av_freep(&s->scratchbuf); | 606 | av_freep(&s->scratchbuf); |
| 568 | 607 | ||
| 569 | for(i=0; i<3; i++){ | 608 | for (i = 0; i < 3; i++) { |
| 570 | av_freep(&s->motion_val8[i]); | 609 | av_freep(&s->motion_val8[i]); |
| 571 | av_freep(&s->motion_val16[i]); | 610 | av_freep(&s->motion_val16[i]); |
| 572 | } | 611 | } |
| @@ -578,7 +617,6 @@ static av_cold int svq1_encode_end(AVCodecContext *avctx) · 5 unmodified lines | |||
| 578 | return 0; | 617 | return 0; |
| 579 | } | 618 | } |
| 580 | 619 | ||
| 581 | |||
| 582 | AVCodec ff_svq1_encoder = { | 620 | AVCodec ff_svq1_encoder = { |
| 583 | .name = "svq1", | 621 | .name = "svq1", |
| 584 | .type = AVMEDIA_TYPE_VIDEO, | 622 | .type = AVMEDIA_TYPE_VIDEO, |
| @@ -587,6 +625,7 @@ AVCodec ff_svq1_encoder = { · 2 unmodified lines | |||
| 587 | .init = svq1_encode_init, | 625 | .init = svq1_encode_init, |
| 588 | .encode2 = svq1_encode_frame, | 626 | .encode2 = svq1_encode_frame, |
| 589 | .close = svq1_encode_end, | 627 | .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 }, | ||
| 591 | .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"), | 630 | .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"), |
| 592 | }; | 631 | }; |
| @@ -30,67 +30,57 @@ · 29 unmodified lines | |||
| 30 | #include <stdint.h> | 30 | #include <stdint.h> |
| 31 | 31 | ||
| 32 | static const int8_t svq1_inter_codebook_sum[4][16*6] = { | 32 | static const int8_t svq1_inter_codebook_sum[4][16*6] = { |
| 33 | { | 33 | { -1, 1, -2, 0, 1, -1, -1, -1, -2, -1, 1, -1, -1, 0, -1, -1, |
| 34 | -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 | 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, 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 | 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 | -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 | 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 | },{ | 40 | 0, 0, 0, -2, 0, 1, 0, -1, -1, 0, 2, -3, 1, -2, 3, -1, |
| 41 | -2, 1, -1, -1, 1, 0, 1, -1, -1, -1, 1, -1, 0, -1, 0, -1, | 41 | 2, 0, 2, 1, 1, -1, 1, 1, 0, 0, 1, 1, 2, -2, 1, 0, |
| 42 | 0, 0, 0, -2, 0, 1, 0, -1, -1, 0, 2, -3, 1, -2, 3, -1, | 42 | -2, -1, 2, -2, -2, 0, -3, 0, -1, 0, -1, 0, -1, 0, -2, -3, |
| 43 | 2, 0, 2, 1, 1, -1, 1, 1, 0, 0, 1, 1, 2, -2, 1, 0, | 43 | 1, -2, -2, -1, 1, -1, -1, 1, -1, 1, 1, 0, -2, 0, 1, 1, |
| 44 | -2, -1, 2, -2, -2, 0, -3, 0, -1, 0, -1, 0, -1, 0, -2, -3, | 44 | 1, 1, 2, 1, 0, 0, -1, 0, 0, 1, 0, 1, -1, 1, 0, 2, }, |
| 45 | 1, -2, -2, -1, 1, -1, -1, 1, -1, 1, 1, 0, -2, 0, 1, 1, | 45 | { 0, 0, 0, -3, 1, 1, 1, -3, 0, -1, 0, -3, 1, -3, 0, -2, |
| 46 | 1, 1, 2, 1, 0, 0, -1, 0, 0, 1, 0, 1, -1, 1, 0, 2, | 46 | 1, 2, -1, -3, 0, -3, 1, -1, 0, -1, 0, 0, 1, 2, 1, 1, |
| 47 | },{ | 47 | -1, 2, -3, 3, 1, 0, -5, 1, 0, -1, -3, 1, 0, 2, 0, -3, |
| 48 | 0, 0, 0, -3, 1, 1, 1, -3, 0, -1, 0, -3, 1, -3, 0, -2, | 48 | 4, 2, 0, -2, 1, -2, 3, -2, 1, 1, 0, -1, 2, 5, 3, 1, |
| 49 | 1, 2, -1, -3, 0, -3, 1, -1, 0, -1, 0, 0, 1, 2, 1, 1, | 49 | -1, 0, 2, -3, -2, 0, 0, -2, 2, -3, -1, -1, 2, 1, 0, -2, |
| 50 | -1, 2, -3, 3, 1, 0, -5, 1, 0, -1, -3, 1, 0, 2, 0, -3, | 50 | 3, -1, 1, -1, 2, 4, 0, 1, 0, 1, 0, -1, -3, -2, -1, 0, }, |
| 51 | 4, 2, 0, -2, 1, -2, 3, -2, 1, 1, 0, -1, 2, 5, 3, 1, | 51 | { 0, 2, -1, -1, 2, -4, -2, 3, 0, -1, -5, 1, 0, 1, 0, 6, |
| 52 | -1, 0, 2, -3, -2, 0, 0, -2, 2, -3, -1, -1, 2, 1, 0, -2, | 52 | -2, 2, 0, 1, 1, -1, -1, -2, 1, -2, -1, 0, 2, -2, -2, -1, |
| 53 | 3, -1, 1, -1, 2, 4, 0, 1, 0, 1, 0, -1, -3, -2, -1, 0, | 53 | -4, 2, -1, -3, -1, -2, 2, -1, 2, -1, 2, 0, 3, -3, -3, 0, |
| 54 | },{ | 54 | -3, 0, 0, -2, 4, -4, 0, -1, 4, 0, -2, -2, 3, -2, 0, 4, |
| 55 | 0, 2, -1, -1, 2, -4, -2, 3, 0, -1, -5, 1, 0, 1, 0, 6, | 55 | 5, 0, 1, 0, -3, 3, 3, 2, 0, 0, 1, 2, -5, -2, -3, 0, |
| 56 | -2, 2, 0, 1, 1, -1, -1, -2, 1, -2, -1, 0, 2, -2, -2, -1, | 56 | -3, 2, -2, 2, -2, 4, 7, -3, 4, 2, 3, 2, -1, 0, -3, 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 | } | ||
| 62 | }; | 57 | }; |
| 63 | 58 | ||
| 64 | static const int8_t svq1_intra_codebook_sum[4][16*6] = { | 59 | static const int8_t svq1_intra_codebook_sum[4][16*6] = { |
| 65 | { | 60 | { 0, 0, 0, -1, -1, -1, -1, -2, 0, -1, -1, 0, -1, 0, 1, 0, |
| 66 | 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, |
| 67 | 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, |
| 68 | -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, |
| 69 | 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, |
| 70 | 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, }, |
| 71 | 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, |
| 72 | },{ | 67 | 0, 0, 4, -2, -1, 1, 1, 0, 2, 1, 1, 0, 2, 0, 0, 0, |
| 73 | -1, -2, 0, -1, 1, 0, -1, 0, -1, -4, -1, -2, -1, -2, 1, -2, | 68 | 1, 1, 0, -1, -1, -1, 1, 0, -1, -3, -3, 1, -1, 1, -2, -1, |
| 74 | 0, 0, 4, -2, -1, 1, 1, 0, 2, 1, 1, 0, 2, 0, 0, 0, | 69 | 1, -1, 0, 1, 2, 1, -1, -1, 1, 1, 1, 2, 1, 0, 1, -2, |
| 75 | 1, 1, 0, -1, -1, -1, 1, 0, -1, -3, -3, 1, -1, 1, -2, -1, | 70 | -2, 0, -1, -2, -2, 0, -1, -1, -1, 0, 1, 0, -1, -1, 0, -1, |
| 76 | 1, -1, 0, 1, 2, 1, -1, -1, 1, 1, 1, 2, 1, 0, 1, -2, | 71 | 0, 2, 1, 2, 2, 1, -1, 1, 0, 2, 0, -1, 1, 0, 0, 0, }, |
| 77 | -2, 0, -1, -2, -2, 0, -1, -1, -1, 0, 1, 0, -1, -1, 0, -1, | 72 | { -2, 0, -1, -1, 1, 1, -2, 0, -2, 0, 1, -2, -2, 1, -1, -1, |
| 78 | 0, 2, 1, 2, 2, 1, -1, 1, 0, 2, 0, -1, 1, 0, 0, 0, | 73 | 3, -2, 0, -3, -4, -3, 2, 1, 0, 3, -2, 2, 3, 2, 2, -1, |
| 79 | },{ | 74 | -3, 1, 0, 1, 0, 0, 0, 1, -2, 1, -2, -2, -1, -2, -2, 2, |
| 80 | -2, 0, -1, -1, 1, 1, -2, 0, -2, 0, 1, -2, -2, 1, -1, -1, | 75 | 0, -4, 0, 2, -1, 0, 2, 2, 2, 1, 0, -1, -1, 1, -3, 2, |
| 81 | 3, -2, 0, -3, -4, -3, 2, 1, 0, 3, -2, 2, 3, 2, 2, -1, | 76 | 2, 1, 0, 3, 1, -1, 1, 3, 1, 0, 1, 1, 2, -1, 1, -1, |
| 82 | -3, 1, 0, 1, 0, 0, 0, 1, -2, 1, -2, -2, -1, -2, -2, 2, | 77 | -2, -1, 0, -1, 1, -1, 1, -2, -2, -1, -1, -3, 1, -4, -3, 1, }, |
| 83 | 0, -4, 0, 2, -1, 0, 2, 2, 2, 1, 0, -1, -1, 1, -3, 2, | 78 | { -2, 0, -2, 3, -1, -1, 0, 2, 2, -1, -3, 2, 1, 0, -2, -1, |
| 84 | 2, 1, 0, 3, 1, -1, 1, 3, 1, 0, 1, 1, 2, -1, 1, -1, | 79 | -3, -2, -2, 1, 2, -3, 0, 1, -5, -2, -3, 0, -2, -1, 2, 0, |
| 85 | -2, -1, 0, -1, 1, -1, 1, -2, -2, -1, -1, -3, 1, -4, -3, 1, | 80 | -1, -1, 0, -2, 1, 3, -7, -2, -2, -1, 2, -1, 0, 3, 1, 3, |
| 86 | },{ | 81 | 1, 0, 0, 1, 2, 3, 1, 2, 0, -2, -2, 1, 1, 2, 2, 3, |
| 87 | -2, 0, -2, 3, -1, -1, 0, 2, 2, -1, -3, 2, 1, 0, -2, -1, | 82 | 4, 1, -1, 2, -2, 4, 0, 0, 0, 4, 2, 0, -2, -2, 2, -4, |
| 88 | -3, -2, -2, 1, 2, -3, 0, 1, -5, -2, -3, 0, -2, -1, 2, 0, | 83 | -1, 5, -2, -2, -3, 2, -3, -1, 3, -3, 0, 4, 3, 0, 1, -2, } |
| 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 | } | ||
| 94 | }; | 84 | }; |
| 95 | 85 | ||
| 96 | #endif /* AVCODEC_SVQ1ENC_CB_H */ | 86 | #endif /* AVCODEC_SVQ1ENC_CB_H */ |
| @@ -1351,7 +1351,7 @@ static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y, · 1350 unmodified lines | |||
| 1351 | int px, py; | 1351 | int px, py; |
| 1352 | int sum; | 1352 | int sum; |
| 1353 | int mixedmv_pic, num_samefield = 0, num_oppfield = 0; | 1353 | 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; |
| 1355 | int16_t field_predA[2]; | 1355 | int16_t field_predA[2]; |
| 1356 | int16_t field_predB[2]; | 1356 | int16_t field_predB[2]; |
| 1357 | int16_t field_predC[2]; | 1357 | 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 | |||
| 1460 | 1460 | ||
| 1461 | if (v->field_mode) { | 1461 | if (v->field_mode) { |
| 1462 | if (num_samefield <= num_oppfield) | 1462 | if (num_samefield <= num_oppfield) |
| 1463 | opposit = 1 - pred_flag; | 1463 | opposite = 1 - pred_flag; |
| 1464 | else | 1464 | else |
| 1465 | opposit = pred_flag; | 1465 | opposite = pred_flag; |
| 1466 | } else | 1466 | } else |
| 1467 | opposit = 0; | 1467 | opposite = 0; |
| 1468 | if (opposit) { | 1468 | if (opposite) { |
| 1469 | if (a_valid && !a_f) { | 1469 | if (a_valid && !a_f) { |
| 1470 | field_predA[0] = scaleforopp(v, field_predA[0], 0, dir); | 1470 | field_predA[0] = scaleforopp(v, field_predA[0], 0, dir); |
| 1471 | field_predA[1] = scaleforopp(v, field_predA[1], 1, dir); | 1471 | field_predA[1] = scaleforopp(v, field_predA[1], 1, dir); |
| @@ -395,9 +395,24 @@ int avio_open2(AVIOContext **s, const char *url, int flags, · 394 unmodified lines | |||
| 395 | * resource. | 395 | * resource. |
| 396 | * | 396 | * |
| 397 | * @return 0 on success, an AVERROR < 0 on error. | 397 | * @return 0 on success, an AVERROR < 0 on error. |
| 398 | * @see avio_closep | ||
| 398 | */ | 399 | */ |
| 399 | int avio_close(AVIOContext *s); | 400 | int avio_close(AVIOContext *s); |
| 400 | 401 | ||
| 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 | |||
| 401 | /** | 416 | /** |
| 402 | * Open a write only memory stream. | 417 | * Open a write only memory stream. |
| 403 | * | 418 | * |
| @@ -803,6 +803,13 @@ int avio_close(AVIOContext *s) · 802 unmodified lines | |||
| 803 | return ffurl_close(h); | 803 | return ffurl_close(h); |
| 804 | } | 804 | } |
| 805 | 805 | ||
| 806 | int avio_closep(AVIOContext **s) | ||
| 807 | { | ||
| 808 | int ret = avio_close(*s); | ||
| 809 | *s = NULL; | ||
| 810 | return ret; | ||
| 811 | } | ||
| 812 | |||
| 806 | int avio_printf(AVIOContext *s, const char *fmt, ...) | 813 | int avio_printf(AVIOContext *s, const char *fmt, ...) |
| 807 | { | 814 | { |
| 808 | va_list ap; | 815 | va_list ap; |
| @@ -669,10 +669,10 @@ static int mpegts_write_header(AVFormatContext *s) · 668 unmodified lines | |||
| 669 | ts->sdt_packet_count = ts->sdt_packet_period-1; | 669 | ts->sdt_packet_count = ts->sdt_packet_period-1; |
| 670 | 670 | ||
| 671 | if (ts->mux_rate == 1) | 671 | if (ts->mux_rate == 1) |
| 672 | av_log(s, AV_LOG_INFO, "muxrate VBR, "); | 672 | av_log(s, AV_LOG_VERBOSE, "muxrate VBR, "); |
| 673 | else | 673 | else |
| 674 | av_log(s, AV_LOG_INFO, "muxrate %d, ", ts->mux_rate); | 674 | av_log(s, AV_LOG_VERBOSE, "muxrate %d, ", ts->mux_rate); |
| 675 | av_log(s, AV_LOG_INFO, "pcr every %d pkts, " | 675 | av_log(s, AV_LOG_VERBOSE, "pcr every %d pkts, " |
| 676 | "sdt every %d, pat/pmt every %d pkts\n", | 676 | "sdt every %d, pat/pmt every %d pkts\n", |
| 677 | service->pcr_packet_period, | 677 | service->pcr_packet_period, |
| 678 | ts->sdt_packet_period, ts->pat_packet_period); | 678 | ts->sdt_packet_period, ts->pat_packet_period); |
| @@ -30,7 +30,7 @@ · 29 unmodified lines | |||
| 30 | #include "libavutil/avutil.h" | 30 | #include "libavutil/avutil.h" |
| 31 | 31 | ||
| 32 | #define LIBAVFORMAT_VERSION_MAJOR 54 | 32 | #define LIBAVFORMAT_VERSION_MAJOR 54 |
| 33 | #define LIBAVFORMAT_VERSION_MINOR 31 | 33 | #define LIBAVFORMAT_VERSION_MINOR 32 |
| 34 | #define LIBAVFORMAT_VERSION_MICRO 100 | 34 | #define LIBAVFORMAT_VERSION_MICRO 100 |
| 35 | 35 | ||
| 36 | #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ | 36 | #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |
| @@ -723,8 +723,8 @@ int main(void) · 722 unmodified lines | |||
| 723 | int ret; | 723 | int ret; |
| 724 | AVRational q = (AVRational){0, 0}; | 724 | AVRational q = (AVRational){0, 0}; |
| 725 | ret = av_parse_video_rate(&q, rates[i]); | 725 | ret = av_parse_video_rate(&q, rates[i]); |
| 726 | printf("'%s' -> %d/%d%s\n", | 726 | printf("'%s' -> %d/%d %s\n", |
| 727 | rates[i], q.num, q.den, ret ? " error" : ""); | 727 | rates[i], q.num, q.den, ret ? "ERROR" : "OK"); |
| 728 | } | 728 | } |
| 729 | } | 729 | } |
| 730 | 730 | ||
| @@ -1,29 +1,29 @@ | |||
| 1 | Testing av_parse_video_rate() | 1 | Testing av_parse_video_rate() |
| 2 | '-inf' -> -1/0 error | 2 | '-inf' -> -1/0 ERROR |
| 3 | 'inf' -> 1/0 error | 3 | 'inf' -> 1/0 ERROR |
| 4 | 'nan' -> 0/0 error | 4 | 'nan' -> 0/0 ERROR |
| 5 | '123/0' -> 1/0 error | 5 | '123/0' -> 1/0 ERROR |
| 6 | '-123 / 0' -> -1/0 error | 6 | '-123 / 0' -> -1/0 ERROR |
| 7 | '' -> 0/0 error | 7 | '' -> 0/0 ERROR |
| 8 | '/' -> 0/0 error | 8 | '/' -> 0/0 ERROR |
| 9 | ' 123 / 321' -> 41/107 | 9 | ' 123 / 321' -> 41/107 OK |
| 10 | 'foo/foo' -> 0/0 error | 10 | 'foo/foo' -> 0/0 ERROR |
| 11 | 'foo/1' -> 0/0 error | 11 | 'foo/1' -> 0/0 ERROR |
| 12 | '1/foo' -> 1/0 error | 12 | '1/foo' -> 1/0 ERROR |
| 13 | '0/0' -> 0/0 error | 13 | '0/0' -> 0/0 ERROR |
| 14 | '/0' -> 0/0 error | 14 | '/0' -> 0/0 ERROR |
| 15 | '1/' -> 1/0 error | 15 | '1/' -> 1/0 ERROR |
| 16 | '1' -> 1/1 | 16 | '1' -> 1/1 OK |
| 17 | '0' -> 0/1 error | 17 | '0' -> 0/1 ERROR |
| 18 | '-123/123' -> -1/1 error | 18 | '-123/123' -> -1/1 ERROR |
| 19 | '-foo' -> 0/0 error | 19 | '-foo' -> 0/0 ERROR |
| 20 | '123.23' -> 12323/100 | 20 | '123.23' -> 12323/100 OK |
| 21 | '.23' -> 23/100 | 21 | '.23' -> 23/100 OK |
| 22 | '-.23' -> -23/100 error | 22 | '-.23' -> -23/100 ERROR |
| 23 | '-0.234' -> -117/500 error | 23 | '-0.234' -> -117/500 ERROR |
| 24 | '-0.0000001' -> 0/1 error | 24 | '-0.0000001' -> 0/1 ERROR |
| 25 | ' 21332.2324 ' -> 917286/43 | 25 | ' 21332.2324 ' -> 917286/43 OK |
| 26 | ' -21332.2324 ' -> -917286/43 error | 26 | ' -21332.2324 ' -> -917286/43 ERROR |
| 27 | 27 | ||
| 28 | Testing av_parse_color() | 28 | Testing av_parse_color() |
| 29 | bikeshed -> R(80) G(64) B(140) A(59) | 29 | bikeshed -> R(80) G(64) B(140) A(59) |