Mercurial > libavcodec.hg
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 |
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: | |
42 break; | |
67 | 43 case CODEC_ID_MPEG4: |
0 | 44 s->time_increment_bits = 4; /* default value for broken headers */ |
45 s->h263_pred = 1; | |
46 break; | |
47 case CODEC_ID_MSMPEG4: | |
48 s->h263_msmpeg4 = 1; | |
49 s->h263_pred = 1; | |
50 break; | |
51 case CODEC_ID_H263I: | |
52 s->h263_intel = 1; | |
53 break; | |
54 default: | |
55 return -1; | |
56 } | |
57 | |
58 /* for h263, we allocate the images after having read the header */ | |
59 if (MPV_common_init(s) < 0) | |
60 return -1; | |
61 | |
60 | 62 /* XXX: suppress this matrix init, only needed because using mpeg1 |
63 dequantize in mmx case */ | |
64 for(i=0;i<64;i++) | |
65 s->non_intra_matrix[i] = default_non_intra_matrix[i]; | |
66 | |
0 | 67 if (s->h263_msmpeg4) |
68 msmpeg4_decode_init_vlc(s); | |
69 else | |
70 h263_decode_init_vlc(s); | |
71 | |
72 return 0; | |
73 } | |
74 | |
75 static int h263_decode_end(AVCodecContext *avctx) | |
76 { | |
77 MpegEncContext *s = avctx->priv_data; | |
78 | |
79 MPV_common_end(s); | |
80 return 0; | |
81 } | |
82 | |
83 static int h263_decode_frame(AVCodecContext *avctx, | |
84 void *data, int *data_size, | |
85 UINT8 *buf, int buf_size) | |
86 { | |
87 MpegEncContext *s = avctx->priv_data; | |
88 int ret; | |
89 AVPicture *pict = data; | |
90 | |
91 #ifdef DEBUG | |
92 printf("*****frame %d size=%d\n", avctx->frame_number, buf_size); | |
93 printf("bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]); | |
94 #endif | |
95 | |
96 /* no supplementary picture */ | |
97 if (buf_size == 0) { | |
98 *data_size = 0; | |
99 return 0; | |
100 } | |
101 | |
102 init_get_bits(&s->gb, buf, buf_size); | |
103 | |
104 /* let's go :-) */ | |
105 if (s->h263_msmpeg4) { | |
106 ret = msmpeg4_decode_picture_header(s); | |
107 } else if (s->h263_pred) { | |
108 ret = mpeg4_decode_picture_header(s); | |
109 } else if (s->h263_intel) { | |
110 ret = intel_h263_decode_picture_header(s); | |
111 } else { | |
112 ret = h263_decode_picture_header(s); | |
113 } | |
114 if (ret < 0) | |
115 return -1; | |
116 | |
117 MPV_frame_start(s); | |
118 | |
119 #ifdef DEBUG | |
120 printf("qscale=%d\n", s->qscale); | |
121 #endif | |
122 | |
123 /* decode each macroblock */ | |
124 for(s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) { | |
125 for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) { | |
126 #ifdef DEBUG | |
127 printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); | |
128 #endif | |
129 /* DCT & quantize */ | |
130 if (s->h263_msmpeg4) { | |
131 msmpeg4_dc_scale(s); | |
132 } else if (s->h263_pred) { | |
133 h263_dc_scale(s); | |
134 } else { | |
135 /* default quantization values */ | |
136 s->y_dc_scale = 8; | |
137 s->c_dc_scale = 8; | |
138 } | |
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 | 141 s->mv_dir = MV_DIR_FORWARD; |
142 s->mv_type = MV_TYPE_16X16; | |
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 | 145 return -1; |
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 | 148 return -1; |
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 | 151 } |
67 | 152 if (avctx->draw_horiz_band) { |
153 UINT8 *src_ptr[3]; | |
154 int y, h, offset; | |
155 y = s->mb_y * 16; | |
156 h = s->height - y; | |
157 if (h > 16) | |
158 h = 16; | |
159 offset = y * s->linesize; | |
160 src_ptr[0] = s->current_picture[0] + offset; | |
161 src_ptr[1] = s->current_picture[1] + (offset >> 2); | |
162 src_ptr[2] = s->current_picture[2] + (offset >> 2); | |
163 avctx->draw_horiz_band(avctx, src_ptr, s->linesize, | |
164 y, s->width, h); | |
165 } | |
0 | 166 } |
167 | |
168 MPV_frame_end(s); | |
169 | |
170 pict->data[0] = s->current_picture[0]; | |
171 pict->data[1] = s->current_picture[1]; | |
172 pict->data[2] = s->current_picture[2]; | |
173 pict->linesize[0] = s->linesize; | |
174 pict->linesize[1] = s->linesize / 2; | |
175 pict->linesize[2] = s->linesize / 2; | |
176 | |
177 avctx->quality = s->qscale; | |
178 *data_size = sizeof(AVPicture); | |
179 return buf_size; | |
180 } | |
181 | |
67 | 182 AVCodec mpeg4_decoder = { |
183 "mpeg4", | |
0 | 184 CODEC_TYPE_VIDEO, |
67 | 185 CODEC_ID_MPEG4, |
0 | 186 sizeof(MpegEncContext), |
187 h263_decode_init, | |
188 NULL, | |
189 h263_decode_end, | |
190 h263_decode_frame, | |
67 | 191 CODEC_CAP_DRAW_HORIZ_BAND, |
0 | 192 }; |
193 | |
194 AVCodec h263_decoder = { | |
195 "h263", | |
196 CODEC_TYPE_VIDEO, | |
197 CODEC_ID_H263, | |
198 sizeof(MpegEncContext), | |
199 h263_decode_init, | |
200 NULL, | |
201 h263_decode_end, | |
202 h263_decode_frame, | |
67 | 203 CODEC_CAP_DRAW_HORIZ_BAND, |
0 | 204 }; |
205 | |
206 AVCodec msmpeg4_decoder = { | |
207 "msmpeg4", | |
208 CODEC_TYPE_VIDEO, | |
209 CODEC_ID_MSMPEG4, | |
210 sizeof(MpegEncContext), | |
211 h263_decode_init, | |
212 NULL, | |
213 h263_decode_end, | |
214 h263_decode_frame, | |
67 | 215 CODEC_CAP_DRAW_HORIZ_BAND, |
0 | 216 }; |
217 | |
218 AVCodec h263i_decoder = { | |
219 "h263i", | |
220 CODEC_TYPE_VIDEO, | |
221 CODEC_ID_H263I, | |
222 sizeof(MpegEncContext), | |
223 h263_decode_init, | |
224 NULL, | |
225 h263_decode_end, | |
226 h263_decode_frame, | |
67 | 227 CODEC_CAP_DRAW_HORIZ_BAND, |
0 | 228 }; |
229 |