129a84457aed4c45bc900998b5e11c03023264208James Dong/* ------------------------------------------------------------------
229a84457aed4c45bc900998b5e11c03023264208James Dong * Copyright (C) 1998-2009 PacketVideo
329a84457aed4c45bc900998b5e11c03023264208James Dong *
429a84457aed4c45bc900998b5e11c03023264208James Dong * Licensed under the Apache License, Version 2.0 (the "License");
529a84457aed4c45bc900998b5e11c03023264208James Dong * you may not use this file except in compliance with the License.
629a84457aed4c45bc900998b5e11c03023264208James Dong * You may obtain a copy of the License at
729a84457aed4c45bc900998b5e11c03023264208James Dong *
829a84457aed4c45bc900998b5e11c03023264208James Dong *      http://www.apache.org/licenses/LICENSE-2.0
929a84457aed4c45bc900998b5e11c03023264208James Dong *
1029a84457aed4c45bc900998b5e11c03023264208James Dong * Unless required by applicable law or agreed to in writing, software
1129a84457aed4c45bc900998b5e11c03023264208James Dong * distributed under the License is distributed on an "AS IS" BASIS,
1229a84457aed4c45bc900998b5e11c03023264208James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
1329a84457aed4c45bc900998b5e11c03023264208James Dong * express or implied.
1429a84457aed4c45bc900998b5e11c03023264208James Dong * See the License for the specific language governing permissions
1529a84457aed4c45bc900998b5e11c03023264208James Dong * and limitations under the License.
1629a84457aed4c45bc900998b5e11c03023264208James Dong * -------------------------------------------------------------------
1729a84457aed4c45bc900998b5e11c03023264208James Dong */
1829a84457aed4c45bc900998b5e11c03023264208James Dong/**
1929a84457aed4c45bc900998b5e11c03023264208James DongThis file contains application function interfaces to the AVC encoder library
2029a84457aed4c45bc900998b5e11c03023264208James Dongand necessary type defitionitions and enumerations.
2129a84457aed4c45bc900998b5e11c03023264208James Dong@publishedAll
2229a84457aed4c45bc900998b5e11c03023264208James Dong*/
2329a84457aed4c45bc900998b5e11c03023264208James Dong
2429a84457aed4c45bc900998b5e11c03023264208James Dong#ifndef AVCENC_API_H_INCLUDED
2529a84457aed4c45bc900998b5e11c03023264208James Dong#define AVCENC_API_H_INCLUDED
2629a84457aed4c45bc900998b5e11c03023264208James Dong
2729a84457aed4c45bc900998b5e11c03023264208James Dong#ifndef AVCAPI_COMMON_H_INCLUDED
2829a84457aed4c45bc900998b5e11c03023264208James Dong#include "avcapi_common.h"
2929a84457aed4c45bc900998b5e11c03023264208James Dong#endif
3029a84457aed4c45bc900998b5e11c03023264208James Dong
31d54329e48d2ee6bc6b24d148770eec562e10e739James Dong// For memset, etc
32d54329e48d2ee6bc6b24d148770eec562e10e739James Dong#include <string.h>
33d54329e48d2ee6bc6b24d148770eec562e10e739James Dong
3429a84457aed4c45bc900998b5e11c03023264208James Dong/**
3529a84457aed4c45bc900998b5e11c03023264208James Dong This enumeration is used for the status returned from the library interface.
3629a84457aed4c45bc900998b5e11c03023264208James Dong*/
3729a84457aed4c45bc900998b5e11c03023264208James Dongtypedef enum
3829a84457aed4c45bc900998b5e11c03023264208James Dong{
3929a84457aed4c45bc900998b5e11c03023264208James Dong    /**
4029a84457aed4c45bc900998b5e11c03023264208James Dong    Fail information, need to add more error code for more specific info
4129a84457aed4c45bc900998b5e11c03023264208James Dong    */
4229a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_TRAILINGONES_FAIL = -35,
4329a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_SLICE_EMPTY = -34,
4429a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_POC_FAIL = -33,
4529a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_CONSECUTIVE_NONREF = -32,
4629a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_CABAC_FAIL = -31,
4729a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_PRED_WEIGHT_TAB_FAIL = -30,
4829a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_DEC_REF_PIC_MARK_FAIL = -29,
4929a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_SPS_FAIL = -28,
5029a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_BITSTREAM_BUFFER_FULL    = -27,
5129a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_BITSTREAM_INIT_FAIL = -26,
5229a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_CHROMA_QP_FAIL = -25,
5329a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_INIT_QS_FAIL = -24,
5429a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_INIT_QP_FAIL = -23,
5529a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_WEIGHTED_BIPRED_FAIL = -22,
5629a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_INVALID_INTRA_PERIOD = -21,
5729a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_INVALID_CHANGE_RATE = -20,
5829a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_INVALID_BETA_OFFSET = -19,
5929a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_INVALID_ALPHA_OFFSET = -18,
6029a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_INVALID_DEBLOCK_IDC = -17,
6129a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_INVALID_REDUNDANT_PIC = -16,
6229a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_INVALID_FRAMERATE = -15,
6329a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_INVALID_NUM_SLICEGROUP = -14,
6429a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_INVALID_POC_LSB = -13,
6529a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_INVALID_NUM_REF = -12,
6629a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_INVALID_FMO_TYPE = -11,
6729a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_ENCPARAM_MEM_FAIL = -10,
6829a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_LEVEL_NOT_SUPPORTED = -9,
6929a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_LEVEL_FAIL = -8,
7029a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_PROFILE_NOT_SUPPORTED = -7,
7129a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_TOOLS_NOT_SUPPORTED = -6,
7229a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_WRONG_STATE = -5,
7329a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_UNINITIALIZED = -4,
7429a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_ALREADY_INITIALIZED = -3,
7529a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_NOT_SUPPORTED = -2,
7629a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_MEMORY_FAIL = AVC_MEMORY_FAIL,
7729a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_FAIL = AVC_FAIL,
7829a84457aed4c45bc900998b5e11c03023264208James Dong    /**
7929a84457aed4c45bc900998b5e11c03023264208James Dong    Generic success value
8029a84457aed4c45bc900998b5e11c03023264208James Dong    */
8129a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_SUCCESS = AVC_SUCCESS,
8229a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_PICTURE_READY = 2,
8329a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_NEW_IDR = 3, /* upon getting this, users have to call PVAVCEncodeSPS and PVAVCEncodePPS to get a new SPS and PPS*/
8429a84457aed4c45bc900998b5e11c03023264208James Dong    AVCENC_SKIPPED_PICTURE = 4 /* continuable error message */
8529a84457aed4c45bc900998b5e11c03023264208James Dong
8629a84457aed4c45bc900998b5e11c03023264208James Dong} AVCEnc_Status;
8729a84457aed4c45bc900998b5e11c03023264208James Dong
8829a84457aed4c45bc900998b5e11c03023264208James Dong#define MAX_NUM_SLICE_GROUP  8      /* maximum for all the profiles */
8929a84457aed4c45bc900998b5e11c03023264208James Dong
9029a84457aed4c45bc900998b5e11c03023264208James Dong/**
9129a84457aed4c45bc900998b5e11c03023264208James DongThis structure contains the encoding parameters.
9229a84457aed4c45bc900998b5e11c03023264208James Dong*/
9329a84457aed4c45bc900998b5e11c03023264208James Dongtypedef struct tagAVCEncParam
9429a84457aed4c45bc900998b5e11c03023264208James Dong{
9529a84457aed4c45bc900998b5e11c03023264208James Dong    /* if profile/level is set to zero, encoder will choose the closest one for you */
9629a84457aed4c45bc900998b5e11c03023264208James Dong    AVCProfile profile; /* profile of the bitstream to be compliant with*/
9729a84457aed4c45bc900998b5e11c03023264208James Dong    AVCLevel   level;   /* level of the bitstream to be compliant with*/
9829a84457aed4c45bc900998b5e11c03023264208James Dong
9929a84457aed4c45bc900998b5e11c03023264208James Dong    int width;      /* width of an input frame in pixel */
10029a84457aed4c45bc900998b5e11c03023264208James Dong    int height;     /* height of an input frame in pixel */
10129a84457aed4c45bc900998b5e11c03023264208James Dong
10229a84457aed4c45bc900998b5e11c03023264208James Dong    int poc_type; /* picture order count mode, 0,1 or 2 */
10329a84457aed4c45bc900998b5e11c03023264208James Dong    /* for poc_type == 0 */
10429a84457aed4c45bc900998b5e11c03023264208James Dong    uint log2_max_poc_lsb_minus_4; /* specify maximum value of POC Lsb, range 0..12*/
10529a84457aed4c45bc900998b5e11c03023264208James Dong    /* for poc_type == 1 */
10629a84457aed4c45bc900998b5e11c03023264208James Dong    uint delta_poc_zero_flag; /* delta POC always zero */
10729a84457aed4c45bc900998b5e11c03023264208James Dong    int offset_poc_non_ref; /* offset for non-reference pic */
10829a84457aed4c45bc900998b5e11c03023264208James Dong    int offset_top_bottom; /* offset between top and bottom field */
10929a84457aed4c45bc900998b5e11c03023264208James Dong    uint num_ref_in_cycle; /* number of reference frame in one cycle */
11029a84457aed4c45bc900998b5e11c03023264208James Dong    int *offset_poc_ref; /* array of offset for ref pic, dimension [num_ref_in_cycle] */
11129a84457aed4c45bc900998b5e11c03023264208James Dong
11229a84457aed4c45bc900998b5e11c03023264208James Dong    int num_ref_frame;  /* number of reference frame used */
11329a84457aed4c45bc900998b5e11c03023264208James Dong    int num_slice_group;  /* number of slice group */
11429a84457aed4c45bc900998b5e11c03023264208James Dong    int fmo_type;   /* 0: interleave, 1: dispersed, 2: foreground with left-over
11529a84457aed4c45bc900998b5e11c03023264208James Dong                    3: box-out, 4:raster scan, 5:wipe, 6:explicit */
11629a84457aed4c45bc900998b5e11c03023264208James Dong    /* for fmo_type == 0 */
11729a84457aed4c45bc900998b5e11c03023264208James Dong    uint run_length_minus1[MAX_NUM_SLICE_GROUP];   /* array of size num_slice_group, in round robin fasion */
11829a84457aed4c45bc900998b5e11c03023264208James Dong    /* fmo_type == 2*/
11929a84457aed4c45bc900998b5e11c03023264208James Dong    uint top_left[MAX_NUM_SLICE_GROUP-1];           /* array of co-ordinates of each slice_group */
12029a84457aed4c45bc900998b5e11c03023264208James Dong    uint bottom_right[MAX_NUM_SLICE_GROUP-1];       /* except the last one which is the background. */
12129a84457aed4c45bc900998b5e11c03023264208James Dong    /* fmo_type == 3,4,5 */
12229a84457aed4c45bc900998b5e11c03023264208James Dong    AVCFlag change_dir_flag;  /* slice group change direction flag */
12329a84457aed4c45bc900998b5e11c03023264208James Dong    uint change_rate_minus1;
12429a84457aed4c45bc900998b5e11c03023264208James Dong    /* fmo_type == 6 */
12529a84457aed4c45bc900998b5e11c03023264208James Dong    uint *slice_group; /* array of size MBWidth*MBHeight */
12629a84457aed4c45bc900998b5e11c03023264208James Dong
12729a84457aed4c45bc900998b5e11c03023264208James Dong    AVCFlag db_filter;  /* enable deblocking loop filter */
12829a84457aed4c45bc900998b5e11c03023264208James Dong    int disable_db_idc;  /* 0: filter everywhere, 1: no filter, 2: no filter across slice boundary */
12929a84457aed4c45bc900998b5e11c03023264208James Dong    int alpha_offset;   /* alpha offset range -6,...,6 */
13029a84457aed4c45bc900998b5e11c03023264208James Dong    int beta_offset;    /* beta offset range -6,...,6 */
13129a84457aed4c45bc900998b5e11c03023264208James Dong
13229a84457aed4c45bc900998b5e11c03023264208James Dong    AVCFlag constrained_intra_pred; /* constrained intra prediction flag */
13329a84457aed4c45bc900998b5e11c03023264208James Dong
13429a84457aed4c45bc900998b5e11c03023264208James Dong    AVCFlag auto_scd;   /* scene change detection on or off */
13529a84457aed4c45bc900998b5e11c03023264208James Dong    int idr_period; /* idr frame refresh rate in number of target encoded frame (no concept of actual time).*/
13629a84457aed4c45bc900998b5e11c03023264208James Dong    int intramb_refresh;    /* minimum number of intra MB per frame */
13729a84457aed4c45bc900998b5e11c03023264208James Dong    AVCFlag data_par;   /* enable data partitioning */
13829a84457aed4c45bc900998b5e11c03023264208James Dong
13929a84457aed4c45bc900998b5e11c03023264208James Dong    AVCFlag fullsearch; /* enable full-pel full-search mode */
14029a84457aed4c45bc900998b5e11c03023264208James Dong    int search_range;   /* search range for motion vector in (-search_range,+search_range) pixels */
14129a84457aed4c45bc900998b5e11c03023264208James Dong    AVCFlag sub_pel;    /* enable sub pel prediction */
14229a84457aed4c45bc900998b5e11c03023264208James Dong    AVCFlag submb_pred; /* enable sub MB partition mode */
14329a84457aed4c45bc900998b5e11c03023264208James Dong    AVCFlag rdopt_mode; /* RD optimal mode selection */
14429a84457aed4c45bc900998b5e11c03023264208James Dong    AVCFlag bidir_pred; /* enable bi-directional for B-slice, this flag forces the encoder to encode
14529a84457aed4c45bc900998b5e11c03023264208James Dong                        any frame with POC less than the previously encoded frame as a B-frame.
14629a84457aed4c45bc900998b5e11c03023264208James Dong                        If it's off, then such frames will remain P-frame. */
14729a84457aed4c45bc900998b5e11c03023264208James Dong
14829a84457aed4c45bc900998b5e11c03023264208James Dong    AVCFlag rate_control; /* rate control enable, on: RC on, off: constant QP */
14929a84457aed4c45bc900998b5e11c03023264208James Dong    int initQP;     /* initial QP */
15029a84457aed4c45bc900998b5e11c03023264208James Dong    uint32 bitrate;    /* target encoding bit rate in bits/second */
15129a84457aed4c45bc900998b5e11c03023264208James Dong    uint32 CPB_size;  /* coded picture buffer in number of bits */
15229a84457aed4c45bc900998b5e11c03023264208James Dong    uint32 init_CBP_removal_delay; /* initial CBP removal delay in msec */
15329a84457aed4c45bc900998b5e11c03023264208James Dong
15429a84457aed4c45bc900998b5e11c03023264208James Dong    uint32 frame_rate;  /* frame rate in the unit of frames per 1000 second */
15529a84457aed4c45bc900998b5e11c03023264208James Dong    /* note, frame rate is only needed by the rate control, AVC is timestamp agnostic. */
15629a84457aed4c45bc900998b5e11c03023264208James Dong
15729a84457aed4c45bc900998b5e11c03023264208James Dong    AVCFlag out_of_band_param_set; /* flag to set whether param sets are to be retrieved up front or not */
15829a84457aed4c45bc900998b5e11c03023264208James Dong
15929a84457aed4c45bc900998b5e11c03023264208James Dong    AVCFlag use_overrun_buffer;  /* do not throw away the frame if output buffer is not big enough.
16029a84457aed4c45bc900998b5e11c03023264208James Dong                                    copy excess bits to the overrun buffer */
16129a84457aed4c45bc900998b5e11c03023264208James Dong} AVCEncParams;
16229a84457aed4c45bc900998b5e11c03023264208James Dong
16329a84457aed4c45bc900998b5e11c03023264208James Dong
16429a84457aed4c45bc900998b5e11c03023264208James Dong/**
16529a84457aed4c45bc900998b5e11c03023264208James DongThis structure contains current frame encoding statistics for debugging purpose.
16629a84457aed4c45bc900998b5e11c03023264208James Dong*/
16729a84457aed4c45bc900998b5e11c03023264208James Dongtypedef struct tagAVCEncFrameStats
16829a84457aed4c45bc900998b5e11c03023264208James Dong{
16929a84457aed4c45bc900998b5e11c03023264208James Dong    int avgFrameQP;   /* average frame QP */
17029a84457aed4c45bc900998b5e11c03023264208James Dong    int numIntraMBs;  /* number of intra MBs */
17129a84457aed4c45bc900998b5e11c03023264208James Dong    int numFalseAlarm;
17229a84457aed4c45bc900998b5e11c03023264208James Dong    int numMisDetected;
17329a84457aed4c45bc900998b5e11c03023264208James Dong    int numDetected;
17429a84457aed4c45bc900998b5e11c03023264208James Dong
17529a84457aed4c45bc900998b5e11c03023264208James Dong} AVCEncFrameStats;
17629a84457aed4c45bc900998b5e11c03023264208James Dong
17729a84457aed4c45bc900998b5e11c03023264208James Dong#ifdef __cplusplus
17829a84457aed4c45bc900998b5e11c03023264208James Dongextern "C"
17929a84457aed4c45bc900998b5e11c03023264208James Dong{
18029a84457aed4c45bc900998b5e11c03023264208James Dong#endif
18129a84457aed4c45bc900998b5e11c03023264208James Dong    /** THE FOLLOWINGS ARE APIS */
18229a84457aed4c45bc900998b5e11c03023264208James Dong    /**
18329a84457aed4c45bc900998b5e11c03023264208James Dong    This function initializes the encoder library. It verifies the validity of the
18429a84457aed4c45bc900998b5e11c03023264208James Dong    encoding parameters against the specified profile/level and the list of supported
18529a84457aed4c45bc900998b5e11c03023264208James Dong    tools by this library. It allocates necessary memories required to perform encoding.
18629a84457aed4c45bc900998b5e11c03023264208James Dong    For re-encoding application, if users want to setup encoder in a more precise way,
18729a84457aed4c45bc900998b5e11c03023264208James Dong    users can give the external SPS and PPS to the encoder to follow.
18829a84457aed4c45bc900998b5e11c03023264208James Dong    \param "avcHandle"  "Handle to the AVC encoder library object."
18929a84457aed4c45bc900998b5e11c03023264208James Dong    \param "encParam"   "Pointer to the encoding parameter structure."
19029a84457aed4c45bc900998b5e11c03023264208James Dong    \param "extSPS"     "External SPS used for re-encoding purpose. NULL if not present"
19129a84457aed4c45bc900998b5e11c03023264208James Dong    \param "extPPS"     "External PPS used for re-encoding purpose. NULL if not present"
19229a84457aed4c45bc900998b5e11c03023264208James Dong    \return "AVCENC_SUCCESS for success,
19329a84457aed4c45bc900998b5e11c03023264208James Dong             AVCENC_NOT_SUPPORTED for the use of unsupported tools,
19429a84457aed4c45bc900998b5e11c03023264208James Dong             AVCENC_MEMORY_FAIL for memory allocation failure,
19529a84457aed4c45bc900998b5e11c03023264208James Dong             AVCENC_FAIL for generic failure."
19629a84457aed4c45bc900998b5e11c03023264208James Dong    */
19729a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF AVCEnc_Status PVAVCEncInitialize(AVCHandle *avcHandle, AVCEncParams *encParam, void* extSPS, void* extPPS);
19829a84457aed4c45bc900998b5e11c03023264208James Dong
19929a84457aed4c45bc900998b5e11c03023264208James Dong
20029a84457aed4c45bc900998b5e11c03023264208James Dong    /**
20129a84457aed4c45bc900998b5e11c03023264208James Dong    Since the output buffer size is not known prior to encoding a frame, users need to
20229a84457aed4c45bc900998b5e11c03023264208James Dong    allocate big enough buffer otherwise, that frame will be dropped. This function returns
20329a84457aed4c45bc900998b5e11c03023264208James Dong    the size of the output buffer to be allocated by the users that guarantees to hold one frame.
20429a84457aed4c45bc900998b5e11c03023264208James Dong    It follows the CPB spec for a particular level.  However, when the users set use_overrun_buffer
20529a84457aed4c45bc900998b5e11c03023264208James Dong    flag, this API is useless as excess output bits are saved in the overrun buffer waiting to be
20629a84457aed4c45bc900998b5e11c03023264208James Dong    copied out in small chunks, i.e. users can allocate any size of output buffer.
20729a84457aed4c45bc900998b5e11c03023264208James Dong    \param "avcHandle"  "Handle to the AVC encoder library object."
20829a84457aed4c45bc900998b5e11c03023264208James Dong    \param "size"   "Pointer to the size to be modified."
20929a84457aed4c45bc900998b5e11c03023264208James Dong    \return "AVCENC_SUCCESS for success, AVCENC_UNINITIALIZED when level is not known.
21029a84457aed4c45bc900998b5e11c03023264208James Dong    */
21129a84457aed4c45bc900998b5e11c03023264208James Dong
21229a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF AVCEnc_Status PVAVCEncGetMaxOutputBufferSize(AVCHandle *avcHandle, int* size);
21329a84457aed4c45bc900998b5e11c03023264208James Dong
21429a84457aed4c45bc900998b5e11c03023264208James Dong    /**
21529a84457aed4c45bc900998b5e11c03023264208James Dong    Users call this function to provide an input structure to the encoder library which will keep
21629a84457aed4c45bc900998b5e11c03023264208James Dong    a list of input structures it receives in case the users call this function many time before
21729a84457aed4c45bc900998b5e11c03023264208James Dong    calling PVAVCEncodeSlice. The encoder library will encode them according to the frame_num order.
21829a84457aed4c45bc900998b5e11c03023264208James Dong    Users should not modify the content of a particular frame until this frame is encoded and
21929a84457aed4c45bc900998b5e11c03023264208James Dong    returned thru CBAVCEnc_ReturnInput() callback function.
22029a84457aed4c45bc900998b5e11c03023264208James Dong    \param "avcHandle"  "Handle to the AVC encoder library object."
22129a84457aed4c45bc900998b5e11c03023264208James Dong    \param "input"      "Pointer to the input structure."
22229a84457aed4c45bc900998b5e11c03023264208James Dong    \return "AVCENC_SUCCESS for success,
22329a84457aed4c45bc900998b5e11c03023264208James Dong            AVCENC_FAIL if the encoder is not in the right state to take a new input frame.
22429a84457aed4c45bc900998b5e11c03023264208James Dong            AVCENC_NEW_IDR for the detection or determination of a new IDR, with this status,
22529a84457aed4c45bc900998b5e11c03023264208James Dong            the returned NAL is an SPS NAL,
22629a84457aed4c45bc900998b5e11c03023264208James Dong            AVCENC_NO_PICTURE if the input frame coding timestamp is too early, users must
22729a84457aed4c45bc900998b5e11c03023264208James Dong            get next frame or adjust the coding timestamp."
22829a84457aed4c45bc900998b5e11c03023264208James Dong    */
22929a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF AVCEnc_Status PVAVCEncSetInput(AVCHandle *avcHandle, AVCFrameIO *input);
23029a84457aed4c45bc900998b5e11c03023264208James Dong
23129a84457aed4c45bc900998b5e11c03023264208James Dong    /**
23229a84457aed4c45bc900998b5e11c03023264208James Dong    This function is called to encode a NAL unit which can be an SPS NAL, a PPS NAL or
23329a84457aed4c45bc900998b5e11c03023264208James Dong    a VCL (video coding layer) NAL which contains one slice of data. It could be a
23429a84457aed4c45bc900998b5e11c03023264208James Dong    fixed number of macroblocks, as specified in the encoder parameters set, or the
23529a84457aed4c45bc900998b5e11c03023264208James Dong    maximum number of macroblocks fitted into the given input argument "buffer". The
23629a84457aed4c45bc900998b5e11c03023264208James Dong    input frame is taken from the oldest unencoded input frame retrieved by users by
23729a84457aed4c45bc900998b5e11c03023264208James Dong    PVAVCEncGetInput API.
23829a84457aed4c45bc900998b5e11c03023264208James Dong    \param "avcHandle"  "Handle to the AVC encoder library object."
23929a84457aed4c45bc900998b5e11c03023264208James Dong    \param "buffer"     "Pointer to the output AVC bitstream buffer, the format will be EBSP,
24029a84457aed4c45bc900998b5e11c03023264208James Dong                         not RBSP."
24129a84457aed4c45bc900998b5e11c03023264208James Dong    \param "buf_nal_size"   "As input, the size of the buffer in bytes.
24229a84457aed4c45bc900998b5e11c03023264208James Dong                        This is the physical limitation of the buffer. As output, the size of the EBSP."
24329a84457aed4c45bc900998b5e11c03023264208James Dong    \param "nal_type"   "Pointer to the NAL type of the returned buffer."
24429a84457aed4c45bc900998b5e11c03023264208James Dong    \return "AVCENC_SUCCESS for success of encoding one slice,
24529a84457aed4c45bc900998b5e11c03023264208James Dong             AVCENC_PICTURE_READY for the completion of a frame encoding,
24629a84457aed4c45bc900998b5e11c03023264208James Dong             AVCENC_FAIL for failure (this should not occur, though)."
24729a84457aed4c45bc900998b5e11c03023264208James Dong    */
24829a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF AVCEnc_Status PVAVCEncodeNAL(AVCHandle *avcHandle, uint8 *buffer, uint *buf_nal_size, int *nal_type);
24929a84457aed4c45bc900998b5e11c03023264208James Dong
25029a84457aed4c45bc900998b5e11c03023264208James Dong    /**
25129a84457aed4c45bc900998b5e11c03023264208James Dong    This function sniffs the nal_unit_type such that users can call corresponding APIs.
25229a84457aed4c45bc900998b5e11c03023264208James Dong    This function is identical to PVAVCDecGetNALType() in the decoder.
25329a84457aed4c45bc900998b5e11c03023264208James Dong    \param "bitstream"  "Pointer to the beginning of a NAL unit (start with forbidden_zero_bit, etc.)."
25429a84457aed4c45bc900998b5e11c03023264208James Dong    \param "size"       "size of the bitstream (NumBytesInNALunit + 1)."
25529a84457aed4c45bc900998b5e11c03023264208James Dong    \param "nal_unit_type" "Pointer to the return value of nal unit type."
25629a84457aed4c45bc900998b5e11c03023264208James Dong    \return "AVCENC_SUCCESS if success, AVCENC_FAIL otherwise."
25729a84457aed4c45bc900998b5e11c03023264208James Dong    */
25829a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF AVCEnc_Status PVAVCEncGetNALType(uint8 *bitstream, int size, int *nal_type, int *nal_ref_idc);
25929a84457aed4c45bc900998b5e11c03023264208James Dong
26029a84457aed4c45bc900998b5e11c03023264208James Dong    /**
26129a84457aed4c45bc900998b5e11c03023264208James Dong    This function returns the pointer to internal overrun buffer. Users can call this to query
26229a84457aed4c45bc900998b5e11c03023264208James Dong    whether the overrun buffer has been used to encode the current NAL.
26329a84457aed4c45bc900998b5e11c03023264208James Dong    \param "avcHandle"  "Pointer to the handle."
26429a84457aed4c45bc900998b5e11c03023264208James Dong    \return "Pointer to overrun buffer if it is used, otherwise, NULL."
26529a84457aed4c45bc900998b5e11c03023264208James Dong    */
26629a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF uint8* PVAVCEncGetOverrunBuffer(AVCHandle* avcHandle);
26729a84457aed4c45bc900998b5e11c03023264208James Dong
26829a84457aed4c45bc900998b5e11c03023264208James Dong    /**
26929a84457aed4c45bc900998b5e11c03023264208James Dong    This function returns the reconstructed frame of the most recently encoded frame.
27029a84457aed4c45bc900998b5e11c03023264208James Dong    Note that this frame is not returned to the users yet. Users should only read the
27129a84457aed4c45bc900998b5e11c03023264208James Dong    content of this frame.
27229a84457aed4c45bc900998b5e11c03023264208James Dong    \param "avcHandle"  "Handle to the AVC encoder library object."
27329a84457aed4c45bc900998b5e11c03023264208James Dong    \param "output"     "Pointer to the input structure."
27429a84457aed4c45bc900998b5e11c03023264208James Dong    \return "AVCENC_SUCCESS for success, AVCENC_NO_PICTURE if no picture to be outputted."
27529a84457aed4c45bc900998b5e11c03023264208James Dong    */
27629a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF AVCEnc_Status PVAVCEncGetRecon(AVCHandle *avcHandle, AVCFrameIO *recon);
27729a84457aed4c45bc900998b5e11c03023264208James Dong
27829a84457aed4c45bc900998b5e11c03023264208James Dong    /**
27929a84457aed4c45bc900998b5e11c03023264208James Dong    This function is used to return the recontructed frame back to the AVC encoder library
28029a84457aed4c45bc900998b5e11c03023264208James Dong    in order to be re-used for encoding operation. If users want the content of it to remain
28129a84457aed4c45bc900998b5e11c03023264208James Dong    unchanged for a long time, they should make a copy of it and release the memory back to
28229a84457aed4c45bc900998b5e11c03023264208James Dong    the encoder. The encoder relies on the id element in the AVCFrameIO structure,
28329a84457aed4c45bc900998b5e11c03023264208James Dong    thus users should not change the id value.
28429a84457aed4c45bc900998b5e11c03023264208James Dong    \param "avcHandle"  "Handle to the AVC decoder library object."
28529a84457aed4c45bc900998b5e11c03023264208James Dong    \param "output"      "Pointer to the AVCFrameIO structure."
28629a84457aed4c45bc900998b5e11c03023264208James Dong    \return "AVCENC_SUCCESS for success, AVCENC_FAIL for fail for id not found."
28729a84457aed4c45bc900998b5e11c03023264208James Dong    */
28829a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF AVCEnc_Status PVAVCEncReleaseRecon(AVCHandle *avcHandle, AVCFrameIO *recon);
28929a84457aed4c45bc900998b5e11c03023264208James Dong
29029a84457aed4c45bc900998b5e11c03023264208James Dong    /**
29129a84457aed4c45bc900998b5e11c03023264208James Dong    This function performs clean up operation including memory deallocation.
29229a84457aed4c45bc900998b5e11c03023264208James Dong    The encoder will also clear the list of input structures it has not released.
29329a84457aed4c45bc900998b5e11c03023264208James Dong    This implies that users must keep track of the number of input structure they have allocated
29429a84457aed4c45bc900998b5e11c03023264208James Dong    and free them accordingly.
29529a84457aed4c45bc900998b5e11c03023264208James Dong    \param "avcHandle"  "Handle to the AVC encoder library object."
29629a84457aed4c45bc900998b5e11c03023264208James Dong    */
29729a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF void    PVAVCCleanUpEncoder(AVCHandle *avcHandle);
29829a84457aed4c45bc900998b5e11c03023264208James Dong
29929a84457aed4c45bc900998b5e11c03023264208James Dong    /**
30029a84457aed4c45bc900998b5e11c03023264208James Dong    This function extracts statistics of the current frame. If the encoder has not finished
30129a84457aed4c45bc900998b5e11c03023264208James Dong    with the current frame, the result is not accurate.
30229a84457aed4c45bc900998b5e11c03023264208James Dong    \param "avcHandle"  "Handle to the AVC encoder library object."
30329a84457aed4c45bc900998b5e11c03023264208James Dong    \param "avcStats"   "Pointer to AVCEncFrameStats structure."
30429a84457aed4c45bc900998b5e11c03023264208James Dong    \return "void."
30529a84457aed4c45bc900998b5e11c03023264208James Dong    */
30629a84457aed4c45bc900998b5e11c03023264208James Dong    void PVAVCEncGetFrameStats(AVCHandle *avcHandle, AVCEncFrameStats *avcStats);
30729a84457aed4c45bc900998b5e11c03023264208James Dong
30829a84457aed4c45bc900998b5e11c03023264208James Dong    /**
30929a84457aed4c45bc900998b5e11c03023264208James Dong    These functions are used for the modification of encoding parameters.
31029a84457aed4c45bc900998b5e11c03023264208James Dong    To be polished.
31129a84457aed4c45bc900998b5e11c03023264208James Dong    */
31229a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF AVCEnc_Status PVAVCEncUpdateBitRate(AVCHandle *avcHandle, uint32 bitrate);
31329a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF AVCEnc_Status PVAVCEncUpdateFrameRate(AVCHandle *avcHandle, uint32 num, uint32 denom);
31429a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF AVCEnc_Status PVAVCEncUpdateIDRInterval(AVCHandle *avcHandle, int IDRInterval);
31529a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF AVCEnc_Status PVAVCEncIDRRequest(AVCHandle *avcHandle);
31629a84457aed4c45bc900998b5e11c03023264208James Dong    OSCL_IMPORT_REF AVCEnc_Status PVAVCEncUpdateIMBRefresh(AVCHandle *avcHandle, int numMB);
31729a84457aed4c45bc900998b5e11c03023264208James Dong
31829a84457aed4c45bc900998b5e11c03023264208James Dong
31929a84457aed4c45bc900998b5e11c03023264208James Dong#ifdef __cplusplus
32029a84457aed4c45bc900998b5e11c03023264208James Dong}
32129a84457aed4c45bc900998b5e11c03023264208James Dong#endif
32229a84457aed4c45bc900998b5e11c03023264208James Dong#endif  /* _AVCENC_API_H_ */
32329a84457aed4c45bc900998b5e11c03023264208James Dong
324