History

Fix implicit weight for b frames in mbaff.

Originally committed as revision 22733 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Niedermayer committed 16 years ago

Commit 1052b761 parent c28112f3 files · +40 −19Browse files

Unified · Split

3 files
  1. libavcodec/h264.c +39 −12
  2. libavcodec/h264.h +1 −1
  3. libavcodec/h264_refs.c +0 −6
libavcodec/h264.c+39−12
@@ -488,7 +488,7 @@ static inline void mc_part_weighted(H264Context *h, int n, int square, int chrom · 487 unmodified lines
488488 x_offset, y_offset, qpix_put, chroma_put);
489489
490490 if(h->use_weight == 2){
491− int weight0 = h->implicit_weight[refn0][refn1];
491+ int weight0 = h->implicit_weight[refn0][refn1][s->mb_y&1];
492492 int weight1 = 64 - weight0;
493493 luma_weight_avg( dest_y, tmp_y, h-> mb_linesize, 5, weight0, weight1, 0);
494494 chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, 5, weight0, weight1, 0);
@@ -531,7 +531,7 @@ static inline void mc_part(H264Context *h, int n, int square, int chroma_height, · 36 unmodified lines
531531 h264_weight_func *weight_op, h264_biweight_func *weight_avg,
532532 int list0, int list1){
533533 if((h->use_weight==2 && list0 && list1
534− && (h->implicit_weight[ h->ref_cache[0][scan8[n]] ][ h->ref_cache[1][scan8[n]] ] != 32))
534+ && (h->implicit_weight[ h->ref_cache[0][scan8[n]] ][ h->ref_cache[1][scan8[n]] ][h->s.mb_y&1] != 32))
535535 || h->use_weight==1)
536536 mc_part_weighted(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr,
537537 x_offset, y_offset, qpix_put, chroma_put,
@@ -1408,40 +1408,61 @@ static int pred_weight_table(H264Context *h){ · 870 unmodified lines
14081408 return 0;
14091409 }
14101410
1411−static void implicit_weight_table(H264Context *h){
1411+/**
1412+ * Initialize implicit_weight table.
1413+ * @param field, 0/1 initialize the weight for interlaced MBAFF
1414+ * -1 initializes the rest
1415+ */
1416+static void implicit_weight_table(H264Context *h, int field){
14121417 MpegEncContext * const s = &h->s;
1413− int ref0, ref1, i;
1414− int cur_poc = s->current_picture_ptr->poc;
1418+ int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
14151419
14161420 for (i = 0; i < 2; i++) {
14171421 h->luma_weight_flag[i] = 0;
14181422 h->chroma_weight_flag[i] = 0;
14191423 }
14201424
1421− if( h->ref_count[0] == 1 && h->ref_count[1] == 1
1425+ if(field < 0){
1426+ cur_poc = s->current_picture_ptr->poc;
1427+ if( h->ref_count[0] == 1 && h->ref_count[1] == 1 && !FRAME_MBAFF
14221428 && h->ref_list[0][0].poc + h->ref_list[1][0].poc == 2*cur_poc){
14231429 h->use_weight= 0;
14241430 h->use_weight_chroma= 0;
14251431 return;
14261432 }
1433+ ref_start= 0;
1434+ ref_count0= h->ref_count[0];
1435+ ref_count1= h->ref_count[1];
1436+ }else{
1437+ cur_poc = s->current_picture_ptr->field_poc[field];
1438+ ref_start= 16;
1439+ ref_count0= 16+2*h->ref_count[0];
1440+ ref_count1= 16+2*h->ref_count[1];
1441+ }
14271442
14281443 h->use_weight= 2;
14291444 h->use_weight_chroma= 2;
14301445 h->luma_log2_weight_denom= 5;
14311446 h->chroma_log2_weight_denom= 5;
14321447
1433− for(ref0=0; ref0 < h->ref_count[0]; ref0++){
1448+ for(ref0=ref_start; ref0 < ref_count0; ref0++){
14341449 int poc0 = h->ref_list[0][ref0].poc;
1435− for(ref1=0; ref1 < h->ref_count[1]; ref1++){
1450+ for(ref1=ref_start; ref1 < ref_count1; ref1++){
14361451 int poc1 = h->ref_list[1][ref1].poc;
14371452 int td = av_clip(poc1 - poc0, -128, 127);
1438− h->implicit_weight[ref0][ref1] = 32;
1453+ int w= 32;
14391454 if(td){
14401455 int tb = av_clip(cur_poc - poc0, -128, 127);
14411456 int tx = (16384 + (FFABS(td) >> 1)) / td;
14421457 int dist_scale_factor = (tb*tx + 32) >> 8;
14431458 if(dist_scale_factor >= -64 && dist_scale_factor <= 128)
1444− h->implicit_weight[ref0][ref1] = 64 - dist_scale_factor;
1459+ w = 64 - dist_scale_factor;
1460+ }
1461+ if(field<0){
1462+ h->implicit_weight[ref0][ref1][0]=
1463+ h->implicit_weight[ref0][ref1][1]= w;
1464+ }else{
1465+ h->implicit_weight[ref0][ref1][field]=w;
14451466 }
14461467 }
14471468 }
@@ -2005,7 +2026,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ · 557 unmodified lines
20052026 || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== FF_B_TYPE ) )
20062027 pred_weight_table(h);
20072028 else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE){
2008− implicit_weight_table(h);
2029+ implicit_weight_table(h, -1);
20092030 }else {
20102031 h->use_weight = 0;
20112032 for (i = 0; i < 2; i++) {
@@ -2017,9 +2038,15 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ · 5 unmodified lines
20172038 if(h->nal_ref_idc)
20182039 ff_h264_decode_ref_pic_marking(h0, &s->gb);
20192040
2020− if(FRAME_MBAFF)
2041+ if(FRAME_MBAFF){
20212042 ff_h264_fill_mbaff_ref_list(h);
20222043
2044+ if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE){
2045+ implicit_weight_table(h, 0);
2046+ implicit_weight_table(h, 1);
2047+ }
2048+ }
2049+
20232050 if(h->slice_type_nos==FF_B_TYPE && !h->direct_spatial_mv_pred)
20242051 ff_h264_direct_dist_scale_factor(h);
20252052 ff_h264_direct_ref_list_init(h);
libavcodec/h264.h+1−1
@@ -378,7 +378,7 @@ typedef struct H264Context{ · 377 unmodified lines
378378 //The following 2 can be changed to int8_t but that causes 10cpu cycles speedloss
379379 int luma_weight[48][2][2];
380380 int chroma_weight[48][2][2][2];
381− int implicit_weight[48][48];
381+ int implicit_weight[48][48][2];
382382
383383 int direct_spatial_mv_pred;
384384 int col_parity;
libavcodec/h264_refs.c+0−6
@@ -323,12 +323,6 @@ void ff_h264_fill_mbaff_ref_list(H264Context *h){ · 322 unmodified lines
323323 }
324324 }
325325 }
326− for(j=0; j<h->ref_count[1]; j++){
327− for(i=0; i<h->ref_count[0]; i++)
328− h->implicit_weight[j][16+2*i] = h->implicit_weight[j][16+2*i+1] = h->implicit_weight[j][i];
329− memcpy(h->implicit_weight[16+2*j], h->implicit_weight[j], sizeof(*h->implicit_weight));
330− memcpy(h->implicit_weight[16+2*j+1], h->implicit_weight[j], sizeof(*h->implicit_weight));
331− }
332326 }
333327
334328 /**

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t