| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * H.263/MPEG-4 backend for encoder and decoder | ||
| 3 | * Copyright (c) 2000,2001 Fabrice Bellard | ||
| 4 | * H.263+ support. | ||
| 5 | * Copyright (c) 2001 Juan J. Sierralta P | ||
| 6 | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | ||
| 7 | * | ||
| 8 | * This file is part of FFmpeg. | ||
| 9 | * | ||
| 10 | * FFmpeg is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU Lesser General Public | ||
| 12 | * License as published by the Free Software Foundation; either | ||
| 13 | * version 2.1 of the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * Lesser General Public License for more details. | ||
| 19 | * | ||
| 20 | * You should have received a copy of the GNU Lesser General Public | ||
| 21 | * License along with FFmpeg; if not, write to the Free Software | ||
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 23 | */ | ||
| 24 | |||
| 25 | /** | ||
| 26 | * @file | ||
| 27 | * H.263/MPEG-4 codec. | ||
| 28 | */ | ||
| 29 | |||
| 30 | #include "config.h" | ||
| 31 | |||
| 32 | #include "libavutil/thread.h" | ||
| 33 | #include "mpegvideo.h" | ||
| 34 | #include "h263.h" | ||
| 35 | #include "h263data.h" | ||
| 36 | #include "h263dsp.h" | ||
| 37 | #include "mathops.h" | ||
| 38 | #include "mpegpicture.h" | ||
| 39 | #include "mpegutils.h" | ||
| 40 | #include "rl.h" | ||
| 41 | |||
| 42 | #if CONFIG_MPEGVIDEO | ||
| 43 | 220 | static av_cold void h263_init_rl_inter(void) | |
| 44 | { | ||
| 45 | static uint8_t h263_rl_inter_table[2][2 * MAX_RUN + MAX_LEVEL + 3]; | ||
| 46 | 220 | ff_rl_init(&ff_h263_rl_inter, h263_rl_inter_table); | |
| 47 | 220 | } | |
| 48 | |||
| 49 | 220 | av_cold void ff_h263_init_rl_inter(void) | |
| 50 | { | ||
| 51 | static AVOnce init_static_once = AV_ONCE_INIT; | ||
| 52 | 220 | ff_thread_once(&init_static_once, h263_init_rl_inter); | |
| 53 | 220 | } | |
| 54 | #endif | ||
| 55 | |||
| 56 | 3483541 | void ff_h263_update_motion_val(MpegEncContext * s){ | |
| 57 | 3483541 | const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; | |
| 58 | //FIXME a lot of that is only needed for !low_delay | ||
| 59 | 3483541 | const int wrap = s->b8_stride; | |
| 60 | 3483541 | const int xy = s->block_index[0]; | |
| 61 | |||
| 62 |
2/2✓ Branch 0 taken 3273820 times.
✓ Branch 1 taken 209721 times.
|
3483541 | if(s->mv_type != MV_TYPE_8X8){ |
| 63 | int motion_x, motion_y; | ||
| 64 |
2/2✓ Branch 0 taken 513604 times.
✓ Branch 1 taken 2760216 times.
|
3273820 | if (s->mb_intra) { |
| 65 | 513604 | motion_x = 0; | |
| 66 | 513604 | motion_y = 0; | |
| 67 |
1/2✓ Branch 0 taken 2760216 times.
✗ Branch 1 not taken.
|
2760216 | } else if (s->mv_type == MV_TYPE_16X16) { |
| 68 | 2760216 | motion_x = s->mv[0][0][0]; | |
| 69 | 2760216 | motion_y = s->mv[0][0][1]; | |
| 70 | } else /*if (s->mv_type == MV_TYPE_FIELD)*/ { | ||
| 71 | int i; | ||
| 72 | ✗ | motion_x = s->mv[0][0][0] + s->mv[0][1][0]; | |
| 73 | ✗ | motion_y = s->mv[0][0][1] + s->mv[0][1][1]; | |
| 74 | ✗ | motion_x = (motion_x>>1) | (motion_x&1); | |
| 75 | ✗ | for(i=0; i<2; i++){ | |
| 76 | ✗ | s->p_field_mv_table[i][0][mb_xy][0]= s->mv[0][i][0]; | |
| 77 | ✗ | s->p_field_mv_table[i][0][mb_xy][1]= s->mv[0][i][1]; | |
| 78 | } | ||
| 79 | ✗ | s->cur_pic.ref_index[0][4*mb_xy ] = | |
| 80 | ✗ | s->cur_pic.ref_index[0][4*mb_xy + 1] = s->field_select[0][0]; | |
| 81 | ✗ | s->cur_pic.ref_index[0][4*mb_xy + 2] = | |
| 82 | ✗ | s->cur_pic.ref_index[0][4*mb_xy + 3] = s->field_select[0][1]; | |
| 83 | } | ||
| 84 | |||
| 85 | /* no update if 8X8 because it has been done during parsing */ | ||
| 86 | 3273820 | s->cur_pic.motion_val[0][xy][0] = motion_x; | |
| 87 | 3273820 | s->cur_pic.motion_val[0][xy][1] = motion_y; | |
| 88 | 3273820 | s->cur_pic.motion_val[0][xy + 1][0] = motion_x; | |
| 89 | 3273820 | s->cur_pic.motion_val[0][xy + 1][1] = motion_y; | |
| 90 | 3273820 | s->cur_pic.motion_val[0][xy + wrap][0] = motion_x; | |
| 91 | 3273820 | s->cur_pic.motion_val[0][xy + wrap][1] = motion_y; | |
| 92 | 3273820 | s->cur_pic.motion_val[0][xy + 1 + wrap][0] = motion_x; | |
| 93 | 3273820 | s->cur_pic.motion_val[0][xy + 1 + wrap][1] = motion_y; | |
| 94 | } | ||
| 95 | 3483541 | } | |
| 96 | |||
| 97 | 260100 | void ff_h263_loop_filter(MpegEncContext * s){ | |
| 98 | int qp_c; | ||
| 99 | 260100 | const int linesize = s->linesize; | |
| 100 | 260100 | const int uvlinesize= s->uvlinesize; | |
| 101 | 260100 | const int xy = s->mb_y * s->mb_stride + s->mb_x; | |
| 102 | 260100 | uint8_t *dest_y = s->dest[0]; | |
| 103 | 260100 | uint8_t *dest_cb= s->dest[1]; | |
| 104 | 260100 | uint8_t *dest_cr= s->dest[2]; | |
| 105 | |||
| 106 | /* | ||
| 107 | Diag Top | ||
| 108 | Left Center | ||
| 109 | */ | ||
| 110 |
2/2✓ Branch 0 taken 187629 times.
✓ Branch 1 taken 72471 times.
|
260100 | if (!IS_SKIP(s->cur_pic.mb_type[xy])) { |
| 111 | 187629 | qp_c= s->qscale; | |
| 112 | 187629 | s->h263dsp.h263_v_loop_filter(dest_y + 8 * linesize, linesize, qp_c); | |
| 113 | 187629 | s->h263dsp.h263_v_loop_filter(dest_y + 8 * linesize + 8, linesize, qp_c); | |
| 114 | }else | ||
| 115 | 72471 | qp_c= 0; | |
| 116 | |||
| 117 |
2/2✓ Branch 0 taken 244080 times.
✓ Branch 1 taken 16020 times.
|
260100 | if(s->mb_y){ |
| 118 | int qp_dt, qp_tt, qp_tc; | ||
| 119 | |||
| 120 |
2/2✓ Branch 0 taken 64470 times.
✓ Branch 1 taken 179610 times.
|
244080 | if (IS_SKIP(s->cur_pic.mb_type[xy - s->mb_stride])) |
| 121 | 64470 | qp_tt=0; | |
| 122 | else | ||
| 123 | 179610 | qp_tt = s->cur_pic.qscale_table[xy - s->mb_stride]; | |
| 124 | |||
| 125 |
2/2✓ Branch 0 taken 179730 times.
✓ Branch 1 taken 64350 times.
|
244080 | if(qp_c) |
| 126 | 179730 | qp_tc= qp_c; | |
| 127 | else | ||
| 128 | 64350 | qp_tc= qp_tt; | |
| 129 | |||
| 130 |
2/2✓ Branch 0 taken 197619 times.
✓ Branch 1 taken 46461 times.
|
244080 | if(qp_tc){ |
| 131 | 197619 | const int chroma_qp= s->chroma_qscale_table[qp_tc]; | |
| 132 | 197619 | s->h263dsp.h263_v_loop_filter(dest_y, linesize, qp_tc); | |
| 133 | 197619 | s->h263dsp.h263_v_loop_filter(dest_y + 8, linesize, qp_tc); | |
| 134 | |||
| 135 | 197619 | s->h263dsp.h263_v_loop_filter(dest_cb, uvlinesize, chroma_qp); | |
| 136 | 197619 | s->h263dsp.h263_v_loop_filter(dest_cr, uvlinesize, chroma_qp); | |
| 137 | } | ||
| 138 | |||
| 139 |
2/2✓ Branch 0 taken 179610 times.
✓ Branch 1 taken 64470 times.
|
244080 | if(qp_tt) |
| 140 | 179610 | s->h263dsp.h263_h_loop_filter(dest_y - 8 * linesize + 8, linesize, qp_tt); | |
| 141 | |||
| 142 |
2/2✓ Branch 0 taken 232386 times.
✓ Branch 1 taken 11694 times.
|
244080 | if(s->mb_x){ |
| 143 |
4/4✓ Branch 0 taken 60530 times.
✓ Branch 1 taken 171856 times.
✓ Branch 2 taken 45687 times.
✓ Branch 3 taken 14843 times.
|
232386 | if (qp_tt || IS_SKIP(s->cur_pic.mb_type[xy - 1 - s->mb_stride])) |
| 144 | 217543 | qp_dt= qp_tt; | |
| 145 | else | ||
| 146 | 14843 | qp_dt = s->cur_pic.qscale_table[xy - 1 - s->mb_stride]; | |
| 147 | |||
| 148 |
2/2✓ Branch 0 taken 186699 times.
✓ Branch 1 taken 45687 times.
|
232386 | if(qp_dt){ |
| 149 | 186699 | const int chroma_qp= s->chroma_qscale_table[qp_dt]; | |
| 150 | 186699 | s->h263dsp.h263_h_loop_filter(dest_y - 8 * linesize, linesize, qp_dt); | |
| 151 | 186699 | s->h263dsp.h263_h_loop_filter(dest_cb - 8 * uvlinesize, uvlinesize, chroma_qp); | |
| 152 | 186699 | s->h263dsp.h263_h_loop_filter(dest_cr - 8 * uvlinesize, uvlinesize, chroma_qp); | |
| 153 | } | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 |
2/2✓ Branch 0 taken 187629 times.
✓ Branch 1 taken 72471 times.
|
260100 | if(qp_c){ |
| 158 | 187629 | s->h263dsp.h263_h_loop_filter(dest_y + 8, linesize, qp_c); | |
| 159 |
2/2✓ Branch 0 taken 8019 times.
✓ Branch 1 taken 179610 times.
|
187629 | if(s->mb_y + 1 == s->mb_height) |
| 160 | 8019 | s->h263dsp.h263_h_loop_filter(dest_y + 8 * linesize + 8, linesize, qp_c); | |
| 161 | } | ||
| 162 | |||
| 163 |
2/2✓ Branch 0 taken 247635 times.
✓ Branch 1 taken 12465 times.
|
260100 | if(s->mb_x){ |
| 164 | int qp_lc; | ||
| 165 |
4/4✓ Branch 0 taken 68126 times.
✓ Branch 1 taken 179509 times.
✓ Branch 2 taken 53041 times.
✓ Branch 3 taken 15085 times.
|
247635 | if (qp_c || IS_SKIP(s->cur_pic.mb_type[xy - 1])) |
| 166 | 232550 | qp_lc= qp_c; | |
| 167 | else | ||
| 168 | 15085 | qp_lc = s->cur_pic.qscale_table[xy - 1]; | |
| 169 | |||
| 170 |
2/2✓ Branch 0 taken 194594 times.
✓ Branch 1 taken 53041 times.
|
247635 | if(qp_lc){ |
| 171 | 194594 | s->h263dsp.h263_h_loop_filter(dest_y, linesize, qp_lc); | |
| 172 |
2/2✓ Branch 0 taken 7895 times.
✓ Branch 1 taken 186699 times.
|
194594 | if(s->mb_y + 1 == s->mb_height){ |
| 173 | 7895 | const int chroma_qp= s->chroma_qscale_table[qp_lc]; | |
| 174 | 7895 | s->h263dsp.h263_h_loop_filter(dest_y + 8 * linesize, linesize, qp_lc); | |
| 175 | 7895 | s->h263dsp.h263_h_loop_filter(dest_cb, uvlinesize, chroma_qp); | |
| 176 | 7895 | s->h263dsp.h263_h_loop_filter(dest_cr, uvlinesize, chroma_qp); | |
| 177 | } | ||
| 178 | } | ||
| 179 | } | ||
| 180 | 260100 | } | |
| 181 | |||
| 182 | 4032128 | int16_t *ff_h263_pred_motion(MpegEncContext * s, int block, int dir, | |
| 183 | int *px, int *py) | ||
| 184 | { | ||
| 185 | int wrap; | ||
| 186 | int16_t *A, *B, *C, (*mot_val)[2]; | ||
| 187 | static const int off[4]= {2, 1, 1, -1}; | ||
| 188 | |||
| 189 | 4032128 | wrap = s->b8_stride; | |
| 190 | 4032128 | mot_val = s->cur_pic.motion_val[dir] + s->block_index[block]; | |
| 191 | |||
| 192 | 4032128 | A = mot_val[ - 1]; | |
| 193 | /* special case for first (slice) line */ | ||
| 194 |
4/4✓ Branch 0 taken 434678 times.
✓ Branch 1 taken 3597450 times.
✓ Branch 2 taken 395906 times.
✓ Branch 3 taken 38772 times.
|
4032128 | if (s->first_slice_line && block<3) { |
| 195 | // we can't just change some MVs to simulate that as we need them for the B-frames (and ME) | ||
| 196 | // and if we ever support non rectangular objects than we need to do a few ifs here anyway :( | ||
| 197 |
2/2✓ Branch 0 taken 318362 times.
✓ Branch 1 taken 77544 times.
|
395906 | if(block==0){ //most common case |
| 198 |
2/2✓ Branch 0 taken 15466 times.
✓ Branch 1 taken 302896 times.
|
318362 | if(s->mb_x == s->resync_mb_x){ //rare |
| 199 | 15466 | *px= *py = 0; | |
| 200 |
4/4✓ Branch 0 taken 2120 times.
✓ Branch 1 taken 300776 times.
✓ Branch 2 taken 1859 times.
✓ Branch 3 taken 261 times.
|
302896 | }else if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare |
| 201 | 1859 | C = mot_val[off[block] - wrap]; | |
| 202 |
2/2✓ Branch 0 taken 118 times.
✓ Branch 1 taken 1741 times.
|
1859 | if(s->mb_x==0){ |
| 203 | 118 | *px = C[0]; | |
| 204 | 118 | *py = C[1]; | |
| 205 | }else{ | ||
| 206 | 1741 | *px = mid_pred(A[0], 0, C[0]); | |
| 207 | 1741 | *py = mid_pred(A[1], 0, C[1]); | |
| 208 | } | ||
| 209 | }else{ | ||
| 210 | 301037 | *px = A[0]; | |
| 211 | 301037 | *py = A[1]; | |
| 212 | } | ||
| 213 |
2/2✓ Branch 0 taken 38772 times.
✓ Branch 1 taken 38772 times.
|
77544 | }else if(block==1){ |
| 214 |
4/4✓ Branch 0 taken 751 times.
✓ Branch 1 taken 38021 times.
✓ Branch 2 taken 730 times.
✓ Branch 3 taken 21 times.
|
38772 | if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare |
| 215 | 730 | C = mot_val[off[block] - wrap]; | |
| 216 | 730 | *px = mid_pred(A[0], 0, C[0]); | |
| 217 | 730 | *py = mid_pred(A[1], 0, C[1]); | |
| 218 | }else{ | ||
| 219 | 38042 | *px = A[0]; | |
| 220 | 38042 | *py = A[1]; | |
| 221 | } | ||
| 222 | }else{ /* block==2*/ | ||
| 223 | 38772 | B = mot_val[ - wrap]; | |
| 224 | 38772 | C = mot_val[off[block] - wrap]; | |
| 225 |
2/2✓ Branch 0 taken 2243 times.
✓ Branch 1 taken 36529 times.
|
38772 | if(s->mb_x == s->resync_mb_x) //rare |
| 226 | 2243 | A[0]=A[1]=0; | |
| 227 | |||
| 228 | 38772 | *px = mid_pred(A[0], B[0], C[0]); | |
| 229 | 38772 | *py = mid_pred(A[1], B[1], C[1]); | |
| 230 | } | ||
| 231 | } else { | ||
| 232 | 3636222 | B = mot_val[ - wrap]; | |
| 233 | 3636222 | C = mot_val[off[block] - wrap]; | |
| 234 | 3636222 | *px = mid_pred(A[0], B[0], C[0]); | |
| 235 | 3636222 | *py = mid_pred(A[1], B[1], C[1]); | |
| 236 | } | ||
| 237 | 4032128 | return *mot_val; | |
| 238 | } | ||
| 239 |