提交 c6148de2 编写于 作者: M Michael Niedermayer

h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)

Originally committed as revision 3176 to svn://svn.ffmpeg.org/ffmpeg/trunk
上级 20646267
......@@ -55,7 +55,7 @@ ASM_OBJS=
# codecs which are patented in some non free countries like the us
ifeq ($(CONFIG_RISKY),yes)
OBJS+= h263.o msmpeg4.o h263dec.o svq1.o rv10.o wmadec.o indeo3.o
OBJS+= h263.o h261.o msmpeg4.o h263dec.o svq1.o rv10.o wmadec.o indeo3.o
endif
ifeq ($(HAVE_XVMC_ACCEL),yes)
......
......@@ -84,6 +84,7 @@ void avcodec_register_all(void)
#ifdef CONFIG_DECODERS
#ifdef CONFIG_RISKY
register_avcodec(&h263_decoder);
register_avcodec(&h261_decoder);
register_avcodec(&mpeg4_decoder);
register_avcodec(&msmpeg4v1_decoder);
register_avcodec(&msmpeg4v2_decoder);
......@@ -213,6 +214,7 @@ PCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_g726);
/* parsers */
av_register_codec_parser(&mpegvideo_parser);
av_register_codec_parser(&mpeg4video_parser);
av_register_codec_parser(&h261_parser);
av_register_codec_parser(&h263_parser);
av_register_codec_parser(&h264_parser);
......
......@@ -34,6 +34,7 @@ enum CodecID {
CODEC_ID_MPEG1VIDEO,
CODEC_ID_MPEG2VIDEO, /* prefered ID for MPEG Video 1 or 2 decoding */
CODEC_ID_MPEG2VIDEO_XVMC,
CODEC_ID_H261,
CODEC_ID_H263,
CODEC_ID_RV10,
CODEC_ID_RV20,
......@@ -1724,6 +1725,7 @@ extern AVCodec zlib_encoder;
extern AVCodec svq1_encoder;
extern AVCodec h263_decoder;
extern AVCodec h261_decoder;
extern AVCodec mpeg4_decoder;
extern AVCodec msmpeg4v1_decoder;
extern AVCodec msmpeg4v2_decoder;
......@@ -2124,6 +2126,7 @@ void av_parser_close(AVCodecParserContext *s);
extern AVCodecParser mpegvideo_parser;
extern AVCodecParser mpeg4video_parser;
extern AVCodecParser h261_parser;
extern AVCodecParser h263_parser;
extern AVCodecParser h264_parser;
extern AVCodecParser mpegaudio_parser;
......
......@@ -2360,6 +2360,36 @@ static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
}
}
static void h261_v_loop_filter_c(uint8_t *dest,uint8_t *src, int stride){
int i,j,xy,yz;
int res;
for(i=0; i<8; i++){
for(j=1; j<7; j++){
xy = j * stride + i;
yz = j * 8 + i;
res = (int)src[yz-1*8] + ((int)(src[yz+0*8]) * 2) + (int)src[yz+1*8];
res +=2;
res >>=2;
dest[xy] = (uint8_t)res;
}
}
}
static void h261_h_loop_filter_c(uint8_t *dest,uint8_t *src, int stride){
int i,j,xy,yz;
int res;
for(i=1; i<7; i++){
for(j=0; j<8; j++){
xy = j * stride + i;
yz = j * 8 + i;
res = (int)src[yz-1] + ((int)(src[yz]) *2) + (int)src[yz+1];
res+=2;
res>>=2;
dest[xy] = (uint8_t)res;
}
}
}
static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
{
int s, i;
......@@ -3295,6 +3325,9 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
c->h263_h_loop_filter= h263_h_loop_filter_c;
c->h263_v_loop_filter= h263_v_loop_filter_c;
c->h261_h_loop_filter= h261_h_loop_filter_c;
c->h261_v_loop_filter= h261_v_loop_filter_c;
c->try_8x8basis= try_8x8basis_c;
c->add_8x8basis= add_8x8basis_c;
......
......@@ -261,6 +261,9 @@ typedef struct DSPContext {
void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
void (*h261_v_loop_filter)(uint8_t *dest,uint8_t *src, int stride);
void (*h261_h_loop_filter)(uint8_t *dest,uint8_t *src, int stride);
/* (I)DCT */
void (*fdct)(DCTELEM *block/* align 16*/);
void (*fdct248)(DCTELEM *block/* align 16*/);
......
此差异已折叠。
/**
* @file h261data.h
* H.261 tables.
*/
#define MB_TYPE_H261_FIL 0x800000
// H.261 VLC table for macroblock addressing
const uint8_t h261_mba_code[34] = {
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)
};
const uint8_t h261_mba_bits[34] = {
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)
};
//H.261 VLC table for macroblock type
const uint8_t h261_mtype_code[10] = {
1, 1, 1, 1,
1, 1, 1, 1,
1, 1
};
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
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
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
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
};
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
};
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,
};
......@@ -53,6 +53,10 @@ static void dct_unquantize_h263_intra_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
static void dct_unquantize_h263_inter_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
static void dct_unquantize_h261_intra_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
static void dct_unquantize_h261_inter_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w);
#ifdef CONFIG_ENCODERS
static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
......@@ -215,6 +219,8 @@ int DCT_common_init(MpegEncContext *s)
{
s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c;
s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c;
s->dct_unquantize_h261_intra = dct_unquantize_h261_intra_c;
s->dct_unquantize_h261_inter = dct_unquantize_h261_inter_c;
s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c;
s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c;
s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c;
......@@ -1454,6 +1460,9 @@ alloc:
}else if(s->out_format == FMT_H263){
s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
}else if(s->out_format == FMT_H261){
s->dct_unquantize_intra = s->dct_unquantize_h261_intra;
s->dct_unquantize_inter = s->dct_unquantize_h261_inter;
}else{
s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra;
s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;
......@@ -2494,6 +2503,12 @@ if(s->quarter_sample)
uvsrc_x = src_x>>1;
uvsrc_y = src_y>>1;
}
}else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261
mx = motion_x / 4;
my = motion_y / 4;
uvdxy = 0;
uvsrc_x = s->mb_x*8 + mx;
uvsrc_y = s->mb_y*8 + my;
} else {
mx = motion_x / 2;
my = motion_y / 2;
......@@ -5782,6 +5797,59 @@ static void dct_unquantize_h263_inter_c(MpegEncContext *s,
}
}
static void dct_unquantize_h261_intra_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale)
{
int i, level, odd;
int nCoeffs;
assert(s->block_last_index[n]>=0);
if (n < 4)
block[0] = block[0] * s->y_dc_scale;
else
block[0] = block[0] * s->c_dc_scale;
odd = qscale & 0x1;
nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
for(i=1; i<=nCoeffs; i++){
level = block[i];
if (level){
if (level < 0){
level = qscale * ((level << 1) - 1) + (~odd);
}else{
level = qscale * ((level << 1) + 1) - (~odd);
}
}
block[i] = level;
}
}
static void dct_unquantize_h261_inter_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale)
{
int i, level, odd;
int nCoeffs;
assert(s->block_last_index[n]>=0);
odd = qscale & 0x1;
nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
for(i=0; i<=nCoeffs; i++){
level = block[i];
if (level){
if (level < 0){
level = qscale * ((level << 1) - 1) + (~odd);
}else{
level = qscale * ((level << 1) + 1) - (~odd);
}
}
block[i] = level;
}
}
static const AVOption mpeg4_options[] =
{
AVOPTION_CODEC_INT("bitrate", "desired video bitrate", bit_rate, 4, 240000000, 800000),
......
......@@ -32,6 +32,7 @@
enum OutputFormat {
FMT_MPEG1,
FMT_H261,
FMT_H263,
FMT_MJPEG,
FMT_H264,
......@@ -703,6 +704,10 @@ typedef struct MpegEncContext {
DCTELEM *block/*align 16*/, int n, int qscale);
void (*dct_unquantize_h263_inter)(struct MpegEncContext *s,
DCTELEM *block/*align 16*/, int n, int qscale);
void (*dct_unquantize_h261_intra)(struct MpegEncContext *s,
DCTELEM *block/*align 16*/, int n, int qscale);
void (*dct_unquantize_h261_inter)(struct MpegEncContext *s,
DCTELEM *block/*align 16*/, int n, int qscale);
void (*dct_unquantize_intra)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both)
DCTELEM *block/*align 16*/, int n, int qscale);
void (*dct_unquantize_inter)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both)
......
......@@ -259,6 +259,21 @@ static int h263_probe(AVProbeData *p)
return 0;
}
static int h261_probe(AVProbeData *p)
{
int code;
const uint8_t *d;
if (p->buf_size < 6)
return 0;
d = p->buf;
code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
if (code == 0x10) {
return 50;
}
return 0;
}
AVInputFormat ac3_iformat = {
"ac3",
"raw ac3",
......@@ -285,6 +300,18 @@ AVOutputFormat ac3_oformat = {
};
#endif //CONFIG_ENCODERS
AVInputFormat h261_iformat = {
"h261",
"raw h261",
0,
h261_probe,
video_read_header,
raw_read_partial_packet,
raw_read_close,
.extensions = "h261",
.value = CODEC_ID_H261,
};
AVInputFormat h263_iformat = {
"h263",
"raw h263",
......@@ -586,6 +613,8 @@ int raw_init(void)
av_register_input_format(&ac3_iformat);
av_register_output_format(&ac3_oformat);
av_register_input_format(&h261_iformat);
av_register_input_format(&h263_iformat);
av_register_output_format(&h263_oformat);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册