1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* Modifications: |
* XVID MPEG-4 VIDEO CODEC |
4 |
|
* - Encoder header - |
5 |
* |
* |
6 |
* 22.08.2001 added support for EXT_MODE encoding mode |
* This program is an implementation of a part of one or more MPEG-4 |
7 |
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
8 |
|
* to use this software module in hardware or software products are |
9 |
|
* advised that its use may infringe existing patents or copyrights, and |
10 |
|
* any such use would be at such party's own risk. The original |
11 |
|
* developer of this software module and his/her company, and subsequent |
12 |
|
* editors and their companies, will have no liability for use of this |
13 |
|
* software or modifications or derivatives thereof. |
14 |
|
* |
15 |
|
* This program is free software ; you can redistribute it and/or modify |
16 |
|
* it under the terms of the GNU General Public License as published by |
17 |
|
* the Free Software Foundation ; either version 2 of the License, or |
18 |
|
* (at your option) any later version. |
19 |
|
* |
20 |
|
* This program is distributed in the hope that it will be useful, |
21 |
|
* but WITHOUT ANY WARRANTY ; without even the implied warranty of |
22 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 |
|
* GNU General Public License for more details. |
24 |
|
* |
25 |
|
* You should have received a copy of the GNU General Public License |
26 |
|
* along with this program ; if not, write to the Free Software |
27 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
|
* |
29 |
|
****************************************************************************/ |
30 |
|
/***************************************************************************** |
31 |
|
* |
32 |
|
* History |
33 |
|
* |
34 |
|
* - 13.06.2002 Added legal header |
35 |
|
* - 22.08.2001 Added support for EXT_MODE encoding mode |
36 |
* support for EXTENDED API |
* support for EXTENDED API |
37 |
* 22.08.2001 fixed bug in iDQtab |
* - 22.08.2001 fixed bug in iDQtab |
38 |
* |
* |
39 |
* Michael Militzer <isibaar@videocoding.de> |
* $Id$ |
40 |
* |
* |
41 |
**************************************************************************/ |
****************************************************************************/ |
42 |
|
|
43 |
#ifndef _ENCODER_H_ |
#ifndef _ENCODER_H_ |
44 |
#define _ENCODER_H_ |
#define _ENCODER_H_ |
45 |
|
|
|
|
|
46 |
#include "xvid.h" |
#include "xvid.h" |
|
|
|
47 |
#include "portab.h" |
#include "portab.h" |
48 |
#include "global.h" |
#include "global.h" |
49 |
#include "image/image.h" |
#include "utils/ratecontrol.h" |
50 |
|
|
51 |
|
/***************************************************************************** |
52 |
|
* Constants |
53 |
|
****************************************************************************/ |
54 |
|
|
55 |
|
/* Quatization type */ |
56 |
#define H263_QUANT 0 |
#define H263_QUANT 0 |
57 |
#define MPEG4_QUANT 1 |
#define MPEG4_QUANT 1 |
58 |
|
|
59 |
|
/* Indicates no quantizer changes in INTRA_Q/INTER_Q modes */ |
60 |
|
#define NO_CHANGE 64 |
61 |
|
|
62 |
typedef uint32_t bool; |
/***************************************************************************** |
63 |
|
* Types |
64 |
|
****************************************************************************/ |
65 |
typedef enum |
|
66 |
{ |
typedef int bool; |
67 |
I_VOP = 0, |
|
68 |
P_VOP = 1, |
/***************************************************************************** |
69 |
B_VOP = 2 |
* Structures |
70 |
} |
****************************************************************************/ |
|
VOP_TYPE; |
|
|
|
|
|
/*********************************** |
|
|
|
|
|
Encoding Parameters |
|
|
|
|
|
************************************/ |
|
71 |
|
|
72 |
typedef struct |
typedef struct |
73 |
{ |
{ |
74 |
|
/* --- constants --- */ |
75 |
uint32_t width; |
uint32_t width; |
76 |
uint32_t height; |
uint32_t height; |
77 |
|
|
80 |
uint32_t mb_width; |
uint32_t mb_width; |
81 |
uint32_t mb_height; |
uint32_t mb_height; |
82 |
|
|
83 |
|
int plugin_flags; |
84 |
|
|
85 |
/* frame rate increment & base */ |
/* frame rate increment & base */ |
86 |
uint32_t fincr; |
uint32_t fincr; |
87 |
uint32_t fbase; |
uint32_t fbase; |
88 |
|
|
89 |
#ifdef BFRAMES |
xvid_global_t global_flags; |
90 |
int max_bframes; |
int bquant_ratio; |
91 |
|
int bquant_offset; |
92 |
|
int frame_drop_ratio; |
93 |
|
|
94 |
|
#ifdef _SMP |
95 |
|
int num_threads; |
96 |
#endif |
#endif |
97 |
|
|
98 |
|
|
99 |
|
int iMaxKeyInterval; |
100 |
|
int max_bframes; |
101 |
|
|
102 |
|
/* --- inbetween vop stuff --- */ |
103 |
/* rounding type; alternate 0-1 after each interframe */ |
/* rounding type; alternate 0-1 after each interframe */ |
104 |
/* 1 <= fixed_code <= 4 |
/* 1 <= fixed_code <= 4 |
105 |
automatically adjusted using motion vector statistics inside |
automatically adjusted using motion vector statistics inside |
106 |
*/ |
*/ |
107 |
|
|
108 |
/* vars that not "quite" frame independant */ |
/* vars that not "quite" frame independant */ |
|
uint32_t m_quant_type; |
|
109 |
uint32_t m_rounding_type; |
uint32_t m_rounding_type; |
110 |
uint32_t m_fcode; |
uint32_t m_fcode; |
111 |
|
xvid_vol_t vol_flags; |
112 |
|
|
113 |
HINTINFO * hint; |
int64_t m_stamp; |
114 |
|
} |
115 |
|
MBParam; |
116 |
|
|
|
#ifdef BFRAMES |
|
|
uint32_t m_seconds; |
|
|
uint32_t m_ticks; |
|
|
#endif |
|
117 |
|
|
118 |
} MBParam; |
typedef struct |
119 |
|
{ |
120 |
|
int iTextBits; |
121 |
|
int iMvSum; |
122 |
|
int iMvCount; |
123 |
|
int kblks; |
124 |
|
int mblks; |
125 |
|
int ublks; |
126 |
|
int gblks; |
127 |
|
} |
128 |
|
Statistics; |
129 |
|
|
130 |
|
|
131 |
|
/* encoding queue */ |
132 |
typedef struct |
typedef struct |
133 |
{ |
{ |
134 |
uint32_t quant; |
xvid_enc_frame_t frame; |
135 |
uint32_t motion_flags; |
unsigned char quant_intra_matrix[64]; |
136 |
uint32_t global_flags; |
unsigned char quant_inter_matrix[64]; |
137 |
|
IMAGE image; |
138 |
|
} QUEUEINFO; |
139 |
|
|
140 |
|
|
141 |
VOP_TYPE coding_type; |
typedef struct |
142 |
|
{ |
143 |
|
int frame_num; |
144 |
|
int fincr; |
145 |
|
xvid_vol_t vol_flags; |
146 |
|
xvid_vop_t vop_flags; |
147 |
|
xvid_motion_t motion_flags; |
148 |
|
|
149 |
|
int coding_type; |
150 |
|
uint32_t quant; |
151 |
uint32_t rounding_type; |
uint32_t rounding_type; |
152 |
uint32_t fcode; |
uint32_t fcode; |
153 |
uint32_t bcode; |
uint32_t bcode; |
154 |
|
|
|
#ifdef BFRAMES |
|
155 |
uint32_t seconds; |
uint32_t seconds; |
156 |
uint32_t ticks; |
uint32_t ticks; |
157 |
#endif |
int64_t stamp; |
158 |
|
|
159 |
IMAGE image; |
IMAGE image; |
160 |
|
|
161 |
MACROBLOCK * mbs; |
MACROBLOCK * mbs; |
162 |
|
|
163 |
} FRAMEINFO; |
WARPPOINTS warp; // as in bitstream |
164 |
|
GMC_DATA gmc_data; // common data for all MBs |
165 |
|
|
166 |
typedef struct |
int length; /* the encoded size of this frame */ |
|
{ |
|
|
int iTextBits; |
|
|
float fMvPrevSigma; |
|
|
int iMvSum; |
|
|
int iMvCount; |
|
|
int kblks; |
|
|
int mblks; |
|
|
int ublks; |
|
|
} |
|
|
Statistics; |
|
167 |
|
|
168 |
|
Statistics sStat; |
169 |
|
} |
170 |
|
FRAMEINFO; |
171 |
|
|
172 |
|
|
173 |
typedef struct |
typedef struct |
175 |
MBParam mbParam; |
MBParam mbParam; |
176 |
|
|
177 |
int iFrameNum; |
int iFrameNum; |
|
int iMaxKeyInterval; |
|
178 |
int bitrate; |
int bitrate; |
179 |
|
|
180 |
|
// plugins |
181 |
|
int num_plugins; /* note: we store plugin flags in MBPARAM */ |
182 |
|
xvid_enc_plugin_t * plugins; |
183 |
|
|
184 |
|
// dquant |
185 |
|
|
186 |
|
int * temp_dquants; |
187 |
|
|
188 |
// images |
// images |
189 |
|
|
190 |
FRAMEINFO * current; |
FRAMEINFO * current; |
191 |
FRAMEINFO * reference; |
FRAMEINFO * reference; |
192 |
|
|
193 |
#ifdef _DEBUG |
IMAGE sOriginal; /* original image copy for i/p frames */ |
194 |
IMAGE sOriginal; |
IMAGE sOriginal2; /* original image copy for b-frames */ |
|
#endif |
|
195 |
IMAGE vInterH; |
IMAGE vInterH; |
196 |
IMAGE vInterV; |
IMAGE vInterV; |
197 |
IMAGE vInterVf; |
IMAGE vInterVf; |
198 |
IMAGE vInterHV; |
IMAGE vInterHV; |
199 |
IMAGE vInterHVf; |
IMAGE vInterHVf; |
200 |
|
|
201 |
#ifdef BFRAMES |
IMAGE vGMC; |
202 |
/* constants */ |
|
203 |
int bquant_ratio; |
/* image queue */ |
204 |
/* vars */ |
int queue_head; |
205 |
|
int queue_tail; |
206 |
|
int queue_size; |
207 |
|
QUEUEINFO *queue; |
208 |
|
|
209 |
|
/* bframe buffer */ |
210 |
int bframenum_head; |
int bframenum_head; |
211 |
int bframenum_tail; |
int bframenum_tail; |
212 |
int flush_bframes; |
int flush_bframes; |
215 |
IMAGE f_refh; |
IMAGE f_refh; |
216 |
IMAGE f_refv; |
IMAGE f_refv; |
217 |
IMAGE f_refhv; |
IMAGE f_refhv; |
|
#endif |
|
|
Statistics sStat; |
|
|
} |
|
|
Encoder; |
|
218 |
|
|
219 |
|
/* closed_gop fixup temporary storage */ |
220 |
|
int closed_bframenum; /* == -1 if there is no fixup intended */ |
221 |
|
QUEUEINFO closed_qframe; /* qFrame, only valid when >= 0 */ |
222 |
|
|
223 |
// indicates no quantizer changes in INTRA_Q/INTER_Q modes |
int m_framenum; /* debug frame num counter; unlike iFrameNum, does not reset at ivop */ |
|
#define NO_CHANGE 64 |
|
224 |
|
|
225 |
void init_encoder(uint32_t cpu_flags); |
RateControl rate_control; |
226 |
|
|
227 |
int encoder_create(XVID_ENC_PARAM * pParam); |
float fMvPrevSigma; |
228 |
int encoder_destroy(Encoder * pEnc); |
} |
229 |
int encoder_encode(Encoder * pEnc, XVID_ENC_FRAME * pFrame, XVID_ENC_STATS * pResult); |
Encoder; |
230 |
|
|
231 |
static __inline uint8_t get_fcode(uint16_t sr) |
/***************************************************************************** |
232 |
|
* Inline functions |
233 |
|
****************************************************************************/ |
234 |
|
|
235 |
|
static __inline uint8_t |
236 |
|
get_fcode(uint16_t sr) |
237 |
{ |
{ |
238 |
if (sr <= 16) |
if (sr <= 16) |
239 |
return 1; |
return 1; |
260 |
return 0; |
return 0; |
261 |
} |
} |
262 |
|
|
263 |
#endif /* _ENCODER_H_ */ |
|
264 |
|
/***************************************************************************** |
265 |
|
* Prototypes |
266 |
|
****************************************************************************/ |
267 |
|
|
268 |
|
void init_encoder(uint32_t cpu_flags); |
269 |
|
|
270 |
|
int enc_create(xvid_enc_create_t * create, xvid_enc_rc_t * rc); |
271 |
|
int enc_destroy(Encoder * pEnc); |
272 |
|
int enc_encode(Encoder * pEnc, |
273 |
|
xvid_enc_frame_t * pFrame, |
274 |
|
xvid_enc_stats_t * stats); |
275 |
|
|
276 |
|
#endif |