Home | History | Annotate | Download | only in inc
      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
     27 extern "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 */
     53 typedef 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 */
     65 typedef 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 */
     86 typedef 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 */
    111 typedef 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 */
    131 typedef 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 */
    166 typedef 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 */
    199 typedef 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 */
    222 typedef 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 */
    240 typedef 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 */
    255 typedef 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     M4OSA_Int32            videoProfile; /** video profile */
    270     M4OSA_Int32            videoLevel;   /** video level */
    271 } M4ENCODER_Params;
    272 
    273 /**
    274  ******************************************************************************
    275  * struct    M4ENCODER_AdvancedParams
    276  * @brief    This structure defines the advanced settings available for MPEG-4 encoding.
    277  ******************************************************************************
    278 */
    279 typedef struct
    280 {
    281     /**
    282      * Input parameters (grabber coupled with encoder): */
    283     M4ENCODER_InputFormat    InputFormat;                /**< Input video format */
    284     M4ENCODER_FrameWidth    InputFrameWidth;            /**< Input Frame width */
    285     M4ENCODER_FrameHeight    InputFrameHeight;            /**< Input Frame height */
    286 
    287     /**
    288      * Common settings for H263 and MPEG-4: */
    289     M4ENCODER_FrameWidth    FrameWidth;                    /**< Frame width  */
    290     M4ENCODER_FrameHeight    FrameHeight;                /**< Frame height  */
    291     M4OSA_UInt32            Bitrate;                    /**< Free value for the bitrate */
    292     /**< Framerate (if set to M4ENCODER_kUSE_TIMESCALE use uiRateFactor & uiTimeScale instead) */
    293     M4ENCODER_FrameRate        FrameRate;
    294     /**< Video compression format: H263 or MPEG4 */
    295     M4ENCODER_Format        Format;
    296     M4OSA_Int32            videoProfile; /** output video profile */
    297     M4OSA_Int32            videoLevel;   /** output video level */
    298     M4OSA_UInt32            uiHorizontalSearchRange; /**< Set to 0 will use default value (15) */
    299     M4OSA_UInt32            uiVerticalSearchRange;   /**< Set to 0 will use default value (15) */
    300     /**< Set to 0 will use default value (0x7FFF i.e. let engine decide when to put an I) */
    301     M4OSA_UInt32            uiStartingQuantizerValue;
    302     /**< Enable if priority is quality, Disable if priority is framerate */
    303     M4OSA_Bool                bInternalRegulation;
    304     /**< Ratio between the encoder frame rate and the actual frame rate */
    305     M4OSA_UInt8                uiRateFactor;
    306     /**< I frames periodicity, set to 0 will use default value */
    307     M4OSA_UInt32            uiIVopPeriod;
    308     /**< Motion estimation [default=0 (all tools), disable=8 (no tool)] */
    309     M4OSA_UInt8             uiMotionEstimationTools;
    310 
    311     /**
    312      * Settings for MPEG-4 only: */
    313     M4OSA_UInt32            uiTimeScale;                /**< Free value for the timescale */
    314     M4OSA_Bool                bErrorResilience;           /**< Disabled by default */
    315     /**< Disabled by default (if enabled, bErrorResilience should be enabled too!) */
    316     M4OSA_Bool                bDataPartitioning;
    317     M4OSA_Bool              bAcPrediction;           /**< AC prediction [default=1, disable=0] */
    318 
    319 } M4ENCODER_AdvancedParams;
    320 
    321 /**
    322  ******************************************************************************
    323  * struct    M4ENCODER_StillPictureParams
    324  * @brief    This structure defines all the settings avalaible when encoding still
    325  *            picture.
    326  ******************************************************************************
    327 */
    328 typedef struct
    329 {
    330     M4ENCODER_FrameWidth    FrameWidth;            /**< Frame width  */
    331     M4ENCODER_FrameHeight    FrameHeight;        /**< Frame height  */
    332     M4OSA_UInt32            Quality;            /**< Bitrate, see enum  */
    333     M4ENCODER_Format        InputFormat;        /**< YUV 420 or 422  */
    334     M4ENCODER_Format        Format;                /**< Video compression format, H263, MPEG4,
    335                                                          MJPEG ...  */
    336     M4OSA_Bool                PreProcessNeeded;    /**< Is the call to the VPP is necessary */
    337     M4OSA_Bool                EncodingPerStripes;    /**< Is encoding per stripes */
    338 
    339 } M4ENCODER_StillPictureParams;
    340 
    341 /**
    342  ******************************************************************************
    343  * struct    M4ENCODER_Header
    344  * @brief    This structure defines the buffer where the sequence header is put.
    345  ******************************************************************************
    346 */
    347 typedef struct
    348 {
    349     M4OSA_MemAddr8    pBuf;        /**< Buffer for the header */
    350     M4OSA_UInt32    Size;        /**< Size of the data */
    351 
    352 } M4ENCODER_Header;
    353 
    354 /**
    355  ******************************************************************************
    356  * enum    M4ENCODER_OptionID
    357  * @brief This enums defines all avalaible options.
    358  ******************************************************************************
    359 */
    360 typedef enum
    361 {
    362     /**< set the fragment size, option value is M4OSA_UInt32 type */
    363     M4ENCODER_kOptionID_VideoFragmentSize    = M4OSA_OPTION_ID_CREATE (M4_WRITE,\
    364                                                      M4ENCODER_COMMON, 0x01),
    365 
    366     /**< set the stabilization filtering, option value is M4ENCODER_StabMode type */
    367     M4ENCODER_kOptionID_ImageStabilization    = M4OSA_OPTION_ID_CREATE (M4_WRITE,\
    368                                                           M4ENCODER_COMMON, 0x02),
    369 
    370     /**< prevent writting of any AU, option value is M4OSA_Bool type */
    371     M4ENCODER_kOptionID_InstantStop            = M4OSA_OPTION_ID_CREATE (M4_WRITE,\
    372                                                          M4ENCODER_COMMON, 0x03),
    373 
    374     /**< get the DSI (encoder header) generated by the encoder */
    375     M4ENCODER_kOptionID_EncoderHeader        = M4OSA_OPTION_ID_CREATE (M4_READ ,\
    376                                                              M4ENCODER_COMMON, 0x04),
    377 /*+ CR LV6775 -H.264 Trimming  */
    378 
    379     M4ENCODER_kOptionID_SetH264ProcessNALUfctsPtr= M4OSA_OPTION_ID_CREATE (M4_READ ,\
    380                                                              M4ENCODER_COMMON, 0x05),
    381     M4ENCODER_kOptionID_H264ProcessNALUContext        = M4OSA_OPTION_ID_CREATE (M4_READ ,\
    382                                                              M4ENCODER_COMMON, 0x06)
    383 /*-CR LV6775 -H.264 Trimming  */
    384 } M4ENCODER_OptionID;
    385 
    386 /*+ CR LV6775 -H.264 Trimming  */
    387 typedef M4OSA_ERR (H264MCS_ProcessEncodedNALU_fct)(M4OSA_Void*ainstance,M4OSA_UInt8* inbuff,
    388                                M4OSA_Int32  inbuf_size,
    389                                M4OSA_UInt8 *outbuff, M4OSA_Int32 *outbuf_size);
    390 //*- CR LV6775 -H.264 Trimming  */
    391 
    392 typedef M4OSA_Void* M4ENCODER_Context;
    393 
    394 typedef M4OSA_ERR (M4ENCODER_init) (
    395         M4ENCODER_Context* pContext,
    396         M4WRITER_DataInterface* pWriterDataInterface,
    397         M4VPP_apply_fct* pVPPfct,
    398         M4VPP_Context pVPPctxt,
    399         M4OSA_Void* pExternalAPI,
    400         M4OSA_Void* pUserData
    401 );
    402 
    403 typedef M4OSA_ERR (M4ENCODER_open) (
    404         M4ENCODER_Context pContext,
    405         M4SYS_AccessUnit* pAU,
    406         M4OSA_Void* pParams     /* Can be M4ENCODER_Params, M4ENCODER_AdvancedParams or
    407                                     M4ENCODER_StillPictureParams */
    408 );
    409 
    410 typedef M4OSA_ERR (M4ENCODER_start) (M4ENCODER_Context pContext);
    411 typedef M4OSA_ERR (M4ENCODER_stop) (M4ENCODER_Context pContext);
    412 typedef M4OSA_ERR (M4ENCODER_pause) (M4ENCODER_Context pContext);
    413 typedef M4OSA_ERR (M4ENCODER_resume) (M4ENCODER_Context pContext);
    414 typedef M4OSA_ERR (M4ENCODER_close) (M4ENCODER_Context pContext);
    415 typedef M4OSA_ERR (M4ENCODER_cleanup) (M4ENCODER_Context pContext);
    416 typedef M4OSA_ERR (M4ENCODER_regulBitRate) (M4ENCODER_Context pContext);
    417 
    418 typedef M4OSA_ERR (M4ENCODER_encode) (
    419         M4ENCODER_Context pContext,
    420         M4VIFI_ImagePlane* pInPlane,
    421         M4OSA_Double Cts,
    422         M4ENCODER_FrameMode FrameMode
    423 );
    424 
    425 typedef M4OSA_ERR (M4ENCODER_setOption)    (
    426         M4ENCODER_Context pContext,
    427         M4OSA_UInt32 optionID,
    428         M4OSA_DataOption optionValue
    429 );
    430 
    431 typedef M4OSA_ERR (M4ENCODER_getOption)    (
    432         M4ENCODER_Context pContext,
    433         M4OSA_UInt32 optionID,
    434         M4OSA_DataOption optionValue
    435 );
    436 
    437 /**
    438  ******************************************************************************
    439  * struct    M4ENCODER_GlobalInterface
    440  * @brief    Defines all the functions required for an encoder shell.
    441  ******************************************************************************
    442 */
    443 
    444 typedef struct _M4ENCODER_GlobalInterface
    445 {
    446     M4ENCODER_init*                pFctInit;
    447     M4ENCODER_open*                pFctOpen;
    448 
    449     M4ENCODER_start*            pFctStart;          /* Grabber mode */
    450     M4ENCODER_stop*                pFctStop;           /* Grabber mode */
    451 
    452     M4ENCODER_pause*            pFctPause;          /* Grabber mode */
    453     M4ENCODER_resume*            pFctResume;         /* Grabber mode */
    454 
    455     M4ENCODER_close*            pFctClose;
    456     M4ENCODER_cleanup*            pFctCleanup;
    457 
    458     M4ENCODER_regulBitRate*     pFctRegulBitRate;
    459     M4ENCODER_encode*            pFctEncode;         /* Standalone mode */
    460 
    461     M4ENCODER_setOption*        pFctSetOption;
    462     M4ENCODER_getOption*        pFctGetOption;
    463 } M4ENCODER_GlobalInterface;
    464 
    465 
    466 #ifdef __cplusplus
    467 }
    468 #endif /* __cplusplus */
    469 
    470 #endif /*__M4ENCODER_COMMON_H__*/
    471 
    472