yading@10
|
1 /*
|
yading@10
|
2 * MPEG4 encoder/decoder internal header.
|
yading@10
|
3 * Copyright (c) 2000,2001 Fabrice Bellard
|
yading@10
|
4 * Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
|
yading@10
|
5 *
|
yading@10
|
6 * This file is part of FFmpeg.
|
yading@10
|
7 *
|
yading@10
|
8 * FFmpeg is free software; you can redistribute it and/or
|
yading@10
|
9 * modify it under the terms of the GNU Lesser General Public
|
yading@10
|
10 * License as published by the Free Software Foundation; either
|
yading@10
|
11 * version 2.1 of the License, or (at your option) any later version.
|
yading@10
|
12 *
|
yading@10
|
13 * FFmpeg is distributed in the hope that it will be useful,
|
yading@10
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@10
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@10
|
16 * Lesser General Public License for more details.
|
yading@10
|
17 *
|
yading@10
|
18 * You should have received a copy of the GNU Lesser General Public
|
yading@10
|
19 * License along with FFmpeg; if not, write to the Free Software
|
yading@10
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@10
|
21 */
|
yading@10
|
22
|
yading@10
|
23 #ifndef AVCODEC_MPEG4VIDEO_H
|
yading@10
|
24 #define AVCODEC_MPEG4VIDEO_H
|
yading@10
|
25
|
yading@10
|
26 #include <stdint.h>
|
yading@10
|
27 #include "get_bits.h"
|
yading@10
|
28 #include "mpegvideo.h"
|
yading@10
|
29 #include "rl.h"
|
yading@10
|
30
|
yading@10
|
31 // shapes
|
yading@10
|
32 #define RECT_SHAPE 0
|
yading@10
|
33 #define BIN_SHAPE 1
|
yading@10
|
34 #define BIN_ONLY_SHAPE 2
|
yading@10
|
35 #define GRAY_SHAPE 3
|
yading@10
|
36
|
yading@10
|
37 #define SIMPLE_VO_TYPE 1
|
yading@10
|
38 #define CORE_VO_TYPE 3
|
yading@10
|
39 #define MAIN_VO_TYPE 4
|
yading@10
|
40 #define NBIT_VO_TYPE 5
|
yading@10
|
41 #define ARTS_VO_TYPE 10
|
yading@10
|
42 #define ACE_VO_TYPE 12
|
yading@10
|
43 #define ADV_SIMPLE_VO_TYPE 17
|
yading@10
|
44
|
yading@10
|
45 // aspect_ratio_info
|
yading@10
|
46 #define EXTENDED_PAR 15
|
yading@10
|
47
|
yading@10
|
48 //vol_sprite_usage / sprite_enable
|
yading@10
|
49 #define STATIC_SPRITE 1
|
yading@10
|
50 #define GMC_SPRITE 2
|
yading@10
|
51
|
yading@10
|
52 #define MOTION_MARKER 0x1F001
|
yading@10
|
53 #define DC_MARKER 0x6B001
|
yading@10
|
54
|
yading@10
|
55 #define VOS_STARTCODE 0x1B0
|
yading@10
|
56 #define USER_DATA_STARTCODE 0x1B2
|
yading@10
|
57 #define GOP_STARTCODE 0x1B3
|
yading@10
|
58 #define VISUAL_OBJ_STARTCODE 0x1B5
|
yading@10
|
59 #define VOP_STARTCODE 0x1B6
|
yading@10
|
60
|
yading@10
|
61 /* dc encoding for mpeg4 */
|
yading@10
|
62 extern const uint8_t ff_mpeg4_DCtab_lum[13][2];
|
yading@10
|
63 extern const uint8_t ff_mpeg4_DCtab_chrom[13][2];
|
yading@10
|
64
|
yading@10
|
65 extern const uint16_t ff_mpeg4_intra_vlc[103][2];
|
yading@10
|
66 extern RLTable ff_mpeg4_rl_intra;
|
yading@10
|
67
|
yading@10
|
68 /* Note this is identical to the intra rvlc except that it is reordered. */
|
yading@10
|
69 extern RLTable ff_rvlc_rl_inter;
|
yading@10
|
70 extern RLTable ff_rvlc_rl_intra;
|
yading@10
|
71
|
yading@10
|
72 extern const uint16_t ff_sprite_trajectory_tab[15][2];
|
yading@10
|
73 extern const uint8_t ff_mb_type_b_tab[4][2];
|
yading@10
|
74
|
yading@10
|
75 /* these matrixes will be permuted for the idct */
|
yading@10
|
76 extern const int16_t ff_mpeg4_default_intra_matrix[64];
|
yading@10
|
77 extern const int16_t ff_mpeg4_default_non_intra_matrix[64];
|
yading@10
|
78
|
yading@10
|
79 extern const uint8_t ff_mpeg4_y_dc_scale_table[32];
|
yading@10
|
80 extern const uint8_t ff_mpeg4_c_dc_scale_table[32];
|
yading@10
|
81 extern const uint16_t ff_mpeg4_resync_prefix[8];
|
yading@10
|
82
|
yading@10
|
83 extern const uint8_t ff_mpeg4_dc_threshold[8];
|
yading@10
|
84
|
yading@10
|
85 void ff_mpeg4_encode_mb(MpegEncContext *s,
|
yading@10
|
86 int16_t block[6][64],
|
yading@10
|
87 int motion_x, int motion_y);
|
yading@10
|
88 void ff_mpeg4_pred_ac(MpegEncContext * s, int16_t *block, int n,
|
yading@10
|
89 int dir);
|
yading@10
|
90 void ff_set_mpeg4_time(MpegEncContext * s);
|
yading@10
|
91 void ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
|
yading@10
|
92
|
yading@10
|
93 int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb);
|
yading@10
|
94 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
|
yading@10
|
95 void ff_mpeg4_clean_buffers(MpegEncContext *s);
|
yading@10
|
96 void ff_mpeg4_stuffing(PutBitContext * pbc);
|
yading@10
|
97 void ff_mpeg4_init_partitions(MpegEncContext *s);
|
yading@10
|
98 void ff_mpeg4_merge_partitions(MpegEncContext *s);
|
yading@10
|
99 void ff_clean_mpeg4_qscales(MpegEncContext *s);
|
yading@10
|
100 int ff_mpeg4_decode_partitions(MpegEncContext *s);
|
yading@10
|
101 int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s);
|
yading@10
|
102 int ff_mpeg4_decode_video_packet_header(MpegEncContext *s);
|
yading@10
|
103 void ff_mpeg4_init_direct_mv(MpegEncContext *s);
|
yading@10
|
104 void ff_mpeg4videodec_static_init(void);
|
yading@10
|
105
|
yading@10
|
106 /**
|
yading@10
|
107 *
|
yading@10
|
108 * @return the mb_type
|
yading@10
|
109 */
|
yading@10
|
110 int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my);
|
yading@10
|
111
|
yading@10
|
112 extern uint8_t ff_mpeg4_static_rl_table_store[3][2][2*MAX_RUN + MAX_LEVEL + 3];
|
yading@10
|
113
|
yading@10
|
114
|
yading@10
|
115 #if 0 //3IV1 is quite rare and it slows things down a tiny bit
|
yading@10
|
116 #define IS_3IV1 s->codec_tag == AV_RL32("3IV1")
|
yading@10
|
117 #else
|
yading@10
|
118 #define IS_3IV1 0
|
yading@10
|
119 #endif
|
yading@10
|
120
|
yading@10
|
121
|
yading@10
|
122 /**
|
yading@10
|
123 * Predict the dc.
|
yading@10
|
124 * encoding quantized level -> quantized diff
|
yading@10
|
125 * decoding quantized diff -> quantized level
|
yading@10
|
126 * @param n block index (0-3 are luma, 4-5 are chroma)
|
yading@10
|
127 * @param dir_ptr pointer to an integer where the prediction direction will be stored
|
yading@10
|
128 */
|
yading@10
|
129 static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding)
|
yading@10
|
130 {
|
yading@10
|
131 int a, b, c, wrap, pred, scale, ret;
|
yading@10
|
132 int16_t *dc_val;
|
yading@10
|
133
|
yading@10
|
134 /* find prediction */
|
yading@10
|
135 if (n < 4) {
|
yading@10
|
136 scale = s->y_dc_scale;
|
yading@10
|
137 } else {
|
yading@10
|
138 scale = s->c_dc_scale;
|
yading@10
|
139 }
|
yading@10
|
140 if(IS_3IV1)
|
yading@10
|
141 scale= 8;
|
yading@10
|
142
|
yading@10
|
143 wrap= s->block_wrap[n];
|
yading@10
|
144 dc_val = s->dc_val[0] + s->block_index[n];
|
yading@10
|
145
|
yading@10
|
146 /* B C
|
yading@10
|
147 * A X
|
yading@10
|
148 */
|
yading@10
|
149 a = dc_val[ - 1];
|
yading@10
|
150 b = dc_val[ - 1 - wrap];
|
yading@10
|
151 c = dc_val[ - wrap];
|
yading@10
|
152
|
yading@10
|
153 /* outside slice handling (we can't do that by memset as we need the dc for error resilience) */
|
yading@10
|
154 if(s->first_slice_line && n!=3){
|
yading@10
|
155 if(n!=2) b=c= 1024;
|
yading@10
|
156 if(n!=1 && s->mb_x == s->resync_mb_x) b=a= 1024;
|
yading@10
|
157 }
|
yading@10
|
158 if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1){
|
yading@10
|
159 if(n==0 || n==4 || n==5)
|
yading@10
|
160 b=1024;
|
yading@10
|
161 }
|
yading@10
|
162
|
yading@10
|
163 if (abs(a - b) < abs(b - c)) {
|
yading@10
|
164 pred = c;
|
yading@10
|
165 *dir_ptr = 1; /* top */
|
yading@10
|
166 } else {
|
yading@10
|
167 pred = a;
|
yading@10
|
168 *dir_ptr = 0; /* left */
|
yading@10
|
169 }
|
yading@10
|
170 /* we assume pred is positive */
|
yading@10
|
171 pred = FASTDIV((pred + (scale >> 1)), scale);
|
yading@10
|
172
|
yading@10
|
173 if(encoding){
|
yading@10
|
174 ret = level - pred;
|
yading@10
|
175 }else{
|
yading@10
|
176 level += pred;
|
yading@10
|
177 ret= level;
|
yading@10
|
178 if(s->err_recognition&(AV_EF_BITSTREAM|AV_EF_AGGRESSIVE)){
|
yading@10
|
179 if(level<0){
|
yading@10
|
180 av_log(s->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\n", s->mb_x, s->mb_y);
|
yading@10
|
181 return -1;
|
yading@10
|
182 }
|
yading@10
|
183 if(level*scale > 2048 + scale){
|
yading@10
|
184 av_log(s->avctx, AV_LOG_ERROR, "dc overflow at %dx%d\n", s->mb_x, s->mb_y);
|
yading@10
|
185 return -1;
|
yading@10
|
186 }
|
yading@10
|
187 }
|
yading@10
|
188 }
|
yading@10
|
189 level *=scale;
|
yading@10
|
190 if(level&(~2047)){
|
yading@10
|
191 if(level<0)
|
yading@10
|
192 level=0;
|
yading@10
|
193 else if(!(s->workaround_bugs&FF_BUG_DC_CLIP))
|
yading@10
|
194 level=2047;
|
yading@10
|
195 }
|
yading@10
|
196 dc_val[0]= level;
|
yading@10
|
197
|
yading@10
|
198 return ret;
|
yading@10
|
199 }
|
yading@10
|
200 #endif /* AVCODEC_MPEG4VIDEO_H */
|