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 | 2407668 | 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 1605112 times.
✓ Branch 1 taken 802556 times.
|
2407668 | if (n < 4) |
60 | 1605112 | scale = s->y_dc_scale; | |
61 | else | ||
62 | 802556 | scale = s->c_dc_scale; | |
63 | if (IS_3IV1) | ||
64 | scale = 8; | ||
65 | |||
66 | 2407668 | wrap = s->block_wrap[n]; | |
67 | 2407668 | dc_val = s->dc_val[0] + s->block_index[n]; | |
68 | |||
69 | /* B C | ||
70 | * A X | ||
71 | */ | ||
72 | 2407668 | a = dc_val[-1]; | |
73 | 2407668 | b = dc_val[-1 - wrap]; | |
74 | 2407668 | 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 283356 times.
✓ Branch 1 taken 2124312 times.
✓ Branch 2 taken 236130 times.
✓ Branch 3 taken 47226 times.
|
2407668 | if (s->first_slice_line && n != 3) { |
79 |
2/2✓ Branch 0 taken 188904 times.
✓ Branch 1 taken 47226 times.
|
236130 | if (n != 2) |
80 | 188904 | b = c = 1024; | |
81 |
4/4✓ Branch 0 taken 188904 times.
✓ Branch 1 taken 47226 times.
✓ Branch 2 taken 9980 times.
✓ Branch 3 taken 178924 times.
|
236130 | if (n != 1 && s->mb_x == s->resync_mb_x) |
82 | 9980 | b = a = 1024; | |
83 | } | ||
84 |
4/4✓ Branch 0 taken 105828 times.
✓ Branch 1 taken 2301840 times.
✓ Branch 2 taken 15060 times.
✓ Branch 3 taken 90768 times.
|
2407668 | if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) { |
85 |
6/6✓ Branch 0 taken 12550 times.
✓ Branch 1 taken 2510 times.
✓ Branch 2 taken 10040 times.
✓ Branch 3 taken 2510 times.
✓ Branch 4 taken 2510 times.
✓ Branch 5 taken 7530 times.
|
15060 | if (n == 0 || n == 4 || n == 5) |
86 | 7530 | b = 1024; | |
87 | } | ||
88 | |||
89 |
2/2✓ Branch 0 taken 882650 times.
✓ Branch 1 taken 1525018 times.
|
2407668 | if (abs(a - b) < abs(b - c)) { |
90 | 882650 | pred = c; | |
91 | 882650 | *dir_ptr = 1; /* top */ | |
92 | } else { | ||
93 | 1525018 | pred = a; | |
94 | 1525018 | *dir_ptr = 0; /* left */ | |
95 | } | ||
96 | /* we assume pred is positive */ | ||
97 | 2407668 | pred = FASTDIV((pred + (scale >> 1)), scale); | |
98 | |||
99 |
2/2✓ Branch 0 taken 1277262 times.
✓ Branch 1 taken 1130406 times.
|
2407668 | if (encoding) { |
100 | 1277262 | ret = level - pred; | |
101 | } else { | ||
102 | 1130406 | level += pred; | |
103 | 1130406 | ret = level; | |
104 | } | ||
105 | 2407668 | level *= scale; | |
106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2407668 times.
|
2407668 | 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 | 2407668 | dc_val[0] = level; | |
125 | |||
126 | 2407668 | return ret; | |
127 | } | ||
128 | |||
129 | #endif /* AVCODEC_MPEG4VIDEO_H */ | ||
130 |