Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libavcodec/Makefile4
-rw-r--r--libavcodec/h261data.c155
-rw-r--r--libavcodec/h261data.h138
-rw-r--r--libavcodec/h261dec.c27
-rw-r--r--libavcodec/h261enc.c16
5 files changed, 188 insertions, 152 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index e8c2fd5dc3..9a0e75c1ad 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -184,9 +184,9 @@ OBJS-$(CONFIG_GIF_DECODER) += gifdec.o lzw.o
OBJS-$(CONFIG_GIF_ENCODER) += gif.o lzwenc.o
OBJS-$(CONFIG_GSM_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o
OBJS-$(CONFIG_GSM_MS_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o
-OBJS-$(CONFIG_H261_DECODER) += h261dec.o h261.o \
+OBJS-$(CONFIG_H261_DECODER) += h261dec.o h261.o h261data.o \
mpegvideo.o error_resilience.o
-OBJS-$(CONFIG_H261_ENCODER) += h261enc.o h261.o \
+OBJS-$(CONFIG_H261_ENCODER) += h261enc.o h261.o h261data.o \
mpegvideo_enc.o motion_est.o \
ratecontrol.o mpeg12data.o \
mpegvideo.o
diff --git a/libavcodec/h261data.c b/libavcodec/h261data.c
new file mode 100644
index 0000000000..a05161f4bc
--- /dev/null
+++ b/libavcodec/h261data.c
@@ -0,0 +1,155 @@
+/*
+ * copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ * copyright (c) 2004 Maarten Daniels
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * H.261 tables.
+ */
+
+#include <stdint.h>
+#include "h261.h"
+#include "h261data.h"
+
+// H.261 VLC table for macroblock addressing
+const uint8_t ff_h261_mba_code[35] = {
+ 1, 3, 2, 3,
+ 2, 3, 2, 7,
+ 6, 11, 10, 9,
+ 8, 7, 6, 23,
+ 22, 21, 20, 19,
+ 18, 35, 34, 33,
+ 32, 31, 30, 29,
+ 28, 27, 26, 25,
+ 24,
+ 15, //(MBA stuffing)
+ 1 //(start code)
+};
+
+const uint8_t ff_h261_mba_bits[35] = {
+ 1, 3, 3, 4,
+ 4, 5, 5, 7,
+ 7, 8, 8, 8,
+ 8, 8, 8, 10,
+ 10, 10, 10, 10,
+ 10, 11, 11, 11,
+ 11, 11, 11, 11,
+ 11, 11, 11, 11,
+ 11,
+ 11, //(MBA stuffing)
+ 16 //(start code)
+};
+
+//H.261 VLC table for macroblock type
+const uint8_t ff_h261_mtype_code[10] = {
+ 1, 1, 1, 1,
+ 1, 1, 1, 1,
+ 1, 1
+};
+
+const uint8_t ff_h261_mtype_bits[10] = {
+ 4, 7, 1, 5,
+ 9, 8, 10, 3,
+ 2, 6
+};
+
+const int ff_h261_mtype_map[10]= {
+ MB_TYPE_INTRA4x4,
+ MB_TYPE_INTRA4x4 | MB_TYPE_QUANT,
+ MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_CBP,
+ MB_TYPE_16x16,
+ MB_TYPE_CBP | MB_TYPE_16x16,
+ MB_TYPE_QUANT | MB_TYPE_CBP | MB_TYPE_16x16,
+ MB_TYPE_16x16 | MB_TYPE_H261_FIL,
+ MB_TYPE_CBP | MB_TYPE_16x16 | MB_TYPE_H261_FIL,
+ MB_TYPE_QUANT | MB_TYPE_CBP | MB_TYPE_16x16 | MB_TYPE_H261_FIL
+};
+
+//H.261 VLC table for motion vectors
+const uint8_t ff_h261_mv_tab[17][2] = {
+ {1,1}, {1,2}, {1,3}, {1,4}, {3,6}, {5,7}, {4,7}, {3,7},
+ {11,9}, {10,9}, {9,9}, {17,10}, {16,10}, {15,10}, {14,10}, {13,10}, {12,10}
+};
+
+//H.261 VLC table for coded block pattern
+const uint8_t ff_h261_cbp_tab[63][2] =
+{
+ {11,5}, {9,5}, {13,6}, {13,4}, {23,7}, {19,7}, {31,8}, {12,4},
+ {22,7}, {18,7}, {30,8}, {19,5}, {27,8}, {23,8}, {19,8}, {11,4},
+ {21,7}, {17,7}, {29,8}, {17,5}, {25,8}, {21,8}, {17,8}, {15,6},
+ {15,8}, {13,8}, {3,9}, {15,5}, {11,8}, {7,8}, {7,9}, {10,4},
+ {20,7}, {16,7}, {28,8}, {14,6}, {14,8}, {12,8}, {2,9}, {16,5},
+ {24,8}, {20,8}, {16,8}, {14,5}, {10,8}, {6,8}, {6,9}, {18,5},
+ {26,8}, {22,8}, {18,8}, {13,5}, {9,8}, {5,8}, {5,9}, {12,5},
+ {8,8}, {4,8}, {4,9}, {7,3}, {10,5}, {8,5}, {12,6}
+};
+
+//H.261 VLC table for transform coefficients
+static const uint16_t h261_tcoeff_vlc[65][2] = {
+{ 0x2, 2 }, { 0x3, 2 },{ 0x4, 4 },{ 0x5, 5 },
+{ 0x6, 7 },{ 0x26, 8 },{ 0x21, 8 },{ 0xa, 10 },
+{ 0x1d, 12 },{ 0x18, 12 },{ 0x13, 12 },{ 0x10 , 12 },
+{ 0x1a, 13},{ 0x19, 13 }, { 0x18, 13 }, { 0x17, 13 },
+{ 0x3, 3 }, { 0x6, 6 }, { 0x25 , 8 }, { 0xc, 10 },
+{ 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 0x5, 4},
+{ 0x4, 7}, { 0xb, 10 }, { 0x14, 12 }, { 0x14, 13 },
+{ 0x7, 5 }, { 0x24, 8 }, { 0x1c, 12 }, { 0x13, 13 },
+{ 0x6, 5 }, { 0xf, 10 }, { 0x12, 12}, { 0x7, 6},
+{ 0x9 , 10 }, { 0x12, 13 }, { 0x5, 6 }, { 0x1e, 12 },
+{ 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12},
+{ 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 },
+{ 0x23, 8 }, { 0x22, 8 }, { 0x20, 8 }, { 0xe , 10 },
+{ 0xd, 10 }, { 0x8, 10 },{ 0x1f, 12 }, { 0x1a, 12 },
+{ 0x19, 12 }, { 0x17, 12 }, { 0x16, 12}, { 0x1f, 13},
+{ 0x1e, 13 }, { 0x1d, 13 }, { 0x1c, 13}, { 0x1b, 13},
+{ 0x1, 6 } //escape
+};
+
+static const int8_t h261_tcoeff_level[64] = {
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15,
+ 1, 2, 3, 4, 5, 6, 7, 1,
+ 2, 3, 4, 5, 1, 2, 3, 4,
+ 1, 2, 3, 1, 2, 3, 1, 2,
+ 1, 2, 1, 2, 1, 2, 1, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1
+};
+
+static const int8_t h261_tcoeff_run[64] = {
+ 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 1, 1, 1, 1, 1, 2, 2,
+ 2, 2, 2, 3, 3, 3, 3, 4,
+ 4, 4, 5, 5, 5, 6, 6, 7,
+ 7, 8, 8, 9, 9, 10, 10, 11,
+ 12, 13, 14, 15, 16, 17, 18, 19,
+ 20, 21, 22, 23, 24, 25, 26
+};
+
+RLTable ff_h261_rl_tcoeff = {
+ 64,
+ 64,
+ h261_tcoeff_vlc,
+ h261_tcoeff_run,
+ h261_tcoeff_level,
+};
diff --git a/libavcodec/h261data.h b/libavcodec/h261data.h
index 82bae163df..e9e5244d15 100644
--- a/libavcodec/h261data.h
+++ b/libavcodec/h261data.h
@@ -30,135 +30,13 @@
#include <stdint.h>
#include "h261.h"
-// H.261 VLC table for macroblock addressing
-static const uint8_t h261_mba_code[35] = {
- 1, 3, 2, 3,
- 2, 3, 2, 7,
- 6, 11, 10, 9,
- 8, 7, 6, 23,
- 22, 21, 20, 19,
- 18, 35, 34, 33,
- 32, 31, 30, 29,
- 28, 27, 26, 25,
- 24,
- 15, //(MBA stuffing)
- 1 //(start code)
-};
-
-static const uint8_t h261_mba_bits[35] = {
- 1, 3, 3, 4,
- 4, 5, 5, 7,
- 7, 8, 8, 8,
- 8, 8, 8, 10,
- 10, 10, 10, 10,
- 10, 11, 11, 11,
- 11, 11, 11, 11,
- 11, 11, 11, 11,
- 11,
- 11, //(MBA stuffing)
- 16 //(start code)
-};
-
-//H.261 VLC table for macroblock type
-static const uint8_t h261_mtype_code[10] = {
- 1, 1, 1, 1,
- 1, 1, 1, 1,
- 1, 1
-};
-
-static const uint8_t h261_mtype_bits[10] = {
- 4, 7, 1, 5,
- 9, 8, 10, 3,
- 2, 6
-};
-
-static const int h261_mtype_map[10]= {
- MB_TYPE_INTRA4x4,
- MB_TYPE_INTRA4x4 | MB_TYPE_QUANT,
- MB_TYPE_CBP,
- MB_TYPE_QUANT | MB_TYPE_CBP,
- MB_TYPE_16x16,
- MB_TYPE_CBP | MB_TYPE_16x16,
- MB_TYPE_QUANT | MB_TYPE_CBP | MB_TYPE_16x16,
- MB_TYPE_16x16 | MB_TYPE_H261_FIL,
- MB_TYPE_CBP | MB_TYPE_16x16 | MB_TYPE_H261_FIL,
- MB_TYPE_QUANT | MB_TYPE_CBP | MB_TYPE_16x16 | MB_TYPE_H261_FIL
-};
-
-//H.261 VLC table for motion vectors
-static const uint8_t h261_mv_tab[17][2] = {
- {1,1}, {1,2}, {1,3}, {1,4}, {3,6}, {5,7}, {4,7}, {3,7},
- {11,9}, {10,9}, {9,9}, {17,10}, {16,10}, {15,10}, {14,10}, {13,10}, {12,10}
-};
-
-static const int mvmap[17] =
-{
- 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
-};
-
-//H.261 VLC table for coded block pattern
-static const uint8_t h261_cbp_tab[63][2] =
-{
- {11,5}, {9,5}, {13,6}, {13,4}, {23,7}, {19,7}, {31,8}, {12,4},
- {22,7}, {18,7}, {30,8}, {19,5}, {27,8}, {23,8}, {19,8}, {11,4},
- {21,7}, {17,7}, {29,8}, {17,5}, {25,8}, {21,8}, {17,8}, {15,6},
- {15,8}, {13,8}, {3,9}, {15,5}, {11,8}, {7,8}, {7,9}, {10,4},
- {20,7}, {16,7}, {28,8}, {14,6}, {14,8}, {12,8}, {2,9}, {16,5},
- {24,8}, {20,8}, {16,8}, {14,5}, {10,8}, {6,8}, {6,9}, {18,5},
- {26,8}, {22,8}, {18,8}, {13,5}, {9,8}, {5,8}, {5,9}, {12,5},
- {8,8}, {4,8}, {4,9}, {7,3}, {10,5}, {8,5}, {12,6}
-};
-
-//H.261 VLC table for transform coefficients
-static const uint16_t h261_tcoeff_vlc[65][2] = {
-{ 0x2, 2 }, { 0x3, 2 },{ 0x4, 4 },{ 0x5, 5 },
-{ 0x6, 7 },{ 0x26, 8 },{ 0x21, 8 },{ 0xa, 10 },
-{ 0x1d, 12 },{ 0x18, 12 },{ 0x13, 12 },{ 0x10 , 12 },
-{ 0x1a, 13},{ 0x19, 13 }, { 0x18, 13 }, { 0x17, 13 },
-{ 0x3, 3 }, { 0x6, 6 }, { 0x25 , 8 }, { 0xc, 10 },
-{ 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 0x5, 4},
-{ 0x4, 7}, { 0xb, 10 }, { 0x14, 12 }, { 0x14, 13 },
-{ 0x7, 5 }, { 0x24, 8 }, { 0x1c, 12 }, { 0x13, 13 },
-{ 0x6, 5 }, { 0xf, 10 }, { 0x12, 12}, { 0x7, 6},
-{ 0x9 , 10 }, { 0x12, 13 }, { 0x5, 6 }, { 0x1e, 12 },
-{ 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12},
-{ 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 },
-{ 0x23, 8 }, { 0x22, 8 }, { 0x20, 8 }, { 0xe , 10 },
-{ 0xd, 10 }, { 0x8, 10 },{ 0x1f, 12 }, { 0x1a, 12 },
-{ 0x19, 12 }, { 0x17, 12 }, { 0x16, 12}, { 0x1f, 13},
-{ 0x1e, 13 }, { 0x1d, 13 }, { 0x1c, 13}, { 0x1b, 13},
-{ 0x1, 6 } //escape
-};
-
-static const int8_t h261_tcoeff_level[64] = {
- 0, 1, 2, 3, 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 13, 14, 15,
- 1, 2, 3, 4, 5, 6, 7, 1,
- 2, 3, 4, 5, 1, 2, 3, 4,
- 1, 2, 3, 1, 2, 3, 1, 2,
- 1, 2, 1, 2, 1, 2, 1, 2,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1
-};
-
-static const int8_t h261_tcoeff_run[64] = {
- 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 1,
- 1, 1, 1, 1, 1, 1, 2, 2,
- 2, 2, 2, 3, 3, 3, 3, 4,
- 4, 4, 5, 5, 5, 6, 6, 7,
- 7, 8, 8, 9, 9, 10, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19,
- 20, 21, 22, 23, 24, 25, 26
-};
-
-static RLTable h261_rl_tcoeff = {
- 64,
- 64,
- h261_tcoeff_vlc,
- h261_tcoeff_run,
- h261_tcoeff_level,
-};
+extern const uint8_t ff_h261_mba_code[35];
+extern const uint8_t ff_h261_mba_bits[35];
+extern const uint8_t ff_h261_mtype_code[10];
+extern const uint8_t ff_h261_mtype_bits[10];
+extern const int ff_h261_mtype_map[10];
+extern const uint8_t ff_h261_mv_tab[17][2];
+extern const uint8_t ff_h261_cbp_tab[63][2];
+extern RLTable ff_h261_rl_tcoeff;
#endif /* AVCODEC_H261DATA_H */
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 967e859f6e..54571b6354 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -55,19 +55,19 @@ static av_cold void h261_decode_init_vlc(H261Context *h){
if(!done){
done = 1;
INIT_VLC_STATIC(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
- h261_mba_bits, 1, 1,
- h261_mba_code, 1, 1, 662);
+ ff_h261_mba_bits, 1, 1,
+ ff_h261_mba_code, 1, 1, 662);
INIT_VLC_STATIC(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
- h261_mtype_bits, 1, 1,
- h261_mtype_code, 1, 1, 80);
+ ff_h261_mtype_bits, 1, 1,
+ ff_h261_mtype_code, 1, 1, 80);
INIT_VLC_STATIC(&h261_mv_vlc, H261_MV_VLC_BITS, 17,
- &h261_mv_tab[0][1], 2, 1,
- &h261_mv_tab[0][0], 2, 1, 144);
+ &ff_h261_mv_tab[0][1], 2, 1,
+ &ff_h261_mv_tab[0][0], 2, 1, 144);
INIT_VLC_STATIC(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
- &h261_cbp_tab[0][1], 2, 1,
- &h261_cbp_tab[0][0], 2, 1, 512);
- ff_init_rl(&h261_rl_tcoeff, ff_h261_rl_table_store);
- INIT_VLC_RL(h261_rl_tcoeff, 552);
+ &ff_h261_cbp_tab[0][1], 2, 1,
+ &ff_h261_cbp_tab[0][0], 2, 1, 512);
+ ff_init_rl(&ff_h261_rl_tcoeff, ff_h261_rl_table_store);
+ INIT_VLC_RL(ff_h261_rl_tcoeff, 552);
}
}
@@ -228,6 +228,9 @@ static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2 )
}
static int decode_mv_component(GetBitContext *gb, int v){
+ static const int mvmap[17] = {
+ 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
+ };
int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);
/* check if mv_diff is valid */
@@ -290,7 +293,7 @@ static int h261_decode_mb(H261Context *h){
av_log(s->avctx, AV_LOG_ERROR, "illegal mtype %d\n", h->mtype);
return SLICE_ERROR;
}
- h->mtype = h261_mtype_map[h->mtype];
+ h->mtype = ff_h261_mtype_map[h->mtype];
// Read mquant
if ( IS_QUANT ( h->mtype ) ){
@@ -367,7 +370,7 @@ static int h261_decode_block(H261Context * h, DCTELEM * block,
{
MpegEncContext * const s = &h->s;
int code, level, i, j, run;
- RLTable *rl = &h261_rl_tcoeff;
+ RLTable *rl = &ff_h261_rl_tcoeff;
const uint8_t *scan_table;
// For the variable length encoding there are two code tables, one being used for
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index df97dc1988..a91652cd43 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -128,7 +128,7 @@ static void h261_encode_motion(H261Context * h, int val){
int sign, code;
if(val==0){
code = 0;
- put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]);
+ put_bits(&s->pb,ff_h261_mv_tab[code][1],ff_h261_mv_tab[code][0]);
}
else{
if(val > 15)
@@ -137,7 +137,7 @@ static void h261_encode_motion(H261Context * h, int val){
val+=32;
sign = val < 0;
code = sign ? -val : val;
- put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]);
+ put_bits(&s->pb,ff_h261_mv_tab[code][1],ff_h261_mv_tab[code][0]);
put_bits(&s->pb,1,sign);
}
}
@@ -182,7 +182,7 @@ void ff_h261_encode_mb(MpegEncContext * s,
}
/* MB is not skipped, encode MBA */
- put_bits(&s->pb, h261_mba_bits[(h->current_mba-h->previous_mba)-1], h261_mba_code[(h->current_mba-h->previous_mba)-1]);
+ put_bits(&s->pb, ff_h261_mba_bits[(h->current_mba-h->previous_mba)-1], ff_h261_mba_code[(h->current_mba-h->previous_mba)-1]);
/* calculate MTYPE */
if(!s->mb_intra){
@@ -200,9 +200,9 @@ void ff_h261_encode_mb(MpegEncContext * s,
if(s->dquant)
h->mtype++;
- put_bits(&s->pb, h261_mtype_bits[h->mtype], h261_mtype_code[h->mtype]);
+ put_bits(&s->pb, ff_h261_mtype_bits[h->mtype], ff_h261_mtype_code[h->mtype]);
- h->mtype = h261_mtype_map[h->mtype];
+ h->mtype = ff_h261_mtype_map[h->mtype];
if(IS_QUANT(h->mtype)){
ff_set_qscale(s,s->qscale+s->dquant);
@@ -222,7 +222,7 @@ void ff_h261_encode_mb(MpegEncContext * s,
if(HAS_CBP(h->mtype)){
assert(cbp>0);
- put_bits(&s->pb,h261_cbp_tab[cbp-1][1],h261_cbp_tab[cbp-1][0]);
+ put_bits(&s->pb,ff_h261_cbp_tab[cbp-1][1],ff_h261_cbp_tab[cbp-1][0]);
}
for(i=0; i<6; i++) {
/* encode each block */
@@ -240,7 +240,7 @@ void ff_h261_encode_init(MpegEncContext *s){
if (!done) {
done = 1;
- ff_init_rl(&h261_rl_tcoeff, ff_h261_rl_table_store);
+ ff_init_rl(&ff_h261_rl_tcoeff, ff_h261_rl_table_store);
}
s->min_qcoeff= -127;
@@ -260,7 +260,7 @@ static void h261_encode_block(H261Context * h, DCTELEM * block, int n){
int level, run, i, j, last_index, last_non_zero, sign, slevel, code;
RLTable *rl;
- rl = &h261_rl_tcoeff;
+ rl = &ff_h261_rl_tcoeff;
if (s->mb_intra) {
/* DC coef */
level = block[0];