Mercurial > libavcodec.hg
comparison mpegvideo.c @ 756:f2644bb12a43 libavcodec
fixing h263 decoding (did segfault)
author | michaelni |
---|---|
date | Sat, 19 Oct 2002 01:31:26 +0000 |
parents | d17846a6c164 |
children | e858fe220ce0 |
comparison
equal
deleted
inserted
replaced
755:d17846a6c164 | 756:f2644bb12a43 |
---|---|
223 } | 223 } |
224 | 224 |
225 /* init common structure for both encoder and decoder */ | 225 /* init common structure for both encoder and decoder */ |
226 int MPV_common_init(MpegEncContext *s) | 226 int MPV_common_init(MpegEncContext *s) |
227 { | 227 { |
228 int c_size, i; | |
229 UINT8 *pict; | 228 UINT8 *pict; |
229 int y_size, c_size, yc_size, i; | |
230 | 230 |
231 DCT_common_init(s); | 231 DCT_common_init(s); |
232 | 232 |
233 s->flags= s->avctx->flags; | 233 s->flags= s->avctx->flags; |
234 | 234 |
235 s->mb_width = (s->width + 15) / 16; | 235 s->mb_width = (s->width + 15) / 16; |
236 s->mb_height = (s->height + 15) / 16; | 236 s->mb_height = (s->height + 15) / 16; |
237 | |
238 y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); | |
239 c_size = (s->mb_width + 2) * (s->mb_height + 2); | |
240 yc_size = y_size + 2 * c_size; | |
237 | 241 |
238 /* set default edge pos, will be overriden in decode_header if needed */ | 242 /* set default edge pos, will be overriden in decode_header if needed */ |
239 s->h_edge_pos= s->mb_width*16; | 243 s->h_edge_pos= s->mb_width*16; |
240 s->v_edge_pos= s->mb_height*16; | 244 s->v_edge_pos= s->mb_height*16; |
241 | 245 |
244 + (toupper((s->avctx->fourcc>>8 )&0xFF)<<8 ) | 248 + (toupper((s->avctx->fourcc>>8 )&0xFF)<<8 ) |
245 + (toupper((s->avctx->fourcc>>16)&0xFF)<<16) | 249 + (toupper((s->avctx->fourcc>>16)&0xFF)<<16) |
246 + (toupper((s->avctx->fourcc>>24)&0xFF)<<24); | 250 + (toupper((s->avctx->fourcc>>24)&0xFF)<<24); |
247 | 251 |
248 s->mb_num = s->mb_width * s->mb_height; | 252 s->mb_num = s->mb_width * s->mb_height; |
253 | |
249 if(!(s->flags&CODEC_FLAG_DR1)){ | 254 if(!(s->flags&CODEC_FLAG_DR1)){ |
250 s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH; | 255 s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH; |
251 s->uvlinesize = s->mb_width * 8 + EDGE_WIDTH; | 256 s->uvlinesize = s->mb_width * 8 + EDGE_WIDTH; |
252 | 257 |
253 for(i=0;i<3;i++) { | 258 for(i=0;i<3;i++) { |
254 int w, h, shift, pict_start; | 259 int w, h, shift, pict_start, size; |
255 | 260 |
256 w = s->linesize; | 261 w = s->linesize; |
257 h = s->mb_height * 16 + 2 * EDGE_WIDTH; | 262 h = s->mb_height * 16 + 2 * EDGE_WIDTH; |
258 shift = (i == 0) ? 0 : 1; | 263 shift = (i == 0) ? 0 : 1; |
259 c_size = (s->linesize>>shift) * (h >> shift); | 264 size = (s->linesize>>shift) * (h >> shift); |
260 pict_start = (s->linesize>>shift) * (EDGE_WIDTH >> shift) + (EDGE_WIDTH >> shift); | 265 pict_start = (s->linesize>>shift) * (EDGE_WIDTH >> shift) + (EDGE_WIDTH >> shift); |
261 | 266 |
262 CHECKED_ALLOCZ(pict, c_size) | 267 CHECKED_ALLOCZ(pict, size) |
263 s->last_picture_base[i] = pict; | 268 s->last_picture_base[i] = pict; |
264 s->last_picture[i] = pict + pict_start; | 269 s->last_picture[i] = pict + pict_start; |
265 if(i>0) memset(s->last_picture_base[i], 128, c_size); | 270 if(i>0) memset(s->last_picture_base[i], 128, size); |
266 | 271 |
267 CHECKED_ALLOCZ(pict, c_size) | 272 CHECKED_ALLOCZ(pict, size) |
268 s->next_picture_base[i] = pict; | 273 s->next_picture_base[i] = pict; |
269 s->next_picture[i] = pict + pict_start; | 274 s->next_picture[i] = pict + pict_start; |
270 if(i>0) memset(s->next_picture_base[i], 128, c_size); | 275 if(i>0) memset(s->next_picture_base[i], 128, size); |
271 | 276 |
272 if (s->has_b_frames || s->codec_id==CODEC_ID_MPEG4) { | 277 if (s->has_b_frames || s->codec_id==CODEC_ID_MPEG4) { |
273 /* Note the MPEG4 stuff is here cuz of buggy encoders which dont set the low_delay flag but | 278 /* Note the MPEG4 stuff is here cuz of buggy encoders which dont set the low_delay flag but |
274 do low-delay encoding, so we cant allways distinguish b-frame containing streams from low_delay streams */ | 279 do low-delay encoding, so we cant allways distinguish b-frame containing streams from low_delay streams */ |
275 CHECKED_ALLOCZ(pict, c_size) | 280 CHECKED_ALLOCZ(pict, size) |
276 s->aux_picture_base[i] = pict; | 281 s->aux_picture_base[i] = pict; |
277 s->aux_picture[i] = pict + pict_start; | 282 s->aux_picture[i] = pict + pict_start; |
278 if(i>0) memset(s->aux_picture_base[i], 128, c_size); | 283 if(i>0) memset(s->aux_picture_base[i], 128, size); |
279 } | 284 } |
280 } | 285 } |
281 s->ip_buffer_count= 2; | 286 s->ip_buffer_count= 2; |
282 } | 287 } |
283 | 288 |
308 | 313 |
309 if(s->max_b_frames){ | 314 if(s->max_b_frames){ |
310 for(j=0; j<REORDER_BUFFER_SIZE; j++){ | 315 for(j=0; j<REORDER_BUFFER_SIZE; j++){ |
311 int i; | 316 int i; |
312 for(i=0;i<3;i++) { | 317 for(i=0;i<3;i++) { |
313 int w, h, shift; | 318 int w, h, shift, size; |
314 | 319 |
315 w = s->linesize; | 320 w = s->linesize; |
316 h = s->mb_height * 16; | 321 h = s->mb_height * 16; |
317 shift = (i == 0) ? 0 : 1; | 322 shift = (i == 0) ? 0 : 1; |
318 c_size = (w >> shift) * (h >> shift); | 323 size = (w >> shift) * (h >> shift); |
319 | 324 |
320 CHECKED_ALLOCZ(pict, c_size); | 325 CHECKED_ALLOCZ(pict, size); |
321 s->picture_buffer[j][i] = pict; | 326 s->picture_buffer[j][i] = pict; |
322 } | 327 } |
323 } | 328 } |
324 } | 329 } |
325 | 330 |
354 /* 4mv b frame decoding table */ | 359 /* 4mv b frame decoding table */ |
355 //note this is needed for h263 without b frames too (segfault on damaged streams otherwise) | 360 //note this is needed for h263 without b frames too (segfault on damaged streams otherwise) |
356 CHECKED_ALLOCZ(s->co_located_type_table, s->mb_num * sizeof(UINT8)) | 361 CHECKED_ALLOCZ(s->co_located_type_table, s->mb_num * sizeof(UINT8)) |
357 | 362 |
358 if (s->h263_pred || s->h263_plus) { | 363 if (s->h263_pred || s->h263_plus) { |
359 int y_size, c_size, i, size; | |
360 | |
361 /* dc values */ | |
362 | |
363 y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); | |
364 c_size = (s->mb_width + 2) * (s->mb_height + 2); | |
365 size = y_size + 2 * c_size; | |
366 CHECKED_ALLOCZ(s->dc_val[0], size * sizeof(INT16)); | |
367 s->dc_val[1] = s->dc_val[0] + y_size; | |
368 s->dc_val[2] = s->dc_val[1] + c_size; | |
369 for(i=0;i<size;i++) | |
370 s->dc_val[0][i] = 1024; | |
371 | |
372 /* ac values */ | 364 /* ac values */ |
373 CHECKED_ALLOCZ(s->ac_val[0], size * sizeof(INT16) * 16); | 365 CHECKED_ALLOCZ(s->ac_val[0], yc_size * sizeof(INT16) * 16); |
374 s->ac_val[1] = s->ac_val[0] + y_size; | 366 s->ac_val[1] = s->ac_val[0] + y_size; |
375 s->ac_val[2] = s->ac_val[1] + c_size; | 367 s->ac_val[2] = s->ac_val[1] + c_size; |
376 | 368 |
377 /* cbp values */ | 369 /* cbp values */ |
378 CHECKED_ALLOCZ(s->coded_block, y_size); | 370 CHECKED_ALLOCZ(s->coded_block, y_size); |
382 | 374 |
383 /* cbp, ac_pred, pred_dir */ | 375 /* cbp, ac_pred, pred_dir */ |
384 CHECKED_ALLOCZ(s->cbp_table , s->mb_num * sizeof(UINT8)) | 376 CHECKED_ALLOCZ(s->cbp_table , s->mb_num * sizeof(UINT8)) |
385 CHECKED_ALLOCZ(s->pred_dir_table, s->mb_num * sizeof(UINT8)) | 377 CHECKED_ALLOCZ(s->pred_dir_table, s->mb_num * sizeof(UINT8)) |
386 } | 378 } |
379 | |
380 if (s->h263_pred || s->h263_plus || !s->encoding) { | |
381 /* dc values */ | |
382 //MN: we need these for error resilience of intra-frames | |
383 CHECKED_ALLOCZ(s->dc_val[0], yc_size * sizeof(INT16)); | |
384 s->dc_val[1] = s->dc_val[0] + y_size; | |
385 s->dc_val[2] = s->dc_val[1] + c_size; | |
386 for(i=0;i<yc_size;i++) | |
387 s->dc_val[0][i] = 1024; | |
388 } | |
389 | |
387 CHECKED_ALLOCZ(s->qscale_table , s->mb_num * sizeof(UINT8)) | 390 CHECKED_ALLOCZ(s->qscale_table , s->mb_num * sizeof(UINT8)) |
388 | 391 |
389 /* which mb is a intra block */ | 392 /* which mb is a intra block */ |
390 CHECKED_ALLOCZ(s->mbintra_table, s->mb_num); | 393 CHECKED_ALLOCZ(s->mbintra_table, s->mb_num); |
391 memset(s->mbintra_table, 1, s->mb_num); | 394 memset(s->mbintra_table, 1, s->mb_num); |