FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mpeg4video.h
Date: 2024-07-26 21:54:09
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 2389626 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 1593084 times.
✓ Branch 1 taken 796542 times.
2389626 if (n < 4)
60 1593084 scale = s->y_dc_scale;
61 else
62 796542 scale = s->c_dc_scale;
63 if (IS_3IV1)
64 scale = 8;
65
66 2389626 wrap = s->block_wrap[n];
67 2389626 dc_val = s->dc_val[0] + s->block_index[n];
68
69 /* B C
70 * A X
71 */
72 2389626 a = dc_val[-1];
73 2389626 b = dc_val[-1 - wrap];
74 2389626 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 282738 times.
✓ Branch 1 taken 2106888 times.
✓ Branch 2 taken 235615 times.
✓ Branch 3 taken 47123 times.
2389626 if (s->first_slice_line && n != 3) {
79
2/2
✓ Branch 0 taken 188492 times.
✓ Branch 1 taken 47123 times.
235615 if (n != 2)
80 188492 b = c = 1024;
81
4/4
✓ Branch 0 taken 188492 times.
✓ Branch 1 taken 47123 times.
✓ Branch 2 taken 9960 times.
✓ Branch 3 taken 178532 times.
235615 if (n != 1 && s->mb_x == s->resync_mb_x)
82 9960 b = a = 1024;
83 }
84
4/4
✓ Branch 0 taken 105324 times.
✓ Branch 1 taken 2284302 times.
✓ Branch 2 taken 15030 times.
✓ Branch 3 taken 90294 times.
2389626 if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) {
85
6/6
✓ Branch 0 taken 12525 times.
✓ Branch 1 taken 2505 times.
✓ Branch 2 taken 10020 times.
✓ Branch 3 taken 2505 times.
✓ Branch 4 taken 2505 times.
✓ Branch 5 taken 7515 times.
15030 if (n == 0 || n == 4 || n == 5)
86 7515 b = 1024;
87 }
88
89
2/2
✓ Branch 0 taken 875773 times.
✓ Branch 1 taken 1513853 times.
2389626 if (abs(a - b) < abs(b - c)) {
90 875773 pred = c;
91 875773 *dir_ptr = 1; /* top */
92 } else {
93 1513853 pred = a;
94 1513853 *dir_ptr = 0; /* left */
95 }
96 /* we assume pred is positive */
97 2389626 pred = FASTDIV((pred + (scale >> 1)), scale);
98
99
2/2
✓ Branch 0 taken 1256166 times.
✓ Branch 1 taken 1133460 times.
2389626 if (encoding) {
100 1256166 ret = level - pred;
101 } else {
102 1133460 level += pred;
103 1133460 ret = level;
104 }
105 2389626 level *= scale;
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2389626 times.
2389626 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 2389626 dc_val[0] = level;
125
126 2389626 return ret;
127 }
128
129 #endif /* AVCODEC_MPEG4VIDEO_H */
130