FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mpeg4video.h
Date: 2024-03-28 04:31:58
Exec Total Coverage
Lines: 31 42 73.8%
Functions: 1 1 100.0%
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 2349804 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 1566536 times.
✓ Branch 1 taken 783268 times.
2349804 if (n < 4)
60 1566536 scale = s->y_dc_scale;
61 else
62 783268 scale = s->c_dc_scale;
63 if (IS_3IV1)
64 scale = 8;
65
66 2349804 wrap = s->block_wrap[n];
67 2349804 dc_val = s->dc_val[0] + s->block_index[n];
68
69 /* B C
70 * A X
71 */
72 2349804 a = dc_val[-1];
73 2349804 b = dc_val[-1 - wrap];
74 2349804 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 281934 times.
✓ Branch 1 taken 2067870 times.
✓ Branch 2 taken 234945 times.
✓ Branch 3 taken 46989 times.
2349804 if (s->first_slice_line && n != 3) {
79
2/2
✓ Branch 0 taken 187956 times.
✓ Branch 1 taken 46989 times.
234945 if (n != 2)
80 187956 b = c = 1024;
81
4/4
✓ Branch 0 taken 187956 times.
✓ Branch 1 taken 46989 times.
✓ Branch 2 taken 9940 times.
✓ Branch 3 taken 178016 times.
234945 if (n != 1 && s->mb_x == s->resync_mb_x)
82 9940 b = a = 1024;
83 }
84
4/4
✓ Branch 0 taken 104682 times.
✓ Branch 1 taken 2245122 times.
✓ Branch 2 taken 14994 times.
✓ Branch 3 taken 89688 times.
2349804 if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) {
85
6/6
✓ Branch 0 taken 12495 times.
✓ Branch 1 taken 2499 times.
✓ Branch 2 taken 9996 times.
✓ Branch 3 taken 2499 times.
✓ Branch 4 taken 2499 times.
✓ Branch 5 taken 7497 times.
14994 if (n == 0 || n == 4 || n == 5)
86 7497 b = 1024;
87 }
88
89
2/2
✓ Branch 0 taken 864849 times.
✓ Branch 1 taken 1484955 times.
2349804 if (abs(a - b) < abs(b - c)) {
90 864849 pred = c;
91 864849 *dir_ptr = 1; /* top */
92 } else {
93 1484955 pred = a;
94 1484955 *dir_ptr = 0; /* left */
95 }
96 /* we assume pred is positive */
97 2349804 pred = FASTDIV((pred + (scale >> 1)), scale);
98
99
2/2
✓ Branch 0 taken 1228296 times.
✓ Branch 1 taken 1121508 times.
2349804 if (encoding) {
100 1228296 ret = level - pred;
101 } else {
102 1121508 level += pred;
103 1121508 ret = level;
104 }
105 2349804 level *= scale;
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2349804 times.
2349804 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 2349804 dc_val[0] = level;
125
126 2349804 return ret;
127 }
128
129 #endif /* AVCODEC_MPEG4VIDEO_H */
130