Home | History | Annotate | Download | only in include
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      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
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 /**
     19 This file contains common type definitions and enumerations used by AVC encoder
     20 and decoder libraries which are exposed to the users.
     21 @publishedAll
     22 */
     23 
     24 #ifndef AVCAPI_COMMON_H_INCLUDED
     25 #define AVCAPI_COMMON_H_INCLUDED
     26 
     27 #define PV_MEMORY_POOL
     28 /**
     29 This is common return status.
     30 @publishedAll
     31 */
     32 typedef enum
     33 {
     34     AVC_NO_BUFFER = -2,
     35     AVC_MEMORY_FAIL = -1,
     36     AVC_FAIL = 0,
     37     AVC_SUCCESS = 1,
     38     AVC_PICTURE_OUTPUT_READY = 2
     39 } AVCStatus;
     40 
     41 /**
     42 This enumeration is for profiles. The value follows the profile_idc  in sequence
     43 parameter set rbsp. See Annex A.
     44 @publishedAll
     45 */
     46 typedef enum
     47 {
     48     AVC_BASELINE = 66,
     49     AVC_MAIN = 77,
     50     AVC_EXTENDED = 88,
     51     AVC_HIGH = 100,
     52     AVC_HIGH10 = 110,
     53     AVC_HIGH422 = 122,
     54     AVC_HIGH444 = 144
     55 } AVCProfile;
     56 
     57 /**
     58 This enumeration is for levels. The value follows the level_idc in sequence
     59 parameter set rbsp. See Annex A.
     60 @published All
     61 */
     62 typedef enum
     63 {
     64     AVC_LEVEL_AUTO = 0,
     65     AVC_LEVEL1_B = 9,
     66     AVC_LEVEL1 = 10,
     67     AVC_LEVEL1_1 = 11,
     68     AVC_LEVEL1_2 = 12,
     69     AVC_LEVEL1_3 = 13,
     70     AVC_LEVEL2 = 20,
     71     AVC_LEVEL2_1 = 21,
     72     AVC_LEVEL2_2 = 22,
     73     AVC_LEVEL3 = 30,
     74     AVC_LEVEL3_1 = 31,
     75     AVC_LEVEL3_2 = 32,
     76     AVC_LEVEL4 = 40,
     77     AVC_LEVEL4_1 = 41,
     78     AVC_LEVEL4_2 = 42,
     79     AVC_LEVEL5 = 50,
     80     AVC_LEVEL5_1 = 51
     81 } AVCLevel;
     82 
     83 /**
     84 This enumeration follows Table 7-1 for NAL unit type codes.
     85 This may go to avccommon_api.h later (external common).
     86 @publishedAll
     87 */
     88 typedef enum
     89 {
     90     AVC_NALTYPE_SLICE = 1,  /* non-IDR non-data partition */
     91     AVC_NALTYPE_DPA = 2,    /* data partition A */
     92     AVC_NALTYPE_DPB = 3,    /* data partition B */
     93     AVC_NALTYPE_DPC = 4,    /* data partition C */
     94     AVC_NALTYPE_IDR = 5,    /* IDR NAL */
     95     AVC_NALTYPE_SEI = 6,    /* supplemental enhancement info */
     96     AVC_NALTYPE_SPS = 7,    /* sequence parameter set */
     97     AVC_NALTYPE_PPS = 8,    /* picture parameter set */
     98     AVC_NALTYPE_AUD = 9,    /* access unit delimiter */
     99     AVC_NALTYPE_EOSEQ = 10, /* end of sequence */
    100     AVC_NALTYPE_EOSTREAM = 11, /* end of stream */
    101     AVC_NALTYPE_FILL = 12   /* filler data */
    102 } AVCNalUnitType;
    103 
    104 /**
    105 This enumeration specifies debug logging type.
    106 This may go to avccommon_api.h later (external common).
    107 @publishedAll
    108 */
    109 typedef enum
    110 {
    111     AVC_LOGTYPE_ERROR = 0,
    112     AVC_LOGTYPE_WARNING = 1,
    113     AVC_LOGTYPE_INFO = 2
    114 } AVCLogType;
    115 
    116 /**
    117 This enumerate the status of certain flags.
    118 @publishedAll
    119 */
    120 typedef enum
    121 {
    122     AVC_OFF = 0,
    123     AVC_ON = 1
    124 } AVCFlag;
    125 
    126 /**
    127 This structure contains input information.
    128 Note, this structure is identical to AVCDecOutput for now.
    129 */
    130 typedef struct tagAVCFrameIO
    131 {
    132     /** A unique identification number for a particular instance of this structure.
    133     To remain unchanged by the application between the time when it is given to the
    134     library and the time when the library returns it back. */
    135     uint32 id;
    136 
    137     /** Array of pointers to Y,Cb,Cr content in 4:2:0 format. For AVC decoding,
    138     this memory is allocated by the AVC decoder library. For AVC encoding, only the
    139     memory for original unencoded frame is allocated by the application. Internal
    140     memory is also allocated by the AVC encoder library. */
    141     uint8 *YCbCr[3];
    142 
    143     /** In/Out: Coded width of the luma component, it has to be multiple of 16. */
    144     int pitch;
    145 
    146     /** In/Out: Coded height of the luma component, must be multiple of 16. */
    147     int height;
    148 
    149     /** In/Out: Display width, less than picth */
    150     int clip_width;
    151 
    152     /** In/Out: Display height, less than height */
    153     int clip_height;
    154 
    155     /** Input: Origin of the display area [0]=>row, [1]=>column  */
    156     int clip_origin[2];
    157 
    158     /** Output: Frame number in de/encoding order (not necessary)*/
    159     uint32 coding_order;
    160 
    161     /** Output: Frame number in displaying order (this may or may not be associated with the POC at all!!!). */
    162     uint32 disp_order;
    163 
    164     /** In/Out: Flag for use for reference or not. */
    165     uint  is_reference;
    166 
    167     /** In/Out: Coding timestamp in msec (not display timestamp) */
    168     uint32 coding_timestamp;
    169 
    170     /* there could be something else here such as format, DON (decoding order number)
    171      if available thru SEI, etc. */
    172 } AVCFrameIO;
    173 
    174 
    175 /** CALLBACK FUNCTION TO BE IMPLEMENTED BY APPLICATION */
    176 /** In AVCDecControls structure, userData is a pointer to an object with the following
    177     member functions.
    178 */
    179 
    180 
    181 /** @brief Decoded picture buffers (DPB) must be allocated or re-allocated before an
    182     IDR frame is decoded. If PV_MEMORY_POOL is not defined, AVC lib will allocate DPB
    183     internally which cannot be shared with the application. In that case, this function
    184     will not be called.
    185     @param userData  The same value of userData in AVCHandle object.
    186     @param frame_size_in_mbs  The size of each frame in number of macroblocks.
    187     @param num_frames The number of frames in DPB.
    188     @return 1 for success, 0 for fail (cannot allocate DPB)
    189 */
    190 
    191 typedef int (*FunctionType_DPBAlloc)(void *userData, uint frame_size_in_mbs, uint num_buffers);
    192 
    193 /** @brief AVC library calls this function is reserve a memory of one frame from the DPB.
    194     Once reserved, this frame shall not be deleted or over-written by the app.
    195     @param userData  The same value of userData in AVCHandle object.
    196     @param indx      Index of a frame in DPB (AVC library keeps track of the index).
    197     @param yuv      The address of the yuv pointer returned to the AVC lib.
    198     @return         1 for success, 0 for fail (no frames available to bind).
    199     */
    200 typedef int (*FunctionType_FrameBind)(void *userData, int indx, uint8 **yuv);
    201 
    202 /** @brief AVC library calls this function once a bound frame is not needed for decoding
    203     operation (falls out of the sliding window, or marked unused for reference).
    204     @param userData  The same value of userData in AVCHandle object.
    205     @param indx      Index of frame to be unbound (AVC library keeps track of the index).
    206     @return  none.
    207 */
    208 typedef void (*FuctionType_FrameUnbind)(void *userData, int);
    209 
    210 /** Pointer to malloc function for general memory allocation, so that application can keep track of
    211     memory usage.
    212 \param "size" "Size of requested memory in bytes."
    213 \param "attribute" "Some value specifying types, priority, etc. of the memory."
    214 \return "The address of the allocated memory casted to int"
    215 */
    216 typedef int (*FunctionType_Malloc)(void *userData, int32 size, int attribute);
    217 
    218 /** Function pointer to free
    219 \param "mem" "Pointer to the memory to be freed casted to int"
    220 \return "void"
    221 */
    222 typedef void (*FunctionType_Free)(void *userData, int mem);
    223 
    224 /** Debug logging information is returned to the application thru this function.
    225 \param "type"   "Type of logging message, see definition of AVCLogType."
    226 \param "string1"    "Logging message."
    227 \param "string2"    "To be defined."
    228 */
    229 typedef void (*FunctionType_DebugLog)(uint32 *userData, AVCLogType type, char *string1, int val1, int val2);
    230 
    231 /**
    232 This structure has to be allocated and maintained by the user of the library.
    233 This structure is used as a handle to the library object.
    234 */
    235 typedef struct tagAVCHandle
    236 {
    237     /** A pointer to the internal data structure. Users have to make sure that this value
    238         is NULL at the beginning.
    239     */
    240     void        *AVCObject;
    241 
    242     /** A pointer to user object which has the following member functions used for
    243     callback purpose.  !!! */
    244     void        *userData;
    245 
    246     /** Pointers to functions implemented by the users of AVC library */
    247     FunctionType_DPBAlloc CBAVC_DPBAlloc;
    248 
    249     FunctionType_FrameBind CBAVC_FrameBind;
    250 
    251     FuctionType_FrameUnbind CBAVC_FrameUnbind;
    252 
    253     FunctionType_Malloc CBAVC_Malloc;
    254 
    255     FunctionType_Free  CBAVC_Free;
    256 
    257     FunctionType_DebugLog CBAVC_DebugLog;
    258 
    259     /** Flag to enable debugging */
    260     uint32  debugEnable;
    261 
    262 } AVCHandle;
    263 
    264 
    265 
    266 #ifdef PVDEBUGMSG_LOG
    267 #define DEBUG_LOG(a,b,c,d,e)    CBAVC_DebugLog(a,b,c,d,e)
    268 #else
    269 #define DEBUG_LOG(a,b,c,d,e)
    270 #endif
    271 
    272 #endif /* _AVCAPI_COMMON_H_ */
    273