annotate h263dec.c @ 134:2c469e390117 libavcodec

dering in c dering bugfix
author michael
date Fri, 26 Oct 2001 00:35:41 +0000
parents cdd89f96cbe1
children cb5dabd00ba2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
2 * H263 decoder
986e461dc072 Initial revision
glantau
parents:
diff changeset
3 * Copyright (c) 2001 Gerard Lantau.
986e461dc072 Initial revision
glantau
parents:
diff changeset
4 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
986e461dc072 Initial revision
glantau
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
986e461dc072 Initial revision
glantau
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
986e461dc072 Initial revision
glantau
parents:
diff changeset
8 * (at your option) any later version.
986e461dc072 Initial revision
glantau
parents:
diff changeset
9 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
986e461dc072 Initial revision
glantau
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
986e461dc072 Initial revision
glantau
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
986e461dc072 Initial revision
glantau
parents:
diff changeset
13 * GNU General Public License for more details.
986e461dc072 Initial revision
glantau
parents:
diff changeset
14 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
986e461dc072 Initial revision
glantau
parents:
diff changeset
16 * along with this program; if not, write to the Free Software
986e461dc072 Initial revision
glantau
parents:
diff changeset
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
986e461dc072 Initial revision
glantau
parents:
diff changeset
18 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
19 #include <stdlib.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
20 #include <stdio.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
21 #include <string.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
22 #include "dsputil.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
23 #include "avcodec.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
24 #include "mpegvideo.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
25
986e461dc072 Initial revision
glantau
parents:
diff changeset
26 //#define DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
27
986e461dc072 Initial revision
glantau
parents:
diff changeset
28 static int h263_decode_init(AVCodecContext *avctx)
986e461dc072 Initial revision
glantau
parents:
diff changeset
29 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
30 MpegEncContext *s = avctx->priv_data;
60
35c1141e23d9 moved matrix init away from MPV_common_init()
glantau
parents: 56
diff changeset
31 int i;
35c1141e23d9 moved matrix init away from MPV_common_init()
glantau
parents: 56
diff changeset
32
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
33 s->avctx = avctx;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
34 s->out_format = FMT_H263;
986e461dc072 Initial revision
glantau
parents:
diff changeset
35
986e461dc072 Initial revision
glantau
parents:
diff changeset
36 s->width = avctx->width;
986e461dc072 Initial revision
glantau
parents:
diff changeset
37 s->height = avctx->height;
986e461dc072 Initial revision
glantau
parents:
diff changeset
38
986e461dc072 Initial revision
glantau
parents:
diff changeset
39 /* select sub codec */
986e461dc072 Initial revision
glantau
parents:
diff changeset
40 switch(avctx->codec->id) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
41 case CODEC_ID_H263:
986e461dc072 Initial revision
glantau
parents:
diff changeset
42 break;
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
43 case CODEC_ID_MPEG4:
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
44 s->time_increment_bits = 4; /* default value for broken headers */
986e461dc072 Initial revision
glantau
parents:
diff changeset
45 s->h263_pred = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
46 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
47 case CODEC_ID_MSMPEG4:
986e461dc072 Initial revision
glantau
parents:
diff changeset
48 s->h263_msmpeg4 = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
49 s->h263_pred = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
51 case CODEC_ID_H263I:
986e461dc072 Initial revision
glantau
parents:
diff changeset
52 s->h263_intel = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
53 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
54 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
55 return -1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
56 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
57
986e461dc072 Initial revision
glantau
parents:
diff changeset
58 /* for h263, we allocate the images after having read the header */
986e461dc072 Initial revision
glantau
parents:
diff changeset
59 if (MPV_common_init(s) < 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
60 return -1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
61
60
35c1141e23d9 moved matrix init away from MPV_common_init()
glantau
parents: 56
diff changeset
62 /* XXX: suppress this matrix init, only needed because using mpeg1
35c1141e23d9 moved matrix init away from MPV_common_init()
glantau
parents: 56
diff changeset
63 dequantize in mmx case */
35c1141e23d9 moved matrix init away from MPV_common_init()
glantau
parents: 56
diff changeset
64 for(i=0;i<64;i++)
35c1141e23d9 moved matrix init away from MPV_common_init()
glantau
parents: 56
diff changeset
65 s->non_intra_matrix[i] = default_non_intra_matrix[i];
35c1141e23d9 moved matrix init away from MPV_common_init()
glantau
parents: 56
diff changeset
66
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
67 if (s->h263_msmpeg4)
986e461dc072 Initial revision
glantau
parents:
diff changeset
68 msmpeg4_decode_init_vlc(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
69 else
986e461dc072 Initial revision
glantau
parents:
diff changeset
70 h263_decode_init_vlc(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
71
986e461dc072 Initial revision
glantau
parents:
diff changeset
72 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
73 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
74
986e461dc072 Initial revision
glantau
parents:
diff changeset
75 static int h263_decode_end(AVCodecContext *avctx)
986e461dc072 Initial revision
glantau
parents:
diff changeset
76 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
77 MpegEncContext *s = avctx->priv_data;
986e461dc072 Initial revision
glantau
parents:
diff changeset
78
986e461dc072 Initial revision
glantau
parents:
diff changeset
79 MPV_common_end(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
80 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
81 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
82
986e461dc072 Initial revision
glantau
parents:
diff changeset
83 static int h263_decode_frame(AVCodecContext *avctx,
986e461dc072 Initial revision
glantau
parents:
diff changeset
84 void *data, int *data_size,
986e461dc072 Initial revision
glantau
parents:
diff changeset
85 UINT8 *buf, int buf_size)
986e461dc072 Initial revision
glantau
parents:
diff changeset
86 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
87 MpegEncContext *s = avctx->priv_data;
986e461dc072 Initial revision
glantau
parents:
diff changeset
88 int ret;
986e461dc072 Initial revision
glantau
parents:
diff changeset
89 AVPicture *pict = data;
986e461dc072 Initial revision
glantau
parents:
diff changeset
90
986e461dc072 Initial revision
glantau
parents:
diff changeset
91 #ifdef DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
92 printf("*****frame %d size=%d\n", avctx->frame_number, buf_size);
986e461dc072 Initial revision
glantau
parents:
diff changeset
93 printf("bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
94 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
95
986e461dc072 Initial revision
glantau
parents:
diff changeset
96 /* no supplementary picture */
986e461dc072 Initial revision
glantau
parents:
diff changeset
97 if (buf_size == 0) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
98 *data_size = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
99 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
100 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
101
986e461dc072 Initial revision
glantau
parents:
diff changeset
102 init_get_bits(&s->gb, buf, buf_size);
986e461dc072 Initial revision
glantau
parents:
diff changeset
103
986e461dc072 Initial revision
glantau
parents:
diff changeset
104 /* let's go :-) */
986e461dc072 Initial revision
glantau
parents:
diff changeset
105 if (s->h263_msmpeg4) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
106 ret = msmpeg4_decode_picture_header(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
107 } else if (s->h263_pred) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
108 ret = mpeg4_decode_picture_header(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
109 } else if (s->h263_intel) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
110 ret = intel_h263_decode_picture_header(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
111 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
112 ret = h263_decode_picture_header(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
113 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
114 if (ret < 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
115 return -1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
116
986e461dc072 Initial revision
glantau
parents:
diff changeset
117 MPV_frame_start(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
118
986e461dc072 Initial revision
glantau
parents:
diff changeset
119 #ifdef DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
120 printf("qscale=%d\n", s->qscale);
986e461dc072 Initial revision
glantau
parents:
diff changeset
121 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
122
986e461dc072 Initial revision
glantau
parents:
diff changeset
123 /* decode each macroblock */
986e461dc072 Initial revision
glantau
parents:
diff changeset
124 for(s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
125 for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
126 #ifdef DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
127 printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y);
986e461dc072 Initial revision
glantau
parents:
diff changeset
128 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
129 /* DCT & quantize */
986e461dc072 Initial revision
glantau
parents:
diff changeset
130 if (s->h263_msmpeg4) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
131 msmpeg4_dc_scale(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
132 } else if (s->h263_pred) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
133 h263_dc_scale(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
134 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
135 /* default quantization values */
986e461dc072 Initial revision
glantau
parents:
diff changeset
136 s->y_dc_scale = 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
137 s->c_dc_scale = 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
138 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
139
12
4d50c7d89e0f use block[] in structure to have it aligned on 8 bytes for mmx optimizations
glantau
parents: 0
diff changeset
140 memset(s->block, 0, sizeof(s->block));
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
141 s->mv_dir = MV_DIR_FORWARD;
986e461dc072 Initial revision
glantau
parents:
diff changeset
142 s->mv_type = MV_TYPE_16X16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
143 if (s->h263_msmpeg4) {
12
4d50c7d89e0f use block[] in structure to have it aligned on 8 bytes for mmx optimizations
glantau
parents: 0
diff changeset
144 if (msmpeg4_decode_mb(s, s->block) < 0)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
145 return -1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
146 } else {
12
4d50c7d89e0f use block[] in structure to have it aligned on 8 bytes for mmx optimizations
glantau
parents: 0
diff changeset
147 if (h263_decode_mb(s, s->block) < 0)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
148 return -1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
149 }
12
4d50c7d89e0f use block[] in structure to have it aligned on 8 bytes for mmx optimizations
glantau
parents: 0
diff changeset
150 MPV_decode_mb(s, s->block);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
151 }
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
152 if (avctx->draw_horiz_band) {
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
153 UINT8 *src_ptr[3];
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
154 int y, h, offset;
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
155 y = s->mb_y * 16;
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
156 h = s->height - y;
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
157 if (h > 16)
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
158 h = 16;
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
159 offset = y * s->linesize;
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
160 src_ptr[0] = s->current_picture[0] + offset;
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
161 src_ptr[1] = s->current_picture[1] + (offset >> 2);
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
162 src_ptr[2] = s->current_picture[2] + (offset >> 2);
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
163 avctx->draw_horiz_band(avctx, src_ptr, s->linesize,
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
164 y, s->width, h);
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
165 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
166 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
167
986e461dc072 Initial revision
glantau
parents:
diff changeset
168 MPV_frame_end(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
169
986e461dc072 Initial revision
glantau
parents:
diff changeset
170 pict->data[0] = s->current_picture[0];
986e461dc072 Initial revision
glantau
parents:
diff changeset
171 pict->data[1] = s->current_picture[1];
986e461dc072 Initial revision
glantau
parents:
diff changeset
172 pict->data[2] = s->current_picture[2];
986e461dc072 Initial revision
glantau
parents:
diff changeset
173 pict->linesize[0] = s->linesize;
986e461dc072 Initial revision
glantau
parents:
diff changeset
174 pict->linesize[1] = s->linesize / 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
175 pict->linesize[2] = s->linesize / 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
176
986e461dc072 Initial revision
glantau
parents:
diff changeset
177 avctx->quality = s->qscale;
986e461dc072 Initial revision
glantau
parents:
diff changeset
178 *data_size = sizeof(AVPicture);
986e461dc072 Initial revision
glantau
parents:
diff changeset
179 return buf_size;
986e461dc072 Initial revision
glantau
parents:
diff changeset
180 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
181
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
182 AVCodec mpeg4_decoder = {
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
183 "mpeg4",
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
184 CODEC_TYPE_VIDEO,
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
185 CODEC_ID_MPEG4,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
186 sizeof(MpegEncContext),
986e461dc072 Initial revision
glantau
parents:
diff changeset
187 h263_decode_init,
986e461dc072 Initial revision
glantau
parents:
diff changeset
188 NULL,
986e461dc072 Initial revision
glantau
parents:
diff changeset
189 h263_decode_end,
986e461dc072 Initial revision
glantau
parents:
diff changeset
190 h263_decode_frame,
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
191 CODEC_CAP_DRAW_HORIZ_BAND,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
192 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
193
986e461dc072 Initial revision
glantau
parents:
diff changeset
194 AVCodec h263_decoder = {
986e461dc072 Initial revision
glantau
parents:
diff changeset
195 "h263",
986e461dc072 Initial revision
glantau
parents:
diff changeset
196 CODEC_TYPE_VIDEO,
986e461dc072 Initial revision
glantau
parents:
diff changeset
197 CODEC_ID_H263,
986e461dc072 Initial revision
glantau
parents:
diff changeset
198 sizeof(MpegEncContext),
986e461dc072 Initial revision
glantau
parents:
diff changeset
199 h263_decode_init,
986e461dc072 Initial revision
glantau
parents:
diff changeset
200 NULL,
986e461dc072 Initial revision
glantau
parents:
diff changeset
201 h263_decode_end,
986e461dc072 Initial revision
glantau
parents:
diff changeset
202 h263_decode_frame,
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
203 CODEC_CAP_DRAW_HORIZ_BAND,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
204 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
205
986e461dc072 Initial revision
glantau
parents:
diff changeset
206 AVCodec msmpeg4_decoder = {
986e461dc072 Initial revision
glantau
parents:
diff changeset
207 "msmpeg4",
986e461dc072 Initial revision
glantau
parents:
diff changeset
208 CODEC_TYPE_VIDEO,
986e461dc072 Initial revision
glantau
parents:
diff changeset
209 CODEC_ID_MSMPEG4,
986e461dc072 Initial revision
glantau
parents:
diff changeset
210 sizeof(MpegEncContext),
986e461dc072 Initial revision
glantau
parents:
diff changeset
211 h263_decode_init,
986e461dc072 Initial revision
glantau
parents:
diff changeset
212 NULL,
986e461dc072 Initial revision
glantau
parents:
diff changeset
213 h263_decode_end,
986e461dc072 Initial revision
glantau
parents:
diff changeset
214 h263_decode_frame,
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
215 CODEC_CAP_DRAW_HORIZ_BAND,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
216 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
217
986e461dc072 Initial revision
glantau
parents:
diff changeset
218 AVCodec h263i_decoder = {
986e461dc072 Initial revision
glantau
parents:
diff changeset
219 "h263i",
986e461dc072 Initial revision
glantau
parents:
diff changeset
220 CODEC_TYPE_VIDEO,
986e461dc072 Initial revision
glantau
parents:
diff changeset
221 CODEC_ID_H263I,
986e461dc072 Initial revision
glantau
parents:
diff changeset
222 sizeof(MpegEncContext),
986e461dc072 Initial revision
glantau
parents:
diff changeset
223 h263_decode_init,
986e461dc072 Initial revision
glantau
parents:
diff changeset
224 NULL,
986e461dc072 Initial revision
glantau
parents:
diff changeset
225 h263_decode_end,
986e461dc072 Initial revision
glantau
parents:
diff changeset
226 h263_decode_frame,
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
227 CODEC_CAP_DRAW_HORIZ_BAND,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
228 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
229