FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mpeg4video.h
Date: 2022-11-26 13:19:19
Exec Total Coverage
Lines: 31 42 73.8%
Branches: 27 40 67.5%

Line Branch Exec Source
1 /*
2 * MPEG-4 encoder/decoder internal header.
3 * Copyright (c) 2000,2001 Fabrice Bellard
4 * Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #ifndef AVCODEC_MPEG4VIDEO_H
24 #define AVCODEC_MPEG4VIDEO_H
25
26 #include <stdint.h>
27
28 #include "mpegvideo.h"
29
30 void ff_mpeg4_clean_buffers(MpegEncContext *s);
31 int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s);
32 void ff_mpeg4_init_direct_mv(MpegEncContext *s);
33
34 /**
35 * @return the mb_type
36 */
37 int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my);
38
39 #if 0 //3IV1 is quite rare and it slows things down a tiny bit
40 #define IS_3IV1 s->codec_tag == AV_RL32("3IV1")
41 #else
42 #define IS_3IV1 0
43 #endif
44
45 /**
46 * Predict the dc.
47 * encoding quantized level -> quantized diff
48 * decoding quantized diff -> quantized level
49 * @param n block index (0-3 are luma, 4-5 are chroma)
50 * @param dir_ptr pointer to an integer where the prediction direction will be stored
51 */
52 2340354 static inline int ff_mpeg4_pred_dc(MpegEncContext *s, int n, int level,
53 int *dir_ptr, int encoding)
54 {
55 int a, b, c, wrap, pred, scale, ret;
56 int16_t *dc_val;
57
58 /* find prediction */
59
2/2
✓ Branch 0 taken 1560236 times.
✓ Branch 1 taken 780118 times.
2340354 if (n < 4)
60 1560236 scale = s->y_dc_scale;
61 else
62 780118 scale = s->c_dc_scale;
63 if (IS_3IV1)
64 scale = 8;
65
66 2340354 wrap = s->block_wrap[n];
67 2340354 dc_val = s->dc_val[0] + s->block_index[n];
68
69 /* B C
70 * A X
71 */
72 2340354 a = dc_val[-1];
73 2340354 b = dc_val[-1 - wrap];
74 2340354 c = dc_val[-wrap];
75
76 /* outside slice handling (we can't do that by memset as we need the
77 * dc for error resilience) */
78
4/4
✓ Branch 0 taken 281412 times.
✓ Branch 1 taken 2058942 times.
✓ Branch 2 taken 234510 times.
✓ Branch 3 taken 46902 times.
2340354 if (s->first_slice_line && n != 3) {
79
2/2
✓ Branch 0 taken 187608 times.
✓ Branch 1 taken 46902 times.
234510 if (n != 2)
80 187608 b = c = 1024;
81
4/4
✓ Branch 0 taken 187608 times.
✓ Branch 1 taken 46902 times.
✓ Branch 2 taken 9928 times.
✓ Branch 3 taken 177680 times.
234510 if (n != 1 && s->mb_x == s->resync_mb_x)
82 9928 b = a = 1024;
83 }
84
4/4
✓ Branch 0 taken 104214 times.
✓ Branch 1 taken 2236140 times.
✓ Branch 2 taken 14964 times.
✓ Branch 3 taken 89250 times.
2340354 if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) {
85
6/6
✓ Branch 0 taken 12470 times.
✓ Branch 1 taken 2494 times.
✓ Branch 2 taken 9976 times.
✓ Branch 3 taken 2494 times.
✓ Branch 4 taken 2494 times.
✓ Branch 5 taken 7482 times.
14964 if (n == 0 || n == 4 || n == 5)
86 7482 b = 1024;
87 }
88
89
2/2
✓ Branch 0 taken 860878 times.
✓ Branch 1 taken 1479476 times.
2340354 if (abs(a - b) < abs(b - c)) {
90 860878 pred = c;
91 860878 *dir_ptr = 1; /* top */
92 } else {
93 1479476 pred = a;
94 1479476 *dir_ptr = 0; /* left */
95 }
96 /* we assume pred is positive */
97 2340354 pred = FASTDIV((pred + (scale >> 1)), scale);
98
99
2/2
✓ Branch 0 taken 1228836 times.
✓ Branch 1 taken 1111518 times.
2340354 if (encoding) {
100 1228836 ret = level - pred;
101 } else {
102 1111518 level += pred;
103 1111518 ret = level;
104 }
105 2340354 level *= scale;
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2340354 times.
2340354 if (level & (~2047)) {
107 if (!s->encoding && (s->avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_AGGRESSIVE))) {
108 if (level < 0) {
109 av_log(s->avctx, AV_LOG_ERROR,
110 "dc<0 at %dx%d\n", s->mb_x, s->mb_y);
111 return AVERROR_INVALIDDATA;
112 }
113 if (level > 2048 + scale) {
114 av_log(s->avctx, AV_LOG_ERROR,
115 "dc overflow at %dx%d\n", s->mb_x, s->mb_y);
116 return AVERROR_INVALIDDATA;
117 }
118 }
119 if (level < 0)
120 level = 0;
121 else if (!(s->workaround_bugs & FF_BUG_DC_CLIP))
122 level = 2047;
123 }
124 2340354 dc_val[0] = level;
125
126 2340354 return ret;
127 }
128
129 #endif /* AVCODEC_MPEG4VIDEO_H */
130