Mercurial > libavcodec.hg
annotate h263dec.c @ 248:56ee684c48bb libavcodec
- H.263+ decoder support for Advanded INTRA Coding (buggy)
author | pulento |
---|---|
date | Mon, 18 Feb 2002 19:33:27 +0000 |
parents | d1a9663b973b |
children | 42a0b7b16738 |
rev | line source |
---|---|
0 | 1 /* |
2 * H263 decoder | |
3 * Copyright (c) 2001 Gerard Lantau. | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License as published by | |
7 * the Free Software Foundation; either version 2 of the License, or | |
8 * (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program; if not, write to the Free Software | |
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 */ | |
19 #include <stdlib.h> | |
20 #include <stdio.h> | |
21 #include <string.h> | |
22 #include "dsputil.h" | |
23 #include "avcodec.h" | |
24 #include "mpegvideo.h" | |
25 | |
26 //#define DEBUG | |
27 | |
28 static int h263_decode_init(AVCodecContext *avctx) | |
29 { | |
30 MpegEncContext *s = avctx->priv_data; | |
60 | 31 int i; |
32 | |
67 | 33 s->avctx = avctx; |
0 | 34 s->out_format = FMT_H263; |
35 | |
36 s->width = avctx->width; | |
37 s->height = avctx->height; | |
38 | |
39 /* select sub codec */ | |
40 switch(avctx->codec->id) { | |
41 case CODEC_ID_H263: | |
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
42 s->gob_number = 0; |
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
43 s->first_gob_line = 0; |
0 | 44 break; |
67 | 45 case CODEC_ID_MPEG4: |
0 | 46 s->time_increment_bits = 4; /* default value for broken headers */ |
47 s->h263_pred = 1; | |
48 break; | |
49 case CODEC_ID_MSMPEG4: | |
50 s->h263_msmpeg4 = 1; | |
51 s->h263_pred = 1; | |
52 break; | |
53 case CODEC_ID_H263I: | |
54 s->h263_intel = 1; | |
55 break; | |
56 default: | |
57 return -1; | |
58 } | |
59 | |
60 /* for h263, we allocate the images after having read the header */ | |
144 | 61 if (avctx->codec->id != CODEC_ID_H263) |
62 if (MPV_common_init(s) < 0) | |
63 return -1; | |
0 | 64 |
60 | 65 /* XXX: suppress this matrix init, only needed because using mpeg1 |
66 dequantize in mmx case */ | |
67 for(i=0;i<64;i++) | |
68 s->non_intra_matrix[i] = default_non_intra_matrix[i]; | |
69 | |
0 | 70 if (s->h263_msmpeg4) |
71 msmpeg4_decode_init_vlc(s); | |
72 else | |
73 h263_decode_init_vlc(s); | |
74 | |
75 return 0; | |
76 } | |
77 | |
78 static int h263_decode_end(AVCodecContext *avctx) | |
79 { | |
80 MpegEncContext *s = avctx->priv_data; | |
81 | |
82 MPV_common_end(s); | |
83 return 0; | |
84 } | |
85 | |
86 static int h263_decode_frame(AVCodecContext *avctx, | |
87 void *data, int *data_size, | |
88 UINT8 *buf, int buf_size) | |
89 { | |
90 MpegEncContext *s = avctx->priv_data; | |
91 int ret; | |
92 AVPicture *pict = data; | |
93 | |
94 #ifdef DEBUG | |
95 printf("*****frame %d size=%d\n", avctx->frame_number, buf_size); | |
96 printf("bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]); | |
97 #endif | |
144 | 98 |
0 | 99 /* no supplementary picture */ |
100 if (buf_size == 0) { | |
101 *data_size = 0; | |
102 return 0; | |
103 } | |
104 | |
105 init_get_bits(&s->gb, buf, buf_size); | |
106 | |
107 /* let's go :-) */ | |
108 if (s->h263_msmpeg4) { | |
109 ret = msmpeg4_decode_picture_header(s); | |
110 } else if (s->h263_pred) { | |
111 ret = mpeg4_decode_picture_header(s); | |
112 } else if (s->h263_intel) { | |
113 ret = intel_h263_decode_picture_header(s); | |
114 } else { | |
115 ret = h263_decode_picture_header(s); | |
160 | 116 /* After H263 header decode we have the height, width, */ |
117 /* and other parameters. So then we could init the picture */ | |
118 /* FIXME: By the way H263 decoder is evolving it should have */ | |
119 /* an H263EncContext */ | |
120 if (!s->context_initialized) { | |
144 | 121 avctx->width = s->width; |
122 avctx->height = s->height; | |
160 | 123 if (MPV_common_init(s) < 0) |
124 return -1; | |
125 } else if (s->width != avctx->width || s->height != avctx->height) { | |
126 /* H.263 could change picture size any time */ | |
127 MPV_common_end(s); | |
144 | 128 if (MPV_common_init(s) < 0) |
129 return -1; | |
130 } | |
0 | 131 } |
132 if (ret < 0) | |
133 return -1; | |
134 | |
135 MPV_frame_start(s); | |
136 | |
137 #ifdef DEBUG | |
138 printf("qscale=%d\n", s->qscale); | |
139 #endif | |
140 | |
141 /* decode each macroblock */ | |
142 for(s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) { | |
162 | 143 /* Check for GOB headers on H.263 */ |
144 /* FIXME: In the future H.263+ will have intra prediction */ | |
145 /* and we are gonna need another way to detect MPEG4 */ | |
146 if (s->mb_y && !s->h263_pred) { | |
147 s->first_gob_line = h263_decode_gob_header(s); | |
148 } | |
0 | 149 for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) { |
150 #ifdef DEBUG | |
151 printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); | |
152 #endif | |
144 | 153 //fprintf(stderr,"\nFrame: %d\tMB: %d",avctx->frame_number, (s->mb_y * s->mb_width) + s->mb_x); |
0 | 154 /* DCT & quantize */ |
155 if (s->h263_msmpeg4) { | |
156 msmpeg4_dc_scale(s); | |
157 } else if (s->h263_pred) { | |
158 h263_dc_scale(s); | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
242
diff
changeset
|
159 } else if (s->h263_aic) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
242
diff
changeset
|
160 s->y_dc_scale = s->qscale; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
242
diff
changeset
|
161 s->c_dc_scale = s->qscale; |
0 | 162 } else { |
163 /* default quantization values */ | |
164 s->y_dc_scale = 8; | |
165 s->c_dc_scale = 8; | |
166 } | |
167 | |
203 | 168 #ifdef HAVE_MMX |
169 if (mm_flags & MM_MMX) { | |
170 asm volatile( | |
171 "pxor %%mm7, %%mm7 \n\t" | |
172 "movl $-128*6, %%eax \n\t" | |
173 "1: \n\t" | |
174 "movq %%mm7, (%0, %%eax) \n\t" | |
175 "movq %%mm7, 8(%0, %%eax) \n\t" | |
176 "movq %%mm7, 16(%0, %%eax) \n\t" | |
177 "movq %%mm7, 24(%0, %%eax) \n\t" | |
178 "addl $32, %%eax \n\t" | |
179 " js 1b \n\t" | |
180 : : "r" (((int)s->block)+128*6) | |
181 : "%eax" | |
182 ); | |
183 }else{ | |
184 memset(s->block, 0, sizeof(s->block)); | |
185 } | |
186 #else | |
12
4d50c7d89e0f
use block[] in structure to have it aligned on 8 bytes for mmx optimizations
glantau
parents:
0
diff
changeset
|
187 memset(s->block, 0, sizeof(s->block)); |
203 | 188 #endif |
0 | 189 s->mv_dir = MV_DIR_FORWARD; |
190 s->mv_type = MV_TYPE_16X16; | |
191 if (s->h263_msmpeg4) { | |
242
d1a9663b973b
* continue after error in msmpeg4_decode_mb - helps for some movie samples
kabi
parents:
231
diff
changeset
|
192 if (msmpeg4_decode_mb(s, s->block) < 0) { |
d1a9663b973b
* continue after error in msmpeg4_decode_mb - helps for some movie samples
kabi
parents:
231
diff
changeset
|
193 fprintf(stderr,"\nError at MB: %d\n", (s->mb_y * s->mb_width) + s->mb_x); |
0 | 194 return -1; |
242
d1a9663b973b
* continue after error in msmpeg4_decode_mb - helps for some movie samples
kabi
parents:
231
diff
changeset
|
195 } |
0 | 196 } else { |
161 | 197 if (h263_decode_mb(s, s->block) < 0) { |
198 fprintf(stderr,"\nError at MB: %d\n", (s->mb_y * s->mb_width) + s->mb_x); | |
0 | 199 return -1; |
161 | 200 } |
0 | 201 } |
12
4d50c7d89e0f
use block[] in structure to have it aligned on 8 bytes for mmx optimizations
glantau
parents:
0
diff
changeset
|
202 MPV_decode_mb(s, s->block); |
0 | 203 } |
67 | 204 if (avctx->draw_horiz_band) { |
205 UINT8 *src_ptr[3]; | |
206 int y, h, offset; | |
207 y = s->mb_y * 16; | |
208 h = s->height - y; | |
209 if (h > 16) | |
210 h = 16; | |
211 offset = y * s->linesize; | |
212 src_ptr[0] = s->current_picture[0] + offset; | |
213 src_ptr[1] = s->current_picture[1] + (offset >> 2); | |
214 src_ptr[2] = s->current_picture[2] + (offset >> 2); | |
215 avctx->draw_horiz_band(avctx, src_ptr, s->linesize, | |
216 y, s->width, h); | |
217 } | |
0 | 218 } |
208 | 219 |
220 if (s->h263_msmpeg4) | |
221 if(msmpeg4_decode_ext_header(s, buf_size) < 0) return -1; | |
0 | 222 |
223 MPV_frame_end(s); | |
224 | |
225 pict->data[0] = s->current_picture[0]; | |
226 pict->data[1] = s->current_picture[1]; | |
227 pict->data[2] = s->current_picture[2]; | |
228 pict->linesize[0] = s->linesize; | |
229 pict->linesize[1] = s->linesize / 2; | |
230 pict->linesize[2] = s->linesize / 2; | |
231 | |
232 avctx->quality = s->qscale; | |
231 | 233 |
234 /* Return the Picture timestamp as the frame number */ | |
235 /* we substract 1 because it is added on utils.c */ | |
236 avctx->frame_number = s->picture_number - 1; | |
237 | |
0 | 238 *data_size = sizeof(AVPicture); |
239 return buf_size; | |
240 } | |
241 | |
67 | 242 AVCodec mpeg4_decoder = { |
243 "mpeg4", | |
0 | 244 CODEC_TYPE_VIDEO, |
67 | 245 CODEC_ID_MPEG4, |
0 | 246 sizeof(MpegEncContext), |
247 h263_decode_init, | |
248 NULL, | |
249 h263_decode_end, | |
250 h263_decode_frame, | |
67 | 251 CODEC_CAP_DRAW_HORIZ_BAND, |
0 | 252 }; |
253 | |
254 AVCodec h263_decoder = { | |
255 "h263", | |
256 CODEC_TYPE_VIDEO, | |
257 CODEC_ID_H263, | |
258 sizeof(MpegEncContext), | |
259 h263_decode_init, | |
260 NULL, | |
261 h263_decode_end, | |
262 h263_decode_frame, | |
67 | 263 CODEC_CAP_DRAW_HORIZ_BAND, |
0 | 264 }; |
265 | |
266 AVCodec msmpeg4_decoder = { | |
267 "msmpeg4", | |
268 CODEC_TYPE_VIDEO, | |
269 CODEC_ID_MSMPEG4, | |
270 sizeof(MpegEncContext), | |
271 h263_decode_init, | |
272 NULL, | |
273 h263_decode_end, | |
274 h263_decode_frame, | |
67 | 275 CODEC_CAP_DRAW_HORIZ_BAND, |
0 | 276 }; |
277 | |
278 AVCodec h263i_decoder = { | |
279 "h263i", | |
280 CODEC_TYPE_VIDEO, | |
281 CODEC_ID_H263I, | |
282 sizeof(MpegEncContext), | |
283 h263_decode_init, | |
284 NULL, | |
285 h263_decode_end, | |
286 h263_decode_frame, | |
67 | 287 CODEC_CAP_DRAW_HORIZ_BAND, |
0 | 288 }; |
289 |