Mercurial > libavcodec.hg
annotate h263dec.c @ 144:cb5dabd00ba2 libavcodec
- Bug fix on inter MCBPC table for inter+q.
- H.263/H.263+ decoder now knows GOB start codes.
- H.263/H.263+ decoder now returns the size of the stream on the first call.
- Added show_bits() functions to see the buffer without loosing the bits.
- TODO: H.263v1 UMV parsing is buggy.
| author | pulento |
|---|---|
| date | Sat, 03 Nov 2001 00:49:53 +0000 |
| parents | cdd89f96cbe1 |
| children | f914f710b8d0 |
| 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 */ | |
| 144 | 59 if (avctx->codec->id != CODEC_ID_H263) |
| 60 if (MPV_common_init(s) < 0) | |
| 61 return -1; | |
| 0 | 62 |
| 60 | 63 /* XXX: suppress this matrix init, only needed because using mpeg1 |
| 64 dequantize in mmx case */ | |
| 65 for(i=0;i<64;i++) | |
| 66 s->non_intra_matrix[i] = default_non_intra_matrix[i]; | |
| 67 | |
| 0 | 68 if (s->h263_msmpeg4) |
| 69 msmpeg4_decode_init_vlc(s); | |
| 70 else | |
| 71 h263_decode_init_vlc(s); | |
| 72 | |
| 73 return 0; | |
| 74 } | |
| 75 | |
| 76 static int h263_decode_end(AVCodecContext *avctx) | |
| 77 { | |
| 78 MpegEncContext *s = avctx->priv_data; | |
| 79 | |
| 80 MPV_common_end(s); | |
| 81 return 0; | |
| 82 } | |
| 83 | |
| 84 static int h263_decode_frame(AVCodecContext *avctx, | |
| 85 void *data, int *data_size, | |
| 86 UINT8 *buf, int buf_size) | |
| 87 { | |
| 88 MpegEncContext *s = avctx->priv_data; | |
| 89 int ret; | |
| 90 AVPicture *pict = data; | |
| 91 | |
| 92 #ifdef DEBUG | |
| 93 printf("*****frame %d size=%d\n", avctx->frame_number, buf_size); | |
| 94 printf("bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]); | |
| 95 #endif | |
| 144 | 96 |
| 0 | 97 /* no supplementary picture */ |
| 98 if (buf_size == 0) { | |
| 99 *data_size = 0; | |
| 100 return 0; | |
| 101 } | |
| 102 | |
| 103 init_get_bits(&s->gb, buf, buf_size); | |
| 104 | |
| 105 /* let's go :-) */ | |
| 106 if (s->h263_msmpeg4) { | |
| 107 ret = msmpeg4_decode_picture_header(s); | |
| 108 } else if (s->h263_pred) { | |
| 109 ret = mpeg4_decode_picture_header(s); | |
| 110 } else if (s->h263_intel) { | |
| 111 ret = intel_h263_decode_picture_header(s); | |
| 112 } else { | |
| 113 ret = h263_decode_picture_header(s); | |
| 144 | 114 /* After H263 header decode we have the height, width, */ |
| 115 /* and other parameters. So then we could init the picture */ | |
| 116 if (s->width != avctx->width || s->height != avctx->height) { | |
| 117 avctx->width = s->width; | |
| 118 avctx->height = s->height; | |
| 119 /* FIXME: By the way H263 decoder is evolving it should have */ | |
| 120 /* an H263EncContext */ | |
| 121 if (MPV_common_init(s) < 0) | |
| 122 return -1; | |
| 123 } | |
| 0 | 124 } |
| 125 if (ret < 0) | |
| 126 return -1; | |
| 127 | |
| 128 MPV_frame_start(s); | |
| 129 | |
| 130 #ifdef DEBUG | |
| 131 printf("qscale=%d\n", s->qscale); | |
| 132 #endif | |
| 133 | |
| 134 /* decode each macroblock */ | |
| 135 for(s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) { | |
| 136 for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) { | |
| 137 #ifdef DEBUG | |
| 138 printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); | |
| 139 #endif | |
| 144 | 140 //fprintf(stderr,"\nFrame: %d\tMB: %d",avctx->frame_number, (s->mb_y * s->mb_width) + s->mb_x); |
| 0 | 141 /* DCT & quantize */ |
| 142 if (s->h263_msmpeg4) { | |
| 143 msmpeg4_dc_scale(s); | |
| 144 } else if (s->h263_pred) { | |
| 145 h263_dc_scale(s); | |
| 146 } else { | |
| 147 /* default quantization values */ | |
| 148 s->y_dc_scale = 8; | |
| 149 s->c_dc_scale = 8; | |
| 150 } | |
| 151 | |
|
12
4d50c7d89e0f
use block[] in structure to have it aligned on 8 bytes for mmx optimizations
glantau
parents:
0
diff
changeset
|
152 memset(s->block, 0, sizeof(s->block)); |
| 0 | 153 s->mv_dir = MV_DIR_FORWARD; |
| 154 s->mv_type = MV_TYPE_16X16; | |
| 155 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
|
156 if (msmpeg4_decode_mb(s, s->block) < 0) |
| 0 | 157 return -1; |
| 158 } else { | |
|
12
4d50c7d89e0f
use block[] in structure to have it aligned on 8 bytes for mmx optimizations
glantau
parents:
0
diff
changeset
|
159 if (h263_decode_mb(s, s->block) < 0) |
| 0 | 160 return -1; |
| 161 } | |
|
12
4d50c7d89e0f
use block[] in structure to have it aligned on 8 bytes for mmx optimizations
glantau
parents:
0
diff
changeset
|
162 MPV_decode_mb(s, s->block); |
| 0 | 163 } |
| 67 | 164 if (avctx->draw_horiz_band) { |
| 165 UINT8 *src_ptr[3]; | |
| 166 int y, h, offset; | |
| 167 y = s->mb_y * 16; | |
| 168 h = s->height - y; | |
| 169 if (h > 16) | |
| 170 h = 16; | |
| 171 offset = y * s->linesize; | |
| 172 src_ptr[0] = s->current_picture[0] + offset; | |
| 173 src_ptr[1] = s->current_picture[1] + (offset >> 2); | |
| 174 src_ptr[2] = s->current_picture[2] + (offset >> 2); | |
| 175 avctx->draw_horiz_band(avctx, src_ptr, s->linesize, | |
| 176 y, s->width, h); | |
| 177 } | |
| 0 | 178 } |
| 179 | |
| 180 MPV_frame_end(s); | |
| 181 | |
| 182 pict->data[0] = s->current_picture[0]; | |
| 183 pict->data[1] = s->current_picture[1]; | |
| 184 pict->data[2] = s->current_picture[2]; | |
| 185 pict->linesize[0] = s->linesize; | |
| 186 pict->linesize[1] = s->linesize / 2; | |
| 187 pict->linesize[2] = s->linesize / 2; | |
| 188 | |
| 189 avctx->quality = s->qscale; | |
| 190 *data_size = sizeof(AVPicture); | |
| 191 return buf_size; | |
| 192 } | |
| 193 | |
| 67 | 194 AVCodec mpeg4_decoder = { |
| 195 "mpeg4", | |
| 0 | 196 CODEC_TYPE_VIDEO, |
| 67 | 197 CODEC_ID_MPEG4, |
| 0 | 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 h263_decoder = { | |
| 207 "h263", | |
| 208 CODEC_TYPE_VIDEO, | |
| 209 CODEC_ID_H263, | |
| 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 msmpeg4_decoder = { | |
| 219 "msmpeg4", | |
| 220 CODEC_TYPE_VIDEO, | |
| 221 CODEC_ID_MSMPEG4, | |
| 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 | |
| 230 AVCodec h263i_decoder = { | |
| 231 "h263i", | |
| 232 CODEC_TYPE_VIDEO, | |
| 233 CODEC_ID_H263I, | |
| 234 sizeof(MpegEncContext), | |
| 235 h263_decode_init, | |
| 236 NULL, | |
| 237 h263_decode_end, | |
| 238 h263_decode_frame, | |
| 67 | 239 CODEC_CAP_DRAW_HORIZ_BAND, |
| 0 | 240 }; |
| 241 |
