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 INPUT AND OUTPUT DEFINITIONS 21 22 Inputs: 23 pInputStream = pointer to a BITS structure that holds information 24 regarding the input stream. 25 26 Local Stores/Buffers/Pointers Needed: 27 None 28 29 Global Stores/Buffers/Pointers Needed: 30 None 31 32 Outputs: 33 None 34 35 Pointers and Buffers Modified: 36 pInputStream->usedBits is rounded up to a number that represents the next 37 byte boundary. 38 39 Local Stores Modified: 40 None 41 42 Global Stores Modified: 43 None 44 45------------------------------------------------------------------------------ 46 FUNCTION DESCRIPTION 47 48 Adquire Data Stream element (DSE) from raw bitstream 49 At this time this function just drops the information. 50 51------------------------------------------------------------------------------ 52 REQUIREMENTS 53 54 This function shall not use global or static variables. 55 56------------------------------------------------------------------------------ 57 REFERENCES 58 59 (1) MPEG-2 NBC Audio Decoder 60 "This software module was originally developed by AT&T, Dolby 61 Laboratories, Fraunhofer Gesellschaft IIS in the course of development 62 of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and 63 3. This software module is an implementation of a part of one or more 64 MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 65 Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio 66 standards free license to this software module or modifications thereof 67 for use in hardware or software products claiming conformance to the 68 MPEG-2 NBC/MPEG-4 Audio standards. Those intending to use this software 69 module in hardware or software products are advised that this use may 70 infringe existing patents. The original developer of this software 71 module and his/her company, the subsequent editors and their companies, 72 and ISO/IEC have no liability for use of this software module or 73 modifications thereof in an implementation. Copyright is not released 74 for non MPEG-2 NBC/MPEG-4 Audio conforming products.The original 75 developer retains full right to use the code for his/her own purpose, 76 assign or donate the code to a third party and to inhibit third party 77 from using the code for non MPEG-2 NBC/MPEG-4 Audio conforming products. 78 This copyright notice must be included in all copies or derivative 79 works." 80 Copyright(c)1996. 81 82------------------------------------------------------------------------------ 83 PSEUDO-CODE 84 85void byte_align( 86 BITS *pInputStream) 87 88 MODIFYING(pInputStream->usedBits = pInputStream->usedBits + 89 (pInputStream->usedBits + 7) % 8) 90 91 RETURN(nothing) 92 93------------------------------------------------------------------------------ 94 RESOURCES USED 95 96 STACK USAGE: 97 98 where: 99 100 DATA MEMORY USED: x words 101 102 PROGRAM MEMORY USED: x words 103 104 CLOCK CYCLES: 105 106------------------------------------------------------------------------------ 107*/ 108 109 110/*---------------------------------------------------------------------------- 111; INCLUDES 112----------------------------------------------------------------------------*/ 113 114#include "pv_audio_type_defs.h" 115#include "get_dse.h" 116#include "ibstream.h" 117#include "getbits.h" 118#include "s_bits.h" 119 120 121/*---------------------------------------------------------------------------- 122; MACROS 123; Define module specific macros here 124----------------------------------------------------------------------------*/ 125 126/*---------------------------------------------------------------------------- 127; DEFINES 128; Include all pre-processor statements here. Include conditional 129; compile variables also. 130----------------------------------------------------------------------------*/ 131 132 133/*---------------------------------------------------------------------------- 134; LOCAL FUNCTION DEFINITIONS 135; Function Prototype declaration 136----------------------------------------------------------------------------*/ 137 138/*---------------------------------------------------------------------------- 139; LOCAL VARIABLE DEFINITIONS 140; Variable declaration - defined here and used outside this module 141----------------------------------------------------------------------------*/ 142 143/*---------------------------------------------------------------------------- 144; EXTERNAL FUNCTION REFERENCES 145; Declare functions defined elsewhere and referenced in this module 146----------------------------------------------------------------------------*/ 147 148/*---------------------------------------------------------------------------- 149; EXTERNAL VARIABLES REFERENCES 150; Declare variables used in this module but defined elsewhere 151----------------------------------------------------------------------------*/ 152 153/*---------------------------------------------------------------------------- 154; FUNCTION CODE 155----------------------------------------------------------------------------*/ 156 157void get_dse( 158 Char *DataStreamBytes, 159 BITS *pInputStream) 160{ 161 Int i; 162 Int data_byte_align_flag; 163 UInt count; 164 Int esc_count; 165 Char *pDataStreamBytes; 166 167 pDataStreamBytes = DataStreamBytes; 168 169 /* 170 * Get element instance tag ( 4 bits) 171 * ( max of 16 per raw data block) 172 */ 173 get9_n_lessbits(LEN_TAG, pInputStream); 174 175 /* 176 * get data_byte_align_flag ( 1 bit0 to see if byte alignment is 177 * performed within the DSE 178 */ 179 data_byte_align_flag = get1bits(pInputStream); 180 181 /* 182 * get count ( 8 bits) 183 */ 184 count = get9_n_lessbits(LEN_D_CNT, pInputStream); 185 186 /* 187 * if count == 255, its value it is incremented by a 188 * second 8 bit value, esc_count. This final value represents 189 * the number of bytes in the DSE 190 */ 191 if (count == (1 << LEN_D_CNT) - 1) 192 { 193 esc_count = (Int)get9_n_lessbits(LEN_D_ESC, pInputStream); /* 8 bits */ 194 count += esc_count; 195 } 196 197 /* 198 * Align if flag is set 199 */ 200 if (data_byte_align_flag) 201 { 202 byte_align(pInputStream); 203 } 204 205 for (i = count; i != 0; i--) 206 { 207 *(pDataStreamBytes++) = (Char) get9_n_lessbits( 208 LEN_BYTE, 209 pInputStream); 210 } 211 212 return; 213 214} /* end get_dse */ 215 216