comparison mpeg12.c @ 21:20e680e7a490 libavcodec

get_bits() specialization, gives 4\speedup
author arpi_esp
date Sat, 04 Aug 2001 00:46:50 +0000
parents 1d2077091e88
children 5bf15419d47e
comparison
equal deleted inserted replaced
20:907b67420d84 21:20e680e7a490
481 } 481 }
482 } 482 }
483 483
484 static inline int get_dmv(MpegEncContext *s) 484 static inline int get_dmv(MpegEncContext *s)
485 { 485 {
486 if(get_bits(&s->gb, 1)) 486 if(get_bits1(&s->gb))
487 return 1 - (get_bits(&s->gb, 1) << 1); 487 return 1 - (get_bits1(&s->gb) << 1);
488 else 488 else
489 return 0; 489 return 0;
490 } 490 }
491 491
492 /* motion type (for mpeg2) */ 492 /* motion type (for mpeg2) */
550 } 550 }
551 551
552 switch(s->pict_type) { 552 switch(s->pict_type) {
553 default: 553 default:
554 case I_TYPE: 554 case I_TYPE:
555 if (get_bits(&s->gb, 1) == 0) { 555 if (get_bits1(&s->gb) == 0) {
556 if (get_bits(&s->gb, 1) == 0) 556 if (get_bits1(&s->gb) == 0)
557 return -1; 557 return -1;
558 mb_type = MB_QUANT | MB_INTRA; 558 mb_type = MB_QUANT | MB_INTRA;
559 } else { 559 } else {
560 mb_type = MB_INTRA; 560 mb_type = MB_INTRA;
561 } 561 }
582 } 582 }
583 /* compute dct type */ 583 /* compute dct type */
584 if (s->picture_structure == PICT_FRAME && 584 if (s->picture_structure == PICT_FRAME &&
585 !s->frame_pred_frame_dct && 585 !s->frame_pred_frame_dct &&
586 (mb_type & (MB_PAT | MB_INTRA))) { 586 (mb_type & (MB_PAT | MB_INTRA))) {
587 s->interlaced_dct = get_bits(&s->gb, 1); 587 s->interlaced_dct = get_bits1(&s->gb);
588 #ifdef DEBUG 588 #ifdef DEBUG
589 if (s->interlaced_dct) 589 if (s->interlaced_dct)
590 printf("interlaced_dct\n"); 590 printf("interlaced_dct\n");
591 #endif 591 #endif
592 } else { 592 } else {
607 } 607 }
608 if (mb_type & MB_INTRA) { 608 if (mb_type & MB_INTRA) {
609 if (s->concealment_motion_vectors) { 609 if (s->concealment_motion_vectors) {
610 /* just parse them */ 610 /* just parse them */
611 if (s->picture_structure != PICT_FRAME) 611 if (s->picture_structure != PICT_FRAME)
612 get_bits(&s->gb, 1); /* field select */ 612 skip_bits1(&s->gb); /* field select */
613 mpeg_decode_motion(s, s->mpeg_f_code[0][0], 0); 613 mpeg_decode_motion(s, s->mpeg_f_code[0][0], 0);
614 mpeg_decode_motion(s, s->mpeg_f_code[0][1], 0); 614 mpeg_decode_motion(s, s->mpeg_f_code[0][1], 0);
615 } 615 }
616 s->mb_intra = 1; 616 s->mb_intra = 1;
617 cbp = 0x3f; 617 cbp = 0x3f;
653 } 653 }
654 } else { 654 } else {
655 /* MT_16X8 */ 655 /* MT_16X8 */
656 s->mv_type = MV_TYPE_16X8; 656 s->mv_type = MV_TYPE_16X8;
657 for(j=0;j<2;j++) { 657 for(j=0;j<2;j++) {
658 s->field_select[i][j] = get_bits(&s->gb, 1); 658 s->field_select[i][j] = get_bits1(&s->gb);
659 for(k=0;k<2;k++) { 659 for(k=0;k<2;k++) {
660 val = mpeg_decode_motion(s, s->mpeg_f_code[i][k], 660 val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
661 s->last_mv[i][j][k]); 661 s->last_mv[i][j][k]);
662 s->last_mv[i][j][k] = val; 662 s->last_mv[i][j][k] = val;
663 s->mv[i][j][k] = val; 663 s->mv[i][j][k] = val;
667 break; 667 break;
668 case MT_FIELD: 668 case MT_FIELD:
669 if (s->picture_structure == PICT_FRAME) { 669 if (s->picture_structure == PICT_FRAME) {
670 s->mv_type = MV_TYPE_FIELD; 670 s->mv_type = MV_TYPE_FIELD;
671 for(j=0;j<2;j++) { 671 for(j=0;j<2;j++) {
672 s->field_select[i][j] = get_bits(&s->gb, 1); 672 s->field_select[i][j] = get_bits1(&s->gb);
673 val = mpeg_decode_motion(s, s->mpeg_f_code[i][0], 673 val = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
674 s->last_mv[i][j][0]); 674 s->last_mv[i][j][0]);
675 s->last_mv[i][j][0] = val; 675 s->last_mv[i][j][0] = val;
676 s->mv[i][j][0] = val; 676 s->mv[i][j][0] = val;
677 dprintf("fmx=%d\n", val); 677 dprintf("fmx=%d\n", val);
681 s->mv[i][j][1] = val; 681 s->mv[i][j][1] = val;
682 dprintf("fmy=%d\n", val); 682 dprintf("fmy=%d\n", val);
683 } 683 }
684 } else { 684 } else {
685 s->mv_type = MV_TYPE_16X16; 685 s->mv_type = MV_TYPE_16X16;
686 s->field_select[i][0] = get_bits(&s->gb, 1); 686 s->field_select[i][0] = get_bits1(&s->gb);
687 for(k=0;k<2;k++) { 687 for(k=0;k<2;k++) {
688 val = mpeg_decode_motion(s, s->mpeg_f_code[i][k], 688 val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
689 s->last_mv[i][0][k]); 689 s->last_mv[i][0][k]);
690 s->last_mv[i][0][k] = val; 690 s->last_mv[i][0][k] = val;
691 s->last_mv[i][1][k] = val; 691 s->last_mv[i][1][k] = val;
737 } 737 }
738 } 738 }
739 } 739 }
740 740
741 if ((mb_type & MB_INTRA) && s->concealment_motion_vectors) { 741 if ((mb_type & MB_INTRA) && s->concealment_motion_vectors) {
742 get_bits(&s->gb, 1); /* marker */ 742 skip_bits1(&s->gb); /* marker */
743 } 743 }
744 744
745 if (mb_type & MB_PAT) { 745 if (mb_type & MB_PAT) {
746 cbp = get_vlc(&s->gb, &mb_pat_vlc); 746 cbp = get_vlc(&s->gb, &mb_pat_vlc);
747 if (cbp < 0) 747 if (cbp < 0)
787 return 0xffff; 787 return 0xffff;
788 } 788 }
789 if (code == 0) { 789 if (code == 0) {
790 return pred; 790 return pred;
791 } 791 }
792 sign = get_bits(&s->gb, 1); 792 sign = get_bits1(&s->gb);
793 shift = fcode - 1; 793 shift = fcode - 1;
794 val = (code - 1) << shift; 794 val = (code - 1) << shift;
795 if (shift > 0) 795 if (shift > 0)
796 val |= get_bits(&s->gb, shift); 796 val |= get_bits(&s->gb, shift);
797 val++; 797 val++;
888 level = get_bits(&s->gb, 8); 888 level = get_bits(&s->gb, 8);
889 } 889 }
890 } else { 890 } else {
891 run = rl->table_run[code]; 891 run = rl->table_run[code];
892 level = rl->table_level[code]; 892 level = rl->table_level[code];
893 if (get_bits(&s->gb, 1)) 893 if (get_bits1(&s->gb))
894 level = -level; 894 level = -level;
895 } 895 }
896 i += run; 896 i += run;
897 if (i >= 64) 897 if (i >= 64)
898 return -1; 898 return -1;
961 level = get_bits(&s->gb, 12); 961 level = get_bits(&s->gb, 12);
962 level = (level << 20) >> 20; 962 level = (level << 20) >> 20;
963 } else { 963 } else {
964 run = rl->table_run[code]; 964 run = rl->table_run[code];
965 level = rl->table_level[code]; 965 level = rl->table_level[code];
966 if (get_bits(&s->gb, 1)) 966 if (get_bits1(&s->gb))
967 level = -level; 967 level = -level;
968 } 968 }
969 i += run; 969 i += run;
970 if (i >= 64) 970 if (i >= 64)
971 return -1; 971 return -1;
1034 level = get_bits(&s->gb, 12); 1034 level = get_bits(&s->gb, 12);
1035 level = (level << 20) >> 20; 1035 level = (level << 20) >> 20;
1036 } else { 1036 } else {
1037 run = rl->table_run[code]; 1037 run = rl->table_run[code];
1038 level = rl->table_level[code]; 1038 level = rl->table_level[code];
1039 if (get_bits(&s->gb, 1)) 1039 if (get_bits1(&s->gb))
1040 level = -level; 1040 level = -level;
1041 } 1041 }
1042 i += run; 1042 i += run;
1043 if (i >= 64) 1043 if (i >= 64)
1044 return -1; 1044 return -1;
1119 init_get_bits(&s->gb, buf, buf_size); 1119 init_get_bits(&s->gb, buf, buf_size);
1120 1120
1121 ref = get_bits(&s->gb, 10); /* temporal ref */ 1121 ref = get_bits(&s->gb, 10); /* temporal ref */
1122 s->pict_type = get_bits(&s->gb, 3); 1122 s->pict_type = get_bits(&s->gb, 3);
1123 dprintf("pict_type=%d\n", s->pict_type); 1123 dprintf("pict_type=%d\n", s->pict_type);
1124 get_bits(&s->gb, 16); 1124 skip_bits(&s->gb, 16);
1125 if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) { 1125 if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {
1126 s->full_pel[0] = get_bits(&s->gb, 1); 1126 s->full_pel[0] = get_bits1(&s->gb);
1127 f_code = get_bits(&s->gb, 3); 1127 f_code = get_bits(&s->gb, 3);
1128 if (f_code == 0) 1128 if (f_code == 0)
1129 return -1; 1129 return -1;
1130 s->mpeg_f_code[0][0] = f_code; 1130 s->mpeg_f_code[0][0] = f_code;
1131 s->mpeg_f_code[0][1] = f_code; 1131 s->mpeg_f_code[0][1] = f_code;
1132 } 1132 }
1133 if (s->pict_type == B_TYPE) { 1133 if (s->pict_type == B_TYPE) {
1134 s->full_pel[1] = get_bits(&s->gb, 1); 1134 s->full_pel[1] = get_bits1(&s->gb);
1135 f_code = get_bits(&s->gb, 3); 1135 f_code = get_bits(&s->gb, 3);
1136 if (f_code == 0) 1136 if (f_code == 0)
1137 return -1; 1137 return -1;
1138 s->mpeg_f_code[1][0] = f_code; 1138 s->mpeg_f_code[1][0] = f_code;
1139 s->mpeg_f_code[1][1] = f_code; 1139 s->mpeg_f_code[1][1] = f_code;
1148 { 1148 {
1149 int horiz_size_ext, vert_size_ext; 1149 int horiz_size_ext, vert_size_ext;
1150 int bit_rate_ext, vbv_buf_ext, low_delay; 1150 int bit_rate_ext, vbv_buf_ext, low_delay;
1151 int frame_rate_ext_n, frame_rate_ext_d; 1151 int frame_rate_ext_n, frame_rate_ext_d;
1152 1152
1153 get_bits(&s->gb, 8); /* profil and level */ 1153 skip_bits(&s->gb, 8); /* profil and level */
1154 get_bits(&s->gb, 1); /* progressive_sequence */ 1154 skip_bits(&s->gb, 1); /* progressive_sequence */
1155 get_bits(&s->gb, 2); /* chroma_format */ 1155 skip_bits(&s->gb, 2); /* chroma_format */
1156 horiz_size_ext = get_bits(&s->gb, 2); 1156 horiz_size_ext = get_bits(&s->gb, 2);
1157 vert_size_ext = get_bits(&s->gb, 2); 1157 vert_size_ext = get_bits(&s->gb, 2);
1158 s->width |= (horiz_size_ext << 12); 1158 s->width |= (horiz_size_ext << 12);
1159 s->height |= (vert_size_ext << 12); 1159 s->height |= (vert_size_ext << 12);
1160 bit_rate_ext = get_bits(&s->gb, 12); /* XXX: handle it */ 1160 bit_rate_ext = get_bits(&s->gb, 12); /* XXX: handle it */
1161 s->bit_rate = ((s->bit_rate / 400) | (bit_rate_ext << 12)) * 400; 1161 s->bit_rate = ((s->bit_rate / 400) | (bit_rate_ext << 12)) * 400;
1162 get_bits(&s->gb, 1); /* marker */ 1162 skip_bits1(&s->gb); /* marker */
1163 vbv_buf_ext = get_bits(&s->gb, 8); 1163 vbv_buf_ext = get_bits(&s->gb, 8);
1164 low_delay = get_bits(&s->gb, 1); 1164 low_delay = get_bits1(&s->gb);
1165 frame_rate_ext_n = get_bits(&s->gb, 2); 1165 frame_rate_ext_n = get_bits(&s->gb, 2);
1166 frame_rate_ext_d = get_bits(&s->gb, 5); 1166 frame_rate_ext_d = get_bits(&s->gb, 5);
1167 if (frame_rate_ext_d >= 1) 1167 if (frame_rate_ext_d >= 1)
1168 s->frame_rate = (s->frame_rate * frame_rate_ext_n) / frame_rate_ext_d; 1168 s->frame_rate = (s->frame_rate * frame_rate_ext_n) / frame_rate_ext_d;
1169 dprintf("sequence extension\n"); 1169 dprintf("sequence extension\n");
1172 1172
1173 static void mpeg_decode_quant_matrix_extension(MpegEncContext *s) 1173 static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
1174 { 1174 {
1175 int i, v; 1175 int i, v;
1176 1176
1177 if (get_bits(&s->gb, 1)) { 1177 if (get_bits1(&s->gb)) {
1178 for(i=0;i<64;i++) { 1178 for(i=0;i<64;i++) {
1179 v = get_bits(&s->gb, 8); 1179 v = get_bits(&s->gb, 8);
1180 s->intra_matrix[i] = v; 1180 s->intra_matrix[i] = v;
1181 s->chroma_intra_matrix[i] = v; 1181 s->chroma_intra_matrix[i] = v;
1182 } 1182 }
1183 } 1183 }
1184 if (get_bits(&s->gb, 1)) { 1184 if (get_bits1(&s->gb)) {
1185 for(i=0;i<64;i++) { 1185 for(i=0;i<64;i++) {
1186 v = get_bits(&s->gb, 8); 1186 v = get_bits(&s->gb, 8);
1187 s->non_intra_matrix[i] = v; 1187 s->non_intra_matrix[i] = v;
1188 s->chroma_non_intra_matrix[i] = v; 1188 s->chroma_non_intra_matrix[i] = v;
1189 } 1189 }
1190 } 1190 }
1191 if (get_bits(&s->gb, 1)) { 1191 if (get_bits1(&s->gb)) {
1192 for(i=0;i<64;i++) { 1192 for(i=0;i<64;i++) {
1193 v = get_bits(&s->gb, 8); 1193 v = get_bits(&s->gb, 8);
1194 s->chroma_intra_matrix[i] = v; 1194 s->chroma_intra_matrix[i] = v;
1195 } 1195 }
1196 } 1196 }
1197 if (get_bits(&s->gb, 1)) { 1197 if (get_bits1(&s->gb)) {
1198 for(i=0;i<64;i++) { 1198 for(i=0;i<64;i++) {
1199 v = get_bits(&s->gb, 8); 1199 v = get_bits(&s->gb, 8);
1200 s->chroma_non_intra_matrix[i] = v; 1200 s->chroma_non_intra_matrix[i] = v;
1201 } 1201 }
1202 } 1202 }
1209 s->mpeg_f_code[0][1] = get_bits(&s->gb, 4); 1209 s->mpeg_f_code[0][1] = get_bits(&s->gb, 4);
1210 s->mpeg_f_code[1][0] = get_bits(&s->gb, 4); 1210 s->mpeg_f_code[1][0] = get_bits(&s->gb, 4);
1211 s->mpeg_f_code[1][1] = get_bits(&s->gb, 4); 1211 s->mpeg_f_code[1][1] = get_bits(&s->gb, 4);
1212 s->intra_dc_precision = get_bits(&s->gb, 2); 1212 s->intra_dc_precision = get_bits(&s->gb, 2);
1213 s->picture_structure = get_bits(&s->gb, 2); 1213 s->picture_structure = get_bits(&s->gb, 2);
1214 s->top_field_first = get_bits(&s->gb, 1); 1214 s->top_field_first = get_bits1(&s->gb);
1215 s->frame_pred_frame_dct = get_bits(&s->gb, 1); 1215 s->frame_pred_frame_dct = get_bits1(&s->gb);
1216 s->concealment_motion_vectors = get_bits(&s->gb, 1); 1216 s->concealment_motion_vectors = get_bits1(&s->gb);
1217 s->q_scale_type = get_bits(&s->gb, 1); 1217 s->q_scale_type = get_bits1(&s->gb);
1218 s->intra_vlc_format = get_bits(&s->gb, 1); 1218 s->intra_vlc_format = get_bits1(&s->gb);
1219 s->alternate_scan = get_bits(&s->gb, 1); 1219 s->alternate_scan = get_bits1(&s->gb);
1220 s->repeat_first_field = get_bits(&s->gb, 1); 1220 s->repeat_first_field = get_bits1(&s->gb);
1221 s->chroma_420_type = get_bits(&s->gb, 1); 1221 s->chroma_420_type = get_bits1(&s->gb);
1222 s->progressive_frame = get_bits(&s->gb, 1); 1222 s->progressive_frame = get_bits1(&s->gb);
1223 /* composite display not parsed */ 1223 /* composite display not parsed */
1224 dprintf("dc_preci=%d\n", s->intra_dc_precision); 1224 dprintf("dc_preci=%d\n", s->intra_dc_precision);
1225 dprintf("pict_structure=%d\n", s->picture_structure); 1225 dprintf("pict_structure=%d\n", s->picture_structure);
1226 dprintf("conceal=%d\n", s->concealment_motion_vectors); 1226 dprintf("conceal=%d\n", s->concealment_motion_vectors);
1227 dprintf("intrafmt=%d\n", s->intra_vlc_format); 1227 dprintf("intrafmt=%d\n", s->intra_vlc_format);
1283 1283
1284 init_get_bits(&s->gb, buf, buf_size); 1284 init_get_bits(&s->gb, buf, buf_size);
1285 1285
1286 s->qscale = get_bits(&s->gb, 5); 1286 s->qscale = get_bits(&s->gb, 5);
1287 /* extra slice info */ 1287 /* extra slice info */
1288 while (get_bits(&s->gb, 1) != 0) { 1288 while (get_bits1(&s->gb) != 0) {
1289 get_bits(&s->gb, 8); 1289 skip_bits(&s->gb, 8);
1290 } 1290 }
1291 1291
1292 for(;;) { 1292 for(;;) {
1293 memset(s->block, 0, sizeof(s->block)); 1293 memset(s->block, 0, sizeof(s->block));
1294 ret = mpeg_decode_mb(s, s->block); 1294 ret = mpeg_decode_mb(s, s->block);
1349 1349
1350 init_get_bits(&s->gb, buf, buf_size); 1350 init_get_bits(&s->gb, buf, buf_size);
1351 1351
1352 width = get_bits(&s->gb, 12); 1352 width = get_bits(&s->gb, 12);
1353 height = get_bits(&s->gb, 12); 1353 height = get_bits(&s->gb, 12);
1354 get_bits(&s->gb, 4); 1354 skip_bits(&s->gb, 4);
1355 s->frame_rate_index = get_bits(&s->gb, 4); 1355 s->frame_rate_index = get_bits(&s->gb, 4);
1356 if (s->frame_rate_index == 0) 1356 if (s->frame_rate_index == 0)
1357 return -1; 1357 return -1;
1358 s->bit_rate = get_bits(&s->gb, 18) * 400; 1358 s->bit_rate = get_bits(&s->gb, 18) * 400;
1359 if (get_bits(&s->gb, 1) == 0) /* marker */ 1359 if (get_bits1(&s->gb) == 0) /* marker */
1360 return -1; 1360 return -1;
1361 if (width <= 0 || height <= 0 || 1361 if (width <= 0 || height <= 0 ||
1362 (width % 2) != 0 || (height % 2) != 0) 1362 (width % 2) != 0 || (height % 2) != 0)
1363 return -1; 1363 return -1;
1364 if (width != s->width || 1364 if (width != s->width ||
1380 return -1; 1380 return -1;
1381 mpeg1_init_vlc(s); 1381 mpeg1_init_vlc(s);
1382 s1->mpeg_enc_ctx_allocated = 1; 1382 s1->mpeg_enc_ctx_allocated = 1;
1383 } 1383 }
1384 1384
1385 get_bits(&s->gb, 10); /* vbv_buffer_size */ 1385 skip_bits(&s->gb, 10); /* vbv_buffer_size */
1386 get_bits(&s->gb, 1); 1386 skip_bits(&s->gb, 1);
1387 1387
1388 /* get matrix */ 1388 /* get matrix */
1389 if (get_bits(&s->gb, 1)) { 1389 if (get_bits1(&s->gb)) {
1390 for(i=0;i<64;i++) { 1390 for(i=0;i<64;i++) {
1391 v = get_bits(&s->gb, 8); 1391 v = get_bits(&s->gb, 8);
1392 s->intra_matrix[i] = v; 1392 s->intra_matrix[i] = v;
1393 s->chroma_intra_matrix[i] = v; 1393 s->chroma_intra_matrix[i] = v;
1394 } 1394 }
1397 v = default_intra_matrix[i]; 1397 v = default_intra_matrix[i];
1398 s->intra_matrix[i] = v; 1398 s->intra_matrix[i] = v;
1399 s->chroma_intra_matrix[i] = v; 1399 s->chroma_intra_matrix[i] = v;
1400 } 1400 }
1401 } 1401 }
1402 if (get_bits(&s->gb, 1)) { 1402 if (get_bits1(&s->gb)) {
1403 for(i=0;i<64;i++) { 1403 for(i=0;i<64;i++) {
1404 v = get_bits(&s->gb, 8); 1404 v = get_bits(&s->gb, 8);
1405 s->non_intra_matrix[i] = v; 1405 s->non_intra_matrix[i] = v;
1406 s->chroma_non_intra_matrix[i] = v; 1406 s->chroma_non_intra_matrix[i] = v;
1407 } 1407 }