M4ENCODER_common.h revision 8806b706693c0992724f6603353af18aeb4a0f80
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16/**
17 ******************************************************************************
18 * @file    M4ENCODER_common.h
19 * @note    This file defines the types internally used by the VES to abstract encoders
20
21 ******************************************************************************
22*/
23#ifndef __M4ENCODER_COMMON_H__
24#define __M4ENCODER_COMMON_H__
25
26#ifdef __cplusplus
27extern "C" {
28#endif /* __cplusplus */
29
30
31/**
32 * Video preprocessing common interface */
33#include "M4VPP_API.h"
34
35/**
36 * Writer common interface */
37#include "M4WRITER_common.h"
38
39/* IMAGE STAB */
40/* percentage of image suppressed (computed from the standard dimension).*/
41#define M4ENCODER_STAB_FILTER_CROP_PERCENTAGE 10
42        /* WARNING: take the inferior even dimension, ex: 10% for QCIF output => 192x158 */
43
44/**
45 ******************************************************************************
46 * enum        M4ENCODER_OpenMode
47 * @brief    Definition of open mode for the encoder.
48 * @note    DEFAULT  : pointer to M4ENCODER_open() which use default parameters
49 *          ADVANCED : pointer to M4ENCODER_open_advanced() which allow to customize
50 *                     various encoding parameters
51 ******************************************************************************
52*/
53typedef enum
54{
55    M4ENCODER_OPEN_DEFAULT,
56    M4ENCODER_OPEN_ADVANCED
57} M4ENCODER_OpenMode;
58
59 /**
60 ******************************************************************************
61 * enum        M4ENCODER_FrameRate
62 * @brief    Thie enum defines the encoded video framerates.
63 ******************************************************************************
64*/
65typedef enum
66{
67    M4ENCODER_k5_FPS,
68    M4ENCODER_k7_5_FPS,
69    M4ENCODER_k10_FPS,
70    M4ENCODER_k12_5_FPS,
71    M4ENCODER_k15_FPS,
72    M4ENCODER_k20_FPS,
73    M4ENCODER_k25_FPS,
74    M4ENCODER_k30_FPS,
75    M4ENCODER_kVARIABLE_FPS,            /**< Variable video bitrate */
76    M4ENCODER_kUSE_TIMESCALE            /**< Advanced encoding, use timescale indication rather
77                                                than framerate */
78} M4ENCODER_FrameRate;
79
80/**
81 ******************************************************************************
82 * enum        M4ENCODER_InputFormat
83 * @brief    Thie enum defines the video format of the grabbing.
84 ******************************************************************************
85*/
86typedef enum
87{
88    M4ENCODER_kIYUV420=0, /**< YUV 4:2:0 planar (standard input for mpeg-4 video) */
89    M4ENCODER_kIYUV422,   /**< YUV422 planar */
90    M4ENCODER_kIYUYV,     /**< YUV422 interlaced, luma first */
91    M4ENCODER_kIUYVY,     /**< YUV422 interlaced, chroma first */
92    M4ENCODER_kIJPEG,     /**< JPEG compressed frames */
93    M4ENCODER_kIRGB444,   /**< RGB 12 bits 4:4:4 */
94    M4ENCODER_kIRGB555,   /**< RGB 15 bits 5:5:5 */
95    M4ENCODER_kIRGB565,   /**< RGB 16 bits 5:6:5 */
96    M4ENCODER_kIRGB24,    /**< RGB 24 bits 8:8:8 */
97    M4ENCODER_kIRGB32,    /**< RGB 32 bits  */
98    M4ENCODER_kIBGR444,   /**< BGR 12 bits 4:4:4 */
99    M4ENCODER_kIBGR555,   /**< BGR 15 bits 5:5:5 */
100    M4ENCODER_kIBGR565,   /**< BGR 16 bits 5:6:5 */
101    M4ENCODER_kIBGR24,    /**< BGR 24 bits 8:8:8 */
102    M4ENCODER_kIBGR32     /**< BGR 32 bits  */
103} M4ENCODER_InputFormat;
104
105/**
106 ******************************************************************************
107 * enum        M4ENCODER_Format
108 * @brief    Thie enum defines the video compression formats.
109 ******************************************************************************
110*/
111typedef enum
112{
113    M4ENCODER_kMPEG4 = 0,
114    M4ENCODER_kH263,
115    M4ENCODER_kH264,
116    M4ENCODER_kJPEG,
117    M4ENCODER_kMJPEG,
118    M4ENCODER_kNULL,
119    M4ENCODER_kYUV420,            /**< No compression */
120    M4ENCODER_kYUV422,            /**< No compression */
121
122    M4ENCODER_kVideo_NB /* number of decoders, keep it as last enum entry */
123} M4ENCODER_Format;
124
125/**
126 ******************************************************************************
127 * enum        M4ENCODER_FrameWidth
128 * @brief    Thie enum defines the avalaible frame Width.
129 ******************************************************************************
130*/
131typedef enum
132{
133    M4ENCODER_SQCIF_Width = 128, /**< SQCIF 128x96 */
134    M4ENCODER_QQVGA_Width = 160, /**< QQVGA 160x120 */
135    M4ENCODER_QCIF_Width  = 176, /**< QCIF 176x144 */
136    M4ENCODER_QVGA_Width  = 320, /**< QVGA 320x240 */
137    M4ENCODER_CIF_Width   = 352, /**< CIF 352x288 */
138    M4ENCODER_VGA_Width   = 640, /**< VGA 640x480 */
139    M4ENCODER_SVGA_Width  = 800, /**< SVGA 800x600 */
140    M4ENCODER_XGA_Width   = 1024, /**< XGA 1024x768 */
141    M4ENCODER_XVGA_Width  = 1280, /**< XVGA 1280x1024 */
142/* +PR LV5807 */
143    M4ENCODER_WVGA_Width  = 800, /**< WVGA 800 x 480 */
144    M4ENCODER_NTSC_Width  = 720, /**< NTSC 720 x 480 */
145/* -PR LV5807 */
146
147/* +CR Google */
148    M4ENCODER_640_360_Width   = 640,  /**< 640x360 */
149    // StageFright encoders require %16 resolution
150    M4ENCODER_854_480_Width   = 848,  /**< 848x480 */
151    M4ENCODER_1280_720_Width  = 1280, /**< 720p 1280x720 */
152    // StageFright encoders require %16 resolution
153    M4ENCODER_1080_720_Width  = 1088, /**< 720p 1088x720 */
154    M4ENCODER_960_720_Width   = 960,  /**< 720p 960x720 */
155    M4ENCODER_1920_1080_Width = 1920  /**< 1080p 1920x1080 */
156/* -CR Google */
157
158} M4ENCODER_FrameWidth;
159
160/**
161 ******************************************************************************
162 * enum        M4ENCODER_FrameHeight
163 * @brief    Thie enum defines the avalaible frame Height.
164 ******************************************************************************
165*/
166typedef enum
167{
168    M4ENCODER_SQCIF_Height = 96,  /**< SQCIF 128x96 */
169    M4ENCODER_QQVGA_Height = 120, /**< QQVGA 160x120 */
170    M4ENCODER_QCIF_Height  = 144, /**< QCIF 176x144 */
171    M4ENCODER_QVGA_Height  = 240, /**< QVGA 320x240 */
172    M4ENCODER_CIF_Height   = 288, /**< CIF 352x288 */
173    M4ENCODER_VGA_Height   = 480, /**< VGA 340x480 */
174    M4ENCODER_SVGA_Height  = 600, /**< SVGA 800x600 */
175    M4ENCODER_XGA_Height   = 768, /**< XGA 1024x768 */
176    M4ENCODER_XVGA_Height  = 1024, /**< XVGA 1280x1024 */
177/* +PR LV5807 */
178    M4ENCODER_WVGA_Height  = 480, /**< WVGA 800 x 480 */
179    M4ENCODER_NTSC_Height  = 480, /**< NTSC 720 x 480 */
180/* -PR LV5807 */
181
182/* +CR Google */
183    M4ENCODER_640_360_Height  = 360, /**< 640x360 */
184    M4ENCODER_854_480_Height  = 480, /**< 854x480 */
185    M4ENCODER_1280_720_Height = 720, /**< 720p 1280x720 */
186    M4ENCODER_1080_720_Height = 720, /**< 720p 1080x720 */
187    M4ENCODER_960_720_Height  = 720, /**< 720p 960x720 */
188    // StageFright encoders require %16 resolution
189    M4ENCODER_1920_1080_Height = 1088 /**< 1080p 1920x1080 */
190/* -CR Google */
191} M4ENCODER_FrameHeight;
192
193/**
194 ******************************************************************************
195 * enum        M4ENCODER_Bitrate
196 * @brief    Thie enum defines the avalaible bitrates.
197 ******************************************************************************
198*/
199typedef enum
200{
201    M4ENCODER_k28_KBPS  = 28000,
202    M4ENCODER_k40_KBPS  = 40000,
203    M4ENCODER_k64_KBPS  = 64000,
204    M4ENCODER_k96_KBPS  = 96000,
205    M4ENCODER_k128_KBPS = 128000,
206    M4ENCODER_k192_KBPS = 192000,
207    M4ENCODER_k256_KBPS = 256000,
208    M4ENCODER_k384_KBPS = 384000,
209    M4ENCODER_k512_KBPS = 512000,
210    M4ENCODER_k800_KBPS = 800000
211
212} M4ENCODER_Bitrate;
213
214/* IMAGE STAB */
215
216/**
217 ******************************************************************************
218 * enum            M4ENCODER_StabMode
219 * @brief        The current mode of the stabilization filter.
220 ******************************************************************************
221*/
222typedef enum
223{
224    M4ENCODER_kStabOff = 0,        /**< stabilization filter is disabled */
225    M4ENCODER_kStabCentered,    /**< stabilization filter is enabled. */
226                                /**< Video input and output must have the same dimensions. Output
227                                    image will have black borders */
228    M4ENCODER_kStabGrabMore        /**< stabilization filter is enabled. */
229                                /**< Video input dimensions must be bigger than output. The ratio
230                                        is indicated by M4ENCODER_STAB_FILTER_CROP_PERCENTAGE */
231
232} M4ENCODER_StabMode;
233
234/**
235 ******************************************************************************
236 * enum            M4ENCODER_FrameMode
237 * @brief        Values to drive the encoder behaviour (type of frames produced)
238 ******************************************************************************
239*/
240typedef enum
241{
242    M4ENCODER_kNormalFrame = 0,   /**< let the encoder decide which type of frame to encode */
243    M4ENCODER_kLastFrame   = 1,   /**< force encoder the flush all its buffers because it is
244                                         last frame  */
245    M4ENCODER_kIFrame      = 2    /**< force encoder to generate an I frame */
246
247} M4ENCODER_FrameMode;
248
249/**
250 ******************************************************************************
251 * struct    M4ENCODER_Params
252 * @brief    This structure defines all the settings avalaible when encoding.
253 ******************************************************************************
254*/
255typedef struct
256{
257    /* Input */
258    M4ENCODER_InputFormat    InputFormat;        /**< Input video format (grabbing) */
259    M4ENCODER_FrameWidth    InputFrameWidth;    /**< Input Frame width (grabbing) */
260    M4ENCODER_FrameHeight    InputFrameHeight;    /**< Input Frame height (grabbing) */
261
262    /* Output */
263    M4ENCODER_FrameWidth    FrameWidth;            /**< Frame width  */
264    M4ENCODER_FrameHeight    FrameHeight;        /**< Frame height  */
265    M4ENCODER_Bitrate        Bitrate;            /**< Bitrate, see enum  */
266    M4ENCODER_FrameRate        FrameRate;            /**< Framerate, see enum  */
267    M4ENCODER_Format        Format;                /**< Video compression format, H263, MPEG4,
268                                                         MJPEG ...  */
269
270} M4ENCODER_Params;
271
272/**
273 ******************************************************************************
274 * struct    M4ENCODER_AdvancedParams
275 * @brief    This structure defines the advanced settings available for MPEG-4 encoding.
276 ******************************************************************************
277*/
278typedef struct
279{
280    /**
281     * Input parameters (grabber coupled with encoder): */
282    M4ENCODER_InputFormat    InputFormat;                /**< Input video format */
283    M4ENCODER_FrameWidth    InputFrameWidth;            /**< Input Frame width */
284    M4ENCODER_FrameHeight    InputFrameHeight;            /**< Input Frame height */
285
286    /**
287     * Common settings for H263 and MPEG-4: */
288    M4ENCODER_FrameWidth    FrameWidth;                    /**< Frame width  */
289    M4ENCODER_FrameHeight    FrameHeight;                /**< Frame height  */
290    M4OSA_UInt32            Bitrate;                    /**< Free value for the bitrate */
291    /**< Framerate (if set to M4ENCODER_kUSE_TIMESCALE use uiRateFactor & uiTimeScale instead) */
292    M4ENCODER_FrameRate        FrameRate;
293    /**< Video compression format: H263 or MPEG4 */
294    M4ENCODER_Format        Format;
295    M4OSA_UInt32            uiHorizontalSearchRange; /**< Set to 0 will use default value (15) */
296    M4OSA_UInt32            uiVerticalSearchRange;   /**< Set to 0 will use default value (15) */
297    /**< Set to 0 will use default value (0x7FFF i.e. let engine decide when to put an I) */
298    M4OSA_UInt32            uiStartingQuantizerValue;
299    /**< Enable if priority is quality, Disable if priority is framerate */
300    M4OSA_Bool                bInternalRegulation;
301    /**< Ratio between the encoder frame rate and the actual frame rate */
302    M4OSA_UInt8                uiRateFactor;
303    /**< I frames periodicity, set to 0 will use default value */
304    M4OSA_UInt32            uiIVopPeriod;
305    /**< Motion estimation [default=0 (all tools), disable=8 (no tool)] */
306    M4OSA_UInt8             uiMotionEstimationTools;
307
308    /**
309     * Settings for MPEG-4 only: */
310    M4OSA_UInt32            uiTimeScale;                /**< Free value for the timescale */
311    M4OSA_Bool                bErrorResilience;           /**< Disabled by default */
312    /**< Disabled by default (if enabled, bErrorResilience should be enabled too!) */
313    M4OSA_Bool                bDataPartitioning;
314    M4OSA_Bool              bAcPrediction;           /**< AC prediction [default=1, disable=0] */
315
316} M4ENCODER_AdvancedParams;
317
318/**
319 ******************************************************************************
320 * struct    M4ENCODER_StillPictureParams
321 * @brief    This structure defines all the settings avalaible when encoding still
322 *            picture.
323 ******************************************************************************
324*/
325typedef struct
326{
327    M4ENCODER_FrameWidth    FrameWidth;            /**< Frame width  */
328    M4ENCODER_FrameHeight    FrameHeight;        /**< Frame height  */
329    M4OSA_UInt32            Quality;            /**< Bitrate, see enum  */
330    M4ENCODER_Format        InputFormat;        /**< YUV 420 or 422  */
331    M4ENCODER_Format        Format;                /**< Video compression format, H263, MPEG4,
332                                                         MJPEG ...  */
333    M4OSA_Bool                PreProcessNeeded;    /**< Is the call to the VPP is necessary */
334    M4OSA_Bool                EncodingPerStripes;    /**< Is encoding per stripes */
335
336} M4ENCODER_StillPictureParams;
337
338/**
339 ******************************************************************************
340 * struct    M4ENCODER_Header
341 * @brief    This structure defines the buffer where the sequence header is put.
342 ******************************************************************************
343*/
344typedef struct
345{
346    M4OSA_MemAddr8    pBuf;        /**< Buffer for the header */
347    M4OSA_UInt32    Size;        /**< Size of the data */
348
349} M4ENCODER_Header;
350
351/**
352 ******************************************************************************
353 * enum    M4ENCODER_OptionID
354 * @brief This enums defines all avalaible options.
355 ******************************************************************************
356*/
357typedef enum
358{
359    /**< set the fragment size, option value is M4OSA_UInt32 type */
360    M4ENCODER_kOptionID_VideoFragmentSize    = M4OSA_OPTION_ID_CREATE (M4_WRITE,\
361                                                     M4ENCODER_COMMON, 0x01),
362
363    /**< set the stabilization filtering, option value is M4ENCODER_StabMode type */
364    M4ENCODER_kOptionID_ImageStabilization    = M4OSA_OPTION_ID_CREATE (M4_WRITE,\
365                                                          M4ENCODER_COMMON, 0x02),
366
367    /**< prevent writting of any AU, option value is M4OSA_Bool type */
368    M4ENCODER_kOptionID_InstantStop            = M4OSA_OPTION_ID_CREATE (M4_WRITE,\
369                                                         M4ENCODER_COMMON, 0x03),
370
371    /**< get the DSI (encoder header) generated by the encoder */
372    M4ENCODER_kOptionID_EncoderHeader        = M4OSA_OPTION_ID_CREATE (M4_READ ,\
373                                                             M4ENCODER_COMMON, 0x04),
374/*+ CR LV6775 -H.264 Trimming  */
375
376    M4ENCODER_kOptionID_SetH264ProcessNALUfctsPtr= M4OSA_OPTION_ID_CREATE (M4_READ ,\
377                                                             M4ENCODER_COMMON, 0x05),
378    M4ENCODER_kOptionID_H264ProcessNALUContext        = M4OSA_OPTION_ID_CREATE (M4_READ ,\
379                                                             M4ENCODER_COMMON, 0x06)
380/*-CR LV6775 -H.264 Trimming  */
381} M4ENCODER_OptionID;
382
383/*+ CR LV6775 -H.264 Trimming  */
384typedef M4OSA_ERR (H264MCS_ProcessEncodedNALU_fct)(M4OSA_Void*ainstance,M4OSA_UInt8* inbuff,
385                               M4OSA_Int32  inbuf_size,
386                               M4OSA_UInt8 *outbuff, M4OSA_Int32 *outbuf_size);
387//*- CR LV6775 -H.264 Trimming  */
388
389typedef M4OSA_Void* M4ENCODER_Context;
390
391typedef M4OSA_ERR (M4ENCODER_init) (
392        M4ENCODER_Context* pContext,
393        M4WRITER_DataInterface* pWriterDataInterface,
394        M4VPP_apply_fct* pVPPfct,
395        M4VPP_Context pVPPctxt,
396        M4OSA_Void* pExternalAPI,
397        M4OSA_Void* pUserData
398);
399
400typedef M4OSA_ERR (M4ENCODER_open) (
401        M4ENCODER_Context pContext,
402        M4SYS_AccessUnit* pAU,
403        M4OSA_Void* pParams     /* Can be M4ENCODER_Params, M4ENCODER_AdvancedParams or
404                                    M4ENCODER_StillPictureParams */
405);
406
407typedef M4OSA_ERR (M4ENCODER_start) (M4ENCODER_Context pContext);
408typedef M4OSA_ERR (M4ENCODER_stop) (M4ENCODER_Context pContext);
409typedef M4OSA_ERR (M4ENCODER_pause) (M4ENCODER_Context pContext);
410typedef M4OSA_ERR (M4ENCODER_resume) (M4ENCODER_Context pContext);
411typedef M4OSA_ERR (M4ENCODER_close) (M4ENCODER_Context pContext);
412typedef M4OSA_ERR (M4ENCODER_cleanup) (M4ENCODER_Context pContext);
413typedef M4OSA_ERR (M4ENCODER_regulBitRate) (M4ENCODER_Context pContext);
414
415typedef M4OSA_ERR (M4ENCODER_encode) (
416        M4ENCODER_Context pContext,
417        M4VIFI_ImagePlane* pInPlane,
418        M4OSA_Double Cts,
419        M4ENCODER_FrameMode FrameMode
420);
421
422typedef M4OSA_ERR (M4ENCODER_setOption)    (
423        M4ENCODER_Context pContext,
424        M4OSA_UInt32 optionID,
425        M4OSA_DataOption optionValue
426);
427
428typedef M4OSA_ERR (M4ENCODER_getOption)    (
429        M4ENCODER_Context pContext,
430        M4OSA_UInt32 optionID,
431        M4OSA_DataOption optionValue
432);
433
434/**
435 ******************************************************************************
436 * struct    M4ENCODER_GlobalInterface
437 * @brief    Defines all the functions required for an encoder shell.
438 ******************************************************************************
439*/
440
441typedef struct _M4ENCODER_GlobalInterface
442{
443    M4ENCODER_init*                pFctInit;
444    M4ENCODER_open*                pFctOpen;
445
446    M4ENCODER_start*            pFctStart;          /* Grabber mode */
447    M4ENCODER_stop*                pFctStop;           /* Grabber mode */
448
449    M4ENCODER_pause*            pFctPause;          /* Grabber mode */
450    M4ENCODER_resume*            pFctResume;         /* Grabber mode */
451
452    M4ENCODER_close*            pFctClose;
453    M4ENCODER_cleanup*            pFctCleanup;
454
455    M4ENCODER_regulBitRate*     pFctRegulBitRate;
456    M4ENCODER_encode*            pFctEncode;         /* Standalone mode */
457
458    M4ENCODER_setOption*        pFctSetOption;
459    M4ENCODER_getOption*        pFctGetOption;
460} M4ENCODER_GlobalInterface;
461
462
463#ifdef __cplusplus
464}
465#endif /* __cplusplus */
466
467#endif /*__M4ENCODER_COMMON_H__*/
468
469