mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 11:41:09 +00:00
moving libs around
Original commit message from CVS: moving libs around
This commit is contained in:
parent
b9f6bb9c0e
commit
be277c79e0
11 changed files with 1206 additions and 2 deletions
|
@ -1,3 +1,3 @@
|
|||
SUBDIRS = bytestream
|
||||
SUBDIRS = bytestream control getbits putbits
|
||||
|
||||
DIST_SUBDIRS = bytestream
|
||||
DIST_SUBDIRS = bytestream control getbits putbits
|
||||
|
|
22
libs/gst/getbits/Makefile.am
Normal file
22
libs/gst/getbits/Makefile.am
Normal file
|
@ -0,0 +1,22 @@
|
|||
librarydir = $(libdir)/gst
|
||||
|
||||
library_LTLIBRARIES = libgstgetbits.la
|
||||
|
||||
if HAVE_CPU_I386
|
||||
GSTARCH_SRCS = gstgetbits_i386.s
|
||||
else
|
||||
GSTARCH_SRCS =
|
||||
endif
|
||||
|
||||
libgstgetbits_la_SOURCES = getbits.c gstgetbits_inl.h gstgetbits_generic.c $(GSTARCH_SRCS)
|
||||
libgstgetbits_la_LIBADD = $(GST_LIBS)
|
||||
libgstgetbits_la_CFLAGS = $(GST_CFLAGS) -funroll-all-loops -finline-functions -ffast-math
|
||||
EXTRA_libgstgetbits_la_SOURCES = gstgetbits_i386.s
|
||||
|
||||
libgstgetbitsincludedir = $(includedir)/gst/getbits
|
||||
libgstgetbitsinclude_HEADERS = getbits.h
|
||||
|
||||
noinst_HEADERS = getbits.h gstgetbits_inl.h
|
||||
|
||||
# check_PROGRAMS = gbtest
|
||||
|
94
libs/gst/getbits/gbtest.c
Normal file
94
libs/gst/getbits/gbtest.c
Normal file
|
@ -0,0 +1,94 @@
|
|||
#include <stdlib.h>
|
||||
#include "gstgetbits.h"
|
||||
|
||||
char *print_bits(unsigned long bits,int size) {
|
||||
char *ret = (char *)malloc(size+1);
|
||||
int i;
|
||||
ret[size] = 0;
|
||||
for (i=0;i<size;i++) {
|
||||
if (bits & (1<<i))
|
||||
ret[(size-1)-i] = '1';
|
||||
else
|
||||
ret[(size-1)-i] = '0';
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static unsigned char testbuffer[] =
|
||||
{
|
||||
0x11, 0x22, 0x44, 0x88, 0xCC, 0xEE,0xFF,0x11
|
||||
};
|
||||
|
||||
void empty(gst_getbits_t *gb, void *data) {
|
||||
printf("buffer empty\n");
|
||||
|
||||
gst_getbits_newbuf(gb,(unsigned char *)testbuffer, 7);
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[]) {
|
||||
gst_getbits_t gb;
|
||||
int i, j;
|
||||
int bits;
|
||||
|
||||
gst_getbits_init(&gb, NULL, NULL);
|
||||
gst_getbits_newbuf(&gb,(unsigned char *)testbuffer, 7);
|
||||
|
||||
for (i=0;i<7;i++) {
|
||||
for (j=0;j<8;j++) {
|
||||
printf("%lu",gst_getbits2(&gb));
|
||||
gst_backbitsn(&gb, 1);
|
||||
}
|
||||
printf(" = %01x\n", testbuffer[i]);
|
||||
}
|
||||
|
||||
gst_getbits_newbuf(&gb,(unsigned char *)testbuffer, 7);
|
||||
|
||||
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);
|
||||
|
||||
gst_backbitsn(&gb, 16);
|
||||
|
||||
bits = gst_getbits10(&gb);
|
||||
printf("%08x <-> 00000088 \n",bits);
|
||||
|
||||
gst_getbits_newbuf(&gb,(unsigned char *)testbuffer, 7);
|
||||
|
||||
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);
|
||||
|
||||
bits = gst_getbits6(&gb);
|
||||
printf("%08x <-> 00000022 \n",bits);
|
||||
|
||||
gst_backbitsn(&gb, 19);
|
||||
|
||||
bits = gst_getbits19(&gb);
|
||||
printf("%08x <-> 00009122 \n",bits);
|
||||
|
||||
bits = gst_getbits10(&gb);
|
||||
printf("%08x <-> 000000cc \n",bits);
|
||||
|
||||
gst_backbitsn(&gb, 8);
|
||||
|
||||
gst_backbitsn(&gb, 19);
|
||||
|
||||
gst_backbitsn(&gb, 8);
|
||||
|
||||
bits = gst_getbits19(&gb);
|
||||
printf("%08x <-> 00012244 \n",bits);
|
||||
bits = gst_getbits8(&gb);
|
||||
printf("%08x <-> 00000088 \n",bits);
|
||||
|
||||
return 0;
|
||||
}
|
214
libs/gst/getbits/getbits.c
Normal file
214
libs/gst/getbits/getbits.c
Normal file
|
@ -0,0 +1,214 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include "gstgetbits.h"
|
||||
|
||||
/* Defined in gstgetbits_i386.s */
|
||||
extern unsigned long _gst_get1bit_i386(gst_getbits_t *gb, unsigned long bits);
|
||||
extern unsigned long _gst_getbits_i386(gst_getbits_t *gb, unsigned long bits);
|
||||
extern unsigned long _gst_getbits_fast_i386(gst_getbits_t *gb, unsigned long bits);
|
||||
extern unsigned long _gst_showbits_i386(gst_getbits_t *gb, unsigned long bits);
|
||||
extern void _gst_flushbits_i386(gst_getbits_t *gb, unsigned long bits);
|
||||
extern void _gst_getbits_back_i386(gst_getbits_t *gb, unsigned long bits);
|
||||
|
||||
/* Defined in gstgetbits_generic.c */
|
||||
extern unsigned long _gst_getbits_int_cb(gst_getbits_t *gb, unsigned long bits);
|
||||
extern unsigned long _gst_get1bit_int(gst_getbits_t *gb, unsigned long bits);
|
||||
extern unsigned long _gst_getbits_int(gst_getbits_t *gb, unsigned long bits);
|
||||
extern unsigned long _gst_getbits_fast_int(gst_getbits_t *gb, unsigned long bits);
|
||||
extern unsigned long _gst_showbits_int(gst_getbits_t *gb, unsigned long bits);
|
||||
extern void _gst_flushbits_int(gst_getbits_t *gb, unsigned long bits);
|
||||
extern void _gst_getbits_back_int(gst_getbits_t *gb, unsigned long bits);
|
||||
|
||||
|
||||
unsigned long gst_getbits_nBitMask[] = {
|
||||
0x00000000, 0x80000000, 0xc0000000, 0xe0000000,
|
||||
0xf0000000, 0xf8000000, 0xfc000000, 0xfe000000,
|
||||
0xff000000, 0xff800000, 0xffc00000, 0xffe00000,
|
||||
0xfff00000, 0xfff80000, 0xfffc0000, 0xfffe0000,
|
||||
0xffff0000, 0xffff8000, 0xffffc000, 0xffffe000,
|
||||
0xfffff000, 0xfffff800, 0xfffffc00, 0xfffffe00,
|
||||
0xffffff00, 0xffffff80, 0xffffffc0, 0xffffffe0,
|
||||
0xfffffff0, 0xfffffff8, 0xfffffffc, 0xfffffffe};
|
||||
|
||||
unsigned long _getbits_masks[] = {
|
||||
0x00000000,
|
||||
0x00000001, 0x00000003, 0x00000007, 0x0000000f,
|
||||
0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
|
||||
0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff,
|
||||
0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff,
|
||||
0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff,
|
||||
0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff,
|
||||
0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff,
|
||||
0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff,
|
||||
};
|
||||
|
||||
#ifdef HAVE_LIBMMX
|
||||
unsigned long _getbits_64_minus_index[] = {
|
||||
64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,
|
||||
40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,
|
||||
16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1 };
|
||||
|
||||
/* this routine taken from Intel AppNote AP-527:
|
||||
"Using MMX[tm] Instructions to Get Bits From a Data Stream"
|
||||
written in C with libmmx to *closely* mimic Intel's ASM implementation
|
||||
|
||||
this isn't as cycle-efficient, due to the simple fact that I must call
|
||||
emms() at the end. all state must be kept in *gb, not in registers */
|
||||
unsigned long _gst_getbits_mmx(gst_getbits_t *gb,unsigned long bits) {
|
||||
signed long remaining;
|
||||
unsigned long result;
|
||||
|
||||
/* NOTE: this is a code-size optimization Intel seems to have missed!
|
||||
according to the MMX Programmer's Reference Manual, Chapter 5,
|
||||
neither movd nor movq have any effect on the flags. that means you
|
||||
can put them before the sub and jl in their code, which I've done
|
||||
symbolically in this C code. gcc is probably going to lose horribly,
|
||||
I'll do an inline asm version later. I've a point to prove ;-) */
|
||||
/* find the right shift value, put it in mm3 */
|
||||
movd_m2r(_getbits_64_minus_index[bits],mm3);
|
||||
/* load the current quadword into mm0 */
|
||||
movq_m2r(gb->qword,mm0);
|
||||
/* copy it to mm2 */
|
||||
movq_r2r(mm0,mm2);
|
||||
|
||||
remaining = gb->bits - bits;
|
||||
|
||||
if (remaining <= 0) {
|
||||
unsigned long dword1,dword2;
|
||||
|
||||
/* shift the pointer by 64 bits (8 bytes) */
|
||||
gb->ptr += 8;
|
||||
/* add 64 to bits remaining, to bring it positive */
|
||||
remaining += 64;
|
||||
|
||||
/* grab the first 32 bits from the buffer and swap them around */
|
||||
dword1 = swab32(*(gb->ptr-8));
|
||||
/* grab the second 32 bits, swap */
|
||||
dword2 = swab32(*(gb->ptr-4));
|
||||
|
||||
/* put second dword in mm4 */
|
||||
movd_m2r(dword2,mm4);
|
||||
/* shift mm2 over to make room for new bits */
|
||||
psrlq_r2r(mm3,mm2);
|
||||
|
||||
/* put first dword in mm1 */
|
||||
movd_m2r(dword1,mm1);
|
||||
/* shift second dword up 32 bits */
|
||||
psrlq_i2r(32,mm4);
|
||||
|
||||
/* put the shift counter in mm3 */
|
||||
movd_m2r(remaining,mm3);
|
||||
/* combine the swapped data in mm4 */
|
||||
por_r2r(mm1,mm4);
|
||||
|
||||
/* save off the bits in mm4 to mm0 */
|
||||
movq_r2r(mm4,mm0);
|
||||
/* get the new low-order bits in mm4, shifted by 'mm3' */
|
||||
psrlq_r2r(mm3,mm4);
|
||||
|
||||
/* save off new remaining bits */
|
||||
gb->bits = remaining;
|
||||
/* combine bits into mm2 */
|
||||
por_r2r(mm2,mm4);
|
||||
|
||||
/* save off the result */
|
||||
movd_r2m(mm2,result);
|
||||
/* get rid of the bits we just read */
|
||||
psllq_r2r(mm1,mm0);
|
||||
|
||||
/* save off mm0 */
|
||||
movq_r2m(mm0,gb->qword);
|
||||
|
||||
/* finished with MMX */
|
||||
emms();
|
||||
|
||||
/* we have what we came for */
|
||||
return(result);
|
||||
} else {
|
||||
/* load the number of bits requested into mm1 */
|
||||
movd_m2r(bits,mm1);
|
||||
/* shift the quadword in mm2 by 'mm3' bits */
|
||||
psrlq_r2r(mm3,mm2);
|
||||
|
||||
/* update the number of valid bits */
|
||||
gb->bits = remaining;
|
||||
|
||||
/* save off the remaining bits */
|
||||
movd_r2m(mm2,result);
|
||||
/* discard those bits in mm0 */
|
||||
psllq_r2r(mm1,mm0);
|
||||
|
||||
/* save off mm0 */
|
||||
movq_r2m(mm0,gb->qword);
|
||||
/* finished with MMX */
|
||||
emms();
|
||||
|
||||
/* we have what we came for */
|
||||
return(result);
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_LIBMMX */
|
||||
|
||||
unsigned long _gst_getbyte(gst_getbits_t *gb, unsigned long bits) {
|
||||
return *gb->ptr++;
|
||||
}
|
||||
|
||||
/* initialize the getbits structure with the proper getbits func */
|
||||
void gst_getbits_init(gst_getbits_t *gb, GstGetbitsCallback callback, void *data) {
|
||||
gb->ptr = NULL;
|
||||
gb->bits = 0;
|
||||
gb->callback = callback;
|
||||
gb->data = data;
|
||||
|
||||
#ifdef HAVE_LIBMMX
|
||||
if (1) {
|
||||
gb->getbits = _gst_getbits_mmx;
|
||||
// gb->backbits = _gst_getbits_back_mmx;
|
||||
// gb->backbytes = _gst_getbits_byteback_mmx;
|
||||
// printf("gstgetbits: using MMX optimized versions\n");
|
||||
} else
|
||||
#endif /* HAVE_LIBMMX */
|
||||
{
|
||||
if (gb->callback) {
|
||||
gb->getbits = _gst_getbits_int_cb;
|
||||
gb->showbits = _gst_showbits_int;
|
||||
gb->flushbits = _gst_flushbits_int;
|
||||
gb->backbits = _gst_getbits_back_int;
|
||||
// printf("gstgetbits: using callback versions\n");
|
||||
}
|
||||
else {
|
||||
#ifdef HAVE_CPU_I386
|
||||
gb->get1bit = _gst_get1bit_i386;
|
||||
gb->getbits = _gst_getbits_i386;
|
||||
gb->getbits_fast = _gst_getbits_fast_i386;
|
||||
gb->getbyte = _gst_getbyte;
|
||||
gb->show1bit = _gst_showbits_i386;
|
||||
gb->showbits = _gst_showbits_i386;
|
||||
gb->flushbits = _gst_flushbits_i386;
|
||||
gb->backbits = _gst_getbits_back_i386;
|
||||
// printf("gstgetbits: using i386 optimized versions\n");
|
||||
#else
|
||||
gb->get1bit = _gst_get1bit_int;
|
||||
gb->getbits = _gst_getbits_int;
|
||||
gb->getbits_fast = _gst_getbits_fast_int;
|
||||
gb->getbyte = _gst_getbyte;
|
||||
gb->show1bit = _gst_showbits_int;
|
||||
gb->showbits = _gst_showbits_int;
|
||||
gb->flushbits = _gst_flushbits_int;
|
||||
gb->backbits = _gst_getbits_back_int;
|
||||
// printf("gstgetbits: using normal versions\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* set up the getbits structure with a new buffer */
|
||||
void gst_getbits_newbuf(gst_getbits_t *gb,unsigned char *buffer, unsigned long len) {
|
||||
gb->ptr = buffer;
|
||||
gb->endptr = buffer+len;
|
||||
gb->bits = 0;
|
||||
#ifdef HAVE_LIBMMX
|
||||
// gb->qword = 0;
|
||||
#endif /* HAVE_LIBMMX */
|
||||
}
|
149
libs/gst/getbits/getbits.h
Normal file
149
libs/gst/getbits/getbits.h
Normal file
|
@ -0,0 +1,149 @@
|
|||
#ifndef __GST_GETBITS_H__
|
||||
#define __GST_GETBITS_H__
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// getbits is critical, we need to forcibly disable DEBUG
|
||||
#define GST_DEBUG_FORCE_DISABLE
|
||||
#include <gst/gst.h>
|
||||
|
||||
/* disabled for now */
|
||||
#undef HAVE_LIBMMX
|
||||
|
||||
#ifdef HAVE_LIBMMX
|
||||
#include <mmx.h>
|
||||
#endif /* HAVE_LIBMMX */
|
||||
#ifdef HAVE_LIBSSE
|
||||
#include <sse.h>
|
||||
#endif /* HAVE_LIBSSE */
|
||||
|
||||
#define swab32(x) GUINT32_FROM_BE(x)
|
||||
|
||||
typedef struct _gst_getbits_t gst_getbits_t;
|
||||
typedef void (*GstGetbitsCallback) (gst_getbits_t *gb, void *data);
|
||||
|
||||
/* breaks in structure show alignment on quadword boundaries */
|
||||
/* FIXME: need to find out how to force GCC to align this to octwords */
|
||||
struct _gst_getbits_t {
|
||||
unsigned char *ptr;
|
||||
unsigned long *longptr;
|
||||
unsigned char *endptr;
|
||||
unsigned long length;
|
||||
long bits;
|
||||
unsigned long dword;
|
||||
unsigned long temp;
|
||||
|
||||
GstGetbitsCallback callback;
|
||||
void *data;
|
||||
|
||||
unsigned long (*get1bit)(gst_getbits_t *gb, unsigned long bits);
|
||||
unsigned long (*getbits)(gst_getbits_t *gb, unsigned long bits);
|
||||
unsigned long (*getbits_fast)(gst_getbits_t *gb, unsigned long bits);
|
||||
unsigned long (*getbyte)(gst_getbits_t *gb, unsigned long bits);
|
||||
unsigned long (*show1bit)(gst_getbits_t *gb, unsigned long bits);
|
||||
unsigned long (*showbits)(gst_getbits_t *gb, unsigned long bits);
|
||||
void (*flushbits)(gst_getbits_t *gb, unsigned long bits);
|
||||
void (*backbits)(gst_getbits_t *gb, unsigned long bits);
|
||||
|
||||
#ifdef HAVE_LIBMMX
|
||||
mmx_t qword; /* qword */
|
||||
#endif /* HAVE_LIBMMX */
|
||||
|
||||
#ifdef HAVE_LIBSSE
|
||||
sse_t oword; /* oword */
|
||||
#endif /* HAVE_LIBSSE */
|
||||
};
|
||||
|
||||
|
||||
#ifdef GST_GETBITS_INLINE
|
||||
#include "gstgetbits_inl.h"
|
||||
#else
|
||||
|
||||
void gst_getbits_init(gst_getbits_t *gb, GstGetbitsCallback callback, void *data);
|
||||
void gst_getbits_newbuf(gst_getbits_t *gb, unsigned char *buffer, unsigned long len);
|
||||
|
||||
#define gst_getbits_bitoffset(gb) \
|
||||
( \
|
||||
(-(gb)->bits)&0x7 \
|
||||
)
|
||||
|
||||
#define gst_getbits_align_byte(gb)
|
||||
|
||||
#define gst_getbits_bufferpos(gb) ((gb)->ptr)
|
||||
|
||||
#define gst_getbits_bytesleft(gb) ((gb)->endptr - (gb)->ptr)
|
||||
|
||||
#define gst_getbits_bitsleft(gb) (((gb)->endptr - (gb)->ptr)*8 - ((-(gb)->bits)&0x7))
|
||||
|
||||
#define gst_get1bit(gb) (((gb)->get1bit)(gb, 1))
|
||||
#define gst_getbitsX(gb,bits) (((gb)->getbits)(gb,bits))
|
||||
#define gst_getbits_fastX(gb,bits) (((gb)->getbits_fast)(gb,bits))
|
||||
#define gst_show1bit(gb,bits) (((gb)->show1bit)(gb,bits))
|
||||
#define gst_showbitsX(gb,bits) (((gb)->showbits)(gb,bits))
|
||||
#define gst_flushbitsX(gb,bits) (((gb)->flushbits)(gb,bits))
|
||||
#define gst_backbitsX(gb,bits) (((gb)->backbits)(gb,bits))
|
||||
|
||||
#define gst_getbyte(gb) (((gb)->getbyte)(gb,8))
|
||||
|
||||
#define gst_getbits_fastn(gb,n) gst_getbits_fastX(gb, n)
|
||||
|
||||
#define gst_getbitsn(gb,n) gst_getbitsX(gb, n)
|
||||
#define gst_getbits1(gb) gst_get1bit(gb)
|
||||
#define gst_getbits2(gb) gst_getbits_fastX(gb, 2)
|
||||
#define gst_getbits3(gb) gst_getbits_fastX(gb, 3)
|
||||
#define gst_getbits4(gb) gst_getbits_fastX(gb, 4)
|
||||
#define gst_getbits5(gb) gst_getbits_fastX(gb, 5)
|
||||
#define gst_getbits6(gb) gst_getbits_fastX(gb, 6)
|
||||
#define gst_getbits7(gb) gst_getbits_fastX(gb, 7)
|
||||
#define gst_getbits8(gb) gst_getbits_fastX(gb, 8)
|
||||
#define gst_getbits9(gb) gst_getbits_fastX(gb, 9)
|
||||
#define gst_getbits10(gb) gst_getbitsX(gb, 10)
|
||||
#define gst_getbits11(gb) gst_getbitsX(gb, 11)
|
||||
#define gst_getbits12(gb) gst_getbitsX(gb, 12)
|
||||
#define gst_getbits13(gb) gst_getbitsX(gb, 13)
|
||||
#define gst_getbits14(gb) gst_getbitsX(gb, 14)
|
||||
#define gst_getbits15(gb) gst_getbitsX(gb, 15)
|
||||
#define gst_getbits16(gb) gst_getbitsX(gb, 16)
|
||||
#define gst_getbits17(gb) gst_getbitsX(gb, 17)
|
||||
#define gst_getbits18(gb) gst_getbitsX(gb, 18)
|
||||
#define gst_getbits19(gb) gst_getbitsX(gb, 19)
|
||||
#define gst_getbits20(gb) gst_getbitsX(gb, 20)
|
||||
#define gst_getbits21(gb) gst_getbitsX(gb, 21)
|
||||
#define gst_getbits22(gb) gst_getbitsX(gb, 22)
|
||||
#define gst_getbits23(gb) gst_getbitsX(gb, 23)
|
||||
|
||||
#define gst_showbitsn(gb,n) gst_showbitsX(gb, n)
|
||||
#define gst_showbits1(gb) gst_show1bit(gb, 1)
|
||||
#define gst_showbits2(gb) gst_showbitsX(gb, 2)
|
||||
#define gst_showbits3(gb) gst_showbitsX(gb, 3)
|
||||
#define gst_showbits4(gb) gst_showbitsX(gb, 4)
|
||||
#define gst_showbits5(gb) gst_showbitsX(gb, 5)
|
||||
#define gst_showbits6(gb) gst_showbitsX(gb, 6)
|
||||
#define gst_showbits7(gb) gst_showbitsX(gb, 7)
|
||||
#define gst_showbits8(gb) gst_showbitsX(gb, 8)
|
||||
#define gst_showbits9(gb) gst_showbitsX(gb, 9)
|
||||
#define gst_showbits10(gb) gst_showbitsX(gb, 10)
|
||||
#define gst_showbits11(gb) gst_showbitsX(gb, 11)
|
||||
#define gst_showbits12(gb) gst_showbitsX(gb, 12)
|
||||
#define gst_showbits13(gb) gst_showbitsX(gb, 13)
|
||||
#define gst_showbits14(gb) gst_showbitsX(gb, 14)
|
||||
#define gst_showbits15(gb) gst_showbitsX(gb, 15)
|
||||
#define gst_showbits16(gb) gst_showbitsX(gb, 16)
|
||||
#define gst_showbits17(gb) gst_showbitsX(gb, 17)
|
||||
#define gst_showbits18(gb) gst_showbitsX(gb, 18)
|
||||
#define gst_showbits19(gb) gst_showbitsX(gb, 19)
|
||||
#define gst_showbits20(gb) gst_showbitsX(gb, 20)
|
||||
#define gst_showbits21(gb) gst_showbitsX(gb, 21)
|
||||
#define gst_showbits22(gb) gst_showbitsX(gb, 22)
|
||||
#define gst_showbits23(gb) gst_showbitsX(gb, 23)
|
||||
#define gst_showbits24(gb) gst_showbitsX(gb, 24)
|
||||
#define gst_showbits32(gb) gst_showbitsX(gb, 32)
|
||||
|
||||
#define gst_flushbitsn(gb,n) gst_flushbitsX(gb, n)
|
||||
#define gst_flushbits32(gb) gst_flushbitsX(gb, 32)
|
||||
|
||||
#define gst_backbitsn(gb,n) gst_backbitsX(gb, n)
|
||||
#define gst_backbits24(gb) gst_backbitsX(gb, 24)
|
||||
#endif
|
||||
|
||||
#endif /* __GST_GETBITS_H__ */
|
116
libs/gst/getbits/gstgetbits_generic.c
Normal file
116
libs/gst/getbits/gstgetbits_generic.c
Normal file
|
@ -0,0 +1,116 @@
|
|||
#include "gstgetbits.h"
|
||||
|
||||
unsigned long _gst_getbits_int_cb(gst_getbits_t *gb, unsigned long bits);
|
||||
unsigned long _gst_get1bit_int(gst_getbits_t *gb, unsigned long bits);
|
||||
unsigned long _gst_getbits_int(gst_getbits_t *gb, unsigned long bits);
|
||||
unsigned long _gst_getbits_fast_int(gst_getbits_t *gb, unsigned long bits);
|
||||
unsigned long _gst_showbits_int(gst_getbits_t *gb, unsigned long bits);
|
||||
void _gst_flushbits_int(gst_getbits_t *gb, unsigned long bits);
|
||||
void _gst_getbits_back_int(gst_getbits_t *gb, unsigned long bits);
|
||||
|
||||
|
||||
unsigned long _gst_getbits_int_cb(gst_getbits_t *gb, unsigned long bits) {
|
||||
int result;
|
||||
int bitsleft;
|
||||
|
||||
//printf("gst_getbits%lu %ld %p %08x\n", bits, gb->bits, gb->ptr, gb->dword);
|
||||
|
||||
if (!bits) return 0;
|
||||
|
||||
gb->bits -= bits;
|
||||
result = gb->dword >> (32-bits);
|
||||
|
||||
if (gb->bits < 0) {
|
||||
|
||||
gb->ptr += 4;
|
||||
|
||||
bitsleft = (gb->endptr - gb->ptr)*8;
|
||||
bits = -gb->bits;
|
||||
gb->bits += (bitsleft>32? 32 : bitsleft);
|
||||
|
||||
if (gb->endptr <= gb->ptr) {
|
||||
(gb->callback)(gb, gb->data);
|
||||
gb->bits -= bits;
|
||||
}
|
||||
gb->dword = swab32(*((unsigned long *)(gb->ptr)));
|
||||
|
||||
result |= (gb->dword >> (32-bits));
|
||||
}
|
||||
gb->dword <<= bits;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned long _gst_get1bit_int(gst_getbits_t *gb, unsigned long bits) {
|
||||
unsigned char rval;
|
||||
|
||||
rval = *gb->ptr << gb->bits;
|
||||
|
||||
gb->bits++;
|
||||
gb->ptr += (gb->bits>>3);
|
||||
gb->bits &= 0x7;
|
||||
|
||||
GST_DEBUG (0,"getbits%ld, %08x\n", bits, rval);
|
||||
return rval>>7;
|
||||
}
|
||||
|
||||
unsigned long _gst_getbits_int(gst_getbits_t *gb, unsigned long bits) {
|
||||
unsigned long rval;
|
||||
|
||||
if (bits == 0) return 0;
|
||||
|
||||
rval = swab32(*((unsigned long *)(gb->ptr)));
|
||||
rval <<= gb->bits;
|
||||
|
||||
gb->bits += bits;
|
||||
|
||||
rval >>= (32-bits);
|
||||
gb->ptr += (gb->bits>>3);
|
||||
gb->bits &= 0x7;
|
||||
|
||||
GST_DEBUG (0,"getbits%ld, %08lx\n", bits, rval);
|
||||
return rval;
|
||||
}
|
||||
|
||||
unsigned long _gst_getbits_fast_int(gst_getbits_t *gb, unsigned long bits) {
|
||||
unsigned long rval;
|
||||
|
||||
rval = (unsigned char) (gb->ptr[0] << gb->bits);
|
||||
rval |= ((unsigned int) gb->ptr[1] << gb->bits)>>8;
|
||||
rval <<= bits;
|
||||
rval >>= 8;
|
||||
|
||||
gb->bits += bits;
|
||||
gb->ptr += (gb->bits>>3);
|
||||
gb->bits &= 0x7;
|
||||
|
||||
GST_DEBUG (0,"getbits%ld, %08lx\n", bits, rval);
|
||||
return rval;
|
||||
}
|
||||
|
||||
unsigned long _gst_showbits_int(gst_getbits_t *gb, unsigned long bits) {
|
||||
unsigned long rval;
|
||||
|
||||
if (bits == 0) return 0;
|
||||
|
||||
rval = swab32(*((unsigned long *)(gb->ptr)));
|
||||
rval <<= gb->bits;
|
||||
rval >>= (32-bits);
|
||||
|
||||
GST_DEBUG (0,"showbits%ld, %08lx\n", bits, rval);
|
||||
return rval;
|
||||
}
|
||||
|
||||
void _gst_flushbits_int(gst_getbits_t *gb, unsigned long bits) {
|
||||
gb->bits += bits;
|
||||
gb->ptr += (gb->bits>>3);
|
||||
gb->bits &= 0x7;
|
||||
GST_DEBUG (0,"flushbits%ld\n", bits);
|
||||
}
|
||||
|
||||
void _gst_getbits_back_int(gst_getbits_t *gb, unsigned long bits) {
|
||||
gb->bits -= bits;
|
||||
gb->ptr += (gb->bits>>3);
|
||||
gb->bits &= 0x7;
|
||||
}
|
||||
|
115
libs/gst/getbits/gstgetbits_i386.s
Normal file
115
libs/gst/getbits/gstgetbits_i386.s
Normal file
|
@ -0,0 +1,115 @@
|
|||
.p2align 4,,7
|
||||
.globl _gst_getbits_i386
|
||||
.type _gst_getbits_i386,@function
|
||||
_gst_getbits_i386:
|
||||
cmpl $0,8(%esp)
|
||||
jne .L39
|
||||
xorl %eax,%eax
|
||||
ret
|
||||
.L39:
|
||||
movl 4(%esp),%edx
|
||||
movl (%edx),%ecx
|
||||
movl (%ecx),%eax
|
||||
bswap %eax
|
||||
movl 16(%edx),%ecx
|
||||
shll %cl, %eax
|
||||
movl 8(%esp),%ecx
|
||||
addl %ecx, 16(%edx)
|
||||
negl %ecx
|
||||
addl $32,%ecx
|
||||
shrl %cl, %eax
|
||||
movl 16(%edx),%ecx
|
||||
sarl $3,%ecx
|
||||
addl %ecx,(%edx)
|
||||
andl $7,16(%edx)
|
||||
ret
|
||||
|
||||
.p2align 4,,7
|
||||
.globl _gst_getbits_fast_i386
|
||||
.type _gst_getbits_fast_i386,@function
|
||||
_gst_getbits_fast_i386:
|
||||
movl 4(%esp),%edx
|
||||
movl (%edx),%ecx
|
||||
movzbl 1(%ecx),%eax
|
||||
movb (%ecx), %ah
|
||||
movl 16(%edx),%ecx
|
||||
shlw %cl, %ax
|
||||
movl 8(%esp),%ecx
|
||||
addl %ecx, 16(%edx)
|
||||
negl %ecx
|
||||
addl $16,%ecx
|
||||
shrl %cl, %eax
|
||||
movl 16(%edx),%ecx
|
||||
sarl $3,%ecx
|
||||
addl %ecx,(%edx)
|
||||
andl $7,16(%edx)
|
||||
ret
|
||||
|
||||
.p2align 4,,7
|
||||
.globl _gst_get1bit_i386
|
||||
.type _gst_get1bit_i386,@function
|
||||
_gst_get1bit_i386:
|
||||
movl 4(%esp),%edx
|
||||
movl (%edx),%ecx
|
||||
movzbl (%ecx),%eax
|
||||
movl 16(%edx),%ecx
|
||||
incl %ecx
|
||||
rolb %cl, %al
|
||||
andb $1, %al
|
||||
movl %ecx, 16(%edx)
|
||||
andl $7,16(%edx)
|
||||
sarl $3,%ecx
|
||||
addl %ecx,(%edx)
|
||||
ret
|
||||
|
||||
.p2align 4,,7
|
||||
.globl _gst_showbits_i386
|
||||
.type _gst_showbits_i386,@function
|
||||
_gst_showbits_i386:
|
||||
cmpl $0,8(%esp)
|
||||
jne .L40
|
||||
xorl %eax,%eax
|
||||
ret
|
||||
.L40:
|
||||
movl 4(%esp),%edx
|
||||
movl (%edx),%ecx
|
||||
movl (%ecx), %eax
|
||||
bswap %eax
|
||||
movl 16(%edx),%ecx
|
||||
shll %cl, %eax
|
||||
movl 8(%esp),%ecx
|
||||
negl %ecx
|
||||
addl $32,%ecx
|
||||
shrl %cl, %eax
|
||||
ret
|
||||
|
||||
|
||||
.p2align 4,,7
|
||||
.globl _gst_flushbits_i386
|
||||
.type _gst_flushbits_i386,@function
|
||||
_gst_flushbits_i386:
|
||||
movl 4(%esp),%ecx
|
||||
movl 16(%ecx),%eax
|
||||
addl 8(%esp),%eax
|
||||
movl %eax, %edx
|
||||
sarl $3,%eax
|
||||
addl %eax,(%ecx)
|
||||
andl $7, %edx
|
||||
movl %edx, 16(%ecx)
|
||||
ret
|
||||
|
||||
|
||||
.p2align 4,,7
|
||||
.globl _gst_getbits_back_i386
|
||||
.type _gst_getbits_back_i386,@function
|
||||
_gst_getbits_back_i386:
|
||||
movl 4(%esp),%edx
|
||||
movl 16(%edx),%ecx
|
||||
subl 8(%esp),%ecx
|
||||
movl %ecx, %eax
|
||||
sarl $3,%ecx
|
||||
addl %ecx,(%edx)
|
||||
andl $7,%eax
|
||||
movl %eax, 16(%edx)
|
||||
ret
|
||||
|
302
libs/gst/getbits/gstgetbits_inl.h
Normal file
302
libs/gst/getbits/gstgetbits_inl.h
Normal file
|
@ -0,0 +1,302 @@
|
|||
/*
|
||||
* Copyright (c) 1995 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose, without fee, and without written agreement is
|
||||
* hereby granted, provided that the above copyright notice and the following
|
||||
* two paragraphs appear in all copies of this software.
|
||||
*
|
||||
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
|
||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
|
||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
|
||||
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
|
||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions of this software Copyright (c) 1995 Brown University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose, without fee, and without written agreement
|
||||
* is hereby granted, provided that the above copyright notice and the
|
||||
* following two paragraphs appear in all copies of this software.
|
||||
*
|
||||
* IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE TO ANY PARTY FOR
|
||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
|
||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BROWN
|
||||
* UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* BROWN UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
|
||||
* BASIS, AND BROWN UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
|
||||
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
|
||||
/*
|
||||
Changes to make the code reentrant:
|
||||
deglobalized: curBits, curVidStream
|
||||
deglobalized: bitOffset, bitLength, bitBuffer in vid_stream, not used
|
||||
here
|
||||
Additional changes:
|
||||
-lsh@cs.brown.edu (Loring Holden)
|
||||
*/
|
||||
|
||||
#ifndef __GST_GETBITS_INL_H__
|
||||
#define __GST_GETBITS_INL_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
//#define GETBITS_DEBUG_ENABLED
|
||||
//#define GETBITS_OVERRUN_ENABLED
|
||||
|
||||
#ifdef GETBITS_DEBUG_ENABLED
|
||||
#define debug2(format,args...) g_print(format,##args)
|
||||
#define debug(format,args...) g_print(format,##args),
|
||||
#else
|
||||
#define debug(format,args...)
|
||||
#define debug2(format,args...)
|
||||
#endif
|
||||
|
||||
#ifdef GETBITS_OVERRUN_ENABLED
|
||||
#define checklength2(src, dst) (((unsigned char*)src)<(dst)?0:printf("overrun !! %p>=%p %ld %s %d\n", (src), (dst), (gb)->bits, __PRETTY_FUNCTION__, __LINE__))
|
||||
#define checklength(src, dst) (((unsigned char*)src)<(dst)?0:printf("overrun !! %p>=%p %ld %s %d\n", (src), (dst), (gb)->bits, __PRETTY_FUNCTION__, __LINE__)),
|
||||
#else
|
||||
#define checklength(src, dst)
|
||||
#define checklength2(src, dst)
|
||||
#endif
|
||||
|
||||
#define swab32(x) GUINT32_FROM_BE(x)
|
||||
|
||||
/* External declarations for bitstream i/o operations. */
|
||||
extern unsigned long gst_getbits_nBitMask[];
|
||||
|
||||
#define gst_getbits_init(gb, callback, data)
|
||||
|
||||
#define gst_getbits_newbuf(gb, buffer, len) \
|
||||
{ \
|
||||
(gb)->longptr = (unsigned long *)(buffer); \
|
||||
(gb)->endptr = (unsigned char *)buffer+len; \
|
||||
(gb)->length = len; \
|
||||
(gb)->bits = 0; \
|
||||
(gb)->dword = swab32(*(gb)->longptr); \
|
||||
}
|
||||
|
||||
#define gst_getbits_bitoffset(gb) \
|
||||
( \
|
||||
debug("bitoffset: %ld %p\n", (gb)->bits, (gb)->longptr) \
|
||||
(gb)->bits \
|
||||
)
|
||||
|
||||
#define gst_getbits_bufferpos(gb) ((gb)->longptr)
|
||||
|
||||
#define gst_getbits_bytesleft(gb) ((gb)->endptr - (unsigned char*)(gb)->longptr)
|
||||
|
||||
#define gst_getbits_bitsleft(gb) (((gb)->endptr - (unsigned char*)(gb)->longptr)*8 - (gb)->bits)
|
||||
|
||||
#define gst_getbits1(gb) \
|
||||
( \
|
||||
((gb)->temp = (((gb)->dword & 0x80000000) != 0)), \
|
||||
(gb)->dword <<= 1, \
|
||||
(gb)->bits++, \
|
||||
\
|
||||
((gb)->bits & 0x20 ? ( \
|
||||
(gb)->bits = 0, \
|
||||
(gb)->longptr++, \
|
||||
checklength((gb)->longptr, (gb)->endptr) \
|
||||
((gb)->dword = swab32(*(gb)->longptr)) \
|
||||
) \
|
||||
:0), \
|
||||
debug("getbits1 : %04lx %08lx %p\n", (gb)->temp, (gb)->dword, (gb)->longptr) \
|
||||
(gb)->temp \
|
||||
)
|
||||
|
||||
#define gst_getbits2(gb) \
|
||||
( \
|
||||
(gb)->bits += 2, \
|
||||
\
|
||||
((gb)->bits & 0x20 ? ( \
|
||||
(gb)->bits -= 32, \
|
||||
(gb)->longptr++, \
|
||||
checklength((gb)->longptr, (gb)->endptr) \
|
||||
((gb)->bits ? ( \
|
||||
((gb)->dword |= \
|
||||
(swab32(*(gb)->longptr) >> (2 - (gb)->bits))) \
|
||||
) \
|
||||
: 0 \
|
||||
),( \
|
||||
((gb)->temp = (((gb)->dword & 0xc0000000) >> 30)), \
|
||||
((gb)->dword = swab32(*(gb)->longptr) << (gb)->bits)) \
|
||||
) \
|
||||
: ( \
|
||||
((gb)->temp = (((gb)->dword & 0xc0000000) >> 30)), \
|
||||
((gb)->dword <<= 2) \
|
||||
) \
|
||||
), \
|
||||
debug("getbits2 : %04lx %08lx %p\n", (gb)->temp, (gb)->dword, (gb)->longptr) \
|
||||
(gb)->temp \
|
||||
)
|
||||
|
||||
#define gst_getbitsX(gb, num, mask, shift) \
|
||||
( \
|
||||
(gb)->bits += (num), \
|
||||
\
|
||||
((gb)->bits & 0x20 ? ( \
|
||||
(gb)->bits -= 32, \
|
||||
(gb)->longptr++, \
|
||||
checklength((gb)->longptr, (gb)->endptr) \
|
||||
((gb)->bits ? ( \
|
||||
((gb)->dword |= (swab32(*(gb)->longptr) >> \
|
||||
((num) - (gb)->bits))) \
|
||||
) \
|
||||
:0 \
|
||||
), \
|
||||
((gb)->temp = (((gb)->dword & (mask)) >> (shift))), \
|
||||
((gb)->dword = swab32(*(gb)->longptr) << (gb)->bits) \
|
||||
) \
|
||||
: ( \
|
||||
((gb)->temp = (((gb)->dword & mask) >> shift)), \
|
||||
((gb)->dword <<= (num)) \
|
||||
) \
|
||||
), \
|
||||
debug("getbits%-2d: %04lx %08lx %lu %p\n", num, (gb)->temp, (gb)->dword, mask, (gb)->longptr) \
|
||||
(gb)->temp \
|
||||
)
|
||||
|
||||
#define gst_getbits3(gb) gst_getbitsX(gb, 3, 0xe0000000UL, 29)
|
||||
#define gst_getbits4(gb) gst_getbitsX(gb, 4, 0xf0000000UL, 28)
|
||||
#define gst_getbits5(gb) gst_getbitsX(gb, 5, 0xf8000000UL, 27)
|
||||
#define gst_getbits6(gb) gst_getbitsX(gb, 6, 0xfc000000UL, 26)
|
||||
#define gst_getbits7(gb) gst_getbitsX(gb, 7, 0xfe000000UL, 25)
|
||||
#define gst_getbits8(gb) gst_getbitsX(gb, 8, 0xff000000UL, 24)
|
||||
#define gst_getbits9(gb) gst_getbitsX(gb, 9, 0xff800000UL, 23)
|
||||
#define gst_getbits10(gb) gst_getbitsX(gb, 10, 0xffc00000UL, 22)
|
||||
#define gst_getbits11(gb) gst_getbitsX(gb, 11, 0xffe00000UL, 21)
|
||||
#define gst_getbits12(gb) gst_getbitsX(gb, 12, 0xfff00000UL, 20)
|
||||
#define gst_getbits13(gb) gst_getbitsX(gb, 13, 0xfff80000UL, 19)
|
||||
#define gst_getbits14(gb) gst_getbitsX(gb, 14, 0xfffc0000UL, 18)
|
||||
#define gst_getbits15(gb) gst_getbitsX(gb, 15, 0xfffe0000UL, 17)
|
||||
#define gst_getbits16(gb) gst_getbitsX(gb, 16, 0xffff0000UL, 16)
|
||||
#define gst_getbits17(gb) gst_getbitsX(gb, 17, 0xffff8000UL, 15)
|
||||
#define gst_getbits18(gb) gst_getbitsX(gb, 18, 0xffffc000UL, 14)
|
||||
#define gst_getbits19(gb) gst_getbitsX(gb, 19, 0xffffe000UL, 13)
|
||||
#define gst_getbits20(gb) gst_getbitsX(gb, 20, 0xfffff000UL, 12)
|
||||
#define gst_getbits21(gb) gst_getbitsX(gb, 21, 0xfffff800UL, 11)
|
||||
#define gst_getbits22(gb) gst_getbitsX(gb, 22, 0xfffffc00UL, 10)
|
||||
#define gst_getbits32(gb) gst_getbitsX(gb, 32, 0xffffffffUL, 0)
|
||||
|
||||
#define gst_getbitsn(gb,num) gst_getbitsX(gb, (num), ((num) ? ((0xffffffffUL) << (32-(num))):0), (32-(num)))
|
||||
|
||||
#define gst_showbits32(gb) \
|
||||
( \
|
||||
((gb)->bits ? ( \
|
||||
(gb)->dword | (swab32(*((gb)->longptr+1)) >> \
|
||||
(32 - (gb)->bits)) \
|
||||
) \
|
||||
: ( \
|
||||
(gb)->dword \
|
||||
) \
|
||||
) \
|
||||
)
|
||||
|
||||
#define gst_showbitsX(gb, num, mask, shift) \
|
||||
( \
|
||||
((gb)->temp = (gb)->bits + num), \
|
||||
((gb)->temp > 32 ? ( \
|
||||
(gb)->temp -= 32, \
|
||||
(((gb)->dword & mask) >> shift) | \
|
||||
(swab32(*((gb)->longptr+1)) >> (shift + (num - (gb)->temp))) \
|
||||
) \
|
||||
: ( \
|
||||
(((gb)->dword & mask) >> shift) \
|
||||
) \
|
||||
) \
|
||||
)
|
||||
|
||||
#define gst_showbits1(gb) gst_showbitsX(gb, 1, 0x80000000, 31)
|
||||
#define gst_showbits2(gb) gst_showbitsX(gb, 2, 0xc0000000, 30)
|
||||
#define gst_showbits3(gb) gst_showbitsX(gb, 3, 0xe0000000, 29)
|
||||
#define gst_showbits4(gb) gst_showbitsX(gb, 4, 0xf0000000, 28)
|
||||
#define gst_showbits5(gb) gst_showbitsX(gb, 5, 0xf8000000, 27)
|
||||
#define gst_showbits6(gb) gst_showbitsX(gb, 6, 0xfc000000, 26)
|
||||
#define gst_showbits7(gb) gst_showbitsX(gb, 7, 0xfe000000, 25)
|
||||
#define gst_showbits8(gb) gst_showbitsX(gb, 8, 0xff000000, 24)
|
||||
#define gst_showbits9(gb) gst_showbitsX(gb, 9, 0xff800000, 23)
|
||||
#define gst_showbits10(gb) gst_showbitsX(gb, 10, 0xffc00000, 22)
|
||||
#define gst_showbits11(gb) gst_showbitsX(gb, 11, 0xffe00000, 21)
|
||||
#define gst_showbits12(gb) gst_showbitsX(gb, 12, 0xfff00000, 20)
|
||||
#define gst_showbits13(gb) gst_showbitsX(gb, 13, 0xfff80000, 19)
|
||||
#define gst_showbits14(gb) gst_showbitsX(gb, 14, 0xfffc0000, 18)
|
||||
#define gst_showbits15(gb) gst_showbitsX(gb, 15, 0xfffe0000, 17)
|
||||
#define gst_showbits16(gb) gst_showbitsX(gb, 16, 0xffff0000, 16)
|
||||
#define gst_showbits17(gb) gst_showbitsX(gb, 17, 0xffff8000, 15)
|
||||
#define gst_showbits18(gb) gst_showbitsX(gb, 18, 0xffffc000, 14)
|
||||
#define gst_showbits19(gb) gst_showbitsX(gb, 19, 0xffffe000, 13)
|
||||
#define gst_showbits20(gb) gst_showbitsX(gb, 20, 0xfffff000, 12)
|
||||
#define gst_showbits21(gb) gst_showbitsX(gb, 21, 0xfffff800, 11)
|
||||
#define gst_showbits22(gb) gst_showbitsX(gb, 22, 0xfffffc00, 10)
|
||||
#define gst_showbits23(gb) gst_showbitsX(gb, 23, 0xfffffe00, 9)
|
||||
#define gst_showbits24(gb) gst_showbitsX(gb, 24, 0xffffff00, 8)
|
||||
#define gst_showbits25(gb) gst_showbitsX(gb, 25, 0xffffff80, 7)
|
||||
#define gst_showbits26(gb) gst_showbitsX(gb, 26, 0xffffffc0, 6)
|
||||
#define gst_showbits27(gb) gst_showbitsX(gb, 27, 0xffffffe0, 5)
|
||||
#define gst_showbits28(gb) gst_showbitsX(gb, 28, 0xfffffff0, 4)
|
||||
#define gst_showbits29(gb) gst_showbitsX(gb, 29, 0xfffffff8, 3)
|
||||
#define gst_showbits30(gb) gst_showbitsX(gb, 30, 0xfffffffc, 2)
|
||||
#define gst_showbits31(gb) gst_showbitsX(gb, 31, 0xfffffffe, 1)
|
||||
|
||||
#define gst_showbitsn(gb,num) gst_showbitsX(gb, (num), ((0xffffffff) << (32-num)), (32-(num)))
|
||||
|
||||
#define gst_flushbits32(gb) \
|
||||
{ \
|
||||
(gb)->longptr++; \
|
||||
checklength2((gb)->longptr, (gb)->endptr); \
|
||||
(gb)->dword = swab32(*(gb)->longptr) << (gb)->bits; \
|
||||
}
|
||||
|
||||
|
||||
#define gst_flushbitsn(gb, num) \
|
||||
{ \
|
||||
(gb)->bits += num; \
|
||||
\
|
||||
if ((gb)->bits & 0x20) { \
|
||||
(gb)->bits -= 32; \
|
||||
(gb)->longptr++; \
|
||||
checklength2((gb)->longptr, (gb)->endptr); \
|
||||
(gb)->dword = swab32(*(gb)->longptr) << (gb)->bits; \
|
||||
} \
|
||||
else { \
|
||||
(gb)->dword <<= num; \
|
||||
} \
|
||||
debug2("flushbits%-2d: %08lx %p\n", num, (gb)->dword, (gb)->longptr); \
|
||||
}
|
||||
|
||||
#define gst_backbits24(gb) \
|
||||
{ \
|
||||
(gb)->bits -= 24; \
|
||||
if ((gb)->bits < 0) { \
|
||||
(gb)->bits += 32; \
|
||||
(gb)->longptr--; \
|
||||
} \
|
||||
(gb)->dword = swab32(*(gb)->longptr) << (gb)->bits; \
|
||||
}
|
||||
|
||||
#define gst_backbitsn(gb, num) \
|
||||
{ \
|
||||
(gb)->bits -= num; \
|
||||
while ((gb)->bits < 0) { \
|
||||
(gb)->bits += 32; \
|
||||
(gb)->longptr--; \
|
||||
} \
|
||||
(gb)->dword = swab32(*(gb)->longptr) << (gb)->bits; \
|
||||
debug2("backbits%-2d: %08lx %p\n", num, (gb)->dword, (gb)->longptr); \
|
||||
}
|
||||
|
||||
#endif /* __GST_GETBITS_INL_H__ */
|
13
libs/gst/putbits/Makefile.am
Normal file
13
libs/gst/putbits/Makefile.am
Normal file
|
@ -0,0 +1,13 @@
|
|||
librarydir = $(libdir)/gst
|
||||
|
||||
library_LTLIBRARIES = libgstputbits.la
|
||||
|
||||
libgstputbits_la_SOURCES = putbits.c
|
||||
|
||||
libgstputbitsincludedir = $(includedir)/gst/putbits
|
||||
libgstputbitsinclude_HEADERS = putbits.h
|
||||
|
||||
noinst_HEADERS = putbits.h
|
||||
|
||||
libgstputbits_la_LIBADD = $(GST_LIBS)
|
||||
libgstputbits_la_CFLAGS = $(GST_CFLAGS) -funroll-all-loops -finline-functions -ffast-math
|
101
libs/gst/putbits/putbits.c
Normal file
101
libs/gst/putbits/putbits.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
/* putbits.c, bit-level output */
|
||||
|
||||
/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
|
||||
|
||||
/*
|
||||
* Disclaimer of Warranty
|
||||
*
|
||||
* These software programs are available to the user without any license fee or
|
||||
* royalty on an "as is" basis. The MPEG Software Simulation Group disclaims
|
||||
* any and all warranties, whether express, implied, or statuary, including any
|
||||
* implied warranties or merchantability or of fitness for a particular
|
||||
* purpose. In no event shall the copyright-holder be liable for any
|
||||
* incidental, punitive, or consequential damages of any kind whatsoever
|
||||
* arising from the use of these programs.
|
||||
*
|
||||
* This disclaimer of warranty extends to the user of these programs and user's
|
||||
* customers, employees, agents, transferees, successors, and assigns.
|
||||
*
|
||||
* The MPEG Software Simulation Group does not represent or warrant that the
|
||||
* programs furnished hereunder are free of infringement of any third-party
|
||||
* patents.
|
||||
*
|
||||
* Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
|
||||
* are subject to royalty fees to patent holders. Many of these patents are
|
||||
* general enough such that they are unavoidable regardless of implementation
|
||||
* design.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "gstputbits.h"
|
||||
|
||||
/* initialize buffer, call once before first putbits or alignbits */
|
||||
void gst_putbits_init(gst_putbits_t *pb)
|
||||
{
|
||||
pb->outcnt = 8;
|
||||
pb->bytecnt = 0;
|
||||
pb->outbase = 0;
|
||||
}
|
||||
|
||||
void gst_putbits_new_empty_buffer(gst_putbits_t *pb, int len)
|
||||
{
|
||||
pb->outbfr = pb->outbase = malloc(len);
|
||||
pb->temp = 0;
|
||||
pb->len = len;
|
||||
pb->newlen = 0;
|
||||
pb->outcnt = 8;
|
||||
}
|
||||
|
||||
void gst_putbits_new_buffer(gst_putbits_t *pb, unsigned char *buffer, int len)
|
||||
{
|
||||
pb->outbfr = buffer;
|
||||
pb->temp = 0;
|
||||
pb->outcnt = 8;
|
||||
pb->bytecnt = 0;
|
||||
pb->len = len;
|
||||
}
|
||||
|
||||
/* write rightmost n (0<=n<=32) bits of val to outfile */
|
||||
void gst_putbits(gst_putbits_t *pb, int val, int n)
|
||||
{
|
||||
int i;
|
||||
unsigned int mask;
|
||||
|
||||
//printf("putbits: %p %08x %d %d %d\n", pb, val, n, pb->outcnt, pb->newlen);
|
||||
mask = 1 << (n-1); /* selects first (leftmost) bit */
|
||||
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
pb->temp <<= 1;
|
||||
|
||||
if (val & mask)
|
||||
pb->temp|= 1;
|
||||
|
||||
mask >>= 1; /* select next bit */
|
||||
pb->outcnt--;
|
||||
|
||||
if (pb->outcnt==0) /* 8 bit buffer full */
|
||||
{
|
||||
pb->len--;
|
||||
pb->newlen++;
|
||||
*(pb->outbfr++) = pb->temp;
|
||||
pb->outcnt = 8;
|
||||
pb->bytecnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* zero bit stuffing to next byte boundary (5.2.3, 6.2.1) */
|
||||
void gst_putbits_align(gst_putbits_t *pb)
|
||||
{
|
||||
if (pb->outcnt!=8)
|
||||
gst_putbits(pb, 0, pb->outcnt);
|
||||
}
|
||||
|
||||
/* return total number of generated bits */
|
||||
int gst_putbits_bitcount(gst_putbits_t *pb)
|
||||
{
|
||||
return 8*pb->bytecnt + (8-pb->outcnt);
|
||||
}
|
78
libs/gst/putbits/putbits.h
Normal file
78
libs/gst/putbits/putbits.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/* putbits.h, bit-level output */
|
||||
|
||||
/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
|
||||
|
||||
/*
|
||||
* Disclaimer of Warranty
|
||||
*
|
||||
* These software programs are available to the user without any license fee or
|
||||
* royalty on an "as is" basis. The MPEG Software Simulation Group disclaims
|
||||
* any and all warranties, whether express, implied, or statuary, including any
|
||||
* implied warranties or merchantability or of fitness for a particular
|
||||
* purpose. In no event shall the copyright-holder be liable for any
|
||||
* incidental, punitive, or consequential damages of any kind whatsoever
|
||||
* arising from the use of these programs.
|
||||
*
|
||||
* This disclaimer of warranty extends to the user of these programs and user's
|
||||
* customers, employees, agents, transferees, successors, and assigns.
|
||||
*
|
||||
* The MPEG Software Simulation Group does not represent or warrant that the
|
||||
* programs furnished hereunder are free of infringement of any third-party
|
||||
* patents.
|
||||
*
|
||||
* Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
|
||||
* are subject to royalty fees to patent holders. Many of these patents are
|
||||
* general enough such that they are unavoidable regardless of implementation
|
||||
* design.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __GST_PUTBITS_H__
|
||||
#define __GST_PUTBITS_H__
|
||||
|
||||
typedef struct _gst_putbits_t gst_putbits_t;
|
||||
|
||||
struct _gst_putbits_t {
|
||||
unsigned char *outbfr;
|
||||
unsigned char *outbase;
|
||||
unsigned char temp;
|
||||
int outcnt;
|
||||
int bytecnt;
|
||||
int len;
|
||||
int newlen;
|
||||
};
|
||||
|
||||
void gst_putbits_init(gst_putbits_t *pb);
|
||||
void gst_putbits_new_empty_buffer(gst_putbits_t *pb, int len);
|
||||
void gst_putbits_new_buffer(gst_putbits_t *pb, unsigned char *buffer, int len);
|
||||
void gst_putbits(gst_putbits_t *pb, int val, int n);
|
||||
void gst_putbits_align(gst_putbits_t *pb);
|
||||
int gst_putbits_bitcount(gst_putbits_t *pb);
|
||||
|
||||
#define gst_putbits1(gb, val) gst_putbits(gb, val, 1)
|
||||
#define gst_putbits2(gb, val) gst_putbits(gb, val, 2)
|
||||
#define gst_putbits3(gb, val) gst_putbits(gb, val, 3)
|
||||
#define gst_putbits4(gb, val) gst_putbits(gb, val, 4)
|
||||
#define gst_putbits5(gb, val) gst_putbits(gb, val, 5)
|
||||
#define gst_putbits6(gb, val) gst_putbits(gb, val, 6)
|
||||
#define gst_putbits7(gb, val) gst_putbits(gb, val, 7)
|
||||
#define gst_putbits8(gb, val) gst_putbits(gb, val, 8)
|
||||
#define gst_putbits9(gb, val) gst_putbits(gb, val, 9)
|
||||
#define gst_putbits10(gb, val) gst_putbits(gb, val, 10)
|
||||
#define gst_putbits11(gb, val) gst_putbits(gb, val, 11)
|
||||
#define gst_putbits12(gb, val) gst_putbits(gb, val, 12)
|
||||
#define gst_putbits13(gb, val) gst_putbits(gb, val, 13)
|
||||
#define gst_putbits14(gb, val) gst_putbits(gb, val, 14)
|
||||
#define gst_putbits15(gb, val) gst_putbits(gb, val, 15)
|
||||
#define gst_putbits16(gb, val) gst_putbits(gb, val, 16)
|
||||
#define gst_putbits17(gb, val) gst_putbits(gb, val, 17)
|
||||
#define gst_putbits18(gb, val) gst_putbits(gb, val, 18)
|
||||
#define gst_putbits19(gb, val) gst_putbits(gb, val, 19)
|
||||
#define gst_putbits20(gb, val) gst_putbits(gb, val, 20)
|
||||
#define gst_putbits21(gb, val) gst_putbits(gb, val, 21)
|
||||
#define gst_putbits22(gb, val) gst_putbits(gb, val, 22)
|
||||
#define gst_putbits32(gb, val) gst_putbits(gb, val, 32)
|
||||
|
||||
#define gst_putbitsn(gb, val, n) gst_putbits(gb, val, n)
|
||||
|
||||
#endif /* __GST_PUTBITS_H__ */
|
Loading…
Reference in a new issue