[XviD-devel] API 3.0 (more stuff)

peter ross xvid-devel@xvid.org
Wed, 18 Sep 2002 22:06:34 +1000


This is a multi-part message in MIME format.

------=_NextPart_000_26c9_492f_50b3
Content-Type: text/plain; format=flowed

hello all,

i've been pretty slack--busy lately with other stuff and really
havent had much time to integrate the new api. its also alot of work,
because the new api changes many things. not significantly, but
theres the potential for breakage.

anyway my latest api recommedations:

* create a new XVID_ENC_RC structure; this contains all the rc
  parameters using a union. it is passed at encoder creation time, eg.

    memset(&xratecon, 0, sizeof(XVID_ENC_RC);
    xratecon.version = XVID_VERSION;
    xratecon.mode = XVID_CBR;
    xratecon.data.cbr.rate = 780000;	/* 780 kbps */

    xvid_encore(handle, XVID_ENC_CREATE, &xparam, &xratecon);

* remove XVID_ENC_STATS structure, since rate control is going to be
   housed inside xvidcore.(external apps dont need access to these
   statistics)

* decoder notify, for return vop & vol info. it could be extended
to support other "non-video" mpeg4 features. btw, 2dmesh looks simple
to implement, does anyone know where i can find some sample 2dmesh
streams?

* the hinted-me-bitstream stuff can be replaced by a 'char *
hint_filename', and shoved  in the 2pass rc structs.

anyway, ive attacheed the latest xvid.h prototype.

-- pete

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com

------=_NextPart_000_26c9_492f_50b3
Content-Type: text/plain; name="xvid_300.h"; format=flowed
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="xvid_300.h"

/*****************************************************************************
*
*  XVID MPEG-4 VIDEO CODEC
*  - XviD Main header file -
*
*  This program is an implementation of a part of one or more MPEG-4
*  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
*  to use this software module in hardware or software products are
*  advised that its use may infringe existing patents or copyrights, and
*  any such use would be at such party's own risk.  The original
*  developer of this software module and his/her company, and subsequent
*  editors and their companies, will have no liability for use of this
*  software or modifications or derivatives thereof.
*
*  This program is free software ; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation ; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY ; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program ; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
*
*  $Id: xvid.h,v 1.17 2002/07/31 18:10:34 chl Exp $
*
*****************************************************************************/

#ifndef _XVID_H_
#define _XVID_H_

#ifdef __cplusplus
extern "C" {
#endif

/*****************************************************************************
* Global constants
****************************************************************************/

/* API Version : 3.0 */
#define XVID_MAKE_VERSION(A,B,C)	(((A) << 16) | ((B) << 8) | (C))
#define XVID_VERSION		XVID_MAKE_VERSION(3,0,0)


/* Error codes */
#define XVID_ERR_OK			0
#define XVID_ERR_FAIL		1
#define	XVID_ERR_MEMORY		2
#define XVID_ERR_FORMAT		3
#define XVID_ERR_VERSION	4


/* Colorspaces */
#define XVID_CSP_NULL 		0
#define XVID_CSP_USER		1	/* custom yuv planar */
#define XVID_CSP_EXTERN		3	/* per slice rendering; external yuv planar */
#define XVID_CSP_YV12		4	/* yuv planar */
#define XVID_CSP_I420		5	/* yvu planar */
#define XVID_CSP_YUY2		6	/* yuyv packed */
#define XVID_CSP_YVYU		7	/* yvyu packed */
#define XVID_CSP_UYVY		8	/* uyvy packed */
#define XVID_CSP_RGB32 		9	/* rgb 32 */
#define XVID_CSP_RGB24 		10	/* rgb 24 */
#define XVID_CSP_RGB565		11	/* rgb 16 */
#define XVID_CSP_RGB555		12	/* rgb 15 */
#define XVID_CSP_VFLIP		0x80000000	/* vertical flip mask */

/*****************************************************************************
* Global structures
****************************************************************************/


// This struct is used for XVID_CSP_USER, XVID_CSP_EXTERN
	typedef struct
	{
		void *y,*u,*v;
		int stride_y, stride_u, stride_v;
	} XVID_IMAGE;


/*****************************************************************************
*  Initialization constants
****************************************************************************/

/* CPU flags for XVID_INIT_PARAM.cpu_flags */
// ARCH_X86
#define XVID_CPU_MMX		0x00000001
#define XVID_CPU_MMXEXT		0x00000002
#define XVID_CPU_SSE		0x00000004
#define XVID_CPU_SSE2		0x00000008
#define XVID_CPU_3DNOW		0x00000010
#define XVID_CPU_3DNOWEXT	0x00000020
#define XVID_CPU_TSC		0x00000040
// ARCH_IA64
#define XVID_CPU_IA64		0x00000001
// ARCH_PPC
#define XVID_CPU_ALTIVEC	0x00000001
// arch independant
#define XVID_CPU_CHKONLY	0x40000000		/* [input only] check cpu only; dont 
init globals */
#define XVID_CPU_FORCE		0x80000000		/* [input only] force


/*****************************************************************************
*  Initialization structures
****************************************************************************/

	typedef struct
	{
		int version;
		int max_version;	/* [out]		max supported api version */
		int cpu_flags;		/* [in:opt,out]	cpu flags */
	}
	XVID_INIT_PARAM;

/*****************************************************************************
*  Initialization entry point
****************************************************************************/

	int xvid_init(void *handle,
				  int opt,
				  void *param1,
				  void *param2);


/*****************************************************************************
* Decoder constants
****************************************************************************/

	/* Flags for XVID_DEC_PARAM.global */
#define XVID_DEC_LOWDELAY0	0x00000001	/* assume low delay is disabled by 
default */

/* Flags for XVID_DEC_FRAME.general */
#define XVID_DEC_QUICK		0x00000001	/* dont decode bframes */

/* Flags for XVID_DEC_FRAME.notify */
#define XVID_DEC_NONE		0		/* dont display this frame */
#define XVID_DEC_VOP		1		/* vop */
#define XVID_DEC_VOL		2		/* vol: width height change; recall decore */


/*****************************************************************************
* Decoder structures
****************************************************************************/

	typedef struct
	{
		int version;
		int global;			/* [in:opt] global flags */
		void *handle;		/* [out]	codec handle */
		struct {
			int _null_;
			/* extended fields */
	    } ext;
	}
	XVID_DEC_PARAM;


	typedef struct
	{
		int version;
		int general;		/* [in:opt]	general flags */
		void *bitstream;	/* [in]		input bitstream */
		int length;			/* [in,out]	length of input bitstream (bytes)
										number of bytes consumed*/

		void *image;		/* [in]		output image */
		int stride;			/* [in]		output image stride */
		int colorspace;		/* [in]		output colorspace */

		int notify;			/* [out]	output 'mode' */
		union
		{
			struct	/* XVID_DEC_VOP */
			{
				int time_increment;	/* [out]	time increment */
			} vop;
			struct	/* XVID_DEC_RESIZE */
			{
				int general;		/* [out]	flags: eg. frames are interlaced */
				int width;			/* [out]	width */
				int height;			/* [out]	height */
				int aspect_ratio;	/* [out]	aspect ratio */
				int par_width;		/* [out]	aspect ratio width */
				int par_height		/* [out]	aspect ratio height */
				int time_base;		/* [out]	time base */
				int time_increment;	/* [out]	fixed time increment; 0=varible increment 
*/
			} vol;
		} data;

		struct {
			int _null_;
			/* extended fields */
	    } ext;
	}
	XVID_DEC_FRAME;


/*****************************************************************************
* Decoder entry point
****************************************************************************/

/* decoder options */
#define XVID_DEC_DECODE		0
#define XVID_DEC_CREATE		1
#define XVID_DEC_DESTROY	2

	int xvid_decore(void *handle,
					int opt,
					void *param1,
					void *param2);


/*****************************************************************************
* Encoder constants
****************************************************************************/

/* Flags for XVID_ENC_PARAM.global */
#define XVID_BFRAMES		0x00000001	/* enable bframes encoding*/
#define XVID_PACKED			0x00000002	/* packed bitstream */
#define XVID_DX50BVOP		0x00000004	/* dx50 bvop compatibility */
#define XVID_DEBUG			0x80000000	/* generic debug flag: print debug info on 
each frame */

/* Flags for XVID_ENC_RC.mode */
#define XVID_NONE				0
#define XVID_FIXEDQUANT			1
#define XVID_CBR				2
#define XVID_VBR2PASS1			3
#define XVID_VRB2PASS2			4

/* Flags for XVID_ENC_FRAME.general */
#define XVID_VALID_FLAGS		0x80000000

#define XVID_CUSTOM_QMATRIX		0x00000004	/* use custom quant matrix */
#define XVID_H263QUANT			0x00000010
#define XVID_MPEGQUANT			0x00000020
#define XVID_HALFPEL			0x00000040	/* use halfpel interpolation */
#define XVID_ADAPTIVEQUANT		0x00000080
#define XVID_LUMIMASKING		0x00000100
#define XVID_132INTER			0x00000200	/* 132-consective inter frame rule */

#define XVID_INTERLACING		0x00000400	/* enable interlaced encoding */
#define XVID_TOPFIELDFIRST		0x00000800	/* set top-field-first flag  */
#define XVID_ALTERNATESCAN		0x00001000	/* set alternate vertical scan flag 
*/

#define XVID_INTER4V			0x00008000

#define XVID_ME_ZERO			0x00010000
#define XVID_ME_LOGARITHMIC		0x00020000
#define XVID_ME_FULLSEARCH		0x00040000
#define XVID_ME_PMVFAST			0x00080000
#define XVID_ME_EPZS			0x00100000


#define XVID_GREYSCALE			0x01000000	/* enable greyscale only mode (even for 
*/
#define XVID_GRAYSCALE			0x01000000  /* color input material chroma is 
ignored) */


/* Flags for XVID_ENC_FRAME.motion */
#define PMV_ADVANCEDDIAMOND8	0x00004000
#define PMV_ADVANCEDDIAMOND16   0x00008000

#define PMV_HALFPELDIAMOND16 	0x00010000
#define PMV_HALFPELREFINE16 	0x00020000
#define PMV_EXTSEARCH16 		0x00040000	/* extend PMV by more searches */
#define PMV_EARLYSTOP16	   		0x00080000
#define PMV_QUICKSTOP16	   		0x00100000	/* like early, but without any more 
refinement */
#define PMV_UNRESTRICTED16   	0x00200000	/* unrestricted ME, not implemented 
*/
#define PMV_OVERLAPPING16   	0x00400000	/* overlapping ME, not implemented 
*/
#define PMV_USESQUARES16		0x00800000

#define PMV_HALFPELDIAMOND8 	0x01000000
#define PMV_HALFPELREFINE8 		0x02000000
#define PMV_EXTSEARCH8 			0x04000000	/* extend PMV by more searches */
#define PMV_EARLYSTOP8	   		0x08000000
#define PMV_QUICKSTOP8	   		0x10000000	/* like early, but without any more 
refinement */
#define PMV_UNRESTRICTED8   	0x20000000	/* unrestricted ME, not implemented 
*/
#define PMV_OVERLAPPING8   		0x40000000	/* overlapping ME, not implemented 
*/
#define PMV_USESQUARES8			0x80000000


/*****************************************************************************
* Encoder structures
****************************************************************************/

	typedef struct
	{
		int version;
		int global;				/* [in:opt]		global flags */
		int num_threads;		/* [in:opt]		number of threads */

		int width;				/* [in]			width */
		int	height;				/* [in]			height */

		int max_key_interval;	/* [in:opt]		the maximum interval between key frames 
*/
		int max_bframes;		/* [in]			max sequential bframes */

		int bquant_ratio_a;		/* [in]			bframes quantizer multiplier a */
		int bquant_ratio_b;		/* [in]			bframes quantizer multiplier b */
								/* used only when bquant < 1
								 * bquant = AVG(past_quant + future_quant) * bquant_ratio_a + 
bquant_ratio_b */

		int min_iquant;			/* [in:opt]		lower iframe quantizer */
		int max_iquant;			/* [in:opt]		upper iframe quantizer */
		int min_pquant;			/* [in:opt]		lower pframe quantizer */
		int max_pquant;			/* [in:opt]		upper pframe quantizer */
		int min_bquant;			/* [in:opt]		lower bframe quantizer */
		int max_bquant;			/* [in:opt]		upper bframe quantizer */

		void *handle;			/* [out]		encoder instance handle */

	    struct {
			int _null_;
			/* extended fields */
	    } ext;

	}
	XVID_ENC_PARAM;


	typedef struct
	{
		int version;
		int mode;				/* [in]		rate control mode */

		union
		{
			struct				/* XVID_FIXEDQUANT */
			{
				float quant;
			} fixed_quant;

			struct				/* XVID_CBR */
			{
				int bitrate;		/* [in] the bitrate of the target encoded stream, in 
bits/second */
				int reaction_delay_factor;	/* [in] how fast the rate control reacts - 
lower values are faster */
				int averaging_period;	/* [in] as above */
				int buffer;			/* [in]			 as above */
			} cbr;

			struct				/* XVID_VBR2PASS1 */
			{
				char * stat_file;	/* [in]			output stats file */
				char * hint_file;	/* [in:opt]		ouput motion vector hint file */
			} vbr2pass_1;

			struct				/* XVID_VBR2PASS2 */
			{
				char * stat_file;	/* [in]			input stat file */
				char * hint_file;	/* [in:opt]		input motion vector hint file */
				long desired_size;	/* [in]			desired file size: bytes */
			} vbr2pass_2;
		} data;
	}
	XVID_ENC_RC;

	typedef struct
	{
		int version;
		int general;			/* [in:opt]		general options */
		int motion;				/* [in:opt]		ME options */

		void *image;			/* [in]			input image ptr */
		int stride;				/* [in]			input image stride */
		int colorspace;			/* [in]			input source colorspace */

		void *bitstream;		/* [in]			output bitstream ptr */
		int length;				/* [out]		output bitstream length (bytes) */
		int keyframe;			/* [in:out]		is this bitstream a keyframe  */

		int time_increment;		/* [in]			frame increment */
		int	time_base;			/* [in]			frame base.  */
								/*				each frame = "fincr/fbase" seconds */

		int quant;				/* [in]			frame quantizer; when zero use prescribed rate 
control*/

		unsigned char *quant_intra_matrix;	/* [in:opt] custom intra qmatrix */
		unsigned char *quant_inter_matrix;	/* [in:opt] custom inter qmatrix */

		int frame_drop_ratio;   /* [in:opt]		frame dropping level: 
0=none...100=all */

		struct {
			int _null_;
			/* extended fields */
	    } ext;
	}
	XVID_ENC_FRAME;

	/* XXX: stats are made redundant by internal ratecontrol/2pass
	   they could be still useful for debug ?
	*/
	typedef struct
	{
		int version;
		int coding_type;			/* [out]	frame vop coding type */
		int quant;					/* [out]	frame quantizer */
		int quant_type;				/* [out]	quant type */
		int length;					/* [out]	frame length (bytes) */
		int header_bits;			/* [out]	header bits */
		int texture_bits;			/* [out]	texture bits */
		int kblks, mblks, ublks;	/* [out]	key,motion,uncoded macroblocks*/
		float mv_rms;				/* [out]	motion vector rms */

		struct {
			int _null_;
			/* extended fields */
	    } ext;

	}
	XVID_ENC_STATS;


/*****************************************************************************
* Encoder entry point
****************************************************************************/

/* Encoder options */
#define XVID_ENC_ENCODE		0
#define XVID_ENC_CREATE		1
#define XVID_ENC_DESTROY	2

	int xvid_encore(void *handle,
					int opt,
					void *param1,
					void *param2);


#ifdef __cplusplus
}
#endif

#endif


------=_NextPart_000_26c9_492f_50b3--