golomb-test.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <stdint.h>
22 #include <stdio.h>
23 
24 #include "libavutil/mem.h"
25 
26 #include "get_bits.h"
27 #include "golomb.h"
28 #include "put_bits.h"
29 
30 #define COUNT 8191
31 #define SIZE (COUNT * 4)
32 
33 int main(void)
34 {
35  int i, ret = 0;
36  uint8_t *temp;
37  PutBitContext pb;
38  GetBitContext gb;
39 
40  temp = av_malloc(SIZE);
41  if (!temp)
42  return 2;
43 
44  init_put_bits(&pb, temp, SIZE);
45  for (i = 0; i < COUNT; i++)
46  set_ue_golomb(&pb, i);
47  flush_put_bits(&pb);
48 
49  init_get_bits(&gb, temp, 8 * SIZE);
50  for (i = 0; i < COUNT; i++) {
51  int j, s = show_bits(&gb, 25);
52 
53  j = get_ue_golomb(&gb);
54  if (j != i) {
55  fprintf(stderr, "get_ue_golomb: expected %d, got %d. bits: %7x\n",
56  i, j, s);
57  ret = 1;
58  }
59  }
60 
61 #define EXTEND(i) (i << 3 | i & 7)
62  init_put_bits(&pb, temp, SIZE);
63  for (i = 0; i < COUNT; i++)
64  set_ue_golomb(&pb, EXTEND(i));
65  flush_put_bits(&pb);
66 
67  init_get_bits(&gb, temp, 8 * SIZE);
68  for (i = 0; i < COUNT; i++) {
69  int j, s = show_bits_long(&gb, 32);
70 
71  j = get_ue_golomb_long(&gb);
72  if (j != EXTEND(i)) {
73  fprintf(stderr, "get_ue_golomb_long: expected %d, got %d. "
74  "bits: %8x\n", EXTEND(i), j, s);
75  ret = 1;
76  }
77  }
78 
79  init_put_bits(&pb, temp, SIZE);
80  for (i = 0; i < COUNT; i++)
81  set_se_golomb(&pb, i - COUNT / 2);
82  flush_put_bits(&pb);
83 
84  init_get_bits(&gb, temp, 8 * SIZE);
85  for (i = 0; i < COUNT; i++) {
86  int j, s = show_bits(&gb, 25);
87 
88  j = get_se_golomb(&gb);
89  if (j != i - COUNT / 2) {
90  fprintf(stderr, "get_se_golomb: expected %d, got %d. bits: %7x\n",
91  i - COUNT / 2, j, s);
92  ret = 1;
93  }
94  }
95 
96  av_free(temp);
97 
98  return ret;
99 }
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition: get_bits.h:352
const char * s
Definition: avisynth_c.h:668
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
Definition: golomb.h:175
memory handling functions
else temp
Definition: vf_mcdeint.c:148
static void set_ue_golomb(PutBitContext *pb, int i)
write unsigned exp golomb code.
Definition: golomb.h:442
int main(void)
Definition: golomb-test.c:33
uint8_t
#define SIZE
Definition: golomb-test.c:31
bitstream reader API header.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
static int get_ue_golomb(GetBitContext *gb)
read unsigned exp golomb code.
Definition: golomb.h:53
#define COUNT
Definition: golomb-test.c:30
ret
Definition: avfilter.c:821
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:255
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
Definition: golomb.h:85
static void set_se_golomb(PutBitContext *pb, int i)
write signed exp golomb code.
Definition: golomb.h:476
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
synthesis window for stochastic i
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:379
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:81
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:54
exp golomb vlc stuff
#define EXTEND(i)
bitstream writer API