comparison h264.c @ 4600:6ac364a4ce2b libavcodec

Supply context to tprintf
author mbardiaux
date Tue, 27 Feb 2007 09:39:04 +0000
parents a96d905dcbaa
children 8036b117ae26
comparison
equal deleted inserted replaced
4599:2cd245d65761 4600:6ac364a4ce2b
542 const int top_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[top_pair_xy]); 542 const int top_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[top_pair_xy]);
543 const int topright_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[topright_pair_xy]); 543 const int topright_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[topright_pair_xy]);
544 const int left_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[pair_xy-1]); 544 const int left_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[pair_xy-1]);
545 const int curr_mb_frame_flag = !IS_INTERLACED(mb_type); 545 const int curr_mb_frame_flag = !IS_INTERLACED(mb_type);
546 const int bottom = (s->mb_y & 1); 546 const int bottom = (s->mb_y & 1);
547 tprintf("fill_caches: curr_mb_frame_flag:%d, left_mb_frame_flag:%d, topleft_mb_frame_flag:%d, top_mb_frame_flag:%d, topright_mb_frame_flag:%d\n", curr_mb_frame_flag, left_mb_frame_flag, topleft_mb_frame_flag, top_mb_frame_flag, topright_mb_frame_flag); 547 tprintf(s->avctx, "fill_caches: curr_mb_frame_flag:%d, left_mb_frame_flag:%d, topleft_mb_frame_flag:%d, top_mb_frame_flag:%d, topright_mb_frame_flag:%d\n", curr_mb_frame_flag, left_mb_frame_flag, topleft_mb_frame_flag, top_mb_frame_flag, topright_mb_frame_flag);
548 if (bottom 548 if (bottom
549 ? !curr_mb_frame_flag // bottom macroblock 549 ? !curr_mb_frame_flag // bottom macroblock
550 : (!curr_mb_frame_flag && !top_mb_frame_flag) // top macroblock 550 : (!curr_mb_frame_flag && !top_mb_frame_flag) // top macroblock
551 ) { 551 ) {
552 top_xy -= s->mb_stride; 552 top_xy -= s->mb_stride;
1058 const int index8= scan8[n]; 1058 const int index8= scan8[n];
1059 const int left= h->intra4x4_pred_mode_cache[index8 - 1]; 1059 const int left= h->intra4x4_pred_mode_cache[index8 - 1];
1060 const int top = h->intra4x4_pred_mode_cache[index8 - 8]; 1060 const int top = h->intra4x4_pred_mode_cache[index8 - 8];
1061 const int min= FFMIN(left, top); 1061 const int min= FFMIN(left, top);
1062 1062
1063 tprintf("mode:%d %d min:%d\n", left ,top, min); 1063 tprintf(h->s.avctx, "mode:%d %d min:%d\n", left ,top, min);
1064 1064
1065 if(min<0) return DC_PRED; 1065 if(min<0) return DC_PRED;
1066 else return min; 1066 else return min;
1067 } 1067 }
1068 1068
1105 const int top = h->non_zero_count_cache[index8 - 8]; 1105 const int top = h->non_zero_count_cache[index8 - 8];
1106 int i= left + top; 1106 int i= left + top;
1107 1107
1108 if(i<64) i= (i+1)>>1; 1108 if(i<64) i= (i+1)>>1;
1109 1109
1110 tprintf("pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31); 1110 tprintf(h->s.avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31);
1111 1111
1112 return i&31; 1112 return i&31;
1113 } 1113 }
1114 1114
1115 static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){ 1115 static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){
1116 const int topright_ref= h->ref_cache[list][ i - 8 + part_width ]; 1116 const int topright_ref= h->ref_cache[list][ i - 8 + part_width ];
1117 MpegEncContext *s = &h->s;
1117 1118
1118 /* there is no consistent mapping of mvs to neighboring locations that will 1119 /* there is no consistent mapping of mvs to neighboring locations that will
1119 * make mbaff happy, so we can't move all this logic to fill_caches */ 1120 * make mbaff happy, so we can't move all this logic to fill_caches */
1120 if(FRAME_MBAFF){ 1121 if(FRAME_MBAFF){
1121 MpegEncContext *s = &h->s;
1122 const uint32_t *mb_types = s->current_picture_ptr->mb_type; 1122 const uint32_t *mb_types = s->current_picture_ptr->mb_type;
1123 const int16_t *mv; 1123 const int16_t *mv;
1124 *(uint32_t*)h->mv_cache[list][scan8[0]-2] = 0; 1124 *(uint32_t*)h->mv_cache[list][scan8[0]-2] = 0;
1125 *C = h->mv_cache[list][scan8[0]-2]; 1125 *C = h->mv_cache[list][scan8[0]-2];
1126 1126
1160 1160
1161 if(topright_ref != PART_NOT_AVAILABLE){ 1161 if(topright_ref != PART_NOT_AVAILABLE){
1162 *C= h->mv_cache[list][ i - 8 + part_width ]; 1162 *C= h->mv_cache[list][ i - 8 + part_width ];
1163 return topright_ref; 1163 return topright_ref;
1164 }else{ 1164 }else{
1165 tprintf("topright MV not available\n"); 1165 tprintf(s->avctx, "topright MV not available\n");
1166 1166
1167 *C= h->mv_cache[list][ i - 8 - 1 ]; 1167 *C= h->mv_cache[list][ i - 8 - 1 ];
1168 return h->ref_cache[list][ i - 8 - 1 ]; 1168 return h->ref_cache[list][ i - 8 - 1 ];
1169 } 1169 }
1170 } 1170 }
1195 . . . L . . . . 1195 . . . L . . . .
1196 */ 1196 */
1197 1197
1198 diagonal_ref= fetch_diagonal_mv(h, &C, index8, list, part_width); 1198 diagonal_ref= fetch_diagonal_mv(h, &C, index8, list, part_width);
1199 match_count= (diagonal_ref==ref) + (top_ref==ref) + (left_ref==ref); 1199 match_count= (diagonal_ref==ref) + (top_ref==ref) + (left_ref==ref);
1200 tprintf("pred_motion match_count=%d\n", match_count); 1200 tprintf(h->s.avctx, "pred_motion match_count=%d\n", match_count);
1201 if(match_count > 1){ //most common 1201 if(match_count > 1){ //most common
1202 *mx= mid_pred(A[0], B[0], C[0]); 1202 *mx= mid_pred(A[0], B[0], C[0]);
1203 *my= mid_pred(A[1], B[1], C[1]); 1203 *my= mid_pred(A[1], B[1], C[1]);
1204 }else if(match_count==1){ 1204 }else if(match_count==1){
1205 if(left_ref==ref){ 1205 if(left_ref==ref){
1220 *mx= mid_pred(A[0], B[0], C[0]); 1220 *mx= mid_pred(A[0], B[0], C[0]);
1221 *my= mid_pred(A[1], B[1], C[1]); 1221 *my= mid_pred(A[1], B[1], C[1]);
1222 } 1222 }
1223 } 1223 }
1224 1224
1225 tprintf("pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, A[0], A[1], ref, *mx, *my, h->s.mb_x, h->s.mb_y, n, list); 1225 tprintf(h->s.avctx, "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, A[0], A[1], ref, *mx, *my, h->s.mb_x, h->s.mb_y, n, list);
1226 } 1226 }
1227 1227
1228 /** 1228 /**
1229 * gets the directionally predicted 16x8 MV. 1229 * gets the directionally predicted 16x8 MV.
1230 * @param n the block index 1230 * @param n the block index
1234 static inline void pred_16x8_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ 1234 static inline void pred_16x8_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){
1235 if(n==0){ 1235 if(n==0){
1236 const int top_ref= h->ref_cache[list][ scan8[0] - 8 ]; 1236 const int top_ref= h->ref_cache[list][ scan8[0] - 8 ];
1237 const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ]; 1237 const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ];
1238 1238
1239 tprintf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list); 1239 tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list);
1240 1240
1241 if(top_ref == ref){ 1241 if(top_ref == ref){
1242 *mx= B[0]; 1242 *mx= B[0];
1243 *my= B[1]; 1243 *my= B[1];
1244 return; 1244 return;
1245 } 1245 }
1246 }else{ 1246 }else{
1247 const int left_ref= h->ref_cache[list][ scan8[8] - 1 ]; 1247 const int left_ref= h->ref_cache[list][ scan8[8] - 1 ];
1248 const int16_t * const A= h->mv_cache[list][ scan8[8] - 1 ]; 1248 const int16_t * const A= h->mv_cache[list][ scan8[8] - 1 ];
1249 1249
1250 tprintf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); 1250 tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list);
1251 1251
1252 if(left_ref == ref){ 1252 if(left_ref == ref){
1253 *mx= A[0]; 1253 *mx= A[0];
1254 *my= A[1]; 1254 *my= A[1];
1255 return; 1255 return;
1269 static inline void pred_8x16_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ 1269 static inline void pred_8x16_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){
1270 if(n==0){ 1270 if(n==0){
1271 const int left_ref= h->ref_cache[list][ scan8[0] - 1 ]; 1271 const int left_ref= h->ref_cache[list][ scan8[0] - 1 ];
1272 const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ]; 1272 const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ];
1273 1273
1274 tprintf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); 1274 tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list);
1275 1275
1276 if(left_ref == ref){ 1276 if(left_ref == ref){
1277 *mx= A[0]; 1277 *mx= A[0];
1278 *my= A[1]; 1278 *my= A[1];
1279 return; 1279 return;
1282 const int16_t * C; 1282 const int16_t * C;
1283 int diagonal_ref; 1283 int diagonal_ref;
1284 1284
1285 diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2); 1285 diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2);
1286 1286
1287 tprintf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list); 1287 tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list);
1288 1288
1289 if(diagonal_ref == ref){ 1289 if(diagonal_ref == ref){
1290 *mx= C[0]; 1290 *mx= C[0];
1291 *my= C[1]; 1291 *my= C[1];
1292 return; 1292 return;
1299 1299
1300 static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my){ 1300 static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my){
1301 const int top_ref = h->ref_cache[0][ scan8[0] - 8 ]; 1301 const int top_ref = h->ref_cache[0][ scan8[0] - 8 ];
1302 const int left_ref= h->ref_cache[0][ scan8[0] - 1 ]; 1302 const int left_ref= h->ref_cache[0][ scan8[0] - 1 ];
1303 1303
1304 tprintf("pred_pskip: (%d) (%d) at %2d %2d\n", top_ref, left_ref, h->s.mb_x, h->s.mb_y); 1304 tprintf(h->s.avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", top_ref, left_ref, h->s.mb_x, h->s.mb_y);
1305 1305
1306 if(top_ref == PART_NOT_AVAILABLE || left_ref == PART_NOT_AVAILABLE 1306 if(top_ref == PART_NOT_AVAILABLE || left_ref == PART_NOT_AVAILABLE
1307 || (top_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 8 ] == 0) 1307 || (top_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 8 ] == 0)
1308 || (left_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 1 ] == 0)){ 1308 || (left_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 1 ] == 0)){
1309 1309
1406 if(!is_b8x8) 1406 if(!is_b8x8)
1407 *mb_type |= MB_TYPE_DIRECT2; 1407 *mb_type |= MB_TYPE_DIRECT2;
1408 if(MB_FIELD) 1408 if(MB_FIELD)
1409 *mb_type |= MB_TYPE_INTERLACED; 1409 *mb_type |= MB_TYPE_INTERLACED;
1410 1410
1411 tprintf("mb_type = %08x, sub_mb_type = %08x, is_b8x8 = %d, mb_type_col = %08x\n", *mb_type, sub_mb_type, is_b8x8, mb_type_col); 1411 tprintf(s->avctx, "mb_type = %08x, sub_mb_type = %08x, is_b8x8 = %d, mb_type_col = %08x\n", *mb_type, sub_mb_type, is_b8x8, mb_type_col);
1412 1412
1413 if(h->direct_spatial_mv_pred){ 1413 if(h->direct_spatial_mv_pred){
1414 int ref[2]; 1414 int ref[2];
1415 int mv[2][2]; 1415 int mv[2][2];
1416 int list; 1416 int list;
1801 1801
1802 /** 1802 /**
1803 * identifies the exact end of the bitstream 1803 * identifies the exact end of the bitstream
1804 * @return the length of the trailing, or 0 if damaged 1804 * @return the length of the trailing, or 0 if damaged
1805 */ 1805 */
1806 static int decode_rbsp_trailing(uint8_t *src){ 1806 static int decode_rbsp_trailing(H264Context *h, uint8_t *src){
1807 int v= *src; 1807 int v= *src;
1808 int r; 1808 int r;
1809 1809
1810 tprintf("rbsp trailing %X\n", v); 1810 tprintf(h->s.avctx, "rbsp trailing %X\n", v);
1811 1811
1812 for(r=1; r<9; r++){ 1812 for(r=1; r<9; r++){
1813 if(v&1) return r; 1813 if(v&1) return r;
1814 v>>=1; 1814 v>>=1;
1815 } 1815 }
3450 int temp8, i; 3450 int temp8, i;
3451 uint64_t temp64; 3451 uint64_t temp64;
3452 int deblock_left = (s->mb_x > 0); 3452 int deblock_left = (s->mb_x > 0);
3453 int deblock_top = (s->mb_y > 1); 3453 int deblock_top = (s->mb_y > 1);
3454 3454
3455 tprintf("xchg_pair_border: src_y:%p src_cb:%p src_cr:%p ls:%d uvls:%d\n", src_y, src_cb, src_cr, linesize, uvlinesize); 3455 tprintf(s->avctx, "xchg_pair_border: src_y:%p src_cb:%p src_cr:%p ls:%d uvls:%d\n", src_y, src_cb, src_cr, linesize, uvlinesize);
3456 3456
3457 src_y -= 2 * linesize + 1; 3457 src_y -= 2 * linesize + 1;
3458 src_cb -= 2 * uvlinesize + 1; 3458 src_cb -= 2 * uvlinesize + 1;
3459 src_cr -= 2 * uvlinesize + 1; 3459 src_cr -= 2 * uvlinesize + 1;
3460 3460
3750 3750
3751 backup_pair_border(h, pair_dest_y, pair_dest_cb, pair_dest_cr, s->linesize, s->uvlinesize); 3751 backup_pair_border(h, pair_dest_y, pair_dest_cb, pair_dest_cr, s->linesize, s->uvlinesize);
3752 // deblock a pair 3752 // deblock a pair
3753 // top 3753 // top
3754 s->mb_y--; 3754 s->mb_y--;
3755 tprintf("call mbaff filter_mb mb_x:%d mb_y:%d pair_dest_y = %p, dest_y = %p\n", mb_x, mb_y, pair_dest_y, dest_y); 3755 tprintf(h->s.avctx, "call mbaff filter_mb mb_x:%d mb_y:%d pair_dest_y = %p, dest_y = %p\n", mb_x, mb_y, pair_dest_y, dest_y);
3756 fill_caches(h, mb_type_top, 1); //FIXME don't fill stuff which isn't used by filter_mb 3756 fill_caches(h, mb_type_top, 1); //FIXME don't fill stuff which isn't used by filter_mb
3757 h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy]); 3757 h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy]);
3758 filter_mb(h, mb_x, mb_y, pair_dest_y, pair_dest_cb, pair_dest_cr, linesize, uvlinesize); 3758 filter_mb(h, mb_x, mb_y, pair_dest_y, pair_dest_cb, pair_dest_cr, linesize, uvlinesize);
3759 // bottom 3759 // bottom
3760 s->mb_y++; 3760 s->mb_y++;
3761 tprintf("call mbaff filter_mb\n"); 3761 tprintf(h->s.avctx, "call mbaff filter_mb\n");
3762 fill_caches(h, mb_type_bottom, 1); //FIXME don't fill stuff which isn't used by filter_mb 3762 fill_caches(h, mb_type_bottom, 1); //FIXME don't fill stuff which isn't used by filter_mb
3763 h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy+s->mb_stride]); 3763 h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy+s->mb_stride]);
3764 filter_mb(h, mb_x, mb_y+1, dest_y, dest_cb, dest_cr, linesize, uvlinesize); 3764 filter_mb(h, mb_x, mb_y+1, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
3765 } else { 3765 } else {
3766 tprintf("call filter_mb\n"); 3766 tprintf(h->s.avctx, "call filter_mb\n");
3767 backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize); 3767 backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
3768 fill_caches(h, mb_type, 1); //FIXME don't fill stuff which isn't used by filter_mb 3768 fill_caches(h, mb_type, 1); //FIXME don't fill stuff which isn't used by filter_mb
3769 filter_mb_fast(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize); 3769 filter_mb_fast(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
3770 } 3770 }
3771 } 3771 }
3829 3829
3830 assert(best_i != INT_MIN); 3830 assert(best_i != INT_MIN);
3831 3831
3832 limit= best_poc; 3832 limit= best_poc;
3833 sorted_short_ref[out_i]= *h->short_ref[best_i]; 3833 sorted_short_ref[out_i]= *h->short_ref[best_i];
3834 tprintf("sorted poc: %d->%d poc:%d fn:%d\n", best_i, out_i, sorted_short_ref[out_i].poc, sorted_short_ref[out_i].frame_num); 3834 tprintf(h->s.avctx, "sorted poc: %d->%d poc:%d fn:%d\n", best_i, out_i, sorted_short_ref[out_i].poc, sorted_short_ref[out_i].frame_num);
3835 if (-1 == smallest_poc_greater_than_current) { 3835 if (-1 == smallest_poc_greater_than_current) {
3836 if (h->short_ref[best_i]->poc >= s->current_picture_ptr->poc) { 3836 if (h->short_ref[best_i]->poc >= s->current_picture_ptr->poc) {
3837 smallest_poc_greater_than_current = out_i; 3837 smallest_poc_greater_than_current = out_i;
3838 } 3838 }
3839 } 3839 }
3841 } 3841 }
3842 3842
3843 if(s->picture_structure == PICT_FRAME){ 3843 if(s->picture_structure == PICT_FRAME){
3844 if(h->slice_type==B_TYPE){ 3844 if(h->slice_type==B_TYPE){
3845 int list; 3845 int list;
3846 tprintf("current poc: %d, smallest_poc_greater_than_current: %d\n", s->current_picture_ptr->poc, smallest_poc_greater_than_current); 3846 tprintf(h->s.avctx, "current poc: %d, smallest_poc_greater_than_current: %d\n", s->current_picture_ptr->poc, smallest_poc_greater_than_current);
3847 3847
3848 // find the largest poc 3848 // find the largest poc
3849 for(list=0; list<2; list++){ 3849 for(list=0; list<2; list++){
3850 int index = 0; 3850 int index = 0;
3851 int j= -99; 3851 int j= -99;
3904 //FIXME second field balh 3904 //FIXME second field balh
3905 } 3905 }
3906 } 3906 }
3907 #ifdef TRACE 3907 #ifdef TRACE
3908 for (i=0; i<h->ref_count[0]; i++) { 3908 for (i=0; i<h->ref_count[0]; i++) {
3909 tprintf("List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].data[0]); 3909 tprintf(h->s.avctx, "List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].data[0]);
3910 } 3910 }
3911 if(h->slice_type==B_TYPE){ 3911 if(h->slice_type==B_TYPE){
3912 for (i=0; i<h->ref_count[1]; i++) { 3912 for (i=0; i<h->ref_count[1]; i++) {
3913 tprintf("List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[0][i].data[0]); 3913 tprintf(h->s.avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[0][i].data[0]);
3914 } 3914 }
3915 } 3915 }
3916 #endif 3916 #endif
3917 return 0; 3917 return 0;
3918 } 3918 }
4913 av_log(h->s.avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", s->mb_x, s->mb_y, total_coeff); 4913 av_log(h->s.avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", s->mb_x, s->mb_y, total_coeff);
4914 return -1; 4914 return -1;
4915 } 4915 }
4916 4916
4917 trailing_ones= coeff_token&3; 4917 trailing_ones= coeff_token&3;
4918 tprintf("trailing:%d, total:%d\n", trailing_ones, total_coeff); 4918 tprintf(h->s.avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff);
4919 assert(total_coeff<=16); 4919 assert(total_coeff<=16);
4920 4920
4921 for(i=0; i<trailing_ones; i++){ 4921 for(i=0; i<trailing_ones; i++){
4922 level[i]= 1 - 2*get_bits1(gb); 4922 level[i]= 1 - 2*get_bits1(gb);
4923 } 4923 }
5090 unsigned int mb_type, cbp; 5090 unsigned int mb_type, cbp;
5091 int dct8x8_allowed= h->pps.transform_8x8_mode; 5091 int dct8x8_allowed= h->pps.transform_8x8_mode;
5092 5092
5093 s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong? 5093 s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong?
5094 5094
5095 tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); 5095 tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
5096 cbp = 0; /* avoid warning. FIXME: find a solution without slowing 5096 cbp = 0; /* avoid warning. FIXME: find a solution without slowing
5097 down the code */ 5097 down the code */
5098 if(h->slice_type != I_TYPE && h->slice_type != SI_TYPE){ 5098 if(h->slice_type != I_TYPE && h->slice_type != SI_TYPE){
5099 if(s->mb_skip_run==-1) 5099 if(s->mb_skip_run==-1)
5100 s->mb_skip_run= get_ue_golomb(&s->gb); 5100 s->mb_skip_run= get_ue_golomb(&s->gb);
5161 5161
5162 // The pixels are stored in the same order as levels in h->mb array. 5162 // The pixels are stored in the same order as levels in h->mb array.
5163 for(y=0; y<16; y++){ 5163 for(y=0; y<16; y++){
5164 const int index= 4*(y&3) + 32*((y>>2)&1) + 128*(y>>3); 5164 const int index= 4*(y&3) + 32*((y>>2)&1) + 128*(y>>3);
5165 for(x=0; x<16; x++){ 5165 for(x=0; x<16; x++){
5166 tprintf("LUMA ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8)); 5166 tprintf(s->avctx, "LUMA ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8));
5167 h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= get_bits(&s->gb, 8); 5167 h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= get_bits(&s->gb, 8);
5168 } 5168 }
5169 } 5169 }
5170 for(y=0; y<8; y++){ 5170 for(y=0; y<8; y++){
5171 const int index= 256 + 4*(y&3) + 32*(y>>2); 5171 const int index= 256 + 4*(y&3) + 32*(y>>2);
5172 for(x=0; x<8; x++){ 5172 for(x=0; x<8; x++){
5173 tprintf("CHROMA U ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8)); 5173 tprintf(s->avctx, "CHROMA U ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8));
5174 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8); 5174 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8);
5175 } 5175 }
5176 } 5176 }
5177 for(y=0; y<8; y++){ 5177 for(y=0; y<8; y++){
5178 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2); 5178 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2);
5179 for(x=0; x<8; x++){ 5179 for(x=0; x<8; x++){
5180 tprintf("CHROMA V ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8)); 5180 tprintf(s->avctx, "CHROMA V ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8));
5181 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8); 5181 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8);
5182 } 5182 }
5183 } 5183 }
5184 5184
5185 // In deblocking, the quantizer is 0 5185 // In deblocking, the quantizer is 0
5312 const int index= 4*i + block_width*j; 5312 const int index= 4*i + block_width*j;
5313 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ]; 5313 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];
5314 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); 5314 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);
5315 mx += get_se_golomb(&s->gb); 5315 mx += get_se_golomb(&s->gb);
5316 my += get_se_golomb(&s->gb); 5316 my += get_se_golomb(&s->gb);
5317 tprintf("final mv:%d %d\n", mx, my); 5317 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
5318 5318
5319 if(IS_SUB_8X8(sub_mb_type)){ 5319 if(IS_SUB_8X8(sub_mb_type)){
5320 mv_cache[ 1 ][0]= 5320 mv_cache[ 1 ][0]=
5321 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; 5321 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
5322 mv_cache[ 1 ][1]= 5322 mv_cache[ 1 ][1]=
5361 unsigned int val; 5361 unsigned int val;
5362 if(IS_DIR(mb_type, 0, list)){ 5362 if(IS_DIR(mb_type, 0, list)){
5363 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); 5363 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);
5364 mx += get_se_golomb(&s->gb); 5364 mx += get_se_golomb(&s->gb);
5365 my += get_se_golomb(&s->gb); 5365 my += get_se_golomb(&s->gb);
5366 tprintf("final mv:%d %d\n", mx, my); 5366 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
5367 5367
5368 val= pack16to32(mx,my); 5368 val= pack16to32(mx,my);
5369 }else 5369 }else
5370 val=0; 5370 val=0;
5371 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, val, 4); 5371 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, val, 4);
5391 unsigned int val; 5391 unsigned int val;
5392 if(IS_DIR(mb_type, i, list)){ 5392 if(IS_DIR(mb_type, i, list)){
5393 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); 5393 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);
5394 mx += get_se_golomb(&s->gb); 5394 mx += get_se_golomb(&s->gb);
5395 my += get_se_golomb(&s->gb); 5395 my += get_se_golomb(&s->gb);
5396 tprintf("final mv:%d %d\n", mx, my); 5396 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
5397 5397
5398 val= pack16to32(mx,my); 5398 val= pack16to32(mx,my);
5399 }else 5399 }else
5400 val=0; 5400 val=0;
5401 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4); 5401 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4);
5422 unsigned int val; 5422 unsigned int val;
5423 if(IS_DIR(mb_type, i, list)){ 5423 if(IS_DIR(mb_type, i, list)){
5424 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); 5424 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);
5425 mx += get_se_golomb(&s->gb); 5425 mx += get_se_golomb(&s->gb);
5426 my += get_se_golomb(&s->gb); 5426 my += get_se_golomb(&s->gb);
5427 tprintf("final mv:%d %d\n", mx, my); 5427 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
5428 5428
5429 val= pack16to32(mx,my); 5429 val= pack16to32(mx,my);
5430 }else 5430 }else
5431 val=0; 5431 val=0;
5432 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 4); 5432 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 4);
5779 int cbp_b = -1; 5779 int cbp_b = -1;
5780 int i8x8; 5780 int i8x8;
5781 5781
5782 if( h->slice_table[h->top_mb_xy] == h->slice_num ) { 5782 if( h->slice_table[h->top_mb_xy] == h->slice_num ) {
5783 cbp_b = h->top_cbp; 5783 cbp_b = h->top_cbp;
5784 tprintf("cbp_b = top_cbp = %x\n", cbp_b); 5784 tprintf(h->s.avctx, "cbp_b = top_cbp = %x\n", cbp_b);
5785 } 5785 }
5786 5786
5787 for( i8x8 = 0; i8x8 < 4; i8x8++ ) { 5787 for( i8x8 = 0; i8x8 < 4; i8x8++ ) {
5788 int cbp_a = -1; 5788 int cbp_a = -1;
5789 int x, y; 5789 int x, y;
5794 5794
5795 if( x > 0 ) 5795 if( x > 0 )
5796 cbp_a = cbp; 5796 cbp_a = cbp;
5797 else if( h->slice_table[h->left_mb_xy[0]] == h->slice_num ) { 5797 else if( h->slice_table[h->left_mb_xy[0]] == h->slice_num ) {
5798 cbp_a = h->left_cbp; 5798 cbp_a = h->left_cbp;
5799 tprintf("cbp_a = left_cbp = %x\n", cbp_a); 5799 tprintf(h->s.avctx, "cbp_a = left_cbp = %x\n", cbp_a);
5800 } 5800 }
5801 5801
5802 if( y > 0 ) 5802 if( y > 0 )
5803 cbp_b = cbp; 5803 cbp_b = cbp;
5804 5804
6218 int mb_type, partition_count, cbp = 0; 6218 int mb_type, partition_count, cbp = 0;
6219 int dct8x8_allowed= h->pps.transform_8x8_mode; 6219 int dct8x8_allowed= h->pps.transform_8x8_mode;
6220 6220
6221 s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong?) 6221 s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong?)
6222 6222
6223 tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); 6223 tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
6224 if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE ) { 6224 if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE ) {
6225 int skip; 6225 int skip;
6226 /* a skipped mb needs the aff flag from the following mb */ 6226 /* a skipped mb needs the aff flag from the following mb */
6227 if( FRAME_MBAFF && s->mb_x==0 && (s->mb_y&1)==0 ) 6227 if( FRAME_MBAFF && s->mb_x==0 && (s->mb_y&1)==0 )
6228 predict_field_decoding_flag(h); 6228 predict_field_decoding_flag(h);
6310 6310
6311 // The pixels are stored in the same order as levels in h->mb array. 6311 // The pixels are stored in the same order as levels in h->mb array.
6312 for(y=0; y<16; y++){ 6312 for(y=0; y<16; y++){
6313 const int index= 4*(y&3) + 32*((y>>2)&1) + 128*(y>>3); 6313 const int index= 4*(y&3) + 32*((y>>2)&1) + 128*(y>>3);
6314 for(x=0; x<16; x++){ 6314 for(x=0; x<16; x++){
6315 tprintf("LUMA ICPM LEVEL (%3d)\n", *ptr); 6315 tprintf(s->avctx, "LUMA ICPM LEVEL (%3d)\n", *ptr);
6316 h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= *ptr++; 6316 h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= *ptr++;
6317 } 6317 }
6318 } 6318 }
6319 for(y=0; y<8; y++){ 6319 for(y=0; y<8; y++){
6320 const int index= 256 + 4*(y&3) + 32*(y>>2); 6320 const int index= 256 + 4*(y&3) + 32*(y>>2);
6321 for(x=0; x<8; x++){ 6321 for(x=0; x<8; x++){
6322 tprintf("CHROMA U ICPM LEVEL (%3d)\n", *ptr); 6322 tprintf(s->avctx, "CHROMA U ICPM LEVEL (%3d)\n", *ptr);
6323 h->mb[index + (x&3) + 16*(x>>2)]= *ptr++; 6323 h->mb[index + (x&3) + 16*(x>>2)]= *ptr++;
6324 } 6324 }
6325 } 6325 }
6326 for(y=0; y<8; y++){ 6326 for(y=0; y<8; y++){
6327 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2); 6327 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2);
6328 for(x=0; x<8; x++){ 6328 for(x=0; x<8; x++){
6329 tprintf("CHROMA V ICPM LEVEL (%3d)\n", *ptr); 6329 tprintf(s->avctx, "CHROMA V ICPM LEVEL (%3d)\n", *ptr);
6330 h->mb[index + (x&3) + 16*(x>>2)]= *ptr++; 6330 h->mb[index + (x&3) + 16*(x>>2)]= *ptr++;
6331 } 6331 }
6332 } 6332 }
6333 6333
6334 ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr); 6334 ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);
6446 int16_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ]; 6446 int16_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ];
6447 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mpx, &mpy); 6447 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mpx, &mpy);
6448 6448
6449 mx = mpx + decode_cabac_mb_mvd( h, list, index, 0 ); 6449 mx = mpx + decode_cabac_mb_mvd( h, list, index, 0 );
6450 my = mpy + decode_cabac_mb_mvd( h, list, index, 1 ); 6450 my = mpy + decode_cabac_mb_mvd( h, list, index, 1 );
6451 tprintf("final mv:%d %d\n", mx, my); 6451 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
6452 6452
6453 if(IS_SUB_8X8(sub_mb_type)){ 6453 if(IS_SUB_8X8(sub_mb_type)){
6454 mv_cache[ 1 ][0]= 6454 mv_cache[ 1 ][0]=
6455 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; 6455 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
6456 mv_cache[ 1 ][1]= 6456 mv_cache[ 1 ][1]=
6506 if(IS_DIR(mb_type, 0, list)){ 6506 if(IS_DIR(mb_type, 0, list)){
6507 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mpx, &mpy); 6507 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mpx, &mpy);
6508 6508
6509 mx = mpx + decode_cabac_mb_mvd( h, list, 0, 0 ); 6509 mx = mpx + decode_cabac_mb_mvd( h, list, 0, 0 );
6510 my = mpy + decode_cabac_mb_mvd( h, list, 0, 1 ); 6510 my = mpy + decode_cabac_mb_mvd( h, list, 0, 1 );
6511 tprintf("final mv:%d %d\n", mx, my); 6511 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
6512 6512
6513 fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx-mpx,my-mpy), 4); 6513 fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx-mpx,my-mpy), 4);
6514 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); 6514 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);
6515 }else 6515 }else
6516 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, 0, 4); 6516 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, 0, 4);
6530 for(i=0; i<2; i++){ 6530 for(i=0; i<2; i++){
6531 if(IS_DIR(mb_type, i, list)){ 6531 if(IS_DIR(mb_type, i, list)){
6532 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mpx, &mpy); 6532 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mpx, &mpy);
6533 mx = mpx + decode_cabac_mb_mvd( h, list, 8*i, 0 ); 6533 mx = mpx + decode_cabac_mb_mvd( h, list, 8*i, 0 );
6534 my = mpy + decode_cabac_mb_mvd( h, list, 8*i, 1 ); 6534 my = mpy + decode_cabac_mb_mvd( h, list, 8*i, 1 );
6535 tprintf("final mv:%d %d\n", mx, my); 6535 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
6536 6536
6537 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx-mpx,my-mpy), 4); 6537 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx-mpx,my-mpy), 4);
6538 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); 6538 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);
6539 }else{ 6539 }else{
6540 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); 6540 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);
6558 if(IS_DIR(mb_type, i, list)){ 6558 if(IS_DIR(mb_type, i, list)){
6559 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mpx, &mpy); 6559 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mpx, &mpy);
6560 mx = mpx + decode_cabac_mb_mvd( h, list, 4*i, 0 ); 6560 mx = mpx + decode_cabac_mb_mvd( h, list, 4*i, 0 );
6561 my = mpy + decode_cabac_mb_mvd( h, list, 4*i, 1 ); 6561 my = mpy + decode_cabac_mb_mvd( h, list, 4*i, 1 );
6562 6562
6563 tprintf("final mv:%d %d\n", mx, my); 6563 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
6564 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx-mpx,my-mpy), 4); 6564 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx-mpx,my-mpy), 4);
6565 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); 6565 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);
6566 }else{ 6566 }else{
6567 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); 6567 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);
6568 fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); 6568 fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);
6751 }else{ 6751 }else{
6752 /* p0', q0' */ 6752 /* p0', q0' */
6753 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; 6753 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
6754 pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; 6754 pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
6755 } 6755 }
6756 tprintf("filter_mb_edgev i:%d d:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, d, p2, p1, p0, q0, q1, q2, pix[-2], pix[-1], pix[0], pix[1]); 6756 tprintf(h->s.avctx, "filter_mb_edgev i:%d d:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, d, p2, p1, p0, q0, q1, q2, pix[-2], pix[-1], pix[0], pix[1]);
6757 } 6757 }
6758 pix += stride; 6758 pix += stride;
6759 } 6759 }
6760 } 6760 }
6761 } 6761 }
6823 } 6823 }
6824 6824
6825 i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); 6825 i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
6826 pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */ 6826 pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */
6827 pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ 6827 pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */
6828 tprintf("filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); 6828 tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1);
6829 } 6829 }
6830 }else{ 6830 }else{
6831 const int p0 = pix[-1]; 6831 const int p0 = pix[-1];
6832 const int p1 = pix[-2]; 6832 const int p1 = pix[-2];
6833 const int p2 = pix[-3]; 6833 const int p2 = pix[-3];
6866 }else{ 6866 }else{
6867 /* p0', q0' */ 6867 /* p0', q0' */
6868 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; 6868 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
6869 pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; 6869 pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
6870 } 6870 }
6871 tprintf("filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, p2, p1, p0, q0, q1, q2, pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]); 6871 tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, p2, p1, p0, q0, q1, q2, pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]);
6872 } 6872 }
6873 } 6873 }
6874 } 6874 }
6875 } 6875 }
6876 static void filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[8], int qp[2] ) { 6876 static void filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[8], int qp[2] ) {
6904 FFABS( q1 - q0 ) < beta ) { 6904 FFABS( q1 - q0 ) < beta ) {
6905 const int i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); 6905 const int i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
6906 6906
6907 pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */ 6907 pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */
6908 pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ 6908 pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */
6909 tprintf("filter_mb_mbaff_edgecv i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); 6909 tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1);
6910 } 6910 }
6911 }else{ 6911 }else{
6912 const int p0 = pix[-1]; 6912 const int p0 = pix[-1];
6913 const int p1 = pix[-2]; 6913 const int p1 = pix[-2];
6914 const int q0 = pix[0]; 6914 const int q0 = pix[0];
6918 FFABS( p1 - p0 ) < beta && 6918 FFABS( p1 - p0 ) < beta &&
6919 FFABS( q1 - q0 ) < beta ) { 6919 FFABS( q1 - q0 ) < beta ) {
6920 6920
6921 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ 6921 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */
6922 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ 6922 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */
6923 tprintf("filter_mb_mbaff_edgecv i:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, pix[-3], p1, p0, q0, q1, pix[2], pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]); 6923 tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, pix[-3], p1, p0, q0, q1, pix[2], pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]);
6924 } 6924 }
6925 } 6925 }
6926 } 6926 }
6927 } 6927 }
6928 6928
6977 }else{ 6977 }else{
6978 /* p0', q0' */ 6978 /* p0', q0' */
6979 pix[-1*pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2; 6979 pix[-1*pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
6980 pix[ 0*pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2; 6980 pix[ 0*pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
6981 } 6981 }
6982 tprintf("filter_mb_edgeh i:%d d:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, d, qp, index_a, alpha, beta, bS[i], p2, p1, p0, q0, q1, q2, pix[-2*pix_next], pix[-pix_next], pix[0], pix[pix_next]); 6982 tprintf(h->s.avctx, "filter_mb_edgeh i:%d d:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, d, qp, index_a, alpha, beta, bS[i], p2, p1, p0, q0, q1, q2, pix[-2*pix_next], pix[-pix_next], pix[0], pix[pix_next]);
6983 } 6983 }
6984 pix++; 6984 pix++;
6985 } 6985 }
6986 } 6986 }
6987 } 6987 }
7180 qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1; 7180 qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1;
7181 chroma_qp[1] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, mb_qp ) + 7181 chroma_qp[1] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, mb_qp ) +
7182 get_chroma_qp( h->pps.chroma_qp_index_offset, mbn1_qp ) + 1 ) >> 1; 7182 get_chroma_qp( h->pps.chroma_qp_index_offset, mbn1_qp ) + 1 ) >> 1;
7183 7183
7184 /* Filter edge */ 7184 /* Filter edge */
7185 tprintf("filter mb:%d/%d MBAFF, QPy:%d/%d, QPc:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], chroma_qp[0], chroma_qp[1], linesize, uvlinesize); 7185 tprintf(s->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPc:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], chroma_qp[0], chroma_qp[1], linesize, uvlinesize);
7186 { int i; for (i = 0; i < 8; i++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); } 7186 { int i; for (i = 0; i < 8; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
7187 filter_mb_mbaff_edgev ( h, &img_y [0], linesize, bS, qp ); 7187 filter_mb_mbaff_edgev ( h, &img_y [0], linesize, bS, qp );
7188 filter_mb_mbaff_edgecv( h, &img_cb[0], uvlinesize, bS, chroma_qp ); 7188 filter_mb_mbaff_edgecv( h, &img_cb[0], uvlinesize, bS, chroma_qp );
7189 filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, chroma_qp ); 7189 filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, chroma_qp );
7190 } 7190 }
7191 /* dir : 0 -> vertical edge, 1 -> horizontal edge */ 7191 /* dir : 0 -> vertical edge, 1 -> horizontal edge */
7243 } 7243 }
7244 } 7244 }
7245 // Do not use s->qscale as luma quantizer because it has not the same 7245 // Do not use s->qscale as luma quantizer because it has not the same
7246 // value in IPCM macroblocks. 7246 // value in IPCM macroblocks.
7247 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; 7247 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1;
7248 tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize); 7248 tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize);
7249 { int i; for (i = 0; i < 4; i++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); } 7249 { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
7250 filter_mb_edgeh( h, &img_y[j*linesize], tmp_linesize, bS, qp ); 7250 filter_mb_edgeh( h, &img_y[j*linesize], tmp_linesize, bS, qp );
7251 chroma_qp = ( h->chroma_qp + 7251 chroma_qp = ( h->chroma_qp +
7252 get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1; 7252 get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
7253 filter_mb_edgech( h, &img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp ); 7253 filter_mb_edgech( h, &img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp );
7254 filter_mb_edgech( h, &img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp ); 7254 filter_mb_edgech( h, &img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp );
7340 7340
7341 /* Filter edge */ 7341 /* Filter edge */
7342 // Do not use s->qscale as luma quantizer because it has not the same 7342 // Do not use s->qscale as luma quantizer because it has not the same
7343 // value in IPCM macroblocks. 7343 // value in IPCM macroblocks.
7344 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; 7344 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1;
7345 //tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp, s->current_picture.qscale_table[mbn_xy]); 7345 //tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp, s->current_picture.qscale_table[mbn_xy]);
7346 tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); 7346 tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
7347 { int i; for (i = 0; i < 4; i++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); } 7347 { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
7348 if( dir == 0 ) { 7348 if( dir == 0 ) {
7349 filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp ); 7349 filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp );
7350 if( (edge&1) == 0 ) { 7350 if( (edge&1) == 0 ) {
7351 int chroma_qp = ( h->chroma_qp + 7351 int chroma_qp = ( h->chroma_qp +
7352 get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1; 7352 get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
7429 ++s->mb_y; 7429 ++s->mb_y;
7430 } 7430 }
7431 } 7431 }
7432 7432
7433 if( eos || s->mb_y >= s->mb_height ) { 7433 if( eos || s->mb_y >= s->mb_height ) {
7434 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); 7434 tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
7435 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); 7435 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
7436 return 0; 7436 return 0;
7437 } 7437 }
7438 } 7438 }
7439 7439
7464 ++s->mb_y; 7464 ++s->mb_y;
7465 if(FRAME_MBAFF) { 7465 if(FRAME_MBAFF) {
7466 ++s->mb_y; 7466 ++s->mb_y;
7467 } 7467 }
7468 if(s->mb_y >= s->mb_height){ 7468 if(s->mb_y >= s->mb_height){
7469 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); 7469 tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
7470 7470
7471 if(get_bits_count(&s->gb) == s->gb.size_in_bits ) { 7471 if(get_bits_count(&s->gb) == s->gb.size_in_bits ) {
7472 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); 7472 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
7473 7473
7474 return 0; 7474 return 0;
7479 } 7479 }
7480 } 7480 }
7481 } 7481 }
7482 7482
7483 if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){ 7483 if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){
7484 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); 7484 tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
7485 if(get_bits_count(&s->gb) == s->gb.size_in_bits ){ 7485 if(get_bits_count(&s->gb) == s->gb.size_in_bits ){
7486 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); 7486 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
7487 7487
7488 return 0; 7488 return 0;
7489 }else{ 7489 }else{
8135 if (ptr==NULL || dst_length <= 0){ 8135 if (ptr==NULL || dst_length <= 0){
8136 return -1; 8136 return -1;
8137 } 8137 }
8138 while(ptr[dst_length - 1] == 0 && dst_length > 1) 8138 while(ptr[dst_length - 1] == 0 && dst_length > 1)
8139 dst_length--; 8139 dst_length--;
8140 bit_length= 8*dst_length - decode_rbsp_trailing(ptr + dst_length - 1); 8140 bit_length= 8*dst_length - decode_rbsp_trailing(h, ptr + dst_length - 1);
8141 8141
8142 if(s->avctx->debug&FF_DEBUG_STARTCODE){ 8142 if(s->avctx->debug&FF_DEBUG_STARTCODE){
8143 av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", h->nal_unit_type, buf_index, buf_size, dst_length); 8143 av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", h->nal_unit_type, buf_index, buf_size, dst_length);
8144 } 8144 }
8145 8145