1 /*
2     libfame - Fast Assembly MPEG Encoder Library
3     Copyright (C) 2000-2001 Vivien Chappelier
4 
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License as published by the Free Software Foundation; either
8     version 2 of the License, or (at your option) any later version.
9 
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Library General Public License for more details.
14 
15     You should have received a copy of the GNU Library General Public
16     License along with this library; if not, write to the Free
17     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 
20 #ifndef __FAME_H__
21 #define __FAME_H__
22 
23 #include <stdlib.h>
24 #include "fame_version.h"
25 
26 /* Some compilers use a special export keyword */
27 /* Code taken from SDL                         */
28 #ifndef DECLSPEC
29 # ifdef __BEOS__
30 #  define ASMSYM
31 #  if defined(__GNUC__)
32 #   define DECLSPEC     __declspec(dllexport)
33 #  else
34 #   define DECLSPEC     __declspec(export)
35 #  endif
36 # else
37 # ifdef WIN32
38 #  define DECLSPEC      __declspec(dllexport)
39 #  define ASMSYM  "_"
40 # else
41 #  define DECLSPEC
42 #  define ASMSYM
43 # endif
44 # endif
45 #endif
46 
47 /* Alignment */
48 #if defined(__GNUC__)
49 #ifdef WIN32
50 #define FAME_ALIGNMENT 16
51 #else
52 #define FAME_ALIGNMENT 32
53 #endif
54 #define FAME_ALIGNED __attribute__ ((__aligned__(FAME_ALIGNMENT)))
55 #else
56 #define FAME_ALIGNED
57 #endif
58 
59 /* Error management */
60 #if defined(__GNUC__)
61 #define FAME_INFO(format, args...) \
62       fprintf(stderr, format, ##args)
63 #define FAME_WARNING(format, args...) \
64       fprintf(stderr, "Warning: " format, ##args)
65 #define FAME_ERROR(format, args...) \
66       fprintf(stderr, "Error: " format, ##args)
67 #define FAME_FATAL(format, args...) \
68       { fprintf(stderr, "Fatal: " format, ##args); exit(-1); }
69 #else /* not __GNUC__ */
70 /* No vararg macros */
71 int FAME_INFO(const char *format, ...);
72 int FAME_WARNING(const char *format, ...);
73 int FAME_ERROR(const char *format, ...);
74 int FAME_FATAL(const char *format, ...);
75 
76 #endif
77 
78 #ifndef fame_min
79 #define fame_min(X,Y) (((X) < (Y)) ? (X) : (Y))
80 #endif
81 #ifndef fame_max
82 #define fame_max(X,Y) (((X) > (Y)) ? (X) : (Y))
83 #endif
84 
85 /* object management */
86 #define FAME_EXTENDS(t) t super
87 #define FAME_NEW(t) t ## _constructor((t *) malloc(sizeof(t)))
88 #define FAME_CONSTRUCTOR(t) t * t ## _constructor(t *this)
89 #define FAME_DELETE(x) free(x)
90 #define FAME_OVERLOADED(x) super_ ## x
91 
92 typedef struct _fame_yuv_t_ {
93   unsigned int w, h, p;
94   unsigned char *y;
95   unsigned char *u;
96   unsigned char *v;
97 } fame_yuv_t;
98 
99 typedef enum { bab_not_coded,
100 	       bab_all_coded,
101 	       bab_border_16x16,
102 	       bab_border_8x8,
103 	       bab_border_4x4 } fame_bab_t;
104 
105 typedef struct _fame_box_t_ {
106   short x, y;
107   unsigned short w, h;
108 } fame_box_t;
109 
110 typedef struct _fame_vlc_t_ {
111   unsigned long code;
112   unsigned long length;
113 } fame_vlc_t;
114 
115 #if defined(HAS_MMX)
116 typedef short dct_t;
117 #else
118 typedef float dct_t;
119 #endif
120 
121 struct _fame_motion_vector_t_ {
122   int dx;
123   int dy;
124   int error;
125   unsigned long deviation;
126   unsigned short count;
127 };
128 typedef struct _fame_motion_vector_t_ fame_motion_vector_t;
129 
130 typedef enum { motion_intra, motion_inter, motion_inter4v } fame_motion_coding_t;
131 
132 typedef enum { fame_mismatch_local, fame_mismatch_global } fame_mismatch_t;
133 
134 typedef struct _fame_context_t_ fame_context_t;
135 typedef struct _fame_frame_statistics_t_ fame_frame_statistics_t;
136 typedef struct _fame_global_statistics_t_ fame_global_statistics_t;
137 typedef struct _fame_parameters_t_ fame_parameters_t;
138 
139 /******************************* object type *********************************/
140 typedef struct _fame_object_t_ {
141   char const *name;
142 } fame_object_t;
143 
144 #define FAME_OBJECT(x) ((fame_object_t *) x)
145 
146 typedef struct _fame_list_t_ {
147   char const *type;
148   fame_object_t *item;
149   struct _fame_list_t_ *next;
150 } fame_list_t;
151 
152 /********************************** context **********************************/
153 
154 struct _fame_context_t_ {
155   fame_list_t *type_list;
156   fame_object_t *profile;
157   struct _fame_private_t_ *priv;
158 };
159 
160 /******************************** statistics *********************************/
161 
162 struct _fame_frame_statistics_t_ {
163   unsigned int frame_number;
164   char coding;
165   signed int target_bits;
166   unsigned int actual_bits;
167   unsigned int spatial_activity;
168   float quant_scale;
169 };
170 
171 
172 struct _fame_global_statistics_t_ {
173   unsigned int total_frames;
174   unsigned int target_rate;
175   unsigned int actual_rate;
176   unsigned int mean_spatial_activity;
177 };
178 
179 
180 /******************************** parameters *********************************/
181 
182 struct _fame_parameters_t_ {
183   int width;                        /* width of the video sequence */
184   int height;                       /* height of the video sequence */
185   char const *coding;               /* coding sequence */
186   int quality;                      /* video quality */
187   int bitrate;                      /* video bitrate (0=VBR)*/
188   int slices_per_frame;             /* number of slices per frame */
189   unsigned int frames_per_sequence; /* number of frames per sequence */
190   int frame_rate_num;               /* numerator of frames per second */
191   int frame_rate_den;               /* denominator of frames per second */
192   int shape_quality;                /* binary shape quality */
193   unsigned int search_range;        /* motion estimation search range */
194   unsigned char verbose;            /* verbosity */
195   char const *profile;              /* profile name */
196   unsigned int total_frames;        /* total number of frames */
197   int (* retrieve_cb)(fame_frame_statistics_t *stats);
198 };
199 
200 #define FAME_PARAMETERS_INITIALIZER {		                             \
201   352,					/* CIF width  */	             \
202   288,					/* CIF height */	             \
203   "I",					/* I sequence */	             \
204   75,					/* average video quality */          \
205   0,                                    /* variable bitrate */               \
206   1,					/* 1 slice/frame */	             \
207   0xffffffff,				/* unlimited length */	             \
208   25,                                   /* 25 frames/second */               \
209   1,                                    /* /1 */                             \
210   100,                                  /* original shape */                 \
211   0,                                    /* adaptative search range */        \
212   1,                                    /* verbose mode */                   \
213   "mpeg4",                              /* profile name */                   \
214   0,                                    /* number of frames */               \
215   NULL                                  /* stats retrieval callback */       \
216 }
217 
218 /***************************** function prototypes ***************************/
219 
220 #ifdef __cplusplus
221 extern "C" {
222 #endif
223 
224 extern DECLSPEC fame_context_t * fame_open();
225 
226 extern DECLSPEC void fame_register(fame_context_t * context,
227 				   char const *type,
228 				   fame_object_t *object);
229 
230 extern DECLSPEC void fame_unregister(fame_context_t * context,
231 				     char const *type);
232 
233 extern DECLSPEC fame_object_t *fame_get_object(fame_context_t * context,
234 					       char const *type);
235 
236 extern DECLSPEC void fame_init(fame_context_t * context,
237 			       fame_parameters_t *p,
238 			       unsigned char *buffer,
239 			       unsigned int size);
240 
241 extern DECLSPEC void fame_start_frame(fame_context_t *context,
242 				      fame_yuv_t *yuv,
243 				      unsigned char *mask);
244 
245 extern DECLSPEC int fame_encode_slice(fame_context_t *context);
246 
247 extern DECLSPEC void fame_end_frame(fame_context_t *context,
248 				    fame_frame_statistics_t *stats);
249 
250 extern DECLSPEC int fame_close(fame_context_t *context);
251 
252 /* DEPRECATED */
253 extern DECLSPEC int fame_encode_frame(fame_context_t *context,
254 				      fame_yuv_t *yuv,
255 				      unsigned char *mask);
256 
257 #ifdef __cplusplus
258 }
259 #endif
260 
261 #endif
262