FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h263.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 113 123 91.9%
Functions: 5 5 100.0%
Branches: 61 64 95.3%

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 "libavutil/thread.h"
31 #include "mpegvideo.h"
32 #include "h263.h"
33 #include "h263data.h"
34 #include "h263dsp.h"
35 #include "idctdsp.h"
36 #include "mathops.h"
37 #include "mpegpicture.h"
38 #include "mpegutils.h"
39 #include "rl.h"
40
41 283 static av_cold void h263_init_rl_inter(void)
42 {
43 static uint8_t h263_rl_inter_table[2][2 * MAX_RUN + MAX_LEVEL + 3];
44 283 ff_rl_init(&ff_h263_rl_inter, h263_rl_inter_table);
45 283 }
46
47 283 av_cold void ff_h263_init_rl_inter(void)
48 {
49 static AVOnce init_static_once = AV_ONCE_INIT;
50 283 ff_thread_once(&init_static_once, h263_init_rl_inter);
51 283 }
52
53 3463687 void ff_h263_update_motion_val(MpegEncContext * s){
54 3463687 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
55 //FIXME a lot of that is only needed for !low_delay
56 3463687 const int wrap = s->b8_stride;
57 3463687 const int xy = s->block_index[0];
58
59
2/2
✓ Branch 0 taken 3258589 times.
✓ Branch 1 taken 205098 times.
3463687 if(s->mv_type != MV_TYPE_8X8){
60 int motion_x, motion_y;
61
2/2
✓ Branch 0 taken 514381 times.
✓ Branch 1 taken 2744208 times.
3258589 if (s->mb_intra) {
62 514381 motion_x = 0;
63 514381 motion_y = 0;
64
1/2
✓ Branch 0 taken 2744208 times.
✗ Branch 1 not taken.
2744208 } else if (s->mv_type == MV_TYPE_16X16) {
65 2744208 motion_x = s->mv[0][0][0];
66 2744208 motion_y = s->mv[0][0][1];
67 } else /*if (s->mv_type == MV_TYPE_FIELD)*/ {
68 int i;
69 motion_x = s->mv[0][0][0] + s->mv[0][1][0];
70 motion_y = s->mv[0][0][1] + s->mv[0][1][1];
71 motion_x = (motion_x>>1) | (motion_x&1);
72 for(i=0; i<2; i++){
73 s->p_field_mv_table[i][0][mb_xy][0]= s->mv[0][i][0];
74 s->p_field_mv_table[i][0][mb_xy][1]= s->mv[0][i][1];
75 }
76 s->cur_pic.ref_index[0][4*mb_xy ] =
77 s->cur_pic.ref_index[0][4*mb_xy + 1] = s->field_select[0][0];
78 s->cur_pic.ref_index[0][4*mb_xy + 2] =
79 s->cur_pic.ref_index[0][4*mb_xy + 3] = s->field_select[0][1];
80 }
81
82 /* no update if 8X8 because it has been done during parsing */
83 3258589 s->cur_pic.motion_val[0][xy][0] = motion_x;
84 3258589 s->cur_pic.motion_val[0][xy][1] = motion_y;
85 3258589 s->cur_pic.motion_val[0][xy + 1][0] = motion_x;
86 3258589 s->cur_pic.motion_val[0][xy + 1][1] = motion_y;
87 3258589 s->cur_pic.motion_val[0][xy + wrap][0] = motion_x;
88 3258589 s->cur_pic.motion_val[0][xy + wrap][1] = motion_y;
89 3258589 s->cur_pic.motion_val[0][xy + 1 + wrap][0] = motion_x;
90 3258589 s->cur_pic.motion_val[0][xy + 1 + wrap][1] = motion_y;
91 }
92 3463687 }
93
94 260100 void ff_h263_loop_filter(MpegEncContext * s){
95 int qp_c;
96 260100 const int linesize = s->linesize;
97 260100 const int uvlinesize= s->uvlinesize;
98 260100 const int xy = s->mb_y * s->mb_stride + s->mb_x;
99 260100 uint8_t *dest_y = s->dest[0];
100 260100 uint8_t *dest_cb= s->dest[1];
101 260100 uint8_t *dest_cr= s->dest[2];
102
103 /*
104 Diag Top
105 Left Center
106 */
107
2/2
✓ Branch 0 taken 187629 times.
✓ Branch 1 taken 72471 times.
260100 if (!IS_SKIP(s->cur_pic.mb_type[xy])) {
108 187629 qp_c= s->qscale;
109 187629 s->h263dsp.h263_v_loop_filter(dest_y + 8 * linesize, linesize, qp_c);
110 187629 s->h263dsp.h263_v_loop_filter(dest_y + 8 * linesize + 8, linesize, qp_c);
111 }else
112 72471 qp_c= 0;
113
114
2/2
✓ Branch 0 taken 244080 times.
✓ Branch 1 taken 16020 times.
260100 if(s->mb_y){
115 int qp_dt, qp_tt, qp_tc;
116
117
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]))
118 64470 qp_tt=0;
119 else
120 179610 qp_tt = s->cur_pic.qscale_table[xy - s->mb_stride];
121
122
2/2
✓ Branch 0 taken 179730 times.
✓ Branch 1 taken 64350 times.
244080 if(qp_c)
123 179730 qp_tc= qp_c;
124 else
125 64350 qp_tc= qp_tt;
126
127
2/2
✓ Branch 0 taken 197619 times.
✓ Branch 1 taken 46461 times.
244080 if(qp_tc){
128 197619 const int chroma_qp= s->chroma_qscale_table[qp_tc];
129 197619 s->h263dsp.h263_v_loop_filter(dest_y, linesize, qp_tc);
130 197619 s->h263dsp.h263_v_loop_filter(dest_y + 8, linesize, qp_tc);
131
132 197619 s->h263dsp.h263_v_loop_filter(dest_cb, uvlinesize, chroma_qp);
133 197619 s->h263dsp.h263_v_loop_filter(dest_cr, uvlinesize, chroma_qp);
134 }
135
136
2/2
✓ Branch 0 taken 179610 times.
✓ Branch 1 taken 64470 times.
244080 if(qp_tt)
137 179610 s->h263dsp.h263_h_loop_filter(dest_y - 8 * linesize + 8, linesize, qp_tt);
138
139
2/2
✓ Branch 0 taken 232386 times.
✓ Branch 1 taken 11694 times.
244080 if(s->mb_x){
140
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]))
141 217543 qp_dt= qp_tt;
142 else
143 14843 qp_dt = s->cur_pic.qscale_table[xy - 1 - s->mb_stride];
144
145
2/2
✓ Branch 0 taken 186699 times.
✓ Branch 1 taken 45687 times.
232386 if(qp_dt){
146 186699 const int chroma_qp= s->chroma_qscale_table[qp_dt];
147 186699 s->h263dsp.h263_h_loop_filter(dest_y - 8 * linesize, linesize, qp_dt);
148 186699 s->h263dsp.h263_h_loop_filter(dest_cb - 8 * uvlinesize, uvlinesize, chroma_qp);
149 186699 s->h263dsp.h263_h_loop_filter(dest_cr - 8 * uvlinesize, uvlinesize, chroma_qp);
150 }
151 }
152 }
153
154
2/2
✓ Branch 0 taken 187629 times.
✓ Branch 1 taken 72471 times.
260100 if(qp_c){
155 187629 s->h263dsp.h263_h_loop_filter(dest_y + 8, linesize, qp_c);
156
2/2
✓ Branch 0 taken 8019 times.
✓ Branch 1 taken 179610 times.
187629 if(s->mb_y + 1 == s->mb_height)
157 8019 s->h263dsp.h263_h_loop_filter(dest_y + 8 * linesize + 8, linesize, qp_c);
158 }
159
160
2/2
✓ Branch 0 taken 247635 times.
✓ Branch 1 taken 12465 times.
260100 if(s->mb_x){
161 int qp_lc;
162
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]))
163 232550 qp_lc= qp_c;
164 else
165 15085 qp_lc = s->cur_pic.qscale_table[xy - 1];
166
167
2/2
✓ Branch 0 taken 194594 times.
✓ Branch 1 taken 53041 times.
247635 if(qp_lc){
168 194594 s->h263dsp.h263_h_loop_filter(dest_y, linesize, qp_lc);
169
2/2
✓ Branch 0 taken 7895 times.
✓ Branch 1 taken 186699 times.
194594 if(s->mb_y + 1 == s->mb_height){
170 7895 const int chroma_qp= s->chroma_qscale_table[qp_lc];
171 7895 s->h263dsp.h263_h_loop_filter(dest_y + 8 * linesize, linesize, qp_lc);
172 7895 s->h263dsp.h263_h_loop_filter(dest_cb, uvlinesize, chroma_qp);
173 7895 s->h263dsp.h263_h_loop_filter(dest_cr, uvlinesize, chroma_qp);
174 }
175 }
176 }
177 260100 }
178
179 3950325 int16_t *ff_h263_pred_motion(MpegEncContext * s, int block, int dir,
180 int *px, int *py)
181 {
182 int wrap;
183 int16_t *A, *B, *C, (*mot_val)[2];
184 static const int off[4]= {2, 1, 1, -1};
185
186 3950325 wrap = s->b8_stride;
187 3950325 mot_val = s->cur_pic.motion_val[dir] + s->block_index[block];
188
189 3950325 A = mot_val[ - 1];
190 /* special case for first (slice) line */
191
4/4
✓ Branch 0 taken 429469 times.
✓ Branch 1 taken 3520856 times.
✓ Branch 2 taken 391547 times.
✓ Branch 3 taken 37922 times.
3950325 if (s->first_slice_line && block<3) {
192 // we can't just change some MVs to simulate that as we need them for the B-frames (and ME)
193 // and if we ever support non rectangular objects than we need to do a few ifs here anyway :(
194
2/2
✓ Branch 0 taken 315703 times.
✓ Branch 1 taken 75844 times.
391547 if(block==0){ //most common case
195
2/2
✓ Branch 0 taken 15269 times.
✓ Branch 1 taken 300434 times.
315703 if(s->mb_x == s->resync_mb_x){ //rare
196 15269 *px= *py = 0;
197
4/4
✓ Branch 0 taken 2120 times.
✓ Branch 1 taken 298314 times.
✓ Branch 2 taken 1859 times.
✓ Branch 3 taken 261 times.
300434 }else if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare
198 1859 C = mot_val[off[block] - wrap];
199
2/2
✓ Branch 0 taken 118 times.
✓ Branch 1 taken 1741 times.
1859 if(s->mb_x==0){
200 118 *px = C[0];
201 118 *py = C[1];
202 }else{
203 1741 *px = mid_pred(A[0], 0, C[0]);
204 1741 *py = mid_pred(A[1], 0, C[1]);
205 }
206 }else{
207 298575 *px = A[0];
208 298575 *py = A[1];
209 }
210
2/2
✓ Branch 0 taken 37922 times.
✓ Branch 1 taken 37922 times.
75844 }else if(block==1){
211
4/4
✓ Branch 0 taken 751 times.
✓ Branch 1 taken 37171 times.
✓ Branch 2 taken 730 times.
✓ Branch 3 taken 21 times.
37922 if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare
212 730 C = mot_val[off[block] - wrap];
213 730 *px = mid_pred(A[0], 0, C[0]);
214 730 *py = mid_pred(A[1], 0, C[1]);
215 }else{
216 37192 *px = A[0];
217 37192 *py = A[1];
218 }
219 }else{ /* block==2*/
220 37922 B = mot_val[ - wrap];
221 37922 C = mot_val[off[block] - wrap];
222
2/2
✓ Branch 0 taken 2171 times.
✓ Branch 1 taken 35751 times.
37922 if(s->mb_x == s->resync_mb_x) //rare
223 2171 A[0]=A[1]=0;
224
225 37922 *px = mid_pred(A[0], B[0], C[0]);
226 37922 *py = mid_pred(A[1], B[1], C[1]);
227 }
228 } else {
229 3558778 B = mot_val[ - wrap];
230 3558778 C = mot_val[off[block] - wrap];
231 3558778 *px = mid_pred(A[0], B[0], C[0]);
232 3558778 *py = mid_pred(A[1], B[1], C[1]);
233 }
234 3950325 return *mot_val;
235 }
236