1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* Modifications: |
* XVID MPEG-4 VIDEO CODEC |
4 |
|
* - Encoder header - |
5 |
* |
* |
6 |
* 22.08.2001 added support for EXT_MODE encoding mode |
* Copyright(C) 2002 Michael Militzer |
|
* support for EXTENDED API |
|
|
* 22.08.2001 fixed bug in iDQtab |
|
7 |
* |
* |
8 |
* Michael Militzer <isibaar@videocoding.de> |
* This program is an implementation of a part of one or more MPEG-4 |
9 |
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
10 |
|
* to use this software module in hardware or software products are |
11 |
|
* advised that its use may infringe existing patents or copyrights, and |
12 |
|
* any such use would be at such party's own risk. The original |
13 |
|
* developer of this software module and his/her company, and subsequent |
14 |
|
* editors and their companies, will have no liability for use of this |
15 |
|
* software or modifications or derivatives thereof. |
16 |
* |
* |
17 |
**************************************************************************/ |
* This program is free software ; you can redistribute it and/or modify |
18 |
|
* it under the terms of the GNU General Public License as published by |
19 |
|
* the Free Software Foundation ; either version 2 of the License, or |
20 |
|
* (at your option) any later version. |
21 |
|
* |
22 |
|
* This program is distributed in the hope that it will be useful, |
23 |
|
* but WITHOUT ANY WARRANTY ; without even the implied warranty of |
24 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
25 |
|
* GNU General Public License for more details. |
26 |
|
* |
27 |
|
* You should have received a copy of the GNU General Public License |
28 |
|
* along with this program ; if not, write to the Free Software |
29 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
30 |
|
* |
31 |
|
* $Id: encoder.h,v 1.21 2002-09-04 21:42:56 edgomez Exp $ |
32 |
|
* |
33 |
|
****************************************************************************/ |
34 |
|
|
35 |
#ifndef _ENCODER_H_ |
#ifndef _ENCODER_H_ |
36 |
#define _ENCODER_H_ |
#define _ENCODER_H_ |
37 |
|
|
|
|
|
38 |
#include "xvid.h" |
#include "xvid.h" |
|
|
|
39 |
#include "portab.h" |
#include "portab.h" |
40 |
#include "global.h" |
#include "global.h" |
41 |
#include "image/image.h" |
#include "image/image.h" |
42 |
|
#include "utils/ratecontrol.h" |
43 |
|
|
44 |
|
/***************************************************************************** |
45 |
|
* Constants |
46 |
|
****************************************************************************/ |
47 |
|
|
48 |
|
/* Quatization type */ |
49 |
#define H263_QUANT 0 |
#define H263_QUANT 0 |
50 |
#define MPEG4_QUANT 1 |
#define MPEG4_QUANT 1 |
51 |
|
|
52 |
|
/* Indicates no quantizer changes in INTRA_Q/INTER_Q modes */ |
53 |
|
#define NO_CHANGE 64 |
54 |
|
|
55 |
typedef uint32_t bool; |
/***************************************************************************** |
56 |
|
* Types |
57 |
|
****************************************************************************/ |
58 |
|
|
59 |
|
typedef int bool; |
60 |
|
|
61 |
typedef enum |
typedef enum |
62 |
{ |
{ |
63 |
I_VOP = 0, |
I_VOP = 0, |
64 |
P_VOP = 1 |
P_VOP = 1, |
65 |
|
B_VOP = 2 |
66 |
} |
} |
67 |
VOP_TYPE; |
VOP_TYPE; |
68 |
|
|
69 |
/*********************************** |
/***************************************************************************** |
70 |
|
* Structures |
71 |
Encoding Parameters |
****************************************************************************/ |
|
|
|
|
************************************/ |
|
72 |
|
|
73 |
typedef struct |
typedef struct |
74 |
{ |
{ |
80 |
uint32_t mb_width; |
uint32_t mb_width; |
81 |
uint32_t mb_height; |
uint32_t mb_height; |
82 |
|
|
83 |
VOP_TYPE coding_type; |
/* frame rate increment & base */ |
84 |
|
uint32_t fincr; |
85 |
|
uint32_t fbase; |
86 |
|
|
87 |
|
#ifdef _SMP |
88 |
|
int num_threads; |
89 |
|
#endif |
90 |
|
|
91 |
/* rounding type; alternate 0-1 after each interframe */ |
/* rounding type; alternate 0-1 after each interframe */ |
|
|
|
|
uint32_t rounding_type; |
|
|
|
|
92 |
/* 1 <= fixed_code <= 4 |
/* 1 <= fixed_code <= 4 |
93 |
automatically adjusted using motion vector statistics inside |
automatically adjusted using motion vector statistics inside |
94 |
*/ |
*/ |
95 |
|
|
96 |
uint32_t fixed_code; |
/* vars that not "quite" frame independant */ |
97 |
|
uint32_t m_quant_type; |
98 |
|
uint32_t m_rounding_type; |
99 |
|
uint32_t m_fcode; |
100 |
|
|
101 |
|
HINTINFO *hint; |
102 |
|
|
103 |
|
uint32_t m_seconds; |
104 |
|
uint32_t m_ticks; |
105 |
|
|
106 |
|
} |
107 |
|
MBParam; |
108 |
|
|
109 |
|
|
110 |
|
typedef struct |
111 |
|
{ |
112 |
uint32_t quant; |
uint32_t quant; |
|
uint32_t quant_type; |
|
113 |
uint32_t motion_flags; |
uint32_t motion_flags; |
114 |
uint32_t global_flags; |
uint32_t global_flags; |
115 |
} MBParam; |
|
116 |
|
VOP_TYPE coding_type; |
117 |
|
uint32_t rounding_type; |
118 |
|
uint32_t fcode; |
119 |
|
uint32_t bcode; |
120 |
|
|
121 |
|
uint32_t seconds; |
122 |
|
uint32_t ticks; |
123 |
|
|
124 |
|
IMAGE image; |
125 |
|
|
126 |
|
MACROBLOCK *mbs; |
127 |
|
|
128 |
|
} |
129 |
|
FRAMEINFO; |
130 |
|
|
131 |
typedef struct |
typedef struct |
132 |
{ |
{ |
148 |
|
|
149 |
int iFrameNum; |
int iFrameNum; |
150 |
int iMaxKeyInterval; |
int iMaxKeyInterval; |
|
int lum_masking; |
|
151 |
int bitrate; |
int bitrate; |
152 |
|
|
153 |
// images |
// images |
154 |
|
|
155 |
IMAGE sCurrent; |
FRAMEINFO *current; |
156 |
IMAGE sReference; |
FRAMEINFO *reference; |
157 |
|
|
158 |
|
#ifdef _DEBUG_PSNR |
159 |
|
IMAGE sOriginal; |
160 |
|
#endif |
161 |
IMAGE vInterH; |
IMAGE vInterH; |
162 |
IMAGE vInterV; |
IMAGE vInterV; |
163 |
|
IMAGE vInterVf; |
164 |
IMAGE vInterHV; |
IMAGE vInterHV; |
165 |
|
IMAGE vInterHVf; |
|
// macroblock |
|
|
|
|
|
MACROBLOCK * pMBs; |
|
166 |
|
|
167 |
Statistics sStat; |
Statistics sStat; |
168 |
|
RateControl rate_control; |
169 |
} |
} |
170 |
Encoder; |
Encoder; |
171 |
|
|
172 |
|
/***************************************************************************** |
173 |
|
* Inline functions |
174 |
|
****************************************************************************/ |
175 |
|
|
176 |
// indicates no quantizer changes in INTRA_Q/INTER_Q modes |
static __inline uint8_t |
177 |
#define NO_CHANGE 64 |
get_fcode(uint16_t sr) |
|
|
|
|
void init_encoder(uint32_t cpu_flags); |
|
|
|
|
|
int encoder_create(XVID_ENC_PARAM * pParam); |
|
|
int encoder_destroy(Encoder * pEnc); |
|
|
int encoder_encode(Encoder * pEnc, XVID_ENC_FRAME * pFrame, XVID_ENC_STATS * pResult); |
|
|
|
|
|
static __inline uint8_t get_fcode(uint16_t sr) |
|
178 |
{ |
{ |
179 |
if (sr <= 16) |
if (sr <= 16) |
180 |
return 1; |
return 1; |
201 |
return 0; |
return 0; |
202 |
} |
} |
203 |
|
|
204 |
#endif /* _ENCODER_H_ */ |
|
205 |
|
/***************************************************************************** |
206 |
|
* Prototypes |
207 |
|
****************************************************************************/ |
208 |
|
|
209 |
|
void init_encoder(uint32_t cpu_flags); |
210 |
|
|
211 |
|
int encoder_create(XVID_ENC_PARAM * pParam); |
212 |
|
int encoder_destroy(Encoder * pEnc); |
213 |
|
int encoder_encode(Encoder * pEnc, |
214 |
|
XVID_ENC_FRAME * pFrame, |
215 |
|
XVID_ENC_STATS * pResult); |
216 |
|
|
217 |
|
int encoder_encode_bframes(Encoder * pEnc, |
218 |
|
XVID_ENC_FRAME * pFrame, |
219 |
|
XVID_ENC_STATS * pResult); |
220 |
|
|
221 |
|
#endif |