FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mpeg4video.h
Date: 2022-07-06 18:02:43
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 // shapes
31 #define RECT_SHAPE 0
32 #define BIN_SHAPE 1
33 #define BIN_ONLY_SHAPE 2
34 #define GRAY_SHAPE 3
35
36 #define SIMPLE_VO_TYPE 1
37 #define CORE_VO_TYPE 3
38 #define MAIN_VO_TYPE 4
39 #define NBIT_VO_TYPE 5
40 #define ARTS_VO_TYPE 10
41 #define ACE_VO_TYPE 12
42 #define SIMPLE_STUDIO_VO_TYPE 14
43 #define CORE_STUDIO_VO_TYPE 15
44 #define ADV_SIMPLE_VO_TYPE 17
45
46 #define VOT_VIDEO_ID 1
47 #define VOT_STILL_TEXTURE_ID 2
48
49 // aspect_ratio_info
50 #define EXTENDED_PAR 15
51
52 //vol_sprite_usage / sprite_enable
53 #define STATIC_SPRITE 1
54 #define GMC_SPRITE 2
55
56 #define MOTION_MARKER 0x1F001
57 #define DC_MARKER 0x6B001
58
59 #define VOS_STARTCODE 0x1B0
60 #define USER_DATA_STARTCODE 0x1B2
61 #define GOP_STARTCODE 0x1B3
62 #define VISUAL_OBJ_STARTCODE 0x1B5
63 #define VOP_STARTCODE 0x1B6
64 #define SLICE_STARTCODE 0x1B7
65 #define EXT_STARTCODE 0x1B8
66
67 #define QUANT_MATRIX_EXT_ID 0x3
68
69 /* smaller packets likely don't contain a real frame */
70 #define MAX_NVOP_SIZE 19
71
72 void ff_mpeg4_clean_buffers(MpegEncContext *s);
73 int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s);
74 void ff_mpeg4_init_direct_mv(MpegEncContext *s);
75
76 /**
77 * @return the mb_type
78 */
79 int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my);
80
81 #if 0 //3IV1 is quite rare and it slows things down a tiny bit
82 #define IS_3IV1 s->codec_tag == AV_RL32("3IV1")
83 #else
84 #define IS_3IV1 0
85 #endif
86
87 /**
88 * Predict the dc.
89 * encoding quantized level -> quantized diff
90 * decoding quantized diff -> quantized level
91 * @param n block index (0-3 are luma, 4-5 are chroma)
92 * @param dir_ptr pointer to an integer where the prediction direction will be stored
93 */
94 2297970 static inline int ff_mpeg4_pred_dc(MpegEncContext *s, int n, int level,
95 int *dir_ptr, int encoding)
96 {
97 int a, b, c, wrap, pred, scale, ret;
98 int16_t *dc_val;
99
100 /* find prediction */
101
2/2
✓ Branch 0 taken 1531980 times.
✓ Branch 1 taken 765990 times.
2297970 if (n < 4)
102 1531980 scale = s->y_dc_scale;
103 else
104 765990 scale = s->c_dc_scale;
105 if (IS_3IV1)
106 scale = 8;
107
108 2297970 wrap = s->block_wrap[n];
109 2297970 dc_val = s->dc_val[0] + s->block_index[n];
110
111 /* B C
112 * A X
113 */
114 2297970 a = dc_val[-1];
115 2297970 b = dc_val[-1 - wrap];
116 2297970 c = dc_val[-wrap];
117
118 /* outside slice handling (we can't do that by memset as we need the
119 * dc for error resilience) */
120
4/4
✓ Branch 0 taken 279612 times.
✓ Branch 1 taken 2018358 times.
✓ Branch 2 taken 233010 times.
✓ Branch 3 taken 46602 times.
2297970 if (s->first_slice_line && n != 3) {
121
2/2
✓ Branch 0 taken 186408 times.
✓ Branch 1 taken 46602 times.
233010 if (n != 2)
122 186408 b = c = 1024;
123
4/4
✓ Branch 0 taken 186408 times.
✓ Branch 1 taken 46602 times.
✓ Branch 2 taken 9916 times.
✓ Branch 3 taken 176492 times.
233010 if (n != 1 && s->mb_x == s->resync_mb_x)
124 9916 b = a = 1024;
125 }
126
4/4
✓ Branch 0 taken 103464 times.
✓ Branch 1 taken 2194506 times.
✓ Branch 2 taken 14928 times.
✓ Branch 3 taken 88536 times.
2297970 if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) {
127
6/6
✓ Branch 0 taken 12440 times.
✓ Branch 1 taken 2488 times.
✓ Branch 2 taken 9952 times.
✓ Branch 3 taken 2488 times.
✓ Branch 4 taken 2488 times.
✓ Branch 5 taken 7464 times.
14928 if (n == 0 || n == 4 || n == 5)
128 7464 b = 1024;
129 }
130
131
2/2
✓ Branch 0 taken 852290 times.
✓ Branch 1 taken 1445680 times.
2297970 if (abs(a - b) < abs(b - c)) {
132 852290 pred = c;
133 852290 *dir_ptr = 1; /* top */
134 } else {
135 1445680 pred = a;
136 1445680 *dir_ptr = 0; /* left */
137 }
138 /* we assume pred is positive */
139 2297970 pred = FASTDIV((pred + (scale >> 1)), scale);
140
141
2/2
✓ Branch 0 taken 1229016 times.
✓ Branch 1 taken 1068954 times.
2297970 if (encoding) {
142 1229016 ret = level - pred;
143 } else {
144 1068954 level += pred;
145 1068954 ret = level;
146 }
147 2297970 level *= scale;
148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2297970 times.
2297970 if (level & (~2047)) {
149 if (!s->encoding && (s->avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_AGGRESSIVE))) {
150 if (level < 0) {
151 av_log(s->avctx, AV_LOG_ERROR,
152 "dc<0 at %dx%d\n", s->mb_x, s->mb_y);
153 return AVERROR_INVALIDDATA;
154 }
155 if (level > 2048 + scale) {
156 av_log(s->avctx, AV_LOG_ERROR,
157 "dc overflow at %dx%d\n", s->mb_x, s->mb_y);
158 return AVERROR_INVALIDDATA;
159 }
160 }
161 if (level < 0)
162 level = 0;
163 else if (!(s->workaround_bugs & FF_BUG_DC_CLIP))
164 level = 2047;
165 }
166 2297970 dc_val[0] = level;
167
168 2297970 return ret;
169 }
170
171 #endif /* AVCODEC_MPEG4VIDEO_H */
172