2001-12-23 17:12:25 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "gstgetbits.h"
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
char *
|
|
|
|
print_bits (unsigned long bits, int size)
|
|
|
|
{
|
|
|
|
char *ret = (char *) malloc (size + 1);
|
2001-12-23 17:12:25 +00:00
|
|
|
int i;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2001-12-23 17:12:25 +00:00
|
|
|
ret[size] = 0;
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
if (bits & (1 << i))
|
|
|
|
ret[(size - 1) - i] = '1';
|
2001-12-23 17:12:25 +00:00
|
|
|
else
|
2004-03-13 15:27:01 +00:00
|
|
|
ret[(size - 1) - i] = '0';
|
2001-12-23 17:12:25 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static unsigned char testbuffer[] = {
|
|
|
|
0x11, 0x22, 0x44, 0x88, 0xCC, 0xEE, 0xFF, 0x11
|
2001-12-23 17:12:25 +00:00
|
|
|
};
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
void
|
|
|
|
empty (gst_getbits_t * gb, void *data)
|
|
|
|
{
|
|
|
|
printf ("buffer empty\n");
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_getbits_newbuf (gb, (unsigned char *) testbuffer, 7);
|
2001-12-23 17:12:25 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2001-12-23 17:12:25 +00:00
|
|
|
gst_getbits_t gb;
|
|
|
|
int i, j;
|
|
|
|
int bits;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_getbits_init (&gb, NULL, NULL);
|
|
|
|
gst_getbits_newbuf (&gb, (unsigned char *) testbuffer, 7);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < 7; i++) {
|
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
printf ("%lu", gst_getbits2 (&gb));
|
|
|
|
gst_backbitsn (&gb, 1);
|
2001-12-23 17:12:25 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
printf (" = %01x\n", testbuffer[i]);
|
2001-12-23 17:12:25 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_getbits_newbuf (&gb, (unsigned char *) testbuffer, 7);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
bits = gst_getbits8 (&gb);
|
|
|
|
printf ("%08x <-> 00000011 %lu\n", bits, gb.bits);
|
|
|
|
bits = gst_getbits8 (&gb);
|
|
|
|
printf ("%08x <-> 00000022 %lu\n", bits, gb.bits);
|
|
|
|
bits = gst_getbits8 (&gb);
|
|
|
|
printf ("%08x <-> 00000044 %lu\n", bits, gb.bits);
|
|
|
|
bits = gst_getbits8 (&gb);
|
|
|
|
printf ("%08x <-> 00000088 %lu\n", bits, gb.bits);
|
|
|
|
bits = gst_getbits6 (&gb);
|
|
|
|
printf ("%08x <-> 00000033 %lu\n", bits, gb.bits);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_backbitsn (&gb, 16);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
bits = gst_getbits10 (&gb);
|
|
|
|
printf ("%08x <-> 00000088 \n", bits);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_getbits_newbuf (&gb, (unsigned char *) testbuffer, 7);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
bits = gst_getbits8 (&gb);
|
|
|
|
printf ("%08x <-> 00000011 \n", bits);
|
|
|
|
bits = gst_getbits8 (&gb);
|
|
|
|
printf ("%08x <-> 00000022 \n", bits);
|
|
|
|
bits = gst_getbits8 (&gb);
|
|
|
|
printf ("%08x <-> 00000044 \n", bits);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
bits = gst_getbits6 (&gb);
|
|
|
|
printf ("%08x <-> 00000022 \n", bits);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_backbitsn (&gb, 19);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
bits = gst_getbits19 (&gb);
|
|
|
|
printf ("%08x <-> 00009122 \n", bits);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
bits = gst_getbits10 (&gb);
|
|
|
|
printf ("%08x <-> 000000cc \n", bits);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_backbitsn (&gb, 8);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_backbitsn (&gb, 19);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_backbitsn (&gb, 8);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
bits = gst_getbits19 (&gb);
|
|
|
|
printf ("%08x <-> 00012244 \n", bits);
|
|
|
|
bits = gst_getbits8 (&gb);
|
|
|
|
printf ("%08x <-> 00000088 \n", bits);
|
2001-12-23 17:12:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|