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