FFmpeg
mpeg4video.h
Go to the documentation of this file.
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 
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 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  if (n < 4)
60  scale = s->y_dc_scale;
61  else
62  scale = s->c_dc_scale;
63  if (IS_3IV1)
64  scale = 8;
65 
66  wrap = s->block_wrap[n];
67  dc_val = s->dc_val[0] + s->block_index[n];
68 
69  /* B C
70  * A X
71  */
72  a = dc_val[-1];
73  b = dc_val[-1 - wrap];
74  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  if (s->first_slice_line && n != 3) {
79  if (n != 2)
80  b = c = 1024;
81  if (n != 1 && s->mb_x == s->resync_mb_x)
82  b = a = 1024;
83  }
84  if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) {
85  if (n == 0 || n == 4 || n == 5)
86  b = 1024;
87  }
88 
89  if (abs(a - b) < abs(b - c)) {
90  pred = c;
91  *dir_ptr = 1; /* top */
92  } else {
93  pred = a;
94  *dir_ptr = 0; /* left */
95  }
96  /* we assume pred is positive */
97  pred = FASTDIV((pred + (scale >> 1)), scale);
98 
99  if (encoding) {
100  ret = level - pred;
101  } else {
102  level += pred;
103  ret = level;
104  }
105  level *= scale;
106  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  dc_val[0] = level;
125 
126  return ret;
127 }
128 
129 #endif /* AVCODEC_MPEG4VIDEO_H */
FF_BUG_DC_CLIP
#define FF_BUG_DC_CLIP
Definition: avcodec.h:1292
level
uint8_t level
Definition: svq3.c:204
b
#define b
Definition: input.c:41
mpegvideo.h
ff_mpeg4_init_direct_mv
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
Definition: mpeg4video.c:83
wrap
#define wrap(func)
Definition: neontest.h:65
AV_EF_BITSTREAM
#define AV_EF_BITSTREAM
detect bitstream specification deviations
Definition: defs.h:49
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
s
#define s(width, name)
Definition: cbs_vp9.c:256
abs
#define abs(x)
Definition: cuda_runtime.h:35
FASTDIV
#define FASTDIV(a, b)
Definition: mathops.h:205
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ff_mpeg4_set_direct_mv
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
Definition: mpeg4video.c:129
ff_mpeg4_pred_dc
static int ff_mpeg4_pred_dc(MpegEncContext *s, int n, int level, int *dir_ptr, int encoding)
Predict the dc.
Definition: mpeg4video.h:52
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
ff_mpeg4_get_video_packet_prefix_length
int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s)
Definition: mpeg4video.c:42
ret
ret
Definition: filter_design.txt:187
AV_EF_AGGRESSIVE
#define AV_EF_AGGRESSIVE
consider things that a sane encoder/muxer should not do as an error
Definition: defs.h:56
pred
static const float pred[4]
Definition: siprdata.h:259
ff_mpeg4_clean_buffers
void ff_mpeg4_clean_buffers(MpegEncContext *s)
Definition: mpeg4video.c:57
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:70
IS_3IV1
#define IS_3IV1
Definition: mpeg4video.h:42