comparison h261.c @ 2134:8afd396fa198 libavcodec

- Support empty GOB's (no mb's) and skip all mb's - Mb's were not skipped at the end of a GOB - One value too much was used in iDCT - Chroma_qscale was not updated for mquant patch by ("Chris Flerackers" <cflerackers at androme dot be>)
author michael
date Thu, 22 Jul 2004 10:23:28 +0000
parents c89a3019e088
children 8eae8e652584
comparison
equal deleted inserted replaced
2133:29f774bb85fe 2134:8afd396fa198
205 205
206 return -1; 206 return -1;
207 } 207 }
208 208
209 /** 209 /**
210 * decodes a skipped macroblock, called when when mba_diff > 1. 210 * decodes skipped macroblocks
211 * @return 0 211 * @return 0
212 */ 212 */
213 static int h261_decode_mb_skipped(H261Context *h, 213 static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2 )
214 DCTELEM block[6][64])
215 { 214 {
216 MpegEncContext * const s = &h->s; 215 MpegEncContext * const s = &h->s;
217 int i; 216 int i;
218 const int xy = s->mb_x + s->mb_y * s->mb_stride; 217
219 s->mb_intra = 0; 218 s->mb_intra = 0;
220 for(i=0;i<6;i++) 219
221 s->block_last_index[i] = -1; 220 for(i=mba1; i<mba2; i++){
222 s->mv_dir = MV_DIR_FORWARD; 221 int j, xy;
223 s->mv_type = MV_TYPE_16X16; 222
224 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; 223 s->mb_x= ((h->gob_number-1) % 2) * 11 + i % 11;
225 s->mv[0][0][0] = 0; 224 s->mb_y= ((h->gob_number-1) / 2) * 3 + i / 11;
226 s->mv[0][0][1] = 0; 225 xy = s->mb_x + s->mb_y * s->mb_stride;
227 s->mb_skiped = 1; 226 ff_init_block_index(s);
227 ff_update_block_index(s);
228 s->dsp.clear_blocks(s->block[0]);
229
230 for(j=0;j<6;j++)
231 s->block_last_index[j] = -1;
232
233 s->mv_dir = MV_DIR_FORWARD;
234 s->mv_type = MV_TYPE_16X16;
235 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
236 s->mv[0][0][0] = 0;
237 s->mv[0][0][1] = 0;
238 s->mb_skiped = 1;
239
240 MPV_decode_mb(s, s->block);
241 }
242
228 return 0; 243 return 0;
229 } 244 }
230 245
231 static int decode_mv_component(GetBitContext *gb, int v){ 246 static int decode_mv_component(GetBitContext *gb, int v){
232 int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2); 247 int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);
268 283
269 xy = s->mb_x + s->mb_y * s->mb_stride; 284 xy = s->mb_x + s->mb_y * s->mb_stride;
270 285
271 ff_init_block_index(s); 286 ff_init_block_index(s);
272 ff_update_block_index(s); 287 ff_update_block_index(s);
288 s->dsp.clear_blocks(s->block[0]);
273 289
274 // Read mtype 290 // Read mtype
275 old_mtype = h->mtype; 291 old_mtype = h->mtype;
276 h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2); 292 h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
277 h->mtype = h261_mtype_map[h->mtype]; 293 h->mtype = h261_mtype_map[h->mtype];
279 if (IS_FIL (h->mtype)) 295 if (IS_FIL (h->mtype))
280 h->loop_filter = 1; 296 h->loop_filter = 1;
281 297
282 // Read mquant 298 // Read mquant
283 if ( IS_QUANT ( h->mtype ) ){ 299 if ( IS_QUANT ( h->mtype ) ){
284 s->qscale = get_bits(&s->gb, 5); 300 ff_set_qscale(s, get_bits(&s->gb, 5));
285 } 301 }
286 302
287 s->mb_intra = IS_INTRA4x4(h->mtype); 303 s->mb_intra = IS_INTRA4x4(h->mtype);
288 304
289 // Read mv 305 // Read mv
430 } 446 }
431 j = scan_table[i]; 447 j = scan_table[i];
432 block[j] = level; 448 block[j] = level;
433 i++; 449 i++;
434 } 450 }
435 s->block_last_index[n] = i; 451 s->block_last_index[n] = i-1;
436 return 0; 452 return 0;
437 } 453 }
438 454
439 /** 455 /**
440 * decodes the H261 picture header. 456 * decodes the H261 picture header.
506 return 0; 522 return 0;
507 } 523 }
508 524
509 static int h261_decode_gob(H261Context *h){ 525 static int h261_decode_gob(H261Context *h){
510 MpegEncContext * const s = &h->s; 526 MpegEncContext * const s = &h->s;
511 int i;
512 527
513 ff_set_qscale(s, s->qscale); 528 ff_set_qscale(s, s->qscale);
529
530 /* check for empty gob */
531 int v= show_bits(&s->gb, 15);
532
533 if(get_bits_count(&s->gb) + 15 > s->gb.size_in_bits){
534 v>>= get_bits_count(&s->gb) + 15 - s->gb.size_in_bits;
535 }
536
537 if(v==0){
538 h261_decode_mb_skipped(h, 0, 33);
539 return 0;
540 }
541
542 /* decode mb's */
514 while(h->current_mba <= MAX_MBA) 543 while(h->current_mba <= MAX_MBA)
515 { 544 {
516 int ret; 545 int ret;
517 /* DCT & quantize */ 546 /* DCT & quantize */
518 s->dsp.clear_blocks(s->block[0]);
519 ret= h261_decode_mb(h, s->block); 547 ret= h261_decode_mb(h, s->block);
520 if(ret<0){ 548 if(ret<0){
521 const int xy= s->mb_x + s->mb_y*s->mb_stride; 549 const int xy= s->mb_x + s->mb_y*s->mb_stride;
522 if(ret==SLICE_END){ 550 if(ret==SLICE_END){
523 MPV_decode_mb(s, s->block); 551 MPV_decode_mb(s, s->block);
524 if(h->loop_filter){ 552 if(h->loop_filter){
525 ff_h261_loop_filter(h); 553 ff_h261_loop_filter(h);
526 } 554 }
527 h->loop_filter = 0; 555 h->loop_filter = 0;
528 for(i=1; i<h->mba_diff; i++){ 556 h261_decode_mb_skipped(h, h->current_mba-h->mba_diff, h->current_mba-1);
529 s->mb_x= ((h->gob_number-1) % 2) * 11 + ((h->current_mba-1-i) % 11); 557 h261_decode_mb_skipped(h, h->current_mba, 33);
530 s->mb_y= ((h->gob_number-1) / 2) * 3 + ((h->current_mba-1-i) / 11);
531 ff_init_block_index(s);
532 ff_update_block_index(s);
533 s->dsp.clear_blocks(s->block[0]);
534 ret= h261_decode_mb_skipped(h, s->block);
535 MPV_decode_mb(s, s->block);
536 }
537
538 return 0; 558 return 0;
539 }else if(ret==SLICE_NOEND){ 559 }else if(ret==SLICE_NOEND){
540 av_log(s->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy); 560 av_log(s->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy);
541 return -1; 561 return -1;
542 } 562 }
547 if(h->loop_filter){ 567 if(h->loop_filter){
548 ff_h261_loop_filter(h); 568 ff_h261_loop_filter(h);
549 } 569 }
550 570
551 h->loop_filter = 0; 571 h->loop_filter = 0;
552 for(i=1; i<h->mba_diff; i++){ 572 h261_decode_mb_skipped(h, h->current_mba-h->mba_diff, h->current_mba-1);
553 s->mb_x= ((h->gob_number-1) % 2) * 11 + ((h->current_mba-1-i) % 11);
554 s->mb_y= ((h->gob_number-1) / 2) * 3 + ((h->current_mba-1-i) / 11);
555 ff_init_block_index(s);
556 ff_update_block_index(s);
557 s->dsp.clear_blocks(s->block[0]);
558 ret= h261_decode_mb_skipped(h, s->block);
559 MPV_decode_mb(s, s->block);
560 }
561 } 573 }
562 574
563 return -1; 575 return -1;
564 } 576 }
565 577