Line data Source code
1 : /*
2 : * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 : *
4 : * Use of this source code is governed by a BSD-style license
5 : * that can be found in the LICENSE file in the root of the source
6 : * tree. An additional intellectual property rights grant can be found
7 : * in the file PATENTS. All contributing project authors may
8 : * be found in the AUTHORS file in the root of the source tree.
9 : */
10 :
11 : #include "arith_routines.h"
12 : #include "settings.h"
13 :
14 :
15 : /*
16 : * terminate and return byte stream;
17 : * returns the number of bytes in the stream
18 : */
19 0 : int WebRtcIsac_EncTerminate(Bitstr *streamdata) /* in-/output struct containing bitstream */
20 : {
21 : uint8_t *stream_ptr;
22 :
23 :
24 : /* point to the right place in the stream buffer */
25 0 : stream_ptr = streamdata->stream + streamdata->stream_index;
26 :
27 : /* find minimum length (determined by current interval width) */
28 0 : if ( streamdata->W_upper > 0x01FFFFFF )
29 : {
30 0 : streamdata->streamval += 0x01000000;
31 : /* add carry to buffer */
32 0 : if (streamdata->streamval < 0x01000000)
33 : {
34 : /* propagate carry */
35 0 : while ( !(++(*--stream_ptr)) );
36 : /* put pointer back to the old value */
37 0 : stream_ptr = streamdata->stream + streamdata->stream_index;
38 : }
39 : /* write remaining data to bitstream */
40 0 : *stream_ptr++ = (uint8_t) (streamdata->streamval >> 24);
41 : }
42 : else
43 : {
44 0 : streamdata->streamval += 0x00010000;
45 : /* add carry to buffer */
46 0 : if (streamdata->streamval < 0x00010000)
47 : {
48 : /* propagate carry */
49 0 : while ( !(++(*--stream_ptr)) );
50 : /* put pointer back to the old value */
51 0 : stream_ptr = streamdata->stream + streamdata->stream_index;
52 : }
53 : /* write remaining data to bitstream */
54 0 : *stream_ptr++ = (uint8_t) (streamdata->streamval >> 24);
55 0 : *stream_ptr++ = (uint8_t) ((streamdata->streamval >> 16) & 0x00FF);
56 : }
57 :
58 : /* calculate stream length */
59 0 : return (int)(stream_ptr - streamdata->stream);
60 : }
|