Imported Debian version 0.1.3.1
[deb_fdk-aac.git] / libFDK / include / FDK_bitstream.h
1
2 /* -----------------------------------------------------------------------------------------------------------
3 Software License for The Fraunhofer FDK AAC Codec Library for Android
4
5 © Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
6 All rights reserved.
7
8 1. INTRODUCTION
9 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
10 the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
11 This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
12
13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
14 audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
15 independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
16 of the MPEG specifications.
17
18 Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
19 may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
20 individually for the purpose of encoding or decoding bit streams in products that are compliant with
21 the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
22 these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
23 software may already be covered under those patent licenses when it is used for those licensed purposes only.
24
25 Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
26 are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
27 applications information and documentation.
28
29 2. COPYRIGHT LICENSE
30
31 Redistribution and use in source and binary forms, with or without modification, are permitted without
32 payment of copyright license fees provided that you satisfy the following conditions:
33
34 You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
35 your modifications thereto in source code form.
36
37 You must retain the complete text of this software license in the documentation and/or other materials
38 provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
39 You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
40 modifications thereto to recipients of copies in binary form.
41
42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without
43 prior written permission.
44
45 You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
46 software or your modifications thereto.
47
48 Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
49 and the date of any change. For modified versions of the FDK AAC Codec, the term
50 "Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
51 "Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
52
53 3. NO PATENT LICENSE
54
55 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
56 ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
57 respect to this software.
58
59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
60 by appropriate patent licenses.
61
62 4. DISCLAIMER
63
64 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
65 "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
66 of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
67 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
68 including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
69 or business interruption, however caused and on any theory of liability, whether in contract, strict
70 liability, or tort (including negligence), arising in any way out of the use of this software, even if
71 advised of the possibility of such damage.
72
73 5. CONTACT INFORMATION
74
75 Fraunhofer Institute for Integrated Circuits IIS
76 Attention: Audio and Multimedia Departments - FDK AAC LL
77 Am Wolfsmantel 33
78 91058 Erlangen, Germany
79
80 www.iis.fraunhofer.de/amm
81 amm-info@iis.fraunhofer.de
82 ----------------------------------------------------------------------------------------------------------- */
83
84 /*************************** Fraunhofer IIS FDK Tools ***********************
85
86 Author(s): M. Lohwasser
87 Description: bitstream interface to bitbuffer routines
88
89 ******************************************************************************/
90
91 #ifndef __FDK_BITSTREAM_H__
92 #define __FDK_BITSTREAM_H__
93
94
95
96 #include "FDK_bitbuffer.h"
97 #include "machine_type.h"
98
99 #include "genericStds.h"
100
101 #define CACHE_BITS 32
102
103 typedef enum {
104 BS_READER,
105 BS_WRITER
106 } FDK_BS_CFG;
107
108
109 typedef struct
110 {
111 UINT CacheWord ;
112 UINT BitsInCache ;
113 FDK_BITBUF hBitBuf;
114 UINT ConfigCache ;
115 } FDK_BITSTREAM;
116
117 typedef FDK_BITSTREAM* HANDLE_FDK_BITSTREAM;
118
119 /**
120 * \brief CreateBitStream Function.
121 *
122 * Create and initialize bitstream with extern allocated buffer.
123 *
124 * \param pBuffer Pointer to BitBuffer array.
125 * \param bufSize Length of BitBuffer array. (awaits size 2^n)
126 * \param config Initialize BitStream as Reader or Writer.
127 */
128 FDK_INLINE
129 HANDLE_FDK_BITSTREAM FDKcreateBitStream (UCHAR *pBuffer,
130 UINT bufSize,
131 FDK_BS_CFG config = BS_READER)
132 {
133 HANDLE_FDK_BITSTREAM hBitStream = (HANDLE_FDK_BITSTREAM) FDKcalloc(1, sizeof(FDK_BITSTREAM));
134 FDK_InitBitBuffer(&hBitStream->hBitBuf, pBuffer, bufSize, 0) ;
135
136 /* init cache */
137 hBitStream->CacheWord = hBitStream->BitsInCache = 0 ;
138 hBitStream->ConfigCache = config ;
139
140 return hBitStream ;
141 }
142
143
144 /**
145 * \brief Initialize BistreamBuffer. BitBuffer can point to filled BitBuffer array .
146 *
147 * \param hBitStream HANDLE_FDK_BITSTREAM handle
148 * \param pBuffer Pointer to BitBuffer array.
149 * \param bufSize Length of BitBuffer array. (awaits size 2^n)
150 * \param validBits Number of valid BitBuffer filled Bits.
151 * \param config Initialize BitStream as Reader or Writer.
152 * \return void
153 */
154 FDK_INLINE
155 void FDKinitBitStream (HANDLE_FDK_BITSTREAM hBitStream,
156 UCHAR *pBuffer,
157 UINT bufSize,
158 UINT validBits,
159 FDK_BS_CFG config = BS_READER)
160 {
161 FDK_InitBitBuffer(&hBitStream->hBitBuf, pBuffer, bufSize, validBits) ;
162
163 /* init cache */
164 hBitStream->CacheWord = hBitStream->BitsInCache = 0 ;
165 hBitStream->ConfigCache = config ;
166 }
167
168
169 /**
170 * \brief ResetBitbuffer Function. Reset states in BitBuffer and Cache.
171 *
172 * \param hBitStream HANDLE_FDK_BITSTREAM handle
173 * \param config Initialize BitStream as Reader or Writer.
174 * \return void
175 */
176 FDK_INLINE void FDKresetBitbuffer( HANDLE_FDK_BITSTREAM hBitStream, FDK_BS_CFG config = BS_READER)
177 {
178 FDK_ResetBitBuffer( &hBitStream->hBitBuf ) ;
179
180 /* init cache */
181 hBitStream->CacheWord = hBitStream->BitsInCache = 0 ;
182 hBitStream->ConfigCache = config ;
183 }
184
185
186 /** DeleteBitStream.
187
188 Deletes the in Create Bitstream allocated BitStream and BitBuffer.
189 */
190 FDK_INLINE void FDKdeleteBitStream (HANDLE_FDK_BITSTREAM hBitStream)
191 {
192 FDK_DeleteBitBuffer(&hBitStream->hBitBuf) ;
193 FDKfree(hBitStream) ;
194 }
195
196
197 /**
198 * \brief ReadBits Function (forward). This function returns a number of sequential
199 * bits from the input bitstream.
200 *
201 * \param hBitStream HANDLE_FDK_BITSTREAM handle
202 * \param numberOfBits The number of bits to be retrieved.
203 * \return the requested bits, right aligned
204 * \return
205 */
206 #define OPTIMIZE_FDKREADBITS
207
208 FDK_INLINE UINT FDKreadBits(HANDLE_FDK_BITSTREAM hBitStream,
209 const UINT numberOfBits)
210 {
211 #ifdef noOPTIMIZE_FDKREADBITS
212 INT missingBits = numberOfBits - hBitStream->BitsInCache;
213 if (missingBits > 0)
214 {
215 UINT bits = hBitStream->CacheWord << missingBits;
216 hBitStream->CacheWord = FDK_get32 (&hBitStream->hBitBuf) ;
217 hBitStream->BitsInCache = CACHE_BITS - missingBits;
218 return ( bits | (hBitStream->CacheWord >> hBitStream->BitsInCache)) & BitMask[numberOfBits];
219 }
220
221 hBitStream->BitsInCache -= numberOfBits;
222 return ( hBitStream->CacheWord >> hBitStream->BitsInCache) & BitMask[numberOfBits];
223
224 #else
225 const UINT validMask = BitMask [numberOfBits] ;
226
227 if (hBitStream->BitsInCache <= numberOfBits)
228 {
229 const INT freeBits = (CACHE_BITS-1) - hBitStream->BitsInCache ;
230
231 hBitStream->CacheWord = (hBitStream->CacheWord << freeBits) | FDK_get (&hBitStream->hBitBuf,freeBits) ;
232 hBitStream->BitsInCache += freeBits ;
233 }
234
235 hBitStream->BitsInCache -= numberOfBits ;
236
237 return (hBitStream->CacheWord >> hBitStream->BitsInCache) & validMask ;
238 #endif
239 }
240
241 FDK_INLINE UINT FDKreadBit(HANDLE_FDK_BITSTREAM hBitStream)
242 {
243 #ifdef OPTIMIZE_FDKREADBITS
244 if (!hBitStream->BitsInCache)
245 {
246 hBitStream->CacheWord = FDK_get32 (&hBitStream->hBitBuf);
247 hBitStream->BitsInCache = CACHE_BITS;
248 }
249 hBitStream->BitsInCache--;
250
251 return (hBitStream->CacheWord >> hBitStream->BitsInCache) & 1;
252 #else
253 return FDKreadBits(hBitStream,1);
254 #endif
255 }
256
257 /**
258 * \brief Read2Bits Function (forward). This function 2 sequential
259 * bits from the input bitstream. It is the optimized version
260 of FDKreadBits() for readign 2 bits.
261 *
262 * \param hBitStream HANDLE_FDK_BITSTREAM handle
263 * \return the requested bits, right aligned
264 * \return
265 */
266 inline UINT FDKread2Bits(HANDLE_FDK_BITSTREAM hBitStream)
267 {
268 UINT BitsInCache = hBitStream->BitsInCache;
269 if (BitsInCache < 2) /* Comparison changed from 'less-equal' to 'less' */
270 {
271 const INT freeBits = (CACHE_BITS-1) - BitsInCache ;
272
273 hBitStream->CacheWord = (hBitStream->CacheWord << freeBits) | FDK_get (&hBitStream->hBitBuf,freeBits) ;
274 BitsInCache += freeBits;
275 }
276 hBitStream->BitsInCache = BitsInCache - 2;
277 return (hBitStream->CacheWord >> hBitStream->BitsInCache) & 0x3;
278 }
279
280 /**
281 * \brief ReadBits Function (backward). This function returns a number of sequential bits
282 * from the input bitstream.
283 *
284 * \param hBitStream HANDLE_FDK_BITSTREAM handle
285 * \param numberOfBits The number of bits to be retrieved.
286 * \return the requested bits, right aligned
287 */
288 FDK_INLINE UINT FDKreadBitsBwd(HANDLE_FDK_BITSTREAM hBitStream,
289 const UINT numberOfBits)
290 {
291 const UINT validMask = BitMask [numberOfBits] ;
292
293 if (hBitStream->BitsInCache <= numberOfBits)
294 {
295 const INT freeBits = (CACHE_BITS-1) - hBitStream->BitsInCache ;
296
297 hBitStream->CacheWord = (hBitStream->CacheWord << freeBits) | FDK_getBwd (&hBitStream->hBitBuf,freeBits) ;
298 hBitStream->BitsInCache += freeBits ;
299 }
300
301 hBitStream->BitsInCache -= numberOfBits ;
302
303 return (hBitStream->CacheWord >> hBitStream->BitsInCache) & validMask ;
304 }
305
306
307 /**
308 * \brief return a number of bits from the bitBuffer.
309 * You have to know what you do! Cache has to be synchronized before using this
310 * function.
311 *
312 * \param hBitStream HANDLE_FDK_BITSTREAM handle
313 * \param numBits The number of bits to be retrieved.
314 * \return the requested bits, right aligned
315 */
316 FDK_INLINE UINT FDKgetBits (HANDLE_FDK_BITSTREAM hBitStream, UINT numBits)
317 {
318 return FDK_get (&hBitStream->hBitBuf, numBits) ;
319 }
320
321
322 /**
323 * \brief WriteBits Function. This function writes numberOfBits of value into bitstream.
324 *
325 * \param hBitStream HANDLE_FDK_BITSTREAM handle
326 * \param value Variable holds data to be written.
327 * \param numberOfBits The number of bits to be written.
328 * \return number of bits written
329 */
330 FDK_INLINE UCHAR FDKwriteBits(HANDLE_FDK_BITSTREAM hBitStream, UINT value,
331 const UINT numberOfBits)
332 {
333 const UINT validMask = BitMask [numberOfBits] ;
334
335 if ((hBitStream->BitsInCache+numberOfBits) < CACHE_BITS)
336 {
337 hBitStream->BitsInCache += numberOfBits ;
338 hBitStream->CacheWord = (hBitStream->CacheWord << numberOfBits) | (value & validMask);
339 }
340 else
341 {
342 FDK_put(&hBitStream->hBitBuf, hBitStream->CacheWord, hBitStream->BitsInCache) ;
343 hBitStream->BitsInCache = numberOfBits ;
344 hBitStream->CacheWord = (value & validMask) ;
345 }
346
347 return numberOfBits;
348 }
349
350
351 /**
352 * \brief WriteBits Function (backward). This function writes numberOfBits of value into bitstream.
353 *
354 * \param hBitStream HANDLE_FDK_BITSTREAM handle
355 * \param value Variable holds data to be written.
356 * \param numberOfBits The number of bits to be written.
357 * \return number of bits written
358 */
359 FDK_INLINE UCHAR FDKwriteBitsBwd(HANDLE_FDK_BITSTREAM hBitStream, UINT value,
360 const UINT numberOfBits)
361 {
362 const UINT validMask = BitMask [numberOfBits] ;
363
364 if ((hBitStream->BitsInCache+numberOfBits) <= CACHE_BITS)
365 {
366 hBitStream->BitsInCache += numberOfBits ;
367 hBitStream->CacheWord = (hBitStream->CacheWord << numberOfBits) | (value & validMask);
368 }
369 else
370 {
371 FDK_putBwd(&hBitStream->hBitBuf, hBitStream->CacheWord, hBitStream->BitsInCache) ;
372 hBitStream->BitsInCache = numberOfBits ;
373 hBitStream->CacheWord = (value & validMask) ;
374 }
375
376 return numberOfBits;
377 }
378
379
380 /**
381 * \brief SyncCache Function. Clear cache after read forward.
382 *
383 * \param hBitStream HANDLE_FDK_BITSTREAM handle
384 * \return void
385 */
386 FDK_INLINE void FDKsyncCache (HANDLE_FDK_BITSTREAM hBitStream)
387 {
388 if (hBitStream->ConfigCache == BS_READER)
389 FDK_pushBack (&hBitStream->hBitBuf,hBitStream->BitsInCache,hBitStream->ConfigCache) ;
390 else /* BS_WRITER */
391 FDK_put(&hBitStream->hBitBuf, hBitStream->CacheWord, hBitStream->BitsInCache) ;
392
393 hBitStream->BitsInCache = 0 ;
394 hBitStream->CacheWord = 0 ;
395 }
396
397
398 /**
399 * \brief SyncCache Function. Clear cache after read backwards.
400 *
401 * \param hBitStream HANDLE_FDK_BITSTREAM handle
402 * \return void
403 */
404 FDK_INLINE void FDKsyncCacheBwd (HANDLE_FDK_BITSTREAM hBitStream)
405 {
406 if (hBitStream->ConfigCache == BS_READER) {
407 FDK_pushForward (&hBitStream->hBitBuf,hBitStream->BitsInCache,hBitStream->ConfigCache) ;
408 } else { /* BS_WRITER */
409 FDK_putBwd (&hBitStream->hBitBuf, hBitStream->CacheWord, hBitStream->BitsInCache) ;
410 }
411
412 hBitStream->BitsInCache = 0 ;
413 hBitStream->CacheWord = 0 ;
414 }
415
416
417 /**
418 * \brief Byte Alignment Function.
419 * This function performs the byte_alignment() syntactic function on the input stream,
420 * i.e. some bits will be discarded/padded so that the next bits to be read/written will
421 * be aligned on a byte boundary with respect to the bit position 0.
422 *
423 * \param hBitStream HANDLE_FDK_BITSTREAM handle
424 * \return void
425 */
426 FDK_INLINE void FDKbyteAlign (HANDLE_FDK_BITSTREAM hBitStream)
427 {
428 FDKsyncCache (hBitStream) ;
429 FDK_byteAlign (&hBitStream->hBitBuf, (UCHAR)hBitStream->ConfigCache) ;
430 }
431
432
433 /**
434 * \brief Byte Alignment Function with anchor
435 * This function performs the byte_alignment() syntactic function on the input stream,
436 * i.e. some bits will be discarded so that the next bits to be read/written would be aligned
437 * on a byte boundary with respect to the given alignment anchor.
438 *
439 * \param hBitStream HANDLE_FDK_BITSTREAM handle
440 * \param alignmentAnchor bit position to be considered as origin for byte alignment
441 * \return void
442 */
443 FDK_INLINE void FDKbyteAlign (HANDLE_FDK_BITSTREAM hBitStream, UINT alignmentAnchor)
444 {
445 FDKsyncCache (hBitStream) ;
446 if (hBitStream->ConfigCache == BS_READER) {
447 FDK_pushForward (&hBitStream->hBitBuf,
448 (8 - ((alignmentAnchor - FDK_getValidBits(&hBitStream->hBitBuf)) & 0x07)) & 0x07,
449 hBitStream->ConfigCache) ;
450 }
451 else {
452 FDK_put (&hBitStream->hBitBuf,
453 0,
454 (8 - ((FDK_getValidBits(&hBitStream->hBitBuf)-alignmentAnchor) & 0x07)) & 0x07 );
455 }
456 }
457
458
459 /**
460 * \brief Push Back(Cache) / For / BiDirectional Function.
461 * PushBackCache function ungets a number of bits erroneously read/written by the last Get() call.
462 * NB: The number of bits to be stuffed back into the stream may never exceed the
463 * number of bits returned by the immediately preceding Get() call.
464 *
465 * PushBack function ungets a number of bits (combines cache and bitbuffer indices)
466 * PushFor function gets a number of bits (combines cache and bitbuffer indices)
467 * PushBiDirectional gets/ungets number of bits as defined in PusBack/For function
468 * NB: The sign of bits is not known, so the function checks direction and calls
469 * appropriate function. (positive sign pushFor, negative sign pushBack )
470 *
471 * \param hBitStream HANDLE_FDK_BITSTREAM handle
472 * \param numberOfBits The number of bits to be pushed back/for.
473 * \return void
474 */
475 FDK_INLINE void FDKpushBackCache (HANDLE_FDK_BITSTREAM hBitStream, const UINT numberOfBits)
476 {
477 FDK_ASSERT ((hBitStream->BitsInCache+numberOfBits)<=CACHE_BITS);
478 hBitStream->BitsInCache += numberOfBits ;
479 }
480
481 FDK_INLINE void FDKpushBack (HANDLE_FDK_BITSTREAM hBitStream, const UINT numberOfBits)
482 {
483 if ((hBitStream->BitsInCache+numberOfBits)<CACHE_BITS && (hBitStream->ConfigCache == BS_READER) ) {
484 hBitStream->BitsInCache += numberOfBits ;
485 FDKsyncCache(hBitStream) ; /* sync cache to avoid invalid cache */
486 }
487 else {
488 FDKsyncCache(hBitStream) ;
489 FDK_pushBack(&hBitStream->hBitBuf,numberOfBits,hBitStream->ConfigCache);
490 }
491 }
492
493 FDK_INLINE void FDKpushFor (HANDLE_FDK_BITSTREAM hBitStream, const UINT numberOfBits)
494 {
495 if ( (hBitStream->BitsInCache>numberOfBits) && (hBitStream->ConfigCache == BS_READER) ) {
496 hBitStream->BitsInCache -= numberOfBits;
497 }
498 else {
499 FDKsyncCache(hBitStream) ;
500 FDK_pushForward(&hBitStream->hBitBuf,numberOfBits,hBitStream->ConfigCache);
501 }
502 }
503
504 FDK_INLINE void FDKpushBiDirectional (HANDLE_FDK_BITSTREAM hBitStream, const INT numberOfBits)
505 {
506 if(numberOfBits>=0) FDKpushFor(hBitStream, numberOfBits) ;
507 else FDKpushBack(hBitStream, -numberOfBits) ;
508 }
509
510
511 /**
512 * \brief GetValidBits Function. Clear cache and return valid Bits from Bitbuffer.
513 * \param hBitStream HANDLE_FDK_BITSTREAM handle
514 * \return amount of valid bits that still can be read or were already written.
515 *
516 */
517 FDK_INLINE UINT FDKgetValidBits (HANDLE_FDK_BITSTREAM hBitStream)
518 {
519 FDKsyncCache(hBitStream) ;
520 return FDK_getValidBits(&hBitStream->hBitBuf) ;
521 }
522
523
524 /**
525 * \brief return amount of unused Bits from Bitbuffer.
526 * \param hBitStream HANDLE_FDK_BITSTREAM handle
527 * \return amount of free bits that still can be written into the bitstream
528 */
529 FDK_INLINE INT FDKgetFreeBits (HANDLE_FDK_BITSTREAM hBitStream)
530 {
531 return FDK_getFreeBits (&hBitStream->hBitBuf) ;
532 }
533
534 /**
535 * \brief reset bitcounter in bitBuffer to zero.
536 * \param hBitStream HANDLE_FDK_BITSTREAM handle
537 * \return void
538 */
539 FDK_INLINE void FDKresetBitCnt (HANDLE_FDK_BITSTREAM hBitStream)
540 {
541 FDKsyncCache (hBitStream) ;
542 FDK_setBitCnt (&hBitStream->hBitBuf, 0) ;
543 }
544
545 /**
546 * \brief set bitcoutner in bitBuffer to given value.
547 * \param hBitStream HANDLE_FDK_BITSTREAM handle
548 * \param value new value to be assigned to the bit counter
549 * \return void
550 */
551 FDK_INLINE void FDKsetBitCnt (HANDLE_FDK_BITSTREAM hBitStream, UINT value)
552 {
553 FDKsyncCache (hBitStream) ;
554 FDK_setBitCnt (&hBitStream->hBitBuf, value) ;
555 }
556
557 /**
558 * \brief get bitcounter state from bitBuffer.
559 * \param hBitStream HANDLE_FDK_BITSTREAM handle
560 * \return current bit counter value
561 */
562 FDK_INLINE INT FDKgetBitCnt (HANDLE_FDK_BITSTREAM hBitStream)
563 {
564 FDKsyncCache(hBitStream) ;
565 return FDK_getBitCnt(&hBitStream->hBitBuf) ;
566 }
567
568
569 /**
570 * \brief Fill the BitBuffer with a number of input bytes from external source.
571 * The bytesValid variable returns the number of ramaining valid bytes in extern inputBuffer.
572 *
573 * \param hBitStream HANDLE_FDK_BITSTREAM handle
574 * \param inputBuffer Pointer to input buffer with bitstream data.
575 * \param bufferSize Total size of inputBuffer array.
576 * \param bytesValid Input: number of valid bytes in inputBuffer. Output: bytes still left unread in inputBuffer.
577 * \return void
578 */
579 FDK_INLINE void FDKfeedBuffer (HANDLE_FDK_BITSTREAM hBitStream, const UCHAR inputBuffer [], const UINT bufferSize, UINT *bytesValid)
580 {
581 FDKsyncCache (hBitStream) ;
582 FDK_Feed(&hBitStream->hBitBuf, (UCHAR*)inputBuffer, bufferSize, bytesValid ) ;
583 }
584
585
586 /**
587 * \brief fill destination BitBuffer with a number of bytes from source BitBuffer. The
588 * bytesValid variable returns the number of ramaining valid bytes in source BitBuffer.
589 *
590 * \param hBSDst HANDLE_FDK_BITSTREAM handle to write data into
591 * \param hBSSrc HANDLE_FDK_BITSTREAM handle to read data from
592 * \param bytesValid Input: number of valid bytes in inputBuffer. Output: bytes still left unread in inputBuffer.
593 * \return void
594 */
595 FDK_INLINE void FDKcopyBuffer (HANDLE_FDK_BITSTREAM hBSDst, HANDLE_FDK_BITSTREAM hBSSrc, UINT *bytesValid)
596 {
597 FDKsyncCache (hBSSrc) ;
598 FDK_Copy (&hBSDst->hBitBuf, &hBSSrc->hBitBuf, bytesValid) ;
599 }
600
601
602 /**
603 * \brief fill the outputBuffer with all valid bytes hold in BitBuffer. The WriteBytes
604 * variable returns the number of written Bytes.
605 *
606 * \param hBitStream HANDLE_FDK_BITSTREAM handle
607 * \param outputBuffer Pointer to output buffer.
608 * \param writeBytes Number of bytes write to output buffer.
609 * \return void
610 */
611 FDK_INLINE void FDKfetchBuffer(HANDLE_FDK_BITSTREAM hBitStream, UCHAR *outputBuffer, UINT *writeBytes)
612 {
613 FDKsyncCache (hBitStream) ;
614 FDK_Fetch(&hBitStream->hBitBuf, outputBuffer, writeBytes);
615 }
616
617
618 #endif