videoeditorengine/avcedit/inc/biblin.h
branchRCL_3
changeset 3 e0b5df5c0969
parent 0 951a5db380a0
child 5 4c409de21d23
equal deleted inserted replaced
0:951a5db380a0 3:e0b5df5c0969
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 * Header file for Bit Buffer module.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef _BIBLIN_H_
       
    22 #define _BIBLIN_H_
       
    23 
       
    24 // @@ HARI AVC  Added the below 8 lines
       
    25 // make sure they are in the proper location etc... 
       
    26 #if defined(__SYMBIAN32__)
       
    27 #define __EPOC__
       
    28 //#include "epoclib.h"
       
    29 #else
       
    30 #include <assert.h>
       
    31 #include <string.h>
       
    32 //#include <stdlib.h>
       
    33 #endif
       
    34 
       
    35 #include "nrctyp32.h"
       
    36 
       
    37 /*
       
    38  * Defines
       
    39  */
       
    40 
       
    41 /* Error codes */
       
    42 /* Obsolete error codes are not used anymore and are defined only to maintain
       
    43    backwards compatibility with older versions of the file. */
       
    44 #define ERR_BIB_STRUCT_ALLOC 1000      /* If a structure allocation failed */
       
    45 #define ERR_BIB_BUFFER_ALLOC 1001      /* Obsolete */
       
    46 #define ERR_BIB_FILE_READ 1002         /* Obsolete */
       
    47 #define ERR_BIB_NOT_ENOUGH_DATA 1003   /* If the number of bits requested from
       
    48                                           the buffer is greater than the number
       
    49                                           of bits available in the buffer */
       
    50 #define ERR_BIB_ALREADY_OPENED 1004    /* Obsolete */
       
    51 #define ERR_BIB_FILE_OPEN 1005         /* Obsolete */
       
    52 #define ERR_BIB_ALREADY_CLOSED 1006    /* Obsolete */
       
    53 #define ERR_BIB_FILE_CLOSE 1007        /* Obsolete */
       
    54 #define ERR_BIB_NUM_BITS 1008          /* Obsolete */
       
    55 #define ERR_BIB_FILE_NOT_OPEN 1009     /* Obsolete */
       
    56 #define ERR_BIB_ILLEGAL_SIZE 1010      /* Obsolete */
       
    57 #define ERR_BIB_CANNOT_REWIND 1011     /* If the number of bits requested to be
       
    58                                           rewinded is greater than the number
       
    59                                           of bits available in the buffer */
       
    60 #define ERR_BIB_BUFLIST 1012           /* If the internal buffer list has
       
    61                                           been corrupted */
       
    62 #define ERR_BIB_TOO_SMALL_BUFFER 1013  /* Obsolete */
       
    63 #define ERR_BIB_FEC_RELOCK 1050        /* Obsolete */
       
    64 #define ERR_BIB_PSC_FOUND 1060         /* Obsolete */
       
    65 
       
    66 
       
    67 /*
       
    68  * Structs and typedefs
       
    69  */
       
    70 
       
    71 
       
    72 
       
    73 /* {{-output"bibBuffer_t_info.txt" -ignore"*" -noCR}}
       
    74  * The bibBuffer_t data type is a structure containing all the necessary data
       
    75  * for a bit buffer instance (except for the actual data buffer). This
       
    76  * structure is passed to all of the bit buffer functions.
       
    77  * {{-output"bibBuffer_t_info.txt"}}
       
    78  */
       
    79 
       
    80 /* {{-output"bibBuffer_t.txt"}} */
       
    81 
       
    82 
       
    83 
       
    84 enum CopyMode {
       
    85      CopyNone        = 0,
       
    86      CopyWhole       = 1,
       
    87      CopyWithEdit    = 2,
       
    88      EditOnly        = 3
       
    89 };
       
    90 
       
    91 typedef struct bibEditParams_s {
       
    92 
       
    93    int StartByteIndex;      // start byte position where data is to be written 
       
    94    int StartBitIndex;       // start bit position where data is to be written 
       
    95    int curNumBits;      // number of bits that need to be replaced 
       
    96    int newNumBits;      // number of bits to be written 
       
    97    int newValue;      // the value to be written 
       
    98 
       
    99 } bibEditParams_t; 
       
   100 
       
   101 typedef struct bibBufferEdit_s {
       
   102 
       
   103     CopyMode copyMode; 
       
   104     int numChanges; 
       
   105     bibEditParams_t *editParams;
       
   106 
       
   107 } bibBufferEdit_t; 
       
   108 
       
   109 
       
   110 
       
   111 
       
   112 typedef struct bibBuffer_s {
       
   113    u_char *baseAddr;       /* the start address of the buffer */
       
   114 
       
   115    unsigned size;          /* the size of the buffer in bytes */
       
   116 
       
   117    unsigned getIndex;      /* an index to the buffer where data was last got */
       
   118 
       
   119    int bitIndex;           /* an index to the byte pointed by getIndex + 1 */
       
   120 
       
   121    u_int32 bitsLeft;       /* the number of bits currently in the buffer */
       
   122 
       
   123    u_int32 numBytesRead;   /* the total number of bytes read */
       
   124 
       
   125    int error;               /* stores possible error code */
       
   126 
       
   127 } bibBuffer_t;
       
   128 /* {{-output"bibBuffer_t.txt"}} */
       
   129 
       
   130 #ifdef DEBUG_OUTPUT
       
   131 extern bibBuffer_t * buffer_global;
       
   132 #endif
       
   133 
       
   134 /* typedefs for bibFlushBits, bibGetBits, and bibShowBits function types */
       
   135 typedef void (*bibFlushBits_t) (int, bibBuffer_t *, int *, int *, int16 *);
       
   136 typedef u_int32 (*bibGetBits_t) (int, bibBuffer_t *, int *, int *, int16 *);
       
   137 typedef u_int32 (*bibShowBits_t) (int, bibBuffer_t *, int *, int *, int16 *);
       
   138 
       
   139 /*
       
   140  * External macros
       
   141  */
       
   142 
       
   143 /*
       
   144     * bibNumberOfBitsLeft
       
   145     *
       
   146     * Parameters:
       
   147     *    bibBuffer_t *buffer        input bit buffer instance
       
   148     *
       
   149     * Function:
       
   150     *    This macro returns the number of bits which are left to be read
       
   151     *    from the current position.
       
   152     *
       
   153     * Returns:
       
   154     *    See above.
       
   155     */
       
   156 
       
   157    #define bibNumberOfBitsLeft(buffer) \
       
   158       ((buffer)->bitsLeft)
       
   159 
       
   160 /*
       
   161  * External function prototypes
       
   162  */
       
   163 
       
   164 bibBuffer_t *bibCreate(void *srcBuffer, unsigned srcBufferLength,
       
   165    int16 *errorCode);
       
   166 
       
   167 void bibDelete(bibBuffer_t *buffer, int16 *errorCode);
       
   168 
       
   169 u_int32 bibNumberOfFlushedBits(bibBuffer_t *buffer);
       
   170 
       
   171 u_int32 bibNumberOfFlushedBytes(bibBuffer_t *buffer);
       
   172 
       
   173 u_int32 bibNumberOfRewBits(bibBuffer_t *buffer);
       
   174 
       
   175 void bibRewindBits(u_int32 numberOfBits, bibBuffer_t *buffer, int16 *errorCode);
       
   176 
       
   177 int bibCheckPSCValidity( bibBuffer_t *buffer, int syncCodeLength );
       
   178 
       
   179 void bibAddMPEG4Header( bibBuffer_t *buffer, u_int8 *data, int length, int16 *errorCode );
       
   180 
       
   181 void bibMarkBufferWithPSC( bibBuffer_t *buffer, int16 *error );
       
   182 
       
   183 /* 
       
   184  * Prototypes for bibFlushBits/bibGetBits/bibShowBits 
       
   185  */
       
   186 
       
   187 void bibFlushBitsL(int numberOfBits, bibBuffer_t *buffer);
       
   188 u_int32 bibGetBitsL(int numberOfBits, bibBuffer_t *buffer);
       
   189 u_int32 bibShowBitsL(int numberOfBits, bibBuffer_t *buffer);
       
   190 
       
   191 inline void bibFlushBits(int numberOfBits, bibBuffer_t *buffer, int *numberOfBitsGot, int * /*bitErrorIndication*/, int16 * /*errorCode*/)
       
   192 {
       
   193     *numberOfBitsGot = numberOfBits;
       
   194     bibFlushBitsL(numberOfBits, buffer);
       
   195 }
       
   196 
       
   197 inline u_int32 bibGetBits(int numberOfBits, bibBuffer_t *buffer, int *numberOfBitsGot, int * /*bitErrorIndication*/, int16 * /*errorCode*/)
       
   198 {
       
   199     *numberOfBitsGot = numberOfBits;
       
   200     return bibGetBitsL(numberOfBits, buffer);
       
   201 }
       
   202 
       
   203 inline u_int32 bibShowBits(int numberOfBits, bibBuffer_t *buffer, int *numberOfBitsGot, int * /*bitErrorIndication*/, int16 * /*errorCode*/)
       
   204 {
       
   205     *numberOfBitsGot = numberOfBits;
       
   206     return bibShowBitsL(numberOfBits, buffer);
       
   207 }
       
   208 
       
   209 #define bibFlushBitsFromBuffer bibFlushBits
       
   210 #define bibGetBitsFromBuffer bibGetBits
       
   211 #define bibShowBitsFromBuffer bibShowBits
       
   212 
       
   213 
       
   214 bibBufferEdit_t *bibBufferEditCreate(int16 *errorCode);
       
   215 void bibBufEditDelete(bibBufferEdit_t *bufEdit, int16 *errorCode);
       
   216 
       
   217 // copy from input buffer to output buffer in various copy modes (with or without editing)
       
   218 void CopyStream(bibBuffer_t *SrcBuffer,bibBuffer_t *DestBuffer,bibBufferEdit_t *bufEdit, 
       
   219 								int ByteStart,int BitStart);
       
   220 // copy from input buffer to output buffer (without editing)
       
   221 void CopyBuffer(bibBuffer_t *SrcBuffer,bibBuffer_t *DestBuffer, 
       
   222 								int ByteStart,int BitStart, int ByteEnd, int BitEnd);
       
   223 // copy from BufferEdit to output buffer (no copying; rather, inserting code into output buffer)
       
   224 void CopyBufferEdit(bibBuffer_t *SrcBuffer, bibBuffer_t *DestBuffer, 
       
   225 										bibEditParams_t *edParam, int updateSrcBufferStats=1);
       
   226 // insert correct IntraDC values for H.263 chrominance blocks in output buffer
       
   227 void ResetH263IntraDcUV(bibBuffer_t *DestBuffer, int uValue, int vValue); 
       
   228 // insert correct IntraDC values for MPEG-4 chrominance blocks in output buffer
       
   229 void ResetMPEG4IntraDcUV(bibBuffer_t *DestBuffer, int IntraDC_size); 
       
   230 
       
   231 	/* 
       
   232 			SrcValue		the source value from which bits are to be extacted 
       
   233 			MaxNumBits	the length in bits of the source value
       
   234 			StartBit		the index of the starting bit form where data is to be retrieved
       
   235 			getBits			the number of bits to be retrieved 
       
   236 	*/
       
   237 u_int32 bibGetBitsFromWordL(u_int32 SrcValue, u_int32 getBits, u_int32 *StartBit, 
       
   238 												u_int32 MaxNumBits);
       
   239 void bibForwardBits(u_int32 numberOfBits, bibBuffer_t *buffer);
       
   240 void bibStuffBits(bibBuffer_t *buffer);
       
   241 void bibStuffBitsMPEG4(bibBuffer_t *inBuffer, bibBuffer_t *outBuffer, bibBufferEdit_t *bufEdit, 
       
   242 											 int *StartByteIndex, int *StartBitIndex, int updateSrcBufferStats);
       
   243 
       
   244 
       
   245 #endif
       
   246 // End of File