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 20 Pathname: getfill.c 21 Funtions: getfill 22 23------------------------------------------------------------------------------ 24 REVISION HISTORY 25 26 Description: Modified from original shareware code 27 28 Description: Modified to pass variables by reference to eliminate use 29 of global variables. 30 31 Description: 1. Used template to re-organize function and filled out 32 Input/Output and Function definition section. 33 2. Optimized code. 34 35 Description: Made the following changes based on review comments. 36 1. Exchanging MODIFYING and RETURNING on line 87, 88. 37 2. Added MPEG reference. 38 3. Changed "fill" to "pass over", "bitstreams are" to 39 "bitstream is" in FUNCTION DESCRIPTION section. 40 4. Fixed tabs. 41 42 Description: Replace some instances of getbits to get9_n_lessbits 43 when the number of bits read is 9 or less. 44 45 Who: Date: 46 Description: 47 48------------------------------------------------------------------------------ 49 INPUT AND OUTPUT DEFINITIONS 50 51 Inputs: 52 pInputStream = pointer to structure BITS containing input stream 53 information. 54 55 Local Stores/Buffers/Pointers Needed: 56 None 57 58 Global Stores/Buffers/Pointers Needed: 59 None 60 61 Outputs: 62 None 63 64 Pointers and Buffers Modified: 65 pInputStream->usedBits is updated to the newly calculated value. 66 67 Local Stores Modified: 68 None 69 70 Global Stores Modified: 71 None 72 73------------------------------------------------------------------------------ 74 FUNCTION DESCRIPTION 75 76 This function passes over fill bits in the raw data block to adjust the 77 instantaneous bit rate when the bitstream is to be transmitted over a 78 constant rate channel. 79 80------------------------------------------------------------------------------ 81 REQUIREMENTS 82 83 None 84 85------------------------------------------------------------------------------ 86 REFERENCES 87 88 (1) MPEG-2 NBC Audio Decoder 89 90 "This software module was originally developed by AT&T, Dolby 91 Laboratories, Fraunhofer Gesellschaft IIS in the course of development 92 of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and 93 3. This software module is an implementation of a part of one or more 94 MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 95 Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio 96 standards free license to this software module or modifications thereof 97 for use in hardware or software products claiming conformance to the 98 MPEG-2 NBC/MPEG-4 Audio standards. Those intending to use this software 99 module in hardware or software products are advised that this use may 100 infringe existing patents. The original developer of this software 101 module and his/her company, the subsequent editors and their companies, 102 and ISO/IEC have no liability for use of this software module or 103 modifications thereof in an implementation. Copyright is not released 104 for non MPEG-2 NBC/MPEG-4 Audio conforming products.The original 105 developer retains full right to use the code for his/her own purpose, 106 assign or donate the code to a third party and to inhibit third party 107 from using the code for non MPEG-2 NBC/MPEG-4 Audio conforming products. 108 This copyright notice must be included in all copies or derivative 109 works." 110 Copyright(c)1996. 111 112 (2) ISO/IEC 14496-3: 1999(E) 113 Subpart 4 p15 (Table 4.4.11) 114 115------------------------------------------------------------------------------ 116 PSEUDO-CODE 117 118 CALL getbits( 119 LEN_F_CNT, 120 pInputStream); 121 MODIFYING (pInputStream) 122 RETURNING (cnt) 123 124 IF ( cnt == (1<<LEN_F_CNT)-1 ) 125 126 CALL getbits( 127 LEN_F_ESC, 128 pInputStream); 129 MODIFYING (pInputStream) 130 RETURNING (esc_cnt) 131 132 cnt += esc_cnt - 1; 133 134 ENDIF 135 136 pInputStream->usedBits += cnt * LEN_BYTE; 137 138------------------------------------------------------------------------------ 139 RESOURCES USED 140 When the code is written for a specific target processor the 141 the resources used should be documented below. 142 143 STACK USAGE: [stack count for this module] + [variable to represent 144 stack usage for each subroutine called] 145 146 where: [stack usage variable] = stack usage for [subroutine 147 name] (see [filename].ext) 148 149 DATA MEMORY USED: x words 150 151 PROGRAM MEMORY USED: x words 152 153 CLOCK CYCLES: [cycle count equation for this module] + [variable 154 used to represent cycle count for each subroutine 155 called] 156 157 where: [cycle count variable] = cycle count for [subroutine 158 name] (see [filename].ext) 159 160------------------------------------------------------------------------------ 161*/ 162 163/*---------------------------------------------------------------------------- 164; INCLUDES 165----------------------------------------------------------------------------*/ 166#include "pv_audio_type_defs.h" 167#include "s_bits.h" 168#include "ibstream.h" 169#include "e_rawbitstreamconst.h" 170#include "getfill.h" 171 172/*---------------------------------------------------------------------------- 173; MACROS 174; Define module specific macros here 175----------------------------------------------------------------------------*/ 176 177/*---------------------------------------------------------------------------- 178; DEFINES 179; Include all pre-processor statements here. Include conditional 180; compile variables also. 181----------------------------------------------------------------------------*/ 182 183/*---------------------------------------------------------------------------- 184; LOCAL FUNCTION DEFINITIONS 185; Function Prototype declaration 186----------------------------------------------------------------------------*/ 187 188/*---------------------------------------------------------------------------- 189; LOCAL VARIABLE DEFINITIONS 190; Variable declaration - defined here and used outside this module 191----------------------------------------------------------------------------*/ 192 193/*---------------------------------------------------------------------------- 194; EXTERNAL FUNCTION REFERENCES 195; Declare functions defined elsewhere and referenced in this module 196----------------------------------------------------------------------------*/ 197 198/*---------------------------------------------------------------------------- 199; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES 200; Declare variables used in this module but defined elsewhere 201----------------------------------------------------------------------------*/ 202 203/*---------------------------------------------------------------------------- 204; FUNCTION CODE 205----------------------------------------------------------------------------*/ 206 207void getfill(BITS *pInputStream) 208{ 209 /*---------------------------------------------------------------------------- 210 ; Define all local variables 211 ----------------------------------------------------------------------------*/ 212 Int cnt; 213 Int esc_cnt; 214 215 /*---------------------------------------------------------------------------- 216 ; Function body here 217 ----------------------------------------------------------------------------*/ 218 219 cnt = get9_n_lessbits( 220 LEN_F_CNT, 221 pInputStream); 222 223 if (cnt == (1 << LEN_F_CNT) - 1) /* if (cnt == 15) */ 224 { 225 esc_cnt = get9_n_lessbits( 226 LEN_F_ESC, 227 pInputStream); 228 229 cnt += esc_cnt - 1; 230 } 231 232 /* 233 * The following codes are replaced by directly updating usedBits 234 * in BITS structure. This will save one call for getbits(). 235 * 236 * for (i=0; i<cnt; i++) 237 * { getbits(LEN_BYTE, pInputStream); } 238 */ 239 240 pInputStream->usedBits += cnt * LEN_BYTE; 241 242 /*---------------------------------------------------------------------------- 243 ; Return nothing or data or data pointer 244 ----------------------------------------------------------------------------*/ 245 246} /* getfill */ 247 248